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 <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
This commit is contained in:
Michael Meffie 2015-04-29 12:00:24 -04:00 committed by Benjamin Kaduk
parent c17d142230
commit 0028ea92ad
6 changed files with 83 additions and 4 deletions

View File

@ -20,6 +20,7 @@ B<afsd> [B<-afsdb>] [B<-backuptree>]
S<<< [B<-files> <I<files in cache>>] >>>
S<<< [B<-files_per_subdir> <I<log(2) of files per dir>> ] >>>
[B<-help>] S<<< [B<-logfile> <I<Place to keep the CM log>>] >>>
S<<< [B<-inumcalc>] <I<method>> >>>
[B<-mem_alloc_sleep>] [B<-memcache>]
S<<< [B<-mountdir> <I<mount location>>] >>> [B<-nomount>]
[B<-nosettime>]
@ -604,6 +605,24 @@ ignored.
This option is obsolete and no longer has any effect.
=item B<-inumcalc> <I<method>>
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<compat> and C<md5>. The default method is C<compat>.
When the C<compat> 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<md5> 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<md5> 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.

View File

@ -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

View File

@ -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;
}

View File

@ -41,7 +41,7 @@
#include <sys/fp_io.h>
#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);

View File

@ -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 <afsconfig.h>
@ -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:

View File

@ -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.