Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Eric Van Hensbergen and committed by
Eric Van Hensbergen
8b81ef58 992b3f1d

+146 -207
+1 -1
fs/9p/v9fs.c
··· 30 30 #include <linux/parser.h> 31 31 #include <linux/idr.h> 32 32 #include <net/9p/9p.h> 33 - #include <net/9p/transport.h> 34 33 #include <net/9p/client.h> 34 + #include <net/9p/transport.h> 35 35 #include "v9fs.h" 36 36 #include "v9fs_vfs.h" 37 37
+18 -1
include/net/9p/client.h
··· 27 27 #define NET_9P_CLIENT_H 28 28 29 29 /** 30 + * enum p9_trans_status - different states of underlying transports 31 + * @Connected: transport is connected and healthy 32 + * @Disconnected: transport has been disconnected 33 + * @Hung: transport is connected by wedged 34 + * 35 + * This enumeration details the various states a transport 36 + * instatiation can be in. 37 + */ 38 + 39 + enum p9_trans_status { 40 + Connected, 41 + Disconnected, 42 + Hung, 43 + }; 44 + 45 + /** 30 46 * struct p9_client - per client instance state 31 47 * @lock: protect @fidlist 32 48 * @msize: maximum data size negotiated by protocol ··· 64 48 int msize; 65 49 unsigned char dotu; 66 50 struct p9_trans_module *trans_mod; 67 - struct p9_trans *trans; 51 + enum p9_trans_status status; 52 + void *trans; 68 53 struct p9_conn *conn; 69 54 70 55 struct p9_idpool *fidpool;
+7 -48
include/net/9p/transport.h
··· 26 26 #ifndef NET_9P_TRANSPORT_H 27 27 #define NET_9P_TRANSPORT_H 28 28 29 - #include <linux/module.h> 30 - 31 - /** 32 - * enum p9_trans_status - different states of underlying transports 33 - * @Connected: transport is connected and healthy 34 - * @Disconnected: transport has been disconnected 35 - * @Hung: transport is connected by wedged 36 - * 37 - * This enumeration details the various states a transport 38 - * instatiation can be in. 39 - */ 40 - 41 - enum p9_trans_status { 42 - Connected, 43 - Disconnected, 44 - Hung, 45 - }; 46 - 47 - /** 48 - * struct p9_trans - per-transport state and API 49 - * @status: transport &p9_trans_status 50 - * @msize: negotiated maximum packet size (duplicate from client) 51 - * @extended: negotiated protocol extensions (duplicate from client) 52 - * @priv: transport private data 53 - * @close: member function to disconnect and close the transport 54 - * @rpc: member function to issue a request to the transport 55 - * 56 - * This is the basic API for a transport instance. It is used as 57 - * a handle by the client to issue requests. This interface is currently 58 - * in flux during reorganization. 59 - * 60 - * Bugs: there is lots of duplicated data here and its not clear that 61 - * the member functions need to be per-instance versus per transport 62 - * module. 63 - */ 64 - 65 - struct p9_trans { 66 - enum p9_trans_status status; 67 - int msize; 68 - unsigned char extended; 69 - void *priv; 70 - void (*close) (struct p9_trans *); 71 - int (*rpc) (struct p9_trans *t, struct p9_fcall *tc, 72 - struct p9_fcall **rc); 73 - }; 74 - 75 29 /** 76 30 * struct p9_trans_module - transport module interface 77 31 * @list: used to maintain a list of currently available transports ··· 33 79 * @maxsize: transport provided maximum packet size 34 80 * @def: set if this transport should be considered the default 35 81 * @create: member function to create a new connection on this transport 82 + * @close: member function to disconnect and close the transport 83 + * @rpc: member function to issue a request to the transport 36 84 * 37 85 * This is the basic API for a transport module which is registered by the 38 86 * transport module with the 9P core network module and used by the client 39 87 * to instantiate a new connection on a transport. 40 88 * 41 - * Bugs: the transport module list isn't protected. 89 + * BUGS: the transport module list isn't protected. 42 90 */ 43 91 44 92 struct p9_trans_module { ··· 48 92 char *name; /* name of transport */ 49 93 int maxsize; /* max message size of transport */ 50 94 int def; /* this transport should be default */ 51 - struct p9_trans * (*create)(const char *, char *, int, unsigned char); 52 95 struct module *owner; 96 + int (*create)(struct p9_client *, const char *, char *); 97 + void (*close) (struct p9_client *); 98 + int (*rpc) (struct p9_client *t, struct p9_fcall *tc, 99 + struct p9_fcall **rc); 53 100 }; 54 101 55 102 void v9fs_register_trans(struct p9_trans_module *m);
+7 -14
net/9p/client.c
··· 33 33 #include <linux/uaccess.h> 34 34 #include <net/9p/9p.h> 35 35 #include <linux/parser.h> 36 - #include <net/9p/transport.h> 37 36 #include <net/9p/client.h> 37 + #include <net/9p/transport.h> 38 38 39 39 static struct p9_fid *p9_fid_create(struct p9_client *clnt); 40 40 static void p9_fid_destroy(struct p9_fid *fid); ··· 136 136 p9_client_rpc(struct p9_client *c, struct p9_fcall *tc, 137 137 struct p9_fcall **rc) 138 138 { 139 - return c->trans->rpc(c->trans, tc, rc); 139 + return c->trans_mod->rpc(c, tc, rc); 140 140 } 141 141 142 142 struct p9_client *p9_client_create(const char *dev_name, char *options) ··· 179 179 clnt, clnt->trans_mod, clnt->msize, clnt->dotu); 180 180 181 181 182 - clnt->trans = clnt->trans_mod->create(dev_name, options, clnt->msize, 183 - clnt->dotu); 184 - if (IS_ERR(clnt->trans)) { 185 - err = PTR_ERR(clnt->trans); 186 - clnt->trans = NULL; 182 + err = clnt->trans_mod->create(clnt, dev_name, options); 183 + if (err) 187 184 goto error; 188 - } 189 185 190 186 if ((clnt->msize+P9_IOHDRSZ) > clnt->trans_mod->maxsize) 191 187 clnt->msize = clnt->trans_mod->maxsize-P9_IOHDRSZ; ··· 229 233 230 234 P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt); 231 235 232 - if (clnt->trans) { 233 - clnt->trans->close(clnt->trans); 234 - kfree(clnt->trans); 235 - clnt->trans = NULL; 236 - } 236 + if (clnt->trans_mod) 237 + clnt->trans_mod->close(clnt); 237 238 238 239 v9fs_put_trans(clnt->trans_mod); 239 240 ··· 247 254 void p9_client_disconnect(struct p9_client *clnt) 248 255 { 249 256 P9_DPRINTK(P9_DEBUG_9P, "clnt %p\n", clnt); 250 - clnt->trans->status = Disconnected; 257 + clnt->status = Disconnected; 251 258 } 252 259 EXPORT_SYMBOL(p9_client_disconnect); 253 260
+1
net/9p/mod.c
··· 29 29 #include <net/9p/9p.h> 30 30 #include <linux/fs.h> 31 31 #include <linux/parser.h> 32 + #include <net/9p/client.h> 32 33 #include <net/9p/transport.h> 33 34 #include <linux/list.h> 34 35 #include <linux/spinlock.h>
+92 -113
net/9p/trans_fd.c
··· 39 39 #include <linux/file.h> 40 40 #include <linux/parser.h> 41 41 #include <net/9p/9p.h> 42 + #include <net/9p/client.h> 42 43 #include <net/9p/transport.h> 43 44 44 45 #define P9_PORT 564 ··· 147 146 * @mux_list: list link for mux to manage multiple connections (?) 148 147 * @msize: maximum size for connection (dup) 149 148 * @extended: 9p2000.u flag (dup) 150 - * @trans: reference to transport instance for this connection 149 + * @client: reference to client instance for this connection 151 150 * @tagpool: id accounting for transactions 152 151 * @err: error state 153 152 * @req_list: accounting for requests which have been sent ··· 172 171 struct list_head mux_list; 173 172 int msize; 174 173 unsigned char extended; 175 - struct p9_trans *trans; 174 + struct p9_client *client; 176 175 struct p9_idpool *tagpool; 177 176 int err; 178 177 struct list_head req_list; ··· 215 214 static void p9_write_work(struct work_struct *work); 216 215 static void p9_pollwait(struct file *filp, wait_queue_head_t *wait_address, 217 216 poll_table *p); 218 - static int p9_fd_write(struct p9_trans *trans, void *v, int len); 219 - static int p9_fd_read(struct p9_trans *trans, void *v, int len); 217 + static int p9_fd_write(struct p9_client *client, void *v, int len); 218 + static int p9_fd_read(struct p9_client *client, void *v, int len); 220 219 221 220 static DEFINE_SPINLOCK(p9_poll_lock); 222 221 static LIST_HEAD(p9_poll_pending_list); ··· 224 223 static struct task_struct *p9_poll_task; 225 224 226 225 static void p9_conn_destroy(struct p9_conn *); 227 - static unsigned int p9_fd_poll(struct p9_trans *trans, 226 + static unsigned int p9_fd_poll(struct p9_client *client, 228 227 struct poll_table_struct *pt); 229 228 230 229 #ifdef P9_NONBLOCK ··· 272 271 273 272 /** 274 273 * p9_conn_create - allocate and initialize the per-session mux data 275 - * @trans: transport structure 274 + * @client: client instance 276 275 * 277 276 * Note: Creates the polling task if this is the first session. 278 277 */ 279 278 280 - static struct p9_conn *p9_conn_create(struct p9_trans *trans) 279 + static struct p9_conn *p9_conn_create(struct p9_client *client) 281 280 { 282 281 int i, n; 283 282 struct p9_conn *m; 284 283 285 - P9_DPRINTK(P9_DEBUG_MUX, "transport %p msize %d\n", trans, 286 - trans->msize); 284 + P9_DPRINTK(P9_DEBUG_MUX, "client %p msize %d\n", client, client->msize); 287 285 m = kzalloc(sizeof(struct p9_conn), GFP_KERNEL); 288 286 if (!m) 289 287 return ERR_PTR(-ENOMEM); 290 288 291 289 spin_lock_init(&m->lock); 292 290 INIT_LIST_HEAD(&m->mux_list); 293 - m->msize = trans->msize; 294 - m->extended = trans->extended; 295 - m->trans = trans; 291 + m->msize = client->msize; 292 + m->extended = client->dotu; 293 + m->client = client; 296 294 m->tagpool = p9_idpool_create(); 297 295 if (IS_ERR(m->tagpool)) { 298 296 kfree(m); ··· 305 305 INIT_LIST_HEAD(&m->poll_pending_link); 306 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 309 if (n & POLLIN) { 310 310 P9_DPRINTK(P9_DEBUG_MUX, "mux %p can read\n", m); 311 311 set_bit(Rpending, &m->wsched); ··· 345 345 346 346 p9_conn_cancel(m, -ECONNRESET); 347 347 348 - m->trans = NULL; 348 + m->client = NULL; 349 349 p9_idpool_destroy(m->tagpool); 350 350 kfree(m); 351 351 } ··· 420 420 if (m->err < 0) 421 421 return; 422 422 423 - n = p9_fd_poll(m->trans, NULL); 423 + n = p9_fd_poll(m->client, NULL); 424 424 if (n < 0 || n & (POLLERR | POLLHUP | POLLNVAL)) { 425 425 P9_DPRINTK(P9_DEBUG_MUX, "error mux %p err %d\n", m, n); 426 426 if (n >= 0) ··· 533 533 P9_DPRINTK(P9_DEBUG_MUX, "mux %p pos %d size %d\n", m, m->wpos, 534 534 m->wsize); 535 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 537 P9_DPRINTK(P9_DEBUG_MUX, "mux %p sent %d bytes\n", m, err); 538 538 if (err == -EAGAIN) { 539 539 clear_bit(Wworksched, &m->wsched); ··· 555 555 if (test_and_clear_bit(Wpending, &m->wsched)) 556 556 n = POLLOUT; 557 557 else 558 - n = p9_fd_poll(m->trans, NULL); 558 + n = p9_fd_poll(m->client, NULL); 559 559 560 560 if (n & POLLOUT) { 561 561 P9_DPRINTK(P9_DEBUG_MUX, "schedule write work %p\n", m); ··· 640 640 } 641 641 642 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 644 P9_DPRINTK(P9_DEBUG_MUX, "mux %p got %d bytes\n", m, err); 645 645 if (err == -EAGAIN) { 646 646 clear_bit(Rworksched, &m->wsched); ··· 735 735 if (test_and_clear_bit(Rpending, &m->wsched)) 736 736 n = POLLIN; 737 737 else 738 - n = p9_fd_poll(m->trans, NULL); 738 + n = p9_fd_poll(m->client, NULL); 739 739 740 740 if (n & POLLIN) { 741 741 P9_DPRINTK(P9_DEBUG_MUX, "schedule read work %p\n", m); ··· 819 819 if (test_and_clear_bit(Wpending, &m->wsched)) 820 820 n = POLLOUT; 821 821 else 822 - n = p9_fd_poll(m->trans, NULL); 822 + n = p9_fd_poll(m->client, NULL); 823 823 824 824 if (n & POLLOUT && !test_and_set_bit(Wworksched, &m->wsched)) 825 825 queue_work(p9_mux_wq, &m->wq); ··· 933 933 /** 934 934 * p9_fd_rpc- sends 9P request and waits until a response is available. 935 935 * The function can be interrupted. 936 - * @t: transport data 936 + * @client: client instance 937 937 * @tc: request to be sent 938 938 * @rc: pointer where a pointer to the response is stored 939 939 * 940 940 */ 941 941 942 942 int 943 - p9_fd_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc) 943 + p9_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 946 struct p9_conn *m = p->conn; 947 947 int err, sigpending; 948 948 unsigned long flags; ··· 975 975 if (r.err < 0) 976 976 err = r.err; 977 977 978 - if (err == -ERESTARTSYS && m->trans->status == Connected 978 + if (err == -ERESTARTSYS && client->status == Connected 979 979 && m->err == 0) { 980 980 if (p9_mux_flush_request(m, req)) { 981 981 /* wait until we get response of the flush message */ ··· 984 984 err = wait_event_interruptible(r.wqueue, 985 985 r.rcall || r.err); 986 986 } while (!r.rcall && !r.err && err == -ERESTARTSYS && 987 - m->trans->status == Connected && !m->err); 987 + client->status == Connected && !m->err); 988 988 989 989 err = -ERESTARTSYS; 990 990 } ··· 1133 1133 return 0; 1134 1134 } 1135 1135 1136 - static int p9_fd_open(struct p9_trans *trans, int rfd, int wfd) 1136 + static int p9_fd_open(struct p9_client *client, int rfd, int wfd) 1137 1137 { 1138 1138 struct p9_trans_fd *ts = kmalloc(sizeof(struct p9_trans_fd), 1139 1139 GFP_KERNEL); ··· 1151 1151 return -EIO; 1152 1152 } 1153 1153 1154 - trans->priv = ts; 1155 - trans->status = Connected; 1154 + client->trans = ts; 1155 + client->status = Connected; 1156 1156 1157 1157 return 0; 1158 1158 } 1159 1159 1160 - static int p9_socket_open(struct p9_trans *trans, struct socket *csocket) 1160 + static int p9_socket_open(struct p9_client *client, struct socket *csocket) 1161 1161 { 1162 1162 int fd, ret; 1163 1163 ··· 1168 1168 return fd; 1169 1169 } 1170 1170 1171 - ret = p9_fd_open(trans, fd, fd); 1171 + ret = p9_fd_open(client, fd, fd); 1172 1172 if (ret < 0) { 1173 1173 P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to open fd\n"); 1174 1174 sockfd_put(csocket); 1175 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 1180 return 0; 1181 1181 } 1182 1182 1183 1183 /** 1184 1184 * p9_fd_read- read from a fd 1185 - * @trans: transport instance state 1185 + * @client: client instance 1186 1186 * @v: buffer to receive data into 1187 1187 * @len: size of receive buffer 1188 1188 * 1189 1189 */ 1190 1190 1191 - static int p9_fd_read(struct p9_trans *trans, void *v, int len) 1191 + static int p9_fd_read(struct p9_client *client, void *v, int len) 1192 1192 { 1193 1193 int ret; 1194 1194 struct p9_trans_fd *ts = NULL; 1195 1195 1196 - if (trans && trans->status != Disconnected) 1197 - ts = trans->priv; 1196 + if (client && client->status != Disconnected) 1197 + ts = client->trans; 1198 1198 1199 1199 if (!ts) 1200 1200 return -EREMOTEIO; ··· 1204 1204 1205 1205 ret = kernel_read(ts->rd, ts->rd->f_pos, v, len); 1206 1206 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN) 1207 - trans->status = Disconnected; 1207 + client->status = Disconnected; 1208 1208 return ret; 1209 1209 } 1210 1210 1211 1211 /** 1212 1212 * p9_fd_write - write to a socket 1213 - * @trans: transport instance state 1213 + * @client: client instance 1214 1214 * @v: buffer to send data from 1215 1215 * @len: size of send buffer 1216 1216 * 1217 1217 */ 1218 1218 1219 - static int p9_fd_write(struct p9_trans *trans, void *v, int len) 1219 + static int p9_fd_write(struct p9_client *client, void *v, int len) 1220 1220 { 1221 1221 int ret; 1222 1222 mm_segment_t oldfs; 1223 1223 struct p9_trans_fd *ts = NULL; 1224 1224 1225 - if (trans && trans->status != Disconnected) 1226 - ts = trans->priv; 1225 + if (client && client->status != Disconnected) 1226 + ts = client->trans; 1227 1227 1228 1228 if (!ts) 1229 1229 return -EREMOTEIO; ··· 1238 1238 set_fs(oldfs); 1239 1239 1240 1240 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN) 1241 - trans->status = Disconnected; 1241 + client->status = Disconnected; 1242 1242 return ret; 1243 1243 } 1244 1244 1245 1245 static unsigned int 1246 - p9_fd_poll(struct p9_trans *trans, struct poll_table_struct *pt) 1246 + p9_fd_poll(struct p9_client *client, struct poll_table_struct *pt) 1247 1247 { 1248 1248 int ret, n; 1249 1249 struct p9_trans_fd *ts = NULL; 1250 1250 1251 - if (trans && trans->status == Connected) 1252 - ts = trans->priv; 1251 + if (client && client->status == Connected) 1252 + ts = client->trans; 1253 1253 1254 1254 if (!ts) 1255 1255 return -EREMOTEIO; ··· 1275 1275 } 1276 1276 1277 1277 /** 1278 - * p9_fd_close - shutdown socket 1279 - * @trans: private socket structure 1278 + * p9_fd_close - shutdown file descriptor transport 1279 + * @client: client instance 1280 1280 * 1281 1281 */ 1282 1282 1283 - static void p9_fd_close(struct p9_trans *trans) 1283 + static void p9_fd_close(struct p9_client *client) 1284 1284 { 1285 1285 struct p9_trans_fd *ts; 1286 1286 1287 - if (!trans) 1287 + if (!client) 1288 1288 return; 1289 1289 1290 - ts = xchg(&trans->priv, NULL); 1291 - 1290 + ts = client->trans; 1292 1291 if (!ts) 1293 1292 return; 1294 1293 1294 + client->status = Disconnected; 1295 + 1295 1296 p9_conn_destroy(ts->conn); 1296 1297 1297 - trans->status = Disconnected; 1298 1298 if (ts->rd) 1299 1299 fput(ts->rd); 1300 1300 if (ts->wr) 1301 1301 fput(ts->wr); 1302 + 1302 1303 kfree(ts); 1303 1304 } 1304 1305 ··· 1320 1319 return 0; 1321 1320 } 1322 1321 1323 - static struct p9_trans * 1324 - p9_trans_create_tcp(const char *addr, char *args, int msize, unsigned char dotu) 1322 + static int 1323 + p9_fd_create_tcp(struct p9_client *client, const char *addr, char *args) 1325 1324 { 1326 1325 int err; 1327 - struct p9_trans *trans; 1328 1326 struct socket *csocket; 1329 1327 struct sockaddr_in sin_server; 1330 1328 struct p9_fd_opts opts; 1331 - struct p9_trans_fd *p; 1329 + struct p9_trans_fd *p = NULL; /* this gets allocated in p9_fd_open */ 1332 1330 1333 1331 err = parse_opts(args, &opts); 1334 1332 if (err < 0) 1335 - return ERR_PTR(err); 1333 + return err; 1336 1334 1337 1335 if (valid_ipaddr4(addr) < 0) 1338 - return ERR_PTR(-EINVAL); 1336 + return -EINVAL; 1339 1337 1340 1338 csocket = NULL; 1341 - trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL); 1342 - if (!trans) 1343 - return ERR_PTR(-ENOMEM); 1344 - trans->msize = msize; 1345 - trans->extended = dotu; 1346 - trans->rpc = p9_fd_rpc; 1347 - trans->close = p9_fd_close; 1348 1339 1349 1340 sin_server.sin_family = AF_INET; 1350 1341 sin_server.sin_addr.s_addr = in_aton(addr); ··· 1359 1366 goto error; 1360 1367 } 1361 1368 1362 - err = p9_socket_open(trans, csocket); 1369 + err = p9_socket_open(client, csocket); 1363 1370 if (err < 0) 1364 1371 goto error; 1365 1372 1366 - p = (struct p9_trans_fd *) trans->priv; 1367 - p->conn = p9_conn_create(trans); 1373 + p = (struct p9_trans_fd *) client->trans; 1374 + p->conn = p9_conn_create(client); 1368 1375 if (IS_ERR(p->conn)) { 1369 1376 err = PTR_ERR(p->conn); 1370 1377 p->conn = NULL; 1371 1378 goto error; 1372 1379 } 1373 1380 1374 - return trans; 1381 + return 0; 1375 1382 1376 1383 error: 1377 1384 if (csocket) 1378 1385 sock_release(csocket); 1379 1386 1380 - kfree(trans); 1381 - return ERR_PTR(err); 1387 + kfree(p); 1388 + 1389 + return err; 1382 1390 } 1383 1391 1384 - static struct p9_trans * 1385 - p9_trans_create_unix(const char *addr, char *args, int msize, 1386 - unsigned char dotu) 1392 + static int 1393 + p9_fd_create_unix(struct p9_client *client, const char *addr, char *args) 1387 1394 { 1388 1395 int err; 1389 1396 struct socket *csocket; 1390 1397 struct sockaddr_un sun_server; 1391 - struct p9_trans *trans; 1392 - struct p9_trans_fd *p; 1398 + struct p9_trans_fd *p = NULL; /* this gets allocated in p9_fd_open */ 1393 1399 1394 1400 csocket = NULL; 1395 - trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL); 1396 - if (!trans) 1397 - return ERR_PTR(-ENOMEM); 1398 - 1399 - trans->rpc = p9_fd_rpc; 1400 - trans->close = p9_fd_close; 1401 1401 1402 1402 if (strlen(addr) > UNIX_PATH_MAX) { 1403 1403 P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n", ··· 1411 1425 goto error; 1412 1426 } 1413 1427 1414 - err = p9_socket_open(trans, csocket); 1428 + err = p9_socket_open(client, csocket); 1415 1429 if (err < 0) 1416 1430 goto error; 1417 1431 1418 - trans->msize = msize; 1419 - trans->extended = dotu; 1420 - p = (struct p9_trans_fd *) trans->priv; 1421 - p->conn = p9_conn_create(trans); 1432 + p = (struct p9_trans_fd *) client->trans; 1433 + p->conn = p9_conn_create(client); 1422 1434 if (IS_ERR(p->conn)) { 1423 1435 err = PTR_ERR(p->conn); 1424 1436 p->conn = NULL; 1425 1437 goto error; 1426 1438 } 1427 1439 1428 - return trans; 1440 + return 0; 1429 1441 1430 1442 error: 1431 1443 if (csocket) 1432 1444 sock_release(csocket); 1433 1445 1434 - kfree(trans); 1435 - return ERR_PTR(err); 1446 + kfree(p); 1447 + return err; 1436 1448 } 1437 1449 1438 - static struct p9_trans * 1439 - p9_trans_create_fd(const char *name, char *args, int msize, 1440 - unsigned char extended) 1450 + static int 1451 + p9_fd_create(struct p9_client *client, const char *addr, char *args) 1441 1452 { 1442 1453 int err; 1443 - struct p9_trans *trans; 1444 1454 struct p9_fd_opts opts; 1445 - struct p9_trans_fd *p; 1455 + struct p9_trans_fd *p = NULL; /* this get allocated in p9_fd_open */ 1446 1456 1447 1457 parse_opts(args, &opts); 1448 1458 1449 1459 if (opts.rfd == ~0 || opts.wfd == ~0) { 1450 1460 printk(KERN_ERR "v9fs: Insufficient options for proto=fd\n"); 1451 - return ERR_PTR(-ENOPROTOOPT); 1461 + return -ENOPROTOOPT; 1452 1462 } 1453 1463 1454 - trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL); 1455 - if (!trans) 1456 - return ERR_PTR(-ENOMEM); 1457 - 1458 - trans->rpc = p9_fd_rpc; 1459 - trans->close = p9_fd_close; 1460 - 1461 - err = p9_fd_open(trans, opts.rfd, opts.wfd); 1464 + err = p9_fd_open(client, opts.rfd, opts.wfd); 1462 1465 if (err < 0) 1463 1466 goto error; 1464 1467 1465 - trans->msize = msize; 1466 - trans->extended = extended; 1467 - p = (struct p9_trans_fd *) trans->priv; 1468 - p->conn = p9_conn_create(trans); 1468 + p = (struct p9_trans_fd *) client->trans; 1469 + p->conn = p9_conn_create(client); 1469 1470 if (IS_ERR(p->conn)) { 1470 1471 err = PTR_ERR(p->conn); 1471 1472 p->conn = NULL; 1472 1473 goto error; 1473 1474 } 1474 1475 1475 - return trans; 1476 + return 0; 1476 1477 1477 1478 error: 1478 - kfree(trans); 1479 - return ERR_PTR(err); 1479 + kfree(p); 1480 + return err; 1480 1481 } 1481 1482 1482 1483 static struct p9_trans_module p9_tcp_trans = { 1483 1484 .name = "tcp", 1484 1485 .maxsize = MAX_SOCK_BUF, 1485 1486 .def = 1, 1486 - .create = p9_trans_create_tcp, 1487 + .create = p9_fd_create_tcp, 1488 + .close = p9_fd_close, 1489 + .rpc = p9_fd_rpc, 1487 1490 .owner = THIS_MODULE, 1488 1491 }; 1489 1492 ··· 1480 1505 .name = "unix", 1481 1506 .maxsize = MAX_SOCK_BUF, 1482 1507 .def = 0, 1483 - .create = p9_trans_create_unix, 1508 + .create = p9_fd_create_unix, 1509 + .close = p9_fd_close, 1510 + .rpc = p9_fd_rpc, 1484 1511 .owner = THIS_MODULE, 1485 1512 }; 1486 1513 ··· 1490 1513 .name = "fd", 1491 1514 .maxsize = MAX_SOCK_BUF, 1492 1515 .def = 0, 1493 - .create = p9_trans_create_fd, 1516 + .create = p9_fd_create, 1517 + .close = p9_fd_close, 1518 + .rpc = p9_fd_rpc, 1494 1519 .owner = THIS_MODULE, 1495 1520 }; 1496 1521
+20 -30
net/9p/trans_virtio.c
··· 41 41 #include <linux/file.h> 42 42 #include <net/9p/9p.h> 43 43 #include <linux/parser.h> 44 + #include <net/9p/client.h> 44 45 #include <net/9p/transport.h> 45 46 #include <linux/scatterlist.h> 46 47 #include <linux/virtio.h> ··· 55 54 static int chan_index; 56 55 57 56 #define P9_INIT_MAXTAG 16 58 - 59 57 60 58 /** 61 59 * enum p9_req_status_t - virtio request status ··· 197 197 * 198 198 */ 199 199 200 - static void p9_virtio_close(struct p9_trans *trans) 200 + static void p9_virtio_close(struct p9_client *client) 201 201 { 202 - struct virtio_chan *chan = trans->priv; 202 + struct virtio_chan *chan = client->trans; 203 203 int count; 204 204 unsigned long flags; 205 205 ··· 215 215 chan->inuse = false; 216 216 mutex_unlock(&virtio_9p_lock); 217 217 218 - kfree(trans); 218 + client->trans = NULL; 219 219 } 220 220 221 221 /** ··· 292 292 */ 293 293 294 294 static int 295 - p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc) 295 + p9_virtio_rpc(struct p9_client *c, struct p9_fcall *tc, struct p9_fcall **rc) 296 296 { 297 297 int in, out; 298 298 int n, err, size; 299 - struct virtio_chan *chan = t->priv; 299 + struct virtio_chan *chan = c->trans; 300 300 char *rdata; 301 301 struct p9_req_t *req; 302 302 unsigned long flags; 303 303 304 304 if (*rc == NULL) { 305 - *rc = kmalloc(sizeof(struct p9_fcall) + t->msize, GFP_KERNEL); 305 + *rc = kmalloc(sizeof(struct p9_fcall) + c->msize, GFP_KERNEL); 306 306 if (!*rc) 307 307 return -ENOMEM; 308 308 } ··· 325 325 P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio rpc tag %d\n", n); 326 326 327 327 out = pack_sg_list(chan->sg, 0, VIRTQUEUE_NUM, tc->sdata, tc->size); 328 - in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata, t->msize); 328 + in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata, c->msize); 329 329 330 330 req->status = REQ_STATUS_SENT; 331 331 ··· 341 341 342 342 size = le32_to_cpu(*(__le32 *) rdata); 343 343 344 - err = p9_deserialize_fcall(rdata, size, *rc, t->extended); 344 + err = p9_deserialize_fcall(rdata, size, *rc, c->dotu); 345 345 if (err < 0) { 346 346 P9_DPRINTK(P9_DEBUG_TRANS, 347 347 "9p debug: virtio rpc deserialize returned %d\n", err); ··· 352 352 if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) { 353 353 char buf[150]; 354 354 355 - p9_printfcall(buf, sizeof(buf), *rc, t->extended); 356 - printk(KERN_NOTICE ">>> %p %s\n", t, buf); 355 + p9_printfcall(buf, sizeof(buf), *rc, c->dotu); 356 + printk(KERN_NOTICE ">>> %p %s\n", c, buf); 357 357 } 358 358 #endif 359 359 ··· 422 422 423 423 /** 424 424 * p9_virtio_create - allocate a new virtio channel 425 + * @client: client instance invoking this transport 425 426 * @devname: string identifying the channel to connect to (unused) 426 427 * @args: args passed from sys_mount() for per-transport options (unused) 427 - * @msize: requested maximum packet size 428 - * @extended: 9p2000.u enabled flag 429 428 * 430 429 * This sets up a transport channel for 9p communication. Right now 431 430 * we only match the first available channel, but eventually we couldlook up ··· 440 441 * 441 442 */ 442 443 443 - static struct p9_trans * 444 - p9_virtio_create(const char *devname, char *args, int msize, 445 - unsigned char extended) 444 + static int 445 + p9_virtio_create(struct p9_client *client, const char *devname, char *args) 446 446 { 447 - struct p9_trans *trans; 448 447 struct virtio_chan *chan = channels; 449 448 int index = 0; 450 449 ··· 460 463 461 464 if (index >= MAX_9P_CHAN) { 462 465 printk(KERN_ERR "9p: no channels available\n"); 463 - return ERR_PTR(-ENODEV); 466 + return -ENODEV; 464 467 } 465 468 466 469 chan->tagpool = p9_idpool_create(); 467 470 if (IS_ERR(chan->tagpool)) { 468 471 printk(KERN_ERR "9p: couldn't allocate tagpool\n"); 469 - return ERR_PTR(-ENOMEM); 472 + return -ENOMEM; 470 473 } 471 474 p9_idpool_get(chan->tagpool); /* reserve tag 0 */ 472 475 chan->max_tag = 0; 473 476 chan->reqs = NULL; 474 477 475 - trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL); 476 - if (!trans) { 477 - printk(KERN_ERR "9p: couldn't allocate transport\n"); 478 - return ERR_PTR(-ENOMEM); 479 - } 480 - trans->extended = extended; 481 - trans->msize = msize; 482 - trans->close = p9_virtio_close; 483 - trans->rpc = p9_virtio_rpc; 484 - trans->priv = chan; 478 + client->trans = (void *)chan; 485 479 486 - return trans; 480 + return 0; 487 481 } 488 482 489 483 /** ··· 514 526 static struct p9_trans_module p9_virtio_trans = { 515 527 .name = "virtio", 516 528 .create = p9_virtio_create, 529 + .close = p9_virtio_close, 530 + .rpc = p9_virtio_rpc, 517 531 .maxsize = PAGE_SIZE*16, 518 532 .def = 0, 519 533 .owner = THIS_MODULE,