On Wed, 2023-03-15 at 21:10 +0800, Li Xiao Keng wrote: > > > I test move close() after ioctl(). The reason of EBUSY is that > mdadm > open(sdf) with O_EXCL. So fd should be closed before ioctl. When I > remove > O_EXCL, ioctl() will return success. This makes sense. I suppose mdadm must use O_EXCL if it modifies RAID meta data, otherwise data corruption is just too likely. It is also impossible to drop the O_EXCL flag with fcntl() without closing the fd. So, if mdadm must close the fd before calling ioctl(), the race can hardly be avoided. The close() will cause a uevent, and nothing prevents the udev rules from running before the ioctl() returns. Unless we want to explore the flag-in-tmpfs idea, I think mdadm must expect this to happen, and deal with -EBUSY accordingly. But first we should get an answer to Coly's question, which version of mdadm is in use? Martin