From 8b64393257134c25582497188beb4bb6b85bcbb7 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 13 Nov 2008 16:27:30 +0000 Subject: [PATCH] ebl Add writable variable to director plugin interface git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8045 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/dir_plugins.c | 65 +++++++++++++++++++++++++++++++++-- bacula/src/dird/dir_plugins.h | 3 +- bacula/src/dird/newvol.c | 5 +-- bacula/src/jcr.h | 4 ++- bacula/technotes-2.5 | 2 +- 5 files changed, 72 insertions(+), 7 deletions(-) diff --git a/bacula/src/dird/dir_plugins.c b/bacula/src/dird/dir_plugins.c index 0985ed3e28..45ca43af71 100644 --- a/bacula/src/dird/dir_plugins.c +++ b/bacula/src/dird/dir_plugins.c @@ -79,7 +79,7 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) } bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; - event.eventType = eventType; + jcr->eventType = event.eventType = eventType; Dmsg2(dbglvl, "plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId); @@ -320,10 +320,70 @@ static bRC baculaGetValue(bpContext *ctx, brVariable var, void *value) return ret; } +extern struct s_jl joblevels[]; + static bRC baculaSetValue(bpContext *ctx, bwVariable var, void *value) { + bRC ret=bRC_OK; + + if (!ctx || !var || !value) { + return bRC_Error; + } + + JCR *jcr = (JCR *)ctx->bContext; + int intval = *(int*)value; + char *strval = (char *)value; + bool ok; + + switch (var) { + case bwVarJobReport: + Jmsg(jcr, M_INFO, 0, "%s", (char *)value); + break; + + case bwVarVolumeName: + /* Make sure VolumeName is valid and we are in VolumeName event */ + if (jcr->eventType == bEventNewVolume && + is_volume_name_legal(NULL, strval)) + { + pm_strcpy(jcr->VolumeName, strval); + Dmsg1(100, "Set Vol=%s\n", strval); + } else { + jcr->VolumeName[0] = 0; + ret = bRC_Error; + } + break; + + case bwVarPriority: + Dmsg1(000, "Set priority=%d\n", intval); + if (intval >= 1 && intval <= 100) { + jcr->JobPriority = intval; + } else { + ret = bRC_Error; + } + break; + + case bwVarJobLevel: + ok=true; + if (jcr->eventType == bEventJobInit) { + for (int i=0; ok && joblevels[i].level_name; i++) { + if (strcasecmp(strval, joblevels[i].level_name) == 0) { + if (joblevels[i].job_type == jcr->get_JobType()) { + jcr->set_JobLevel(joblevels[i].level); + jcr->jr.JobLevel = jcr->get_JobLevel(); + ok = false; + } + } + } + } else { + ret = bRC_Error; + } + break; + default: + ret = bRC_Error; + break; + } Dmsg1(dbglvl, "bacula: baculaSetValue var=%d\n", var); - return bRC_OK; + return ret; } static bRC baculaRegisterEvents(bpContext *ctx, ...) @@ -378,6 +438,7 @@ int main(int argc, char *argv[]) generate_plugin_event(jcr1, bEventJobStart, (void *)"Start Job 1"); generate_plugin_event(jcr1, bEventJobEnd); + generate_plugin_event(jcr2, bEventJobInit, (void *)"Start Job 1"); generate_plugin_event(jcr2, bEventJobStart, (void *)"Start Job 1"); free_plugins(jcr1); generate_plugin_event(jcr2, bEventJobEnd); diff --git a/bacula/src/dird/dir_plugins.h b/bacula/src/dird/dir_plugins.h index 6158c8ed61..5d5a4df516 100644 --- a/bacula/src/dird/dir_plugins.h +++ b/bacula/src/dird/dir_plugins.h @@ -109,7 +109,8 @@ typedef enum { bEventJobEnd = 2, bEventJobInit = 3, bEventJobRun = 4, - bEventVolumePurged = 5 + bEventVolumePurged = 5, + bEventNewVolume = 6 } bEventType; typedef struct s_bEvent { diff --git a/bacula/src/dird/newvol.c b/bacula/src/dird/newvol.c index d9f274e2cb..87c47f81d8 100644 --- a/bacula/src/dird/newvol.c +++ b/bacula/src/dird/newvol.c @@ -71,8 +71,9 @@ bool newVolume(JCR *jcr, MEDIA_DBR *mr) set_pool_dbr_defaults_in_media_dbr(mr, &pr); jcr->VolumeName[0] = 0; bstrncpy(mr->MediaType, jcr->wstore->media_type, sizeof(mr->MediaType)); - if (generate_job_event(jcr, "NewVolume") == 1 && jcr->VolumeName[0] && - is_volume_name_legal(NULL, jcr->VolumeName)) { + generate_job_event(jcr, "NewVolume"); /* return bool */ + generate_plugin_event(jcr, bEventNewVolume); /* return void... */ + if (jcr->VolumeName[0] && is_volume_name_legal(NULL, jcr->VolumeName)) { bstrncpy(mr->VolumeName, jcr->VolumeName, sizeof(mr->VolumeName)); /* Check for special characters */ } else if (pr.LabelFormat[0] && pr.LabelFormat[0] != '*') { diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index a07b6dc429..57ba318250 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -201,7 +201,9 @@ public: POOLMEM *VolumeName; /* Volume name desired -- pool_memory */ POOLMEM *errmsg; /* edited error message */ char Job[MAX_NAME_LENGTH]; /* Unique name of this Job */ - char event[MAX_NAME_LENGTH]; /* Current event */ + char event[MAX_NAME_LENGTH]; /* Current event (python) */ + uint32_t eventType; /* Current event type (plugin) */ + uint32_t JobId; /* Director's JobId */ uint32_t VolSessionId; uint32_t VolSessionTime; diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index 9a311512e1..70df1e0bd2 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -11,7 +11,7 @@ mixed priorities General: 13Nov08 -ebl Add more variable accessible through the director plugin +ebl Add more variables accessible through the director plugin interface. 12Nov08 ebl Do work on plugins -- 2.39.5