[prev in list] [next in list] [prev in thread] [next in thread]
List: bacula-commits
Subject: [Bacula-commits] SF.net SVN: bacula: [6325] trunk/bacula/src
From: kerns () users ! sourceforge ! net
Date: 2008-01-26 10:52:19
Message-ID: E1JIie3-00006o-F6 () sc8-pr-svn2 ! sourceforge ! net
[Download RAW message or body]
Revision: 6325
http://bacula.svn.sourceforge.net/bacula/?rev=6325&view=rev
Author: kerns
Date: 2008-01-26 02:52:19 -0800 (Sat, 26 Jan 2008)
Log Message:
-----------
First integration of FD plugin
Modified Paths:
--------------
trunk/bacula/src/filed/fd-plugins.c
trunk/bacula/src/filed/fd-plugins.h
trunk/bacula/src/filed/filed.c
trunk/bacula/src/filed/filed.h
trunk/bacula/src/filed/filed_conf.c
trunk/bacula/src/filed/job.c
trunk/bacula/src/plugins/fd/fd-plugins.c
trunk/bacula/src/plugins/fd/fd-plugins.h
Modified: trunk/bacula/src/filed/fd-plugins.c
===================================================================
--- trunk/bacula/src/filed/fd-plugins.c 2008-01-26 09:22:55 UTC (rev 6324)
+++ trunk/bacula/src/filed/fd-plugins.c 2008-01-26 10:52:19 UTC (rev 6325)
@@ -33,7 +33,6 @@
*/
#include "bacula.h"
#include "jcr.h"
-#include "lib/plugin.h"
#include "fd-plugins.h"
const int dbglvl = 0;
@@ -49,12 +48,7 @@
static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line,
int level, const char *msg);
-void load_fd_plugins(const char *plugin_dir);
-void new_plugins(JCR *jcr);
-void free_plugins(JCR *jcr);
-void plugin_event(JCR *jcr, bEventType event);
-
/* Bacula info */
static bInfo binfo = {
sizeof(bFuncs),
@@ -71,15 +65,20 @@
baculaJobMsg,
baculaDebugMsg
};
-
-
-void plugin_event(JCR *jcr, bEventType eventType)
+/*
+ * Create a plugin event
+ */
+void generate_plugin_event(JCR *jcr, bEventType eventType)
{
bEvent event;
Plugin *plugin;
int i = 0;
+ if (!plugin_list) {
+ return;
+ }
+
bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId);
event.eventType = eventType;
@@ -95,7 +94,6 @@
}
plugin_list = New(alist(10, not_owned_by_alist));
-
load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type);
}
@@ -107,6 +105,10 @@
Plugin *plugin;
int i = 0;
+ if (!plugin_list) {
+ return;
+ }
+
int num = plugin_list->size();
if (num == 0) {
@@ -116,7 +118,7 @@
jcr->plugin_ctx = (void *)malloc(sizeof(bpContext) * num);
bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
- Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId);
+ Dmsg2(dbglvl, "Instantiate plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, \
jcr->JobId); foreach_alist(plugin, plugin_list) {
/* Start a new instance of each plugin */
plugin_ctx[i].bContext = (void *)jcr;
@@ -133,7 +135,12 @@
Plugin *plugin;
int i = 0;
+ if (!plugin_list) {
+ return;
+ }
+
bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
+ Dmsg2(dbglvl, "Free instance plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, \
jcr->JobId); foreach_alist(plugin, plugin_list) {
/* Free the plugin instance */
plug_func(plugin)->freePlugin(&plugin_ctx[i++]);
@@ -143,21 +150,28 @@
}
+/* ==============================================================
+ *
+ * Callbacks from the plugin
+ *
+ * ==============================================================
+ */
static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value)
{
JCR *jcr = (JCR *)(ctx->bContext);
- Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var);
+// Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var);
if (!value) {
return 1;
}
- Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr);
+// Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr);
switch (var) {
case bVarJobId:
*((int *)value) = jcr->JobId;
Dmsg1(dbglvl, "Bacula: return bVarJobId=%d\n", jcr->JobId);
break;
case bVarFDName:
- *((char **)value) = "FD Name";
+ *((char **)value) = my_name;
+ Dmsg1(dbglvl, "Bacula: return my_name=%s\n", my_name);
break;
case bVarLevel:
case bVarType:
@@ -207,6 +221,8 @@
#ifdef TEST_PROGRAM
+char my_name = "test-fd";
+
int main(int argc, char *argv[])
{
char plugin_dir[1000];
@@ -223,11 +239,11 @@
jcr2->JobId = 222;
new_plugins(jcr2);
- plugin_event(jcr1, bEventJobStart);
- plugin_event(jcr1, bEventJobEnd);
- plugin_event(jcr2, bEventJobStart);
+ generate_plugin_event(jcr1, bEventJobStart);
+ generate_plugin_event(jcr1, bEventJobEnd);
+ generate_plugin_event(jcr2, bEventJobStart);
free_plugins(jcr1);
- plugin_event(jcr2, bEventJobEnd);
+ generate_plugin_event(jcr2, bEventJobEnd);
free_plugins(jcr2);
unload_plugins();
Modified: trunk/bacula/src/filed/fd-plugins.h
===================================================================
--- trunk/bacula/src/filed/fd-plugins.h 2008-01-26 09:22:55 UTC (rev 6324)
+++ trunk/bacula/src/filed/fd-plugins.h 2008-01-26 10:52:19 UTC (rev 6325)
@@ -48,6 +48,8 @@
#endif
+
+
/****************************************************************************
* *
* Bacula definitions *
@@ -93,7 +95,14 @@
int level, const char *msg);
} bFuncs;
+/* Bacula Subroutines */
+void load_fd_plugins(const char *plugin_dir);
+void new_plugins(JCR *jcr);
+void free_plugins(JCR *jcr);
+void generate_plugin_event(JCR *jcr, bEventType event);
+
+
/****************************************************************************
* *
* Plugin definitions *
Modified: trunk/bacula/src/filed/filed.c
===================================================================
--- trunk/bacula/src/filed/filed.c 2008-01-26 09:22:55 UTC (rev 6324)
+++ trunk/bacula/src/filed/filed.c 2008-01-26 10:52:19 UTC (rev 6325)
@@ -1,7 +1,7 @@
/*
Bacula ® - The Network Backup Solution
- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
@@ -208,6 +208,8 @@
create_pid_file(me->pid_directory, "bacula-fd", \
get_first_port_host_order(me->FDaddrs)); read_state_file(me->working_directory, \
"bacula-fd", get_first_port_host_order(me->FDaddrs));
+ load_fd_plugins(me->plugin_directory);
+
drop(uid, gid);
#ifdef BOMB
@@ -248,6 +250,7 @@
bnet_stop_thread_server(server_tid);
generate_daemon_event(NULL, "Exit");
+ unload_plugins();
write_state_file(me->working_directory, "bacula-fd", \
get_first_port_host_order(me->FDaddrs)); delete_pid_file(me->pid_directory, \
"bacula-fd", get_first_port_host_order(me->FDaddrs));
Modified: trunk/bacula/src/filed/filed.h
===================================================================
--- trunk/bacula/src/filed/filed.h 2008-01-26 09:22:55 UTC (rev 6324)
+++ trunk/bacula/src/filed/filed.h 2008-01-26 10:52:19 UTC (rev 6325)
@@ -1,14 +1,7 @@
/*
- * Bacula File Daemon specific configuration and defines
- *
- * Kern Sibbald, Jan MMI
- *
- * Version $Id$
- */
-/*
Bacula ® - The Network Backup Solution
- Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2001-2008 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
@@ -32,9 +25,18 @@
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ * Bacula File Daemon specific configuration and defines
+ *
+ * Kern Sibbald, Jan MMI
+ *
+ * Version $Id$
+ */
+
#define FILE_DAEMON 1
#include "filed_conf.h"
+#include "fd-plugins.h"
#include "findlib/find.h"
#include "jcr.h"
#include "acl.h"
Modified: trunk/bacula/src/filed/filed_conf.c
===================================================================
--- trunk/bacula/src/filed/filed_conf.c 2008-01-26 09:22:55 UTC (rev 6324)
+++ trunk/bacula/src/filed/filed_conf.c 2008-01-26 10:52:19 UTC (rev 6325)
@@ -260,6 +260,9 @@
if (res->res_client.scripts_directory) {
free(res->res_client.scripts_directory);
}
+ if (res->res_client.plugin_directory) {
+ free(res->res_client.plugin_directory);
+ }
if (res->res_client.FDaddrs) {
free_addresses(res->res_client.FDaddrs);
}
Modified: trunk/bacula/src/filed/job.c
===================================================================
--- trunk/bacula/src/filed/job.c 2008-01-26 09:22:55 UTC (rev 6324)
+++ trunk/bacula/src/filed/job.c 2008-01-26 10:52:19 UTC (rev 6325)
@@ -212,6 +212,7 @@
jcr->last_fname = get_pool_memory(PM_FNAME);
jcr->last_fname[0] = 0;
jcr->client_name = get_memory(strlen(my_name) + 1);
+ new_plugins(jcr); /* instantiate plugins for this jcr */
pm_strcpy(jcr->client_name, my_name);
jcr->pki_sign = me->pki_sign;
jcr->pki_encrypt = me->pki_encrypt;
@@ -280,12 +281,15 @@
}
generate_daemon_event(jcr, "JobEnd");
+ generate_plugin_event(jcr, bEventJobEnd);
dequeue_messages(jcr); /* send any queued messages */
/* Inform Director that we are done */
- bnet_sig(dir, BNET_TERMINATE);
+ dir->signal(BNET_TERMINATE);
+ free_plugins(jcr); /* release instantiated plugins */
+
/* Clean up fileset */
FF_PKT *ff = jcr->ff;
findFILESET *fileset = ff->fileset;
@@ -1405,6 +1409,7 @@
}
generate_daemon_event(jcr, "JobStart");
+ generate_plugin_event(jcr, bEventJobStart);
#if defined(WIN32_VSS)
/* START VSS ON WIN 32 */
@@ -1554,6 +1559,7 @@
dir->fsend(OKverify);
generate_daemon_event(jcr, "JobStart");
+ generate_plugin_event(jcr, bEventJobStart);
Dmsg1(110, "bfiled>dird: %s", dir->msg);
@@ -1650,7 +1656,7 @@
jcr->replace = replace;
jcr->prefix_links = prefix_links;
- bnet_fsend(dir, OKrestore);
+ dir->fsend(OKrestore);
Dmsg1(110, "bfiled>dird: %s", dir->msg);
jcr->JobType = JT_RESTORE;
@@ -1669,6 +1675,7 @@
*/
start_dir_heartbeat(jcr);
generate_daemon_event(jcr, "JobStart");
+ generate_plugin_event(jcr, bEventJobStart);
do_restore(jcr);
stop_dir_heartbeat(jcr);
@@ -1680,13 +1687,13 @@
/*
* Send Close session command to Storage daemon
*/
- bnet_fsend(sd, read_close, jcr->Ticket);
+ sd->fsend(read_close, jcr->Ticket);
Dmsg1(130, "bfiled>stored: %s", sd->msg);
bget_msg(sd); /* get OK */
/* Inform Storage daemon that we are done */
- bnet_sig(sd, BNET_TERMINATE);
+ sd->signal(BNET_TERMINATE);
bail_out:
Modified: trunk/bacula/src/plugins/fd/fd-plugins.c
===================================================================
--- trunk/bacula/src/plugins/fd/fd-plugins.c 2008-01-26 09:22:55 UTC (rev 6324)
+++ trunk/bacula/src/plugins/fd/fd-plugins.c 2008-01-26 10:52:19 UTC (rev 6325)
@@ -33,7 +33,6 @@
*/
#include "bacula.h"
#include "jcr.h"
-#include "lib/plugin.h"
#include "fd-plugins.h"
const int dbglvl = 0;
@@ -49,12 +48,7 @@
static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line,
int level, const char *msg);
-void load_fd_plugins(const char *plugin_dir);
-void new_plugins(JCR *jcr);
-void free_plugins(JCR *jcr);
-void plugin_event(JCR *jcr, bEventType event);
-
/* Bacula info */
static bInfo binfo = {
sizeof(bFuncs),
@@ -71,15 +65,20 @@
baculaJobMsg,
baculaDebugMsg
};
-
-
-void plugin_event(JCR *jcr, bEventType eventType)
+/*
+ * Create a plugin event
+ */
+void generate_plugin_event(JCR *jcr, bEventType eventType)
{
bEvent event;
Plugin *plugin;
int i = 0;
+ if (!plugin_list) {
+ return;
+ }
+
bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId);
event.eventType = eventType;
@@ -95,7 +94,6 @@
}
plugin_list = New(alist(10, not_owned_by_alist));
-
load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type);
}
@@ -107,6 +105,10 @@
Plugin *plugin;
int i = 0;
+ if (!plugin_list) {
+ return;
+ }
+
int num = plugin_list->size();
if (num == 0) {
@@ -116,7 +118,7 @@
jcr->plugin_ctx = (void *)malloc(sizeof(bpContext) * num);
bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
- Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId);
+ Dmsg2(dbglvl, "Instantiate plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, \
jcr->JobId); foreach_alist(plugin, plugin_list) {
/* Start a new instance of each plugin */
plugin_ctx[i].bContext = (void *)jcr;
@@ -133,7 +135,12 @@
Plugin *plugin;
int i = 0;
+ if (!plugin_list) {
+ return;
+ }
+
bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
+ Dmsg2(dbglvl, "Free instance plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, \
jcr->JobId); foreach_alist(plugin, plugin_list) {
/* Free the plugin instance */
plug_func(plugin)->freePlugin(&plugin_ctx[i++]);
@@ -143,21 +150,28 @@
}
+/* ==============================================================
+ *
+ * Callbacks from the plugin
+ *
+ * ==============================================================
+ */
static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value)
{
JCR *jcr = (JCR *)(ctx->bContext);
- Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var);
+// Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var);
if (!value) {
return 1;
}
- Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr);
+// Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr);
switch (var) {
case bVarJobId:
*((int *)value) = jcr->JobId;
Dmsg1(dbglvl, "Bacula: return bVarJobId=%d\n", jcr->JobId);
break;
case bVarFDName:
- *((char **)value) = "FD Name";
+ *((char **)value) = my_name;
+ Dmsg1(dbglvl, "Bacula: return my_name=%s\n", my_name);
break;
case bVarLevel:
case bVarType:
@@ -207,12 +221,15 @@
#ifdef TEST_PROGRAM
+
int main(int argc, char *argv[])
{
char plugin_dir[1000];
JCR mjcr1, mjcr2;
JCR *jcr1 = &mjcr1;
JCR *jcr2 = &mjcr2;
+
+ strcpy(my_name, "test-fd");
getcwd(plugin_dir, sizeof(plugin_dir)-1);
load_fd_plugins(plugin_dir);
@@ -223,11 +240,11 @@
jcr2->JobId = 222;
new_plugins(jcr2);
- plugin_event(jcr1, bEventJobStart);
- plugin_event(jcr1, bEventJobEnd);
- plugin_event(jcr2, bEventJobStart);
+ generate_plugin_event(jcr1, bEventJobStart);
+ generate_plugin_event(jcr1, bEventJobEnd);
+ generate_plugin_event(jcr2, bEventJobStart);
free_plugins(jcr1);
- plugin_event(jcr2, bEventJobEnd);
+ generate_plugin_event(jcr2, bEventJobEnd);
free_plugins(jcr2);
unload_plugins();
Modified: trunk/bacula/src/plugins/fd/fd-plugins.h
===================================================================
--- trunk/bacula/src/plugins/fd/fd-plugins.h 2008-01-26 09:22:55 UTC (rev 6324)
+++ trunk/bacula/src/plugins/fd/fd-plugins.h 2008-01-26 10:52:19 UTC (rev 6325)
@@ -48,6 +48,8 @@
#endif
+
+
/****************************************************************************
* *
* Bacula definitions *
@@ -93,7 +95,14 @@
int level, const char *msg);
} bFuncs;
+/* Bacula Subroutines */
+void load_fd_plugins(const char *plugin_dir);
+void new_plugins(JCR *jcr);
+void free_plugins(JCR *jcr);
+void generate_plugin_event(JCR *jcr, bEventType event);
+
+
/****************************************************************************
* *
* Plugin definitions *
This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Bacula-commits mailing list
Bacula-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic