From patchwork Sun Jun 19 21:42:02 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Van Hensbergen X-Patchwork-Id: 895382 X-Patchwork-Delegate: ericvh@gmail.com Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5JLhWPW003241 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 19 Jun 2011 21:43:53 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1QYPly-0000h5-KX; Sun, 19 Jun 2011 21:43:14 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1QYPly-0000gz-03 for v9fs-developer@lists.sourceforge.net; Sun, 19 Jun 2011 21:43:14 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of gmail.com designates 74.125.83.47 as permitted sender) client-ip=74.125.83.47; envelope-from=ericvh@gmail.com; helo=mail-gw0-f47.google.com; Received: from mail-gw0-f47.google.com ([74.125.83.47]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1QYPlw-0006im-V7 for v9fs-developer@lists.sourceforge.net; Sun, 19 Jun 2011 21:43:13 +0000 Received: by gwb11 with SMTP id 11so5243gwb.34 for ; Sun, 19 Jun 2011 14:43:07 -0700 (PDT) Received: by 10.236.200.234 with SMTP id z70mr4277138yhn.325.1308519787347; Sun, 19 Jun 2011 14:43:07 -0700 (PDT) Received: from localhost.localdomain (cpe-72-177-122-77.austin.res.rr.com [72.177.122.77]) by mx.google.com with ESMTPS id v22sm3124999yhm.20.2011.06.19.14.43.05 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 19 Jun 2011 14:43:06 -0700 (PDT) From: Eric Van Hensbergen To: v9fs-developer@lists.sourceforge.net Date: Sun, 19 Jun 2011 16:42:02 -0500 Message-Id: <1308519722-31238-1-git-send-email-ericvh@gmail.com> X-Mailer: git-send-email 1.7.4.1 X-Spam-Score: -1.6 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain 0.0 FREEMAIL_FROM Sender email is freemail (ericvh[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.0 T_FRT_FREE BODY: ReplaceTags: Free -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 RFC_ABUSE_POST Both abuse and postmaster missing on sender domain 0.0 T_TO_NO_BRKTS_FREEMAIL T_TO_NO_BRKTS_FREEMAIL X-Headers-End: 1QYPlw-0006im-V7 Cc: Eric Van Hensbergen Subject: [V9fs-developer] [PATCH] 9p: clean up packet dump code X-BeenThere: v9fs-developer@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: v9fs-developer-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sun, 19 Jun 2011 21:43:53 +0000 (UTC) Switch to generic kernel hexdump library and cleanup macros to be more consistent with the way we do normal debug prints. Signed-off-by: Eric Van Hensbergen --- include/net/9p/9p.h | 6 ++++++ net/9p/client.c | 39 ++++++++++++++++++++------------------- net/9p/protocol.c | 44 +++++++++++++++++--------------------------- 3 files changed, 43 insertions(+), 46 deletions(-) diff --git a/include/net/9p/9p.h b/include/net/9p/9p.h index 008711e..1abbfd8 100644 --- a/include/net/9p/9p.h +++ b/include/net/9p/9p.h @@ -40,6 +40,7 @@ * @P9_DEBUG_FID: fid allocation/deallocation tracking * @P9_DEBUG_PKT: packet marshalling/unmarshalling * @P9_DEBUG_FSC: FS-cache tracing + * @P9_DEBUG_VPKT: Verbose packet debugging (full packet dump) * * These flags are passed at mount time to turn on various levels of * verbosity and tracing which will be output to the system logs. @@ -57,6 +58,7 @@ enum p9_debug_flags { P9_DEBUG_FID = (1<<9), P9_DEBUG_PKT = (1<<10), P9_DEBUG_FSC = (1<<11), + P9_DEBUG_VPKT = (1<<12), }; #ifdef CONFIG_NET_9P_DEBUG @@ -74,10 +76,14 @@ do { \ } \ } while (0) +#define P9_DUMP_PKT(way, pdu) p9pdu_dump(way, pdu) + #else #define P9_DPRINTK(level, format, arg...) do { } while (0) +#define P9_DUMP_PKT(way, pdu) do { } while (0) #endif + #define P9_EPRINTK(level, format, arg...) \ do { \ printk(level "9p: %s (%d): " \ diff --git a/net/9p/client.c b/net/9p/client.c index 9e3b0e6..b2ed0a8 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -749,7 +749,7 @@ static int p9_client_version(struct p9_client *c) err = p9pdu_readf(req->rc, c->proto_version, "ds", &msize, &version); if (err) { P9_DPRINTK(P9_DEBUG_9P, "version error %d\n", err); - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto error; } @@ -911,7 +911,7 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, err = p9pdu_readf(req->rc, clnt->proto_version, "Q", &qid); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); p9_free_req(clnt, req); goto error; } @@ -971,7 +971,7 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, uint16_t nwname, err = p9pdu_readf(req->rc, clnt->proto_version, "R", &nwqids, &wqids); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); p9_free_req(clnt, req); goto clunk_fid; } @@ -1038,7 +1038,7 @@ int p9_client_open(struct p9_fid *fid, int mode) err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", &qid, &iounit); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto free_and_error; } @@ -1081,7 +1081,7 @@ int p9_client_create_dotl(struct p9_fid *ofid, char *name, u32 flags, u32 mode, err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", qid, &iounit); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto free_and_error; } @@ -1126,7 +1126,7 @@ int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode, err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", &qid, &iounit); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto free_and_error; } @@ -1165,7 +1165,7 @@ int p9_client_symlink(struct p9_fid *dfid, char *name, char *symtgt, gid_t gid, err = p9pdu_readf(req->rc, clnt->proto_version, "Q", qid); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto free_and_error; } @@ -1318,11 +1318,12 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset, err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto free_and_error; } P9_DPRINTK(P9_DEBUG_9P, "<<< RREAD count %d\n", count); + P9_DUMP_PKT(1, req->rc); if (!req->tc->pbuf_size) { if (data) { @@ -1386,7 +1387,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata, err = p9pdu_readf(req->rc, clnt->proto_version, "d", &count); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto free_and_error; } @@ -1426,7 +1427,7 @@ struct p9_wstat *p9_client_stat(struct p9_fid *fid) err = p9pdu_readf(req->rc, clnt->proto_version, "wS", &ignored, ret); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); p9_free_req(clnt, req); goto error; } @@ -1477,7 +1478,7 @@ struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid, err = p9pdu_readf(req->rc, clnt->proto_version, "A", ret); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); p9_free_req(clnt, req); goto error; } @@ -1625,7 +1626,7 @@ int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb) &sb->bsize, &sb->blocks, &sb->bfree, &sb->bavail, &sb->files, &sb->ffree, &sb->fsid, &sb->namelen); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); p9_free_req(clnt, req); goto error; } @@ -1701,7 +1702,7 @@ struct p9_fid *p9_client_xattrwalk(struct p9_fid *file_fid, } err = p9pdu_readf(req->rc, clnt->proto_version, "q", attr_size); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); p9_free_req(clnt, req); goto clunk_fid; } @@ -1780,7 +1781,7 @@ int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset) err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto free_and_error; } @@ -1817,7 +1818,7 @@ int p9_client_mknod_dotl(struct p9_fid *fid, char *name, int mode, err = p9pdu_readf(req->rc, clnt->proto_version, "Q", qid); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto error; } P9_DPRINTK(P9_DEBUG_9P, "<<< RMKNOD qid %x.%llx.%x\n", qid->type, @@ -1848,7 +1849,7 @@ int p9_client_mkdir_dotl(struct p9_fid *fid, char *name, int mode, err = p9pdu_readf(req->rc, clnt->proto_version, "Q", qid); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto error; } P9_DPRINTK(P9_DEBUG_9P, "<<< RMKDIR qid %x.%llx.%x\n", qid->type, @@ -1883,7 +1884,7 @@ int p9_client_lock_dotl(struct p9_fid *fid, struct p9_flock *flock, u8 *status) err = p9pdu_readf(req->rc, clnt->proto_version, "b", status); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto error; } P9_DPRINTK(P9_DEBUG_9P, "<<< RLOCK status %i\n", *status); @@ -1916,7 +1917,7 @@ int p9_client_getlock_dotl(struct p9_fid *fid, struct p9_getlock *glock) &glock->start, &glock->length, &glock->proc_id, &glock->client_id); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto error; } P9_DPRINTK(P9_DEBUG_9P, "<<< RGETLOCK type %i start %lld length %lld " @@ -1944,7 +1945,7 @@ int p9_client_readlink(struct p9_fid *fid, char **target) err = p9pdu_readf(req->rc, clnt->proto_version, "s", target); if (err) { - p9pdu_dump(1, req->rc); + P9_DUMP_PKT(1, req->rc); goto error; } P9_DPRINTK(P9_DEBUG_9P, "<<< RREADLINK target %s\n", *target); diff --git a/net/9p/protocol.c b/net/9p/protocol.c index a873277..df58375 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c @@ -44,30 +44,24 @@ p9pdu_writef(struct p9_fcall *pdu, int proto_version, const char *fmt, ...); void p9pdu_dump(int way, struct p9_fcall *pdu) { - int i, n; - u8 *data = pdu->sdata; - int datalen = pdu->size; - char buf[255]; - int buflen = 255; - - i = n = 0; - if (datalen > (buflen-16)) - datalen = buflen-16; - while (i < datalen) { - n += scnprintf(buf + n, buflen - n, "%02x ", data[i]); - if (i%4 == 3) - n += scnprintf(buf + n, buflen - n, " "); - if (i%32 == 31) - n += scnprintf(buf + n, buflen - n, "\n"); - - i++; + int len = pdu->size; + + if ((p9_debug_level & P9_DEBUG_VPKT) != P9_DEBUG_VPKT) { + if ((p9_debug_level & P9_DEBUG_PKT) == P9_DEBUG_PKT) { + if (len > 32) + len = 32; + } else { + /* shouldn't happen */ + return; + } } - n += scnprintf(buf + n, buflen - n, "\n"); if (way) - P9_DPRINTK(P9_DEBUG_PKT, "[[[(%d) %s\n", datalen, buf); + print_hex_dump_bytes("[9P] ", DUMP_PREFIX_OFFSET, pdu->sdata, + len); else - P9_DPRINTK(P9_DEBUG_PKT, "]]](%d) %s\n", datalen, buf); + print_hex_dump_bytes("]9P[ ", DUMP_PREFIX_OFFSET, pdu->sdata, + len); } #else void @@ -610,7 +604,7 @@ int p9stat_read(char *buf, int len, struct p9_wstat *st, int proto_version) ret = p9pdu_readf(&fake_pdu, proto_version, "S", st); if (ret) { P9_DPRINTK(P9_DEBUG_9P, "<<< p9stat_read failed: %d\n", ret); - p9pdu_dump(1, &fake_pdu); + P9_DUMP_PKT(0, &fake_pdu); } return ret; @@ -632,11 +626,7 @@ int p9pdu_finalize(struct p9_fcall *pdu) err = p9pdu_writef(pdu, 0, "d", size); pdu->size = size; -#ifdef CONFIG_NET_9P_DEBUG - if ((p9_debug_level & P9_DEBUG_PKT) == P9_DEBUG_PKT) - p9pdu_dump(0, pdu); -#endif - + P9_DUMP_PKT(0, pdu); P9_DPRINTK(P9_DEBUG_9P, ">>> size=%d type: %d tag: %d\n", pdu->size, pdu->id, pdu->tag); @@ -669,7 +659,7 @@ int p9dirent_read(char *buf, int len, struct p9_dirent *dirent, &dirent->d_off, &dirent->d_type, &nameptr); if (ret) { P9_DPRINTK(P9_DEBUG_9P, "<<< p9dirent_read failed: %d\n", ret); - p9pdu_dump(1, &fake_pdu); + P9_DUMP_PKT(1, &fake_pdu); goto out; }