[SCM] Samba Shared Repository - branch master updated

Ralph Böhme slow at samba.org
Mon Jul 3 22:13:03 UTC 2017


The branch, master has been updated
       via  a760324 net: add net cache samlogon list|show|ndrdump|delete
       via  392c96e samlogon_cache: add netsamlog_cache_for_all()
       via  4be4f4b netlogon.idl: mark session keys with NDR_SECRET
       via  4929307 s4/torture: test fetching a resume key twice
       via  2d01558 s3/smbd: remove unneeded flags argument from SMB_VFS_OFFLOAD_WRITE_SEND
       via  fe6d71d s3/smbd: get rid of files_struct.aapl_copyfile_supported
       via  2b3fcc5 s4/torture: more tests for copy-chunk across shares
       via  3645f83 s3/vfs: make SMB_VFS_OFFLOAD_WRITE_SEND offload token based
       via  d50f307 s4/torture: add a test for copy-chunk across shares
       via  74e018f s3/smbd: redesign macOS copyfile copy-chunk
       via  2ad11c6 s3/smbd: remove copy-chunk chunk merging optimisation
       via  9c65502 s3/smbd: remove unused arg smb1req from copychunk_check_handles()
       via  60e3e10 s3/smbd: remove flags2 FLAGS2_READ_PERMIT_EXECUTE hack in the SMB2 code
       via  697d8e9 s3/smbd: remove ununsed req arg from CHECK_READ_IOCTL macro
       via  64bedef s3/vfs: rename SMB_VFS_COPY_CHUNK_SEND/RECV to SMB_VFS_OFFLOAD_WRITE_SEND/RECV
       via  67ed1ed s3/smbd: use SMB_VFS_OFFLOAD_READ_SEND/RECV
       via  af6cbc7 s3/vfs: add SMB_VFS_OFFLOAD_READ_SEND/RECV
       via  47600c4 s4/torture: pass destination tree to test_setup_copy_chunk
       via  d6a8a79 librpc/idl: make use storage_offload_token
       via  e3cb6a9 librpc/idl: fix STORAGE_OFFLOAD_TOKEN_TYPE_ZERO_DATA definition
       via  ebee458 librpc/idl: convert offload flags to a bitmap
       via  d10ca1a lib/util: add more tfork tests
       via  9b1c779 lib/util: adjust loglevel in tfork test with samba_runcmd_send()
       via  12a3eb7 lib/util: make use of tfork in samba_runcmd_send()
       via  844db65 lib/util: enhanced tfork()
      from  1f5a297 s3:rpc_server: wrap make_auth4_context() into {become,unbecome}_root()

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit a760324dbd04f5c53636fa66ad6f89b14a4d1042
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Jun 28 07:14:36 2017 +0200

    net: add net cache samlogon list|show|ndrdump|delete
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    
    Autobuild-User(master): Ralph Böhme <slow at samba.org>
    Autobuild-Date(master): Tue Jul  4 00:12:46 CEST 2017 on sn-devel-144

commit 392c96e884aa01b64aaa6de5b2ff375810cab89b
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Jun 27 17:34:34 2017 +0200

    samlogon_cache: add netsamlog_cache_for_all()
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 4be4f4b3a31bfa75b4df38744fd61baad646c84b
Author: Ralph Boehme <slow at samba.org>
Date:   Mon Jul 3 12:38:22 2017 +0200

    netlogon.idl: mark session keys with NDR_SECRET
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 492930779a228d3fddfc584141dace393c7f5ebb
Author: Ralph Boehme <slow at samba.org>
Date:   Mon Jul 3 15:16:13 2017 +0200

    s4/torture: test fetching a resume key twice
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 2d01558ad3d9452c8c64a30e5bf143b4bdc3e207
Author: Ralph Boehme <slow at samba.org>
Date:   Sat Jun 10 09:05:55 2017 +0200

    s3/smbd: remove unneeded flags argument from SMB_VFS_OFFLOAD_WRITE_SEND
    
    ...and instead use the fsctl to infer required behaviour in the VFS
    backends.
    
    Note that this removes the check from vfs_default because there we only
    handle FSCTL_SRV_COPYCHUNK(_WRITE) and must always perform the lock
    checks.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit fe6d71d7f978c4db8401ccff3cce17c9368b24e4
