Skip to content

Commit b001760

Browse files
committed
9p: fix EBADF errors in cached mode
cached operations sometimes need to do invalid operations (e.g. read on a write only file) Historic fscache had added a "writeback fid", a special handle opened RW as root, for this. The conversion to new fscache missed that bit. This commit reinstates a slightly lesser variant of the original code that uses the writeback fid for partial pages backfills if the regular user fid had been open as WRONLY, and thus would lack read permissions. Link: https://lkml.kernel.org/r/[email protected] Fixes: eb49794 ("9p: Convert to using the netfs helper lib to do reads and caching") Cc: [email protected] Cc: David Howells <[email protected]> Reported-By: Christian Schoenebeck <[email protected]> Reviewed-by: Christian Schoenebeck <[email protected]> Tested-by: Christian Schoenebeck <[email protected]> Signed-off-by: Dominique Martinet <[email protected]>
1 parent 2a3dcbc commit b001760

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

fs/9p/vfs_addr.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,21 @@ static void v9fs_issue_read(struct netfs_io_subrequest *subreq)
5858
*/
5959
static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file)
6060
{
61+
struct inode *inode = file_inode(file);
62+
struct v9fs_inode *v9inode = V9FS_I(inode);
6163
struct p9_fid *fid = file->private_data;
6264

65+
BUG_ON(!fid);
66+
67+
/* we might need to read from a fid that was opened write-only
68+
* for read-modify-write of page cache, use the writeback fid
69+
* for that */
70+
if (rreq->origin == NETFS_READ_FOR_WRITE &&
71+
(fid->mode & O_ACCMODE) == O_WRONLY) {
72+
fid = v9inode->writeback_fid;
73+
BUG_ON(!fid);
74+
}
75+
6376
refcount_inc(&fid->count);
6477
rreq->netfs_priv = fid;
6578
return 0;

0 commit comments

Comments
 (0)