Skip to content

Commit

Permalink
plugins: Enhance fd-plugin interface.
Browse files Browse the repository at this point in the history
Added two new methods in the Bareos FD callback methods:

- SetSeenBitmap to Set a bit in the seen bitmap for a specific file or
  for all files in a backup.
- ClearSeenBitmap to Clear a bit in the seen bitmap for a specific file
  or for all files in a backup.
  • Loading branch information
Marco van Wieringen committed May 13, 2016
1 parent 58ed3dd commit eca0d3f
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 28 deletions.
39 changes: 39 additions & 0 deletions src/filed/accurate.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,45 @@ bool accurate_mark_file_as_seen(JCR *jcr, char *fname)
return true;
}

bool accurate_unmark_file_as_seen(JCR *jcr, char *fname)
{
accurate_payload *temp;

if (!jcr->accurate || !jcr->file_list) {
return false;
}

temp = jcr->file_list->lookup_payload(jcr, fname);
if (temp) {
jcr->file_list->unmark_file_as_seen(jcr, temp);
Dmsg1(dbglvl, "unmarked <%s> as seen\n", fname);
} else {
Dmsg1(dbglvl, "<%s> not found to be unmarked as seen\n", fname);
}

return true;
}

bool accurate_mark_all_files_as_seen(JCR *jcr)
{
if (!jcr->accurate || !jcr->file_list) {
return false;
}

jcr->file_list->mark_all_files_as_seen(jcr);
return true;
}

bool accurate_unmark_all_files_as_seen(JCR *jcr)
{
if (!jcr->accurate || !jcr->file_list) {
return false;
}

jcr->file_list->unmark_all_files_as_seen(jcr);
return true;
}

