Skip to content

Commit

Permalink
NFS: add filehandle crc for debug display
Browse files Browse the repository at this point in the history
Match wireshark's CRC-32 hash for easier debugging

Signed-off-by: Weston Andros Adamson <dros@netapp.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
  • Loading branch information
Weston Andros Adamson authored and Trond Myklebust committed Mar 7, 2012
1 parent ff2eb68 commit d8e0539
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
23 changes: 20 additions & 3 deletions fs/nfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <linux/slab.h>
#include <linux/compat.h>
#include <linux/freezer.h>
#include <linux/crc32.h>

#include <asm/system.h>
#include <asm/uaccess.h>
Expand Down Expand Up @@ -1045,15 +1046,30 @@ struct nfs_fh *nfs_alloc_fhandle(void)
return fh;
}

/**
#ifdef RPC_DEBUG
/*
* _nfs_display_fhandle_hash - calculate the crc32 hash for the filehandle
* in the same way that wireshark does
*
* @fh: file handle
*
* For debugging only.
*/
u32 _nfs_display_fhandle_hash(const struct nfs_fh *fh)
{
/* wireshark uses 32-bit AUTODIN crc and does a bitwise
* not on the result */
return ~crc32(0xFFFFFFFF, &fh->data[0], fh->size);
}

/*
* _nfs_display_fhandle - display an NFS file handle on the console
*
* @fh: file handle to display
* @caption: display caption
*
* For debugging only.
*/
#ifdef RPC_DEBUG
void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption)
{
unsigned short i;
Expand All @@ -1063,7 +1079,8 @@ void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption)
return;
}

printk(KERN_DEFAULT "%s at %p is %u bytes:\n", caption, fh, fh->size);
printk(KERN_DEFAULT "%s at %p is %u bytes, crc: 0x%08x:\n",
caption, fh, fh->size, _nfs_display_fhandle_hash(fh));
for (i = 0; i < fh->size; i += 16) {
__be32 *pos = (__be32 *)&fh->data[i];

Expand Down
8 changes: 8 additions & 0 deletions include/linux/nfs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,21 @@ static inline void nfs_free_fhandle(const struct nfs_fh *fh)
}

#ifdef RPC_DEBUG
extern u32 _nfs_display_fhandle_hash(const struct nfs_fh *fh);
static inline u32 nfs_display_fhandle_hash(const struct nfs_fh *fh)
{
return _nfs_display_fhandle_hash(fh);
}
extern void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption);
#define nfs_display_fhandle(fh, caption) \
do { \
if (unlikely(nfs_debug & NFSDBG_FACILITY)) \
_nfs_display_fhandle(fh, caption); \
} while (0)
#else
static inline u32 nfs_display_fhandle_hash(const struct nfs_fh *fh)
{
}
static inline void nfs_display_fhandle(const struct nfs_fh *fh,
const char *caption)
{
Expand Down

0 comments on commit d8e0539

Please sign in to comment.