From: Kern Sibbald Date: Wed, 7 May 2003 16:24:02 +0000 (+0000) Subject: Fix double mount needed to release drive after unmount X-Git-Tag: Release-1.31~160 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b71e8dd48707b2d91d86d3bb348f7e0580d12394;p=bacula%2Fbacula Fix double mount needed to release drive after unmount git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@496 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kernstodo b/bacula/kernstodo index 42cf9f0cf7..364860f20d 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -16,6 +16,8 @@ Testing to do: (painful) - multiple simultaneous Volumes For 1.31 release: +- Check for existence of all new Win32 API's. See LoadLibrary in + winservice.cpp - Fix Dir heartbeat in restore and verify vol. Be sure to make bnet_recv() ignore BNET_HEARTBEAT. - Fix problem reported by Christopher McCurdy diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index 68e9e67050..f638764078 100755 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -166,9 +166,10 @@ void init_resource(int type, struct res_items *items) *(int *)(items[i].value) = items[i].default_value; } else if (items[i].handler == store_int64) { *(int64_t *)(items[i].value) = items[i].default_value; - } else if (items[i].handler == store_size || - items[i].handler == store_time) { - *(uint64_t *)(items[i].value) = items[i].default_value; + } else if (items[i].handler == store_size) { + *(uint64_t *)(items[i].value) = (uint64_t)items[i].default_value; + } else if (items[i].handler == store_time) { + *(utime_t *)(items[i].value) = (utime_t)items[i].default_value; } } /* If this triggers, take a look at lib/parse_conf.h */ diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index 742497727d..f3a7a3d14a 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -446,6 +446,7 @@ static int wait_for_sysop(JCR *jcr, DEVICE *dev, int wait_sec) time_t start = time(NULL); time_t last_heartbeat = 0; int stat = 0; + int add_wait; /* * Wait requested time (wait_sec). However, we also wake up every @@ -453,25 +454,25 @@ static int wait_for_sysop(JCR *jcr, DEVICE *dev, int wait_sec) * to keep stateful firewalls from closing them down while waiting * for the operator. */ + add_wait = wait_sec; + if (me->heartbeat_interval && add_wait > me->heartbeat_interval) { + add_wait = me->heartbeat_interval; + } gettimeofday(&tv, &tz); timeout.tv_nsec = tv.tv_usec * 1000; - if (me->heartbeat_interval) { - utime_t hb = me->heartbeat_interval; - timeout.tv_sec = tv.tv_sec + (wait_sec > hb ? hb : wait_sec); - } else { - timeout.tv_sec = tv.tv_sec + wait_sec; - } + timeout.tv_sec = tv.tv_sec + add_wait; P(dev->mutex); dev_blocked = dev->dev_blocked; dev->dev_blocked = BST_WAITING_FOR_SYSOP; /* indicate waiting for mount */ for ( ; !job_canceled(jcr); ) { - int add_wait; time_t now; - Dmsg1(190, "I'm going to sleep on device %s\n", dev->dev_name); + Dmsg3(100, "I'm going to sleep on device %s. HB=%d wait=%d\n", dev->dev_name, + (int)me->heartbeat_interval, wait_sec); stat = pthread_cond_timedwait(&dev->wait_next_vol, &dev->mutex, &timeout); + Dmsg1(100, "Wokeup from sleep on device stat=%d\n", stat); now = time(NULL); @@ -481,7 +482,7 @@ static int wait_for_sysop(JCR *jcr, DEVICE *dev, int wait_sec) /* send heartbeats */ if (jcr->file_bsock) { bnet_sig(jcr->file_bsock, BNET_HEARTBEAT); - Dmsg0(000, "Send heartbeat to FD.\n"); + Dmsg0(100, "Send heartbeat to FD.\n"); } if (jcr->dir_bsock) { bnet_sig(jcr->dir_bsock, BNET_HEARTBEAT); @@ -490,30 +491,26 @@ static int wait_for_sysop(JCR *jcr, DEVICE *dev, int wait_sec) } } - /* Check if we blocked the device */ - if (dev->dev_blocked == BST_WAITING_FOR_SYSOP) { - if (stat != ETIMEDOUT) { /* we blocked the device */ - break; /* on error return */ - } - if (now - start >= wait_sec) { /* on exceeding wait time return */ - break; - } - add_wait = wait_sec - (now - start); - if (me->heartbeat_interval && add_wait > me->heartbeat_interval) { - add_wait = me->heartbeat_interval; - } - } else { /* Oops someone else has it blocked now */ - add_wait = 10; /* hang around until he releases it */ + if (dev->dev_blocked == BST_MOUNT) { /* mount request ? */ + stat = 0; + break; + } + + if (stat != ETIMEDOUT) { /* we blocked the device */ + break; /* on error return */ + } + if (now - start >= wait_sec) { /* on exceeding wait time return */ + Dmsg0(100, "Exceed wait time.\n"); + break; + } + add_wait = wait_sec - (now - start); + if (me->heartbeat_interval && add_wait > me->heartbeat_interval) { + add_wait = me->heartbeat_interval; } - /* - * Note, if dev_blocked is not BST_WAITING FOR_SYSOP, - * someone other than us has blocked the device (probably the - * user via the Console program), so we continue waiting - * until he releases the device back to us. - */ gettimeofday(&tv, &tz); timeout.tv_nsec = tv.tv_usec * 1000; timeout.tv_sec = tv.tv_sec + add_wait; /* additional wait */ + Dmsg1(100, "Additional wait %d sec.\n", add_wait); } dev->dev_blocked = dev_blocked; diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 7de8be29c7..b438b38d51 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -545,7 +545,7 @@ reread: Mmsg2(&dev->errmsg, _("Block length %u is greater than buffer %u. Attempting recovery.\n"), block->block_len, block->buf_len); Emsg0(M_WARNING, 0, dev->errmsg); - Dmsg1(000, "%s", dev->errmsg); + Pmsg1(000, "%s", dev->errmsg); /* Attempt to reposition to re-read the block */ if (dev->state & ST_TAPE) { Dmsg0(100, "Backspace record for reread.\n"); @@ -562,7 +562,7 @@ reread: } Mmsg1(&dev->errmsg, _("Resetting buffer size to %u bytes.\n"), block->block_len); Emsg0(M_WARNING, 0, dev->errmsg); - Dmsg1(000, "%s", dev->errmsg); + Pmsg1(000, "%s", dev->errmsg); /* Set new block length */ dev->max_block_size = block->block_len; block->buf_len = block->block_len; diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index c3e961b445..e121d642f4 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -1221,7 +1221,7 @@ This may take a long time. I.e. hours! ...\n\n"); stream_to_ascii(rec.Stream, rec.FileIndex), rec.data_len); } if (stop > 0) { - Dmsg0(000, "Write_end_session_label()\n"); + Dmsg0(100, "Write_end_session_label()\n"); /* Create Job status for end of session label */ if (!job_canceled(jcr) && ok) { set_jcr_job_status(jcr, JS_Terminated); diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 9614061193..86799f5f53 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -485,7 +485,7 @@ int update_pos_dev(DEVICE *dev) dev->file_addr = 0; pos = lseek(dev->fd, (off_t)0, SEEK_CUR); if (pos < 0) { - Dmsg1(000, "Seek error: ERR=%s\n", strerror(dev->dev_errno)); + Pmsg1(000, "Seek error: ERR=%s\n", strerror(dev->dev_errno)); dev->dev_errno = errno; Mmsg2(&dev->errmsg, _("lseek error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index ffcd90781e..4bcc54b778 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -109,6 +109,7 @@ #define BST_DOING_ACQUIRE 3 /* Opening/validating/moving tape */ #define BST_WRITING_LABEL 4 /* Labeling a tape */ #define BST_UNMOUNTED_WAITING_FOR_SYSOP 5 /* Closed by user during mount request */ +#define BST_MOUNT 6 /* Mount request */ /* Volume Catalog Information structure definition */ typedef struct s_volume_catalog_info { diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 344fdb5108..08d653d770 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -491,7 +491,8 @@ static int mount_cmd(JCR *jcr) DEV_BLOCK *block; case BST_WAITING_FOR_SYSOP: /* Someone is waiting, wake him */ - Dmsg0(90, "Waiting for mount attempt to wake thread\n"); + Dmsg0(100, "Waiting for mount. Attempting to wake thread\n"); + dev->dev_blocked = BST_MOUNT; pthread_cond_signal(&dev->wait_next_vol); bnet_fsend(dir, "3001 OK mount. Device=%s\n", dev->dev_name); break; @@ -508,12 +509,12 @@ static int mount_cmd(JCR *jcr) read_dev_volume_label(jcr, dev, block); free_block(block); if (dev->dev_blocked == BST_UNMOUNTED) { - Dmsg0(90, "Unmounted unblocking device\n"); + Dmsg0(100, "Unmounted. Unblocking device\n"); read_label(jcr, dev); unblock_device(dev); } else { - Dmsg0(90, "Unmounted waiting for mount attempt to wake thread\n"); - dev->dev_blocked = BST_WAITING_FOR_SYSOP; + Dmsg0(100, "Unmounted waiting for mount. Attempting to wake thread\n"); + dev->dev_blocked = BST_MOUNT; pthread_cond_signal(&dev->wait_next_vol); } if (dev->state & ST_LABEL) { diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index 6012cec012..c3c8240d61 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -149,9 +149,10 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ... sendit(sock, "Director: name=%s\n", res->res_dir.hdr.name); break; case R_STORAGE: - sendit(sock, "Storage: name=%s SDaddr=%s SDport=%d SDDport=%d\n", - res->res_store.hdr.name, res->res_store.SDaddr, - res->res_store.SDport, res->res_store.SDDport); + sendit(sock, "Storage: name=%s SDaddr=%s SDport=%d SDDport=%d HB=%s\n", + res->res_store.hdr.name, NPRT(res->res_store.SDaddr), + res->res_store.SDport, res->res_store.SDDport, + edit_utime(res->res_store.heartbeat_interval, buf)); break; case R_DEVICE: sendit(sock, "Device: name=%s MediaType=%s Device=%s\n",