From patchwork Tue Jun 10 08:53:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 4327131 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D7DED9F314 for ; Tue, 10 Jun 2014 08:52:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 119B72028D for ; Tue, 10 Jun 2014 08:52:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EB2EB20176 for ; Tue, 10 Jun 2014 08:52:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751566AbaFJIwH (ORCPT ); Tue, 10 Jun 2014 04:52:07 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:7418 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750937AbaFJIwG (ORCPT ); Tue, 10 Jun 2014 04:52:06 -0400 X-IronPort-AV: E=Sophos;i="4.98,1007,1392134400"; d="scan'208";a="31700726" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 10 Jun 2014 16:49:26 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s5A8q3pd018171; Tue, 10 Jun 2014 16:52:03 +0800 Received: from adam-work.lan (10.167.226.24) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 10 Jun 2014 16:52:07 +0800 From: Qu Wenruo To: CC: Anand Jain Subject: [PATCH] btrfs: When devices with same dev uuid occurs, only add the one with largest generation. Date: Tue, 10 Jun 2014 16:53:07 +0800 Message-ID: <1402390387-28730-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.0.0 MIME-Version: 1.0 X-Originating-IP: [10.167.226.24] 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.5 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 Since btrfs currently use dulicated dev uuid when doing device replace, the following problem will happen: 1) mount with device A missing using degraded mode. 2) replace device A with device B. 3) device A reappears. 4) umount btrfs fs. 5) mount btrfs fs. After step 5), btrfs will still use device A even device B has a larger generation. The patch will judge generation when difference device with same dev uuid. And the patch should be applied after Anand's patch: https://patchwork.kernel.org/patch/4309651/ Cc: Anand Jain Signed-off-by: Qu Wenruo --- 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 0a5017a..07f0cf7 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -508,7 +508,8 @@ static noinline int device_list_add(const char *path, ret = 1; device->fs_devices = fs_devices; - } else if (!device->name || strcmp(device->name->str, path)) { + } else if (!device->name || (strcmp(device->name->str, path) && + found_transid > device->generation)) { /* * When FS is already mounted. * 1. If you are here and if the device->name is NULL that means