/*1* include/net/9p/client.h2*3* 9P Client Definitions4*5* Copyright (C) 2008 by Eric Van Hensbergen <[email protected]>6* Copyright (C) 2007 by Latchesar Ionkov <[email protected]>7*8* This program is free software; you can redistribute it and/or modify9* it under the terms of the GNU General Public License version 210* as published by the Free Software Foundation.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to:19* Free Software Foundation20* 51 Franklin Street, Fifth Floor21* Boston, MA 02111-1301 USA22*23*/2425#ifndef NET_9P_CLIENT_H26#define NET_9P_CLIENT_H2728/* Number of requests per row */29#define P9_ROW_MAXTAG 2553031/** enum p9_proto_versions - 9P protocol versions32* @p9_proto_legacy: 9P Legacy mode, pre-9P2000.u33* @p9_proto_2000u: 9P2000.u extension34* @p9_proto_2000L: 9P2000.L extension35*/3637enum p9_proto_versions{38p9_proto_legacy = 0,39p9_proto_2000u = 1,40p9_proto_2000L = 2,41};424344/**45* enum p9_trans_status - different states of underlying transports46* @Connected: transport is connected and healthy47* @Disconnected: transport has been disconnected48* @Hung: transport is connected by wedged49*50* This enumeration details the various states a transport51* instatiation can be in.52*/5354enum p9_trans_status {55Connected,56BeginDisconnect,57Disconnected,58Hung,59};6061/**62* enum p9_req_status_t - status of a request63* @REQ_STATUS_IDLE: request slot unused64* @REQ_STATUS_ALLOC: request has been allocated but not sent65* @REQ_STATUS_UNSENT: request waiting to be sent66* @REQ_STATUS_SENT: request sent to server67* @REQ_STATUS_FLSH: a flush has been sent for this request68* @REQ_STATUS_RCVD: response received from server69* @REQ_STATUS_FLSHD: request has been flushed70* @REQ_STATUS_ERROR: request encountered an error on the client side71*72* The @REQ_STATUS_IDLE state is used to mark a request slot as unused73* but use is actually tracked by the idpool structure which handles tag74* id allocation.75*76*/7778enum p9_req_status_t {79REQ_STATUS_IDLE,80REQ_STATUS_ALLOC,81REQ_STATUS_UNSENT,82REQ_STATUS_SENT,83REQ_STATUS_FLSH,84REQ_STATUS_RCVD,85REQ_STATUS_FLSHD,86REQ_STATUS_ERROR,87};8889/**90* struct p9_req_t - request slots91* @status: status of this request slot92* @t_err: transport error93* @flush_tag: tag of request being flushed (for flush requests)94* @wq: wait_queue for the client to block on for this request95* @tc: the request fcall structure96* @rc: the response fcall structure97* @aux: transport specific data (provided for trans_fd migration)98* @req_list: link for higher level objects to chain requests99*100* Transport use an array to track outstanding requests101* instead of a list. While this may incurr overhead during initial102* allocation or expansion, it makes request lookup much easier as the103* tag id is a index into an array. (We use tag+1 so that we can accommodate104* the -1 tag for the T_VERSION request).105* This also has the nice effect of only having to allocate wait_queues106* once, instead of constantly allocating and freeing them. Its possible107* other resources could benefit from this scheme as well.108*109*/110111struct p9_req_t {112int status;113int t_err;114wait_queue_head_t *wq;115struct p9_fcall *tc;116struct p9_fcall *rc;117void *aux;118119struct list_head req_list;120};121122/**123* struct p9_client - per client instance state124* @lock: protect @fidlist125* @msize: maximum data size negotiated by protocol126* @dotu: extension flags negotiated by protocol127* @proto_version: 9P protocol version to use128* @trans_mod: module API instantiated with this client129* @trans: tranport instance state and API130* @conn: connection state information used by trans_fd131* @fidpool: fid handle accounting for session132* @fidlist: List of active fid handles133* @tagpool - transaction id accounting for session134* @reqs - 2D array of requests135* @max_tag - current maximum tag id allocated136*137* The client structure is used to keep track of various per-client138* state that has been instantiated.139* In order to minimize per-transaction overhead we use a140* simple array to lookup requests instead of a hash table141* or linked list. In order to support larger number of142* transactions, we make this a 2D array, allocating new rows143* when we need to grow the total number of the transactions.144*145* Each row is 256 requests and we'll support up to 256 rows for146* a total of 64k concurrent requests per session.147*148* Bugs: duplicated data and potentially unnecessary elements.149*/150151struct p9_client {152spinlock_t lock; /* protect client structure */153int msize;154unsigned char proto_version;155struct p9_trans_module *trans_mod;156enum p9_trans_status status;157void *trans;158struct p9_conn *conn;159160struct p9_idpool *fidpool;161struct list_head fidlist;162163struct p9_idpool *tagpool;164struct p9_req_t *reqs[P9_ROW_MAXTAG];165int max_tag;166};167168/**169* struct p9_fid - file system entity handle170* @clnt: back pointer to instantiating &p9_client171* @fid: numeric identifier for this handle172* @mode: current mode of this fid (enum?)173* @qid: the &p9_qid server identifier this handle points to174* @iounit: the server reported maximum transaction size for this file175* @uid: the numeric uid of the local user who owns this handle176* @rdir: readdir accounting structure (allocated on demand)177* @flist: per-client-instance fid tracking178* @dlist: per-dentry fid tracking179*180* TODO: This needs lots of explanation.181*/182183struct p9_fid {184struct p9_client *clnt;185u32 fid;186int mode;187struct p9_qid qid;188u32 iounit;189uid_t uid;190191void *rdir;192193struct list_head flist;194struct list_head dlist; /* list of all fids attached to a dentry */195};196197/**198* struct p9_dirent - directory entry structure199* @qid: The p9 server qid for this dirent200* @d_off: offset to the next dirent201* @d_type: type of file202* @d_name: file name203*/204205struct p9_dirent {206struct p9_qid qid;207u64 d_off;208unsigned char d_type;209char d_name[256];210};211212int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb);213int p9_client_rename(struct p9_fid *fid, struct p9_fid *newdirfid, char *name);214struct p9_client *p9_client_create(const char *dev_name, char *options);215void p9_client_destroy(struct p9_client *clnt);216void p9_client_disconnect(struct p9_client *clnt);217void p9_client_begin_disconnect(struct p9_client *clnt);218struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,219char *uname, u32 n_uname, char *aname);220struct p9_fid *p9_client_walk(struct p9_fid *oldfid, uint16_t nwname,221char **wnames, int clone);222int p9_client_open(struct p9_fid *fid, int mode);223int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,224char *extension);225int p9_client_link(struct p9_fid *fid, struct p9_fid *oldfid, char *newname);226int p9_client_symlink(struct p9_fid *fid, char *name, char *symname, gid_t gid,227struct p9_qid *qid);228int p9_client_create_dotl(struct p9_fid *ofid, char *name, u32 flags, u32 mode,229gid_t gid, struct p9_qid *qid);230int p9_client_clunk(struct p9_fid *fid);231int p9_client_fsync(struct p9_fid *fid, int datasync);232int p9_client_remove(struct p9_fid *fid);233int p9_client_read(struct p9_fid *fid, char *data, char __user *udata,234u64 offset, u32 count);235int p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,236u64 offset, u32 count);237int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset);238int p9dirent_read(char *buf, int len, struct p9_dirent *dirent,239int proto_version);240struct p9_wstat *p9_client_stat(struct p9_fid *fid);241int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst);242int p9_client_setattr(struct p9_fid *fid, struct p9_iattr_dotl *attr);243244struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid,245u64 request_mask);246247int p9_client_mknod_dotl(struct p9_fid *oldfid, char *name, int mode,248dev_t rdev, gid_t gid, struct p9_qid *);249int p9_client_mkdir_dotl(struct p9_fid *fid, char *name, int mode,250gid_t gid, struct p9_qid *);251int p9_client_lock_dotl(struct p9_fid *fid, struct p9_flock *flock, u8 *status);252int p9_client_getlock_dotl(struct p9_fid *fid, struct p9_getlock *fl);253struct p9_req_t *p9_tag_lookup(struct p9_client *, u16);254void p9_client_cb(struct p9_client *c, struct p9_req_t *req);255256int p9_parse_header(struct p9_fcall *, int32_t *, int8_t *, int16_t *, int);257int p9stat_read(char *, int, struct p9_wstat *, int);258void p9stat_free(struct p9_wstat *);259260int p9_is_proto_dotu(struct p9_client *clnt);261int p9_is_proto_dotl(struct p9_client *clnt);262struct p9_fid *p9_client_xattrwalk(struct p9_fid *, const char *, u64 *);263int p9_client_xattrcreate(struct p9_fid *, const char *, u64, int);264int p9_client_readlink(struct p9_fid *fid, char **target);265266#endif /* NET_9P_CLIENT_H */267268269