From a6e8f33901887e1bc8352a1fe37427c7cca2fbe2 Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 11:58:34 +0530 Subject: [PATCH 01/14] vfs_glusterfs: Accept fsp with const qualifier This is in preparation to avoid any `const` qualifier being discarded warning with future changes to various *_at() calls which has `const file_struct` arguments. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit 5f51fa9c07e194bcc3c4f39a1bfc2e01139c917b) --- source3/modules/vfs_glusterfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index dd05da0f9bb..92fc0a80e9f 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -606,7 +606,7 @@ static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct *handle, } static glfs_fd_t *vfs_gluster_fetch_glfd(struct vfs_handle_struct *handle, - files_struct *fsp) + const files_struct *fsp) { glfs_fd_t **glfd = (glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp); if (glfd == NULL) { -- 2.37.2 From b49fc6f6f1c5bfb176b767976b98256893346b0c Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 12:17:33 +0530 Subject: [PATCH 02/14] source3/wscript: Detect glusterfs-api with *at() calls support BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit 3425fa0daf9e32d09c7716692cdfdffdc09856d7) --- source3/wscript | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source3/wscript b/source3/wscript index 04c278bbe36..22be17a1a6f 100644 --- a/source3/wscript +++ b/source3/wscript @@ -1725,6 +1725,10 @@ main() { conf.CHECK_CFG(package='glusterfs-api', args='"glusterfs-api >= 7.9" --cflags --libs', msg='Checking for glusterfs-api >= 7.9', uselib_store="GFAPI_VER_7_9") + conf.CHECK_CFG(package='glusterfs-api', args='"glusterfs-api >= 7.11" --cflags --libs', + msg='Checking for glusterfs-api >= 7.11', + uselib_store="GFAPI_VER_7_11") + else: conf.SET_TARGET_TYPE('gfapi', 'EMPTY') conf.undefine('HAVE_GLUSTERFS') -- 2.37.2 From 5ba0ed21d4ec798870c0703bf8aa6bcc848a9811 Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 12:07:08 +0530 Subject: [PATCH 03/14] vfs_glusterfs: Use glfs_openat() for SMB_VFS_OPENAT BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit 184a9913241acd4f69128ced3370d3bf49b95f3b) --- source3/modules/vfs_glusterfs.c | 105 +++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 29 deletions(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 92fc0a80e9f..3503dfc251f 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -765,9 +765,12 @@ static int vfs_gluster_openat(struct vfs_handle_struct *handle, files_struct *fsp, const struct vfs_open_how *how) { - struct smb_filename *name = NULL; + int flags = how->flags; + struct smb_filename *full_fname = NULL; + bool have_opath = false; bool became_root = false; glfs_fd_t *glfd; + glfs_fd_t *pglfd = NULL; glfs_fd_t **p_tmp; START_PROFILE(syscall_openat); @@ -778,58 +781,103 @@ static int vfs_gluster_openat(struct vfs_handle_struct *handle, return -1; } - /* - * Looks like glfs API doesn't have openat(). - */ - if (fsp_get_pathref_fd(dirfsp) != AT_FDCWD) { - name = full_path_from_dirfsp_atname(talloc_tos(), - dirfsp, - smb_fname); - if (name == NULL) { - END_PROFILE(syscall_openat); - return -1; - } - smb_fname = name; - } - p_tmp = VFS_ADD_FSP_EXTENSION(handle, fsp, glfs_fd_t *, NULL); if (p_tmp == NULL) { - TALLOC_FREE(name); END_PROFILE(syscall_openat); errno = ENOMEM; return -1; } +#ifdef O_PATH + have_opath = true; if (fsp->fsp_flags.is_pathref) { - /* - * ceph doesn't support O_PATH so we have to fallback to - * become_root(). - */ + flags |= O_PATH; + } +#endif + + full_fname = full_path_from_dirfsp_atname(talloc_tos(), + dirfsp, + smb_fname); + if (full_fname == NULL) { + END_PROFILE(syscall_openat); + return -1; + } + + if (fsp->fsp_flags.is_pathref && !have_opath) { become_root(); became_root = true; } - if (how->flags & O_DIRECTORY) { - glfd = glfs_opendir(handle->data, smb_fname->base_name); - } else if (how->flags & O_CREAT) { + /* + * O_CREAT flag in open is handled differently in a way which is *NOT* + * safe against symlink race situations. We use glfs_creat() instead + * for correctness as glfs_openat() is broken with O_CREAT present + * in open flags. + */ + if (flags & O_CREAT) { + if (fsp_get_pathref_fd(dirfsp) != AT_FDCWD) { + /* + * Replace smb_fname with full_path constructed above. + */ + smb_fname = full_fname; + } + + /* + * smb_fname can either be a full_path or the same one + * as received from the caller. In the latter case we + * are operating at current working directory. + */ glfd = glfs_creat(handle->data, smb_fname->base_name, - how->flags, + flags, how->mode); } else { - glfd = glfs_open(handle->data, - smb_fname->base_name, - how->flags); + if (fsp_get_pathref_fd(dirfsp) != AT_FDCWD) { +#ifdef HAVE_GFAPI_VER_7_11 + /* + * Fetch Gluster fd for parent directory using dirfsp + * before calling glfs_openat(); + */ + pglfd = vfs_gluster_fetch_glfd(handle, dirfsp); + if (pglfd == NULL) { + END_PROFILE(syscall_openat); + DBG_ERR("Failed to fetch gluster fd\n"); + return -1; + } + + glfd = glfs_openat(pglfd, + smb_fname->base_name, + flags, + how->mode); +#else + /* + * Replace smb_fname with full_path constructed above. + */ + smb_fname = full_fname; +#endif + } + + if (pglfd == NULL) { + /* + * smb_fname can either be a full_path or the same one + * as received from the caller. In the latter case we + * are operating at current working directory. + */ + glfd = glfs_open(handle->data, + smb_fname->base_name, + flags); + } } if (became_root) { unbecome_root(); } + TALLOC_FREE(full_fname); + fsp->fsp_flags.have_proc_fds = false; if (glfd == NULL) { - TALLOC_FREE(name); END_PROFILE(syscall_openat); /* no extension destroy_fn, so no need to save errno */ VFS_REMOVE_FSP_EXTENSION(handle, fsp); @@ -838,7 +886,6 @@ static int vfs_gluster_openat(struct vfs_handle_struct *handle, *p_tmp = glfd; - TALLOC_FREE(name); END_PROFILE(syscall_openat); /* An arbitrary value for error reporting, so you know its us. */ return 13371337; -- 2.37.2 From f0f8bc62feefa807492d379e3df1a7e092adc953 Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 12:10:16 +0530 Subject: [PATCH 04/14] vfs_glusterfs: Use glfs_mkdirat() for SMB_VFS_MKDIRAT BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit 56c4aab11190b8d48a5b92babea7fc7e78b54b4e) --- source3/modules/vfs_glusterfs.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 3503dfc251f..ae11e81ad17 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -737,9 +737,24 @@ static int vfs_gluster_mkdirat(struct vfs_handle_struct *handle, const struct smb_filename *smb_fname, mode_t mode) { - struct smb_filename *full_fname = NULL; int ret; +#ifdef HAVE_GFAPI_VER_7_11 + glfs_fd_t *pglfd = NULL; + + START_PROFILE(syscall_mkdirat); + + pglfd = vfs_gluster_fetch_glfd(handle, dirfsp); + if (pglfd == NULL) { + END_PROFILE(syscall_mkdirat); + DBG_ERR("Failed to fetch gluster fd\n"); + return -1; + } + + ret = glfs_mkdirat(pglfd, smb_fname->base_name, mode); +#else + struct smb_filename *full_fname = NULL; + START_PROFILE(syscall_mkdirat); full_fname = full_path_from_dirfsp_atname(talloc_tos(), @@ -753,6 +768,7 @@ static int vfs_gluster_mkdirat(struct vfs_handle_struct *handle, ret = glfs_mkdir(handle->data, full_fname->base_name, mode); TALLOC_FREE(full_fname); +#endif END_PROFILE(syscall_mkdirat); -- 2.37.2 From f4421a5cd6317c0b52db766664cc10910f82766a Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 12:11:02 +0530 Subject: [PATCH 05/14] vfs_glusterfs: Use glfs_renameat() for SMB_VFS_RENAMEAT BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit 2b721ff22be04cea90086dde2a50f4287d075326) --- source3/modules/vfs_glusterfs.c | 34 ++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index ae11e81ad17..3d4a0af93b2 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -1305,9 +1305,33 @@ static int vfs_gluster_renameat(struct vfs_handle_struct *handle, files_struct *dstfsp, const struct smb_filename *smb_fname_dst) { + int ret; + +#ifdef HAVE_GFAPI_VER_7_11 + glfs_fd_t *src_pglfd = NULL; + glfs_fd_t *dst_pglfd = NULL; + + START_PROFILE(syscall_renameat); + + src_pglfd = vfs_gluster_fetch_glfd(handle, srcfsp); + if (src_pglfd == NULL) { + END_PROFILE(syscall_renameat); + DBG_ERR("Failed to fetch gluster fd\n"); + return -1; + } + + dst_pglfd = vfs_gluster_fetch_glfd(handle, dstfsp); + if (dst_pglfd == NULL) { + END_PROFILE(syscall_renameat); + DBG_ERR("Failed to fetch gluster fd\n"); + return -1; + } + + ret = glfs_renameat(src_pglfd, smb_fname_src->base_name, + dst_pglfd, smb_fname_dst->base_name); +#else struct smb_filename *full_fname_src = NULL; struct smb_filename *full_fname_dst = NULL; - int ret; START_PROFILE(syscall_renameat); @@ -1315,24 +1339,28 @@ static int vfs_gluster_renameat(struct vfs_handle_struct *handle, srcfsp, smb_fname_src); if (full_fname_src == NULL) { - errno = ENOMEM; END_PROFILE(syscall_renameat); + errno = ENOMEM; return -1; } + full_fname_dst = full_path_from_dirfsp_atname(talloc_tos(), dstfsp, smb_fname_dst); if (full_fname_dst == NULL) { + END_PROFILE(syscall_renameat); TALLOC_FREE(full_fname_src); errno = ENOMEM; - END_PROFILE(syscall_renameat); return -1; } ret = glfs_rename(handle->data, full_fname_src->base_name, full_fname_dst->base_name); + TALLOC_FREE(full_fname_src); TALLOC_FREE(full_fname_dst); +#endif + END_PROFILE(syscall_renameat); return ret; -- 2.37.2 From 88ba287a05a79ef55011e4a61d3d59761ae43187 Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 12:11:54 +0530 Subject: [PATCH 06/14] vfs_glusterfs: Use glfs_unlinkat() for SMB_VFS_UNLINKAT BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit 2fa71202ab347fd057bb9b42740e57344e2679e1) --- source3/modules/vfs_glusterfs.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 3d4a0af93b2..dfed5c739cc 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -1581,9 +1581,24 @@ static int vfs_gluster_unlinkat(struct vfs_handle_struct *handle, const struct smb_filename *smb_fname, int flags) { - struct smb_filename *full_fname = NULL; int ret; +#ifdef HAVE_GFAPI_VER_7_11 + glfs_fd_t *pglfd = NULL; + + START_PROFILE(syscall_unlinkat); + + pglfd = vfs_gluster_fetch_glfd(handle, dirfsp); + if (pglfd == NULL) { + END_PROFILE(syscall_unlinkat); + DBG_ERR("Failed to fetch gluster fd\n"); + return -1; + } + + ret = glfs_unlinkat(pglfd, smb_fname->base_name, flags); +#else + struct smb_filename *full_fname = NULL; + START_PROFILE(syscall_unlinkat); full_fname = full_path_from_dirfsp_atname(talloc_tos(), @@ -1599,7 +1614,10 @@ static int vfs_gluster_unlinkat(struct vfs_handle_struct *handle, } else { ret = glfs_unlink(handle->data, full_fname->base_name); } + TALLOC_FREE(full_fname); +#endif + END_PROFILE(syscall_unlinkat); return ret; -- 2.37.2 From 2056bf34b944711175404014bda1e4ca1b2a88ef Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 12:12:43 +0530 Subject: [PATCH 07/14] vfs_glusterfs: Use glfs_symlinkat() for SMB_VFS_SYMLINKAT BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit b2746eb5fa64e0ec58e99eed5be10c98ea4e1c1e) --- source3/modules/vfs_glusterfs.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index dfed5c739cc..808dc72f902 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -2017,24 +2017,42 @@ static int vfs_gluster_symlinkat(struct vfs_handle_struct *handle, struct files_struct *dirfsp, const struct smb_filename *new_smb_fname) { - struct smb_filename *full_fname = NULL; int ret; +#ifdef HAVE_GFAPI_VER_7_11 + glfs_fd_t *pglfd = NULL; + + START_PROFILE(syscall_symlinkat); + + pglfd = vfs_gluster_fetch_glfd(handle, dirfsp); + if (pglfd == NULL) { + END_PROFILE(syscall_symlinkat); + DBG_ERR("Failed to fetch gluster fd\n"); + return -1; + } + + ret = glfs_symlinkat(link_target->base_name, + pglfd, + new_smb_fname->base_name); +#else + struct smb_filename *full_fname = NULL; + START_PROFILE(syscall_symlinkat); full_fname = full_path_from_dirfsp_atname(talloc_tos(), - dirfsp, - new_smb_fname); + dirfsp, + new_smb_fname); if (full_fname == NULL) { END_PROFILE(syscall_symlinkat); return -1; } ret = glfs_symlink(handle->data, - link_target->base_name, - full_fname->base_name); + link_target->base_name, + full_fname->base_name); TALLOC_FREE(full_fname); +#endif END_PROFILE(syscall_symlinkat); -- 2.37.2 From 505316c5e328cbada99ef6d9e073bfc3488f78d0 Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 12:13:33 +0530 Subject: [PATCH 08/14] vfs_glusterfs: Use glfs_readlinkat() for SMB_VFS_READLINKAT BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit 58b6cdabc0c3d788b407d3bfa46570311e910180) --- source3/modules/vfs_glusterfs.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 808dc72f902..1f2aab256ed 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -2065,14 +2065,29 @@ static int vfs_gluster_readlinkat(struct vfs_handle_struct *handle, char *buf, size_t bufsiz) { - struct smb_filename *full_fname = NULL; int ret; +#ifdef HAVE_GFAPI_VER_7_11 + glfs_fd_t *pglfd = NULL; + + START_PROFILE(syscall_readlinkat); + + pglfd = vfs_gluster_fetch_glfd(handle, dirfsp); + if (pglfd == NULL) { + END_PROFILE(syscall_readlinkat); + DBG_ERR("Failed to fetch gluster fd\n"); + return -1; + } + + ret = glfs_readlinkat(pglfd, smb_fname->base_name, buf, bufsiz); +#else + struct smb_filename *full_fname = NULL; + START_PROFILE(syscall_readlinkat); full_fname = full_path_from_dirfsp_atname(talloc_tos(), - dirfsp, - smb_fname); + dirfsp, + smb_fname); if (full_fname == NULL) { END_PROFILE(syscall_readlinkat); return -1; @@ -2081,6 +2096,7 @@ static int vfs_gluster_readlinkat(struct vfs_handle_struct *handle, ret = glfs_readlink(handle->data, full_fname->base_name, buf, bufsiz); TALLOC_FREE(full_fname); +#endif END_PROFILE(syscall_readlinkat); -- 2.37.2 From cbe4eecb069ac83102add9f15663da833e2c70dc Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 12:14:29 +0530 Subject: [PATCH 09/14] vfs_glusterfs: Use glfs_linkat() for SMB_VFS_LINKAT BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit 21654af5a5a062d831f7cb1efec1f1b1eb333bd2) --- source3/modules/vfs_glusterfs.c | 40 ++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 1f2aab256ed..b2de957d1c7 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -2111,24 +2111,52 @@ static int vfs_gluster_linkat(struct vfs_handle_struct *handle, int flags) { int ret; + +#ifdef HAVE_GFAPI_VER_7_11 + glfs_fd_t *src_pglfd = NULL; + glfs_fd_t *dst_pglfd = NULL; + + START_PROFILE(syscall_linkat); + + src_pglfd = vfs_gluster_fetch_glfd(handle, srcfsp); + if (src_pglfd == NULL) { + END_PROFILE(syscall_linkat); + DBG_ERR("Failed to fetch gluster fd\n"); + return -1; + } + + dst_pglfd = vfs_gluster_fetch_glfd(handle, dstfsp); + if (dst_pglfd == NULL) { + END_PROFILE(syscall_linkat); + DBG_ERR("Failed to fetch gluster fd\n"); + return -1; + } + + ret = glfs_linkat(src_pglfd, + old_smb_fname->base_name, + dst_pglfd, + new_smb_fname->base_name, + flags); +#else struct smb_filename *full_fname_old = NULL; struct smb_filename *full_fname_new = NULL; START_PROFILE(syscall_linkat); full_fname_old = full_path_from_dirfsp_atname(talloc_tos(), - srcfsp, - old_smb_fname); + srcfsp, + old_smb_fname); if (full_fname_old == NULL) { END_PROFILE(syscall_linkat); return -1; } + full_fname_new = full_path_from_dirfsp_atname(talloc_tos(), - dstfsp, - new_smb_fname); + dstfsp, + new_smb_fname); if (full_fname_new == NULL) { - TALLOC_FREE(full_fname_old); END_PROFILE(syscall_linkat); + TALLOC_FREE(full_fname_old); return -1; } @@ -2138,6 +2166,8 @@ static int vfs_gluster_linkat(struct vfs_handle_struct *handle, TALLOC_FREE(full_fname_old); TALLOC_FREE(full_fname_new); +#endif + END_PROFILE(syscall_linkat); return ret; -- 2.37.2 From b3a7bf5fa211e0917fdd7677d677231855544a04 Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 12:15:10 +0530 Subject: [PATCH 10/14] vfs_glusterfs: Use glfs_mknodat() for SMB_VFS_MKNODAT BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit a4235200383fa4dc2f376ce042ed067a45f105d5) --- source3/modules/vfs_glusterfs.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index b2de957d1c7..bfcf85007c0 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -2179,14 +2179,29 @@ static int vfs_gluster_mknodat(struct vfs_handle_struct *handle, mode_t mode, SMB_DEV_T dev) { - struct smb_filename *full_fname = NULL; int ret; +#ifdef HAVE_GFAPI_VER_7_11 + glfs_fd_t *pglfd = NULL; + + START_PROFILE(syscall_mknodat); + + pglfd = vfs_gluster_fetch_glfd(handle, dirfsp); + if (pglfd == NULL) { + END_PROFILE(syscall_mknodat); + DBG_ERR("Failed to fetch gluster fd\n"); + return -1; + } + + ret = glfs_mknodat(pglfd, smb_fname->base_name, mode, dev); +#else + struct smb_filename *full_fname = NULL; + START_PROFILE(syscall_mknodat); full_fname = full_path_from_dirfsp_atname(talloc_tos(), - dirfsp, - smb_fname); + dirfsp, + smb_fname); if (full_fname == NULL) { END_PROFILE(syscall_mknodat); return -1; @@ -2195,6 +2210,7 @@ static int vfs_gluster_mknodat(struct vfs_handle_struct *handle, ret = glfs_mknod(handle->data, full_fname->base_name, mode, dev); TALLOC_FREE(full_fname); +#endif END_PROFILE(syscall_mknodat); -- 2.37.2 From cd6bb1123eb1ba6e0e1e9c21899b41a9362fc4a8 Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 12:51:16 +0530 Subject: [PATCH 11/14] vfs_glusterfs: Use glfs_symlinkat() for SMB_VFS_CREATE_DFS_PATHAT BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit 310a908098b4ff3130a61594c15e91d5e561f357) --- source3/modules/vfs_glusterfs.c | 35 +++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index bfcf85007c0..c47089d5d4d 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -2403,14 +2403,11 @@ static NTSTATUS vfs_gluster_create_dfs_pathat(struct vfs_handle_struct *handle, NTSTATUS status = NT_STATUS_NO_MEMORY; int ret; char *msdfs_link = NULL; +#ifdef HAVE_GFAPI_VER_7_11 + glfs_fd_t *pglfd = NULL; +#else struct smb_filename *full_fname = NULL; - - full_fname = full_path_from_dirfsp_atname(talloc_tos(), - dirfsp, - smb_fname); - if (full_fname == NULL) { - goto out; - } +#endif /* Form the msdfs_link contents */ msdfs_link = msdfs_link_string(frame, @@ -2420,9 +2417,27 @@ static NTSTATUS vfs_gluster_create_dfs_pathat(struct vfs_handle_struct *handle, goto out; } - ret = glfs_symlink(handle->data, - msdfs_link, - full_fname->base_name); +#ifdef HAVE_GFAPI_VER_7_11 + pglfd = vfs_gluster_fetch_glfd(handle, dirfsp); + if (pglfd == NULL) { + DBG_ERR("Failed to fetch gluster fd\n"); + status = NT_STATUS_OBJECT_NAME_NOT_FOUND; + goto out; + } + + ret = glfs_symlinkat(msdfs_link, pglfd, smb_fname->base_name); +#else + full_fname = full_path_from_dirfsp_atname(talloc_tos(), + dirfsp, + smb_fname); + if (full_fname == NULL) { + goto out; + } + + ret = glfs_symlink(handle->data, msdfs_link, full_fname->base_name); + + TALLOC_FREE(full_fname); +#endif if (ret == 0) { status = NT_STATUS_OK; } else { -- 2.37.2 From 7cd252e95d32e3a7c477873db5374d8786720d13 Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 13:08:42 +0530 Subject: [PATCH 12/14] vfs_glusterfs: Use glfs_readlinkat() for SMB_VFS_READ_DFS_PATHAT BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit 55548d7405ceca1d20e788a459e685c56f2ff139) --- source3/modules/vfs_glusterfs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index c47089d5d4d..1ecf21387a2 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -2479,6 +2479,9 @@ static NTSTATUS vfs_gluster_read_dfs_pathat(struct vfs_handle_struct *handle, struct stat st; struct smb_filename *full_fname = NULL; int ret; +#ifdef HAVE_GFAPI_VER_7_11 + glfs_fd_t *pglfd = NULL; +#endif if (is_named_stream(smb_fname)) { status = NT_STATUS_OBJECT_NAME_NOT_FOUND; @@ -2514,10 +2517,23 @@ static NTSTATUS vfs_gluster_read_dfs_pathat(struct vfs_handle_struct *handle, goto err; } +#ifdef HAVE_GFAPI_VER_7_11 + pglfd = vfs_gluster_fetch_glfd(handle, dirfsp); + if (pglfd == NULL) { + DBG_ERR("Failed to fetch gluster fd\n"); + return NT_STATUS_OBJECT_NAME_NOT_FOUND; + } + + referral_len = glfs_readlinkat(pglfd, + smb_fname->base_name, + link_target, + bufsize - 1); +#else referral_len = glfs_readlink(handle->data, full_fname->base_name, link_target, bufsize - 1); +#endif if (referral_len < 0) { if (errno == EINVAL) { DBG_INFO("%s is not a link.\n", full_fname->base_name); -- 2.37.2 From 69087c2627c2c984635da4f33ae303f67dd7feae Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Fri, 19 Aug 2022 12:16:08 +0530 Subject: [PATCH 13/14] vfs_glusterfs: Use glfs_fgetxattr() for SMB_VFS_GET_REAL_FILENAME_AT BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison (cherry picked from commit 65f4c4e31e4cc60eb9ebca3858275a29f43d5e12) --- source3/modules/vfs_glusterfs.c | 46 ++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 1ecf21387a2..3c309028c89 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -2235,10 +2235,29 @@ static NTSTATUS vfs_gluster_get_real_filename_at( int ret; char key_buf[GLUSTER_NAME_MAX + 64]; char val_buf[GLUSTER_NAME_MAX + 1]; - NTSTATUS status = NT_STATUS_OK; +#ifdef HAVE_GFAPI_VER_7_11 + glfs_fd_t *pglfd = NULL; +#else struct smb_filename *smb_fname_dot = NULL; struct smb_filename *full_fname = NULL; +#endif + + if (strlen(name) >= GLUSTER_NAME_MAX) { + return NT_STATUS_OBJECT_NAME_INVALID; + } + + snprintf(key_buf, GLUSTER_NAME_MAX + 64, + "glusterfs.get_real_filename:%s", name); +#ifdef HAVE_GFAPI_VER_7_11 + pglfd = vfs_gluster_fetch_glfd(handle, dirfsp); + if (pglfd == NULL) { + DBG_ERR("Failed to fetch gluster fd\n"); + return NT_STATUS_OBJECT_NAME_NOT_FOUND; + } + + ret = glfs_fgetxattr(pglfd, key_buf, val_buf, GLUSTER_NAME_MAX + 1); +#else smb_fname_dot = synthetic_smb_fname(mem_ctx, ".", NULL, @@ -2257,35 +2276,26 @@ static NTSTATUS vfs_gluster_get_real_filename_at( return NT_STATUS_NO_MEMORY; } - if (strlen(name) >= GLUSTER_NAME_MAX) { - status = NT_STATUS_OBJECT_NAME_INVALID; - goto out; - } - - snprintf(key_buf, GLUSTER_NAME_MAX + 64, - "glusterfs.get_real_filename:%s", name); - ret = glfs_getxattr(handle->data, full_fname->base_name, key_buf, val_buf, GLUSTER_NAME_MAX + 1); + + TALLOC_FREE(smb_fname_dot); + TALLOC_FREE(full_fname); +#endif + if (ret == -1) { if (errno == ENOATTR) { errno = ENOENT; } - status = map_nt_error_from_unix(errno); - goto out; + return map_nt_error_from_unix(errno); } *found_name = talloc_strdup(mem_ctx, val_buf); if (found_name[0] == NULL) { - status = NT_STATUS_NO_MEMORY; - goto out; + return NT_STATUS_NO_MEMORY; } -out: - TALLOC_FREE(smb_fname_dot); - TALLOC_FREE(full_fname); - - return status; + return NT_STATUS_OK; } static const char *vfs_gluster_connectpath(struct vfs_handle_struct *handle, -- 2.37.2 From c8bfafd39819d2e4508f652a2d28829d2247e59c Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Wed, 24 Aug 2022 15:01:31 +0530 Subject: [PATCH 14/14] vfs_glusterfs: Implement SMB_VFS_FSTATAT BUG: https://bugzilla.samba.org/show_bug.cgi?id=15157 Signed-off-by: Anoop C S Reviewed-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Fri Aug 26 17:33:15 UTC 2022 on sn-devel-184 (cherry picked from commit b7c460b902800c0156385b2edb82efb07f561c51) --- source3/modules/vfs_glusterfs.c | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 3c309028c89..e2f9fbd8bd4 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -1543,6 +1543,55 @@ static int vfs_gluster_fstat(struct vfs_handle_struct *handle, return ret; } +static int vfs_gluster_fstatat(struct vfs_handle_struct *handle, + const struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + SMB_STRUCT_STAT *sbuf, + int flags) +{ + struct stat st; + int ret; + +#ifdef HAVE_GFAPI_VER_7_11 + glfs_fd_t *pglfd = NULL; + + START_PROFILE(syscall_fstatat); + + pglfd = vfs_gluster_fetch_glfd(handle, dirfsp); + if (pglfd == NULL) { + END_PROFILE(syscall_fstatat); + DBG_ERR("Failed to fetch gluster fd\n"); + return -1; + } + + ret = glfs_fstatat(pglfd, smb_fname->base_name, &st, flags); +#else + struct smb_filename *full_fname = NULL; + + START_PROFILE(syscall_fstatat); + + full_fname = full_path_from_dirfsp_atname(talloc_tos(), + dirfsp, + smb_fname); + if (full_fname == NULL) { + END_PROFILE(syscall_fstatat); + return -1; + } + + ret = glfs_stat(handle->data, full_fname->base_name, &st); + + TALLOC_FREE(full_fname->base_name); +#endif + + if (ret == 0) { + smb_stat_ex_from_stat(sbuf, &st); + } + + END_PROFILE(syscall_fstatat); + + return ret; +} + static int vfs_gluster_lstat(struct vfs_handle_struct *handle, struct smb_filename *smb_fname) { @@ -2641,6 +2690,7 @@ static struct vfs_fn_pointers glusterfs_fns = { .stat_fn = vfs_gluster_stat, .fstat_fn = vfs_gluster_fstat, + .fstatat_fn = vfs_gluster_fstatat, .lstat_fn = vfs_gluster_lstat, .get_alloc_size_fn = vfs_gluster_get_alloc_size, .unlinkat_fn = vfs_gluster_unlinkat, -- 2.37.2