Author: Ralph Boehme <slow at samba.org>
Date:   Fri Jun 9 17:27:17 2017 +0200

    s3/smbd: get rid of files_struct.aapl_copyfile_supported
    
    A previous commit removed the special hook from the SMB layer, so we
    don't need this anymore.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 2b3fcc56e6ecc696da753ff3421cb9008fb5f4ea
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Jun 6 14:36:38 2017 +0200

    s4/torture: more tests for copy-chunk across shares
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 3645f83a3c83fa3e4bf4dbacf885cc4295e7eadd
Author: Ralph Boehme <slow at samba.org>
Date:   Fri Jun 9 13:02:49 2017 +0200

    s3/vfs: make SMB_VFS_OFFLOAD_WRITE_SEND offload token based
    
    Remove the source fsp argument and instead pass the offload token
    generated with SMB_VFS_OFFLOAD_READ_SEND/RECV.
    
    An actual offload fsctl is not implemented yet, neither in the VFS nor
    at the SMB ioctl layer, and returns NT_STATUS_NOT_IMPLEMENTED
    
    With these changes we now pass the copy-chunk-across-shares test.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit d50f307e97ae28b9fbdc2e6cffb1b5493c583a09
Author: Ralph Boehme <slow at samba.org>
Date:   Mon Jun 5 08:31:19 2017 +0200

    s4/torture: add a test for copy-chunk across shares
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 74e018f476608429caa1c3594102485ccc17afce
Author: Ralph Boehme <slow at samba.org>
Date:   Fri Jun 9 16:50:05 2017 +0200

    s3/smbd: redesign macOS copyfile copy-chunk
    
    The copy-chunk request chunk_count can be 0 and Windows server just
    returns success saying number of copied chunks is 0.
    
    macOS client overload this after negotiating AAPL via their SMB2
    extensions, meaning it's a so called copyfile request (copy whole file
    and all streams).
    
    We previously checked this at the SMB layer, with this patch we just
    send this down the VFS, if vfs_fruit is loaded it implements the macOS
    copyile semantics, otherwise we get Windows behavour..
    
    No change in behaviour.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 2ad11c6920fada646cd174b53efa4cf590b80901
Author: Ralph Boehme <slow at samba.org>
Date:   Fri Jun 9 16:35:39 2017 +0200

    s3/smbd: remove copy-chunk chunk merging optimisation
    
    As we won't have the source fsp around with the coming token based
    offload read/write based code, we can't merge chunks as that requires
    checking against the source file size.
    
    We could still merge chunks without checking, but getting the error
    handling correct would require comlicated logic for the SMB2 ioctl
    copy-chunk error reporting.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 9c6550262394dca73b7f7c4bfa1038af8c866904
Author: Ralph Boehme <slow at samba.org>
Date:   Fri Jun 9 13:08:43 2017 +0200

    s3/smbd: remove unused arg smb1req from copychunk_check_handles()
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 60e3e10e84983da073fcc539378ec50f88e9f41c
Author: Ralph Boehme <slow at samba.org>
Date:   Fri Jun 9 13:02:49 2017 +0200

    s3/smbd: remove flags2 FLAGS2_READ_PERMIT_EXECUTE hack in the SMB2 code
    
    By adding a SMB2 specific CHECK_READ_SMB2 macro called that always
    grants read access if execute was granted, we can get rid of the flags2
    hack.
    
    All callers in the SMB2 code are converted to use the CHECK_READ_SMB2
    macro.
    
    Amongs other things, this later allows moving the handle checks in
    copychunk_check_handles() down into the VFS layer where we don't have
    access to the smbreq.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 697d8e9e2a48643fe771723beaf1c33f625921f6
