From patchwork Sat Jun 13 02:07:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 6601811 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3EB209F326 for ; Sat, 13 Jun 2015 02:07:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 518612065D for ; Sat, 13 Jun 2015 02:07:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5CB442062A for ; Sat, 13 Jun 2015 02:07:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753637AbbFMCHG (ORCPT ); Fri, 12 Jun 2015 22:07:06 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]:35109 "EHLO mail-pa0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753549AbbFMCHG (ORCPT ); Fri, 12 Jun 2015 22:07:06 -0400 Received: by pabli10 with SMTP id li10so9580648pab.2 for ; Fri, 12 Jun 2015 19:07:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=xsfteCPCvIfyJ+UehGvVdiONbrN5WlPCV0Qi5mkqg8Y=; b=kw3QlZHLdnoGkPkTpRL5RADHaCi4N/BzYoLZ6oyFW8ku5f5y06t6KDjBua6xL5/NgL G95x+tuQR6Xd945zw6173LfvdRNG+R1vAzTYDi8uOP9h2BavzASx7Sg8F2j+u+t4zpl8 rhA2UUEQiGqPo2ImwmqnsrHx3Vy65//O/QDOCLN2Kd/CnP9rRsWeWdleaYrFACrHRaDZ AzJldFM/2+/+BXl9UzKZM0YTddokpP8TzJ4JpOQ7S8nuI9Agml/iZ8dIb8dZtfNlz4eR bNmOVDpu2TOeJyxFrA4RNH8YWLInvA9wqG1g8IrGgiON9HPmh4bCTRkZ1wuHKNU1xR04 mPog== X-Received: by 10.68.68.167 with SMTP id x7mr27624037pbt.161.1434161225761; Fri, 12 Jun 2015 19:07:05 -0700 (PDT) Received: from [192.168.99.13] ([104.143.41.79]) by mx.google.com with ESMTPSA id cd10sm4903111pac.7.2015.06.12.19.07.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 19:07:04 -0700 (PDT) Message-ID: <557B9044.8060105@gmail.com> Date: Sat, 13 Jun 2015 10:07:00 +0800 From: Kinglong Mee User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Trond Myklebust CC: "linux-nfs@vger.kernel.org" , David Howells , kinglongmee@gmail.com Subject: [PATCH v2] nfs: Fix showing truncated fsid/dev in, /proc/net/nfsfs/volumes References: <557AE2E7.1090908@gmail.com> In-Reply-To: Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A truncated fsid showing from /proc/fs/nfsfs/volumes as, NV SERVER PORT DEV FSID FSC v4 c0a80881 801 0:43 34931f044c2a439b no It should be as, NV SERVER PORT DEV FSID FSC v4 c0a80881 801 0:43 34931f044c2a439b:954c5d830fa4be8c no The max buffer length for storing "%llx:%llx" format should be 16 + 1 + 16 + 1 = 34 (16 for %llx, 1 for ':', 1 for '\0'). Also, for storing "%u:%u" of MAJOR() and MINOR() should be 8 + 1 + 3 + 1 = 13 (8 for 2^24, 1 for ':', 3 for 2^8, 1 for '\0'). v2, add comments for dev/fsid buffer and use sizeof in snprintf. Signed-off-by: Kinglong Mee --- fs/nfs/client.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 892aeff..1e37491 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -1364,27 +1364,29 @@ static int nfs_volume_list_show(struct seq_file *m, void *v) { struct nfs_server *server; struct nfs_client *clp; - char dev[8], fsid[17]; + char dev[13]; // 8 for 2^24, 1 for ':', 3 for 2^8, 1 for '\0' + char fsid[34]; // 2 * 16 for %llx, 1 for ':', 1 for '\0' struct nfs_net *nn = net_generic(seq_file_net(m), nfs_net_id); /* display header on line 1 */ if (v == &nn->nfs_volume_list) { - seq_puts(m, "NV SERVER PORT DEV FSID FSC\n"); + seq_puts(m, "NV SERVER PORT DEV FSID" + " FSC\n"); return 0; } /* display one transport per line on subsequent lines */ server = list_entry(v, struct nfs_server, master_link); clp = server->nfs_client; - snprintf(dev, 8, "%u:%u", + snprintf(dev, sizeof(dev), "%u:%u", MAJOR(server->s_dev), MINOR(server->s_dev)); - snprintf(fsid, 17, "%llx:%llx", + snprintf(fsid, sizeof(fsid), "%llx:%llx", (unsigned long long) server->fsid.major, (unsigned long long) server->fsid.minor); rcu_read_lock(); - seq_printf(m, "v%u %s %s %-7s %-17s %s\n", + seq_printf(m, "v%u %s %s %-12s %-33s %s\n", clp->rpc_ops->version, rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),