Skip to content

Commit

Permalink
9p: consolidate transport structure
Browse files Browse the repository at this point in the history
Right now there is a transport module structure which provides per-transport
type functions and data and a transport structure which contains per-instance
public data as well as function pointers to instance specific functions.

This patch moves public transport visible instance data to the client
structure (which in some cases had duplicate data) and consolidates the
functions into the transport module structure.

Signed-off-by: Eric Van Hensbergen <[email protected]>
  • Loading branch information
Eric Van Hensbergen authored and ericvh committed Oct 17, 2008
1 parent 992b3f1 commit 8b81ef5
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 207 deletions.
2 changes: 1 addition & 1 deletion fs/9p/v9fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#include <linux/parser.h>
#include <linux/idr.h>
#include <net/9p/9p.h>
#include <net/9p/transport.h>
#include <net/9p/client.h>
#include <net/9p/transport.h>
#include "v9fs.h"
#include "v9fs_vfs.h"

Expand Down
19 changes: 18 additions & 1 deletion include/net/9p/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@
#ifndef NET_9P_CLIENT_H
#define NET_9P_CLIENT_H

/**
* enum p9_trans_status - different states of underlying transports
* @Connected: transport is connected and healthy
* @Disconnected: transport has been disconnected
* @Hung: transport is connected by wedged
*
* This enumeration details the various states a transport
* instatiation can be in.
*/

enum p9_trans_status {
Connected,
Disconnected,
Hung,
};

/**
* struct p9_client - per client instance state
* @lock: protect @fidlist
Expand All @@ -48,7 +64,8 @@ struct p9_client {
int msize;
unsigned char dotu;
struct p9_trans_module *trans_mod;
struct p9_trans *trans;
enum p9_trans_status status;
void *trans;
struct p9_conn *conn;

struct p9_idpool *fidpool;
Expand Down
55 changes: 7 additions & 48 deletions include/net/9p/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,74 +26,33 @@
#ifndef NET_9P_TRANSPORT_H
#define NET_9P_TRANSPORT_H

#include <linux/module.h>

/**
* enum p9_trans_status - different states of underlying transports
* @Connected: transport is connected and healthy
* @Disconnected: transport has been disconnected
* @Hung: transport is connected by wedged
*
* This enumeration details the various states a transport
* instatiation can be in.
*/

enum p9_trans_status {
Connected,
Disconnected,
Hung,
};

/**
* struct p9_trans - per-transport state and API
* @status: transport &p9_trans_status
* @msize: negotiated maximum packet size (duplicate from client)
* @extended: negotiated protocol extensions (duplicate from client)
* @priv: transport private data
* @close: member function to disconnect and close the transport
* @rpc: member function to issue a request to the transport
*
* This is the basic API for a transport instance. It is used as
* a handle by the client to issue requests. This interface is currently
* in flux during reorganization.
*
* Bugs: there is lots of duplicated data here and its not clear that
* the member functions need to be per-instance versus per transport
* module.
*/

struct p9_trans {
enum p9_trans_status status;
int msize;
unsigned char extended;
void *priv;
void (*close) (struct p9_trans *);
int (*rpc) (struct p9_trans *t, struct p9_fcall *tc,
struct p9_fcall **rc);
};

/**
* struct p9_trans_module - transport module interface
* @list: used to maintain a list of currently available transports
* @name: the human-readable name of the transport
* @maxsize: transport provided maximum packet size
* @def: set if this transport should be considered the default
* @create: member function to create a new connection on this transport
* @close: member function to disconnect and close the transport
* @rpc: member function to issue a request to the transport
*
* This is the basic API for a transport module which is registered by the
* transport module with the 9P core network module and used by the client
* to instantiate a new connection on a transport.
*
* Bugs: the transport module list isn't protected.
* BUGS: the transport module list isn't protected.
*/

struct p9_trans_module {
struct list_head list;
char *name; /* name of transport */
int maxsize; /* max message size of transport */
int def; /* this transport should be default */
struct p9_trans * (*create)(const char *, char *, int, unsigned char);
struct module *owner;
int (*create)(struct p9_client *, const char *, char *);
void (*close) (struct p9_client *);
int (*rpc) (struct p9_client *t, struct p9_fcall *tc,
struct p9_fcall **rc);
};

void v9fs_register_trans(struct p9_trans_module *m);
Expand Down
21 changes: 7 additions & 14 deletions net/9p/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include <linux/uaccess.h>
#include <net/9p/9p.h>
#include <linux/parser.h>
#include <net/9p/transport.h>
#include <net/9p/client.h>
#include <net/9p/transport.h>

static struct p9_fid *p9_fid_create(struct p9_client *clnt);
static void p9_fid_destroy(struct p9_fid *fid);
Expand Down Expand Up @@ -136,7 +136,7 @@ int
p9_client_rpc(struct p9_client *c, struct p9_fcall *tc,
struct p9_fcall **rc)
{
return c->trans->rpc(c->trans, tc, rc);
return c->trans_mod->rpc(c, tc, rc);
}

struct p9_client *p9_client_create(const char *dev_name, char *options)
Expand Down Expand Up @@ -179,13 +179,9 @@ struct p9_client *p9_client_create(const char *dev_name, char *options)
clnt, clnt->trans_mod, clnt->msize, clnt->dotu);


clnt->trans = clnt->trans_mod->create(dev_name, options, clnt->msize,
clnt->dotu);
if (IS_ERR(clnt->trans)) {
err = PTR_ERR(clnt->trans);
clnt->trans = NULL;
err = clnt->trans_mod->create(clnt, dev_name, options);
if (err)
goto error;
}

if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize)
clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ;
Expand Down Expand Up @@ -233,11 +229,8 @@ void p9_client_destroy(struct p9_client *clnt)

P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);

if (clnt->trans) {
clnt->trans->close(clnt->trans);
kfree(clnt->trans);
clnt->trans = NULL;
}
if (clnt->trans_mod)
clnt->trans_mod->close(clnt);

v9fs_put_trans(clnt->trans_mod);

Expand All @@ -254,7 +247,7 @@ EXPORT_SYMBOL(p9_client_destroy);
void p9_client_disconnect(struct p9_client *clnt)
{
P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt);
clnt->trans->status = Disconnected;
clnt->status = Disconnected;
}
EXPORT_SYMBOL(p9_client_disconnect);

Expand Down
1 change: 1 addition & 0 deletions net/9p/mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <net/9p/9p.h>
#include <linux/fs.h>
#include <linux/parser.h>
#include <net/9p/client.h>
#include <net/9p/transport.h>
#include <linux/list.h>
#include <linux/spinlock.h>
Expand Down
Loading

0 comments on commit 8b81ef5

Please sign in to comment.