src/dird/ua_label.c
static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
                               POOL_DBR *pr, int relabel, bool media_record_exists,
                               int drive)
{
   BSOCK *sd;
   char dev_name[MAX_NAME_LENGTH];
   bool ok = false;
   uint64_t VolBytes = 0;
   uint64_t VolABytes = 0;
   uint32_t VolType = 0;

   if (!(sd=open_sd_bsock(ua))) {
      return false;
   }
   bstrncpy(dev_name, ua->jcr->wstore->dev_name(), sizeof(dev_name));
   bash_spaces(dev_name);
   bash_spaces(mr->VolumeName);
   bash_spaces(mr->MediaType);
   bash_spaces(pr->Name);
   if (relabel) {
      bash_spaces(omr->VolumeName);
      sd->fsend("relabel %s OldName=%s NewName=%s PoolName=%s "
                     "MediaType=%s Slot=%d drive=%d",
                 dev_name, omr->VolumeName, mr->VolumeName, pr->Name,
                 mr->MediaType, mr->Slot, drive);
      ua->send_msg(_("Sending relabel command from \"%s\" to \"%s\" ...\n"),
         omr->VolumeName, mr->VolumeName);
   } else {
      sd->fsend("label %s VolumeName=%s PoolName=%s MediaType=%s "
                     "Slot=%d drive=%d",
                 dev_name, mr->VolumeName, pr->Name, mr->MediaType,
                 mr->Slot, drive);
      ua->send_msg(_("Sending label command for Volume \"%s\" Slot %d ...\n"),
         mr->VolumeName, mr->Slot);
      Dmsg6(100, "label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d drive=%d\n",
         dev_name, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot, drive);
   }

   while (bget_dirmsg(sd) >= 0) {
      ua->send_msg("%s", sd->msg);
      if (sscanf(sd->msg, "3000 OK label. VolBytes=%llu VolABytes=%lld VolType=%d ",
                 &VolBytes, &VolABytes, &VolType) == 3) {
         ok = true;
         if (media_record_exists) {      /* we update it */
            mr->VolBytes = VolBytes;
            mr->VolABytes = VolABytes;
            mr->VolType = VolType;
            mr->InChanger = mr->Slot > 0;  /* if slot give assume in changer */
            set_storageid_in_mr(ua->jcr->wstore, mr);
            if (!db_update_media_record(ua->jcr, ua->db, mr)) {
               ua->error_msg("%s", db_strerror(ua->db));
               ok = false;
            }
         } else {                        /* create the media record */
            set_pool_dbr_defaults_in_media_dbr(mr, pr);
            mr->VolBytes = VolBytes;
            mr->VolABytes = VolABytes;
            mr->VolType = VolType;
            mr->InChanger = mr->Slot > 0;  /* if slot give assume in changer */
            mr->Enabled = 1;
            set_storageid_in_mr(ua->jcr->wstore, mr);
            if (db_create_media_record(ua->jcr, ua->db, mr)) {
               ua->info_msg(_("Catalog record for Volume \"%s\", Slot %d  successfully created.\n"),
                            mr->VolumeName, mr->Slot);
               /* Update number of volumes in pool */
               pr->NumVols++;
               if (!db_update_pool_record(ua->jcr, ua->db, pr)) {
                  ua->error_msg("%s", db_strerror(ua->db));
               }
            } else {
               ua->error_msg("%s", db_strerror(ua->db));
               ok = false;
            }
         }
      }
   }
   if (!ok) {
      ua->error_msg(_("Label command failed for Volume %s.\n"), mr->VolumeName);
   }
   return ok;
}
/*
 * NOTE! This routine opens the SD socket but leaves it open
 */
