Skip to content

Commit 34eb98c

Browse files
Paulo Alcantarabrauner
authored andcommitted
netfs: Fix setting of transferred bytes with short DIO reads
A netfslib request comprises an ordered stream of subrequests that, when doing an unbuffered/DIO read, are contiguous. The subrequests may be performed in parallel, but may not be fully completed. For instance, if we try and make a 256KiB DIO read from a 3-byte file with a 64KiB rsize and 256KiB bsize, netfslib will attempt to make a read of 256KiB, broken up into four 64KiB subreads, with the expectation that the first will be short and the subsequent three be completely devoid - but we do all four on the basis that the file may have been changed by a third party. The read-collection code, however, walks through all the subreqs and advances the notion of how much data has been read in the stream to the start of each subreq plus its amount transferred (which are 3, 0, 0, 0 for the example above) - which gives an amount apparently read of 3*64KiB - which is incorrect. Fix the collection code to cut short the calculation of the transferred amount with the first short subrequest in an unbuffered read; everything beyond that must be ignored as there's a hole that cannot be filled. This applies both to shortness due to hitting the EOF and shortness due to an error. This is achieved by setting a flag on the request when we collect the first short subrequest (collection is done in ascending order). This can be tested by mounting a cifs volume with rsize=65536,bsize=262144 and doing a 256k DIO read of a very small file (e.g. 3 bytes). read() should return 3, not >3. This problem came in when netfs_read_collection() set rreq->transferred to stream->transferred, even for DIO. Prior to that, netfs_rreq_assess_dio() just went over the list and added up the subreqs till it met a short one - but now the subreqs are discarded earlier. Fixes: e2d46f2 ("netfs: Change the read result collector to only use one work item") Reported-by: Nicolas Baranger <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: "Paulo Alcantara (Red Hat)" <[email protected]> Signed-off-by: David Howells <[email protected]> Link: https://lore.kernel.org/[email protected] cc: [email protected] cc: [email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 4481f7f commit 34eb98c

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

fs/netfs/read_collect.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,13 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq)
280280
stream->need_retry = true;
281281
notes |= NEED_RETRY | MADE_PROGRESS;
282282
break;
283+
} else if (test_bit(NETFS_RREQ_SHORT_TRANSFER, &rreq->flags)) {
284+
notes |= MADE_PROGRESS;
283285
} else {
284286
if (!stream->failed)
285-
stream->transferred = stream->collected_to - rreq->start;
287+
stream->transferred += transferred;
288+
if (front->transferred < front->len)
289+
set_bit(NETFS_RREQ_SHORT_TRANSFER, &rreq->flags);
286290
notes |= MADE_PROGRESS;
287291
}
288292

@@ -342,23 +346,8 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq)
342346
*/
343347
static void netfs_rreq_assess_dio(struct netfs_io_request *rreq)
344348
{
345-
struct netfs_io_subrequest *subreq;
346-
struct netfs_io_stream *stream = &rreq->io_streams[0];
347349
unsigned int i;
348350

349-
/* Collect unbuffered reads and direct reads, adding up the transfer
350-
* sizes until we find the first short or failed subrequest.
351-
*/
352-
list_for_each_entry(subreq, &stream->subrequests, rreq_link) {
353-
rreq->transferred += subreq->transferred;
354-
355-
if (subreq->transferred < subreq->len ||
356-
test_bit(NETFS_SREQ_FAILED, &subreq->flags)) {
357-
rreq->error = subreq->error;
358-
break;
359-
}
360-
}
361-
362351
if (rreq->origin == NETFS_DIO_READ) {
363352
for (i = 0; i < rreq->direct_bv_count; i++) {
364353
flush_dcache_page(rreq->direct_bv[i].bv_page);

include/linux/netfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ struct netfs_io_request {
279279
#define NETFS_RREQ_USE_IO_ITER 12 /* Use ->io_iter rather than ->i_pages */
280280
#define NETFS_RREQ_ALL_QUEUED 13 /* All subreqs are now queued */
281281
#define NETFS_RREQ_RETRYING 14 /* Set if we're in the retry path */
282+
#define NETFS_RREQ_SHORT_TRANSFER 15 /* Set if we have a short transfer */
282283
#define NETFS_RREQ_USE_PGPRIV2 31 /* [DEPRECATED] Use PG_private_2 to mark
283284
* write to cache on read */
284285
const struct netfs_request_ops *netfs_ops;

0 commit comments

Comments
 (0)