]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/stored/dev.c
authorEric Bollengier <eric@baculasystems.com>
Tue, 12 May 2020 16:47:51 +0000 (18:47 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 29 Apr 2021 08:44:18 +0000 (10:44 +0200)
This commit is the result of the squash of the following main commits:

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Fri Jan 25 17:58:55 2019 +0100

    Add device device_specific_close() function to fix open_device() code

Author: Alain Spineux <alain@baculasystems.com>
Date:   Tue Oct 10 14:07:58 2017 +0200

    BIG backport of the devices from Community 9.0

Author: Kern Sibbald <kern@sibbald.com>
Date:   Fri Jun 17 18:31:23 2016 +0200

    First cut cloud + aligned loadable drivers

Author: Kern Sibbald <kern@sibbald.com>
Date:   Fri Jun 8 17:51:54 2012 +0200

    Rewrite some SD subroutines as class members

Author: Kern Sibbald <kern@sibbald.com>
Date:   Wed Feb 8 18:56:00 2012 +0100

    Clear slot on free only for SAN shared storage

bacula/src/stored/dev.c

index fcb34f655aea6c1db7c0ea40e99a14caffa993cc..e423906e1c605d3430a3094881ffebcc317cf31d 100644 (file)
@@ -85,11 +85,25 @@ extern uint32_t status_dev(DEVICE *dev);
 const char *mode_to_str(int mode);
 DEVICE *m_init_dev(JCR *jcr, DEVRES *device, bool adata);
 
+/* To open device readonly when appropriate, like for bls for dedup devices */
+int device_default_open_mode = omd_rdonly;
+
 /*
  * Device specific initialization.
  */
-void DEVICE::device_specific_init(JCR *jcr, DEVRES *device)
+int DEVICE::device_specific_init(JCR *jcr, DEVRES *device)
 {
+   return 0; // OK
+}
+
+int DEVICE::device_specific_close(DCR *dcr)
+{
+   int ret = 0;
+   if (m_fd >= 0) {
+      ret = d_close(m_fd) ;
+      clear_opened();
+   }
+   return ret;
 }
 
 /*
@@ -118,8 +132,7 @@ bool DEVICE::open_device(DCR *dcr, int omode)
          return true;
       } else {
          Dmsg1(200, "Close fd=%d for mode change in open().\n", m_fd);
-         d_close(m_fd);
-         clear_opened();
+         device_specific_close(dcr);
          preserve = state & (ST_LABEL|ST_APPEND|ST_READ);
       }
    }
@@ -329,6 +342,16 @@ bool DEVICE::close(DCR *dcr)
    /* Clean up device packet so it can be reused */
    clear_opened();
 
+   /*
+    * Only when SAN shared storage configured,
+    *   when the device is unloaded, the slot information
+    *   can be incorrect, so clear the slot.
+    */
+   /* ***BEEF ***/
+   if (is_tape() && device->lock_command && device->control_name) {
+      clear_slot();
+   }
+
    state &= ~(ST_LABEL|ST_READ|ST_APPEND|ST_EOT|ST_WEOT|ST_EOF|
               ST_NOSPACE|ST_MOUNTED|ST_MEDIA|ST_SHORT);
    label_type = B_BACULA_LABEL;
@@ -706,10 +729,23 @@ void DEVICE::updateVolCatBytes(uint64_t bytes)
    Lock_VolCatInfo();
    VolCatInfo.VolCatAmetaBytes += bytes;
    VolCatInfo.VolCatBytes += bytes;
+   VolCatInfo.BytesWritten += bytes; /* We keep the count of written bytes since the last catalog update */
    setVolCatInfo(false);
    Unlock_VolCatInfo();
 }
 
+/* Used by subclass like dedup to take account of bytes going into dedup.
+ * The accounting is expected to be done in VolCatAdataBytes & VolCatBytes
+ */
+void DEVICE::updateVolCatExtraBytes(uint64_t bytes)
+{
+}
+
+/*
+ * Note, for us a hole is bytes skipped. The OS
+ *  may have a different idea of a hole due to
+ *  the filesystem block size.
+ */
 void DEVICE::updateVolCatHoleBytes(uint64_t hole)
 {
    return;
@@ -1035,8 +1071,14 @@ 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");
+      }
+   }
+
    if (is_user_volume_size_reached(dcr, true)) {
-      Dmsg0(40, "Calling terminate_writing_volume\n");
+      Dmsg0(50, "Calling terminate_writing_volume\n");
       terminate_writing_volume(dcr);
       reread_last_block(dcr);   /* Only used on tapes */
       dev_errno = ENOSPC;
@@ -1137,7 +1179,6 @@ void DEVICE::register_metrics(bstatcollect *collector)
          devstatcollector->registration(met.c_str(), METRIC_INT, METRIC_UNIT_BYTE,
             (char*)"The size of the disk storage for device (could be shared).");
 };
-
 bool DEVICE::get_tape_worm(DCR *dcr)
 {
    return false;