X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Fdircmd.c;h=fb30c52e96e360df9a5d0bd8fc7976ae3bb97642;hb=37190d54ceff7f2b45a58a1c6241688cc5cba1c2;hp=2d6f1b13bda3384d7204bdd4db5230fbdcba0b8d;hpb=effb543c440df2e8db1ee10e574cabb1d78ce665;p=bacula%2Fbacula diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 2d6f1b13bd..fb30c52e96 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -1,24 +1,3 @@ -/* - * This file handles accepting Director Commands - * - * Most Director commands are handled here, with the - * exception of the Job command command and subsequent - * subcommands that are handled - * in job.c. - * - * N.B. in this file, in general we must use P(dev->mutex) rather - * than lock_device(dev) so that we can examine the blocked - * state rather than blocking ourselves because a Job - * thread has the device blocked. In some "safe" cases, - * we can do things to a blocked device. CAREFUL!!!! - * - * File daemon commands are handled in fdcmd.c - * - * Kern Sibbald, May MMI - * - * Version $Id$ - * - */ /* Bacula® - The Network Backup Solution @@ -55,7 +34,7 @@ * in job.c. * * N.B. in this file, in general we must use P(dev->mutex) rather - * than lock_device(dev) so that we can examine the blocked + * than dev->r_lock() so that we can examine the blocked * state rather than blocking ourselves because a Job * thread has the device blocked. In some "safe" cases, * we can do things to a blocked device. CAREFUL!!!! @@ -96,6 +75,7 @@ extern bool qstatus_cmd(JCR *jcr); /* Forward referenced functions */ static bool label_cmd(JCR *jcr); +static bool die_cmd(JCR *jcr); static bool relabel_cmd(JCR *jcr); static bool readlabel_cmd(JCR *jcr); static bool release_cmd(JCR *jcr); @@ -128,6 +108,7 @@ static struct s_cmds cmds[] = { {"autochanger", changer_cmd, 0}, {"bootstrap", bootstrap_cmd, 0}, {"cancel", cancel_cmd, 0}, + {".die", die_cmd, 0}, {"label", label_cmd, 0}, /* label a tape */ {"mount", mount_cmd, 0}, {"readlabel", readlabel_cmd, 0}, @@ -189,6 +170,7 @@ void *handle_connection_request(void *arg) */ Dmsg1(110, "Conn: %s", bs->msg); if (sscanf(bs->msg, "Hello Start Job %127s", name) == 1) { + Dmsg0(110, "Got a FD connection\n"); handle_filed_connection(bs, name); return NULL; } @@ -196,7 +178,7 @@ void *handle_connection_request(void *arg) /* * This is a connection from the Director, so setup a JCR */ - Dmsg0(110, "Start Dir Job\n"); + Dmsg0(110, "Got a DIR connection\n"); jcr = new_jcr(sizeof(JCR), stored_free_jcr); /* create Job Control Record */ jcr->dir_bsock = bs; /* save Director bsock */ jcr->dir_bsock->set_jcr(jcr); @@ -260,6 +242,24 @@ bail_out: return NULL; } + +/* + * Force SD to die, and hopefully dump itself. Turned on only + * in development version. + */ +static bool die_cmd(JCR *jcr) +{ +#ifdef DEVELOPER + JCR *djcr = NULL; + int a; + Pmsg0(000, "I have been requested to die ..."); + a = djcr->JobId; /* ref NULL pointer */ +#endif + return 0; +} + + + /* * Set debug level as requested by the Director * @@ -303,14 +303,19 @@ static bool cancel_cmd(JCR *cjcr) jcr->unlock(); if (jcr->file_bsock) { bnet_sig(jcr->file_bsock, BNET_TERMINATE); + } else { + /* Still waiting for FD to connect, release it */ + pthread_cond_signal(&jcr->job_start_wait); /* wake waiting job */ } /* If thread waiting on mount, wake him */ if (jcr->dcr && jcr->dcr->dev && jcr->dcr->dev->waiting_for_mount()) { pthread_cond_broadcast(&jcr->dcr->dev->wait_next_vol); + Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)jcr->JobId); pthread_cond_broadcast(&wait_device_release); } if (jcr->read_dcr && jcr->read_dcr->dev && jcr->read_dcr->dev->waiting_for_mount()) { pthread_cond_broadcast(&jcr->read_dcr->dev->wait_next_vol); + Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)jcr->JobId); pthread_cond_broadcast(&wait_device_release); } Jmsg(jcr, M_INFO, 0, _("Job %s marked to be canceled.\n"), jcr->Job); @@ -376,7 +381,7 @@ static bool do_label(JCR *jcr, int relabel) dcr = find_device(jcr, dev_name, drive); if (dcr) { dev = dcr->dev; - dev->lock(); /* Use P to avoid indefinite block */ + dev->dlock(); /* Use P to avoid indefinite block */ if (!dev->is_open()) { Dmsg1(400, "Can %slabel. Device is not open\n", relabel?"re":""); label_volume_if_ok(dcr, oldname, newname, poolname, slot, relabel); @@ -391,7 +396,7 @@ static bool do_label(JCR *jcr, int relabel) Dmsg0(400, "Can relabel. device not used\n"); label_volume_if_ok(dcr, oldname, newname, poolname, slot, relabel); } - dev->unlock(); + dev->dunlock(); free_dcr(dcr); jcr->dcr = NULL; } else { @@ -496,7 +501,7 @@ static void label_volume_if_ok(DCR *dcr, char *oldname, dev->is_dvd()?1:0, newname, dev->print_name()); break; case VOL_NO_MEDIA: - bnet_fsend(dir, _("3912 Failed to label Volume: ERR=%s\n"), dev->bstrerror()); + bnet_fsend(dir, _("3914 Failed to label Volume (no media): ERR=%s\n"), dev->bstrerror()); break; default: bnet_fsend(dir, _("3913 Cannot label Volume. " @@ -506,7 +511,7 @@ static void label_volume_if_ok(DCR *dcr, char *oldname, bail_out: if (!dev->is_open()) { - free_volume(dev); + dev->clear_volhdr(); } give_back_device_lock(dev, &hold); return; @@ -640,7 +645,7 @@ static bool mount_cmd(JCR *jcr) dcr = find_device(jcr, devname, drive); if (dcr) { dev = dcr->dev; - dev->lock(); /* Use P to avoid indefinite block */ + dev->dlock(); /* Use P to avoid indefinite block */ Dmsg1(100, "mount cmd blocked=%d\n", dev->blocked()); switch (dev->blocked()) { /* device blocked? */ case BST_WAITING_FOR_SYSOP: @@ -650,6 +655,7 @@ static bool mount_cmd(JCR *jcr) bnet_fsend(dir, "3001 OK mount. Device=%s\n", dev->print_name()); pthread_cond_broadcast(&dev->wait_next_vol); + Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)dcr->jcr->JobId); pthread_cond_broadcast(&wait_device_release); break; @@ -689,6 +695,7 @@ static bool mount_cmd(JCR *jcr) dev->print_name()); } pthread_cond_broadcast(&dev->wait_next_vol); + Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)dcr->jcr->JobId); pthread_cond_broadcast(&wait_device_release); break; @@ -747,7 +754,7 @@ static bool mount_cmd(JCR *jcr) bnet_fsend(dir, _("3905 Bizarre wait state %d\n"), dev->blocked()); break; } - dev->unlock(); + dev->dunlock(); free_dcr(dcr); jcr->dcr = NULL; } else { @@ -776,7 +783,7 @@ static bool unmount_cmd(JCR *jcr) dcr = find_device(jcr, devname, drive); if (dcr) { dev = dcr->dev; - dev->lock(); /* Use P to avoid indefinite block */ + dev->dlock(); /* Use P to avoid indefinite block */ if (!dev->is_open()) { if (!dev->is_busy()) { unload_autochanger(dcr, -1); @@ -838,7 +845,7 @@ static bool unmount_cmd(JCR *jcr) dev->print_name()); } } - dev->unlock(); + dev->dunlock(); free_dcr(dcr); jcr->dcr = NULL; } else { @@ -872,7 +879,7 @@ static bool release_cmd(JCR *jcr) dcr = find_device(jcr, devname, drive); if (dcr) { dev = dcr->dev; - dev->lock(); /* Use P to avoid indefinite block */ + dev->dlock(); /* Use P to avoid indefinite block */ if (!dev->is_open()) { if (!dev->is_busy()) { unload_autochanger(dcr, -1); @@ -911,7 +918,7 @@ static bool release_cmd(JCR *jcr) bnet_fsend(dir, _("3022 Device %s released.\n"), dev->print_name()); } - dev->unlock(); + dev->dunlock(); free_dcr(dcr); jcr->dcr = NULL; } else { @@ -963,7 +970,7 @@ static bool changer_cmd(JCR *jcr) dcr = find_device(jcr, devname, -1); if (dcr) { dev = dcr->dev; - dev->lock(); /* Use P to avoid indefinite block */ + dev->dlock(); /* Use P to avoid indefinite block */ if (!dev->device->changer_res) { bnet_fsend(dir, _("3995 Device %s is not an autochanger.\n"), dev->print_name()); @@ -975,7 +982,7 @@ static bool changer_cmd(JCR *jcr) } else { /* device not being used */ autochanger_cmd(dcr, dir, cmd); } - dev->unlock(); + dev->dunlock(); free_dcr(dcr); jcr->dcr = NULL; } else { @@ -1007,7 +1014,7 @@ static bool readlabel_cmd(JCR *jcr) dcr = find_device(jcr, devname, drive); if (dcr) { dev = dcr->dev; - dev->lock(); /* Use P to avoid indefinite block */ + dev->dlock(); /* Use P to avoid indefinite block */ if (!dev->is_open()) { read_volume_label(jcr, dev, Slot); dev->close(); @@ -1019,7 +1026,7 @@ static bool readlabel_cmd(JCR *jcr) } else { /* device not being used */ read_volume_label(jcr, dev, Slot); } - dev->unlock(); + dev->dunlock(); free_dcr(dcr); jcr->dcr = NULL; } else {