Skip to contentSkip to conversation

9p: marshalling to/from scatter list

PATCH In review Latchesar Ionkov 1 participant 1 message Nov 2, 2007

Subsystems (3)
lore
Share & tools
lore

Latchesar Ionkov

author maintainer
#0 lore raw

PATCH 10/10 9p: marshalling to/from scatter list

In order to achieve zero-copy of the data in the 9P client and server code, the marshalling code needs to be modified to serialize/deserialize to a scatterlist instead of continuous memory block.

---
 fs/9p/v9fs_vfs.h        |    2 +-
 fs/9p/vfs_dir.c         |    8 +-
 fs/9p/vfs_inode.c       |   32 +-
 fs/9p/vfs_super.c       |    2 +-
 include/net/9p/9p.h     |   65 ++--
 include/net/9p/client.h |    8 +-
 net/9p/client.c         |  122 ++++---
 net/9p/conv.c           | 1048 ++++++++++++++++++++++++++++++++++------------
 net/9p/fcprint.c        |  116 +++---
 net/9p/ramfs/ramfs.c    |   28 +-
 net/9p/srv.c            |   18 +-
 11 files changed, 992 insertions(+), 457 deletions(-)
fs/9p/v9fs_vfs.h +1 -1
index fd01d90..f2681fb 100644
@@ -46,7 +46,7 @@ extern struct dentry_operations v9fs_cached_dentry_operations;
 
 struct inode *v9fs_get_inode(struct super_block *sb, int mode);
 ino_t v9fs_qid2ino(struct p9_qid *qid);
-void v9fs_stat2inode(struct p9_stat *, struct inode *, struct super_block *);
+void v9fs_stat2inode(struct p9_wstat *, struct inode *, struct super_block *);
 int v9fs_dir_release(struct inode *inode, struct file *filp);
 int v9fs_file_open(struct inode *inode, struct file *file);
 void v9fs_inode2stat(struct inode *inode, struct p9_stat *stat);
fs/9p/vfs_dir.c +4 -4
index 0924d44..6c87fcb 100644
@@ -45,7 +45,7 @@
  *
  */
 
