From d1eb40192bad8ecb6781f7ab99cc34345578f3a3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Apr 2018 16:59:02 -0700 Subject: [PATCH 1/3] s3: VFS: Add a synchronous smb_vfs_fsync_sync() call, built from async primitives. Will be used in the next commit. Signed-off-by: Jeremy Allison --- source3/include/vfs.h | 1 + source3/smbd/vfs.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/source3/include/vfs.h b/source3/include/vfs.h index bb4a135e41e..a31cb5aeaf2 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -1217,6 +1217,7 @@ struct tevent_req *smb_vfs_call_fsync_send(struct vfs_handle_struct *handle, struct files_struct *fsp); int SMB_VFS_FSYNC_RECV(struct tevent_req *req, struct vfs_aio_state *state); +int smb_vfs_fsync_sync(files_struct *fsp); int smb_vfs_call_stat(struct vfs_handle_struct *handle, struct smb_filename *smb_fname); int smb_vfs_call_fstat(struct vfs_handle_struct *handle, diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index 59702203612..b29a5c54acc 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -1988,6 +1988,45 @@ int SMB_VFS_FSYNC_RECV(struct tevent_req *req, struct vfs_aio_state *vfs_aio_sta return state->retval; } +/* + * Synchronous version of fsync, built from backend + * async VFS primitives. Uses a temporary sub-event + * context (NOT NESTED). + */ + +int smb_vfs_fsync_sync(files_struct *fsp) +{ + TALLOC_CTX *frame = talloc_stackframe(); + struct tevent_req *req = NULL; + struct vfs_aio_state aio_state = { 0 }; + int ret = -1; + bool ok; + struct tevent_context *ev = samba_tevent_context_init(frame); + + if (ev == NULL) { + goto out; + } + + req = SMB_VFS_FSYNC_SEND(talloc_tos(), ev, fsp); + if (req == NULL) { + goto out; + } + + ok = tevent_req_poll(req, ev); + if (!ok) { + goto out; + } + + ret = SMB_VFS_FSYNC_RECV(req, &aio_state); + + out: + + TALLOC_FREE(frame); + if (aio_state.error != 0) { + errno = aio_state.error; + } + return ret; +} int smb_vfs_call_stat(struct vfs_handle_struct *handle, struct smb_filename *smb_fname) -- 2.17.0.441.gb46fe60e1d-goog From 9e83562d62f67b3f1c4e23ef5a975ded0439c257 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Apr 2018 16:59:42 -0700 Subject: [PATCH 2/3] s3: vfs: Use the new smb_vfs_fsync_sync() call in place of SMB_VFS_FSYNC(). Signed-off-by: Jeremy Allison --- source3/smbd/fileio.c | 2 +- source3/torture/cmd_vfs.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c index ec6333eaa10..7b17889b55c 100644 --- a/source3/smbd/fileio.c +++ b/source3/smbd/fileio.c @@ -1057,7 +1057,7 @@ NTSTATUS sync_file(connection_struct *conn, files_struct *fsp, bool write_throug if (ret == -1) { return map_nt_error_from_unix(errno); } - ret = SMB_VFS_FSYNC(fsp); + ret = smb_vfs_fsync_sync(fsp); if (ret == -1) { return map_nt_error_from_unix(errno); } diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c index 034136f3d23..3ae788e7bd9 100644 --- a/source3/torture/cmd_vfs.c +++ b/source3/torture/cmd_vfs.c @@ -640,7 +640,6 @@ static NTSTATUS cmd_rename(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, return NT_STATUS_OK; } - static NTSTATUS cmd_fsync(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv) { int ret, fd; @@ -650,7 +649,7 @@ static NTSTATUS cmd_fsync(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, } fd = atoi(argv[1]); - ret = SMB_VFS_FSYNC(vfs->files[fd]); + ret = smb_vfs_fsync_sync(vfs->files[fd]); if (ret == -1) { printf("fsync: error=%d (%s)\n", errno, strerror(errno)); return NT_STATUS_UNSUCCESSFUL; -- 2.17.0.441.gb46fe60e1d-goog From 64ee87c5033b86939546b824d8af7a364803c8b6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Apr 2018 17:06:10 -0700 Subject: [PATCH 3/3] s3: VFS: Remove fsync_fn() from the VFS and all modules. VFS ABI change. Signed-off-by: Jeremy Allison --- examples/VFS/skel_opaque.c | 7 ------- examples/VFS/skel_transparent.c | 6 ------ source3/include/vfs.h | 7 +++---- source3/modules/vfs_catia.c | 18 ------------------ source3/modules/vfs_ceph.c | 9 --------- source3/modules/vfs_default.c | 15 --------------- source3/modules/vfs_full_audit.c | 13 ------------- source3/modules/vfs_glusterfs.c | 7 ------- source3/modules/vfs_streams_xattr.c | 13 ------------- source3/modules/vfs_time_audit.c | 19 ------------------- source3/smbd/vfs.c | 7 ------- 11 files changed, 3 insertions(+), 118 deletions(-) diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c index e6c066d2eb8..41215ccf911 100644 --- a/examples/VFS/skel_opaque.c +++ b/examples/VFS/skel_opaque.c @@ -311,12 +311,6 @@ static int skel_rename(vfs_handle_struct *handle, return -1; } -static int skel_fsync(vfs_handle_struct *handle, files_struct *fsp) -{ - errno = ENOSYS; - return -1; -} - static struct tevent_req *skel_fsync_send(struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, struct tevent_context *ev, @@ -967,7 +961,6 @@ struct vfs_fn_pointers skel_opaque_fns = { .sendfile_fn = skel_sendfile, .recvfile_fn = skel_recvfile, .rename_fn = skel_rename, - .fsync_fn = skel_fsync, .fsync_send_fn = skel_fsync_send, .fsync_recv_fn = skel_fsync_recv, .stat_fn = skel_stat, diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c index 59d16340025..7a82a55a2af 100644 --- a/examples/VFS/skel_transparent.c +++ b/examples/VFS/skel_transparent.c @@ -388,11 +388,6 @@ static int skel_rename(vfs_handle_struct *handle, return SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst); } -static int skel_fsync(vfs_handle_struct *handle, files_struct *fsp) -{ - return SMB_VFS_NEXT_FSYNC(handle, fsp); -} - struct skel_fsync_state { int ret; struct vfs_aio_state vfs_aio_state; @@ -1140,7 +1135,6 @@ struct vfs_fn_pointers skel_transparent_fns = { .sendfile_fn = skel_sendfile, .recvfile_fn = skel_recvfile, .rename_fn = skel_rename, - .fsync_fn = skel_fsync, .fsync_send_fn = skel_fsync_send, .fsync_recv_fn = skel_fsync_recv, .stat_fn = skel_stat, diff --git a/source3/include/vfs.h b/source3/include/vfs.h index a31cb5aeaf2..6f940edeeaa 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -245,8 +245,10 @@ /* Version 37 - Rename SMB_VFS_STRICT_LOCK to SMB_VFS_STRICT_LOCK_CHECK */ /* Version 38 - Remove SMB_VFS_INIT_SEARCH_OP */ +/* Version 39 - Remove SMB_VFS_FSYNC + Only implement async versions. */ -#define SMB_VFS_INTERFACE_VERSION 38 +#define SMB_VFS_INTERFACE_VERSION 39 /* All intercepted VFS operations must be declared as static functions inside module source @@ -707,7 +709,6 @@ struct vfs_fn_pointers { int (*rename_fn)(struct vfs_handle_struct *handle, const struct smb_filename *smb_fname_src, const struct smb_filename *smb_fname_dst); - int (*fsync_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp); struct tevent_req *(*fsync_send_fn)(struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, struct tevent_context *ev, @@ -1208,8 +1209,6 @@ ssize_t smb_vfs_call_recvfile(struct vfs_handle_struct *handle, int fromfd, int smb_vfs_call_rename(struct vfs_handle_struct *handle, const struct smb_filename *smb_fname_src, const struct smb_filename *smb_fname_dst); -int smb_vfs_call_fsync(struct vfs_handle_struct *handle, - struct files_struct *fsp); struct tevent_req *smb_vfs_call_fsync_send(struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, diff --git a/source3/modules/vfs_catia.c b/source3/modules/vfs_catia.c index 6f90c4d97bc..b8c61e26ab8 100644 --- a/source3/modules/vfs_catia.c +++ b/source3/modules/vfs_catia.c @@ -2078,23 +2078,6 @@ static off_t catia_lseek(vfs_handle_struct *handle, return result; } -static int catia_fsync(vfs_handle_struct *handle, files_struct *fsp) -{ - struct catia_cache *cc = NULL; - int ret; - - ret = CATIA_FETCH_FSP_PRE_NEXT(talloc_tos(), handle, fsp, &cc); - if (ret != 0) { - return -1; - } - - ret = SMB_VFS_NEXT_FSYNC(handle, fsp); - - CATIA_FETCH_FSP_POST_NEXT(&cc, fsp); - - return ret; -} - struct catia_fsync_state { int ret; struct vfs_aio_state vfs_aio_state; @@ -2495,7 +2478,6 @@ static struct vfs_fn_pointers vfs_catia_fns = { .pwrite_recv_fn = catia_pwrite_recv, .lseek_fn = catia_lseek, .rename_fn = catia_rename, - .fsync_fn = catia_fsync, .fsync_send_fn = catia_fsync_send, .fsync_recv_fn = catia_fsync_recv, .stat_fn = catia_stat, diff --git a/source3/modules/vfs_ceph.c b/source3/modules/vfs_ceph.c index 656ce57009f..2062fe47462 100644 --- a/source3/modules/vfs_ceph.c +++ b/source3/modules/vfs_ceph.c @@ -562,14 +562,6 @@ static int cephwrap_rename(struct vfs_handle_struct *handle, WRAP_RETURN(result); } -static int cephwrap_fsync(struct vfs_handle_struct *handle, files_struct *fsp) -{ - int result; - DBG_DEBUG("[CEPH] cephwrap_fsync\n"); - result = ceph_fsync(handle->data, fsp->fh->fd, false); - WRAP_RETURN(result); -} - /* * Fake up an async ceph fsync by calling the sychronous API. */ @@ -1490,7 +1482,6 @@ static struct vfs_fn_pointers ceph_fns = { .sendfile_fn = cephwrap_sendfile, .recvfile_fn = cephwrap_recvfile, .rename_fn = cephwrap_rename, - .fsync_fn = cephwrap_fsync, .fsync_send_fn = cephwrap_fsync_send, .fsync_recv_fn = cephwrap_fsync_recv, .stat_fn = cephwrap_stat, diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index e2efdabf47c..6de0329b337 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -1127,20 +1127,6 @@ static int vfswrap_rename(vfs_handle_struct *handle, return result; } -static int vfswrap_fsync(vfs_handle_struct *handle, files_struct *fsp) -{ -#ifdef HAVE_FSYNC - int result; - - START_PROFILE(syscall_fsync); - result = fsync(fsp->fh->fd); - END_PROFILE(syscall_fsync); - return result; -#else - return 0; -#endif -} - static int vfswrap_stat(vfs_handle_struct *handle, struct smb_filename *smb_fname) { @@ -3036,7 +3022,6 @@ static struct vfs_fn_pointers vfs_default_fns = { .sendfile_fn = vfswrap_sendfile, .recvfile_fn = vfswrap_recvfile, .rename_fn = vfswrap_rename, - .fsync_fn = vfswrap_fsync, .fsync_send_fn = vfswrap_fsync_send, .fsync_recv_fn = vfswrap_fsync_recv, .stat_fn = vfswrap_stat, diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c index fbe1715b90e..45d6544b5c2 100644 --- a/source3/modules/vfs_full_audit.c +++ b/source3/modules/vfs_full_audit.c @@ -1286,18 +1286,6 @@ static int smb_full_audit_rename(vfs_handle_struct *handle, return result; } -static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp) -{ - int result; - - result = SMB_VFS_NEXT_FSYNC(handle, fsp); - - do_log(SMB_VFS_OP_FSYNC, (result >= 0), handle, "%s", - fsp_str_do_log(fsp)); - - return result; -} - struct smb_full_audit_fsync_state { vfs_handle_struct *handle; files_struct *fsp; @@ -2531,7 +2519,6 @@ static struct vfs_fn_pointers vfs_full_audit_fns = { .sendfile_fn = smb_full_audit_sendfile, .recvfile_fn = smb_full_audit_recvfile, .rename_fn = smb_full_audit_rename, - .fsync_fn = smb_full_audit_fsync, .fsync_send_fn = smb_full_audit_fsync_send, .fsync_recv_fn = smb_full_audit_fsync_recv, .stat_fn = smb_full_audit_stat, diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 38abb78f1f3..5878c14aba7 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -931,12 +931,6 @@ static int vfs_gluster_rename(struct vfs_handle_struct *handle, smb_fname_dst->base_name); } -static int vfs_gluster_fsync(struct vfs_handle_struct *handle, - files_struct *fsp) -{ - return glfs_fsync(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp)); -} - static struct tevent_req *vfs_gluster_fsync_send(struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, struct tevent_context *ev, @@ -1471,7 +1465,6 @@ static struct vfs_fn_pointers glusterfs_fns = { .sendfile_fn = vfs_gluster_sendfile, .recvfile_fn = vfs_gluster_recvfile, .rename_fn = vfs_gluster_rename, - .fsync_fn = vfs_gluster_fsync, .fsync_send_fn = vfs_gluster_fsync_send, .fsync_recv_fn = vfs_gluster_fsync_recv, diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c index c653656e5f8..5355dd8ca44 100644 --- a/source3/modules/vfs_streams_xattr.c +++ b/source3/modules/vfs_streams_xattr.c @@ -1323,18 +1323,6 @@ static int streams_xattr_fchmod(vfs_handle_struct *handle, return 0; } -static int streams_xattr_fsync(vfs_handle_struct *handle, files_struct *fsp) -{ - struct stream_io *sio = - (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp); - - if (sio == NULL) { - return SMB_VFS_NEXT_FSYNC(handle, fsp); - } - - return 0; -} - static ssize_t streams_xattr_fgetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, @@ -1683,7 +1671,6 @@ static struct vfs_fn_pointers vfs_streams_xattr_fns = { .fchown_fn = streams_xattr_fchown, .fchmod_fn = streams_xattr_fchmod, - .fsync_fn = streams_xattr_fsync, .fgetxattr_fn = streams_xattr_fgetxattr, .flistxattr_fn = streams_xattr_flistxattr, diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c index 4a0ec89f044..383f49b7b22 100644 --- a/source3/modules/vfs_time_audit.c +++ b/source3/modules/vfs_time_audit.c @@ -938,24 +938,6 @@ static int smb_time_audit_rename(vfs_handle_struct *handle, return result; } -static int smb_time_audit_fsync(vfs_handle_struct *handle, files_struct *fsp) -{ - int result; - struct timespec ts1,ts2; - double timediff; - - clock_gettime_mono(&ts1); - result = SMB_VFS_NEXT_FSYNC(handle, fsp); - clock_gettime_mono(&ts2); - timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9; - - if (timediff > audit_timeout) { - smb_time_audit_log_fsp("fsync", timediff, fsp); - } - - return result; -} - struct smb_time_audit_fsync_state { struct files_struct *fsp; int ret; @@ -2707,7 +2689,6 @@ static struct vfs_fn_pointers vfs_time_audit_fns = { .sendfile_fn = smb_time_audit_sendfile, .recvfile_fn = smb_time_audit_recvfile, .rename_fn = smb_time_audit_rename, - .fsync_fn = smb_time_audit_fsync, .fsync_send_fn = smb_time_audit_fsync_send, .fsync_recv_fn = smb_time_audit_fsync_recv, .stat_fn = smb_time_audit_stat, diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index b29a5c54acc..f659c8f2783 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -1921,13 +1921,6 @@ int smb_vfs_call_rename(struct vfs_handle_struct *handle, return handle->fns->rename_fn(handle, smb_fname_src, smb_fname_dst); } -int smb_vfs_call_fsync(struct vfs_handle_struct *handle, - struct files_struct *fsp) -{ - VFS_FIND(fsync); - return handle->fns->fsync_fn(handle, fsp); -} - struct smb_vfs_call_fsync_state { int (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state); int retval; -- 2.17.0.441.gb46fe60e1d-goog