Author: Ralph Boehme <slow at samba.org>
Date:   Fri Jun 9 12:57:03 2017 +0200

    s3/smbd: remove ununsed req arg from CHECK_READ_IOCTL macro
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 64bedefa117b4861a752c4e2fc3f5e775eb7f542
Author: Ralph Boehme <slow at samba.org>
Date:   Sun Jun 4 13:50:33 2017 +0200

    s3/vfs: rename SMB_VFS_COPY_CHUNK_SEND/RECV to SMB_VFS_OFFLOAD_WRITE_SEND/RECV
    
    No change in behaviour, just a rename in preperation of more changes to
    SMB_VFS_OFFLOAD_WRITE_SEND. It helps keeping the diff of the actual
    changes smaller.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 67ed1edba75e967d7d8d4157f918b50d23c47b0b
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Jun 6 12:23:27 2017 +0200

    s3/smbd: use SMB_VFS_OFFLOAD_READ_SEND/RECV
    
    No change in behaviour, this just uses the new SMB_VFS_OFFLOAD_READ_SEND
    in the duplicate extents and the resume key ioctls.
    
    In the copy-chunk/resume-key case this means using
    SMB_VFS_OFFLOAD_READ_SEND to create the resume-key token that is
    returned to the client.
    
    In the duplicate-extents case this ensures we can later call
    offload-write, which requires a previous call to offload-read that
    associates a token with a file-handle.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit af6cbc7a441e05f71ae4e97c7d82c27868633e53
Author: Ralph Boehme <slow at samba.org>
Date:   Sat Jun 3 12:57:59 2017 +0200

    s3/vfs: add SMB_VFS_OFFLOAD_READ_SEND/RECV
    
    Add SMB_VFS_OFFLOAD_READ_SEND an SMB_VFS_OFFLOAD_READ_RECV.
    
    This paves the way for supporting server-side copy-chunk with source and
    destination file-handles on different shares. It can be used to
    implement copy offload fsctl in the future, but for now this will be
    used as a mere copy-chunk replacement.
    
    SMB_VFS_OFFLOAD_READ generates a token that associates an fsp with the
    token and stores the fsp in a in-memory db.
    
    Initially only a copy-chunk resume key fsctl is supported. In the future
    this can be enhanced to support real offload fsctl.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 47600c4977fb013f6f7c63f90ac9d64eac71bd71
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Jun 6 14:50:15 2017 +0200

    s4/torture: pass destination tree to test_setup_copy_chunk
    
    No change in behaviour, will be used in subsequent commits.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit d6a8a79fcb08387133e3e9720000a72e2707c156
Author: Ralph Boehme <slow at samba.org>
Date:   Fri Jun 2 13:09:41 2017 +0200

    librpc/idl: make use storage_offload_token
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit e3cb6a936df1b52107081dfa817e18d55e473abf
Author: Ralph Boehme <slow at samba.org>
Date:   Fri Jun 2 13:06:31 2017 +0200

    librpc/idl: fix STORAGE_OFFLOAD_TOKEN_TYPE_ZERO_DATA definition
    
    STORAGE_OFFLOAD_TOKEN_TYPE_ZERO_DATA is defined as 0xffff0001 in MS-FSCC
    2.3.79.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit ebee4589fbabe0ed6f8b1662481558ff784e0e92
Author: Ralph Boehme <slow at samba.org>
Date:   Fri Jun 2 13:05:22 2017 +0200

    librpc/idl: convert offload flags to a bitmap
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit d10ca1a00550d8ca315f6f741d87c668d29faeb9
Author: Ralph Boehme <slow at samba.org>
Date:   Fri May 26 18:10:07 2017 +0200

    lib/util: add more tfork tests
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 9b1c7794478e397d99e14d1a2970c93df846d987
Author: Ralph Boehme <slow at samba.org>
Date:   Thu May 18 12:02:22 2017 +0200

    lib/util: adjust loglevel in tfork test with samba_runcmd_send()
    
    No change in behaviour, this just ensures stdout and stderror are
    logged with log level 0.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 12a3eb7b5e9a2fd9f5d03a6e80e5f33fcfd3b811
