aio_complete(dio->iocb, ret, 0);
}
- if (dio->flags & DIO_LOCKING)
- inode_dio_done(dio->inode);
+ inode_dio_done(dio->inode);
return ret;
}
* For writes this function is called under i_mutex and returns with
* i_mutex held, for reads, i_mutex is not held on entry, but it is
* taken and dropped again before returning.
- * The i_dio_count counter keeps track of the number of outstanding
- * direct I/O requests, and truncate waits for it to reach zero.
- * New references to i_dio_count must only be grabbed with i_mutex
- * held.
- *
* - if the flags value does NOT contain DIO_LOCKING we don't use any
* internal locking but rather rely on the filesystem to synchronize
* direct I/O reads/writes versus each other and truncate.
+ *
+ * To help with locking against truncate we incremented the i_dio_count
+ * counter before starting direct I/O, and decrement it once we are done.
+ * Truncate can wait for it to reach zero to provide exclusion. It is
+ * expected that filesystem provide exclusion between new direct I/O
+ * and truncates. For DIO_LOCKING filesystems this is done by i_mutex,
+ * but other filesystems need to take care of this on their own.
*/
ssize_t
__blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
goto out;
}
}
-
- /*
- * Will be decremented at I/O completion time.
- */
- atomic_inc(&inode->i_dio_count);
}
+ /*
+ * Will be decremented at I/O completion time.
+ */
+ atomic_inc(&inode->i_dio_count);
+
/*
* For file extending writes updating i_size before data
* writeouts complete can expose uninitialized blocks. So
/* this io's submitter should not have unlocked this before we could */
BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
- if (ocfs2_iocb_is_sem_locked(iocb)) {
- inode_dio_done(inode);
+ if (ocfs2_iocb_is_sem_locked(iocb))
ocfs2_iocb_clear_sem_locked(iocb);
- }
ocfs2_iocb_clear_rw_locked(iocb);
relock:
/* to match setattr's i_mutex -> rw_lock ordering */
if (direct_io) {
- atomic_inc(&inode->i_dio_count);
have_alloc_sem = 1;
/* communicate with ocfs2_dio_end_io */
ocfs2_iocb_set_sem_locked(iocb);
*/
if (direct_io && !can_do_direct) {
ocfs2_rw_unlock(inode, rw_level);
- inode_dio_done(inode);
have_alloc_sem = 0;
rw_level = -1;
ocfs2_rw_unlock(inode, rw_level);
out_sems:
- if (have_alloc_sem) {
- inode_dio_done(inode);
+ if (have_alloc_sem)
ocfs2_iocb_clear_sem_locked(iocb);
- }
mutex_unlock(&inode->i_mutex);
*/
if (filp->f_flags & O_DIRECT) {
have_alloc_sem = 1;
- atomic_inc(&inode->i_dio_count);
ocfs2_iocb_set_sem_locked(iocb);
ret = ocfs2_rw_lock(inode, 0);
}
bail:
- if (have_alloc_sem) {
- inode_dio_done(inode);
+ if (have_alloc_sem)
ocfs2_iocb_clear_sem_locked(iocb);
- }
+
if (rw_level != -1)
ocfs2_rw_unlock(inode, rw_level);