~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/9p/vfs_addr.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * This file contians vfs address (mmap) ops for 9P2000.
  4  *
  5  *  Copyright (C) 2005 by Eric Van Hensbergen <ericvh@gmail.com>
  6  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
  7  */
  8 
  9 #include <linux/module.h>
 10 #include <linux/errno.h>
 11 #include <linux/fs.h>
 12 #include <linux/file.h>
 13 #include <linux/stat.h>
 14 #include <linux/string.h>
 15 #include <linux/pagemap.h>
 16 #include <linux/sched.h>
 17 #include <linux/swap.h>
 18 #include <linux/uio.h>
 19 #include <linux/netfs.h>
 20 #include <net/9p/9p.h>
 21 #include <net/9p/client.h>
 22 #include <trace/events/netfs.h>
 23 
 24 #include "v9fs.h"
 25 #include "v9fs_vfs.h"
 26 #include "cache.h"
 27 #include "fid.h"
 28 
 29 /*
 30  * Writeback calls this when it finds a folio that needs uploading.  This isn't
 31  * called if writeback only has copy-to-cache to deal with.
 32  */
 33 static void v9fs_begin_writeback(struct netfs_io_request *wreq)
 34 {
 35         struct p9_fid *fid;
 36 
 37         fid = v9fs_fid_find_inode(wreq->inode, true, INVALID_UID, true);
 38         if (!fid) {
 39                 WARN_ONCE(1, "folio expected an open fid inode->i_ino=%lx\n",
 40                           wreq->inode->i_ino);
 41                 return;
 42         }
 43 
 44         wreq->wsize = fid->clnt->msize - P9_IOHDRSZ;
 45         if (fid->iounit)
 46                 wreq->wsize = min(wreq->wsize, fid->iounit);
 47         wreq->netfs_priv = fid;
 48         wreq->io_streams[0].avail = true;
 49 }
 50 
 51 /*
 52  * Issue a subrequest to write to the server.
 53  */
 54 static void v9fs_issue_write(struct netfs_io_subrequest *subreq)
 55 {
 56         struct p9_fid *fid = subreq->rreq->netfs_priv;
 57         int err, len;
 58 
 59         len = p9_client_write(fid, subreq->start, &subreq->io_iter, &err);
 60         netfs_write_subrequest_terminated(subreq, len ?: err, false);
 61 }
 62 
 63 /**
 64  * v9fs_issue_read - Issue a read from 9P
 65  * @subreq: The read to make
 66  */
 67 static void v9fs_issue_read(struct netfs_io_subrequest *subreq)
 68 {
 69         struct netfs_io_request *rreq = subreq->rreq;
 70         struct p9_fid *fid = rreq->netfs_priv;
 71         int total, err;
 72 
 73         total = p9_client_read(fid, subreq->start + subreq->transferred,
 74                                &subreq->io_iter, &err);
 75 
 76         /* if we just extended the file size, any portion not in
 77          * cache won't be on server and is zeroes */
 78         if (subreq->rreq->origin != NETFS_DIO_READ)
 79                 __set_bit(NETFS_SREQ_CLEAR_TAIL, &subreq->flags);
 80 
 81         netfs_subreq_terminated(subreq, err ?: total, false);
 82 }
 83 
 84 /**
 85  * v9fs_init_request - Initialise a request
 86  * @rreq: The read request
 87  * @file: The file being read from
 88  */
 89 static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file)
 90 {
 91         struct p9_fid *fid;
 92         bool writing = (rreq->origin == NETFS_READ_FOR_WRITE ||
 93                         rreq->origin == NETFS_WRITETHROUGH ||
 94                         rreq->origin == NETFS_UNBUFFERED_WRITE ||
 95                         rreq->origin == NETFS_DIO_WRITE);
 96 
 97         if (rreq->origin == NETFS_WRITEBACK)
 98                 return 0; /* We don't get the write handle until we find we
 99                            * have actually dirty data and not just
100                            * copy-to-cache data.
101                            */
102 
103         if (file) {
104                 fid = file->private_data;
105                 if (!fid)
106                         goto no_fid;
107                 p9_fid_get(fid);
108         } else {
109                 fid = v9fs_fid_find_inode(rreq->inode, writing, INVALID_UID, true);
110                 if (!fid)
111                         goto no_fid;
112         }
113 
114         rreq->wsize = fid->clnt->msize - P9_IOHDRSZ;
115         if (fid->iounit)
116                 rreq->wsize = min(rreq->wsize, fid->iounit);
117 
118         /* we might need to read from a fid that was opened write-only
119          * for read-modify-write of page cache, use the writeback fid
120          * for that */
121         WARN_ON(rreq->origin == NETFS_READ_FOR_WRITE && !(fid->mode & P9_ORDWR));
122         rreq->netfs_priv = fid;
123         return 0;
124 
125 no_fid:
126         WARN_ONCE(1, "folio expected an open fid inode->i_ino=%lx\n",
127                   rreq->inode->i_ino);
128         return -EINVAL;
129 }
130 
131 /**
132  * v9fs_free_request - Cleanup request initialized by v9fs_init_rreq
133  * @rreq: The I/O request to clean up
134  */
135 static void v9fs_free_request(struct netfs_io_request *rreq)
136 {
137         struct p9_fid *fid = rreq->netfs_priv;
138 
139         p9_fid_put(fid);
140 }
141 
142 const struct netfs_request_ops v9fs_req_ops = {
143         .init_request           = v9fs_init_request,
144         .free_request           = v9fs_free_request,
145         .issue_read             = v9fs_issue_read,
146         .begin_writeback        = v9fs_begin_writeback,
147         .issue_write            = v9fs_issue_write,
148 };
149 
150 const struct address_space_operations v9fs_addr_operations = {
151         .read_folio             = netfs_read_folio,
152         .readahead              = netfs_readahead,
153         .dirty_folio            = netfs_dirty_folio,
154         .release_folio          = netfs_release_folio,
155         .invalidate_folio       = netfs_invalidate_folio,
156         .direct_IO              = noop_direct_IO,
157         .writepages             = netfs_writepages,
158 };
159 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php