]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
blockdev-util: add partscan check function that takes an sd_device*
authorLennart Poettering <lennart@poettering.net>
Mon, 1 Jul 2024 09:44:26 +0000 (11:44 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 1 Jul 2024 14:35:56 +0000 (16:35 +0200)
src/partition/repart.c
src/shared/blockdev-util.c
src/shared/blockdev-util.h
src/shared/dissect-image.c
src/shared/loop-util.c
src/test/test-blockdev-util.c

index a3a6605ae5120d254f8dceeb30abf1aacd464bed..ab41769348d147cf360361631133fb2feb470ae6 100644 (file)
@@ -5903,7 +5903,7 @@ static int context_write_partition_table(Context *context) {
         if (r < 0)
                 return log_error_errno(r, "Failed to write partition table: %m");
 
-        capable = blockdev_partscan_enabled(fdisk_get_devfd(context->fdisk_context));
+        capable = blockdev_partscan_enabled_fd(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)
index 2055550336f6aa89e390e926bd73b1a399930013..53d60bd0dd7b99472ee328dddaeb6f8c53a0f32f 100644 (file)
@@ -356,8 +356,7 @@ int lock_whole_block_device(dev_t devt, int operation) {
         return TAKE_FD(lock_fd);
 }
 
-int blockdev_partscan_enabled(int fd) {
-        _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
+int blockdev_partscan_enabled(sd_device *dev) {
         unsigned capability;
         int r, ext_range;
 
@@ -408,11 +407,7 @@ int blockdev_partscan_enabled(int fd) {
          * 4) check 'ext_range' sysfs attribute, and if '1' we can conclude partition scanning is disabled,
          * 5) otherwise check 'capability' sysfs attribute for ancient version. */
 
-        assert(fd >= 0);
-
-        r = block_device_new_from_fd(fd, 0, &dev);
-        if (r < 0)
-                return r;
+        assert(dev);
 
         /* For v6.10 or newer. */
         r = device_get_sysattr_bool(dev, "partscan");
@@ -458,6 +453,19 @@ int blockdev_partscan_enabled(int fd) {
         return true;
 }
 
+int blockdev_partscan_enabled_fd(int fd) {
+        _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
+        int r;
+
+        assert(fd >= 0);
+
+        r = block_device_new_from_fd(fd, 0, &dev);
+        if (r < 0)
+                return r;
+
+        return blockdev_partscan_enabled(dev);
+}
+
 static int blockdev_is_encrypted(const char *sysfs_path, unsigned depth_left) {
         _cleanup_free_ char *p = NULL, *uuids = NULL;
         _cleanup_closedir_ DIR *d = NULL;
index 28aede289a0590f44cb408174153f8450a80284e..e8e9d37ef9b5716067776c900d334a666f25efa0 100644 (file)
@@ -40,7 +40,8 @@ int get_block_device_harder(const char *path, dev_t *dev);
 
 int lock_whole_block_device(dev_t devt, int operation);
 
-int blockdev_partscan_enabled(int fd);
+int blockdev_partscan_enabled(sd_device *d);
+int blockdev_partscan_enabled_fd(int fd);
 
 int fd_is_encrypted(int fd);
 int path_is_encrypted(const char *path);
index 1a3ed0cf7f41378b9d98ec466f29f9f13385c796..28c2d7dbc0a388c8b841d43de578d9361591378e 100644 (file)
@@ -893,7 +893,7 @@ static int dissect_image(
         if (FLAGS_SET(flags, DISSECT_IMAGE_ADD_PARTITION_DEVICES)) {
                 /* Safety check: refuse block devices that carry a partition table but for which the kernel doesn't
                  * do partition scanning. */
-                r = blockdev_partscan_enabled(fd);
+                r = blockdev_partscan_enabled_fd(fd);
                 if (r < 0)
                         return r;
                 if (r == 0)
index e295eb2a21ce2c40ec69fb82c781ac47e61b15b0..d707d466abdfe199b4d91fc8bdf90aefe5bde628 100644 (file)
@@ -149,7 +149,7 @@ static int loop_configure_verify(int fd, const struct loop_config *c) {
                  * into the block device. Let's hence verify if things work correctly here
                  * before returning. */
 
-                r = blockdev_partscan_enabled(fd);
+                r = blockdev_partscan_enabled_fd(fd);
                 if (r < 0)
                         return r;
                 if (r == 0) {
index 19626e0b771d01df8f71af0c994df6b7b61b4556..6ede05852d9d8309dbdd32d3629acb7ea3c59a5c 100644 (file)
@@ -65,7 +65,7 @@ TEST(partscan_enabled) {
                         continue;
                 }
 
-                r = blockdev_partscan_enabled(fd);
+                r = blockdev_partscan_enabled_fd(fd);
                 if (r < 0) {
                         log_warning_errno(r, "Failed to determine if block device '%s' has partition scanning enabled, skipping: %m", name);
                         continue;