]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add device function to compute the file_size depending on the device driver
authorEric Bollengier <eric@baculasystems.com>
Wed, 17 Aug 2022 07:50:29 +0000 (09:50 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:58 +0000 (13:56 +0200)
bacula/src/stored/block.c
bacula/src/stored/dev.c
bacula/src/stored/dev.h

index 01efd75a43e6ec2a7729a1d7406459ecdeaf7109..0f8fa2cbc0297ceda4678fffc75484eb27eff651 100644 (file)
@@ -235,9 +235,9 @@ bool DCR::write_block_to_dev()
          dev->clrerror(-1);
       }
       stat = dev->write(block->buf, (size_t)wlen);
-      Dmsg4(100, "%s write() BlockAddr=%lld wlen=%d Vol=%s wlen=%d\n",
-         block->adata?"Adata":"Ameta", block->BlockAddr, wlen,
-         dev->VolHdr.VolumeName);
+      Dmsg4(100, "%s write() BlockAddr=%lld wlen=%d Vol=%s\n",
+            block->adata?"Adata":"Ameta",
+            block->BlockAddr, wlen, dev->VolHdr.VolumeName);
    } while (stat == -1 && (errno == EBUSY || errno == EIO) && retry++ < 3);
 
    /* ***FIXME*** remove 2 lines debug */
@@ -392,7 +392,7 @@ bool DCR::write_block_to_dev()
    }
 
    dev->file_addr += wlen;            /* update file address */
-   dev->file_size += wlen;
+   dev->update_file_size(wlen);
    dev->usage += wlen;                /* update usage counter */
    if (dev->part > 0) {
       dev->part_size += wlen;
@@ -629,7 +629,7 @@ reread:
          if (forge_on) {
             /* Skip the current byte to find a valid block */
             dev->file_addr += 1;
-            dev->file_size += 1;
+            dev->update_file_size(1);
             /* Can be canceled at this point... */
             if (jcr->is_canceled()) {
                jcr->forceJobStatus(status);
@@ -724,7 +724,7 @@ reread:
       dcr->VolMediaId = dev->VolCatInfo.VolMediaId;
    }
    dev->file_addr += block->read_len;
-   dev->file_size += block->read_len;
+   dev->update_file_size(block->read_len);
    dev->usage     += block->read_len;      /* update usage counter */
 
    /*
@@ -751,7 +751,7 @@ reread:
          edit_int64(pos, ed1), block->block_len,
             block->read_len);
       dev->file_addr = pos;
-      dev->file_size = pos;
+      dev->set_file_size(pos);
    }
    Dmsg3(150, "Exit read_block read_len=%d block_len=%d binbuf=%d\n",
       block->read_len, block->block_len, block->binbuf);
index 973a115634459a7c385a029515e3cdcba22d6d2a..5d1992ee2752366a30cf7af6f514776902c65000 100644 (file)
@@ -179,7 +179,7 @@ void DEVICE::set_ateof()
 {
    set_eof();
    file_addr = 0;
-   file_size = 0;
+   set_file_size(0);
    block_num = 0;
 }
 
@@ -356,7 +356,7 @@ bool DEVICE::close(DCR *dcr)
               ST_NOSPACE|ST_MOUNTED|ST_MEDIA|ST_SHORT);
    label_type = B_BACULA_LABEL;
    file = block_num = 0;
-   file_size = 0;
+   set_file_size(0);
    file_addr = 0;
    EndFile = EndBlock = 0;
    openmode = 0;
@@ -941,7 +941,7 @@ bool DEVICE::weof(DCR */*dcr*/, int num)
       return false;
    }
 
-   file_size = 0;
+   set_file_size(0);
    return true;
 }
 
@@ -968,7 +968,7 @@ bool DEVICE::eod(DCR *dcr)
    }
    clear_eof();         /* remove EOF flag */
    block_num = file = 0;
-   file_size = 0;
+   set_file_size(0);
    file_addr = 0;
    Leave(100);
    return ok;
@@ -1056,7 +1056,6 @@ char *DEVICE::print_addr(char *buf, int32_t buf_len, boffset_t addr)
 bool DEVICE::do_size_checks(DCR *dcr, DEV_BLOCK *block)
 {
    JCR *jcr = dcr->jcr;
-
    if (is_pool_size_reached(dcr, true)) {
       if (!dir_get_pool_info(dcr, &VolCatInfo)) {
          Dmsg0(50, "Error updating volume info.\n");
@@ -1081,7 +1080,7 @@ bool DEVICE::do_size_checks(DCR *dcr, DEV_BLOCK *block)
     */
    if ((max_file_size > 0) &&
        (file_size+block->binbuf) >= max_file_size) {
-      file_size = 0;             /* reset file size */
+      set_file_size(0);             /* reset file size */
 
       if (!weof(dcr, 1)) {            /* write eof */
          Dmsg0(50, "WEOF error in max file size.\n");
index fa0a29c0574f416f6a140b5a87a29b6bd7c2856f..ed45758a309590308d745071a5fcf8084638a2c0 100644 (file)
@@ -527,6 +527,8 @@ public:
 
 
    /* Virtual functions that can be overridden */
+   virtual void set_file_size(uint64_t val) { file_size = val;};
+   virtual uint64_t update_file_size(uint64_t add) { file_size += add; return file_size; };
    virtual void setVolCatName(const char *name);
    virtual void setVolCatStatus(const char *status);
    virtual void free_dcr_blocks(DCR *dcr);        /* in block_util.c */