From 428481877e2f746c3100af2fe2b7970d340d51b3 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 20 May 2005 09:00:10 +0000 Subject: [PATCH] Unify the reserve_device() for a single device into one subroutine. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2072 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kes-1.37 | 2 + bacula/src/host.h.in | 17 ++---- bacula/src/jcr.h | 1 - bacula/src/stored/job.c | 126 ++++++++++++++++++---------------------- bacula/src/version.h | 4 +- 5 files changed, 68 insertions(+), 82 deletions(-) diff --git a/bacula/kes-1.37 b/bacula/kes-1.37 index 3a1d8f7887..252f4c7cff 100644 --- a/bacula/kes-1.37 +++ b/bacula/kes-1.37 @@ -4,6 +4,8 @@ General: Changes to 1.37.19: +20May05 +- Unify the reserve_device() for a single device into one subroutine. 18May05 - Modify wait during use_device to happen only after all devices have been examined rather than in the reserve_device code. diff --git a/bacula/src/host.h.in b/bacula/src/host.h.in index dfe93bf042..fc4fa56541 100644 --- a/bacula/src/host.h.in +++ b/bacula/src/host.h.in @@ -5,22 +5,17 @@ * */ /* - Copyright (C) 2000-2004 Kern Sibbald and John Walker + Copyright (C) 2000-2005 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as ammended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 8fdc424ff2..0ef096e29b 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -239,7 +239,6 @@ struct JCR { int type; DCR *dcr; /* device context record */ alist *dcrs; /* list of dcrs open */ -// DEVRES *device; /* device resource to use */ POOLMEM *job_name; /* base Job name (not unique) */ POOLMEM *fileset_name; /* FileSet */ POOLMEM *fileset_md5; /* MD5 for FileSet */ diff --git a/bacula/src/stored/job.c b/bacula/src/stored/job.c index 1b01cdc0f5..f2ac8022b9 100644 --- a/bacula/src/stored/job.c +++ b/bacula/src/stored/job.c @@ -267,6 +267,7 @@ public: }; static int search_res_for_device(JCR *jcr, DIRSTORE *store, char *device_name, int append); +static int reserve_device(JCR *jcr, DIRSTORE *store, DEVRES *device, char *device_name, int append); static bool use_storage_cmd(JCR *jcr) { @@ -402,18 +403,13 @@ done: return ok; } -/* - * Returns: 1 -- OK, have DCR - * 0 -- must wait - * -1 -- fatal error - */ static int search_res_for_device(JCR *jcr, DIRSTORE *store, char *device_name, int append) { DEVRES *device; AUTOCHANGER *changer; BSOCK *dir = jcr->dir_bsock; bool ok; - DCR *dcr; + int stat; Dmsg1(100, "Search res for %s\n", device_name); foreach_res(device, R_DEVICE) { @@ -421,36 +417,9 @@ static int search_res_for_device(JCR *jcr, DIRSTORE *store, char *device_name, i /* 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; - 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"), - device_name); - return 0; - } - Dmsg1(100, "Found device %s\n", device->hdr.name); - dcr = new_dcr(jcr, device->dev); - if (!dcr) { - bnet_fsend(dir, _("3926 Could not get dcr for device: %s\n"), device_name); - Dmsg1(100, ">dird: %s\n", dir->msg); - return -1; - } - jcr->dcr = dcr; - 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); - if (append == SD_APPEND) { - ok = reserve_device_for_append(dcr); - } else { - ok = reserve_device_for_read(dcr); - } - if (!ok) { - free_dcr(jcr->dcr); - return 0; + stat = reserve_device(jcr, store, device, device_name, append); + if (stat != 1) { + return stat; } Dmsg1(220, "Got: %s", dir->msg); bash_spaces(device_name); @@ -463,43 +432,14 @@ static int search_res_for_device(JCR *jcr, DIRSTORE *store, char *device_name, i Dmsg1(100, "Try changer res=%s\n", changer->hdr.name); /* 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; /* 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", device_name); - 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, device_name); - 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"), device_name); - Dmsg1(100, ">dird: %s\n", dir->msg); + stat = reserve_device(jcr, store, device, device_name, append); + if (stat == -1) { /* hard error */ return -1; } - 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"), device_name); - free_dcr(jcr->dcr); + if (stat == 0) { /* must wait, try next one */ continue; } POOL_MEM dev_name; @@ -515,6 +455,56 @@ static int search_res_for_device(JCR *jcr, DIRSTORE *store, char *device_name, i return 0; /* nothing found */ } +/* + * Returns: 1 -- OK, have DCR + * 0 -- must wait + * -1 -- fatal error + */ +static int reserve_device(JCR *jcr, DIRSTORE *store, DEVRES *device, char *device_name, int append) +{ + bool ok; + DCR *dcr; + const int name_len = MAX_NAME_LENGTH; + if (!device->dev) { + device->dev = init_dev(jcr, NULL, device); + } + if (!device->dev) { + if (dev_cap(device->dev, CAP_AUTOCHANGER)) { + 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, device_name); + } else { + Jmsg(jcr, M_WARNING, 0, _("\n" + " Device \"%s\" requested by DIR could not be opened or does not exist.\n"), + device_name); + } + return 0; + } + Dmsg1(100, "Found device %s\n", device->hdr.name); + dcr = new_dcr(jcr, device->dev); + if (!dcr) { + BSOCK *dir = jcr->dir_bsock; + bnet_fsend(dir, _("3926 Could not get dcr for device: %s\n"), device_name); + Dmsg1(100, ">dird: %s\n", dir->msg); + return -1; + } + jcr->dcr = dcr; + 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); + if (append == SD_APPEND) { + ok = reserve_device_for_append(dcr); + } else { + ok = reserve_device_for_read(dcr); + } + if (!ok) { + free_dcr(jcr->dcr); + return 0; + } + return 1; +} + #ifdef needed /* diff --git a/bacula/src/version.h b/bacula/src/version.h index 8bf04ac47c..a3d4614df5 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #undef VERSION #define VERSION "1.37.19" -#define BDATE "18 May 2005" -#define LSMDATE "18May05" +#define BDATE "20 May 2005" +#define LSMDATE "20May05" /* Debug flags */ #undef DEBUG -- 2.39.5