• Al Viro's avatar
    fix return values of seq_read_iter() · 4bbf439b
    Al Viro authored
    Unlike ->read(), ->read_iter() instances *must* return the amount
    of data they'd left in iterator.  For ->read() returning less than
    it has actually copied is a QoI issue; read(fd, unmapped_page - 5, 8)
    is allowed to fill all 5 bytes of destination and return 4; it's
    not nice to caller, but POSIX allows pretty much anything in such
    situation, up to and including a SIGSEGV.
    
    generic_file_splice_read() uses pipe-backed iterator as destination;
    there a short copy comes from pipe being full, not from running into
    an un{mapped,writable} page in the middle of destination as we
    have for iovec-backed iterators read(2) uses.  And there we rely
    upon the ->read_iter() reporting the actual amount it has left
    in destination.
    
    Conversion of a ->read() instance into ->read_iter() has to watch
    out for that.  If you really need an "all or nothing" kind of
    behaviour somewhere, you need to do iov_iter_revert() to prune
    the partial copy.
    
    In case of seq_read_iter() we can handle short copy just fine;
    the data is in m->buf and next call will fetch it from there.
    
    Fixes: d4d50710 (seq_file: add seq_read_iter)
    Tested-by: default avatarNathan Chancellor <natechancellor@gmail.com>
    Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
    4bbf439b
seq_file.c 24.7 KB