From: Kern Sibbald Date: Sat, 5 Apr 2003 22:09:16 +0000 (+0000) Subject: Work on labeling barcodes X-Git-Tag: Release-1.30~45 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=404a826f49fdd95f906845d8ed7b5e8a3124b657;p=bacula%2Fbacula Work on labeling barcodes git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@422 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kernstodo b/bacula/kernstodo index 4dca20a714..f42b638d5a 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -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... diff --git a/bacula/src/dird/ua_label.c b/bacula/src/dird/ua_label.c index 42c7652235..3679a3018a 100644 --- a/bacula/src/dird/ua_label.c +++ b/bacula/src/dird/ua_label.c @@ -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; +} diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index fdabb03f56..8793cac6ee 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -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); diff --git a/bacula/src/stored/job.c b/bacula/src/stored/job.c index 0481e25866..5b269e5273 100644 --- a/bacula/src/stored/job.c +++ b/bacula/src/stored/job.c @@ -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; diff --git a/bacula/src/version.h b/bacula/src/version.h index 9f0bebdde4..5e3db51145 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -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