+
+ // Remove dead lock.
+ // This happened when process is terminated while blocking on read.
+ // In that case, the process is still holding the inode lock and it will
+ // never get released.
+ // FIXME is this a good solution?
+ /*
+ * Consider two process both open the same file both with fd=x.
+ * Process A: busy on reading x
+ * Process B: do nothing with x
+ * Assume that, after a very short time, process B get terminated while
+ * process A is still busy in it's reading business. By this design, the
+ * inode lock of this file x is get released by B rather than A. And
+ * this will cause a probable race condition on A if other process is
+ * writing to this file later after B exit.
+ *
+ * A possible solution is to add a owner identification in the lock
+ * context, so only the lock holder can do the release.
+ */
+ if (mutex_on_hold(&file->inode->lock)) {
+ unlock_inode(file->inode);
+ }