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

Adam Megacz megacz@cs.berkeley.edu
Thu, 15 Feb 2007 10:17:53 -0800


Is there any chance of this patch -- or something close to it -- being
integrated into OpenAFS?

  - a


Matt Benjamin <matt@linuxbox.com> writes:
> 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");

-- 
PGP/GPG: 5C9F F366 C9CF 2145 E770  B1B8 EFB1 462D A146 C380