-/*
- * We reserve the device for appending by incrementing the
- * reserved_device. We do virtually all the same work that
- * is done in acquire_device_for_append(), but we do
- * not attempt to mount the device. This routine allows
- * the DIR to reserve multiple devices before *really*
- * starting the job. It also permits the SD to refuse
- * certain devices (not up, ...).
- *
- * Note, in reserving a device, if the device is for the
- * same pool and the same pool type, then it is acceptable.
- * The Media Type has already been checked. If we are
- * the first tor reserve the device, we put the pool
- * name and pool type in the device record.
- */
-bool reserve_device_for_append(JCR *jcr, DEVICE *dev)
-{
- DCR *dcr = jcr->dcr;
- bool ok = false;
-
- ASSERT(dcr);
-
- lock_device(dev);
- block_device(dev, BST_DOING_ACQUIRE);
- unlock_device(dev);
- if (dev->can_read()) {
- Jmsg(jcr, M_WARNING, 0, _("Device %s is busy reading.\n"), dev->print_name());
- goto bail_out;
- }
- if (device_is_unmounted(dev)) {
- Jmsg(jcr, M_WARNING, 0, _("device %s is BLOCKED due to user unmount.\n"),
- dev->print_name());
- goto bail_out;
- }
- Dmsg1(190, "reserve_append device is %s\n", dev_is_tape(dev)?"tape":"disk");
- /*
- * First handle the case that the drive is not yet in append mode
- */
- if (!dev->can_append() && dev->num_writers == 0) {
- /* Now check if there are any reservations on the drive */
- if (dev->reserved_device) {
- /* 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) {
- /* OK, compatible device */
- } else {
- /* Drive not suitable for us */
- Jmsg(jcr, M_WARNING, 0, _("Device %s is busy writing on another Volume.\n"), dev->print_name());
- goto bail_out;
- }
- } else {
- /* Device is available but not yet reserved, reserve it for us */
- bstrncpy(dev->pool_name, dcr->pool_name, sizeof(dev->pool_name));
- bstrncpy(dev->pool_type, dcr->pool_type, sizeof(dev->pool_type));
- dev->PoolId = dcr->PoolId;
- }
- goto do_reserve;
- }
-
- /*
- * Now check if the device is in append mode
- */
- if (dev->can_append() || dev->num_writers > 0) {
- Dmsg0(190, "device already in append.\n");
- /* 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) {
- /* OK, compatible device */
- } else {
- /* Drive not suitable for us */
- Jmsg(jcr, M_WARNING, 0, _("Device %s is busy writing on another Volume.\n"), dev->print_name());
- goto bail_out;
- }
- } else {
- Pmsg0(000, "Logic error!!!! Should not get here.\n");
- goto bail_out; /* should not get here */
- }
-
-do_reserve:
- dev->reserved_device++;
- dcr->reserved_device = true;
- ok = true;
-
-bail_out:
- P(dev->mutex);
- unblock_device(dev);
- V(dev->mutex);
- return ok;
-}