[PATCHES] vfs_offline VFS module

Uri Simchoni uri at samba.org
Wed Nov 4 19:48:47 UTC 2015


Hi,

Attached is a vfs_offline module, whose very simple action is to set the 
offline dos attribute for all files in the share. This comes handy when 
dealing with remote FUSE file systems as it prevents Windows explorer 
from needlessly reading picture files just for generating thumbnails.

For samba development it also unit-tests the is_offline-to-dos-attribute 
code path :)

Review & push appreciated (if found useful for inclusion)

Thanks,
Uri

-------------- next part --------------
From 3e4c25fb4b8bc907d52646dff65dd334519d6fe0 Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 4 Nov 2015 08:44:29 +0200
Subject: [PATCH 1/3] vfs_offline: add vfs_offline module

This module marks all file in the share as offline.
It can be useful for shares mounted on top of a remote file
system (either through a samba VFS module or via FUSE).

Offline files change the behavior of Windows explorer, and
prevent it from peeking inside folders just for the sake of
drawing a nice icon of them. This greatly reduces the number
of requests Windows Explorer makes, and improves user experience
when dealing with remote file systems.

The offline bit also has an effect on the behavior of Windows
redirector.

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 source3/modules/vfs_offline.c | 47 +++++++++++++++++++++++++++++++++++++++++++
 source3/modules/wscript_build |  7 +++++++
 source3/wscript               |  2 +-
 3 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 source3/modules/vfs_offline.c

