From patchwork Sat Aug 3 18:43:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 2838299 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 E123DBF535 for ; Sat, 3 Aug 2013 18:43:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 027512014A for ; Sat, 3 Aug 2013 18:43:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F180E20149 for ; Sat, 3 Aug 2013 18:43:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752778Ab3HCSnm (ORCPT ); Sat, 3 Aug 2013 14:43:42 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:65117 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752452Ab3HCSnl (ORCPT ); Sat, 3 Aug 2013 14:43:41 -0400 Received: by mail-wi0-f179.google.com with SMTP id hr7so400719wib.6 for ; Sat, 03 Aug 2013 11:43:39 -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:x-mailer; bh=7BtCC3U1zBa5FU77O/tTwGLqJ1DIbKTgvIiLhXhVhE4=; b=tQrwjBj9W2TwQQu4rTvKos/IM8IR5AHUsHN5tM3LLE3Zk3b9rbJbjoOXvbi7bwB+ot 6/fCb+Xgxv19wGCNEt9Q/1mP8/FbUr6w9ongQyTl7mTJGwLE2WnPzmoshmjo2TOL9+0v tpQujX/9Rz6AkjD/HvGKRrX9ka0/3XgS8M3isOzrK98BRX0bK16zl5bYGVFNKVR1v+Bu 0V8E08qddyv96M/UrvHUkA7DA3vP8VZITKk4ZLaoTEpk30tcJx+iQdxQCHhSXTA8rYFs zuXDl1su1MvjnZkw5/nk6K8dHQV1U7SnR8Dx+I5Rjrl4m48Xig0hrYZg4xBZpSaK6ZhX nilA== X-Received: by 10.194.121.65 with SMTP id li1mr8895318wjb.24.1375555419723; Sat, 03 Aug 2013 11:43:39 -0700 (PDT) Received: from storm-desktop.lan (bl5-78-32.dsl.telepac.pt. [82.154.78.32]) by mx.google.com with ESMTPSA id nb12sm10971657wic.3.2013.08.03.11.43.37 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 03 Aug 2013 11:43:39 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH] Btrfs: race free update of super flags Date: Sat, 3 Aug 2013 19:43:17 +0100 Message-Id: <1375555397-10886-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.9.5 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.2 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 Before updating the super block's flags, which is a non-atomic operation, grab the super_lock in the fs_info structure. At the moment only 2 different code paths can update these flags in parallel: 1) when adding a new device 2) writing all super block copies to disk Signed-off-by: Filipe David Borba Manana --- fs/btrfs/ctree.h | 4 ++-- fs/btrfs/disk-io.c | 2 ++ fs/btrfs/volumes.c | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index cbb1263..fd47c02 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1375,8 +1375,8 @@ struct btrfs_fs_info { wait_queue_head_t async_submit_wait; /* - * Used to protect the incompat_flags, compat_flags, compat_ro_flags - * when they are updated. + * Used to protect the incompat_flags, compat_flags, compat_ro_flags, + * flags and label when they are updated. * * Because we do not clear the flags for ever, so we needn't use * the lock on the read side. diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index b71e882..3900c36 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3357,8 +3357,10 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors) memcpy(dev_item->uuid, dev->uuid, BTRFS_UUID_SIZE); memcpy(dev_item->fsid, dev->fs_devices->fsid, BTRFS_UUID_SIZE); + spin_lock(&root->fs_info->super_lock); flags = btrfs_super_flags(sb); btrfs_set_super_flags(sb, flags | BTRFS_HEADER_FLAG_WRITTEN); + spin_unlock(&root->fs_info->super_lock); ret = write_dev_supers(dev, sb, do_barriers, 0, max_mirrors); if (ret) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 090f57c..8c67bd7 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1862,9 +1862,11 @@ static int btrfs_prepare_sprout(struct btrfs_root *root) generate_random_uuid(fs_devices->fsid); memcpy(root->fs_info->fsid, fs_devices->fsid, BTRFS_FSID_SIZE); memcpy(disk_super->fsid, fs_devices->fsid, BTRFS_FSID_SIZE); + spin_lock(&root->fs_info->super_lock); super_flags = btrfs_super_flags(disk_super) & ~BTRFS_SUPER_FLAG_SEEDING; btrfs_set_super_flags(disk_super, super_flags); + spin_unlock(&root->fs_info->super_lock); return 0; }