From: Jeremy Allison Date: Fri, 27 Apr 2018 23:59:02 +0000 (-0700) Subject: s3: VFS: Add a synchronous smb_vfs_fsync_sync() call, built from async primitives. X-Git-Tag: ldb-1.4.0~469 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0482b9d8daa4f8a1ff2e3011fa9a2fcc370c3a1;p=thirdparty%2Fsamba.git 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 Reviewed-by: Ralph Boehme --- 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)