Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3cf6429a authored by Latchesar Ionkov's avatar Latchesar Ionkov Committed by Linus Torvalds
Browse files

[PATCH] v9fs: new multiplexer implementation



New multiplexer implementation. Decreases the number of kernel threads
required. Better handling when the user process receives a signal.

Signed-off-by: default avatarLatchesar Ionkov <lucho@ionkov.net>
Cc: Eric Van Hensbergen <ericvh@ericvh.myip.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent f5ef3c10
Loading
Loading
Loading
Loading
+49 −19
Original line number Diff line number Diff line
@@ -52,10 +52,11 @@ v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,

	dprintk(DEBUG_9P, "msize: %d version: %s\n", msize, version);
	msg.id = TVERSION;
	msg.tag = ~0;
	msg.params.tversion.msize = msize;
	msg.params.tversion.version = version;

	return v9fs_mux_rpc(v9ses, &msg, fcall);
	return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
}

/**
@@ -83,7 +84,30 @@ v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
	msg.params.tattach.uname = uname;
	msg.params.tattach.aname = aname;

	return v9fs_mux_rpc(v9ses, &msg, fcall);
	return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
}

static void v9fs_t_clunk_cb(void *a, struct v9fs_fcall *tc,
	struct v9fs_fcall *rc, int err)
{
	int fid;
	struct v9fs_session_info *v9ses;

	if (err)
		return;

	fid = tc->params.tclunk.fid;
	kfree(tc);

	if (!rc)
		return;

	dprintk(DEBUG_9P, "tcall id %d rcall id %d\n", tc->id, rc->id);
	v9ses = a;
	if (rc->id == RCLUNK)
		v9fs_put_idpool(fid, &v9ses->fidpool);

	kfree(rc);
}

/**
@@ -93,18 +117,24 @@ v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
 * @fcall: pointer to response fcall pointer
 *
 */

int
v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid,
	     struct v9fs_fcall **fcall)
v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid)
{
	struct v9fs_fcall msg;
	int err;
	struct v9fs_fcall *tc, *rc;

	tc = kmalloc(sizeof(struct v9fs_fcall), GFP_KERNEL);

	dprintk(DEBUG_9P, "fid %d\n", fid);
	msg.id = TCLUNK;
	msg.params.tclunk.fid = fid;
	tc->id = TCLUNK;
	tc->params.tclunk.fid = fid;

	err = v9fs_mux_rpc(v9ses->mux, tc, &rc);
	if (err >= 0) {
		v9fs_t_clunk_cb(v9ses, tc, rc, 0);
	}

	return v9fs_mux_rpc(v9ses, &msg, fcall);
	return err;
}

