From: Guenther Deschner Date: Thu, 5 Sep 2024 07:49:52 +0000 (+0530) Subject: vfs_ceph_new: Dynamically open library for 'proxy' mode X-Git-Tag: samba-4.20.8~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae13462d06fe9ed8c4c1f3172e8890d6a26b300c;p=thirdparty%2Fsamba.git vfs_ceph_new: Dynamically open library for 'proxy' mode 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 Signed-off-by: Guenther Deschner Signed-off-by: Anoop C S Reviewed-by: Guenther Deschner (cherry picked from commit 47812a279118befbaeffdd6c81e3d49b071f04c5) --- diff --git a/source3/modules/vfs_ceph_new.c b/source3/modules/vfs_ceph_new.c index fd977dbe7ef..c72c8dce377 100644 --- a/source3/modules/vfs_ceph_new.c +++ b/source3/modules/vfs_ceph_new.c @@ -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);