From patchwork Thu Oct 10 17:37:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 3017721 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 4DD5CBF924 for ; Thu, 10 Oct 2013 17:38:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A8CCB202FF for ; Thu, 10 Oct 2013 17:38:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EDCC7202BE for ; Thu, 10 Oct 2013 17:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756203Ab3JJRiE (ORCPT ); Thu, 10 Oct 2013 13:38:04 -0400 Received: from mail-ee0-f51.google.com ([74.125.83.51]:38041 "EHLO mail-ee0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755583Ab3JJRiA (ORCPT ); Thu, 10 Oct 2013 13:38:00 -0400 Received: by mail-ee0-f51.google.com with SMTP id c1so1329436eek.10 for ; Thu, 10 Oct 2013 10:37:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=/TOKkzC9nu+AfL0PKia5EYI3wDtrcvnV1/7iyftl5h4=; b=umipOALihJ7aXLC860XRafClcrJKlvo7jVHn9EYeWMk5Q69WcszLbf5JGFri73wpKF ou/e/SHJbW7uPJVu2nd5CxWNJaY1c4uXb8aERujwWW8whyaFjv11rsUa6eQu3OeZyirL H5ItXnyImrUHZogXdAnWyNop/+UiXQCv5nvUe0Afd2gaatZgGhfl2W6Cn6+FKFE9VatQ X98z+P6Q20bmqTXyr5VmOHGASQmRG0Z+SUdHdhj7CKT+pu4JyH561w1XVK/JtwW/teyc L6iyyv5v9Ie3dqQUXAswU/UNyFu+rRXIi/JofffsPI+aJODe5dCQChfOVJvdOORpc2fm UWWQ== X-Received: by 10.15.101.137 with SMTP id bp9mr3919169eeb.53.1381426679942; Thu, 10 Oct 2013 10:37:59 -0700 (PDT) Received: from localhost ([109.110.75.198]) by mx.google.com with ESMTPSA id b45sm104055421eef.4.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 10 Oct 2013 10:37:59 -0700 (PDT) From: Ilya Dryomov To: linux-btrfs@vger.kernel.org Cc: Chris Mason , Stefan Behrens , idryomov@gmail.com Subject: [PATCH] Btrfs: nuke a bogus rw_devices decrement in __btrfs_close_devices Date: Thu, 10 Oct 2013 20:37:29 +0300 Message-Id: <1381426649-31789-1-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 1.7.10.4 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.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 On mount failures, __btrfs_close_devices can be called well before dev-replace state is read and ->is_tgtdev_for_dev_replace is set. This leads to a bogus decrement of ->rw_devices and sets off a WARN_ON in __btrfs_close_devices if replace target device happens to be on the lists and we fail early in the mount sequence. Fix this by checking the devid instead of ->is_tgtdev_for_dev_replace before the decrement: for replace targets devid is always equal to BTRFS_DEV_REPLACE_DEVID. Cc: Stefan Behrens Signed-off-by: Ilya Dryomov --- fs/btrfs/volumes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 043b215..a306db9 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -666,7 +666,8 @@ static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices) if (device->bdev) fs_devices->open_devices--; - if (device->writeable && !device->is_tgtdev_for_dev_replace) { + if (device->writeable && + device->devid != BTRFS_DEV_REPLACE_DEVID) { list_del_init(&device->dev_alloc_list); fs_devices->rw_devices--; }