From afddb35b2b13ac98dadfe4cc1e0843c16ff17255 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 2 Jan 2008 10:38:00 +0000 Subject: [PATCH] kes Fix exist switch drive SD code to call autochanger to release any old volume. This must be done to keep the autochanger from releasing subsequently newly reserved volumes in doing a close(). kes Fail if attempting to get console input in batch mode. This should help fail RunScript console commands that are incomplete. kes First cut implementing switch_drive() in SD (not actually called). git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6175 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/ua_input.c | 6 +++--- bacula/src/stored/acquire.c | 16 +++++++++++++--- bacula/src/stored/protos.h | 1 + bacula/src/stored/reserve.c | 33 +++++++++++++++++++++++++++++++-- bacula/src/version.h | 8 ++++---- bacula/technotes-2.3 | 7 +++++++ 6 files changed, 59 insertions(+), 12 deletions(-) diff --git a/bacula/src/dird/ua_input.c b/bacula/src/dird/ua_input.c index ea27cae06e..3c9af2500e 100644 --- a/bacula/src/dird/ua_input.c +++ b/bacula/src/dird/ua_input.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2001-2007 Free Software Foundation Europe e.V. + Copyright (C) 2001-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -49,11 +49,11 @@ int get_cmd(UAContext *ua, const char *prompt) int stat; ua->cmd[0] = 0; - if (!sock) { /* No UA */ + if (!sock || ua->batch) { /* No UA or batch mode */ return 0; } sock->fsend("%s", prompt); - sock->signal(BNET_PROMPT); /* request more input */ + sock->signal(BNET_PROMPT); /* request more input */ for ( ;; ) { stat = sock->recv(); if (stat == BNET_SIGNAL) { diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 6320e12d15..cbd7616f30 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -134,9 +134,7 @@ bool acquire_device_for_read(DCR *dcr) bstrncpy(store->pool_type, dcr->pool_type, sizeof(store->pool_type)); store->append = false; rctx.store = store; - dcr->keep_dcr = true; /* do not free the dcr */ - release_device(dcr); - dcr->keep_dcr = false; + clean_device(dcr); /* clean up the dcr */ /* * Search for a new device @@ -597,6 +595,18 @@ bool release_device(DCR *dcr) return ok; } +/* + * Clean up the device for reuse without freeing the memory + */ +bool clean_device(DCR *dcr) +{ + bool ok; + dcr->keep_dcr = true; /* do not free the dcr */ + ok = release_device(dcr); + dcr->keep_dcr = false; + return ok; +} + /* * Create a new Device Control Record and attach * it to the device (if this is a real job). diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index f9e98a243c..0944a5ebaa 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -38,6 +38,7 @@ uint32_t new_VolSessionId(); DCR *acquire_device_for_append(DCR *dcr); bool acquire_device_for_read(DCR *dcr); bool release_device(DCR *dcr); +bool clean_device(DCR *dcr); DCR *new_dcr(JCR *jcr, DCR *dcr, DEVICE *dev); void free_dcr(DCR *dcr); void detach_dcr_from_dev(DCR *dcr); diff --git a/bacula/src/stored/reserve.c b/bacula/src/stored/reserve.c index 4e44a524f0..6911c9ad89 100644 --- a/bacula/src/stored/reserve.c +++ b/bacula/src/stored/reserve.c @@ -331,8 +331,8 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName) goto get_out; /* Volume already on this device */ } else { Dmsg2(dbglvl, "reserve_vol free vol=%s at %p\n", vol->vol_name, vol->vol_name); - vol_list->remove(vol); - free_vol_item(vol); + unload_autochanger(dcr, -1); /* unload the volume */ + free_volume(dev); debug_list_volumes("reserve_vol free"); } } @@ -391,6 +391,35 @@ get_out: return vol; } +/* + * Switch from current device to given device + */ +void switch_device(DCR *dcr, DEVICE *dev) +{ + // lock_reservations(); + DCR save_dcr; + + dev->dlock(); + memcpy(&save_dcr, dcr, sizeof(save_dcr)); + clean_device(dcr); /* clean up the dcr */ + + dcr->dev = dev; /* get new device pointer */ + Jmsg(dcr->jcr, M_INFO, 0, _("Device switch. New device %s chosen.\n"), + dcr->dev->print_name()); + + bstrncpy(dcr->VolumeName, save_dcr.VolumeName, sizeof(dcr->VolumeName)); + bstrncpy(dcr->media_type, save_dcr.media_type, sizeof(dcr->media_type)); + dcr->VolCatInfo.Slot = save_dcr.VolCatInfo.Slot; + bstrncpy(dcr->pool_name, save_dcr.pool_name, sizeof(dcr->pool_name)); + bstrncpy(dcr->pool_type, save_dcr.pool_type, sizeof(dcr->pool_type)); + bstrncpy(dcr->dev_name, save_dcr.dev_name, sizeof(dcr->dev_name)); + + dev->reserved_device++; + dcr->reserved_device = true; + + dev->dunlock(); +} + /* * Search for a Volume name in the Volume list. * diff --git a/bacula/src/version.h b/bacula/src/version.h index 2348c59310..6ad992a29e 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,16 +4,16 @@ #undef VERSION #define VERSION "2.3.8" -#define BDATE "31 December 2007" -#define LSMDATE "31Dec07" +#define BDATE "02 January 2008" +#define LSMDATE "02Jan08" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" -#define BYEAR "2007" /* year for copyright messages in progs */ +#define BYEAR "2008" /* year for copyright messages in progs */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 63fb28a6c2..274ec0a653 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -1,6 +1,13 @@ Technical notes on version 2.3 General: +02Jan08 +kes Fix exist switch drive SD code to call autochanger to release + any old volume. This must be done to keep the autochanger from + releasing subsequently newly reserved volumes in doing a close(). +kes Fail if attempting to get console input in batch mode. This + should help fail RunScript console commands that are incomplete. +kes First cut implementing switch_drive() in SD (not actually called). 31Dec07 kes Implement first cut running console commands in a RunScript. 29Dec07 -- 2.39.5