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 <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
(cherry picked from commit 0028ea92ad)

Change-Id: I9021eea9f64c754157061d039f63b6f744ec2ec5
Reviewed-on: https://gerrit.openafs.org/12608
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Tested-by: Stephan Wiesand <stephan.wiesand@desy.de>
This commit is contained in:
Michael Meffie 2015-04-29 12:00:24 -04:00 committed by Stephan Wiesand
parent 703f7219ab
commit 32571182cb
6 changed files with 84 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>]
@ -605,6 +606,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.
*/
@ -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;
}

View File

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

View File

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

View File

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