diff --git a/source3/modules/vfs_offline.c b/source3/modules/vfs_offline.c
new file mode 100644
index 0000000..5921f43
--- /dev/null
+++ b/source3/modules/vfs_offline.c
@@ -0,0 +1,47 @@
+/*
+  Unix SMB/CIFS implementation.
+  Samba VFS module for marking all files as offline.
+
+  (c) Uri Simchoni, 2015
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+
+static uint32_t offline_fs_capabilities(struct vfs_handle_struct *handle,
+					enum timestamp_set_resolution *p_ts_res)
+{
+	return SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res) |
+	       FILE_SUPPORTS_REMOTE_STORAGE;
+}
+
+static bool offline_is_offline(struct vfs_handle_struct *handle,
+			       const struct smb_filename *fname,
+			       SMB_STRUCT_STAT *stbuf)
+{
+	return true;
+}
+
+static struct vfs_fn_pointers offline_fns = {
+    .fs_capabilities_fn = offline_fs_capabilities,
+    .is_offline_fn = offline_is_offline,
+};
+
+NTSTATUS vfs_offline_init(void);
+NTSTATUS vfs_offline_init(void)
+{
+	return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "offline",
+				&offline_fns);
+}
diff --git a/source3/modules/wscript_build b/source3/modules/wscript_build
index fef412a..be1de50 100644
--- a/source3/modules/wscript_build
+++ b/source3/modules/wscript_build
@@ -499,3 +499,10 @@ bld.SAMBA3_MODULE('vfs_vxfs',
                  init_function='',
                  internal_module=bld.SAMBA3_IS_STATIC_MODULE('vfs_vxfs'),
                  enabled=bld.SAMBA3_IS_ENABLED_MODULE('vfs_vxfs'))
+
+bld.SAMBA3_MODULE('vfs_offline',
+                 subsystem='vfs',
+                 source='vfs_offline.c',
+                 init_function='',
+                 internal_module=bld.SAMBA3_IS_STATIC_MODULE('vfs_offline'),
+                 enabled=bld.SAMBA3_IS_ENABLED_MODULE('vfs_offline'))
diff --git a/source3/wscript b/source3/wscript
index 3118f59..092d8fa 100644
--- a/source3/wscript
+++ b/source3/wscript
@@ -1604,7 +1604,7 @@ main() {
                                       vfs_smb_traffic_analyzer vfs_preopen vfs_catia
                                       vfs_media_harmony vfs_unityed_media vfs_fruit vfs_shell_snap
                                       vfs_commit vfs_worm vfs_crossrename vfs_linux_xfs_sgid
-                                      vfs_time_audit
+                                      vfs_time_audit vfs_offline
                                   '''))
     default_shared_modules.extend(TO_LIST('auth_script idmap_tdb2 idmap_script'))
     # these have broken dependencies
-- 
2.4.3


From cf6650489e7219da11f306e8369ee2ed0fba72dd Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 4 Nov 2015 12:06:03 +0200
Subject: [PATCH 2/3] vfs_offline: add a blackbox test

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 selftest/target/Samba3.pm            |  6 ++++++
 source3/script/tests/test_offline.sh | 33 +++++++++++++++++++++++++++++++++
 source3/selftest/tests.py            |  1 +
 3 files changed, 40 insertions(+)
 create mode 100755 source3/script/tests/test_offline.sh

diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index f66aea7..281ac3c 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -594,6 +594,9 @@ sub setup_fileserver($$)
 	my $valid_users_sharedir="$share_dir/valid_users";
 	push(@dirs,$valid_users_sharedir);
 
+	my $offline_sharedir="$share_dir/offline";
+	push(@dirs,$offline_sharedir);
+
 	my $fileserver_options = "
 [lowercase]
 	path = $lower_case_share_dir
@@ -616,6 +619,9 @@ sub setup_fileserver($$)
 [valid-users-access]
 	path = $valid_users_sharedir
 	valid users = +userdup
+[offline]
+	path = $offline_sharedir
+	vfs objects = offline
 	";
 
 	my $vars = $self->provision($path,
diff --git a/source3/script/tests/test_offline.sh b/source3/script/tests/test_offline.sh
new file mode 100755
index 0000000..fbc071a
--- /dev/null
+++ b/source3/script/tests/test_offline.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# Blackbox test for shadow_copy2 VFS.
+#
+if [ $# -lt 7 ]; then
+cat <<EOF
+Usage: test_offline SERVER SERVER_IP DOMAIN USERNAME PASSWORD WORKDIR SMBCLIENT
+EOF
+exit 1;
+fi
+
+SERVER=${1}
+SERVER_IP=${2}
+DOMAIN=${3}
+USERNAME=${4}
+PASSWORD=${5}
+WORKDIR=${6}
+SMBCLIENT=${7}
+shift 7
+SMBCLIENT="$VALGRIND ${SMBCLIENT}"
+ADDARGS="$*"
+
+incdir=`dirname $0`/../../../testprogs/blackbox
+. $incdir/subunit.sh
+
+touch $WORKDIR/foo
+
+failed=0
+
+attribs=`$SMBCLIENT -U$USERNAME%$PASSWORD "//$SERVER/offline" -I $SERVER_IP -c "allinfo foo" | sed -n 's/^attributes:.*(\([^)]*\)).*/\1/p'`
+testit "file has offline attribute" test "x$attribs" = "x1000"  || failed=`expr $failed + 1`
+
+exit $failed
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index 048675a..9c68943 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -178,6 +178,7 @@ for env in ["fileserver"]:
     plantestsuite("samba3.blackbox.preserve_case (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_preserve_case.sh"), '$SERVER', '$DOMAIN', '$USERNAME', '$PASSWORD', '$PREFIX', smbclient3])
     plantestsuite("samba3.blackbox.dfree_command (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_dfree_command.sh"), '$SERVER', '$DOMAIN', '$USERNAME', '$PASSWORD', '$PREFIX', smbclient3])
     plantestsuite("samba3.blackbox.valid_users (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_valid_users.sh"), '$SERVER', '$SERVER_IP', '$DOMAIN', '$USERNAME', '$PASSWORD', '$PREFIX', smbclient3])
+    plantestsuite("samba3.blackbox.offline (%s)" % env, env, [os.path.join(samba3srcdir, "script/tests/test_offline.sh"), '$SERVER', '$SERVER_IP', '$DOMAIN', '$USERNAME', '$PASSWORD', '$LOCAL_PATH/offline', smbclient3])
 
     #
     # tar command tests
