]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix verify volume jobs with sparse files
authorEric Bollengier <eric@baculasystems.com>
Thu, 29 Nov 2018 12:30:36 +0000 (13:30 +0100)
committerKern Sibbald <kern@sibbald.com>
Mon, 8 Apr 2019 16:16:52 +0000 (18:16 +0200)
The verify read() loop was not reading the data like the backup loop was
doing. So the sparse block detection was miss-aligned giving false errors.

We now use the configuration NetworkBufferSize to adjust the amount of data we
read in a loop. I'm not sure it's 100% accurate for dedup jobs.

bacula/src/filed/verify.c

index 427f711ea7e26417427f1cf4a9eba3d786733c16..368984a55fb6a314b8ab29043e295916c058f0ff 100644 (file)
@@ -37,7 +37,17 @@ static int read_digest(BFILE *bfd, DIGEST *digest, JCR *jcr);
 void do_verify(JCR *jcr)
 {
    jcr->setJobStatus(JS_Running);
-   jcr->buf_size = DEFAULT_NETWORK_BUFFER_SIZE;
+
+   LockRes();
+   CLIENT *client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
+   UnlockRes();
+
+   if (client) {
+      jcr->buf_size = client->max_network_buffer_size ?
+         client->max_network_buffer_size : DEFAULT_NETWORK_BUFFER_SIZE;
+   } else {
+      jcr->buf_size = DEFAULT_NETWORK_BUFFER_SIZE; /* use default */
+   }
    if ((jcr->big_buf = (char *) malloc(jcr->buf_size)) == NULL) {
       Jmsg1(jcr, M_ABORT, 0, _("Cannot malloc %d network read buffer\n"),
          DEFAULT_NETWORK_BUFFER_SIZE);
@@ -327,14 +337,20 @@ int digest_file(JCR *jcr, FF_PKT *ff_pkt, DIGEST *digest)
  */
 static int read_digest(BFILE *bfd, DIGEST *digest, JCR *jcr)
 {
-   char buf[DEFAULT_NETWORK_BUFFER_SIZE];
+   char  *buf;
    int64_t n;
-   int64_t bufsiz = (int64_t)sizeof(buf);
+   int64_t bufsiz = jcr->buf_size;
    FF_PKT *ff_pkt = (FF_PKT *)jcr->ff;
    uint64_t fileAddr = 0;             /* file address */
 
-
+   buf = (char *)malloc(bufsiz);
    Dmsg0(50, "=== read_digest\n");
+   /* With this option, we read shorter blocks, so to not break the
+    * sparse block detection, we need to adjust the read size.
+    */
+   if (ff_pkt->flags & FO_SPARSE) {
+      bufsiz -= OFFSET_FADDR_SIZE;
+   }
    while ((n=bread(bfd, buf, bufsiz)) > 0) {
       /* Check for sparse blocks */
       if (ff_pkt->flags & FO_SPARSE) {
@@ -362,6 +378,7 @@ static int read_digest(BFILE *bfd, DIGEST *digest, JCR *jcr)
       }
       jcr->ReadBytes += n;
    }
+   free(buf);
    if (n < 0) {
       berrno be;
       be.set_errno(bfd->berrno);