本文整理汇总了C++中Dmsg2函数的典型用法代码示例。如果您正苦于以下问题:C++ Dmsg2函数的具体用法?C++ Dmsg2怎么用?C++ Dmsg2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Dmsg2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: commit_attribute_spool
bool commit_attribute_spool(JCR *jcr)
{
boffset_t size, data_end;
char ec1[30];
char tbuf[MAX_TIME_LENGTH];
BSOCK *dir;
Dmsg1(100, "Commit attributes at %s\n", bstrftimes(tbuf, sizeof(tbuf), (utime_t)time(NULL)));
if (are_attributes_spooled(jcr)) {
dir = jcr->dir_bsock;
if ((size = lseek(dir->m_spool_fd, 0, SEEK_END)) == -1) {
berrno be;
Jmsg(jcr, M_FATAL, 0, _("lseek on attributes file failed: ERR=%s\n"), be.bstrerror());
jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
goto bail_out;
}
if (jcr->is_JobStatus(JS_Incomplete)) {
data_end = dir->get_data_end();
/*
* Check and truncate to last valid data_end if necssary
*/
if (size > data_end) {
if (ftruncate(dir->m_spool_fd, data_end) != 0) {
berrno be;
Jmsg(jcr, M_FATAL, 0, _("Truncate on attributes file failed: ERR=%s\n"), be.bstrerror());
jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
goto bail_out;
}
Dmsg2(100, "=== Attrib spool truncated from %lld to %lld\n", size, data_end);
size = data_end;
}
}
if (size < 0) {
berrno be;
Jmsg(jcr, M_FATAL, 0, _("Fseek on attributes file failed: ERR=%s\n"),
be.bstrerror());
jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
goto bail_out;
}
P(mutex);
if (spool_stats.attr_size + size > spool_stats.max_attr_size) {
spool_stats.max_attr_size = spool_stats.attr_size + size;
}
spool_stats.attr_size += size;
V(mutex);
jcr->sendJobStatus(JS_AttrDespooling);
Jmsg(jcr, M_INFO, 0, _("Sending spooled attrs to the Director. Despooling %s bytes ...\n"),
edit_uint64_with_commas(size, ec1));
if (!blast_attr_spool_file(jcr, size)) {
/* Can't read spool file from director side,
* send content over network.
*/
dir->despool(update_attr_spool_size, size);
}
return close_attr_spool_file(jcr, dir);
}
return true;
bail_out:
close_attr_spool_file(jcr, dir);
return false;
}
示例2: save_resource
//.........这里部分代码省略.........
URES *res;
int rindex = type - r_first;
int i, size = 0;
int error = 0;
/*
* Ensure that all required items are present
*/
for (i=0; items[i].name; i++) {
if (items[i].flags & ITEM_REQUIRED) {
if (!bit_is_set(i, res_all.dir_res.hdr.item_present)) {
Emsg2(M_ABORT, 0, _("%s item is required in %s resource, but not found.\n"),
items[i].name, resources[rindex]);
}
}
}
/*
* During pass 2, we looked up pointers to all the resources
* referrenced in the current resource, , now we
* must copy their address from the static record to the allocated
* record.
*/
if (pass == 2) {
switch (type) {
/*
* Resources not containing a resource
*/
case R_DIRECTOR:
break;
case R_CONSOLE:
case R_CONSOLE_FONT:
break;
default:
Emsg1(M_ERROR, 0, _("Unknown resource type %d\n"), type);
error = 1;
break;
}
/*
* Note, the resoure name was already saved during pass 1,
* so here, we can just release it.
*/
if (res_all.dir_res.hdr.name) {
free(res_all.dir_res.hdr.name);
res_all.dir_res.hdr.name = NULL;
}
if (res_all.dir_res.hdr.desc) {
free(res_all.dir_res.hdr.desc);
res_all.dir_res.hdr.desc = NULL;
}
return;
}
/*
* The following code is only executed during pass 1
*/
switch (type) {
case R_DIRECTOR:
size = sizeof(DIRRES);
break;
case R_CONSOLE_FONT:
size = sizeof(CONFONTRES);
break;
case R_CONSOLE:
size = sizeof(CONRES);
break;
default:
printf(_("Unknown resource type %d\n"), type);
error = 1;
break;
}
/*
* Common
*/
if (!error) {
res = (URES *)malloc(size);
memcpy(res, &res_all, size);
if (!res_head[rindex]) {
res_head[rindex] = (RES *)res; /* store first entry */
} else {
RES *next, *last;
/*
* Add new res to end of chain
*/
for (last=next=res_head[rindex]; next; next=next->next) {
last = next;
if (strcmp(next->name, res->dir_res.hdr.name) == 0) {
Emsg2(M_ERROR_TERM, 0,
_("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
resources[rindex].name, res->dir_res.hdr.name);
}
}
last->next = (RES *)res;
Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
res->dir_res.hdr.name);
}
}
}
示例3: duration_to_utime
/*
* Convert a string duration to utime_t (64 bit seconds)
* Returns false: if error
true: if OK, and value stored in value
*/
bool duration_to_utime(char *str, utime_t *value)
{
int i, mod_len;
double val, total = 0.0;
char mod_str[20];
char num_str[50];
/*
* The "n" = mins and months appears before minutes so that m maps to months.
*/
static const char *mod[] = {
"n",
"seconds",
"months",
"minutes",
"mins",
"hours",
"days",
"weeks",
"quarters",
"years",
(char *)NULL
};
static const int32_t mult[] = {
60,
1,
60 * 60 * 24 * 30,
60,
60,
3600,
3600 * 24,
3600 * 24 * 7,
3600 * 24 * 91,
3600 * 24 * 365,
0
};
while (*str) {
if (!get_modifier(str, num_str, sizeof(num_str), mod_str, sizeof(mod_str))) {
return false;
}
/* Now find the multiplier corresponding to the modifier */
mod_len = strlen(mod_str);
if (mod_len == 0) {
i = 1; /* default to seconds */
} else {
for (i=0; mod[i]; i++) {
if (bstrncasecmp(mod_str, mod[i], mod_len)) {
break;
}
}
if (mod[i] == NULL) {
return false;
}
}
Dmsg2(900, "str=%s: mult=%d\n", num_str, mult[i]);
errno = 0;
val = strtod(num_str, NULL);
if (errno != 0 || val < 0) {
return false;
}
total += val * mult[i];
}
*value = (utime_t)total;
return true;
}
示例4: dir_find_next_appendable_volume
/**
* Get info on the next appendable volume in the Director's database
*
* Returns: true on success dcr->VolumeName is volume
* reserve_volume() called on Volume name
* false on failure dcr->VolumeName[0] == 0
* also sets dcr->found_in_use if at least one
* in use volume was found.
*
* Volume information returned in dcr
*
*/
bool dir_find_next_appendable_volume(DCR *dcr)
{
JCR *jcr = dcr->jcr;
BSOCK *dir = jcr->dir_bsock;
bool rtn;
char lastVolume[MAX_NAME_LENGTH];
Dmsg2(dbglvl, "dir_find_next_appendable_volume: reserved=%d Vol=%s\n",
dcr->is_reserved(), dcr->VolumeName);
/*
* Try the twenty oldest or most available volumes. Note,
* the most available could already be mounted on another
* drive, so we continue looking for a not in use Volume.
*/
lock_volumes();
P(vol_info_mutex);
dcr->clear_found_in_use();
lastVolume[0] = 0;
for (int vol_index=1; vol_index < 20; vol_index++) {
bash_spaces(dcr->media_type);
bash_spaces(dcr->pool_name);
dir->fsend(Find_media, jcr->Job, vol_index, dcr->pool_name, dcr->media_type);
unbash_spaces(dcr->media_type);
unbash_spaces(dcr->pool_name);
Dmsg1(dbglvl, ">dird %s", dir->msg);
if (do_get_volume_info(dcr)) {
/* Give up if we get the same volume name twice */
if (lastVolume[0] && bstrcmp(lastVolume, dcr->VolumeName)) {
Dmsg1(dbglvl, "Got same vol = %s\n", lastVolume);
break;
}
bstrncpy(lastVolume, dcr->VolumeName, sizeof(lastVolume));
if (dcr->can_i_write_volume()) {
Dmsg1(dbglvl, "Call reserve_volume for write. Vol=%s\n", dcr->VolumeName);
if (reserve_volume(dcr, dcr->VolumeName) == NULL) {
Dmsg2(dbglvl, "Could not reserve volume %s on %s\n", dcr->VolumeName,
dcr->dev->print_name());
continue;
}
Dmsg1(dbglvl, "dir_find_next_appendable_volume return true. vol=%s\n",
dcr->VolumeName);
rtn = true;
goto get_out;
} else {
Dmsg1(dbglvl, "Volume %s is in use.\n", dcr->VolumeName);
/* If volume is not usable, it is in use by someone else */
dcr->set_found_in_use();
continue;
}
}
Dmsg2(dbglvl, "No vol. index %d return false. dev=%s\n", vol_index,
dcr->dev->print_name());
break;
}
rtn = false;
dcr->VolumeName[0] = 0;
get_out:
V(vol_info_mutex);
unlock_volumes();
return rtn;
}
示例5: match_all
/*
* Match all the components of current record
* returns 1 on match
* returns 0 no match
* returns -1 no additional matches possible
*/
static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
SESSION_LABEL *sessrec, bool done, JCR *jcr)
{
Dmsg0(dbglevel, "Enter match_all\n");
if (bsr->done) {
// Dmsg0(dbglevel, "bsr->done set\n");
goto no_match;
}
if (!match_volume(bsr, bsr->volume, volrec, 1)) {
Dmsg2(dbglevel, "bsr fail bsr_vol=%s != rec read_vol=%s\n", bsr->volume->VolumeName,
volrec->VolumeName);
goto no_match;
}
Dmsg2(dbglevel, "OK bsr match bsr_vol=%s read_vol=%s\n", bsr->volume->VolumeName,
volrec->VolumeName);
if (!match_volfile(bsr, bsr->volfile, rec, 1)) {
if (bsr->volfile) {
Dmsg3(dbglevel, "Fail on file=%u. bsr=%u,%u\n",
rec->File, bsr->volfile->sfile, bsr->volfile->efile);
}
goto no_match;
}
if (!match_voladdr(bsr, bsr->voladdr, rec, 1)) {
if (bsr->voladdr) {
Dmsg3(dbglevel, "Fail on Addr=%llu. bsr=%llu,%llu\n",
get_record_address(rec), bsr->voladdr->saddr, bsr->voladdr->eaddr);
}
goto no_match;
}
if (!match_sesstime(bsr, bsr->sesstime, rec, 1)) {
Dmsg2(dbglevel, "Fail on sesstime. bsr=%u rec=%u\n",
bsr->sesstime->sesstime, rec->VolSessionTime);
goto no_match;
}
/* NOTE!! This test MUST come after the sesstime test */
if (!match_sessid(bsr, bsr->sessid, rec)) {
Dmsg2(dbglevel, "Fail on sessid. bsr=%u rec=%u\n",
bsr->sessid->sessid, rec->VolSessionId);
goto no_match;
}
/* NOTE!! This test MUST come after sesstime and sessid tests */
if (!match_findex(bsr, bsr->FileIndex, rec, 1)) {
Dmsg3(dbglevel, "Fail on findex=%d. bsr=%d,%d\n",
rec->FileIndex, bsr->FileIndex->findex, bsr->FileIndex->findex2);
goto no_match;
}
Dmsg3(dbglevel, "match on findex=%d. bsr=%d,%d\n",
rec->FileIndex, bsr->FileIndex->findex, bsr->FileIndex->findex2);
if (!match_fileregex(bsr, rec, jcr)) {
Dmsg1(dbglevel, "Fail on fileregex='%s'\n", bsr->fileregex);
goto no_match;
}
/* This flag is set by match_fileregex (and perhaps other tests) */
if (bsr->skip_file) {
Dmsg1(dbglevel, "Skipping findex=%d\n", rec->FileIndex);
goto no_match;
}
/*
* If a count was specified and we have a FileIndex, assume
* it is a Bareos created bsr (or the equivalent). We
* then save the bsr where the match occurred so that
* after processing the record or records, we can update
* the found count. I.e. rec->bsr points to the bsr that
* satisfied the match.
*/
if (bsr->count && bsr->FileIndex) {
rec->bsr = bsr;
Dmsg0(dbglevel, "Leave match_all 1\n");
return 1; /* this is a complete match */
}
/*
* The selections below are not used by Bareos's
* restore command, and don't work because of
* the rec->bsr = bsr optimization above.
*/
if (!match_jobid(bsr, bsr->JobId, sessrec, 1)) {
Dmsg0(dbglevel, "fail on JobId\n");
goto no_match;
}
if (!match_job(bsr, bsr->job, sessrec, 1)) {
Dmsg0(dbglevel, "fail on Job\n");
goto no_match;
}
if (!match_client(bsr, bsr->client, sessrec, 1)) {
//.........这里部分代码省略.........
示例6: db_find_next_volume
/*
* Find Available Media (Volume) for Pool
*
* Find a Volume for a given PoolId, MediaType, and Status.
* The unwanted_volumes variable lists the VolumeNames which we should skip if any.
*
* Returns: 0 on failure
* numrows on success
*/
int db_find_next_volume(JCR *jcr, B_DB *mdb, int item, bool InChanger, MEDIA_DBR *mr, const char *unwanted_volumes)
{
char ed1[50];
int num_rows = 0;
SQL_ROW row = NULL;
bool find_oldest = false;
bool found_candidate = false;
char esc_type[MAX_ESCAPE_NAME_LENGTH];
char esc_status[MAX_ESCAPE_NAME_LENGTH];
db_lock(mdb);
mdb->db_escape_string(jcr, esc_type, mr->MediaType, strlen(mr->MediaType));
mdb->db_escape_string(jcr, esc_status, mr->VolStatus, strlen(mr->VolStatus));
if (item == -1) {
find_oldest = true;
item = 1;
}
retry_fetch:
if (find_oldest) {
/*
* Find oldest volume(s)
*/
Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolJobs,VolFiles,VolBlocks,"
"VolBytes,VolMounts,VolErrors,VolWrites,MaxVolBytes,VolCapacityBytes,"
"MediaType,VolStatus,PoolId,VolRetention,VolUseDuration,MaxVolJobs,"
"MaxVolFiles,Recycle,Slot,FirstWritten,LastWritten,InChanger,"
"EndFile,EndBlock,LabelType,LabelDate,StorageId,"
"Enabled,LocationId,RecycleCount,InitialWrite,"
"ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime,"
"ActionOnPurge,EncryptionKey,MinBlocksize,MaxBlocksize "
"FROM Media WHERE PoolId=%s AND MediaType='%s' AND VolStatus IN ('Full',"
"'Recycle','Purged','Used','Append') AND Enabled=1 "
"ORDER BY LastWritten LIMIT %d",
edit_int64(mr->PoolId, ed1), esc_type, item);
} else {
POOL_MEM changer(PM_FNAME);
const char *order;
/*
* Find next available volume
*/
if (InChanger) {
Mmsg(changer, "AND InChanger=1 AND StorageId=%s", edit_int64(mr->StorageId, ed1));
}
if (bstrcmp(mr->VolStatus, "Recycle") ||
bstrcmp(mr->VolStatus, "Purged")) {
order = "AND Recycle=1 ORDER BY LastWritten ASC,MediaId"; /* take oldest that can be recycled */
} else {
order = sql_media_order_most_recently_written[db_get_type_index(mdb)]; /* take most recently written */
}
Mmsg(mdb->cmd, "SELECT MediaId,VolumeName,VolJobs,VolFiles,VolBlocks,"
"VolBytes,VolMounts,VolErrors,VolWrites,MaxVolBytes,VolCapacityBytes,"
"MediaType,VolStatus,PoolId,VolRetention,VolUseDuration,MaxVolJobs,"
"MaxVolFiles,Recycle,Slot,FirstWritten,LastWritten,InChanger,"
"EndFile,EndBlock,LabelType,LabelDate,StorageId,"
"Enabled,LocationId,RecycleCount,InitialWrite,"
"ScratchPoolId,RecyclePoolId,VolReadTime,VolWriteTime,"
"ActionOnPurge,EncryptionKey,MinBlocksize,MaxBlocksize "
"FROM Media WHERE PoolId=%s AND MediaType='%s' AND Enabled=1 "
"AND VolStatus='%s' "
"%s "
"%s LIMIT %d",
edit_int64(mr->PoolId, ed1), esc_type,
esc_status, changer.c_str(), order, item);
}
Dmsg1(100, "fnextvol=%s\n", mdb->cmd);
if (!QUERY_DB(jcr, mdb, mdb->cmd)) {
goto bail_out;
}
num_rows = sql_num_rows(mdb);
if (item > num_rows || item < 1) {
Dmsg2(050, "item=%d got=%d\n", item, num_rows);
Mmsg2(&mdb->errmsg, _("Request for Volume item %d greater than max %d or less than 1\n"), item, num_rows);
num_rows = 0;
goto bail_out;
}
for (int i = 0 ; i < item; i++) {
if ((row = sql_fetch_row(mdb)) == NULL) {
Dmsg1(050, "Fail fetch item=%d\n", i);
Mmsg1(&mdb->errmsg, _("No Volume record found for item %d.\n"), i);
sql_free_result(mdb);
num_rows = 0;
goto bail_out;
//.........这里部分代码省略.........
示例7: run_scripts
int run_scripts(JCR *jcr, alist *runscripts, const char *label, alist *allowed_script_dirs)
{
RUNSCRIPT *script;
bool runit;
int when;
Dmsg2(200, "runscript: running all RUNSCRIPT object (%s) JobStatus=%c\n", label, jcr->JobStatus);
if (strstr(label, NT_("Before"))) {
when = SCRIPT_Before;
} else if (bstrcmp(label, NT_("ClientAfterVSS"))) {
when = SCRIPT_AfterVSS;
} else {
when = SCRIPT_After;
}
if (runscripts == NULL) {
Dmsg0(100, "runscript: WARNING RUNSCRIPTS list is NULL\n");
return 0;
}
foreach_alist(script, runscripts) {
Dmsg2(200, "runscript: try to run %s:%s\n", NPRT(script->target), NPRT(script->command));
runit = false;
if ((script->when & SCRIPT_Before) && (when & SCRIPT_Before)) {
if ((script->on_success && (jcr->JobStatus == JS_Running || jcr->JobStatus == JS_Created)) ||
(script->on_failure && (job_canceled(jcr) || jcr->JobStatus == JS_Differences))) {
Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n",
script->command, script->on_success, script->on_failure, jcr->JobStatus );
runit = true;
}
}
if ((script->when & SCRIPT_AfterVSS) && (when & SCRIPT_AfterVSS)) {
if ((script->on_success && (jcr->JobStatus == JS_Blocked)) ||
(script->on_failure && job_canceled(jcr))) {
Dmsg4(200, "runscript: Run it because SCRIPT_AfterVSS (%s,%i,%i,%c)\n",
script->command, script->on_success, script->on_failure, jcr->JobStatus );
runit = true;
}
}
if ((script->when & SCRIPT_After) && (when & SCRIPT_After)) {
if ((script->on_success && (jcr->JobStatus == JS_Terminated || jcr->JobStatus == JS_Warnings)) ||
(script->on_failure && (job_canceled(jcr) || jcr->JobStatus == JS_Differences))) {
Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n",
script->command, script->on_success, script->on_failure, jcr->JobStatus );
runit = true;
}
}
if (!script->is_local()) {
runit = false;
}
/*
* We execute it
*/
if (runit) {
if (!script_dir_allowed(jcr, script, allowed_script_dirs)) {
Dmsg1(200, "runscript: Not running script %s because its not in one of the allowed scripts dirs\n",
script->command);
Jmsg(jcr, M_ERROR, 0, _("Runscript: run %s \"%s\" could not execute, "
"not in one of the allowed scripts dirs\n"), label, script->command);
jcr->setJobStatus(JS_ErrorTerminated);
goto bail_out;
}
script->run(jcr, label);
}
}
示例8: 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;
}
示例9: 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
//.........这里部分代码省略.........
示例10: Dmsg2
/*
* If release is set, we rewind the current volume,
* which we no longer want, and ask the user (console)
* to mount the next volume.
*
* Continue trying until we get it, and then ensure
* that we can write on it.
*
* This routine returns a 0 only if it is REALLY
* impossible to get the requested Volume.
*
*/
bool DCR::mount_next_write_volume()
{
int retry = 0;
bool ask = false, recycle, autochanger;
bool do_find = true;
int mode;
DCR *dcr = this;
Dmsg2(150, "Enter mount_next_volume(release=%d) dev=%s\n", dev->must_unload(),
dev->print_name());
init_device_wait_timers(dcr);
lock_volumes();
/*
* Attempt to mount the next volume. If something non-fatal goes
* wrong, we come back here to re-try (new op messages, re-read
* Volume, ...)
*/
mount_next_vol:
Dmsg1(150, "mount_next_vol retry=%d\n", retry);
/* Ignore retry if this is poll request */
if (!dev->poll && retry++ > 4) {
/* Last ditch effort before giving up, force operator to respond */
VolCatInfo.Slot = 0;
unlock_volumes();
if (!dir_ask_sysop_to_mount_volume(dcr, ST_APPEND)) {
Jmsg(jcr, M_FATAL, 0, _("Too many errors trying to mount device %s.\n"),
dev->print_name());
goto no_lock_bail_out;
}
lock_volumes();
Dmsg1(150, "Continue after dir_ask_sysop_to_mount. must_load=%d\n", dev->must_load());
}
if (job_canceled(jcr)) {
Jmsg(jcr, M_FATAL, 0, _("Job %d canceled.\n"), jcr->JobId);
goto bail_out;
}
recycle = false;
if (retry >= 2) {
do_find = false;
}
if (dev->must_unload()) {
ask = true; /* ask operator to mount tape */
do_find = true; /* re-find a volume after unload */
}
do_unload();
do_swapping(true /*is_writing*/);
do_load(true /*is_writing*/);
if (do_find && !find_a_volume()) {
goto no_lock_bail_out;
}
if (job_canceled(jcr)) {
goto bail_out;
}
Dmsg3(150, "After find_next_append. Vol=%s Slot=%d Parts=%d\n",
VolCatInfo.VolCatName, VolCatInfo.Slot, VolCatInfo.VolCatParts);
/*
* Get next volume and ready it for append
* This code ensures that the device is ready for
* writing. We start from the assumption that there
* may not be a tape mounted.
*
* If the device is a file, we create the output
* file. If it is a tape, we check the volume name
* and move the tape to the end of data.
*
*/
if (autoload_device(dcr, true/*writing*/, NULL) > 0) {
autochanger = true;
ask = false;
} else {
autochanger = false;
VolCatInfo.Slot = 0;
ask = retry >= 2;
}
Dmsg1(150, "autoload_dev returns %d\n", autochanger);
/*
* If we autochanged to correct Volume or (we have not just
* released the Volume AND we can automount) we go ahead
* and read the label. If there is no tape in the drive,
* we will fail, recurse and ask the operator the next time.
*/
//.........这里部分代码省略.........
示例11: record_cb
//.........这里部分代码省略.........
}
break;
case STREAM_RESTORE_OBJECT:
/* nothing to do */
break;
/* Data stream and extracting */
case STREAM_FILE_DATA:
case STREAM_SPARSE_DATA:
case STREAM_WIN32_DATA:
if (extract) {
if (rec->maskedStream == STREAM_SPARSE_DATA) {
ser_declare;
uint64_t faddr;
wbuf = rec->data + OFFSET_FADDR_SIZE;
wsize = rec->data_len - OFFSET_FADDR_SIZE;
ser_begin(rec->data, OFFSET_FADDR_SIZE);
unser_uint64(faddr);
if (fileAddr != faddr) {
fileAddr = faddr;
if (blseek(&bfd, (boffset_t)fileAddr, SEEK_SET) < 0) {
berrno be;
Emsg2(M_ERROR_TERM, 0, _("Seek error on %s: %s\n"),
attr->ofname, be.bstrerror());
}
}
} else {
wbuf = rec->data;
wsize = rec->data_len;
}
total += wsize;
Dmsg2(8, "Write %u bytes, total=%u\n", wsize, total);
store_data(&bfd, wbuf, wsize);
fileAddr += wsize;
}
break;
/* GZIP data stream */
case STREAM_GZIP_DATA:
case STREAM_SPARSE_GZIP_DATA:
case STREAM_WIN32_GZIP_DATA:
#ifdef HAVE_LIBZ
if (extract) {
uLong compress_len = compress_buf_size;
int status = Z_BUF_ERROR;
if (rec->maskedStream == STREAM_SPARSE_GZIP_DATA) {
ser_declare;
uint64_t faddr;
char ec1[50];
wbuf = rec->data + OFFSET_FADDR_SIZE;
wsize = rec->data_len - OFFSET_FADDR_SIZE;
ser_begin(rec->data, OFFSET_FADDR_SIZE);
unser_uint64(faddr);
if (fileAddr != faddr) {
fileAddr = faddr;
if (blseek(&bfd, (boffset_t)fileAddr, SEEK_SET) < 0) {
berrno be;
Emsg3(M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
edit_uint64(fileAddr, ec1), attr->ofname, be.bstrerror());
extract = false;
return true;
}
}
示例12: create_volume_label
int DCR::check_volume_label(bool &ask, bool &autochanger)
{
int vol_label_status;
/*
* If we are writing to a stream device, ASSUME the volume label
* is correct.
*/
if (dev->has_cap(CAP_STREAM)) {
vol_label_status = VOL_OK;
create_volume_label(dev, VolumeName, "Default", false /* not DVD */);
dev->VolHdr.LabelType = PRE_LABEL;
} else {
vol_label_status = read_dev_volume_label(this);
}
if (job_canceled(jcr)) {
goto check_bail_out;
}
Dmsg2(150, "Want dirVol=%s dirStat=%s\n", VolumeName,
VolCatInfo.VolCatStatus);
/*
* At this point, dev->VolCatInfo has what is in the drive, if anything,
* and dcr->VolCatInfo has what the Director wants.
*/
switch (vol_label_status) {
case VOL_OK:
Dmsg1(150, "Vol OK name=%s\n", dev->VolHdr.VolumeName);
dev->VolCatInfo = VolCatInfo; /* structure assignment */
break; /* got a Volume */
case VOL_NAME_ERROR:
VOLUME_CAT_INFO dcrVolCatInfo, devVolCatInfo;
char saveVolumeName[MAX_NAME_LENGTH];
Dmsg2(150, "Vol NAME Error Have=%s, want=%s\n", dev->VolHdr.VolumeName, VolumeName);
if (dev->is_volume_to_unload()) {
ask = true;
goto check_next_volume;
}
/* If not removable, Volume is broken */
if (!dev->is_removable()) {
Jmsg(jcr, M_WARNING, 0, _("Volume \"%s\" not on device %s.\n"),
VolumeName, dev->print_name());
mark_volume_in_error();
goto check_next_volume;
}
/*
* OK, we got a different volume mounted. First save the
* requested Volume info (dcr) structure, then query if
* this volume is really OK. If not, put back the desired
* volume name, mark it not in changer and continue.
*/
dcrVolCatInfo = VolCatInfo; /* structure assignment */
devVolCatInfo = dev->VolCatInfo; /* structure assignment */
/* Check if this is a valid Volume in the pool */
bstrncpy(saveVolumeName, VolumeName, sizeof(saveVolumeName));
bstrncpy(VolumeName, dev->VolHdr.VolumeName, sizeof(VolumeName));
if (!dir_get_volume_info(this, GET_VOL_INFO_FOR_WRITE)) {
POOL_MEM vol_info_msg;
pm_strcpy(vol_info_msg, jcr->dir_bsock->msg); /* save error message */
/* Restore desired volume name, note device info out of sync */
/* This gets the info regardless of the Pool */
bstrncpy(VolumeName, dev->VolHdr.VolumeName, sizeof(VolumeName));
if (autochanger && !dir_get_volume_info(this, GET_VOL_INFO_FOR_READ)) {
/*
* If we get here, we know we cannot write on the Volume,
* and we know that we cannot read it either, so it
* is not in the autochanger.
*/
mark_volume_not_inchanger();
}
dev->VolCatInfo = devVolCatInfo; /* structure assignment */
dev->set_unload(); /* unload this volume */
Jmsg(jcr, M_WARNING, 0, _("Director wanted Volume \"%s\".\n"
" Current Volume \"%s\" not acceptable because:\n"
" %s"),
dcrVolCatInfo.VolCatName, dev->VolHdr.VolumeName,
vol_info_msg.c_str());
ask = true;
/* Restore saved DCR before continuing */
bstrncpy(VolumeName, saveVolumeName, sizeof(VolumeName));
VolCatInfo = dcrVolCatInfo; /* structure assignment */
goto check_next_volume;
}
/*
* This was not the volume we expected, but it is OK with
* the Director, so use it.
*/
Dmsg1(150, "Got new Volume name=%s\n", VolumeName);
dev->VolCatInfo = VolCatInfo; /* structure assignment */
Dmsg1(100, "Call reserve_volume=%s\n", dev->VolHdr.VolumeName);
if (reserve_volume(this, dev->VolHdr.VolumeName) == NULL) {
Jmsg2(jcr, M_WARNING, 0, _("Could not reserve volume %s on %s\n"),
dev->VolHdr.VolumeName, dev->print_name());
ask = true;
goto check_next_volume;
}
break; /* got a Volume */
/*
//.........这里部分代码省略.........
示例13: save_resource
/*
* Save the new resource by chaining it into the head list for
* the resource. If this is pass 2, we update any resource
* pointers (currently only in the Job resource).
*/
bool save_resource(int type, RES_ITEM *items, int pass)
{
URES *res;
int rindex = type - R_FIRST;
int i;
int error = 0;
/*
* Ensure that all required items are present
*/
for (i = 0; items[i].name; i++) {
if (items[i].flags & CFG_ITEM_REQUIRED) {
if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
Emsg2(M_ABORT, 0, _("%s item is required in %s resource, but not found.\n"),
items[i].name, resources[rindex]);
}
}
}
/*
* During pass 2, we looked up pointers to all the resources
* referrenced in the current resource, , now we
* must copy their address from the static record to the allocated
* record.
*/
if (pass == 2) {
switch (type) {
case R_CONSOLE:
if ((res = (URES *)GetResWithName(R_CONSOLE, res_all.res_cons.name())) == NULL) {
Emsg1(M_ABORT, 0, _("Cannot find Console resource %s\n"), res_all.res_cons.name());
} else {
res->res_cons.tls.allowed_cns = res_all.res_cons.tls.allowed_cns;
}
break;
case R_DIRECTOR:
if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.name())) == NULL) {
Emsg1(M_ABORT, 0, _("Cannot find Director resource %s\n"), res_all.res_dir.name());
} else {
res->res_dir.tls.allowed_cns = res_all.res_dir.tls.allowed_cns;
}
break;
default:
Emsg1(M_ERROR, 0, _("Unknown resource type %d\n"), type);
error = 1;
break;
}
/*
* Note, the resoure name was already saved during pass 1,
* so here, we can just release it.
*/
if (res_all.res_dir.hdr.name) {
free(res_all.res_dir.hdr.name);
res_all.res_dir.hdr.name = NULL;
}
if (res_all.res_dir.hdr.desc) {
free(res_all.res_dir.hdr.desc);
res_all.res_dir.hdr.desc = NULL;
}
return (error == 0);
}
/*
* Common
*/
if (!error) {
res = (URES *)malloc(resources[rindex].size);
memcpy(res, &res_all, resources[rindex].size);
if (!res_head[rindex]) {
res_head[rindex] = (RES *)res; /* store first entry */
} else {
RES *next, *last;
for (last=next=res_head[rindex]; next; next=next->next) {
last = next;
if (bstrcmp(next->name, res->res_dir.name())) {
Emsg2(M_ERROR_TERM, 0,
_("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
resources[rindex].name, res->res_dir.name());
}
}
last->next = (RES *)res;
Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type), res->res_dir.name());
}
}
return (error == 0);
}
示例14: write_nbytes
int32_t write_nbytes(BSOCK * bsock, char *ptr, int32_t nbytes)
{
int32_t nleft, nwritten;
if (bsock->is_spooling()) {
nwritten = fwrite(ptr, 1, nbytes, bsock->m_spool_fd);
if (nwritten != nbytes) {
berrno be;
bsock->b_errno = errno;
Qmsg3(bsock->jcr(), M_FATAL, 0, _("Attr spool write error. wrote=%d wanted=%d bytes. ERR=%s\n"),
nbytes, nwritten, be.bstrerror());
Dmsg2(400, "nwritten=%d nbytes=%d.\n", nwritten, nbytes);
errno = bsock->b_errno;
return -1;
}
return nbytes;
}
#ifdef HAVE_TLS
if (bsock->tls) {
/* TLS enabled */
return (tls_bsock_writen(bsock, ptr, nbytes));
}
#endif /* HAVE_TLS */
nleft = nbytes;
while (nleft > 0) {
do {
errno = 0;
nwritten = socketWrite(bsock->m_fd, ptr, nleft);
if (bsock->is_timed_out() || bsock->is_terminated()) {
return -1;
}
#ifdef HAVE_WIN32
/*
* For Windows, we must simulate Unix errno on a socket
* error in order to handle errors correctly.
*/
if (nwritten == SOCKET_ERROR) {
DWORD err = WSAGetLastError();
nwritten = -1;
if (err == WSAEINTR) {
errno = EINTR;
} else if (err == WSAEWOULDBLOCK) {
errno = EAGAIN;
} else {
errno = EIO; /* some other error */
}
}
#endif
} while (nwritten == -1 && errno == EINTR);
/*
* If connection is non-blocking, we will get EAGAIN, so
* use select() to keep from consuming all the CPU
* and try again.
*/
if (nwritten == -1 && errno == EAGAIN) {
fd_set fdset;
struct timeval tv;
FD_ZERO(&fdset);
FD_SET((unsigned)bsock->m_fd, &fdset);
tv.tv_sec = 1;
tv.tv_usec = 0;
select(bsock->m_fd + 1, NULL, &fdset, NULL, &tv);
continue;
}
if (nwritten <= 0) {
return -1; /* error */
}
nleft -= nwritten;
ptr += nwritten;
if (bsock->use_bwlimit()) {
bsock->control_bwlimit(nwritten);
}
}
return nbytes - nleft;
}
示例15: read_ansi_ibm_label
//.........这里部分代码省略.........
}
}
switch (i) {
case 0: /* Want VOL1 label */
if (stat == 80) {
if (strncmp("VOL1", label, 4) == 0) {
ok = true;
dev->label_type = B_ANSI_LABEL;
Dmsg0(100, "Got ANSI VOL1 label\n");
} else {
/* Try EBCDIC */
ebcdic_to_ascii(label, label, sizeof(label));
if (strncmp("VOL1", label, 4) == 0) {
ok = true;;
dev->label_type = B_IBM_LABEL;
Dmsg0(100, "Found IBM label.\n");
Dmsg0(100, "Got IBM VOL1 label\n");
}
}
}
if (!ok) {
Dmsg0(100, "No VOL1 label\n");
Mmsg0(jcr->errmsg, _("No VOL1 label while reading ANSI/IBM label.\n"));
return VOL_NO_LABEL; /* No ANSI label */
}
/* Compare Volume Names allow special wild card */
if (VolName && *VolName && *VolName != '*') {
if (!same_label_names(VolName, &label[4])) {
char *p = &label[4];
char *q;
free_volume(dev);
/* Store new Volume name */
q = dev->VolHdr.VolumeName;
for (int i=0; *p != ' ' && i < 6; i++) {
*q++ = *p++;
}
*q = 0;
Dmsg0(100, "Call reserve_volume\n");
/* ***FIXME*** why is this reserve_volume() needed???? KES */
reserve_volume(dcr, dev->VolHdr.VolumeName);
dev = dcr->dev; /* may have changed in reserve_volume */
Dmsg2(100, "Wanted ANSI Vol %s got %6s\n", VolName, dev->VolHdr.VolumeName);
Mmsg2(jcr->errmsg, _("Wanted ANSI Volume \"%s\" got \"%s\"\n"), VolName, dev->VolHdr.VolumeName);
return VOL_NAME_ERROR;
}
}
break;
case 1:
if (dev->label_type == B_IBM_LABEL) {
ebcdic_to_ascii(label, label, sizeof(label));
}
if (stat != 80 || strncmp("HDR1", label, 4) != 0) {
Dmsg0(100, "No HDR1 label\n");
Mmsg0(jcr->errmsg, _("No HDR1 label while reading ANSI label.\n"));
return VOL_LABEL_ERROR;
}
if (strncmp("BACULA.DATA", &label[4], 11) != 0) {
Dmsg1(100, "HD1 not Bacula label. Wanted BACULA.DATA got %11s\n",
&label[4]);
Mmsg1(jcr->errmsg, _("ANSI/IBM Volume \"%s\" does not belong to Bacula.\n"),
dev->VolHdr.VolumeName);
return VOL_NAME_ERROR; /* Not a Bacula label */
}
Dmsg0(100, "Got HDR1 label\n");
break;
case 2:
if (dev->label_type == B_IBM_LABEL) {
ebcdic_to_ascii(label, label, sizeof(label));
}
if (stat != 80 || strncmp("HDR2", label, 4) != 0) {
Dmsg0(100, "No HDR2 label\n");
Mmsg0(jcr->errmsg, _("No HDR2 label while reading ANSI/IBM label.\n"));
return VOL_LABEL_ERROR;
}
Dmsg0(100, "Got ANSI HDR2 label\n");
break;
default:
if (stat == 0) {
Dmsg0(100, "ANSI label OK\n");
return VOL_OK;
}
if (dev->label_type == B_IBM_LABEL) {
ebcdic_to_ascii(label, label, sizeof(label));
}
if (stat != 80 || strncmp("HDR", label, 3) != 0) {
Dmsg0(100, "Unknown or bad ANSI/IBM label record.\n");
Mmsg0(jcr->errmsg, _("Unknown or bad ANSI/IBM label record.\n"));
return VOL_LABEL_ERROR;
}
Dmsg0(100, "Got HDR label\n");
break;
}
}
Dmsg0(100, "Too many records in ANSI/IBM label.\n");
Mmsg0(jcr->errmsg, _("Too many records in while reading ANSI/IBM label.\n"));
return VOL_LABEL_ERROR;
}