From 9c47eb07a54ffa760db9fa2645271910ac38d323 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 18 Apr 2012 09:57:06 +0200 Subject: [PATCH] Change dev->open() to return bool --- bacula/src/stored/acquire.c | 2 +- bacula/src/stored/bcopy.c | 4 ++-- bacula/src/stored/btape.c | 4 ++-- bacula/src/stored/dev.c | 14 +++++++------- bacula/src/stored/dev.h | 2 +- bacula/src/stored/device.c | 6 +++--- bacula/src/stored/dircmd.c | 6 +++--- bacula/src/stored/dvd.c | 26 +++----------------------- bacula/src/stored/label.c | 12 ++++++------ bacula/src/stored/mount.c | 8 ++++---- 10 files changed, 32 insertions(+), 52 deletions(-) diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 96bdc062da..035b9114b4 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -233,7 +233,7 @@ bool acquire_device_for_read(DCR *dcr) * If it is a tape, it checks the volume name */ Dmsg1(100, "bstored: open vol=%s\n", dcr->VolumeName); - if (dev->open(dcr, OPEN_READ_ONLY) < 0) { + if (!dev->open(dcr, OPEN_READ_ONLY)) { if (!dev->poll) { Jmsg3(jcr, M_WARNING, 0, _("Read open device %s Volume \"%s\" failed: ERR=%s\n"), dev->print_name(), dcr->VolumeName, dev->bstrerror()); diff --git a/bacula/src/stored/bcopy.c b/bacula/src/stored/bcopy.c index 72398c2180..d53129baae 100644 --- a/bacula/src/stored/bcopy.c +++ b/bacula/src/stored/bcopy.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2002-2010 Free Software Foundation Europe e.V. + Copyright (C) 2002-2012 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -200,7 +200,7 @@ int main (int argc, char *argv[]) Dmsg0(100, "About to acquire device for writing\n"); /* For we must now acquire the device for writing */ out_dev->r_dlock(); - if (out_dev->open(out_jcr->dcr, OPEN_READ_WRITE) < 0) { + if (!out_dev->open(out_jcr->dcr, OPEN_READ_WRITE)) { Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), out_dev->errmsg); out_dev->dunlock(); exit(1); diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 03c70b3c11..a6afadd4b1 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2011 Free Software Foundation Europe e.V. + Copyright (C) 2000-2012 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -469,7 +469,7 @@ static bool open_the_device() block = new_block(dev); dev->r_dlock(); Dmsg1(200, "Opening device %s\n", dcr->VolumeName); - if (dev->open(dcr, OPEN_READ_WRITE) < 0) { + if (!dev->open(dcr, OPEN_READ_WRITE)) { Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg); ok = false; goto bail_out; diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 8bf46d396a..7c44a9f62d 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -344,8 +344,8 @@ ssize_t DEVICE::d_write(int fd, const void *buffer, size_t count) * Open the device with the operating system and * initialize buffer pointers. * - * Returns: -1 on error - * fd on success + * Returns: true on success + * false on error * * Note, for a tape, the VolName is the name we give to the * volume (not really used here), but for a file, the @@ -353,13 +353,13 @@ ssize_t DEVICE::d_write(int fd, const void *buffer, size_t count) * In the case of a file, the full name is the device name * (archive_name) with the VolName concatenated. */ -int +bool DEVICE::open(DCR *dcr, int omode) { int preserve = 0; if (is_open()) { if (openmode == omode) { - return m_fd; + return true; } else { d_close(m_fd); clear_opened(); @@ -387,7 +387,7 @@ DEVICE::open(DCR *dcr, int omode) } state |= preserve; /* reset any important state info */ Dmsg2(100, "preserve=0x%x fd=%d\n", preserve, m_fd); - return m_fd; + return m_fd >= 0; } void DEVICE::set_mode(int new_mode) @@ -567,8 +567,8 @@ void DEVICE::open_file_device(DCR *dcr, int omode) Mmsg2(errmsg, _("Could not open: %s, ERR=%s\n"), archive_name.c_str(), be.bstrerror()); Dmsg1(100, "open failed: %s", errmsg); -// Jmsg1(NULL, M_WARNING, 0, "%s", errmsg); - } else { + } + if (m_fd >= 0) { dev_errno = 0; file = 0; file_addr = 0; diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index d6d1004ee5..75473e9133 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -409,7 +409,7 @@ public: void clear_volhdr(); /* in dev.c */ void close(); /* in dev.c */ void close_part(DCR *dcr); /* in dev.c */ - int open(DCR *dcr, int mode); /* in dev.c */ + bool 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 */ diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 7cee4a049c..7324864371 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2010 Free Software Foundation Europe e.V. + Copyright (C) 2000-2012 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -294,7 +294,7 @@ bool first_open_device(DCR *dcr) mode = OPEN_READ_ONLY; } Dmsg0(129, "Opening device.\n"); - if (dev->open(dcr, mode) < 0) { + if (!dev->open(dcr, mode)) { Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg); ok = false; goto bail_out; @@ -319,7 +319,7 @@ bool open_device(DCR *dcr) } else { mode = OPEN_READ_WRITE; } - if (dev->open(dcr, mode) < 0) { + if (!dev->open(dcr, mode)) { /* If polling, ignore the error */ /* If DVD, also ignore the error, very often you cannot open the device * (when there is no DVD, or when the one inserted is a wrong one) */ diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 65fcefed25..702c2490c1 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -477,7 +477,7 @@ static void label_volume_if_ok(DCR *dcr, char *oldname, } /* Set old volume name for open if relabeling */ dcr->setVolCatName(volname); - if (dev->open(dcr, mode) < 0) { + if (!dev->open(dcr, mode)) { dir->fsend(_("3910 Unable to open device \"%s\": ERR=%s\n"), dev->print_name(), dev->bstrerror()); goto bail_out; @@ -694,7 +694,7 @@ static bool mount_cmd(JCR *jcr) try_autoload_device(jcr, dcr, slot, ""); } /* We freed the device, so reopen it and wake any waiting threads */ - if (dev->open(dcr, OPEN_READ_ONLY) < 0) { + if (!dev->open(dcr, OPEN_READ_ONLY)) { dir->fsend(_("3901 Unable to open device \"%s\": ERR=%s\n"), dev->print_name(), dev->bstrerror()); if (dev->blocked() == BST_UNMOUNTED) { @@ -752,7 +752,7 @@ static bool mount_cmd(JCR *jcr) dev->print_name()); } } else if (dev->is_tape()) { - if (dev->open(dcr, OPEN_READ_ONLY) < 0) { + if (!dev->open(dcr, OPEN_READ_ONLY)) { dir->fsend(_("3901 Unable to open device \"%s\": ERR=%s\n"), dev->print_name(), dev->bstrerror()); break; diff --git a/bacula/src/stored/dvd.c b/bacula/src/stored/dvd.c index b0c7656a67..5b8ea26c9f 100644 --- a/bacula/src/stored/dvd.c +++ b/bacula/src/stored/dvd.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2005-2011 Free Software Foundation Europe e.V. + Copyright (C) 2005-2012 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -360,33 +360,13 @@ int dvd_open_next_part(DCR *dcr) return -1; } } - -#ifdef neeeded - Dmsg2(400, "num_dvd_parts=%d part=%d\n", dev->num_dvd_parts, dev->part); - make_spooled_dvd_filename(dev, archive_name); /* makes spool name */ - - /* Check if the next part exists in spool directory . */ - Dmsg1(100, "Check if part on spool: %s\n", archive_name.c_str()); - if ((stat(archive_name.c_str(), &buf) == 0) || (errno != ENOENT)) { - Dmsg1(29, "======= Part %s is in the way, deleting it...\n", archive_name.c_str()); - /* Then try to unlink it */ - if (unlink(archive_name.c_str()) < 0) { - berrno be; - dev->set_part_spooled(false); - dev->dev_errno = errno; - Mmsg2(dev->errmsg, _("open_next_part can't unlink existing part %s, ERR=%s\n"), - archive_name.c_str(), be.bstrerror()); - return -1; - } - } -#endif } Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->getVolCatName(), dev->openmode); /* Open next part. Note, this sets part_size for part opened. */ - if (dev->open(dcr, OPEN_READ_ONLY) < 0) { + if (!dev->open(dcr, OPEN_READ_ONLY)) { return -1; } dev->set_labeled(); /* all next parts are "labeled" */ @@ -415,7 +395,7 @@ static bool dvd_open_first_part(DCR *dcr, int mode) dev->part = 1; dev->part_start = 0; - if (dev->open(dcr, mode) < 0) { + if (!dev->open(dcr, mode)) { Dmsg0(400, "open dev() failed\n"); return false; } diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 9fd0c3df83..4590a55e87 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2010 Free Software Foundation Europe e.V. + Copyright (C) 2000-2012 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -79,7 +79,7 @@ int read_dev_volume_label(DCR *dcr) dev->VolHdr.VolumeName[0]?dev->VolHdr.VolumeName:"*NULL*"); if (!dev->is_open()) { - if (dev->open(dcr, OPEN_READ_ONLY) < 0) { + if (!dev->open(dcr, OPEN_READ_ONLY)) { return VOL_IO_ERROR; } } @@ -322,9 +322,9 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, dev->setVolCatName(VolName); dcr->setVolCatName(VolName); Dmsg1(150, "New VolName=%s\n", VolName); - if (dev->open(dcr, OPEN_READ_WRITE) < 0) { + if (!dev->open(dcr, OPEN_READ_WRITE)) { /* If device is not tape, attempt to create it */ - if (dev->is_tape() || dev->open(dcr, CREATE_READ_WRITE) < 0) { + if (dev->is_tape() || !dev->open(dcr, CREATE_READ_WRITE)) { Jmsg3(dcr->jcr, M_WARNING, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"), dev->print_name(), dcr->VolumeName, dev->bstrerror()); goto bail_out; @@ -425,7 +425,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) DEVICE *dev = dcr->dev; JCR *jcr = dcr->jcr; - if (dev->open(dcr, OPEN_READ_WRITE) < 0) { + if (!dev->open(dcr, OPEN_READ_WRITE)) { Jmsg3(jcr, M_WARNING, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"), dev->print_name(), dcr->VolumeName, dev->bstrerror()); return false; @@ -463,7 +463,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) dev->print_name(), dev->print_errmsg()); return false; } - if (dev->open(dcr, OPEN_READ_WRITE) < 0) { + if (!dev->open(dcr, OPEN_READ_WRITE)) { Jmsg2(jcr, M_FATAL, 0, _("Failed to re-open DVD after truncate on device %s: ERR=%s\n"), dev->print_name(), dev->print_errmsg()); diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 782181a599..c77da4c256 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2002-2010 Free Software Foundation Europe e.V. + Copyright (C) 2002-2012 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -188,10 +188,10 @@ mount_next_vol: mode = OPEN_READ_WRITE; } /* Try autolabel if enabled */ - if (dev->open(dcr, mode) < 0) { + if (!dev->open(dcr, mode)) { try_autolabel(false); /* try to create a new volume label */ } - while (dev->open(dcr, mode) < 0) { + while (!dev->open(dcr, mode)) { Dmsg1(150, "open_device failed: ERR=%s\n", dev->bstrerror()); if ((dev->is_file() && dev->is_removable()) || dev->is_dvd()) { bool ok = true; @@ -202,7 +202,7 @@ mount_next_vol: } } if (ok && dev->scan_dir_for_volume(dcr)) { - if (dev->open(dcr, mode) >= 0) { + if (dev->open(dcr, mode)) { break; /* got a valid volume */ } } -- 2.39.5