Message ID | b3864441547e49a69d45c7771aa8cc5e595d18fc.1656934419.git.fdmanana@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: a few direct IO fixes/improvements | expand |
On Mon, Jul 04, 2022 at 12:42:03PM +0100, fdmanana@kernel.org wrote: > + * filemap_read(), we fail to fault in pages for the read buffer, > + * in which case filemap_read() returns a short read (the number > + * of bytes previously read is > 0, so it does not return -EFAULT). Two overly long lines here, which are especially annoying in block comments as they completely break the layout. > + ret = (flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOTBLK; Nit: I'd find this a lot more readable with a good old if / else. Either way the technical change looks good: Reviewed-by: Christoph Hellwig <hch@lst.de>
On Mon, Jul 04, 2022 at 04:57:41AM -0700, Christoph Hellwig wrote: > On Mon, Jul 04, 2022 at 12:42:03PM +0100, fdmanana@kernel.org wrote: > > + * filemap_read(), we fail to fault in pages for the read buffer, > > + * in which case filemap_read() returns a short read (the number > > + * of bytes previously read is > 0, so it does not return -EFAULT). > > Two overly long lines here, which are especially annoying in block > comments as they completely break the layout. The only line that is not under 81 is the last one and what does not if is "T).". This is within the acceptable overflow and I adjust many lines in patches based on how the code looks (ie. avoiding some line breaks) and if the potentially overflown text does not obscure the meaning. Keeping the lines under 80 makes sense for me personally when resolving conflicts in the 3+1 vimdiff view, but the limit is not strict and the criteria is if the code follows the common patterns we've settled on and what people in the btrfs group are used to, either reading or writing. The kernel coding style does not cover everything and is a good starting point. The rest is at https://btrfs.wiki.kernel.org/index.php/Development_notes#Coding_style_preferences
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 7a54f964ff37..b86be4c3513d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7684,7 +7684,19 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start, if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags) || em->block_start == EXTENT_MAP_INLINE) { free_extent_map(em); - ret = -ENOTBLK; + /* + * If we are in a NOWAIT context, return -EAGAIN in order to + * fallback to buffered IO. This is not only because we can + * block with buffered IO (no support for NOWAIT semantics at + * the moment) but also to avoid returning short reads to user + * space - this happens if we were able to read some data from + * previous non-compressed extents and then when we fallback to + * buffered IO, at btrfs_file_read_iter() by calling + * filemap_read(), we fail to fault in pages for the read buffer, + * in which case filemap_read() returns a short read (the number + * of bytes previously read is > 0, so it does not return -EFAULT). + */ + ret = (flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOTBLK; goto unlock_err; }