]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_label.c
03Dec05
[bacula/bacula] / bacula / src / dird / ua_label.c
index 60040cdee8d46435c7b97aa7350e13d6421e595b..a0bdd945adf229792a8302c377881804c06ce6d6 100644 (file)
@@ -66,11 +66,12 @@ static bool get_user_slot_list(UAContext *ua, char *slot_list, int num_slots)
    int i;
    const char *msg;
 
+   /* slots are numbered 1 to num_slots */
    for (int i=0; i <= num_slots; i++) {
       slot_list[i] = 0;
    }
    i = find_arg_with_value(ua, "slots");
-   if (i >= 0) {
+   if (i > 0) {
       /* scan slot list in ua->argv[i] */
       char *p, *e, *h;
       int beg, end;
@@ -117,7 +118,7 @@ static bool get_user_slot_list(UAContext *ua, char *slot_list, int num_slots)
             msg = _("Values must be be greater than zero.\n");
             goto bail_out;
          }
-         if (end >= num_slots) {
+         if (end > num_slots) {
             msg = _("Slot too large.\n");
             goto bail_out;
          }
@@ -127,7 +128,7 @@ static bool get_user_slot_list(UAContext *ua, char *slot_list, int num_slots)
       }
    } else {
       /* Turn everything on */
-      for (i=0; i <= num_slots; i++) {
+      for (i=1; i <= num_slots; i++) {
          slot_list[i] = 1;
       }
    }
@@ -160,12 +161,12 @@ int update_slots(UAContext *ua)
    if (!open_db(ua)) {
       return 1;
    }
-   store = get_storage_resource(ua, 1);
+   store = get_storage_resource(ua, true/*arg is storage*/);
    if (!store) {
       return 1;
    }
-   drive = get_storage_drive(ua, store);
    set_storage(ua->jcr, store);
+   drive = get_storage_drive(ua, store);
 
    scan = find_arg(ua, N_("scan")) >= 0;
 
@@ -190,7 +191,7 @@ int update_slots(UAContext *ua)
    /* Walk through the list updating the media records */
    for (vl=vol_list; vl; vl=vl->next) {
       if (vl->Slot > max_slots) {
-         bsendmsg(ua, _("Slot %d larger than max %d ignored.\n"),
+         bsendmsg(ua, _("Slot %d greater than max %d ignored.\n"),
             vl->Slot, max_slots);
          continue;
       }
@@ -209,16 +210,16 @@ int update_slots(UAContext *ua)
          Dmsg2(100, "Got Vol=%s from SD for Slot=%d\n", vl->VolName, vl->Slot);
       }
       slot_list[vl->Slot] = 0;        /* clear Slot */
+      memset(&mr, 0, sizeof(mr));
+      mr.Slot = vl->Slot;
+      mr.InChanger = 1;
+      mr.StorageId = store->StorageId;
+      /* Set InChanger to zero for this Slot */
+      db_lock(ua->db);
+      db_make_inchanger_unique(ua->jcr, ua->db, &mr);
+      db_unlock(ua->db);
       if (!vl->VolName) {
-         Dmsg1(100, "No VolName for Slot=%d setting InChanger to zero.\n", vl->Slot);
-         memset(&mr, 0, sizeof(mr));
-         mr.Slot = vl->Slot;
-         mr.InChanger = 1;
-         mr.StorageId = store->StorageId;
-         /* Set InChanger to zero for this Slot */
-         db_lock(ua->db);
-         db_make_inchanger_unique(ua->jcr, ua->db, &mr);
-         db_unlock(ua->db);
+         Dmsg1(000, "No VolName for Slot=%d setting InChanger to zero.\n", vl->Slot);
          bsendmsg(ua, _("No VolName for Slot=%d set InChanger to zero.\n"), vl->Slot);
          continue;
       }
@@ -244,8 +245,8 @@ int update_slots(UAContext *ua)
          db_unlock(ua->db);
          continue;
       } else {
-         bsendmsg(ua, _("Record for Volume \"%s\" not found in catalog.\n"),
-             mr.VolumeName);
+         bsendmsg(ua, _("Volume \"%s\" not found in catalog. Slot=%d set InChanger to zero.\n"),
+             mr.VolumeName, vl->Slot);
       }
       db_unlock(ua->db);
    }
