From aa413887a8992364c989dcd8306bdc01becc06d9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rados=C5=82aw=20Korzeniewski?= Date: Tue, 30 Mar 2021 16:19:19 +0200 Subject: [PATCH] metaplugin: Fix PluginObject handling as last item --- .../src/plugins/fd/pluginlib/metaplugin.cpp | 7 ++- bacula/src/plugins/fd/pluginlib/metaplugin.h | 1 + bacula/src/plugins/fd/pluginlib/ptcomm.h | 4 +- .../fd/pluginlib/test_metaplugin_backend.c | 49 ++++++++++++++++++- regress/scripts/metaplugin-protocol-tests.sh | 2 +- 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp index 070c9fbcd..fd58375bc 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp +++ b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp @@ -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 */ diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin.h b/bacula/src/plugins/fd/pluginlib/metaplugin.h index 6dd09b380..167b4d85a 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin.h +++ b/bacula/src/plugins/fd/pluginlib/metaplugin.h @@ -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 */ diff --git a/bacula/src/plugins/fd/pluginlib/ptcomm.h b/bacula/src/plugins/fd/pluginlib/ptcomm.h index 5b8da78b3..c869f46e7 100644 --- a/bacula/src/plugins/fd/pluginlib/ptcomm.h +++ b/bacula/src/plugins/fd/pluginlib/ptcomm.h @@ -172,7 +172,7 @@ public: * -1 - when encountered any error * - 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 * - 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); diff --git a/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c b/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c index 9deaddceb..9cd98d5b8 100644 --- a/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c +++ b/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c @@ -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(); } diff --git a/regress/scripts/metaplugin-protocol-tests.sh b/regress/scripts/metaplugin-protocol-tests.sh index 37b81094b..0bb939052 100755 --- a/regress/scripts/metaplugin-protocol-tests.sh +++ b/regress/scripts/metaplugin-protocol-tests.sh @@ -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)) -- 2.47.3