On Mi, 23.06.21 14:03, Hannes Reinecke (hare@xxxxxxx) wrote: > On 6/23/21 12:58 PM, Matteo Croce wrote: > > From: Matteo Croce <mcroce@xxxxxxxxxxxxx> > > > > With this series a monotonically increasing number is added to disks, > > precisely in the genhd struct, and it's exported in sysfs and uevent. > > > > This helps the userspace correlate events for devices that reuse the > > same device, like loop. > > > I'm failing to see the point here. > Apparently you are assuming that there is a userspace tool tracking events, > and has a need to correlate events related to different instances of the > disk. > But if you have an userspace application tracking events, why can't the same > application track the 'add' and 'remove' events to track the lifetime of the > devices, and implement its own numbering based on that? > > Why do we need to burden the kernel with this? The problem is that tracking the "add" and "remove" events is simply not safely possibly right now for block devices whose names are frequently reused. Consider the loopback block device subsystem: whenever some tool wants a loopback block device it will ask the kernel for one and the kernel allocates from the bottom, hence /dev/loop0 is the most frequently used loopback block device. If a large number of concurrently running programs now repeatedly/quickly allocate/deallocate block devices they all sooner or later get /dev/loop0. If they now want to watch the "add" and "remove" uevents for that device for their own use of it there's a very good chance they'll end up seeing the previous user's "add" and "remove" events, as there's simply no way to associate the uevents you see with *your* *own* use of /dev/loop0 right now, and distinguish them from the uevent that might have been queued from a prior use of /dev/loop0 and were just slow to be processed. or to say this differently: loopback devices are named from a very small, dense pool of names, and are frequently and quickly reused. uevents are enqeued asynchronously and potentially take a long time to reach the listeners (after all they have to travel through two AF_NETLINK sockets and udev) and the only way to match up the device uses and their uevents is by these kernel device names that are so useless as a stable identifier. This not only applies to loopback block devices, but many other block device subsystems too. For example nbd allocates from the bottom, too, i.e. /dev/nbd0 is the most like name to be used. And for SCSI devices too: if you quickly plug/unplug/replug a bunch of USB sticks, you'll likely always get /dev/sda... Lennart -- Lennart Poettering, Berlin