Referring to original posting:http://marc.theaimsgroup.com/?t=113752710100001&r=1&w=2

Suparna pointed out that this fix has a potential race window. I thinkthe race condition also exists on the READ side currently. The fundamentalproblem is that dio->result is overloaded with dual use: an indicator offall back path for partial dio write, and an error indicator used in theI/O completion path. In the event of device error, the setting of -EIOto dio->result clashes with value used to track partial write that activatesthe fall back path.

One way to fix the race issue is to pull all the code that uses dio->resultup before I/O is submitted and then never look at dio->result once IO issubmitted. Or alternatively another independent variable can be introduceto track fall back state, note that to set the tracking logic, kernel stillhave to look at dio->result before I/O is submitted.

The following patch implements the first option. I would appreciate somereviews. Thanks.

[patch] bug fix in dio handling write error

There is a bug in direct-io on propagating write error up to thehigher I/O layer. When performing an async ODIRECT write to ablock device, if a device error occurred (like media error or diskis pulled), the error code is only propagated from device driverto the DIO layer. The error code stops at finished_one_bio(). Theaysnc write, however, is supposedly have a corresponding AIO eventwith appropriate return code (in this case -EIO). Applicationwhich waits on the async write event, will hang forever since suchAIO event is lost forever (if such app did not use the timeoutoption in io_getevents call. Regardless, an AIO event is lost).

The discovery of above bug leads to another discovery of potentialrace window with dio->result. The fundamental problem is thatdio->result is overloaded with dual use: an indicator of fall backpath for partial dio write, and an error indicator used in the I/Ocompletion path. In the event of device error, the setting of -EIOto dio->result clashes with value used to track partial write thatactivates the fall back path.

Propose to fix the race issue by pulling all the code that usesdio->result up before I/O is submitted and then never look atdio->result once IO is submitted.