vfs_fileid: add fileid:algorithm = fsname_nodirs
authorRalph Boehme <slow@samba.org>
Thu, 4 Jan 2018 16:02:53 +0000 (17:02 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 5 Jan 2018 23:07:17 +0000 (00:07 +0100)
Enabling fileid:algorithm = fsname_nodirs uses the hostname algorithm
for directories and thus breaks cluster lock coherence for directories.

Based-on-a-patch-by: Christian Ambach <ambi@samba.org>
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
docs-xml/manpages/vfs_fileid.8.xml
source3/modules/vfs_fileid.c

index 6a09f16cf794ec8b2e7b36aa1927733568b5a4b9..9e8becb6b0c21e44f0df65c81624b9093b993df5 100644 (file)
                <term>fileid:algorithm = ALGORITHM</term>
                <listitem>
                <para>Available algorithms are <command>fsname</command>,
-               <command>fsid</command> and <command>hostname</command>. The
-               default value is <command>fsname</command>.
+               <command>fsname_nodirs</command>, <command>fsid</command> and
+               <command>hostname</command>. The default value is
+               <command>fsname</command>.
                </para>
                <para>The <command>fsname</command> algorithm generates
                device id by hashing the kernel device name.
                </para>
+               <para>The <command>fsname_nodirs</command> algorithm generates
+               device id by hashing the kernel device name for files and by hashing
+               the hostname for directories. This can be used to deliberately
+               break lock coherency for directories in a cluster.
+               </para>
                <para>The <command>fsid</command> algorithm generates
                the device id from the <command>f_fsid</command> returned
                from the <command>statfs()</command> syscall.
index 76f08f31a9e7ac63c851d364b24debb4e7c6a6b0..4752bc5528684e884edd2192541fcd195b09da23 100644 (file)
@@ -238,6 +238,18 @@ static uint64_t fileid_device_mapping_hostname(struct fileid_handle_data *data,
        return id;
 }
 
+/* a device mapping using a fsname for files and hostname for dirs */
+static uint64_t fileid_device_mapping_fsname_nodirs(
+       struct fileid_handle_data *data,
+       const SMB_STRUCT_STAT *sbuf)
+{
+       if (S_ISDIR(sbuf->st_ex_mode)) {
+               return fileid_device_mapping_hostname(data, sbuf);
+       }
+
+       return fileid_device_mapping_fsname(data, sbuf);
+}
+
 /* device mapping functions using a fsid */
 static uint64_t fileid_device_mapping_fsid(struct fileid_handle_data *data,
                                           const SMB_STRUCT_STAT *sbuf)
@@ -302,6 +314,8 @@ static int fileid_connect(struct vfs_handle_struct *handle,
                                         algorithm);
        if (strcmp("fsname", algorithm) == 0) {
                data->device_mapping_fn = fileid_device_mapping_fsname;
+       } else if (strcmp("fsname_nodirs", algorithm) == 0) {
+               data->device_mapping_fn = fileid_device_mapping_fsname_nodirs;
        } else if (strcmp("fsid", algorithm) == 0) {
                data->device_mapping_fn = fileid_device_mapping_fsid;
        } else if (strcmp("hostname", algorithm) == 0) {