-static inline int dt_type(struct p9_stat *mistat)
+static inline int dt_type(struct p9_wstat *mistat)
 {
 	unsigned long perm = mistat->mode;
 	int rettype = DT_REG;
@@ -72,7 +72,7 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
 	struct p9_fid *fid;
 	struct v9fs_session_info *v9ses;
 	struct inode *inode;
-	struct p9_stat *st;
+	struct p9_wstat *st;
 
 	P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
 	inode = filp->f_path.dentry->d_inode;
@@ -82,13 +82,13 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
 		if (IS_ERR(st))
 			return PTR_ERR(st);
 
-		over = filldir(dirent, st->name.str, st->name.len, filp->f_pos,
+		over = filldir(dirent, st->name, strlen(st->name), filp->f_pos,
 			v9fs_qid2ino(&st->qid), dt_type(st));
 
 		if (over)
 			break;
 
-		filp->f_pos += st->size;
+		filp->f_pos += st->size + 2;
 		kfree(st);
 		st = NULL;
 	}
fs/9p/vfs_inode.c +10 -22
index 23581bc..44e5a5f 100644
@@ -313,7 +313,7 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
 {
 	int err, umode;
 	struct inode *ret;
-	struct p9_stat *st;
+	struct p9_wstat *st;
 
 	ret = NULL;
 	st = p9_client_stat(fid);
@@ -711,7 +711,7 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
 	int err;
 	struct v9fs_session_info *v9ses;
 	struct p9_fid *fid;
-	struct p9_stat *st;
+	struct p9_wstat *st;
 
 	P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
 	err = -EPERM;
@@ -792,11 +792,9 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
  */
 
 void
-v9fs_stat2inode(struct p9_stat *stat, struct inode *inode,
+v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
 	struct super_block *sb)
 {
-	int n;
-	char ext[32];
 	struct v9fs_session_info *v9ses = sb->s_fs_info;
 
 	inode->i_nlink = 1;
@@ -819,12 +817,7 @@ v9fs_stat2inode(struct p9_stat *stat, struct inode *inode,
 		int major = -1;
 		int minor = -1;
 
-		n = stat->extension.len;
-		if (n > sizeof(ext)-1)
-			n = sizeof(ext)-1;
-		memmove(ext, stat->extension.str, n);
-		ext[n] = 0;
-		sscanf(ext, "%c %u %u", &type, &major, &minor);
+		sscanf(stat->extension, "%c %u %u", &type, &major, &minor);
 		switch (type) {
 		case 'c':
 			inode->i_mode &= ~S_IFBLK;
@@ -834,8 +827,8 @@ v9fs_stat2inode(struct p9_stat *stat, struct inode *inode,
 			break;
 		default:
 			P9_DPRINTK(P9_DEBUG_ERROR,
-				"Unknown special type %c (%.*s)\n", type,
-				stat->extension.len, stat->extension.str);
+				"Unknown special type %c (%s)\n", type,
+				stat->extension);
 		};
 		inode->i_rdev = MKDEV(major, minor);
 	} else
@@ -881,7 +874,7 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
 
 	struct v9fs_session_info *v9ses;
 	struct p9_fid *fid;
-	struct p9_stat *st;
+	struct p9_wstat *st;
 
 	P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name);
 	retval = -EPERM;
@@ -903,17 +896,12 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
 	}
 
 	/* copy extension buffer into buffer */
-	if (st->extension.len < buflen)
-		buflen = st->extension.len + 1;
-
-	memmove(buffer, st->extension.str, buflen - 1);
-	buffer[buflen-1] = 0;
+	strncpy(buffer, st->extension, buflen);
 
 	P9_DPRINTK(P9_DEBUG_VFS,
-		"%s -> %.*s (%s)\n", dentry->d_name.name, st->extension.len,
-		st->extension.str, buffer);
+		"%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer);
 
-	retval = buflen;
+	retval = strlen(buffer);
 
 done:
 	kfree(st);
fs/9p/vfs_super.c +1 -1
index bb0cef9..2f85f20 100644
@@ -110,7 +110,7 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags,
 	struct inode *inode = NULL;
 	struct dentry *root = NULL;
 	struct v9fs_session_info *v9ses = NULL;
-	struct p9_stat *st = NULL;
+	struct p9_wstat *st = NULL;
 	int mode = S_IRWXUGO | S_ISVTX;
 	uid_t uid = current->fsuid;
 	gid_t gid = current->fsgid;
include/net/9p/9p.h +40 -25

155 lines not on this page · raw message

include/net/9p/client.h +6 -2
index 5efb57a..343ccbf 100644
@@ -74,9 +74,13 @@ int p9_client_uread(struct p9_fid *fid, char __user *data, u64 offset,
 								u32 count);
 int p9_client_uwrite(struct p9_fid *fid, const char __user *data, u64 offset,
 								u32 count);
-struct p9_stat *p9_client_stat(struct p9_fid *fid);
+int p9_client_read_sg(struct p9_fid *fid, u64 offset, u32 count,
+	struct scatterlist *sg, int sglen);
+int p9_client_write_sg(struct p9_fid *fid, u64 offset, u32 count,
+	struct scatterlist *sg, int sglen);
+struct p9_wstat *p9_client_stat(struct p9_fid *fid);
 int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst);
-struct p9_stat *p9_client_dirread(struct p9_fid *fid, u64 offset);
+struct p9_wstat *p9_client_dirread(struct p9_fid *fid, u64 offset);
 
 void p9_client_req_incref(struct p9_trans_req *req);
 void p9_client_req_decref(struct p9_trans_req *req);
net/9p/client.c +72 -50

235 lines not on this page · raw message

net/9p/conv.c +774 -274

1,501 lines not on this page · raw message

net/9p/fcprint.c +65 -51

216 lines not on this page · raw message

net/9p/ramfs/ramfs.c +9 -19
index 3aff620..2b6386b 100644
@@ -3,7 +3,7 @@
  *
  * Simple RAM filesystem
  *
- *  Copyright (C) 2007 by Latchesar Ionkov <[email protected]>
+ *  Copyright (C) 200xz7 by Latchesar Ionkov <[email protected]>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2
@@ -97,17 +97,6 @@ static void ramfs_fiddestroy(struct p9srv_fid *fid);
 static void ramfs_connopen(struct p9srv_conn *conn);
 static void ramfs_connclose(struct p9srv_conn *conn);
 
-static char *p9_strdup(struct p9_str *str)
-{
-	char *ret;
-
-	ret = kmalloc(str->len + 1, GFP_KERNEL);
-	memmove(ret, str->str, str->len);
-	ret[str->len] = '\0';
-
-	return ret;
-}
-
 static void file_incref(struct ramfs_file *f)
 {
 	if (!f)
@@ -573,7 +562,7 @@ static void ramfs_read(struct p9srv_req *req)
 	struct ramfs_fid *fid;
 	struct ramfs_file *file, *cf;
 	struct p9_wstat wstat;
-	u8 *data;
+	struct p9_data data;
 
 	tc = req->tcall;
 	rc = req->rcall;
@@ -592,14 +581,14 @@ static void ramfs_read(struct p9srv_req *req)
 			fid->diroffset = 0;
 		}
 
