From patchwork Thu Jun 15 04:54:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Mendoza-Jonas X-Patchwork-Id: 776113 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wpB563zXdz9s65 for ; Thu, 15 Jun 2017 14:55:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="LxbdDPnd"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wpB562mkTzDqLd for ; Thu, 15 Jun 2017 14:55:06 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="LxbdDPnd"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from mendozajonas.com (mendozajonas.com [188.166.185.233]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3wpB4h0yyJzDqLB for ; Thu, 15 Jun 2017 14:54:44 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="LxbdDPnd"; dkim-atps=neutral Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: sam@mendozajonas.com) by mendozajonas.com (Postfix) with ESMTPSA id 0A1971441B0; Thu, 15 Jun 2017 12:54:40 +0800 (SGT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mendozajonas.com; s=mail; t=1497502481; bh=y2qftuc7FzIhCyhzLhf+m+cbn/gLAFD97B0DjPLKgGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LxbdDPndl9i9KSA+hVjGHjVcSRSHAJ6nMhVwC4yKEG7f4QO24g8A//rAFhB1e3tnq FuCko8oh7gkRySDMT8uekpNTgASCMcg+plSFzLAO7N1YyjAT3wQg8GrkXvlyCnZhRr WH5o5zglnktNTImgE0lQK7cQXHLM68KXpAoENEQk= From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 4/4] discover/udev: Handle LVM logical volumes Date: Thu, 15 Jun 2017 14:54:31 +1000 Message-Id: <20170615045431.29572-5-sam@mendozajonas.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170615045431.29572-1-sam@mendozajonas.com> References: <20170615045431.29572-1-sam@mendozajonas.com> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" If logical volumes are active and recognised by udev, no longer ignore them. We also do some extra handling to use user-friendly device names and mount the /dev/mapper/foo device rather than the /dev/dm-xx device. Additionally if we see "LMV2_member" devices start a rescan in case LVM-formatted disks came up after the LVM initscript. Signed-off-by: Samuel Mendoza-Jonas --- discover/udev.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/discover/udev.c b/discover/udev.c index 1e04313..540c912 100644 --- a/discover/udev.c +++ b/discover/udev.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "event.h" #include "udev.h" @@ -70,9 +71,26 @@ static void udev_setup_device_params(struct udev_device *udev, udev_list_entry_get_value(entry)); } +/* + * Search for LVM logical volumes. If any exist they should be recognised + * by udev as normal. + * Normally this is handled in an init script, but on some platforms + * disks are slow enough to come up that we need to check again. + * */ +static void lvm_vg_search(struct device_handler *handler) +{ + if (process_run_simple(handler, pb_system_apps.vgscan, "-qq", NULL)) + pb_log("%s: Failed to execute vgscan\n", __func__); + + if (process_run_simple(handler, pb_system_apps.vgchange, "-ay", "-qq", + NULL)) + pb_log("%s: Failed to execute vgchange\n", __func__); +} + static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev, const char *name) { + char *devlinks = NULL, *link, *saveptr = NULL; struct discover_device *ddev; unsigned int i = 0; const char *typestr; @@ -85,7 +103,6 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev, const char *ignored_types[] = { "linux_raid_member", "swap", - "LVM2_member", NULL, }; bool cdrom, usb; @@ -124,10 +141,9 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev, } } - /* If our environment's udev can recognise them explictly skip any - * device mapper devices we encounter */ + /* Ignore any device mapper devices that aren't logical volumes */ devname = udev_device_get_property_value(dev, "DM_NAME"); - if (devname) { + if (devname && ! udev_device_get_property_value(dev, "DM_LV_NAME")) { pb_debug("SKIP: dm-device %s\n", devname); return 0; } @@ -146,6 +162,12 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev, i++; } + /* Search for LVM logical volumes if we see an LVM member */ + if (strncmp(type, "LVM2_member", strlen("LVM2_member")) == 0) { + lvm_vg_search(udev->handler); + return 0; + } + /* 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"); @@ -158,9 +180,31 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev, } } - ddev = discover_device_create(udev->handler, uuid, name); + /* Use DM_NAME for logical volumes, or the device name otherwise */ + ddev = discover_device_create(udev->handler, uuid, devname ?: name); + + if (devname) { + /* + * For logical volumes udev_device_get_devnode() returns a path + * of the form "/dev/dm-xx". These nodes names are not + * persistent and are opaque to the user. Instead use the more + * recognisable "/dev/mapper/lv-name" node if it is available. + */ + devlinks = talloc_strdup(ddev, + udev_device_get_property_value(dev, "DEVLINKS")); + link = strtok_r(devlinks, " ", &saveptr); + while (link) { + if (strncmp(link, "/dev/mapper/", + strlen("/dev/mapper/")) == 0) { + node = link; + break; + } + link = strtok_r(NULL, " ", &saveptr); + } + } ddev->device_path = talloc_strdup(ddev, node); + talloc_free(devlinks); if (uuid) ddev->uuid = talloc_strdup(ddev, uuid);