From 0ea83336db0dddef48863d3c83a18350de337f77 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 26 Aug 2008 13:14:38 +0000 Subject: [PATCH] Attempt to fix bug #1128 InChanger flag cleared during Migration job when reading from one autochanger and writing to another. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/branches/Branch-2.4@7508 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/patches/2.4.2-inchanger.patch | 100 +++++++++++++++++++++++++++ bacula/src/cats/sql_update.c | 5 +- bacula/src/dird/catreq.c | 21 +++--- bacula/src/dird/dird.c | 1 + bacula/src/version.h | 4 +- bacula/technotes-2.4 | 3 + 6 files changed, 121 insertions(+), 13 deletions(-) create mode 100644 bacula/patches/2.4.2-inchanger.patch diff --git a/bacula/patches/2.4.2-inchanger.patch b/bacula/patches/2.4.2-inchanger.patch new file mode 100644 index 0000000000..5b3e566f0a --- /dev/null +++ b/bacula/patches/2.4.2-inchanger.patch @@ -0,0 +1,100 @@ + + Attempt to fix bug #1128 InChanger flag cleared during Migration + job when reading from one autochanger and writing to another. + Testing is needed. + Apply this patch to Bacula version 2.4.2 with: + + cd + patch -p0 <2.4.2-inchanger.patch + ./configure + make + ... + make install + + +Index: src/dird/catreq.c +=================================================================== +--- src/dird/catreq.c (revision 7507) ++++ src/dird/catreq.c (working copy) +@@ -83,7 +83,7 @@ + jcr->MediaId = mr->MediaId; + pm_strcpy(jcr->VolumeName, mr->VolumeName); + bash_spaces(mr->VolumeName); +- stat = bnet_fsend(sd, OK_media, mr->VolumeName, mr->VolJobs, ++ stat = sd->fsend(OK_media, mr->VolumeName, mr->VolJobs, + mr->VolFiles, mr->VolBlocks, edit_uint64(mr->VolBytes, ed1), + mr->VolMounts, mr->VolErrors, mr->VolWrites, + edit_uint64(mr->MaxVolBytes, ed2), +@@ -266,11 +266,22 @@ + } + } + Dmsg2(400, "Update media: BefVolJobs=%u After=%u\n", mr.VolJobs, sdmr.VolJobs); ++ + /* Check if the volume has been written by the job, + * and update the LastWritten field if needed */ + if (mr.VolBlocks != sdmr.VolBlocks) { + mr.LastWritten = sdmr.LastWritten; + } ++ ++ /* ++ * Update to point to the last device used to write the Volume. ++ * However, do so only if we are writing the tape, i.e. ++ * the number of VolWrites has increased. ++ */ ++ if (jcr->wstore && jcr->wstore->StorageId && sdmr.VolWrites > mr.VolWrites) { ++ mr.StorageId = jcr->wstore->StorageId; ++ } ++ + /* Copy updated values to original media record */ + mr.VolJobs = sdmr.VolJobs; + mr.VolFiles = sdmr.VolFiles; +@@ -285,14 +296,6 @@ + mr.VolWriteTime = sdmr.VolWriteTime; + mr.VolParts = sdmr.VolParts; + bstrncpy(mr.VolStatus, sdmr.VolStatus, sizeof(mr.VolStatus)); +- /* +- * Update to point to the last device used to write the Volume. +- * However, do so only if we are writing the tape, i.e. +- * the number of VolBlocks has increased. +- */ +- if (jcr->wstore && jcr->wstore->StorageId && mr.VolBlocks != sdmr.VolBlocks) { +- mr.StorageId = jcr->wstore->StorageId; +- } + + Dmsg2(400, "db_update_media_record. Stat=%s Vol=%s\n", mr.VolStatus, mr.VolumeName); + /* +Index: src/dird/dird.c +=================================================================== +--- src/dird/dird.c (revision 7507) ++++ src/dird/dird.c (working copy) +@@ -914,6 +914,7 @@ + db_create_storage_record(NULL, db, &sr); + store->StorageId = sr.StorageId; /* set storage Id */ + if (!sr.created) { /* if not created, update it */ ++ sr.AutoChanger = store->autochanger; + db_update_storage_record(NULL, db, &sr); + } + +Index: src/cats/sql_update.c +=================================================================== +--- src/cats/sql_update.c (revision 7507) ++++ src/cats/sql_update.c (working copy) +@@ -1,7 +1,7 @@ + /* + 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. +@@ -445,7 +445,8 @@ + db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) + { + char ed1[50], ed2[50]; +- if (mr->InChanger != 0 && mr->Slot != 0) { ++ if (mr->InChanger != 0 && mr->Slot != 0 && mr->StorageId != 0 && ++ mr->MediaId != 0) { + Mmsg(mdb->cmd, "UPDATE Media SET InChanger=0 WHERE " + "Slot=%d AND StorageId=%s AND MediaId!=%s", + mr->Slot, diff --git a/bacula/src/cats/sql_update.c b/bacula/src/cats/sql_update.c index 5b524108d4..d77d025654 100644 --- a/bacula/src/cats/sql_update.c +++ b/bacula/src/cats/sql_update.c @@ -1,7 +1,7 @@ /* 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. @@ -445,7 +445,8 @@ void db_make_inchanger_unique(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr) { char ed1[50], ed2[50]; - if (mr->InChanger != 0 && mr->Slot != 0) { + if (mr->InChanger != 0 && mr->Slot != 0 && mr->StorageId != 0 && + mr->MediaId != 0) { Mmsg(mdb->cmd, "UPDATE Media SET InChanger=0 WHERE " "Slot=%d AND StorageId=%s AND MediaId!=%s", mr->Slot, diff --git a/bacula/src/dird/catreq.c b/bacula/src/dird/catreq.c index 224d5e7e2b..9d2409de95 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -83,7 +83,7 @@ static int send_volume_info_to_storage_daemon(JCR *jcr, BSOCK *sd, MEDIA_DBR *mr jcr->MediaId = mr->MediaId; pm_strcpy(jcr->VolumeName, mr->VolumeName); bash_spaces(mr->VolumeName); - stat = bnet_fsend(sd, OK_media, mr->VolumeName, mr->VolJobs, + stat = sd->fsend(OK_media, mr->VolumeName, mr->VolJobs, mr->VolFiles, mr->VolBlocks, edit_uint64(mr->VolBytes, ed1), mr->VolMounts, mr->VolErrors, mr->VolWrites, edit_uint64(mr->MaxVolBytes, ed2), @@ -266,11 +266,22 @@ void catalog_request(JCR *jcr, BSOCK *bs) } } Dmsg2(400, "Update media: BefVolJobs=%u After=%u\n", mr.VolJobs, sdmr.VolJobs); + /* Check if the volume has been written by the job, * and update the LastWritten field if needed */ if (mr.VolBlocks != sdmr.VolBlocks) { mr.LastWritten = sdmr.LastWritten; } + + /* + * Update to point to the last device used to write the Volume. + * However, do so only if we are writing the tape, i.e. + * the number of VolWrites has increased. + */ + if (jcr->wstore && jcr->wstore->StorageId && sdmr.VolWrites > mr.VolWrites) { + mr.StorageId = jcr->wstore->StorageId; + } + /* Copy updated values to original media record */ mr.VolJobs = sdmr.VolJobs; mr.VolFiles = sdmr.VolFiles; @@ -285,14 +296,6 @@ void catalog_request(JCR *jcr, BSOCK *bs) mr.VolWriteTime = sdmr.VolWriteTime; mr.VolParts = sdmr.VolParts; bstrncpy(mr.VolStatus, sdmr.VolStatus, sizeof(mr.VolStatus)); - /* - * Update to point to the last device used to write the Volume. - * However, do so only if we are writing the tape, i.e. - * the number of VolBlocks has increased. - */ - if (jcr->wstore && jcr->wstore->StorageId && mr.VolBlocks != sdmr.VolBlocks) { - mr.StorageId = jcr->wstore->StorageId; - } Dmsg2(400, "db_update_media_record. Stat=%s Vol=%s\n", mr.VolStatus, mr.VolumeName); /* diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 760c1e5c8d..d7a3d3c4fc 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -914,6 +914,7 @@ static bool check_catalog() db_create_storage_record(NULL, db, &sr); store->StorageId = sr.StorageId; /* set storage Id */ if (!sr.created) { /* if not created, update it */ + sr.AutoChanger = store->autochanger; db_update_storage_record(NULL, db, &sr); } diff --git a/bacula/src/version.h b/bacula/src/version.h index 8e1f368e8a..5355414598 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.4.3" -#define BDATE "24 August 2008" -#define LSMDATE "24Aug08" +#define BDATE "26 August 2008" +#define LSMDATE "26Aug08" #define PROG_COPYRIGHT "Copyright (C) %d-2008 Free Software Foundation Europe e.V.\n" #define BYEAR "2008" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.4 b/bacula/technotes-2.4 index 0f9b6002e8..03bc56b15f 100644 --- a/bacula/technotes-2.4 +++ b/bacula/technotes-2.4 @@ -1,6 +1,9 @@ Technical notes on version 2.4 General: +26Aug08 +kes Attempt to fix bug #1128 InChanger flag cleared during Migration + job when reading from one autochanger and writing to another. 24Aug08 kes Add more information to SD acquire.c INFO messages. kes Fix NULL Volume name error when reading and the drive must -- 2.39.5