aboutsummaryrefslogtreecommitdiffstats
path: root/net/9p/trans_fd.c
diff options
context:
space:
mode:
authorEric Van Hensbergen <ericvh@ericvh-desktop.austin.ibm.com>2008-10-13 19:45:25 -0400
committerEric Van Hensbergen <ericvh@gmail.com>2008-10-17 12:04:41 -0400
commit8b81ef589ad1483dd977ef47fe00d4ce4d91a0ab (patch)
tree380a19ca0f55fefc60c4a45771f5273c80539c07 /net/9p/trans_fd.c
parent992b3f1dbeec401e19a80bdb8c81e5df5381f4c5 (diff)
9p: consolidate transport structure
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 <ericvh@gmail.com>
Diffstat (limited to 'net/9p/trans_fd.c')
-rw-r--r--net/9p/trans_fd.c205
1 files changed, 92 insertions, 113 deletions
diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
index f84592345573..d09389f08382 100644
--- a/net/9p/trans_fd.c
+++ b/net/9p/trans_fd.c
@@ -39,6 +39,7 @@
39#include <linux/file.h> 39#include <linux/file.h>
40#include <linux/parser.h> 40#include <linux/parser.h>
41#include <net/9p/9p.h> 41#include <net/9p/9p.h>
42#include <net/9p/client.h>
42#include <net/9p/transport.h> 43#include <net/9p/transport.h>
43 44
44#define P9_PORT 564 45#define P9_PORT 564
@@ -146,7 +147,7 @@ struct p9_poll_wait {
146 * @mux_list: list link for mux to manage multiple connections (?) 147 * @mux_list: list link for mux to manage multiple connections (?)
147 * @msize: maximum size for connection (dup) 148 * @msize: maximum size for connection (dup)
148 * @extended: 9p2000.u flag (dup) 149 * @extended: 9p2000.u flag (dup)
149 * @trans: reference to transport instance for this connection 150 * @client: reference to client instance for this connection
150 * @tagpool: id accounting for transactions 151 * @tagpool: id accounting for transactions
151 * @err: error state 152 * @err: error state
152 * @req_list: accounting for requests which have been sent 153 * @req_list: accounting for requests which have been sent
@@ -171,7 +172,7 @@ struct p9_conn {
171 struct list_head mux_list; 172 struct list_head mux_list;
172 int msize; 173 int msize;
173 unsigned char extended; 174 unsigned char extended;
174 struct p9_trans *trans; 175 struct p9_client *client;
175 struct p9_idpool *tagpool; 176 struct p9_idpool *tagpool;
176 int err; 177 int err;
177 struct list_head req_list; 178 struct list_head req_list;
@@ -214,8 +215,8 @@ static void p9_read_work(struct work_struct *work);
214static void p9_write_work(struct work_struct *work); 215static void p9_write_work(struct work_struct *work);
215static void p9_pollwait(struct file *filp, wait_queue_head_t *wait_address, 216static void p9_pollwait(struct file *filp, wait_queue_head_t *wait_address,
216 poll_table *p); 217 poll_table *p);
217static int p9_fd_write(struct p9_trans *trans, void *v, int len); 218static int p9_fd_write(struct p9_client *client, void *v, int len);
218static int p9_fd_read(struct p9_trans *trans, void *v, int len); 219static int p9_fd_read(struct p9_client *client, void *v, int len);
219 220
220static DEFINE_SPINLOCK(p9_poll_lock); 221static DEFINE_SPINLOCK(p9_poll_lock);
221static LIST_HEAD(p9_poll_pending_list); 222static LIST_HEAD(p9_poll_pending_list);
@@ -223,7 +224,7 @@ static struct workqueue_struct *p9_mux_wq;
223static struct task_struct *p9_poll_task; 224static struct task_struct *p9_poll_task;
224 225
225static void p9_conn_destroy(struct p9_conn *); 226static void p9_conn_destroy(struct p9_conn *);
226static unsigned int p9_fd_poll(struct p9_trans *trans, 227static unsigned int p9_fd_poll(struct p9_client *client,
227 struct poll_table_struct *pt); 228 struct poll_table_struct *pt);
228 229
229#ifdef P9_NONBLOCK 230#ifdef P9_NONBLOCK
@@ -271,27 +272,26 @@ static void p9_mux_poll_stop(struct p9_conn *m)
271 272
272/** 273/**
273 * p9_conn_create - allocate and initialize the per-session mux data 274 * p9_conn_create - allocate and initialize the per-session mux data
274 * @trans: transport structure 275 * @client: client instance
275 * 276 *
276 * Note: Creates the polling task if this is the first session. 277 * Note: Creates the polling task if this is the first session.
277 */ 278 */
278 279
279static struct p9_conn *p9_conn_create(struct p9_trans *trans) 280static struct p9_conn *p9_conn_create(struct p9_client *client)
280{ 281{
281 int i, n; 282 int i, n;
282 struct p9_conn *m; 283 struct p9_conn *m;
283 284
284 P9_DPRINTK(P9_DEBUG_MUX, "transport %p msize %d\n", trans, 285 P9_DPRINTK(P9_DEBUG_MUX, "client %p msize %d\n", client, client->msize);
285 trans->msize);
286 m = kzalloc(sizeof(struct p9_conn), GFP_KERNEL); 286 m = kzalloc(sizeof(struct p9_conn), GFP_KERNEL);
287 if (!m) 287 if (!m)
288 return ERR_PTR(-ENOMEM); 288 return ERR_PTR(-ENOMEM);
289 289
290 spin_lock_init(&m->lock); 290 spin_lock_init(&m->lock);
291 INIT_LIST_HEAD(&m->mux_list); 291 INIT_LIST_HEAD(&m->mux_list);
292 m->msize = trans->msize; 292 m->msize = client->msize;
293 m->extended = trans->extended; 293 m->extended = client->dotu;
294 m->trans = trans; 294 m->client = client;
295 m->tagpool = p9_idpool_create(); 295 m->tagpool = p9_idpool_create();
296 if (IS_ERR(m->tagpool)) { 296 if (IS_ERR(m->tagpool)) {
297 kfree(m); 297 kfree(m);
@@ -305,7 +305,7 @@ static struct p9_conn *p9_conn_create(struct p9_trans *trans)
305 INIT_LIST_HEAD(&m->poll_pending_link); 305 INIT_LIST_HEAD(&m->poll_pending_link);
306 init_poll_funcptr(&m->pt, p9_pollwait); 306 init_poll_funcptr(&m->pt, p9_pollwait);
307 307
308 n = p9_fd_poll(trans, &m->pt); 308 n = p9_fd_poll(client, &m->pt);
309 if (n & POLLIN) { 309 if (n & POLLIN) {
310 P9_DPRINTK(P9_DEBUG_MUX, "mux %p can read\n", m); 310 P9_DPRINTK(P9_DEBUG_MUX, "mux %p can read\n", m);
311 set_bit(Rpending, &m->wsched); 311 set_bit(Rpending, &m->wsched);
@@ -345,7 +345,7 @@ static void p9_conn_destroy(struct p9_conn *m)
345 345
346 p9_conn_cancel(m, -ECONNRESET); 346 p9_conn_cancel(m, -ECONNRESET);
347 347
348 m->trans = NULL; 348 m->client = NULL;
349 p9_idpool_destroy(m->tagpool); 349 p9_idpool_destroy(m->tagpool);
350 kfree(m); 350 kfree(m);
351} 351}
@@ -420,7 +420,7 @@ static void p9_poll_mux(struct p9_conn *m)
420 if (m->err < 0) 420 if (m->err < 0)
421 return; 421 return;
422 422
423 n = p9_fd_poll(m->trans, NULL); 423 n = p9_fd_poll(m->client, NULL);
424 if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) { 424 if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) {
425 P9_DPRINTK(P9_DEBUG_MUX, "error mux %p err %d\n", m, n); 425 P9_DPRINTK(P9_DEBUG_MUX, "error mux %p err %d\n", m, n);
426 if (n >= 0) 426 if (n >= 0)
@@ -533,7 +533,7 @@ again:
533 P9_DPRINTK(P9_DEBUG_MUX, "mux %p pos %d size %d\n", m, m->wpos, 533 P9_DPRINTK(P9_DEBUG_MUX, "mux %p pos %d size %d\n", m, m->wpos,
534 m->wsize); 534 m->wsize);
535 clear_bit(Wpending, &m->wsched); 535 clear_bit(Wpending, &m->wsched);
536 err = p9_fd_write(m->trans, m->wbuf + m->wpos, m->wsize - m->wpos); 536 err = p9_fd_write(m->client, m->wbuf + m->wpos, m->wsize - m->wpos);
537 P9_DPRINTK(P9_DEBUG_MUX, "mux %p sent %d bytes\n", m, err); 537 P9_DPRINTK(P9_DEBUG_MUX, "mux %p sent %d bytes\n", m, err);
538 if (err == -EAGAIN) { 538 if (err == -EAGAIN) {
539 clear_bit(Wworksched, &m->wsched); 539 clear_bit(Wworksched, &m->wsched);
@@ -555,7 +555,7 @@ again:
555 if (test_and_clear_bit(Wpending, &m->wsched)) 555 if (test_and_clear_bit(Wpending, &m->wsched))
556 n = POLLOUT; 556 n = POLLOUT;
557 else 557 else
558 n = p9_fd_poll(m->trans, NULL); 558 n = p9_fd_poll(m->client, NULL);
559 559
560 if (n & POLLOUT) { 560 if (n & POLLOUT) {
561 P9_DPRINTK(P9_DEBUG_MUX, "schedule write work %p\n", m); 561 P9_DPRINTK(P9_DEBUG_MUX, "schedule write work %p\n", m);
@@ -640,7 +640,7 @@ static void p9_read_work(struct work_struct *work)
640 } 640 }
641 641
642 clear_bit(Rpending, &m->wsched); 642 clear_bit(Rpending, &m->wsched);
643 err = p9_fd_read(m->trans, m->rbuf + m->rpos, m->msize - m->rpos); 643 err = p9_fd_read(m->client, m->rbuf + m->rpos, m->msize - m->rpos);
644 P9_DPRINTK(P9_DEBUG_MUX, "mux %p got %d bytes\n", m, err); 644 P9_DPRINTK(P9_DEBUG_MUX, "mux %p got %d bytes\n", m, err);
645 if (err == -EAGAIN) { 645 if (err == -EAGAIN) {
646 clear_bit(Rworksched, &m->wsched); 646 clear_bit(Rworksched, &m->wsched);
@@ -735,7 +735,7 @@ static void p9_read_work(struct work_struct *work)
735 if (test_and_clear_bit(Rpending, &m->wsched)) 735 if (test_and_clear_bit(Rpending, &m->wsched))
736 n = POLLIN; 736 n = POLLIN;
737 else 737 else
738 n = p9_fd_poll(m->trans, NULL); 738 n = p9_fd_poll(m->client, NULL);
739 739
740 if (n & POLLIN) { 740 if (n & POLLIN) {
741 P9_DPRINTK(P9_DEBUG_MUX, "schedule read work %p\n", m); 741 P9_DPRINTK(P9_DEBUG_MUX, "schedule read work %p\n", m);
@@ -819,7 +819,7 @@ static struct p9_req *p9_send_request(struct p9_conn *m,
819 if (test_and_clear_bit(Wpending, &m->wsched)) 819 if (test_and_clear_bit(Wpending, &m->wsched))
820 n = POLLOUT; 820 n = POLLOUT;
821 else 821 else
822 n = p9_fd_poll(m->trans, NULL); 822 n = p9_fd_poll(m->client, NULL);
823 823
824 if (n & POLLOUT && !test_and_set_bit(Wworksched, &m->wsched)) 824 if (n & POLLOUT && !test_and_set_bit(Wworksched, &m->wsched))
825 queue_work(p9_mux_wq, &m->wq); 825 queue_work(p9_mux_wq, &m->wq);
@@ -933,16 +933,16 @@ p9_conn_rpc_cb(struct p9_req *req, void *a)
933/** 933/**
934 * p9_fd_rpc- sends 9P request and waits until a response is available. 934 * p9_fd_rpc- sends 9P request and waits until a response is available.
935 * The function can be interrupted. 935 * The function can be interrupted.
936 * @t: transport data 936 * @client: client instance
937 * @tc: request to be sent 937 * @tc: request to be sent
938 * @rc: pointer where a pointer to the response is stored 938 * @rc: pointer where a pointer to the response is stored
939 * 939 *
940 */ 940 */
941 941
942int 942int
943p9_fd_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc) 943p9_fd_rpc(struct p9_client *client, struct p9_fcall *tc, struct p9_fcall **rc)
944{ 944{
945 struct p9_trans_fd *p = t->priv; 945 struct p9_trans_fd *p = client->trans;
946 struct p9_conn *m = p->conn; 946 struct p9_conn *m = p->conn;
947 int err, sigpending; 947 int err, sigpending;
948 unsigned long flags; 948 unsigned long flags;
@@ -975,7 +975,7 @@ p9_fd_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
975 if (r.err < 0) 975 if (r.err < 0)
976 err = r.err; 976 err = r.err;
977 977
978 if (err == -ERESTARTSYS && m->trans->status == Connected 978 if (err == -ERESTARTSYS && client->status == Connected
979 && m->err == 0) { 979 && m->err == 0) {
980 if (p9_mux_flush_request(m, req)) { 980 if (p9_mux_flush_request(m, req)) {
981 /* wait until we get response of the flush message */ 981 /* wait until we get response of the flush message */
@@ -984,7 +984,7 @@ p9_fd_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
984 err = wait_event_interruptible(r.wqueue, 984 err = wait_event_interruptible(r.wqueue,
985 r.rcall || r.err); 985 r.rcall || r.err);
986 } while (!r.rcall && !r.err && err == -ERESTARTSYS && 986 } while (!r.rcall && !r.err && err == -ERESTARTSYS &&
987 m->trans->status == Connected && !m->err); 987 client->status == Connected && !m->err);
988 988
989 err = -ERESTARTSYS; 989 err = -ERESTARTSYS;
990 } 990 }
@@ -1133,7 +1133,7 @@ static int parse_opts(char *params, struct p9_fd_opts *opts)
1133 return 0; 1133 return 0;
1134} 1134}
1135 1135
1136static int p9_fd_open(struct p9_trans *trans, int rfd, int wfd) 1136static int p9_fd_open(struct p9_client *client, int rfd, int wfd)
1137{ 1137{
1138 struct p9_trans_fd *ts = kmalloc(sizeof(struct p9_trans_fd), 1138 struct p9_trans_fd *ts = kmalloc(sizeof(struct p9_trans_fd),
1139 GFP_KERNEL); 1139 GFP_KERNEL);
@@ -1151,13 +1151,13 @@ static int p9_fd_open(struct p9_trans *trans, int rfd, int wfd)
1151 return -EIO; 1151 return -EIO;
1152 } 1152 }
1153 1153
1154 trans->priv = ts; 1154 client->trans = ts;
1155 trans->status = Connected; 1155 client->status = Connected;
1156 1156
1157 return 0; 1157 return 0;
1158} 1158}
1159 1159
1160static int p9_socket_open(struct p9_trans *trans, struct socket *csocket) 1160static int p9_socket_open(struct p9_client *client, struct socket *csocket)
1161{ 1161{
1162 int fd, ret; 1162 int fd, ret;
1163 1163
@@ -1168,33 +1168,33 @@ static int p9_socket_open(struct p9_trans *trans, struct socket *csocket)
1168 return fd; 1168 return fd;
1169 } 1169 }
1170 1170
1171 ret = p9_fd_open(trans, fd, fd); 1171 ret = p9_fd_open(client, fd, fd);
1172 if (ret < 0) { 1172 if (ret < 0) {
1173 P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to open fd\n"); 1173 P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to open fd\n");
1174 sockfd_put(csocket); 1174 sockfd_put(csocket);
1175 return ret; 1175 return ret;
1176 } 1176 }
1177 1177
1178 ((struct p9_trans_fd *)trans->priv)->rd->f_flags |= O_NONBLOCK; 1178 ((struct p9_trans_fd *)client->trans)->rd->f_flags |= O_NONBLOCK;
1179 1179
1180 return 0; 1180 return 0;
1181} 1181}
1182 1182
1183/** 1183/**
1184 * p9_fd_read- read from a fd 1184 * p9_fd_read- read from a fd
1185 * @trans: transport instance state 1185 * @client: client instance
1186 * @v: buffer to receive data into 1186 * @v: buffer to receive data into
1187 * @len: size of receive buffer 1187 * @len: size of receive buffer
1188 * 1188 *
1189 */ 1189 */
1190 1190
1191static int p9_fd_read(struct p9_trans *trans, void *v, int len) 1191static int p9_fd_read(struct p9_client *client, void *v, int len)
1192{ 1192{
1193 int ret; 1193 int ret;
1194 struct p9_trans_fd *ts = NULL; 1194 struct p9_trans_fd *ts = NULL;
1195 1195
1196 if (trans && trans->status != Disconnected) 1196 if (client && client->status != Disconnected)
1197 ts = trans->priv; 1197 ts = client->trans;
1198 1198
1199 if (!ts) 1199 if (!ts)
1200 return -EREMOTEIO; 1200 return -EREMOTEIO;
@@ -1204,26 +1204,26 @@ static int p9_fd_read(struct p9_trans *trans, void *v, int len)
1204 1204
1205 ret = kernel_read(ts->rd, ts->rd->f_pos, v, len); 1205 ret = kernel_read(ts->rd, ts->rd->f_pos, v, len);
1206 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN) 1206 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
1207 trans->status = Disconnected; 1207 client->status = Disconnected;
1208 return ret; 1208 return ret;
1209} 1209}
1210 1210
1211/** 1211/**
1212 * p9_fd_write - write to a socket 1212 * p9_fd_write - write to a socket
1213 * @trans: transport instance state 1213 * @client: client instance
1214 * @v: buffer to send data from 1214 * @v: buffer to send data from
1215 * @len: size of send buffer 1215 * @len: size of send buffer
1216 * 1216 *
1217 */ 1217 */
1218 1218
1219static int p9_fd_write(struct p9_trans *trans, void *v, int len) 1219static int p9_fd_write(struct p9_client *client, void *v, int len)
1220{ 1220{
1221 int ret; 1221 int ret;
1222 mm_segment_t oldfs; 1222 mm_segment_t oldfs;
1223 struct p9_trans_fd *ts = NULL; 1223 struct p9_trans_fd *ts = NULL;
1224 1224
1225 if (trans && trans->status != Disconnected) 1225 if (client && client->status != Disconnected)
1226 ts = trans->priv; 1226 ts = client->trans;
1227 1227
1228 if (!ts) 1228 if (!ts)
1229 return -EREMOTEIO; 1229 return -EREMOTEIO;
@@ -1238,18 +1238,18 @@ static int p9_fd_write(struct p9_trans *trans, void *v, int len)
1238 set_fs(oldfs); 1238 set_fs(oldfs);
1239 1239
1240 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN) 1240 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
1241 trans->status = Disconnected; 1241 client->status = Disconnected;
1242 return ret; 1242 return ret;
1243} 1243}
1244 1244
1245static unsigned int 1245static unsigned int
1246p9_fd_poll(struct p9_trans *trans, struct poll_table_struct *pt) 1246p9_fd_poll(struct p9_client *client, struct poll_table_struct *pt)
1247{ 1247{
1248 int ret, n; 1248 int ret, n;
1249 struct p9_trans_fd *ts = NULL; 1249 struct p9_trans_fd *ts = NULL;
1250 1250
1251 if (trans && trans->status == Connected) 1251 if (client && client->status == Connected)
1252 ts = trans->priv; 1252 ts = client->trans;
1253 1253
1254 if (!ts) 1254 if (!ts)
1255 return -EREMOTEIO; 1255 return -EREMOTEIO;
@@ -1275,30 +1275,31 @@ p9_fd_poll(struct p9_trans *trans, struct poll_table_struct *pt)
1275} 1275}
1276 1276
1277/** 1277/**
1278 * p9_fd_close - shutdown socket 1278 * p9_fd_close - shutdown file descriptor transport
1279 * @trans: private socket structure 1279 * @client: client instance
1280 * 1280 *
1281 */ 1281 */
1282 1282
1283static void p9_fd_close(struct p9_trans *trans) 1283static void p9_fd_close(struct p9_client *client)
1284{ 1284{
1285 struct p9_trans_fd *ts; 1285 struct p9_trans_fd *ts;
1286 1286
1287 if (!trans) 1287 if (!client)
1288 return; 1288 return;
1289 1289
1290 ts = xchg(&trans->priv, NULL); 1290 ts = client->trans;
1291
1292 if (!ts) 1291 if (!ts)
1293 return; 1292 return;
1294 1293
1294 client->status = Disconnected;
1295
1295 p9_conn_destroy(ts->conn); 1296 p9_conn_destroy(ts->conn);
1296 1297
1297 trans->status = Disconnected;
1298 if (ts->rd) 1298 if (ts->rd)
1299 fput(ts->rd); 1299 fput(ts->rd);
1300 if (ts->wr) 1300 if (ts->wr)
1301 fput(ts->wr); 1301 fput(ts->wr);
1302
1302 kfree(ts); 1303 kfree(ts);
1303} 1304}
1304 1305
@@ -1319,31 +1320,23 @@ static inline int valid_ipaddr4(const char *buf)
1319 return 0; 1320 return 0;
1320} 1321}
1321 1322
1322static struct p9_trans * 1323static int
1323p9_trans_create_tcp(const char *addr, char *args, int msize, unsigned char dotu) 1324p9_fd_create_tcp(struct p9_client *client, const char *addr, char *args)
1324{ 1325{
1325 int err; 1326 int err;
1326 struct p9_trans *trans;
1327 struct socket *csocket; 1327 struct socket *csocket;
1328 struct sockaddr_in sin_server; 1328 struct sockaddr_in sin_server;
1329 struct p9_fd_opts opts; 1329 struct p9_fd_opts opts;
1330 struct p9_trans_fd *p; 1330 struct p9_trans_fd *p = NULL; /* this gets allocated in p9_fd_open */
1331 1331
1332 err = parse_opts(args, &opts); 1332 err = parse_opts(args, &opts);
1333 if (err < 0) 1333 if (err < 0)
1334 return ERR_PTR(err); 1334 return err;
1335 1335
1336 if (valid_ipaddr4(addr) < 0) 1336 if (valid_ipaddr4(addr) < 0)
1337 return ERR_PTR(-EINVAL); 1337 return -EINVAL;
1338 1338
1339 csocket = NULL; 1339 csocket = NULL;
1340 trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL);
1341 if (!trans)
1342 return ERR_PTR(-ENOMEM);
1343 trans->msize = msize;
1344 trans->extended = dotu;
1345 trans->rpc = p9_fd_rpc;
1346 trans->close = p9_fd_close;
1347 1340
1348 sin_server.sin_family = AF_INET; 1341 sin_server.sin_family = AF_INET;
1349 sin_server.sin_addr.s_addr = in_aton(addr); 1342 sin_server.sin_addr.s_addr = in_aton(addr);
@@ -1366,45 +1359,38 @@ p9_trans_create_tcp(const char *addr, char *args, int msize, unsigned char dotu)
1366 goto error; 1359 goto error;
1367 } 1360 }
1368 1361
1369 err = p9_socket_open(trans, csocket); 1362 err = p9_socket_open(client, csocket);
1370 if (err < 0) 1363 if (err < 0)
1371 goto error; 1364 goto error;
1372 1365
1373 p = (struct p9_trans_fd *) trans->priv; 1366 p = (struct p9_trans_fd *) client->trans;
1374 p->conn = p9_conn_create(trans); 1367 p->conn = p9_conn_create(client);
1375 if (IS_ERR(p->conn)) { 1368 if (IS_ERR(p->conn)) {
1376 err = PTR_ERR(p->conn); 1369 err = PTR_ERR(p->conn);
1377 p->conn = NULL; 1370 p->conn = NULL;
1378 goto error; 1371 goto error;
1379 } 1372 }
1380 1373
1381 return trans; 1374 return 0;
1382 1375
1383error: 1376error:
1384 if (csocket) 1377 if (csocket)
1385 sock_release(csocket); 1378 sock_release(csocket);
1386 1379
1387 kfree(trans); 1380 kfree(p);
1388 return ERR_PTR(err); 1381
1382 return err;
1389} 1383}
1390 1384
1391static struct p9_trans * 1385static int
1392p9_trans_create_unix(const char *addr, char *args, int msize, 1386p9_fd_create_unix(struct p9_client *client, const char *addr, char *args)
1393 unsigned char dotu)
1394{ 1387{
1395 int err; 1388 int err;
1396 struct socket *csocket; 1389 struct socket *csocket;
1397 struct sockaddr_un sun_server; 1390 struct sockaddr_un sun_server;
1398 struct p9_trans *trans; 1391 struct p9_trans_fd *p = NULL; /* this gets allocated in p9_fd_open */
1399 struct p9_trans_fd *p;
1400 1392
1401 csocket = NULL; 1393 csocket = NULL;
1402 trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL);
1403 if (!trans)
1404 return ERR_PTR(-ENOMEM);
1405
1406 trans->rpc = p9_fd_rpc;
1407 trans->close = p9_fd_close;
1408 1394
1409 if (strlen(addr) > UNIX_PATH_MAX) { 1395 if (strlen(addr) > UNIX_PATH_MAX) {
1410 P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n", 1396 P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n",
@@ -1425,79 +1411,68 @@ p9_trans_create_unix(const char *addr, char *args, int msize,
1425 goto error; 1411 goto error;
1426 } 1412 }
1427 1413
1428 err = p9_socket_open(trans, csocket); 1414 err = p9_socket_open(client, csocket);
1429 if (err < 0) 1415 if (err < 0)
1430 goto error; 1416 goto error;
1431 1417
1432 trans->msize = msize; 1418 p = (struct p9_trans_fd *) client->trans;
1433 trans->extended = dotu; 1419 p->conn = p9_conn_create(client);
1434 p = (struct p9_trans_fd *) trans->priv;
1435 p->conn = p9_conn_create(trans);
1436 if (IS_ERR(p->conn)) { 1420 if (IS_ERR(p->conn)) {
1437 err = PTR_ERR(p->conn); 1421 err = PTR_ERR(p->conn);
1438 p->conn = NULL; 1422 p->conn = NULL;
1439 goto error; 1423 goto error;
1440 } 1424 }
1441 1425
1442 return trans; 1426 return 0;
1443 1427
1444error: 1428error:
1445 if (csocket) 1429 if (csocket)
1446 sock_release(csocket); 1430 sock_release(csocket);
1447 1431
1448 kfree(trans); 1432 kfree(p);
1449 return ERR_PTR(err); 1433 return err;
1450} 1434}
1451 1435
1452static struct p9_trans * 1436static int
1453p9_trans_create_fd(const char *name, char *args, int msize, 1437p9_fd_create(struct p9_client *client, const char *addr, char *args)
1454 unsigned char extended)
1455{ 1438{
1456 int err; 1439 int err;
1457 struct p9_trans *trans;
1458 struct p9_fd_opts opts; 1440 struct p9_fd_opts opts;
1459 struct p9_trans_fd *p; 1441 struct p9_trans_fd *p = NULL; /* this get allocated in p9_fd_open */
1460 1442
1461 parse_opts(args, &opts); 1443 parse_opts(args, &opts);
1462 1444
1463 if (opts.rfd == ~0 || opts.wfd == ~0) { 1445 if (opts.rfd == ~0 || opts.wfd == ~0) {
1464 printk(KERN_ERR "v9fs: Insufficient options for proto=fd\n"); 1446 printk(KERN_ERR "v9fs: Insufficient options for proto=fd\n");
1465 return ERR_PTR(-ENOPROTOOPT); 1447 return -ENOPROTOOPT;
1466 } 1448 }
1467 1449
1468 trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL); 1450 err = p9_fd_open(client, opts.rfd, opts.wfd);
1469 if (!trans)
1470 return ERR_PTR(-ENOMEM);
1471
1472 trans->rpc = p9_fd_rpc;
1473 trans->close = p9_fd_close;
1474
1475 err = p9_fd_open(trans, opts.rfd, opts.wfd);
1476 if (err < 0) 1451 if (err < 0)
1477 goto error; 1452 goto error;
1478 1453
1479 trans->msize = msize; 1454 p = (struct p9_trans_fd *) client->trans;
1480 trans->extended = extended; 1455 p->conn = p9_conn_create(client);
1481 p = (struct p9_trans_fd *) trans->priv;
1482 p->conn = p9_conn_create(trans);
1483 if (IS_ERR(p->conn)) { 1456 if (IS_ERR(p->conn)) {
1484 err = PTR_ERR(p->conn); 1457 err = PTR_ERR(p->conn);
1485 p->conn = NULL; 1458 p->conn = NULL;
1486 goto error; 1459 goto error;
1487 } 1460 }
1488 1461
1489 return trans; 1462 return 0;
1490 1463
1491error: 1464error:
1492 kfree(trans); 1465 kfree(p);
1493 return ERR_PTR(err); 1466 return err;
1494} 1467}
1495 1468
1496static struct p9_trans_module p9_tcp_trans = { 1469static struct p9_trans_module p9_tcp_trans = {
1497 .name = "tcp", 1470 .name = "tcp",
1498 .maxsize = MAX_SOCK_BUF, 1471 .maxsize = MAX_SOCK_BUF,
1499 .def = 1, 1472 .def = 1,
1500 .create = p9_trans_create_tcp, 1473 .create = p9_fd_create_tcp,
1474 .close = p9_fd_close,
1475 .rpc = p9_fd_rpc,
1501 .owner = THIS_MODULE, 1476 .owner = THIS_MODULE,
1502}; 1477};
1503 1478
@@ -1505,7 +1480,9 @@ static struct p9_trans_module p9_unix_trans = {
1505 .name = "unix", 1480 .name = "unix",
1506 .maxsize = MAX_SOCK_BUF, 1481 .maxsize = MAX_SOCK_BUF,
1507 .def = 0, 1482 .def = 0,
1508 .create = p9_trans_create_unix, 1483 .create = p9_fd_create_unix,
1484 .close = p9_fd_close,
1485 .rpc = p9_fd_rpc,
1509 .owner = THIS_MODULE, 1486 .owner = THIS_MODULE,
1510}; 1487};
1511 1488
@@ -1513,7 +1490,9 @@ static struct p9_trans_module p9_fd_trans = {
1513 .name = "fd", 1490 .name = "fd",
1514 .maxsize = MAX_SOCK_BUF, 1491 .maxsize = MAX_SOCK_BUF,
1515 .def = 0, 1492 .def = 0,
1516 .create = p9_trans_create_fd, 1493 .create = p9_fd_create,
1494 .close = p9_fd_close,
1495 .rpc = p9_fd_rpc,
1517 .owner = THIS_MODULE, 1496 .owner = THIS_MODULE,
1518}; 1497};
1519 1498