Message ID | 20170214024603.9563-3-rgoldwyn@suse.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
> + /* Don't sleep on inode rwsem */ > + if (iocb->ki_flags & IOCB_NONBLOCKING) { > + if (!inode_trylock(inode)) > + return -EAGAIN; > + } else > + inode_lock(inode); A way to avoid the additional branch in the fast path would be: if (!inode_trylock(inode)) { if (iocb->ki_flags & IOCB_NONBLOCKING) return -EAGAIN; inode_lock(inode); } but otherwise this looks fine: Reviewed-by: Christoph Hellwig <hch@lst.de>
diff --git a/mm/filemap.c b/mm/filemap.c index d8d7df8..50cee70 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2885,7 +2885,12 @@ ssize_t generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from) struct inode *inode = file->f_mapping->host; ssize_t ret; - inode_lock(inode); + /* Don't sleep on inode rwsem */ + if (iocb->ki_flags & IOCB_NONBLOCKING) { + if (!inode_trylock(inode)) + return -EAGAIN; + } else + inode_lock(inode); ret = generic_write_checks(iocb, from); if (ret > 0) ret = __generic_file_write_iter(iocb, from);