]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/stored/fd_cmds.c
authorEric Bollengier <eric@baculasystems.com>
Tue, 12 May 2020 16:50:11 +0000 (18:50 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 29 Apr 2021 08:44:18 +0000 (10:44 +0200)
This commit is the result of the squash of the following main commits:

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Fri Apr 24 20:16:22 2020 +0200

    Reliably log user activity in a way that satisfies auditors

    Messages {
      name = Standard
      append = /tmp/bacula.log = all

      # To send the events into a log and in the catalog
      append = /tmp/audit.log = events, !events.bweb
      catalog = all, events
    }

    Users can create custom events with a console command:

    .events

    They can list events in the catalog with

    * list events
    +---------------------+------------+-----------+--------------------------------+
    | time                | type       | source    | events                         |
    +---------------------+------------+-----------+--------------------------------+
    | 2020-04-24 17:04:07 | daemon     | *Daemon*  | Director startup               |
    | 2020-04-24 17:04:12 | connection | *Console* | Connection from 127.0.0.1:8101 |
    | 2020-04-24 17:04:20 | command    | *Console* | purge jobid=1                  |
    +---------------------+------------+-----------+--------------------------------+

    The event format in the log is:

    24-Apr 17:04 Events: code=DC0001 from=zog8-dir ref=0x1fa5 type=daemon source=*Daemon* text=Director startup

    24-Apr 17:04 Events: code=DC0002 from=zog8-dir ref=0x7fb58000c4b8 type=connection source=*Console* text=Connection from 127.0.0.1:8101

    The reference (ref) is used to identify a console session, all activity
    from the same console will have the same reference.

    The source is the name of the restricted console, or *Console* if this
    is the default console.

    We have the following events:
     - cancel a job
     - delete volume
     - delete job
     - purge job
     - delete pool
     - delete client
     - daemon startup
     - daemon shutdown
     - console connection
     - console disconnection

    To add a new events:
    ua->send_events(type, format, arguments);

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Jul 11 16:57:45 2019 +0200

    Rework SD/FD test network function

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Mon Jul 8 18:19:00 2019 +0200

    Add RTT estimation to the 'status network' command

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Wed Aug 17 10:35:11 2016 +0200

    Add "status network" command to test the connection and the bandwidth between a Client and a Storage Daemon

bacula/src/stored/fd_cmds.c

index 021f2f4dc46436905b076460b889cefe2deb3b6a..2a5244271849fd03c748ef82d96ba0414f0207f2 100644 (file)
@@ -26,6 +26,8 @@
  *  then when the Storage daemon receives a proper connection from
  *  the File daemon, control is passed here to handle the
  *  subsequent File daemon commands.
+ *
+ *
  */
 
 #include "bacula.h"
@@ -141,14 +143,13 @@ void run_job(JCR *jcr)
       append_end_session(jcr);
    } else if (jcr->is_JobType(JT_MIGRATE) || jcr->is_JobType(JT_COPY)) {
       jcr->session_opened = true;
-      /*
-       * Send "3000 OK data" now to avoid a dead lock, the other side is also
-       * waiting for one. The old code was reading the "3000 OK" reply
+      /* send "3000 OK data" now to avoid a dead lock, the other side is also
+       * waiting for one. The old peace of code was reading the "3000 OK" reply
        * at the end of the backup (not really appropriate).
-       * dedup needs duplex communication with the other side and needs the
-       * "3000 OK" to be read, which is handled here by the code below.
-       */
-      Dmsg0(215, "send OK_data\n");
+       * dedup need duplex communication with the other side and need the
+       * "3000 OK" to be out of the socket, and be handle here by the right
+       * peace of code */
+      Dmsg0(DT_DEDUP|215, "send OK_data\n");
       jcr->file_bsock->fsend(OK_data);
       jcr->is_ok_data_sent = true;
       Dmsg1(050, "Do: read_data_cmd file_bsock=%p\n", jcr->file_bsock);
@@ -171,6 +172,13 @@ bail_out:
    flush_jobmedia_queue(jcr);
    dequeue_messages(jcr);             /* send any queued messages */
    jcr->setJobStatus(JS_Terminated);
+
+   /* Keep track of the important events */
+   events_send_msg(jcr, "SJ0002",
+                      EVENTS_TYPE_JOB, jcr->director->hdr.name, (intptr_t)jcr,
+                      "Job End jobid=%i job=%s status=%c",
+                      jcr->JobId, jcr->Job, jcr->JobStatus);
+
    generate_daemon_event(jcr, "JobEnd");
    generate_plugin_event(jcr, bsdEventJobEnd);
    bash_spaces(jcr->StatusErrMsg);
@@ -292,31 +300,58 @@ static bool append_end_session(JCR *jcr)
 static bool sd_testnetwork_cmd(JCR *jcr)
 {
    BSOCK *fd = jcr->file_bsock;
-   int64_t nb=0;
-   bool can_compress, ok=true;
-
-   if (sscanf(fd->msg, "testnetwork bytes=%lld", &nb) != 1) {
-      return false;
+   int64_t nb=0, nbrtt=0, rtt=0, bandwidth=0;
+   int32_t ok=1;
+   bool can_compress;
+   btime_t start, end;
+
+   if (scan_string(fd->msg, "testnetwork bytes=%lld rtt=%lld bw=%lld", &nb, &nbrtt, &bandwidth) != 3) {
+      if (scan_string(fd->msg, "testnetwork bytes=%lld", &nb) != 1) {
+         Dmsg1(0, "Invalid command %s\n", fd->msg);
+         return false;
+      }
    }
+
    /* We disable the comline compression for this test */
    can_compress = fd->can_compress();
    fd->clear_compress();
 
-   /* First, get data from the FD */
-   while (fd->recv() > 0) { }
+   if (nb > 0) {
+      /* First, get data from the FD */
+      while (fd->recv() > 0) { }
 
-   /* Then, send back data to the FD */
-   memset(fd->msg, 0xBB, sizeof_pool_memory(fd->msg));
-   fd->msglen = sizeof_pool_memory(fd->msg);
+      /* Then, send back data to the FD */
+      memset(fd->msg, 0xBB, sizeof_pool_memory(fd->msg));
+      fd->msglen = sizeof_pool_memory(fd->msg);
+
+      while(nb > 0 && ok > 0) {
+         if (nb < fd->msglen) {
+            fd->msglen = nb;
+         }
+         ok = fd->send();
+         nb -= fd->msglen;
+      }
+      fd->signal(BNET_EOD);
+   }
+
+   /* Compute RTT */
+   ok = 1;
+   if (nbrtt > 0) {
+      while (ok > 0) {
+         start = get_current_btime();
+         ok = fd->recv();
+         if (ok > 0) {
+            ok = fd->send();
+            end = get_current_btime() + 1;
+            rtt += end - start;
+         }
+      }
 
-   while(nb > 0 && ok) {
-      if (nb < fd->msglen) {
-         fd->msglen = nb;
+      if (nbrtt) {
+         fd->set_bandwidth(bandwidth);
+         fd->set_rtt(rtt / nbrtt);
       }
-      ok = fd->send();
-      nb -= fd->msglen;
    }
-   fd->signal(BNET_EOD);
 
    if (can_compress) {
       fd->set_compress();