NOTE. This routine opens the SD socket but leaves it open
NOTE . This routine opens the SD socket but leaves it open
static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
                               POOL_DBR *pr, int relabel, bool media_record_exists,
                               int drive)
{
   BSOCK *sd;
   char dev_name[MAX_NAME_LENGTH];
   bool ok = false;
   uint64_t VolBytes = 0;
   uint64_t VolABytes = 0;
   uint32_t VolType = 0;
   if (!(sd=open_sd_bsock(ua))) {
      return false;
   }
   bstrncpy(dev_name, ua->jcr->wstore->dev_name(), sizeof(dev_name));
   bash_spaces(dev_name);
   bash_spaces(mr->VolumeName);
   bash_spaces(mr->MediaType);
   bash_spaces(pr->Name);
   if (relabel) {
      bash_spaces(omr->VolumeName);
      sd->fsend("relabel %s OldName=%s NewName=%s PoolName=%s "
                     "MediaType=%s Slot=%d drive=%d",
                 dev_name, omr->VolumeName, mr->VolumeName, pr->Name,
                 mr->MediaType, mr->Slot, drive);
      ua->send_msg(_("Sending relabel command from \"%s\" to \"%s\" ...\n"),
         omr->VolumeName, mr->VolumeName);
   } else {
      sd->fsend("label %s VolumeName=%s PoolName=%s MediaType=%s "
                     "Slot=%d drive=%d",
                 dev_name, mr->VolumeName, pr->Name, mr->MediaType,
                 mr->Slot, drive);
      ua->send_msg(_("Sending label command for Volume \"%s\" Slot %d ...\n"),
         mr->VolumeName, mr->Slot);
      Dmsg6(100, "label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d drive=%d\n",
         dev_name, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot, drive);
   }
   while (bget_dirmsg(sd) >= 0) {
      ua->send_msg("%s", sd->msg);
      if (sscanf(sd->msg, "3000 OK label. VolBytes=%llu VolABytes=%lld VolType=%d ",
                 &VolBytes, &VolABytes, &VolType) == 3) {
         ok = true;
         if (media_record_exists) {      
            mr->VolBytes = VolBytes;
            mr->VolABytes = VolABytes;
            mr->VolType = VolType;
            mr->InChanger = mr->Slot > 0;  
            set_storageid_in_mr(ua->jcr->wstore, mr);
            if (!db_update_media_record(ua->jcr, ua->db, mr)) {
               ua->error_msg("%s", db_strerror(ua->db));
               ok = false;
            }
         } else {                        
            set_pool_dbr_defaults_in_media_dbr(mr, pr);
            mr->VolBytes = VolBytes;
            mr->VolABytes = VolABytes;
            mr->VolType = VolType;
            mr->InChanger = mr->Slot > 0;  
            mr->Enabled = 1;
            set_storageid_in_mr(ua->jcr->wstore, mr);
            if (db_create_media_record(ua->jcr, ua->db, mr)) {
               ua->info_msg(_("Catalog record for Volume \"%s\", Slot %d  successfully created.\n"),
                            mr->VolumeName, mr->Slot);
               pr->NumVols++;
               if (!db_update_pool_record(ua->jcr, ua->db, pr)) {
                  ua->error_msg("%s", db_strerror(ua->db));
               }
            } else {
               ua->error_msg("%s", db_strerror(ua->db));
               ok = false;
            }
         }
      }
   }
   if (!ok) {
      ua->error_msg(_("Label command failed for Volume %s.\n"), mr->VolumeName);
   }
   return ok;
}
static bool send_label_request ( UAContext * ua , MEDIA_DBR * mr , MEDIA_DBR * omr , POOL_DBR * pr , int relabel , bool media_record_exists , int drive ) { BSOCK * sd ; char dev_name [ MAX_NAME_LENGTH ] ; bool ok = false ; uint64_t VolBytes = 0 ; uint64_t VolABytes = 0 ; uint32_t VolType = 0 ; if ( ! ( sd = open_sd_bsock ( ua ) ) ) { return false ; } bstrncpy ( dev_name , ua -> jcr -> wstore -> dev_name ( ) , sizeof ( dev_name ) ) ; bash_spaces ( dev_name ) ; bash_spaces ( mr -> VolumeName ) ; bash_spaces ( mr -> MediaType ) ; bash_spaces ( pr -> Name ) ; if ( relabel ) { bash_spaces ( omr -> VolumeName ) ; sd -> fsend ( " " " " , dev_name , omr -> VolumeName , mr -> VolumeName , pr -> Name , mr -> MediaType , mr -> Slot , drive ) ; ua -> send_msg ( _ ( " \" \" \" \" \n " ) , omr -> VolumeName , mr -> VolumeName ) ; } else { sd -> fsend ( " " " " , dev_name , mr -> VolumeName , pr -> Name , mr -> MediaType , mr -> Slot , drive ) ; ua -> send_msg ( _ ( " \" \" \n " ) , mr -> VolumeName , mr -> Slot ) ; Dmsg6 ( 100 , " \n " , dev_name , mr -> VolumeName , pr -> Name , mr -> MediaType , mr -> Slot , drive ) ; } while ( bget_dirmsg ( sd ) >= 0 ) { ua -> send_msg ( " " , sd -> msg ) ; if ( sscanf ( sd -> msg , " " , & VolBytes , & VolABytes , & VolType ) == 3 ) { ok = true ; if ( media_record_exists ) { mr -> VolBytes = VolBytes ; mr -> VolABytes = VolABytes ; mr -> VolType = VolType ; mr -> InChanger = mr -> Slot > 0 ; set_storageid_in_mr ( ua -> jcr -> wstore , mr ) ; if ( ! db_update_media_record ( ua -> jcr , ua -> db , mr ) ) { ua -> error_msg ( " " , db_strerror ( ua -> db ) ) ; ok = false ; } } else { set_pool_dbr_defaults_in_media_dbr ( mr , pr ) ; mr -> VolBytes = VolBytes ; mr -> VolABytes = VolABytes ; mr -> VolType = VolType ; mr -> InChanger = mr -> Slot > 0 ; mr -> Enabled = 1 ; set_storageid_in_mr ( ua -> jcr -> wstore , mr ) ; if ( db_create_media_record ( ua -> jcr , ua -> db , mr ) ) { ua -> info_msg ( _ ( " \" \" \n " ) , mr -> VolumeName , mr -> Slot ) ; pr -> NumVols ++ ; if ( ! db_update_pool_record ( ua -> jcr , ua -> db , pr ) ) { ua -> error_msg ( " " , db_strerror ( ua -> db ) ) ; } } else { ua -> error_msg ( " " , db_strerror ( ua -> db ) ) ; ok = false ; } } } } if ( ! ok ) { ua -> error_msg ( _ ( " \n " ) , mr -> VolumeName ) ; } return ok ; }
NOTE!
NOTE!
/* we update it */ /* if slot give assume in changer */ /* create the media record */ /* if slot give assume in changer */ /* Update number of volumes in pool */