From patchwork Fri Mar 11 00:04:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauhen Kharuzhy X-Patchwork-Id: 8561011 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AF831C0553 for ; Fri, 11 Mar 2016 00:04:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B30A120328 for ; Fri, 11 Mar 2016 00:04:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 91F33200ED for ; Fri, 11 Mar 2016 00:04:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932930AbcCKAEt (ORCPT ); Thu, 10 Mar 2016 19:04:49 -0500 Received: from mail-pf0-f181.google.com ([209.85.192.181]:36112 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932844AbcCKAEs (ORCPT ); Thu, 10 Mar 2016 19:04:48 -0500 Received: by mail-pf0-f181.google.com with SMTP id u190so51110263pfb.3 for ; Thu, 10 Mar 2016 16:04:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=u5ZQ2IBuPXwjS3R7rm/C35PHJO32zZB9BrSqq1/hv/s=; b=FAhunsc9TtesgSGImy55J5DY9azDqemAabR0O7omxtMu+K9P2xm0G0fnsXrMRP/V83 KBjqx+TWIe30ocXd5ehc/hJkl7czIppMtGZteGsIvSiuJQpJ5lkbVH8XM3BwE2Uv1Mxw TpTpMXFIl03y4xmWMt+IMcGSW6vjV0cuX8xaIJ5VMMYYxSpJFe3MSfup+amsvVUe/iN+ r3rFGB9Mn/MMRvpgdxIUP3DPgXJRtwS3QbH2pvBeMuazK2Ii2oX+6TB3M7SPhMAeGH68 XP0Lo73ysP7z09QJoalV4kuU2CxAotx46a65xV45I+XNIRN+0PLRJxWzfoQIEvOl+YsV b01A== X-Gm-Message-State: AD7BkJKez8hh9L4CKTEbenvpDWdK7AUIhXgscoq/eoNNQ70N1Al7oL/tOBkhS4Fq7hoOng== X-Received: by 10.98.34.196 with SMTP id p65mr9000815pfj.23.1457654687641; Thu, 10 Mar 2016 16:04:47 -0800 (PST) Received: from jek-Latitude-E7440 (pat.hitachigst.com. [199.255.44.5]) by smtp.gmail.com with ESMTPSA id ux2sm8019663pac.46.2016.03.10.16.04.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Mar 2016 16:04:46 -0800 (PST) Received: from jek by jek-Latitude-E7440 with local (Exim 4.86) (envelope-from ) id 1aeAZS-0003ft-AK; Thu, 10 Mar 2016 16:04:46 -0800 From: Yauhen Kharuzhy To: linux-btrfs@vger.kernel.org Cc: Yauhen Kharuzhy Subject: [PATCH] btrfs-progs: Dont' stop scanning of devices at first failed device Date: Thu, 10 Mar 2016 16:04:35 -0800 Message-Id: <1457654675-14084-1-git-send-email-yauhen.kharuzhy@zavadatar.com> X-Mailer: git-send-email 2.5.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 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 When 'btrfs device scan' command is invoked, it scans all devices, check them for btrfs superblock and add devices with btrfs to a list. Next, each device from the list is passed to kernel where it is handled in the btrfs_scan_one_device() function. This function can, for example, return -EBUSY when device contains superblock matched to existing and mounted filesystem (if this device was pulled out from RAID and connected again after some time). btrfs tool stops device scan if any device has been failed to add, so other existing devices with (possibly) valid FS will never be reached. Fix this by remove stopping at any failure in the btrfs_register_all_devices(), just return error count. btrfs_scan_one_device() reports any kind of error already. Signed-off-by: Yauhen Kharuzhy --- cmds-device.c | 2 +- utils.c | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/cmds-device.c b/cmds-device.c index 94ffdc5..ec871d2 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -278,7 +278,7 @@ static int cmd_device_scan(int argc, char **argv) ret = btrfs_scan_lblkid(); error_on(ret, "error %d while scanning", ret); ret = btrfs_register_all_devices(); - error_on(ret, "error %d while registering devices", ret); + error_on(ret, "there are %d errors while registering devices", ret); goto out; } diff --git a/utils.c b/utils.c index eabc36d..a5dcfbe 100644 --- a/utils.c +++ b/utils.c @@ -1545,7 +1545,7 @@ int btrfs_register_one_device(const char *fname) */ int btrfs_register_all_devices(void) { - int err; + int err, ret = 0; struct btrfs_fs_devices *fs_devices; struct btrfs_device *device; struct list_head *all_uuids; @@ -1554,16 +1554,15 @@ int btrfs_register_all_devices(void) list_for_each_entry(fs_devices, all_uuids, list) { list_for_each_entry(device, &fs_devices->devices, dev_list) { - if (*device->name) { + if (*device->name) err = btrfs_register_one_device(device->name); - if (err < 0) - return err; - if (err > 0) - return -err; - } + + if (err) + ret++; } } - return 0; + + return ret; } int btrfs_device_already_in_root(struct btrfs_root *root, int fd,