Skip to content

Commit

Permalink
s3-vfs: Add pread_send/recv to vfs modules
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremy Allison <[email protected]>
  • Loading branch information
vlendec authored and jrasamba committed Jul 18, 2012
1 parent 4668398 commit 90461aa
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/VFS/skel_opaque.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,21 @@ static ssize_t skel_pread(vfs_handle_struct *handle, files_struct *fsp, void *da
return -1;
}

static struct tevent_req *skel_pread_send(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct files_struct *fsp,
void *data, size_t n, off_t offset)
{
return NULL;
}

static ssize_t skel_pread_recv(struct tevent_req *req, int *err)
{
*err = ENOSYS;
return -1;
}

static ssize_t skel_write(vfs_handle_struct *handle, files_struct *fsp, const void *data, size_t n)
{
errno = ENOSYS;
Expand Down Expand Up @@ -805,6 +820,8 @@ struct vfs_fn_pointers skel_opaque_fns = {
.close_fn = skel_close_fn,
.read_fn = skel_vfs_read,
.pread_fn = skel_pread,
.pread_send_fn = skel_pread_send,
.pread_recv_fn = skel_pread_recv,
.write_fn = skel_write,
.pwrite_fn = skel_pwrite,
.lseek_fn = skel_lseek,
Expand Down
56 changes: 56 additions & 0 deletions examples/VFS/skel_transparent.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


#include "../source3/include/includes.h"
#include "lib/util/tevent_unix.h"

/* PLEASE,PLEASE READ THE VFS MODULES CHAPTER OF THE
SAMBA DEVELOPERS GUIDE!!!!!!
Expand Down Expand Up @@ -193,6 +194,59 @@ static ssize_t skel_pread(vfs_handle_struct *handle, files_struct *fsp, void *da
return SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
}

struct skel_pread_state {
ssize_t ret;
int err;
};

static void skel_pread_done(struct tevent_req *subreq);

static struct tevent_req *skel_pread_send(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct files_struct *fsp,
void *data, size_t n, off_t offset)
{
struct tevent_req *req, *subreq;
struct skel_pread_state *state;

req = tevent_req_create(mem_ctx, &state, struct skel_pread_state);
if (req == NULL) {
return NULL;
}
subreq = SMB_VFS_NEXT_PREAD_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, skel_pread_done, req);
return req;
}

static void skel_pread_done(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(
subreq, struct tevent_req);
struct skel_pread_state *state = tevent_req_data(
req, struct skel_pread_state);

state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
TALLOC_FREE(subreq);
tevent_req_done(req);
}

static ssize_t skel_pread_recv(struct tevent_req *req, int *err)
{
struct skel_pread_state *state = tevent_req_data(
req, struct skel_pread_state);

if (tevent_req_is_unix_error(req, err)) {
return -1;
}
*err = state->err;
return state->ret;
}

static ssize_t skel_write(vfs_handle_struct *handle, files_struct *fsp, const void *data, size_t n)
{
return SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
Expand Down Expand Up @@ -765,6 +819,8 @@ struct vfs_fn_pointers skel_transparent_fns = {
.close_fn = skel_close_fn,
.read_fn = skel_vfs_read,
.pread_fn = skel_pread,
.pread_send_fn = skel_pread_send,
.pread_recv_fn = skel_pread_recv,
.write_fn = skel_write,
.pwrite_fn = skel_pwrite,
.lseek_fn = skel_lseek,
Expand Down
77 changes: 77 additions & 0 deletions source3/modules/vfs_full_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "ntioctl.h"
#include "lib/param/loadparm.h"
#include "lib/util/bitmap.h"
#include "lib/util/tevent_unix.h"

static int vfs_full_audit_debug_level = DBGC_VFS;

Expand Down Expand Up @@ -111,6 +112,8 @@ typedef enum _vfs_op_type {
SMB_VFS_OP_CLOSE,
SMB_VFS_OP_READ,
SMB_VFS_OP_PREAD,
SMB_VFS_OP_PREAD_SEND,
SMB_VFS_OP_PREAD_RECV,
SMB_VFS_OP_WRITE,
SMB_VFS_OP_PWRITE,
SMB_VFS_OP_LSEEK,
Expand Down Expand Up @@ -247,6 +250,8 @@ static struct {
{ SMB_VFS_OP_CLOSE, "close" },
{ SMB_VFS_OP_READ, "read" },
{ SMB_VFS_OP_PREAD, "pread" },
{ SMB_VFS_OP_PREAD_SEND, "pread_send" },
{ SMB_VFS_OP_PREAD_RECV, "pread_recv" },
{ SMB_VFS_OP_WRITE, "write" },
{ SMB_VFS_OP_PWRITE, "pwrite" },
{ SMB_VFS_OP_LSEEK, "lseek" },
Expand Down Expand Up @@ -964,6 +969,76 @@ static ssize_t smb_full_audit_pread(vfs_handle_struct *handle, files_struct *fsp
return result;
}

struct smb_full_audit_pread_state {
vfs_handle_struct *handle;
files_struct *fsp;
ssize_t ret;
int err;
};

static void smb_full_audit_pread_done(struct tevent_req *subreq);

static struct tevent_req *smb_full_audit_pread_send(
struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
struct tevent_context *ev, struct files_struct *fsp,
void *data, size_t n, off_t offset)
{
struct tevent_req *req, *subreq;
struct smb_full_audit_pread_state *state;

req = tevent_req_create(mem_ctx, &state,
struct smb_full_audit_pread_state);
if (req == NULL) {
do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
fsp_str_do_log(fsp));
return NULL;
}
state->handle = handle;
state->fsp = fsp;

subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
n, offset);
if (tevent_req_nomem(subreq, req)) {
do_log(SMB_VFS_OP_PREAD_SEND, false, handle, "%s",
fsp_str_do_log(fsp));
return tevent_req_post(req, ev);
}
tevent_req_set_callback(subreq, smb_full_audit_pread_done, req);

do_log(SMB_VFS_OP_PREAD_SEND, true, handle, "%s", fsp_str_do_log(fsp));
return req;
}

static void smb_full_audit_pread_done(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(
subreq, struct tevent_req);
struct smb_full_audit_pread_state *state = tevent_req_data(
req, struct smb_full_audit_pread_state);

state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
TALLOC_FREE(subreq);
tevent_req_done(req);
}

static ssize_t smb_full_audit_pread_recv(struct tevent_req *req, int *err)
{
struct smb_full_audit_pread_state *state = tevent_req_data(
req, struct smb_full_audit_pread_state);

if (tevent_req_is_unix_error(req, err)) {
do_log(SMB_VFS_OP_PREAD_RECV, false, state->handle, "%s",
fsp_str_do_log(state->fsp));
return -1;
}

do_log(SMB_VFS_OP_PREAD_RECV, (state->ret >= 0), state->handle, "%s",
fsp_str_do_log(state->fsp));

*err = state->err;
return state->ret;
}

static ssize_t smb_full_audit_write(vfs_handle_struct *handle, files_struct *fsp,
const void *data, size_t n)
{
Expand Down Expand Up @@ -2203,6 +2278,8 @@ static struct vfs_fn_pointers vfs_full_audit_fns = {
.close_fn = smb_full_audit_close,
.read_fn = smb_full_audit_read,
.pread_fn = smb_full_audit_pread,
.pread_send_fn = smb_full_audit_pread_send,
.pread_recv_fn = smb_full_audit_pread_recv,
.write_fn = smb_full_audit_write,
.pwrite_fn = smb_full_audit_pwrite,
.lseek_fn = smb_full_audit_lseek,
Expand Down
68 changes: 68 additions & 0 deletions source3/modules/vfs_time_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "includes.h"
#include "smbd/smbd.h"
#include "ntioctl.h"
#include "lib/util/tevent_unix.h"

#undef DBGC_CLASS
#define DBGC_CLASS DBGC_VFS
Expand Down Expand Up @@ -519,6 +520,71 @@ static ssize_t smb_time_audit_pread(vfs_handle_struct *handle,
return result;
}

struct smb_time_audit_pread_state {
struct timespec ts1;
ssize_t ret;
int err;
};

static void smb_time_audit_pread_done(struct tevent_req *subreq);

static struct tevent_req *smb_time_audit_pread_send(
struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx,
struct tevent_context *ev, struct files_struct *fsp,
void *data, size_t n, off_t offset)
{
struct tevent_req *req, *subreq;
struct smb_time_audit_pread_state *state;

req = tevent_req_create(mem_ctx, &state,
struct smb_time_audit_pread_state);
if (req == NULL) {
return NULL;
}
clock_gettime_mono(&state->ts1);

subreq = SMB_VFS_NEXT_PREAD_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, smb_time_audit_pread_done, req);
return req;
}

static void smb_time_audit_pread_done(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(
subreq, struct tevent_req);
struct smb_time_audit_pread_state *state = tevent_req_data(
req, struct smb_time_audit_pread_state);

state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
TALLOC_FREE(subreq);
tevent_req_done(req);
}

static ssize_t smb_time_audit_pread_recv(struct tevent_req *req, int *err)
{
struct smb_time_audit_pread_state *state = tevent_req_data(
req, struct smb_time_audit_pread_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("pread", timediff);
}

if (tevent_req_is_unix_error(req, err)) {
return -1;
}
*err = state->err;
return state->ret;
}

static ssize_t smb_time_audit_write(vfs_handle_struct *handle,
files_struct *fsp,
const void *data, size_t n)
Expand Down Expand Up @@ -2282,6 +2348,8 @@ static struct vfs_fn_pointers vfs_time_audit_fns = {
.close_fn = smb_time_audit_close,
.read_fn = smb_time_audit_read,
.pread_fn = smb_time_audit_pread,
.pread_send_fn = smb_time_audit_pread_send,
.pread_recv_fn = smb_time_audit_pread_recv,
.write_fn = smb_time_audit_write,
.pwrite_fn = smb_time_audit_pwrite,
.lseek_fn = smb_time_audit_lseek,
Expand Down

0 comments on commit 90461aa

Please sign in to comment.