]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_ceph: split ceph mount logic into a new function
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 15 Feb 2023 19:22:00 +0000 (14:22 -0500)
committerAnoop C S <anoopcs@samba.org>
Fri, 24 Feb 2023 04:43:32 +0000 (04:43 +0000)
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 <jmulligan@redhat.com>
Reviewed-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/modules/vfs_ceph.c

index c5ee9d5967c5ba2b91ca3c958d12ebf65898b386..09c7aee99285c06696227edfdfff154d60e97867 100644 (file)
 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)