9p: 9P server interface and common srv code
Subsystems (3)
Latchesar Ionkov
maintainerRFC PATCH 2/6 9p: 9P server interface and common srv code
This patchset provides support for in-kernel 9P2000 servers.
This patch adds the header file that defines the 9P server interface as well as the code for the common support functions for the server.
Signed-off-by Latchesar Ionkov <[email protected]>
--- include/net/9p/srv.h | 208 ++++++++++++ net/9p/srv/srv.c | 891 ++++++++++++++++++++++++++++++++++++++++++++++++++ net/9p/srv/srvimpl.h | 46 +++ 3 files changed, 1145 insertions(+), 0 deletions(-) create mode 100644 include/net/9p/srv.h create mode 100644 net/9p/srv/srv.c create mode 100644 net/9p/srv/srvimpl.h
include/net/9p/srv.h new file +208 -0
@@ -0,0 +1,208 @@ +/* +* include/net/9p/srv.h +* +* 9P server definitions. +* +* Copyright (C) 2007 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 +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to: +* Free Software Foundation +* 51 Franklin Street, Fifth Floor +* Boston, MA 02111-1301 USA +* +*/ + +#ifndef NET_9PSRV_H +#define NET_9PSRV_H + +#define P9SRV_DEBUG_SRV (1<<16) +#define P9SRV_DEBUG_CONN (1<<17) +#define P9SRV_DEBUG_FID (1<<18) +#define P9SRV_DEBUG_REQ (1<<19) +#define P9SRV_DEBUG_FCALL (1<<20) +#define P9SRV_DEBUG_FS (1<<21) + +#define MAXPOLLWADDR 2 + +struct p9srv ; +struct p9srv_fid ; +struct p9srv_fidpool ; +struct p9srv_conn ; +struct p9srv_req ; + +struct p9srv { +int msize; +int dotu;/* 9P2000.u */ +void *srvaux; +void *treeaux; +int debuglevel; +void (*start)(struct p9srv *); +void (*stop)(struct p9srv *); +void (*destroy)(struct p9srv *); +void (*connopen)(struct p9srv_conn *); +void (*connclose)(struct p9srv_conn *); +void (*fiddestroy)(struct p9srv_fid *); +void (*reqdestroy)(struct p9srv_req *); + +/* 9P message handlers */ +void (*attach)(struct p9srv_req *); +void (*auth)(struct p9srv_req *); +int (*flush)(struct p9srv_req *); +void (*walk)(struct p9srv_req *); +void (*open)(struct p9srv_req *); +void (*create)(struct p9srv_req *); +void (*read)(struct p9srv_req *); +void (*write)(struct p9srv_req *); +void (*clunk)(struct p9srv_req *); +void (*remove)(struct p9srv_req *); +void (*stat)(struct p9srv_req *); +void (*wstat)(struct p9srv_req *); + +/* implementation specific */ +atomic_t refcount; +spinlock_t lock;/* covers all srv fields */ +unsigned long status; +struct list_head conn_list;/* all connections for srv */ +struct list_head req_list;/* requests not yet worked on */ +struct list_head workreq_list;/* requests being worked on */ +struct work_struct pq;/* process request */ +}; + +enum { +/* connection status values */ + Worksched =1 ,/* work scheduled or running */ +}; + +struct p9srv_conn { +struct p9srv *srv; +struct p9_trans *trans; +int msize; +int dotu;/* 9P2000.u */ + +/* implementation specific */ +spinlock_t lock;/* covers all conn fields */ +unsigned long status; +struct p9srv_fidpool *fidpool; +struct work_struct rq; +struct work_struct wq; +struct list_head conn_list;/* all srv connections */ +struct list_head vpt_conn_list;/* all connections for vpt */ + +/* outgoing data */ +struct list_head oreq_list; +char *obuf;/* outgoing data */ +int opos;/* next byte in obuf */ +int osize;/* obuf size */ + +/* incoming data */ +struct p9_fcall *icall; +int ipos;/*next byte in ibuf */ +char *ibuf;/* icall->pkt */ + +/* connection & polling threads management */ +struct p9srv_poll_task *poll_task; +wait_queue_t poll_wait[MAXPOLLWADDR ]; +wait_queue_head_t *poll_waddr[MAXPOLLWADDR ]; +poll_table pt; + +/* connection reset */ +atomic_t reset_wcount; +wait_queue_head_t reset_wqueue; +}; + +enum { +/* connection status values */ + Rworksched =1 ,/* read work scheduled or running */ + Rpending =2 ,/* can read */ + Wworksched =3 ,/* write work scheduled or running */ + Wpending =4 ,/* can write */ + Reset =5 ,/* resetting */ + Destroy =6 ,/* destroying */ +}; + +struct p9srv_fid { +u32 fid; +atomic_t refcount; +struct p9srv_conn *conn; +void *aux; +u16 omode; +u8 type; +u32 diroffset; +u32 uid; + +/* implementation specific */ +struct p9srv_fidpool *fidpool; +struct hlist_node fid_list; +}; + +#define FID_HTABLE_BITS 5 +#define FID_HTABLE_SIZE (1 << FID_HTABLE_BITS) + +struct p9srv_req { +int tag; +void *aux; +struct p9_fcall *tcall; +struct p9_fcall *rcall; +struct p9srv_fid *fid; +struct p9srv_fid *afid;/* Tauth, Tattach */ +struct p9srv_fid *newfid;/* Twalk */ + +/* implementation specific */ +long status; +atomic_t refcount; +struct p9srv_conn *conn; +struct list_head flush_req_list; +struct list_head req_list; +}; + +enum { +/* p9srv_req status */ + Respond =1 , + Flush, +}; + +extern char *Eunknownfid; +extern char *Enomem; +extern char *Enoauth; +extern char *Enotimpl; +extern char *Einuse; +extern char *Ebadusefid; +extern char *Enotdir; +extern char *Etoomanywnames; +extern char *Eperm; +extern char *Etoolarge; +extern char *Ebadoffset; +extern char *Edirchange; +extern char *Enotfound; +extern char *Eopen; +extern char *Eexist; +extern char *Enotempty; + + +struct p9srv *p9srv_srv_create (void ); +void p9srv_srv_stop (struct p9srv *srv); +void p9srv_srv_destroy (struct p9srv *srv); +void p9srv_srv_start (struct p9srv *srv); +void p9srv_respond (struct p9srv_req *req,struct p9_fcall *rc); +void p9srv_respond_error (struct p9srv_req *req,char *ename,int ecode); +struct p9srv_req *p9srv_req_create (void ); +void p9srv_req_ref (struct p9srv_req *req); +void p9srv_req_unref (struct p9srv_req *req); +struct p9srv_conn *p9srv_conn_create (struct p9srv *srv,struct p9_trans *trans); +void p9srv_conn_destroy (struct p9srv_conn *conn); +struct p9srv_fid *p9srv_fid_find (struct p9srv_fidpool *fp,u32 fid); +void p9srv_fid_incref (struct p9srv_fid *fid); +void p9srv_fid_decref (struct p9srv_fid *fid); + +struct p9srv *p9srv_socksrv_create (int port); +#endif
net/9p/srv/srv.c new file +891 -0
891 lines not on this page · raw message
net/9p/srv/srvimpl.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
1.5.2.4