]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add getAccurateAttribs() FD Plugins callback.
authorRadosław Korzeniewski <radoslaw@korzeniewski.net>
Mon, 30 Aug 2021 07:58:41 +0000 (09:58 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:03 +0000 (09:03 +0100)
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.

bacula/src/filed/accurate.c
bacula/src/filed/fd_plugins.c
bacula/src/filed/fd_plugins.h
bacula/src/filed/protos.h

index 7dd7e4ceabe24f22b1e231d77b75aee803d02c63..22c62a6b0da414d634634296c4f73298008cfef7 100644 (file)
@@ -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;
index 2c83028e977419c77b1631733542895f1e93c19a..4463844b2d735f9e9389aec96ff275967a4dcfef 100644 (file)
@@ -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;
index 317324fbefd23c023c8bd9f5d7b1ceeabb42d70d..9ee90b8ef60ab28f47ce735c03ff8d4192ffa82f 100644 (file)
@@ -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;
 
 
index 060a55164e3583a536d4ad6c6fd2e1e731096f9d..3dd3550e59f792c9ce01303d1d41ac1cbcfadf5d 100644 (file)
@@ -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);