-- 
2.4.3


From 42aa141325ebc7b1c8d4a9953fd7ced7bc7892da Mon Sep 17 00:00:00 2001
From: Uri Simchoni <uri at samba.org>
Date: Wed, 4 Nov 2015 21:18:20 +0200
Subject: [PATCH 3/3] vfs_offline: add documentation

Signed-off-by: Uri Simchoni <uri at samba.org>
---
 docs-xml/manpages/vfs_offline.8.xml | 72 +++++++++++++++++++++++++++++++++++++
 docs-xml/wscript_build              |  1 +
 2 files changed, 73 insertions(+)
 create mode 100644 docs-xml/manpages/vfs_offline.8.xml

diff --git a/docs-xml/manpages/vfs_offline.8.xml b/docs-xml/manpages/vfs_offline.8.xml
new file mode 100644
index 0000000..5a702b6
--- /dev/null
+++ b/docs-xml/manpages/vfs_offline.8.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE refentry PUBLIC "-//Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">
+<refentry id="vfs_offline.8">
+
+<refmeta>
+	<refentrytitle>vfs_offline</refentrytitle>
+	<manvolnum>8</manvolnum>
+	<refmiscinfo class="source">Samba</refmiscinfo>
+	<refmiscinfo class="manual">System Administration tools</refmiscinfo>
+	<refmiscinfo class="version">4.4</refmiscinfo>
+</refmeta>
+
+
+<refnamediv>
+	<refname>vfs_offline</refname>
+	<refpurpose>Mark all files as offline</refpurpose>
+</refnamediv>
+
+<refsynopsisdiv>
+	<cmdsynopsis>
+		<command>vfs objects = offline</command>
+	</cmdsynopsis>
+</refsynopsisdiv>
+
+<refsect1>
+	<title>DESCRIPTION</title>
+
+	<para>This VFS module is part of the
+	<citerefentry><refentrytitle>samba</refentrytitle>
+	<manvolnum>7</manvolnum></citerefentry> suite.</para>
+
+	<para>The <command>vfs_offline</command> module marks all files
+	in the share as having the offline DOS attribute.</para>
+
+	<para>Files with the offline DOS attribute are handled differently
+	by the Windows SMB client, as well as by Windows Explorer. In
+	particular, Windows Explorer does not read those files for the sole
+	purpose of drawing a thumbnail, as it normally does. This can
+	improve user experience with some remote file systems.</para>
+
+</refsect1>
+
+<refsect1>
+	<title>EXAMPLES</title>
+
+	<para>Mark all files in a share as offline:</para>
+
+<programlisting>
+        <smbconfsection name="[remote]"/>
+	<smbconfoption name="vfs objects">offline</smbconfoption>
+</programlisting>
+
+</refsect1>
+
+<refsect1>
+	<title>VERSION</title>
+
+	<para>This man page is correct for version 4.4 of the Samba suite.
+	</para>
+</refsect1>
+
+<refsect1>
+	<title>AUTHOR</title>
+
+	<para>The original Samba software and related utilities
+	were created by Andrew Tridgell. Samba is now developed
+	by the Samba Team as an Open Source project similar
+	to the way the Linux kernel is developed.</para>
+
+</refsect1>
+
+</refentry>
diff --git a/docs-xml/wscript_build b/docs-xml/wscript_build
index 568eba1..b327a3e 100644
--- a/docs-xml/wscript_build
+++ b/docs-xml/wscript_build
@@ -68,6 +68,7 @@ manpages='''
          manpages/vfs_linux_xfs_sgid.8
          manpages/vfs_media_harmony.8
          manpages/vfs_netatalk.8
+         manpages/vfs_offline.8
          manpages/vfs_prealloc.8
          manpages/vfs_preopen.8
          manpages/vfs_readahead.8
-- 
2.4.3



More information about the samba-technical mailing list