*
*/
/*
- Copyright (C) 2000-2005 Kern Sibbald
+ Copyright (C) 2000-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
static bool reserve_device_for_append(DCR *dcr, RCTX &rctx);
static bool use_storage_cmd(JCR *jcr);
bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx);
+static void queue_reserve_message(JCR *jcr);
/* Requests from the Director daemon */
static char use_storage[] = "use storage=%127s media_type=%127s "
int Copy, Stripe;
DIRSTORE *store;
RCTX rctx;
+ char *msg;
+ alist *msgs;
memset(&rctx, 0, sizeof(RCTX));
rctx.jcr = jcr;
* use_device for each device that it wants to use.
*/
jcr->dirstore = New(alist(10, not_owned_by_alist));
+ msgs = jcr->reserve_msgs = New(alist(10, not_owned_by_alist));
do {
Dmsg1(100, "<dird: %s", dir->msg);
ok = sscanf(dir->msg, use_storage, store_name.c_str(),
/* ***FIXME**** remove after 1.38 release */
char *device_name;
foreach_alist(store, jcr->dirstore) {
- Dmsg4(100, "Storage=%s media_type=%s pool=%s pool_type=%s\n",
+ Dmsg5(100, "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->pool_type, store->append);
foreach_alist(device_name, store->device) {
Dmsg1(100, " Device=%s\n", device_name);
}
}
#endif
+ init_jcr_device_wait_timers(jcr);
/*
* At this point, we have a list of all the Director's Storage
* resources indicated for this Job, which include Pool, PoolType,
if (ok) {
bool first = true; /* print wait message once */
for ( ; !job_canceled(jcr); ) {
+ P(search_lock); /* only one thread at a time */
+ while ((msg = (char *)msgs->pop())) {
+ free(msg);
+ }
rctx.suitable_device = false;
rctx.have_volume = false;
rctx.any_drive = false;
rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device,
rctx.autochanger_only, rctx.any_drive);
if ((ok = find_suitable_device_for_job(jcr, rctx))) {
- goto done;
+ break;
}
/* Look through all drives possibly for low_use drive */
if (rctx.low_use_drive) {
rctx.try_low_use_drive = true;
if ((ok = find_suitable_device_for_job(jcr, rctx))) {
- goto done;
+ break;
}
rctx.try_low_use_drive = false;
}
rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device,
rctx.autochanger_only, rctx.any_drive);
if ((ok = find_suitable_device_for_job(jcr, rctx))) {
- goto done;
+ break;
}
}
/* Look for an exact match all drives */
rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device,
rctx.autochanger_only, rctx.any_drive);
if ((ok = find_suitable_device_for_job(jcr, rctx))) {
- goto done;
+ break;
}
/* Look for any mounted drive */
rctx.exact_match = false;
rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device,
rctx.autochanger_only, rctx.any_drive);
if ((ok = find_suitable_device_for_job(jcr, rctx))) {
- goto done;
+ break;
}
/* Try any drive */
rctx.any_drive = true;
rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device,
rctx.autochanger_only, rctx.any_drive);
if ((ok = find_suitable_device_for_job(jcr, rctx))) {
- goto done;
+ break;
}
+ /* Unlock before possible wait */
+ V(search_lock);
if (!rctx.suitable_device || !wait_for_device(jcr, first)) {
break; /* Get out, failure ... */
}
first = false;
bnet_sig(dir, BNET_HEARTBEAT); /* Inform Dir that we are alive */
}
+ /* Note if !ok then search_lock is already cleared */
+ if (ok) {
+ V(search_lock);
+ goto all_done;
+ }
/*
* If we get here, there are no suitable devices available, which
Dmsg1(100, ">dird: %s", dir->msg);
}
-done:
+all_done:
foreach_alist(store, jcr->dirstore) {
delete store->device;
delete store;
}
delete jcr->dirstore;
-#ifdef implemented
- while (error=(char*)rctx->errors.first()) {
- free(error);
+ P(search_lock);
+ while ((msg = (char *)msgs->pop())) {
+ free(msg);
}
-#endif
+ delete msgs;
+ jcr->reserve_msgs = NULL;
+ V(search_lock);
return ok;
}
Dmsg4(100, "PrefMnt=%d exact=%d suitable=%d chgronly=%d\n",
rctx.PreferMountedVols, rctx.exact_match, rctx.suitable_device,
rctx.autochanger_only);
- init_jcr_device_wait_timers(jcr);
ok = false;
- P(search_lock);
foreach_alist(store, jcr->dirstore) {
rctx.store = store;
foreach_alist(device_name, store->device) {
rctx.device_name = device_name;
stat = search_res_for_device(rctx);
if (stat == 1) { /* found available device */
- rctx.suitable_device = true;
Dmsg1(100, "Suitable device found=%s\n", device_name);
ok = true;
break;
} else if (stat == 0) { /* device busy */
Dmsg1(100, "Suitable busy device found=%s\n", device_name);
- rctx.suitable_device = true; /* but it is busy, so continue looking */
+ } else {
+ /* otherwise error */
+ Dmsg0(100, "No suitable device found.\n");
}
- /* otherwise error */
}
if (ok) {
break;
}
}
- V(search_lock);
return ok;
}
return -1; /* no use waiting */
}
- Dmsg2(100, "Try reserve %s jobid=%d\n", rctx.device->hdr.name,
+ rctx.suitable_device = true;
+ Dmsg2(100, "Try reserve %s JobId=%u\n", rctx.device->hdr.name,
rctx.jcr->JobId);
dcr = new_dcr(rctx.jcr, rctx.device->dev);
if (!dcr) {
if (rctx.exact_match && !rctx.have_volume) {
dcr->any_volume = true;
if (dir_find_next_appendable_volume(dcr)) {
- Dmsg1(100, "Looking for Volume=%s\n", dcr->VolumeName);
bstrncpy(rctx.VolumeName, dcr->VolumeName, sizeof(rctx.VolumeName));
+ Dmsg2(100, "JobId=%u looking for Volume=%s\n", rctx.jcr->JobId, rctx.VolumeName);
rctx.have_volume = true;
} else {
Dmsg0(100, "No next volume found\n");
if (is_device_unmounted(dev)) {
Dmsg1(200, "Device %s is BLOCKED due to user unmount.\n", dev->print_name());
- Mmsg(jcr->errmsg, _("Device %s is BLOCKED due to user unmount.\n"),
- dev->print_name());
+ Mmsg(jcr->errmsg, _("3601 JobId=%u device %s is BLOCKED due to user unmount.\n"),
+ jcr->JobId, dev->print_name());
+ queue_reserve_message(jcr);
goto bail_out;
}
if (dev->is_busy()) {
Dmsg4(200, "Device %s is busy ST_READ=%d num_writers=%d reserved=%d.\n", dev->print_name(),
dev->state & ST_READ?1:0, dev->num_writers, dev->reserved_device);
- Mmsg1(jcr->errmsg, _("Device %s is busy.\n"),
- dev->print_name());
+ Mmsg(jcr->errmsg, _("3602 JobId=%u device %s is busy (already reading/writing).\n"),
+ jcr->JobId, dev->print_name());
+ queue_reserve_message(jcr);
goto bail_out;
}
/* If device is being read, we cannot write it */
if (dev->can_read()) {
- Mmsg1(jcr->errmsg, _("Device %s is busy reading.\n"), dev->print_name());
+ Mmsg(jcr->errmsg, _("3603 JobId=%u device %s is busy reading.\n"),
+ jcr->JobId, dev->print_name());
Dmsg1(100, "%s", jcr->errmsg);
+ queue_reserve_message(jcr);
goto bail_out;
}
/* If device is unmounted, we are out of luck */
if (is_device_unmounted(dev)) {
- Mmsg(jcr->errmsg, _("Device %s is BLOCKED due to user unmount.\n"), dev->print_name());
+ Mmsg(jcr->errmsg, _("3604 JobId=%u device %s is BLOCKED due to user unmount.\n"),
+ jcr->JobId, dev->print_name());
Dmsg1(100, "%s", jcr->errmsg);
+ queue_reserve_message(jcr);
goto bail_out;
}
* helps spread the load to the least used drives.
*/
if (rctx.try_low_use_drive && dev == rctx.low_use_drive) {
- Dmsg3(100, "OK dev=%s == low_drive=%s. JobId=%d\n",
+ Dmsg3(100, "OK dev=%s == low_drive=%s. JobId=%u\n",
dev->print_name(), rctx.low_use_drive->print_name(), jcr->JobId);
return 1;
}
Dmsg1(100, "not low use num_writers=%d\n", dev->num_writers+
dev->reserved_device);
}
- Dmsg1(100, "failed: !prefMnt && busy. JobId=%d\n", jcr->JobId);
+ Dmsg1(100, "failed: !prefMnt && busy. JobId=%u\n", jcr->JobId);
+ Mmsg(jcr->errmsg, _("3605 JobId=%u wants free drive but device %s is busy.\n"),
+ jcr->JobId, dev->print_name());
+ queue_reserve_message(jcr);
return 0;
}
/* Check for prefer mounted volumes */
if (rctx.PreferMountedVols && !dev->VolHdr.VolumeName[0] && dev->is_tape()) {
- Dmsg1(100, "failed: want mounted -- no vol JobId=%d\n", jcr->JobId);
+ Mmsg(jcr->errmsg, _("3606 JobId=%u wants mounted, but drive %s has no Volume.\n"),
+ jcr->JobId, dev->print_name());
+ queue_reserve_message(jcr);
+ Dmsg1(100, "failed: want mounted -- no vol JobId=%u\n", jcr->JobId);
return 0; /* No volume mounted */
}
/* Check for exact Volume name match */
if (rctx.exact_match && rctx.have_volume &&
strcmp(dev->VolHdr.VolumeName, rctx.VolumeName) != 0) {
+ Mmsg(jcr->errmsg, _("3607 JobId=%u wants Vol=\"%s\" drive has Vol=\"%s\" on drive %s.\n"),
+ jcr->JobId, rctx.VolumeName, dev->VolHdr.VolumeName,
+ dev->print_name());
+ queue_reserve_message(jcr);
Dmsg2(100, "failed: Not exact match have=%s want=%s\n",
dev->VolHdr.VolumeName, rctx.VolumeName);
return 0;
if (rctx.autochanger_only && dev->num_writers == 0 &&
dev->VolHdr.VolumeName[0] == 0) {
/* Device is available but not yet reserved, reserve it for us */
- Dmsg2(100, "OK Res Unused autochanger %s JobId=%d.\n",
+ Dmsg2(100, "OK Res Unused autochanger %s JobId=%u.\n",
dev->print_name(), jcr->JobId);
bstrncpy(dev->pool_name, dcr->pool_name, sizeof(dev->pool_name));
bstrncpy(dev->pool_type, dcr->pool_type, sizeof(dev->pool_type));
if (strcmp(dev->pool_name, dcr->pool_name) == 0 &&
strcmp(dev->pool_type, dcr->pool_type) == 0) {
/* OK, compatible device */
- Dmsg2(100, "OK dev: %s num_writers=0, reserved, pool matches JobId=%d\n",
+ Dmsg2(100, "OK dev: %s num_writers=0, reserved, pool matches JobId=%u\n",
dev->print_name(), jcr->JobId);
return 1;
} else {
- /* Drive not suitable for us */
+ /* Drive Pool not suitable for us */
+ Mmsg(jcr->errmsg, _("3608 JobId=%u wants Pool=\"%s\" but have Pool=\"%s\" on drive %s.\n"),
+ jcr->JobId, dcr->pool_name, dev->pool_name, dev->print_name());
+ queue_reserve_message(jcr);
Dmsg2(100, "failed: busy num_writers=0, reserved, pool=%s wanted=%s\n",
dev->pool_name, dcr->pool_name);
return 0; /* wait */
/* Device in append mode, check if changing pool */
if (strcmp(dev->pool_name, dcr->pool_name) == 0 &&
strcmp(dev->pool_type, dcr->pool_type) == 0) {
- Dmsg2(100, "OK dev: %s num_writers=0, can_append, pool matches. JobId=%d\n",
+ Dmsg2(100, "OK dev: %s num_writers=0, can_append, pool matches. JobId=%u\n",
dev->print_name(), jcr->JobId);
/* OK, compatible device */
return 1;
}
}
/* Device is available but not yet reserved, reserve it for us */
- Dmsg2(100, "OK Dev avail reserved %s JobId=%d\n", dev->print_name(),
+ Dmsg2(100, "OK Dev avail reserved %s JobId=%u\n", dev->print_name(),
jcr->JobId);
bstrncpy(dev->pool_name, dcr->pool_name, sizeof(dev->pool_name));
bstrncpy(dev->pool_type, dcr->pool_type, sizeof(dev->pool_type));
/* Yes, now check if we want the same Pool and pool type */
if (strcmp(dev->pool_name, dcr->pool_name) == 0 &&
strcmp(dev->pool_type, dcr->pool_type) == 0) {
- Dmsg2(100, "OK dev: %s num_writers>=0, can_append, pool matches. JobId=%d\n",
+ Dmsg2(100, "OK dev: %s num_writers>=0, can_append, pool matches. JobId=%u\n",
dev->print_name(), jcr->JobId);
/* OK, compatible device */
return 1;
} else {
- /* Drive not suitable for us */
+ /* Drive Pool not suitable for us */
+ Mmsg(jcr->errmsg, _("3609 JobId=%u wants Pool=\"%s\" but have Pool=\"%s\" on drive %s.\n"),
+ jcr->JobId, dcr->pool_name, dev->pool_name, dev->print_name());
+ queue_reserve_message(jcr);
Dmsg2(100, "failed: busy num_writers>0, can_append, pool=%s wanted=%s\n",
dev->pool_name, dcr->pool_name);
return 0; /* wait */
}
} else {
Pmsg0(000, _("Logic error!!!! Should not get here.\n"));
+ Mmsg(jcr->errmsg, _("3910 JobId=%u Logic error!!!! drive %s Should not get here.\n"),
+ jcr->JobId, dev->print_name());
+ queue_reserve_message(jcr);
Jmsg0(jcr, M_FATAL, 0, _("Logic error!!!! Should not get here.\n"));
return -1; /* error, should not get here */
}
- Dmsg2(100, "failed: No reserve %s JobId=%d\n", dev->print_name(), jcr->JobId);
+ Mmsg(jcr->errmsg, _("3911 JobId=%u failed reserve drive %s.\n"),
+ jcr->JobId, dev->print_name());
+ queue_reserve_message(jcr);
+ Dmsg2(100, "failed: No reserve %s JobId=%u\n", dev->print_name(), jcr->JobId);
return 0;
}
+
+/*
+ * search_lock is already set on entering this routine
+ */
+static void queue_reserve_message(JCR *jcr)
+{
+ int i;
+ alist *msgs = jcr->reserve_msgs;
+ char *msg;
+
+ if (!msgs) {
+ return;
+ }
+ /*
+ * Look for duplicate message. If found, do
+ * not insert
+ */
+ for (i=msgs->size()-1; i >= 0; i--) {
+ msg = (char *)msgs->get(i);
+ if (!msg) {
+ return;
+ }
+ /* Comparison based on 4 digit message number */
+ if (strncmp(msg, jcr->errmsg, 4) == 0) {
+ return;
+ }
+ }
+ /* Message unique, so insert it */
+ jcr->reserve_msgs->push(bstrdup(jcr->errmsg));
+}
+
+/*
+ * Send any reservation messages queued for this jcr
+ */
+void send_drive_reserve_messages(JCR *jcr, BSOCK *user)
+{
+ int i;
+ alist *msgs;
+ char *msg;
+
+ P(search_lock);
+ msgs = jcr->reserve_msgs;
+ if (!msgs || msgs->size() == 0) {
+ V(search_lock);
+ return;
+ }
+ for (i=msgs->size()-1; i >= 0; i--) {
+ msg = (char *)msgs->get(i);
+ if (msg) {
+ bnet_fsend(user, " %s", msg);
+ } else {
+ break;
+ }
+ }
+ V(search_lock);
+}