]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: Add debug logging for block_device_partition_add()
authorDaan De Meyer <daan@amutable.com>
Wed, 13 May 2026 19:23:48 +0000 (21:23 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 13 May 2026 20:25:55 +0000 (22:25 +0200)
src/fundamental/macro-fundamental.h
src/repart/repart.c

index 6ed6cf2f8a0a11e5be48b846c7b2dad3c45dd9b8..d38800d260747146d198468b3bc51ea31046dbe1 100644 (file)
@@ -278,6 +278,13 @@ assert_cc(sizeof(long long) == sizeof(intmax_t));
                         CONST_ISPOWEROF2(_x);                          \
                 }))
 
+/* Returns the largest power of two that divides x (i.e. x's natural alignment in bytes), or 0 if x is 0. */
+#define NATURAL_ALIGNMENT(x)                                                    \
+        ({                                                                      \
+                const uint64_t _x = (x);                                        \
+                _x == 0 ? UINT64_C(0) : UINT64_C(1) << __builtin_ctzll(_x);     \
+        })
+
 #define ADD_SAFE(ret, a, b) (!__builtin_add_overflow(a, b, ret))
 #define INC_SAFE(a, b) __INC_SAFE(UNIQ, a, b)
 #define __INC_SAFE(q, a, b)                                     \
index 331b31b789991cdd2711ead83a73fb3309d33293..0cdfef56be3a761889c0f1e95ab7ed6db1b7120a 100644 (file)
@@ -5202,6 +5202,10 @@ static int partition_target_prepare(
                          * keep them alive if we succeed, and the rescan will remove them if possible if
                          * there is an error before writing the partition table.
                          */
+                        log_debug("Adding partition '%s' (nr=%i, offset=%" PRIu64 " [align=%" PRIu64 "], size=%" PRIu64 " [align=%" PRIu64 "])",
+                                  part_node, nr,
+                                  p->offset, NATURAL_ALIGNMENT(p->offset),
+                                  size, NATURAL_ALIGNMENT(size));
                         r = block_device_add_partition(whole_fd, part_node, nr, p->offset, size);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to create new partition '%s': %m", part_node);