static inline bool accurate_lookup(JCR *jcr, char *fname, accurate_payload **payload)
{
bool found = false;
Expand Down
3 changes: 3 additions & 0 deletions src/filed/accurate.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class B_ACCURATE: public SMARTALLOC {
virtual bool send_deleted_list(JCR *jcr) = 0;
virtual void destroy(JCR *jcr) = 0;
void mark_file_as_seen(JCR *jcr, accurate_payload *payload) { set_bit(payload->filenr, m_seen_bitmap); };
void unmark_file_as_seen(JCR *jcr, accurate_payload *payload) { clear_bit(payload->filenr, m_seen_bitmap); };
void mark_all_files_as_seen(JCR *jcr) { set_bits(0, m_filenr - 1, m_seen_bitmap); };
void unmark_all_files_as_seen(JCR *jcr) { clear_bits(0, m_filenr - 1, m_seen_bitmap); };
};

/*
Expand Down
107 changes: 87 additions & 20 deletions src/filed/fd_plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ extern DLL_IMP_EXP boffset_t (*plugin_blseek)(BFILE *bfd, boffset_t offset, int
static bRC bareosGetValue(bpContext *ctx, bVariable var, void *value);
static bRC bareosSetValue(bpContext *ctx, bVariable var, void *value);
static bRC bareosRegisterEvents(bpContext *ctx, int nr_events, ...);
static bRC bareosJobMsg(bpContext *ctx, const char *file, int line,
static bRC bareosJobMsg(bpContext *ctx, const char *fname, int line,
int type, utime_t mtime, const char *fmt, ...);
static bRC bareosDebugMsg(bpContext *ctx, const char *file, int line,
static bRC bareosDebugMsg(bpContext *ctx, const char *fname, int line,
int level, const char *fmt, ...);
static void *bareosMalloc(bpContext *ctx, const char *file, int line,
static void *bareosMalloc(bpContext *ctx, const char *fname, int line,
size_t size);
static void bareosFree(bpContext *ctx, const char *file, int line, void *mem);
static bRC bareosAddExclude(bpContext *ctx, const char *file);
Expand All @@ -78,6 +78,8 @@ static bool is_plugin_compatible(Plugin *plugin);
static bool get_plugin_name(JCR *jcr, char *cmd, int *ret);
static bRC bareosCheckChanges(bpContext *ctx, struct save_pkt *sp);
static bRC bareosAcceptFile(bpContext *ctx, struct save_pkt *sp);
static bRC bareosSetSeenBitmap(bpContext *ctx, bool all, char *fname);
static bRC bareosClearSeenBitmap(bpContext *ctx, bool all, char *fname);

/*
* These will be plugged into the global pointer structure for the findlib.
Expand Down Expand Up @@ -114,7 +116,9 @@ static bFuncs bfuncs = {
bareosNewInclude,
bareosNewPreInclude,
bareosCheckChanges,
bareosAcceptFile
bareosAcceptFile,
bareosSetSeenBitmap,
bareosClearSeenBitmap
};

/*
Expand Down Expand Up @@ -2157,7 +2161,7 @@ static bRC bareosRegisterEvents(bpContext *ctx, int nr_events, ...)
return bRC_OK;
}

static bRC bareosJobMsg(bpContext *ctx, const char *file, int line,
static bRC bareosJobMsg(bpContext *ctx, const char *fname, int line,
int type, utime_t mtime, const char *fmt, ...)
{
JCR *jcr;
Expand All @@ -2178,7 +2182,7 @@ static bRC bareosJobMsg(bpContext *ctx, const char *file, int line,
return bRC_OK;
}

static bRC bareosDebugMsg(bpContext *ctx, const char *file, int line,
static bRC bareosDebugMsg(bpContext *ctx, const char *fname, int line,
int level, const char *fmt, ...)
{
va_list arg_ptr;
Expand All @@ -2187,25 +2191,24 @@ static bRC bareosDebugMsg(bpContext *ctx, const char *file, int line,
va_start(arg_ptr, fmt);
buffer.bvsprintf(fmt, arg_ptr);
va_end(arg_ptr);
d_msg(file, line, level, "%s", buffer.c_str());
d_msg(fname, line, level, "%s", buffer.c_str());

return bRC_OK;
}

static void *bareosMalloc(bpContext *ctx, const char *file, int line,
size_t size)
static void *bareosMalloc(bpContext *ctx, const char *fname, int line, size_t size)
{
#ifdef SMARTALLOC
return sm_malloc(file, line, size);
return sm_malloc(fname, line, size);
#else
return malloc(size);
#endif
}

static void bareosFree(bpContext *ctx, const char *file, int line, void *mem)
static void bareosFree(bpContext *ctx, const char *fname, int line, void *mem)
{
#ifdef SMARTALLOC
sm_free(file, line, mem);
sm_free(fname, line, mem);
#else
free(mem);
#endif
Expand Down Expand Up @@ -2233,15 +2236,15 @@ static bool is_ctx_good(bpContext *ctx, JCR *&jcr, b_plugin_ctx *&bctx)
/**
* Let the plugin define files/directories to be excluded from the main backup.
*/
static bRC bareosAddExclude(bpContext *ctx, const char *file)
static bRC bareosAddExclude(bpContext *ctx, const char *fname)
{
JCR *jcr;
findINCEXE *old;
b_plugin_ctx *bctx;
if (!is_ctx_good(ctx, jcr, bctx)) {
return bRC_Error;
}
if (!file) {
if (!fname) {
return bRC_Error;
}

Expand All @@ -2266,22 +2269,22 @@ static bRC bareosAddExclude(bpContext *ctx, const char *file)
*/
set_incexe(jcr, bctx->exclude);

add_file_to_fileset(jcr, file, true);
add_file_to_fileset(jcr, fname, true);

/*
* Restore the current context
*/
set_incexe(jcr, old);

Dmsg1(100, "Add exclude file=%s\n", file);
Dmsg1(100, "Add exclude file=%s\n", fname);

return bRC_OK;
}

/**
* Let the plugin define files/directories to be excluded from the main backup.
*/
static bRC bareosAddInclude(bpContext *ctx, const char *file)
static bRC bareosAddInclude(bpContext *ctx, const char *fname)
{
JCR *jcr;
findINCEXE *old;
Expand All @@ -2291,7 +2294,7 @@ static bRC bareosAddInclude(bpContext *ctx, const char *file)
return bRC_Error;
}

if (!file) {
if (!fname) {
return bRC_Error;
}

Expand All @@ -2312,14 +2315,14 @@ static bRC bareosAddInclude(bpContext *ctx, const char *file)
}

set_incexe(jcr, bctx->include);
add_file_to_fileset(jcr, file, true);
add_file_to_fileset(jcr, fname, true);

/*
* Restore the current context
*/
set_incexe(jcr, old);

Dmsg1(100, "Add include file=%s\n", file);
Dmsg1(100, "Add include file=%s\n", fname);

return bRC_OK;
}
Expand Down Expand Up @@ -2506,6 +2509,70 @@ static bRC bareosAcceptFile(bpContext *ctx, struct save_pkt *sp)
return ret;
}

