From patchwork Thu Dec 4 18:39:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 5439761 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 B0B69BEEA8 for ; Thu, 4 Dec 2014 18:39:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C658720272 for ; Thu, 4 Dec 2014 18:39:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ECFB82025A for ; Thu, 4 Dec 2014 18:39:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932950AbaLDSjy (ORCPT ); Thu, 4 Dec 2014 13:39:54 -0500 Received: from mail-wg0-f52.google.com ([74.125.82.52]:56000 "EHLO mail-wg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932215AbaLDSju (ORCPT ); Thu, 4 Dec 2014 13:39:50 -0500 Received: by mail-wg0-f52.google.com with SMTP id a1so23362025wgh.11 for ; Thu, 04 Dec 2014 10:39:49 -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=1JtEQUD/1HHzXUDRmhAfWAVvhKsEoUV/GpAHySQ3q+4=; b=AVmyTifPWRPu5v4PtrOKHnI9O79kVw4bNJbOgjf+pjzhIZTQLf2ryk+j9I6W5uP6cQ xlGBj28ashWoA9gj49/vbt9D4+P+lJQOpp+aE+oR5k5OOEA/YFULNTN/LDtZ3dg6cfET /W4GsYl+vzlnf7zC60eaxYxHxEoAXUilqq+jBlbSITKcaw/z9ii6+S8Lcg/61e00SuqJ poSDc9QScCiPD3kk4X0qJnB6rxlSWUyULfgDABiSf+V2cphpJOEerp5I4kcTr5ODSBZl fEZudaP6z86uZvk7S6Hkcgu3SgfqzAdhevnfwjxxlP0ikf8SPiWSHW8Q1yTtBZYQoAVV b6tQ== X-Received: by 10.194.61.168 with SMTP id q8mr17882798wjr.53.1417718389010; Thu, 04 Dec 2014 10:39:49 -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.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Dec 2014 10:39:48 -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:39:42 +0100 Message-Id: <1417718382-6753-6-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 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 --- volumes.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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);