From: John Mulligan Date: Wed, 15 Feb 2023 19:22:00 +0000 (-0500) Subject: vfs_ceph: split ceph mount logic into a new function X-Git-Tag: talloc-2.4.1~1577 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=df073c7eedc61fe1c95b2e26a18915b2a0c77552;p=thirdparty%2Fsamba.git vfs_ceph: split ceph mount logic into a new function This new function is entirely dedicated to just setting up a libcephfs mount. Handling the cmount global and samba connection params remains in cephwrap_connect. This change will later be used to avoid a single global cached connection and add improved connection handling. Signed-off-by: John Mulligan Reviewed-by: Guenther Deschner Reviewed-by: Anoop C S --- diff --git a/source3/modules/vfs_ceph.c b/source3/modules/vfs_ceph.c index c5ee9d5967c..09c7aee9928 100644 --- a/source3/modules/vfs_ceph.c +++ b/source3/modules/vfs_ceph.c @@ -77,66 +77,89 @@ static struct ceph_mount_info * cmount = NULL; static uint32_t cmount_cnt = 0; -/* Check for NULL pointer parameters in cephwrap_* functions */ - -/* We don't want to have NULL function pointers lying around. Someone - is sure to try and execute them. These stubs are used to prevent - this possibility. */ - -static int cephwrap_connect(struct vfs_handle_struct *handle, const char *service, const char *user) +static struct ceph_mount_info *cephmount_mount_fs(const int snum) { int ret; char buf[256]; - int snum = SNUM(handle->conn); - const char *conf_file; - const char *user_id; - - if (cmount) { - handle->data = cmount; /* We have been here before */ - cmount_cnt++; - return 0; - } - + struct ceph_mount_info *mnt = NULL; /* if config_file and/or user_id are NULL, ceph will use defaults */ - conf_file = lp_parm_const_string(snum, "ceph", "config_file", NULL); - user_id = lp_parm_const_string(snum, "ceph", "user_id", NULL); + const char *conf_file = + lp_parm_const_string(snum, "ceph", "config_file", NULL); + const char *user_id = + lp_parm_const_string(snum, "ceph", "user_id", NULL); DBG_DEBUG("[CEPH] calling: ceph_create\n"); - ret = ceph_create(&cmount, user_id); + ret = ceph_create(&mnt, user_id); if (ret) { - goto err_out; + errno = -ret; + return NULL; } DBG_DEBUG("[CEPH] calling: ceph_conf_read_file with %s\n", (conf_file == NULL ? "default path" : conf_file)); - ret = ceph_conf_read_file(cmount, conf_file); + ret = ceph_conf_read_file(mnt, conf_file); if (ret) { goto err_cm_release; } DBG_DEBUG("[CEPH] calling: ceph_conf_get\n"); - ret = ceph_conf_get(cmount, "log file", buf, sizeof(buf)); + ret = ceph_conf_get(mnt, "log file", buf, sizeof(buf)); if (ret < 0) { goto err_cm_release; } /* libcephfs disables POSIX ACL support by default, enable it... */ - ret = ceph_conf_set(cmount, "client_acl_type", "posix_acl"); + ret = ceph_conf_set(mnt, "client_acl_type", "posix_acl"); if (ret < 0) { goto err_cm_release; } /* tell libcephfs to perform local permission checks */ - ret = ceph_conf_set(cmount, "fuse_default_permissions", "false"); + ret = ceph_conf_set(mnt, "fuse_default_permissions", "false"); if (ret < 0) { goto err_cm_release; } DBG_DEBUG("[CEPH] calling: ceph_mount\n"); - ret = ceph_mount(cmount, NULL); - if (ret < 0) { - goto err_cm_release; + ret = ceph_mount(mnt, NULL); + if (ret >= 0) { + goto cm_done; + } + + err_cm_release: + ceph_release(mnt); + mnt = NULL; + DBG_DEBUG("[CEPH] Error mounting fs: %s\n", strerror(-ret)); + cm_done: + /* + * Handle the error correctly. Ceph returns -errno. + */ + if (ret) { + errno = -ret; + } + return mnt; +} + +/* Check for NULL pointer parameters in cephwrap_* functions */ + +/* We don't want to have NULL function pointers lying around. Someone + is sure to try and execute them. These stubs are used to prevent + this possibility. */ + +static int cephwrap_connect(struct vfs_handle_struct *handle, const char *service, const char *user) +{ + int snum = SNUM(handle->conn); + + if (cmount) { + handle->data = cmount; /* We have been here before */ + cmount_cnt++; + return 0; } + cmount = cephmount_mount_fs(snum); + if (cmount == NULL) { + /* errno has been set in cephmount_mount_fs */ + return -1; + } /* * encode mount context/state into our vfs/connection holding structure * cmount is a ceph_mount_t* @@ -150,16 +173,6 @@ static int cephwrap_connect(struct vfs_handle_struct *handle, const char *servi lp_do_parameter(SNUM(handle->conn), "smbd async dosmode", "false"); return 0; - -err_cm_release: - ceph_release(cmount); - cmount = NULL; -err_out: - /* - * Handle the error correctly. Ceph returns -errno. - */ - DBG_DEBUG("[CEPH] Error return: %s\n", strerror(-ret)); - WRAP_RETURN(ret); } static void cephwrap_disconnect(struct vfs_handle_struct *handle)