From: Volker Lendecke Date: Tue, 5 Apr 2022 13:32:08 +0000 (+0200) Subject: streams_depot: Simplify stream_dir() X-Git-Tag: tevent-0.12.0~149 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a27bbfc8a961968976649aa4db71b37a0db98b38;p=thirdparty%2Fsamba.git streams_depot: Simplify stream_dir() The only place where we could have entered the mark_valid() code path is via openat(). In openat(":stream") with O_CREAT fsp->base_fsp() is fully opened from within create_file_unixpath(). Change streams_depot_openat() to call the FSETXATTR from mark_file_valid() directly. This means we don't need the expensive synthetic_pathref() call from stream_dir() anymore. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Wed Apr 6 17:09:59 UTC 2022 on sn-devel-184 --- diff --git a/source3/modules/vfs_streams_depot.c b/source3/modules/vfs_streams_depot.c index f129b6101c2..107543f6bbc 100644 --- a/source3/modules/vfs_streams_depot.c +++ b/source3/modules/vfs_streams_depot.c @@ -110,25 +110,6 @@ static bool file_is_valid(vfs_handle_struct *handle, return true; } -static bool mark_file_valid(vfs_handle_struct *handle, - const struct smb_filename *smb_fname) -{ - char buf = '1'; - int ret; - - DEBUG(10, ("marking file %s as valid\n", smb_fname->base_name)); - - ret = SMB_VFS_FSETXATTR(smb_fname->fsp, SAMBA_XATTR_MARKER, - &buf, sizeof(buf), 0); - - if (ret == -1) { - DEBUG(10, ("SETXATTR failed: %s\n", strerror(errno))); - return false; - } - - return true; -} - /* * Return the root of the stream directory. Can be * external to the share definition but by default @@ -183,8 +164,6 @@ static char *stream_dir(vfs_handle_struct *handle, char *rootdir = NULL; struct smb_filename *rootdir_fname = NULL; struct smb_filename *tmp_fname = NULL; - struct smb_filename *tmpref = NULL; - const struct smb_filename *pathref = NULL; int ret; check_valid = lp_parm_bool(SNUM(handle->conn), @@ -424,27 +403,7 @@ static char *stream_dir(vfs_handle_struct *handle, if ((ret != 0) && (errno != EEXIST)) { goto fail; } - pathref = smb_fname; - if (smb_fname->fsp == NULL) { - NTSTATUS status; - status = synthetic_pathref(talloc_tos(), - handle->conn->cwd_fsp, - smb_fname->base_name, - NULL, - NULL, - smb_fname->twrp, - smb_fname->flags, - &tmpref); - if (!NT_STATUS_IS_OK(status)) { - goto fail; - } - pathref = tmpref; - } - if (check_valid && !mark_file_valid(handle, pathref)) { - goto fail; - } - TALLOC_FREE(tmpref); TALLOC_FREE(rootdir_fname); TALLOC_FREE(rootdir); TALLOC_FREE(tmp_fname); @@ -452,7 +411,6 @@ static char *stream_dir(vfs_handle_struct *handle, return result; fail: - TALLOC_FREE(tmpref); TALLOC_FREE(rootdir_fname); TALLOC_FREE(rootdir); TALLOC_FREE(tmp_fname); @@ -743,6 +701,34 @@ static int streams_depot_openat(struct vfs_handle_struct *handle, goto done; } + if (create_it) { + bool check_valid = lp_parm_bool( + SNUM(handle->conn), + "streams_depot", + "check_valid", + true); + + if (check_valid) { + char buf = '1'; + + DBG_DEBUG("marking file %s as valid\n", + fsp->base_fsp->fsp_name->base_name); + + ret = SMB_VFS_FSETXATTR( + fsp->base_fsp, + SAMBA_XATTR_MARKER, + &buf, + sizeof(buf), + 0); + + if (ret == -1) { + DBG_DEBUG("FSETXATTR failed: %s\n", + strerror(errno)); + return -1; + } + } + } + status = vfs_at_fspcwd(talloc_tos(), handle->conn, &fspcwd); if (!NT_STATUS_IS_OK(status)) { ret = -1;