From patchwork Mon Aug 18 08:38:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 4733281 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9D3BDC0338 for ; Mon, 18 Aug 2014 08:36:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DADDF2011E for ; Mon, 18 Aug 2014 08:36:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F31BE20108 for ; Mon, 18 Aug 2014 08:36:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751710AbaHRIfm (ORCPT ); Mon, 18 Aug 2014 04:35:42 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:22518 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752526AbaHRIe6 (ORCPT ); Mon, 18 Aug 2014 04:34:58 -0400 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s7I8YrAs025665 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 18 Aug 2014 08:34:53 GMT Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by ucsinet22.oracle.com (8.14.5+Sun/8.14.5) with ESMTP id s7I8YqH4015637 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 18 Aug 2014 08:34:52 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userz7022.oracle.com (8.14.5+Sun/8.14.4) with ESMTP id s7I8YpvR015602; Mon, 18 Aug 2014 08:34:52 GMT Received: from OL.sg.oracle.com (/10.186.101.34) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 18 Aug 2014 01:34:51 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: lists@colorremedies.com Subject: [PATCH v2] btrfs-progs: do a separate probe for transient replacing device Date: Mon, 18 Aug 2014 16:38:19 +0800 Message-Id: <1408351099-4721-3-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 2.0.0.153.g79dcccc In-Reply-To: <1408351099-4721-1-git-send-email-anand.jain@oracle.com> References: <1408158488-4316-1-git-send-email-anand.jain@oracle.com> <1408351099-4721-1-git-send-email-anand.jain@oracle.com> X-Source-IP: ucsinet22.oracle.com [156.151.31.94] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 As mentioned in the kernel patch btrfs: ioctl BTRFS_IOC_FS_INFO and BTRFS_IOC_DEV_INFO miss-matched with slots The count as returned by BTRFS_IOC_FS_INFO is the number of slots that btrfs-progs would allocate for the BTRFS_IOC_DEV_INFO ioctl. Since BTRFS_IOC_DEV_INFO would loop across the seed devices, So its better ioctl BTRFS_IOC_FS_INFO returns the total_devices instead of num_devices. The above mentioned patch just does that. That is, it returns total_devices instead of num_devices. Which means we need to probe for the replacing device separately. This patch will probe for the replacing device separately. Signed-off-by: Anand Jain --- v2: commit update utils.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/utils.c b/utils.c index 8bdc2a7..fa837b9 100644 --- a/utils.c +++ b/utils.c @@ -1929,12 +1929,29 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args, if (!fi_args->num_devices) goto out; - di_args = *di_ret = malloc(fi_args->num_devices * sizeof(*di_args)); + /* + * with kernel patch + * btrfs: ioctl BTRFS_IOC_FS_INFO and BTRFS_IOC_DEV_INFO miss-matched with slots + * the kernel now returns total_devices which does not include + * replacing device if running. + * As we need to get dev info of the replace device if it is running, + * so just add one to fi_args->num_devices. + */ + + di_args = *di_ret = malloc((fi_args->num_devices + 1) * sizeof(*di_args)); if (!di_args) { ret = -errno; goto out; } + /* get the replace target device if it is there */ + ret = get_device_info(fd, i, &di_args[ndevs]); + if (!ret) { + ndevs++; + fi_args->num_devices++; + } + i++; + for (; i <= fi_args->max_id; ++i) { BUG_ON(ndevs >= fi_args->num_devices); ret = get_device_info(fd, i, &di_args[ndevs]);