26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #include <linux/module.h>
29 #include <linux/errno.h>
31 #include <linux/poll.h>
34 #include <linux/slab.h>
35 #include <linux/sched.h>
43 #define CREATE_TRACE_POINTS
83 static int safe_errno(
int err)
94 static int get_protocol_version(
char *
s)
98 if (!
strcmp(s,
"9p2000")) {
101 }
else if (!
strcmp(s,
"9p2000.u")) {
104 }
else if (!
strcmp(s,
"9p2000.L")) {
108 pr_info(
"Unknown protocol version %s\n", s);
139 "failed to allocate copy of option string\n");
142 options = tmp_options;
154 "integer field, but no integer?\n");
165 "problem allocating copy of trans arg\n");
166 goto free_and_return;
170 pr_info(
"Could not find request transport: %s\n",
174 goto free_and_return;
186 "problem allocating copy of version arg\n");
187 goto free_and_return;
189 ret = get_protocol_version(s);
192 goto free_and_return;
228 int alloc_msize =
min(c->
msize, max_size);
243 pr_err(
"Couldn't grow tag array\n");
244 spin_unlock_irqrestore(&c->
lock, flags);
253 spin_unlock_irqrestore(&c->
lock, flags);
258 req = &c->
reqs[row][col];
262 pr_err(
"Couldn't grow tag array\n");
270 if ((!req->
tc) || (!req->
rc)) {
271 pr_err(
"Couldn't grow tag array\n");
279 req->
tc->capacity = alloc_msize;
280 req->
rc->capacity = alloc_msize;
281 req->
tc->sdata = (
char *) req->
tc +
sizeof(
struct p9_fcall);
282 req->
rc->sdata = (
char *) req->
rc +
sizeof(
struct p9_fcall);
288 req->
tc->tag = tag-1;
291 return &c->
reqs[row][col];
315 return &c->
reqs[row][col];
327 static int p9_tag_init(
struct p9_client *c)
353 static void p9_tag_cleanup(
struct p9_client *c)
362 "Attempting to cleanup non-free tag %d,%d\n",
396 int tag = r->
tc->tag;
441 err =
p9pdu_readf(pdu, 0,
"dbw", &r_size, &r_type, &r_tag);
443 goto rewind_and_exit;
489 trace_9p_protocol_dump(c, req->
rc);
542 char *uidata,
int in_hdrlen,
int kern_buf)
554 trace_9p_protocol_dump(c, req->
rc);
567 int inline_len = in_hdrlen - (7 + 2);
579 if (len <= inline_len) {
596 memcpy(ename + inline_len, uidata,
600 uidata, len - inline_len);
665 req = p9_client_rpc(c,
P9_TFLUSH,
"w", oldtag);
675 spin_unlock(&c->
lock);
682 int8_t type,
int req_size,
692 return ERR_PTR(-
EIO);
696 return ERR_PTR(-
EIO);
705 req = p9_tag_alloc(c, tag, req_size);
715 trace_9p_client_req(c, type, tag);
740 req = p9_client_prepare_req(c, type, c->
msize, fmt, ap);
779 p9_client_flush(c, req);
788 spin_unlock_irqrestore(&
current->sighand->siglock, flags);
793 err = p9_check_errors(c, req);
794 trace_9p_client_res(c, type, req->
rc->tag, err);
799 return ERR_PTR(safe_errno(err));
816 char *uidata,
char *uodata,
817 int inlen,
int olen,
int in_hdrlen,
818 int kern_buf,
const char *fmt, ...)
830 req = p9_client_prepare_req(c, type,
P9_ZC_HDR_SZ, fmt, ap);
845 err = c->
trans_mod->zc_request(c, req, uidata, uodata,
846 inlen, olen, in_hdrlen, kern_buf);
862 p9_client_flush(c, req);
871 spin_unlock_irqrestore(&
current->sighand->siglock, flags);
876 err = p9_check_zc_errors(c, req, uidata, in_hdrlen, kern_buf);
877 trace_9p_client_res(c, type, req->
rc->tag, err);
882 return ERR_PTR(safe_errno(err));
910 spin_unlock_irqrestore(&clnt->
lock, flags);
919 static void p9_fid_destroy(
struct p9_fid *fid)
929 spin_unlock_irqrestore(&clnt->
lock, flags);
934 static int p9_client_version(
struct p9_client *c)
947 c->
msize,
"9P2000.L");
951 c->
msize,
"9P2000.u");
968 trace_9p_protocol_dump(c, req->
rc);
973 if (!
strncmp(version,
"9P2000.L", 8))
975 else if (!
strncmp(version,
"9P2000.u", 8))
977 else if (!
strncmp(version,
"9P2000", 6))
984 if (msize < c->msize)
1007 INIT_LIST_HEAD(&clnt->
fidlist);
1009 err = p9_tag_init(clnt);
1013 err = parse_opts(options, clnt);
1015 goto destroy_tagpool;
1023 "No transport defined or default transport\n");
1024 goto destroy_tagpool;
1036 err = clnt->
trans_mod->create(clnt, dev_name, options);
1038 goto destroy_fidpool;
1043 err = p9_client_version(clnt);
1059 return ERR_PTR(err);
1075 pr_info(
"Found fid %d not clunked\n", fid->
fid);
1076 p9_fid_destroy(fid);
1082 p9_tag_cleanup(clnt);
1103 char *uname,
u32 n_uname,
char *aname)
1112 afid ? afid->
fid : -1, uname, aname);
1113 fid = p9_fid_create(clnt);
1121 afid ? afid->
fid :
P9_NOFID, uname, aname, n_uname);
1129 trace_9p_protocol_dump(clnt, req->
rc);
1130 p9_free_req(clnt, req);
1139 p9_free_req(clnt, req);
1144 p9_fid_destroy(fid);
1145 return ERR_PTR(err);
1150 char **wnames,
int clone)
1161 clnt = oldfid->
clnt;
1163 fid = p9_fid_create(clnt);
1176 oldfid->
fid, fid->
fid, nwname, wnames ? wnames[0] :
NULL);
1178 req = p9_client_rpc(clnt,
P9_TWALK,
"ddT", oldfid->
fid, fid->
fid,
1187 trace_9p_protocol_dump(clnt, req->
rc);
1188 p9_free_req(clnt, req);
1191 p9_free_req(clnt, req);
1195 if (nwqids != nwname) {
1200 for (count = 0; count < nwqids; count++)
1202 count, wqids[count].type,
1203 (
unsigned long long)wqids[count].
path,
1204 wqids[count].version);
1220 if (fid && (fid != oldfid))
1221 p9_fid_destroy(fid);
1223 return ERR_PTR(err);
1240 if (fid->
mode != -1)
1244 req = p9_client_rpc(clnt,
P9_TLOPEN,
"dd", fid->
fid, mode);
1246 req = p9_client_rpc(clnt,
P9_TOPEN,
"db", fid->
fid, mode);
1254 trace_9p_protocol_dump(clnt, req->
rc);
1255 goto free_and_error;
1260 (
unsigned long long)qid.
path, qid.
version, iounit);
1266 p9_free_req(clnt, req);
1281 ">>> TLCREATE fid %d name %s flags %d mode %d gid %d\n",
1282 ofid->
fid, name, flags, mode, gid);
1285 if (ofid->
mode != -1)
1288 req = p9_client_rpc(clnt,
P9_TLCREATE,
"dsddd", ofid->
fid, name, flags,
1297 trace_9p_protocol_dump(clnt, req->
rc);
1298 goto free_and_error;
1303 (
unsigned long long)qid->
path,
1310 p9_free_req(clnt, req);
1326 fid->
fid, name, perm, mode);
1330 if (fid->
mode != -1)
1333 req = p9_client_rpc(clnt,
P9_TCREATE,
"dsdb?s", fid->
fid, name, perm,
1342 trace_9p_protocol_dump(clnt, req->
rc);
1343 goto free_and_error;
1348 (
unsigned long long)qid.
path,
1355 p9_free_req(clnt, req);
1369 dfid->
fid, name, symtgt);
1372 req = p9_client_rpc(clnt,
P9_TSYMLINK,
"dssd", dfid->
fid, name, symtgt,
1381 trace_9p_protocol_dump(clnt, req->
rc);
1382 goto free_and_error;
1389 p9_free_req(clnt, req);
1401 dfid->
fid, oldfid->
fid, newname);
1403 req = p9_client_rpc(clnt,
P9_TLINK,
"dds", dfid->
fid, oldfid->
fid,
1406 return PTR_ERR(req);
1409 p9_free_req(clnt, req);
1421 fid->
fid, datasync);
1425 req = p9_client_rpc(clnt,
P9_TFSYNC,
"dd", fid->
fid, datasync);
1433 p9_free_req(clnt, req);
1448 pr_warn(
"%s (%d): Trying to clunk with NULL fid\n",
1449 __func__, task_pid_nr(
current));
1468 p9_free_req(clnt, req);
1479 p9_fid_destroy(fid);
1502 p9_free_req(clnt, req);
1507 p9_fid_destroy(fid);
1519 dfid->
fid, name, flags);
1522 req = p9_client_rpc(clnt,
P9_TUNLINKAT,
"dsd", dfid->
fid, name, flags);
1529 p9_free_req(clnt, req);
1543 int err, rsize, non_zc = 0;
1547 fid->
fid, (
unsigned long long) offset, count);
1559 if (clnt->
trans_mod->zc_request && rsize > 1024) {
1565 indata = (
__force char *)udata;
1570 req = p9_client_zc_rpc(clnt,
P9_TREAD, indata,
NULL, rsize, 0,
1571 11, kernel_buf,
"dqd", fid->
fid,
1575 req = p9_client_rpc(clnt,
P9_TREAD,
"dqd", fid->
fid, offset,
1585 trace_9p_protocol_dump(clnt, req->
rc);
1586 goto free_and_error;
1593 memmove(data, dataptr, count);
1598 goto free_and_error;
1602 p9_free_req(clnt, req);
1606 p9_free_req(clnt, req);
1622 fid->
fid, (
unsigned long long) offset, count);
1634 if (clnt->
trans_mod->zc_request && rsize > 1024) {
1640 odata = (
char *)udata;
1641 req = p9_client_zc_rpc(clnt,
P9_TWRITE,
NULL, odata, 0, rsize,
1643 fid->
fid, offset, rsize);
1647 offset, rsize, data);
1650 offset, rsize, udata);
1659 trace_9p_protocol_dump(clnt, req->
rc);
1660 goto free_and_error;
1665 p9_free_req(clnt, req);
1669 p9_free_req(clnt, req);
1691 req = p9_client_rpc(clnt,
P9_TSTAT,
"d", fid->
fid);
1699 trace_9p_protocol_dump(clnt, req->
rc);
1700 p9_free_req(clnt, req);
1705 "<<< RSTAT sz=%x type=%x dev=%x qid=%x.%llx.%x\n"
1706 "<<< mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n"
1707 "<<< name=%s uid=%s gid=%s muid=%s extension=(%s)\n"
1708 "<<< uid=%d gid=%d n_muid=%d\n",
1710 (
unsigned long long)ret->
qid.path, ret->
qid.version, ret->
mode,
1715 p9_free_req(clnt, req);
1720 return ERR_PTR(err);
1734 fid->
fid, request_mask);
1742 req = p9_client_rpc(clnt,
P9_TGETATTR,
"dq", fid->
fid, request_mask);
1750 trace_9p_protocol_dump(clnt, req->
rc);
1751 p9_free_req(clnt, req);
1756 "<<< RGETATTR st_result_mask=%lld\n"
1757 "<<< qid=%x.%llx.%x\n"
1758 "<<< st_mode=%8.8x st_nlink=%llu\n"
1759 "<<< st_uid=%d st_gid=%d\n"
1760 "<<< st_rdev=%llx st_size=%llx st_blksize=%llu st_blocks=%llu\n"
1761 "<<< st_atime_sec=%lld st_atime_nsec=%lld\n"
1762 "<<< st_mtime_sec=%lld st_mtime_nsec=%lld\n"
1763 "<<< st_ctime_sec=%lld st_ctime_nsec=%lld\n"
1764 "<<< st_btime_sec=%lld st_btime_nsec=%lld\n"
1765 "<<< st_gen=%lld st_data_version=%lld",
1774 p9_free_req(clnt, req);
1779 return ERR_PTR(err);
1783 static int p9_client_statsize(
struct p9_wstat *wst,
int proto_version)
1791 ret = 2+4+13+4+4+4+8+2+2+2+2;
1823 " sz=%x type=%x dev=%x qid=%x.%llx.%x\n"
1824 " mode=%8.8x atime=%8.8x mtime=%8.8x length=%llx\n"
1825 " name=%s uid=%s gid=%s muid=%s extension=(%s)\n"
1826 " uid=%d gid=%d n_muid=%d\n",
1828 (
unsigned long long)wst->
qid.path, wst->
qid.version, wst->
mode,
1841 p9_free_req(clnt, req);
1857 " valid=%x mode=%x uid=%d gid=%d size=%lld\n"
1858 " atime_sec=%lld atime_nsec=%lld\n"
1859 " mtime_sec=%lld mtime_nsec=%lld\n",
1871 p9_free_req(clnt, req);
1898 trace_9p_protocol_dump(clnt, req->
rc);
1899 p9_free_req(clnt, req);
1904 "blocks %llu bfree %llu bavail %llu files %llu ffree %llu "
1905 "fsid %llu namelen %ld\n",
1906 fid->
fid, (
long unsigned int)sb->
type, (
long int)sb->
bsize,
1910 p9_free_req(clnt, req);
1927 fid->
fid, newdirfid->
fid, name);
1930 newdirfid->
fid, name);
1938 p9_free_req(clnt, req);
1945 struct p9_fid *newdirfid,
const char *new_name)
1952 clnt = olddirfid->
clnt;
1955 " newdirfid %d new name %s\n", olddirfid->
fid, old_name,
1956 newdirfid->
fid, new_name);
1959 old_name, newdirfid->
fid, new_name);
1966 newdirfid->
fid, new_name);
1968 p9_free_req(clnt, req);
1986 clnt = file_fid->
clnt;
1987 attr_fid = p9_fid_create(clnt);
1988 if (IS_ERR(attr_fid)) {
1989 err = PTR_ERR(attr_fid);
1994 ">>> TXATTRWALK file_fid %d, attr_fid %d name %s\n",
1995 file_fid->
fid, attr_fid->
fid, attr_name);
1998 file_fid->
fid, attr_fid->
fid, attr_name);
2005 trace_9p_protocol_dump(clnt, req->
rc);
2006 p9_free_req(clnt, req);
2009 p9_free_req(clnt, req);
2011 attr_fid->
fid, *attr_size);
2017 if (attr_fid && (attr_fid != file_fid))
2018 p9_fid_destroy(attr_fid);
2020 return ERR_PTR(err);
2025 u64 attr_size,
int flags)
2032 ">>> TXATTRCREATE fid %d name %s size %lld flag %d\n",
2033 fid->
fid, name, (
long long)attr_size, flags);
2037 fid->
fid, name, attr_size, flags);
2043 p9_free_req(clnt, req);
2051 int err, rsize, non_zc = 0;
2057 fid->
fid, (
unsigned long long) offset, count);
2070 if (clnt->
trans_mod->zc_request && rsize > 1024) {
2076 11, 1,
"dqd", fid->
fid, offset, rsize);
2089 trace_9p_protocol_dump(clnt, req->
rc);
2090 goto free_and_error;
2096 memmove(data, dataptr, count);
2098 p9_free_req(clnt, req);
2102 p9_free_req(clnt, req);
2118 "minor %d\n", fid->
fid, name, mode,
MAJOR(rdev),
MINOR(rdev));
2119 req = p9_client_rpc(clnt,
P9_TMKNOD,
"dsdddd", fid->
fid, name, mode,
2122 return PTR_ERR(req);
2126 trace_9p_protocol_dump(clnt, req->
rc);
2133 p9_free_req(clnt, req);
2149 fid->
fid, name, mode, gid);
2150 req = p9_client_rpc(clnt,
P9_TMKDIR,
"dsdd", fid->
fid, name, mode,
2153 return PTR_ERR(req);
2157 trace_9p_protocol_dump(clnt, req->
rc);
2164 p9_free_req(clnt, req);
2179 "start %lld length %lld proc_id %d client_id %s\n",
2188 return PTR_ERR(req);
2192 trace_9p_protocol_dump(clnt, req->
rc);
2197 p9_free_req(clnt, req);
2212 "length %lld proc_id %d client_id %s\n", fid->
fid, glock->
type,
2219 return PTR_ERR(req);
2225 trace_9p_protocol_dump(clnt, req->
rc);
2229 "proc_id %d client_id %s\n", glock->
type, glock->
start,
2232 p9_free_req(clnt, req);
2249 return PTR_ERR(req);
2253 trace_9p_protocol_dump(clnt, req->
rc);
2258 p9_free_req(clnt, req);