From f5057f404d6531ad567e8d449b56922835635d8a Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 30 Apr 2012 21:12:32 +0200 Subject: [PATCH] Ensure that StorageId is updated after write --- bacula/src/dird/catreq.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/bacula/src/dird/catreq.c b/bacula/src/dird/catreq.c index 7d7b4d197f..e193bff464 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -275,6 +275,20 @@ void catalog_request(JCR *jcr, BSOCK *bs) mr.LastWritten = VolLastWritten; } + /* + * 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 && sdmr.VolWrites > mr.VolWrites) { + Dmsg2(050, "Update StorageId old=%d new=%d\n", + mr.StorageId, jcr->wstore->StorageId); + /* Update StorageId after write */ + set_storageid_in_mr(jcr->wstore, &mr); + } else { + /* Nothing written, reset same StorageId */ + set_storageid_in_mr(NULL, &mr); + } /* Copy updated values to original media record */ mr.VolJobs = sdmr.VolJobs; @@ -295,26 +309,6 @@ void catalog_request(JCR *jcr, BSOCK *bs) mr.VolWriteTime = sdmr.VolWriteTime; } - /* - * 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) { - Dmsg2(050, "Update StorageId old=%d new=%d\n", - mr.StorageId, jcr->wstore->StorageId); - if (jcr->wstore->StorageId == 0) { - Jmsg(jcr, M_ERROR, 0, _("Attempt to set StorageId to zero.\n")); - db_unlock(jcr->db); - return; - } else { - set_storageid_in_mr(jcr->wstore, &mr); - } - } else { - /* ***FIXME*** is this correct? */ - set_storageid_in_mr(NULL, &mr); - } - Dmsg2(400, "db_update_media_record. Stat=%s Vol=%s\n", mr.VolStatus, mr.VolumeName); /* * Update the database, then before sending the response to the -- 2.39.5