From patchwork Thu Dec 4 18:39:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 5439741 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 AE671BEEA8 for ; Thu, 4 Dec 2014 18:39:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C32842025A for ; Thu, 4 Dec 2014 18:39:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B70B220328 for ; Thu, 4 Dec 2014 18:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932898AbaLDSjt (ORCPT ); Thu, 4 Dec 2014 13:39:49 -0500 Received: from mail-wg0-f53.google.com ([74.125.82.53]:48328 "EHLO mail-wg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932215AbaLDSjr (ORCPT ); Thu, 4 Dec 2014 13:39:47 -0500 Received: by mail-wg0-f53.google.com with SMTP id l18so23103859wgh.26 for ; Thu, 04 Dec 2014 10:39:46 -0800 (PST) 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=YtDovDhTARABRnvucXBrlNlqFC/PKKXjj+dwYkKHT94=; b=F6FjbP1ew7SHItb/1B4iqqlIG3WJTXJBpEsgrba/txBG455G0VbFUF7nCoKyUE62/n 4rCNvLs8xfv67y7FHnVmMj9UXWEXQ+/kjhpPhnAvhuHiRAAFBz0JZ72ADV9cKXbXmOvY 263/L18vd0jKgKYdIS3WbQpD3nYDXHa6taHBpxAQwQ6/aw0OTo03WoL+s2ZyOkdzP+pG IrzgJmeu18L6C/DjcIlPQ7apXUWJ5BrD8V9nJ0rcBUo9Fui1hom3v4YDcjctD4Zc73ov s+eUJL9/hfEjALCgvRUiuRjIDANFfjb3ga/jV7qY5vUbUl/tHGRU4M/N4TtCU/+s5qYy PDYQ== X-Received: by 10.194.80.193 with SMTP id t1mr4252983wjx.8.1417718386715; Thu, 04 Dec 2014 10:39:46 -0800 (PST) Received: from venice.bhome (ppp-252-95.24-151.libero.it. [151.24.95.252]) by mx.google.com with ESMTPSA id r10sm56037194wiy.13.2014.12.04.10.39.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Dec 2014 10:39:46 -0800 (PST) From: Goffredo Baroncelli X-Google-Original-From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Goffredo Baroncelli Subject: [PATCH 2/5] 'btrfs device scan' skips lvm snapshots. Date: Thu, 4 Dec 2014 19:39:39 +0100 Message-Id: <1417718382-6753-3-git-send-email-kreijack@inwind.it> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1417718382-6753-1-git-send-email-kreijack@inwind.it> References: <1417718382-6753-1-git-send-email-kreijack@inwind.it> 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.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_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 LVM snapshots create a problem to the btrfs devices management. BTRFS assumes that each device has an unique 'device UUID'. A LVM snapshot breaks this assumption. With this patch, 'btrfs device scan' skips LVM snapshot. If you need to consider a LVM snapshot you have to pass the '-s' switch ot set the environment variable BTRFS_SKIP_LVM_SNAPSHOT to "no". Signed-off-by: Goffredo Baroncelli --- cmds-device.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cmds-device.c b/cmds-device.c index 6cd41e1..f6c76e7 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -197,9 +197,10 @@ static int cmd_rm_dev(int argc, char **argv) } static const char * const cmd_scan_dev_usage[] = { - "btrfs device scan [(-d|--all-devices)| [...]]", + "btrfs device scan [-s][(-d|--all-devices)| [...]]", "Scan devices for a btrfs filesystem", " -d|--all-devices (deprecated)", + " -s don't skip lvm snapshot\n", NULL }; @@ -209,6 +210,7 @@ static int cmd_scan_dev(int argc, char **argv) int devstart = 1; int all = 0; int ret = 0; + int skip_snapshot = btrfs_scan_get_skip_lvm_snapshot(); optind = 1; while (1) { @@ -217,7 +219,7 @@ static int cmd_scan_dev(int argc, char **argv) { "all-devices", no_argument, NULL, 'd'}, { 0, 0, 0, 0 }, }; - int c = getopt_long(argc, argv, "d", long_options, + int c = getopt_long(argc, argv, "sd", long_options, &long_index); if (c < 0) break; @@ -225,6 +227,10 @@ static int cmd_scan_dev(int argc, char **argv) case 'd': all = 1; break; + case 's': + skip_snapshot = 0; + devstart++; + break; default: usage(cmd_scan_dev_usage); } @@ -233,7 +239,7 @@ static int cmd_scan_dev(int argc, char **argv) if (all && check_argc_max(argc, 2)) usage(cmd_scan_dev_usage); - if (all || argc == 1) { + if (all || argc == devstart) { printf("Scanning for Btrfs filesystems\n"); ret = btrfs_scan_lblkid(); if (ret) @@ -261,6 +267,11 @@ static int cmd_scan_dev(int argc, char **argv) ret = 1; goto out; } + if (skip_snapshot && is_low_priority_device(path)) { + fprintf(stderr, "WARNING: skip device '%s' because it is a snapshot\n", + argv[i]); + continue; + } printf("Scanning for Btrfs filesystems in '%s'\n", path); if (btrfs_register_one_device(path) != 0) { ret = 1;