From 32571182cbd47b83bdb432c7a6905764413523f9 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. Reviewed-on: https://gerrit.openafs.org/11855 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk (cherry picked from commit 0028ea92ad3e7aac6a4c51f63703a4d9d7b9dcd6) Change-Id: I9021eea9f64c754157061d039f63b6f744ec2ec5 Reviewed-on: https://gerrit.openafs.org/12608 Reviewed-by: Mark Vitale Reviewed-by: Stephan Wiesand Tested-by: Stephan Wiesand --- 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 | 9 +++++++++ 6 files changed, 84 insertions(+), 4 deletions(-) diff --git a/doc/man-pages/pod8/afsd.pod b/doc/man-pages/pod8/afsd.pod index 062e38b0a5..dcc826aaba 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>] @@ -605,6 +606,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 7a12d8e4d6..4f02d81623 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. */ @@ -1304,6 +1307,19 @@ afs_syscall_call(long parm, long parm2, long parm3, } else if (parm == AFSOP_SET_RMTSYS_FLAG) { afs_rmtsys_enable = parm2; code = 0; + } 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 d79c386982..e0f6cd1cda 100644 --- a/src/afs/afs_util.c +++ b/src/afs/afs_util.c @@ -53,7 +53,7 @@ #include #endif -afs_int32 afs_new_inum = 0; +afs_int32 afs_md5inum = 0; #ifndef afs_cv2string char * @@ -373,7 +373,7 @@ afs_calc_inum(afs_int32 cell, afs_int32 volume, afs_int32 vnode) char digest[16]; struct afs_md5 ct; - if (afs_new_inum) { + if (afs_md5inum) { int offset; AFS_MD5_Init(&ct); AFS_MD5_Update(&ct, &cell, 4); diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index 4adfc09423..2f0478db19 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -51,6 +51,7 @@ * -waitclose make close calls always synchronous (slows em down, tho) * -files_per_subdir [n] number of files per cache subdir. (def=2048) * -shutdown Shutdown afs daemons + * -inumcalc inode number calculation method; 0=compat, 1=MD5 digest *---------------------------------------------------------------------------*/ #include @@ -297,6 +298,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? */ @@ -1912,6 +1914,11 @@ mainproc(struct cmd_syndesc *as, void *arock) rxmaxfrags = atoi(as->parms[38].items->data); } + if (as->parms[39].items) { + /* -inumcalc */ + inumcalc = strdup(as->parms[39].items->data); + } + /* parse cacheinfo file if this is a diskcache */ if (ParseCacheInfoFile()) { exit(1); @@ -2336,6 +2343,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_call_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_call_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, @@ -2593,6 +2627,8 @@ afsd_init(void) cmd_AddParm(ts, "-rxmaxfrags", CMD_SINGLE, CMD_OPTIONAL, "Set the maximum number of UDP fragments Rx should send/receive" " per Rx packet"); + cmd_AddParm(ts, "-inumcalc", CMD_SINGLE, CMD_OPTIONAL, + "Set inode number calculation method"); } int diff --git a/src/config/afs_args.h b/src/config/afs_args.h index 73d3ee62c3..62ba387293 100644 --- a/src/config/afs_args.h +++ b/src/config/afs_args.h @@ -53,6 +53,8 @@ #define AFSOP_SET_RXMAXFRAGS 43 /* set rxi_nSendFrags, rxi_nRecvFrags */ #define AFSOP_SET_RMTSYS_FLAG 44 /* set flag if rmtsys is enabled */ +#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 #define AFSCALL_SETPAG 21 @@ -175,6 +177,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.