Commit 19cba8ab authored by Latchesar Ionkov's avatar Latchesar Ionkov Committed by Linus Torvalds

[PATCH] v9fs: remove additional buffer allocation from v9fs_file_read and v9fs_file_write

v9fs_file_read and v9fs_file_write use kmalloc to allocate buffers as big
as the data buffer received as parameter.  kmalloc cannot be used to
allocate buffers bigger than 128K, so reading/writing data in chunks bigger
than 128k fails.

This patch reorganizes v9fs_file_read and v9fs_file_write to allocate only
buffers as big as the maximum data that can be sent in one 9P message.
Signed-off-by: default avatarLatchesar Ionkov <lucho@ionkov.net>
Cc: Eric Van Hensbergen <ericvh@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ad6ce87e
...@@ -175,16 +175,16 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl) ...@@ -175,16 +175,16 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
} }
/** /**
* v9fs_read - read from a file (internal) * v9fs_file_read - read from a file
* @filep: file pointer to read * @filep: file pointer to read
* @data: data buffer to read data into * @data: 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
* *
*/ */
static ssize_t static ssize_t
v9fs_read(struct file *filp, char *buffer, size_t count, loff_t * offset) v9fs_file_read(struct file *filp, char __user * data, size_t count,
loff_t * offset)
{ {
struct inode *inode = filp->f_dentry->d_inode; struct inode *inode = filp->f_dentry->d_inode;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
...@@ -194,6 +194,7 @@ v9fs_read(struct file *filp, char *buffer, size_t count, loff_t * offset) ...@@ -194,6 +194,7 @@ v9fs_read(struct file *filp, char *buffer, size_t count, loff_t * offset)
int rsize = 0; int rsize = 0;
int result = 0; int result = 0;
int total = 0; int total = 0;
int n;
dprintk(DEBUG_VFS, "\n"); dprintk(DEBUG_VFS, "\n");
...@@ -216,10 +217,15 @@ v9fs_read(struct file *filp, char *buffer, size_t count, loff_t * offset) ...@@ -216,10 +217,15 @@ v9fs_read(struct file *filp, char *buffer, size_t count, loff_t * offset)
} else } else
*offset += result; *offset += result;
/* XXX - extra copy */ n = copy_to_user(data, fcall->params.rread.data, result);
memcpy(buffer, fcall->params.rread.data, result); if (n) {
dprintk(DEBUG_ERROR, "Problem copying to user %d\n", n);
kfree(fcall);
return -EFAULT;
}
count -= result; count -= result;
buffer += result; data += result;
total += result; total += result;
kfree(fcall); kfree(fcall);
...@@ -232,42 +238,7 @@ v9fs_read(struct file *filp, char *buffer, size_t count, loff_t * offset) ...@@ -232,42 +238,7 @@ v9fs_read(struct file *filp, char *buffer, size_t count, loff_t * offset)
} }
/** /**
* v9fs_file_read - read from a file * v9fs_file_write - write to a file
* @filep: file pointer to read
* @data: data buffer to read data into
* @count: size of buffer
* @offset: offset at which to read data
*
*/
static ssize_t
v9fs_file_read(struct file *filp, char __user * data, size_t count,
loff_t * offset)
{
int retval = -1;
int ret = 0;
char *buffer;
buffer = kmalloc(count, GFP_KERNEL);
if (!buffer)
return -ENOMEM;
retval = v9fs_read(filp, buffer, count, offset);
if (retval > 0) {
if ((ret = copy_to_user(data, buffer, retval)) != 0) {
dprintk(DEBUG_ERROR, "Problem copying to user %d\n",
ret);
retval = ret;
}
}
kfree(buffer);
return retval;
}
/**
* v9fs_write - write to a file
* @filep: file pointer to write * @filep: file pointer to write
* @data: data buffer to write data from * @data: data buffer to write data from
* @count: size of buffer * @count: size of buffer
...@@ -276,7 +247,8 @@ v9fs_file_read(struct file *filp, char __user * data, size_t count, ...@@ -276,7 +247,8 @@ v9fs_file_read(struct file *filp, char __user * data, size_t count,
*/ */
static ssize_t static ssize_t
v9fs_write(struct file *filp, char *buffer, size_t count, loff_t * offset) v9fs_file_write(struct file *filp, const char __user * data,
size_t count, loff_t * offset)
{ {
struct inode *inode = filp->f_dentry->d_inode; struct inode *inode = filp->f_dentry->d_inode;
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
...@@ -286,30 +258,42 @@ v9fs_write(struct file *filp, char *buffer, size_t count, loff_t * offset) ...@@ -286,30 +258,42 @@ v9fs_write(struct file *filp, char *buffer, size_t count, loff_t * offset)
int result = -EIO; int result = -EIO;
int rsize = 0; int rsize = 0;
int total = 0; int total = 0;
char *buf;
dprintk(DEBUG_VFS, "data %p count %d offset %x\n", buffer, (int)count, dprintk(DEBUG_VFS, "data %p count %d offset %x\n", data, (int)count,
(int)*offset); (int)*offset);
rsize = v9ses->maxdata - V9FS_IOHDRSZ; rsize = v9ses->maxdata - V9FS_IOHDRSZ;
if (v9fid->iounit != 0 && rsize > v9fid->iounit) if (v9fid->iounit != 0 && rsize > v9fid->iounit)
rsize = v9fid->iounit; rsize = v9fid->iounit;
dump_data(buffer, count); buf = kmalloc(v9ses->maxdata - V9FS_IOHDRSZ, GFP_KERNEL);
if (!buf)
return -ENOMEM;
do { do {
if (count < rsize) if (count < rsize)
rsize = count; rsize = count;
result = result = copy_from_user(buf, data, rsize);
v9fs_t_write(v9ses, fid, *offset, rsize, buffer, &fcall); if (result) {
dprintk(DEBUG_ERROR, "Problem copying from user\n");
kfree(buf);
return -EFAULT;
}
dump_data(buf, rsize);
result = v9fs_t_write(v9ses, fid, *offset, rsize, buf, &fcall);
if (result < 0) { if (result < 0) {
eprintk(KERN_ERR, "error while writing: %s(%d)\n", eprintk(KERN_ERR, "error while writing: %s(%d)\n",
FCALL_ERROR(fcall), result); FCALL_ERROR(fcall), result);
kfree(fcall); kfree(fcall);
kfree(buf);
return result; return result;
} else } else
*offset += result; *offset += result;
kfree(fcall); kfree(fcall);
fcall = NULL;
if (result != rsize) { if (result != rsize) {
eprintk(KERN_ERR, eprintk(KERN_ERR,
...@@ -319,46 +303,14 @@ v9fs_write(struct file *filp, char *buffer, size_t count, loff_t * offset) ...@@ -319,46 +303,14 @@ v9fs_write(struct file *filp, char *buffer, size_t count, loff_t * offset)
} }
count -= result; count -= result;
buffer += result; data += result;
total += result; total += result;
} while (count); } while (count);
kfree(buf);
return total; return total;
} }
/**
* v9fs_file_write - write to a file
* @filep: file pointer to write
* @data: data buffer to write data from
* @count: size of buffer
* @offset: offset at which to write data
*
*/
static ssize_t
v9fs_file_write(struct file *filp, const char __user * data,
size_t count, loff_t * offset)
{
int ret = -1;
char *buffer;
buffer = kmalloc(count, GFP_KERNEL);
if (buffer == NULL)
return -ENOMEM;
ret = copy_from_user(buffer, data, count);
if (ret) {
dprintk(DEBUG_ERROR, "Problem copying from user\n");
ret = -EFAULT;
} else {
ret = v9fs_write(filp, buffer, count, offset);
}
kfree(buffer);
return ret;
}
struct file_operations v9fs_file_operations = { struct file_operations v9fs_file_operations = {
.llseek = generic_file_llseek, .llseek = generic_file_llseek,
.read = v9fs_file_read, .read = v9fs_file_read,
......
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