[OpenAFS-devel] Was: [OpenAFS] set client to refuse byte-range locks?

Matt Benjamin matt@linuxbox.com
Sun, 28 Jan 2007 16:32:02 -0500


This is a multi-part message in MIME format.
--------------060405090804050907020903
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Adam,

There is work ongoing to improve the Unix-like clients' locking 
support.  At the moment, I don't think OpenAFS 1.4 or 1.5 have an easy 
way to do (either notion you suggested of ) what you want, but, it was 
easy to hack up a patch to do your first suggestion (I didn't want to 
think about the second one).

** disclaimer: hackery **

Somewhat tested, only on i386 Linux 2.6.  Not reviewed.  Uses C ioctl 
space (seems like should be O, but that's not really in 1.4.2, at 
least).  Not what we'll be configuring in future, really, because Unix 
client locking options are increased with new features.  Still, people 
should have the freedom to disable "no-op" byte range locks.

Matt

Adam Megacz wrote:
> Is there any way to set the Linux OpenAFS client to simply refuse all
> requests for byte-range locks?
>
> Barring that, is there a way to find out which file the message "afs:
> byte-range lock/unlock ignored; make sure no one else is running this
> program" refers to?
>
>   - a
>
>   


-- 

Matt Benjamin

The Linux Box
206 South Fifth Ave. Suite 150
Ann Arbor, MI  48104

http://linuxbox.com

tel. 734-761-4689
fax. 734-769-8938
cel. 734-216-5309



--------------060405090804050907020903
Content-Type: text/x-patch;
 name="lockhack.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="lockhack.patch"

diff -Nur openafs-1.4.2/src/afs/afs_pioctl.c openafs-1.4.2-lockhack/src/afs/afs_pioctl.c
--- openafs-1.4.2/src/afs/afs_pioctl.c	2006-03-02 01:44:05.000000000 -0500
+++ openafs-1.4.2-lockhack/src/afs/afs_pioctl.c	2007-01-28 15:12:49.000000000 -0500
@@ -90,6 +90,9 @@
 DECL_PIOCTL(PPrefetchFromTape);
 DECL_PIOCTL(PResidencyCmd);
 DECL_PIOCTL(PCallBackAddr);
+DECL_PIOCTL(PGetRangeLockFlags);
+DECL_PIOCTL(PSetRangeLockFlags);
+DECL_PIOCTL(PNoOp);
 
 /*
  * A macro that says whether we're going to need HandleClientContext().
@@ -192,6 +195,13 @@
 	PNewAlias,		/* 1 -- create new cell alias */
 	PListAliases,		/* 2 -- list cell aliases */
 	PCallBackAddr,		/* 3 -- request addr for callback rxcon */
+	PNoOp, /* placeholders, known to be in 1.5 plus rxk5 */
+	PNoOp,
+	PNoOp,
+	PNoOp,
+	PNoOp,
+	PGetRangeLockFlags, /* 9 - get range lock flag set */
+	PSetRangeLockFlags, /* 10 - set range lock flag set */
 };
 
 #define PSetClientContext 99	/*  Special pioctl to setup caller's creds  */
@@ -3927,3 +3937,33 @@
 #endif /* UKERNEL */
     return 0;
 }
+
+DECL_PIOCTL(PNoOp)
+{
+
+    afs_warn("no op pioctl\n");
+
+    return 0;
+}
+
+DECL_PIOCTL(PGetRangeLockFlags)
+{
+    memcpy(aout, (char *)&range_lock_flags, sizeof(afs_int32));
+    *aoutSize = sizeof(afs_int32);
+
+    return 0;
+}
+
+DECL_PIOCTL(PSetRangeLockFlags)
+{
+    afs_int32 tmpval;
+
+    if (!afs_osi_suser(*acred))
+	return EPERM;
+    if (ainSize != sizeof(afs_int32) || ain == NULL)
+	return EINVAL;
+    memcpy((char *)&tmpval, ain, sizeof(afs_int32));
+    range_lock_flags = tmpval;
+
+    return 0;
+}
diff -Nur openafs-1.4.2/src/afs/afs_prototypes.h openafs-1.4.2-lockhack/src/afs/afs_prototypes.h
--- openafs-1.4.2/src/afs/afs_prototypes.h	2006-08-14 18:12:22.000000000 -0400
+++ openafs-1.4.2-lockhack/src/afs/afs_prototypes.h	2007-01-28 14:16:13.000000000 -0500
@@ -934,7 +934,7 @@
 		      int clid);
 extern int HandleFlock(register struct vcache *avc, int acom,
 		       struct vrequest *areq, pid_t clid, int onlymine);
-
+extern afs_int32 range_lock_flags;
 
 
 /* VNOPS/afs_vnop_lookup.c */
diff -Nur openafs-1.4.2/src/afs/VNOPS/afs_vnop_flock.c openafs-1.4.2-lockhack/src/afs/VNOPS/afs_vnop_flock.c
--- openafs-1.4.2/src/afs/VNOPS/afs_vnop_flock.c	2006-06-02 17:23:52.000000000 -0400
+++ openafs-1.4.2-lockhack/src/afs/VNOPS/afs_vnop_flock.c	2007-01-28 15:37:06.000000000 -0500
@@ -26,6 +26,9 @@
 #include "afs/afs_osidnlc.h"
 #include "afs/unified_afs.h"
 
