Skip to contentSkip to conversation

Returning more precise errors from read()

DISCUSSION Matthew Wilcox 1 participant 1 message Apr 19, 2024 VFS

lore
Share & tools
lore
#0 lore raw

Today we throw away the actual error returned by the block device / network protocol and transform it into an EIO return from read() [1]. There's no way today to send the error from the I/O completion routine up to the VFS [2]. Is it worth doing?

For block devices, there's a fairly limited set of additional errors that would apply to reads [3].

The important question in my mind is whether returning any of these errors to userspace would confuse applications. I suspect they would, and returning anything other than EIO to userspace is just a bad idea. But I'd like opinions before I pass up the opportunity to make this improvement.

I'm not going to make this change without a reason because it would impose some small costs on a few filesystems (notably any using iomap).

[1] For the curious, this happens in filemap_read_folio():

        error = filler(file, folio);
        if (error)
                return error;
        error = folio_wait_locked_killable(folio);
        if (error)
                return error;
        if (folio_test_uptodate(folio))
                return 0;
        return -EIO;

This looks like it can return a lot of different errors, but all real filesystems will only return synchronous errors like -ENOMEM ("couldn't allocate memory to submit request"). Any error from the block device simply leaves the folio being left as !uptodate and we return -EIO.

[2] I prototyped one once, but never got round to submitting it. I'm in the middle of converting a lot of filesystems, and it occurred to me that a fairly small change to folio_end_read() would make this easier to do in the future.

[3]

        [BLK_STS_TIMEOUT]       = { -ETIMEDOUT, "timeout" },
        [BLK_STS_TRANSPORT]     = { -ENOLINK,   "recoverable transport" },
        [BLK_STS_TARGET]        = { -EREMOTEIO, "critical target" },
        [BLK_STS_MEDIUM]        = { -ENODATA,   "critical medium" },
        [BLK_STS_PROTECTION]    = { -EILSEQ,    "protection" },
        [BLK_STS_RESOURCE]      = { -ENOMEM,    "kernel resource" },
        [BLK_STS_DEV_RESOURCE]  = { -EBUSY,     "device resource" },
        [BLK_STS_AGAIN]         = { -EAGAIN,    "nonblocking retry" },
        [BLK_STS_OFFLINE]       = { -ENODEV,    "device offline" },

[BLK_STS_DURATION_LIMIT] = { -ETIME, "duration limit exceeded" },