From: Guenther Deschner Date: Thu, 5 Sep 2024 06:49:52 +0000 (+0530) Subject: vfs_ceph_new: Add a new struct to hold ceph module config X-Git-Tag: samba-4.20.8~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12137411955d0826e49639bc938be92d1ae23970;p=thirdparty%2Fsamba.git vfs_ceph_new: Add a new struct to hold ceph module config Consolidate all required configuration related data under a dedicated structure named vfs_ceph_config. As of now it includes the location of configuration file, file system name, ceph client user id and mount related information. This is expected to grow in future with more details as and when required. Apart from that small cleanups are also done to make code more robust. 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 f1d418181d12bd513204cf2b77c37990939e2041) --- diff --git a/source3/modules/vfs_ceph_new.c b/source3/modules/vfs_ceph_new.c index ce46eff69cf..87f58364f8e 100644 --- a/source3/modules/vfs_ceph_new.c +++ b/source3/modules/vfs_ceph_new.c @@ -78,6 +78,14 @@ static ssize_t lstatus_code(intmax_t ret) return (ssize_t)ret; } +struct vfs_ceph_config { + const char *conf_file; + const char *user_id; + const char *fsname; + struct cephmount_cached *mount_entry; + struct ceph_mount_info *mount; +}; + /* * Track unique connections, as virtual mounts, to cephfs file systems. * Individual mount-entries will be set on the handle->data attribute, but @@ -156,41 +164,33 @@ static int cephmount_cache_remove(struct cephmount_cached *entry) return 0; } -static char *cephmount_get_cookie(TALLOC_CTX * mem_ctx, const int snum) +static char *cephmount_get_cookie(TALLOC_CTX * mem_ctx, + struct vfs_ceph_config *config) { - const char *conf_file = - lp_parm_const_string(snum, "ceph_new", "config_file", "."); - const char *user_id = - lp_parm_const_string(snum, "ceph_new", "user_id", ""); - const char *fsname = - lp_parm_const_string(snum, "ceph_new", "filesystem", ""); - return talloc_asprintf(mem_ctx, "(%s/%s/%s)", conf_file, user_id, - fsname); + return talloc_asprintf(mem_ctx, "(%s/%s/%s)", + config->conf_file, + config->user_id, + config->fsname); } -static struct ceph_mount_info *cephmount_mount_fs(const int snum) +static struct ceph_mount_info *cephmount_mount_fs( + struct vfs_ceph_config *config) { int ret; char buf[256]; struct ceph_mount_info *mnt = NULL; /* if config_file and/or user_id are NULL, ceph will use defaults */ - const char *conf_file = - lp_parm_const_string(snum, "ceph_new", "config_file", NULL); - const char *user_id = - lp_parm_const_string(snum, "ceph_new", "user_id", NULL); - const char *fsname = - lp_parm_const_string(snum, "ceph_new", "filesystem", NULL); DBG_DEBUG("[CEPH] calling: ceph_create\n"); - ret = ceph_create(&mnt, user_id); + ret = ceph_create(&mnt, config->user_id); if (ret) { 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(mnt, conf_file); + (config->conf_file == NULL ? "default path" : config->conf_file)); + ret = ceph_conf_read_file(mnt, config->conf_file); if (ret) { goto err_cm_release; } @@ -216,8 +216,8 @@ static struct ceph_mount_info *cephmount_mount_fs(const int snum) * In ceph, multiple file system support has been stable since * 'pacific'. Permit different shares to access different file systems. */ - if (fsname != NULL) { - ret = ceph_select_filesystem(mnt, fsname); + if (config->fsname != NULL) { + ret = ceph_select_filesystem(mnt, config->fsname); if (ret < 0) { goto err_cm_release; } @@ -243,6 +243,48 @@ static struct ceph_mount_info *cephmount_mount_fs(const int snum) return mnt; } +static int vfs_ceph_config_destructor(struct vfs_ceph_config *config) +{ + return 0; +} + +static bool vfs_ceph_load_config(struct vfs_handle_struct *handle, + struct vfs_ceph_config **config) +{ + struct vfs_ceph_config *config_tmp = NULL; + int snum = SNUM(handle->conn); + const char *module_name = "ceph_new"; + + if (SMB_VFS_HANDLE_TEST_DATA(handle)) { + SMB_VFS_HANDLE_GET_DATA(handle, config_tmp, + struct vfs_ceph_config, + return false); + goto done; + } + + config_tmp = talloc_zero(handle->conn, struct vfs_ceph_config); + if (config_tmp == NULL) { + errno = ENOMEM; + return false; + } + talloc_set_destructor(config_tmp, vfs_ceph_config_destructor); + + config_tmp->conf_file = lp_parm_const_string(snum, module_name, + "config_file", "."); + config_tmp->user_id = lp_parm_const_string(snum, module_name, + "user_id", ""); + config_tmp->fsname = lp_parm_const_string(snum, module_name, + "filesystem", ""); + + SMB_VFS_HANDLE_SET_DATA(handle, config_tmp, NULL, + struct vfs_ceph_config, return false); + +done: + *config = config_tmp; + + return true; +} + /* Check for NULL pointer parameters in vfs_ceph_* functions */ /* We don't want to have NULL function pointers lying around. Someone @@ -254,9 +296,17 @@ static int vfs_ceph_connect(struct vfs_handle_struct *handle, { int ret = 0; struct cephmount_cached *entry = NULL; - struct ceph_mount_info *cmount = NULL; - int snum = SNUM(handle->conn); - char *cookie = cephmount_get_cookie(handle, snum); + struct ceph_mount_info *mount = NULL; + char *cookie; + struct vfs_ceph_config *config = NULL; + bool ok; + + ok = vfs_ceph_load_config(handle, &config); + if (!ok) { + return -1; + } + + cookie = cephmount_get_cookie(handle, config); if (cookie == NULL) { return -1; } @@ -266,18 +316,20 @@ static int vfs_ceph_connect(struct vfs_handle_struct *handle, goto connect_ok; } - cmount = cephmount_mount_fs(snum); - if (cmount == NULL) { + mount = cephmount_mount_fs(config); + if (mount == NULL) { ret = -1; goto connect_fail; } - ret = cephmount_cache_add(cookie, cmount, &entry); + + ret = cephmount_cache_add(cookie, mount, &entry); if (ret != 0) { goto connect_fail; } connect_ok: - handle->data = entry; + config->mount = entry->mount; + config->mount_entry = entry; DBG_WARNING("Connection established with the server: %s\n", cookie); /* @@ -289,34 +341,35 @@ connect_fail: return ret; } -static struct ceph_mount_info *cmount_of(const struct vfs_handle_struct *handle) -{ - const struct cephmount_cached *entry = handle->data; - - return entry->mount; -} - static void vfs_ceph_disconnect(struct vfs_handle_struct *handle) { - struct ceph_mount_info *cmount = cmount_of(handle); + struct ceph_mount_info *mount = NULL; int ret = 0; + struct vfs_ceph_config *config = NULL; - ret = cephmount_cache_remove(handle->data); + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, return); + + mount = config->mount; + + ret = cephmount_cache_remove(config->mount_entry); if (ret > 0) { DBG_DEBUG("[CEPH] mount cache entry still in use\n"); return; } - ret = ceph_unmount(cmount); + ret = ceph_unmount(mount); if (ret < 0) { DBG_ERR("[CEPH] failed to unmount: %s\n", strerror(-ret)); } - ret = ceph_release(cmount); + ret = ceph_release(mount); if (ret < 0) { DBG_ERR("[CEPH] failed to release: %s\n", strerror(-ret)); } - handle->data = NULL; + + config->mount_entry = NULL; + + TALLOC_FREE(config); } /* Ceph user-credentials */ @@ -433,8 +486,14 @@ static int vfs_ceph_add_fh(struct vfs_handle_struct *handle, files_struct *fsp, struct vfs_ceph_fh **out_cfh) { - struct cephmount_cached *cme = handle->data; + struct cephmount_cached *cme = NULL; struct UserPerm *uperm = NULL; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + + cme = config->mount_entry; uperm = vfs_ceph_userperm_new(handle); if (uperm == NULL) { @@ -490,10 +549,14 @@ static int vfs_ceph_ll_lookup_inode(const struct vfs_handle_struct *handle, Inode **pout) { struct inodeno_t ino = {.val = inoval}; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_lookup_inode: ino=%" PRIu64 "\n", inoval); - return ceph_ll_lookup_inode(cmount_of(handle), ino, pout); + return ceph_ll_lookup_inode(config->mount, ino, pout); } static int vfs_ceph_ll_walk(const struct vfs_handle_struct *handle, @@ -505,6 +568,10 @@ static int vfs_ceph_ll_walk(const struct vfs_handle_struct *handle, { struct UserPerm *uperm = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_walk: name=%s\n", name); @@ -513,7 +580,7 @@ static int vfs_ceph_ll_walk(const struct vfs_handle_struct *handle, return -ENOMEM; } - ret = ceph_ll_walk(cmount_of(handle), + ret = ceph_ll_walk(config->mount, name, pin, stx, @@ -529,9 +596,14 @@ static int vfs_ceph_ll_statfs(const struct vfs_handle_struct *handle, const struct vfs_ceph_iref *iref, struct statvfs *stbuf) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_statfs: ino=%" PRIu64 "\n", iref->ino); - return ceph_ll_statfs(cmount_of(handle), iref->inode, stbuf); + return ceph_ll_statfs(config->mount, iref->inode, stbuf); } static int vfs_ceph_ll_getattr2(const struct vfs_handle_struct *handle, @@ -541,10 +613,14 @@ static int vfs_ceph_ll_getattr2(const struct vfs_handle_struct *handle, { struct ceph_statx stx = {0}; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_getattr: ino=%" PRIu64 "\n", iref->ino); - ret = ceph_ll_getattr(cmount_of(handle), + ret = ceph_ll_getattr(config->mount, iref->inode, &stx, SAMBA_STATX_ATTR_MASK, @@ -580,6 +656,10 @@ static int vfs_ceph_ll_chown(struct vfs_handle_struct *handle, struct ceph_statx stx = {.stx_uid = uid, .stx_gid = gid}; struct UserPerm *uperm = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_setattr: ino=%" PRIu64 " uid=%u gid=%u\n", iref->ino, uid, gid); @@ -588,7 +668,7 @@ static int vfs_ceph_ll_chown(struct vfs_handle_struct *handle, if (uperm == NULL) { return -ENOMEM; } - ret = ceph_ll_setattr(cmount_of(handle), + ret = ceph_ll_setattr(config->mount, iref->inode, &stx, CEPH_STATX_UID | CEPH_STATX_GID, @@ -603,11 +683,15 @@ static int vfs_ceph_ll_fchown(struct vfs_handle_struct *handle, gid_t gid) { struct ceph_statx stx = {.stx_uid = uid, .stx_gid = gid}; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_setattr: ino=%" PRIu64 " uid=%u gid=%u\n", cfh->iref.ino, uid, gid); - return ceph_ll_setattr(cmount_of(handle), + return ceph_ll_setattr(config->mount, cfh->iref.inode, &stx, CEPH_STATX_UID | CEPH_STATX_GID, @@ -619,11 +703,15 @@ static int vfs_ceph_ll_fchmod(struct vfs_handle_struct *handle, mode_t mode) { struct ceph_statx stx = {.stx_mode = mode}; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_setattr: ino=%" PRIu64 " mode=%o\n", cfh->iref.ino, mode); - return ceph_ll_setattr(cmount_of(handle), + return ceph_ll_setattr(config->mount, cfh->iref.inode, &stx, CEPH_STATX_MODE, @@ -636,6 +724,10 @@ static int vfs_ceph_ll_futimes(struct vfs_handle_struct *handle, { struct ceph_statx stx = {0}; int mask = 0; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); if (!is_omit_timespec(&ft->atime)) { stx.stx_atime = ft->atime; @@ -665,7 +757,7 @@ static int vfs_ceph_ll_futimes(struct vfs_handle_struct *handle, full_timespec_to_nt_time(&stx.stx_ctime), full_timespec_to_nt_time(&stx.stx_btime)); - return ceph_ll_setattr(cmount_of(handle), + return ceph_ll_setattr(config->mount, cfh->iref.inode, &stx, mask, @@ -675,10 +767,15 @@ static int vfs_ceph_ll_futimes(struct vfs_handle_struct *handle, static int vfs_ceph_ll_releasedir(const struct vfs_handle_struct *handle, const struct vfs_ceph_fh *dircfh) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_releasedir: ino=%" PRIu64 " fd=%d\n", dircfh->iref.ino, dircfh->fd); - return ceph_ll_releasedir(cmount_of(handle), dircfh->dirp.cdr); + return ceph_ll_releasedir(config->mount, dircfh->dirp.cdr); } static int vfs_ceph_ll_create(const struct vfs_handle_struct *handle, @@ -692,11 +789,15 @@ static int vfs_ceph_ll_create(const struct vfs_handle_struct *handle, struct Inode *inode = NULL; struct Fh *fh = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_create: parent-ino=%" PRIu64 " name=%s " "mode=%o\n", parent->ino, name, mode); - ret = ceph_ll_create(cmount_of(handle), + ret = ceph_ll_create(config->mount, parent->inode, name, mode, @@ -729,6 +830,10 @@ static int vfs_ceph_ll_lookup(const struct vfs_handle_struct *handle, struct Inode *inode = NULL; struct UserPerm *uperm = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_lookup: parent-ino=%" PRIu64 " name=%s\n", parent->ino, name); @@ -737,7 +842,7 @@ static int vfs_ceph_ll_lookup(const struct vfs_handle_struct *handle, if (uperm == NULL) { return -ENOMEM; } - ret = ceph_ll_lookup(cmount_of(handle), + ret = ceph_ll_lookup(config->mount, parent->inode, name, &inode, @@ -766,11 +871,15 @@ static int vfs_ceph_ll_lookup2(const struct vfs_handle_struct *handle, { struct Inode *inode = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_lookup: parent-ino=%" PRIu64 " name=%s\n", parent_fh->iref.ino, name); - ret = ceph_ll_lookup(cmount_of(handle), + ret = ceph_ll_lookup(config->mount, parent_fh->iref.inode, name, &inode, @@ -830,11 +939,15 @@ static int vfs_ceph_ll_open(const struct vfs_handle_struct *handle, struct Inode *in = cfh->iref.inode; struct Fh *fh = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_open: ino=%" PRIu64 " flags=0x%x\n", cfh->iref.ino, flags); - ret = ceph_ll_open(cmount_of(handle), in, flags, &fh, cfh->uperm); + ret = ceph_ll_open(config->mount, in, flags, &fh, cfh->uperm); if (ret == 0) { cfh->fh = fh; vfs_ceph_assign_fh_fd(cfh); @@ -845,9 +958,14 @@ static int vfs_ceph_ll_open(const struct vfs_handle_struct *handle, static int vfs_ceph_ll_opendir(const struct vfs_handle_struct *handle, struct vfs_ceph_fh *cfh) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_opendir: ino=%" PRIu64 "\n", cfh->iref.ino); - return ceph_ll_opendir(cmount_of(handle), + return ceph_ll_opendir(config->mount, cfh->iref.inode, &cfh->dirp.cdr, cfh->uperm); @@ -856,19 +974,28 @@ static int vfs_ceph_ll_opendir(const struct vfs_handle_struct *handle, static struct dirent *vfs_ceph_ll_readdir(const struct vfs_handle_struct *hndl, const struct vfs_ceph_fh *dircfh) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(hndl, config, struct vfs_ceph_config, + return NULL); + DBG_DEBUG("[ceph] ceph_readdir: ino=%" PRIu64 " fd=%d\n", dircfh->iref.ino, dircfh->fd); - return ceph_readdir(cmount_of(hndl), dircfh->dirp.cdr); + return ceph_readdir(config->mount, dircfh->dirp.cdr); } static void vfs_ceph_ll_rewinddir(const struct vfs_handle_struct *handle, const struct vfs_ceph_fh *dircfh) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, return); + DBG_DEBUG("[ceph] ceph_rewinddir: ino=%" PRIu64 " fd=%d\n", dircfh->iref.ino, dircfh->fd); - ceph_rewinddir(cmount_of(handle), dircfh->dirp.cdr); + ceph_rewinddir(config->mount, dircfh->dirp.cdr); } static int vfs_ceph_ll_mkdirat(const struct vfs_handle_struct *handle, @@ -880,11 +1007,15 @@ static int vfs_ceph_ll_mkdirat(const struct vfs_handle_struct *handle, struct ceph_statx stx = {.stx_ino = 0}; struct Inode *inode = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_mkdir: parent-ino=%" PRIu64 " name=%s " "mode=%o\n", dircfh->iref.ino, name, mode); - ret = ceph_ll_mkdir(cmount_of(handle), + ret = ceph_ll_mkdir(config->mount, dircfh->iref.inode, name, mode, @@ -906,10 +1037,15 @@ static int vfs_ceph_ll_rmdir(const struct vfs_handle_struct *handle, const struct vfs_ceph_fh *dircfh, const char *name) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_rmdir: parent-ino=%" PRIu64 " name=%s\n", dircfh->iref.ino, name); - return ceph_ll_rmdir(cmount_of(handle), + return ceph_ll_rmdir(config->mount, dircfh->iref.inode, name, dircfh->uperm); @@ -919,10 +1055,15 @@ static int vfs_ceph_ll_unlinkat(const struct vfs_handle_struct *handle, const struct vfs_ceph_fh *dircfh, const char *name) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_unlink: parent-ino=%" PRIu64 " name=%s\n", dircfh->iref.ino, name); - return ceph_ll_unlink(cmount_of(handle), + return ceph_ll_unlink(config->mount, dircfh->iref.inode, name, dircfh->uperm); @@ -937,11 +1078,15 @@ static int vfs_ceph_ll_symlinkat(const struct vfs_handle_struct *handle, struct ceph_statx stx = {.stx_ino = 0}; struct Inode *inode = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_symlink: parent-ino=%" PRIu64 " name=%s\n", dircfh->iref.ino, name); - ret = ceph_ll_symlink(cmount_of(handle), + ret = ceph_ll_symlink(config->mount, dircfh->iref.inode, name, value, @@ -965,9 +1110,14 @@ static int vfs_ceph_ll_readlinkat(const struct vfs_handle_struct *handle, char *buf, size_t bsz) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_readlink: ino=%" PRIu64 "\n", iref->ino); - return ceph_ll_readlink(cmount_of(handle), + return ceph_ll_readlink(config->mount, iref->inode, buf, bsz, @@ -980,10 +1130,15 @@ static int vfs_ceph_ll_read(const struct vfs_handle_struct *handle, uint64_t len, char *buf) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_read: ino=%" PRIu64 " fd=%d off=%jd " "len=%ju\n", cfh->iref.ino, cfh->fd, off, len); - return ceph_ll_read(cmount_of(handle), cfh->fh, off, len, buf); + return ceph_ll_read(config->mount, cfh->fh, off, len, buf); } static int vfs_ceph_ll_write(const struct vfs_handle_struct *handle, @@ -992,10 +1147,15 @@ static int vfs_ceph_ll_write(const struct vfs_handle_struct *handle, uint64_t len, const char *data) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_write: ino=%" PRIu64 " fd=%d off=%jd " "len=%ju\n", cfh->iref.ino, cfh->fd, off, len); - return ceph_ll_write(cmount_of(handle), cfh->fh, off, len, data); + return ceph_ll_write(config->mount, cfh->fh, off, len, data); } static off_t vfs_ceph_ll_lseek(const struct vfs_handle_struct *handle, @@ -1003,20 +1163,30 @@ static off_t vfs_ceph_ll_lseek(const struct vfs_handle_struct *handle, off_t offset, int whence) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_lseek: ino=%" PRIu64 " fd=%d offset=%jd " "whence=%d\n", cfh->iref.ino, cfh->fd, offset, whence); - return ceph_ll_lseek(cmount_of(handle), cfh->fh, offset, whence); + return ceph_ll_lseek(config->mount, cfh->fh, offset, whence); } static int vfs_ceph_ll_fsync(const struct vfs_handle_struct *handle, const struct vfs_ceph_fh *cfh, int syncdataonly) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_fsync: ino=%" PRIu64 " fd=%d " "syncdataonly=%d\n", cfh->iref.ino, cfh->fd, syncdataonly); - return ceph_ll_fsync(cmount_of(handle), cfh->fh, syncdataonly); + return ceph_ll_fsync(config->mount, cfh->fh, syncdataonly); } static int vfs_ceph_ll_ftruncate(struct vfs_handle_struct *handle, @@ -1024,11 +1194,15 @@ static int vfs_ceph_ll_ftruncate(struct vfs_handle_struct *handle, int64_t size) { struct ceph_statx stx = {.stx_size = (uint64_t)size}; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_setattr: ino=%" PRIu64 " fd=%d size=%jd\n", cfh->iref.ino, cfh->fd, size); - return ceph_ll_setattr(cmount_of(handle), + return ceph_ll_setattr(config->mount, cfh->iref.inode, &stx, CEPH_SETATTR_SIZE, @@ -1041,10 +1215,15 @@ static int vfs_ceph_ll_fallocate(const struct vfs_handle_struct *handle, int64_t off, int64_t len) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_fallocate: ino=%" PRIu64 " fd=%d off=%jd " "len=%jd\n", cfh->iref.ino, cfh->fd, off, len); - return ceph_ll_fallocate(cmount_of(handle), cfh->fh, mode, off, len); + return ceph_ll_fallocate(config->mount, cfh->fh, mode, off, len); } static int vfs_ceph_ll_link(const struct vfs_handle_struct *handle, @@ -1052,10 +1231,15 @@ static int vfs_ceph_ll_link(const struct vfs_handle_struct *handle, const char *name, const struct vfs_ceph_iref *iref) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_link: parent-ino=%" PRIu64 " name=%s\n", dircfh->iref.ino, name); - return ceph_ll_link(cmount_of(handle), + return ceph_ll_link(config->mount, iref->inode, dircfh->iref.inode, name, @@ -1068,11 +1252,16 @@ static int vfs_ceph_ll_rename(const struct vfs_handle_struct *handle, const struct vfs_ceph_fh *newparent, const char *newname) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_rename: parent-ino=%" PRIu64 " name=%s newparent-ino=%" PRIu64 " newname=%s\n", parent->iref.ino, name, newparent->iref.ino, newname); - return ceph_ll_rename(cmount_of(handle), + return ceph_ll_rename(config->mount, parent->iref.inode, name, newparent->iref.inode, @@ -1090,11 +1279,15 @@ static int vfs_ceph_ll_mknod(const struct vfs_handle_struct *handle, struct ceph_statx stx = {.stx_ino = 0}; struct Inode *inode = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_mknod: parent-ino=%" PRIu64 " name=%s " "mode=%o\n", parent->iref.ino, name, mode); - ret = ceph_ll_mknod(cmount_of(handle), + ret = ceph_ll_mknod(config->mount, parent->iref.inode, name, mode, @@ -1120,6 +1313,10 @@ static int vfs_ceph_ll_getxattr(const struct vfs_handle_struct *handle, { struct UserPerm *uperm = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_getxattr: ino=%" PRIu64 " name=%s\n", iref->ino, name); @@ -1129,7 +1326,7 @@ static int vfs_ceph_ll_getxattr(const struct vfs_handle_struct *handle, return -ENOMEM; } - ret = ceph_ll_getxattr(cmount_of(handle), + ret = ceph_ll_getxattr(config->mount, iref->inode, name, value, @@ -1147,10 +1344,15 @@ static int vfs_ceph_ll_fgetxattr(const struct vfs_handle_struct *handle, void *value, size_t size) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_getxattr: ino=%" PRIu64 " name=%s\n", cfh->iref.ino, name); - return ceph_ll_getxattr(cmount_of(handle), + return ceph_ll_getxattr(config->mount, cfh->iref.inode, name, value, @@ -1167,6 +1369,10 @@ static int vfs_ceph_ll_setxattr(const struct vfs_handle_struct *handle, { struct UserPerm *uperm = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_setxattr: ino=%" PRIu64 " name=%s " "size=%zu\n", iref->ino, name, size); @@ -1176,7 +1382,7 @@ static int vfs_ceph_ll_setxattr(const struct vfs_handle_struct *handle, return -ENOMEM; } - ret = ceph_ll_setxattr(cmount_of(handle), + ret = ceph_ll_setxattr(config->mount, iref->inode, name, value, @@ -1196,10 +1402,15 @@ static int vfs_ceph_ll_fsetxattr(const struct vfs_handle_struct *handle, size_t size, int flags) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_setxattr: ino=%" PRIu64 " name=%s " "size=%zu\n", cfh->iref.ino, name, size); - return ceph_ll_setxattr(cmount_of(handle), + return ceph_ll_setxattr(config->mount, cfh->iref.inode, name, value, @@ -1216,6 +1427,10 @@ static int vfs_ceph_ll_listxattr(const struct vfs_handle_struct *handle, { struct UserPerm *uperm = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_listxattr: ino=%" PRIu64 "\n", iref->ino); @@ -1224,7 +1439,7 @@ static int vfs_ceph_ll_listxattr(const struct vfs_handle_struct *handle, return -ENOMEM; } - ret = ceph_ll_listxattr(cmount_of(handle), + ret = ceph_ll_listxattr(config->mount, iref->inode, list, buf_size, @@ -1242,9 +1457,14 @@ static int vfs_ceph_ll_flistxattr(const struct vfs_handle_struct *handle, size_t buf_size, size_t *list_size) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_listxattr: ino=%" PRIu64 "\n", cfh->iref.ino); - return ceph_ll_listxattr(cmount_of(handle), + return ceph_ll_listxattr(config->mount, cfh->iref.inode, list, buf_size, @@ -1258,6 +1478,10 @@ static int vfs_ceph_ll_removexattr(const struct vfs_handle_struct *handle, { struct UserPerm *uperm = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); DBG_DEBUG("[ceph] ceph_ll_removexattr: ino=%" PRIu64 " name=%s\n", iref->ino, name); @@ -1267,7 +1491,7 @@ static int vfs_ceph_ll_removexattr(const struct vfs_handle_struct *handle, return -ENOMEM; } - ret = ceph_ll_removexattr(cmount_of(handle), iref->inode, name, uperm); + ret = ceph_ll_removexattr(config->mount, iref->inode, name, uperm); vfs_ceph_userperm_del(uperm); @@ -1278,10 +1502,15 @@ static int vfs_ceph_ll_fremovexattr(const struct vfs_handle_struct *handle, const struct vfs_ceph_fh *cfh, const char *name) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[ceph] ceph_ll_removexattr: ino=%" PRIu64 " name=%s\n", cfh->iref.ino, name); - return ceph_ll_removexattr(cmount_of(handle), + return ceph_ll_removexattr(config->mount, cfh->iref.inode, name, cfh->uperm); @@ -1330,8 +1559,14 @@ static int vfs_ceph_iget_by_fname(const struct vfs_handle_struct *handle, struct vfs_ceph_iref *iref) { const char *name = smb_fname->base_name; - const char *cwd = ceph_getcwd(cmount_of(handle)); + const char *cwd = NULL; int ret = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + + cwd = ceph_getcwd(config->mount); if (!strcmp(name, cwd)) { ret = vfs_ceph_iget(handle, 0, "./", 0, iref); @@ -1393,9 +1628,14 @@ static void vfs_ceph_iput(const struct vfs_handle_struct *handle, struct vfs_ceph_iref *iref) { if ((iref != NULL) && (iref->inode != NULL) && iref->owner) { + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return); + DBG_DEBUG("[ceph] ceph_ll_put: ino=%" PRIu64 "\n", iref->ino); - ceph_ll_put(cmount_of(handle), iref->inode); + ceph_ll_put(config->mount, iref->inode); iref->inode = NULL; } } @@ -1411,15 +1651,19 @@ static uint64_t vfs_ceph_disk_free(struct vfs_handle_struct *handle, struct statvfs statvfs_buf = { 0 }; struct Inode *inode = NULL; int ret; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); - ret = ceph_ll_lookup_root(cmount_of(handle), &inode); + ret = ceph_ll_lookup_root(config->mount, &inode); if (ret != 0) { DBG_DEBUG("[CEPH] ceph_ll_lookup_root returned %d\n", ret); errno = -ret; return (uint64_t)(-1); } - ret = ceph_ll_statfs(cmount_of(handle), inode, &statvfs_buf); - ceph_ll_put(cmount_of(handle), inode); + ret = ceph_ll_statfs(config->mount, inode, &statvfs_buf); + ceph_ll_put(config->mount, inode); if (ret != 0) { DBG_DEBUG("[CEPH] ceph_ll_statfs returned %d\n", ret); errno = -ret; @@ -2247,8 +2491,13 @@ static int vfs_ceph_chdir(struct vfs_handle_struct *handle, const struct smb_filename *smb_fname) { int result = -1; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return -ENOMEM); + DBG_DEBUG("[CEPH] chdir(%p, %s)\n", handle, smb_fname->base_name); - result = ceph_chdir(cmount_of(handle), smb_fname->base_name); + result = ceph_chdir(config->mount, smb_fname->base_name); DBG_DEBUG("[CEPH] chdir(...) = %d\n", result); return status_code(result); } @@ -2256,7 +2505,13 @@ static int vfs_ceph_chdir(struct vfs_handle_struct *handle, static struct smb_filename *vfs_ceph_getwd(struct vfs_handle_struct *handle, TALLOC_CTX *ctx) { - const char *cwd = ceph_getcwd(cmount_of(handle)); + const char *cwd = NULL; + struct vfs_ceph_config *config = NULL; + + SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config, + return NULL); + + cwd = ceph_getcwd(config->mount); DBG_DEBUG("[CEPH] getwd(%p) = %s\n", handle, cwd); return synthetic_smb_fname(ctx, cwd, NULL, NULL, 0, 0); }