本文整理汇总了C++中DEVICE::Lock方法的典型用法代码示例。如果您正苦于以下问题:C++ DEVICE::Lock方法的具体用法?C++ DEVICE::Lock怎么用?C++ DEVICE::Lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DEVICE
的用法示例。
在下文中一共展示了DEVICE::Lock方法的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
/*
* Wait for SysOp to mount a tape on a specific device
*
* Returns: W_ERROR, W_TIMEOUT, W_POLL, W_MOUNT, or W_WAKE
*/
int wait_for_sysop(DCR *dcr)
{
struct timeval tv;
struct timezone tz;
struct timespec timeout;
time_t last_heartbeat = 0;
time_t first_start = time(NULL);
int status = 0;
int add_wait;
bool unmounted;
DEVICE *dev = dcr->dev;
JCR *jcr = dcr->jcr;
dev->Lock();
Dmsg1(dbglvl, "Enter blocked=%s\n", dev->print_blocked());
/*
* Since we want to mount a tape, make sure current one is
* not marked as using this drive.
*/
volume_unused(dcr);
unmounted = dev->is_device_unmounted();
dev->poll = false;
/*
* Wait requested time (dev->rem_wait_sec). However, we also wake up every
* HB_TIME seconds and send a heartbeat to the FD and the Director
* to keep stateful firewalls from closing them down while waiting
* for the operator.
*/
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) {
add_wait = dev->vol_poll_interval;
}
if (!unmounted) {
Dmsg1(dbglvl, "blocked=%s\n", dev->print_blocked());
dev->dev_prev_blocked = dev->blocked();
dev->set_blocked(BST_WAITING_FOR_SYSOP); /* indicate waiting for mount */
}
for ( ; !job_canceled(jcr); ) {
time_t now, start, total_waited;
gettimeofday(&tv, &tz);
timeout.tv_nsec = tv.tv_usec * 1000;
timeout.tv_sec = tv.tv_sec + add_wait;
Dmsg4(dbglvl, "I'm going to sleep on device %s. HB=%d rem_wait=%d add_wait=%d\n",
dev->print_name(), (int)me->heartbeat_interval, dev->rem_wait_sec, add_wait);
start = time(NULL);
/* Wait required time */
status = pthread_cond_timedwait(&dev->wait_next_vol, &dev->m_mutex, &timeout);
Dmsg2(dbglvl, "Wokeup from sleep on device status=%d blocked=%s\n", status,
dev->print_blocked());
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;
}
//.........这里部分代码省略.........
示例4: acquire_device_for_read
/*********************************************************************
* Acquire device for reading.
* The drive should have previously been reserved by calling
* reserve_device_for_read(). We read the Volume label from the block and
* leave the block pointers just after the label.
*
* Returns: NULL if failed for any reason
* dcr if successful
*/
bool acquire_device_for_read(DCR *dcr)
{
DEVICE *dev;
JCR *jcr = dcr->jcr;
bool ok = false;
bool tape_previously_mounted;
VOL_LIST *vol;
bool try_autochanger = true;
int i;
int vol_label_status;
int retry = 0;
Enter(rdbglvl);
dev = dcr->dev;
dev->Lock_read_acquire();
Dmsg2(rdbglvl, "dcr=%p dev=%p\n", dcr, dcr->dev);
Dmsg2(rdbglvl, "MediaType dcr=%s dev=%s\n", dcr->media_type, dev->device->media_type);
dev->dblock(BST_DOING_ACQUIRE);
if (dev->num_writers > 0) {
Jmsg2(jcr, M_FATAL, 0, _("Acquire read: num_writers=%d not zero. Job %d canceled.\n"),
dev->num_writers, jcr->JobId);
goto get_out;
}
/* Find next Volume, if any */
vol = jcr->VolList;
if (!vol) {
char ed1[50];
Jmsg(jcr, M_FATAL, 0, _("No volumes specified for reading. Job %s canceled.\n"),
edit_int64(jcr->JobId, ed1));
goto get_out;
}
jcr->CurReadVolume++;
for (i=1; i<jcr->CurReadVolume; i++) {
vol = vol->next;
}
if (!vol) {
Jmsg(jcr, M_FATAL, 0, _("Logic error: no next volume to read. Numvol=%d Curvol=%d\n"),
jcr->NumReadVolumes, jcr->CurReadVolume);
goto get_out; /* should not happen */
}
set_dcr_from_vol(dcr, vol);
Dmsg2(rdbglvl, "Want Vol=%s Slot=%d\n", vol->VolumeName, vol->Slot);
/*
* If the MediaType requested for this volume is not the
* same as the current drive, we attempt to find the same
* device that was used to write the orginal volume. If
* found, we switch to using that device.
*
* N.B. A lot of routines rely on the dcr pointer not changing
* read_records.c even has multiple dcrs cached, so we take care
* here to release all important parts of the dcr and re-acquire
* them such as the block pointer (size may change), but we do
* not release the dcr.
*/
Dmsg2(rdbglvl, "MediaType dcr=%s dev=%s\n", dcr->media_type, dev->device->media_type);
if (dcr->media_type[0] && !bstrcmp(dcr->media_type, dev->device->media_type)) {
RCTX rctx;
DIRSTORE *store;
int status;
Jmsg3(jcr, M_INFO, 0, _("Changing read device. Want Media Type=\"%s\" have=\"%s\"\n"
" device=%s\n"),
dcr->media_type, dev->device->media_type, dev->print_name());
Dmsg3(rdbglvl, "Changing read device. Want Media Type=\"%s\" have=\"%s\"\n"
" device=%s\n",
dcr->media_type, dev->device->media_type, dev->print_name());
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 */
/*
//.........这里部分代码省略.........
示例5: release_device
/*
* This job is done, so release the device. From a Unix standpoint,
* the device remains open.
*
* Note, if we were spooling, we may enter with the device blocked.
* We unblock at the end, only if it was us who blocked the
* device.
*
*/
bool release_device(DCR *dcr)
{
utime_t now;
JCR *jcr = dcr->jcr;
DEVICE *dev = dcr->dev;
bool ok = true;
char tbuf[100];
int was_blocked = BST_NOT_BLOCKED;
/*
* Capture job statistics now that we are done using this device.
*/
now = (utime_t)time(NULL);
update_job_statistics(jcr, now);
dev->Lock();
if (!dev->is_blocked()) {
block_device(dev, BST_RELEASING);
} else {
was_blocked = dev->blocked();
dev->set_blocked(BST_RELEASING);
}
lock_volumes();
Dmsg2(100, "release_device device %s is %s\n", dev->print_name(), dev->is_tape() ? "tape" : "disk");
/*
* If device is reserved, job never started, so release the reserve here
*/
dcr->clear_reserved();
if (dev->can_read()) {
VOLUME_CAT_INFO *vol = &dev->VolCatInfo;
dev->clear_read(); /* clear read bit */
Dmsg2(150, "dir_update_vol_info. label=%d Vol=%s\n",
dev->is_labeled(), vol->VolCatName);
if (dev->is_labeled() && vol->VolCatName[0] != 0) {
dcr->dir_update_volume_info(false, false); /* send Volume info to Director */
remove_read_volume(jcr, dcr->VolumeName);
volume_unused(dcr);
}
} else if (dev->num_writers > 0) {
/*
* Note if WEOT is set, we are at the end of the tape and may not be positioned correctly,
* so the job_media_record and update_vol_info have already been done,
* which means we skip them here.
*/
dev->num_writers--;
Dmsg1(100, "There are %d writers in release_device\n", dev->num_writers);
if (dev->is_labeled()) {
Dmsg2(200, "dir_create_jobmedia. Release vol=%s dev=%s\n",
dev->getVolCatName(), dev->print_name());
if (!dev->at_weot() && !dcr->dir_create_jobmedia_record(false)) {
Jmsg2(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
dcr->getVolCatName(), jcr->Job);
}
/*
* If no more writers, and no errors, and wrote something, write an EOF
*/
if (!dev->num_writers && dev->can_write() && dev->block_num > 0) {
dev->weof(1);
write_ansi_ibm_labels(dcr, ANSI_EOF_LABEL, dev->VolHdr.VolumeName);
}
if (!dev->at_weot()) {
dev->VolCatInfo.VolCatFiles = dev->file; /* set number of files */
/*
* Note! do volume update before close, which zaps VolCatInfo
*/
dcr->dir_update_volume_info(false, false); /* send Volume info to Director */
Dmsg2(200, "dir_update_vol_info. Release vol=%s dev=%s\n",
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
//.........这里部分代码省略.........
示例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;
}