From patchwork Thu Dec 4 18:24:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 5439691 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 EFEDF9F1D4 for ; Thu, 4 Dec 2014 18:24:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 13E752024D for ; Thu, 4 Dec 2014 18:24:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2973820225 for ; Thu, 4 Dec 2014 18:24:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932845AbaLDSYv (ORCPT ); Thu, 4 Dec 2014 13:24:51 -0500 Received: from mail-wi0-f170.google.com ([209.85.212.170]:41789 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932723AbaLDSYq (ORCPT ); Thu, 4 Dec 2014 13:24:46 -0500 Received: by mail-wi0-f170.google.com with SMTP id bs8so36954258wib.1 for ; Thu, 04 Dec 2014 10:24:45 -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=VSOhx17zfp2GdsnjQgFnO+4y6XPthWRgUnILg0SuDIU=; b=pPDW04wPTXdNMeUf6H4nUJrS78oAyM/NHEAfB7q1L/oVTJA/734TrbrBW8zHeUpmE4 UgVXJl/aBa5+ynCtiRf9VUSByTDXUx2F0Z9XFb45tmxi111bMk8B1crBrnBxssb/cMsI 6A8AUxbOyvybgapP2+HkA/bdL38KEXzJ4uS/XFtaE8zhEGXPbmGoUIfKSJ7Dl7HVIUKN 9RPtPL3b7kx0BfQfF7XShhgZAlXXZNzDXqHVlCSSgjgrpUCbRrjN6NHid/5kFbIG0HCf QKBqoMAYLwN0l+L5TiGpBYZgRir0b1cEgCyylRNLBkA3kx9qWmUTuT31VScsS9iDqBBB 7ESg== X-Received: by 10.180.98.138 with SMTP id ei10mr26543941wib.32.1417717484910; Thu, 04 Dec 2014 10:24:44 -0800 (PST) Received: from venice.bhome (ppp-252-95.24-151.libero.it. [151.24.95.252]) by mx.google.com with ESMTPSA id wa5sm15767794wjc.8.2014.12.04.10.24.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Dec 2014 10:24:44 -0800 (PST) From: Goffredo Baroncelli X-Google-Original-From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Goffredo Baroncelli Subject: [PATCH 5/5] Abort in case of device uuid conflict. Date: Thu, 4 Dec 2014 19:24:30 +0100 Message-Id: <1417717470-6298-6-git-send-email-kreijack@inwind.it> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1417717470-6298-1-git-send-email-kreijack@inwind.it> References: <1417717470-6298-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 Add a check to ensure that the all devices have differents device uuid. In case of conflict the program ends. Pay attention that it is still possible to insert two device with the same dev uuid via the "btrfs device scan " command. Signed-off-by: Goffredo Baroncelli --- cmds-device.c | 4 ++-- volumes.c | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cmds-device.c b/cmds-device.c index 580879c..f6c76e7 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -229,6 +229,7 @@ static int cmd_scan_dev(int argc, char **argv) break; case 's': skip_snapshot = 0; + devstart++; break; default: usage(cmd_scan_dev_usage); @@ -238,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) @@ -266,7 +267,6 @@ 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]); diff --git a/volumes.c b/volumes.c index 5b007fc..6ff4b4a 100644 --- a/volumes.c +++ b/volumes.c @@ -17,6 +17,7 @@ */ #define _XOPEN_SOURCE 600 #define __USE_XOPEN2K +#define _BSD_SOURCE /* for minor/major macro */ #include #include #include @@ -139,7 +140,31 @@ static int device_list_add(const char *path, list_add(&device->dev_list, &fs_devices->devices); device->fs_devices = fs_devices; } else if (!device->name || strcmp(device->name, path)) { - char *name = strdup(path); + char *name; + struct stat statbuf1; + + /* + * check if the old device and the new device are differents + * if so abort because we can't say which one is the right one + */ + if (device->name && !stat(device->name, &statbuf1)) { + struct stat statbuf2; + + if (stat(path, &statbuf2)) + return -ENOENT; + + if (major(statbuf1.st_rdev) != major(statbuf2.st_rdev) || + minor(statbuf1.st_rdev) != minor(statbuf2.st_rdev)) { + fprintf(stderr, "ERROR: two devices (%s and %s) have the same dev uuid !!\n", + device->name, path); + fprintf(stderr, "ERROR: remove one of the device and retry\n"); + fprintf(stderr, "ERROR: the program will abort now\n"); + + exit(100); + } + } + + name = strdup(path); if (!name) return -ENOMEM; kfree(device->name);