From patchwork Thu Apr 30 09:07:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xuw2015@gmail.com X-Patchwork-Id: 6300781 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3EF049F859 for ; Thu, 30 Apr 2015 09:07:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7F94C2013A for ; Thu, 30 Apr 2015 09:07:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 877C6201C0 for ; Thu, 30 Apr 2015 09:07:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751175AbbD3JHj (ORCPT ); Thu, 30 Apr 2015 05:07:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41815 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751145AbbD3JHg (ORCPT ); Thu, 30 Apr 2015 05:07:36 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 465E2CC098; Thu, 30 Apr 2015 09:07:36 +0000 (UTC) Received: from localhost (dhcp-12-175.nay.redhat.com [10.66.12.175]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3U97Yj6014332; Thu, 30 Apr 2015 05:07:35 -0400 From: xuw2015@gmail.com To: linux-btrfs@vger.kernel.org Cc: George Wang Subject: [PATCH 3/3] btrfs: do not allow device path updated by the stale one Date: Thu, 30 Apr 2015 17:07:25 +0800 Message-Id: <1430384845-9666-3-git-send-email-xuw2015@gmail.com> In-Reply-To: <1430384845-9666-1-git-send-email-xuw2015@gmail.com> References: <1430384845-9666-1-git-send-email-xuw2015@gmail.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 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, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_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 From: George Wang Use the btrfs_device->generation to identify which device(with same devid and dev_uuid) is newer, and never allow the path updated by the stale one. The btrfs_device->generation is corresponded with transaction id, which is increased from old to new. Whether the fs_devices opened or not, stale device can never get effective. Signed-off-by: George Wang --- fs/btrfs/disk-io.c | 3 +++ fs/btrfs/volumes.c | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 342d4fc..25faa53 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3508,6 +3508,9 @@ static int write_all_supers(struct btrfs_root *root, int max_mirrors) if (!dev->in_fs_metadata || !dev->writeable) continue; + /* update device generation according to disk super */ + dev->generation = sb->generation; + btrfs_set_stack_device_generation(dev_item, 0); btrfs_set_stack_device_type(dev_item, dev->type); btrfs_set_stack_device_id(dev_item, dev->devid); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index c8ece13..de6968d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -525,10 +525,9 @@ static noinline int device_list_add(const char *path, * tracking a problem where systems fail mount by subvolume id * when we reject replacement on a mounted FS. */ - if (!fs_devices->opened && found_transid < device->generation) { + if (found_transid < device->generation) { /* - * That is if the FS is _not_ mounted and if you - * are here, that means there is more than one + * If you are here, that means there is more than one * disk with same uuid and devid.We keep the one * with larger generation number or the last-in if * generation are equal.