- 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:
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);
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) {
}
/* 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;
::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;
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 */
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
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) {
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);
}
#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
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"),
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;
#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 {
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; }
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; };
{
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)
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)
} 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;
}
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.
break; /* there must be something mounted */
}
get_out:
-#endif
free_pool_memory(results);
return false;
}
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) {
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());
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;
}
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) {
/* 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);
}
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 {
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");
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;
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)) {
}
/* 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));
} 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);
}
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);
}