/**
@@ -121,7 +151,7 @@ int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 tag)
	dprintk(DEBUG_9P, "oldtag %d\n", tag);
	msg.id = TFLUSH;
	msg.params.tflush.oldtag = tag;
	return v9fs_mux_rpc(v9ses, &msg, NULL);
	return v9fs_mux_rpc(v9ses->mux, &msg, NULL);
}

/**
@@ -143,7 +173,7 @@ v9fs_t_stat(struct v9fs_session_info *v9ses, u32 fid, struct v9fs_fcall **fcall)

	msg.id = TSTAT;
	msg.params.tstat.fid = fid;
	return v9fs_mux_rpc(v9ses, &msg, fcall);
	return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
}

/**
@@ -166,7 +196,7 @@ v9fs_t_wstat(struct v9fs_session_info *v9ses, u32 fid,
	msg.params.twstat.fid = fid;
	msg.params.twstat.stat = stat;

	return v9fs_mux_rpc(v9ses, &msg, fcall);
	return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
}

/**
@@ -199,7 +229,7 @@ v9fs_t_walk(struct v9fs_session_info *v9ses, u32 fid, u32 newfid,
		msg.params.twalk.nwname = 0;
	}

	return v9fs_mux_rpc(v9ses, &msg, fcall);
	return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
}

/**
@@ -217,14 +247,14 @@ v9fs_t_open(struct v9fs_session_info *v9ses, u32 fid, u8 mode,
	    struct v9fs_fcall **fcall)
{
	struct v9fs_fcall msg;
	long errorno = -1;
	int errorno = -1;

	dprintk(DEBUG_9P, "fid %d mode %d\n", fid, mode);
	msg.id = TOPEN;
	msg.params.topen.fid = fid;
	msg.params.topen.mode = mode;

	errorno = v9fs_mux_rpc(v9ses, &msg, fcall);
	errorno = v9fs_mux_rpc(v9ses->mux, &msg, fcall);

	return errorno;
}
@@ -246,7 +276,7 @@ v9fs_t_remove(struct v9fs_session_info *v9ses, u32 fid,
	dprintk(DEBUG_9P, "fid %d\n", fid);
	msg.id = TREMOVE;
	msg.params.tremove.fid = fid;
	return v9fs_mux_rpc(v9ses, &msg, fcall);
	return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
}

/**
@@ -275,7 +305,7 @@ v9fs_t_create(struct v9fs_session_info *v9ses, u32 fid, char *name,
	msg.params.tcreate.perm = perm;
	msg.params.tcreate.mode = mode;

	return v9fs_mux_rpc(v9ses, &msg, fcall);
	return v9fs_mux_rpc(v9ses->mux, &msg, fcall);
}

/**
@@ -302,7 +332,7 @@ v9fs_t_read(struct v9fs_session_info *v9ses, u32 fid, u64 offset,
	msg.params.tread.fid = fid;
	msg.params.tread.offset = offset;
	msg.params.tread.count = count;
	errorno = v9fs_mux_rpc(v9ses, &msg, &rc);
	errorno = v9fs_mux_rpc(v9ses->mux, &msg, &rc);

	if (!errorno) {
		errorno = rc->params.rread.count;
@@ -345,7 +375,7 @@ v9fs_t_write(struct v9fs_session_info *v9ses, u32 fid,
	msg.params.twrite.count = count;
	msg.params.twrite.data = data;

	errorno = v9fs_mux_rpc(v9ses, &msg, &rc);
	errorno = v9fs_mux_rpc(v9ses->mux, &msg, &rc);

	if (!errorno)
		errorno = rc->params.rwrite.count;
+7 −2
Original line number Diff line number Diff line
@@ -100,6 +100,9 @@ enum {
	V9FS_QTFILE = 0x00,
};

#define V9FS_NOTAG	(u16)(~0)
#define V9FS_NOFID	(u32)(~0)

/* ample room for Twrite/Rread header (iounit) */
#define V9FS_IOHDRSZ	24

@@ -303,6 +306,9 @@ struct v9fs_fcall {
	} params;
};

#define V9FS_FCALLHDRSZ (sizeof(struct v9fs_fcall) + \
	sizeof(struct v9fs_stat) + 16*sizeof(struct v9fs_qid) + 16)

#define FCALL_ERROR(fcall) (fcall ? fcall->params.rerror.error : "")

int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
@@ -311,8 +317,7 @@ int v9fs_t_version(struct v9fs_session_info *v9ses, u32 msize,
int v9fs_t_attach(struct v9fs_session_info *v9ses, char *uname, char *aname,
		  u32 fid, u32 afid, struct v9fs_fcall **rcall);

int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid,
		 struct v9fs_fcall **rcall);
int v9fs_t_clunk(struct v9fs_session_info *v9ses, u32 fid);

int v9fs_t_flush(struct v9fs_session_info *v9ses, u16 oldtag);

