From 0b1d10fd2535b0059d1e88c23fbd3f60041edc9f Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Tue, 20 Feb 2018 11:51:01 -0500 Subject: [PATCH] afs: improve -volume-ttl error messages Change the afs call which sets the volume ttl value to return EFAULT instead of EINVAL when given an out of range value for the volume ttl parameter. This is more consistent with the other op codes, which return EFAULT when given an out of range parameter and allows the caller to distinguish between an invalid opcode and a bad parameter. Move the volume ttl range constants to afs_args.h, which is where constants related to the op codes are supposed to be defined. This makes the constants available to the caller in afsd.c as well as the implementation in afs_call.c. Update afsd to print a more sensible error message when the volume ttl set calls fails due to an out of range parameter. Reviewed-on: https://gerrit.openafs.org/12918 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk (cherry picked from commit 6d74e3d6a1becf86cec30efc2d01a5692167afe1) Change-Id: I2cd86b6fbba31f74862bb902ac94b0874de8afac Reviewed-on: https://gerrit.openafs.org/12936 Tested-by: BuildBot Reviewed-by: Mark Vitale Reviewed-by: Benjamin Kaduk --- src/afs/afs.h | 4 ---- src/afs/afs_call.c | 2 +- src/afsd/afsd.c | 16 ++++++++++++++-- src/config/afs_args.h | 3 +++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/afs/afs.h b/src/afs/afs.h index d94f32825..bf2273dc9 100644 --- a/src/afs/afs.h +++ b/src/afs/afs.h @@ -1398,10 +1398,6 @@ extern struct brequest afs_brs[NBRS]; /* request structures */ #define AFS_VOLCHECK_MTPTS 0x4 /* mount point invalidation also */ #define AFS_VOLCHECK_FORCE 0x8 /* do all forcibly */ -/* For volume ttl expiry checks. */ -#define AFS_MIN_VOLUME_TTL 600 -#define AFS_MAX_VOLUME_TTL MAX_AFS_INT32 - #endif /* KERNEL */ #define AFS_FSPORT ((unsigned short) htons(7000)) diff --git a/src/afs/afs_call.c b/src/afs/afs_call.c index bec71c4d1..6eae4dab2 100644 --- a/src/afs/afs_call.c +++ b/src/afs/afs_call.c @@ -1321,7 +1321,7 @@ afs_syscall_call(long parm, long parm2, long parm3, } } else if (parm == AFSOP_SET_VOLUME_TTL) { if ((parm2 < AFS_MIN_VOLUME_TTL) || (parm2 > AFS_MAX_VOLUME_TTL)) { - code = EINVAL; + code = EFAULT; } else { afs_volume_ttl = parm2; code = 0; diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index 46921728a..b3f2fc56b 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -2433,8 +2433,20 @@ afsd_run(void) if (afsd_verbose) printf("%s: Calling AFSOP_SET_VOLUME_TTL with '%d'\n", rn, volume_ttl); code = afsd_syscall(AFSOP_SET_VOLUME_TTL, volume_ttl); - if (code != 0) - printf("%s: Error setting volume ttl to %d seconds; code=%d.\n", rn, volume_ttl, code); + if (code == EFAULT) { + if (volume_ttl < AFS_MIN_VOLUME_TTL) + printf("%s: Failed to set volume ttl to %d seconds; " + "value is too low.\n", rn, volume_ttl); + else if (volume_ttl > AFS_MAX_VOLUME_TTL) + printf("%s: Failed to set volume ttl to %d seconds; " + "value is too high.\n", rn, volume_ttl); + else + printf("%s: Failed to set volume ttl to %d seconds; " + "value is out of range.\n", rn, volume_ttl); + } else if (code != 0) { + printf("%s: Failed to set volume ttl to %d seconds; " + "code=%d.\n", rn, volume_ttl, code); + } } /* diff --git a/src/config/afs_args.h b/src/config/afs_args.h index 4fa286ba3..2609bcef4 100644 --- a/src/config/afs_args.h +++ b/src/config/afs_args.h @@ -179,6 +179,9 @@ enum { AFS_INUMCALC_MD5 = 1 }; +/* Supported volume ttl range. */ +#define AFS_MIN_VOLUME_TTL 600 +#define AFS_MAX_VOLUME_TTL MAX_AFS_INT32 /* * Note that the AFS_*ALLOCSIZ values should be multiples of sizeof(void*) to -- 2.39.5