From 20ea6e850c589bc5deb55a6de373ba1c3b5d6eb5 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 4 Apr 2005 18:37:37 +0000 Subject: [PATCH] - Increase the index width of Filename and Path entries to 255 chars -- suggestion of Meno Abels. - Change remaining VARCHARS to TINYBLOBs. - Remove recursion from is_volume_selected() following bug report from Peter. - Implement mostly correct handling of use_storage in the SD with full lists, ... git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1909 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 1 + bacula/src/cats/make_mysql_tables.in | 16 +- bacula/src/dird/bsr.c | 226 +++++++++++++------------ bacula/src/stored/job.c | 236 +++++++++++++++------------ bacula/src/version.h | 4 +- 5 files changed, 261 insertions(+), 222 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index 63f5012697..99babf5fed 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -61,6 +61,7 @@ For 1.37: - Make sure that Python has access to Client address/port so that it can check if Clients are alive. - Implement copies and stripes. +- Add history file to console. Maybe in 1.37: - By the way: on page http://www.bacula.org/?page=tapedrives , at the diff --git a/bacula/src/cats/make_mysql_tables.in b/bacula/src/cats/make_mysql_tables.in index 19e898c037..822b851f72 100644 --- a/bacula/src/cats/make_mysql_tables.in +++ b/bacula/src/cats/make_mysql_tables.in @@ -6,18 +6,24 @@ bindir=@SQL_BINDIR@ if $bindir/mysql $* -f <next) { int32_t findex, findex2; if ((fi->findex >= FirstIndex && fi->findex <= LastIndex) || - (fi->findex2 >= FirstIndex && fi->findex2 <= LastIndex) || - (fi->findex < FirstIndex && fi->findex2 > LastIndex)) { - findex = fi->findex < FirstIndex ? FirstIndex : fi->findex; - findex2 = fi->findex2 > LastIndex ? LastIndex : fi->findex2; - if (findex == findex2) { + (fi->findex2 >= FirstIndex && fi->findex2 <= LastIndex) || + (fi->findex < FirstIndex && fi->findex2 > LastIndex)) { + findex = fi->findex < FirstIndex ? FirstIndex : fi->findex; + findex2 = fi->findex2 > LastIndex ? LastIndex : fi->findex2; + if (findex == findex2) { fprintf(fd, "FileIndex=%d\n", findex); - count++; - } else { + count++; + } else { fprintf(fd, "FileIndex=%d-%d\n", findex, findex2); - count += findex2 - findex + 1; - } + count += findex2 - findex + 1; + } } } return count; @@ -95,15 +95,14 @@ static uint32_t write_findex(UAContext *ua, RBSR_FINDEX *fi, * falls within the range of selected files in the bsr. */ static bool is_volume_selected(RBSR_FINDEX *fi, - int32_t FirstIndex, int32_t LastIndex) + int32_t FirstIndex, int32_t LastIndex) { - if (fi) { + for ( ; fi; fi=fi->next) { if ((fi->findex >= FirstIndex && fi->findex <= LastIndex) || - (fi->findex2 >= FirstIndex && fi->findex2 <= LastIndex) || - (fi->findex < FirstIndex && fi->findex2 > LastIndex)) { - return true; + (fi->findex2 >= FirstIndex && fi->findex2 <= LastIndex) || + (fi->findex < FirstIndex && fi->findex2 > LastIndex)) { + return true; } - return is_volume_selected(fi->next, FirstIndex, LastIndex); } return false; } @@ -138,7 +137,7 @@ void free_bsr(RBSR *bsr) if (bsr) { free_findex(bsr->fi); if (bsr->VolParams) { - free(bsr->VolParams); + free(bsr->VolParams); } free_bsr(bsr->next); free(bsr); @@ -157,18 +156,18 @@ int complete_bsr(UAContext *ua, RBSR *bsr) jr.JobId = bsr->JobId; if (!db_get_job_record(ua->jcr, ua->db, &jr)) { bsendmsg(ua, _("Unable to get Job record. ERR=%s\n"), db_strerror(ua->db)); - return 0; + return 0; } bsr->VolSessionId = jr.VolSessionId; bsr->VolSessionTime = jr.VolSessionTime; if ((bsr->VolCount=db_get_job_volume_parameters(ua->jcr, ua->db, bsr->JobId, - &(bsr->VolParams))) == 0) { + &(bsr->VolParams))) == 0) { bsendmsg(ua, _("Unable to get Job Volume Parameters. ERR=%s\n"), db_strerror(ua->db)); - if (bsr->VolParams) { - free(bsr->VolParams); - bsr->VolParams = NULL; - } - return 0; + if (bsr->VolParams) { + free(bsr->VolParams); + bsr->VolParams = NULL; + } + return 0; } return complete_bsr(ua, bsr->next); } @@ -190,7 +189,7 @@ uint32_t write_bsr_file(UAContext *ua, RBSR *bsr) if (!fd) { berrno be; bsendmsg(ua, _("Unable to create bootstrap file %s. ERR=%s\n"), - fname, be.strerror()); + fname, be.strerror()); goto bail_out; } /* Write them to file */ @@ -213,9 +212,9 @@ uint32_t write_bsr_file(UAContext *ua, RBSR *bsr) start_prompt(ua, ""); for (RBSR *nbsr=bsr; nbsr; nbsr=nbsr->next) { for (int i=0; i < nbsr->VolCount; i++) { - if (nbsr->VolParams[i].VolumeName[0]) { - add_prompt(ua, nbsr->VolParams[i].VolumeName); - } + if (nbsr->VolParams[i].VolumeName[0]) { + add_prompt(ua, nbsr->VolParams[i].VolumeName); + } } } for (int i=0; i < ua->num_prompts; i++) { @@ -246,45 +245,45 @@ static uint32_t write_bsr(UAContext *ua, RBSR *bsr, FILE *fd) * VolCount is the number of JobMedia records. */ for (int i=0; i < bsr->VolCount; i++) { - if (!is_volume_selected(bsr->fi, bsr->VolParams[i].FirstIndex, - bsr->VolParams[i].LastIndex)) { - bsr->VolParams[i].VolumeName[0] = 0; /* zap VolumeName */ - continue; - } + if (!is_volume_selected(bsr->fi, bsr->VolParams[i].FirstIndex, + bsr->VolParams[i].LastIndex)) { + bsr->VolParams[i].VolumeName[0] = 0; /* zap VolumeName */ + continue; + } fprintf(fd, "Volume=\"%s\"\n", bsr->VolParams[i].VolumeName); fprintf(fd, "MediaType=\"%s\"\n", bsr->VolParams[i].MediaType); fprintf(fd, "VolSessionId=%u\n", bsr->VolSessionId); fprintf(fd, "VolSessionTime=%u\n", bsr->VolSessionTime); - if (bsr->VolParams[i].StartFile == bsr->VolParams[i].EndFile) { + if (bsr->VolParams[i].StartFile == bsr->VolParams[i].EndFile) { fprintf(fd, "VolFile=%u\n", bsr->VolParams[i].StartFile); - } else { + } else { fprintf(fd, "VolFile=%u-%u\n", bsr->VolParams[i].StartFile, - bsr->VolParams[i].EndFile); - } - if (bsr->VolParams[i].StartBlock == bsr->VolParams[i].EndBlock) { + bsr->VolParams[i].EndFile); + } + if (bsr->VolParams[i].StartBlock == bsr->VolParams[i].EndBlock) { fprintf(fd, "VolFile=%u\n", bsr->VolParams[i].StartBlock); - } else { + } else { fprintf(fd, "VolBlock=%u-%u\n", bsr->VolParams[i].StartBlock, - bsr->VolParams[i].EndBlock); - } + bsr->VolParams[i].EndBlock); + } // Dmsg2(100, "bsr VolParam FI=%u LI=%u\n", -// bsr->VolParams[i].FirstIndex, bsr->VolParams[i].LastIndex); +// bsr->VolParams[i].FirstIndex, bsr->VolParams[i].LastIndex); - count = write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex, - bsr->VolParams[i].LastIndex, fd); - if (count) { + count = write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex, + bsr->VolParams[i].LastIndex, fd); + if (count) { fprintf(fd, "Count=%u\n", count); - } - total_count += count; - /* If the same file is present on two tapes or in two files - * on a tape, it is a continuation, and should not be treated - * twice in the totals. - */ - if (!first && LastIndex == bsr->VolParams[i].FirstIndex) { - total_count--; - } - first = false; - LastIndex = bsr->VolParams[i].LastIndex; + } + total_count += count; + /* If the same file is present on two tapes or in two files + * on a tape, it is a continuation, and should not be treated + * twice in the totals. + */ + if (!first && LastIndex == bsr->VolParams[i].FirstIndex) { + total_count--; + } + first = false; + LastIndex = bsr->VolParams[i].LastIndex; } write_bsr(ua, bsr->next, fd); } @@ -300,10 +299,10 @@ void print_bsr(UAContext *ua, RBSR *bsr) bsendmsg(ua, "VolSessionId=%u\n", bsr->VolSessionId); bsendmsg(ua, "VolSessionTime=%u\n", bsr->VolSessionTime); bsendmsg(ua, "VolFile=%u-%u\n", bsr->VolParams[i].StartFile, - bsr->VolParams[i].EndFile); + bsr->VolParams[i].EndFile); bsendmsg(ua, "VolBlock=%u-%u\n", bsr->VolParams[i].StartBlock, - bsr->VolParams[i].EndBlock); - print_findex(ua, bsr->fi); + bsr->VolParams[i].EndBlock); + print_findex(ua, bsr->fi); } print_bsr(ua, bsr->next); } @@ -323,10 +322,10 @@ void add_findex(RBSR *bsr, uint32_t JobId, int32_t findex) RBSR_FINDEX *fi, *lfi; if (findex == 0) { - return; /* probably a dummy directory */ + return; /* probably a dummy directory */ } - if (bsr->fi == NULL) { /* if no FI add one */ + if (bsr->fi == NULL) { /* if no FI add one */ /* This is the first FileIndex item in the chain */ bsr->fi = new_findex(); bsr->JobId = JobId; @@ -337,22 +336,22 @@ void add_findex(RBSR *bsr, uint32_t JobId, int32_t findex) /* Walk down list of bsrs until we find the JobId */ if (bsr->JobId != JobId) { for (nbsr=bsr->next; nbsr; nbsr=nbsr->next) { - if (nbsr->JobId == JobId) { - bsr = nbsr; - break; - } + if (nbsr->JobId == JobId) { + bsr = nbsr; + break; + } } - if (!nbsr) { /* Must add new JobId */ - /* Add new JobId at end of chain */ - for (nbsr=bsr; nbsr->next; nbsr=nbsr->next) - { } - nbsr->next = new_bsr(); - nbsr->next->JobId = JobId; - nbsr->next->fi = new_findex(); - nbsr->next->fi->findex = findex; - nbsr->next->fi->findex2 = findex; - return; + if (!nbsr) { /* Must add new JobId */ + /* Add new JobId at end of chain */ + for (nbsr=bsr; nbsr->next; nbsr=nbsr->next) + { } + nbsr->next = new_bsr(); + nbsr->next->JobId = JobId; + nbsr->next->fi = new_findex(); + nbsr->next->fi->findex = findex; + nbsr->next->fi->findex2 = findex; + return; } } @@ -364,10 +363,10 @@ void add_findex(RBSR *bsr, uint32_t JobId, int32_t findex) /* Check if this findex is smaller than first item */ if (findex < fi->findex) { if ((findex+1) == fi->findex) { - fi->findex = findex; /* extend down */ - return; + fi->findex = findex; /* extend down */ + return; } - fi = new_findex(); /* yes, insert before first item */ + fi = new_findex(); /* yes, insert before first item */ fi->findex = findex; fi->findex2 = findex; fi->next = lfi; @@ -377,26 +376,26 @@ void add_findex(RBSR *bsr, uint32_t JobId, int32_t findex) /* Walk down fi chain and find where to insert insert new FileIndex */ for ( ; fi; fi=fi->next) { if (findex == (fi->findex2 + 1)) { /* extend up */ - RBSR_FINDEX *nfi; - fi->findex2 = findex; - /* - * If the following record contains one higher, merge its - * file index by extending it up. - */ - if (fi->next && ((findex+1) == fi->next->findex)) { - nfi = fi->next; - fi->findex2 = nfi->findex2; - fi->next = nfi->next; - free(nfi); - } - return; + RBSR_FINDEX *nfi; + fi->findex2 = findex; + /* + * If the following record contains one higher, merge its + * file index by extending it up. + */ + if (fi->next && ((findex+1) == fi->next->findex)) { + nfi = fi->next; + fi->findex2 = nfi->findex2; + fi->next = nfi->next; + free(nfi); + } + return; } if (findex < fi->findex) { /* add before */ - if ((findex+1) == fi->findex) { - fi->findex = findex; - return; - } - break; + if ((findex+1) == fi->findex) { + fi->findex = findex; + return; + } + break; } lfi = fi; } @@ -419,7 +418,7 @@ void add_findex_all(RBSR *bsr, uint32_t JobId) RBSR *nbsr; RBSR_FINDEX *fi; - if (bsr->fi == NULL) { /* if no FI add one */ + if (bsr->fi == NULL) { /* if no FI add one */ /* This is the first FileIndex item in the chain */ bsr->fi = new_findex(); bsr->JobId = JobId; @@ -430,22 +429,22 @@ void add_findex_all(RBSR *bsr, uint32_t JobId) /* Walk down list of bsrs until we find the JobId */ if (bsr->JobId != JobId) { for (nbsr=bsr->next; nbsr; nbsr=nbsr->next) { - if (nbsr->JobId == JobId) { - bsr = nbsr; - break; - } + if (nbsr->JobId == JobId) { + bsr = nbsr; + break; + } } - if (!nbsr) { /* Must add new JobId */ - /* Add new JobId at end of chain */ - for (nbsr=bsr; nbsr->next; nbsr=nbsr->next) - { } - nbsr->next = new_bsr(); - nbsr->next->JobId = JobId; - nbsr->next->fi = new_findex(); - nbsr->next->fi->findex = 1; - nbsr->next->fi->findex2 = INT32_MAX; - return; + if (!nbsr) { /* Must add new JobId */ + /* Add new JobId at end of chain */ + for (nbsr=bsr; nbsr->next; nbsr=nbsr->next) + { } + nbsr->next = new_bsr(); + nbsr->next->JobId = JobId; + nbsr->next->fi = new_findex(); + nbsr->next->fi->findex = 1; + nbsr->next->fi->findex2 = INT32_MAX; + return; } } @@ -458,4 +457,3 @@ void add_findex_all(RBSR *bsr, uint32_t JobId) fi->findex2 = INT32_MAX; return; } - diff --git a/bacula/src/stored/job.c b/bacula/src/stored/job.c index 404970bb2a..2e161f3406 100644 --- a/bacula/src/stored/job.c +++ b/bacula/src/stored/job.c @@ -270,10 +270,6 @@ public: char pool_type[MAX_NAME_LENGTH]; }; -class DIRDEVICE { - alist *device; -}; - static bool use_storage_cmd(JCR *jcr) { POOL_MEM store_name, dev_name, media_type, pool_name, pool_type; @@ -281,120 +277,96 @@ static bool use_storage_cmd(JCR *jcr) DEVRES *device; AUTOCHANGER *changer; int append; - bool ok; + bool ok; int Copy, Stripe; + alist *dirstore; + DIRSTORE *store; + char *device_name; /* * If there are multiple devices, the director sends us * use_device for each device that it wants to use. */ Dmsg1(100, "msg); - ok = sscanf(dir->msg, use_storage, store_name.c_str(), - media_type.c_str(), pool_name.c_str(), - pool_type.c_str(), &append, &Copy, &Stripe) == 7; - if (ok) { + dirstore = New(alist(10, not_owned_by_alist)); + do { + ok = sscanf(dir->msg, use_storage, store_name.c_str(), + media_type.c_str(), pool_name.c_str(), + pool_type.c_str(), &append, &Copy, &Stripe) == 7; + if (!ok) { + break; + } unbash_spaces(store_name); unbash_spaces(media_type); unbash_spaces(pool_name); unbash_spaces(pool_type); - if (bnet_recv(dir) <= 0) { - return false; - } - ok = sscanf(dir->msg, use_device, dev_name.c_str()) == 1; - if (!ok) { - return false; - } - /* Eat to BNET_EOD -- end of Devices */ - while (bnet_recv(dir) > 0) { - } - /* Eat to end of Devices */ - while (bnet_recv(dir) > 0) { - } - LockRes(); - foreach_res(device, R_DEVICE) { - /* Find resource, and make sure we were able to open it */ - if (fnmatch(dev_name.c_str(), device->hdr.name, 0) == 0 && - strcmp(device->media_type, media_type.c_str()) == 0) { - const int name_len = MAX_NAME_LENGTH; - DCR *dcr; - UnlockRes(); - if (!device->dev) { - device->dev = init_dev(jcr, NULL, device); - } - if (!device->dev) { - Jmsg(jcr, M_WARNING, 0, _("\n" - " Device \"%s\" requested by DIR could not be opened or does not exist.\n"), - dev_name.c_str()); - bnet_fsend(dir, NOT_open, dev_name.c_str()); - Dmsg1(100, ">dird: %s\n", dir->msg); - return false; - } - dcr = new_dcr(jcr, device->dev); - if (!dcr) { - bnet_fsend(dir, _("3926 Could not get dcr for device: %s\n"), dev_name.c_str()); - Dmsg1(100, ">dird: %s\n", dir->msg); - return false; - } - Dmsg1(100, "Found device %s\n", device->hdr.name); - bstrncpy(dcr->pool_name, pool_name, name_len); - bstrncpy(dcr->pool_type, pool_type, name_len); - bstrncpy(dcr->media_type, media_type, name_len); - bstrncpy(dcr->dev_name, dev_name, name_len); - dcr->Copy = Copy; - dcr->Stripe = Stripe; - jcr->dcr = dcr; - if (append == SD_APPEND) { - ok = reserve_device_for_append(dcr); - } else { - ok = reserve_device_for_read(dcr); - } - if (!ok) { - bnet_fsend(dir, _("3927 Could not reserve device: %s\n"), dev_name.c_str()); - Dmsg1(100, ">dird: %s\n", dir->msg); - free_dcr(jcr->dcr); - return false; - } - Dmsg1(220, "Got: %s", dir->msg); - bash_spaces(dev_name); - ok = bnet_fsend(dir, OK_device, dev_name.c_str()); - Dmsg1(100, ">dird: %s\n", dir->msg); - return ok; + store = new DIRSTORE; + dirstore->append(store); + memset(store, 0, sizeof(DIRSTORE)); + store->device = New(alist(10)); + bstrncpy(store->name, store_name, sizeof(store->name)); + bstrncpy(store->media_type, media_type, sizeof(store->media_type)); + bstrncpy(store->pool_name, pool_name, sizeof(store->pool_name)); + bstrncpy(store->pool_type, pool_type, sizeof(store->pool_type)); + + /* Now get all devices */ + while (bnet_recv(dir) >= 0) { + ok = sscanf(dir->msg, use_device, dev_name.c_str()) == 1; + if (!ok) { + break; } + unbash_spaces(dev_name); + store->device->append(bstrdup(dev_name.c_str())); + } + } while (ok && bnet_recv(dir) >= 0); + + /* This loop is debug code and can be removed */ + /* ***FIXME*** turn off in production */ + foreach_alist(store, dirstore) { + Dmsg4(100, "Storage=%s media_type=%s pool=%s pool_type=%s\n", + store->name, store->media_type, store->pool_name, + store->pool_type); + foreach_alist(device_name, store->device) { + Dmsg1(100, " Device=%s\n", device_name); } + } - foreach_res(changer, R_AUTOCHANGER) { - /* Find resource, and make sure we were able to open it */ - if (fnmatch(dev_name.c_str(), changer->hdr.name, 0) == 0) { - const int name_len = MAX_NAME_LENGTH; - DCR *dcr; - /* Try each device in this AutoChanger */ - foreach_alist(device, changer->device) { - Dmsg1(100, "Try changer device %s\n", device->hdr.name); + + if (ok) { + LockRes(); + store = (DIRSTORE *)dirstore->first(); + foreach_alist(device_name, store->device) { + foreach_res(device, R_DEVICE) { + /* Find resource, and make sure we were able to open it */ + if (fnmatch(device_name, device->hdr.name, 0) == 0 && + strcmp(device->media_type, store->media_type) == 0) { + const int name_len = MAX_NAME_LENGTH; + DCR *dcr; + UnlockRes(); if (!device->dev) { device->dev = init_dev(jcr, NULL, device); } if (!device->dev) { - Dmsg1(100, "Device %s could not be opened. Skipped\n", dev_name.c_str()); Jmsg(jcr, M_WARNING, 0, _("\n" - " Device \"%s\" in changer \"%s\" requested by DIR could not be opened or does not exist.\n"), - device->hdr.name, dev_name.c_str()); - continue; - } - if (!device->dev->autoselect) { - continue; /* device is not available */ - } + " Device \"%s\" requested by DIR could not be opened or does not exist.\n"), + dev_name.c_str()); + bnet_fsend(dir, NOT_open, dev_name.c_str()); + Dmsg1(100, ">dird: %s\n", dir->msg); + return false; + } dcr = new_dcr(jcr, device->dev); if (!dcr) { bnet_fsend(dir, _("3926 Could not get dcr for device: %s\n"), dev_name.c_str()); Dmsg1(100, ">dird: %s\n", dir->msg); - UnlockRes(); return false; } - Dmsg1(100, "Found changer device %s\n", device->hdr.name); - bstrncpy(dcr->pool_name, pool_name, name_len); - bstrncpy(dcr->pool_type, pool_type, name_len); - bstrncpy(dcr->media_type, media_type, name_len); - bstrncpy(dcr->dev_name, dev_name, name_len); + Dmsg1(100, "Found device %s\n", device->hdr.name); + bstrncpy(dcr->pool_name, store->pool_name, name_len); + bstrncpy(dcr->pool_type, store->pool_type, name_len); + bstrncpy(dcr->media_type, store->media_type, name_len); + bstrncpy(dcr->dev_name, device_name, name_len); + dcr->Copy = Copy; + dcr->Stripe = Stripe; jcr->dcr = dcr; if (append == SD_APPEND) { ok = reserve_device_for_append(dcr); @@ -402,19 +374,73 @@ static bool use_storage_cmd(JCR *jcr) ok = reserve_device_for_read(dcr); } if (!ok) { - Jmsg(jcr, M_WARNING, 0, _("Could not reserve device: %s\n"), dev_name.c_str()); + bnet_fsend(dir, _("3927 Could not reserve device: %s\n"), dev_name.c_str()); + Dmsg1(100, ">dird: %s\n", dir->msg); free_dcr(jcr->dcr); - continue; + goto get_out; } - Dmsg1(100, "Device %s opened.\n", dev_name.c_str()); - UnlockRes(); - pm_strcpy(dev_name, device->hdr.name); + Dmsg1(220, "Got: %s", dir->msg); bash_spaces(dev_name); ok = bnet_fsend(dir, OK_device, dev_name.c_str()); Dmsg1(100, ">dird: %s\n", dir->msg); - return ok; + goto get_out; + } + } + foreach_res(changer, R_AUTOCHANGER) { + /* Find resource, and make sure we were able to open it */ + if (fnmatch(device_name, changer->hdr.name, 0) == 0) { + const int name_len = MAX_NAME_LENGTH; + DCR *dcr; + /* Try each device in this AutoChanger */ + foreach_alist(device, changer->device) { + Dmsg1(100, "Try changer device %s\n", device->hdr.name); + if (!device->dev) { + device->dev = init_dev(jcr, NULL, device); + } + if (!device->dev) { + Dmsg1(100, "Device %s could not be opened. Skipped\n", dev_name.c_str()); + Jmsg(jcr, M_WARNING, 0, _("\n" + " Device \"%s\" in changer \"%s\" requested by DIR could not be opened or does not exist.\n"), + device->hdr.name, dev_name.c_str()); + continue; + } + if (!device->dev->autoselect) { + continue; /* device is not available */ + } + dcr = new_dcr(jcr, device->dev); + if (!dcr) { + bnet_fsend(dir, _("3926 Could not get dcr for device: %s\n"), dev_name.c_str()); + Dmsg1(100, ">dird: %s\n", dir->msg); + UnlockRes(); + ok = false; + goto get_out; + } + Dmsg1(100, "Found changer device %s\n", device->hdr.name); + bstrncpy(dcr->pool_name, store->pool_name, name_len); + bstrncpy(dcr->pool_type, store->pool_type, name_len); + bstrncpy(dcr->media_type, store->media_type, name_len); + bstrncpy(dcr->dev_name, device_name, name_len); + jcr->dcr = dcr; + if (append == SD_APPEND) { + ok = reserve_device_for_append(dcr); + } else { + ok = reserve_device_for_read(dcr); + } + if (!ok) { + Jmsg(jcr, M_WARNING, 0, _("Could not reserve device: %s\n"), dev_name.c_str()); + free_dcr(jcr->dcr); + continue; + } + Dmsg1(100, "Device %s opened.\n", device_name); + UnlockRes(); + pm_strcpy(dev_name, device->hdr.name); + bash_spaces(dev_name); + ok = bnet_fsend(dir, OK_device, dev_name.c_str()); + Dmsg1(100, ">dird: %s\n", dir->msg); + goto get_out; + } + break; /* we found it but could not open a device */ } - break; /* we found it but could not open a device */ } } @@ -429,6 +455,7 @@ static bool use_storage_cmd(JCR *jcr) dev_name.c_str(), media_type.c_str()); bnet_fsend(dir, NO_device, dev_name.c_str()); Dmsg1(100, ">dird: %s\n", dir->msg); + ok = false; } else { unbash_spaces(dir->msg); pm_strcpy(jcr->errmsg, dir->msg); @@ -438,9 +465,16 @@ static bool use_storage_cmd(JCR *jcr) Jmsg(jcr, M_FATAL, 0, _("Bad Use Device command: %s\n"), jcr->errmsg); bnet_fsend(dir, BAD_use, jcr->errmsg); Dmsg1(100, ">dird: %s\n", dir->msg); + ok = false; } - return false; /* ERROR return */ +get_out: + foreach_alist(store, dirstore) { + delete store->device; + delete store; + } + delete dirstore; + return ok; } #ifdef needed diff --git a/bacula/src/version.h b/bacula/src/version.h index 725330d613..be98752e57 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #undef VERSION #define VERSION "1.37.12" -#define BDATE "02 April 2005" -#define LSMDATE "02Apr05" +#define BDATE "04 April 2005" +#define LSMDATE "04Apr05" /* Debug flags */ #undef DEBUG -- 2.39.5