]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
metaplugin: Add new STAT command flavour.
authorRadosław Korzeniewski <radoslaw@korzeniewski.net>
Mon, 4 Oct 2021 08:02:16 +0000 (10:02 +0200)
committerEric Bollengier <eric@baculasystems.com>
Wed, 6 Sep 2023 07:49:00 +0000 (09:49 +0200)
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.

bacula/src/plugins/fd/pluginlib/Makefile
bacula/src/plugins/fd/pluginlib/metaplugin.cpp
bacula/src/plugins/fd/pluginlib/metaplugin_attributes.cpp
bacula/src/plugins/fd/pluginlib/metaplugin_attributes.h
bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c

index a6a13ddb523378283b15672d3a7fb83a99e1ef36..ad5f36c90a0a8acdb1c3c791055661d858fe5332 100644 (file)
@@ -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 $<
index 7cfd27e5940b51e33a57cead3fd118cbf1281104..311b36378541ceab6e2ed59620161b7c838985e2 100644 (file)
@@ -2323,6 +2323,9 @@ bRC METAPLUGIN::startBackupFile(bpContext *ctx, struct save_pkt *sp)
                reqparams--;
             }
             continue;
+         case metaplugin::attributes::Status_Handled:
+            reqparams--;
+            continue;
          default:
             break;
          }
index 1b377f57b5fbf6e0a6a5b6e79bd00c18a0c291eb..4029614f8197732d32b58955e967f51124dfe603 100644 (file)
@@ -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);
index 8598c9e6a99d9fac5261cbf7a869196968cf3097..2fd1872590d280aa2bdacee60ba3ae625793d182 100644 (file)
@@ -41,6 +41,7 @@ namespace attributes
       Status_OK,
       Invalid_Stat_Packet,
       Invalid_File_Type,
+      Status_Handled,
       Not_Command,
    } Status;
 
index dd53f6501282e8f0b80f93cc1220d87eaf4a8280..386192f03ad956c2b35813d53a538a625b9d9bc8 100644 (file)
@@ -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)
    {