]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: VFS: Add a synchronous smb_vfs_fsync_sync() call, built from async primitives.
authorJeremy Allison <jra@samba.org>
Fri, 27 Apr 2018 23:59:02 +0000 (16:59 -0700)
committerRalph Boehme <slow@samba.org>
Tue, 1 May 2018 20:15:21 +0000 (22:15 +0200)
Will be used in the next commit.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/include/vfs.h
source3/smbd/vfs.c

index bb4a135e41e2cda82588a7722df62e40e1a6a425..a31cb5aeaf2d4ec923717efa62cc3e36e83f64de 100644 (file)
@@ -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,
index 59702203612e4ec5d61d3c828204b3ad63455b40..b29a5c54acc08a5ccef7375dc82d943ba9844493 100644 (file)
@@ -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)