From 0028ea92ad3e7aac6a4c51f63703a4d9d7b9dcd6 Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Wed, 29 Apr 2015 12:00:24 -0400 Subject: [PATCH] afs: add afsd -inumcalc option This commit adds the afsd -inumcalc command line switch to specify the inode number calculation method in a platform neutral way. Inode numbers reported for files within the AFS filesystem are generated by the cache manager using a calculation which derives a number from a FID. Long ago, a new type of calculation was added which generates inode numbers using a MD5 message digest of the FID. The MD5 inode number calculation variant is computationally more expensive but greatly reduces the chances for inode number collisions. The MD5 calculation can be enabled on the Linux cache manager using the Linux sysctl interface. Other than the sysctl method of selecting the inode calculation type, the MD5 inode number calculation method is not specific to Linux. This change introduces a command-line option which accepts a value to indicate the calculation method, instead of a simple flag to enable MD5 inode numbers. This should allow for new inode calculation methods in the future without the need for additional afsd command-line flags. Two values are currently accepted for -inumcalc. The value of 'compat' specifies the legacy inode number calculation. The value 'md5' indicates that the new MD5 calculation is to be used. Change-Id: I0257c68ca1a32a7a4c55ca8174a4926ff78ddea4 Reviewed-on: https://gerrit.openafs.org/11855 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk --- doc/man-pages/pod8/afsd.pod | 19 +++++++++++++++++++ src/afs/LINUX/osi_sysctl.c | 4 ++-- src/afs/afs_call.c | 16 ++++++++++++++++ src/afs/afs_util.c | 4 ++-- src/afsd/afsd.c | 36 ++++++++++++++++++++++++++++++++++++ src/config/afs_args.h | 8 ++++++++ 6 files changed, 83 insertions(+), 4 deletions(-) diff --git a/doc/man-pages/pod8/afsd.pod b/doc/man-pages/pod8/afsd.pod index b28417279a..dd48a161fc 100644 --- a/doc/man-pages/pod8/afsd.pod +++ b/doc/man-pages/pod8/afsd.pod @@ -20,6 +20,7 @@ B [B<-afsdb>] [B<-backuptree>] S<<< [B<-files> >] >>> S<<< [B<-files_per_subdir> > ] >>> [B<-help>] S<<< [B<-logfile> >] >>> + S<<< [B<-inumcalc>] > >>> [B<-mem_alloc_sleep>] [B<-memcache>] S<<< [B<-mountdir> >] >>> [B<-nomount>] [B<-nosettime>] @@ -604,6 +605,24 @@ ignored. This option is obsolete and no longer has any effect. +=item B<-inumcalc> > + +Specifies the method used by the Cache Manager to generate inode numbers for +files, directories, and symlinks in the AFS filesystem. Valid methods are +C and C. The default method is C. + +When the C method is in effect, the Cache Manager generates inode +numbers for a given inode by multiplying the AFS volume number by 65536, adding +the result to the AFS vnode number, and finally truncating the result to a +signed 32 bit integer. + +When the C method is in effect, the Cache Manager generates inode numbers +for a given inode by calculating the MD5 digest of a combination of the cell +number, volume number, and vnode number. The result is truncated to a signed 32 +bit integer. The C method is computationally more expensive but greatly +reduces the chance for inode number collisions, especially when volumes from +multiple cells are mounted within the AFS filesystem. + =item B<-mem_alloc_sleep> This option is obsolete and no longer has any effect. diff --git a/src/afs/LINUX/osi_sysctl.c b/src/afs/LINUX/osi_sysctl.c index 834e8ad317..2b1be3b0c6 100644 --- a/src/afs/LINUX/osi_sysctl.c +++ b/src/afs/LINUX/osi_sysctl.c @@ -19,7 +19,7 @@ #endif /* From afs_util.c */ -extern afs_int32 afs_new_inum; +extern afs_int32 afs_md5inum; /* From afs_analyze.c */ extern afs_int32 hm_retry_RO; @@ -226,7 +226,7 @@ static struct ctl_table afs_sysctl_table[] = { #endif #endif .procname = "md5inum", - .data = &afs_new_inum, + .data = &afs_md5inum, .maxlen = sizeof(afs_int32), .mode = 0644, .proc_handler = &proc_dointvec diff --git a/src/afs/afs_call.c b/src/afs/afs_call.c index f071e20e64..4938e7b001 100644 --- a/src/afs/afs_call.c +++ b/src/afs/afs_call.c @@ -87,6 +87,9 @@ afs_int32 afs_rx_idledead_rep = AFS_IDLEDEADTIME_REP; static int afscall_set_rxpck_received = 0; +/* From afs_util.c */ +extern afs_int32 afs_md5inum; + /* This is code which needs to be called once when the first daemon enters * the client. A non-zero return means an error and AFS should not start. */ @@ -1301,6 +1304,19 @@ afs_syscall_call(long parm, long parm2, long parm3, afs_osi_Free(seedbuf, parm3); } #endif + } else if (parm == AFSOP_SET_INUMCALC) { + switch (parm2) { + case AFS_INUMCALC_COMPAT: + afs_md5inum = 0; + code = 0; + break; + case AFS_INUMCALC_MD5: + afs_md5inum = 1; + code = 0; + break; + default: + code = EINVAL; + } } else { code = EINVAL; } diff --git a/src/afs/afs_util.c b/src/afs/afs_util.c index 28796136c6..8bd595cc10 100644 --- a/src/afs/afs_util.c +++ b/src/afs/afs_util.c @@ -41,7 +41,7 @@ #include #endif -afs_int32 afs_new_inum = 0; +afs_int32 afs_md5inum = 0; #ifndef afs_cv2string char * @@ -381,7 +381,7 @@ afs_calc_inum_md5(afs_int32 cell, afs_int32 volume, afs_int32 vnode) char digest[16]; struct md5 ct; - if (afs_new_inum) { + if (afs_md5inum) { int offset; MD5_Init(&ct); MD5_Update(&ct, &cell, 4); diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index 877869367e..147865105f 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -66,6 +66,7 @@ * -rxpck Value for rx_extraPackets. * -splitcache RW/RO ratio for cache. * -rxmaxfrags Max number of UDP fragments per rx packet. + * -inumcalc inode number calculation method; 0=compat, 1=MD5 digest *---------------------------------------------------------------------------*/ #include @@ -276,6 +277,7 @@ static int enable_fakestat = 0; /* enable fakestat support */ static int enable_backuptree = 0; /* enable backup tree support */ static int enable_nomount = 0; /* do not mount */ static int enable_splitcache = 0; +static char *inumcalc = NULL; /* inode number calculation method */ static int afsd_dynamic_vcaches = 0; /* Enable dynamic-vcache support */ int afsd_verbose = 0; /*Are we being chatty? */ int afsd_debug = 0; /*Are we printing debugging info? */ @@ -359,6 +361,7 @@ enum optionsList { OPT_rxmaxmtu, OPT_dynrootsparse, OPT_rxmaxfrags, + OPT_inumcalc, }; #ifdef MACOS_EVENT_HANDLING @@ -1891,6 +1894,9 @@ mainproc(struct cmd_syndesc *as, void *arock) } cmd_OptionAsInt(as, OPT_rxmaxfrags, &rxmaxfrags); + if (cmd_OptionPresent(as, OPT_inumcalc)) { + cmd_OptionAsString(as, OPT_inumcalc, &inumcalc); + } /* parse cacheinfo file if this is a diskcache */ if (ParseCacheInfoFile()) { @@ -2311,6 +2317,33 @@ afsd_run(void) printf("%s: Error seting rxmaxmtu\n", rn); } + if (inumcalc != NULL) { + if (strcmp(inumcalc, "compat") == 0) { + if (afsd_verbose) { + printf("%s: Setting original inode number calculation method in kernel.\n", + rn); + } + code = afsd_syscall(AFSOP_SET_INUMCALC, AFS_INUMCALC_COMPAT); + if (code) { + printf("%s: Error setting inode calculation method: code=%d.\n", + rn, code); + } + } else if (strcmp(inumcalc, "md5") == 0) { + if (afsd_verbose) { + printf("%s: Setting md5 digest inode number calculation in kernel.\n", + rn); + } + code = afsd_syscall(AFSOP_SET_INUMCALC, AFS_INUMCALC_MD5); + if (code) { + printf("%s: Error setting inode calculation method: code=%d.\n", + rn, code); + } + } else { + printf("%s: Unknown value for -inumcalc: %s." + "Using default inode calculation method.\n", rn, inumcalc); + } + } + if (enable_dynroot) { if (afsd_verbose) printf("%s: Enabling dynroot support in kernel%s.\n", rn, @@ -2581,6 +2614,8 @@ afsd_init(void) CMD_OPTIONAL, "Set the maximum number of UDP fragments Rx should " "send/receive per Rx packet"); + cmd_AddParmAtOffset(ts, OPT_inumcalc, "-inumcalc", CMD_SINGLE, CMD_OPTIONAL, + "Set inode number calculation method"); } int @@ -2646,6 +2681,7 @@ afsd_syscall_populate(struct afsd_syscall_args *args, int syscall, va_list ap) case AFSOP_BUCKETPCT: case AFSOP_GO: case AFSOP_SET_RMTSYS_FLAG: + case AFSOP_SET_INUMCALC: params[0] = CAST_SYSCALL_PARAM((va_arg(ap, int))); break; case AFSOP_SET_THISCELL: diff --git a/src/config/afs_args.h b/src/config/afs_args.h index 01bdac53ea..959d91ba65 100644 --- a/src/config/afs_args.h +++ b/src/config/afs_args.h @@ -53,6 +53,7 @@ #define AFSOP_SET_RXMAXFRAGS 43 /* set rxi_nSendFrags, rxi_nRecvFrags */ #define AFSOP_SET_RMTSYS_FLAG 44 /* set flag if rmtsys is enabled */ #define AFSOP_SEED_ENTROPY 45 /* Give the kernel hcrypto entropy */ +#define AFSOP_SET_INUMCALC 46 /* set inode number calculation method */ /* The range 20-30 is reserved for AFS system offsets in the afs_syscall */ #define AFSCALL_PIOCTL 20 @@ -169,6 +170,13 @@ struct afs_cacheParams { afs_int32 dynamic_vcaches; }; +/* Supported values for AFSOP_SET_INUMCALC. */ +enum { + AFS_INUMCALC_COMPAT = 0, + AFS_INUMCALC_MD5 = 1 +}; + + /* * Note that the AFS_*ALLOCSIZ values should be multiples of sizeof(void*) to * accomodate pointer alignment.