[PATCHES] vfs_gpfs: Update fallocate callback

Christof Schmitt cs at samba.org
Mon Apr 22 17:15:30 UTC 2019


All supported versions of the file system now support the fallocate()
call, so the gpfs_prealloc API call is no longer necessary. There is
also limited support for the punch hole call; allow that with the
limitation that ZERO_DATA can only be used on sparse files.

Christof
-------------- next part --------------
From 6b9bc865ab37d4fa9a6934863f5896d4305e2389 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Mon, 14 May 2018 14:33:15 -0700
Subject: [PATCH 1/4] vfs_gpfs: Remove usage of gpfs_prealloc

All supported versions of GPFS now support fallocate. Use the default
codepath instead of the API call. Keep the function stub as it will
be used for a check later.

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 source3/modules/vfs_gpfs.c | 40 +++-----------------------------------
 1 file changed, 3 insertions(+), 37 deletions(-)

diff --git a/source3/modules/vfs_gpfs.c b/source3/modules/vfs_gpfs.c
index d86d0996fcd..4de8720e940 100644
--- a/source3/modules/vfs_gpfs.c
+++ b/source3/modules/vfs_gpfs.c
@@ -48,7 +48,6 @@ struct gpfs_config_data {
 	bool ftruncate;
 	bool getrealfilename;
 	bool dfreequota;
-	bool prealloc;
 	bool acl;
 	bool settimes;
 	bool recalls;
@@ -1944,40 +1943,10 @@ static int vfs_gpfs_ntimes(struct vfs_handle_struct *handle,
 }
 
 static int vfs_gpfs_fallocate(struct vfs_handle_struct *handle,
-		       struct files_struct *fsp, uint32_t mode,
-		       off_t offset, off_t len)
+			      struct files_struct *fsp, uint32_t mode,
+			      off_t offset, off_t len)
 {
-	int ret;
-	struct gpfs_config_data *config;
-
-	SMB_VFS_HANDLE_GET_DATA(handle, config,
-				struct gpfs_config_data,
-				return -1);
-
-	if (!config->prealloc) {
-		/* you should better not run fallocate() on GPFS at all */
-		errno = ENOTSUP;
-		return -1;
-	}
-
-	if (mode != 0) {
-		DEBUG(10, ("unmapped fallocate flags: %lx\n",
-		      (unsigned long)mode));
-		errno = ENOTSUP;
-		return -1;
-	}
-
-	ret = gpfswrap_prealloc(fsp->fh->fd, offset, len);
-
-	if (ret == -1 && errno != ENOSYS) {
-		DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno)));
-	} else if (ret == -1 && errno == ENOSYS) {
-		DEBUG(10, ("GPFS prealloc not supported.\n"));
-	} else {
-		DEBUG(10, ("GPFS prealloc succeeded.\n"));
-	}
-
-	return ret;
+	return SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
 }
 
 static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
@@ -2152,9 +2121,6 @@ static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
 	config->dfreequota = lp_parm_bool(SNUM(handle->conn), "gpfs",
 					  "dfreequota", false);
 
