From ceda1ea2e5742ad8ad15ec0780316d11693eb708 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 26 Feb 2005 11:28:03 +0000 Subject: [PATCH] - Clean up drive reservation system. Add more sanity checks. - Implement a few more methods for the DEVICE class in SD. - Add latex directories to make clean - move DEV_BSIZE to B_DEV_BSIZE to avoid conflicts with certain header files (FreeBSD). git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1845 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/Makefile.in | 6 ++--- bacula/src/baconfig.h | 13 +++++++---- bacula/src/lib/bnet_server.c | 27 +++++++++++----------- bacula/src/stored/acquire.c | 43 +++++++++++++++++++++++++----------- bacula/src/stored/append.c | 4 ++-- bacula/src/stored/block.c | 4 ++++ bacula/src/stored/btape.c | 4 ++-- bacula/src/stored/dev.h | 10 +++++++++ bacula/src/stored/stored.c | 4 ++-- bacula/src/version.h | 4 ++-- 10 files changed, 77 insertions(+), 42 deletions(-) diff --git a/bacula/Makefile.in b/bacula/Makefile.in index a5b99c1e03..02fbdadc4e 100755 --- a/bacula/Makefile.in +++ b/bacula/Makefile.in @@ -176,7 +176,7 @@ Makefiles: chmod 755 make_catalog_backup delete_catalog_backup) clean: - @for I in ${all_subdirs}; \ + @for I in ${all_subdirs} doc/latex doc/latex-fr; \ do (cd $$I; echo "==>Entering directory `pwd`"; ${MAKE} $@ || exit 1); done @(cd platforms; echo "==>Entering directory `pwd`"; ${MAKE} $@ || exit 1) @$(RMF) *~ 1 2 3 core core.* config.guess console.log console.sum @@ -187,7 +187,7 @@ clean: # clean for distribution distclean: - @for I in $(all_subdirs); do (cd $$I; $(MAKE) $@ || exit 1); done + @for I in $(all_subdirs) doc/latex doc/latex-fr; do (cd $$I; $(MAKE) $@ || exit 1); done @for I in $(all_subdirs); do (cd $$I; $(RMF) startit stopit btraceback); done @(cd $(srcdir); $(RMF) *~ config.cache config.h config.log config.status config.out) @(cd $(srcdir); $(RMF) Makefile autoconf/Make.common) @@ -203,7 +203,7 @@ distclean: @$(RMF) -r CVS src/gnome-console/CVS src/tconsole/CVS devclean: - @for I in $(all_subdirs); do (cd $$I; $(MAKE) $@ || exit 1); done + @for I in $(all_subdirs) doc/latex doc/latex-fr; do (cd $$I; $(MAKE) $@ || exit 1); done @for I in $(all_subdirs); do (cd $$I; $(RMF) startit stopit btraceback); done @(cd $(srcdir); $(RMF) *~ config.cache config.h config.log config.status config.out) @(cd $(srcdir); $(RMF) Makefile autoconf/Make.common) diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index 8db3edca0c..9ce9c4a305 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -86,12 +86,17 @@ /* All tape operations MUST be a multiple of this */ #define TAPE_BSIZE 1024 -#if !defined(DEV_BSIZE) && defined(BSIZE) -#define DEV_BSIZE BSIZE + +#ifdef DEV_BSIZE +#define B_DEV_BSIZE DEV_BSIZE +#endif + +#if !defined(B_DEV_BSIZE) & defined(BSIZE) +#define B_DEV_BSIZE BSIZE #endif -#ifndef DEV_BSIZE -#define DEV_BSIZE 512 +#ifndef B_DEV_BSIZE +#define B_DEV_BSIZE 512 #endif /* diff --git a/bacula/src/lib/bnet_server.c b/bacula/src/lib/bnet_server.c index 30e00c3eea..c2cad7deaa 100644 --- a/bacula/src/lib/bnet_server.c +++ b/bacula/src/lib/bnet_server.c @@ -25,7 +25,6 @@ */ #include "bacula.h" -#undef DEV_BSIZE #include #include #include @@ -99,7 +98,7 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, if (tlog <= 0) { berrno be; char curbuf[256]; - Emsg3(M_ABORT, 0, _("Cannot open stream socket. ERR=%s. Current %s All %s\n"), + Emsg3(M_ABORT, 0, _("Cannot open stream socket. ERR=%s. Current %s All %s\n"), be.strerror(), p->build_address_str(curbuf, sizeof(curbuf)), build_addresses_str(addrs, allbuf, sizeof(allbuf))); @@ -112,7 +111,7 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, if (setsockopt(fd_ptr->fd, SOL_SOCKET, SO_REUSEADDR, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) { berrno be; - Emsg1(M_WARNING, 0, _("Cannot set SO_REUSEADDR on socket: %s\n"), + Emsg1(M_WARNING, 0, _("Cannot set SO_REUSEADDR on socket: %s\n"), be.strerror()); } @@ -122,12 +121,12 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, berrno be; if (tlog <= 0) { tlog = 2 * 60; /* Complain every 2 minutes */ - Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s. Retrying ...\n"), + Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s. Retrying ...\n"), ntohs(fd_ptr->port), be.strerror()); } bmicrosleep(5, 0); if (--tmax <= 0) { - Emsg2(M_ABORT, 0, _("Cannot bind port %d: ERR=%s.\n"), ntohs(fd_ptr->port), + Emsg2(M_ABORT, 0, _("Cannot bind port %d: ERR=%s.\n"), ntohs(fd_ptr->port), be.strerror()); } } @@ -162,7 +161,7 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, close(fd_ptr->fd); free((void *)fd_ptr); } - Emsg1(M_FATAL, 0, _("Error in select: %s\n"), be.strerror()); + Emsg1(M_FATAL, 0, _("Error in select: %s\n"), be.strerror()); break; } @@ -198,7 +197,7 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, if (setsockopt(newsockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) { berrno be; - Emsg1(M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"), + Emsg1(M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"), be.strerror()); } @@ -207,16 +206,16 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, sockaddr_to_ascii(&cli_addr, buf, sizeof(buf)); V(mutex); BSOCK *bs; - bs = init_bsock(NULL, newsockfd, "client", buf, fd_ptr->port, &cli_addr); + bs = init_bsock(NULL, newsockfd, "client", buf, fd_ptr->port, &cli_addr); if (bs == NULL) { - Jmsg0(NULL, M_ABORT, 0, _("Could not create client BSOCK.\n")); + Jmsg0(NULL, M_ABORT, 0, _("Could not create client BSOCK.\n")); } /* Queue client to be served */ if ((stat = workq_add(client_wq, (void *)bs, NULL, 0)) != 0) { berrno be; be.set_errno(stat); - Jmsg1(NULL, M_ABORT, 0, _("Could not add job to client queue: ERR=%s\n"), + Jmsg1(NULL, M_ABORT, 0, _("Could not add job to client queue: ERR=%s\n"), be.strerror()); } } @@ -254,7 +253,7 @@ BSOCK *bnet_bind(int port) } if (tlog <= 0) { tlog = 2 * 60; - Emsg1(M_ERROR, 0, _("Cannot open stream socket: %s\n"), strerror(errno)); + Emsg1(M_ERROR, 0, _("Cannot open stream socket: %s\n"), strerror(errno)); } bmicrosleep(60, 0); } @@ -283,7 +282,7 @@ BSOCK *bnet_bind(int port) } if (tlog <= 0) { tlog = 2 * 60; - Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s: retrying ...\n"), port, + Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s: retrying ...\n"), port, be.strerror()); } bmicrosleep(5, 0); @@ -325,7 +324,7 @@ BSOCK *bnet_accept(BSOCK * bsock, char *who) errno = 0; continue; } - Emsg1(M_FATAL, 0, _("Error in select: %s\n"), strerror(errno)); + Emsg1(M_FATAL, 0, _("Error in select: %s\n"), strerror(errno)); newsockfd = -1; break; } @@ -376,7 +375,7 @@ BSOCK *bnet_accept(BSOCK * bsock, char *who) return NULL; } else { if (caller == NULL) { - caller = "unknown"; + caller = "unknown"; } len = strlen(caller) + strlen(who) + 3; buf = (char *)malloc(len); diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 599af52a2d..88e88c3e83 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -70,6 +70,11 @@ void free_dcr(DCR *dcr) if (dcr->reserved_device) { lock_device(dev); dev->num_writers--; + if (dev->num_writers < 0) { + Jmsg1(dcr->jcr, M_ERROR, 0, _("Hey! num_writers=%d!!!!\n"), dev->num_writers); + dev->num_writers = 0; + dcr->reserved_device = false; + } unlock_device(dev); } @@ -111,7 +116,7 @@ bool reserve_device_for_read(JCR *jcr, DEVICE *dev) block_device(dev, BST_DOING_ACQUIRE); unlock_device(dev); - if (dev->can_read() || dev->num_writers > 0) { + if (dev->is_busy()) { Jmsg2(jcr, M_FATAL, 0, _("Device %s is busy. Job %d canceled.\n"), dev_name(dev), jcr->JobId); goto get_out; @@ -119,8 +124,8 @@ bool reserve_device_for_read(JCR *jcr, DEVICE *dev) if (!dcr) { dcr = new_dcr(jcr, dev); } - dev->state &= ~ST_APPEND; /* clear any previous append mode */ - dev->state |= ST_READ; /* set read mode */ + dev->clear_append(); + dev->set_read(); ok = true; get_out: @@ -162,6 +167,12 @@ DCR *acquire_device_for_read(JCR *jcr, DEVICE *dev) dev->is_labeled(); tape_initially_mounted = tape_previously_mounted; + if (dev->num_writers > 0) { + Jmsg2(jcr, M_FATAL, 0, _("Num_writers=%d not zero. Job %d canceled.\n"), + dev->num_writers, jcr->JobId); + goto get_out; + } + /* Find next Volume, if any */ vol = jcr->VolList; if (!vol) { @@ -183,7 +194,7 @@ DCR *acquire_device_for_read(JCR *jcr, DEVICE *dev) dev->num_parts = dcr->VolCatInfo.VolCatParts; for (i=0; i<5; i++) { - dev->state &= ~ST_LABEL; /* force reread of label */ + dev->clear_label(); /* force reread of label */ if (job_canceled(jcr)) { Mmsg1(dev->errmsg, _("Job %d canceled.\n"), jcr->JobId); goto get_out; /* error return */ @@ -285,9 +296,8 @@ default_path: goto get_out; } - dev->state &= ~ST_APPEND; /* clear any previous append mode */ - dev->num_writers = 0; - dev->state |= ST_READ; /* set read mode */ + dev->clear_append(); + dev->set_read(); set_jcr_job_status(jcr, JS_Running); dir_send_job_status(jcr); Jmsg(jcr, M_INFO, 0, _("Ready to read from volume \"%s\" on device %s.\n"), @@ -330,10 +340,10 @@ bool reserve_device_for_append(JCR *jcr, DEVICE *dev) goto get_out; } Dmsg1(190, "reserve_append device is %s\n", dev_is_tape(dev)?"tape":"disk"); - if (dev->can_append() || dev->num_writers > 0) { + if (dev->can_append() || dev->num_writers > 0 || dev->reserved_device) { Dmsg0(190, "device already in append.\n"); /* - * Device already in append mode + * Device already in append mode or reserved for write * * Check if we have the right Volume mounted * OK if current volume info OK @@ -477,7 +487,7 @@ DCR *acquire_device_for_append(JCR *jcr, DEVICE *dev) } } - dev->num_writers++; + dev->num_writers++; /* we are now a writer */ if (jcr->NumVolumes == 0) { jcr->NumVolumes = 1; } @@ -508,8 +518,15 @@ bool release_device(JCR *jcr) DEVICE *dev = dcr->dev; lock_device(dev); Dmsg1(100, "release_device device is %s\n", dev_is_tape(dev)?"tape":"disk"); - if (dev_state(dev, ST_READ)) { - dev->state &= ~ST_READ; /* clear read bit */ + + /* if device is reserved, job never started, so release the reserve here */ + if (dcr->reserved_device) { + dev->reserved_device--; + dcr->reserved_device = false; + } + + if (dev->can_read()) { + dev->clear_read(); /* clear read bit */ if (!dev_is_tape(dev) || !dev_cap(dev, CAP_ALWAYSOPEN)) { offline_or_rewind_dev(dev); close_dev(dev); @@ -536,7 +553,7 @@ bool release_device(JCR *jcr) dir_update_volume_info(dcr, false); /* send Volume info to Director */ } - if (!dev->num_writers && (!dev->is_tape() || !dev_cap(dev, CAP_ALWAYSOPEN))) { + if (dev->num_writers == 0 && dev->is_tape() && !dev_cap(dev, CAP_ALWAYSOPEN)) { offline_or_rewind_dev(dev); close_dev(dev); } diff --git a/bacula/src/stored/append.c b/bacula/src/stored/append.c index 59f8502d31..95c05cdb0b 100644 --- a/bacula/src/stored/append.c +++ b/bacula/src/stored/append.c @@ -196,8 +196,8 @@ bool do_append_data(JCR *jcr) if (!write_block_to_device(dcr)) { Dmsg2(90, "Got write_block_to_dev error on device %s. %s\n", dev_name(dev), strerror_dev(dev)); - Jmsg(jcr, M_FATAL, 0, _("Fatal device error: ERR=%s\n"), - strerror_dev(dev)); + Jmsg2(jcr, M_FATAL, 0, _("Fatal append error on device %s: ERR=%s\n"), + dev_name(dev), strerror_dev(dev)); ok = false; break; } diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 9ccad4999e..64cb165864 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -481,17 +481,21 @@ bool write_block_to_dev(DCR *dcr) if (weof_dev(dev, 1) != 0) { /* write eof */ Dmsg0(190, "WEOF error in max file size.\n"); + Jmsg(jcr, M_FATAL, 0, _("Unable to write EOF. ERR=%s\n"), + strerror_dev(dev)); terminate_writing_volume(dcr); dev->dev_errno = ENOSPC; return false; } if (!do_new_file_bookkeeping(dcr)) { + /* Error message already sent */ return false; } } if (!do_dvd_size_checks(dcr)) { + /* Error message already sent */ return false; } diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index c59f8dfef2..c6e5a09eda 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -149,9 +149,9 @@ int main(int margc, char *margv[]) char buf[1000]; /* Sanity checks */ - if (TAPE_BSIZE % DEV_BSIZE != 0 || TAPE_BSIZE / DEV_BSIZE == 0) { + if (TAPE_BSIZE % B_DEV_BSIZE != 0 || TAPE_BSIZE / B_DEV_BSIZE == 0) { Emsg2(M_ABORT, 0, "Tape block size (%d) not multiple of system size (%d)\n", - TAPE_BSIZE, DEV_BSIZE); + TAPE_BSIZE, B_DEV_BSIZE); } if (TAPE_BSIZE != (1 << (ffs(TAPE_BSIZE)-1))) { Emsg1(M_ABORT, 0, "Tape block size (%d) is not a power of 2\n", TAPE_BSIZE); diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 6c7fde3ff5..0a274b2890 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -258,6 +258,11 @@ public: const char *archive_name() const; void set_eof(); void set_eot(); + void set_append(); + void set_read(); + void clear_append(); + void clear_read(); + void clear_label(); }; /* Note, these return int not bool! */ @@ -272,6 +277,11 @@ inline int DEVICE::at_eof() const { return state & ST_EOF; } inline int DEVICE::at_eot() const { return state & ST_EOT; } inline int DEVICE::can_append() const { return state & ST_APPEND; } inline int DEVICE::can_read() const { return state & ST_READ; } +inline void DEVICE::set_append() { state |= ST_APPEND; } +inline void DEVICE::set_read() { state |= ST_READ; } +inline void DEVICE::clear_append() { state &= ~ST_APPEND; } +inline void DEVICE::clear_read() { state &= ~ST_READ; } +inline void DEVICE::clear_label() { state &= ~ST_LABEL; } inline const char *DEVICE::strerror() const { return errmsg; } inline const char *DEVICE::archive_name() const { return dev_name; } diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index 27766d8c20..baea8fd55f 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -103,9 +103,9 @@ int main (int argc, char *argv[]) daemon_start_time = time(NULL); /* Sanity checks */ - if (TAPE_BSIZE % DEV_BSIZE != 0 || TAPE_BSIZE / DEV_BSIZE == 0) { + if (TAPE_BSIZE % B_DEV_BSIZE != 0 || TAPE_BSIZE / B_DEV_BSIZE == 0) { Emsg2(M_ABORT, 0, "Tape block size (%d) not multiple of system size (%d)\n", - TAPE_BSIZE, DEV_BSIZE); + TAPE_BSIZE, B_DEV_BSIZE); } if (TAPE_BSIZE != (1 << (ffs(TAPE_BSIZE)-1))) { Emsg1(M_ABORT, 0, "Tape block size (%d) is not a power of 2\n", TAPE_BSIZE); diff --git a/bacula/src/version.h b/bacula/src/version.h index ff33c08bd1..dfc011e914 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #undef VERSION #define VERSION "1.37.4" -#define BDATE "24 February 2005" -#define LSMDATE "24Feb05" +#define BDATE "26 February 2005" +#define LSMDATE "26Feb05" /* Debug flags */ #undef DEBUG -- 2.39.2