From 9fe6f5cc1668e97be58847a3596890273a402c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 28 Nov 2019 11:05:42 +0100 Subject: [PATCH 1/7] gpt-auto-generator: move functions around open_parent_devno() which is a helper is moved out of the main "business logic" block of various add_*() functions. And parse_proc_cmdline_item() is moved to the end, near to run() where it is used. No functional change. --- src/gpt-auto-generator/gpt-auto-generator.c | 297 ++++++++++---------- 1 file changed, 148 insertions(+), 149 deletions(-) diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index de51801d23..1dd98eeb1f 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -39,6 +39,69 @@ static bool arg_enabled = true; static bool arg_root_enabled = true; static int arg_root_rw = -1; +static int open_parent_devno(dev_t devnum, int *ret) { + _cleanup_(sd_device_unrefp) sd_device *d = NULL; + const char *name, *devtype, *node; + sd_device *parent; + dev_t pn; + int fd, r; + + assert(ret); + + r = sd_device_new_from_devnum(&d, 'b', devnum); + if (r < 0) + return log_debug_errno(r, "Failed to open device: %m"); + + if (sd_device_get_devname(d, &name) < 0) { + r = sd_device_get_syspath(d, &name); + if (r < 0) { + log_device_debug_errno(d, r, "Device %u:%u does not have a name, ignoring: %m", major(devnum), minor(devnum)); + return 0; + } + } + + r = sd_device_get_parent(d, &parent); + if (r < 0) { + log_device_debug_errno(d, r, "Not a partitioned device, ignoring: %m"); + return 0; + } + + /* Does it have a devtype? */ + r = sd_device_get_devtype(parent, &devtype); + if (r < 0) { + log_device_debug_errno(parent, r, "Parent doesn't have a device type, ignoring: %m"); + return 0; + } + + /* Is this a disk or a partition? We only care for disks... */ + if (!streq(devtype, "disk")) { + log_device_debug(parent, "Parent isn't a raw disk, ignoring."); + return 0; + } + + /* Does it have a device node? */ + r = sd_device_get_devname(parent, &node); + if (r < 0) { + log_device_debug_errno(parent, r, "Parent device does not have device node, ignoring: %m"); + return 0; + } + + log_device_debug(d, "Root device %s.", node); + + r = sd_device_get_devnum(parent, &pn); + if (r < 0) { + log_device_debug_errno(parent, r, "Parent device is not a proper block device, ignoring: %m"); + return 0; + } + + fd = open(node, O_RDONLY|O_CLOEXEC|O_NOCTTY); + if (fd < 0) + return log_error_errno(errno, "Failed to open %s: %m", node); + + *ret = fd; + return 1; +} + static int add_cryptsetup(const char *id, const char *what, bool rw, bool require, char **device) { _cleanup_free_ char *e = NULL, *n = NULL, *d = NULL, *id_escaped = NULL, *what_escaped = NULL; _cleanup_fclose_ FILE *f = NULL; @@ -530,67 +593,61 @@ static int add_root_rw(DissectedPartition *p) { return 0; } -static int open_parent_devno(dev_t devnum, int *ret) { - _cleanup_(sd_device_unrefp) sd_device *d = NULL; - const char *name, *devtype, *node; - sd_device *parent; - dev_t pn; - int fd, r; +#if ENABLE_EFI +static int add_root_cryptsetup(void) { - assert(ret); + /* If a device /dev/gpt-auto-root-luks appears, then make it pull in systemd-cryptsetup-root.service, which + * sets it up, and causes /dev/gpt-auto-root to appear which is all we are looking for. */ - r = sd_device_new_from_devnum(&d, 'b', devnum); - if (r < 0) - return log_debug_errno(r, "Failed to open device: %m"); + return add_cryptsetup("root", "/dev/gpt-auto-root-luks", true, false, NULL); +} +#endif - if (sd_device_get_devname(d, &name) < 0) { - r = sd_device_get_syspath(d, &name); - if (r < 0) { - log_device_debug_errno(d, r, "Device %u:%u does not have a name, ignoring: %m", major(devnum), minor(devnum)); +static int add_root_mount(void) { +#if ENABLE_EFI + int r; + + if (!is_efi_boot()) { + log_debug("Not a EFI boot, not creating root mount."); + return 0; + } + + r = efi_loader_get_device_part_uuid(NULL); + if (r == -ENOENT) { + log_debug("EFI loader partition unknown, exiting."); + return 0; + } else if (r < 0) + return log_error_errno(r, "Failed to read ESP partition UUID: %m"); + + /* OK, we have an ESP partition, this is fantastic, so let's + * wait for a root device to show up. A udev rule will create + * the link for us under the right name. */ + + if (in_initrd()) { + r = generator_write_initrd_root_device_deps(arg_dest, "/dev/gpt-auto-root"); + if (r < 0) return 0; - } + + r = add_root_cryptsetup(); + if (r < 0) + return r; } - r = sd_device_get_parent(d, &parent); - if (r < 0) { - log_device_debug_errno(d, r, "Not a partitioned device, ignoring: %m"); - return 0; - } + /* Note that we do not need to enable systemd-remount-fs.service here. If + * /etc/fstab exists, systemd-fstab-generator will pull it in for us. */ - /* Does it have a devtype? */ - r = sd_device_get_devtype(parent, &devtype); - if (r < 0) { - log_device_debug_errno(parent, r, "Parent doesn't have a device type, ignoring: %m"); - return 0; - } - - /* Is this a disk or a partition? We only care for disks... */ - if (!streq(devtype, "disk")) { - log_device_debug(parent, "Parent isn't a raw disk, ignoring."); - return 0; - } - - /* Does it have a device node? */ - r = sd_device_get_devname(parent, &node); - if (r < 0) { - log_device_debug_errno(parent, r, "Parent device does not have device node, ignoring: %m"); - return 0; - } - - log_device_debug(d, "Root device %s.", node); - - r = sd_device_get_devnum(parent, &pn); - if (r < 0) { - log_device_debug_errno(parent, r, "Parent device is not a proper block device, ignoring: %m"); - return 0; - } - - fd = open(node, O_RDONLY|O_CLOEXEC|O_NOCTTY); - if (fd < 0) - return log_error_errno(errno, "Failed to open %s: %m", node); - - *ret = fd; - return 1; + return add_mount( + "root", + "/dev/gpt-auto-root", + in_initrd() ? "/sysroot" : "/", + NULL, + arg_root_rw > 0, + NULL, + "Root Partition", + in_initrd() ? SPECIAL_INITRD_ROOT_FS_TARGET : SPECIAL_LOCAL_FS_TARGET); +#else + return 0; +#endif } static int enumerate_partitions(dev_t devnum) { @@ -649,6 +706,43 @@ static int enumerate_partitions(dev_t devnum) { return r; } +static int add_mounts(void) { + dev_t devno; + int r; + + r = get_block_device_harder("/", &devno); + if (r < 0) + return log_error_errno(r, "Failed to determine block device of root file system: %m"); + if (r == 0) { + r = get_block_device_harder("/usr", &devno); + if (r < 0) + return log_error_errno(r, "Failed to determine block device of /usr file system: %m"); + if (r == 0) { + _cleanup_free_ char *p = NULL; + mode_t m; + + /* If the root mount has been replaced by some form of volatile file system (overlayfs), the + * original root block device node is symlinked in /run/systemd/volatile-root. Let's read that + * here. */ + r = readlink_malloc("/run/systemd/volatile-root", &p); + if (r == -ENOENT) { + log_debug("Neither root nor /usr file system are on a (single) block device."); + return 0; + } + if (r < 0) + return log_error_errno(r, "Failed to read symlink /run/systemd/volatile-root: %m"); + + r = device_path_parse_major_minor(p, &m, &devno); + if (r < 0) + return log_error_errno(r, "Failed to parse major/minor device node: %m"); + if (!S_ISBLK(m)) + return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK), "Volatile root device is of wrong type."); + } + } + + return enumerate_partitions(devno); +} + static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { int r; @@ -690,101 +784,6 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat return 0; } -#if ENABLE_EFI -static int add_root_cryptsetup(void) { - - /* If a device /dev/gpt-auto-root-luks appears, then make it pull in systemd-cryptsetup-root.service, which - * sets it up, and causes /dev/gpt-auto-root to appear which is all we are looking for. */ - - return add_cryptsetup("root", "/dev/gpt-auto-root-luks", true, false, NULL); -} -#endif - -static int add_root_mount(void) { - -#if ENABLE_EFI - int r; - - if (!is_efi_boot()) { - log_debug("Not a EFI boot, not creating root mount."); - return 0; - } - - r = efi_loader_get_device_part_uuid(NULL); - if (r == -ENOENT) { - log_debug("EFI loader partition unknown, exiting."); - return 0; - } else if (r < 0) - return log_error_errno(r, "Failed to read ESP partition UUID: %m"); - - /* OK, we have an ESP partition, this is fantastic, so let's - * wait for a root device to show up. A udev rule will create - * the link for us under the right name. */ - - if (in_initrd()) { - r = generator_write_initrd_root_device_deps(arg_dest, "/dev/gpt-auto-root"); - if (r < 0) - return 0; - - r = add_root_cryptsetup(); - if (r < 0) - return r; - } - - /* Note that we do not need to enable systemd-remount-fs.service here. If - * /etc/fstab exists, systemd-fstab-generator will pull it in for us. */ - - return add_mount( - "root", - "/dev/gpt-auto-root", - in_initrd() ? "/sysroot" : "/", - NULL, - arg_root_rw > 0, - NULL, - "Root Partition", - in_initrd() ? SPECIAL_INITRD_ROOT_FS_TARGET : SPECIAL_LOCAL_FS_TARGET); -#else - return 0; -#endif -} - -static int add_mounts(void) { - dev_t devno; - int r; - - r = get_block_device_harder("/", &devno); - if (r < 0) - return log_error_errno(r, "Failed to determine block device of root file system: %m"); - if (r == 0) { - r = get_block_device_harder("/usr", &devno); - if (r < 0) - return log_error_errno(r, "Failed to determine block device of /usr file system: %m"); - if (r == 0) { - _cleanup_free_ char *p = NULL; - mode_t m; - - /* If the root mount has been replaced by some form of volatile file system (overlayfs), the - * original root block device node is symlinked in /run/systemd/volatile-root. Let's read that - * here. */ - r = readlink_malloc("/run/systemd/volatile-root", &p); - if (r == -ENOENT) { - log_debug("Neither root nor /usr file system are on a (single) block device."); - return 0; - } - if (r < 0) - return log_error_errno(r, "Failed to read symlink /run/systemd/volatile-root: %m"); - - r = device_path_parse_major_minor(p, &m, &devno); - if (r < 0) - return log_error_errno(r, "Failed to parse major/minor device node: %m"); - if (!S_ISBLK(m)) - return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK), "Volatile root device is of wrong type."); - } - } - - return enumerate_partitions(devno); -} - static int run(const char *dest, const char *dest_early, const char *dest_late) { int r, k; From 074cdb953bd2d9ae09aa04769c86868ef8bd066d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 28 Nov 2019 13:17:28 +0100 Subject: [PATCH 2/7] gpt-auto-generator: improve debug messages a bit In particular, let's give a hint when we do nothing in the common case of root= being used. --- src/gpt-auto-generator/gpt-auto-generator.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 1dd98eeb1f..5f27edc9ee 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -225,7 +225,7 @@ static int add_mount( assert(where); assert(description); - log_debug("Adding %s: %s %s", where, what, strna(fstype)); + log_debug("Adding %s: %s fstype=%s", where, what, fstype ?: "(any)"); if (streq_ptr(fstype, "crypto_LUKS")) { @@ -765,7 +765,10 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat /* Disable root disk logic if there's a root= value * specified (unless it happens to be "gpt-auto") */ - arg_root_enabled = streq(value, "gpt-auto"); + if (!streq(value, "gpt-auto")) { + arg_root_enabled = false; + log_debug("Disabling root partition auto-detection, root= is defined."); + } } else if (proc_cmdline_key_streq(key, "roothash")) { From 1fac34b9412154c8e69f77274ae10cb459afc65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 28 Nov 2019 13:20:58 +0100 Subject: [PATCH 3/7] gpt-auto-generator: use write_drop_in_format() helper and downgrade failure If we fail to write the timeout, let's not exit. (This might happen if another generator writes the same dropin.) No need to make this fatal. Since this is non-fatal now and the name doesn't need to be unique, let's make the drop-in name shorter. --- src/gpt-auto-generator/gpt-auto-generator.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 5f27edc9ee..99b5da17f5 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -13,6 +13,7 @@ #include "device-util.h" #include "dirent-util.h" #include "dissect-image.h" +#include "dropin.h" #include "efi-loader.h" #include "fd-util.h" #include "fileio.h" @@ -166,28 +167,25 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, bool requir if (r < 0) return r; - if (require) { - const char *dmname; + const char *dmname; + dmname = strjoina("dev-mapper-", e, ".device"); + if (require) { r = generator_add_symlink(arg_dest, "cryptsetup.target", "requires", n); if (r < 0) return r; - dmname = strjoina("dev-mapper-", e, ".device"); r = generator_add_symlink(arg_dest, dmname, "requires", n); if (r < 0) return r; } - p = strjoina(arg_dest, "/dev-mapper-", e, ".device.d/50-job-timeout-sec-0.conf"); - mkdir_parents_label(p, 0755); - r = write_string_file(p, - "# Automatically generated by systemd-gpt-auto-generator\n\n" - "[Unit]\n" - "JobTimeoutSec=0\n", - WRITE_STRING_FILE_CREATE); /* the binary handles timeouts anyway */ + r = write_drop_in_format(arg_dest, dmname, 50, "job-timeout", + "# Automatically generated by systemd-gpt-auto-generator\n\n" + "[Unit]\n" + "JobTimeoutSec=0"); /* the binary handles timeouts anyway */ if (r < 0) - return log_error_errno(r, "Failed to write device drop-in: %m"); + log_warning_errno(r, "Failed to write device timeout drop-in, ignoring: %m"); if (device) { char *ret; From b50a3a1565028cda00e1ade264bb209c97dac3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 28 Nov 2019 18:21:22 +0100 Subject: [PATCH 4/7] gpt-auto-generator: make it easier to notice if boot loader support is missing The docs didn't talk about this, so let's add an explicit mention that the boot loader must cooperate. And also make the message from the generator notice level. This should help people who are trying to mix grub and the gpt auto logic. --- man/systemd-gpt-auto-generator.xml | 23 ++++++++++++--------- src/gpt-auto-generator/gpt-auto-generator.c | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/man/systemd-gpt-auto-generator.xml b/man/systemd-gpt-auto-generator.xml index 22cd638f1f..8d208f4cb9 100644 --- a/man/systemd-gpt-auto-generator.xml +++ b/man/systemd-gpt-auto-generator.xml @@ -35,7 +35,7 @@ root, /home/, /srv/, the EFI System Partition, the Extended Boot Loader Partition and swap partitions and creates mount and swap units for them, based on the partition type GUIDs of GUID partition tables (GPT), see UEFI Specification, chapter 5. It implements the UEFI Specification, chapter 5. It implements the Discoverable Partitions Specification. Note that this generator has no effect on non-GPT systems, and on specific mount points that are directories already containing files. Also, on systems where the units are explicitly @@ -44,18 +44,21 @@ units this generator creates are overridden, but additional implicit dependencies might be created. - This generator will only look for root partitions on the - same physical disk the EFI System Partition (ESP) is located on. - It will only look for the other partitions on the same physical - disk the root file system is located on. These partitions will not - be searched for on systems where the root file system is distributed - on multiple disks, for example via btrfs RAID. + This generator will only look for the root partition on the same physical disk the EFI System + Partition (ESP) is located on. Note that support from the boot loader is required: EFI variable + LoaderDevicePartUUID-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f is used to determine from + which partition, and hence the disk from which the system was booted. If the boot loader does not set + this variable, this generator will not be able to autodetect the root partition. - systemd-gpt-auto-generator is useful - for centralizing file system configuration in the partition table - and making configuration in /etc/fstab unnecessary. + Similarly, this generator will only look for the other partitions on the same physical disk as the + root partition. In this case, boot loader support is not required. These partitions will not be searched + for on systems where the root file system is distributed on multiple disks, for example via btrfs RAID. + systemd-gpt-auto-generator is useful for centralizing file system + configuration in the partition table and making configuration in /etc/fstab or on + the kernel command line unnecessary. + This generator looks for the partitions based on their partition type GUID. The following partition type GUIDs are identified: diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 99b5da17f5..bbfebbbe95 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -612,7 +612,8 @@ static int add_root_mount(void) { r = efi_loader_get_device_part_uuid(NULL); if (r == -ENOENT) { - log_debug("EFI loader partition unknown, exiting."); + log_notice("EFI loader partition unknown, exiting.\n" + "(The boot loader did not set EFI variable LoaderDevicePartUUID.)"); return 0; } else if (r < 0) return log_error_errno(r, "Failed to read ESP partition UUID: %m"); From 607ebf2bd28fdd85c9122d2ea523ff9ebb6adc4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 28 Nov 2019 19:43:04 +0100 Subject: [PATCH 5/7] bootlctl: show LoaderDevicePartUUID information in status --- src/boot/bootctl.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index a90502b4c3..5874b9ec68 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -1163,6 +1163,15 @@ static void read_loader_efi_var(const char *name, char **var) { log_warning_errno(r, "Failed to read EFI variable %s: %m", name); } +static void print_yes_no_line(bool first, bool good, const char *name) { + printf("%s%s%s%s %s\n", + first ? " Features: " : " ", + good ? ansi_highlight_green() : ansi_highlight_red(), + good ? special_glyph(SPECIAL_GLYPH_CHECK_MARK) : special_glyph(SPECIAL_GLYPH_CROSS_MARK), + ansi_normal(), + name); +} + static int verb_status(int argc, char *argv[], void *userdata) { sd_id128_t esp_uuid = SD_ID128_NULL, xbootldr_uuid = SD_ID128_NULL; int r, k; @@ -1242,18 +1251,15 @@ static int verb_status(int argc, char *argv[], void *userdata) { printf("Current Boot Loader:\n"); printf(" Product: %s%s%s\n", ansi_highlight(), strna(loader), ansi_normal()); - for (i = 0; i < ELEMENTSOF(flags); i++) { + for (i = 0; i < ELEMENTSOF(flags); i++) + print_yes_no_line(i == 0, FLAGS_SET(loader_features, flags[i].flag), flags[i].name); - if (i == 0) - printf(" Features: "); - else - printf(" "); + sd_id128_t bootloader_esp_uuid; + bool have_bootloader_esp_uuid = efi_loader_get_device_part_uuid(&bootloader_esp_uuid) >= 0; - if (FLAGS_SET(loader_features, flags[i].flag)) - printf("%s%s%s %s\n", ansi_highlight_green(), special_glyph(SPECIAL_GLYPH_CHECK_MARK), ansi_normal(), flags[i].name); - else - printf("%s%s%s %s\n", ansi_highlight_red(), special_glyph(SPECIAL_GLYPH_CROSS_MARK), ansi_normal(), flags[i].name); - } + print_yes_no_line(false, have_bootloader_esp_uuid, "Boot loader sets ESP partition information"); + if (have_bootloader_esp_uuid && !sd_id128_equal(esp_uuid, bootloader_esp_uuid)) + printf("WARNING: The boot loader reports different ESP UUID then detected!\n"); if (stub) printf(" Stub: %s\n", stub); From 46c41478c933dabbfa8f005eddd38cb1a2a7eea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 30 Nov 2019 15:33:59 +0100 Subject: [PATCH 6/7] tree-wise: standarize on "auto-detection" spelling --- TODO | 2 +- test/README.testsuite | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index c3cc999ac4..faddc6f847 100644 --- a/TODO +++ b/TODO @@ -211,7 +211,7 @@ Features: 1. add resume_offset support to the resume code (i.e. support swap files properly) 2. check if swap is on weird storage and refuse if so - 3. add autodetection of hibernation images + 3. add auto-detection of hibernation images * cgroups: use inotify to get notified when somebody else modifies cgroups owned by us, then log a friendly warning. diff --git a/test/README.testsuite b/test/README.testsuite index 9e0c36512c..471771acd4 100644 --- a/test/README.testsuite +++ b/test/README.testsuite @@ -51,7 +51,7 @@ TEST_NO_NSPAWN=1 Don't run tests under systemd-nspawn TEST_NO_KVM=1 - Disable QEMU KVM autodetection (may be necessary when you're trying to run the + Disable QEMU KVM auto-detection (may be necessary when you're trying to run the *vanilla* QEMU and have both qemu and qemu-kvm installed) TEST_NESTED_KVM=1 From 3d92aa4596a7f4273a84a069018190abb7ca82ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 30 Nov 2019 17:32:54 +0100 Subject: [PATCH 7/7] gpt-auto-generator: rename function for clarity As requested in https://github.com/systemd/systemd/pull/14196#discussion_r352036184. --- src/gpt-auto-generator/gpt-auto-generator.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index bbfebbbe95..4aac903aa6 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -40,14 +40,14 @@ static bool arg_enabled = true; static bool arg_root_enabled = true; static int arg_root_rw = -1; -static int open_parent_devno(dev_t devnum, int *ret) { +static int open_parent_block_device(dev_t devnum, int *ret_fd) { _cleanup_(sd_device_unrefp) sd_device *d = NULL; const char *name, *devtype, *node; sd_device *parent; dev_t pn; int fd, r; - assert(ret); + assert(ret_fd); r = sd_device_new_from_devnum(&d, 'b', devnum); if (r < 0) @@ -56,7 +56,8 @@ static int open_parent_devno(dev_t devnum, int *ret) { if (sd_device_get_devname(d, &name) < 0) { r = sd_device_get_syspath(d, &name); if (r < 0) { - log_device_debug_errno(d, r, "Device %u:%u does not have a name, ignoring: %m", major(devnum), minor(devnum)); + log_device_debug_errno(d, r, "Device %u:%u does not have a name, ignoring: %m", + major(devnum), minor(devnum)); return 0; } } @@ -99,7 +100,7 @@ static int open_parent_devno(dev_t devnum, int *ret) { if (fd < 0) return log_error_errno(errno, "Failed to open %s: %m", node); - *ret = fd; + *ret_fd = fd; return 1; } @@ -654,7 +655,7 @@ static int enumerate_partitions(dev_t devnum) { _cleanup_(dissected_image_unrefp) DissectedImage *m = NULL; int r, k; - r = open_parent_devno(devnum, &fd); + r = open_parent_block_device(devnum, &fd); if (r <= 0) return r;