Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bareos/bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rogge <andreas.rogge@bareos.com>2022-09-27 11:33:22 +0300
committerAndreas Rogge <andreas.rogge@bareos.com>2022-11-07 19:37:27 +0300
commit1a23d7826255997a49c7a844d543a0356f074381 (patch)
treeb4374b5c700e110907639825deb4887644af0ce6
parent990970bcd1ccd8ecaa62f6c3dd2fc6166065efce (diff)
stored: load file device dynamically
Instead of building unix_file_device/win32_file_device directory into libbareossd, this patch builds them as a dynamic backend and removes special handling for them. Also move all backend build configuration into the backends directory.
-rw-r--r--core/CMakeLists.txt1
-rw-r--r--core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.storage1
-rw-r--r--core/platforms/packaging/bareos.spec1
-rw-r--r--core/src/stored/CMakeLists.txt37
-rw-r--r--core/src/stored/backends/CMakeLists.txt65
-rw-r--r--core/src/stored/backends/unix_file_device.cc20
-rw-r--r--core/src/stored/backends/unix_file_device.h4
-rw-r--r--core/src/stored/dev.cc75
-rw-r--r--core/src/stored/sd_backends.cc1
-rw-r--r--debian/bareos-storage.install.in1
10 files changed, 107 insertions, 99 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index e8a1c1467..c0750dfa5 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -30,6 +30,7 @@ endif()
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0057 NEW)
+cmake_policy(SET CMP0079 NEW)
if(POLICY CMP0109)
cmake_policy(SET CMP0109 NEW)
diff --git a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.storage b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.storage
index 4e19878bb..fd456b2ec 100644
--- a/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.storage
+++ b/core/platforms/freebsd/bareos-freebsd/bareos.com-common/pkg-plist.storage
@@ -13,6 +13,7 @@
sbin/bareos-sd
lib/bareos/scripts/disk-changer
lib/bareos/plugins/autoxflate-sd.so
+lib/libbareossd-file.so
man/man8/bareos-sd.8.gz
@dir(bareos,bareos,0775) /var/lib/bareos/storage
etc/rc.d/bareos-sd
diff --git a/core/platforms/packaging/bareos.spec b/core/platforms/packaging/bareos.spec
index a51f5c05c..0fc9d718c 100644
--- a/core/platforms/packaging/bareos.spec
+++ b/core/platforms/packaging/bareos.spec
@@ -1300,6 +1300,7 @@ mkdir -p %{?buildroot}/%{_libdir}/bareos/plugins/vmware_plugin
%{_sbindir}/bareos-sd
%{script_dir}/disk-changer
%{plugin_dir}/autoxflate-sd.so
+%{backend_dir}/libbareossd-file*.so
%{_mandir}/man8/bareos-sd.8.gz
%if 0%{?systemd_support}
%{_unitdir}/bareos-sd.service
diff --git a/core/src/stored/CMakeLists.txt b/core/src/stored/CMakeLists.txt
index 97bc92ef1..3a5e11291 100644
--- a/core/src/stored/CMakeLists.txt
+++ b/core/src/stored/CMakeLists.txt
@@ -44,34 +44,6 @@ if(NOT build_client_only)
message("Backends are now ${BACKENDS}")
endif()
-if(NOT ${HAVE_DYNAMIC_SD_BACKENDS})
- set(AVAILABLE_DEVICE_API_SRCS backends/generic_tape_device.cc)
-
- if(HAVE_WIN32)
- list(
- APPEND
- AVAILABLE_DEVICE_API_SRCS
- ${PROJECT_SOURCE_DIR}/src/win32/stored/backends/win32_fifo_device.cc
- ${PROJECT_SOURCE_DIR}/src/win32/stored/backends/win32_file_device.cc
- ${PROJECT_SOURCE_DIR}/src/win32/stored/backends/win32_tape_device.cc
- )
- else()
- list(APPEND AVAILABLE_DEVICE_API_SRCS backends/unix_fifo_device.cc
- # backends/droplet_device.cc
- backends/unix_tape_device.cc backends/unix_file_device.cc
- )
- endif()
-
- if(${HAVE_GFAPI})
- list(APPEND AVAILABLE_DEVICE_API_SRCS backends/gfapi_device.cc)
- endif()
-
- if(TARGET droplet)
- list(APPEND AVAILABLE_DEVICE_API_SRCS backends/droplet_device.cc)
- list(APPEND AVAILABLE_DEVICE_API_SRCS backends/chunked_device.cc)
- endif()
-endif()
-
set(LIBBAREOSSD_SRCS
acquire.cc
ansi_label.cc
@@ -103,7 +75,6 @@ set(LIBBAREOSSD_SRCS
stored_conf.cc
vol_mgr.cc
wait.cc
- ${AVAILABLE_DEVICE_API_SRCS}
)
set(SDSRCS
@@ -177,10 +148,6 @@ else()
message(STATUS "LIBBAREOSSD_LIBRARIES ARE ${LIBBAREOSSD_LIBRARIES}")
endif()
-if(${HAVE_DYNAMIC_SD_BACKENDS})
- list(APPEND LIBBAREOSSD_SRCS backends/unix_file_device.cc)
-endif()
-
add_library(bareossd SHARED ${LIBBAREOSSD_SRCS})
target_link_libraries(bareossd PRIVATE bareos Threads::Threads)
set_target_properties(
@@ -240,9 +207,7 @@ install(SCRIPT ${PROJECT_SOURCE_DIR}/cmake/install-stored-configfiles.cmake)
install(DIRECTORY DESTINATION "${archivedir}")
-if(${HAVE_DYNAMIC_SD_BACKENDS})
- add_subdirectory(backends)
-endif()
+add_subdirectory(backends)
if(TARGET droplet)
target_compile_definitions(bareossd PRIVATE HAVE_BAREOSSD_DROPLET_DEVICE)
diff --git a/core/src/stored/backends/CMakeLists.txt b/core/src/stored/backends/CMakeLists.txt
index fa870ac0e..0f4733c31 100644
--- a/core/src/stored/backends/CMakeLists.txt
+++ b/core/src/stored/backends/CMakeLists.txt
@@ -1,6 +1,6 @@
# BAREOSĀ® - Backup Archiving REcovery Open Sourced
#
-# Copyright (C) 2017-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
@@ -16,40 +16,67 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
+
message("Entering ${CMAKE_CURRENT_SOURCE_DIR}")
list(APPEND CMAKE_INSTALL_RPATH ${backenddir})
+macro(add_sd_backend backend_name)
+ if(HAVE_DYNAMIC_SD_BACKENDS)
+ add_library(${backend_name} MODULE)
+ install(TARGETS ${backend_name} DESTINATION ${backenddir})
+ else()
+ add_library(${backend_name} STATIC)
+ target_link_libraries(bareossd PRIVATE ${backend_name})
+ endif()
+ set_property(TARGET ${backend_name} PROPERTY POSITION_INDEPENDENT_CODE ON)
+endmacro()
+
if(${HAVE_GLUSTERFS})
- add_library(bareossd-gfapi MODULE gfapi_device.cc)
- install(TARGETS bareossd-gfapi DESTINATION ${backenddir})
+ add_sd_backend(bareossd-gfapi)
+ target_sources(bareossd-gfapi PRIVATE gfapi_device.cc)
target_include_directories(bareossd-gfapi PUBLIC ${GFAPI_INCLUDE_DIRS})
target_link_libraries(bareossd-gfapi ${GFAPI_LIBRARIES})
endif()
if(TARGET droplet)
- add_library(bareossd-chunked SHARED ordered_cbuf.cc chunked_device.cc)
- target_link_libraries(bareossd-chunked droplet)
- install(TARGETS bareossd-chunked DESTINATION ${backenddir})
+ add_sd_backend(bareossd-droplet)
+ target_sources(bareossd-droplet PRIVATE droplet_device.cc)
+ target_link_libraries(bareossd-droplet PRIVATE droplet)
+ target_compile_definitions(
+ bareossd-droplet INTERFACE HAVE_BAREOSSD_DROPLET_DEVICE
+ )
+ if(HAVE_DYNAMIC_SD_BACKENDS)
+ add_library(bareossd-chunked SHARED ordered_cbuf.cc chunked_device.cc)
+ install(TARGETS bareossd-chunked DESTINATION ${backenddir})
+ target_link_libraries(bareossd-droplet PRIVATE bareossd-chunked)
+ else()
+ target_sources(bareossd-droplet PRIVATE ordered_cbuf.cc chunked_device.cc)
+ endif()
- add_library(bareossd-droplet MODULE droplet_device.cc)
- target_link_libraries(bareossd-droplet bareossd-chunked droplet)
- install(TARGETS bareossd-droplet DESTINATION ${backenddir})
endif()
-add_library(bareossd-fifo MODULE unix_fifo_device.cc)
-install(TARGETS bareossd-fifo DESTINATION ${backenddir})
+add_sd_backend(bareossd-fifo)
+target_sources(bareossd-fifo PRIVATE unix_fifo_device.cc)
if(HAVE_DARWIN_OS)
target_link_libraries(bareossd-fifo bareos bareossd)
endif()
-add_library(bareossd-gentape SHARED generic_tape_device.cc)
-install(TARGETS bareossd-gentape DESTINATION ${backenddir})
-if(HAVE_DARWIN_OS)
- target_link_libraries(bareossd-gentape bareos bareossd)
-endif()
+add_sd_backend(bareossd-tape)
+target_sources(bareossd-tape PRIVATE unix_tape_device.cc)
-add_library(bareossd-tape MODULE unix_tape_device.cc)
-install(TARGETS bareossd-tape DESTINATION ${backenddir})
+if(HAVE_DYNAMIC_SD_BACKENDS)
+ add_library(bareossd-gentape SHARED generic_tape_device.cc)
+ install(TARGETS bareossd-gentape DESTINATION ${backenddir})
+ target_link_libraries(bareossd-tape bareossd-gentape)
+ if(HAVE_DARWIN_OS)
+ target_link_libraries(bareossd-gentape bareos bareossd)
+ endif()
+else()
+ target_sources(bareossd-tape PRIVATE generic_tape_device.cc)
+endif()
-target_link_libraries(bareossd-tape bareossd-gentape)
+if(NOT HAVE_WIN32)
+ add_sd_backend(bareossd-file)
+ target_sources(bareossd-file PRIVATE unix_file_device.cc)
+endif()
diff --git a/core/src/stored/backends/unix_file_device.cc b/core/src/stored/backends/unix_file_device.cc
index 363762c77..048f0417b 100644
--- a/core/src/stored/backends/unix_file_device.cc
+++ b/core/src/stored/backends/unix_file_device.cc
@@ -32,6 +32,7 @@
#include "include/bareos.h"
#include "stored/stored.h"
#include "stored/stored_globals.h"
+#include "stored/sd_backends.h"
#include "stored/device_control_record.h"
#include "unix_file_device.h"
#include "lib/berrno.h"
@@ -310,4 +311,23 @@ bail_out:
return true;
}
+class Backend : public BackendInterface {
+ public:
+ Device* GetDevice(JobControlRecord* jcr, DeviceType device_type) override
+ {
+ switch (device_type) {
+ case DeviceType::B_FILE_DEV:
+ return new unix_file_device;
+ default:
+ Jmsg(jcr, M_FATAL, 0, _("Request for unknown devicetype: %d\n"),
+ device_type);
+ return nullptr;
+ }
+ }
+};
+
+#ifdef HAVE_DYNAMIC_SD_BACKENDS
+extern "C" BackendInterface* GetBackend(void) { return new Backend; }
+#endif
+
} /* namespace storagedaemon */
diff --git a/core/src/stored/backends/unix_file_device.h b/core/src/stored/backends/unix_file_device.h
index 51eb5aaa2..3c8ec0a73 100644
--- a/core/src/stored/backends/unix_file_device.h
+++ b/core/src/stored/backends/unix_file_device.h
@@ -2,7 +2,7 @@
BAREOSĀ® - Backup Archiving REcovery Open Sourced
Copyright (C) 2013-2013 Planets Communications B.V.
- Copyright (C) 2013-2021 Bareos GmbH & Co. KG
+ Copyright (C) 2013-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
@@ -28,6 +28,8 @@
#ifndef BAREOS_STORED_BACKENDS_UNIX_FILE_DEVICE_H_
#define BAREOS_STORED_BACKENDS_UNIX_FILE_DEVICE_H_
+#include "stored/dev.h"
+
namespace storagedaemon {
class unix_file_device : public Device {
diff --git a/core/src/stored/dev.cc b/core/src/stored/dev.cc
index 971a7ec18..28b1ee2ef 100644
--- a/core/src/stored/dev.cc
+++ b/core/src/stored/dev.cc
@@ -92,20 +92,16 @@
# endif
# include "backends/generic_tape_device.h"
# ifdef HAVE_WIN32
+# include "backends/win32_file_device.h"
# include "backends/win32_tape_device.h"
# include "backends/win32_fifo_device.h"
# else
+# include "backends/unix_file_device.h"
# include "backends/unix_tape_device.h"
# include "backends/unix_fifo_device.h"
# endif
#endif /* HAVE_DYNAMIC_SD_BACKENDS */
-#ifdef HAVE_WIN32
-# include "backends/win32_file_device.h"
-#else
-# include "backends/unix_file_device.h"
-#endif
-
#ifndef O_NONBLOCK
# define O_NONBLOCK 0
#endif
@@ -171,12 +167,12 @@ Device* FactoryCreateDevice(JobControlRecord* jcr,
Device* dev = nullptr;
+ /*
+ * When using dynamic loading use the InitBackendDevice() function
+ * for any type of device.
+ */
+#if !defined(HAVE_DYNAMIC_SD_BACKENDS)
switch (device_resource->dev_type) {
- /*
- * When using dynamic loading use the InitBackendDevice() function
- * for any type of device not being of the type file.
- */
-#ifndef HAVE_DYNAMIC_SD_BACKENDS
# ifdef HAVE_GFAPI
case DeviceType::B_GFAPI_DEV:
dev = new gfapi_device;
@@ -188,6 +184,9 @@ Device* FactoryCreateDevice(JobControlRecord* jcr,
break;
# endif
# ifdef HAVE_WIN32
+ case DeviceType::B_FILE_DEV:
+ dev = new win32_file_device;
+ break;
case DeviceType::B_TAPE_DEV:
dev = new win32_tape_device;
break;
@@ -195,6 +194,9 @@ Device* FactoryCreateDevice(JobControlRecord* jcr,
dev = new win32_fifo_device;
break;
# else
+ case DeviceType::B_FILE_DEV:
+ dev = new unix_file_device;
+ break;
case DeviceType::B_TAPE_DEV:
dev = new unix_tape_device;
break;
@@ -202,42 +204,29 @@ Device* FactoryCreateDevice(JobControlRecord* jcr,
dev = new unix_fifo_device;
break;
# endif
-#endif /* HAVE_DYNAMIC_SD_BACKENDS */
-#ifdef HAVE_WIN32
- case DeviceType::B_FILE_DEV:
- dev = new win32_file_device;
- break;
-#else
- case DeviceType::B_FILE_DEV:
- dev = new unix_file_device;
- break;
-#endif
- default:
-#ifdef HAVE_DYNAMIC_SD_BACKENDS
- dev = InitBackendDevice(jcr, device_resource->dev_type);
- if (!dev) {
- try {
- Jmsg2(jcr, M_ERROR, 0,
- _("Initialization of dynamic %s device \"%s\" with archive "
- "device \"%s\" failed. Backend "
- "library might be missing or backend directory incorrect.\n"),
- device_type_to_name_mapping.at(device_resource->dev_type),
- device_resource->resource_name_,
- device_resource->archive_device_string);
- } catch (const std::out_of_range&) {
- // device_resource->dev_type could exceed limits of map
- }
- return nullptr;
- }
-#endif
- break;
+ case DeviceType::B_UNKNOWN_DEV:
+ Jmsg2(jcr, M_ERROR, 0, _("%s has an unknown device type %d\n"),
+ device_resource->archive_device_string, device_resource->dev_type);
+ return nullptr;
}
-
+#else
+ dev = InitBackendDevice(jcr, device_resource->dev_type);
if (!dev) {
- Jmsg2(jcr, M_ERROR, 0, _("%s has an unknown device type %d\n"),
- device_resource->archive_device_string, device_resource->dev_type);
+ try {
+ Jmsg2(jcr, M_ERROR, 0,
+ _("Initialization of dynamic %s device \"%s\" with archive "
+ "device \"%s\" failed. Backend "
+ "library might be missing or backend directory incorrect.\n"),
+ device_type_to_name_mapping.at(device_resource->dev_type),
+ device_resource->resource_name_,
+ device_resource->archive_device_string);
+ } catch (const std::out_of_range&) {
+ // device_resource->dev_type could exceed limits of map
+ }
return nullptr;
}
+#endif // !defined(HAVE_DYNAMIC_SD_BACKENDS)
+
dev->InvalidateSlotNumber(); /* unknown */
// Copy user supplied device parameters from Resource
diff --git a/core/src/stored/sd_backends.cc b/core/src/stored/sd_backends.cc
index 8351804b1..1687cb35e 100644
--- a/core/src/stored/sd_backends.cc
+++ b/core/src/stored/sd_backends.cc
@@ -93,6 +93,7 @@ struct BackendDeviceLibraryDescriptor {
const std::map<DeviceType, const char*> device_type_to_name_mapping
= {{DeviceType::B_FIFO_DEV, "fifo"},
+ {DeviceType::B_FILE_DEV, "file"},
{DeviceType::B_TAPE_DEV, "tape"},
{DeviceType::B_GFAPI_DEV, "gfapi"},
{DeviceType::B_DROPLET_DEV, "droplet"},
diff --git a/debian/bareos-storage.install.in b/debian/bareos-storage.install.in
index 101deba2d..de1fa14d6 100644
--- a/debian/bareos-storage.install.in
+++ b/debian/bareos-storage.install.in
@@ -1,4 +1,5 @@
@plugindir@/autoxflate-sd.so
+@backenddir@/libbareossd-file.so*
@scriptdir@/disk-changer
@configtemplatedir@/bareos-sd.d/device/FileStorage.conf
@configtemplatedir@/bareos-sd.d/director/bareos-dir.conf