From: Michal Rakowski Date: Mon, 24 Jan 2022 21:57:02 +0000 (+0100) Subject: Fix #8571 About adding intermediate JobStatus for Runscripts X-Git-Tag: Beta-15.0.0~666 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=865c7916b9e248c2b405a933148c4228f04b20e6;p=thirdparty%2Fbacula.git Fix #8571 About adding intermediate JobStatus for Runscripts --- diff --git a/bacula/src/dird/ua_status.c b/bacula/src/dird/ua_status.c index 08c23807d..fc6017d70 100644 --- a/bacula/src/dird/ua_status.c +++ b/bacula/src/dird/ua_status.c @@ -1221,6 +1221,7 @@ static void list_running_jobs(UAContext *ua) bool pool_mem = false; OutputWriter ow(ua->api_opts); JobId_t jid = 0; + POOL_MEM msg_buf; if ((i = find_arg_with_value(ua, "jobid")) >= 0) { jid = str_to_int64(ua->argv[i]); @@ -1443,10 +1444,18 @@ static void list_running_jobs(UAContext *ua) break; } + uint32_t curr_op = jcr->job_task; + if (curr_op != 0) { + /* We can add some more descriptive message */ + Mmsg(msg_buf, "%s (%s)", msg, get_job_task(curr_op)); + } else { + pm_strcpy(msg_buf, msg); + } + if (ua->api == 1) { bash_spaces(jcr->comment); ua->send_msg(_("%6d\t%-6s\t%-20s\t%s\t%s\n"), - jcr->JobId, level, jcr->Job, msg, jcr->comment); + jcr->JobId, level, jcr->Job, msg_buf.c_str(), jcr->comment); unbash_spaces(jcr->comment); } else if (ua->api > 1) { @@ -1460,7 +1469,7 @@ static void list_running_jobs(UAContext *ua) OT_JOBLEVEL,"level", jcr->getJobLevel(), OT_JOBTYPE, "type", jcr->getJobType(), OT_JOBSTATUS,"status", status, - OT_STRING, "status_desc",msg, + OT_STRING, "status_desc",msg_buf.c_str(), OT_STRING, "comment", jcr->comment, OT_SIZE, "jobbytes", jcr->JobBytes, OT_INT32, "jobfiles", jcr->JobFiles, @@ -1486,7 +1495,7 @@ static void list_running_jobs(UAContext *ua) jcr->JobId, b1, level, edit_uint64_with_commas(jcr->JobFiles, b2), edit_uint64_with_suffix(jcr->JobBytes, b3), - jcr->job->name(), msg); + jcr->job->name(), msg_buf.c_str()); } if (pool_mem) { diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 50ab23a3f..07bc3d87e 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -92,6 +92,22 @@ #define JS_CloudUpload 'u' /* Cloud upload */ #define JS_CloudDownload 'w' /* Cloud download */ +/* Helper for more descriptive job status */ +enum { + JOB_TASK_ZERO = 0, + JOB_TASK_BEFORE_SCRIPT = 100, + JOB_TASK_AFTER_SCRIPT +}; + +struct job_task { + const uint32_t op_code; + const char *op_message; +}; + + +const char *get_job_task(uint32_t op_code); + + /* Migration selection types. Do not change the order. */ enum { MT_SMALLEST_VOL = 1, @@ -258,7 +274,10 @@ public: char Job[MAX_NAME_LENGTH]; /* Unique name of this Job */ char event[MAX_NAME_LENGTH]; /* Current event (python) */ uint32_t eventType; /* Current event type (plugin) */ - + uint32_t job_task; /* Used to add description of current opearion being executed + (e.g. 'running AfterJob script'). + If not 0, it can be used to make current job + status more descriptive. */ uint32_t JobId; /* Director's JobId */ uint32_t VolSessionId; uint32_t VolSessionTime; diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index 16be87520..b58957088 100644 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -80,6 +80,15 @@ pthread_once_t key_once = PTHREAD_ONCE_INIT; static char Job_status[] = "Status JobId=%ld JobStatus=%d\n"; +/* Mapping of operation code to operation description */ +const struct job_task job_task_map[] = { + { JOB_TASK_ZERO, "\0" }, + { JOB_TASK_BEFORE_SCRIPT, "executing Before Job Scripts" }, + { JOB_TASK_AFTER_SCRIPT, "executing After Job Scripts" } +}; + +const uint32_t job_task_map_size = sizeof(job_task_map) / sizeof(job_task); + void lock_jobs() { P(job_start_mutex); @@ -395,6 +404,7 @@ JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr) jcr->setJobType(JT_SYSTEM); /* internal job until defined */ jcr->setJobLevel(L_NONE); jcr->setJobStatus(JS_Created); /* ready to run */ + jcr->job_task = JOB_TASK_ZERO; #ifndef HAVE_WIN32 struct sigaction sigtimer; sigtimer.sa_flags = 0; @@ -1210,6 +1220,18 @@ int get_next_jobid_from_list(char **p, uint32_t *JobId) return 1; } +/* Get description of operation by given job task code */ +const char *get_job_task(uint32_t op_code) +{ + for (uint32_t i=0; icommand, script->on_success, script->on_failure, jcr->JobStatus ); + /* Set job task code */ + jcr->job_task = JOB_TASK_BEFORE_SCRIPT; runit = true; } } @@ -142,6 +144,8 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label) Dmsg4(200, "runscript: Run it because SCRIPT_AfterVSS (%s,%i,%i,%c)\n", script->command, script->on_success, script->on_failure, jcr->JobStatus ); + /* Set job task code */ + jcr->job_task = JOB_TASK_AFTER_SCRIPT; runit = true; } } @@ -156,6 +160,8 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label) Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n", script->command, script->on_success, script->on_failure, jcr->JobStatus ); + /* Set job task code */ + jcr->job_task = JOB_TASK_AFTER_SCRIPT; runit = true; } } @@ -172,6 +178,9 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label) } } + /* Script ended, reset operation code */ + jcr->job_task = JOB_TASK_ZERO; + return ret; } diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index b548da82b..533c52e5d 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -1004,7 +1004,6 @@ static void label_volume_if_ok(DCR *dcr, char *oldname, int mode; const char *volname = (relabel == 1) ? oldname : newname; uint64_t volCatBytes; - bool opened = false; if (!obtain_device_block(dev, &hold,