Skip to content

Commit

Permalink
vfs: Add flags and xferlen args to SMB_VFS_OFFLOAD_READ_RECV
Browse files Browse the repository at this point in the history
We missed these values which follow from MS-FSCC 2.3.80 “FSCTL_OFFLOAD_READ
Reply”:

  Flags (4 bytes):

    A 32-bit unsigned integer that indicates which flags were returned for this
    operation. Possible values for the flags follow. All unused bits are reserved
    for future use, SHOULD be set to 0, and MUST be ignored.

    OFFLOAD_READ_FLAG_ALL_ZERO_BEYOND_CURRENT_RANGE (0x00000001)
    => The data beyond the current range is logically equivalent to zero.

  TransferLength (8 bytes):

    A 64-bit unsigned integer that contains the amount, in bytes, of data that the
    Token logically represents. This value indicates a contiguous region of the
    file from the beginning of the requested offset in the FileOffset field in the
    FSCTL_OFFLOAD_READ_INPUT data element (section 2.3.79). This value can be
    smaller than the CopyLength field specified in the FSCTL_OFFLOAD_READ_INPUT
    data element, which indicates that less data was logically
    represented (logically read) with the Token than was requested. The value of
    this field MUST be greater than 0x0000000000000000 and MUST be aligned to a
    logical sector boundary on the volume.

As we currently only implement COPY_CHUNK over the OFFLOAD VFS interface, the
VFS COPY_CHUNK backend in vfs_default just sets both values to 0 and they are
unused in the SMB frontend.

Signed-off-by: Ralph Boehme <[email protected]>
Reviewed-by: Jeremy Allison <[email protected]>
  • Loading branch information
