]> git.sur5r.net Git - bacula/bacula/commitdiff
Work on labeling barcodes
authorKern Sibbald <kern@sibbald.com>
Sat, 5 Apr 2003 22:09:16 +0000 (22:09 +0000)
committerKern Sibbald <kern@sibbald.com>
Sat, 5 Apr 2003 22:09:16 +0000 (22:09 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@422 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/kernstodo
bacula/src/dird/ua_label.c
bacula/src/stored/dircmd.c
bacula/src/stored/job.c
bacula/src/version.h

index 4dca20a714e1e7cc4bd797b276f3dbf032df4ef8..f42b638d5aeb21cad290016ce4ac940de4711b4c 100644 (file)
@@ -20,6 +20,9 @@ Testing to do: (painful)
 - multiple simultaneous Volumes
 
 For 1.30 release:
+delete volume
+Please enter a number between 1 and 3
+Select the Pool (1-3): 
 - Add IP address to authentication failures. Implement M_SECURITY
   message class.
 - Remove kern and kelvin from mysql_grant...
index 42c76522350f0d2a8172ba9fa634e82198f51d6a..3679a3018a69d17d42a48ff0b1657f39360477fa 100644 (file)
@@ -34,6 +34,9 @@
 static int do_label(UAContext *ua, char *cmd, int relabel);
 static void label_from_barcodes(UAContext *ua);
 static int is_legal_volume_name(UAContext *ua, char *name);
+static int send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr, 
+              POOL_DBR *pr, int relabel);
+
 
 /*
  * Label a tape 
@@ -58,13 +61,13 @@ static int do_label(UAContext *ua, char *cmd, int relabel)
 {
    STORE *store;
    BSOCK *sd;
+   sd = ua->jcr->store_bsock;
    char dev_name[MAX_NAME_LENGTH];
    MEDIA_DBR mr, omr;
    POOL_DBR pr;
    int ok = FALSE;
    int mounted = FALSE;
    int i;
-   int slot = 0;
    static char *name_keyword[] = {
       "name",
       NULL};
@@ -151,15 +154,14 @@ checkName:
          if (!get_cmd(ua, _("Enter slot (0 for none): "))) {
            return 1;
         }
-        slot = atoi(ua->cmd);
-        if (slot >= 0) {             /* OK */
+        mr.Slot = atoi(ua->cmd);
+        if (mr.Slot >= 0) {          /* OK */
            break;
         }
          bsendmsg(ua, _("Slot numbers must be positive.\n"));
       }
    }
    strcpy(mr.MediaType, store->media_type);
-   mr.Slot = slot;
 
    /* Must select Pool if not already done */
    if (pr.PoolId == 0) {
@@ -176,57 +178,10 @@ checkName:
       return 1;   
    }
    sd = ua->jcr->store_bsock;
