[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Fri Nov 22 11:58:03 MST 2013


The branch, master has been updated
       via  cb353a3 torture: test get/set compression ioctl permissions
       via  aa197c1 torture: split open from test_setup_create_fill
       via  9a3d4d4 smbd/open: disable compression with FILE_NO_COMPRESSION
       via  8bc4e6a s3-smbd: support FILE_ATTRIBUTE_COMPRESSED
       via  a18e0e3 smbd: split out dos_mode debug print function
       via  423230f vfs_btrfs: advertise per-file compression capability
       via  b24e42a vfs_btrfs: fix copy-chunk dest unlock args
       via  3627ed7 vfs_btrfs: add [GET/SET]_COMPRESSION handlers
       via  4ffc85d smb2/ioctl: add support for FSCTL_[GET/SET]_COMPRESSION
       via  d8d5d4c vfs: add [GET/SET]_COMPRESSION hooks
       via  2b435ad torture: attempt to set compression via SetInfo
       via  7dd05f5 torture: test dir non-inherit in compress_inherit_disable
       via  452c2ac selftest/s3: run smb2.ioctl against FS specific share
       via  a3839de selftest/s3: expose share with FS applicable config
       via  4e6934e Rename the profile enums with a SAMBA_ prefix to avoid conflict with system files.
      from  e665fc3 lib/param: Consolidate code to enable smb signing on the server, always enable on AD DC

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


- Log -----------------------------------------------------------------
commit cb353a34dd0ed4475ab13037689a41eced7f791d
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:39 2013 +0100

    torture: test get/set compression ioctl permissions
    
    Windows Server 2012[r2] exhibits some strange behaviour with regard
    to handling the compression fsctls.
    [READ/WRITE]_ATTR permissions are not required for the corresponding
    get/set compression ioctls. WRITE_DATA is required for set compression.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Fri Nov 22 19:57:48 CET 2013 on sn-devel-104

commit aa197c18c4dbd7fbe45702e59600e7acad013f63
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:38 2013 +0100

    torture: split open from test_setup_create_fill
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 9a3d4d484e0868d9174f37a8dfd9efd4e77c044d
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:37 2013 +0100

    smbd/open: disable compression with FILE_NO_COMPRESSION
    
    Files and directories created with FILE_NO_COMPRESSION should not
    inherit the compression attribute from their parent directory.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 8bc4e6a9e0b09c744351e60f66c33c4d22dcfb6e
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:36 2013 +0100

    s3-smbd: support FILE_ATTRIBUTE_COMPRESSED
    
    The FILE_ATTRIBUTE_COMPRESSED flag is computed based on whether the
    filesystem exposes the FILE_FILE_COMPRESSION capability, and whether
    SMB_VFS_GET_COMPRESSION() reports that the file or directory is
    currently compressed.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit a18e0e3aae7e69705cbf78a3bc73617eef630897
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:35 2013 +0100

    smbd: split out dos_mode debug print function
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 423230f473020326ba6262784ed03268f4a894f8
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:34 2013 +0100

    vfs_btrfs: advertise per-file compression capability
    
    Plumb into the get_fs_capabilities code path to advertise the
    FILE_FILE_COMPRESSION attribute.
    
    Also, document file compression support in the VFS btrfs man page.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b24e42a70242757f83a60e723950bbaac148379a
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:33 2013 +0100

    vfs_btrfs: fix copy-chunk dest unlock args
    
    src_fsp used instead of dest_fsp for unlock.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3627ed732637a3b1bf992156306d6ffc14727b46
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:32 2013 +0100

    vfs_btrfs: add [GET/SET]_COMPRESSION handlers
    
    Translate such requests into FS_IOC_GETFLAGS and FS_IOC_SETFLAGS ioctls
    respectively. The module makes no distinction between compression types,
    only whether or not compression is enabled.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 4ffc85dfc561b077eb1e7afe3b3e7445ea741d2a
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:31 2013 +0100

    smb2/ioctl: add support for FSCTL_[GET/SET]_COMPRESSION
    
    In line with MS-FSCC 2.3.47, the FSCTL_SET_COMPRESSION ioctl allows
    remote SMB2 clients to enable and disable compression on a
    per-file or per-directory basis.
    Compression state can be retrieved using the FSCTL_GET_COMPRESSION
    request.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d8d5d4c7428683da04fa4c8b344504e7044f9b1c
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:30 2013 +0100

    vfs: add [GET/SET]_COMPRESSION hooks
    
    The VFS interfaces are sychronous, as the operations only modify
    meta-data.
    These hooks are dependent on support for transparent compression by the
    underlying filesystem - vfs_default returns INVALID_DEVICE_REQUEST.
    Support for other filesystems providing transparent comression, such as
    Btrfs and ZFS, can be added in future.
    
    The get_compression function takes fsp and smb_fname arguments. The
    smb_fname argument is needed due to the current dosmode() code-path.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2b435ad4b45ec39b0cf70f55699daba3bcfcee08
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:29 2013 +0100

    torture: attempt to set compression via SetInfo
    
    Doing so should give a successful SetInfo response, however the
    attribute should not be set in subsequent GetInfo / ioctl responses.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 7dd05f55a8cc34a345fd87e868e3d391e06229b3
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:28 2013 +0100

    torture: test dir non-inherit in compress_inherit_disable
    
    Also add a note reguarding Windows 2008GM copy-chunk note:
    Windows 2008GM (non-R2) fails the copy-chunk src=dest overlap test, as
    it appears to use a different chunk copy algorithm to 208R2.
    Takeaway advice is to avoid using copy-chunk when the source and
    destination ranges overlap in the same file.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 452c2ac704b2b1e17f5d82910703eec0411eece2
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:27 2013 +0100

    selftest/s3: run smb2.ioctl against FS specific share
    
    Run the smb2.ioctl tests against the filesystem specific share.
    This adds ~12s to the selftest runtime on my SSD+Btrfs setup.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit a3839ded473ae6d85d44a25537064ce33c3888c1
Author: David Disseldorp <ddiss at samba.org>
Date:   Mon Nov 18 14:54:26 2013 +0100

    selftest/s3: expose share with FS applicable config
    
    Attempt to determine the underlying test share filesystem using statfs.
    If the filesystem is detected and an applicable configuration is
    available, then apply it to a new filesystem specific share.
    Btrfs is currently the only VFS module to utilize this logic.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 4e6934ec6c163ad6fd9c317b5a7dd7775b0dc83f
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Nov 21 21:33:33 2013 -0800

    Rename the profile enums with a SAMBA_ prefix to avoid conflict with system files.
    
    WRITE_FLUSH is defined in fs.h in Linux.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: David Disseldorp <ddiss at samba.org>

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

Summary of changes:
 docs-xml/manpages/vfs_btrfs.8.xml      |    5 +
 docs-xml/manpages/vfs_full_audit.8.xml |    2 +
 examples/VFS/skel_opaque.c             |   19 ++
 examples/VFS/skel_transparent.c        |   21 ++
 selftest/target/Samba3.pm              |   26 +++-
 source3/include/smb.h                  |   18 +-
 source3/include/smbprofile.h           |    2 +-
 source3/include/vfs.h                  |   19 ++
 source3/include/vfs_macros.h           |   12 +-
 source3/modules/vfs_btrfs.c            |  136 +++++++++++++-
 source3/modules/vfs_default.c          |   19 ++
 source3/modules/vfs_full_audit.c       |   40 ++++
 source3/modules/vfs_time_audit.c       |   53 ++++++
 source3/selftest/tests.py              |    4 +
 source3/smbd/close.c                   |    2 +-
 source3/smbd/dosmode.c                 |   90 ++++++++--
 source3/smbd/fileio.c                  |   26 ++--
 source3/smbd/open.c                    |   12 ++
 source3/smbd/oplock.c                  |    2 +-
 source3/smbd/reply.c                   |    4 +-
 source3/smbd/smb2_ioctl_filesys.c      |  117 ++++++++++++-
 source3/smbd/vfs.c                     |   27 +++-
 source3/utils/status_profile.c         |   16 +-
 source3/wscript                        |    2 +-
 source4/torture/smb2/ioctl.c           |  316 +++++++++++++++++++++++++++++--
 25 files changed, 911 insertions(+), 79 deletions(-)


Changeset truncated at 500 lines:

diff --git a/docs-xml/manpages/vfs_btrfs.8.xml b/docs-xml/manpages/vfs_btrfs.8.xml
index 01f788c..6437321 100644
--- a/docs-xml/manpages/vfs_btrfs.8.xml
+++ b/docs-xml/manpages/vfs_btrfs.8.xml
@@ -46,6 +46,11 @@
 	</para>
 
 	<para>
+		This module also exposes Btrfs per-file compression support to
+		SMB clients via the get/set compression fsctls.
+	</para>
+
+	<para>
 		This module is stackable.
 	</para>
 </refsect1>
diff --git a/docs-xml/manpages/vfs_full_audit.8.xml b/docs-xml/manpages/vfs_full_audit.8.xml
index 1266b1f..2be26b0 100644
--- a/docs-xml/manpages/vfs_full_audit.8.xml
+++ b/docs-xml/manpages/vfs_full_audit.8.xml
@@ -62,6 +62,7 @@
         <member>fstat</member>
         <member>fsync</member>
         <member>ftruncate</member>
+        <member>get_compression</member>
         <member>get_nt_acl</member>
         <member>get_quota</member>
         <member>get_shadow_copy_data</member>
@@ -91,6 +92,7 @@
         <member>rmdir</member>
         <member>seekdir</member>
         <member>sendfile</member>
+        <member>set_compression</member>
         <member>set_nt_acl</member>
         <member>set_quota</member>
         <member>setxattr</member>
diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c
index 53c64ca..5abea20 100644
--- a/examples/VFS/skel_opaque.c
+++ b/examples/VFS/skel_opaque.c
@@ -528,6 +528,23 @@ static NTSTATUS skel_copy_chunk_recv(struct vfs_handle_struct *handle,
 	return NT_STATUS_OK;
 }
 
+static NTSTATUS skel_get_compression(struct vfs_handle_struct *handle,
+				     TALLOC_CTX *mem_ctx,
+				     struct files_struct *fsp,
+				     struct smb_filename *smb_fname,
+				     uint16_t *_compression_fmt)
+{
+	return NT_STATUS_INVALID_DEVICE_REQUEST;
+}
+
+static NTSTATUS skel_set_compression(struct vfs_handle_struct *handle,
+				     TALLOC_CTX *mem_ctx,
+				     struct files_struct *fsp,
+				     uint16_t compression_fmt)
+{
+	return NT_STATUS_INVALID_DEVICE_REQUEST;
+}
+
 static NTSTATUS skel_streaminfo(struct vfs_handle_struct *handle,
 				struct files_struct *fsp,
 				const char *fname,
@@ -867,6 +884,8 @@ struct vfs_fn_pointers skel_opaque_fns = {
 	.file_id_create_fn = skel_file_id_create,
 	.copy_chunk_send_fn = skel_copy_chunk_send,
 	.copy_chunk_recv_fn = skel_copy_chunk_recv,
+	.get_compression_fn = skel_get_compression,
+	.set_compression_fn = skel_set_compression,
 
 	.streaminfo_fn = skel_streaminfo,
 	.get_real_filename_fn = skel_get_real_filename,
diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c
index 99feade..f042b2a 100644
--- a/examples/VFS/skel_transparent.c
+++ b/examples/VFS/skel_transparent.c
@@ -645,6 +645,25 @@ static NTSTATUS skel_copy_chunk_recv(struct vfs_handle_struct *handle,
 	return NT_STATUS_OK;
 }
 
+static NTSTATUS skel_get_compression(struct vfs_handle_struct *handle,
+				     TALLOC_CTX *mem_ctx,
+				     struct files_struct *fsp,
+				     struct smb_filename *smb_fname,
+				     uint16_t *_compression_fmt)
+{
+	return SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
+					    _compression_fmt);
+}
+
+static NTSTATUS skel_set_compression(struct vfs_handle_struct *handle,
+				     TALLOC_CTX *mem_ctx,
+				     struct files_struct *fsp,
+				     uint16_t compression_fmt)
+{
+	return SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
+					    compression_fmt);
+}
+
 static NTSTATUS skel_streaminfo(struct vfs_handle_struct *handle,
 				struct files_struct *fsp,
 				const char *fname,
@@ -973,6 +992,8 @@ struct vfs_fn_pointers skel_transparent_fns = {
 	.file_id_create_fn = skel_file_id_create,
 	.copy_chunk_send_fn = skel_copy_chunk_send,
 	.copy_chunk_recv_fn = skel_copy_chunk_recv,
+	.get_compression_fn = skel_get_compression,
+	.set_compression_fn = skel_set_compression,
 
 	.streaminfo_fn = skel_streaminfo,
 	.get_real_filename_fn = skel_get_real_filename,
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index c3a4345..ebfabf6 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -29,6 +29,25 @@ sub have_ads($) {
 	return $found_ads;
 }
 
+# return smb.conf parameters applicable to @path, based on the underlying
+# filesystem type
+sub get_fs_specific_conf($$)
+{
+	my ($self, $path) = @_;
+	my $mods = "";
+	my $stat_out = `stat --file-system $path` or return "";
+
+	if ($stat_out =~ m/Type:\s+btrfs/) {
+		$mods .= "btrfs ";
+	}
+
+	if ($mods) {
+		return "vfs objects = $mods";
+	}
+
+	return undef;
+}
+
 sub new($$) {
 	my ($classname, $bindir, $binary_mapping, $srcdir, $server_maxtime) = @_;
 	my $self = { vars => {},
@@ -45,7 +64,7 @@ sub teardown_env($$)
 {
 	my ($self, $envvars) = @_;
 	my $count = 0;
-	
+
 	# This should cause smbd to terminate gracefully
 	close($envvars->{STDIN_PIPE});
 
@@ -832,6 +851,8 @@ sub provision($$$$$$)
 	my $nmbdsockdir="$prefix_abs/nmbd";
 	unlink($nmbdsockdir);
 
+	my $fs_specific_conf = $self->get_fs_specific_conf($shrdir);
+
 	## 
 	## create the test directory layout
 	##
@@ -1070,6 +1091,9 @@ sub provision($$$$$$)
 	kernel share modes = no
 	kernel oplocks = no
 	posix locking = no
+[fs_specific]
+	copy = tmp
+	$fs_specific_conf
 [print1]
 	copy = tmp
 	printable = yes
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 52e1d7d..34900db 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -897,15 +897,15 @@ struct smb_extended_info {
  */
 
 enum flush_reason_enum {
-    SEEK_FLUSH,
-    READ_FLUSH,
-    WRITE_FLUSH,
-    READRAW_FLUSH,
-    OPLOCK_RELEASE_FLUSH,
-    CLOSE_FLUSH,
-    SYNC_FLUSH,
-    SIZECHANGE_FLUSH,
+    SAMBA_SEEK_FLUSH,
+    SAMBA_READ_FLUSH,
+    SAMBA_WRITE_FLUSH,
+    SAMBA_READRAW_FLUSH,
+    SAMBA_OPLOCK_RELEASE_FLUSH,
+    SAMBA_CLOSE_FLUSH,
+    SAMBA_SYNC_FLUSH,
+    SAMBA_SIZECHANGE_FLUSH,
     /* NUM_FLUSH_REASONS must remain the last value in the enumeration. */
-    NUM_FLUSH_REASONS};
+    SAMBA_NUM_FLUSH_REASONS};
 
 #endif /* _SMB_H */
diff --git a/source3/include/smbprofile.h b/source3/include/smbprofile.h
index 79410e5..8ecbc30 100644
--- a/source3/include/smbprofile.h
+++ b/source3/include/smbprofile.h
@@ -870,7 +870,7 @@ struct profile_stats {
 	unsigned writecache_non_oplock_writes;
 	unsigned writecache_direct_writes;
 	unsigned writecache_init_writes;
-	unsigned writecache_flushed_writes[NUM_FLUSH_REASONS];
+	unsigned writecache_flushed_writes[SAMBA_NUM_FLUSH_REASONS];
 	unsigned writecache_num_perfect_writes;
 	unsigned writecache_num_write_caches;
 	unsigned writecache_allocated_write_caches;
diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index 0e5b074..1bea0b8 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -154,6 +154,7 @@
 /* Leave at 31 - not yet released. add SMB_VFS_COPY_CHUNK() */
 /* Leave at 31 - not yet released. Remove the unused
 		fsp->pending_break_messages array */
+/* Leave at 31 - not yet released. add SMB_VFS_[GET/SET]_COMPRESSION() */
 
 #define SMB_VFS_INTERFACE_VERSION 31
 
@@ -626,6 +627,15 @@ struct vfs_fn_pointers {
 	NTSTATUS (*copy_chunk_recv_fn)(struct vfs_handle_struct *handle,
 				       struct tevent_req *req,
 				       off_t *copied);
+	NTSTATUS (*get_compression_fn)(struct vfs_handle_struct *handle,
+				       TALLOC_CTX *mem_ctx,
+				       struct files_struct *fsp,
+				       struct smb_filename *smb_fname,
+				       uint16_t *_compression_fmt);
+	NTSTATUS (*set_compression_fn)(struct vfs_handle_struct *handle,
+				       TALLOC_CTX *mem_ctx,
+				       struct files_struct *fsp,
+				       uint16_t compression_fmt);
 
 	NTSTATUS (*streaminfo_fn)(struct vfs_handle_struct *handle,
 				  struct files_struct *fsp,
@@ -1109,6 +1119,15 @@ struct tevent_req *smb_vfs_call_copy_chunk_send(struct vfs_handle_struct *handle
 NTSTATUS smb_vfs_call_copy_chunk_recv(struct vfs_handle_struct *handle,
 				      struct tevent_req *req,
 				      off_t *copied);
+NTSTATUS smb_vfs_call_get_compression(struct vfs_handle_struct *handle,
+				      TALLOC_CTX *mem_ctx,
+				      struct files_struct *fsp,
+				      struct smb_filename *smb_fname,
+				      uint16_t *_compression_fmt);
+NTSTATUS smb_vfs_call_set_compression(struct vfs_handle_struct *handle,
+				      TALLOC_CTX *mem_ctx,
+				      struct files_struct *fsp,
+				      uint16_t compression_fmt);
 NTSTATUS smb_vfs_call_fget_nt_acl(struct vfs_handle_struct *handle,
 				  struct files_struct *fsp,
 				  uint32 security_info,
diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h
index 15e8492..704054d 100644
--- a/source3/include/vfs_macros.h
+++ b/source3/include/vfs_macros.h
@@ -409,8 +409,18 @@
 #define SMB_VFS_NEXT_COPY_CHUNK_RECV(handle, req, copied) \
 	smb_vfs_call_copy_chunk_recv((handle)->next, (req), (copied))
 
+#define SMB_VFS_GET_COMPRESSION(conn, mem_ctx, fsp, smb_fname, _compression_fmt)		\
+	smb_vfs_call_get_compression((conn)->vfs_handles, (mem_ctx), (fsp), (smb_fname), (_compression_fmt))
+#define SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname, _compression_fmt)		\
+	smb_vfs_call_get_compression((handle)->next, (mem_ctx), (fsp), (smb_fname), (_compression_fmt))
+
+#define SMB_VFS_SET_COMPRESSION(conn, mem_ctx, fsp, compression_fmt)		\
+	smb_vfs_call_set_compression((conn)->vfs_handles, (mem_ctx), (fsp), (compression_fmt))
+#define SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp, compression_fmt)		\
+	smb_vfs_call_set_compression((handle)->next, (mem_ctx), (fsp), (compression_fmt))
+
 #define SMB_VFS_FGET_NT_ACL(fsp, security_info, mem_ctx, ppdesc)		\
-		smb_vfs_call_fget_nt_acl((fsp)->conn->vfs_handles, (fsp), (security_info), (mem_ctx), (ppdesc))
+	smb_vfs_call_fget_nt_acl((fsp)->conn->vfs_handles, (fsp), (security_info), (mem_ctx), (ppdesc))
 #define SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, mem_ctx, ppdesc) \
 	smb_vfs_call_fget_nt_acl((handle)->next, (fsp), (security_info), (mem_ctx), (ppdesc))
 
diff --git a/source3/modules/vfs_btrfs.c b/source3/modules/vfs_btrfs.c
index f854f2a..c6e90fd 100644
--- a/source3/modules/vfs_btrfs.c
+++ b/source3/modules/vfs_btrfs.c
@@ -18,13 +18,32 @@
  */
 
 #include <linux/ioctl.h>
+#include <linux/fs.h>
 #include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
 #include "includes.h"
-#include "system/filesys.h"
 #include "smbd/smbd.h"
-#include "../librpc/gen_ndr/smbXsrv.h"
+#include "librpc/gen_ndr/smbXsrv.h"
+#include "librpc/gen_ndr/ioctl.h"
 #include "lib/util/tevent_ntstatus.h"
 
+static uint32_t btrfs_fs_capabilities(struct vfs_handle_struct *handle,
+				      enum timestamp_set_resolution *_ts_res)
+{
+	uint32_t fs_capabilities;
+	enum timestamp_set_resolution ts_res;
+
+	/* inherit default capabilities, expose compression support */
+	fs_capabilities = SMB_VFS_NEXT_FS_CAPABILITIES(handle, &ts_res);
+	fs_capabilities |= FILE_FILE_COMPRESSION;
+	*_ts_res = ts_res;
+
+	return fs_capabilities;
+}
+
 struct btrfs_ioctl_clone_range_args {
 	int64_t src_fd;
 	uint64_t src_offset;
@@ -107,7 +126,7 @@ static struct tevent_req *btrfs_copy_chunk_send(struct vfs_handle_struct *handle
 	cr_args.src_length = (uint64_t)num;
 
 	ret = ioctl(dest_fsp->fh->fd, BTRFS_IOC_CLONE_RANGE, &cr_args);
-	SMB_VFS_STRICT_UNLOCK(src_fsp->conn, src_fsp, &dest_lck);
+	SMB_VFS_STRICT_UNLOCK(dest_fsp->conn, dest_fsp, &dest_lck);
 	SMB_VFS_STRICT_UNLOCK(src_fsp->conn, src_fsp, &src_lck);
 	if (ret < 0) {
 		/*
@@ -187,9 +206,120 @@ static NTSTATUS btrfs_copy_chunk_recv(struct vfs_handle_struct *handle,
 	return NT_STATUS_OK;
 }
 
+/*
+ * caller must pass a non-null fsp or smb_fname. If fsp is null, then
+ * fall back to opening the corresponding file to issue the ioctl.
+ */
+static NTSTATUS btrfs_get_compression(struct vfs_handle_struct *handle,
+				      TALLOC_CTX *mem_ctx,
+				      struct files_struct *fsp,
+				      struct smb_filename *smb_fname,
+				      uint16_t *_compression_fmt)
+{
+	int ret;
+	long flags = 0;
+	int fd;
+	bool opened = false;
+	NTSTATUS status;
+
+	if ((fsp != NULL) && (fsp->fh->fd != -1)) {
+		fd = fsp->fh->fd;
+	} else if (smb_fname != NULL) {
+		if (S_ISDIR(smb_fname->st.st_ex_mode)) {
+			DIR *dir = opendir(smb_fname->base_name);
+			if (dir == NULL) {
+				return NT_STATUS_UNSUCCESSFUL;
+			}
+			fd = dirfd(dir);
+		} else {
+			fd = open(smb_fname->base_name, O_RDONLY);
+		}
+		if (fd < 0) {
+			return NT_STATUS_UNSUCCESSFUL;
+		}
+		opened = true;
+	} else {
+		return NT_STATUS_INVALID_PARAMETER;
+	}
+
+	ret = ioctl(fd, FS_IOC_GETFLAGS, &flags);
+	if (ret < 0) {
+		DEBUG(1, ("FS_IOC_GETFLAGS failed: %s, fd %lld\n",
+			  strerror(errno), (long long)fd));
+		status = map_nt_error_from_unix(errno);
+		goto err_close;
+	}
+	if (flags & FS_COMPR_FL) {
+		*_compression_fmt = COMPRESSION_FORMAT_LZNT1;
+	} else {
+		*_compression_fmt = COMPRESSION_FORMAT_NONE;
+	}
+	status = NT_STATUS_OK;
+err_close:
+	if (opened) {
+		close(fd);
+	}
+
+	return status;
+}
+
+static NTSTATUS btrfs_set_compression(struct vfs_handle_struct *handle,
+				      TALLOC_CTX *mem_ctx,
+				      struct files_struct *fsp,
+				      uint16_t compression_fmt)
+{
+	int ret;
+	long flags = 0;
+	int fd;
+	NTSTATUS status;
+
+	if ((fsp == NULL) || (fsp->fh->fd == -1)) {
+		status = NT_STATUS_INVALID_PARAMETER;
+		goto err_out;
+	}
+	fd = fsp->fh->fd;
+
+	ret = ioctl(fd, FS_IOC_GETFLAGS, &flags);
+	if (ret < 0) {
+		DEBUG(1, ("FS_IOC_GETFLAGS failed: %s, fd %d\n",
+			  strerror(errno), fd));
+		status = map_nt_error_from_unix(errno);
+		goto err_out;
+	}
+
+	if (compression_fmt == COMPRESSION_FORMAT_NONE) {
+		DEBUG(5, ("setting compression\n"));
+		flags &= (~FS_COMPR_FL);
+	} else if ((compression_fmt == COMPRESSION_FORMAT_DEFAULT)
+		|| (compression_fmt == COMPRESSION_FORMAT_LZNT1)) {
+		DEBUG(5, ("clearing compression\n"));
+		flags |= FS_COMPR_FL;
+	} else {
+		DEBUG(1, ("invalid compression format 0x%x\n",
+			  (int)compression_fmt));
+		status = NT_STATUS_INVALID_PARAMETER;
+		goto err_out;
+	}
+
+	ret = ioctl(fd, FS_IOC_SETFLAGS, &flags);
+	if (ret < 0) {
+		DEBUG(1, ("FS_IOC_SETFLAGS failed: %s, fd %d\n",
+			  strerror(errno), fd));
+		status = map_nt_error_from_unix(errno);
+		goto err_out;
+	}
+	status = NT_STATUS_OK;
+err_out:
+	return status;
+}
+
+
 static struct vfs_fn_pointers btrfs_fns = {
+	.fs_capabilities_fn = btrfs_fs_capabilities,
 	.copy_chunk_send_fn = btrfs_copy_chunk_send,
 	.copy_chunk_recv_fn = btrfs_copy_chunk_recv,
+	.get_compression_fn = btrfs_get_compression,
+	.set_compression_fn = btrfs_set_compression,
 };
 
 NTSTATUS vfs_btrfs_init(void);
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index edac0de..90c772b 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -1489,6 +1489,23 @@ static NTSTATUS vfswrap_copy_chunk_recv(struct vfs_handle_struct *handle,
 	return NT_STATUS_OK;
 }
 
+static NTSTATUS vfswrap_get_compression(struct vfs_handle_struct *handle,
+					TALLOC_CTX *mem_ctx,
+					struct files_struct *fsp,
+					struct smb_fname *smb_fname,
+					uint16_t *_compression_fmt)
+{
+	return NT_STATUS_INVALID_DEVICE_REQUEST;
+}
+
+static NTSTATUS vfswrap_set_compression(struct vfs_handle_struct *handle,
+					TALLOC_CTX *mem_ctx,
+					struct files_struct *fsp,
+					uint16_t compression_fmt)
+{
+	return NT_STATUS_INVALID_DEVICE_REQUEST;
+}
+
 /********************************************************************
  Given a stat buffer return the allocated size on disk, taking into
  account sparse files.
@@ -2535,6 +2552,8 @@ static struct vfs_fn_pointers vfs_default_fns = {
 	.fsctl_fn = vfswrap_fsctl,
 	.copy_chunk_send_fn = vfswrap_copy_chunk_send,
 	.copy_chunk_recv_fn = vfswrap_copy_chunk_recv,
+	.get_compression_fn = vfswrap_get_compression,
+	.set_compression_fn = vfswrap_set_compression,
 
 	/* NT ACL operations. */
 
diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c
index 37d8aa4..99e3fcb 100644
--- a/source3/modules/vfs_full_audit.c
+++ b/source3/modules/vfs_full_audit.c
@@ -163,6 +163,8 @@ typedef enum _vfs_op_type {
 	SMB_VFS_OP_TRANSLATE_NAME,
 	SMB_VFS_OP_COPY_CHUNK_SEND,
 	SMB_VFS_OP_COPY_CHUNK_RECV,
+	SMB_VFS_OP_GET_COMPRESSION,
+	SMB_VFS_OP_SET_COMPRESSION,
 
 	/* NT ACL operations. */
 
@@ -285,6 +287,8 @@ static struct {


-- 
Samba Shared Repository


More information about the samba-cvs mailing list