/**
* Manipulate the accurate seen bitmap for setting bits
*/
static bRC bareosSetSeenBitmap(bpContext *ctx, bool all, char *fname)
{
JCR *jcr;
b_plugin_ctx *bctx;
bRC ret = bRC_Error;

if (!is_ctx_good(ctx, jcr, bctx)) {
goto bail_out;
}

if (all && fname) {
Dmsg0(dbglvl, "fd-plugin: API error in call to SetSeenBitmap, both all and fname set!!!\n");
goto bail_out;
}

if (all) {
if (accurate_mark_all_files_as_seen(jcr)) {
ret = bRC_OK;
}
} else if (fname) {
if (accurate_mark_file_as_seen(jcr, fname)) {
ret = bRC_OK;
}
}

bail_out:
return ret;
}

/**
* Manipulate the accurate seen bitmap for clearing bits
*/
static bRC bareosClearSeenBitmap(bpContext *ctx, bool all, char *fname)
{
JCR *jcr;
b_plugin_ctx *bctx;
bRC ret = bRC_Error;

if (!is_ctx_good(ctx, jcr, bctx)) {
goto bail_out;
}

if (all && fname) {
Dmsg0(dbglvl, "fd-plugin: API error in call to ClearSeenBitmap, both all and fname set!!!\n");
goto bail_out;
}

if (all) {
if (accurate_unmark_all_files_as_seen(jcr)) {
ret = bRC_OK;
}
} else if (fname) {
if (accurate_unmark_file_as_seen(jcr, fname)) {
ret = bRC_OK;
}
}

bail_out:
return ret;
}

#ifdef TEST_PROGRAM

/* Exported variables */
Expand Down
16 changes: 8 additions & 8 deletions src/filed/fd_plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,11 @@ typedef struct s_bareosFuncs {
bRC (*registerBareosEvents)(bpContext *ctx, int nr_events, ...);
bRC (*getBareosValue)(bpContext *ctx, bVariable var, void *value);
bRC (*setBareosValue)(bpContext *ctx, bVariable var, void *value);
bRC (*JobMessage)(bpContext *ctx, const char *file, int line,
int type, utime_t mtime, const char *fmt, ...);
bRC (*DebugMessage)(bpContext *ctx, const char *file, int line,
int level, const char *fmt, ...);
void *(*bareosMalloc)(bpContext *ctx, const char *file, int line,
size_t size);
bRC (*JobMessage)(bpContext *ctx, const char *file, int line, int type,
utime_t mtime, const char *fmt, ...);
bRC (*DebugMessage)(bpContext *ctx, const char *file, int line, int level,
const char *fmt, ...);
void *(*bareosMalloc)(bpContext *ctx, const char *file, int line, size_t size);
void (*bareosFree)(bpContext *ctx, const char *file, int line, void *mem);
bRC (*AddExclude)(bpContext *ctx, const char *file);
bRC (*AddInclude)(bpContext *ctx, const char *file);
Expand All @@ -307,6 +306,8 @@ typedef struct s_bareosFuncs {
bRC (*NewPreInclude)(bpContext *ctx);
bRC (*checkChanges)(bpContext *ctx, struct save_pkt *sp);
bRC (*AcceptFile)(bpContext *ctx, struct save_pkt *sp); /* Need fname and statp */
bRC (*SetSeenBitmap)(bpContext *ctx, bool all, char *fname);
bRC (*ClearSeenBitmap)(bpContext *ctx, bool all, char *fname);
} bFuncs;

/****************************************************************************
Expand All @@ -324,8 +325,7 @@ typedef enum {
#define FD_PLUGIN_INTERFACE_VERSION 9

/*
* This is a set of function pointers that Bareos can call
* within the plugin.
* This is a set of function pointers that Bareos can call within the plugin.
*/
typedef struct s_pluginFuncs {
uint32_t size;
Expand Down
3 changes: 3 additions & 0 deletions src/filed/protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
bool accurate_finish(JCR *jcr);
bool accurate_check_file(JCR *jcr, FF_PKT *ff_pkt);
bool accurate_mark_file_as_seen(JCR *jcr, char *fname);
bool accurate_unmark_file_as_seen(JCR *jcr, char *fname);
bool accurate_mark_all_files_as_seen(JCR *jcr);
bool accurate_unmark_all_files_as_seen(JCR *jcr);
void accurate_free(JCR *jcr);

/* authenticate.c */
Expand Down

0 comments on commit eca0d3f

Please sign in to comment.