-   strcpy(dev_name, store->dev_name);
-   bash_spaces(dev_name);
-   bash_spaces(mr.VolumeName);
-   bash_spaces(mr.MediaType);
-   bash_spaces(pr.Name);
-   if (relabel) {
-      bash_spaces(omr.VolumeName);
-      bnet_fsend(sd, _("relabel %s OldName=%s NewName=%s PoolName=%s MediaType=%s Slot=%d"), 
-        dev_name, omr.VolumeName, mr.VolumeName, pr.Name, mr.MediaType, mr.Slot);
-      bsendmsg(ua, _("Sending relabel command ...\n"));
-   } else {
-      bnet_fsend(sd, _("label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d"), 
-        dev_name, mr.VolumeName, pr.Name, mr.MediaType, mr.Slot);
-      bsendmsg(ua, _("Sending label command ...\n"));
-   }
-   while (bget_msg(sd, 0) >= 0) {
-      bsendmsg(ua, "%s", sd->msg);
-      if (strncmp(sd->msg, "3000 OK label.", 14) == 0) {
-        ok = TRUE;
-      } else {
-         bsendmsg(ua, _("Label command failed.\n"));
-      }
-   }
-   ua->jcr->store_bsock = NULL;
-   unbash_spaces(dev_name);
-   unbash_spaces(mr.VolumeName);
-   unbash_spaces(mr.MediaType);
-   unbash_spaces(pr.Name);
-   mr.LabelDate = time(NULL);
+
+   ok = send_label_request(ua, &mr, &omr, &pr, relabel);
+
    if (ok) {
-      set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
-      if (db_create_media_record(ua->jcr, ua->db, &mr)) {
-         bsendmsg(ua, _("Media record for Volume \"%s\" successfully created.\n"),
-           mr.VolumeName);
-        if (ua->automount) {
-            bsendmsg(ua, _("Requesting mount %s ...\n"), dev_name);
-           bash_spaces(dev_name);
-            bnet_fsend(sd, "mount %s", dev_name);
-           unbash_spaces(dev_name);
-           while (bnet_recv(sd) >= 0) {
-               bsendmsg(ua, "%s", sd->msg);
-              /* Here we can get
-               *  3001 OK mount. Device=xxx      or
-               *  3001 Mounted Volume vvvv
-               */
-               mounted = strncmp(sd->msg, "3001 ", 5) == 0;
-           }
-        }
-      } else {
-         bsendmsg(ua, "%s", db_strerror(ua->db));
-      }
       if (relabel) {
         if (!db_delete_media_record(ua->jcr, ua->db, &omr)) {
             bsendmsg(ua, _("Delete of Volume \"%s\" failed. ERR=%s"),
@@ -236,6 +191,21 @@ checkName:
               omr.VolumeName);
         }
       }
+      if (ua->automount) {
+        strcpy(dev_name, store->dev_name);
+         bsendmsg(ua, _("Requesting mount %s ...\n"), dev_name);
+        bash_spaces(dev_name);
+         bnet_fsend(sd, "mount %s", dev_name);
+        unbash_spaces(dev_name);
+        while (bnet_recv(sd) >= 0) {
+            bsendmsg(ua, "%s", sd->msg);
+           /* Here we can get
+            *  3001 OK mount. Device=xxx      or
+            *  3001 Mounted Volume vvvv
+            */
+            mounted = strncmp(sd->msg, "3001 ", 5) == 0;
+        }
+      }
    }
    if (!mounted) {
       bsendmsg(ua, _("Do not forget to mount the drive!!!\n"));
@@ -254,9 +224,10 @@ checkName:
 static void label_from_barcodes(UAContext *ua)
 {
    STORE *store = ua->jcr->store;
-   BSOCK *sd;
+   BSOCK *sd = ua->jcr->store_bsock;
    POOL_DBR pr;
    char dev_name[MAX_NAME_LENGTH];
+//   MEDIA_DBR mr, omr;
 
    bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d ...\n"), 
       store->hdr.name, store->address, store->SDport);
@@ -267,7 +238,6 @@ static void label_from_barcodes(UAContext *ua)
 
    strcpy(dev_name, store->dev_name);
    bash_spaces(dev_name);
-   sd = ua->jcr->store_bsock;
    bnet_fsend(sd, _("autochanger list %s \n"), dev_name);
    while (bget_msg(sd, 0) >= 0) {
       char *p;
@@ -290,6 +260,17 @@ static void label_from_barcodes(UAContext *ua)
       slot = atoi(sd->msg);
       bsendmsg(ua, "Got slot=%d label: %s\n", slot, p);
    }
+
+#ifdef xxxx
+   memset(&mr, 0, sizeof(mr));
+   strcpy(mr.VolumeName, ua->cmd);
+   if (db_get_media_record(ua->jcr, ua->db, &mr)) {
+       bsendmsg(ua, _("Media record for new Volume \"%s\" already exists.\n"), 
+         mr.VolumeName);
+       continue;
+   }
+#endif
+
    bnet_sig(sd, BNET_TERMINATE);
    bnet_close(sd);
    ua->jcr->store_bsock = NULL;
@@ -323,3 +304,53 @@ static int is_legal_volume_name(UAContext *ua, char *name)
    }
    return 1;
 }
