On Thu, Mar 03, 2022 at 10:52:20AM -0700, Uday Shankar wrote: > Userspace learns of disk ro state via the change event emitted by > set_disk_ro_uevent. This function has cyclic dependency with > device_add_disk: the latter performs kobject initialization that is > necessary for uevents to go through, but we want to set up properties > like ro state before exposing the disk to userspace via device_add_disk. > > The usual workaround is to call set_disk_ro both before and after > device_add_disk; the purpose of the "after" call is just to emit the > uevent. Moreover, because set_disk_ro only emits a uevent when the ro > state changes, set_disk_ro needs to be called twice in the "after" > position to ensure that the ro state flips. See drivers/scsi/sd.c for an > example of this pattern. I don't see any such pattern there. I also don't see what the point is. KOBJ_CHANGE uevents tell about a change in device state. But if a device is marked read-only before disk_add that read-only state is already visible by the time the device is added and thus shows up in sysfs, and we do not need an extra notification.