本文整理汇总了C++中DEVICE::is_tape方法的典型用法代码示例。如果您正苦于以下问题:C++ DEVICE::is_tape方法的具体用法?C++ DEVICE::is_tape怎么用?C++ DEVICE::is_tape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DEVICE
的用法示例。
在下文中一共展示了DEVICE::is_tape方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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
//.........这里部分代码省略.........
示例2: 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;
}
示例3: if
DEVICE *m_init_dev(JCR *jcr, DEVRES *device)
{
struct stat statp;
int errstat;
DCR *dcr = NULL;
DEVICE *dev = NULL;
uint32_t max_bs;
/* If no device type specified, try to guess */
if (!device->dev_type) {
/* Check that device is available */
if (stat(device->device_name, &statp) < 0) {
berrno be;
Jmsg2(jcr, M_ERROR, 0, _("Unable to stat device %s: ERR=%s\n"),
device->device_name, be.bstrerror());
return NULL;
}
if (S_ISDIR(statp.st_mode)) {
device->dev_type = B_FILE_DEV;
} else if (S_ISCHR(statp.st_mode)) {
device->dev_type = B_TAPE_DEV;
} else if (S_ISFIFO(statp.st_mode)) {
device->dev_type = B_FIFO_DEV;
#ifdef USE_VTAPE
/* must set DeviceType = Vtape
* in normal mode, autodetection is disabled
*/
} else if (S_ISREG(statp.st_mode)) {
device->dev_type = B_VTAPE_DEV;
#endif
} else if (!(device->cap_bits & CAP_REQMOUNT)) {
Jmsg2(jcr, M_ERROR, 0, _("%s is an unknown device type. Must be tape or directory\n"
" or have RequiresMount=yes for DVD. st_mode=%x\n"),
device->device_name, statp.st_mode);
return NULL;
} else {
device->dev_type = B_DVD_DEV;
}
if (strcmp(device->device_name, "/dev/null") == 0) {
device->dev_type = B_NULL_DEV;
}
}
switch (device->dev_type) {
case B_DVD_DEV:
Jmsg0(jcr, M_FATAL, 0, _("DVD support is now deprecated.\n"));
return NULL;
case B_VTAPE_DEV:
dev = New(vtape);
break;
#ifdef USE_FTP
case B_FTP_DEV:
dev = New(ftp_device);
break;
#endif
case B_TAPE_DEV:
dev = New(tape_dev);
break;
case B_FILE_DEV:
case B_FIFO_DEV:
case B_NULL_DEV:
dev = New(file_dev);
break;
default:
return NULL;
}
dev->clear_slot(); /* unknown */
/* Copy user supplied device parameters from Resource */
dev->dev_name = get_memory(strlen(device->device_name)+1);
pm_strcpy(dev->dev_name, device->device_name);
dev->prt_name = get_memory(strlen(device->device_name) + strlen(device->hdr.name) + 20);
/* We edit "Resource-name" (physical-name) */
Mmsg(dev->prt_name, "\"%s\" (%s)", device->hdr.name, device->device_name);
Dmsg1(400, "Allocate dev=%s\n", dev->print_name());
dev->capabilities = device->cap_bits;
dev->min_free_space = device->min_free_space;
dev->min_block_size = device->min_block_size;
dev->max_block_size = device->max_block_size;
dev->max_volume_size = device->max_volume_size;
dev->max_file_size = device->max_file_size;
dev->max_concurrent_jobs = device->max_concurrent_jobs;
dev->volume_capacity = device->volume_capacity;
dev->max_rewind_wait = device->max_rewind_wait;
dev->max_open_wait = device->max_open_wait;
dev->vol_poll_interval = device->vol_poll_interval;
dev->max_spool_size = device->max_spool_size;
dev->drive_index = device->drive_index;
dev->enabled = device->enabled;
dev->autoselect = device->autoselect;
dev->read_only = device->read_only;
dev->dev_type = device->dev_type;
dev->device = device;
if (dev->is_tape()) { /* No parts on tapes */
dev->max_part_size = 0;
} else {
dev->max_part_size = device->max_part_size;
}
/* Sanity check */
if (dev->vol_poll_interval && dev->vol_poll_interval < 60) {
dev->vol_poll_interval = 60;
//.........这里部分代码省略.........
示例4: if
//.........这里部分代码省略.........
if (!device->mount_point || stat(device->mount_point, &statp) < 0) {
berrno be;
dev->dev_errno = errno;
Jmsg2(jcr, M_ERROR_TERM, 0, _("Unable to stat mount point %s: ERR=%s\n"),
device->mount_point, be.bstrerror());
}
if (!device->mount_command || !device->unmount_command) {
Jmsg0(jcr, M_ERROR_TERM, 0, _("Mount and unmount commands must defined for a device which requires mount.\n"));
}
}
/*
* Sanity check
*/
if (dev->max_block_size == 0) {
max_bs = DEFAULT_BLOCK_SIZE;
} else {
max_bs = dev->max_block_size;
}
if (dev->min_block_size > max_bs) {
Jmsg(jcr, M_ERROR_TERM, 0, _("Min block size > max on device %s\n"), dev->print_name());
}
if (dev->max_block_size > MAX_BLOCK_LENGTH) {
Jmsg3(jcr, M_ERROR, 0, _("Block size %u on device %s is too large, using default %u\n"),
dev->max_block_size, dev->print_name(), DEFAULT_BLOCK_SIZE);
dev->max_block_size = 0;
}
if (dev->max_block_size % TAPE_BSIZE != 0) {
Jmsg3(jcr, M_WARNING, 0, _("Max block size %u not multiple of device %s block size=%d.\n"),
dev->max_block_size, dev->print_name(), TAPE_BSIZE);
}
if (dev->max_volume_size != 0 && dev->max_volume_size < (dev->max_block_size << 4)) {
Jmsg(jcr, M_ERROR_TERM, 0, _("Max Vol Size < 8 * Max Block Size for device %s\n"), dev->print_name());
}
dev->errmsg = get_pool_memory(PM_EMSG);
*dev->errmsg = 0;
if ((errstat = dev->init_mutex()) != 0) {
berrno be;
dev->dev_errno = errstat;
Mmsg1(dev->errmsg, _("Unable to init mutex: ERR=%s\n"), be.bstrerror(errstat));
Jmsg0(jcr, M_ERROR_TERM, 0, dev->errmsg);
}
if ((errstat = pthread_cond_init(&dev->wait, NULL)) != 0) {
berrno be;
dev->dev_errno = errstat;
Mmsg1(dev->errmsg, _("Unable to init cond variable: ERR=%s\n"), be.bstrerror(errstat));
Jmsg0(jcr, M_ERROR_TERM, 0, dev->errmsg);
}
if ((errstat = pthread_cond_init(&dev->wait_next_vol, NULL)) != 0) {
berrno be;
dev->dev_errno = errstat;
Mmsg1(dev->errmsg, _("Unable to init cond variable: ERR=%s\n"), be.bstrerror(errstat));
Jmsg0(jcr, M_ERROR_TERM, 0, dev->errmsg);
}
if ((errstat = pthread_mutex_init(&dev->spool_mutex, NULL)) != 0) {
berrno be;
dev->dev_errno = errstat;
Mmsg1(dev->errmsg, _("Unable to init spool mutex: ERR=%s\n"), be.bstrerror(errstat));
Jmsg0(jcr, M_ERROR_TERM, 0, dev->errmsg);
}
if ((errstat = dev->init_acquire_mutex()) != 0) {
berrno be;
dev->dev_errno = errstat;
Mmsg1(dev->errmsg, _("Unable to init acquire mutex: ERR=%s\n"), be.bstrerror(errstat));
Jmsg0(jcr, M_ERROR_TERM, 0, dev->errmsg);
}
if ((errstat = dev->init_read_acquire_mutex()) != 0) {
berrno be;
dev->dev_errno = errstat;
Mmsg1(dev->errmsg, _("Unable to init read acquire mutex: ERR=%s\n"), be.bstrerror(errstat));
Jmsg0(jcr, M_ERROR_TERM, 0, dev->errmsg);
}
dev->set_mutex_priorities();
#ifdef xxx
if ((errstat = rwl_init(&dev->lock)) != 0) {
berrno be;
dev->dev_errno = errstat;
Mmsg1(dev->errmsg, _("Unable to init mutex: ERR=%s\n"), be.bstrerror(errstat));
Jmsg0(jcr, M_ERROR_TERM, 0, dev->errmsg);
}
#endif
dev->clear_opened();
dev->attached_dcrs = New(dlist(dcr, &dcr->dev_link));
Dmsg2(100, "init_dev: tape=%d dev_name=%s\n", dev->is_tape(), dev->dev_name);
dev->initiated = true;
Dmsg3(100, "dev=%s dev_max_bs=%u max_bs=%u\n", dev->dev_name, dev->device->max_block_size, dev->max_block_size);
return dev;
}
示例5: write_session_label
/* Write session label
* Returns: false on failure
* true on success
*/
bool write_session_label(DCR *dcr, int label)
{
JCR *jcr = dcr->jcr;
DEVICE *dev = dcr->dev;
DEV_RECORD *rec;
DEV_BLOCK *block = dcr->block;
char buf1[100], buf2[100];
rec = new_record();
Dmsg1(130, "session_label record=%x\n", rec);
switch (label) {
case SOS_LABEL:
set_start_vol_position(dcr);
break;
case EOS_LABEL:
if (dev->is_tape()) {
dcr->EndBlock = dev->EndBlock;
dcr->EndFile = dev->EndFile;
} else {
dcr->EndBlock = (uint32_t)dev->file_addr;
dcr->EndFile = (uint32_t)(dev->file_addr >> 32);
}
break;
default:
Jmsg1(jcr, M_ABORT, 0, _("Bad Volume session label = %d\n"), label);
break;
}
create_session_label(dcr, rec, label);
rec->FileIndex = label;
/*
* We guarantee that the session record can totally fit
* into a block. If not, write the block, and put it in
* the next block. Having the sesssion record totally in
* one block makes reading them much easier (no need to
* read the next block).
*/
if (!can_write_record_to_block(block, rec)) {
Dmsg0(150, "Cannot write session label to block.\n");
if (!dcr->write_block_to_device()) {
Dmsg0(130, "Got session label write_block_to_dev error.\n");
free_record(rec);
return false;
}
}
if (!write_record_to_block(dcr, rec)) {
free_record(rec);
return false;
}
Dmsg6(150, "Write sesson_label record JobId=%d FI=%s SessId=%d Strm=%s len=%d "
"remainder=%d\n", jcr->JobId,
FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId,
stream_to_ascii(buf2, rec->Stream, rec->FileIndex), rec->data_len,
rec->remainder);
free_record(rec);
Dmsg2(150, "Leave write_session_label Block=%ud File=%ud\n",
dev->get_block_num(), dev->get_file());
return true;
}
示例6: write_new_volume_label_to_dev
/*
* Write a Volume Label
* !!! Note, this is ONLY used for writing
* a fresh volume label. Any data
* after the label will be destroyed,
* in fact, we write the label 5 times !!!!
*
* This routine should be used only when labeling a blank tape.
*/
bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName,
const char *PoolName, bool relabel)
{
JCR *jcr = dcr->jcr;
DEVICE *dev = dcr->dev;
DEV_BLOCK *block = dcr->block;
Dmsg0(150, "write_volume_label()\n");
if (*VolName == 0) {
Pmsg0(0, "=== ERROR: write_new_volume_label_to_dev called with NULL VolName\n");
goto bail_out;
}
if (relabel) {
volume_unused(dcr); /* mark current volume unused */
/* Truncate device */
if (!dev->truncate(dcr)) {
goto bail_out;
}
if (!dev->is_tape()) {
dev->close(dcr); /* make sure file closed for rename */
}
}
/* Set the new filename for open, ... */
dev->setVolCatName(VolName);
dcr->setVolCatName(VolName);
Dmsg1(150, "New VolName=%s\n", VolName);
if (!dev->open(dcr, OPEN_READ_WRITE)) {
/* If device is not tape, attempt to create it */
if (dev->is_tape() || !dev->open(dcr, CREATE_READ_WRITE)) {
Jmsg3(jcr, M_WARNING, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"),
dev->print_name(), dcr->VolumeName, dev->bstrerror());
goto bail_out;
}
}
Dmsg1(150, "Label type=%d\n", dev->label_type);
/*
* Let any stored plugin know that we are about to write a new label to the volume.
*/
if (generate_plugin_event(jcr, bsdEventLabelWrite, dcr) != bRC_OK) {
Dmsg0(200, "Error from bsdEventLabelWrite plugin event.\n");
goto bail_out;
}
for ( ;; ) {
empty_block(block);
if (!dev->rewind(dcr)) {
Dmsg2(130, "Bad status on %s from rewind: ERR=%s\n", dev->print_name(), dev->print_errmsg());
if (!forge_on) {
goto bail_out;
}
}
/* Temporarily mark in append state to enable writing */
dev->set_append();
/* Create PRE_LABEL */
create_volume_label(dev, VolName, PoolName);
/*
* If we have already detected an ANSI label, re-read it
* to skip past it. Otherwise, we write a new one if
* so requested.
*/
if (dev->label_type != B_BAREOS_LABEL) {
if (read_ansi_ibm_label(dcr) != VOL_OK) {
dev->rewind(dcr);
goto bail_out;
}
} else if (!write_ansi_ibm_labels(dcr, ANSI_VOL_LABEL, VolName)) {
goto bail_out;
}
create_volume_label_record(dcr, dev, dcr->rec);
dcr->rec->Stream = 0;
dcr->rec->maskedStream = 0;
if (!write_record_to_block(dcr, dcr->rec)) {
Dmsg2(130, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->print_errmsg());
goto bail_out;
} else {
Dmsg2(130, "Wrote label of %d bytes to %s\n", dcr->rec->data_len, dev->print_name());
}
Dmsg0(130, "Call write_block_to_dev()\n");
if (!dcr->write_block_to_dev()) {
Dmsg2(130, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->print_errmsg());
goto bail_out;
}
//.........这里部分代码省略.........