diff mbox series

[-next,5/5] loop: increment sequence number

Message ID 20210315200242.67355-6-mcroce@linux.microsoft.com (mailing list archive)
State New, archived
Headers show
Series block: add a sequence number to disks | expand

Commit Message

Matteo Croce March 15, 2021, 8:02 p.m. UTC
From: Matteo Croce <mcroce@microsoft.com>

On a very loaded system, if there are many events queued up from multiple
attach/detach cycles, it's impossible to match them up with the
LOOP_CONFIGURE or LOOP_SET_FD call, since we don't know where the position
of our own association in the queue is[1].
Not even an empty uevent queue is a reliable indication that we already
received the uevent we were waiting for, since with multi-partition block
devices each partition's event is queued asynchronously and might be
delivered later.

Increment the disk sequence number when setting or changing the backing
file, so the userspace knows which backing file generated the event.

[1] https://github.com/systemd/systemd/issues/17469#issuecomment-762919781

Signed-off-by: Matteo Croce <mcroce@microsoft.com>
 drivers/block/loop.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series


diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index a370cde3ddd4..1541ccff81f9 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -734,6 +734,7 @@  static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
 		goto out_err;
 	/* and ... switch */
+	inc_diskseq(lo->lo_disk);
 	mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
 	lo->lo_backing_file = file;
@@ -1122,6 +1123,8 @@  static int loop_configure(struct loop_device *lo, fmode_t mode,
 	if (error)
 		goto out_unlock;
+	inc_diskseq(lo->lo_disk);
 	if (!(file->f_mode & FMODE_WRITE) || !(mode & FMODE_WRITE) ||
 		lo->lo_flags |= LO_FLAGS_READ_ONLY;