From: Kern Sibbald Date: Tue, 16 Aug 2005 20:51:16 +0000 (+0000) Subject: - Fix bug that missed drive=nn specification. X-Git-Tag: Release-1.38.0~186 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b88931200834b9ced689971786f3055f2f1a387c;p=bacula%2Fbacula - Fix bug that missed drive=nn specification. - Eliminate nonblocking kludge in heartbeat of FD as it caused high CPU usage. - Pickup loaded slot when doing open() of tape drive. - Make autochanger reservation code go through full list first pass until exact match found. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2318 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kes-1.37 b/bacula/kes-1.37 index 995ac9f0b5..fb4457aae4 100644 --- a/bacula/kes-1.37 +++ b/bacula/kes-1.37 @@ -4,6 +4,13 @@ General: Changes to 1.37.36: +16Aug05 +- Fix bug that missed drive=nn specification. +- Eliminate nonblocking kludge in heartbeat of FD as + it caused high CPU usage. +- Pickup loaded slot when doing open() of tape drive. +- Make autochanger reservation code go through full list + first pass until exact match found. 15Aug05 - Fix how FileSet is saved in job record to correct continual Full save. diff --git a/bacula/src/dird/ua_select.c b/bacula/src/dird/ua_select.c index 2b576d5f34..e043fdfe3b 100644 --- a/bacula/src/dird/ua_select.c +++ b/bacula/src/dird/ua_select.c @@ -762,14 +762,10 @@ STORE *get_storage_resource(UAContext *ua, bool use_default) STORE *store = NULL; int jobid; JCR *jcr; - int i; + int i, drive; char ed1[50]; - ua->int32_val = -2; /* dummy */ for (i=1; iargc; i++) { - if (strcasecmp("drive", ua->argk[i]) == 0 && ua->argv[i]) { - ua->int32_val = atoi(ua->argv[i]); - } if (use_default && !ua->argv[i]) { /* Ignore slots, scan and barcode(s) keywords */ if (strcasecmp("scan", ua->argk[i]) == 0 || @@ -840,14 +836,21 @@ STORE *get_storage_resource(UAContext *ua, bool use_default) store = select_storage_resource(ua); } /* Get drive for autochanger if possible */ - if (store && store->autochanger && ua->int32_val == -2) { - ua->cmd[0] = 0; - if (!get_cmd(ua, _("Enter autochanger drive [0]: "))) { - ua->int32_val = -1; /* None */ + drive = -2; /* dummy */ + if (store && store->autochanger) { + i = find_arg_with_value(ua, "drive"); + if (i >=0) { + drive = atoi(ua->argv[i]); } else { - ua->int32_val = atoi(ua->cmd); + ua->cmd[0] = 0; + if (!get_cmd(ua, _("Enter autochanger drive[0]: "))) { + drive = -1; /* None */ + } else { + drive = atoi(ua->cmd); + } } } + ua->int32_val = drive; return store; } diff --git a/bacula/src/filed/heartbeat.c b/bacula/src/filed/heartbeat.c index 23f72eca85..7a77621610 100644 --- a/bacula/src/filed/heartbeat.c +++ b/bacula/src/filed/heartbeat.c @@ -26,7 +26,7 @@ #include "bacula.h" #include "filed.h" -#define WAIT_INTERVAL 10 +#define WAIT_INTERVAL 5 extern "C" void *sd_heartbeat_thread(void *arg); extern "C" void *dir_heartbeat_thread(void *arg); @@ -49,12 +49,6 @@ extern "C" void *sd_heartbeat_thread(void *arg) /* Get our own local copy */ sd = dup_bsock(jcr->store_bsock); -#ifndef WIN32 - int oflags; - if ((oflags = fcntl(sd->fd, F_GETFL, 0)) != -1) { - fcntl(sd->fd, F_SETFL, oflags|O_NONBLOCK); - } -#endif dir = dup_bsock(jcr->dir_bsock); jcr->hb_bsock = sd; @@ -139,8 +133,6 @@ void stop_heartbeat_monitor(JCR *jcr) pthread_kill(jcr->heartbeat_id, TIMEOUT_SIGNAL); /* make heartbeat thread go away */ bmicrosleep(0, 500000); } - if (jcr->hb_bsock) { - } } /* diff --git a/bacula/src/lib/bget_msg.c b/bacula/src/lib/bget_msg.c index e0084533ff..912aa5786b 100644 --- a/bacula/src/lib/bget_msg.c +++ b/bacula/src/lib/bget_msg.c @@ -8,22 +8,17 @@ * */ /* - Copyright (C) 2001-2004 Kern Sibbald and John Walker + Copyright (C) 2001-2005 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ @@ -43,57 +38,57 @@ extern char TERM_msg[]; * Returns number of bytes read (may return zero) * Returns -1 on signal (BNET_SIGNAL) * Returns -2 on hard end of file (BNET_HARDEOF) - * Returns -3 on error (BNET_ERROR) + * Returns -3 on error (BNET_ERROR) */ int bget_msg(BSOCK *sock) { int n; for ( ;; ) { n = bnet_recv(sock); - if (n >= 0) { /* normal return */ - return n; + if (n >= 0) { /* normal return */ + return n; } if (is_bnet_stop(sock)) { /* error return */ - return n; + return n; } /* BNET_SIGNAL (-1) return from bnet_recv() => network signal */ switch (sock->msglen) { - case BNET_EOD: /* end of data */ - Dmsg0(msglvl, "Got BNET_EOD\n"); - return n; + case BNET_EOD: /* end of data */ + Dmsg0(msglvl, "Got BNET_EOD\n"); + return n; case BNET_EOD_POLL: - Dmsg0(msglvl, "Got BNET_EOD_POLL\n"); - if (sock->terminated) { - bnet_fsend(sock, TERM_msg); - } else { - bnet_fsend(sock, OK_msg); /* send response */ - } - return n; /* end of data */ + Dmsg0(msglvl, "Got BNET_EOD_POLL\n"); + if (sock->terminated) { + bnet_fsend(sock, TERM_msg); + } else { + bnet_fsend(sock, OK_msg); /* send response */ + } + return n; /* end of data */ case BNET_TERMINATE: - Dmsg0(msglvl, "Got BNET_TERMINATE\n"); - sock->terminated = 1; - return n; + Dmsg0(msglvl, "Got BNET_TERMINATE\n"); + sock->terminated = 1; + return n; case BNET_POLL: - Dmsg0(msglvl, "Got BNET_POLL\n"); - if (sock->terminated) { - bnet_fsend(sock, TERM_msg); - } else { - bnet_fsend(sock, OK_msg); /* send response */ - } - break; + Dmsg0(msglvl, "Got BNET_POLL\n"); + if (sock->terminated) { + bnet_fsend(sock, TERM_msg); + } else { + bnet_fsend(sock, OK_msg); /* send response */ + } + break; case BNET_HEARTBEAT: case BNET_HB_RESPONSE: - break; + break; case BNET_STATUS: - /* *****FIXME***** Implement BNET_STATUS */ - Dmsg0(msglvl, "Got BNET_STATUS\n"); - bnet_fsend(sock, _("Status OK\n")); - bnet_sig(sock, BNET_EOD); - break; + /* *****FIXME***** Implement BNET_STATUS */ + Dmsg0(msglvl, "Got BNET_STATUS\n"); + bnet_fsend(sock, _("Status OK\n")); + bnet_sig(sock, BNET_EOD); + break; default: - Emsg1(M_ERROR, 0, _("bget_msg: unknown signal %d\n"), sock->msglen); - break; + Emsg1(M_ERROR, 0, _("bget_msg: unknown signal %d\n"), sock->msglen); + break; } } } diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index da653f43fb..cd7d1fc229 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -69,13 +69,20 @@ static int32_t read_nbytes(BSOCK * bsock, char *ptr, int32_t nbytes) nleft = nbytes; while (nleft > 0) { - do { - errno = 0; - nread = socketRead(bsock->fd, ptr, nleft); - if (bsock->timed_out || bsock->terminated) { - return nread; + errno = 0; + nread = socketRead(bsock->fd, ptr, nleft); + if (bsock->timed_out || bsock->terminated) { + return nread; + } + if (nread == -1) { + if (errno == EINTR) { + continue; } - } while (nread == -1 && (errno == EINTR || errno == EAGAIN)); + if (errno == EAGAIN) { + bmicrosleep(0, 200000); /* try again in 200ms */ + continue; + } + } if (nread <= 0) { return nread; /* error, or EOF */ } @@ -537,7 +544,7 @@ int bnet_wait_data(BSOCK * bsock, int sec) return 0; case -1: bsock->b_errno = errno; - if (errno == EINTR || errno == EAGAIN) { + if (errno == EINTR) { continue; } return -1; /* error return */ @@ -982,15 +989,15 @@ int bnet_set_nonblocking (BSOCK *bsock) { int oflags; /* Get current flags */ - if((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) { + if ((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) { berrno be; - Emsg1(M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.strerror()); + Jmsg1(bsock->jcr, M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.strerror()); } /* Set O_NONBLOCK flag */ - if((fcntl(bsock->fd, F_SETFL, oflags|O_NONBLOCK)) < 0) { + if ((fcntl(bsock->fd, F_SETFL, oflags|O_NONBLOCK)) < 0) { berrno be; - Emsg1(M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror()); + Jmsg1(bsock->jcr, M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror()); } bsock->blocking = 0; @@ -1003,7 +1010,7 @@ int bnet_set_nonblocking (BSOCK *bsock) { ioctlsocket(bsock->fd, FIONBIO, &ioctlArg); bsock->blocking = 0; - return (flags); + return flags; #endif } @@ -1011,23 +1018,24 @@ int bnet_set_nonblocking (BSOCK *bsock) { * Set socket blocking * Returns previous socket flags */ -int bnet_set_blocking (BSOCK *bsock) { +int bnet_set_blocking (BSOCK *bsock) +{ #ifndef WIN32 int oflags; /* Get current flags */ - if((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) { + if ((oflags = fcntl(bsock->fd, F_GETFL, 0)) < 0) { berrno be; - Emsg1(M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.strerror()); + Jmsg1(bsock->jcr, M_ABORT, 0, _("fcntl F_GETFL error. ERR=%s\n"), be.strerror()); } /* Set O_NONBLOCK flag */ - if((fcntl(bsock->fd, F_SETFL, oflags & ~O_NONBLOCK)) < 0) { + if ((fcntl(bsock->fd, F_SETFL, oflags & ~O_NONBLOCK)) < 0) { berrno be; - Emsg1(M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror()); + Jmsg1(bsock->jcr, M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror()); } bsock->blocking = 1; - return (oflags); + return oflags; #else int flags; u_long ioctlArg = 0; @@ -1036,18 +1044,19 @@ int bnet_set_blocking (BSOCK *bsock) { ioctlsocket(bsock->fd, FIONBIO, &ioctlArg); bsock->blocking = 1; - return (flags); + return flags; #endif } /* * Restores socket flags */ -void bnet_restore_blocking (BSOCK *bsock, int flags) { +void bnet_restore_blocking (BSOCK *bsock, int flags) +{ #ifndef WIN32 - if((fcntl(bsock->fd, F_SETFL, flags)) < 0) { + if ((fcntl(bsock->fd, F_SETFL, flags)) < 0) { berrno be; - Emsg1(M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror()); + Jmsg1(bsock->jcr, M_ABORT, 0, _("fcntl F_SETFL error. ERR=%s\n"), be.strerror()); } bsock->blocking = (flags & O_NONBLOCK); diff --git a/bacula/src/lib/bnet_server.c b/bacula/src/lib/bnet_server.c index f94bc710e8..32940600a2 100644 --- a/bacula/src/lib/bnet_server.c +++ b/bacula/src/lib/bnet_server.c @@ -1,20 +1,15 @@ /* - Copyright (C) 2000-2004 Kern Sibbald and John Walker + Copyright (C) 2000-2005 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ /* @@ -57,7 +52,7 @@ void bnet_stop_thread_server(pthread_t tid) } /* - Become Threaded Network Server + Become Threaded Network Server This function is able to handle multiple server ips in ipv4 and ipv6 style. The Addresse are give in a comma seperated string in bind_addr @@ -65,7 +60,7 @@ void bnet_stop_thread_server(pthread_t tid) */ void bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, - void *handle_client_request(void *bsock)) + void *handle_client_request(void *bsock)) { int newsockfd, stat; socklen_t clilen; @@ -77,7 +72,7 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, #endif IPADDR *p; struct s_sockfd { - dlink link; /* this MUST be the first item */ + dlink link; /* this MUST be the first item */ int fd; int port; } *fd_ptr = NULL; @@ -95,42 +90,41 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, * Open a TCP socket */ for (tlog= 60; (fd_ptr->fd=socket(p->get_family(), SOCK_STREAM, 0)) < 0; tlog -= 10) { - if (tlog <= 0) { - berrno be; - char curbuf[256]; + if (tlog <= 0) { + berrno be; + char curbuf[256]; 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))); - } - bmicrosleep(10, 0); + be.strerror(), + p->build_address_str(curbuf, sizeof(curbuf)), + build_addresses_str(addrs, allbuf, sizeof(allbuf))); + } + bmicrosleep(10, 0); } /* * Reuse old sockets */ if (setsockopt(fd_ptr->fd, SOL_SOCKET, SO_REUSEADDR, (sockopt_val_t)&turnon, - sizeof(turnon)) < 0) { - berrno be; + sizeof(turnon)) < 0) { + berrno be; Emsg1(M_WARNING, 0, _("Cannot set SO_REUSEADDR on socket: %s\n"), - be.strerror()); + be.strerror()); } int tmax = 30 * (60 / 5); /* wait 30 minutes max */ - /* FIXME i can go to a endless loop i get a invalid address */ for (tlog = 0; bind(fd_ptr->fd, p->get_sockaddr(), p->get_sockaddr_len()) < 0; tlog -= 5) { - berrno be; - if (tlog <= 0) { - tlog = 2 * 60; /* Complain every 2 minutes */ + berrno be; + if (tlog <= 0) { + tlog = 2 * 60; /* Complain every 2 minutes */ Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s: Retrying ...\n"), - ntohs(fd_ptr->port), be.strerror()); - } - bmicrosleep(5, 0); - if (--tmax <= 0) { + 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), - be.strerror()); - } + be.strerror()); + } } - listen(fd_ptr->fd, 5); /* tell system we are ready */ + listen(fd_ptr->fd, 5); /* tell system we are ready */ sockfds.append(fd_ptr); } /* Start work queue thread */ @@ -147,78 +141,82 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, fd_set sockset; FD_ZERO(&sockset); foreach_dlist(fd_ptr, &sockfds) { - FD_SET((unsigned)fd_ptr->fd, &sockset); - maxfd = maxfd > (unsigned)fd_ptr->fd ? maxfd : fd_ptr->fd; + FD_SET((unsigned)fd_ptr->fd, &sockset); + maxfd = maxfd > (unsigned)fd_ptr->fd ? maxfd : fd_ptr->fd; } errno = 0; if ((stat = select(maxfd + 1, &sockset, NULL, NULL, NULL)) < 0) { - berrno be; /* capture errno */ - if (errno == EINTR || errno == EAGAIN) { - continue; - } - /* Error, get out */ - foreach_dlist(fd_ptr, &sockfds) { - close(fd_ptr->fd); - free((void *)fd_ptr); - } + berrno be; /* capture errno */ + if (errno == EINTR) { + continue; + } + /* Error, get out */ + foreach_dlist(fd_ptr, &sockfds) { + close(fd_ptr->fd); + free((void *)fd_ptr); + } Emsg1(M_FATAL, 0, _("Error in select: %s\n"), be.strerror()); - break; + break; } foreach_dlist(fd_ptr, &sockfds) { - if (FD_ISSET(fd_ptr->fd, &sockset)) { - /* Got a connection, now accept it. */ - do { - clilen = sizeof(cli_addr); - newsockfd = accept(fd_ptr->fd, &cli_addr, &clilen); - } while (newsockfd < 0 && (errno == EINTR || errno == EAGAIN)); - if (newsockfd < 0) { - continue; - } + if (FD_ISSET(fd_ptr->fd, &sockset)) { + /* Got a connection, now accept it. */ + do { + clilen = sizeof(cli_addr); + newsockfd = accept(fd_ptr->fd, &cli_addr, &clilen); + } while (newsockfd < 0 && errno == EINTR); + if (newsockfd < 0) { + continue; + } #ifdef HAVE_LIBWRAP - P(mutex); /* hosts_access is not thread safe */ - request_init(&request, RQ_DAEMON, my_name, RQ_FILE, newsockfd, 0); - fromhost(&request); - if (!hosts_access(&request)) { - V(mutex); - Jmsg2(NULL, M_SECURITY, 0, + P(mutex); /* hosts_access is not thread safe */ + request_init(&request, RQ_DAEMON, my_name, RQ_FILE, newsockfd, 0); + fromhost(&request); + if (!hosts_access(&request)) { + V(mutex); + Jmsg2(NULL, M_SECURITY, 0, _("Connection from %s:%d refused by hosts.access\n"), - sockaddr_to_ascii(&cli_addr, buf, sizeof(buf)), - sockaddr_get_port(&cli_addr)); - close(newsockfd); - continue; - } - V(mutex); + sockaddr_to_ascii(&cli_addr, buf, sizeof(buf)), + sockaddr_get_port(&cli_addr)); + close(newsockfd); + continue; + } + V(mutex); #endif - /* - * Receive notification when connection dies. - */ - if (setsockopt(newsockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, - sizeof(turnon)) < 0) { - berrno be; + /* + * Receive notification when connection dies. + */ + 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"), - be.strerror()); - } - - /* see who client is. i.e. who connected to us. */ - P(mutex); - sockaddr_to_ascii(&cli_addr, buf, sizeof(buf)); - V(mutex); - BSOCK *bs; + be.strerror()); + } + + /* see who client is. i.e. who connected to us. */ + P(mutex); + sockaddr_to_ascii(&cli_addr, buf, sizeof(buf)); + V(mutex); + BSOCK *bs; + int oflags = fcntl(newsockfd, F_GETFL, 0); + if (oflags & O_NONBLOCK) { + Jmsg1(NULL, M_ABORT, 0, _("Nonblocking socket %d.\n"), newsockfd); + } bs = init_bsock(NULL, newsockfd, "client", buf, fd_ptr->port, &cli_addr); - if (bs == NULL) { + if (bs == NULL) { 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); + /* 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"), - be.strerror()); - } - } + be.strerror()); + } + } } } @@ -227,7 +225,7 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq, berrno be; be.set_errno(stat); Emsg1(M_FATAL, 0, _("Could not destroy client queue: ERR=%s\n"), - be.strerror()); + be.strerror()); } } @@ -249,10 +247,10 @@ BSOCK *bnet_bind(int port) */ for (tlog = 0; (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0; tlog -= 10) { if (errno == EINTR || errno == EAGAIN) { - continue; + continue; } if (tlog <= 0) { - tlog = 2 * 60; + tlog = 2 * 60; Emsg1(M_ERROR, 0, _("Cannot open stream socket: %s\n"), strerror(errno)); } bmicrosleep(60, 0); @@ -263,7 +261,7 @@ BSOCK *bnet_bind(int port) */ if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) { Emsg1(M_WARNING, 0, _("Cannot set SO_REUSEADDR on socket: %s\n"), - strerror(errno)); + strerror(errno)); } /* @@ -275,21 +273,21 @@ BSOCK *bnet_bind(int port) serv_addr.sin_port = htons(port); for (tlog = 0; bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0; - tlog -= 5) { + tlog -= 5) { berrno be; if (errno == EINTR || errno == EAGAIN) { - continue; + continue; } if (tlog <= 0) { - tlog = 2 * 60; + tlog = 2 * 60; Emsg2(M_WARNING, 0, _("Cannot bind port %d: ERR=%s: retrying ...\n"), port, - be.strerror()); + be.strerror()); } bmicrosleep(5, 0); } - listen(sockfd, 1); /* tell system we are ready */ + listen(sockfd, 1); /* tell system we are ready */ return init_bsock(NULL, sockfd, _("Server socket"), _("client"), port, - &serv_addr); + &serv_addr); } /* @@ -320,20 +318,20 @@ BSOCK *bnet_accept(BSOCK * bsock, char *who) */ ready = sockset; if ((stat = select(bsock->fd + 1, &ready, NULL, NULL, NULL)) < 0) { - if (errno == EINTR || errno = EAGAIN) { - errno = 0; - continue; - } + if (errno == EINTR || errno = EAGAIN) { + errno = 0; + continue; + } Emsg1(M_FATAL, 0, _("Error in select: %s\n"), strerror(errno)); - newsockfd = -1; - break; + newsockfd = -1; + break; } do { - clilen = sizeof(cli_addr); - newsockfd = accept(bsock->fd, (struct sockaddr *)&cli_addr, &clilen); + clilen = sizeof(cli_addr); + newsockfd = accept(bsock->fd, (struct sockaddr *)&cli_addr, &clilen); } while (newsockfd < 0 && (errno == EINTR || errno = EAGAIN)); if (newsockfd >= 0) { - break; + break; } } @@ -344,7 +342,7 @@ BSOCK *bnet_accept(BSOCK * bsock, char *who) if (!hosts_access(&request)) { V(mutex); Emsg2(M_SECURITY, 0, _("Connection from %s:%d refused by hosts.access\n"), - inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port)); + inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port)); close(newsockfd); return NULL; } @@ -356,7 +354,7 @@ BSOCK *bnet_accept(BSOCK * bsock, char *who) */ if (setsockopt(newsockfd, SOL_SOCKET, SO_KEEPALIVE, (sockopt_val_t)&turnon, sizeof(turnon)) < 0) { Emsg1(M_WARNING, 0, _("Cannot set SO_KEEPALIVE on socket: %s\n"), - strerror(errno)); + strerror(errno)); } /* see who client is. I.e. who connected to us. @@ -371,7 +369,7 @@ BSOCK *bnet_accept(BSOCK * bsock, char *who) if (newsockfd < 0) { Emsg2(M_FATAL, 0, _("Socket accept error for %s. ERR=%s\n"), who, - strerror(errno)); + strerror(errno)); return NULL; } else { if (caller == NULL) { @@ -384,7 +382,7 @@ BSOCK *bnet_accept(BSOCK * bsock, char *who) bstrncat(buf, len, caller); bs = init_bsock(NULL, newsockfd, _("client"), buf, bsock->port, &cli_addr); free(buf); - return bs; /* return new BSOCK */ + return bs; /* return new BSOCK */ } } diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index 9ab4a452e4..689965d428 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -47,7 +47,7 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir) JCR *jcr = dcr->jcr; DEVICE *dev = dcr->dev; int slot; - int drive = dev->device->drive_index; + int drive = dev->drive_index; int rtn_stat = -1; /* error status */ POOLMEM *changer; diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 6a7e2c23c2..ed9b006b93 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -332,6 +332,10 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) int ioerrcnt = 10; Dmsg0(29, "open dev: device is tape\n"); + if (is_tape() && is_autochanger()) { + get_autochanger_loaded_slot(dcr); + } + set_mode(omode); timeout = max_open_wait; errno = 0; diff --git a/bacula/src/stored/reserve.c b/bacula/src/stored/reserve.c index 62ea51375c..48f3d76b3d 100644 --- a/bacula/src/stored/reserve.c +++ b/bacula/src/stored/reserve.c @@ -454,8 +454,7 @@ static int search_res_for_device(RCTX &rctx) foreach_res(rctx.device, R_DEVICE) { Dmsg1(100, "Try res=%s\n", rctx.device->hdr.name); /* Find resource, and make sure we were able to open it */ - if (fnmatch(rctx.device_name, rctx.device->hdr.name, 0) == 0 && - strcmp(rctx.device->media_type, rctx.store->media_type) == 0) { + if (fnmatch(rctx.device_name, rctx.device->hdr.name, 0) == 0) { stat = reserve_device(rctx); if (stat != 1) { return stat; @@ -506,6 +505,12 @@ static int reserve_device(RCTX &rctx) bool ok; DCR *dcr; const int name_len = MAX_NAME_LENGTH; + + /* Make sure MediaType is OK */ + if (strcmp(rctx.device->media_type, rctx.store->media_type) != 0) { + return -1; + } + if (!rctx.device->dev) { rctx.device->dev = init_dev(rctx.jcr, rctx.device); } @@ -653,8 +658,7 @@ static int can_reserve_drive(DCR *dcr, bool PreferMountedVols) DEVICE *dev = dcr->dev; JCR *jcr = dcr->jcr; - if (PreferMountedVols && !dev->VolHdr.VolumeName[0] && - dev->is_tape() && !dev->is_autochanger()) { + if (PreferMountedVols && !dev->VolHdr.VolumeName[0] && dev->is_tape()) { return 0; /* No volume mounted */ } diff --git a/bacula/src/stored/spool.c b/bacula/src/stored/spool.c index 610c0f33bf..c4fd2641ba 100644 --- a/bacula/src/stored/spool.c +++ b/bacula/src/stored/spool.c @@ -114,7 +114,7 @@ bool commit_data_spool(DCR *dcr) Dmsg0(100, "Committing spooled data\n"); stat = despool_data(dcr, true /*commit*/); if (!stat) { - Pmsg1(000, _("Bad return from despool WroteVol=%d\n"), dcr->WroteVol); + Dmsg1(100, _("Bad return from despool WroteVol=%d\n"), dcr->WroteVol); close_data_spool_file(dcr); return false; } diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index b526c581cf..cc600569bd 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -508,11 +508,6 @@ void *device_initialization(void *arg) if (!first_open_device(dcr)) { Jmsg1(NULL, M_ERROR, 0, _("Could not open device %s\n"), dev->print_name()); Dmsg1(20, "Could not open device %s\n", dev->print_name()); - -#ifdef xxx - term_dev(dev); - device->dev = NULL; -#endif free_dcr(dcr); continue; } diff --git a/bacula/src/version.h b/bacula/src/version.h index ccb575a399..33f6ba7d45 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #undef VERSION #define VERSION "1.37.36" -#define BDATE "15 August 2005" -#define LSMDATE "15Aug05" +#define BDATE "16 August 2005" +#define LSMDATE "16Aug05" /* Debug flags */ #undef DEBUG