From patchwork Thu Apr 10 07:30:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 3960191 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 BB3F09F336 for ; Thu, 10 Apr 2014 07:29:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F29B220630 for ; Thu, 10 Apr 2014 07:29:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DDBD920629 for ; Thu, 10 Apr 2014 07:29:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751159AbaDJH3V (ORCPT ); Thu, 10 Apr 2014 03:29:21 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:4184 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750763AbaDJH3U (ORCPT ); Thu, 10 Apr 2014 03:29:20 -0400 X-IronPort-AV: E=Sophos;i="4.97,832,1389715200"; d="scan'208";a="29086278" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 10 Apr 2014 15:26:50 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s3A7TFBB010815 for ; Thu, 10 Apr 2014 15:29:15 +0800 Received: from adam-work.lan (10.167.226.24) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.146.2; Thu, 10 Apr 2014 15:29:15 +0800 From: Qu Wenruo To: Subject: [PATCH] btrfs-progs: Force 'btrfs dev scan' not using old libblkid cache Date: Thu, 10 Apr 2014 15:30:21 +0800 Message-ID: <1397115021-30426-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 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 'btrfs scan' uses libblkid to scan devices by default, and libblkid uses cache to reduce the probe. But if operations below is done in less than 2 seconds(BLKID_PROBE_MIN), 'btrfs scan' will still use the uncorrect cache and scan on the deleted device. 0. /dev/sda[1-4] mounted on /mnt using single data/metadata 1. btrfs dev scan 2. btrfs dev del /dev/sda3 /mnt 3. btrfs dev scan Since the cache made by step 1 is still validated, step 3 will use the cache and consider /dev/sda3 as a btrfs filesystem and try to scan it. But the superblock(at least the first one) is wiped and failed to scan, a error message, which can be avoided and is unneeded, is output. This patch will force scan_for_btrfs() not to use cache to avoid the problem. Reported-by: Tsutomu Itoh Singed-off-by: Qu Wenruo --- utils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils.c b/utils.c index 0bfb9d9..1cd1d28 100644 --- a/utils.c +++ b/utils.c @@ -2057,7 +2057,8 @@ int btrfs_scan_lblkid(int update_kernel) blkid_cache cache = NULL; char path[PATH_MAX]; - if (blkid_get_cache(&cache, 0) < 0) { + /* No to use libblkid cache to avoid old data */ + if (blkid_get_cache(&cache, "/dev/null") < 0) { printf("ERROR: lblkid cache get failed\n"); return 1; }