summaryrefslogtreecommitdiff
path: root/source3/modules
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2012-07-13 10:22:25 +0200
committerJeremy Allison <jra@samba.org>2012-07-18 15:48:04 -0700
commit5d09cec6fe499ac0bcc1ac98fd8aaffe7e43faa3 (patch)
treeb1438456ff31f7e522089f6569f67c078d6eadc4 /source3/modules
parent3882113e6f44d0adbc321d97931a6e9a37a149b8 (diff)
downloadsamba-5d09cec6fe499ac0bcc1ac98fd8aaffe7e43faa3.tar.gz
samba-5d09cec6fe499ac0bcc1ac98fd8aaffe7e43faa3.tar.bz2
samba-5d09cec6fe499ac0bcc1ac98fd8aaffe7e43faa3.zip
s3-vfs: async fsync
Signed-off-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/modules')
-rw-r--r--source3/modules/vfs_default.c44
-rw-r--r--source3/modules/vfs_full_audit.c74
-rw-r--r--source3/modules/vfs_time_audit.c65
3 files changed, 183 insertions, 0 deletions
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index c79eed0b97..002a5501fd 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -737,6 +737,36 @@ static struct tevent_req *vfswrap_pwrite_send(struct vfs_handle_struct *handle,
return req;
}
+static struct tevent_req *vfswrap_fsync_send(struct vfs_handle_struct *handle,
+ TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct files_struct *fsp)
+{
+ struct tevent_req *req;
+ struct vfswrap_asys_state *state;
+ int ret;
+
+ req = tevent_req_create(mem_ctx, &state, struct vfswrap_asys_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ if (!vfswrap_init_asys_ctx(handle->conn->sconn->conn)) {
+ tevent_req_oom(req);
+ return tevent_req_post(req, ev);
+ }
+ state->asys_ctx = handle->conn->sconn->conn->asys_ctx;
+ state->req = req;
+
+ ret = asys_fsync(state->asys_ctx, fsp->fh->fd, req);
+ if (ret != 0) {
+ tevent_req_error(req, ret);
+ return tevent_req_post(req, ev);
+ }
+ talloc_set_destructor(state, vfswrap_asys_state_destructor);
+
+ return req;
+}
+
static void vfswrap_asys_finished(struct tevent_context *ev,
struct tevent_fd *fde,
uint16_t flags, void *p)
@@ -785,6 +815,18 @@ static ssize_t vfswrap_asys_ssize_t_recv(struct tevent_req *req, int *err)
return state->ret;
}
+static int vfswrap_asys_int_recv(struct tevent_req *req, int *err)
+{
+ struct vfswrap_asys_state *state = tevent_req_data(
+ req, struct vfswrap_asys_state);
+
+ if (tevent_req_is_unix_error(req, err)) {
+ return -1;
+ }
+ *err = state->err;
+ return state->ret;
+}
+
static off_t vfswrap_lseek(vfs_handle_struct *handle, files_struct *fsp, off_t offset, int whence)
{
off_t result = 0;
@@ -2314,6 +2356,8 @@ static struct vfs_fn_pointers vfs_default_fns = {
.recvfile_fn = vfswrap_recvfile,
.rename_fn = vfswrap_rename,
.fsync_fn = vfswrap_fsync,
+ .fsync_send_fn = vfswrap_fsync_send,
+ .fsync_recv_fn = vfswrap_asys_int_recv,
.stat_fn = vfswrap_stat,
.fstat_fn = vfswrap_fstat,
.lstat_fn = vfswrap_lstat,
diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c
index 74cc663be8..1e5679dd6b 100644
--- a/source3/modules/vfs_full_audit.c
+++ b/source3/modules/vfs_full_audit.c
@@ -123,6 +123,8 @@ typedef enum _vfs_op_type {
SMB_VFS_OP_RECVFILE,
SMB_VFS_OP_RENAME,
SMB_VFS_OP_FSYNC,
+ SMB_VFS_OP_FSYNC_SEND,
+ SMB_VFS_OP_FSYNC_RECV,
SMB_VFS_OP_STAT,
SMB_VFS_OP_FSTAT,
SMB_VFS_OP_LSTAT,
@@ -254,6 +256,8 @@ static struct {
{ SMB_VFS_OP_RECVFILE, "recvfile" },
{ SMB_VFS_OP_RENAME, "rename" },
{ SMB_VFS_OP_FSYNC, "fsync" },
+ { SMB_VFS_OP_FSYNC_SEND, "fsync_send" },
+ { SMB_VFS_OP_FSYNC_RECV, "fsync_recv" },
{ SMB_VFS_OP_STAT, "stat" },
{ SMB_VFS_OP_FSTAT, "fstat" },
{ SMB_VFS_OP_LSTAT, "lstat" },
@@ -1195,6 +1199,74 @@ static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
return result;
}
+struct smb_full_audit_fsync_state {
+ vfs_handle_struct *handle;
+ files_struct *fsp;
+ int ret;
+ int err;
+};
+
+static void smb_full_audit_fsync_done(struct tevent_req *subreq);
+
+static struct tevent_req *smb_full_audit_fsync_send(
+ struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev, struct files_struct *fsp)
+{
+ struct tevent_req *req, *subreq;
+ struct smb_full_audit_fsync_state *state;
+
+ req = tevent_req_create(mem_ctx, &state,
+ struct smb_full_audit_fsync_state);
+ if (req == NULL) {
+ do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
+ fsp_str_do_log(fsp));
+ return NULL;
+ }
+ state->handle = handle;
+ state->fsp = fsp;
+
+ subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
+ if (tevent_req_nomem(subreq, req)) {
+ do_log(SMB_VFS_OP_FSYNC_SEND, false, handle, "%s",
+ fsp_str_do_log(fsp));
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, smb_full_audit_fsync_done, req);
+
+ do_log(SMB_VFS_OP_FSYNC_SEND, true, handle, "%s", fsp_str_do_log(fsp));
+ return req;
+}
+
+static void smb_full_audit_fsync_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct smb_full_audit_fsync_state *state = tevent_req_data(
+ req, struct smb_full_audit_fsync_state);
+
+ state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->err);
+ TALLOC_FREE(subreq);
+ tevent_req_done(req);
+}
+
+static int smb_full_audit_fsync_recv(struct tevent_req *req, int *err)
+{
+ struct smb_full_audit_fsync_state *state = tevent_req_data(
+ req, struct smb_full_audit_fsync_state);
+
+ if (tevent_req_is_unix_error(req, err)) {
+ do_log(SMB_VFS_OP_FSYNC_RECV, false, state->handle, "%s",
+ fsp_str_do_log(state->fsp));
+ return -1;
+ }
+
+ do_log(SMB_VFS_OP_FSYNC_RECV, (state->ret >= 0), state->handle, "%s",
+ fsp_str_do_log(state->fsp));
+
+ *err = state->err;
+ return state->ret;
+}
+
static int smb_full_audit_stat(vfs_handle_struct *handle,
struct smb_filename *smb_fname)
{
@@ -2271,6 +2343,8 @@ static struct vfs_fn_pointers vfs_full_audit_fns = {
.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,
.fstat_fn = smb_full_audit_fstat,
.lstat_fn = smb_full_audit_lstat,
diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c
index 16eb624ebb..ff9cf05120 100644
--- a/source3/modules/vfs_time_audit.c
+++ b/source3/modules/vfs_time_audit.c
@@ -791,6 +791,69 @@ static int smb_time_audit_fsync(vfs_handle_struct *handle, files_struct *fsp)
return result;
}
+struct smb_time_audit_fsync_state {
+ struct timespec ts1;
+ int ret;
+ int err;
+};
+
+static void smb_time_audit_fsync_done(struct tevent_req *subreq);
+
+static struct tevent_req *smb_time_audit_fsync_send(
+ struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev, struct files_struct *fsp)
+{
+ struct tevent_req *req, *subreq;
+ struct smb_time_audit_fsync_state *state;
+
+ req = tevent_req_create(mem_ctx, &state,
+ struct smb_time_audit_fsync_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ clock_gettime_mono(&state->ts1);
+
+ subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, smb_time_audit_fsync_done, req);
+ return req;
+}
+
+static void smb_time_audit_fsync_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct smb_time_audit_fsync_state *state = tevent_req_data(
+ req, struct smb_time_audit_fsync_state);
+
+ state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->err);
+ TALLOC_FREE(subreq);
+ tevent_req_done(req);
+}
+
+static int smb_time_audit_fsync_recv(struct tevent_req *req, int *err)
+{
+ struct smb_time_audit_fsync_state *state = tevent_req_data(
+ req, struct smb_time_audit_fsync_state);
+ struct timespec ts2;
+ double timediff;
+
+ clock_gettime_mono(&ts2);
+ timediff = nsec_time_diff(&ts2,&state->ts1)*1.0e-9;
+
+ if (timediff > audit_timeout) {
+ smb_time_audit_log("fsync", timediff);
+ }
+
+ if (tevent_req_is_unix_error(req, err)) {
+ return -1;
+ }
+ *err = state->err;
+ return state->ret;
+}
+
static int smb_time_audit_stat(vfs_handle_struct *handle,
struct smb_filename *fname)
{
@@ -2283,6 +2346,8 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
.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,
.fstat_fn = smb_time_audit_fstat,
.lstat_fn = smb_time_audit_lstat,