udev: switch over to rereadpt() rather than raw BLKRRPART

Fixes: #38672
This commit is contained in:
Lennart Poettering
2025-10-20 15:21:44 +02:00
parent 0ef4118c78
commit aa47d8ade1
3 changed files with 2 additions and 53 deletions

View File

@@ -804,27 +804,6 @@ int block_device_remove_all_partitions(sd_device *dev, int fd) {
return k < 0 ? k : has_partitions;
}
int blockdev_reread_partition_table(sd_device *dev) {
_cleanup_close_ int fd = -EBADF;
assert(dev);
/* Try to re-read the partition table. This only succeeds if none of the devices is busy. */
fd = sd_device_open(dev, O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
if (fd < 0)
return fd;
if (flock(fd, LOCK_EX|LOCK_NB) < 0)
return -errno;
if (ioctl(fd, BLKRRPART, 0) < 0)
return -errno;
return 0;
}
int blockdev_get_sector_size(int fd, uint32_t *ret) {
int ssz = 0;

View File

@@ -51,7 +51,6 @@ int block_device_remove_partition(int fd, const char *name, int nr);
int block_device_resize_partition(int fd, int nr, uint64_t start, uint64_t size);
int partition_enumerator_new(sd_device *dev, sd_device_enumerator **ret);
int block_device_remove_all_partitions(sd_device *dev, int fd);
int blockdev_reread_partition_table(sd_device *dev);
int blockdev_get_sector_size(int fd, uint32_t *ret);
int blockdev_get_device_size(int fd, uint64_t *ret);

View File

@@ -22,6 +22,7 @@
#include "parse-util.h"
#include "pidref.h"
#include "process-util.h"
#include "reread-partition-table.h"
#include "rm-rf.h"
#include "set.h"
#include "signal-util.h"
@@ -161,36 +162,6 @@ static int synthesize_change_one(sd_device *dev, sd_device *target) {
return 0;
}
static int synthesize_change_all(sd_device *dev) {
int r;
assert(dev);
r = blockdev_reread_partition_table(dev);
if (r < 0)
log_device_debug_errno(dev, r, "Failed to re-read partition table, ignoring: %m");
bool part_table_read = r >= 0;
/* search for partitions */
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
r = partition_enumerator_new(dev, &e);
if (r < 0)
return log_device_debug_errno(dev, r, "Failed to initialize partition enumerator, ignoring: %m");
/* We have partitions and re-read the table, the kernel already sent out a "change"
* event for the disk, and "remove/add" for all partitions. */
if (part_table_read && sd_device_enumerator_get_device_first(e))
return 0;
/* We have partitions but re-reading the partition table did not work, synthesize
* "change" for the disk and all partitions. */
r = synthesize_change_one(dev, dev);
FOREACH_DEVICE(e, d)
RET_GATHER(r, synthesize_change_one(dev, d));
return r;
}
static int synthesize_change_child_handler(sd_event_source *s, const siginfo_t *si, void *userdata) {
Manager *manager = ASSERT_PTR(userdata);
assert(s);
@@ -226,7 +197,7 @@ static int synthesize_change(Manager *manager, sd_device *dev) {
return r;
if (r == 0) {
/* child */
(void) synthesize_change_all(dev);
(void) reread_partition_table(dev, REREADPT_FORCE_UEVENT|REREADPT_BSD_LOCK);
_exit(EXIT_SUCCESS);
}