From 3d74eaa7b0160597d25287983cdb0fcbc5ab02b2 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 22 Oct 2005 15:22:54 +0000 Subject: [PATCH] Insure that all the SD tools init the Autochanger resources. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2476 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kes-1.37 | 5 ++++ bacula/src/stored/autochanger.c | 51 +++++++++++++++++++++++++++++++++ bacula/src/stored/butil.c | 2 ++ bacula/src/stored/protos.h | 1 + bacula/src/stored/stored.c | 43 +-------------------------- bacula/src/version.h | 2 +- 6 files changed, 61 insertions(+), 43 deletions(-) diff --git a/bacula/kes-1.37 b/bacula/kes-1.37 index 010f5dc939..2e653e8010 100644 --- a/bacula/kes-1.37 +++ b/bacula/kes-1.37 @@ -3,6 +3,11 @@ General: +Changes to 1.37.42: +22Oct05 +- Insure that all the SD tools init the Autochanger + resources. + Changes to 1.37.41: 22Oct05 - Print error message if no Changer Command found. diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index a1e49d1805..dafae5f749 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -29,6 +29,57 @@ static void lock_changer(DCR *dcr); static void unlock_changer(DCR *dcr); static bool unload_other_drive(DCR *dcr, int slot); +/* Init all the autochanger resources found */ +bool init_autochangers() +{ + bool OK = true; + AUTOCHANGER *changer; + /* Ensure that the media_type for each device is the same */ + foreach_res(changer, R_AUTOCHANGER) { + DEVRES *device; + char *media_type = NULL; + foreach_alist(device, changer->device) { + /* + * If the device does not have a changer name or changer command + * defined, used the one from the Autochanger resource + */ + if (!device->changer_name && changer->changer_name) { + device->changer_name = bstrdup(changer->changer_name); + } + if (!device->changer_command && changer->changer_command) { + device->changer_command = bstrdup(changer->changer_command); + } + if (!device->changer_name) { + Jmsg(NULL, M_ERROR, 0, + _("No Changer Name given for device %s. Cannot continue.\n"), + device->hdr.name); + OK = false; + } + if (!device->changer_command) { + Jmsg(NULL, M_ERROR, 0, + _("No Changer Command given for device %s. Cannot continue.\n"), + device->hdr.name); + OK = false; + } + + if (media_type == NULL) { + media_type = device->media_type; /* get Media Type of first device */ + continue; + } + /* Ensure that other devices Media Types are the same */ + if (strcmp(media_type, device->media_type) != 0) { + Jmsg(NULL, M_ERROR, 0, + _("Media Type not the same for all devices in changer %s. Cannot continue.\n"), + changer->hdr.name); + OK = false; + continue; + } + } + } + return OK; +} + + /* * Called here to do an autoload using the autochanger, if * configured, and if a Slot has been defined for this Volume. diff --git a/bacula/src/stored/butil.c b/bacula/src/stored/butil.c index 37de885283..92923e03e6 100644 --- a/bacula/src/stored/butil.c +++ b/bacula/src/stored/butil.c @@ -92,6 +92,8 @@ JCR *setup_jcr(const char *name, char *dev_name, BSR *bsr, jcr->fileset_md5 = get_pool_memory(PM_FNAME); pm_strcpy(jcr->fileset_md5, "Dummy.fileset.md5"); + init_autochangers(); + dcr = setup_to_access_device(jcr, dev_name, VolumeName, mode); if (!dcr) { return NULL; diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 99b5fe4f95..2dc535451e 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -49,6 +49,7 @@ int authenticate_director(JCR *jcr); int authenticate_filed(JCR *jcr); /* From autochanger.c */ +bool init_autochangers(); int autoload_device(DCR *dcr, int writing, BSOCK *dir); bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd); bool unload_autochanger(DCR *dcr, int loaded); diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index cc600569bd..11f31b2209 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -258,7 +258,6 @@ uint32_t newVolSessionId() static int check_resources() { bool OK = true; - AUTOCHANGER *changer; me = (STORES *)GetNextRes(R_STORAGE, NULL); @@ -397,48 +396,8 @@ static int check_resources() } } - /* Ensure that the media_type for each device is the same */ - foreach_res(changer, R_AUTOCHANGER) { - DEVRES *device; - char *media_type = NULL; - foreach_alist(device, changer->device) { - /* - * If the device does not have a changer name or changer command - * defined, used the one from the Autochanger resource - */ - if (!device->changer_name && changer->changer_name) { - device->changer_name = bstrdup(changer->changer_name); - } - if (!device->changer_command && changer->changer_command) { - device->changer_command = bstrdup(changer->changer_command); - } - if (!device->changer_name) { - Jmsg(NULL, M_ERROR, 0, - _("No Changer Name given for device %s. Cannot continue.\n"), - device->hdr.name); - OK = false; - } - if (!device->changer_command) { - Jmsg(NULL, M_ERROR, 0, - _("No Changer Command given for device %s. Cannot continue.\n"), - device->hdr.name); - OK = false; - } + OK = init_autochangers(); - if (media_type == NULL) { - media_type = device->media_type; /* get Media Type of first device */ - continue; - } - /* Ensure that other devices Media Types are the same */ - if (strcmp(media_type, device->media_type) != 0) { - Jmsg(NULL, M_ERROR, 0, - _("Media Type not the same for all devices in changer %s. Cannot continue.\n"), - changer->hdr.name); - OK = false; - continue; - } - } - } if (OK) { close_msg(NULL); /* close temp message handler */ diff --git a/bacula/src/version.h b/bacula/src/version.h index 2fc06ed30f..083dde788d 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -3,7 +3,7 @@ */ #undef VERSION -#define VERSION "1.37.41" +#define VERSION "1.37.42" #define BDATE "22 October 2005" #define LSMDATE "22Oct05" -- 2.39.2