-	config->prealloc = lp_parm_bool(SNUM(handle->conn), "gpfs",
-				   "prealloc", true);
-
 	config->acl = lp_parm_bool(SNUM(handle->conn), "gpfs", "acl", true);
 
 	config->settimes = lp_parm_bool(SNUM(handle->conn), "gpfs",
-- 
2.17.0


From b4cb235cc164d03aa20ee48b4883899d1c162b53 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Mon, 14 May 2018 14:34:32 -0700
Subject: [PATCH 2/4] vfs_gpfs: Remove gpfs:prealloc from manpage

The option is no longer in the code, remove it from the manpage as well.

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 docs-xml/manpages/vfs_gpfs.8.xml | 27 +--------------------------
 1 file changed, 1 insertion(+), 26 deletions(-)

diff --git a/docs-xml/manpages/vfs_gpfs.8.xml b/docs-xml/manpages/vfs_gpfs.8.xml
index 15e7bcf9d77..2f3b4274e4b 100644
--- a/docs-xml/manpages/vfs_gpfs.8.xml
+++ b/docs-xml/manpages/vfs_gpfs.8.xml
@@ -13,7 +13,7 @@
 
 <refnamediv>
 	<refname>vfs_gpfs</refname>
-	<refpurpose>gpfs specific samba extensions like acls and prealloc</refpurpose>
+	<refpurpose>gpfs specific samba extensions like acls</refpurpose>
 </refnamediv>
 
 <refsynopsisdiv>
@@ -339,31 +339,6 @@
 		</varlistentry>
 		<varlistentry>
 
-		<term>gpfs:prealloc = [ yes | no ]</term>
-		<listitem>
-		<para>
-		If set to yes the gpfs_prealloc function will be used in the
-		fallocate callback when appropriate. If set to no gpfs_prealloc
-		will not be used. In both cases the system and libc calls are
-		avoided.
-		</para>
-
-		<itemizedlist>
-		<listitem><para>
-		<command>yes (default)</command> - Use gpfs_prealloc for the
-		fallocate callback.
-		</para></listitem>
-		<listitem><para>
-		<command>no</command> - Do not use gpfs_prealloc for the
-		fallocate callback.
-		</para></listitem>
-		</itemizedlist>
-		</listitem>
-
-		</varlistentry>
-
-		<varlistentry>
-
 		<term>gpfs:settimes = [ yes | no ]</term>
 		<listitem>
 		<para>
-- 
2.17.0


From eb8f5a0be76c05534fbbcb0aed117db885a80fa0 Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Mon, 14 May 2018 14:35:28 -0700
Subject: [PATCH 3/4] gpfswrap: Remove unused gpfs_prealloc wrapper

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 lib/util/gpfswrap.c | 12 ------------
 lib/util/gpfswrap.h |  1 -
 2 files changed, 13 deletions(-)

diff --git a/lib/util/gpfswrap.c b/lib/util/gpfswrap.c
index 0632ee20757..32be942bc7c 100644
--- a/lib/util/gpfswrap.c
+++ b/lib/util/gpfswrap.c
@@ -34,7 +34,6 @@ static int (*gpfs_set_winattrs_fn)(int fd, int flags,
 static int (*gpfs_get_winattrs_path_fn)(char *pathname,
 					struct gpfs_winattr *attrs);
 static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
-static int (*gpfs_prealloc_fn)(int fd, gpfs_off64_t start, gpfs_off64_t bytes);
 static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
 static int (*gpfs_lib_init_fn)(int flags);
 static int (*gpfs_set_times_path_fn)(char *pathname, int flags,
@@ -68,7 +67,6 @@ int gpfswrap_init(void)
 	gpfs_set_winattrs_fn	      = dlsym(l, "gpfs_set_winattrs");
 	gpfs_get_winattrs_path_fn     = dlsym(l, "gpfs_get_winattrs_path");
 	gpfs_get_winattrs_fn	      = dlsym(l, "gpfs_get_winattrs");
-	gpfs_prealloc_fn	      = dlsym(l, "gpfs_prealloc");
 	gpfs_ftruncate_fn	      = dlsym(l, "gpfs_ftruncate");
 	gpfs_lib_init_fn	      = dlsym(l, "gpfs_lib_init");
 	gpfs_set_times_path_fn	      = dlsym(l, "gpfs_set_times_path");
@@ -173,16 +171,6 @@ int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs)
 	return gpfs_get_winattrs_fn(fd, attrs);
 }
 
-int gpfswrap_prealloc(int fd, gpfs_off64_t start, gpfs_off64_t bytes)
-{
-	if (gpfs_prealloc_fn == NULL) {
-		errno = ENOSYS;
-		return -1;
-	}
-
-	return gpfs_prealloc_fn(fd, start, bytes);
-}
-
 int gpfswrap_ftruncate(int fd, gpfs_off64_t length)
 {
 	if (gpfs_ftruncate_fn == NULL) {
diff --git a/lib/util/gpfswrap.h b/lib/util/gpfswrap.h
index 1c9c64f7e8c..40202104064 100644
--- a/lib/util/gpfswrap.h
+++ b/lib/util/gpfswrap.h
@@ -37,7 +37,6 @@ int gpfswrap_set_winattrs_path(char *pathname, int flags,
 int gpfswrap_set_winattrs(int fd, int flags, struct gpfs_winattr *attrs);
 int gpfswrap_get_winattrs_path(char *pathname, struct gpfs_winattr *attrs);
 int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs);
-int gpfswrap_prealloc(int fd, gpfs_off64_t start, gpfs_off64_t bytes);
 int gpfswrap_ftruncate(int fd, gpfs_off64_t length);
 int gpfswrap_lib_init(int flags);
 int gpfswrap_set_times_path(char *pathname, int flags,
-- 
2.17.0


From 08da56b0e47a3b94f4adc1a7486a83110a7d0bba Mon Sep 17 00:00:00 2001
From: Christof Schmitt <cs at samba.org>
Date: Wed, 8 Aug 2018 14:54:24 -0700
Subject: [PATCH 4/4] vfs_gpfs: Block punchhole calls for non-sparse files

The core smbd code implements ZERO_DATA for non-sparse files by punching
a hole and filling it again with a fallocate(FL_KEEP_SIZE) call. As GPFS
does not provide the fallocate(FL_KEEP_SIZE) call and non-sparse files
should not contain holes, block the punchhole; effectively only allowing
ZERO_DATA/punchhole calls for sparse files.

Signed-off-by: Christof Schmitt <cs at samba.org>
---
 source3/modules/vfs_gpfs.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/source3/modules/vfs_gpfs.c b/source3/modules/vfs_gpfs.c
index 4de8720e940..52c4e5ef25d 100644
--- a/source3/modules/vfs_gpfs.c
+++ b/source3/modules/vfs_gpfs.c
@@ -1946,6 +1946,21 @@ static int vfs_gpfs_fallocate(struct vfs_handle_struct *handle,
 			      struct files_struct *fsp, uint32_t mode,
 			      off_t offset, off_t len)
 {
+	if (mode == (VFS_FALLOCATE_FL_PUNCH_HOLE|VFS_FALLOCATE_FL_KEEP_SIZE) &&
+	    !fsp->is_sparse &&
+	    lp_strict_allocate(SNUM(fsp->conn))) {
+		/*
+		 * This is from a ZERO_DATA request on a non-sparse
+		 * file. GPFS does not support FL_KEEP_SIZE and thus
+		 * cannot fill the whole again in the subsequent
+		 * fallocate(FL_KEEP_SIZE). Deny this FL_PUNCH_HOLE
+		 * call to not end up with a hole in a non-sparse
+		 * file.
+		 */
+		errno = ENOTSUP;
+		return -1;
+	}
+
 	return SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
 }
 
-- 
2.17.0



More information about the samba-technical mailing list