]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_ceph_new: Dynamically open library for 'proxy' mode
authorGuenther Deschner <gd@samba.org>
Thu, 5 Sep 2024 07:49:52 +0000 (13:19 +0530)
committerJule Anger <janger@samba.org>
Mon, 17 Feb 2025 16:09:08 +0000 (16:09 +0000)
Use dlopen() to load either of the shared libraries(libcephfs.so or
libcephfs_proxy.so) based on the configuration for 'proxy' module
parameter. Further down the line we will define the required APIs
as function pointers within the config structure.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15703

Pair-Programmed-With: Anoop C S <anoopcs@samba.org>
Signed-off-by: Guenther Deschner <gd@samba.org>
Signed-off-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
(cherry picked from commit 47812a279118befbaeffdd6c81e3d49b071f04c5)

source3/modules/vfs_ceph_new.c

index fd977dbe7ef9c02e6d821bb89ef4abe0e5dafdfe..c72c8dce3777a79c345929f964955e6ba0c3b05c 100644 (file)
@@ -106,6 +106,7 @@ struct vfs_ceph_config {
        struct cephmount_cached *mount_entry;
        struct ceph_mount_info *mount;
        enum vfs_cephfs_proxy_mode proxy;
+       void *libhandle;
 };
 
 /*
@@ -265,8 +266,49 @@ static struct ceph_mount_info *cephmount_mount_fs(
        return mnt;
 }
 
+static bool vfs_cephfs_load_lib(struct vfs_ceph_config *config)
+{
+       void *libhandle = NULL;
+       const char *libname = "libcephfs.so.2";
+       const char *libname_proxy = "libcephfs_proxy.so.2";
+
+       switch (config->proxy) {
+       case VFS_CEPHFS_PROXY_YES:
+       case VFS_CEPHFS_PROXY_AUTO:
+               libhandle = dlopen(libname_proxy, RTLD_NOW);
+               if (libhandle == NULL) {
+                       if (config->proxy == VFS_CEPHFS_PROXY_YES) {
+                               DBG_ERR("%s\n", dlerror());
+                               return false;
+                       }
+                       DBG_DEBUG("%s, trying %s\n", dlerror(), libname);
+                       FALL_THROUGH;
+               } else {
+                       break;
+               }
+       case VFS_CEPHFS_PROXY_NO:
+       default:
+               libhandle = dlopen(libname, RTLD_LAZY);
+               if (libhandle == NULL) {
+                       DBG_ERR("%s\n", dlerror());
+                       return false;
+               }
+               break;
+       }
+
+       config->libhandle = libhandle;
+
+       return true;
+}
+
 static int vfs_ceph_config_destructor(struct vfs_ceph_config *config)
 {
+       if (config->libhandle) {
+               if (dlclose(config->libhandle)) {
+                       DBG_ERR("%s\n", dlerror());
+               }
+       }
+
        return 0;
 }
 
@@ -276,6 +318,7 @@ static bool vfs_ceph_load_config(struct vfs_handle_struct *handle,
        struct vfs_ceph_config *config_tmp = NULL;
        int snum = SNUM(handle->conn);
        const char *module_name = "ceph_new";
+       bool ok;
 
        if (SMB_VFS_HANDLE_TEST_DATA(handle)) {
                SMB_VFS_HANDLE_GET_DATA(handle, config_tmp,
@@ -305,6 +348,11 @@ static bool vfs_ceph_load_config(struct vfs_handle_struct *handle,
                return false;
        }
 
+       ok = vfs_cephfs_load_lib(config_tmp);
+       if (!ok) {
+               return false;
+       }
+
        SMB_VFS_HANDLE_SET_DATA(handle, config_tmp, NULL,
                                struct vfs_ceph_config, return false);