Author: Ralph Boehme <slow at samba.org>
Date:   Tue May 16 18:36:03 2017 +0200

    lib/util: make use of tfork in samba_runcmd_send()
    
    This makes it possible to use samba_runcmd_send() in processes like smbd
    that install a SIGCHLD handler that reaps all terminated children.
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 844db654987936cf257d3fa8a256e43c4c96d7e7
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Apr 26 00:48:39 2017 +0200

    lib/util: enhanced tfork()
    
    This function is a solution to the problem of fork() requiring special
    preperations in the caller to handle SIGCHLD signals and to reap the
    child by wait()ing for it.
    
    Instead, tfork provides a pollable file descriptor. The caller gets the
    file descriptor by calling tfork_event_fd() on the handle returned from
    tfork_create() and the caller can then get the status of the child
    with a call to tfork_status().
    
    tfork avoids raising SIGCHLD signals in the caller by installing a
    temporary SIGCHLD handler from inside tfork_create() and tfork_status().
    
    The termination signal of other child processes not created with tfork()
    is forwarded to the existing signal handler if any.
    
    There's one thing this thing can't protect us against and that is if a
    process installs a SIGCHLD handler from one thread while another thread
    is running inside tfork_create() or tfork_status() and the signal
    handler doesn't forward signals for exitted childs it didn't fork, ie
    our childs.
    
    Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 examples/VFS/skel_opaque.c           |  60 ++-
 examples/VFS/skel_transparent.c      | 140 +++++-
 lib/util/tests/tfork.c               | 481 +++++++++++++++++-
 lib/util/tfork.c                     | 950 +++++++++++++++++++++++++++--------
 lib/util/tfork.h                     | 102 +++-
 lib/util/util_runcmd.c               | 105 ++--
 lib/util/util_runcmd.h               |   4 +-
 librpc/idl/ioctl.idl                 |  21 +-
 librpc/idl/netlogon.idl              |   4 +-
 selftest/knownfail                   |   1 +
 source3/include/smb_macros.h         |  18 +-
 source3/include/vfs.h                |  91 ++--
 source3/include/vfs_macros.h         |  28 +-
 source3/libsmb/samlogon_cache.c      | 102 ++++
 source3/libsmb/samlogon_cache.h      |   5 +
 source3/modules/offload_token.c      | 312 ++++++++++++
 source3/modules/offload_token.h      |  40 ++
 source3/modules/vfs_btrfs.c          | 204 +++++++-
 source3/modules/vfs_default.c        | 278 ++++++----
 source3/modules/vfs_fruit.c          | 206 ++++++--
 source3/modules/vfs_full_audit.c     |  78 ++-
 source3/modules/vfs_glusterfs.c      |   2 -
 source3/modules/vfs_time_audit.c     | 156 ++++--
 source3/modules/wscript_build        |  10 +-
 source3/smbd/smb2_glue.c             |  15 -
 source3/smbd/smb2_ioctl_filesys.c    |  50 +-
 source3/smbd/smb2_ioctl_network_fs.c | 342 ++++---------
 source3/smbd/smb2_read.c             |   2 +-
 source3/smbd/vfs.c                   |  68 ++-
 source3/utils/net_cache.c            | 232 +++++++++
 source4/torture/smb2/ioctl.c         | 372 ++++++++++++--
 31 files changed, 3553 insertions(+), 926 deletions(-)
 create mode 100644 source3/modules/offload_token.c
 create mode 100644 source3/modules/offload_token.h


Changeset truncated at 500 lines:

diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c
index 74ffb67..fed9d2f 100644
--- a/examples/VFS/skel_opaque.c
+++ b/examples/VFS/skel_opaque.c
@@ -537,18 +537,60 @@ static struct file_id skel_file_id_create(vfs_handle_struct *handle,
 	return id;
 }
 
