static int plan9_create(struct session_struct *sp, struct p9_client **cp) { struct p9_nbd_device *nbd = sp->nbd; struct p9_client *clnt = NULL; int err; dprintk(DBG_PLAN9, "%s: p9_client_create %s %s\n", nbd->disk->disk_name, nbd->p9_addr, nbd->p9_opts); session_busy(sp); clnt = p9_client_create(nbd->p9_addr, nbd->p9_opts); if (IS_ERR(clnt)) return PTR_ERR(clnt); if (clnt->msize - P9_IOHDRSZ < nbd->blksize) { err = -EINVAL; goto error; } if (clnt->proto_version != p9_proto_2000L) { err = -EINVAL; goto error; } if (session_idle(sp) < 0) { err = -ETIMEDOUT; goto error; } *cp = clnt; return 0; error: if (clnt) p9_client_destroy(clnt); return err; }
struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses, const char *dev_name, char *data) { int retval = -EINVAL; struct p9_transport *trans; struct p9_fid *fid; v9ses->name = __getname(); if (!v9ses->name) return ERR_PTR(-ENOMEM); v9ses->remotename = __getname(); if (!v9ses->remotename) { __putname(v9ses->name); return ERR_PTR(-ENOMEM); } strcpy(v9ses->name, V9FS_DEFUSER); strcpy(v9ses->remotename, V9FS_DEFANAME); v9fs_parse_options(data, v9ses); switch (v9ses->proto) { case PROTO_TCP: trans = p9_trans_create_tcp(dev_name, v9ses->port); break; case PROTO_UNIX: trans = p9_trans_create_unix(dev_name); *v9ses->remotename = 0; break; case PROTO_FD: trans = p9_trans_create_fd(v9ses->rfdno, v9ses->wfdno); *v9ses->remotename = 0; break; #ifdef CONFIG_PCI_9P case PROTO_PCI: trans = p9pci_trans_create(); *v9ses->remotename = 0; break; #endif default: printk(KERN_ERR "v9fs: Bad mount protocol %d\n", v9ses->proto); retval = -ENOPROTOOPT; goto error; }; if (IS_ERR(trans)) { retval = PTR_ERR(trans); trans = NULL; goto error; } v9ses->clnt = p9_client_create(trans, v9ses->maxdata + P9_IOHDRSZ, v9ses->extended); if (IS_ERR(v9ses->clnt)) { retval = PTR_ERR(v9ses->clnt); v9ses->clnt = NULL; P9_DPRINTK(P9_DEBUG_ERROR, "problem initializing 9p client\n"); goto error; } fid = p9_client_attach(v9ses->clnt, NULL, v9ses->name, v9ses->remotename); if (IS_ERR(fid)) { retval = PTR_ERR(fid); fid = NULL; P9_DPRINTK(P9_DEBUG_ERROR, "cannot attach\n"); goto error; } return fid; error: v9fs_session_close(v9ses); return ERR_PTR(retval); }
struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses, const char *dev_name, char *data) { int retval = -EINVAL; struct p9_fid *fid; int rc; v9ses->uname = __getname(); if (!v9ses->uname) return ERR_PTR(-ENOMEM); v9ses->aname = __getname(); if (!v9ses->aname) { __putname(v9ses->uname); return ERR_PTR(-ENOMEM); } v9ses->flags = V9FS_EXTENDED | V9FS_ACCESS_USER; strcpy(v9ses->uname, V9FS_DEFUSER); strcpy(v9ses->aname, V9FS_DEFANAME); v9ses->uid = ~0; v9ses->dfltuid = V9FS_DEFUID; v9ses->dfltgid = V9FS_DEFGID; if (data) { v9ses->options = kstrdup(data, GFP_KERNEL); if (!v9ses->options) { P9_DPRINTK(P9_DEBUG_ERROR, "failed to allocate copy of option string\n"); retval = -ENOMEM; goto error; } } rc = v9fs_parse_options(v9ses); if (rc < 0) { retval = rc; goto error; } v9ses->clnt = p9_client_create(dev_name, v9ses->options); if (IS_ERR(v9ses->clnt)) { retval = PTR_ERR(v9ses->clnt); v9ses->clnt = NULL; P9_DPRINTK(P9_DEBUG_ERROR, "problem initializing 9p client\n"); goto error; } if (!v9ses->clnt->dotu) v9ses->flags &= ~V9FS_EXTENDED; v9ses->maxdata = v9ses->clnt->msize; /* for legacy mode, fall back to V9FS_ACCESS_ANY */ if (!v9fs_extended(v9ses) && ((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) { v9ses->flags &= ~V9FS_ACCESS_MASK; v9ses->flags |= V9FS_ACCESS_ANY; v9ses->uid = ~0; } fid = p9_client_attach(v9ses->clnt, NULL, v9ses->uname, ~0, v9ses->aname); if (IS_ERR(fid)) { retval = PTR_ERR(fid); fid = NULL; P9_DPRINTK(P9_DEBUG_ERROR, "cannot attach\n"); goto error; } if ((v9ses->flags & V9FS_ACCESS_MASK) == V9FS_ACCESS_SINGLE) fid->uid = v9ses->uid; else fid->uid = ~0; return fid; error: return ERR_PTR(retval); }