From: Kern Sibbald Date: Sun, 18 Feb 2007 15:51:09 +0000 (+0000) Subject: kes Make DEVICE fd private. Its new name is m_fd, and can be X-Git-Tag: Release-7.0.0~6874 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6d168bc4e88849ceb95973bb8e2b69fb7bd59399;p=bacula%2Fbacula kes Make DEVICE fd private. Its new name is m_fd, and can be obtained with dev->fd() outside the class. This is the first of many DEVICE members to be made private. kes Implement Michael Renner's idea on having a virtual disk changer. I made some minor modifications (e.g. I did not implement the Virtual Changer directive, but simply set the Changer Command to an empty string. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4203 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/qt-console/restore/restore.cpp b/bacula/src/qt-console/restore/restore.cpp index c38923a6c4..5e3d8a3422 100644 --- a/bacula/src/qt-console/restore/restore.cpp +++ b/bacula/src/qt-console/restore/restore.cpp @@ -40,14 +40,14 @@ restoreDialog::restoreDialog(Console *parent) { - (void)parent; + (void)parent; /* keep compiler quiet */ setupUi(this); this->show(); } prerestoreDialog::prerestoreDialog(Console *parent) { - (void)parent; + (void)parent; /* keep compiler quiet */ setupUi(this); this->show(); } diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index f42ce5db8b..f278ebe622 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -121,6 +121,12 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir) Dmsg1(200, "Device %s is not an autochanger\n", dev->print_name()); return 0; } + + /* An empty ChangerCommand => virtual disk autochanger */ + if (dcr->device->changer_command && dcr->device->changer_command[0] == 0) { + return 1; /* nothing to load */ + } + slot = dcr->VolCatInfo.InChanger ? dcr->VolCatInfo.Slot : 0; /* * Handle autoloaders here. If we cannot autoload it, we @@ -241,9 +247,13 @@ int get_autochanger_loaded_slot(DCR *dcr) Jmsg(jcr, M_FATAL, 0, _("3992 Missing Changer command.\n")); return -1; } - if (dev->Slot >0) { + if (dev->Slot > 0) { return dev->Slot; } + /* Virtual disk autochanger */ + if (dcr->device->changer_command[0]) { + return 1; + } /* Find out what is loaded, zero means device is unloaded */ changer = get_pool_memory(PM_FNAME); diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 1e4bb96451..a05b9c46cd 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -574,7 +574,7 @@ bool write_block_to_dev(DCR *dcr) dev->file, dev->block_num, dev->print_name(), wlen, stat); } 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->fd(), wlen, stat, dev->block_num, block->BlockNumber, dev->dev_errno, strerror(dev->dev_errno)); ok = terminate_writing_volume(dcr); @@ -941,7 +941,7 @@ reread: if (dev->at_eof() && dev->is_dvd()) { Dmsg1(100, "file_size=%u\n",(unsigned int)dev->file_size); Dmsg1(100, "file_addr=%u\n",(unsigned int)dev->file_addr); - Dmsg1(100, "lseek=%u\n",(unsigned int)lseek(dev->fd, 0, SEEK_CUR)); + Dmsg1(100, "lseek=%u\n",(unsigned int)lseek(dev->fd(), 0, SEEK_CUR)); Dmsg1(100, "part_start=%u\n",(unsigned int)dev->part_start); Dmsg1(100, "part_size=%u\n", (unsigned int)dev->part_size); Dmsg2(100, "part=%u num_dvd_parts=%u\n", dev->part, dev->num_dvd_parts); @@ -984,7 +984,7 @@ reread: Dmsg1(200, "Read device got: ERR=%s\n", be.strerror()); block->read_len = 0; Mmsg5(dev->errmsg, _("Read error on fd=%d at file:blk %u:%u on device %s. ERR=%s.\n"), - dev->fd, dev->file, dev->block_num, dev->print_name(), be.strerror()); + dev->fd(), dev->file, dev->block_num, dev->print_name(), be.strerror()); Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); if (dev->at_eof()) { /* EOF just seen? */ dev->set_eot(); /* yes, error => EOT */ diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index f3f0270a89..8c0444a62a 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -270,7 +270,7 @@ int main (int argc, char *argv[]) if (showProgress) { char ed1[50]; struct stat sb; - fstat(dev->fd, &sb); + fstat(dev->fd(), &sb); currentVolumeSize = sb.st_size; Pmsg1(000, _("First Volume Size = %sn"), edit_uint64(currentVolumeSize, ed1)); @@ -343,7 +343,7 @@ static bool bscan_mount_next_read_volume(DCR *dcr) if (showProgress) { char ed1[50]; struct stat sb; - fstat(dev->fd, &sb); + fstat(dev->fd(), &sb); currentVolumeSize = sb.st_size; Pmsg1(000, _("First Volume Size = %sn"), edit_uint64(currentVolumeSize, ed1)); diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 3bdae65350..d2056e2a02 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -1594,7 +1594,7 @@ static void rrcmd() len = 1024; } buf = (char *)malloc(len); - stat = read(dev->fd, buf, len); + stat = read(dev->fd(), buf, len); if (stat > 0 && stat <= len) { errno = 0; } @@ -1629,7 +1629,7 @@ static void scancmd() tot_files = dev->file; Pmsg1(0, _("Starting scan at file %u\n"), dev->file); for (;;) { - if ((stat = read(dev->fd, buf, sizeof(buf))) < 0) { + if ((stat = read(dev->fd(), buf, sizeof(buf))) < 0) { berrno be; dev->clrerror(-1); Mmsg2(dev->errmsg, _("read error on %s. ERR=%s.\n"), @@ -2495,9 +2495,9 @@ static void rawfill_cmd() for ( ;; ) { *p = block_num; if (dev->is_tape()) { - stat = tape_write(dev->fd, block->buf, block->buf_len); + stat = tape_write(dev->fd(), block->buf, block->buf_len); } else { - stat = write(dev->fd, block->buf, block->buf_len); + stat = write(dev->fd(), block->buf, block->buf_len); } if (stat == (int)block->buf_len) { if ((block_num++ % 100) == 0) { diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 474fa45d41..6e543384d7 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -275,12 +275,12 @@ DEVICE::open(DCR *dcr, int omode) int preserve = 0; if (is_open()) { if (openmode == omode) { - return fd; + return m_fd; } else { if (is_tape()) { - tape_close(fd); + tape_close(m_fd); } else { - ::close(fd); + ::close(m_fd); } clear_opened(); Dmsg0(100, "Close fd for mode change.\n"); @@ -306,8 +306,8 @@ DEVICE::open(DCR *dcr, int omode) open_file_device(dcr, omode); } state |= preserve; /* reset any important state info */ - Dmsg2(100, "preserve=0x%x fd=%d\n", preserve, fd); - return fd; + Dmsg2(100, "preserve=0x%x fd=%d\n", preserve, m_fd); + return m_fd; } void DEVICE::set_mode(int new_mode) @@ -361,7 +361,7 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) #if defined(HAVE_WIN32) /* Windows Code */ - if ((fd = tape_open(dev_name, mode)) < 0) { + if ((m_fd = tape_open(dev_name, mode)) < 0) { dev_errno = errno; } @@ -371,8 +371,8 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) /* If busy retry each second for max_open_wait seconds */ for ( ;; ) { /* Try non-blocking open */ - fd = ::open(dev_name, mode+O_NONBLOCK); - if (fd < 0) { + m_fd = ::open(dev_name, mode+O_NONBLOCK); + if (m_fd < 0) { berrno be; dev_errno = errno; Dmsg5(050, "Open error on %s omode=%d mode=%x errno=%d: ERR=%s\n", @@ -382,10 +382,10 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) Dmsg0(050, "Rewind after open\n"); mt_com.mt_op = MTREW; mt_com.mt_count = 1; - if (ioctl(fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0) { berrno be; dev_errno = errno; /* set error status from rewind */ - ::close(fd); + ::close(m_fd); clear_opened(); Dmsg2(100, "Rewind error on %s close: ERR=%s\n", print_name(), be.strerror(dev_errno)); @@ -395,9 +395,9 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) } } else { /* Got fd and rewind worked, so we must have medium in drive */ - ::close(fd); - fd = ::open(dev_name, mode); /* open normally */ - if (fd < 0) { + ::close(m_fd); + m_fd = ::open(dev_name, mode); /* open normally */ + if (m_fd < 0) { berrno be; dev_errno = errno; Dmsg5(050, "Open error on %s omode=%d mode=%x errno=%d: ERR=%s\n", @@ -430,7 +430,7 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) stop_thread_timer(tid); tid = 0; } - Dmsg1(29, "open dev: tape %d opened\n", fd); + Dmsg1(29, "open dev: tape %d opened\n", m_fd); } @@ -453,7 +453,7 @@ void DEVICE::open_file_device(DCR *dcr, int omode) * we simply use the device name, assuming it has been * appropriately setup by the "autochanger". */ - if (!device->changer_res) { + if (!device->changer_res || device->changer_command[0] == 0) { if (VolCatInfo.VolCatName[0] == 0) { Mmsg(errmsg, _("Could not open file device %s. No Volume name given.\n"), print_name()); @@ -475,7 +475,7 @@ void DEVICE::open_file_device(DCR *dcr, int omode) Dmsg3(29, "open disk: mode=%s open(%s, 0x%x, 0640)\n", mode_to_str(omode), archive_name.c_str(), mode); /* Use system open() */ - if ((fd = ::open(archive_name.c_str(), mode, 0640)) < 0) { + if ((m_fd = ::open(archive_name.c_str(), mode, 0640)) < 0) { berrno be; dev_errno = errno; Mmsg2(errmsg, _("Could not open: %s, ERR=%s\n"), archive_name.c_str(), @@ -488,7 +488,7 @@ void DEVICE::open_file_device(DCR *dcr, int omode) file_addr = 0; } Dmsg4(29, "open dev: disk fd=%d opened, part=%d/%d, part_size=%u\n", - fd, part, num_dvd_parts, part_size); + m_fd, part, num_dvd_parts, part_size); } /* @@ -644,7 +644,7 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode) Dmsg3(29, "mode=%s open(%s, 0x%x, 0640)\n", mode_to_str(omode), archive_name.c_str(), mode); /* Use system open() */ - if ((fd = ::open(archive_name.c_str(), mode, 0640)) < 0) { + if ((m_fd = ::open(archive_name.c_str(), mode, 0640)) < 0) { berrno be; Mmsg2(errmsg, _("Could not open: %s, ERR=%s\n"), archive_name.c_str(), be.strerror()); @@ -663,24 +663,24 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode) Dmsg1(29, "Creating last part on spool: %s\n", archive_name.c_str()); omode = CREATE_READ_WRITE; set_mode(CREATE_READ_WRITE); - fd = ::open(archive_name.c_str(), mode, 0640); + m_fd = ::open(archive_name.c_str(), mode, 0640); set_mode(omode); } } - Dmsg1(100, "after open fd=%d\n", fd); + Dmsg1(100, "after open fd=%d\n", m_fd); if (is_open()) { if (omode == OPEN_READ_WRITE || omode == CREATE_READ_WRITE) { set_append(); } /* Get size of file */ - if (fstat(fd, &filestat) < 0) { + if (fstat(m_fd, &filestat) < 0) { berrno be; dev_errno = errno; Mmsg2(errmsg, _("Could not fstat: %s, ERR=%s\n"), archive_name.c_str(), be.strerror()); Dmsg1(29, "open failed: %s", errmsg); /* Use system close() */ - ::close(fd); + ::close(m_fd); clear_opened(); } else { part_size = filestat.st_size; @@ -702,12 +702,12 @@ bool DEVICE::rewind(DCR *dcr) unsigned int i; bool first = true; - Dmsg3(400, "rewind res=%d fd=%d %s\n", reserved_device, fd, print_name()); + Dmsg3(400, "rewind res=%d fd=%d %s\n", reserved_device, m_fd, print_name()); state &= ~(ST_EOT|ST_EOF|ST_WEOT); /* remove EOF/EOT flags */ block_num = file = 0; file_size = 0; file_addr = 0; - if (fd < 0) { + if (m_fd < 0) { if (!is_dvd()) { /* In case of major error, the fd is not open on DVD, so we don't want to abort. */ dev_errno = EBADF; Mmsg1(errmsg, _("Bad call to rewind. Device %s not open\n"), @@ -724,7 +724,7 @@ bool DEVICE::rewind(DCR *dcr) * retrying every 5 seconds. */ for (i=max_rewind_wait; ; i -= 5) { - if (tape_ioctl(fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0) { berrno be; clrerror(MTREW); if (i == max_rewind_wait) { @@ -738,10 +738,10 @@ bool DEVICE::rewind(DCR *dcr) */ if (first && dcr) { int open_mode = openmode; - tape_close(fd); + tape_close(m_fd); clear_opened(); open(dcr, open_mode); - if (fd < 0) { + if (m_fd < 0) { return false; } first = false; @@ -851,7 +851,7 @@ bool DEVICE::eod(DCR *dcr) bool ok = true; boffset_t pos; - if (fd < 0) { + if (m_fd < 0) { dev_errno = EBADF; Mmsg1(errmsg, _("Bad call to eod. Device %s not open\n"), print_name()); return false; @@ -913,7 +913,7 @@ bool DEVICE::eod(DCR *dcr) mt_com.mt_count = 1; } - if (tape_ioctl(fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0) { berrno be; clrerror(mt_com.mt_op); Dmsg1(50, "ioctl error: %s\n", be.strerror()); @@ -1056,7 +1056,7 @@ uint32_t status_dev(DEVICE *dev) stat |= BMT_TAPE; Pmsg0(-20,_(" Bacula status:")); Pmsg2(-20,_(" file=%d block=%d\n"), dev->file, dev->block_num); - if (tape_ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) { + if (tape_ioctl(dev->fd(), MTIOCGET, (char *)&mt_stat) < 0) { berrno be; dev->dev_errno = errno; Mmsg2(dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"), @@ -1160,7 +1160,7 @@ bool load_dev(DEVICE *dev) struct mtop mt_com; #endif - if (dev->fd < 0) { + if (dev->fd() < 0) { dev->dev_errno = EBADF; Mmsg0(dev->errmsg, _("Bad call to load_dev. Device not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); @@ -1183,7 +1183,7 @@ bool load_dev(DEVICE *dev) dev->file_addr = 0; mt_com.mt_op = MTLOAD; mt_com.mt_count = 1; - if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) { berrno be; dev->dev_errno = errno; Mmsg2(dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"), @@ -1214,7 +1214,7 @@ bool DEVICE::offline() unlock_door(); mt_com.mt_op = MTOFFL; mt_com.mt_count = 1; - if (tape_ioctl(fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com) < 0) { berrno be; dev_errno = errno; Mmsg2(errmsg, _("ioctl MTOFFL error on %s. ERR=%s.\n"), @@ -1227,7 +1227,7 @@ bool DEVICE::offline() bool DEVICE::offline_or_rewind() { - if (fd < 0) { + if (m_fd < 0) { return false; } if (has_cap(CAP_OFFLINEUNMOUNT)) { @@ -1288,7 +1288,7 @@ bool DEVICE::fsf(int num) if (has_cap(CAP_FSF) && has_cap(CAP_MTIOCGET) && has_cap(CAP_FASTFSF)) { mt_com.mt_op = MTFSF; mt_com.mt_count = num; - stat = tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); + stat = tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com); if (stat < 0 || !dev_get_os_pos(this, &mt_stat)) { berrno be; set_eot(); @@ -1363,7 +1363,7 @@ bool DEVICE::fsf(int num) } Dmsg0(100, "Doing MTFSF\n"); - stat = tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); + stat = tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com); if (stat < 0) { /* error => EOT */ berrno be; set_eot(); @@ -1437,7 +1437,7 @@ bool DEVICE::bsf(int num) file_size = 0; mt_com.mt_op = MTBSF; mt_com.mt_count = num; - stat = tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); + stat = tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com); if (stat < 0) { berrno be; clrerror(MTBSF); @@ -1477,7 +1477,7 @@ bool DEVICE::fsr(int num) Dmsg1(29, "fsr %d\n", num); mt_com.mt_op = MTFSR; mt_com.mt_count = num; - stat = tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); + stat = tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com); if (stat == 0) { clear_eof(); block_num += num; @@ -1536,7 +1536,7 @@ bool DEVICE::bsr(int num) clear_eot(); mt_com.mt_op = MTBSR; mt_com.mt_count = num; - stat = tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); + stat = tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com); if (stat < 0) { berrno be; clrerror(MTBSR); @@ -1552,7 +1552,7 @@ void DEVICE::lock_door() struct mtop mt_com; mt_com.mt_op = MTLOCK; mt_com.mt_count = 1; - tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); + tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com); #endif } @@ -1562,7 +1562,7 @@ void DEVICE::unlock_door() struct mtop mt_com; mt_com.mt_op = MTUNLOCK; mt_com.mt_count = 1; - tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); + tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com); #endif } @@ -1674,7 +1674,7 @@ bool DEVICE::weof(int num) clear_eot(); mt_com.mt_op = MTWEOF; mt_com.mt_count = num; - stat = tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); + stat = tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com); if (stat == 0) { block_num = 0; file += num; @@ -1801,7 +1801,7 @@ void DEVICE::clrerror(int func) */ /* On some systems such as NetBSD, this clears all errors */ - tape_ioctl(fd, MTIOCGET, (char *)&mt_stat); + tape_ioctl(m_fd, MTIOCGET, (char *)&mt_stat); /* Found on Linux */ #ifdef MTIOCLRERR @@ -1810,7 +1810,7 @@ void DEVICE::clrerror(int func) mt_com.mt_op = MTIOCLRERR; mt_com.mt_count = 1; /* Clear any error condition on the tape */ - tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); + tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com); Dmsg0(200, "Did MTIOCLRERR\n"); } #endif @@ -1823,7 +1823,7 @@ void DEVICE::clrerror(int func) union mterrstat mt_errstat; Dmsg2(200, "Doing MTIOCERRSTAT errno=%d ERR=%s\n", dev_errno, be.strerror(dev_errno)); - tape_ioctl(fd, MTIOCERRSTAT, (char *)&mt_errstat); + tape_ioctl(m_fd, MTIOCERRSTAT, (char *)&mt_errstat); } #endif @@ -1834,7 +1834,7 @@ void DEVICE::clrerror(int func) mt_com.mt_op = MTCSE; mt_com.mt_count = 1; /* Clear any error condition on the tape */ - tape_ioctl(fd, MTIOCTOP, (char *)&mt_com); + tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com); Dmsg0(200, "Did MTCSE\n"); } #endif @@ -1859,10 +1859,10 @@ void DEVICE::close() switch (dev_type) { case B_TAPE_DEV: unlock_door(); - tape_close(fd); + tape_close(m_fd); break; default: - ::close(fd); + ::close(m_fd); } /* Clean up device packet so it can be reused */ @@ -1914,9 +1914,9 @@ boffset_t DEVICE::lseek(DCR *dcr, boffset_t offset, int whence) return lseek_dvd(dcr, offset, whence); case B_FILE_DEV: #if defined(HAVE_WIN32) - return ::_lseeki64(fd, (__int64)offset, whence); + return ::_lseeki64(m_fd, (__int64)offset, whence); #else - return ::lseek(fd, (off_t)offset, whence); + return ::lseek(m_fd, (off_t)offset, whence); #endif } return -1; @@ -1936,7 +1936,7 @@ bool DEVICE::truncate(DCR *dcr) /* We need the DCR for DVD-writing */ /* ***FIXME*** we really need to unlink() the file so that * its name can be changed for a relabel. */ - if (ftruncate(fd, 0) != 0) { + if (ftruncate(m_fd, 0) != 0) { berrno be; Mmsg2(errmsg, _("Unable to truncate device %s. ERR=%s\n"), print_name(), be.strerror()); @@ -2208,9 +2208,9 @@ ssize_t DEVICE::read(void *buf, size_t len) get_timer_count(); if (this->is_tape()) { - read_len = tape_read(fd, buf, len); + read_len = tape_read(m_fd, buf, len); } else { - read_len = ::read(fd, buf, len); + read_len = ::read(m_fd, buf, len); } last_tick = get_timer_count(); @@ -2233,9 +2233,9 @@ ssize_t DEVICE::write(const void *buf, size_t len) get_timer_count(); if (this->is_tape()) { - write_len = tape_write(fd, buf, len); + write_len = tape_write(m_fd, buf, len); } else { - write_len = ::write(fd, buf, len); + write_len = ::write(m_fd, buf, len); } last_tick = get_timer_count(); @@ -2371,7 +2371,7 @@ void set_os_device_parameters(DCR *dcr) mt_com.mt_op = MTSETBLK; mt_com.mt_count = 0; Dmsg0(050, "Set block size to zero\n"); - if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) { dev->clrerror(MTSETBLK); } } @@ -2387,7 +2387,7 @@ void set_os_device_parameters(DCR *dcr) mt_com.mt_count |= MT_ST_FAST_MTEOM; } Dmsg0(050, "MTSETDRVBUFFER\n"); - if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) { dev->clrerror(MTSETDRVBUFFER); } } @@ -2401,13 +2401,13 @@ void set_os_device_parameters(DCR *dcr) dev->min_block_size == 0) { /* variable block mode */ mt_com.mt_op = MTSETBSIZ; mt_com.mt_count = 0; - if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) { dev->clrerror(MTSETBSIZ); } /* Get notified at logical end of tape */ mt_com.mt_op = MTEWARN; mt_com.mt_count = 1; - if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) { dev->clrerror(MTEWARN); } } @@ -2420,7 +2420,7 @@ void set_os_device_parameters(DCR *dcr) dev->min_block_size == 0) { /* variable block mode */ mt_com.mt_op = MTSETBSIZ; mt_com.mt_count = 0; - if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) { dev->clrerror(MTSETBSIZ); } } @@ -2432,7 +2432,7 @@ void set_os_device_parameters(DCR *dcr) } else { neof = 1; } - if (ioctl(dev->fd, MTIOCSETEOTMODEL, (caddr_t)&neof) < 0) { + if (ioctl(dev->fd(), MTIOCSETEOTMODEL, (caddr_t)&neof) < 0) { berrno be; dev->dev_errno = errno; /* save errno */ Mmsg2(dev->errmsg, _("Unable to set eotmodel on device %s: ERR=%s\n"), @@ -2449,7 +2449,7 @@ void set_os_device_parameters(DCR *dcr) dev->min_block_size == 0) { /* variable block mode */ mt_com.mt_op = MTSRSZ; mt_com.mt_count = 0; - if (tape_ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + if (tape_ioctl(dev->fd(), MTIOCTOP, (char *)&mt_com) < 0) { dev->clrerror(MTSRSZ); } } @@ -2461,7 +2461,7 @@ static bool dev_get_os_pos(DEVICE *dev, struct mtget *mt_stat) { Dmsg0(050, "dev_get_os_pos\n"); return dev->has_cap(CAP_MTIOCGET) && - tape_ioctl(dev->fd, MTIOCGET, (char *)mt_stat) == 0 && + tape_ioctl(dev->fd(), MTIOCGET, (char *)mt_stat) == 0 && mt_stat->mt_fileno >= 0; } diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 688eee3c14..0638e55a1c 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -202,6 +202,8 @@ class DCR; /* forward reference */ * that device and effects all jobs using the device. */ class DEVICE { +private: + int m_fd; /* file descriptor */ public: dlist *attached_dcrs; /* attached DCR list */ pthread_mutex_t mutex; /* access control */ @@ -218,7 +220,6 @@ public: /* New access control in process of being implemented */ brwlock_t lock; /* New mutual exclusion lock */ - int fd; /* file descriptor */ int capabilities; /* capabilities mask */ int state; /* state mask */ int dev_errno; /* Our own errno */ @@ -289,7 +290,7 @@ public: uint64_t DevReadBytes; /* Methods */ - btime_t get_timer_count(); /* return the last timer interval (ms) */ + btime_t get_timer_count(); /* return the last timer interval (ms) */ int has_cap(int cap) const { return capabilities & cap; } void clear_cap(int cap) { capabilities &= ~cap; } @@ -302,7 +303,7 @@ public: int is_fifo() const { return dev_type == B_FIFO_DEV; } int is_dvd() const { return dev_type == B_DVD_DEV; } int is_prog() const { return dev_type == B_PROG_DEV; } - int is_open() const { return fd >= 0; } + int is_open() const { return m_fd >= 0; } int is_offline() const { return state & ST_OFFLINE; } int is_labeled() const { return state & ST_LABEL; } int is_mounted() const { return state & ST_MOUNTED; } @@ -358,7 +359,7 @@ public: void clear_offline() { state &= ~ST_OFFLINE; }; void clear_eot() { state &= ~ST_EOT; }; void clear_eof() { state &= ~ST_EOF; }; - void clear_opened() { fd = -1; }; + void clear_opened() { m_fd = -1; }; void clear_mounted() { state &= ~ST_MOUNTED; }; void clear_media() { state &= ~ST_MEDIA; }; void clear_short_block() { state &= ~ST_SHORT; }; @@ -373,8 +374,8 @@ public: bool truncate(DCR *dcr); /* in dev.c */ int open(DCR *dcr, int mode); /* in dev.c */ void term(void); /* in dev.c */ - ssize_t read(void *buf, size_t len); /* in dev.c */ - ssize_t write(const void *buf, size_t len); /* in dev.c */ + ssize_t read(void *buf, size_t len); /* in dev.c */ + ssize_t write(const void *buf, size_t len); /* in dev.c */ bool rewind(DCR *dcr); /* in dev.c */ bool mount(int timeout); /* in dev.c */ bool unmount(int timeout); /* in dev.c */ @@ -402,6 +403,7 @@ public: uint32_t get_block() const { return block_num; }; const char *print_blocked() const; /* in dev.c */ bool is_blocked() const { return dev_blocked != BST_NOT_BLOCKED; }; + int fd() const { return m_fd; }; private: bool do_mount(int mount, int timeout); /* in dev.c */ diff --git a/bacula/src/stored/dvd.c b/bacula/src/stored/dvd.c index 8cb740e3c0..a739e320a1 100644 --- a/bacula/src/stored/dvd.c +++ b/bacula/src/stored/dvd.c @@ -318,7 +318,7 @@ int dvd_open_next_part(DCR *dcr) if (dev->can_append() && (dev->part > dev->num_dvd_parts) && (dev->part_size == 0)) { Dmsg0(29, "open_next_part exited immediately (dev->part_size == 0).\n"); - return dev->fd; + return dev->fd(); } dev->close_part(dcr); /* close current part */ @@ -392,7 +392,7 @@ int dvd_open_next_part(DCR *dcr) } dev->set_labeled(); /* all next parts are "labeled" */ - return dev->fd; + return dev->fd(); } /* @@ -435,7 +435,7 @@ boffset_t lseek_dvd(DCR *dcr, boffset_t offset, int whence) boffset_t pos; char ed1[50], ed2[50]; - Dmsg5(400, "Enter lseek_dvd fd=%d off=%s w=%d part=%d nparts=%d\n", dev->fd, + Dmsg5(400, "Enter lseek_dvd fd=%d off=%s w=%d part=%d nparts=%d\n", dev->fd(), edit_int64(offset, ed1), whence, dev->part, dev->num_dvd_parts); switch(whence) { @@ -447,9 +447,9 @@ boffset_t lseek_dvd(DCR *dcr, boffset_t offset, int whence) (uint64_t)offset < dev->part_start+dev->part_size) { /* We are staying in the current part, just seek */ #if defined(HAVE_WIN32) - pos = _lseeki64(dev->fd, offset-dev->part_start, SEEK_SET); + pos = _lseeki64(dev->fd(), offset-dev->part_start, SEEK_SET); #else - pos = lseek(dev->fd, offset-dev->part_start, SEEK_SET); + pos = lseek(dev->fd(), offset-dev->part_start, SEEK_SET); #endif if (pos < 0) { return pos; @@ -486,7 +486,7 @@ boffset_t lseek_dvd(DCR *dcr, boffset_t offset, int whence) break; case SEEK_CUR: Dmsg1(400, "lseek_dvd SEEK_CUR to %s\n", edit_int64(offset, ed1)); - if ((pos = lseek(dev->fd, (off_t)0, SEEK_CUR)) < 0) { + if ((pos = lseek(dev->fd(), (off_t)0, SEEK_CUR)) < 0) { Dmsg0(400, "Seek error.\n"); return pos; } @@ -518,7 +518,7 @@ boffset_t lseek_dvd(DCR *dcr, boffset_t offset, int whence) * right part number, simply seek */ if (dev->is_part_spooled() && dev->part > dev->num_dvd_parts) { - if ((pos = lseek(dev->fd, (off_t)0, SEEK_END)) < 0) { + if ((pos = lseek(dev->fd(), (off_t)0, SEEK_END)) < 0) { return pos; } else { Dmsg1(400, "lseek_dvd SEEK_END returns %s\n", diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index b600a66ffc..da6f9908ad 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -419,7 +419,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) if (dev->open(dcr, OPEN_READ_WRITE) < 0) { return false; } - Dmsg2(190, "set append found freshly labeled volume. fd=%d dev=%x\n", dev->fd, 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)) { @@ -471,7 +471,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) } /* Attempt write to check write permission */ - Dmsg1(200, "Attempt to write to device fd=%d.\n", dev->fd); + 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(), dev->print_errmsg()); diff --git a/bacula/src/version.h b/bacula/src/version.h index 848c1621d1..3c2c061141 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.1.4" -#define BDATE "16 February 2007" -#define LSMDATE "16Feb07" +#define BDATE "18 February 2007" +#define LSMDATE "18Feb07" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" #define BYEAR "2007" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index 8899e16a4e..a8908f357b 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -1,6 +1,14 @@ Technical notes on version 2.1 General: +18Feb07 +kes Make DEVICE fd private. Its new name is m_fd, and can be + obtained with dev->fd() outside the class. This is the + first of many DEVICE members to be made private. +kes Implement Michael Renner's idea on having a virtual disk + changer. I made some minor modifications (e.g. I did not + implement the Virtual Changer directive, but simply set + the Changer Command to an empty string. 17Feb07 kes Implement a BSOCK send() method that writes the whole record in a single write() request rather than in two.