本文整理汇总了C++中JCR类的典型用法代码示例。如果您正苦于以下问题:C++ JCR类的具体用法?C++ JCR怎么用?C++ JCR使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JCR类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_killable
void JCR::set_killable(bool killable)
{
JCR *jcr = this;
jcr->lock();
jcr->my_thread_killable = killable;
jcr->unlock();
}
示例2: Py_FindMethod
/* Return Job variables */
PyObject *job_getattr(PyObject *self, char *attrname)
{
JCR *jcr;
bool found = false;
int i;
char buf[10];
char errmsg[200];
Dmsg1(100, "In job_getattr=%s\n", attrname);
jcr = get_jcr_from_PyObject(self);
if (!jcr) {
bstrncpy(errmsg, _("Job pointer not found."), sizeof(errmsg));
goto bail_out;
}
for (i=0; getvars[i].name; i++) {
if (strcmp(getvars[i].name, attrname) == 0) {
found = true;
break;
}
}
if (!found) {
/* Try our methods */
return Py_FindMethod(JobMethods, self, attrname);
}
switch (i) {
case 0: /* Job */
return Py_BuildValue((char *)getvars[i].fmt, jcr->job_name); /* Non-unique name */
case 1: /* SD's name */
return Py_BuildValue((char *)getvars[i].fmt, my_name);
case 2: /* level */
return Py_BuildValue((char *)getvars[i].fmt, job_level_to_str(jcr->get_JobLevel()));
case 3: /* type */
return Py_BuildValue((char *)getvars[i].fmt, job_type_to_str(jcr->get_JobType()));
case 4: /* JobId */
return Py_BuildValue((char *)getvars[i].fmt, jcr->JobId);
case 5: /* Client */
return Py_BuildValue((char *)getvars[i].fmt, jcr->client_name);
case 6: /* Pool */
return Py_BuildValue((char *)getvars[i].fmt, jcr->dcr->pool_name);
case 7: /* MediaType */
return Py_BuildValue((char *)getvars[i].fmt, jcr->dcr->media_type);
case 8: /* JobName */
return Py_BuildValue((char *)getvars[i].fmt, jcr->Job);
case 9: /* JobStatus */
buf[1] = 0;
buf[0] = jcr->JobStatus;
return Py_BuildValue((char *)getvars[i].fmt, buf);
case 10:
return Py_BuildValue((char *)getvars[i].fmt, jcr->dcr->VolumeName);
case 11:
return Py_BuildValue((char *)getvars[i].fmt, jcr->dcr->dev_name);
}
bsnprintf(errmsg, sizeof(errmsg), _("Attribute %s not found."), attrname);
bail_out:
PyErr_SetString(PyExc_AttributeError, errmsg);
return NULL;
}
示例3: jcr_timeout_check
static void jcr_timeout_check(watchdog_t *self)
{
JCR *jcr;
BSOCK *bs;
time_t timer_start;
Dmsg0(dbglvl, "Start JCR timeout checks\n");
/* Walk through all JCRs checking if any one is
* blocked for more than specified max time.
*/
foreach_jcr(jcr) {
Dmsg2(dbglvl, "jcr_timeout_check JobId=%u jcr=0x%x\n", jcr->JobId, jcr);
if (jcr->JobId == 0) {
continue;
}
bs = jcr->store_bsock;
if (bs) {
timer_start = bs->timer_start;
if (timer_start && (watchdog_time - timer_start) > bs->timeout) {
bs->timer_start = 0; /* turn off timer */
bs->set_timed_out();
Qmsg(jcr, M_ERROR, 0, _(
"Watchdog sending kill after %d secs to thread stalled reading Storage daemon.\n"),
watchdog_time - timer_start);
jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
}
}
bs = jcr->file_bsock;
if (bs) {
timer_start = bs->timer_start;
if (timer_start && (watchdog_time - timer_start) > bs->timeout) {
bs->timer_start = 0; /* turn off timer */
bs->set_timed_out();
Qmsg(jcr, M_ERROR, 0, _(
"Watchdog sending kill after %d secs to thread stalled reading File daemon.\n"),
watchdog_time - timer_start);
jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
}
}
bs = jcr->dir_bsock;
if (bs) {
timer_start = bs->timer_start;
if (timer_start && (watchdog_time - timer_start) > bs->timeout) {
bs->timer_start = 0; /* turn off timer */
bs->set_timed_out();
Qmsg(jcr, M_ERROR, 0, _(
"Watchdog sending kill after %d secs to thread stalled reading Director.\n"),
watchdog_time - timer_start);
jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
}
}
}
endeach_jcr(jcr);
Dmsg0(dbglvl, "Finished JCR timeout checks\n");
}
示例4: Dmsg0
/*
* Create a Job Control Record and link it into JCR chain
* Returns newly allocated JCR
* Note, since each daemon has a different JCR, he passes
* us the size.
*/
JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
{
JCR *jcr;
MQUEUE_ITEM *item = NULL;
struct sigaction sigtimer;
int status;
Dmsg0(dbglvl, "Enter new_jcr\n");
status = pthread_once(&key_once, create_jcr_key);
if (status != 0) {
berrno be;
Jmsg1(NULL, M_ABORT, 0, _("pthread_once failed. ERR=%s\n"), be.bstrerror(status));
}
jcr = (JCR *)malloc(size);
memset(jcr, 0, size);
jcr->my_thread_id = pthread_self();
jcr->msg_queue = New(dlist(item, &item->link));
jcr->job_end_push.init(1, false);
jcr->sched_time = time(NULL);
jcr->daemon_free_jcr = daemon_free_jcr; /* plug daemon free routine */
jcr->init_mutex();
jcr->inc_use_count();
jcr->VolumeName = get_pool_memory(PM_FNAME);
jcr->VolumeName[0] = 0;
jcr->errmsg = get_pool_memory(PM_MESSAGE);
jcr->errmsg[0] = 0;
/* Setup some dummy values */
bstrncpy(jcr->Job, "*System*", sizeof(jcr->Job));
jcr->JobId = 0;
jcr->set_JobType(JT_SYSTEM); /* internal job until defined */
jcr->set_JobLevel(L_NONE);
set_jcr_job_status(jcr, JS_Created); /* ready to run */
set_jcr_in_tsd(jcr);
sigtimer.sa_flags = 0;
sigtimer.sa_handler = timeout_handler;
sigfillset(&sigtimer.sa_mask);
sigaction(TIMEOUT_SIGNAL, &sigtimer, NULL);
/*
* Locking jobs is a global lock that is needed
* so that the Director can stop new jobs from being
* added to the jcr chain while it processes a new
* conf file and does the job_end_push().
*/
lock_jobs();
lock_jcr_chain();
if (!jcrs) {
jcrs = New(dlist(jcr, &jcr->link));
}
jcrs->append(jcr);
unlock_jcr_chain();
unlock_jobs();
return jcr;
}
示例5: sendJobStatus
/*
* Set and send Job status to Director
*/
bool JCR::sendJobStatus(int newJobStatus)
{
JCR *jcr = this;
if (!jcr->is_JobStatus(newJobStatus)) {
setJobStatus(newJobStatus);
if (jcr->dir_bsock) {
return jcr->dir_bsock->fsend(Job_status, jcr->Job, jcr->JobStatus);
}
}
return true;
}
示例6: create_session_label
/*
* Create session label
* The pool memory must be released by the calling program
*/
void create_session_label(DCR *dcr, DEV_RECORD *rec, int label)
{
JCR *jcr = dcr->jcr;
ser_declare;
rec->VolSessionId = jcr->VolSessionId;
rec->VolSessionTime = jcr->VolSessionTime;
rec->Stream = jcr->JobId;
rec->maskedStream = jcr->JobId;
rec->data = check_pool_memory_size(rec->data, SER_LENGTH_Session_Label);
ser_begin(rec->data, SER_LENGTH_Session_Label);
if (me->compatible) {
ser_string(OldBaculaId);
ser_uint32(OldCompatibleBareosTapeVersion1);
} else {
ser_string(BareosId);
ser_uint32(BareosTapeVersion);
}
ser_uint32(jcr->JobId);
/* Changed in VerNum 11 */
ser_btime(get_current_btime());
ser_float64(0);
ser_string(dcr->pool_name);
ser_string(dcr->pool_type);
ser_string(jcr->job_name); /* base Job name */
ser_string(jcr->client_name);
/* Added in VerNum 10 */
ser_string(jcr->Job); /* Unique name of this Job */
ser_string(jcr->fileset_name);
ser_uint32(jcr->getJobType());
ser_uint32(jcr->getJobLevel());
/* Added in VerNum 11 */
ser_string(jcr->fileset_md5);
if (label == EOS_LABEL) {
ser_uint32(jcr->JobFiles);
ser_uint64(jcr->JobBytes);
ser_uint32(dcr->StartBlock);
ser_uint32(dcr->EndBlock);
ser_uint32(dcr->StartFile);
ser_uint32(dcr->EndFile);
ser_uint32(jcr->JobErrors);
/* Added in VerNum 11 */
ser_uint32(jcr->JobStatus);
}
ser_end(rec->data, SER_LENGTH_Session_Label);
rec->data_len = ser_length(rec->data);
}
示例7: set_killable
void JCR::set_killable(bool killable)
{
JCR *jcr = this;
jcr->lock();
jcr->my_thread_killable = killable;
if (killable) {
jcr->my_thread_id = pthread_self();
} else {
memset(&jcr->my_thread_id, 0, sizeof(jcr->my_thread_id));
}
jcr->unlock();
}
示例8: Jmsg
/*
* After receiving a connection (in dircmd.c) if it is
* from the Storage daemon, this routine is called.
*/
void *handle_stored_connection(BSOCK *sd, char *job_name)
{
JCR *jcr;
/*
* With the following bmicrosleep on, running the
* SD under the debugger fails.
*/
// bmicrosleep(0, 50000); /* wait 50 millisecs */
if (!(jcr = get_jcr_by_full_name(job_name))) {
Jmsg1(NULL, M_FATAL, 0, _("SD connect failed: Job name not found: %s\n"), job_name);
Dmsg1(3, "**** Job \"%s\" not found.\n", job_name);
sd->close();
delete sd;
return NULL;
}
Dmsg1(50, "Found Job %s\n", job_name);
if (jcr->authenticated) {
Jmsg2(jcr, M_FATAL, 0, _("Hey!!!! JobId %u Job %s already authenticated.\n"),
(uint32_t)jcr->JobId, jcr->Job);
Dmsg2(50, "Hey!!!! JobId %u Job %s already authenticated.\n",
(uint32_t)jcr->JobId, jcr->Job);
sd->close();
delete sd;
free_jcr(jcr);
return NULL;
}
jcr->store_bsock = sd;
jcr->store_bsock->set_jcr(jcr);
/*
* Authenticate the Storage daemon
*/
if (jcr->authenticated || !authenticate_storagedaemon(jcr)) {
Dmsg1(50, "Authentication failed Job %s\n", jcr->Job);
Jmsg(jcr, M_FATAL, 0, _("Unable to authenticate Storage daemon\n"));
} else {
jcr->authenticated = true;
Dmsg2(50, "OK Authentication jid=%u Job %s\n", (uint32_t)jcr->JobId, jcr->Job);
}
if (!jcr->authenticated) {
jcr->setJobStatus(JS_ErrorTerminated);
}
pthread_cond_signal(&jcr->job_start_wait); /* wake waiting job */
free_jcr(jcr);
return NULL;
}
示例9: handle_filed_connection
/*
* After receiving a connection (in dircmd.c) if it is
* from the File daemon, this routine is called.
*/
void handle_filed_connection(BSOCK *fd, char *job_name, int fd_version,
int sd_version)
{
JCR *jcr;
if (!(jcr=get_jcr_by_full_name(job_name))) {
Jmsg1(NULL, M_FATAL, 0, _("FD connect failed: Job name not found: %s\n"), job_name);
Dmsg1(3, "**** Job \"%s\" not found.\n", job_name);
fd->destroy();
return;
}
Dmsg1(100, "Found Filed Job %s\n", job_name);
if (jcr->authenticated) {
Jmsg2(jcr, M_FATAL, 0, _("Hey!!!! JobId %u Job %s already authenticated.\n"),
(uint32_t)jcr->JobId, jcr->Job);
Dmsg2(050, "Hey!!!! JobId %u Job %s already authenticated.\n",
(uint32_t)jcr->JobId, jcr->Job);
fd->destroy();
free_jcr(jcr);
return;
}
jcr->file_bsock = fd;
jcr->file_bsock->set_jcr(jcr);
jcr->FDVersion = fd_version;
jcr->SDVersion = sd_version;
Dmsg2(050, "fd_version=%d sd_version=%d\n", fd_version, sd_version);
/*
* Authenticate the File daemon
*/
if (jcr->authenticated || !authenticate_filed(jcr)) {
Dmsg1(50, "Authentication failed Job %s\n", jcr->Job);
Jmsg(jcr, M_FATAL, 0, _("Unable to authenticate File daemon\n"));
} else {
jcr->authenticated = true;
Dmsg2(050, "OK Authentication jid=%u Job %s\n", (uint32_t)jcr->JobId, jcr->Job);
}
if (!jcr->authenticated) {
jcr->setJobStatus(JS_ErrorTerminated);
}
Dmsg3(050, "=== Auth OK, unblock Job %s jid=%d sd_ver=%d\n", job_name, jcr->JobId, sd_version);
if (sd_version > 0) {
jcr->sd_client = true;
}
pthread_cond_signal(&jcr->job_start_wait); /* wake waiting job */
free_jcr(jcr);
return;
}
示例10: write_spool_header
static bool write_spool_header(DCR *dcr)
{
spool_hdr hdr;
ssize_t status;
DEV_BLOCK *block = dcr->block;
JCR *jcr = dcr->jcr;
hdr.FirstIndex = block->FirstIndex;
hdr.LastIndex = block->LastIndex;
hdr.len = block->binbuf;
/* Write header */
for (int retry = 0; retry <= 1; retry++) {
status = write(dcr->spool_fd, (char*)&hdr, sizeof(hdr));
if (status == -1) {
berrno be;
Jmsg(jcr, M_FATAL, 0, _("Error writing header to spool file. ERR=%s\n"), be.bstrerror());
jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
}
if (status != (ssize_t)sizeof(hdr)) {
Jmsg(jcr, M_ERROR, 0, _("Error writing header to spool file."
" Disk probably full. Attempting recovery. Wanted to write=%d got=%d\n"),
(int)status, (int)sizeof(hdr));
/* If we wrote something, truncate it, then despool */
if (status != -1) {
#if defined(HAVE_WIN32)
boffset_t pos = _lseeki64(dcr->spool_fd, (__int64)0, SEEK_CUR);
#else
boffset_t pos = lseek(dcr->spool_fd, 0, SEEK_CUR);
#endif
if (ftruncate(dcr->spool_fd, pos - status) != 0) {
berrno be;
Jmsg(dcr->jcr, M_ERROR, 0, _("Ftruncate spool file failed: ERR=%s\n"), be.bstrerror());
/* Note, try continuing despite ftruncate problem */
}
}
if (!despool_data(dcr, false)) {
Jmsg(jcr, M_FATAL, 0, _("Fatal despooling error."));
jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
return false;
}
continue; /* try again */
}
return true;
}
Jmsg(jcr, M_FATAL, 0, _("Retrying after header spooling error failed.\n"));
jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
return false;
}
示例11: dir_create_jobmedia_record
/**
* After writing a Volume, create the JobMedia record.
*/
bool dir_create_jobmedia_record(DCR *dcr, bool zero)
{
JCR *jcr = dcr->jcr;
BSOCK *dir = jcr->dir_bsock;
char ed1[50];
/* If system job, do not update catalog */
if (jcr->is_JobType(JT_SYSTEM)) {
return true;
}
/* Throw out records where FI is zero -- i.e. nothing done */
if (!zero && dcr->VolFirstIndex == 0 &&
(dcr->StartBlock != 0 || dcr->EndBlock != 0)) {
Dmsg0(dbglvl, "JobMedia FI=0 StartBlock!=0 record suppressed\n");
return true;
}
if (!dcr->WroteVol) {
return true; /* nothing written to tape */
}
dcr->WroteVol = false;
if (zero) {
/* Send dummy place holder to avoid purging */
dir->fsend(Create_job_media, jcr->Job,
0 , 0, 0, 0, 0, 0, 0, 0, edit_uint64(dcr->VolMediaId, ed1));
} else {
dir->fsend(Create_job_media, jcr->Job,
dcr->VolFirstIndex, dcr->VolLastIndex,
dcr->StartFile, dcr->EndFile,
dcr->StartBlock, dcr->EndBlock,
dcr->Copy, dcr->Stripe,
edit_uint64(dcr->VolMediaId, ed1));
}
Dmsg1(dbglvl, ">dird %s", dir->msg);
if (dir->recv() <= 0) {
Dmsg0(dbglvl, "create_jobmedia error bnet_recv\n");
Jmsg(jcr, M_FATAL, 0, _("Error creating JobMedia record: ERR=%s\n"),
dir->bstrerror());
return false;
}
Dmsg1(dbglvl, "<dird %s", dir->msg);
if (!bstrcmp(dir->msg, OK_create)) {
Dmsg1(dbglvl, "Bad response from Dir: %s\n", dir->msg);
Jmsg(jcr, M_FATAL, 0, _("Error creating JobMedia record: %s\n"), dir->msg);
return false;
}
return true;
}
示例12: read_block_from_spool_file
/*
* Read a block from the spool file
*
* Returns RB_OK on success
* RB_EOT when file done
* RB_ERROR on error
*/
static int read_block_from_spool_file(DCR *dcr)
{
uint32_t rlen;
ssize_t status;
spool_hdr hdr;
DEV_BLOCK *block = dcr->block;
JCR *jcr = dcr->jcr;
rlen = sizeof(hdr);
status = read(dcr->spool_fd, (char *)&hdr, (size_t)rlen);
if (status == 0) {
Dmsg0(100, "EOT on spool read.\n");
return RB_EOT;
} else if (status != (ssize_t)rlen) {
if (status == -1) {
berrno be;
Jmsg(dcr->jcr, M_FATAL, 0, _("Spool header read error. ERR=%s\n"), be.bstrerror());
} else {
Pmsg2(000, _("Spool read error. Wanted %u bytes, got %d\n"), rlen, status);
Jmsg2(jcr, M_FATAL, 0, _("Spool header read error. Wanted %u bytes, got %d\n"), rlen, status);
}
jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
return RB_ERROR;
}
rlen = hdr.len;
if (rlen > block->buf_len) {
Pmsg2(000, _("Spool block too big. Max %u bytes, got %u\n"), block->buf_len, rlen);
Jmsg2(jcr, M_FATAL, 0, _("Spool block too big. Max %u bytes, got %u\n"), block->buf_len, rlen);
jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
return RB_ERROR;
}
status = read(dcr->spool_fd, (char *)block->buf, (size_t)rlen);
if (status != (ssize_t)rlen) {
Pmsg2(000, _("Spool data read error. Wanted %u bytes, got %d\n"), rlen, status);
Jmsg2(dcr->jcr, M_FATAL, 0, _("Spool data read error. Wanted %u bytes, got %d\n"), rlen, status);
jcr->forceJobStatus(JS_FatalError); /* override any Incomplete */
return RB_ERROR;
}
/* Setup write pointers */
block->binbuf = rlen;
block->bufp = block->buf + block->binbuf;
block->FirstIndex = hdr.FirstIndex;
block->LastIndex = hdr.LastIndex;
block->VolSessionId = dcr->jcr->VolSessionId;
block->VolSessionTime = dcr->jcr->VolSessionTime;
Dmsg2(800, "Read block FI=%d LI=%d\n", block->FirstIndex, block->LastIndex);
return RB_OK;
}
示例13: missing_handler
/*
* We are called here for each record that matches the above
* SQL query -- that is for each file contained in the Catalog
* that was not marked earlier. This means that the file in
* question is a missing file (in the Catalog but not on Disk).
*/
static int missing_handler(void *ctx, int num_fields, char **row)
{
JCR *jcr = (JCR *)ctx;
if (job_canceled(jcr)) {
return 1;
}
if (!jcr->fn_printed) {
Qmsg(jcr, M_WARNING, 0, _("The following files are in the Catalog but not on %s:\n"),
jcr->getJobLevel() == L_VERIFY_VOLUME_TO_CATALOG ? "the Volume(s)" : "disk");
jcr->fn_printed = true;
}
Qmsg(jcr, M_INFO, 0, " %s%s\n", row[0]?row[0]:"", row[1]?row[1]:"");
return 0;
}
示例14:
/*
* Given a JobId, find the JCR
*
* Returns: jcr on success
* NULL on failure
*/
JCR *get_jcr_by_id(uint32_t JobId)
{
JCR *jcr;
foreach_jcr(jcr) {
if (jcr->JobId == JobId) {
jcr->inc_use_count();
Dmsg3(dbglvl, "Inc get_jcr jid=%u use_count=%d Job=%s\n",
jcr->JobId, jcr->use_count(), jcr->Job);
break;
}
}
endeach_jcr(jcr);
return jcr;
}
示例15: lock_jcr_chain
/*
* Start walk of jcr chain
* The proper way to walk the jcr chain is:
* JCR *jcr;
* foreach_jcr(jcr) {
* ...
* }
* endeach_jcr(jcr);
*
* It is possible to leave out the endeach_jcr(jcr), but
* in that case, the last jcr referenced must be explicitly
* released with:
*
* free_jcr(jcr);
*/
JCR *jcr_walk_start()
{
JCR *jcr;
lock_jcr_chain();
jcr = (JCR *)jcrs->first();
if (jcr) {
jcr->inc_use_count();
if (jcr->JobId > 0) {
Dmsg3(dbglvl, "Inc walk_start jid=%u use_count=%d Job=%s\n",
jcr->JobId, jcr->use_count(), jcr->Job);
}
}
unlock_jcr_chain();
return jcr;
}