From patchwork Thu Jun 16 11:00: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: 1644284 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=crudebyte.com header.i=@crudebyte.com header.a=rsa-sha256 header.s=lizzy header.b=iczrLVHP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP0Fm5FDCz9s2R for ; Thu, 16 Jun 2022 21:24:59 +1000 (AEST) Received: from localhost ([::1]:45244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1ncN-00076d-ML for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 07:24:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <9472a68965433dde3d30184863fbaf0b66776d4a@lizzy.crudebyte.com>) id 1o1nLT-00079z-C6 for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:07:29 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:45469) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <9472a68965433dde3d30184863fbaf0b66776d4a@lizzy.crudebyte.com>) id 1o1nLR-0003HW-Tc for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:07:27 -0400 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=nUIOvnRFEHoLIJvozGzVxyozJn/l6t57BcihMVejN9I=; b=iczrL VHPz/NZYkium5sdVQLR73HLv33bJSBOD3Gd6cGLNb/a+4uD2mI5g/2x4uchSjsIJfo9npHAeY0XpK m4x24iDAmqDASrD9mEj25ime7yCBn8F90pf/VJq07pwE04TCNviCQjfWdWMxkB0or7AyN4thoLepx xUujedUubJi9CNMCIC8HEQXyTY112/2hnPKjXTYgATrb62Y3rL0SJx2gnYQrgHhfmlrL0znFmoIoN Ue/AYwPYTPOHRsBoh+VULPY/dPc4M6vHrfGCYuqBuSrQHnm3VYPpvo5tL6d86Cjfblo6q6/DyMHXo fpPo+eChwRBUvhsTkSVfEtuuZzoQw==; Message-Id: <9472a68965433dde3d30184863fbaf0b66776d4a.1655377203.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 16 Jun 2022 13:00:04 +0200 Subject: [PULL 1/7] tests/9pfs: walk to non-existent dir To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=9472a68965433dde3d30184863fbaf0b66776d4a@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+incoming=patchwork.ozlabs.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 Based-on: Message-Id: <1f5aa50ace3ba3861ea31e8888367518282065a6.1647339025.git.qemu_oss@crudebyte.com> --- 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 e28c71bd8f..b3837546be 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 Thu Jun 16 11:00: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: 1644288 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=crudebyte.com header.i=@crudebyte.com header.a=rsa-sha256 header.s=lizzy header.b=g1a/jUIO; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP0Tc5vYcz9sG0 for ; Thu, 16 Jun 2022 21:35:15 +1000 (AEST) Received: from localhost ([::1]:52236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1nmB-0003qV-NA for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 07:35:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1nLa-0007Ek-5Y for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:07:35 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:45745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1nLY-0003IC-Lm for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:07:33 -0400 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=Sv3a/9mZpqBDK1dfzgFGiGVNXR8FfCfqve5RJdbsVh0=; b=g1a/j UIO1uKieEbBrw/uoLNc5Ah3GGYNhBOlS+qqzkti5R6pdpWUG77xWHAmnyCcSyROEwMGAC+r8QK6KM 0gQBu8W/zgMWdwbIl9HJHr/9RrasC+GfdO97pZ0D0GE7mWRJfwh1A2Du6LpD8NFVp+K5Zr7c0cpu5 p3Lg9V0WvzkyeuehP0G/cMvEDZH381+Nr2iXc/9H2GD4WpvBk72QMfUPiJeQJXpZgxk+NPmTOf815 l0gK2qXVtYPKCZZuVcLNAOnc0/L69ofD5umvrHH04A2w30hVagi2/hTbakI+of5KwdocwuEZM/EbM 11TIHFOR2BKFkASfyhgcf8HIuhYuw==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 16 Jun 2022 13:00:04 +0200 Subject: [PULL 2/7] tests/9pfs: Twalk with nwname=0 To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=c1668948e8b74cd8f912054ba4412a1cbf0cd03c@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+incoming=patchwork.ozlabs.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 Message-Id: --- 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 b3837546be..7942d5fef9 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 Thu Jun 16 11:00: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: 1644285 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=crudebyte.com header.i=@crudebyte.com header.a=rsa-sha256 header.s=lizzy header.b=fcjBNoFT; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP0GJ43rrz9sFw for ; Thu, 16 Jun 2022 21:25:28 +1000 (AEST) Received: from localhost ([::1]:45826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1ncs-0007Tb-3v for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 07:25:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49784) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1nLf-0007Fo-DO for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:07:41 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:54059) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1nLd-0003Jm-PR for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:07:39 -0400 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=XwupY3TUi3aYveup2Lsr+XAgkE/lW8+yacjW+GAe2R4=; b=fcjBN oFTeLy+oR1/3BjAmm8BmjlbY1Xnuob9835KccU+V0g29JmaSIAMFQl+NqzNVIZWqIlmdpL8yn9e5c /sd2aAcYRnLSrOkShb+rYhwE42gFGNlGMaouWYWNv/uRlmnBFPpOafACSu/CXq0P3llfL5x82e/zj BtFdAsvuwjlDY/00+c577kn5ZYQCbzwbJ0+nUy8aEHBCYj9+GTBwIPeZrRsBjEEOmwBTi714A2+XK yNifqCmOq/6estCuEa4brwMveiXh0HtVrBdnwNB30ZEb4foOnDDVbJUCT4NPhHuq8N0wOdsNcs1xC 09nQfNl/EIYeHVh3SXzKCk3WRp/tQ==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 16 Jun 2022 13:00:04 +0200 Subject: [PULL 3/7] tests/9pfs: compare QIDs in fs_walk_none() test To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=a6821b828404abdc18a0d9e21275ad1d7fd6ed05@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+incoming=patchwork.ozlabs.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 Reviewed-by: Greg Kurz Message-Id: <5bbe9c6931b4600a9a23742f5ff2d38c1188237d.1647339025.git.qemu_oss@crudebyte.com> --- tests/qtest/virtio-9p-test.c | 87 ++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 7942d5fef9..3c0f094929 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -371,8 +371,15 @@ static P9Req *v9fs_tattach(QVirtio9P *v9p, uint32_t fid, uint32_t n_uname, return req; } +/* type[1] version[4] path[8] */ typedef char v9fs_qid[13]; +static inline bool is_same_qid(v9fs_qid a, v9fs_qid b) +{ + /* don't compare QID version for checking for file ID equalness */ + return a[0] == b[0] && memcmp(&a[5], &b[5], 8) == 0; +} + /* size[4] Rattach tag[2] qid[13] */ static void v9fs_rattach(P9Req *req, v9fs_qid *qid) { @@ -425,6 +432,79 @@ static void v9fs_rwalk(P9Req *req, uint16_t *nwqid, v9fs_qid **wqid) v9fs_req_free(req); } +/* size[4] Tgetattr tag[2] fid[4] request_mask[8] */ +static P9Req *v9fs_tgetattr(QVirtio9P *v9p, uint32_t fid, uint64_t request_mask, + uint16_t tag) +{ + P9Req *req; + + req = v9fs_req_init(v9p, 4 + 8, P9_TGETATTR, tag); + v9fs_uint32_write(req, fid); + v9fs_uint64_write(req, request_mask); + v9fs_req_send(req); + return req; +} + +typedef struct v9fs_attr { + uint64_t valid; + v9fs_qid qid; + uint32_t mode; + uint32_t uid; + uint32_t gid; + uint64_t nlink; + uint64_t rdev; + uint64_t size; + uint64_t blksize; + uint64_t blocks; + uint64_t atime_sec; + uint64_t atime_nsec; + uint64_t mtime_sec; + uint64_t mtime_nsec; + uint64_t ctime_sec; + uint64_t ctime_nsec; + uint64_t btime_sec; + uint64_t btime_nsec; + uint64_t gen; + uint64_t data_version; +} v9fs_attr; + +#define P9_GETATTR_BASIC 0x000007ffULL /* Mask for fields up to BLOCKS */ + +/* + * size[4] Rgetattr tag[2] valid[8] qid[13] mode[4] uid[4] gid[4] nlink[8] + * rdev[8] size[8] blksize[8] blocks[8] + * atime_sec[8] atime_nsec[8] mtime_sec[8] mtime_nsec[8] + * ctime_sec[8] ctime_nsec[8] btime_sec[8] btime_nsec[8] + * gen[8] data_version[8] + */ +static void v9fs_rgetattr(P9Req *req, v9fs_attr *attr) +{ + v9fs_req_recv(req, P9_RGETATTR); + + v9fs_uint64_read(req, &attr->valid); + v9fs_memread(req, &attr->qid, 13); + v9fs_uint32_read(req, &attr->mode); + v9fs_uint32_read(req, &attr->uid); + v9fs_uint32_read(req, &attr->gid); + v9fs_uint64_read(req, &attr->nlink); + v9fs_uint64_read(req, &attr->rdev); + v9fs_uint64_read(req, &attr->size); + v9fs_uint64_read(req, &attr->blksize); + v9fs_uint64_read(req, &attr->blocks); + v9fs_uint64_read(req, &attr->atime_sec); + v9fs_uint64_read(req, &attr->atime_nsec); + v9fs_uint64_read(req, &attr->mtime_sec); + v9fs_uint64_read(req, &attr->mtime_nsec); + v9fs_uint64_read(req, &attr->ctime_sec); + v9fs_uint64_read(req, &attr->ctime_nsec); + v9fs_uint64_read(req, &attr->btime_sec); + v9fs_uint64_read(req, &attr->btime_nsec); + v9fs_uint64_read(req, &attr->gen); + v9fs_uint64_read(req, &attr->data_version); + + 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 +1089,7 @@ 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 v9fs_attr attr; do_version(v9p); req = v9fs_tattach(v9p, 0, getuid(), 0); @@ -1021,6 +1102,12 @@ 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_tgetattr(v9p, 1, P9_GETATTR_BASIC, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rgetattr(req, &attr); + + g_assert(is_same_qid(root_qid, attr.qid)); } static void fs_walk_dotdot(void *obj, void *data, QGuestAllocator *t_alloc) From patchwork Thu Jun 16 11:00: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: 1644283 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=crudebyte.com header.i=@crudebyte.com header.a=rsa-sha256 header.s=lizzy header.b=d2SR/QH/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP0933jDFz9sG0 for ; Thu, 16 Jun 2022 21:20:55 +1000 (AEST) Received: from localhost ([::1]:38574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1nYT-0002PX-BM for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 07:20:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1nLl-0007K0-I7 for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:07:45 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:57481) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1nLk-0003KI-5W for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:07:45 -0400 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=LfOg2LJMp+lzmauAGTMKtTKYtVr9WibU0AurDQsfIYI=; b=d2SR/ QH//QplBsViZTxcD1trRxVz8DdOEMuir3n2KLLmkt3MKG+J6SkixraejP5OOtUYhZSVrJz8PTxboI dlXUUgwdfN4WpuF66Ynt0eb4iWTeorOVsG2hW7oChrcSEK4rWrwCJLnkIiNNqPyi1+IXvZ1QGCCZm zfs9Zh1bLkbLfgsZG8LVCOwjYP4rz7iOA6Xkjt8nr+06KqgDAqCBbP2D76u5azf54/bsn5WXvpGSw +702dvleeOX6CwdEK7STDgng4PRrs6z4hUlAy17MnAAvq/XBlwHLTUy4CJxfIZyuNrg/HQcEKGGRZ Ty4cKahG8BTrAou4KXQ/nHsHavp8w==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 16 Jun 2022 13:00:04 +0200 Subject: [PULL 4/7] 9pfs: refactor 'name_idx' -> 'nwalked' in v9fs_walk() To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=fd6c979e651a2163062b746e01adf6f267c8e874@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+incoming=patchwork.ozlabs.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 'nwalked' instead, which we will use in subsequent patch as the number of (requested) path components successfully walked by background I/O thread. Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz Message-Id: --- 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 0cd0c14c2a..f29611e9ed 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1766,7 +1766,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, nwalked; g_autofree V9fsQID *qids = NULL; int i, err = 0; V9fsPath dpath, path; @@ -1844,17 +1844,17 @@ static void coroutine_fn v9fs_walk(void *opaque) break; } stbuf = fidst; - for (name_idx = 0; name_idx < nwnames; name_idx++) { + for (nwalked = 0; nwalked < nwnames; nwalked++) { if (v9fs_request_cancelled(pdu)) { err = -EINTR; break; } if (!same_stat_id(&pdu->s->root_st, &stbuf) || - strcmp("..", wnames[name_idx].data)) + strcmp("..", wnames[nwalked].data)) { err = s->ops->name_to_path(&s->ctx, &dpath, - wnames[name_idx].data, - &pathes[name_idx]); + wnames[nwalked].data, + &pathes[nwalked]); if (err < 0) { err = -errno; break; @@ -1863,13 +1863,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[nwalked], &stbuf); if (err < 0) { err = -errno; break; } - stbufs[name_idx] = stbuf; - v9fs_path_copy(&dpath, &pathes[name_idx]); + stbufs[nwalked] = stbuf; + v9fs_path_copy(&dpath, &pathes[nwalked]); } } }); From patchwork Thu Jun 16 11:00: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: 1644278 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=crudebyte.com header.i=@crudebyte.com header.a=rsa-sha256 header.s=lizzy header.b=J8v502Ci; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LNzwV4Q0Lz9sG0 for ; Thu, 16 Jun 2022 21:10:02 +1000 (AEST) Received: from localhost ([::1]:50950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1nNt-0007PG-Mo for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 07:09:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49832) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1nLs-0007NE-UH for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:07:54 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:34923) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1nLq-0003KO-ED for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:07:52 -0400 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=kqagmhT5Hnxzs3s87xAOx4b5O/RWU8vgFLM+v23qnNQ=; b=J8v50 2CipeToLxQlriKspx6EjxgC49IGaVoHJ6Tbb2sP4bSph5Rq4LUR3vs3m1n8bkHOCfx9eerdqxVnon kCIuJACx38xHnCCFdCIFAlsYmQM9EbnQXEKe6I42+Dx6h7Q7WJGnuL+lnubAA03BmeDNVxig3H2nH HXLjrL7LNd2/vUMb6wH3XtSxZcclm8RW1SDChNagGkCr24zaOtHt7vNX3SH7a5lMYYAMqLjdfcr0v u/8aXpw8YJjeYlBnzlNgKNMNLpb1PVeqo5PuGFt/zujFl0rEvDExg4RvcnQK0eSDJepYonwjHavuC 38EZDOae2UaDInI7eH0nLVWmaC+lA==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 16 Jun 2022 13:00:04 +0200 Subject: [PULL 5/7] 9pfs: fix 'Twalk' to only send error if no component walked To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=a93d2e89e59e67ac5796679fdcef9467e6b2cc55@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+incoming=patchwork.ozlabs.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 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 Reviewed-by: Greg Kurz Message-Id: --- hw/9pfs/9p.c | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index f29611e9ed..aebadeaa03 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1768,7 +1768,7 @@ static void coroutine_fn v9fs_walk(void *opaque) { int name_idx, nwalked; 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; @@ -1834,19 +1834,20 @@ static void coroutine_fn v9fs_walk(void *opaque) * driver code altogether inside the following block. */ v9fs_co_run_in_worker({ + nwalked = 0; if (v9fs_request_cancelled(pdu)) { - err = -EINTR; + any_err |= err = -EINTR; break; } err = s->ops->lstat(&s->ctx, &dpath, &fidst); if (err < 0) { - err = -errno; + any_err |= err = -errno; break; } stbuf = fidst; - for (nwalked = 0; nwalked < nwnames; nwalked++) { + for (; nwalked < nwnames; nwalked++) { if (v9fs_request_cancelled(pdu)) { - err = -EINTR; + any_err |= err = -EINTR; break; } if (!same_stat_id(&pdu->s->root_st, &stbuf) || @@ -1856,16 +1857,16 @@ static void coroutine_fn v9fs_walk(void *opaque) wnames[nwalked].data, &pathes[nwalked]); if (err < 0) { - err = -errno; + any_err |= err = -errno; break; } if (v9fs_request_cancelled(pdu)) { - err = -EINTR; + any_err |= err = -EINTR; break; } err = s->ops->lstat(&s->ctx, &pathes[nwalked], &stbuf); if (err < 0) { - err = -errno; + any_err |= err = -errno; break; } 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 ... + * + * 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; } - err = stat_to_qid(pdu, &fidst, &qid); - if (err < 0) { + any_err |= err = stat_to_qid(pdu, &fidst, &qid); + if (err < 0 && !nwalked) { goto out; } stbuf = fidst; @@ -1890,20 +1897,29 @@ 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 < nwalked; 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); + any_err |= 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)); } + 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 (fidp->fid_type != P9_FID_NONE) { err = -EINVAL; @@ -1921,8 +1937,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 Thu Jun 16 11:00: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: 1644286 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=crudebyte.com header.i=@crudebyte.com header.a=rsa-sha256 header.s=lizzy header.b=eszYiZrp; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP0GV6wrdz9sG0 for ; Thu, 16 Jun 2022 21:25:38 +1000 (AEST) Received: from localhost ([::1]:46368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1nd2-0007s5-Pt for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 07:25:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <15fbff488a908af01210071ffad70f9254d077fc@lizzy.crudebyte.com>) id 1o1nLz-0007PF-Pi for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:08:00 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:44189) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <15fbff488a908af01210071ffad70f9254d077fc@lizzy.crudebyte.com>) id 1o1nLy-0003PD-7g for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:07:59 -0400 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=5ximnrdjmuNJ7F+rLu47YcLj79K0sHNt06kxYGAEflc=; b=eszYi ZrpLopVp3VpNceFwWSxzx55TxjzZXSWrrcGCdytTgLgdaZ1nwrzlHiHLh1ZcvD/wicJuRdfRlIFT/ LknBJV+D1I6FtV6mqApjX4DQ9kku1Yv/D4ZFTs8q195A/IIRNpbtFJL8ZJHs+g664svaXPn1D5r5+ 2EmNVbs8QfkXZQ22PpKnAMT+d9RHY1x7xxjDm/kTsnOrdJLLnaAVuUHCSVs6uMGMPFqWCmUjQ45a9 KKDpg8Zoe4R5GwYUBHVb4e35SFZn4XduNWAVrEs/6RmBOkEa+l7rjuzXJBiSh075bggY9dM4bffRf fngBsiQEZtihwzZ53lHpZ0b++4BGg==; Message-Id: <15fbff488a908af01210071ffad70f9254d077fc.1655377203.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 16 Jun 2022 13:00:04 +0200 Subject: [PULL 6/7] tests/9pfs: guard recent 'Twalk' behaviour fix To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=15fbff488a908af01210071ffad70f9254d077fc@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+incoming=patchwork.ozlabs.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 Message-Id: <61bde2f44b87e24b70ec098dfb81765665b2dfcb.1647339025.git.qemu_oss@crudebyte.com> --- 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 3c0f094929..c787ded4d2 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -669,8 +669,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; @@ -680,12 +684,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) { @@ -1079,9 +1089,33 @@ static void fs_walk_nonexistent(void *obj, void *data, QGuestAllocator *t_alloc) alloc = t_alloc; do_attach(v9p); + /* + * The 9p2000 protocol spec says: "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 says: "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; @@ -1548,6 +1582,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, From patchwork Thu Jun 16 11:00: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: 1644281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=crudebyte.com header.i=@crudebyte.com header.a=rsa-sha256 header.s=lizzy header.b=dUjdTY7w; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LP05G2KQjz9sG0 for ; Thu, 16 Jun 2022 21:17:37 +1000 (AEST) Received: from localhost ([::1]:34254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1nVH-0007ne-7Y for incoming@patchwork.ozlabs.org; Thu, 16 Jun 2022 07:17:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <0e43495d3b4a50fc5e22f7b71261fdd5b56fdfcb@lizzy.crudebyte.com>) id 1o1nM5-0007Ts-BS for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:08:05 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:41567) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <0e43495d3b4a50fc5e22f7b71261fdd5b56fdfcb@lizzy.crudebyte.com>) id 1o1nM3-0003Ua-RH for qemu-devel@nongnu.org; Thu, 16 Jun 2022 07:08:05 -0400 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=5GVtuCb+h3vMK5cR5MF6sILSOR2ZmkmU+JK820SIpM4=; b=dUjdT Y7wF7xqtcKm7OjGQ3PjtZXpndbJ1B5/YR2/4QoN+/0KudoLZTZV1OB6XTVkwh3s9imD5GiQeW5hD+ 82rev7ZvI8J3HiMEJU052LVHLfZk1FgAFyhdooUwFu4RTrOdiNJ0dy+KgrrrxRMyTz8dNN9fb6lYA saC/RfE2WpPRVakK88r4yR9MNDmjPXaQg15X5rwLJXxErbuQVqDZ9nKzzwqx5WOWMPLADMuiHmQVc 2F8GbAy+2bm6DUQLfI3gxYOou5vBF39m1pQRlwaQ/L1omKLQzS9159FZMmrySoui7gRtglkx5LGXF tW9LEfptHOCN7tEmMSx5Y5w6jd13g==; Message-Id: <0e43495d3b4a50fc5e22f7b71261fdd5b56fdfcb.1655377203.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 16 Jun 2022 13:00:04 +0200 Subject: [PULL 7/7] tests/9pfs: check fid being unaffected in fs_walk_2nd_nonexistent To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=0e43495d3b4a50fc5e22f7b71261fdd5b56fdfcb@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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Extend previously added test case by checking that fid was unaffected by 'Twalk' request (i.e. when 2nd path component of request being invalid). Do that by subsequently sending a 'Tgetattr' request with the fid previously used for 'Twalk'; that 'Tgetattr' request should return an 'Rlerror' response by 9p server with error code ENOENT as that fid is basically invalid. And as we are at it, also check that the QID returned by 'Twalk' is not identical to the root node's QID. Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz Message-Id: <6f0813cafdbf683cdac8b1492dd4ef8699c5b1d9.1647339025.git.qemu_oss@crudebyte.com> --- tests/qtest/virtio-9p-test.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index c787ded4d2..25305a4cf7 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -721,14 +721,19 @@ static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc) do_version(obj); } -static void do_attach(QVirtio9P *v9p) +static void do_attach_rqid(QVirtio9P *v9p, v9fs_qid *qid) { P9Req *req; do_version(v9p); req = v9fs_tattach(v9p, 0, getuid(), 0); v9fs_req_wait_for_reply(req, NULL); - v9fs_rattach(req, NULL); + v9fs_rattach(req, qid); +} + +static void do_attach(QVirtio9P *v9p) +{ + do_attach_rqid(v9p, NULL); } static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc) @@ -1101,19 +1106,32 @@ static void fs_walk_2nd_nonexistent(void *obj, void *data, { QVirtio9P *v9p = obj; alloc = t_alloc; + v9fs_qid root_qid; uint16_t nwqid; + uint32_t fid, err; + P9Req *req; 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); + do_attach_rqid(v9p, &root_qid); + fid = do_walk_rqids(v9p, path, &nwqid, &wqid); /* * The 9p2000 protocol spec says: "nwqid is therefore either nwname or the * index of the first elementwise walk that failed." */ assert(nwqid == 1); + + /* returned QID wqid[0] is file ID of 1st subdir */ + g_assert(wqid && wqid[0] && !is_same_qid(root_qid, wqid[0])); + + /* expect fid being unaffected by walk above */ + req = v9fs_tgetattr(v9p, fid, P9_GETATTR_BASIC, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rlerror(req, &err); + + g_assert_cmpint(err, ==, ENOENT); } static void fs_walk_none(void *obj, void *data, QGuestAllocator *t_alloc)