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;
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);
#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"
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);
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);
}