RCTX rctx;
char *msg;
alist *msgs;
+ alist *dirstore;
memset(&rctx, 0, sizeof(RCTX));
rctx.jcr = jcr;
* If there are multiple devices, the director sends us
* use_device for each device that it wants to use.
*/
- jcr->dirstore = New(alist(10, not_owned_by_alist));
+ dirstore = New(alist(10, not_owned_by_alist));
+// Dmsg2(000, "dirstore=%p JobId=%u\n", dirstore, jcr->JobId);
msgs = jcr->reserve_msgs = New(alist(10, not_owned_by_alist));
do {
Dmsg1(100, "<dird: %s", dir->msg);
if (!ok) {
break;
}
+ if (append) {
+ jcr->write_store = dirstore;
+ } else {
+ jcr->read_store = dirstore;
+ }
+ rctx.append = append;
unbash_spaces(store_name);
unbash_spaces(media_type);
unbash_spaces(pool_name);
unbash_spaces(pool_type);
store = new DIRSTORE;
- jcr->dirstore->append(store);
+ dirstore->append(store);
memset(store, 0, sizeof(DIRSTORE));
store->device = New(alist(10));
bstrncpy(store->name, store_name, sizeof(store->name));
/* This loop is debug code and can be removed */
/* ***FIXME**** remove after 1.38 release */
char *device_name;
- foreach_alist(store, jcr->dirstore) {
+ foreach_alist(store, dirstore) {
Dmsg5(110, "Storage=%s media_type=%s pool=%s pool_type=%s append=%d\n",
store->name, store->media_type, store->pool_name,
store->pool_type, store->append);
*/
if (ok) {
bool first = true; /* print wait message once */
+ bool fail = false;
rctx.notify_dir = true;
- for ( ; !job_canceled(jcr); ) {
- lock_reservations(); /* only one thread at a time */
+ lock_reservations();
+ for ( ; !fail && !job_canceled(jcr); ) {
while ((msg = (char *)msgs->pop())) {
free(msg);
}
if ((ok = find_suitable_device_for_job(jcr, rctx))) {
break;
}
- /* Unlock before possible wait */
+ /* Keep reservations locked *except* during wait_for_device() */
unlock_reservations();
if (!rctx.suitable_device || !wait_for_device(jcr, first)) {
Dmsg0(100, "Fail. !suitable_device || !wait_for_device\n");
- break; /* Get out, failure ... */
+ fail = true;
}
+ lock_reservations();
first = false;
bnet_sig(dir, BNET_HEARTBEAT); /* Inform Dir that we are alive */
}
- /* Note if !ok then search_lock is already cleared */
- if (ok) {
- unlock_reservations();
- goto all_done;
- }
-
- /*
- * If we get here, there are no suitable devices available, which
- * means nothing configured. If a device is suitable but busy
- * with another Volume, we will not come here.
- */
- if (verbose) {
+ unlock_reservations();
+ if (!ok) {
+ /*
+ * If we get here, there are no suitable devices available, which
+ * means nothing configured. If a device is suitable but busy
+ * with another Volume, we will not come here.
+ */
unbash_spaces(dir->msg);
pm_strcpy(jcr->errmsg, dir->msg);
Jmsg(jcr, M_INFO, 0, _("Failed command: %s\n"), jcr->errmsg);
- }
- Jmsg(jcr, M_FATAL, 0, _("\n"
- " Device \"%s\" with MediaType \"%s\" requested by DIR not found in SD Device resources.\n"),
- dev_name.c_str(), media_type.c_str());
- bnet_fsend(dir, NO_device, dev_name.c_str());
+ Jmsg(jcr, M_FATAL, 0, _("\n"
+ " Device \"%s\" with MediaType \"%s\" requested by DIR not found in SD Device resources.\n"),
+ dev_name.c_str(), media_type.c_str());
+ bnet_fsend(dir, NO_device, dev_name.c_str());
- Dmsg1(100, ">dird: %s", dir->msg);
+ Dmsg1(100, ">dird: %s", dir->msg);
+ }
} else {
unbash_spaces(dir->msg);
pm_strcpy(jcr->errmsg, dir->msg);
- if (verbose) {
- Jmsg(jcr, M_INFO, 0, _("Failed command: %s\n"), jcr->errmsg);
- }
+ Jmsg(jcr, M_FATAL, 0, _("Failed command: %s\n"), jcr->errmsg);
bnet_fsend(dir, BAD_use, jcr->errmsg);
Dmsg1(100, ">dird: %s", dir->msg);
}
-all_done:
release_msgs(jcr);
return ok;
}
bool ok;
DIRSTORE *store;
char *device_name;
+ alist *dirstore;
+ if (rctx.append) {
+ dirstore = jcr->write_store;
+ } else {
+ dirstore = jcr->read_store;
+ }
/*
* For each storage device that the user specified, we
* search and see if there is a resource for that device.
rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device,
rctx.autochanger_only);
ok = false;
- foreach_alist(store, jcr->dirstore) {
+ foreach_alist(store, dirstore) {
rctx.store = store;
foreach_alist(device_name, store->device) {
int stat;
ASSERT(dcr);
+ /* Get locks in correct order */
+ unlock_reservations();
P(dev->mutex);
+ lock_reservations();
if (is_device_unmounted(dev)) {
Dmsg1(200, "Device %s is BLOCKED due to user unmount.\n", dev->print_name());