[PATCH] Fix Issues with Linux kernel oplocks on GPFS and regular filesystems.

Jeremy Allison jra at samba.org
Wed Jul 31 17:38:23 MDT 2013


2 part patch attached (contains my fix + comment Simo
requested) and Ralph's fix.

Please give a second Team member review and push (or
ok to push) if acceptible.

Cheers,

	Jeremy
-------------- next part --------------
From 1a0e3d5734e7b25d2c3d1957bdef536f2b10357e Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Wed, 31 Jul 2013 16:32:20 -0700
Subject: [PATCH 1/2] Wrap setting leases in become_root()/unbecome_root() to
 ensure correct delivery of signals.

Remove workaround for Linux kernel bug https://bugzilla.kernel.org/show_bug.cgi?id=43336
as we don't need to set capabilities when we're already root.

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/smbd/oplock_linux.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/source3/smbd/oplock_linux.c b/source3/smbd/oplock_linux.c
index 7fa9b7c..dd772bf 100644
--- a/source3/smbd/oplock_linux.c
+++ b/source3/smbd/oplock_linux.c
@@ -75,26 +75,33 @@ int linux_set_lease_sighandler(int fd)
 int linux_setlease(int fd, int leasetype)
 {
 	int ret;
+	int saved_errno;
+
+	/*
+	 * Ensure the lease owner is root to allow
+	 * correct delivery of lease-break signals.
+	 */
+
+	become_root();
 
 	/* First set the signal handler. */
 	if (linux_set_lease_sighandler(fd) == -1) {
-		return -1;
+		saved_errno = errno;
+		ret = -1;
+		goto out;
 	}
 	ret = fcntl(fd, F_SETLEASE, leasetype);
-	if (ret == -1 && errno == EACCES) {
-		set_effective_capability(LEASE_CAPABILITY);
-		/*
-		 * Bug 8974 - work around Linux kernel bug
-		 * https://bugzilla.kernel.org/show_bug.cgi?id=43336.
-		 * "fcntl(F_SETLEASE) resets signal number when
-		 *  called multiple times"
-		 */
-		if (linux_set_lease_sighandler(fd) == -1) {
-			return -1;
-		}
-		ret = fcntl(fd, F_SETLEASE, leasetype);
+	if (ret == -1) {
+		saved_errno = errno;
 	}
 
+  out:
+
+	unbecome_root();
+
+	if (ret == -1) {
+		errno = saved_errno;
+	}
 	return ret;
 }
 
-- 
1.8.3


From efd1386e9ee4ff6d9a645e1a45dc841ebaad1968 Mon Sep 17 00:00:00 2001
From: Ralph Wuerthner <ralphw at de.ibm.com>
Date: Wed, 31 Jul 2013 16:33:48 -0700
Subject: [PATCH 2/2] Ensure gpfs kernel leases are wrapped in a
 become_root()/unbecome_root() pair.

Ensures correct lease owner for signal delivery.

Signed-off-by: Ralph Wuerthner <ralphw at de.ibm.com>
Reviewed-by: Jeremy Allison <jra at samba.org>
---
 source3/modules/vfs_gpfs.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/source3/modules/vfs_gpfs.c b/source3/modules/vfs_gpfs.c
index 13061c8..4a53bf8 100644
--- a/source3/modules/vfs_gpfs.c
+++ b/source3/modules/vfs_gpfs.c
@@ -111,7 +111,13 @@ static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
 	START_PROFILE(syscall_linux_setlease);
 
 	if (config->leases) {
+		/*
+		 * Ensure the lease owner is root to allow
+		 * correct delivery of lease-break signals.
+		 */
+		become_root();
 		ret = set_gpfs_lease(fsp->fh->fd,leasetype);
+		unbecome_root();
 	}
 
 	END_PROFILE(syscall_linux_setlease);
-- 
1.8.3



More information about the samba-technical mailing list