]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/ua_label.c
03Dec05
[bacula/bacula] / bacula / src / dird / ua_label.c
index 00889c90acdae2044ee615f388325cbed92dcab9..a0bdd945adf229792a8302c377881804c06ce6d6 100644 (file)
@@ -135,7 +135,7 @@ static bool get_user_slot_list(UAContext *ua, char *slot_list, int num_slots)
    Dmsg0(100, "Slots turned on:\n");
    for (i=1; i <= num_slots; i++) {
       if (slot_list[i]) {
-         Dmsg1(000, "%d\n", i);
+         Dmsg1(100, "%d\n", i);
       }
    }
    return true;
@@ -165,8 +165,8 @@ int update_slots(UAContext *ua)
    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;
 
@@ -191,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;
       }
@@ -210,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;
       }
@@ -245,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);
    }
@@ -309,8 +309,8 @@ static int do_label(UAContext *ua, const char *cmd, int relabel)
    if (!store) {
       return 1;
    }
-   drive = get_storage_drive(ua, store);
    set_storage(ua->jcr, store);
+   drive = get_storage_drive(ua, store);
 
    if (label_barcodes) {
       label_from_barcodes(ua, drive);
@@ -535,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));
             }
@@ -659,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;
@@ -667,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);
@@ -878,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) {
@@ -893,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;
+}
+
+
 
 
 /*