9pfs: fix 'Twalk' to only send error if no component walked
Current implementation of 'Twalk' request handling always sends an 'Rerror' response if any error occured. The 9p2000 protocol spec says though: " If the first element cannot be walked for any reason, Rerror is returned. Otherwise, the walk will return an Rwalk message containing nwqid qids corresponding, in order, to the files that are visited by the nwqid successful elementwise walks; nwqid is therefore either nwname or the index of the first elementwise walk that failed. " http://ericvh.github.io/9p-rfc/rfc9p2000.html#anchor33 For that reason we are no longer leaving from an error path in function v9fs_walk(), unless really no path component could be walked successfully or if the request has been interrupted. Local variable 'nwalked' counts and reflects the number of path components successfully processed by background I/O thread, whereas local variable 'name_idx' subsequently counts and reflects the number of path components eventually accepted successfully by 9p server controller portion. New local variable 'any_err' is an aggregate variable reflecting whether any error occurred at all, while already existing variable 'err' only reflects the last error. Despite QIDs being delivered to client in a more relaxed way now, it is important to note though that fid still must remain unaffected if any error occurred. Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Reviewed-by: Greg Kurz <groug@kaod.org> Message-Id: <bc73e24258a75dc29458024c7936c8a036c3eac5.1647339025.git.qemu_oss@crudebyte.com>
This commit is contained in:
parent
fd6c979e65
commit
a93d2e89e5
49
hw/9pfs/9p.c
49
hw/9pfs/9p.c
|
@ -1768,7 +1768,7 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
||||||
{
|
{
|
||||||
int name_idx, nwalked;
|
int name_idx, nwalked;
|
||||||
g_autofree V9fsQID *qids = NULL;
|
g_autofree V9fsQID *qids = NULL;
|
||||||
int i, err = 0;
|
int i, err = 0, any_err = 0;
|
||||||
V9fsPath dpath, path;
|
V9fsPath dpath, path;
|
||||||
P9ARRAY_REF(V9fsPath) pathes = NULL;
|
P9ARRAY_REF(V9fsPath) pathes = NULL;
|
||||||
uint16_t nwnames;
|
uint16_t nwnames;
|
||||||
|
@ -1834,19 +1834,20 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
||||||
* driver code altogether inside the following block.
|
* driver code altogether inside the following block.
|
||||||
*/
|
*/
|
||||||
v9fs_co_run_in_worker({
|
v9fs_co_run_in_worker({
|
||||||
|
nwalked = 0;
|
||||||
if (v9fs_request_cancelled(pdu)) {
|
if (v9fs_request_cancelled(pdu)) {
|
||||||
err = -EINTR;
|
any_err |= err = -EINTR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
err = s->ops->lstat(&s->ctx, &dpath, &fidst);
|
err = s->ops->lstat(&s->ctx, &dpath, &fidst);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
err = -errno;
|
any_err |= err = -errno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
stbuf = fidst;
|
stbuf = fidst;
|
||||||
for (nwalked = 0; nwalked < nwnames; nwalked++) {
|
for (; nwalked < nwnames; nwalked++) {
|
||||||
if (v9fs_request_cancelled(pdu)) {
|
if (v9fs_request_cancelled(pdu)) {
|
||||||
err = -EINTR;
|
any_err |= err = -EINTR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!same_stat_id(&pdu->s->root_st, &stbuf) ||
|
if (!same_stat_id(&pdu->s->root_st, &stbuf) ||
|
||||||
|
@ -1856,16 +1857,16 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
||||||
wnames[nwalked].data,
|
wnames[nwalked].data,
|
||||||
&pathes[nwalked]);
|
&pathes[nwalked]);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
err = -errno;
|
any_err |= err = -errno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (v9fs_request_cancelled(pdu)) {
|
if (v9fs_request_cancelled(pdu)) {
|
||||||
err = -EINTR;
|
any_err |= err = -EINTR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
err = s->ops->lstat(&s->ctx, &pathes[nwalked], &stbuf);
|
err = s->ops->lstat(&s->ctx, &pathes[nwalked], &stbuf);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
err = -errno;
|
any_err |= err = -errno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
stbufs[nwalked] = stbuf;
|
stbufs[nwalked] = stbuf;
|
||||||
|
@ -1875,13 +1876,19 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
||||||
});
|
});
|
||||||
/*
|
/*
|
||||||
* Handle all the rest of this Twalk request on main thread ...
|
* Handle all the rest of this Twalk request on main thread ...
|
||||||
|
*
|
||||||
|
* NOTE: -EINTR is an exception where we deviate from the protocol spec
|
||||||
|
* and simply send a (R)Lerror response instead of bothering to assemble
|
||||||
|
* a (deducted) Rwalk response; because -EINTR is always the result of a
|
||||||
|
* Tflush request, so client would no longer wait for a response in this
|
||||||
|
* case anyway.
|
||||||
*/
|
*/
|
||||||
if (err < 0) {
|
if ((err < 0 && !nwalked) || err == -EINTR) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = stat_to_qid(pdu, &fidst, &qid);
|
any_err |= err = stat_to_qid(pdu, &fidst, &qid);
|
||||||
if (err < 0) {
|
if (err < 0 && !nwalked) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
stbuf = fidst;
|
stbuf = fidst;
|
||||||
|
@ -1890,20 +1897,29 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
||||||
v9fs_path_copy(&dpath, &fidp->path);
|
v9fs_path_copy(&dpath, &fidp->path);
|
||||||
v9fs_path_copy(&path, &fidp->path);
|
v9fs_path_copy(&path, &fidp->path);
|
||||||
|
|
||||||
for (name_idx = 0; name_idx < nwnames; name_idx++) {
|
for (name_idx = 0; name_idx < nwalked; name_idx++) {
|
||||||
if (!same_stat_id(&pdu->s->root_st, &stbuf) ||
|
if (!same_stat_id(&pdu->s->root_st, &stbuf) ||
|
||||||
strcmp("..", wnames[name_idx].data))
|
strcmp("..", wnames[name_idx].data))
|
||||||
{
|
{
|
||||||
stbuf = stbufs[name_idx];
|
stbuf = stbufs[name_idx];
|
||||||
err = stat_to_qid(pdu, &stbuf, &qid);
|
any_err |= err = stat_to_qid(pdu, &stbuf, &qid);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
goto out;
|
break;
|
||||||
}
|
}
|
||||||
v9fs_path_copy(&path, &pathes[name_idx]);
|
v9fs_path_copy(&path, &pathes[name_idx]);
|
||||||
v9fs_path_copy(&dpath, &path);
|
v9fs_path_copy(&dpath, &path);
|
||||||
}
|
}
|
||||||
memcpy(&qids[name_idx], &qid, sizeof(qid));
|
memcpy(&qids[name_idx], &qid, sizeof(qid));
|
||||||
}
|
}
|
||||||
|
if (any_err < 0) {
|
||||||
|
if (!name_idx) {
|
||||||
|
/* don't send any QIDs, send Rlerror instead */
|
||||||
|
goto out;
|
||||||
|
} else {
|
||||||
|
/* send QIDs (not Rlerror), but fid MUST remain unaffected */
|
||||||
|
goto send_qids;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (fid == newfid) {
|
if (fid == newfid) {
|
||||||
if (fidp->fid_type != P9_FID_NONE) {
|
if (fidp->fid_type != P9_FID_NONE) {
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
|
@ -1921,8 +1937,9 @@ static void coroutine_fn v9fs_walk(void *opaque)
|
||||||
newfidp->uid = fidp->uid;
|
newfidp->uid = fidp->uid;
|
||||||
v9fs_path_copy(&newfidp->path, &path);
|
v9fs_path_copy(&newfidp->path, &path);
|
||||||
}
|
}
|
||||||
err = v9fs_walk_marshal(pdu, nwnames, qids);
|
send_qids:
|
||||||
trace_v9fs_walk_return(pdu->tag, pdu->id, nwnames, qids);
|
err = v9fs_walk_marshal(pdu, name_idx, qids);
|
||||||
|
trace_v9fs_walk_return(pdu->tag, pdu->id, name_idx, qids);
|
||||||
out:
|
out:
|
||||||
put_fid(pdu, fidp);
|
put_fid(pdu, fidp);
|
||||||
if (newfidp) {
|
if (newfidp) {
|
||||||
|
|
Loading…
Reference in New Issue