]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix org#2567 Device don't always get the right "capabilities"
authorAlain Spineux <alain@baculasystems.com>
Tue, 1 Dec 2020 12:59:21 +0000 (13:59 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:02:57 +0000 (09:02 +0100)
- "capabilities" was sometime adjusted in the constructor or in the factory
  function, but device_generic_init() that is called later by init_dev()
  initialize most of the device fields including "capabilities"
- move the tweak of the "capabilities" in device_specific_init()
  that is called after device_generic_init()
- update the device_generic_init() method of all concerned classes
- doing only a return file_dev::device_specific_init(); in child class is
  useless (not overwriting the method would be ok) but I want to be
  sure that nobody will forget to do it if device_specific_init() is
  modified
- testing can be done by searching for "Ready to append to end of Volume"
  in job log of "tests/restart-job-test"

bacula/src/stored/cloud_dev.c
bacula/src/stored/cloud_dev.h
bacula/src/stored/fifo_dev.c
bacula/src/stored/fifo_dev.h
bacula/src/stored/file_dev.c
bacula/src/stored/file_dev.h
bacula/src/stored/init_dev.c
bacula/src/stored/win_file_dev.h

index 465c6e8e48ac78f112ca4eacc69f25d1bec32089..c5ca1e47ec6219f602db5ebca382a012b8aa375e 100644 (file)
@@ -81,7 +81,6 @@ DEVICE *BaculaSDdriver(JCR *jcr, DEVRES *device)
       return NULL;
    }
    dev = New(cloud_dev(jcr, device));
-   dev->capabilities |= CAP_LSEEK;
    return dev;
 }
 
@@ -927,7 +926,6 @@ cloud_dev::cloud_dev(JCR *jcr, DEVRES *device)
    Enter(dbglvl);
    m_fd = -1;
    *full_type = 0;
-   capabilities |= CAP_LSEEK;
 
    /* Initialize Cloud driver */
    if (!driver) {
@@ -1051,6 +1049,12 @@ cloud_dev::cloud_dev(JCR *jcr, DEVRES *device)
    cloud_prox = cloud_proxy::get_instance();
 }
 
+int cloud_dev::device_specific_init(JCR *jcr, DEVRES *device)
+{
+   // Don't forget to do capabilities |= CAP_LSEEK in device_specific_init()
+   return file_dev::device_specific_init(jcr, device);
+}
+
 /*
  * DEVICE virtuals that we redefine.
  */
@@ -2783,3 +2787,4 @@ bail_out:
    Leave(dbglvl);
    return ret;
 }
+
index f64e87ab30d602f4943623555815003d6e1447b9..04bd30488217ec25e1da4e91dcb602b04f7762ce 100644 (file)
@@ -128,6 +128,7 @@ public:
    void get_api_cloud_upload_transfer_status(OutputWriter &ow, bool verbose);
    uint32_t get_cloud_download_transfer_status(POOL_MEM &msg, bool verbose);
    void get_api_cloud_download_transfer_status(OutputWriter &ow, bool verbose);
+   virtual int device_specific_init(JCR *jcr, DEVRES *device);
 };
 
 /* Exported subroutines */
index 15d667aac7d7b3d8a92e38b02911884054a67141..d08a40b4b290904fc83bcdb93da6ea86b9f0d5cb 100644 (file)
@@ -50,3 +50,9 @@ const char *fifo_dev::print_type()
    return "FIFO";
 }
 
+int fifo_dev::device_specific_init(JCR *jcr, DEVRES *device)
+{
+   capabilities |= CAP_STREAM;
+   return 0;
+}
+
index dc69866e991ea30004868f789e033593c20a945a..e2ac59e9157874f4f8fba77b0d5ec6d7b627b9b8 100644 (file)
@@ -34,6 +34,7 @@ public:
    boffset_t lseek(DCR *dcr, boffset_t offset, int whence);
    bool truncate(DCR *dcr);
    const char *print_type();
+   virtual int device_specific_init(JCR *jcr, DEVRES *device);
 };
 
 #endif /* __FIFO_DEV_ */
index 9fbcbe45dd4a557b3586227ea3325b1d04d55ec0..6ef8dd3f7d48a77cb86fd7b4074e8f9fec9830c1 100644 (file)
@@ -539,3 +539,10 @@ const char *file_dev::print_type()
 {
    return "File";
 }
+
+int file_dev::device_specific_init(JCR *jcr, DEVRES *device)
+{
+   // Called by child to get the CAP_LSEEK
+   capabilities |= CAP_LSEEK;
+   return 0;
+}
index 9bbdc8692817422b4f092c27d6c997cb4557a4c5..caf8b4c0cdb186498491d4527df634eb891d0091 100644 (file)
@@ -32,6 +32,7 @@ public:
    bool eod(DCR *dcr);
    bool open_device(DCR *dcr, int omode);
    const char *print_type();
+   virtual int device_specific_init(JCR *jcr, DEVRES *device);
 };
 
 #endif /* __FILE_DEV_ */
index 34c14c1e7c97ffa5ba6bb3c8443f4e4b4d97ad39..c9fb277f1184422d7958250a182ed532f870b467 100644 (file)
@@ -199,7 +199,6 @@ DEVICE *init_dev(JCR *jcr, DEVRES *device, bool adata, bstatcollect *statcollect
       case B_ALIGNED_DEV:
       case B_FILE_DEV:
          dev = New(win_file_dev);
-         dev->capabilities |= CAP_LSEEK;
          break;
       case B_NULL_DEV:
          dev = New(win_file_dev);
@@ -213,7 +212,6 @@ DEVICE *init_dev(JCR *jcr, DEVRES *device, bool adata, bstatcollect *statcollect
          break;
       case B_FILE_DEV:
          dev = New(file_dev);
-         dev->capabilities |= CAP_LSEEK;
          break;
       case B_NULL_DEV:
          dev = New(null_dev);
@@ -249,11 +247,6 @@ DEVICE *init_dev(JCR *jcr, DEVRES *device, bool adata, bstatcollect *statcollect
       goto bailout;
    }
 
-   /* ***FIXME*** move to fifo driver */
-   if (dev->is_fifo()) {
-      dev->capabilities |= CAP_STREAM; /* set stream device */
-   }
-
    dev->register_metrics(statcollector);
 
    if (!cloning) {
index b43405469d91794ea37c1b8e288bcf2d013b9bd8..86c53d13ce6681a95c6f4327638a26e37b4c611e 100644 (file)
@@ -27,5 +27,9 @@ public:
 
    win_file_dev() { };
    ~win_file_dev() { m_fd = -1; };
+   virtual int device_specific_init(JCR *jcr, DEVRES *device) {
+      // Don't forget to do capabilities |= CAP_LSEEK in device_specific_init()
+      return file_dev::device_specific_init(jcr, device);
+   }
 };
 #endif