From db643f72b162ea1a20fda4be7b89459aab302f0d Mon Sep 17 00:00:00 2001 From: Alain Spineux Date: Tue, 1 Dec 2020 13:59:21 +0100 Subject: [PATCH] Fix org#2567 Device don't always get the right "capabilities" - "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 | 9 +++++++-- bacula/src/stored/cloud_dev.h | 1 + bacula/src/stored/fifo_dev.c | 6 ++++++ bacula/src/stored/fifo_dev.h | 1 + bacula/src/stored/file_dev.c | 7 +++++++ bacula/src/stored/file_dev.h | 1 + bacula/src/stored/init_dev.c | 7 ------- bacula/src/stored/win_file_dev.h | 4 ++++ 8 files changed, 27 insertions(+), 9 deletions(-) diff --git a/bacula/src/stored/cloud_dev.c b/bacula/src/stored/cloud_dev.c index eb79c06a8..45669a5c4 100644 --- a/bacula/src/stored/cloud_dev.c +++ b/bacula/src/stored/cloud_dev.c @@ -83,7 +83,6 @@ DEVICE *BaculaSDdriver(JCR *jcr, DEVRES *device) return NULL; } dev = New(cloud_dev(jcr, device)); - dev->capabilities |= CAP_LSEEK; return dev; } @@ -917,7 +916,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) { @@ -1041,6 +1039,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. */ @@ -2773,3 +2777,4 @@ bail_out: Leave(dbglvl); return ret; } + diff --git a/bacula/src/stored/cloud_dev.h b/bacula/src/stored/cloud_dev.h index f64e87ab3..04bd30488 100644 --- a/bacula/src/stored/cloud_dev.h +++ b/bacula/src/stored/cloud_dev.h @@ -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 */ diff --git a/bacula/src/stored/fifo_dev.c b/bacula/src/stored/fifo_dev.c index 15d667aac..d08a40b4b 100644 --- a/bacula/src/stored/fifo_dev.c +++ b/bacula/src/stored/fifo_dev.c @@ -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; +} + diff --git a/bacula/src/stored/fifo_dev.h b/bacula/src/stored/fifo_dev.h index dc69866e9..e2ac59e91 100644 --- a/bacula/src/stored/fifo_dev.h +++ b/bacula/src/stored/fifo_dev.h @@ -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_ */ diff --git a/bacula/src/stored/file_dev.c b/bacula/src/stored/file_dev.c index 9fbcbe45d..6ef8dd3f7 100644 --- a/bacula/src/stored/file_dev.c +++ b/bacula/src/stored/file_dev.c @@ -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; +} diff --git a/bacula/src/stored/file_dev.h b/bacula/src/stored/file_dev.h index 9bbdc8692..caf8b4c0c 100644 --- a/bacula/src/stored/file_dev.h +++ b/bacula/src/stored/file_dev.h @@ -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_ */ diff --git a/bacula/src/stored/init_dev.c b/bacula/src/stored/init_dev.c index 704978fcf..5d0c8934d 100644 --- a/bacula/src/stored/init_dev.c +++ b/bacula/src/stored/init_dev.c @@ -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) { diff --git a/bacula/src/stored/win_file_dev.h b/bacula/src/stored/win_file_dev.h index b43405469..86c53d13c 100644 --- a/bacula/src/stored/win_file_dev.h +++ b/bacula/src/stored/win_file_dev.h @@ -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 -- 2.47.3