From patchwork Thu Oct 7 03:26:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Su X-Patchwork-Id: 1537518 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=wistron.com header.i=@wistron.com header.a=rsa-sha256 header.s=security header.b=X4Yhp9rE; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HPxZ76Q4yz9sXS for ; Thu, 7 Oct 2021 14:26:38 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HPxZ54Lr4z2ynr for ; Thu, 7 Oct 2021 14:26:37 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=wistron.com header.i=@wistron.com header.a=rsa-sha256 header.s=security header.b=X4Yhp9rE; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=wistron.com (client-ip=103.200.3.19; helo=segapp03.wistron.com; envelope-from=lulu_su@wistron.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=wistron.com header.i=@wistron.com header.a=rsa-sha256 header.s=security header.b=X4Yhp9rE; dkim-atps=neutral Received: from segapp03.wistron.com (segapp02.wistron.com [103.200.3.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4HPxYz5r5gz2yXW for ; Thu, 7 Oct 2021 14:26:30 +1100 (AEDT) Received: from EXCHAPP01.whq.wistron (unknown [10.37.38.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by segapp03.wistron.com (MTA) with ESMTPS id 4HPxYw0KDwz51KWj; Thu, 7 Oct 2021 11:26:28 +0800 (CST) Received: from EXCHAPP02.whq.wistron (10.37.38.25) by EXCHAPP01.whq.wistron (10.37.38.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Thu, 7 Oct 2021 11:26:26 +0800 Received: from gitserver.wistron.com (10.37.38.233) by EXCHAPP02.whq.wistron (10.37.38.25) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Thu, 7 Oct 2021 11:26:26 +0800 From: Lulu Su To: Subject: [PATCH] discover/udev.c: Added warning in system status log Date: Thu, 7 Oct 2021 11:26:24 +0800 Message-ID: <20211007032624.25842-1-Lulu_Su@wistron.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-TM-SNTS-SMTP: 7D9A24518991B8AEA417EEA71DA82B3A5701A5A084C0D0F57FA602C5BDB44FD32000:8 x-msw-jemd-newsletter: false DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wistron.com; s=security; t=1633577188; bh=uU5vJJDb7EnsHC7/5aq9DjKFWGfU1qbK5nhaWC/Yoy0=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=X4Yhp9rEQJnUZ+am4ziuZD3z00leNTYqGPUl0vMb6IwLQP8Wcj6SdhEqFOSTiJdSD SL4w3xOahunovB6kekNmwZ6Y9+b/tIlnEwtOwk5vcf7yuWWGBFsOJBlqgR8oN6nH9M 0E3n0xoCFcO1HW7SJ0Nn9i8FDkcwUZ1Hc127tyBo= X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Erich J Hauptli , Claire_Ku Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" From: LuluTHSu When a new device is detected with the same UUID as an already mounted device, a warning is issued in the status log, which is used to alert the user that the new device will be ignored. Signed-off-by: LuluTHSu --- discover/device-handler.h | 2 ++ discover/udev.c | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/discover/device-handler.h b/discover/device-handler.h index 6591120..216d17b 100644 --- a/discover/device-handler.h +++ b/discover/device-handler.h @@ -25,6 +25,7 @@ struct discover_device { const char *uuid; const char *label; + const char *id_path; char *mount_path; char *root_path; @@ -36,6 +37,7 @@ struct discover_device { bool crypt_device; bool notified; + bool dup_warn; struct list boot_options; struct list params; diff --git a/discover/udev.c b/discover/udev.c index 0c3da66..04ed8f1 100644 --- a/discover/udev.c +++ b/discover/udev.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "event.h" #include "udev.h" @@ -101,6 +102,7 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev, const char *prop; const char *type; const char *devname; + const char *idpath; const char *ignored_types[] = { "linux_raid_member", "swap", @@ -179,11 +181,19 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev, /* We may see multipath devices; they'll have the same uuid as an * existing device, so only parse the first. */ uuid = udev_device_get_property_value(dev, "ID_FS_UUID"); + idpath = udev_device_get_property_value(dev, "ID_PATH"); if (uuid) { ddev = device_lookup_by_uuid(udev->handler, uuid); if (ddev) { pb_log("SKIP: %s UUID [%s] already present (as %s)\n", name, uuid, ddev->device->id); + /* Only warn once in petitboot status log to remind users */ + if (strcmp(idpath, ddev->id_path) && !ddev->dup_warn) { + device_handler_status_info(udev->handler, + _("Duplicate filesystem as %s detected; skipping duplicates"), + ddev->device->id); + ddev->dup_warn = true; + } return 0; } } @@ -211,6 +221,7 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev, } } + ddev->id_path = talloc_strdup(ddev, idpath); ddev->device_path = talloc_strdup(ddev, node); talloc_free(devlinks); @@ -355,6 +366,7 @@ static int udev_handle_dev_remove(struct pb_udev *udev, struct udev_device *dev) { struct discover_device *ddev; const char *name; + const char *uuid; name = udev_device_get_sysname(dev); if (!name) { @@ -363,8 +375,15 @@ static int udev_handle_dev_remove(struct pb_udev *udev, struct udev_device *dev) } ddev = device_lookup_by_id(udev->handler, name); - if (!ddev) + if (!ddev) { + uuid = udev_device_get_property_value(dev, "ID_FS_UUID"); + if (uuid) { + ddev = device_lookup_by_uuid(udev->handler, uuid); + if (ddev) + ddev->dup_warn = false; + } return 0; + } device_handler_remove(udev->handler, ddev);