本文整理汇总了C++中DEVICE::Unlock方法的典型用法代码示例。如果您正苦于以下问题:C++ DEVICE::Unlock方法的具体用法?C++ DEVICE::Unlock怎么用?C++ DEVICE::Unlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DEVICE
的用法示例。
在下文中一共展示了DEVICE::Unlock方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: locked_detach_dcr_from_dev
/*
* DCR is locked before calling this routine
*/
static void locked_detach_dcr_from_dev(DCR *dcr)
{
DEVICE *dev = dcr->dev;
Dmsg0(500, "Enter detach_dcr_from_dev\n"); /* jcr is NULL in some cases */
/* Detach this dcr only if attached */
if (dcr->attached_to_dev && dev) {
dcr->unreserve_device();
dev->Lock();
Dmsg4(200, "Detach Jid=%d dcr=%p size=%d to dev=%s\n", (uint32_t)dcr->jcr->JobId,
dcr, dev->attached_dcrs->size(), dev->print_name());
dcr->attached_to_dev = false;
if (dev->attached_dcrs->size()) {
dev->attached_dcrs->remove(dcr); /* detach dcr from device */
}
// remove_dcr_from_dcrs(dcr); /* remove dcr from jcr list */
dev->Unlock();
}
dcr->attached_to_dev = false;
}
示例2: attach_dcr_to_dev
static void attach_dcr_to_dev(DCR *dcr)
{
DEVICE *dev;
JCR *jcr;
P(dcr->m_mutex);
dev = dcr->dev;
jcr = dcr->jcr;
if (jcr) Dmsg1(500, "JobId=%u enter attach_dcr_to_dev\n", (uint32_t)jcr->JobId);
/* ***FIXME*** return error if dev not initiated */
if (!dcr->attached_to_dev && dev->initiated && jcr && jcr->getJobType() != JT_SYSTEM) {
dev->Lock();
Dmsg4(200, "Attach Jid=%d dcr=%p size=%d dev=%s\n", (uint32_t)jcr->JobId,
dcr, dev->attached_dcrs->size(), dev->print_name());
dev->attached_dcrs->append(dcr); /* attach dcr to device */
dev->Unlock();
dcr->attached_to_dev = true;
}
V(dcr->m_mutex);
}
示例3: wait_for_sysop
//.........这里部分代码省略.........
now = time(NULL);
total_waited = now - first_start;
dev->rem_wait_sec -= (now - start);
/* Note, this always triggers the first time. We want that. */
if (me->heartbeat_interval) {
if (now - last_heartbeat >= me->heartbeat_interval) {
/* send heartbeats */
if (jcr->file_bsock) {
jcr->file_bsock->signal(BNET_HEARTBEAT);
Dmsg0(dbglvl, "Send heartbeat to FD.\n");
}
if (jcr->dir_bsock) {
jcr->dir_bsock->signal(BNET_HEARTBEAT);
}
last_heartbeat = now;
}
}
if (status == EINVAL) {
berrno be;
Jmsg1(jcr, M_FATAL, 0, _("pthread timedwait error. ERR=%s\n"), be.bstrerror(status));
status = W_ERROR; /* error */
break;
}
/*
* Continue waiting if operator is labeling volumes
*/
if (dev->blocked() == BST_WRITING_LABEL) {
continue;
}
if (dev->rem_wait_sec <= 0) { /* on exceeding wait time return */
Dmsg0(dbglvl, "Exceed wait time.\n");
status = W_TIMEOUT;
break;
}
/*
* Check if user unmounted the device while we were waiting
*/
unmounted = dev->is_device_unmounted();
if (!unmounted && dev->vol_poll_interval &&
(total_waited >= dev->vol_poll_interval)) {
Dmsg1(dbglvl, "poll return in wait blocked=%s\n", dev->print_blocked());
dev->poll = true; /* returning a poll event */
status = W_POLL;
break;
}
/*
* Check if user mounted the device while we were waiting
*/
if (dev->blocked() == BST_MOUNT) { /* mount request ? */
Dmsg0(dbglvl, "Mounted return.\n");
status = W_MOUNT;
break;
}
/*
* If we did not timeout, then some event happened, so
* return to check if state changed.
*/
if (status != ETIMEDOUT) {
berrno be;
Dmsg2(dbglvl, "Wake return. status=%d. ERR=%s\n", status, be.bstrerror(status));
status = W_WAKE; /* someone woke us */
break;
}
/*
* At this point, we know we woke up because of a timeout,
* that was due to a heartbeat, because any other reason would
* have caused us to return, so update the wait counters and continue.
*/
add_wait = dev->rem_wait_sec;
if (me->heartbeat_interval && add_wait > me->heartbeat_interval) {
add_wait = me->heartbeat_interval;
}
/* If the user did not unmount the tape and we are polling, ensure
* that we poll at the correct interval.
*/
if (!unmounted && dev->vol_poll_interval &&
add_wait > dev->vol_poll_interval - total_waited) {
add_wait = dev->vol_poll_interval - total_waited;
}
if (add_wait < 0) {
add_wait = 0;
}
}
if (!unmounted) {
dev->set_blocked(dev->dev_prev_blocked); /* restore entry state */
Dmsg1(dbglvl, "set %s\n", dev->print_blocked());
}
Dmsg1(dbglvl, "Exit blocked=%s\n", dev->print_blocked());
dev->Unlock();
return status;
}
示例4: acquire_device_for_read
//.........这里部分代码省略.........
dev->dunblock(DEV_UNLOCKED);
lock_reservations();
memset(&rctx, 0, sizeof(RCTX));
rctx.jcr = jcr;
jcr->read_dcr = dcr;
jcr->reserve_msgs = New(alist(10, not_owned_by_alist));
rctx.any_drive = true;
rctx.device_name = vol->device;
store = new DIRSTORE;
memset(store, 0, sizeof(DIRSTORE));
store->name[0] = 0; /* No dir name */
bstrncpy(store->media_type, vol->MediaType, sizeof(store->media_type));
bstrncpy(store->pool_name, dcr->pool_name, sizeof(store->pool_name));
bstrncpy(store->pool_type, dcr->pool_type, sizeof(store->pool_type));
store->append = false;
rctx.store = store;
clean_device(dcr); /* clean up the dcr */
/*
* Search for a new device
*/
status = search_res_for_device(rctx);
release_reserve_messages(jcr); /* release queued messages */
unlock_reservations();
if (status == 1) { /* found new device to use */
/*
* Switching devices, so acquire lock on new device,
* then release the old one.
*/
dcr->dev->Lock_read_acquire(); /* lock new one */
dev->Unlock_read_acquire(); /* release old one */
dev = dcr->dev; /* get new device pointer */
dev->dblock(BST_DOING_ACQUIRE);
dcr->VolumeName[0] = 0;
Jmsg(jcr, M_INFO, 0, _("Media Type change. New read device %s chosen.\n"),
dev->print_name());
Dmsg1(50, "Media Type change. New read device %s chosen.\n", dev->print_name());
bstrncpy(dcr->VolumeName, vol->VolumeName, sizeof(dcr->VolumeName));
dcr->setVolCatName(vol->VolumeName);
bstrncpy(dcr->media_type, vol->MediaType, sizeof(dcr->media_type));
dcr->VolCatInfo.Slot = vol->Slot;
dcr->VolCatInfo.InChanger = vol->Slot > 0;
bstrncpy(dcr->pool_name, store->pool_name, sizeof(dcr->pool_name));
bstrncpy(dcr->pool_type, store->pool_type, sizeof(dcr->pool_type));
} else {
/* error */
Jmsg1(jcr, M_FATAL, 0, _("No suitable device found to read Volume \"%s\"\n"),
vol->VolumeName);
Dmsg1(rdbglvl, "No suitable device found to read Volume \"%s\"\n", vol->VolumeName);
goto get_out;
}
}
Dmsg2(rdbglvl, "MediaType dcr=%s dev=%s\n", dcr->media_type, dev->device->media_type);
dev->clear_unload();
if (dev->vol && dev->vol->is_swapping()) {
dev->vol->set_slot(vol->Slot);
Dmsg3(rdbglvl, "swapping: slot=%d Vol=%s dev=%s\n", dev->vol->get_slot(),
dev->vol->vol_name, dev->print_name());
}
示例5: release_device
//.........这里部分代码省略.........
dev->getVolCatName(), dev->print_name());
}
if (dev->num_writers == 0) { /* if not being used */
volume_unused(dcr); /* we obviously are not using the volume */
}
}
} else {
/*
* If we reach here, it is most likely because the job has failed,
* since the device is not in read mode and there are no writers.
* It was probably reserved.
*/
volume_unused(dcr);
}
Dmsg3(100, "%d writers, %d reserve, dev=%s\n", dev->num_writers, dev->num_reserved(), dev->print_name());
/*
* If no writers, close if file or !CAP_ALWAYS_OPEN
*/
if (dev->num_writers == 0 && (!dev->is_tape() || !dev->has_cap(CAP_ALWAYSOPEN))) {
dev->close(dcr);
free_volume(dev);
}
unlock_volumes();
/*
* Fire off Alert command and include any output
*/
if (!job_canceled(jcr)) {
if (!dcr->device->drive_tapealert_enabled && dcr->device->alert_command) {
int status = 1;
POOLMEM *alert, *line;
BPIPE *bpipe;
alert = get_pool_memory(PM_FNAME);
line = get_pool_memory(PM_FNAME);
alert = edit_device_codes(dcr, alert, dcr->device->alert_command, "");
/*
* Wait maximum 5 minutes
*/
bpipe = open_bpipe(alert, 60 * 5, "r");
if (bpipe) {
while (bfgets(line, bpipe->rfd)) {
Jmsg(jcr, M_ALERT, 0, _("Alert: %s"), line);
}
status = close_bpipe(bpipe);
} else {
status = errno;
}
if (status != 0) {
berrno be;
Jmsg(jcr, M_ALERT, 0, _("3997 Bad alert command: %s: ERR=%s.\n"), alert, be.bstrerror(status));
}
Dmsg1(400, "alert status=%d\n", status);
free_pool_memory(alert);
free_pool_memory(line);
} else {
/*
* If all reservations are cleared for this device raise an event that SD plugins can register to.
*/
if (dev->num_reserved() == 0) {
generate_plugin_event(jcr, bsdEventDeviceReleased, dcr);
}
}
}
pthread_cond_broadcast(&dev->wait_next_vol);
Dmsg2(100, "JobId=%u broadcast wait_device_release at %s\n",
(uint32_t)jcr->JobId, bstrftimes(tbuf, sizeof(tbuf), (utime_t)time(NULL)));
release_device_cond();
/*
* If we are the thread that blocked the device, then unblock it
*/
if (pthread_equal(dev->no_wait_id, pthread_self())) {
dev->dunblock(true);
} else {
/*
* Otherwise, reset the prior block status and unlock
*/
dev->set_blocked(was_blocked);
dev->Unlock();
}
if (dcr->keep_dcr) {
detach_dcr_from_dev(dcr);
} else {
free_dcr(dcr);
}
Dmsg2(100, "Device %s released by JobId=%u\n", dev->print_name(), (uint32_t)jcr->JobId);
return ok;
}
示例6: Enter
/*
* Acquire device for writing. We permit multiple writers.
* If this is the first one, we read the label.
*
* Returns: NULL if failed for any reason
* dcr if successful.
* Note, normally reserve_device_for_append() is called
* before this routine.
*/
DCR *acquire_device_for_append(DCR *dcr)
{
DEVICE *dev = dcr->dev;
JCR *jcr = dcr->jcr;
bool ok = false;
bool have_vol = false;
Enter(200);
init_device_wait_timers(dcr);
dev->Lock_acquire(); /* only one job at a time */
dev->Lock();
Dmsg1(100, "acquire_append device is %s\n", dev->is_tape() ? "tape" : "disk");
/*
* With the reservation system, this should not happen
*/
if (dev->can_read()) {
Jmsg1(jcr, M_FATAL, 0, _("Want to append, but device %s is busy reading.\n"), dev->print_name());
Dmsg1(200, "Want to append but device %s is busy reading.\n", dev->print_name());
goto get_out;
}
dev->clear_unload();
/*
* have_vol defines whether or not mount_next_write_volume should
* ask the Director again about what Volume to use.
*/
if (dev->can_append() && dcr->is_suitable_volume_mounted() &&
!bstrcmp(dcr->VolCatInfo.VolCatStatus, "Recycle")) {
Dmsg0(190, "device already in append.\n");
/*
* At this point, the correct tape is already mounted, so
* we do not need to do mount_next_write_volume(), unless
* we need to recycle the tape.
*/
if (dev->num_writers == 0) {
dev->VolCatInfo = dcr->VolCatInfo; /* structure assignment */
}
have_vol = dcr->is_tape_position_ok();
}
if (!have_vol) {
dev->rLock(true);
block_device(dev, BST_DOING_ACQUIRE);
dev->Unlock();
Dmsg1(190, "jid=%u Do mount_next_write_vol\n", (uint32_t)jcr->JobId);
if (!dcr->mount_next_write_volume()) {
if (!job_canceled(jcr)) {
/* Reduce "noise" -- don't print if job canceled */
Jmsg(jcr, M_FATAL, 0, _("Could not ready device %s for append.\n"),
dev->print_name());
Dmsg1(200, "Could not ready device %s for append.\n",
dev->print_name());
}
dev->Lock();
unblock_device(dev);
goto get_out;
}
Dmsg2(190, "Output pos=%u:%u\n", dcr->dev->file, dcr->dev->block_num);
dev->Lock();
unblock_device(dev);
}
dev->num_writers++; /* we are now a writer */
if (jcr->NumWriteVolumes == 0) {
jcr->NumWriteVolumes = 1;
}
dev->VolCatInfo.VolCatJobs++; /* increment number of jobs on vol */
Dmsg4(100, "=== nwriters=%d nres=%d vcatjob=%d dev=%s\n",
dev->num_writers, dev->num_reserved(), dev->VolCatInfo.VolCatJobs, dev->print_name());
dcr->dir_update_volume_info(false, false); /* send Volume info to Director */
ok = true;
get_out:
/* Don't plugin close here, we might have multiple writers */
dcr->clear_reserved();
dev->Unlock();
dev->Unlock_acquire();
Leave(200);
return ok ? dcr : NULL;
}