summaryrefslogtreecommitdiff
path: root/source3/modules
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2013-01-14 21:37:52 +0100
committerJeremy Allison <jra@samba.org>2013-01-15 00:55:51 +0100
commita82db92a8a68f6e33e20fd2b55401225d91345cf (patch)
tree74c418a2586b1dbe4e0e1f31803e2db2266ea663 /source3/modules
parent215427202ad993ad48d0ea4c47ac4435fc4610fb (diff)
downloadsamba-a82db92a8a68f6e33e20fd2b55401225d91345cf.tar.gz
samba-a82db92a8a68f6e33e20fd2b55401225d91345cf.tar.bz2
samba-a82db92a8a68f6e33e20fd2b55401225d91345cf.zip
smbd: Fix bug 9544, part 2
Plug in async pwrite Reviewed by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Tue Jan 15 00:55:51 CET 2013 on sn-devel-104
Diffstat (limited to 'source3/modules')
-rw-r--r--source3/modules/vfs_commit.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/source3/modules/vfs_commit.c b/source3/modules/vfs_commit.c
index c9c0a056a5..a6bc2a4a65 100644
--- a/source3/modules/vfs_commit.c
+++ b/source3/modules/vfs_commit.c
@@ -19,6 +19,7 @@
#include "includes.h"
#include "system/filesys.h"
#include "smbd/smbd.h"
+#include "lib/util/tevent_unix.h"
/* Commit data module.
*
@@ -275,6 +276,83 @@ static ssize_t commit_pwrite(
return ret;
}
+struct commit_pwrite_state {
+ struct vfs_handle_struct *handle;
+ struct files_struct *fsp;
+ ssize_t ret;
+ int err;
+};
+
+static void commit_pwrite_written(struct tevent_req *subreq);
+
+static struct tevent_req *commit_pwrite_send(struct vfs_handle_struct *handle,
+ TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct files_struct *fsp,
+ const void *data,
+ size_t n, off_t offset)
+{
+ struct tevent_req *req, *subreq;
+ struct commit_pwrite_state *state;
+
+ req = tevent_req_create(mem_ctx, &state, struct commit_pwrite_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ state->handle = handle;
+ state->fsp = fsp;
+
+ subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
+ n, offset);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, commit_pwrite_written, req);
+ return req;
+}
+
+static void commit_pwrite_written(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct commit_pwrite_state *state = tevent_req_data(
+ req, struct commit_pwrite_state);
+ int commit_ret;
+
+ state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
+ TALLOC_FREE(subreq);
+
+ if (state->ret <= 0) {
+ tevent_req_done(req);
+ return;
+ }
+
+ /*
+ * Ok, this is a sync fake. We should make the sync async as well, but
+ * I'm too lazy for that right now -- vl
+ */
+ commit_ret = commit(state->handle, state->fsp, state->fsp->fh->pos,
+ state->ret);
+
+ if (commit_ret == -1) {
+ state->ret = -1;
+ }
+
+ tevent_req_done(req);
+}
+
+static ssize_t commit_pwrite_recv(struct tevent_req *req, int *err)
+{
+ struct commit_pwrite_state *state =
+ tevent_req_data(req, struct commit_pwrite_state);
+
+ if (tevent_req_is_unix_error(req, err)) {
+ return -1;
+ }
+ *err = state->err;
+ return state->ret;
+}
+
static int commit_close(
vfs_handle_struct * handle,
files_struct * fsp)
@@ -309,6 +387,8 @@ static struct vfs_fn_pointers vfs_commit_fns = {
.close_fn = commit_close,
.write_fn = commit_write,
.pwrite_fn = commit_pwrite,
+ .pwrite_send_fn = commit_pwrite_send,
+ .pwrite_recv_fn = commit_pwrite_recv,
.connect_fn = commit_connect,
.ftruncate_fn = commit_ftruncate
};