]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/dircmd.c
Make btape fill/unfill work
[bacula/bacula] / bacula / src / stored / dircmd.c
index aa0f57f581b3f32c917cec093a8290f533bf003e..433940f7a2f109397b1504365c9231b125322e09 100644 (file)
@@ -59,6 +59,7 @@ static char OKsetdebug[]   = "3000 OK setdebug=%d\n";
 /* Imported functions */
 extern void terminate_child();
 extern int job_cmd(JCR *jcr);
+extern int status_cmd(JCR *sjcr);
 
 /* Forward referenced functions */
 static int label_cmd(JCR *jcr);
@@ -67,13 +68,11 @@ static int setdebug_cmd(JCR *jcr);
 static int cancel_cmd(JCR *cjcr);
 static int mount_cmd(JCR *jcr);
 static int unmount_cmd(JCR *jcr);
-static int status_cmd(JCR *sjcr);
 static int autochanger_cmd(JCR *sjcr);
 static int do_label(JCR *jcr, int relabel);
 static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname,
                               char *newname, char *poolname, 
                               int Slot, int relabel);
-static void send_blocked_status(JCR *jcr, DEVICE *dev);
 
 struct s_cmds {
    char *cmd;
@@ -371,7 +370,7 @@ static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname,
    for ( ; !(dev->state & ST_OPENED); ) {
        if (open_dev(dev, jcr->VolumeName, READ_WRITE) < 0) {
          if (dev->dev_errno == EAGAIN || dev->dev_errno == EBUSY) {
-            sleep(30);
+            bmicrosleep(30, 0);
          }
           bnet_fsend(dir, _("3910 Unable to open device %s. ERR=%s\n"), 
             dev_name(dev), strerror_dev(dev));
@@ -431,11 +430,9 @@ static int read_label(JCR *jcr, DEVICE *dev)
    int stat;
    BSOCK *dir = jcr->dir_bsock;
    DEV_BLOCK *block;
-#ifndef NEW_LOCK
    bsteal_lock_t hold;
    
    steal_device_lock(dev, &hold, BST_DOING_ACQUIRE);
-#endif
    
    jcr->VolumeName[0] = 0;
    block = new_block(dev);
@@ -452,9 +449,7 @@ static int read_label(JCR *jcr, DEVICE *dev)
         break;
    }
    free_block(block);
-#ifndef NEW_LOCK
    return_device_lock(dev, &hold);
-#endif
    return stat;
 }
 
@@ -491,7 +486,8 @@ static int mount_cmd(JCR *jcr)
            DEV_BLOCK *block;
            case BST_WAITING_FOR_SYSOP:
               /* Someone is waiting, wake him */
-               Dmsg0(90, "Waiting for mount attempt to wake thread\n");
+               Dmsg0(100, "Waiting for mount. Attempting to wake thread\n");
+              dev->dev_blocked = BST_MOUNT;
               pthread_cond_signal(&dev->wait_next_vol);
                bnet_fsend(dir, "3001 OK mount. Device=%s\n", dev->dev_name);
               break;
@@ -508,12 +504,12 @@ static int mount_cmd(JCR *jcr)
               read_dev_volume_label(jcr, dev, block);
               free_block(block);
               if (dev->dev_blocked == BST_UNMOUNTED) {
-                  Dmsg0(90, "Unmounted unblocking device\n");
+                  Dmsg0(100, "Unmounted. Unblocking device\n");
                  read_label(jcr, dev);
                  unblock_device(dev);
               } else {
-                  Dmsg0(90, "Unmounted waiting for mount attempt to wake thread\n");
-                 dev->dev_blocked = BST_WAITING_FOR_SYSOP;
+                  Dmsg0(100, "Unmounted waiting for mount. Attempting to wake thread\n");
+                 dev->dev_blocked = BST_MOUNT;
                  pthread_cond_signal(&dev->wait_next_vol);
               }
               if (dev->state & ST_LABEL) {
@@ -669,145 +665,6 @@ static int unmount_cmd(JCR *jcr)
    return 1;
 }
 
-/*
- * Status command from Director
- */
-static int status_cmd(JCR *jcr)
-{
-   DEVRES *device;
-   DEVICE *dev;
-   int found, bps, sec, bpb;
-   BSOCK *user = jcr->dir_bsock;
-   char dt[MAX_TIME_LENGTH];
-   char b1[30], b2[30], b3[30];
-
-   bnet_fsend(user, "\n%s Version: " VERSION " (" BDATE ")\n", my_name);
-   bstrftime(dt, sizeof(dt), daemon_start_time);
-   bnet_fsend(user, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
-        last_job.NumJobs == 1 ? "" : "s");
-   if (last_job.NumJobs > 0) {
-      char termstat[30];
-
-      bstrftime(dt, sizeof(dt), last_job.end_time);
-      bnet_fsend(user, _("Last Job %s finished at %s\n"), last_job.Job, dt);
-
-      jobstatus_to_ascii(last_job.JobStatus, termstat, sizeof(termstat));
-      bnet_fsend(user, _("  Files=%s Bytes=%s Termination Status=%s\n"), 
-          edit_uint64_with_commas(last_job.JobFiles, b1),
-          edit_uint64_with_commas(last_job.JobBytes, b2),
-          termstat);
-   }
-
-   LockRes();
-   for (device=NULL;  (device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device)); ) {
-      for (dev=device->dev; dev; dev=dev->next) {
-        if (dev->state & ST_OPENED) {
-           if (dev->state & ST_LABEL) {
-               bnet_fsend(user, _("Device %s is mounted with Volume \"%s\"\n"), 
-                 dev_name(dev), dev->VolHdr.VolName);
-           } else {
-               bnet_fsend(user, _("Device %s open but no Bacula volume is mounted.\n"), dev_name(dev));
-           }
-           send_blocked_status(jcr, dev);
-           bpb = dev->VolCatInfo.VolCatBlocks;
-           if (bpb <= 0) {
-              bpb = 1;
-           }
-           bpb = dev->VolCatInfo.VolCatBytes / bpb;
-            bnet_fsend(user, _("    Total Bytes=%s Blocks=%s Bytes/block=%s\n"),
-              edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1),
-              edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2), 
-              edit_uint64_with_commas(bpb, b3));
-            bnet_fsend(user, _("    Positioned at File=%s Block=%s\n"), 
-              edit_uint64_with_commas(dev->file, b1),
-              edit_uint64_with_commas(dev->block_num, b2));
-
-        } else {
-            bnet_fsend(user, _("Device %s is not open.\n"), dev_name(dev));
-           send_blocked_status(jcr, dev);
-        }
-      }
-   }
-   UnlockRes();
-
-   found = 0;
-   lock_jcr_chain();
-   /* NOTE, we reuse a calling argument jcr. Be warned! */ 
-   for (jcr=NULL; (jcr=get_next_jcr(jcr)); ) {
-      if (jcr->JobStatus == JS_WaitFD) {
-         bnet_fsend(user, _("%s Job %s waiting for Client connection.\n"),
-           job_type_to_str(jcr->JobType), jcr->Job);
-      }
-      if (jcr->device) {
-         bnet_fsend(user, _("%s %s job %s is using device %s volume %s\n"), 
-                  job_level_to_str(jcr->JobLevel),
-                  job_type_to_str(jcr->JobType),
-                  jcr->Job, jcr->device->device_name,
-                  jcr->VolumeName);
-        sec = time(NULL) - jcr->run_time;
-        if (sec <= 0) {
-           sec = 1;
-        }
-        bps = jcr->JobBytes / sec;
-         bnet_fsend(user, _("    Files=%s Bytes=%s Bytes/sec=%s\n"), 
-           edit_uint64_with_commas(jcr->JobFiles, b1),
-           edit_uint64_with_commas(jcr->JobBytes, b2),
-           edit_uint64_with_commas(bps, b3));
-        found = 1;
-#ifdef DEBUG
-        if (jcr->file_bsock) {
-            bnet_fsend(user, "    FDReadSeqNo=%" lld " fd=%d\n", 
-              jcr->file_bsock->read_seqno, jcr->file_bsock->fd);
-        } else {
-            bnet_fsend(user, "    FDSocket closed\n");
-        }
-#endif
-      }
-      free_locked_jcr(jcr);
-   }
-   unlock_jcr_chain();
-   if (!found) {
-      bnet_fsend(user, _("No jobs running.\n"));
-   }
-
-#ifdef full_status
-   bnet_fsend(user, "\n\n");
-   dump_resource(R_DEVICE, resources[R_DEVICE-r_first].res_head, sendit, user);
-#endif
-   bnet_fsend(user, "====\n");
-
-   bnet_sig(user, BNET_EOD);
-   return 1;
-}
-
-static void send_blocked_status(JCR *jcr, DEVICE *dev) 
-{
-   BSOCK *user = jcr->dir_bsock;
-
-   switch (dev->dev_blocked) {
-      case BST_UNMOUNTED:
-         bnet_fsend(user, _("    Device is BLOCKED. User unmounted.\n"));
-        break;
-      case BST_UNMOUNTED_WAITING_FOR_SYSOP:
-         bnet_fsend(user, _("    Device is BLOCKED. User unmounted during wait for media/mount.\n"));
-        break;
-      case BST_WAITING_FOR_SYSOP:
-        if (jcr->JobStatus == JS_WaitMount) {
-            bnet_fsend(user, _("    Device is BLOCKED waiting for mount.\n"));
-        } else {
-            bnet_fsend(user, _("    Device is BLOCKED waiting for appendable media.\n"));
-        }
-        break;
-      case BST_DOING_ACQUIRE:
-         bnet_fsend(user, _("    Device is being initialized.\n"));
-        break;
-      case BST_WRITING_LABEL:
-         bnet_fsend(user, _("    Device is blocked labeling a Volume.\n"));
-        break;
-      default:
-        break;
-   }
-}
 
 /*
  * Autochanger command from Director