@@ -283,6 +284,7 @@ static int do_label(UAContext *ua, const char *cmd, int relabel)
    MEDIA_DBR mr, omr;
    POOL_DBR pr;
    bool print_reminder = true;
+   bool label_barcodes = false;
    int ok = FALSE;
    int i;
    int drive;
@@ -297,14 +299,20 @@ static int do_label(UAContext *ua, const char *cmd, int relabel)
    if (!open_db(ua)) {
       return 1;
    }
+
+   if (!relabel && (i=find_arg_keyword(ua, barcode_keyword)) >= 0) {
+      *ua->argk[i] = 0;      /* zap barcode keyword */
+      label_barcodes = true;
+   }
+
    store = get_storage_resource(ua, true/*use default*/);
    if (!store) {
       return 1;
    }
-   drive = get_storage_drive(ua, store);
    set_storage(ua->jcr, store);
+   drive = get_storage_drive(ua, store);
 
-   if (!relabel && find_arg_keyword(ua, barcode_keyword) >= 0) {
+   if (label_barcodes) {
       label_from_barcodes(ua, drive);
       return 1;
    }
@@ -527,6 +535,7 @@ static void label_from_barcodes(UAContext *ua, int drive)
             mr.VolBytes = 1;
             bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus));
             mr.MediaType[0] = 0;
+            mr.StorageId = store->StorageId;
             if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
                 bsendmsg(ua, "%s", db_strerror(ua->db));
             }
@@ -651,6 +660,7 @@ static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
       if (media_record_exists) {      /* we update it */
          mr->VolBytes = 1;
          mr->InChanger = 1;
+         mr->StorageId = ua->jcr->store->StorageId;
          if (!db_update_media_record(ua->jcr, ua->db, mr)) {
              bsendmsg(ua, "%s", db_strerror(ua->db));
              ok = false;
@@ -659,6 +669,7 @@ static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
          set_pool_dbr_defaults_in_media_dbr(mr, pr);
          mr->VolBytes = 1;               /* flag indicating Volume labeled */
          mr->InChanger = 1;
+         mr->StorageId = ua->jcr->store->StorageId;
          if (db_create_media_record(ua->jcr, ua->db, mr)) {
             bsendmsg(ua, _("Catalog record for Volume \"%s\", Slot %d  successfully created.\n"),
             mr->VolumeName, mr->Slot);
@@ -870,8 +881,8 @@ static int get_num_slots_from_SD(UAContext *ua)
 
    bstrncpy(dev_name, store->dev_name(), sizeof(dev_name));
    bash_spaces(dev_name);
-   /* Ask for autochanger list of volumes */
-   bnet_fsend(sd, _("autochanger slots %s \n"), dev_name);
+   /* Ask for autochanger number of slots */
+   bnet_fsend(sd, _("autochanger slots %s\n"), dev_name);
 
    while (bnet_recv(sd) >= 0) {
       if (sscanf(sd->msg, "slots=%d\n", &slots) == 1) {
@@ -885,6 +896,39 @@ static int get_num_slots_from_SD(UAContext *ua)
    return slots;
 }
 
+/*
+ * We get the number of drives in the changer from the SD
+ */
+int get_num_drives_from_SD(UAContext *ua)
+{
+   STORE *store = ua->jcr->store;
+   char dev_name[MAX_NAME_LENGTH];
+   BSOCK *sd;
+   int drives = 0;
+
+
+   if (!(sd=open_sd_bsock(ua))) {
+      return 0;
+   }
+
+   bstrncpy(dev_name, store->dev_name(), sizeof(dev_name));
+   bash_spaces(dev_name);
+   /* Ask for autochanger number of slots */
+   bnet_fsend(sd, _("autochanger drives %s\n"), dev_name);
+
+   while (bnet_recv(sd) >= 0) {
+      if (sscanf(sd->msg, "drives=%d\n", &drives) == 1) {
+         break;
+      } else {
+         bsendmsg(ua, "%s", sd->msg);
+      }
+   }
+   close_sd_bsock(ua);
+//   bsendmsg(ua, _("Device \"%s\" has %d drives.\n"), store->dev_name(), drives);
+   return drives;
+}
+
+
 
 
 /*