Re: [PATCH v2 5/6] ext4: introduce direct IO write path using iomap infrastructure
From: Matthew Bobrowski <hidden>
Date: 2019-09-11 12:39:15
Also in:
linux-fsdevel
On Wed, Sep 11, 2019 at 01:38:52PM +0530, Ritesh Harjani wrote:
On 9/9/19 2:56 PM, Ritesh Harjani wrote:quoted
On 9/9/19 4:49 AM, Matthew Bobrowski wrote:quoted
@@ -217,6 +218,14 @@ static ssize_t ext4_write_checks(struct kiocb*iocb, struct iov_iter *from) if (ret <= 0) return ret; + ret = file_remove_privs(iocb->ki_filp); + if (ret) + return 0; + + ret = file_update_time(iocb->ki_filp); + if (ret) + return 0; + if (unlikely(IS_IMMUTABLE(inode))) return -EPERM;Maybe we can move this up. If file is IMMUTABLE no point in calling for above actions (file_remove_privs/file_updatetime).
Yep, sure could do this. In fact, I think we could put this above generic_write_checks().
Also why not use file_modified() API which does the same.
Ah, nice. Indeed we can, thanks for simplifying it.
quoted
quoted
@@ -234,6 +243,34 @@ static ssize_t ext4_write_checks(struct kiocb*iocb, struct iov_iter *from) return iov_iter_count(from); } +static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, + struct iov_iter *from) +{ + ssize_t ret; + struct inode *inode = file_inode(iocb->ki_filp); + + if (iocb->ki_flags & IOCB_NOWAIT) + return -EOPNOTSUPP; + + if (!inode_trylock(inode)) + inode_lock(inode);Is it really needed to check for trylock first? we can directly call for inode_lock() here.
You're right, no need to do this dance. We can call inode_lock() directly.
quoted
quoted
+ + ret = ext4_write_checks(iocb, from); + if (ret <= 0) + goto out; + + current->backing_dev_info = inode_to_bdi(inode); + ret = generic_perform_write(iocb->ki_filp, from, iocb->ki_pos); + current->backing_dev_info = NULL; +out: + inode_unlock(inode); + if (likely(ret > 0)) { + iocb->ki_pos += ret; + ret = generic_write_sync(iocb, ret); + } + return ret; +} + + if (!ext4_dio_checks(inode)) { + inode_unlock(inode); + /* + * Fallback to buffered IO if the operation on the + * inode is not supported by direct IO. + */ + return ext4_buffered_write_iter(iocb, from); + } + + ret = ext4_write_checks(iocb, from);This can modify the count in iov_iter *from.
Good point. We'll recalculate the iter 'count' again. Thank you for the review/suggestions, highly appreciated. --<M>--