From patchwork Thu Oct 23 01:56:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 5137631 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CA1739F30B for ; Thu, 23 Oct 2014 01:57:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D4D9A20251 for ; Thu, 23 Oct 2014 01:57:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C0EB320221 for ; Thu, 23 Oct 2014 01:57:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753710AbaJWB5a (ORCPT ); Wed, 22 Oct 2014 21:57:30 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:10871 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753250AbaJWB53 (ORCPT ); Wed, 22 Oct 2014 21:57:29 -0400 X-IronPort-AV: E=Sophos;i="5.04,772,1406563200"; d="scan'208";a="37780999" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Oct 2014 09:54:21 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s9N1vNNu024478 for ; Thu, 23 Oct 2014 09:57:23 +0800 Received: from localhost.localdomain (10.167.226.111) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 23 Oct 2014 09:57:38 +0800 From: Gui Hecheng To: CC: Gui Hecheng Subject: [PATCH] btrfs-progs: fix dev stats error output related to replace handle Date: Thu, 23 Oct 2014 09:56:11 +0800 Message-ID: <1414029371-6765-1-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 MIME-Version: 1.0 X-Originating-IP: [10.167.226.111] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Steps to reproduce: # mkfs.btrfs -f /dev/sdb7 # mount /dev/sdb7 /mnt # btrfs dev stats /dev/sdb7 output: [/dev/sdb7].write_io_errs 0 [/dev/sdb7].read_io_errs 0 [/dev/sdb7].flush_io_errs 0 [/dev/sdb7].corruption_errs 0 [/dev/sdb7].generation_errs 0 * ERROR: ioctl(BTRFS_IOC_GET_DEV_STATS) on failed: No such device while the following cmd: # btrfs dev stats /mnt yields the right thing: [/dev/sdb7].write_io_errs 0 [/dev/sdb7].read_io_errs 0 [/dev/sdb7].flush_io_errs 0 [/dev/sdb7].corruption_errs 0 [/dev/sdb7].generation_errs 0 This is caused by commit: commit d0588bfa479409b2a0f6243f894338a01a56221a btrfs-progs: do a separate probe for transient replacing device The above commit trys to handle the fi show problem with device under replacing, but it changes the @get_fs_info() logic which annoys dev stats. For @get_fs_info(): o If the passed in @path is a mount point, then the @get_device_info() to probe the replacing device will be glad to accept the device index var @i as its init value 0 and the following i++ correctly sets @i to 1 as the start of all devices in btrfs. o If @path is a block device, then the problem comes... The device index @i is set to devid of the block device passed in, and the @get_device_info() will be forced to accept the devid unwillingly. Then the following i++ do the evil of skip the block device desired and an empty piece is handled next which causes the ERROR above. To fix this problem, let's just pass 0 to the @get_device_info() explicitly, and set the index @i to 1 if a mount point is passed in. Under my own test, this will not affect the original fix of the fi show problem with device under replacing. Signed-off-by: Gui Hecheng --- utils.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/utils.c b/utils.c index f10c178..0ba2b26 100644 --- a/utils.c +++ b/utils.c @@ -1881,12 +1881,15 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args, } /* get the replace target device if it is there */ - ret = get_device_info(fd, i, &di_args[ndevs]); + ret = get_device_info(fd, 0, &di_args[ndevs]); if (!ret) { ndevs++; fi_args->num_devices++; } - i++; + + /* if a mount point is passed in, start from devid 1 */ + if (fi_args->num_devices != 1) + i = 1; for (; i <= fi_args->max_id; ++i) { BUG_ON(ndevs >= fi_args->num_devices);