From ec0ae7b69397ec9bcd2aa384cf8b68f3c50a3f1c Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Thu, 29 Nov 2018 13:30:36 +0100 Subject: [PATCH] Fix verify volume jobs with sparse files 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 | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/bacula/src/filed/verify.c b/bacula/src/filed/verify.c index 427f711ea..368984a55 100644 --- a/bacula/src/filed/verify.c +++ b/bacula/src/filed/verify.c @@ -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); -- 2.47.3