Commit fbedadc1 authored by Eric Van Hensbergen's avatar Eric Van Hensbergen

9p: move readn meta-function from client to fs layer

There are a couple of methods in the client code which aren't actually
wire operations.  To keep things organized cleaner, these operations are
being moved to the fs layer.

This patch moves the readn meta-function (which executes multiple wire
reads until a buffer is full) to the fs layer.
Signed-off-by: default avatarEric Van Hensbergen <ericvh@gmail.com>


parent 0fc9655e
...@@ -234,7 +234,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses, ...@@ -234,7 +234,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
if (!v9ses->clnt->dotu) if (!v9ses->clnt->dotu)
v9ses->flags &= ~V9FS_EXTENDED; v9ses->flags &= ~V9FS_EXTENDED;
v9ses->maxdata = v9ses->clnt->msize; v9ses->maxdata = v9ses->clnt->msize - P9_IOHDRSZ;
/* for legacy mode, fall back to V9FS_ACCESS_ANY */ /* for legacy mode, fall back to V9FS_ACCESS_ANY */
if (!v9fs_extended(v9ses) && if (!v9fs_extended(v9ses) &&
......
...@@ -52,3 +52,5 @@ int v9fs_file_open(struct inode *inode, struct file *file); ...@@ -52,3 +52,5 @@ int v9fs_file_open(struct inode *inode, struct file *file);
void v9fs_inode2stat(struct inode *inode, struct p9_stat *stat); void v9fs_inode2stat(struct inode *inode, struct p9_stat *stat);
void v9fs_dentry_release(struct dentry *); void v9fs_dentry_release(struct dentry *);
int v9fs_uflags2omode(int uflags, int extended); int v9fs_uflags2omode(int uflags, int extended);
ssize_t v9fs_file_readn(struct file *, char *, char __user *, u32, u64);
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "v9fs.h" #include "v9fs.h"
#include "v9fs_vfs.h" #include "v9fs_vfs.h"
#include "fid.h"
/** /**
* v9fs_vfs_readpage - read an entire page in from 9P * v9fs_vfs_readpage - read an entire page in from 9P
...@@ -53,14 +52,12 @@ static int v9fs_vfs_readpage(struct file *filp, struct page *page) ...@@ -53,14 +52,12 @@ static int v9fs_vfs_readpage(struct file *filp, struct page *page)
int retval; int retval;
loff_t offset; loff_t offset;
char *buffer; char *buffer;
struct p9_fid *fid;
P9_DPRINTK(P9_DEBUG_VFS, "\n"); P9_DPRINTK(P9_DEBUG_VFS, "\n");
fid = filp->private_data;
buffer = kmap(page); buffer = kmap(page);
offset = page_offset(page); offset = page_offset(page);
retval = p9_client_readn(fid, buffer, offset, PAGE_CACHE_SIZE); retval = v9fs_file_readn(filp, buffer, NULL, offset, PAGE_CACHE_SIZE);
if (retval < 0) if (retval < 0)
goto done; goto done;
......
...@@ -120,23 +120,72 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl) ...@@ -120,23 +120,72 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
} }
/** /**
* v9fs_file_read - read from a file * v9fs_file_readn - read from a file
* @filp: file pointer to read * @filp: file pointer to read
* @data: data buffer to read data into * @data: data buffer to read data into
* @udata: user data buffer to read data into
* @count: size of buffer * @count: size of buffer
* @offset: offset at which to read data * @offset: offset at which to read data
* *
*/ */
ssize_t
v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count,
u64 offset)
{
int n, total;
struct p9_fid *fid = filp->private_data;
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu count %d\n", fid->fid,
(long long unsigned) offset, count);
n = 0;
total = 0;
do {
n = p9_client_read(fid, data, udata, offset, count);
if (n <= 0)
break;
if (data)
data += n;
if (udata)
udata += n;
offset += n;
count -= n;
total += n;
} while (count > 0 && n == (fid->clnt->msize - P9_IOHDRSZ));
if (n < 0)
total = n;
return total;
}
/**
* v9fs_file_read - read from a file
* @filp: file pointer to read
* @udata: user data buffer to read data into
* @count: size of buffer
* @offset: offset at which to read data
*
*/
static ssize_t static ssize_t
v9fs_file_read(struct file *filp, char __user * data, size_t count, v9fs_file_read(struct file *filp, char __user *udata, size_t count,
loff_t * offset) loff_t * offset)
{ {
int ret; int ret;
struct p9_fid *fid; struct p9_fid *fid;
P9_DPRINTK(P9_DEBUG_VFS, "\n"); P9_DPRINTK(P9_DEBUG_VFS, "count %d offset %lld\n", count, *offset);
fid = filp->private_data; fid = filp->private_data;
ret = p9_client_read(fid, NULL, data, *offset, count);
if (count > (fid->clnt->msize - P9_IOHDRSZ))
ret = v9fs_file_readn(filp, NULL, udata, count, *offset);
else
ret = p9_client_read(fid, NULL, udata, *offset, count);
if (ret > 0) if (ret > 0)
*offset += ret; *offset += ret;
......
...@@ -203,7 +203,6 @@ int p9_client_clunk(struct p9_fid *fid); ...@@ -203,7 +203,6 @@ int p9_client_clunk(struct p9_fid *fid);
int p9_client_remove(struct p9_fid *fid); int p9_client_remove(struct p9_fid *fid);
int p9_client_read(struct p9_fid *fid, char *data, char __user *udata, int p9_client_read(struct p9_fid *fid, char *data, char __user *udata,
u64 offset, u32 count); u64 offset, u32 count);
int p9_client_readn(struct p9_fid *fid, char *data, u64 offset, u32 count);
int p9_client_write(struct p9_fid *fid, char *data, const char __user *udata, int p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
u64 offset, u32 count); u64 offset, u32 count);
struct p9_stat *p9_client_stat(struct p9_fid *fid); struct p9_stat *p9_client_stat(struct p9_fid *fid);
......
...@@ -1150,32 +1150,6 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata, ...@@ -1150,32 +1150,6 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
} }
EXPORT_SYMBOL(p9_client_write); EXPORT_SYMBOL(p9_client_write);
int p9_client_readn(struct p9_fid *fid, char *data, u64 offset, u32 count)
{
int n, total;
P9_DPRINTK(P9_DEBUG_9P, "fid %d offset %llu count %d\n", fid->fid,
(long long unsigned) offset, count);
n = 0;
total = 0;
while (count) {
n = p9_client_read(fid, data, NULL, offset, count);
if (n <= 0)
break;
data += n;
offset += n;
count -= n;
total += n;
}
if (n < 0)
total = n;
return total;
}
EXPORT_SYMBOL(p9_client_readn);
static struct p9_stat *p9_clone_stat(struct p9_stat *st, int dotu) static struct p9_stat *p9_clone_stat(struct p9_stat *st, int dotu)
{ {
int n; int n;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment