]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
metaplugin: Fix PluginObject handling as last item
authorRadosław Korzeniewski <radoslaw@korzeniewski.net>
Tue, 30 Mar 2021 14:19:19 +0000 (16:19 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:00 +0000 (09:03 +0100)
bacula/src/plugins/fd/pluginlib/metaplugin.cpp
bacula/src/plugins/fd/pluginlib/metaplugin.h
bacula/src/plugins/fd/pluginlib/ptcomm.h
bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c
regress/scripts/metaplugin-protocol-tests.sh

index 070c9fbcd819cb060d643620655a9fa4a0af1be3..fd58375bc6060b93ec9a0022c4d23e9ce1e596ad 100644 (file)
@@ -162,6 +162,7 @@ METAPLUGIN::METAPLUGIN(bpContext *bpctx) :
       nextfile(false),
       openerror(false),
       pluginobject(false),
+      pluginobjectsent(false),
       readacl(false),
       readxattr(false),
       accurate_warning(false),
@@ -1737,7 +1738,7 @@ bRC METAPLUGIN::perform_read_pluginobject(bpContext *ctx, struct save_pkt *sp)
    // loop on plugin objects parameters from backend and EOD
    while (true){
       if (backend.ctx->read_command(ctx, cmd) > 0){
-         DMSG(ctx, DDEBUG, "read_command(1): %s\n", cmd.c_str());
+         DMSG(ctx, DDEBUG, "read_command(3): %s\n", cmd.c_str());
          if (scan_parameter_str(cmd, "PLUGINOBJ_CAT:", plugin_obj_cat)){
             DMSG1(ctx, DDEBUG, "category: %s\n", plugin_obj_cat.c_str());
             sp->plugin_obj.object_category = plugin_obj_cat.c_str();
@@ -1788,6 +1789,7 @@ bRC METAPLUGIN::perform_read_pluginobject(bpContext *ctx, struct save_pkt *sp)
             /* no more plugin object params to backup */
             DMSG0(ctx, DINFO, "No more Plugin Object params from backend.\n");
             pluginobject = false;
+            pluginobjectsent = true;
             return bRC_OK;
          }
       }
@@ -2123,8 +2125,9 @@ bRC METAPLUGIN::endBackupFile(bpContext *ctx)
    // check for next file only when no previous error
    if (!openerror)
    {
-      if (estimate)
+      if (estimate || pluginobjectsent)
       {
+         pluginobjectsent = false;
          if (perform_read_metadata(ctx) != bRC_OK)
          {
             /* signal error */
index 6dd09b38095a0009b4c8627556891b847ef9019f..167b4d85aea737ba3a785daea9b1c8dd468a588b 100644 (file)
@@ -139,6 +139,7 @@ private:
    bool nextfile;                // set when IO_CLOSE got FNAME: command
    bool openerror;               // show if "openfile" was unsuccessful
    bool pluginobject;            // set when IO_CLOSE got FNAME: command
+   bool pluginobjectsent;        // set when startBackupFile handled plugin object and endBackupFile has to check for nextfile
    bool readacl;                 // got ACL data from backend
    bool readxattr;               // got XATTR data from backend
    bool accurate_warning;        // for sending accurate mode warning once */
index 5b8da78b3978ea1c99232e411730d65ba46eb79e..c869f46e78b4ab99c06593460107ddf36609b81f 100644 (file)
@@ -172,7 +172,7 @@ public:
     *    -1 - when encountered any error
     *    <n> - the number of bytes sent, success
     */
-   inline int32_t signal_eod(bpContext *ctx) { return sendbackend(ctx, 'F', "000000", 0); }
+   inline int32_t signal_eod(bpContext *ctx) { return sendbackend(ctx, 'F', NULL, 0); }
 
    /**
     * @brief Signal end of communication to the backend.
@@ -183,7 +183,7 @@ public:
     *    -1 - when encountered any error
     *    <n> - the number of bytes sent, success
     */
-   inline int32_t signal_term(bpContext *ctx) { return sendbackend(ctx, 'T', "000000", 0); }
+   inline int32_t signal_term(bpContext *ctx) { return sendbackend(ctx, 'T', NULL, 0); }
 
    void terminate(bpContext *ctx);
 
index 9deaddceb77f0a2fe9997218b1d2bfa810df88be..9cd98d5b83b2b4bf84071a3251a350d01e1477b6 100644 (file)
@@ -406,13 +406,25 @@ void perform_backup()
       write_plugin('A', "Some error...\n");
       return;
    }
+
+   snprintf(buf, BIGBUFLEN, "FNAME:%s/bucket/%d/data.dir/\n", PLUGINPREFIX, mypid);
+   write_plugin('C', buf);
+   write_plugin('C', "STAT:D 1024 100 100 040755 1\n");
+   write_plugin('C', "TSTAMP:1504271937 1504271937 1504271937\n");
+   signal_eod();
+   write_plugin('I', "TEST15 - backup data dir");
+   write_plugin('C', "DATA\n");
+   write_plugin('D', "/* here comes a file data contents */");
+   write_plugin('D', "/* here comes another file line    */");
+   signal_eod();
+
 #if 0
-   snprintf(buf, BIGBUFLEN, "FNAME:%s/bucket/%d/directory\n", PLUGINPREFIX, mypid);
+   snprintf(buf, BIGBUFLEN, "FNAME:%s/bucket/%d/directory.with.xattrs/\n", PLUGINPREFIX, mypid);
    write_plugin('C', buf);
    write_plugin('C', "STAT:D 1024 100 100 040755 1\n");
    write_plugin('C', "TSTAMP:1504271937 1504271937 1504271937\n");
    signal_eod();
-   write_plugin('I', "TEST15 - backup dir + xattrs");
+   write_plugin('I', "TEST16 - backup dir + xattrs");
    write_plugin('C', "DATA\n");
    write_plugin('D', "/* here comes a file data contents */");
    write_plugin('D', "/* here comes another file line    */");
@@ -421,6 +433,20 @@ void perform_backup()
    write_plugin('D', "bacula.custom.data=Inteos\nsystem.custom.data=Bacula\n");
    signal_eod();
 #endif
+
+#if 1
+   snprintf(buf, BIGBUFLEN, "FNAME:%s/bucket/%d/acl.dir/\n", PLUGINPREFIX, mypid);
+   write_plugin('C', buf);
+   write_plugin('C', "STAT:D 1024 100 100 040755 1\n");
+   write_plugin('C', "TSTAMP:1504271937 1504271937 1504271937\n");
+   signal_eod();
+   write_plugin('I', "TEST12 - backup dir");
+   signal_eod();
+   write_plugin('C', "ACL\n");
+   write_plugin('D', "user::rwx\ngroup::r-x\nother::r-x\n");
+   signal_eod();
+#endif
+
    snprintf(buf, BIGBUFLEN, "FNAME:%s/bucket/%d/\n", PLUGINPREFIX, mypid);
    write_plugin('C', buf);
    write_plugin('C', "STAT:D 1024 100 100 040755 1\n");
@@ -513,6 +539,25 @@ void perform_backup()
    signal_eod();
    signal_eod();
 
+   // this plugin object should be the latest item to backup
+   if (regress_backup_plugin_objects)
+   {
+      // test Plugin Objects interface
+      write_plugin('I', "TEST PluginObject Last");
+      snprintf(buf, BIGBUFLEN, "PLUGINOBJ:%s/images/%d/last_po_item\n", PLUGINPREFIX, mypid);
+      write_plugin('C', buf);
+      write_plugin('C', "PLUGINOBJ_CAT:POITEM\n");
+      write_plugin('C', "PLUGINOBJ_TYPE:POINTEM\n");
+      snprintf(buf, BIGBUFLEN, "PLUGINOBJ_NAME:%s%d/last_po_item - Name\n", PLUGINPREFIX, mypid);
+      write_plugin('C', buf);
+      snprintf(buf, BIGBUFLEN, "PLUGINOBJ_SRC:%s\n", PLUGINPREFIX);
+      write_plugin('C', buf);
+      write_plugin('C', "PLUGINOBJ_UUID:09bf8b2a-915d-11eb-8ebb-db6e14058a82\n");
+      write_plugin('C', "PLUGINOBJ_SIZE:1024kB\n");
+      signal_eod();
+      write_plugin('I', "TEST PluginObject Last - END");
+   }
+
    /* this is the end of all data */
    signal_eod();
 }
index 37b81094ba283059ac06f6c1ab5bec19484c0b8c..0bb9390523139a1da08a419d7cbdd2e6a476d519 100755 (executable)
@@ -245,7 +245,7 @@ then
 fi
 
 RET=$(grep -c "objectid:" ${cwd}/tmp/log2.out)
-if [ "$RET" -ne 1 ]
+if [ "$RET" -le 1 ]
 then
    echo "log2" "$RET"
    bstat=$((bstat+4))