+
+static int send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr, 
+                             POOL_DBR *pr, int relabel)
+{
+   BSOCK *sd;
+   char dev_name[MAX_NAME_LENGTH];
+   int ok = FALSE;
+
+   sd = ua->jcr->store_bsock;
+   strcpy(dev_name, ua->jcr->store->dev_name);
+   bash_spaces(dev_name);
+   bash_spaces(mr->VolumeName);
+   bash_spaces(mr->MediaType);
+   bash_spaces(pr->Name);
+   if (relabel) {
+      bash_spaces(omr->VolumeName);
+      bnet_fsend(sd, _("relabel %s OldName=%s NewName=%s PoolName=%s MediaType=%s Slot=%d"), 
+        dev_name, omr->VolumeName, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot);
+      bsendmsg(ua, _("Sending relabel command ...\n"));
+   } else {
+      bnet_fsend(sd, _("label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d"), 
+        dev_name, mr->VolumeName, pr->Name, mr->MediaType, mr->Slot);
+      bsendmsg(ua, _("Sending label command ...\n"));
+   }
+   while (bget_msg(sd, 0) >= 0) {
+      bsendmsg(ua, "%s", sd->msg);
+      if (strncmp(sd->msg, "3000 OK label.", 14) == 0) {
+        ok = TRUE;
+      } else {
+         bsendmsg(ua, _("Label command failed.\n"));
+      }
+   }
+   ua->jcr->store_bsock = NULL;
+   unbash_spaces(dev_name);
+   unbash_spaces(mr->VolumeName);
+   unbash_spaces(mr->MediaType);
+   unbash_spaces(pr->Name);
+   mr->LabelDate = time(NULL);
+   if (ok) {
+      set_pool_dbr_defaults_in_media_dbr(mr, pr);
+      if (db_create_media_record(ua->jcr, ua->db, mr)) {
+         bsendmsg(ua, _("Media record for Volume \"%s\" successfully created.\n"),
+           mr->VolumeName);
+      } else {
+         bsendmsg(ua, "%s", db_strerror(ua->db));
+        ok = FALSE;
+      }
+   }
+   return ok;
+}
index fdabb03f56bfd5f5f055243b466f6de712a1cc49..8793cac6eec7c1726062c8387494a17c2439f3b4 100644 (file)
@@ -121,13 +121,16 @@ void *connection_request(void *arg)
    char name[MAX_NAME_LENGTH];
 
    if (bnet_recv(bs) <= 0) {
-      Emsg0(M_ERROR, 0, "Connection request failed.\n");
+      Emsg0(M_ERROR, 0, _("Connection request failed.\n"));
       return NULL;
    }
 
    /* 
     * See if this is a File daemon connection
     */
+   if (bs->msglen < 25 || bs->msglen > (int)sizeof(name)) {
+      Emsg1(M_ERROR, 0, _("Invalid Dir connection. Len=%d\n"), bs->msglen);
+   }
    if (sscanf(bs->msg, "Hello Start Job %127s calling\n", name) == 1) {
       handle_filed_connection(bs, name);
       return NULL;
@@ -149,7 +152,6 @@ void *connection_request(void *arg)
    Dmsg0(90, "Message channel init completed.\n");
 
    for (quit=0; !quit;) {
-
       /* Read command */
       if ((bnet_stat = bnet_recv(bs)) <= 0) {
         break;                       /* connection terminated */
@@ -458,13 +460,13 @@ static int read_label(JCR *jcr, DEVICE *dev)
  */
 static int mount_cmd(JCR *jcr)
 {
-   char *dev_name;
+   POOLMEM *dev_name;
    BSOCK *dir = jcr->dir_bsock;
    DEVRES *device;
    DEVICE *dev;
    int found = 0;
 
-   dev_name = (char *) get_memory(dir->msglen);
+   dev_name = get_memory(dir->msglen+1);
    if (sscanf(dir->msg, "mount %s", dev_name) == 1) {
       unbash_spaces(dev_name);
       device = NULL;
@@ -571,7 +573,7 @@ static int mount_cmd(JCR *jcr)
          bnet_fsend(dir, _("3999 Device %s not found\n"), dev_name);
       }
    } else {
-      strcpy(dev_name, dir->msg);
+      pm_strcpy(&dev_name, dir->msg);
       bnet_fsend(dir, _("3906 Error scanning mount command: %s\n"), dev_name);
    }
    free_memory(dev_name);
index 0481e25866401d05399ea9e630f8bf81df3191c6..5b269e5273a8b3d01bfa26cde0882c55f79b406d 100644 (file)
@@ -162,7 +162,7 @@ int job_cmd(JCR *jcr)
     *  expires.
     */
    P(jcr->mutex);
-   for ( ;!job_cancelled(jcr); ) {
+   for ( ;!job_canceled(jcr); ) {
       errstat = pthread_cond_timedwait(&jcr->job_start_wait, &jcr->mutex, &timeout);
       if (errstat == 0 || errstat == ETIMEDOUT) {
         break;
@@ -170,7 +170,7 @@ int job_cmd(JCR *jcr)
    }
    V(jcr->mutex);
 
-   if (jcr->authenticated && !job_cancelled(jcr)) {
+   if (jcr->authenticated && !job_canceled(jcr)) {
       run_job(jcr);                  /* Run the job */
    }
    return 0;
index 9f0bebdde4e15ccd03ea4b146f6c57231f7cca85..5e3db511453f6c0e90d760076bedd9e8bc29fd44 100644 (file)
@@ -1,8 +1,8 @@
 /* */
 #define VERSION "1.30"
 #define VSTRING "1"
-#define BDATE   "04 April 2003"
-#define LSMDATE "04Apr03"
+#define BDATE   "05 April 2003"
+#define LSMDATE "05Apr03"
 
 /* Debug flags */
 #define DEBUG 1