+		n = 0;
 		cf = fid->dirent;
 		for (n = 0, cf = fid->dirent; (n < count) && (cf != NULL);
 							cf = cf->next) {
 			BUG_ON(test_bit(Removed, &cf->status));
 			file2wstat(cf, &wstat);
 			P9_DPRINTK(P9SRV_DEBUG_FS, "name %s\n", wstat.name);
-			i = p9_serialize_stat(&wstat, data + n, count - n - 1,
-				req->conn->dotu);
+			i = p9_serialize_stat(&wstat, &data, req->conn->dotu);
 			if (i == 0)
 				break;
 
@@ -619,7 +608,7 @@ static void ramfs_read(struct p9srv_req *req)
 		if (n < 0)
 			n = 0;
 
-		memmove(data, file->data + offset, n);
+		p9_data_put(&data, file->data + offset, n);
 	}
 
 /*
@@ -675,7 +664,8 @@ static void ramfs_write(struct p9srv_req *req)
 	}
 
 	if (count)
-		memmove(file->data + offset, tc->params.twrite.data, count);
+		p9_data_get(file->data + offset, count,
+					&tc->params.twrite.data);
 
 	mutex_lock(&file->lock);
 	file->qid.version++;
@@ -809,12 +799,12 @@ static void ramfs_wstat(struct p9srv_req *req)
 	mutex_lock(&file->lock);
 	lockfile = 1;
 
-	lockparent = stat->name.len != 0 && file->parent != file;
+	lockparent = stat->name.length != 0 && file->parent != file;
 	if (lockparent)
 		mutex_lock(&file->parent->lock);
 
 	oldname = NULL;
-	if (stat->name.len != 0) {
+	if (stat->name.length != 0) {
 		if (!check_perm(req, file->parent, req->fid->uid, 2))
 			goto out;
 
net/9p/srv.c +10 -8
index 1541ece..fade82d 100644
@@ -330,6 +330,7 @@ static void p9srv_preq_work(struct work_struct *work)
 	if (tc->id < P9_FIRST || tc->id > P9_LAST ||
 		!p9srv_fcall[(tc->id - P9_FIRST)/2] || tc->id%2 == 1) {
 
+		P9_DPRINTK(P9SRV_DEBUG_SRV, "unsupported message %d\n", tc->id);
 		p9srv_respond_error(req, "unsupported message", EIO);
 		return;
 	}
@@ -739,7 +740,7 @@ EXPORT_SYMBOL(p9srv_listener_del);
 static void p9srv_version(struct p9srv_req *req)
 {
 	int msize;
-	struct p9_str *version;
+	char *version;
 	struct p9srv *srv;
 	struct p9srv_conn *conn;
 	struct p9_fcall *tc;
@@ -754,14 +755,14 @@ static void p9srv_version(struct p9srv_req *req)
 		return;
 	}
 
-	version = &tc->params.tversion.version;
-	if ((version->len != 8 || memcmp(version->str, "9P2000.u", 8)) &&
-		(version->len != 6 || memcmp(version->str, "9P2000", 6))) {
-
+	version = p9_strdup(&tc->params.tversion.version);
+	if (strcmp(version, "9P2000.u") && strcmp(version, "9P2000")) {
 		p9srv_respond_error(req, "unsupported protocol version", EIO);
+		kfree(version);
 		return;
 	}
 
+	kfree(version);
 	p9srv_conn_reset(conn, req);
 	p9_create_rversion(req->rcall, conn->msize,
 		conn->dotu?"9P2000.u":"9P2000");
@@ -1497,7 +1498,7 @@ EXPORT_SYMBOL(p9srv_conn_destroy);
 void p9srv_conn_reset(struct p9srv_conn *conn, struct p9srv_req *vreq)
 {
 	int i, n;
-	struct p9_str *version;
+	char *version;
 	struct p9srv *srv;
 	struct p9srv_req *req, *rptr;
 	struct p9srv_req *wreqs[16];
@@ -1560,9 +1561,10 @@ again:
 			conn->msize = srv->msize;
 
 		conn->dotu = srv->dotu;
-		version = &vreq->tcall->params.tversion.version;
-		if (version->len != 8 || memcmp(version->str, "9P2000.u", 8) != 0)
+		version = p9_strdup(&vreq->tcall->params.tversion.version);
+		if (strcmp(version, "9P2000.u"))
 			conn->dotu = 0;
+		kfree(version);
 	}
 
 	clear_bit(Reset, &conn->status);