+struct skel_offload_read_state {
+	bool dummy;
+};
+
+static struct tevent_req *skel_offload_read_send(
+	TALLOC_CTX *mem_ctx,
+	struct tevent_context *ev,
+	struct vfs_handle_struct *handle,
+	struct files_struct *fsp,
+	uint32_t fsctl,
+	uint32_t ttl,
+	off_t offset,
+	size_t to_copy)
+{
+	struct tevent_req *req = NULL;
+	struct skel_offload_read_state *state = NULL;
+
+	req = tevent_req_create(mem_ctx, &state, struct skel_offload_read_state);
+	if (req == NULL) {
+		return NULL;
+	}
+
+	tevent_req_nterror(req, NT_STATUS_NOT_IMPLEMENTED);
+	return tevent_req_post(req, ev);
+}
+
+static NTSTATUS skel_offload_read_recv(struct tevent_req *req,
+				       struct vfs_handle_struct *handle,
+				       TALLOC_CTX *mem_ctx,
+				       DATA_BLOB *_token_blob)
+{
+	NTSTATUS status;
+
+	if (tevent_req_is_nterror(req, &status)) {
+		tevent_req_received(req);
+		return status;
+	}
+	tevent_req_received(req);
+
+	return NT_STATUS_OK;
+}
+
 struct skel_cc_state {
 	uint64_t unused;
 };
