Lines Matching +full:qemu +full:- +full:user +full:- +full:static

1 /*-
54 static MALLOC_DEFINE(M_P9CLNT, "p9_client", "p9fs client structure");
55 static uma_zone_t p9fs_fid_zone;
56 static uma_zone_t p9fs_req_zone;
57 static uma_zone_t p9fs_buf_zone;
64 static struct p9_req_t *p9_get_request(struct p9_client *c, int *error);
65 static struct p9_req_t *p9_client_request(
72 return (clnt->proto_version == p9_proto_2000L); in p9_is_proto_dotl()
79 return (clnt->proto_version == p9_proto_2000u); in p9_is_proto_dotu()
83 static int
92 error = vfs_getopt(mp->mnt_optnew, "trans", (void **)&trans, &len); in p9_parse_opts()
97 clnt->proto_version = p9_proto_2000L; in p9_parse_opts()
98 clnt->msize = 8192; in p9_parse_opts()
101 clnt->ops = p9_get_trans_by_name(trans); in p9_parse_opts()
107 static struct p9_buffer *
113 fc->capacity = alloc_msize; in p9_buffer_alloc()
114 fc->offset = 0; in p9_buffer_alloc()
115 fc->size = 0; in p9_buffer_alloc()
116 fc->sdata = (char *)fc + sizeof(struct p9_buffer); in p9_buffer_alloc()
122 static void
132 static void
136 if (req->tc != NULL) { in p9_free_req()
137 if (req->tc->tag != P9_NOTAG) in p9_free_req()
138 p9_tag_destroy(clnt, req->tc->tag); in p9_free_req()
139 p9_buffer_free(&req->tc); in p9_free_req()
142 if (req->rc != NULL) in p9_free_req()
143 p9_buffer_free(&req->rc); in p9_free_req()
149 static struct p9_req_t *
159 req->tc = p9_buffer_alloc(alloc_msize); in p9_get_request()
160 req->rc = p9_buffer_alloc(alloc_msize); in p9_get_request()
165 req->tc->tag = P9_NOTAG; in p9_get_request()
169 req->tc->tag = tag; in p9_get_request()
174 static int
182 buf->offset = 0; in p9_parse_receive()
184 /* This value is set by QEMU for the header.*/ in p9_parse_receive()
185 if (buf->size == 0) in p9_parse_receive()
186 buf->size = QEMU_HEADER; in p9_parse_receive()
193 buf->size = size; in p9_parse_receive()
194 buf->id = type; in p9_parse_receive()
195 buf->tag = tag; in p9_parse_receive()
197 __func__, buf->size, buf->id, buf->tag); in p9_parse_receive()
203 static int
211 error = p9_parse_receive(req->rc, c); in p9_client_check_return()
219 if (req->rc->id != P9PROTO_RERROR && req->rc->id != P9PROTO_RLERROR) in p9_client_check_return()
226 if (req->rc->id == P9PROTO_RERROR) { in p9_client_check_return()
227 error = p9_buf_readf(req->rc, c->proto_version, "s?d", &ename, &ecode); in p9_client_check_return()
228 } else if (req->rc->id == P9PROTO_RLERROR) { in p9_client_check_return()
229 error = p9_buf_readf(req->rc, c->proto_version, "d", &ecode); in p9_client_check_return()
244 if (req->rc->id == P9PROTO_RERROR) { in p9_client_check_return()
247 } else if (req->rc->id == P9PROTO_RLERROR) { in p9_client_check_return()
252 if (req->rc->id == P9PROTO_RERROR) { in p9_client_check_return()
267 clnt->trans_status = P9FS_DISCONNECT; in p9_client_disconnect()
274 clnt->trans_status = P9FS_BEGIN_DISCONNECT; in p9_client_begin_disconnect()
277 static struct p9_req_t *
291 if (c->trans_status == P9FS_DISCONNECT) { in p9_client_prepare_req()
297 if ((c->trans_status == P9FS_BEGIN_DISCONNECT) && in p9_client_prepare_req()
310 /* Marshall the data according to QEMU standards */ in p9_client_prepare_req()
311 *error = p9_buf_prepare(req->tc, type); in p9_client_prepare_req()
318 *error = p9_buf_vwritef(req->tc, c->proto_version, fmt, ap); in p9_client_prepare_req()
325 *error = p9_buf_finalize(c, req->tc); in p9_client_prepare_req()
343 static struct p9_req_t *
351 req = p9_client_prepare_req(c, type, c->msize, error, fmt, ap); in p9_client_request()
359 *error = c->ops->request(c->handle, req); in p9_client_request()
385 tag = alloc_unr(&clnt->tagpool); in p9_tag_create()
388 /* Alloc_unr returning -1 is an error for no units left */ in p9_tag_create()
389 if (tag == -1) { in p9_tag_create()
403 free_unr(&clnt->tagpool, tag); in p9_tag_destroy()
414 fid->fid = alloc_unr(&clnt->fidpool); in p9_fid_create()
415 P9_DEBUG(LPROTO, "%s: fid %d\n", __func__, fid->fid); in p9_fid_create()
417 /* Alloc_unr returning -1 is an error for no units left */ in p9_fid_create()
418 if (fid->fid == -1) { in p9_fid_create()
422 fid->mode = -1; in p9_fid_create()
423 fid->uid = -1; in p9_fid_create()
424 fid->clnt = clnt; in p9_fid_create()
435 P9_DEBUG(LPROTO, "%s: fid %d\n", __func__, fid->fid); in p9_fid_destroy()
436 clnt = fid->clnt; in p9_fid_destroy()
438 free_unr(&clnt->fidpool, fid->fid); in p9_fid_destroy()
454 c->msize, c->proto_version); in p9_client_version()
456 switch (c->proto_version) { in p9_client_version()
459 c->msize, "9P2000.L"); in p9_client_version()
463 c->msize, "9P2000.u"); in p9_client_version()
467 c->msize, "9P2000"); in p9_client_version()
477 error = p9_buf_readf(req->rc, c->proto_version, "ds", &msize, &version); in p9_client_version()
486 c->proto_version = p9_proto_2000L; in p9_client_version()
488 c->proto_version = p9_proto_2000u; in p9_client_version()
490 c->proto_version = p9_proto_legacy; in p9_client_version()
497 if (msize < c->msize) in p9_client_version()
498 c->msize = msize; in p9_client_version()
542 mtx_init(&clnt->clnt_mtx, "p9clnt", NULL, MTX_DEF); in p9_client_create()
549 if (clnt->ops == NULL) { in p9_client_create()
556 init_unrhdr(&clnt->fidpool, P9FS_ROOT_FID_NO, P9FS_MAX_FID_CNT, in p9_client_create()
557 &clnt->clnt_mtx); in p9_client_create()
558 init_unrhdr(&clnt->tagpool, P9FS_MIN_TAG, P9FS_MAX_TAG, in p9_client_create()
559 &clnt->clnt_mtx); in p9_client_create()
562 __func__, clnt, clnt->ops, clnt->msize, clnt->proto_version); in p9_client_create()
564 *error = clnt->ops->create(mount_tag, &clnt->handle); in p9_client_create()
570 clnt->trans_status = P9FS_CONNECT; in p9_client_create()
589 clnt->ops->close(clnt->handle); in p9_client_destroy()
592 clear_unrhdr(&clnt->fidpool); in p9_client_destroy()
595 clear_unrhdr(&clnt->tagpool); in p9_client_destroy()
601 * Attach a user to the filesystem. Create a fid for that user to access
619 fid->uid = n_uname; in p9_client_attach()
621 req = p9_client_request(clnt, P9PROTO_TATTACH, error, "ddssd", fid->fid, in p9_client_attach()
626 *error = p9_buf_readf(req->rc, clnt->proto_version, "Q", &qid); in p9_client_attach()
636 memmove(&fid->qid, &qid, sizeof(struct p9_qid)); in p9_client_attach()
657 P9_DEBUG(PROTO, "TREMOVE fid %d\n", fid->fid); in p9_client_remove()
660 clnt = fid->clnt; in p9_client_remove()
662 req = p9_client_request(clnt, P9PROTO_TREMOVE, &error, "d", fid->fid); in p9_client_remove()
664 P9_DEBUG(PROTO, "RREMOVE fid %d\n", fid->fid); in p9_client_remove()
680 clnt = dfid->clnt; in p9_client_unlink()
683 dfid->fid, name, flags); in p9_client_unlink()
685 P9_DEBUG(PROTO, "RUNLINKAT fid %d\n", dfid->fid); in p9_client_unlink()
711 P9_DEBUG(PROTO, "TCLUNK fid %d \n", fid->fid); in p9_client_clunk()
713 clnt = fid->clnt; in p9_client_clunk()
714 req = p9_client_request(clnt, P9PROTO_TCLUNK, &error, "d", fid->fid); in p9_client_clunk()
716 P9_DEBUG(PROTO, "RCLUNK fid %d\n", fid->fid); in p9_client_clunk()
740 clnt = oldfid->clnt; in p9_client_walk()
749 if (clnt->trans_status != P9FS_CONNECT) { in p9_client_walk()
760 fid->uid = oldfid->uid; in p9_client_walk()
765 oldfid->fid, fid->fid, nwnames, in p9_client_walk()
766 wnames != NULL ? wnames[nwnames-1] : NULL); in p9_client_walk()
770 * qemu on other side allocates or returns a fid if it sees a match in p9_client_walk()
772 req = p9_client_request(clnt, P9PROTO_TWALK, error, "ddT", oldfid->fid, in p9_client_walk()
773 fid->fid, wnames, nwnames); in p9_client_walk()
780 *error = p9_buf_readf(req->rc, clnt->proto_version, "R", &nwqids, in p9_client_walk()
799 memmove(&fid->qid, &wqids[nwqids - 1], sizeof(struct p9_qid)); in p9_client_walk()
801 fid->qid = oldfid->qid; in p9_client_walk()
825 clnt = fid->clnt; in p9_client_open()
830 fid->fid, mode); in p9_client_open()
832 if (fid->mode != -1) in p9_client_open()
837 fid->fid, mode); in p9_client_open()
840 fid->fid, mode); in p9_client_open()
845 error = p9_buf_readf(req->rc, clnt->proto_version, "Qd", &fid->qid, in p9_client_open()
852 (fid->qid).type, (unsigned long long)(fid->qid).path, in p9_client_open()
853 (fid->qid).version, mtu); in p9_client_open()
855 fid->mode = mode; in p9_client_open()
856 fid->mtu = mtu; in p9_client_open()
874 fid->fid, (unsigned long long) offset, count); in p9_client_readdir()
877 rsize = fid->mtu; in p9_client_readdir()
878 clnt = fid->clnt; in p9_client_readdir()
880 if (rsize == 0 || rsize > clnt->msize) in p9_client_readdir()
881 rsize = clnt->msize; in p9_client_readdir()
887 fid->fid, offset, rsize); in p9_client_readdir()
892 return (-error); in p9_client_readdir()
895 error = p9_buf_readf(req->rc, clnt->proto_version, "D", &count, in p9_client_readdir()
901 return (-error); in p9_client_readdir()
914 * buffer data. This buffer is handed over to p9fs to process into user
916 * so in case of an error we return -error so that we can distinguish between
927 clnt = fid->clnt; in p9_client_read()
928 rsize = fid->mtu; in p9_client_read()
932 fid->fid, (unsigned long long) offset, count); in p9_client_read()
934 if (!rsize || rsize > clnt->msize) in p9_client_read()
935 rsize = clnt->msize; in p9_client_read()
941 req = p9_client_request(clnt, P9PROTO_TREAD, &error, "dqd", fid->fid, in p9_client_read()
945 return (-error); in p9_client_read()
948 error = p9_buf_readf(req->rc, clnt->proto_version, "D", &count, in p9_client_read()
964 error = -EIO; in p9_client_read()
975 return (-error); in p9_client_read()
981 * so in case of an error we return -error so that we can distinguish between
992 clnt = fid->clnt; in p9_client_write()
993 rsize = fid->mtu; in p9_client_write()
998 fid->fid, (unsigned long long) offset, count); in p9_client_write()
1000 if (!rsize || rsize > clnt->msize) in p9_client_write()
1001 rsize = clnt->msize; in p9_client_write()
1003 /* Limit set by Qemu ,8168 */ in p9_client_write()
1012 req = p9_client_request(clnt, P9PROTO_TWRITE, &error, "dqD", fid->fid, in p9_client_write()
1017 return (-error); in p9_client_write()
1020 error = p9_buf_readf(req->rc, clnt->proto_version, "d", &ret); in p9_client_write()
1043 return (-error); in p9_client_write()
1059 fid->fid, name, perm, mode); in p9_client_file_create()
1061 clnt = fid->clnt; in p9_client_file_create()
1064 if (fid->mode != -1) in p9_client_file_create()
1068 fid->fid, name, perm, mode, extension); in p9_client_file_create()
1072 error = p9_buf_readf(req->rc, clnt->proto_version, "Qd", &qid, &mtu); in p9_client_file_create()
1078 fid->mode = mode; in p9_client_file_create()
1079 fid->mtu = mtu; in p9_client_file_create()
1095 clnt = fid->clnt; in p9_client_statfs()
1097 P9_DEBUG(PROTO, "TSTATFS fid %d\n", fid->fid); in p9_client_statfs()
1099 req = p9_client_request(clnt, P9PROTO_TSTATFS, &error, "d", fid->fid); in p9_client_statfs()
1104 error = p9_buf_readf(req->rc, clnt->proto_version, "ddqqqqqqd", in p9_client_statfs()
1105 &stat->type, &stat->bsize, &stat->blocks, &stat->bfree, in p9_client_statfs()
1106 &stat->bavail, &stat->files, &stat->ffree, &stat->fsid, in p9_client_statfs()
1107 &stat->namelen); in p9_client_statfs()
1115 fid->fid, (uintmax_t)stat->type, in p9_client_statfs()
1116 (uintmax_t)stat->bsize, (uintmax_t)stat->blocks, in p9_client_statfs()
1117 (uintmax_t)stat->bfree, (uintmax_t)stat->bavail, in p9_client_statfs()
1118 (uintmax_t)stat->files, (uintmax_t)stat->ffree, in p9_client_statfs()
1119 (uintmax_t)stat->fsid, (uintmax_t)stat->namelen); in p9_client_statfs()
1136 oldfid->fid, oldname, newfid->fid, newname); in p9_client_renameat()
1139 clnt = oldfid->clnt; in p9_client_renameat()
1143 * the 9p protocol version 9p2000.u as the QEMU version supports this in p9_client_renameat()
1147 oldfid->fid, oldname, newfid->fid, newname); in p9_client_renameat()
1166 clnt = fid->clnt; in p9_create_symlink()
1168 P9_DEBUG(PROTO, "TSYMLINK fid %d name %s\n", fid->fid, name); in p9_create_symlink()
1171 fid->fid, name, symtgt, gid); in p9_create_symlink()
1176 error = p9_buf_readf(req->rc, clnt->proto_version, "Q", &qid); in p9_create_symlink()
1198 clnt = dfid->clnt; in p9_create_hardlink()
1201 dfid->fid, oldfid->fid, name); in p9_create_hardlink()
1203 req = p9_client_request(clnt, P9PROTO_TLINK, &error, "dds", dfid->fid, in p9_create_hardlink()
1204 oldfid->fid, name); in p9_create_hardlink()
1221 clnt = fid->clnt; in p9_readlink()
1223 P9_DEBUG(PROTO, "TREADLINK fid %d\n", fid->fid); in p9_readlink()
1225 req = p9_client_request(clnt, P9PROTO_TREADLINK, &error, "d", fid->fid); in p9_readlink()
1229 error = p9_buf_readf(req->rc, clnt->proto_version, "s", target); in p9_readlink()
1253 fid->fid, (uintmax_t)request_mask); in p9_client_getattr()
1255 clnt = fid->clnt; in p9_client_getattr()
1256 req = p9_client_request(clnt, P9PROTO_TGETATTR, &err, "dq", fid->fid, in p9_client_getattr()
1263 err = p9_buf_readf(req->rc, clnt->proto_version, "A", stat_dotl); in p9_client_getattr()
1275 "st_stat %ju, st_data_version %ju \n", fid->fid, in p9_client_getattr()
1276 stat_dotl->qid.type, (uintmax_t)stat_dotl->qid.path, in p9_client_getattr()
1277 stat_dotl->qid.version, stat_dotl->st_mode, stat_dotl->st_uid, in p9_client_getattr()
1278 stat_dotl->st_gid, (uintmax_t)stat_dotl->st_nlink, in p9_client_getattr()
1279 (uintmax_t)stat_dotl->st_rdev, (uintmax_t)stat_dotl->st_size, in p9_client_getattr()
1280 (uintmax_t)stat_dotl->st_blksize, in p9_client_getattr()
1281 (uintmax_t)stat_dotl->st_blocks, (uintmax_t)stat_dotl->st_atime_sec, in p9_client_getattr()
1282 (uintmax_t)stat_dotl->st_atime_nsec, (uintmax_t)stat_dotl->st_mtime_sec, in p9_client_getattr()
1283 (uintmax_t)stat_dotl->st_mtime_nsec, (uintmax_t)stat_dotl->st_ctime_sec, in p9_client_getattr()
1284 (uintmax_t)stat_dotl->st_ctime_nsec, (uintmax_t)stat_dotl->st_btime_sec, in p9_client_getattr()
1285 (uintmax_t)stat_dotl->st_btime_nsec, (uintmax_t)stat_dotl->st_gen, in p9_client_getattr()
1286 (uintmax_t)stat_dotl->st_data_version); in p9_client_getattr()
1311 fid->fid, in p9_client_setattr()
1312 p9attr->valid, p9attr->mode, p9attr->uid, p9attr->gid, in p9_client_setattr()
1313 (uintmax_t)p9attr->size, (uintmax_t)p9attr->atime_sec, in p9_client_setattr()
1314 (uintmax_t)p9attr->atime_nsec, (uintmax_t)p9attr->mtime_sec, in p9_client_setattr()
1315 (uintmax_t)p9attr->mtime_nsec); in p9_client_setattr()
1317 clnt = fid->clnt; in p9_client_setattr()
1320 req = p9_client_request(clnt, P9PROTO_TSETATTR, &err, "dA", fid->fid, in p9_client_setattr()