Return-Path: linux-nfs-owner@vger.kernel.org Received: from mail-gy0-f174.google.com ([209.85.160.174]:62070 "EHLO mail-gy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754620Ab2BOVgB (ORCPT ); Wed, 15 Feb 2012 16:36:01 -0500 Received: by mail-gy0-f174.google.com with SMTP id r11so965647ghr.19 for ; Wed, 15 Feb 2012 13:36:01 -0800 (PST) From: Chuck Lever Subject: [PATCH 09/13] NFS: Add a client-side function to display NFS file handles To: trond.myklebust@netapp.com Cc: linux-nfs@vger.kernel.org Date: Wed, 15 Feb 2012 16:36:00 -0500 Message-ID: <20120215213559.3254.94426.stgit@ellison.1015granger.net> In-Reply-To: <20120215213336.3254.98936.stgit@ellison.1015granger.net> References: <20120215213336.3254.98936.stgit@ellison.1015granger.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Sender: linux-nfs-owner@vger.kernel.org List-ID: For debugging, introduce a simplistic function to print NFS file handles on the system console. The main function is hooked into the dprintk debugging facility, but you can directly call the helper, _nfs_display_fhandle(), if you want to print a handle unconditionally. Signed-off-by: Chuck Lever --- fs/nfs/inode.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/nfs_fs.h | 14 ++++++++++++++ 2 files changed, 59 insertions(+), 0 deletions(-) diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 5c9598f..d36c1cb 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -1076,6 +1076,51 @@ struct nfs_fh *nfs_alloc_fhandle(void) } /** + * _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; + + if (fh->size == 0 || fh == NULL) { + printk(KERN_DEFAULT "%s at %p is empty\n", caption, fh); + return; + } + + printk(KERN_DEFAULT "%s at %p is %u bytes:\n", caption, fh, fh->size); + for (i = 0; i < fh->size; i += 16) { + __be32 *pos = (__be32 *)&fh->data[i]; + + switch ((fh->size - i - 1) >> 2) { + case 0: + printk(KERN_DEFAULT " %08x\n", + be32_to_cpup(pos)); + break; + case 1: + printk(KERN_DEFAULT " %08x %08x\n", + be32_to_cpup(pos), be32_to_cpup(pos + 1)); + break; + case 2: + printk(KERN_DEFAULT " %08x %08x %08x\n", + be32_to_cpup(pos), be32_to_cpup(pos + 1), + be32_to_cpup(pos + 2)); + break; + default: + printk(KERN_DEFAULT " %08x %08x %08x %08x\n", + be32_to_cpup(pos), be32_to_cpup(pos + 1), + be32_to_cpup(pos + 2), be32_to_cpup(pos + 3)); + } + } +} +#endif + +/** * nfs_inode_attrs_need_update - check if the inode attributes need updating * @inode - pointer to inode * @fattr - attributes diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index 2e4601a..43b9062 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -399,6 +399,20 @@ static inline void nfs_free_fhandle(const struct nfs_fh *fh) kfree(fh); } +#ifdef RPC_DEBUG +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 void nfs_display_fhandle(const struct nfs_fh *fh, + const char *caption) +{ +} +#endif + /* * linux/fs/nfs/nfsroot.c */