From: Kern Sibbald Date: Mon, 18 Jul 2005 19:25:16 +0000 (+0000) Subject: - Make all files in working directory have .xxx at end. X-Git-Tag: Release-1.38.0~287 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6084570a15d0527dbdadfac6a023010ddc9d1eae;p=bacula%2Fbacula - Make all files in working directory have .xxx at end. - Work on DVD writing. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2217 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kernstodo b/bacula/kernstodo index bb92b37999..600115e415 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -47,7 +47,7 @@ Document: - On Win32 working directory must have drive letter ???? - On Win32 working directory must be writable by SYSTEM to do restores. - +- Clean up working extensions: db, pid, state, bsr, mail, conmsg, spool For 1.39: diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index c608fecee1..c641983ae0 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -344,10 +344,10 @@ void rem_msg_dest(MSGS *msg, int dest_code, int msg_type, char *where) static void make_unique_mail_filename(JCR *jcr, POOLMEM *&name, DEST *d) { if (jcr) { - Mmsg(name, "%s/%s.mail.%s.%d", working_directory, my_name, + Mmsg(name, "%s/%s.%s.%d.mail", working_directory, my_name, jcr->Job, (int)(long)d); } else { - Mmsg(name, "%s/%s.mail.%s.%d", working_directory, my_name, + Mmsg(name, "%s/%s.%s.%d.mail", working_directory, my_name, my_name, (int)(long)d); } Dmsg1(850, "mailname=%s\n", name); diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index ca6cbc8def..4b65c0d975 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -544,8 +544,9 @@ bool write_block_to_dev(DCR *dcr) dev->VolCatInfo.VolCatName, dev->file, dev->block_num, dev->print_name(), wlen, stat); } - Dmsg6(100, "=== Write error. size=%u rtn=%d dev_blk=%d blk_blk=%d errno=%d: ERR=%s\n", - wlen, stat, dev->block_num, block->BlockNumber, dev->dev_errno, strerror(dev->dev_errno)); + Dmsg7(100, "=== Write error. fd=%d size=%u rtn=%d dev_blk=%d blk_blk=%d errno=%d: ERR=%s\n", + dev->fd, wlen, stat, dev->block_num, block->BlockNumber, + dev->dev_errno, strerror(dev->dev_errno)); ok = terminate_writing_volume(dcr); if (!ok && !forge_on) { diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index d75b03a3b1..b34e814b4d 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -338,7 +338,7 @@ void DEVICE::open_tape_device(int omode) } /* If busy retry each second for max_open_wait seconds */ open_again: - Dmsg1(500, "Try open %s\n", dev_name); + Dmsg1(500, "Try open %s\n", print_name()); /* Use system open() */ while ((fd = ::open(dev_name, mode, MODE_RW+nonblocking)) < 0) { berrno be; @@ -377,7 +377,8 @@ open_again: ::close(fd); /* use system close() */ goto open_again; } - openmode = mode; /* save open mode */ + openmode = omode; /* save open mode */ + Dmsg2(100, "openmode=%d %s\n", openmode, mode_to_str(openmode)); dev_errno = 0; set_opened(); use_count = 1; @@ -422,6 +423,7 @@ void DEVICE::open_file_device(int omode) Dmsg3(29, "open dev: %s dev=%s mode=%s\n", is_dvd()?"DVD":"disk", archive_name.c_str(), mode_to_str(omode)); openmode = omode; + Dmsg2(100, "openmode=%d %s\n", openmode, mode_to_str(openmode)); set_mode(omode); /* If creating file, give 0640 permissions */ @@ -486,6 +488,7 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode) is_dvd()?"DVD":"disk", archive_name.c_str(), mode_to_str(omode), part, num_parts); openmode = omode; + Dmsg2(100, "openmode=%d %s\n", openmode, mode_to_str(openmode)); /* * If we are not trying to access the last part, set mode to @@ -522,6 +525,7 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode) fd = ::open(archive_name.c_str(), mode, 0640); /* try on spool */ } } + Dmsg1(100, "after open fd=%d\n", fd); if (fd >= 0) { /* Get size of file */ if (fstat(fd, &filestat) < 0) { @@ -539,17 +543,21 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode) set_opened(); use_count = 1; update_pos_dev(this); /* update position */ - /* Just created Volume */ - if (omode == OPEN_READ_WRITE && part_size == 0) { + /* Check if just created Volume part */ + if (omode == OPEN_READ_WRITE && (part == 0 || part_size == 0)) { part++; - num_parts++; + num_parts = part; VolCatInfo.VolCatParts = num_parts; + } else { + if (part == 0) { /* we must have opened the first part */ + part++; + } } } } Dmsg4(29, "open dev: DVD fd=%d opened, part=%d nump=%d, part_size=%u\n", fd, part, num_parts, part_size); - if (is_open() && is_dvd() && (omode != OPEN_READ_ONLY) && + if (is_open() && (omode != OPEN_READ_ONLY) && (free_space_errno == 0 || num_parts == part)) { update_free_space_dev(this); } @@ -560,7 +568,7 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode) #undef rewind_dev bool _rewind_dev(char *file, int line, DEVICE *dev) { - Dmsg2(100, "rewind_dev called from %s:%d\n", file, line); + Dmsg3(100, "rewind_dev fd=%d called from %s:%d\n", dev->fd, file, line); return rewind_dev(dev); } #endif @@ -575,7 +583,7 @@ bool rewind_dev(DEVICE *dev) struct mtop mt_com; unsigned int i; - Dmsg1(29, "rewind_dev %s\n", dev->print_name()); + Dmsg2(29, "rewind_dev fd=%d %s\n", dev->fd, dev->print_name()); if (dev->fd < 0) { dev->dev_errno = EBADF; Mmsg1(dev->errmsg, _("Bad call to rewind_dev. Device %s not open\n"), @@ -1656,6 +1664,7 @@ static void do_close(DEVICE *dev) dev->file_size = 0; dev->file_addr = 0; dev->part = 0; + dev->num_parts = 0; dev->part_size = 0; dev->part_start = 0; dev->EndFile = dev->EndBlock = 0; diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 726ec18939..5e9d5c2a16 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -112,6 +112,7 @@ enum { #define ST_MOUNTED (1<<15) /* the device is mounted to the mount point */ #define ST_MEDIA (1<<16) /* Media found in mounted device */ #define ST_OFFLINE (1<<17) /* set offline by operator */ +#define ST_PART_SPOOLED (1<<18) /* spooling part */ /* dev_blocked states (mutually exclusive) */ enum { @@ -260,6 +261,7 @@ public: int is_offline() const { return state & ST_OFFLINE; } int is_labeled() const { return state & ST_LABEL; } int is_mounted() const { return state & ST_MOUNTED; } + int is_part_spooled() const { return state & ST_PART_SPOOLED; } int have_media() const { return state & ST_MEDIA; } int is_short_block() const { return state & ST_SHORT; } int is_busy() const { return (state & ST_READ) || num_writers || reserved_device; } @@ -303,6 +305,8 @@ public: void set_mounted() { state |= ST_MOUNTED; }; void set_media() { state |= ST_MEDIA; }; void set_short_block() { state |= ST_SHORT; }; + void set_part_spooled(int val) { if (val) state |= ST_PART_SPOOLED; \ + else state &= ~ST_PART_SPOOLED; }; void set_mounted(int val) { if (val) state |= ST_MOUNTED; \ else state &= ~ST_MOUNTED; }; void clear_append() { state &= ~ST_APPEND; }; diff --git a/bacula/src/stored/dvd.c b/bacula/src/stored/dvd.c index e13357a684..8425f2c913 100644 --- a/bacula/src/stored/dvd.c +++ b/bacula/src/stored/dvd.c @@ -37,6 +37,7 @@ void make_mounted_dvd_filename(DEVICE *dev, POOL_MEM &archive_name) { pm_strcpy(archive_name, dev->device->mount_point); add_file_and_part_name(dev, archive_name); + dev->set_part_spooled(false); } void make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &archive_name) @@ -48,6 +49,7 @@ void make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &archive_name) pm_strcpy(archive_name, working_directory); } add_file_and_part_name(dev, archive_name); + dev->set_part_spooled(true); } static void add_file_and_part_name(DEVICE *dev, POOL_MEM &archive_name) @@ -125,12 +127,11 @@ static bool do_mount_dev(DEVICE* dev, int mount, int dotimeout) } else { timeout = 0; } - results = get_pool_memory(PM_MESSAGE); + results = get_memory(2000); results[0] = 0; /* If busy retry each second */ while ((status = run_program_full_output(ocmd.c_str(), dev->max_open_wait/2, results)) != 0) { - Dmsg1(100, "results len=%d\n", strlen(results)); if (fnmatch("*is already mounted on", results, 0) == 0) { break; } @@ -147,7 +148,6 @@ static bool do_mount_dev(DEVICE* dev, int mount, int dotimeout) Dmsg2(40, "Device %s cannot be mounted. ERR=%s\n", dev->print_name(), results); Mmsg(dev->errmsg, "Device %s cannot be mounted. ERR=%s\n", dev->print_name(), results); -#ifdef xxx /* * Now, just to be sure it is not mounted, try to read the * filesystem. @@ -185,7 +185,6 @@ static bool do_mount_dev(DEVICE* dev, int mount, int dotimeout) break; /* there must be something mounted */ } get_out: -#endif free_pool_memory(results); return false; } @@ -227,7 +226,6 @@ void update_free_space_dev(DEVICE* dev) while (1) { if (run_program_full_output(ocmd.c_str(), dev->max_open_wait/2, results) == 0) { - Dmsg1(100, "results len=%d\n", strlen(results)); Dmsg1(100, "Free space program run : %s\n", results); free = str_to_int64(results); if (free >= 0) { @@ -310,7 +308,6 @@ static bool dvd_write_part(DCR *dcr) Dmsg2(29, "dvd_write_part: cmd=%s timeout=%d\n", ocmd.c_str(), timeout); status = run_program_full_output(ocmd.c_str(), timeout, results.c_str()); - Dmsg1(100, "results len=%d\n", strlen(results.c_str())); if (status != 0) { Mmsg1(dev->errmsg, "Error while writing current part to the DVD: %s", results.c_str()); @@ -327,7 +324,6 @@ static bool dvd_write_part(DCR *dcr) update_free_space_dev(dev); Jmsg(dcr->jcr, M_INFO, 0, _("Remaining free space %s on %s\n"), edit_uint64_with_commas(dev->free_space, ed1), dev->print_name()); - Dmsg1(100, "results=%s\n", results.c_str()); return true; } @@ -417,7 +413,7 @@ int open_next_part(DCR *dcr) dev->num_parts = dev->part; dev->VolCatInfo.VolCatParts = dev->part; } - Dmsg2(50, "Call dev->open(vol=%s, mode=%d", dev->VolCatInfo.VolCatName, + Dmsg2(50, "Call dev->open(vol=%s, mode=%d\n", dev->VolCatInfo.VolCatName, dev->openmode); /* Open next part */ if (dev->open(dcr, dev->openmode) < 0) { @@ -464,12 +460,13 @@ int open_first_part(DCR *dcr, int mode) /* Protected version of lseek, which opens the right part if necessary */ off_t lseek_dev(DEVICE *dev, off_t offset, int whence) { - int openmode; DCR *dcr; off_t pos; - Dmsg0(100, "Enter lseek_dev\n"); - if (!dev->is_dvd() || dev->num_parts <= 1) { /* If there is only one part, simply call lseek. */ + Dmsg3(100, "Enter lseek_dev fd=%d part=%d nparts=%d\n", dev->fd, + dev->part, dev->num_parts); + if (!dev->is_dvd()) { + Dmsg0(100, "Using sys lseek\n"); return lseek(dev->fd, offset, whence); } @@ -478,9 +475,9 @@ off_t lseek_dev(DEVICE *dev, off_t offset, int whence) case SEEK_SET: Dmsg1(100, "lseek_dev SEEK_SET to %d\n", (int)offset); if ((uint64_t)offset >= dev->part_start) { - if ((uint64_t)(offset - dev->part_start) < dev->part_size) { + offset -= dev->part_start; /* adjust for start of this part */ + if (offset == 0 || (uint64_t)offset < dev->part_size) { /* We are staying in the current part, just seek */ - offset -= dev->part_start; /* adjust for start of this part */ if ((pos = lseek(dev->fd, offset, SEEK_SET)) < 0) { return pos; } else { @@ -522,24 +519,36 @@ off_t lseek_dev(DEVICE *dev, off_t offset, int whence) break; case SEEK_END: Dmsg1(100, "lseek_dev SEEK_END to %d\n", (int)offset); + /* + * Bacula does not use offsets for SEEK_END + * Also, Bacula uses seek_end only when it wants to + * append to the volume, so for a dvd that means + * that the volume must be spooled since the DVD + * itself is read-only (as currently implemented). + */ if (offset > 0) { /* Not used by bacula */ Dmsg1(100, "lseek_dev SEEK_END called with an invalid offset %d\n", (int)offset); errno = EINVAL; return -1; } - - if (dev->part == dev->num_parts) { /* The right part is already loaded */ + /* If we are already on a spooled part and have the + * right part number, simply seek + */ + if (dev->is_part_spooled() && dev->part == dev->num_parts) { if ((pos = lseek(dev->fd, (off_t)0, SEEK_END)) < 0) { return pos; } else { return pos + dev->part_start; } } else { - /* Load the first part, then load the next until we reach the last one. - * This is the only way to be sure we compute the right file address. */ - /* Save previous openmode, and open all but last part read-only (useful for DVDs) */ - openmode = dev->openmode; - + /* + * Load the first part, then load the next until we reach the last one. + * This is the only way to be sure we compute the right file address. + * + * Save previous openmode, and open all but last part read-only + * (useful for DVDs) + */ + int modesave = dev->openmode; /* Works because num_parts > 0. */ if (open_first_part(dcr, OPEN_READ_ONLY) < 0) { Dmsg0(100, "lseek_dev failed while trying to open the first part\n"); @@ -551,7 +560,7 @@ off_t lseek_dev(DEVICE *dev, off_t offset, int whence) return -1; } } - dev->openmode = openmode; + dev->openmode = modesave; if (open_next_part(dcr) < 0) { Dmsg0(100, "lseek_dev failed while trying to open the next part\n"); return -1; diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 26c88b6170..50357885a2 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -357,7 +357,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) DEVICE *dev = dcr->dev; JCR *jcr = dcr->jcr; - Dmsg1(190, "set append found freshly labeled volume. dev=%x\n", dev); + Dmsg2(190, "set append found freshly labeled volume. fd=%d dev=%x\n", dev->fd, dev); dev->VolHdr.LabelType = VOL_LABEL; /* set Volume label */ dev->set_append(); if (!write_volume_label_to_block(dcr)) { @@ -398,7 +398,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) } /* Attempt write to check write permission */ - Dmsg0(200, "Attempt to write to device.\n"); + Dmsg1(200, "Attempt to write to device fd=%d.\n", dev->fd); if (!write_block_to_dev(dcr)) { Jmsg2(jcr, M_ERROR, 0, _("Unable to write device %s: ERR=%s\n"), dev->print_name(), strerror_dev(dev)); diff --git a/bacula/src/stored/spool.c b/bacula/src/stored/spool.c index 474ea44199..bf6925b2f8 100644 --- a/bacula/src/stored/spool.c +++ b/bacula/src/stored/spool.c @@ -131,7 +131,7 @@ static void make_unique_data_spool_filename(DCR *dcr, POOLMEM **name) } else { dir = working_directory; } - Mmsg(name, "%s/%s.data.spool.%s.%s", dir, my_name, dcr->jcr->Job, + Mmsg(name, "%s/%s.data.%s.%s.spool", dir, my_name, dcr->jcr->Job, dcr->device->hdr.name); } @@ -563,7 +563,7 @@ bail_out: static void make_unique_spool_filename(JCR *jcr, POOLMEM **name, int fd) { - Mmsg(name, "%s/%s.attr.spool.%s.%d", working_directory, my_name, + Mmsg(name, "%s/%s.attr.%s.%d.spool", working_directory, my_name, jcr->Job, fd); }