From: Kern Sibbald Date: Thu, 7 Sep 2006 08:47:10 +0000 (+0000) Subject: kes Add a new close_part() class in the SD to save the device X-Git-Tag: Release-2.0.0~493 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=cd531493f0b326baf5d4bc766d6b9502a117a3dc;p=bacula%2Fbacula kes Add a new close_part() class in the SD to save the device state around open/close_part/open for DVD writing. This should fix the num_dvd_parts getting zeroed as reported by Richard Mortimer. kes Apply patch from Richard Mortimer that correct edit code for debug output of st_size. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3424 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index e3bcda034e..b52f92353b 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -1817,6 +1817,30 @@ void DEVICE::close() openmode = 0; } +/* + * This call closes the device, but it is used in DVD handling + * where we close one part and then open the next part. The + * difference between close_part() and close() is that close_part() + * saves the state information of the device (e.g. the Volume lable, + * the Volume Catalog record, ... This permits opening and closing + * the Volume parts multiple times without losing track of what the + * main Volume parameters are. + */ +void DEVICE::close_part(DCR *dcr) +{ + VOLUME_LABEL saveVolHdr; + VOLUME_CAT_INFO saveVolCatInfo; /* Volume Catalog Information */ + + + memcpy(&saveVolHdr, &VolHdr, sizeof(saveVolHdr)); + memcpy(&saveVolCatInfo, &VolCatInfo, sizeof(saveVolCatInfo)); + close(); /* close current part */ + memcpy(&VolHdr, &saveVolHdr, sizeof(VolHdr)); + memcpy(&VolCatInfo, &saveVolCatInfo, sizeof(VolCatInfo)); + memcpy(&dcr->VolCatInfo, &saveVolCatInfo, sizeof(dcr->VolCatInfo)); +} + + bool DEVICE::truncate(DCR *dcr) /* We need the DCR for DVD-writing */ diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index af494d5ecd..3781e7c63b 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -343,6 +343,7 @@ public: void block(int why); /* in dev.c */ void unblock(); /* in dev.c */ void close(); /* in dev.c */ + void close_part(DCR *dcr); /* in dev.c */ bool truncate(DCR *dcr); /* in dev.c */ int open(DCR *dcr, int mode); /* in dev.c */ void term(void); /* in dev.c */ diff --git a/bacula/src/stored/dvd.c b/bacula/src/stored/dvd.c index bfa47a4a0b..bcd360c6c9 100644 --- a/bacula/src/stored/dvd.c +++ b/bacula/src/stored/dvd.c @@ -470,7 +470,6 @@ bool dvd_write_part(DCR *dcr) int dvd_open_next_part(DCR *dcr) { DEVICE *dev = dcr->dev; - VOLUME_LABEL VolHdr; Dmsg6(29, "Enter: == open_next_part part=%d npart=%d dev=%s vol=%s mode=%d file_addr=%d\n", dev->part, dev->num_dvd_parts, dev->print_name(), @@ -487,14 +486,7 @@ int dvd_open_next_part(DCR *dcr) return dev->fd; } - /* - * Note, when we close, the Volume header is zeroed. Since - * we reopen, but are in fact opening the same volume without - * re-reading the Volume header, we simply save and restore it. - */ - memcpy(&VolHdr, &dev->VolHdr, sizeof(VolHdr)); - dev->close(); /* close current part */ - memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); + dev->close_part(dcr); /* close current part */ /* * If we have a spooled part open, write it to the @@ -561,8 +553,6 @@ int dvd_open_next_part(DCR *dcr) if (dev->open(dcr, OPEN_READ_ONLY) < 0) { return -1; } - /* Restore Volume header record */ - memcpy(&dev->VolHdr, &VolHdr, sizeof(dev->VolHdr)); dev->set_labeled(); /* all next parts are "labeled" */ return dev->fd; @@ -576,20 +566,12 @@ int dvd_open_next_part(DCR *dcr) int dvd_open_first_part(DCR *dcr, int mode) { DEVICE *dev = dcr->dev; - VOLUME_LABEL VolHdr; Dmsg5(29, "Enter: ==== open_first_part dev=%s Vol=%s mode=%d num_dvd_parts=%d append=%d\n", dev->print_name(), dev->VolCatInfo.VolCatName, dev->openmode, dev->num_dvd_parts, dev->can_append()); - /* - * Note, when we close, the Volume header is zeroed. Since - * we reopen, but are in fact opening the same volume without - * re-reading the Volume header, we simply save and restore it. - */ - memcpy(&VolHdr, &dev->VolHdr, sizeof(VolHdr)); - dev->close(); - memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); + dev->close_part(dcr); Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->VolCatInfo.VolCatName, mode); @@ -597,9 +579,6 @@ int dvd_open_first_part(DCR *dcr, int mode) dev->part = 1; dev->part_start = 0; - - /* Restore Volume header record */ - memcpy(&dev->VolHdr, &VolHdr, sizeof(dev->VolHdr)); if (dev->open(dcr, mode) < 0) { Dmsg0(400, "open dev() failed\n"); return -1; @@ -778,8 +757,7 @@ bool truncate_dvd(DCR *dcr) { DEVICE* dev = dcr->dev; - dev->close(); - memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); + dev->close_part(dcr); if (!unmount_dvd(dev, 1)) { Dmsg0(400, "truncate_dvd: Failed to unmount DVD\n"); @@ -811,8 +789,7 @@ bool truncate_dvd(DCR *dcr) return false; } - dev->close(); - memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); + dev->close_part(dcr); Dmsg0(400, "truncate_dvd: Opening first part (2)...\n"); @@ -904,7 +881,7 @@ bool check_can_write_on_non_blank_dvd(DCR *dcr) filename.c_str(), be.strerror()); return false; } - Dmsg2(99, "check_can_write_on_non_blank_dvd: size of %s is %d\n", + Dmsg2(99, "check_can_write_on_non_blank_dvd: size of %s is %lld\n", filename.c_str(), filestat.st_size); matched = filestat.st_size == 0; } diff --git a/bacula/technotes-1.39 b/bacula/technotes-1.39 index 8b6269985d..3abf44e441 100644 --- a/bacula/technotes-1.39 +++ b/bacula/technotes-1.39 @@ -2,6 +2,12 @@ General: 07Sep06 +kes Add a new close_part() class in the SD to save the device + state around open/close_part/open for DVD writing. This + should fix the num_dvd_parts getting zeroed as reported by + Richard Mortimer. +kes Apply patch from Richard Mortimer that correct edit code + for debug output of st_size. ebl Add support of encrypted data stream to bscan. display data_len instead of data content (may be binary) 06Sep06