+45 −41
Original line number Diff line number Diff line
@@ -252,13 +252,12 @@ static inline void *buf_get_datab(struct cbuf *buf, struct cbuf *dbuf,

/**
 * v9fs_size_stat - calculate the size of a variable length stat struct
 * @v9ses: session information
 * @stat: metadata (stat) structure
 * @extended: non-zero if 9P2000.u
 *
 */

static int v9fs_size_stat(struct v9fs_session_info *v9ses,
			  struct v9fs_stat *stat)
static int v9fs_size_stat(struct v9fs_stat *stat, int extended)
{
	int size = 0;

@@ -288,7 +287,7 @@ static int v9fs_size_stat(struct v9fs_session_info *v9ses,
	if (stat->muid)
		size += strlen(stat->muid);

	if (v9ses->extended) {
	if (extended) {
		size += 4 +	/* n_uid[4] */
		    4 +		/* n_gid[4] */
		    4 +		/* n_muid[4] */
@@ -302,15 +301,14 @@ static int v9fs_size_stat(struct v9fs_session_info *v9ses,

/**
 * serialize_stat - safely format a stat structure for transmission
 * @v9ses: session info
 * @stat: metadata (stat) structure
 * @bufp: buffer to serialize structure into
 * @extended: non-zero if 9P2000.u
 *
 */

static int
serialize_stat(struct v9fs_session_info *v9ses, struct v9fs_stat *stat,
	       struct cbuf *bufp)
serialize_stat(struct v9fs_stat *stat, struct cbuf *bufp, int extended)
{
	buf_put_int16(bufp, stat->size);
	buf_put_int16(bufp, stat->type);
@@ -328,7 +326,7 @@ serialize_stat(struct v9fs_session_info *v9ses, struct v9fs_stat *stat,
	buf_put_string(bufp, stat->gid);
	buf_put_string(bufp, stat->muid);

	if (v9ses->extended) {
	if (extended) {
		buf_put_string(bufp, stat->extension);
		buf_put_int32(bufp, stat->n_uid);
		buf_put_int32(bufp, stat->n_gid);
@@ -343,16 +341,16 @@ serialize_stat(struct v9fs_session_info *v9ses, struct v9fs_stat *stat,

/**
 * deserialize_stat - safely decode a recieved metadata (stat) structure
 * @v9ses: session info
 * @bufp: buffer to deserialize
 * @stat: metadata (stat) structure
 * @dbufp: buffer to deserialize variable strings into
 * @extended: non-zero if 9P2000.u
 *
 */

static inline int
deserialize_stat(struct v9fs_session_info *v9ses, struct cbuf *bufp,
		 struct v9fs_stat *stat, struct cbuf *dbufp)
deserialize_stat(struct cbuf *bufp, struct v9fs_stat *stat,
		 struct cbuf *dbufp, int extended)
{

	stat->size = buf_get_int16(bufp);
@@ -370,7 +368,7 @@ deserialize_stat(struct v9fs_session_info *v9ses, struct cbuf *bufp,
	stat->gid = buf_get_stringb(bufp, dbufp);
	stat->muid = buf_get_stringb(bufp, dbufp);

	if (v9ses->extended) {
	if (extended) {
		stat->extension = buf_get_stringb(bufp, dbufp);
		stat->n_uid = buf_get_int32(bufp);
		stat->n_gid = buf_get_int32(bufp);
@@ -385,20 +383,20 @@ deserialize_stat(struct v9fs_session_info *v9ses, struct cbuf *bufp,

/**
 * deserialize_statb - wrapper for decoding a received metadata structure
 * @v9ses: session info
 * @bufp: buffer to deserialize
 * @dbufp: buffer to deserialize variable strings into
 * @extended: non-zero if 9P2000.u
 *
 */

static inline struct v9fs_stat *deserialize_statb(struct v9fs_session_info
						  *v9ses, struct cbuf *bufp,
						  struct cbuf *dbufp)
static inline struct v9fs_stat *deserialize_statb(struct cbuf *bufp,
						  struct cbuf *dbufp,
						  int extended)
{
	struct v9fs_stat *ret = buf_alloc(dbufp, sizeof(struct v9fs_stat));

	if (ret) {
		int n = deserialize_stat(v9ses, bufp, ret, dbufp);
		int n = deserialize_stat(bufp, ret, dbufp, extended);
		if (n <= 0)
			return NULL;
	}
@@ -408,17 +406,16 @@ static inline struct v9fs_stat *deserialize_statb(struct v9fs_session_info

/**
 * v9fs_deserialize_stat - decode a received metadata structure
 * @v9ses: session info
 * @buf: buffer to deserialize
 * @buflen: length of received buffer
 * @stat: metadata structure to decode into
 * @statlen: length of destination metadata structure
 * @extended: non-zero if 9P2000.u
 *
 */

int
v9fs_deserialize_stat(struct v9fs_session_info *v9ses, void *buf,
		      u32 buflen, struct v9fs_stat *stat, u32 statlen)
int v9fs_deserialize_stat(void *buf, u32 buflen, struct v9fs_stat *stat,
			  u32 statlen, int extended)
{
	struct cbuf buffer;
	struct cbuf *bufp = &buffer;
@@ -429,11 +426,10 @@ v9fs_deserialize_stat(struct v9fs_session_info *v9ses, void *buf,
	buf_init(dbufp, (char *)stat + sizeof(struct v9fs_stat),
		 statlen - sizeof(struct v9fs_stat));

	return deserialize_stat(v9ses, bufp, stat, dbufp);
	return deserialize_stat(bufp, stat, dbufp, extended);
}

static inline int
v9fs_size_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall)
static inline int v9fs_size_fcall(struct v9fs_fcall *fcall, int extended)
{
	int size = 4 + 1 + 2;	/* size[4] msg[1] tag[2] */
	int i = 0;
@@ -485,7 +481,7 @@ v9fs_size_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall)
		break;
	case TWSTAT:		/* fid[4] stat[n] */
		fcall->params.twstat.stat->size =
		    v9fs_size_stat(v9ses, fcall->params.twstat.stat);
		    v9fs_size_stat(fcall->params.twstat.stat, extended);
		size += 4 + 2 + 2 + fcall->params.twstat.stat->size;
	}
	return size;
@@ -493,16 +489,16 @@ v9fs_size_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall)

/*
 * v9fs_serialize_fcall - marshall fcall struct into a packet
 * @v9ses: session information
 * @fcall: structure to convert
 * @data: buffer to serialize fcall into
 * @datalen: length of buffer to serialize fcall into
 * @extended: non-zero if 9P2000.u
 *
 */

int
v9fs_serialize_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall,
		     void *data, u32 datalen)
v9fs_serialize_fcall(struct v9fs_fcall *fcall, void *data, u32 datalen,
		     int extended)
{
	int i = 0;
	struct v9fs_stat *stat = NULL;
@@ -516,7 +512,7 @@ v9fs_serialize_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall,
		return -EINVAL;
	}

	fcall->size = v9fs_size_fcall(v9ses, fcall);
	fcall->size = v9fs_size_fcall(fcall, extended);

	buf_put_int32(bufp, fcall->size);
	buf_put_int8(bufp, fcall->id);
@@ -591,31 +587,31 @@ v9fs_serialize_fcall(struct v9fs_session_info *v9ses, struct v9fs_fcall *fcall,
		stat = fcall->params.twstat.stat;

		buf_put_int16(bufp, stat->size + 2);
		serialize_stat(v9ses, stat, bufp);
		serialize_stat(stat, bufp, extended);
		break;
	}

	if (buf_check_overflow(bufp))
	if (buf_check_overflow(bufp)) {
		dprintk(DEBUG_ERROR, "buffer overflow\n");
		return -EIO;
	}

	return fcall->size;
}

/**
 * deserialize_fcall - unmarshal a response
 * @v9ses: session information
 * @msgsize: size of rcall message
 * @buf: recieved buffer
 * @buflen: length of received buffer
 * @rcall: fcall structure to populate
 * @rcalllen: length of fcall structure to populate
 * @extended: non-zero if 9P2000.u
 *
 */

int
v9fs_deserialize_fcall(struct v9fs_session_info *v9ses, u32 msgsize,
		       void *buf, u32 buflen, struct v9fs_fcall *rcall,
		       int rcalllen)
v9fs_deserialize_fcall(void *buf, u32 buflen, struct v9fs_fcall *rcall,
		       int rcalllen, int extended)
{

	struct cbuf buffer;
@@ -628,7 +624,7 @@ v9fs_deserialize_fcall(struct v9fs_session_info *v9ses, u32 msgsize,
	buf_init(dbufp, (char *)rcall + sizeof(struct v9fs_fcall),
		 rcalllen - sizeof(struct v9fs_fcall));

	rcall->size = msgsize;
	rcall->size = buf_get_int32(bufp);
	rcall->id = buf_get_int8(bufp);
	rcall->tag = buf_get_int16(bufp);

@@ -651,6 +647,12 @@ v9fs_deserialize_fcall(struct v9fs_session_info *v9ses, u32 msgsize,
		break;
	case RWALK:
		rcall->params.rwalk.nwqid = buf_get_int16(bufp);
		if (rcall->params.rwalk.nwqid > 16) {
			eprintk(KERN_ERR, "Rwalk with more than 16 qids: %d\n",
				rcall->params.rwalk.nwqid);
			return -EPROTO;
		}

		rcall->params.rwalk.wqids = buf_alloc(dbufp,
		      rcall->params.rwalk.nwqid * sizeof(struct v9fs_qid));
		if (rcall->params.rwalk.wqids)
@@ -690,19 +692,21 @@ v9fs_deserialize_fcall(struct v9fs_session_info *v9ses, u32 msgsize,
	case RSTAT:
		buf_get_int16(bufp);
		rcall->params.rstat.stat =
		    deserialize_statb(v9ses, bufp, dbufp);
		    deserialize_statb(bufp, dbufp, extended);
		break;
	case RWSTAT:
		break;
	case RERROR:
		rcall->params.rerror.error = buf_get_stringb(bufp, dbufp);
		if (v9ses->extended)
		if (extended)
			rcall->params.rerror.errno = buf_get_int16(bufp);
		break;
	}

	if (buf_check_overflow(bufp) || buf_check_overflow(dbufp))
	if (buf_check_overflow(bufp) || buf_check_overflow(dbufp)) {
		dprintk(DEBUG_ERROR, "buffer overflow\n");
		return -EIO;
	}

	return rcall->size;
}
+6 −7
Original line number Diff line number Diff line
@@ -24,13 +24,12 @@
 *
 */

int v9fs_deserialize_stat(struct v9fs_session_info *, void *buf,
			  u32 buflen, struct v9fs_stat *stat, u32 statlen);
int v9fs_serialize_fcall(struct v9fs_session_info *, struct v9fs_fcall *tcall,
			 void *buf, u32 buflen);
int v9fs_deserialize_fcall(struct v9fs_session_info *, u32 msglen,
			   void *buf, u32 buflen, struct v9fs_fcall *rcall,
			   int rcalllen);
int v9fs_deserialize_stat(void *buf, u32 buflen, struct v9fs_stat *stat,
	u32 statlen, int extended);
int v9fs_serialize_fcall(struct v9fs_fcall *tcall, void *buf, u32 buflen,
	int extended);
int v9fs_deserialize_fcall(void *buf, u32 buflen, struct v9fs_fcall *rcall,
	int rcalllen, int extended);

/* this one is actually in error.c right now */
int v9fs_errstr2errno(char *errstr);
+1 −1
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ static struct v9fs_fid *v9fs_fid_walk_up(struct dentry *dentry)
	return v9fs_fid_create(dentry, v9ses, fidnum, 0);

clunk_fid:
	v9fs_t_clunk(v9ses, fidnum, NULL);
	v9fs_t_clunk(v9ses, fidnum);
	return ERR_PTR(err);
}

Loading