-static struct tevent_req *skel_copy_chunk_send(struct vfs_handle_struct *handle,
+static struct tevent_req *skel_offload_write_send(struct vfs_handle_struct *handle,
 					       TALLOC_CTX *mem_ctx,
 					       struct tevent_context *ev,
-					       struct files_struct *src_fsp,
-					       off_t src_off,
+					       uint32_t fsctl,
+					       DATA_BLOB *token,
+					       off_t transfer_offset,
 					       struct files_struct *dest_fsp,
 					       off_t dest_off,
-					       off_t num,
-					       uint32_t flags)
+					       off_t num)
 {
 	struct tevent_req *req;
 	struct skel_cc_state *cc_state;
@@ -562,7 +604,7 @@ static struct tevent_req *skel_copy_chunk_send(struct vfs_handle_struct *handle,
 	return tevent_req_post(req, ev);
 }
 
-static NTSTATUS skel_copy_chunk_recv(struct vfs_handle_struct *handle,
+static NTSTATUS skel_offload_write_recv(struct vfs_handle_struct *handle,
 				     struct tevent_req *req,
 				     off_t *copied)
 {
@@ -967,8 +1009,10 @@ struct vfs_fn_pointers skel_opaque_fns = {
 	.realpath_fn = skel_realpath,
 	.chflags_fn = skel_chflags,
 	.file_id_create_fn = skel_file_id_create,
-	.copy_chunk_send_fn = skel_copy_chunk_send,
-	.copy_chunk_recv_fn = skel_copy_chunk_recv,
+	.offload_read_send_fn = skel_offload_read_send,
+	.offload_read_recv_fn = skel_offload_read_recv,
+	.offload_write_send_fn = skel_offload_write_send,
+	.offload_write_recv_fn = skel_offload_write_recv,
 	.get_compression_fn = skel_get_compression,
 	.set_compression_fn = skel_set_compression,
 
diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c
index e584d51..d9123e0 100644
--- a/examples/VFS/skel_transparent.c
+++ b/examples/VFS/skel_transparent.c
@@ -622,54 +622,142 @@ static struct file_id skel_file_id_create(vfs_handle_struct *handle,
 	return SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
 }
 
-struct skel_cc_state {
+struct skel_offload_read_state {
+	struct vfs_handle_struct *handle;
+	DATA_BLOB token;
+};
+
+static void skel_offload_read_done(struct tevent_req *subreq);
+
+static struct tevent_req *skel_offload_read_send(
+	TALLOC_CTX *mem_ctx,
+	struct tevent_context *ev,
+	struct vfs_handle_struct *handle,
+	struct files_struct *fsp,
+	uint32_t fsctl,
+	uint32_t ttl,
+	off_t offset,
+	size_t to_copy)
+{
+	struct tevent_req *req = NULL;
+	struct skel_offload_read_state *state = NULL;
+	struct tevent_req *subreq = NULL;
+
+	req = tevent_req_create(mem_ctx, &state, struct skel_offload_read_state);
+	if (req == NULL) {
+		return NULL;
+	}
+	*state = (struct skel_offload_read_state) {
+		.handle = handle,
+	};
+
+	subreq = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
+						fsctl, ttl, offset, to_copy);
+	if (tevent_req_nomem(subreq, req)) {
+		return tevent_req_post(req, ev);
+	}
+	tevent_req_set_callback(subreq, skel_offload_read_done, req);
+	return req;
+}
+
+static void skel_offload_read_done(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct skel_offload_read_state *state = tevent_req_data(
+		req, struct skel_offload_read_state);
+	NTSTATUS status;
+
+	status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq,
+						state->handle,
+						state,
+						&state->token);
+	TALLOC_FREE(subreq);
+	if (tevent_req_nterror(req, status)) {
+		return;
+	}
+
+	tevent_req_done(req);
+	return;
+}
+
+static NTSTATUS skel_offload_read_recv(struct tevent_req *req,
+				       struct vfs_handle_struct *handle,
+				       TALLOC_CTX *mem_ctx,
+				       DATA_BLOB *_token)
+{
+	struct skel_offload_read_state *state = tevent_req_data(
+		req, struct skel_offload_read_state);
+	DATA_BLOB token;
+	NTSTATUS status;
+
+	if (tevent_req_is_nterror(req, &status)) {
+		tevent_req_received(req);
+		return status;
+	}
+
+	token = data_blob_talloc(mem_ctx,
+				 state->token.data,
+				 state->token.length);
+
+	tevent_req_received(req);
+
+	if (token.data == NULL) {
+		return NT_STATUS_NO_MEMORY;
+	}
+
+	*_token = token;
+	return NT_STATUS_OK;
+}
+
+struct skel_offload_write_state {
 	struct vfs_handle_struct *handle;
 	off_t copied;
 };
-static void skel_copy_chunk_done(struct tevent_req *subreq);
+static void skel_offload_write_done(struct tevent_req *subreq);
 
-static struct tevent_req *skel_copy_chunk_send(struct vfs_handle_struct *handle,
+static struct tevent_req *skel_offload_write_send(struct vfs_handle_struct *handle,
 					       TALLOC_CTX *mem_ctx,
 					       struct tevent_context *ev,
-					       struct files_struct *src_fsp,
-					       off_t src_off,
+					       uint32_t fsctl,
+					       DATA_BLOB *token,
+					       off_t transfer_offset,
 					       struct files_struct *dest_fsp,
 					       off_t dest_off,
-					       off_t num,
-					       uint32_t flags)
+					       off_t num)
 {
 	struct tevent_req *req;
 	struct tevent_req *subreq;
-	struct skel_cc_state *cc_state;
+	struct skel_offload_write_state *state;
 
-	req = tevent_req_create(mem_ctx, &cc_state, struct skel_cc_state);
+	req = tevent_req_create(mem_ctx, &state, struct skel_offload_write_state);
 	if (req == NULL) {
 		return NULL;
 	}
 
-	cc_state->handle = handle;
-	subreq = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, cc_state, ev,
-					      src_fsp, src_off,
-					      dest_fsp, dest_off, num, flags);
+	state->handle = handle;
+	subreq = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, state, ev,
+					      fsctl, token, transfer_offset,
+					      dest_fsp, dest_off, num);
 	if (tevent_req_nomem(subreq, req)) {
 		return tevent_req_post(req, ev);
 	}
 
-	tevent_req_set_callback(subreq, skel_copy_chunk_done, req);
+	tevent_req_set_callback(subreq, skel_offload_write_done, req);
 	return req;
 }
 
-static void skel_copy_chunk_done(struct tevent_req *subreq)
+static void skel_offload_write_done(struct tevent_req *subreq)
 {
 	struct tevent_req *req = tevent_req_callback_data(
 		subreq, struct tevent_req);
-	struct skel_cc_state *cc_state
-			= tevent_req_data(req, struct skel_cc_state);
+	struct skel_offload_write_state *state
+			= tevent_req_data(req, struct skel_offload_write_state);
 	NTSTATUS status;
 
-	status = SMB_VFS_NEXT_COPY_CHUNK_RECV(cc_state->handle,
+	status = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(state->handle,
 					      subreq,
-					      &cc_state->copied);
+					      &state->copied);
 	TALLOC_FREE(subreq);
 	if (tevent_req_nterror(req, status)) {
 		return;
@@ -677,15 +765,15 @@ static void skel_copy_chunk_done(struct tevent_req *subreq)
 	tevent_req_done(req);
 }
 
-static NTSTATUS skel_copy_chunk_recv(struct vfs_handle_struct *handle,
+static NTSTATUS skel_offload_write_recv(struct vfs_handle_struct *handle,
 				     struct tevent_req *req,
 				     off_t *copied)
 {
-	struct skel_cc_state *cc_state
-			= tevent_req_data(req, struct skel_cc_state);
+	struct skel_offload_write_state *state
+			= tevent_req_data(req, struct skel_offload_write_state);
 	NTSTATUS status;
 
-	*copied = cc_state->copied;
+	*copied = state->copied;
 	if (tevent_req_is_nterror(req, &status)) {
 		tevent_req_received(req);
 		return status;
@@ -1094,8 +1182,10 @@ struct vfs_fn_pointers skel_transparent_fns = {
 	.realpath_fn = skel_realpath,
 	.chflags_fn = skel_chflags,
 	.file_id_create_fn = skel_file_id_create,
-	.copy_chunk_send_fn = skel_copy_chunk_send,
-	.copy_chunk_recv_fn = skel_copy_chunk_recv,
+	.offload_read_send_fn = skel_offload_read_send,
+	.offload_read_recv_fn = skel_offload_read_recv,
+	.offload_write_send_fn = skel_offload_write_send,
+	.offload_write_recv_fn = skel_offload_write_recv,
 	.get_compression_fn = skel_get_compression,
 	.set_compression_fn = skel_set_compression,
 
diff --git a/lib/util/tests/tfork.c b/lib/util/tests/tfork.c
index bd5809d..c900502 100644
--- a/lib/util/tests/tfork.c
+++ b/lib/util/tests/tfork.c
@@ -29,61 +29,476 @@
 #include "lib/util/tfork.h"
 #include "lib/util/samba_util.h"
 #include "lib/util/sys_rw.h"
+#ifdef HAVE_PTHREAD
+#include <pthread.h>
+#include <sys/syscall.h>
+#endif
 
 static bool test_tfork_simple(struct torture_context *tctx)
 {
-	pid_t pid;
-	pid_t parent = getpid();
-	pid_t parent_arg;
+        pid_t parent = getpid();
+        struct tfork *t = NULL;
+        pid_t child;
+        int ret;
 
-	pid = tfork(NULL, &parent_arg);
-	if (pid == 0) {
-		torture_comment(tctx, "my parent pid is %d\n", parent);
-		torture_assert(tctx, parent == parent_arg, "tfork failed\n");
-		_exit(0);
-	}
-	if (pid == -1) {
+        t = tfork_create();
+        if (t == NULL) {
+                torture_fail(tctx, "tfork failed\n");
+                return false;
+        }
+        child = tfork_child_pid(t);
+        if (child == 0) {
+                torture_comment(tctx, "my parent pid is %d\n", parent);
+                torture_assert(tctx, getpid() != parent, "tfork failed\n");
+                _exit(0);
+        }
+
+        ret = tfork_destroy(&t);
+        torture_assert(tctx, ret == 0, "tfork_destroy failed\n");
+
+        return true;
+}
+
+static bool test_tfork_status(struct torture_context *tctx)
+{
+	struct tfork *t = NULL;
+	int status;
+	pid_t child;
+	bool ok = true;
+
+	t = tfork_create();
+	if (t == NULL) {
 		torture_fail(tctx, "tfork failed\n");
 		return false;
 	}
+	child = tfork_child_pid(t);
+	if (child == 0) {
+		_exit(123);
+	}
+
+	status = tfork_status(&t, true);
+	if (status == -1) {
+		torture_fail(tctx, "tfork_status failed\n");
+	}
 
-	return true;
+	torture_assert_goto(tctx, WIFEXITED(status) == true, ok, done,
+			    "tfork failed\n");
+	torture_assert_goto(tctx, WEXITSTATUS(status) == 123, ok, done,
+			    "tfork failed\n");
+
+	torture_comment(tctx, "exit status [%d]\n", WEXITSTATUS(status));
+
+done:
+	return ok;
 }
 
-static bool test_tfork_status(struct torture_context *tctx)
+static bool test_tfork_sigign(struct torture_context *tctx)
 {
+	struct tfork *t = NULL;
+	struct sigaction act;
 	pid_t child;
 	int status;
-	ssize_t nread;
-	int status_fd = -1;
 	bool ok = true;
+	int ret;
+
+	act = (struct sigaction) {
+		.sa_flags = SA_NOCLDWAIT,
+		.sa_handler = SIG_IGN,
+	};
+
+	ret = sigaction(SIGCHLD, &act, NULL);
+	torture_assert_goto(tctx, ret == 0, ok, done, "sigaction failed\n");
 
-	child = tfork(&status_fd, NULL);
+	t = tfork_create();
+	if (t == NULL) {
+		torture_fail(tctx, "tfork failed\n");
+		return false;
+	}
+	child = tfork_child_pid(t);
 	if (child == 0) {
+		sleep(1);
 		_exit(123);
 	}
+
+	child = fork();
 	if (child == -1) {
+		torture_fail(tctx, "fork failed\n");
+		return false;
+	}
+	if (child == 0) {
+		_exit(0);
+	}
+
+	status = tfork_status(&t, true);
+	if (status == -1) {
+		torture_fail(tctx, "tfork_status failed\n");
+	}
+
+	torture_assert_goto(tctx, WIFEXITED(status) == true, ok, done,
+			    "tfork failed\n");
+	torture_assert_goto(tctx, WEXITSTATUS(status) == 123, ok, done,
+			    "tfork failed\n");
+	torture_comment(tctx, "exit status [%d]\n", WEXITSTATUS(status));
+
+done:
+	return ok;
+}
+
+static void sigchld_handler1(int signum, siginfo_t *si, void *u)
+{
+	pid_t pid;
+	int status;
+
+	if (signum != SIGCHLD) {
+		abort();
+	}
+
+	pid = waitpid(si->si_pid, &status, 0);
+	if (pid != si->si_pid) {
+		abort();
+	}
+}
+
+static bool test_tfork_sighandler(struct torture_context *tctx)
+{
+	struct tfork *t = NULL;
+	struct sigaction act;
+	struct sigaction oldact;
+	pid_t child;
+	int status;
+	bool ok = true;
+	int ret;
+
+	act = (struct sigaction) {
+		.sa_flags = SA_SIGINFO,
+		.sa_sigaction = sigchld_handler1,
+	};
+
+	ret = sigaction(SIGCHLD, &act, &oldact);
+	torture_assert_goto(tctx, ret == 0, ok, done, "sigaction failed\n");
+
+	t = tfork_create();
+	if (t == NULL) {
 		torture_fail(tctx, "tfork failed\n");
 		return false;
 	}
+	child = tfork_child_pid(t);
+	if (child == 0) {
+		sleep(1);
+		_exit(123);
+	}
 
-	nread = sys_read(status_fd, &status, sizeof(status));
-	if (nread != sizeof(status)) {
-		torture_fail(tctx, "sys_read failed\n");
+	child = fork();
+	if (child == -1) {
+		torture_fail(tctx, "fork failed\n");
+		return false;
+	}
+	if (child == 0) {
+		_exit(0);
+	}
+
+	status = tfork_status(&t, true);
+	if (status == -1) {
+		torture_fail(tctx, "tfork_status failed\n");
 	}
 
 	torture_assert_goto(tctx, WIFEXITED(status) == true, ok, done,
 			    "tfork failed\n");
 	torture_assert_goto(tctx, WEXITSTATUS(status) == 123, ok, done,
 			    "tfork failed\n");
+	torture_comment(tctx, "exit status [%d]\n", WEXITSTATUS(status));
+
+done:
+	sigaction(SIGCHLD, &oldact, NULL);
+
+	return ok;


-- 
Samba Shared Repository



More information about the samba-cvs mailing list