From patchwork Mon Aug 12 11:33:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 2843045 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 F292FBF546 for ; Mon, 12 Aug 2013 11:33:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3B0492035D for ; Mon, 12 Aug 2013 11:33:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 753A52035F for ; Mon, 12 Aug 2013 11:33:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755478Ab3HLLdb (ORCPT ); Mon, 12 Aug 2013 07:33:31 -0400 Received: from mail-la0-f49.google.com ([209.85.215.49]:44886 "EHLO mail-la0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755936Ab3HLLd2 (ORCPT ); Mon, 12 Aug 2013 07:33:28 -0400 Received: by mail-la0-f49.google.com with SMTP id ev20so4588447lab.36 for ; Mon, 12 Aug 2013 04:33:27 -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:in-reply-to:references; bh=Kajx8IQjO8waB/mnWUFc0WUyjMxIlHBQ/2O7JUv6ipc=; b=N8kG3x+1nzUKFEyLDcvYm6N4voMeLdx4AkJVrKLF4atnnHgU1HBIyHJWeF+U6PPuQV y5gh1qVVNCHN/L8kyZ/p5rwko0HI+4xWrsIZDLcsGNHz6GCgmCyUs59ZQZDRwAzDjUCP 0NnqVr/RJRyhe1LDC6lqVBrYRWL1hZ4/KbhbhEIJTdea/x/+H2qvxhQMYTlO7KHOeJ2o dtWC7yKmQvfK/8TcrsigWi+Nzt/9nwN6ykzUzqj91CHiG92yJkZSSAwBN4fsVLbgqiT4 lWlLY6GdB3iZjVxKcQ0Un0zJcqfId1gUeVLZgePk13NkJoi4li7UUaAKpI1Iqrzy3YeD KoGg== X-Received: by 10.112.160.97 with SMTP id xj1mr5202395lbb.35.1376307206975; Mon, 12 Aug 2013 04:33:26 -0700 (PDT) Received: from localhost ([109.110.78.166]) by mx.google.com with ESMTPSA id db5sm11699932lac.10.2013.08.12.04.33.26 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 12 Aug 2013 04:33:26 -0700 (PDT) From: Ilya Dryomov To: linux-btrfs@vger.kernel.org Cc: Chris Mason , idryomov@gmail.com Subject: [PATCH 4/4] Btrfs: rollback btrfs_device fields on umount Date: Mon, 12 Aug 2013 14:33:04 +0300 Message-Id: <1376307184-7175-5-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1376307184-7175-1-git-send-email-idryomov@gmail.com> References: <1376307184-7175-1-git-send-email-idryomov@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-9.6 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 It turns out we don't properly rollback in-core btrfs_device state on umount. We zero out ->bdev, ->in_fs_metadata and that's about it. In particular, we don't zero out ->generation, and this can lead to us refusing a mount -- a non-NULL fs_devices->latest_bdev is essential, but btrfs_close_extra_devices will happily assign NULL to ->latest_bdev if the first device on the dev_list happens to be missing and consequently has no bdev attached. This happens because since commit a6b0d5c8 btrfs_close_extra_devices adjusts ->latest_bdev, and in doing that, relies on the ->generation. Fix this, and possibly other problems, by zeroing out everything except for what device_list_add sets, so that a mount right after insmod and 'btrfs dev scan' is no different from any later mount in this respect. Signed-off-by: Ilya Dryomov --- fs/btrfs/volumes.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index af17b17..2f6bc12 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -673,22 +673,19 @@ static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices) if (device->can_discard) fs_devices->num_can_discard--; - new_device = kmalloc(sizeof(*new_device), GFP_NOFS); - BUG_ON(!new_device); /* -ENOMEM */ - memcpy(new_device, device, sizeof(*new_device)); + new_device = btrfs_alloc_device(NULL, &device->devid, + device->uuid); + BUG_ON(IS_ERR(new_device)); /* -ENOMEM */ /* Safe because we are under uuid_mutex */ if (device->name) { name = rcu_string_strdup(device->name->str, GFP_NOFS); - BUG_ON(device->name && !name); /* -ENOMEM */ + BUG_ON(!name); /* -ENOMEM */ rcu_assign_pointer(new_device->name, name); } - new_device->bdev = NULL; - new_device->writeable = 0; - new_device->in_fs_metadata = 0; - new_device->can_discard = 0; - spin_lock_init(&new_device->io_lock); + list_replace_rcu(&device->dev_list, &new_device->dev_list); + new_device->fs_devices = device->fs_devices; call_rcu(&device->rcu, free_device); }