slowfranklin authored and jrasamba committed Oct 8, 2021
1 parent 3afd4bd commit 8fa7848
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 7 deletions.
2 changes: 2 additions & 0 deletions examples/VFS/skel_opaque.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ static struct tevent_req *skel_offload_read_send(
static NTSTATUS skel_offload_read_recv(struct tevent_req *req,
struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
uint32_t *flags,
uint64_t *xferlen,
DATA_BLOB *_token_blob)
{
NTSTATUS status;
Expand Down
8 changes: 8 additions & 0 deletions examples/VFS/skel_transparent.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,8 @@ static uint64_t skel_fs_file_id(vfs_handle_struct *handle,

struct skel_offload_read_state {
struct vfs_handle_struct *handle;
uint32_t flags;
uint64_t xferlen;
DATA_BLOB token;
};

Expand Down Expand Up @@ -714,6 +716,8 @@ static void skel_offload_read_done(struct tevent_req *subreq)
status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq,
state->handle,
state,
&state->flags,
&state->xferlen,
&state->token);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
Expand All @@ -727,6 +731,8 @@ static void skel_offload_read_done(struct tevent_req *subreq)
static NTSTATUS skel_offload_read_recv(struct tevent_req *req,
struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
uint32_t *flags,
uint64_t *xferlen,
DATA_BLOB *_token)
{
struct skel_offload_read_state *state = tevent_req_data(
Expand All @@ -749,6 +755,8 @@ static NTSTATUS skel_offload_read_recv(struct tevent_req *req,
return NT_STATUS_NO_MEMORY;
}

*flags = state->flags;
*xferlen = state->xferlen;
*_token = token;
return NT_STATUS_OK;
}
Expand Down
7 changes: 7 additions & 0 deletions source3/include/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@
* Version 45 - Add SMB_VFS_FCHFLAGS
* Version 45 - Remove SMB_VFS_GETXATTR
* Version 46 - Rename SMB_VFS_KERNEL_FLOCK to SMB_VFS_FILESYSTEM_SHAREMODE
* Version 46 - Add flags and xferlen args to SMB_VFS_OFFLOAD_READ_RECV
*/

#define SMB_VFS_INTERFACE_VERSION 46
Expand Down Expand Up @@ -1089,6 +1090,8 @@ struct vfs_fn_pointers {
NTSTATUS (*offload_read_recv_fn)(struct tevent_req *req,
struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
uint32_t *flags,
uint64_t *xferlen,
DATA_BLOB *token_blob);
struct tevent_req *(*offload_write_send_fn)(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
Expand Down Expand Up @@ -1659,6 +1662,8 @@ struct tevent_req *smb_vfs_call_offload_read_send(
NTSTATUS smb_vfs_call_offload_read_recv(struct tevent_req *req,
struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
uint32_t *flags,
uint64_t *xferlen,
DATA_BLOB *token_blob);
struct tevent_req *smb_vfs_call_offload_write_send(struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
Expand Down Expand Up @@ -2024,6 +2029,8 @@ struct tevent_req *vfs_not_implemented_offload_read_send(
NTSTATUS vfs_not_implemented_offload_read_recv(struct tevent_req *req,
struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
uint32_t *flags,
uint64_t *xferlen,
DATA_BLOB *_token_blob);
struct tevent_req *vfs_not_implemented_offload_write_send(
struct vfs_handle_struct *handle,
Expand Down
8 changes: 4 additions & 4 deletions source3/include/vfs_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,10 @@
#define SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp, fsctl, ttl, offset, to_copy) \
smb_vfs_call_offload_read_send((mem_ctx), (ev), (handle)->next, (fsp), (fsctl), (ttl), (offset), (to_copy))

#define SMB_VFS_OFFLOAD_READ_RECV(req, conn, mem_ctx, token_blob) \
smb_vfs_call_offload_read_recv((req), (conn)->vfs_handles, (mem_ctx), (token_blob))
#define SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx, token_blob) \
smb_vfs_call_offload_read_recv((req), (handle)->next, (mem_ctx), (token_blob))
#define SMB_VFS_OFFLOAD_READ_RECV(req, conn, mem_ctx, flags, xferlen, token_blob) \
smb_vfs_call_offload_read_recv((req), (conn)->vfs_handles, (mem_ctx), (flags), (xferlen), (token_blob))
#define SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx, flags, xferlen, token_blob) \
smb_vfs_call_offload_read_recv((req), (handle)->next, (mem_ctx), flags, xferlen, (token_blob))

#define SMB_VFS_OFFLOAD_WRITE_SEND(conn, mem_ctx, ev, fsctl, token, transfer_offset, dest_fsp, dest_off, num) \
smb_vfs_call_offload_write_send((conn)->vfs_handles, (mem_ctx), (ev), (fsctl), (token), (transfer_offset), (dest_fsp), (dest_off), (num))
Expand Down
8 changes: 8 additions & 0 deletions source3/modules/vfs_btrfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ static struct vfs_offload_ctx *btrfs_offload_ctx;
struct btrfs_offload_read_state {
struct vfs_handle_struct *handle;
files_struct *fsp;
uint32_t flags;
uint64_t xferlen;
DATA_BLOB token;
};

Expand Down Expand Up @@ -158,6 +160,8 @@ static void btrfs_offload_read_done(struct tevent_req *subreq)
status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq,
state->handle,
state,
&state->flags,
&state->xferlen,
&state->token);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
Expand All @@ -178,6 +182,8 @@ static void btrfs_offload_read_done(struct tevent_req *subreq)
static NTSTATUS btrfs_offload_read_recv(struct tevent_req *req,
struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
uint32_t *flags,
uint64_t *xferlen,
DATA_BLOB *token)
{
struct btrfs_offload_read_state *state = tevent_req_data(
Expand All @@ -189,6 +195,8 @@ static NTSTATUS btrfs_offload_read_recv(struct tevent_req *req,
return status;
}

*flags = state->flags;
*xferlen = state->xferlen;
token->length = state->token.length;
token->data = talloc_move(mem_ctx, &state->token.data);

Expand Down
4 changes: 4 additions & 0 deletions source3/modules/vfs_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,8 @@ static struct tevent_req *vfswrap_offload_read_send(
static NTSTATUS vfswrap_offload_read_recv(struct tevent_req *req,
struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
uint32_t *flags,
uint64_t *xferlen,
DATA_BLOB *token)
{
struct vfswrap_offload_read_state *state = tevent_req_data(
Expand All @@ -2001,6 +2003,8 @@ static NTSTATUS vfswrap_offload_read_recv(struct tevent_req *req,
return status;
}

*flags = 0;
*xferlen = 0;
token->length = state->token.length;
token->data = talloc_move(mem_ctx, &state->token.data);

Expand Down
8 changes: 8 additions & 0 deletions source3/modules/vfs_fruit.c
Original file line number Diff line number Diff line change
Expand Up @@ -4486,6 +4486,8 @@ struct fruit_offload_read_state {
struct tevent_context *ev;
files_struct *fsp;
uint32_t fsctl;
uint32_t flags;
uint64_t xferlen;
DATA_BLOB token;
};

Expand Down Expand Up @@ -4537,6 +4539,8 @@ static void fruit_offload_read_done(struct tevent_req *subreq)
status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq,
state->handle,
state,
&state->flags,
&state->xferlen,
&state->token);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
Expand Down Expand Up @@ -4568,6 +4572,8 @@ static void fruit_offload_read_done(struct tevent_req *subreq)
static NTSTATUS fruit_offload_read_recv(struct tevent_req *req,
struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
uint32_t *flags,
uint64_t *xferlen,
DATA_BLOB *token)
{
struct fruit_offload_read_state *state = tevent_req_data(
Expand All @@ -4579,6 +4585,8 @@ static NTSTATUS fruit_offload_read_recv(struct tevent_req *req,
return status;
}

*flags = state->flags;
*xferlen = state->xferlen;
token->length = state->token.length;
token->data = talloc_move(mem_ctx, &state->token.data);

Expand Down
4 changes: 3 additions & 1 deletion source3/modules/vfs_full_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2234,12 +2234,14 @@ static NTSTATUS smb_full_audit_offload_read_recv(
struct tevent_req *req,
struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
uint32_t *flags,
uint64_t *xferlen,
DATA_BLOB *_token_blob)
{
NTSTATUS status;

status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(req, handle, mem_ctx,
_token_blob);
flags, xferlen, _token_blob);

do_log(SMB_VFS_OP_OFFLOAD_READ_RECV, NT_STATUS_IS_OK(status), handle, "");

Expand Down
2 changes: 2 additions & 0 deletions source3/modules/vfs_not_implemented.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ struct tevent_req *vfs_not_implemented_offload_read_send(
NTSTATUS vfs_not_implemented_offload_read_recv(struct tevent_req *req,
struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
uint32_t *flags,
uint64_t *xferlen,
DATA_BLOB *_token_blob)
{
NTSTATUS status;
Expand Down
8 changes: 8 additions & 0 deletions source3/modules/vfs_time_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2031,6 +2031,8 @@ static NTSTATUS smb_time_fset_dos_attributes(struct vfs_handle_struct *handle,
struct time_audit_offload_read_state {
struct vfs_handle_struct *handle;
struct timespec ts_send;
uint32_t flags;
uint64_t xferlen;
DATA_BLOB token_blob;
};

Expand Down Expand Up @@ -2081,6 +2083,8 @@ static void smb_time_audit_offload_read_done(struct tevent_req *subreq)
status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq,
state->handle,
state,
&state->flags,
&state->xferlen,
&state->token_blob);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
Expand All @@ -2093,6 +2097,8 @@ static NTSTATUS smb_time_audit_offload_read_recv(
struct tevent_req *req,
struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
uint32_t *flags,
uint64_t *xferlen,
DATA_BLOB *token_blob)
{
struct time_audit_offload_read_state *state = tevent_req_data(
Expand All @@ -2112,6 +2118,8 @@ static NTSTATUS smb_time_audit_offload_read_recv(
return status;
}

*flags = state->flags;
*xferlen = state->xferlen;
token_blob->length = state->token_blob.length;
token_blob->data = talloc_move(mem_ctx, &state->token_blob.data);

Expand Down
8 changes: 7 additions & 1 deletion source3/smbd/smb2_ioctl_filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,17 @@ static void fsctl_dup_extents_offload_read_done(struct tevent_req *subreq)
subreq, struct tevent_req);
struct fsctl_dup_extents_state *state = tevent_req_data(
req, struct fsctl_dup_extents_state);
uint32_t flags;
uint64_t xferlen;
DATA_BLOB token;
NTSTATUS status;

/*
* Note that both flags and xferlen are not used with copy-chunk.
*/

status = SMB_VFS_OFFLOAD_READ_RECV(subreq, state->dst_fsp->conn,
state, &token);
state, &flags, &xferlen, &token);
if (tevent_req_nterror(req, status)) {
return;
}
Expand Down
7 changes: 7 additions & 0 deletions source3/smbd/smb2_ioctl_network_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,12 +769,19 @@ static void smb2_ioctl_network_fs_offload_read_done(struct tevent_req *subreq)
req, struct smbd_smb2_ioctl_state);
struct req_resume_key_rsp rkey_rsp;
enum ndr_err_code ndr_ret;
uint32_t flags;
uint64_t xferlen;
DATA_BLOB token;
NTSTATUS status;

/*
* Note that both flags and xferlen are not used with copy-chunk.
*/
status = SMB_VFS_OFFLOAD_READ_RECV(subreq,
state->fsp->conn,
state,
&flags,
&xferlen,
&token);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
Expand Down
4 changes: 3 additions & 1 deletion source3/smbd/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2516,10 +2516,12 @@ struct tevent_req *smb_vfs_call_offload_read_send(TALLOC_CTX *mem_ctx,
NTSTATUS smb_vfs_call_offload_read_recv(struct tevent_req *req,
struct vfs_handle_struct *handle,
TALLOC_CTX *mem_ctx,
uint32_t *flags,
uint64_t *xferlen,
DATA_BLOB *token_blob)
{
VFS_FIND(offload_read_recv);
return handle->fns->offload_read_recv_fn(req, handle, mem_ctx, token_blob);
return handle->fns->offload_read_recv_fn(req, handle, mem_ctx, flags, xferlen, token_blob);
}

struct tevent_req *smb_vfs_call_offload_write_send(struct vfs_handle_struct *handle,
Expand Down

0 comments on commit 8fa7848

Please sign in to comment.