From: Shachar Sharon Date: Wed, 4 Sep 2024 11:55:50 +0000 (+0300) Subject: vfs_ceph_new: refactor error-case in cephmount_mount_fs X-Git-Tag: samba-4.20.8~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=191d67baeadd6d0c2fb09663a6c4b2c6af7e8be9;p=thirdparty%2Fsamba.git vfs_ceph_new: refactor error-case in cephmount_mount_fs Align code-style of 'cephmount_mount_fs' with rest of the code: use 'goto' for bail-out upon error case (with proper cleanups). For the common case of successful operation complete execution and return final value. Added extra debug-logging for good-path case. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15703 Signed-off-by: Shachar Sharon Reviewed-by: Anoop C S Reviewed-by: John Mulligan (cherry picked from commit d9b872afeee4dee49de2e6eb86e4b59e07804363) --- diff --git a/source3/modules/vfs_ceph_new.c b/source3/modules/vfs_ceph_new.c index e5517a98298..e5afac20be1 100644 --- a/source3/modules/vfs_ceph_new.c +++ b/source3/modules/vfs_ceph_new.c @@ -266,24 +266,24 @@ static struct ceph_mount_info *cephmount_mount_fs( (config->conf_file == NULL ? "default path" : config->conf_file)); ret = config->ceph_conf_read_file_fn(mnt, config->conf_file); if (ret) { - goto err_cm_release; + goto out; } DBG_DEBUG("[CEPH] calling: ceph_conf_get\n"); ret = config->ceph_conf_get_fn(mnt, "log file", buf, sizeof(buf)); if (ret < 0) { - goto err_cm_release; + goto out; } /* libcephfs disables POSIX ACL support by default, enable it... */ ret = config->ceph_conf_set_fn(mnt, "client_acl_type", "posix_acl"); if (ret < 0) { - goto err_cm_release; + goto out; } /* tell libcephfs to perform local permission checks */ ret = config->ceph_conf_set_fn(mnt, "fuse_default_permissions", "false"); if (ret < 0) { - goto err_cm_release; + goto out; } /* * select a cephfs file system to use: @@ -293,26 +293,30 @@ static struct ceph_mount_info *cephmount_mount_fs( if (config->fsname != NULL) { ret = config->ceph_select_filesystem_fn(mnt, config->fsname); if (ret < 0) { - goto err_cm_release; + goto out; } } DBG_DEBUG("[CEPH] calling: ceph_mount\n"); ret = config->ceph_mount_fn(mnt, NULL); - if (ret >= 0) { - goto cm_done; + if (ret < 0) { + goto out; } + ret = 0; - err_cm_release: - config->ceph_release_fn(mnt); - mnt = NULL; - DBG_DEBUG("[CEPH] Error mounting fs: %s\n", strerror(-ret)); - cm_done: - /* - * Handle the error correctly. Ceph returns -errno. - */ - if (ret) { +out: + if (ret != 0) { + config->ceph_release_fn(mnt); + mnt = NULL; + DBG_ERR("[CEPH] mount failed: user_id='%s' fsname='%s' %s", + (config->user_id != NULL) ? config->user_id : "", + (config->fsname != NULL) ? config->fsname : "", + strerror(-ret)); errno = -ret; + } else { + DBG_DEBUG("[CEPH] mount done: user_id='%s' fsname='%s'", + (config->user_id != NULL) ? config->user_id : "", + (config->fsname != NULL) ? config->fsname : ""); } return mnt; }