+/* Exported variables */
+afs_int32 range_lock_flags = 0;
+
 /* Static prototypes */
 static int HandleGetLock(register struct vcache *avc,
 			 register struct AFS_FLOCK *af,
@@ -465,8 +468,12 @@
 
     /* otherwise, it is time to nag the user */
     lastWarnTime = now;
-    afs_warn
-	("afs: byte-range lock/unlock ignored; make sure no one else is running this program.\n");
+    if(range_lock_flags & 0x0000001)
+	    afs_warn
+		    ("afs: byte-range lock/unlock request refused per settings");
+    else
+	    afs_warn
+		    ("afs: byte-range lock/unlock ignored; make sure no one else is running this program.\n");
 }
 
 
@@ -550,9 +557,14 @@
     /* next line makes byte range locks always succeed,
      * even when they should block */
     if (af->l_whence != 0 || af->l_start != 0 || af->l_len != 0) {
-	DoLockWarning();
-	afs_PutFakeStat(&fakestate);
-	return 0;
+	    int r = 0;
+	    /* unless the client would prefer they always fail */
+	    if(range_lock_flags & 0x00000001) {
+		    r = EINVAL;
+	    }
+	    DoLockWarning();
+	    afs_PutFakeStat(&fakestate);
+	    return r;
     }
     /* otherwise we can turn this into a whole-file flock */
     if (af->l_type == F_RDLCK)
diff -Nur openafs-1.4.2/src/config/venus.h openafs-1.4.2-lockhack/src/config/venus.h
--- openafs-1.4.2/src/config/venus.h	2005-05-08 02:18:12.000000000 -0400
+++ openafs-1.4.2-lockhack/src/config/venus.h	2007-01-28 14:58:15.000000000 -0500
@@ -181,5 +181,8 @@
 #define VIOC_NEWALIAS		_CVICEIOCTL(1)	/* create new cell alias */
 #define VIOC_GETALIAS		_CVICEIOCTL(2)	/* get alias info */
 #define VIOC_CBADDR		_CVICEIOCTL(3)	/* push callback addr */
+#define VIOC_GETRANGELOCKFLAGS        _CVICEIOCTL(9) /* Get range lockctl flags */
+#define VIOC_SETRANGELOCKFLAGS        _CVICEIOCTL(10) /* Set range lockctl flags */
+
 
 #endif /* AFS_VENUS_H */
diff -Nur openafs-1.4.2/src/venus/fs.c openafs-1.4.2-lockhack/src/venus/fs.c
--- openafs-1.4.2/src/venus/fs.c	2006-07-31 13:07:52.000000000 -0400
+++ openafs-1.4.2-lockhack/src/venus/fs.c	2007-01-28 15:11:12.000000000 -0500
@@ -20,6 +20,7 @@
 #include <netdb.h>
 #include <errno.h>
 #include <stdio.h>
+#include <ctype.h>
 #include <netinet/in.h>
 #include <sys/stat.h>
 #include <afs/stds.h>
@@ -3131,6 +3132,61 @@
     return 0;
 }
 
+static afs_int32
+SetRangeLockFlagsCmd(struct cmd_syndesc *as, char *arock)
+{
+    afs_int32 code = 0, flags, digit, flags_len, ix;
+    struct ViceIoctl blob;
+    char *tp;
+
+    tp = as->parms[0].items->data;
+    flags_len = strlen(tp);
+    digit = 1; 
+    for(ix = 0; ix < flags_len; ++ix) {
+	    if(!isdigit(tp[0])) {
+		    digit = 0;
+		    break;
+	    }
+    }
+    if (digit == 0) {
+	fprintf(stderr, "%s: %s must be an undecorated digit string.\n", pn, tp);
+	return EINVAL;
+    }
+    flags = atoi(tp);
+
+    blob.in = (char *)&flags;
+    blob.in_size = sizeof(flags);
+    blob.out_size = 0;
+    code = pioctl(0, VIOC_SETRANGELOCKFLAGS, &blob, 1);
+    if (code)
+	Die(errno, NULL);
+    return 0;
+}
+
+static afs_int32
+GetRangeLockFlagsCmd(struct cmd_syndesc *as, char *arock)
+{
+    afs_int32 code = 0, flags;
+    struct ViceIoctl blob;
+    char *tp;
+
+    blob.in = NULL;
+    blob.in_size = 0;
+    blob.out_size = sizeof(flags);
+    blob.out = space;
+
+    code = pioctl(0, VIOC_GETRANGELOCKFLAGS, &blob, 1);
+
+    if (code)
+	Die(errno, NULL);
+    else {
+	tp = space;
+	memcpy(&flags, tp, sizeof(afs_int32));
+	printf("Client range lock flags currently %d\n", flags);
+    }
+    return 0;
+}
+
 #include "AFS_component_version_number.c"
 
 int
@@ -3422,6 +3478,14 @@
     ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0,
 			  "get cache manager encryption flag");
 
+    ts = cmd_CreateSyntax("setrangelockflags", SetRangeLockFlagsCmd, 0,
+			  "set cache manager byte-range lock behavior flags");
+    cmd_AddParm(ts, "-flagset", CMD_SINGLE, 0, 
+		"flag set (0 default, 01 fail range requests)");
+
+    ts = cmd_CreateSyntax("getrangelockflags", GetRangeLockFlagsCmd, 0,
+			  "get cache manager byte-range lock behavior flags");
+
     ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
 			  "Manage per process RX statistics");
     cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");

--------------060405090804050907020903--