From patchwork Wed Mar 9 12:18:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12775439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2D70C433F5 for ; Wed, 9 Mar 2022 19:13:03 +0000 (UTC) Received: from localhost ([::1]:51440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nS1k6-0000hj-Cd for qemu-devel@archiver.kernel.org; Wed, 09 Mar 2022 14:13:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <62e8103d249fcdb03ad6c706840579a075333398@lizzy.crudebyte.com>) id 1nS1ix-0007va-Ck for qemu-devel@nongnu.org; Wed, 09 Mar 2022 14:11:51 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:46089) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <62e8103d249fcdb03ad6c706840579a075333398@lizzy.crudebyte.com>) id 1nS1iv-0004bW-PW for qemu-devel@nongnu.org; Wed, 09 Mar 2022 14:11:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=Y22/N2T+yp5XUNQcROO4zlRG0A7OoAe0gcpC8S1OTlA=; b=EK0sP 7jkvNaWlsR+cwpOVOIvSfqmq5M+XT9q9+Z3I6pVFBHBrgMCtAwaf9S/mm7otXhbD0hiFZ5DgVOLbR UYCGm3TtcBxzqIxjdYDOCNVoic/TqL/V1RYYRJTNUgPEDcZZnK6SU5uL6nLDeqkOMfhAWVYSp7Tk+ hYtuV+tMx/ofJ9EIdK/HDjJIkh23YkEGPQNfcOgnDjGks1nMOELtnT3C+Bgnwv9wqIFuxUB3joIHY NVdB3oaw5LSlABaP0M7xFpEcGmGnbkhPgS3sswGj29J2NE2HyG9erhd6n+i2Qk/pWSfPlX2SKP3mV 8wLmjqz2HFotmpoPWuHYoUgof1z2Q==; Message-Id: <62e8103d249fcdb03ad6c706840579a075333398.1646850707.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 9 Mar 2022 13:18:50 +0100 Subject: [PATCH 1/6] tests/9pfs: walk to non-existent dir To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=62e8103d249fcdb03ad6c706840579a075333398@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_06_12=1.543, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Expect ENOENT Rlerror response when trying to walk to a non-existent directory. Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz --- tests/qtest/virtio-9p-test.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 01ca076afe..22bdd74bc1 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -606,6 +606,25 @@ static uint32_t do_walk(QVirtio9P *v9p, const char *path) return fid; } +/* utility function: walk to requested dir and expect passed error response */ +static void do_walk_expect_error(QVirtio9P *v9p, const char *path, uint32_t err) +{ + char **wnames; + P9Req *req; + uint32_t _err; + const uint32_t fid = genfid(); + + int nwnames = split(path, "/", &wnames); + + req = v9fs_twalk(v9p, 0, fid, nwnames, wnames, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rlerror(req, &_err); + + g_assert_cmpint(_err, ==, err); + + split_free(&wnames); +} + static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc) { alloc = t_alloc; @@ -974,6 +993,15 @@ static void fs_walk_no_slash(void *obj, void *data, QGuestAllocator *t_alloc) g_free(wnames[0]); } +static void fs_walk_nonexistent(void *obj, void *data, QGuestAllocator *t_alloc) +{ + QVirtio9P *v9p = obj; + alloc = t_alloc; + + do_attach(v9p); + do_walk_expect_error(v9p, "non-existent", ENOENT); +} + static void fs_walk_dotdot(void *obj, void *data, QGuestAllocator *t_alloc) { QVirtio9P *v9p = obj; @@ -1409,6 +1437,8 @@ static void register_virtio_9p_test(void) &opts); qos_add_test("synth/walk/dotdot_from_root", "virtio-9p", fs_walk_dotdot, &opts); + qos_add_test("synth/walk/non_existent", "virtio-9p", fs_walk_nonexistent, + &opts); qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen, &opts); qos_add_test("synth/write/basic", "virtio-9p", fs_write, &opts); qos_add_test("synth/flush/success", "virtio-9p", fs_flush_success, From patchwork Wed Mar 9 13:24:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12775452 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC391C433F5 for ; Wed, 9 Mar 2022 19:18:14 +0000 (UTC) Received: from localhost ([::1]:58382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nS1p7-0005XY-Ln for qemu-devel@archiver.kernel.org; Wed, 09 Mar 2022 14:18:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nS1ky-00023p-TY for qemu-devel@nongnu.org; Wed, 09 Mar 2022 14:13:56 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:37337) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nS1kx-0004oT-CS for qemu-devel@nongnu.org; Wed, 09 Mar 2022 14:13:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=YqbY9vNfa/EmSihxfkUi13kl4TtM5o1x5zqFLwyXJpk=; b=GF+Sn 3PCHQjqbbMUJGJgtj6mpia5DXiT/48iB9s6Tg53bpUVcc/HPQ02jAYMUOzMdwJBeYOMXwokHVUKk+ 55+KnkDAqSl0LSzjRBceWKtemYMyr9YMrL/MTrq8A229DP22QLQNbJwbPEF/VUZt2+zw07bfqxh35 +IfNZOix1kL+dGLGRkYExAAEGzfTMeUh22cXxiBNKX6As980cD9jUgOuDLXE69hZiqrWiECRXuH7R stJybOisSy+uhhy2v1D1audZb2DDYwGuL+nmZ4KicxnGMGlZ3320nRTQDpiaRwub+KwrDYCh+zz2Q Pb1UKbQ2zsrp1EgpP59h/VSY9W77g==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 9 Mar 2022 14:24:24 +0100 Subject: [PATCH 2/6] tests/9pfs: Twalk with nwname=0 To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=f19d6f5fd2b569ebac797f18849710eb22c40984@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Send Twalk request with nwname=0. In this case no QIDs should be returned by 9p server; this is equivalent to walking to dot. Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz --- tests/qtest/virtio-9p-test.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 22bdd74bc1..6c00da03f4 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -1002,6 +1002,27 @@ static void fs_walk_nonexistent(void *obj, void *data, QGuestAllocator *t_alloc) do_walk_expect_error(v9p, "non-existent", ENOENT); } +static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc) +{ + QVirtio9P *v9p = obj; + alloc = t_alloc; + v9fs_qid root_qid; + g_autofree v9fs_qid *wqid = NULL; + P9Req *req; + + do_version(v9p); + req = v9fs_tattach(v9p, 0, getuid(), 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rattach(req, &root_qid); + + req = v9fs_twalk(v9p, 0, 1, 0, NULL, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rwalk(req, NULL, &wqid); + + /* special case: no QID is returned if nwname=0 was sent */ + g_assert(wqid == NULL); +} + static void fs_walk_dotdot(void *obj, void *data, QGuestAllocator *t_alloc) { QVirtio9P *v9p = obj; @@ -1435,6 +1456,7 @@ static void register_virtio_9p_test(void) qos_add_test("synth/walk/basic", "virtio-9p", fs_walk, &opts); qos_add_test("synth/walk/no_slash", "virtio-9p", fs_walk_no_slash, &opts); + qos_add_test("synth/walk/none", "virtio-9p", fs_walk_none, &opts); qos_add_test("synth/walk/dotdot_from_root", "virtio-9p", fs_walk_dotdot, &opts); qos_add_test("synth/walk/non_existent", "virtio-9p", fs_walk_nonexistent, From patchwork Wed Mar 9 14:49:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12775453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6A5BC433EF for ; Wed, 9 Mar 2022 19:18:27 +0000 (UTC) Received: from localhost ([::1]:58902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nS1pK-0005uK-NN for qemu-devel@archiver.kernel.org; Wed, 09 Mar 2022 14:18:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47090) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <699dea34f26b6f60746a16a35748b65d76515f1a@lizzy.crudebyte.com>) id 1nS1m2-0003nQ-IF for qemu-devel@nongnu.org; Wed, 09 Mar 2022 14:15:02 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:58537) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <699dea34f26b6f60746a16a35748b65d76515f1a@lizzy.crudebyte.com>) id 1nS1m0-0004ri-Vq for qemu-devel@nongnu.org; Wed, 09 Mar 2022 14:15:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=8z1sLYd5CDw7cg4PvCyJAi/AJyQA5yqK83lyVZ4XFWY=; b=Vt29E UHy+VB2U1n9YKapf6cDDyAJKmVTq7hUSYdUAZP7G3HFYMYEH2X5USRbL3/QHGDc3wdHeTlIgQPZ51 IURMhzHeF5RUQLyMR7AsNm7ZOqgrHbQS9WvyMf9PMZrTta7lRpBETlnda2FtTbcfbqrjI309NrMPF 83aCHPdz9UUZ8SBw6WvuYR0btAJz5pR9WZFGwm6Xe6oCaM5LM07UOMBTbhLw/IvJEAg2kubKllKNj 2d390mEIqggIa2+TTKSywheavRl22dxFePDyvDDMQ+shYXerXhZmUtArZVyC/Bmp5d6xIEGwCKxVm lyDSa1pnmWMCCNIpvsxdur+rLxW1Q==; Message-Id: <699dea34f26b6f60746a16a35748b65d76515f1a.1646850707.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 9 Mar 2022 15:49:04 +0100 Subject: [PATCH 3/6] tests/9pfs: compare QIDs in fs_walk_none() test To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=699dea34f26b6f60746a16a35748b65d76515f1a@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -4 X-Spam_score: -0.5 X-Spam_bar: / X-Spam_report: (-0.5 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_03_06=1.592, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Extend previously added fs_walk_none() test by comparing the QID of the root fid with the QID of the cloned fid. They should be equal. Signed-off-by: Christian Schoenebeck --- tests/qtest/virtio-9p-test.c | 70 ++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 6c00da03f4..9098e21173 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -146,6 +146,11 @@ static void v9fs_uint16_read(P9Req *req, uint16_t *val) le16_to_cpus(val); } +static void v9fs_int16_read(P9Req *req, int16_t *val) +{ + v9fs_uint16_read(req, (uint16_t *)val); +} + static void v9fs_uint32_write(P9Req *req, uint32_t val) { uint32_t le_val = cpu_to_le32(val); @@ -166,12 +171,22 @@ static void v9fs_uint32_read(P9Req *req, uint32_t *val) le32_to_cpus(val); } +static void v9fs_int32_read(P9Req *req, int32_t *val) +{ + v9fs_uint32_read(req, (uint32_t *)val); +} + static void v9fs_uint64_read(P9Req *req, uint64_t *val) { v9fs_memread(req, val, 8); le64_to_cpus(val); } +static void v9fs_int64_read(P9Req *req, int64_t *val) +{ + v9fs_uint64_read(req, (uint64_t *)val); +} + /* len[2] string[len] */ static uint16_t v9fs_string_size(const char *string) { @@ -425,6 +440,40 @@ static void v9fs_rwalk(P9Req *req, uint16_t *nwqid, v9fs_qid **wqid) v9fs_req_free(req); } +/* size[4] Tstat tag[2] fid[4] */ +static P9Req *v9fs_tstat(QVirtio9P *v9p, uint32_t fid, uint16_t tag) +{ + P9Req *req; + + req = v9fs_req_init(v9p, 4, P9_TSTAT, tag); + v9fs_uint32_write(req, fid); + v9fs_req_send(req); + return req; +} + +/* size[4] Rstat tag[2] stat[n] */ +static void v9fs_rstat(P9Req *req, struct V9fsStat *st) +{ + v9fs_req_recv(req, P9_RSTAT); + + v9fs_int16_read(req, &st->size); + v9fs_int16_read(req, &st->type); + v9fs_int32_read(req, &st->dev); + v9fs_uint8_read(req, &st->qid.type); + v9fs_uint32_read(req, &st->qid.version); + v9fs_uint64_read(req, &st->qid.path); + v9fs_int32_read(req, &st->mode); + v9fs_int32_read(req, &st->mtime); + v9fs_int32_read(req, &st->atime); + v9fs_int64_read(req, &st->length); + v9fs_string_read(req, &st->name.size, &st->name.data); + v9fs_string_read(req, &st->uid.size, &st->uid.data); + v9fs_string_read(req, &st->gid.size, &st->gid.data); + v9fs_string_read(req, &st->muid.size, &st->muid.data); + + v9fs_req_free(req); +} + /* size[4] Treaddir tag[2] fid[4] offset[8] count[4] */ static P9Req *v9fs_treaddir(QVirtio9P *v9p, uint32_t fid, uint64_t offset, uint32_t count, uint16_t tag) @@ -1009,6 +1058,8 @@ static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc) v9fs_qid root_qid; g_autofree v9fs_qid *wqid = NULL; P9Req *req; + struct V9fsStat st[2]; + int i; do_version(v9p); req = v9fs_tattach(v9p, 0, getuid(), 0); @@ -1021,6 +1072,25 @@ static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc) /* special case: no QID is returned if nwname=0 was sent */ g_assert(wqid == NULL); + + req = v9fs_tstat(v9p, 0, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rstat(req, &st[0]); + + req = v9fs_tstat(v9p, 1, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rstat(req, &st[1]); + + /* don't compare QID version for checking for file ID equalness */ + g_assert(st[0].qid.type == st[1].qid.type); + g_assert(st[0].qid.path == st[1].qid.path); + + for (i = 0; i < 2; ++i) { + g_free(st[i].name.data); + g_free(st[i].uid.data); + g_free(st[i].gid.data); + g_free(st[i].muid.data); + } } static void fs_walk_dotdot(void *obj, void *data, QGuestAllocator *t_alloc) From patchwork Wed Mar 9 17:12:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12775494 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33424C433EF for ; Wed, 9 Mar 2022 19:20:03 +0000 (UTC) Received: from localhost ([::1]:34606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nS1qs-00005L-AR for qemu-devel@archiver.kernel.org; Wed, 09 Mar 2022 14:20:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <00bee0f7a89147c90c672f07b9a1ebcd9180215b@lizzy.crudebyte.com>) id 1nS1o7-0005lL-Bf for qemu-devel@nongnu.org; Wed, 09 Mar 2022 14:17:11 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:52541) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <00bee0f7a89147c90c672f07b9a1ebcd9180215b@lizzy.crudebyte.com>) id 1nS1o5-0005N0-Ft for qemu-devel@nongnu.org; Wed, 09 Mar 2022 14:17:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=UqAt3a9BTQwGRW5/taODl7/EqgqAT+6O0K+arOyXnzU=; b=hqOeL pqB65RXGPuZcbMH0QJIuV3SttzVd/3YWadrLFuerSpHhs8taRNlduw5WUa/ntVYqN3K4trq2DfIlK /1snUwJ9fAe5CXmE6KYm+zltVuwHFko674Gruc7VsPzAu1yPQ1WsdFNESHBOk8nel+lloz8i3+ZC0 OAz9uOzr0BtvJN5omcRMiXFBKBGMgi/+fS8pLrccy0e5ncqMAcVG+xUiV//7SWm/IKHMk1K6N3SP9 Wsb6LQpXD+T27QxauJZUpcPanNEFI6Kn9nCIJzfe/RuHEXYb5LMXdy+L/Gfn2oIfckiIa49hM02Vw wOcNfhRR68kAdQ6T5V0ZGJrmKREag==; Message-Id: <00bee0f7a89147c90c672f07b9a1ebcd9180215b.1646850707.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 9 Mar 2022 18:12:17 +0100 Subject: [PATCH 4/6] 9pfs: refactor 'name_idx' -> 'nvalid' in v9fs_walk() To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=00bee0f7a89147c90c672f07b9a1ebcd9180215b@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The local variable 'name_idx' is used in two loops in function v9fs_walk(). Let the first loop use its own variable 'nvalid' instead, which we will use in subsequent patches as the number of (requested) path components successfully retrieved/walked by background I/O thread. Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz --- hw/9pfs/9p.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index a6d6b3f835..6cdc566866 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1764,7 +1764,7 @@ static bool same_stat_id(const struct stat *a, const struct stat *b) static void coroutine_fn v9fs_walk(void *opaque) { - int name_idx; + int name_idx, nvalid; g_autofree V9fsQID *qids = NULL; int i, err = 0; V9fsPath dpath, path; @@ -1842,17 +1842,17 @@ static void coroutine_fn v9fs_walk(void *opaque) break; } stbuf = fidst; - for (name_idx = 0; name_idx < nwnames; name_idx++) { + for (nvalid = 0; nvalid < nwnames; nvalid++) { if (v9fs_request_cancelled(pdu)) { err = -EINTR; break; } if (!same_stat_id(&pdu->s->root_st, &stbuf) || - strcmp("..", wnames[name_idx].data)) + strcmp("..", wnames[nvalid].data)) { err = s->ops->name_to_path(&s->ctx, &dpath, - wnames[name_idx].data, - &pathes[name_idx]); + wnames[nvalid].data, + &pathes[nvalid]); if (err < 0) { err = -errno; break; @@ -1861,13 +1861,13 @@ static void coroutine_fn v9fs_walk(void *opaque) err = -EINTR; break; } - err = s->ops->lstat(&s->ctx, &pathes[name_idx], &stbuf); + err = s->ops->lstat(&s->ctx, &pathes[nvalid], &stbuf); if (err < 0) { err = -errno; break; } - stbufs[name_idx] = stbuf; - v9fs_path_copy(&dpath, &pathes[name_idx]); + stbufs[nvalid] = stbuf; + v9fs_path_copy(&dpath, &pathes[nvalid]); } } }); From patchwork Wed Mar 9 17:57:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12775493 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC28EC433FE for ; Wed, 9 Mar 2022 19:19:37 +0000 (UTC) Received: from localhost ([::1]:32874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nS1qT-0007Ny-19 for qemu-devel@archiver.kernel.org; Wed, 09 Mar 2022 14:19:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <1ad002a1fbc2f8e48384673b0545a164afff7ce9@lizzy.crudebyte.com>) id 1nS1n6-0004se-J7 for qemu-devel@nongnu.org; Wed, 09 Mar 2022 14:16:08 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:56463) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <1ad002a1fbc2f8e48384673b0545a164afff7ce9@lizzy.crudebyte.com>) id 1nS1n2-000523-CQ for qemu-devel@nongnu.org; Wed, 09 Mar 2022 14:16:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=eLRL2ELWGCP4lVOogFRJlNjrIZCxYBFRPJLcd96ZEzo=; b=dmN/S zxStZWf8ub9QgMrkqg7OE5Vyz4O42USJ8sIO/a8nz4FdjQL5g1OplVcba7TfqEJULg2MxKy/YOIdv a5AM3F8IrVIbInkxFbZhKpyYWRfq9dMqpdszzL/p04+AiJQa1Y3j5iytERIQq4KNFNzrjf0tmd2r3 e3tykw+9BwmMuqxt5/ePcu4lcb7vnP/BxnW4/AGqh8HFHnOQewasK7/LbiKld2h1C3FKujAaG6hrE yYGLdHiFeGqJHiJd/fvDn4lS4M6U4eQA+SvvPthzymgN0OI/yEQt0ZB1lSz9XwYzRjFhZfp6Lg1Na rUn9/gR5+rIlDgHxAVJQJvFhYgsUg==; Message-Id: <1ad002a1fbc2f8e48384673b0545a164afff7ce9.1646850707.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 9 Mar 2022 18:57:39 +0100 Subject: [PATCH 5/6] 9pfs: fix 'Twalk' to only send error if no component walked To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=1ad002a1fbc2f8e48384673b0545a164afff7ce9@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Current implementation of 'Twalk' request handling always sends an 'Rerror' response if any error occured. The 9p2000 protocol spec sais 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 'nvalid' 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 uneffacted if any error occurred. Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 6cdc566866..8ccd180608 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1766,7 +1766,7 @@ static void coroutine_fn v9fs_walk(void *opaque) { int name_idx, nvalid; g_autofree V9fsQID *qids = NULL; - int i, err = 0; + int i, err = 0, any_err = 0; V9fsPath dpath, path; P9ARRAY_REF(V9fsPath) pathes = NULL; uint16_t nwnames; @@ -1832,6 +1832,7 @@ static void coroutine_fn v9fs_walk(void *opaque) * driver code altogether inside the following block. */ v9fs_co_run_in_worker({ + nvalid = 0; if (v9fs_request_cancelled(pdu)) { err = -EINTR; break; @@ -1842,7 +1843,7 @@ static void coroutine_fn v9fs_walk(void *opaque) break; } stbuf = fidst; - for (nvalid = 0; nvalid < nwnames; nvalid++) { + for (; nvalid < nwnames; nvalid++) { if (v9fs_request_cancelled(pdu)) { err = -EINTR; break; @@ -1874,12 +1875,13 @@ static void coroutine_fn v9fs_walk(void *opaque) /* * Handle all the rest of this Twalk request on main thread ... */ - if (err < 0) { + if ((err < 0 && !nvalid) || err == -EINTR) { goto out; } + any_err |= err; err = stat_to_qid(pdu, &fidst, &qid); - if (err < 0) { + if (err < 0 && !nvalid) { goto out; } stbuf = fidst; @@ -1888,20 +1890,30 @@ static void coroutine_fn v9fs_walk(void *opaque) v9fs_path_copy(&dpath, &fidp->path); v9fs_path_copy(&path, &fidp->path); - for (name_idx = 0; name_idx < nwnames; name_idx++) { + for (name_idx = 0; name_idx < nvalid; 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; + break; } v9fs_path_copy(&path, &pathes[name_idx]); v9fs_path_copy(&dpath, &path); } memcpy(&qids[name_idx], &qid, sizeof(qid)); } + any_err |= err; + if (any_err) { + 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 (fidp->fid_type != P9_FID_NONE) { err = -EINVAL; @@ -1919,8 +1931,9 @@ static void coroutine_fn v9fs_walk(void *opaque) newfidp->uid = fidp->uid; v9fs_path_copy(&newfidp->path, &path); } - err = v9fs_walk_marshal(pdu, nwnames, qids); - trace_v9fs_walk_return(pdu->tag, pdu->id, nwnames, qids); +send_qids: + err = v9fs_walk_marshal(pdu, name_idx, qids); + trace_v9fs_walk_return(pdu->tag, pdu->id, name_idx, qids); out: put_fid(pdu, fidp); if (newfidp) { From patchwork Wed Mar 9 18:21:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 12775451 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F14EFC433F5 for ; Wed, 9 Mar 2022 19:14:25 +0000 (UTC) Received: from localhost ([::1]:53776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nS1lQ-0002Mb-Tt for qemu-devel@archiver.kernel.org; Wed, 09 Mar 2022 14:14:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <51e7f12fad3f36ce166e2f6e415784b13c4df5c4@lizzy.crudebyte.com>) id 1nS1jx-00011Q-Mr for qemu-devel@nongnu.org; Wed, 09 Mar 2022 14:12:53 -0500 Received: from lizzy.crudebyte.com ([91.194.90.13]:37147) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <51e7f12fad3f36ce166e2f6e415784b13c4df5c4@lizzy.crudebyte.com>) id 1nS1jw-0004jp-6A for qemu-devel@nongnu.org; Wed, 09 Mar 2022 14:12:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=LLaVFJXt6ye6hukG82NJJ1PyuRvSgPlK/UTJCur82V0=; b=eea5d MrY7wnzu2+43AZNa0NZ/a+tu9ny7uvet3NwOhBLA/Q7Cevon7C/WytxXOFIv1Fri4nactiCnCd+Jq g8saYMwUyVKjEhldbvjiilHF2xWhDObN7Unz6gS1yPJK/k9o15+rAHW/gQD6dEb9FVKm5nCnRLuz5 XvtF9I32YQXKpeO/9Gs6ev39LvVh8+LOlpi96QMJP7mh1buqk8hioXNIPn/eY9kNrGtGxLm6GXA17 nwC0uIp2zlqose/9OfRiV1CDe1ubLPHpxOg0vu4rXVjfoLOPEwZLpGdCJXs692j3FF9ainqyQRXEf ixWKrPlTKJOKt2dT3ANkw4GcyGgMg==; Message-Id: <51e7f12fad3f36ce166e2f6e415784b13c4df5c4.1646850707.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Wed, 9 Mar 2022 19:21:18 +0100 Subject: [PATCH 6/6] tests/9pfs: guard recent 'Twalk' behaviour fix To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=51e7f12fad3f36ce166e2f6e415784b13c4df5c4@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Previous 9p patch fixed 'Twalk' request handling, which was previously not behaving as specified by the 9p2000 protocol spec. This patch adds a new test case which guards the new 'Twalk' behaviour in question. More specifically: it sends a 'Twalk' request where the 1st path component is valid, whereas the 2nd path component transmitted to server does not exist. The expected behaviour is that 9p server would respond by sending a 'Rwalk' response with exactly 1 QID (instead of 'Rlerror' response). Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz --- tests/qtest/virtio-9p-test.c | 42 +++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 9098e21173..f29de1ca64 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -638,8 +638,12 @@ static void do_version(QVirtio9P *v9p) g_assert_cmpmem(server_version, server_len, version, strlen(version)); } -/* utility function: walk to requested dir and return fid for that dir */ -static uint32_t do_walk(QVirtio9P *v9p, const char *path) +/* + * utility function: walk to requested dir and return fid for that dir and + * the QIDs of server response + */ +static uint32_t do_walk_rqids(QVirtio9P *v9p, const char *path, uint16_t *nwqid, + v9fs_qid **wqid) { char **wnames; P9Req *req; @@ -649,12 +653,18 @@ static uint32_t do_walk(QVirtio9P *v9p, const char *path) req = v9fs_twalk(v9p, 0, fid, nwnames, wnames, 0); v9fs_req_wait_for_reply(req, NULL); - v9fs_rwalk(req, NULL, NULL); + v9fs_rwalk(req, nwqid, wqid); split_free(&wnames); return fid; } +/* utility function: walk to requested dir and return fid for that dir */ +static uint32_t do_walk(QVirtio9P *v9p, const char *path) +{ + return do_walk_rqids(v9p, path, NULL, NULL); +} + /* utility function: walk to requested dir and expect passed error response */ static void do_walk_expect_error(QVirtio9P *v9p, const char *path, uint32_t err) { @@ -1048,9 +1058,33 @@ static void fs_walk_nonexistent(void *obj, void *data, QGuestAllocator *t_alloc) alloc = t_alloc; do_attach(v9p); + /* + * The 9p2000 protocol spec sais: "If the first element cannot be walked + * for any reason, Rerror is returned." + */ do_walk_expect_error(v9p, "non-existent", ENOENT); } +static void fs_walk_2nd_nonexistent(void *obj, void *data, + QGuestAllocator *t_alloc) +{ + QVirtio9P *v9p = obj; + alloc = t_alloc; + uint16_t nwqid; + g_autofree v9fs_qid *wqid = NULL; + g_autofree char *path = g_strdup_printf( + QTEST_V9FS_SYNTH_WALK_FILE "/non-existent", 0 + ); + + do_attach(v9p); + do_walk_rqids(v9p, path, &nwqid, &wqid); + /* + * The 9p2000 protocol spec sais: "nwqid is therefore either nwname or the + * index of the first elementwise walk that failed." + */ + assert(nwqid == 1); +} + static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc) { QVirtio9P *v9p = obj; @@ -1531,6 +1565,8 @@ static void register_virtio_9p_test(void) fs_walk_dotdot, &opts); qos_add_test("synth/walk/non_existent", "virtio-9p", fs_walk_nonexistent, &opts); + qos_add_test("synth/walk/2nd_non_existent", "virtio-9p", + fs_walk_2nd_nonexistent, &opts); qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen, &opts); qos_add_test("synth/write/basic", "virtio-9p", fs_write, &opts); qos_add_test("synth/flush/success", "virtio-9p", fs_flush_success,