From: Radosław Korzeniewski Date: Mon, 4 Oct 2021 08:02:16 +0000 (+0200) Subject: metaplugin: Add new STAT command flavour. X-Git-Tag: Beta-15.0.0~865 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=43f72587b59e0681ab4def123aa255bbe4ff889a;p=thirdparty%2Fbacula.git metaplugin: Add new STAT command flavour. Now you can ask metaplugin to get all stat(2) field values using an existing file as a template. In this case next TSTAT command is not required. --- diff --git a/bacula/src/plugins/fd/pluginlib/Makefile b/bacula/src/plugins/fd/pluginlib/Makefile index a6a13ddb5..ad5f36c90 100644 --- a/bacula/src/plugins/fd/pluginlib/Makefile +++ b/bacula/src/plugins/fd/pluginlib/Makefile @@ -12,8 +12,6 @@ include ../Makefile.inc _GIT := $(shell eval $(topdir)/scripts/getgitcommit) VERSIONGIT = "/git-$(_GIT)" -UNITTESTSOBJ = $(LIBDIR)/unittests.lo -LIBBACOBJ = $(LIBDIR)/libbac.la LIBBACCFGOBJ = $(LIBDIR)/libbaccfg.la PLUGINLIBSSRC = pluginlib.cpp pluginlib.h @@ -69,9 +67,6 @@ all: $(COMMONPLUGINOBJ) # $(TESTMETAPLUGINBACKENDOBJ) tests: $(COMMONPLUGINTESTS) -$(LIBBACCFGOBJ): - $(MAKE) -C $(LIBDIR) libbaccfg.la - test_metaplugin_backend.lo: $(TESTMETAPLUGINBACKENDSRC) @echo "Compiling backend $< ..." $(NO_ECHO)$(LIBTOOL_COMPILE) $(CXX) $(DEFS) $(DEBUG) $(CPPFLAGS) $(CFLAGS) -I${SRCDIR} -I${FDDIR} -DLOGDIR=\"$(DESTDIR)$(working_dir)\" -c $< diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp index 7cfd27e59..311b36378 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp +++ b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp @@ -2323,6 +2323,9 @@ bRC METAPLUGIN::startBackupFile(bpContext *ctx, struct save_pkt *sp) reqparams--; } continue; + case metaplugin::attributes::Status_Handled: + reqparams--; + continue; default: break; } diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin_attributes.cpp b/bacula/src/plugins/fd/pluginlib/metaplugin_attributes.cpp index 1b377f57b..4029614f8 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin_attributes.cpp +++ b/bacula/src/plugins/fd/pluginlib/metaplugin_attributes.cpp @@ -50,6 +50,38 @@ namespace attributes int nlinks; DMSG0(ctx, DDEBUG, "read_scan_stat_command()\n"); + + if (strncmp(cmd.c_str(), "STAT:/", 6) == 0) + { + DMSG0(ctx, DDEBUG, "read_scan_stat_command():new stat(2)\n"); + POOL_MEM param(PM_FNAME); + // handle stat(2) for this file + scan_parameter_str(cmd, "STAT:", param); + int rc = stat(param.c_str(), &sp->statp); + if (rc < 0) + { + // error + DMSG1(ctx, DERROR, "Invalid path: %s\n", param.c_str()); + return Invalid_Stat_Packet; + } + // stat is working as expected + DMSG1(ctx, DDEBUG, "read_scan_stat_command():stat: %o\n", sp->statp.st_mode & S_IFMT); + switch (sp->statp.st_mode & S_IFMT) + { + case S_IFDIR: + sp->type = FT_DIREND; + sp->link = sp->fname; + break; + case S_IFREG: + sp->type = FT_REG; + break; + default: + DMSG1(ctx, DERROR, "Unsupported file type: %o\n", sp->statp.st_mode & S_IFMT); + return Invalid_Stat_Packet; + } + return Status_Handled; + } + int32_t nfi = -1; int nrscan = sscanf(cmd.c_str(), "STAT:%c %ld %d %d %o %d %d", &type, &size, &uid, &gid, &perms, &nlinks, &nfi); diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin_attributes.h b/bacula/src/plugins/fd/pluginlib/metaplugin_attributes.h index 8598c9e6a..2fd187259 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin_attributes.h +++ b/bacula/src/plugins/fd/pluginlib/metaplugin_attributes.h @@ -41,6 +41,7 @@ namespace attributes Status_OK, Invalid_Stat_Packet, Invalid_File_Type, + Status_Handled, Not_Command, } Status; diff --git a/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c b/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c index dd53f6501..386192f03 100644 --- a/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c +++ b/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c @@ -150,11 +150,11 @@ int read_plugin(char * buf) while (len < size) { int32_t nbytes = 0; int rc = ioctl(STDIN_FILENO, FIONREAD, &nbytes); - snprintf(buflog, BUFLEN, ">> FIONREAD:%d:%ld", rc, nbytes); + snprintf(buflog, BUFLEN, ">> FIONREAD:%d:%ld", rc, (long int)nbytes); LOG(buflog); - if (nbytes < size){ + if (size > (size_t)nbytes){ rc = ioctl(STDIN_FILENO, FIONREAD, &nbytes); - snprintf(buflog, BUFLEN, ">> Second FIONREAD:%d:%ld", rc, nbytes); + snprintf(buflog, BUFLEN, ">> Second FIONREAD:%d:%ld", rc, (long int)nbytes); LOG(buflog); } size_t bufread = size - len > BIGBUFLEN ? BIGBUFLEN : size - len; @@ -1106,6 +1106,22 @@ void perform_backup() signal_eod(); signal_eod(); + // the file with external stat(2) packet + snprintf(buf, BIGBUFLEN, "FNAME:%s/java/%d/stat.file\n", PLUGINPREFIX, mypid); + write_plugin('C', buf); + write_plugin('C', "STAT:/etc/passwd\n"); + write_plugin('I', "TEST18"); + signal_eod(); + // here comes a file data contents + write_plugin('C', "DATA\n"); + write_plugin('D', "/* here comes a file data contents */"); + write_plugin('D', "/* here comes another file line */"); + write_plugin('D', "/* here comes another file line */"); + write_plugin('D', "/* here comes another file line */"); + write_plugin('D', "/* here comes another file line */"); + signal_eod(); + write_plugin('I', "TEST18Data"); + // this plugin object should be the latest item to backup if (regress_backup_plugin_objects) {