From 0a346707d3feb60d6beb8c547a641eb8c5c53911 Mon Sep 17 00:00:00 2001 From: Andreas Rogge Date: Mon, 10 Oct 2022 14:32:27 +0200 Subject: [PATCH] stored: remove BackendInterface layer Instead of returning a factory that will then provide Device*, we can return the Device* from the PluginRegistry's factory directly. This removes the BackendInterface layer that wrapped the factory again. --- core/src/stored/dev.cc | 10 ++-------- core/src/stored/sd_backends.h | 26 +++++--------------------- core/src/stored/sd_backends_dynamic.cc | 2 +- core/src/stored/stored_conf.cc | 5 +---- 4 files changed, 9 insertions(+), 34 deletions(-) diff --git a/core/src/stored/dev.cc b/core/src/stored/dev.cc index 285396764b6..bfae1a23c46 100644 --- a/core/src/stored/dev.cc +++ b/core/src/stored/dev.cc @@ -122,20 +122,14 @@ Device* FactoryCreateDevice(JobControlRecord* jcr, Dmsg1(400, "max_block_size in device_resource res is %u\n", device_resource->max_block_size); - if (!PluginRegistry::IsRegistered( - device_resource->dev_type)) { + if (!PluginRegistry::IsRegistered(device_resource->dev_type)) { Jmsg2(jcr, M_ERROR, 0, _("%s has an unknown device type %s\n"), device_resource->archive_device_string, device_resource->dev_type.c_str()); return nullptr; } - // FIXME: the PluginRegistry should return the device instead of the factory - // so we save one call and a delete. - auto factory - = PluginRegistry::Create(device_resource->dev_type); - Device* dev = factory->GetDevice(); - delete factory; + Device* dev = PluginRegistry::Create(device_resource->dev_type); dev->device_resource = device_resource; device_resource->dev = dev; diff --git a/core/src/stored/sd_backends.h b/core/src/stored/sd_backends.h index 71b8c7108e0..f137137bf23 100644 --- a/core/src/stored/sd_backends.h +++ b/core/src/stored/sd_backends.h @@ -1,8 +1,7 @@ /* BAREOSĀ® - Backup Archiving REcovery Open Sourced - Copyright (C) 2014-2014 Planets Communications B.V. - Copyright (C) 2014-2022 Bareos GmbH & Co. KG + Copyright (C) 2022-2022 Bareos GmbH & Co. KG This program is Free Software; you can redistribute it and/or modify it under the terms of version three of the GNU Affero General Public @@ -19,11 +18,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -// Marco van Wieringen, June 2014 -/** - * @file - * Dynamic loading of SD backend plugins. - */ #ifndef BAREOS_STORED_SD_BACKENDS_H_ #define BAREOS_STORED_SD_BACKENDS_H_ @@ -32,18 +26,8 @@ namespace storagedaemon { -class BackendInterface { - public: - virtual ~BackendInterface() = default; - virtual Device* GetDevice() = 0; -}; - -template class Backend : public BackendInterface { - public: - Device* GetDevice(void) override { return new T(); } -}; - -template BackendInterface* BackendFactory(void) { return new T(); } +class Device; +template Device* DeviceFactory(void) { return new T(); } #if defined(HAVE_DYNAMIC_SD_BACKENDS) bool LoadStorageBackend(const std::string& dev_type, @@ -52,8 +36,8 @@ bool LoadStorageBackend(const std::string& dev_type, #define REGISTER_SD_BACKEND(backend_name, backend_class) \ [[maybe_unused]] static bool backend_name##_backend_ \ - = PluginRegistry::Add( \ - #backend_name, BackendFactory>); + = PluginRegistry::Add(#backend_name, \ + DeviceFactory); } // namespace storagedaemon diff --git a/core/src/stored/sd_backends_dynamic.cc b/core/src/stored/sd_backends_dynamic.cc index 4917f08b9aa..e73a0028c36 100644 --- a/core/src/stored/sd_backends_dynamic.cc +++ b/core/src/stored/sd_backends_dynamic.cc @@ -65,7 +65,7 @@ bool LoadStorageBackend(const std::string& dev_type, return false; } - if (!PluginRegistry::IsRegistered(dev_type)) { + if (!PluginRegistry::IsRegistered(dev_type)) { Jmsg(nullptr, M_ERROR_TERM, 0, "Loaded backend library for %s did not register its backend. This is " "probably a bug in the backend library.\n", diff --git a/core/src/stored/stored_conf.cc b/core/src/stored/stored_conf.cc index 990f251012a..8e6640e2a13 100644 --- a/core/src/stored/stored_conf.cc +++ b/core/src/stored/stored_conf.cc @@ -547,20 +547,17 @@ static void GuessMissingDeviceTypes(ConfigurationParser& my_config) static void CheckAndLoadDeviceBackends(ConfigurationParser& my_config) { - PluginRegistry::DumpDbg(); - #if defined(HAVE_DYNAMIC_SD_BACKENDS) auto storage_res = dynamic_cast(my_config.GetNextRes(R_STORAGE, NULL)); #endif BareosResource* p = nullptr; - while ((p = my_config.GetNextRes(R_DEVICE, p)) != nullptr) { DeviceResource* d = dynamic_cast(p); if (d) { to_lower(d->dev_type); - if (!PluginRegistry::IsRegistered(d->dev_type)) { + if (!PluginRegistry::IsRegistered(d->dev_type)) { #if defined(HAVE_DYNAMIC_SD_BACKENDS) if (!storage_res || storage_res->backend_directories.empty()) { Jmsg2(nullptr, M_ERROR_TERM, 0,