mirror of https://gitee.com/openkylin/qemu.git
9pfs: misc patches
* Add link to 9p developer docs. * Fix runtime check whether client supplied relative path is the export root. * Performance optimization of Twalk requests. * Code cleanup. -----BEGIN PGP SIGNATURE----- iQJLBAABCgA1FiEEltjREM96+AhPiFkBNMK1h2Wkc5UFAmDi6V4XHHFlbXVfb3Nz QGNydWRlYnl0ZS5jb20ACgkQNMK1h2Wkc5WsiA//dwLfbNFE9dxAZF3JzwYPmgID ino0zruJxC2UdHaVYr2r0A6H+uL/K1zFTWj53R1EKo6udhsx5avqJvmuLU5np9MA CEflB99YvwEQWLNyM7IRT+IXa+ebe+UvqC7ouRmJeTRuBaSEu7TMj5S2zMj+AD4b uNGVylm6T8yAt+r8QQar+TvK9KYuPuHt/yJgzXqg8tDfly1GGzLh2uoS/0EZoJQU 4emyYadMsBMVOh+E29sqFMBpUnHwlLl+t9JpUl3xVXM1ZShcqHBl2QbQGJIDsfh7 HxXBMKHLiSzJrFJCc2DklsOlaRlP5nZdCVEcO4B0/Sq1kZpmf6r+4V6uYrdu8cCE tP33QNhC1yWQk9FgvItGkqRfAOI/KK02TE8WWJuLxbyo2n62lE0rEU1gBJOGPkxQ rJTGUiFgweV5Ky+NMRbrB4P8EurPLvcgFEhz7qfOEBanmZKHylzI3vwQg5e9Um/t ZABjIfjm95/QB6ufeCvVuktGnmyfBC/WJSZwiDyRG+tBf1V1TJF1P9EwoBOyYexv WGHoYfAExytKbyzgsKPZ32zTGzzKLtTBko+ATIEFPCpsf5TWiSzralzz3c2/DF3j 5PHuPOdL+7nhUN3CSRi2MJzhg+LKW34ca1G8XRpob0u9RkKSjH6VbqKhysB8eQNm kE1lfhSe00ZtuZoTPto= =WqCY -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/cschoenebeck/tags/pull-9p-20210705' into staging 9pfs: misc patches * Add link to 9p developer docs. * Fix runtime check whether client supplied relative path is the export root. * Performance optimization of Twalk requests. * Code cleanup. # gpg: Signature made Mon 05 Jul 2021 12:13:34 BST # gpg: using RSA key 96D8D110CF7AF8084F88590134C2B58765A47395 # gpg: issuer "qemu_oss@crudebyte.com" # gpg: Good signature from "Christian Schoenebeck <qemu_oss@crudebyte.com>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: ECAB 1A45 4014 1413 BA38 4926 30DB 47C3 A012 D5F4 # Subkey fingerprint: 96D8 D110 CF7A F808 4F88 5901 34C2 B587 65A4 7395 * remotes/cschoenebeck/tags/pull-9p-20210705: 9pfs: reduce latency of Twalk 9pfs: drop root_qid 9pfs: replace not_same_qid() by same_stat_id() 9pfs: drop fid_to_qid() 9pfs: capture root stat 9pfs: fix not_same_qid() 9pfs: simplify v9fs_walk() 9pfs: add link to 9p developer docs Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
9bef7ea9d9
|
@ -1881,6 +1881,7 @@ virtio-9p
|
|||
M: Greg Kurz <groug@kaod.org>
|
||||
M: Christian Schoenebeck <qemu_oss@crudebyte.com>
|
||||
S: Odd Fixes
|
||||
W: https://wiki.qemu.org/Documentation/9p
|
||||
F: hw/9pfs/
|
||||
X: hw/9pfs/xen-9p*
|
||||
F: fsdev/
|
||||
|
|
|
@ -10,6 +10,11 @@
|
|||
* the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "9p.h"
|
||||
#include "9p-local.h"
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/xattr.h"
|
||||
#include "9p.h"
|
||||
|
|
|
@ -10,6 +10,11 @@
|
|||
* the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "9p.h"
|
||||
#include "fsdev/qemu-fsdev.h"
|
||||
|
|
|
@ -10,6 +10,11 @@
|
|||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/xattr.h"
|
||||
#include "9p-util.h"
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "9p.h"
|
||||
#include "fsdev/file-op-9p.h"
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "9p.h"
|
||||
#include "fsdev/file-op-9p.h"
|
||||
|
|
144
hw/9pfs/9p.c
144
hw/9pfs/9p.c
|
@ -11,6 +11,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include <glib/gprintf.h>
|
||||
#include "hw/virtio/virtio.h"
|
||||
|
@ -966,23 +971,6 @@ static int stat_to_qid(V9fsPDU *pdu, const struct stat *stbuf, V9fsQID *qidp)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int coroutine_fn fid_to_qid(V9fsPDU *pdu, V9fsFidState *fidp,
|
||||
V9fsQID *qidp)
|
||||
{
|
||||
struct stat stbuf;
|
||||
int err;
|
||||
|
||||
err = v9fs_co_lstat(pdu, &fidp->path, &stbuf);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
err = stat_to_qid(pdu, &stbuf, qidp);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
V9fsPDU *pdu_alloc(V9fsState *s)
|
||||
{
|
||||
V9fsPDU *pdu = NULL;
|
||||
|
@ -1395,6 +1383,7 @@ static void coroutine_fn v9fs_attach(void *opaque)
|
|||
size_t offset = 7;
|
||||
V9fsQID qid;
|
||||
ssize_t err;
|
||||
struct stat stbuf;
|
||||
|
||||
v9fs_string_init(&uname);
|
||||
v9fs_string_init(&aname);
|
||||
|
@ -1417,7 +1406,13 @@ static void coroutine_fn v9fs_attach(void *opaque)
|
|||
clunk_fid(s, fid);
|
||||
goto out;
|
||||
}
|
||||
err = fid_to_qid(pdu, fidp, &qid);
|
||||
err = v9fs_co_lstat(pdu, &fidp->path, &stbuf);
|
||||
if (err < 0) {
|
||||
err = -EINVAL;
|
||||
clunk_fid(s, fid);
|
||||
goto out;
|
||||
}
|
||||
err = stat_to_qid(pdu, &stbuf, &qid);
|
||||
if (err < 0) {
|
||||
err = -EINVAL;
|
||||
clunk_fid(s, fid);
|
||||
|
@ -1449,7 +1444,7 @@ static void coroutine_fn v9fs_attach(void *opaque)
|
|||
}
|
||||
err += offset;
|
||||
|
||||
memcpy(&s->root_qid, &qid, sizeof(qid));
|
||||
memcpy(&s->root_st, &stbuf, sizeof(stbuf));
|
||||
trace_v9fs_attach_return(pdu->tag, pdu->id,
|
||||
qid.type, qid.version, qid.path);
|
||||
out:
|
||||
|
@ -1700,12 +1695,9 @@ static bool name_is_illegal(const char *name)
|
|||
return !*name || strchr(name, '/') != NULL;
|
||||
}
|
||||
|
||||
static bool not_same_qid(const V9fsQID *qid1, const V9fsQID *qid2)
|
||||
static bool same_stat_id(const struct stat *a, const struct stat *b)
|
||||
{
|
||||
return
|
||||
qid1->type != qid2->type ||
|
||||
qid1->version != qid2->version ||
|
||||
qid1->path != qid2->path;
|
||||
return a->st_dev == b->st_dev && a->st_ino == b->st_ino;
|
||||
}
|
||||
|
||||
static void coroutine_fn v9fs_walk(void *opaque)
|
||||
|
@ -1713,9 +1705,9 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
|||
int name_idx;
|
||||
V9fsQID *qids = NULL;
|
||||
int i, err = 0;
|
||||
V9fsPath dpath, path;
|
||||
V9fsPath dpath, path, *pathes = NULL;
|
||||
uint16_t nwnames;
|
||||
struct stat stbuf;
|
||||
struct stat stbuf, fidst, *stbufs = NULL;
|
||||
size_t offset = 7;
|
||||
int32_t fid, newfid;
|
||||
V9fsString *wnames = NULL;
|
||||
|
@ -1734,9 +1726,15 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
|||
|
||||
trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames);
|
||||
|
||||
if (nwnames && nwnames <= P9_MAXWELEM) {
|
||||
if (nwnames > P9_MAXWELEM) {
|
||||
err = -EINVAL;
|
||||
goto out_nofid;
|
||||
}
|
||||
if (nwnames) {
|
||||
wnames = g_new0(V9fsString, nwnames);
|
||||
qids = g_new0(V9fsQID, nwnames);
|
||||
stbufs = g_new0(struct stat, nwnames);
|
||||
pathes = g_new0(V9fsPath, nwnames);
|
||||
for (i = 0; i < nwnames; i++) {
|
||||
err = pdu_unmarshal(pdu, offset, "s", &wnames[i]);
|
||||
if (err < 0) {
|
||||
|
@ -1748,9 +1746,6 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
|||
}
|
||||
offset += err;
|
||||
}
|
||||
} else if (nwnames > P9_MAXWELEM) {
|
||||
err = -EINVAL;
|
||||
goto out_nofid;
|
||||
}
|
||||
fidp = get_fid(pdu, fid);
|
||||
if (fidp == NULL) {
|
||||
|
@ -1760,35 +1755,85 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
|||
|
||||
v9fs_path_init(&dpath);
|
||||
v9fs_path_init(&path);
|
||||
|
||||
err = fid_to_qid(pdu, fidp, &qid);
|
||||
if (err < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Both dpath and path initially poin to fidp.
|
||||
* Both dpath and path initially point to fidp.
|
||||
* Needed to handle request with nwnames == 0
|
||||
*/
|
||||
v9fs_path_copy(&dpath, &fidp->path);
|
||||
v9fs_path_copy(&path, &fidp->path);
|
||||
for (name_idx = 0; name_idx < nwnames; name_idx++) {
|
||||
if (not_same_qid(&pdu->s->root_qid, &qid) ||
|
||||
strcmp("..", wnames[name_idx].data)) {
|
||||
err = v9fs_co_name_to_path(pdu, &dpath, wnames[name_idx].data,
|
||||
&path);
|
||||
if (err < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
err = v9fs_co_lstat(pdu, &path, &stbuf);
|
||||
if (err < 0) {
|
||||
goto out;
|
||||
/*
|
||||
* To keep latency (i.e. overall execution time for processing this
|
||||
* Twalk client request) as small as possible, run all the required fs
|
||||
* driver code altogether inside the following block.
|
||||
*/
|
||||
v9fs_co_run_in_worker({
|
||||
if (v9fs_request_cancelled(pdu)) {
|
||||
err = -EINTR;
|
||||
break;
|
||||
}
|
||||
err = s->ops->lstat(&s->ctx, &dpath, &fidst);
|
||||
if (err < 0) {
|
||||
err = -errno;
|
||||
break;
|
||||
}
|
||||
stbuf = fidst;
|
||||
for (name_idx = 0; name_idx < nwnames; name_idx++) {
|
||||
if (v9fs_request_cancelled(pdu)) {
|
||||
err = -EINTR;
|
||||
break;
|
||||
}
|
||||
if (!same_stat_id(&pdu->s->root_st, &stbuf) ||
|
||||
strcmp("..", wnames[name_idx].data))
|
||||
{
|
||||
err = s->ops->name_to_path(&s->ctx, &dpath,
|
||||
wnames[name_idx].data, &path);
|
||||
if (err < 0) {
|
||||
err = -errno;
|
||||
break;
|
||||
}
|
||||
if (v9fs_request_cancelled(pdu)) {
|
||||
err = -EINTR;
|
||||
break;
|
||||
}
|
||||
err = s->ops->lstat(&s->ctx, &path, &stbuf);
|
||||
if (err < 0) {
|
||||
err = -errno;
|
||||
break;
|
||||
}
|
||||
stbufs[name_idx] = stbuf;
|
||||
v9fs_path_copy(&dpath, &path);
|
||||
v9fs_path_copy(&pathes[name_idx], &path);
|
||||
}
|
||||
}
|
||||
});
|
||||
/*
|
||||
* Handle all the rest of this Twalk request on main thread ...
|
||||
*/
|
||||
if (err < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
err = stat_to_qid(pdu, &fidst, &qid);
|
||||
if (err < 0) {
|
||||
goto out;
|
||||
}
|
||||
stbuf = fidst;
|
||||
|
||||
/* reset dpath and path */
|
||||
v9fs_path_copy(&dpath, &fidp->path);
|
||||
v9fs_path_copy(&path, &fidp->path);
|
||||
|
||||
for (name_idx = 0; name_idx < nwnames; name_idx++) {
|
||||
if (!same_stat_id(&pdu->s->root_st, &stbuf) ||
|
||||
strcmp("..", wnames[name_idx].data))
|
||||
{
|
||||
stbuf = stbufs[name_idx];
|
||||
err = stat_to_qid(pdu, &stbuf, &qid);
|
||||
if (err < 0) {
|
||||
goto out;
|
||||
}
|
||||
v9fs_path_copy(&path, &pathes[name_idx]);
|
||||
v9fs_path_copy(&dpath, &path);
|
||||
}
|
||||
memcpy(&qids[name_idx], &qid, sizeof(qid));
|
||||
|
@ -1824,9 +1869,12 @@ out_nofid:
|
|||
if (nwnames && nwnames <= P9_MAXWELEM) {
|
||||
for (name_idx = 0; name_idx < nwnames; name_idx++) {
|
||||
v9fs_string_free(&wnames[name_idx]);
|
||||
v9fs_path_free(&pathes[name_idx]);
|
||||
}
|
||||
g_free(wnames);
|
||||
g_free(qids);
|
||||
g_free(stbufs);
|
||||
g_free(pathes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -355,7 +355,7 @@ struct V9fsState {
|
|||
int32_t root_fid;
|
||||
Error *migration_blocker;
|
||||
V9fsConf fsconf;
|
||||
V9fsQID root_qid;
|
||||
struct stat root_st;
|
||||
dev_t dev_id;
|
||||
struct qht qpd_table;
|
||||
struct qht qpp_table;
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "fsdev/qemu-fsdev.h"
|
||||
#include "qemu/thread.h"
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "fsdev/qemu-fsdev.h"
|
||||
#include "qemu/thread.h"
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "fsdev/qemu-fsdev.h"
|
||||
#include "qemu/thread.h"
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "block/thread-pool.h"
|
||||
#include "qemu/coroutine.h"
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "fsdev/qemu-fsdev.h"
|
||||
#include "qemu/thread.h"
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "hw/virtio/virtio.h"
|
||||
#include "qemu/sockets.h"
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "hw/9pfs/9p.h"
|
||||
|
|
|
@ -16,6 +16,11 @@
|
|||
* License along with this library; if not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
|
|
|
@ -7,6 +7,11 @@
|
|||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Not so fast! You might want to read the 9p developer docs first:
|
||||
* https://wiki.qemu.org/Documentation/9p
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest-single.h"
|
||||
#include "qemu/module.h"
|
||||
|
|
Loading…
Reference in New Issue