From: Radosław Korzeniewski Date: Mon, 30 Aug 2021 07:58:41 +0000 (+0200) Subject: Add getAccurateAttribs() FD Plugins callback. X-Git-Tag: Release-11.3.2~365 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01d8aae9ddf8dbb770779b1ae72deaab9ae74700;p=thirdparty%2Fbacula.git Add getAccurateAttribs() FD Plugins callback. This callback implements a direct query on accurate database. To make a query you need to provide `fname` in `accurate_attribs_pkt` parameter struct. Then you will get response at other struct fields. --- diff --git a/bacula/src/filed/accurate.c b/bacula/src/filed/accurate.c index 7dd7e4cea..22c62a6b0 100644 --- a/bacula/src/filed/accurate.c +++ b/bacula/src/filed/accurate.c @@ -265,6 +265,39 @@ static bool accurate_add_file(JCR *jcr, uint32_t len, return ret; } +bool accurate_get_file_attribs(JCR *jcr, accurate_attribs_pkt * att) +{ + CurFile elt; + struct stat statc; + int32_t LinkFIc; + + if (att == NULL || !jcr->accurate || !jcr->file_list) { + return false; + } + + if (att->fname == NULL) { + return false; + } + + if (!accurate_lookup(jcr, att->fname, &elt)) { + Dmsg1(dbglvl, "accurate %s (not found)\n", att->fname); + return false; + } + + // decode catalog stat + decode_stat(elt.lstat, &statc, sizeof(statc), &LinkFIc); + + // populate response data + memcpy(&att->statp, &statc, sizeof(statc)); + if (elt.chksum && *elt.chksum) { + att->chksum = bstrdup(elt.chksum); + } + att->delta_seq = elt.delta_seq; + att->seen = elt.seen; + + return true; +} + bool accurate_check_file(JCR *jcr, ATTR *attr, char *digest) { struct stat statc; diff --git a/bacula/src/filed/fd_plugins.c b/bacula/src/filed/fd_plugins.c index 2c83028e9..4463844b2 100644 --- a/bacula/src/filed/fd_plugins.c +++ b/bacula/src/filed/fd_plugins.c @@ -74,6 +74,7 @@ static bool is_plugin_compatible(Plugin *plugin); static bool get_plugin_name(JCR *jcr, char *cmd, int *ret); static bRC baculaCheckChanges(bpContext *ctx, struct save_pkt *sp); static bRC baculaAcceptFile(bpContext *ctx, struct save_pkt *sp); +static bRC baculaAccurateAttribs(bpContext *ctx, accurate_attribs_pkt *att); /* * These will be plugged into the global pointer structure for @@ -112,7 +113,8 @@ static bFuncs bfuncs = { baculaNewInclude, baculaNewPreInclude, baculaCheckChanges, - baculaAcceptFile + baculaAcceptFile, + baculaAccurateAttribs, }; /* @@ -2493,6 +2495,32 @@ bool plugin_get_features(JCR *jcr, alist *ret) return true; } +/** + * @brief Bacula Callback to get accurate data from the table. + * + * @param ctx Bacula plugin context + * @param att the in/out query parameter and data response; the input is att->fname + * @return bRC when bRC_Seen then query was success and found some data, + * bRC_OK when no data found or no accurate data is available + * bRC_Error on any error found + */ +static bRC baculaAccurateAttribs(bpContext *ctx, accurate_attribs_pkt *att) +{ + JCR *jcr; + bacula_ctx *bctx; + + Dsm_check(999); + if (!is_ctx_good(ctx, jcr, bctx) || att == NULL) { + return bRC_Error; + } + + if (accurate_get_file_attribs(jcr, att)) { + return bRC_Seen; + } + + return bRC_OK; +} + #ifdef TEST_PROGRAM int (*plugin_bopen)(JCR *jcr, const char *fname, uint64_t flags, mode_t mode) = NULL; diff --git a/bacula/src/filed/fd_plugins.h b/bacula/src/filed/fd_plugins.h index 317324fbe..9ee90b8ef 100644 --- a/bacula/src/filed/fd_plugins.h +++ b/bacula/src/filed/fd_plugins.h @@ -378,12 +378,22 @@ enum { BXATTR_RESTORE = 4 }; -struct xacl_pkt { - int32_t pkt_size; /* Size of this packet */ - int32_t func; /* Function code */ - int32_t count; /* read/write count */ - char *content; /* read/write buffer */ - int32_t pkt_end; /* end packet sentinel */ +struct xacl_pkt +{ + int32_t pkt_size; // Size of this packet + int32_t func; // Function code + int32_t count; // read/write count + char *content; // read/write buffer + int32_t pkt_end; // end packet sentinel +}; + +struct accurate_attribs_pkt +{ + char *fname; // file name to lookup + struct stat statp; // decoded stat packet + char *chksum; // file checksum + int32_t delta_seq; // delta seq + bool seen; // if the file was seen before }; /**************************************************************************** @@ -535,6 +545,7 @@ typedef struct s_baculaFuncs { 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 (*getAccurateAttribs)(bpContext *ctx, accurate_attribs_pkt *att); } bFuncs; diff --git a/bacula/src/filed/protos.h b/bacula/src/filed/protos.h index 060a55164..3dd3550e5 100644 --- a/bacula/src/filed/protos.h +++ b/bacula/src/filed/protos.h @@ -87,6 +87,7 @@ bool accurate_check_file(JCR *jcr, FF_PKT *ff_pkt); bool accurate_mark_file_as_seen(JCR *jcr, char *fname); void accurate_free(JCR *jcr); bool accurate_check_file(JCR *jcr, ATTR *attr, char *digest); +bool accurate_get_file_attribs(JCR *jcr, accurate_attribs_pkt *att); /* from backup.c */ void strip_path(FF_PKT *ff_pkt);