Skip to content

Commit 1264a2f

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
NFS: refactor code for calculating the crc32 hash of a filehandle
We want to be able to display the crc32 hash of the filehandle in tracepoints. Signed-off-by: Trond Myklebust <[email protected]>
1 parent c2dd137 commit 1264a2f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

fs/nfs/inode.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include <linux/slab.h>
3939
#include <linux/compat.h>
4040
#include <linux/freezer.h>
41-
#include <linux/crc32.h>
4241

4342
#include <asm/uaccess.h>
4443

@@ -1190,7 +1189,7 @@ u32 _nfs_display_fhandle_hash(const struct nfs_fh *fh)
11901189
{
11911190
/* wireshark uses 32-bit AUTODIN crc and does a bitwise
11921191
* not on the result */
1193-
return ~crc32(0xFFFFFFFF, &fh->data[0], fh->size);
1192+
return nfs_fhandle_hash(fh);
11941193
}
11951194

11961195
/*

fs/nfs/internal.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "nfs4_fs.h"
66
#include <linux/mount.h>
77
#include <linux/security.h>
8+
#include <linux/crc32.h>
89

910
#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1011

@@ -574,3 +575,22 @@ u64 nfs_timespec_to_change_attr(const struct timespec *ts)
574575
{
575576
return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
576577
}
578+
579+
#ifdef CONFIG_CRC32
580+
/**
581+
* nfs_fhandle_hash - calculate the crc32 hash for the filehandle
582+
* @fh - pointer to filehandle
583+
*
584+
* returns a crc32 hash for the filehandle that is compatible with
585+
* the one displayed by "wireshark".
586+
*/
587+
static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
588+
{
589+
return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
590+
}
591+
#else
592+
static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
593+
{
594+
return 0;
595+
}
596+
#endif

0 commit comments

Comments
 (0)