]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/dircmd.c
kes Define a machine dependent ioctl request type for use with
[bacula/bacula] / bacula / src / stored / dircmd.c
index f54994bb978e63bbeeaf132ce55c0242bf317c42..a53efa31c3cb443e4e22fdb178df95e1333652a0 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2001-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2001-2008 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
@@ -20,7 +20,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
@@ -54,8 +54,6 @@
 
 /* Imported variables */
 extern BSOCK *filed_chan;
-extern int r_first, r_last;
-extern struct s_res resources[];
 extern struct s_last_job last_job;
 extern bool init_done;
 
@@ -97,7 +95,7 @@ static void send_dir_busy_message(BSOCK *dir, DEVICE *dev);
 struct s_cmds {
    const char *cmd;
    bool (*func)(JCR *jcr);
-   int monitoraccess; /* specify if monitors have access to this function */
+   bool monitoraccess;                      /* set if monitors can access this cmd */
 };
 
 /*
@@ -149,6 +147,7 @@ void *handle_connection_request(void *arg)
    bool found, quit;
    int bnet_stat = 0;
    char name[500];
+   char tbuf[100];
 
    if (bs->recv() <= 0) {
       Emsg0(M_ERROR, 0, _("Connection request failed.\n"));
@@ -174,7 +173,8 @@ void *handle_connection_request(void *arg)
       Dmsg1(000, "<filed: %s", bs->msg);
    }
    if (sscanf(bs->msg, "Hello Start Job %127s", name) == 1) {
-      Dmsg0(110, "Got a FD connection\n");
+      Dmsg1(110, "Got a FD connection at %s\n", bstrftimes(tbuf, sizeof(tbuf), 
+            (utime_t)time(NULL)));
       handle_filed_connection(bs, name);
       return NULL;
    }
@@ -182,7 +182,8 @@ void *handle_connection_request(void *arg)
    /* 
     * This is a connection from the Director, so setup a JCR 
     */
-   Dmsg0(110, "Got a DIR connection\n");
+   Dmsg1(110, "Got a DIR connection at %s\n", bstrftimes(tbuf, sizeof(tbuf), 
+         (utime_t)time(NULL)));
    jcr = new_jcr(sizeof(JCR), stored_free_jcr); /* create Job Control Record */
    jcr->dir_bsock = bs;               /* save Director bsock */
    jcr->dir_bsock->set_jcr(jcr);
@@ -190,7 +191,8 @@ void *handle_connection_request(void *arg)
    /* Initialize FD start condition variable */
    int errstat = pthread_cond_init(&jcr->job_start_wait, NULL);
    if (errstat != 0) {
-      Jmsg1(jcr, M_FATAL, 0, _("Unable to init job cond variable: ERR=%s\n"), strerror(errstat));
+      berrno be;
+      Jmsg1(jcr, M_FATAL, 0, _("Unable to init job cond variable: ERR=%s\n"), be.bstrerror(errstat));
       goto bail_out;
    }
 
@@ -384,7 +386,7 @@ static bool do_label(JCR *jcr, int relabel)
       if (dcr) {
          dev = dcr->dev;
          dev->dlock();                 /* Use P to avoid indefinite block */
-         if (!dev->is_open()) {
+         if (!dev->is_open() && !dev->is_busy()) {
             Dmsg1(400, "Can %slabel. Device is not open\n", relabel?"re":"");
             label_volume_if_ok(dcr, oldname, newname, poolname, slot, relabel);
             dev->close();
@@ -457,7 +459,7 @@ static void label_volume_if_ok(DCR *dcr, char *oldname,
    bstrncpy(dcr->VolCatInfo.VolCatName, volname, sizeof(dcr->VolCatInfo.VolCatName));
    if (dev->open(dcr, mode) < 0) {
       dir->fsend(_("3910 Unable to open device %s: ERR=%s\n"),
-         dev->print_name(), dev->strerror());
+         dev->print_name(), dev->bstrerror());
       goto bail_out;      
    }
 
@@ -514,6 +516,7 @@ bail_out:
    if (!dev->is_open()) {
       dev->clear_volhdr();
    }
+   volume_unused(dcr);                   /* no longer using volume */
    give_back_device_lock(dev, &hold);
    return;
 }
@@ -547,6 +550,7 @@ static bool read_label(DCR *dcr)
       ok = false;
       break;
    }
+   volume_unused(dcr);
    give_back_device_lock(dev, &hold);
    return ok;
 }
@@ -646,7 +650,8 @@ static bool mount_cmd(JCR *jcr)
       if (dcr) {
          dev = dcr->dev;
          dev->dlock();                 /* Use P to avoid indefinite block */
-         Dmsg1(100, "mount cmd blocked=%d\n", dev->blocked());
+         Dmsg2(100, "mount cmd blocked=%d must_unload=%d\n", dev->blocked(), 
+            dev->must_unload());
          switch (dev->blocked()) {         /* device blocked? */
          case BST_WAITING_FOR_SYSOP:
             /* Someone is waiting, wake him */
@@ -667,8 +672,8 @@ static bool mount_cmd(JCR *jcr)
             }
             /* We freed the device, so reopen it and wake any waiting threads */
             if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
-               dir->fsend(_("3901 open device failed: ERR=%s\n"),
-                  dev->bstrerror());
+               dir->fsend(_("3901 Unable to open device %s: ERR=%s\n"),
+                  dev->print_name(), dev->bstrerror());
                if (dev->blocked() == BST_UNMOUNTED) {
                   /* We blocked the device, so unblock it */
                   Dmsg0(100, "Unmounted. Unblocking device\n");
@@ -724,8 +729,8 @@ static bool mount_cmd(JCR *jcr)
                }
             } else if (dev->is_tape()) {
                if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
-                  dir->fsend(_("3901 open device failed: ERR=%s\n"),
-                     dev->bstrerror());
+                  dir->fsend(_("3901 Unable to open device %s: ERR=%s\n"),
+                     dev->print_name(), dev->bstrerror());
                   break;
                }
                read_label(dcr);
@@ -833,7 +838,7 @@ static bool unmount_cmd(JCR *jcr)
              */
             /*  block_device(dev, BST_UNMOUNTED); replace with 2 lines below */
             dev->set_blocked(BST_UNMOUNTED);
-            dev->no_wait_id = 0;
+            clear_thread_id(dev->no_wait_id);
             if (!unload_autochanger(dcr, -1)) {
                dev->close();
             }
@@ -910,9 +915,8 @@ static bool release_cmd(JCR *jcr)
          } else if (dev->is_busy()) {
             send_dir_busy_message(dir, dev);
          } else {                     /* device not being used */
-            Dmsg0(90, "Device not in use, releaseing\n");
-            unload_autochanger(dcr, -1);
-            release_volume(dcr);
+            Dmsg0(90, "Device not in use, releasing\n");
+            dcr->release_volume();
             dir->fsend(_("3022 Device %s released.\n"), 
                dev->print_name());
          }
@@ -933,6 +937,10 @@ static bool release_cmd(JCR *jcr)
 
 static bool bootstrap_cmd(JCR *jcr)
 {
+   /* If getting the bootstrap file succeeds, we do not need
+    *  the FD because we will be reading.
+    */
+   jcr->need_fd = false;
    return get_bootstrap_file(jcr, jcr->dir_bsock);
 }