diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-09-25 17:23:34 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-09-26 18:31:48 +0200 |
commit | 911ba6240836a737f5d6637295476262739f623b (patch) | |
tree | 31c9f0ae52753e2ffa02dd9ebc6cb3b7b9d723ca /src/partition/repart.c | |
parent | Add Chinese translation (diff) | |
download | systemd-911ba6240836a737f5d6637295476262739f623b.tar.xz systemd-911ba6240836a737f5d6637295476262739f623b.zip |
repart: use proper API to check if block device can do partition scanning
We have the API wrapper already, hence use it, instead of using a
limited version of it that only works for loopback devices.
Diffstat (limited to '')
-rw-r--r-- | src/partition/repart.c | 31 |
1 files changed, 2 insertions, 29 deletions
diff --git a/src/partition/repart.c b/src/partition/repart.c index 3e1dcf53eb..d406c9dbe3 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -2995,33 +2995,6 @@ static int context_acquire_partition_uuids_and_labels(Context *context) { return 0; } -static int device_kernel_partitions_supported(int fd) { - struct loop_info64 info; - struct stat st; - - assert(fd >= 0); - - if (fstat(fd, &st) < 0) - return log_error_errno(fd, "Failed to fstat() image file: %m"); - if (!S_ISBLK(st.st_mode)) - return -ENOTBLK; /* we do not log in this one special case about errors */ - - if (ioctl(fd, LOOP_GET_STATUS64, &info) < 0) { - - if (ERRNO_IS_NOT_SUPPORTED(errno) || errno == EINVAL) - return true; /* not a loopback device, let's assume partition are supported */ - - return log_error_errno(fd, "Failed to issue LOOP_GET_STATUS64 on block device: %m"); - } - -#if HAVE_VALGRIND_MEMCHECK_H - /* Valgrind currently doesn't know LOOP_GET_STATUS64. Remove this once it does */ - VALGRIND_MAKE_MEM_DEFINED(&info, sizeof(info)); -#endif - - return FLAGS_SET(info.lo_flags, LO_FLAGS_PARTSCAN); -} - static int context_mangle_partitions(Context *context) { Partition *p; int r; @@ -3233,11 +3206,11 @@ static int context_write_partition_table( if (r < 0) return log_error_errno(r, "Failed to write partition table: %m"); - capable = device_kernel_partitions_supported(fdisk_get_devfd(context->fdisk_context)); + capable = blockdev_partscan_enabled(fdisk_get_devfd(context->fdisk_context)); if (capable == -ENOTBLK) log_debug("Not telling kernel to reread partition table, since we are not operating on a block device."); else if (capable < 0) - return capable; + return log_error_errno(capable, "Failed to check if block device supports partition scanning: %m"); else if (capable > 0) { log_info("Telling kernel to reread partition table."); |