]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
metaplugin: Update regression to check large RestoreObject.
authorRadosław Korzeniewski <radoslaw@korzeniewski.net>
Tue, 20 Jul 2021 14:15:43 +0000 (16:15 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:03 +0000 (09:03 +0100)
bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c
regress/scripts/metaplugin-protocol-tests.sh

index 65a532b42fea80873483f65ce9dd77874a089b3f..9fd4b2402de7ce39584a059346322ed4f5e50762 100644 (file)
@@ -35,6 +35,7 @@
 #include <string.h>
 #include <errno.h>
 #include <signal.h>
+#include <sys/ioctl.h>
 
 
 #ifndef LOGDIR
@@ -74,7 +75,7 @@ bool regress_cancel_restore = false;
 
 
 #define BUFLEN             4096
-#define BIGBUFLEN          65536
+#define BIGBUFLEN          131072
 
 /**
  * @brief saves the log text to logfile
@@ -110,9 +111,9 @@ void LOG(const char *txt)
  */
 int read_plugin(char * buf)
 {
-   int len;
-   int nread;
-   int size;
+   size_t len;
+   size_t nread;
+   size_t size;
    char header[8];
 
    len = read(STDIN_FILENO, &header, 8);
@@ -130,26 +131,36 @@ int read_plugin(char * buf)
       close(logfd);
       exit(EXIT_SUCCESS);
    }
-   size = atoi(header+1);
-   if (size > BIGBUFLEN){
-      LOG("#> Err: message too long");
-      close(logfd);
-      exit(EXIT_BACKEND_MESSAGE_TOOLONG);
-   }
+   size = atoi(header + 1);
 
    if (header[0] == 'C'){
+      if (size > BIGBUFLEN){
+         LOG("#> Err: message too long");
+         close(logfd);
+         exit(EXIT_BACKEND_MESSAGE_TOOLONG);
+      }
       len = read(STDIN_FILENO, buf, size);
       buf[len] = 0;
       snprintf(buflog, BUFLEN, "> %s", buf);
       LOG(buflog);
    } else {
-      snprintf(buflog, BUFLEN, "> Data:%i", size);
+      snprintf(buflog, BUFLEN, "> Data:%lu", size);
       LOG(buflog);
       len = 0;
-      while (len < size){
-         nread = read(STDIN_FILENO, buf, size - len);
+      while (len < size) {
+         int nbytes;
+         ioctl(STDIN_FILENO, FIONREAD, &nbytes);
+         snprintf(buflog, BUFLEN, ">> FIONREAD:%i", nbytes);
+         LOG(buflog);
+         if (nbytes < size){
+            ioctl(STDIN_FILENO, FIONREAD, &nbytes);
+            snprintf(buflog, BUFLEN, ">> Second FIONREAD:%i", nbytes);
+            LOG(buflog);
+         }
+         size_t bufread = size - len > BIGBUFLEN ? BIGBUFLEN : size - len;
+         nread = read(STDIN_FILENO, buf, bufread);
          len += nread;
-         snprintf(buflog, BUFLEN, "> Dataread:%i", nread);
+         snprintf(buflog, BUFLEN, ">> Dataread:%lu", nread);
          LOG(buflog);
       }
    }
@@ -740,6 +751,19 @@ void perform_backup()
       write_plugin('D', r_data);
       signal_eod();
 
+      // long restore object
+      snprintf(buf, BIGBUFLEN, "RESTOREOBJ:LongObject%d\n", mypid);
+      write_plugin('C', buf);
+      const size_t longobject_num = 6;
+      snprintf(buf, BIGBUFLEN, "RESTOREOBJ_LEN:%lu\n", BIGBUFLEN * longobject_num);
+      write_plugin('C', buf);
+      memset(buf, 'A', BIGBUFLEN);
+      for (size_t a = 0; a < longobject_num; a++)
+      {
+         write_plugin_bin((unsigned char*)buf, BIGBUFLEN);
+      }
+      signal_eod();
+
       // next file
       snprintf(buf, BIGBUFLEN, "FNAME:%s/bucket/%d/vm222-other-file.iso\n", PLUGINPREFIX, mypid);
       write_plugin('C', buf);
@@ -1434,6 +1458,10 @@ int main(int argc, char** argv) {
    }
    //sleep(30);
 
+   int pipesize = fcntl(STDIN_FILENO, F_GETPIPE_SZ);
+   snprintf(buflog, BUFLEN, "#> F_GETPIPE_SZ:%i", pipesize);
+   LOG(buflog);
+
    /* handshake (1) */
    len = read_plugin(buf);
 #if 1
index 30f775d03c843d7bf099540faef608c29b13019f..ecaa4b8c5c83faa87fc1a3342e05476b758fe98c 100755 (executable)
@@ -560,7 +560,7 @@ fi
 RET=$(grep "jobstatus:" ${cwd}/tmp/rlog6.out | tail -1 | awk '{print $2}')
 REND=$(grep -w -c "TESTEND" ${cwd}/tmp/rlog6.out)
 RRO=$(grep -c "TEST6R" ${cwd}/tmp/rlog6.out)
-if [ "x$RET" != "xT" ] || [ "$REND" -ne 2 ] || [ "$RRO" -ne 2 ]
+if [ "x$RET" != "xT" ] || [ "$REND" -ne 2 ] || [ "$RRO" -ne 3 ]
 then
    echo "rlog6" "$RET" "$REND" "$RRO"
    rstat=6