From nobody Fri Mar 29 07:29:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1602944772; cv=none; d=zohomail.com; s=zohoarc; b=g7pTN33tvhW28EVzOG1BEi4gMdVhDC8c4Sqb3YAwS3YBqwNPOlOj4G9ZLf0vicXjVZxpJJ7sQDxb16zhmqyD9vBFjWasOjQkzpkPkV7Z1Bp/JeCSRX+DVpELszhp2cum0zB9Uas/7lqMq+wD15eoduz2VnH5/L5raY/HCtsao7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602944772; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=uYCOhtjPf6+B9BmnvExTz7BoHTRQm0BF5tGsJnw9wkM=; b=KjGgVmw7R0xXaAYKygzvAM8gQiSq1oi+QF59OwmFi6QDOf55CF0S8HcomaM4yNzvqorC1i24uk36dcdnUmvuh0K5rsGeWdp0sODZdEYqSTb5x3mVxiV9M4qq2AFUAVRSdHHuCyfo+ZHbGOxu6lk50p/Y2/1KlS9Wk/Rc/Z0OoK0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602944771930683.9240509484125; Sat, 17 Oct 2020 07:26:11 -0700 (PDT) Received: from localhost ([::1]:43796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kTn9u-00075A-GV for importer@patchew.org; Sat, 17 Oct 2020 10:26:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <49220110c8fb16b9d52ad7485ccf2c2b51157035@lizzy.crudebyte.com>) id 1kTn8U-0005hu-9b for qemu-devel@nongnu.org; Sat, 17 Oct 2020 10:24:42 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:46975) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <49220110c8fb16b9d52ad7485ccf2c2b51157035@lizzy.crudebyte.com>) id 1kTn8S-00061e-Kw for qemu-devel@nongnu.org; Sat, 17 Oct 2020 10:24:41 -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=uYCOhtjPf6+B9BmnvExTz7BoHTRQm0BF5tGsJnw9wkM=; b=HU86b JBO2L706iJhIxiBymfEgXum2DlFih35DpZ3l2bBTSIuMOX0Xzw1OqSWSoHhxEuQtz25TyKJgAdiPn AX6TIdSCsPVTQN6/7AMUb7DVivVqhRhZbROpqv3cTFxYKhPChFH3RskTo3gCqAGuKT5/oWkRXWO7K pMyxq300vIhb9e/msVn7B4NyhD/JSsuIA+tAqaknXMBvVehJ8l6b1WqAvrjtv6CZpl+BuC1o/cyuq YxUV0CvC4ObkBqAqdFqJyiJRRg80rV5+Ihe6OXBn4yiUYHjVEfBEpLlKCOjxnqDb2Baoc3zfdu763 qiE4hsPOk9yliPxfUyHvK+FExCjTg==; Message-Id: <49220110c8fb16b9d52ad7485ccf2c2b51157035.1602943547.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 8 Oct 2020 20:34:56 +0200 Subject: [PULL v2 1/5] tests/9pfs: change qtest name prefix to synth To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=91.194.90.13; envelope-from=49220110c8fb16b9d52ad7485ccf2c2b51157035@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/17 10:23:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: 13 X-Spam_score: 1.3 X-Spam_bar: + X-Spam_report: (1.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, 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 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" All existing 9pfs test cases are using the 'synth' fs driver so far, which means they are not accessing real files, but a purely simulated (in RAM only) file system. Let's make this clear by changing the prefix of the individual qtest case names from 'fs/' to 'synth/'. That way they'll be easily distinguishable from upcoming new 9pfs test cases supposed to be using a different fs driver. Signed-off-by: Christian Schoenebeck Message-Id: Signed-off-by: Christian Schoenebeck --- tests/qtest/virtio-9p-test.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index de30b717b6..3281153b9c 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -897,26 +897,26 @@ static void fs_readdir_split_512(void *obj, void *dat= a, =20 static void register_virtio_9p_test(void) { - qos_add_test("config", "virtio-9p", pci_config, NULL); - qos_add_test("fs/version/basic", "virtio-9p", fs_version, NULL); - qos_add_test("fs/attach/basic", "virtio-9p", fs_attach, NULL); - qos_add_test("fs/walk/basic", "virtio-9p", fs_walk, NULL); - qos_add_test("fs/walk/no_slash", "virtio-9p", fs_walk_no_slash, + qos_add_test("synth/config", "virtio-9p", pci_config, NULL); + qos_add_test("synth/version/basic", "virtio-9p", fs_version, NULL); + qos_add_test("synth/attach/basic", "virtio-9p", fs_attach, NULL); + qos_add_test("synth/walk/basic", "virtio-9p", fs_walk, NULL); + qos_add_test("synth/walk/no_slash", "virtio-9p", fs_walk_no_slash, NULL); - qos_add_test("fs/walk/dotdot_from_root", "virtio-9p", + qos_add_test("synth/walk/dotdot_from_root", "virtio-9p", fs_walk_dotdot, NULL); - qos_add_test("fs/lopen/basic", "virtio-9p", fs_lopen, NULL); - qos_add_test("fs/write/basic", "virtio-9p", fs_write, NULL); - qos_add_test("fs/flush/success", "virtio-9p", fs_flush_success, + qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen, NULL); + qos_add_test("synth/write/basic", "virtio-9p", fs_write, NULL); + qos_add_test("synth/flush/success", "virtio-9p", fs_flush_success, NULL); - qos_add_test("fs/flush/ignored", "virtio-9p", fs_flush_ignored, + qos_add_test("synth/flush/ignored", "virtio-9p", fs_flush_ignored, NULL); - qos_add_test("fs/readdir/basic", "virtio-9p", fs_readdir, NULL); - qos_add_test("fs/readdir/split_512", "virtio-9p", + qos_add_test("synth/readdir/basic", "virtio-9p", fs_readdir, NULL); + qos_add_test("synth/readdir/split_512", "virtio-9p", fs_readdir_split_512, NULL); - qos_add_test("fs/readdir/split_256", "virtio-9p", + qos_add_test("synth/readdir/split_256", "virtio-9p", fs_readdir_split_256, NULL); - qos_add_test("fs/readdir/split_128", "virtio-9p", + qos_add_test("synth/readdir/split_128", "virtio-9p", fs_readdir_split_128, NULL); } =20 --=20 2.20.1 From nobody Fri Mar 29 07:29:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1602944877; cv=none; d=zohomail.com; s=zohoarc; b=GPNjjuDFsvVtjl5Xj3c3Q/gSIhhS2vUA4pGVpbedd1r+5nKpfMlBTcqQ8Fd2U9489cpe6YHqzKHmOifeeMcT8C8FCeGYGMhJYajWnnRIdaRdGjdAmj2zfzO9QwcfHOXIcq6EbwtTwSS7k77e2zaJo4Oe80fhaFcJPfdOilNYX/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602944877; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=UXdORMhNTzUaXATYfFlOjsg4HMQM6pqpJfi/o477dzE=; b=m6xJaWN1SV74RXLoNHY3ym7PLjIV9wCjib6j0devRe8fiJ+yfPe7ubAA8S3PzuoTDifcxi3sfz2pVmIA15n9IU5zYYB9TybhQzXJrIIKLyPGnUEatPg9/anv5fPnDZsL6JWyNmdfP9bkI4QWTYSkCluy2git/mQLMja1KghKdJY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602944877019288.827313454138; Sat, 17 Oct 2020 07:27:57 -0700 (PDT) Received: from localhost ([::1]:50062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kTnBb-0001DZ-OM for importer@patchew.org; Sat, 17 Oct 2020 10:27:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <8b44f1c852cf323a4831279ccebbede60c8f3464@lizzy.crudebyte.com>) id 1kTn8b-0005wS-56 for qemu-devel@nongnu.org; Sat, 17 Oct 2020 10:24:49 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:50029) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <8b44f1c852cf323a4831279ccebbede60c8f3464@lizzy.crudebyte.com>) id 1kTn8Z-00061m-6i for qemu-devel@nongnu.org; Sat, 17 Oct 2020 10:24:48 -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=UXdORMhNTzUaXATYfFlOjsg4HMQM6pqpJfi/o477dzE=; b=XyxH8 4ziOD36j5evJvso3C2EJ/PghbZDsCV+xz80dBrgbdSufp1LmaXl7YBFL1GNwtLj3K7ZZ0VYoNfomt QqVNJo8N87kF+cI0UHxiXVH6B7awwru+XAb8BHC/Xj7mY46V8dfwW5fuyNZK1EqoRbyKYBf8pKgd+ tXDIHvAm+kqBPWb5+k+9swmEHjVxx8zW7w1oD3VptL9pwJkRefqyKjCVtAz5B5QKMQGETlQUd4xPr D7vI/Oy1LhFB/xZgykS7vNLVLecUuOE6TGSmmaeL15aV5MLuhzup/7qslX66Y5TLh3m6opDDwSm7n BjOMANC3KFEnQNlqGTL41FR7gx/rw==; Message-Id: <8b44f1c852cf323a4831279ccebbede60c8f3464.1602943547.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 8 Oct 2020 20:34:56 +0200 Subject: [PULL v2 2/5] tests/9pfs: introduce local tests To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=91.194.90.13; envelope-from=8b44f1c852cf323a4831279ccebbede60c8f3464@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/17 10:23:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: 13 X-Spam_score: 1.3 X-Spam_bar: + X-Spam_report: (1.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, 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 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch introduces 9pfs test cases using the 9pfs 'local' filesystem driver which reads/writes/creates/deletes real files and directories. In this initial version, there is only one local test which actually only checks if the 9pfs 'local' device was created successfully. Before the 9pfs 'local' tests are run, a test directory 'qtest-9p-local' is created (with world rwx permissions) under the current working directory. At this point that test directory is not auto deleted yet. Signed-off-by: Christian Schoenebeck Message-Id: <81fc4b3b6b6c9bf7999e79f5e7cbc364a5f09ddb.1602182956.git.qemu_o= ss@crudebyte.com> Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p.c | 81 ++++++++++++++++++++++++++++++++++ tests/qtest/libqos/virtio-9p.h | 5 +++ tests/qtest/virtio-9p-test.c | 44 ++++++++++++------ 3 files changed, 116 insertions(+), 14 deletions(-) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index 2e300063e3..ee331166de 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -24,6 +24,34 @@ #include "qgraph.h" =20 static QGuestAllocator *alloc; +static char *local_test_path; + +/* Concatenates the passed 2 pathes. Returned result must be freed. */ +static char *concat_path(const char* a, const char* b) +{ + return g_build_filename(a, b, NULL); +} + +static void init_local_test_path(void) +{ + char *pwd =3D g_get_current_dir(); + local_test_path =3D concat_path(pwd, "qtest-9p-local"); + g_free(pwd); +} + +/* Creates the directory for the 9pfs 'local' filesystem driver to access.= */ +static void create_local_test_dir(void) +{ + struct stat st; + + g_assert(local_test_path !=3D NULL); + mkdir(local_test_path, 0777); + + /* ensure test directory exists now ... */ + g_assert(stat(local_test_path, &st) =3D=3D 0); + /* ... and is actually a directory */ + g_assert((st.st_mode & S_IFMT) =3D=3D S_IFDIR); +} =20 static void virtio_9p_cleanup(QVirtio9P *interface) { @@ -146,11 +174,64 @@ static void *virtio_9p_pci_create(void *pci_bus, QGue= stAllocator *t_alloc, return obj; } =20 +/** + * Performs regular expression based search and replace on @a haystack. + * + * @param haystack - input string to be parsed, result of replacement is + * stored back to @a haystack + * @param pattern - the regular expression pattern for scanning @a haystack + * @param replace_fmt - matches of supplied @a pattern are replaced by thi= s, + * if necessary glib printf format can be used to add + * variable arguments of this function to this + * replacement string + */ +static void regex_replace(GString *haystack, const char *pattern, + const char *replace_fmt, ...) +{ + GRegex *regex; + char *replace, *s; + va_list argp; + + va_start(argp, replace_fmt); + replace =3D g_strdup_vprintf(replace_fmt, argp); + va_end(argp); + + regex =3D g_regex_new(pattern, 0, 0, NULL); + s =3D g_regex_replace(regex, haystack->str, -1, 0, replace, 0, NULL); + g_string_assign(haystack, s); + g_free(s); + g_regex_unref(regex); + g_free(replace); +} + +void virtio_9p_assign_local_driver(GString *cmd_line, const char *args) +{ + g_assert_nonnull(local_test_path); + + /* replace 'synth' driver by 'local' driver */ + regex_replace(cmd_line, "-fsdev synth,", "-fsdev local,"); + + /* append 'path=3D...' to '-fsdev ...' group */ + regex_replace(cmd_line, "(-fsdev \\w[^ ]*)", "\\1,path=3D'%s'", + local_test_path); + + if (!args) { + return; + } + + /* append passed args to '-fsdev ...' group */ + regex_replace(cmd_line, "(-fsdev \\w[^ ]*)", "\\1,%s", args); +} + static void virtio_9p_register_nodes(void) { const char *str_simple =3D "fsdev=3Dfsdev0,mount_tag=3D" MOUNT_TAG; const char *str_addr =3D "fsdev=3Dfsdev0,addr=3D04.0,mount_tag=3D" MOU= NT_TAG; =20 + /* make sure test dir for the 'local' tests exists and is clean */ + init_local_test_path(); + create_local_test_dir(); + QPCIAddress addr =3D { .devfn =3D QPCI_DEVFN(4, 0), }; diff --git a/tests/qtest/libqos/virtio-9p.h b/tests/qtest/libqos/virtio-9p.h index b1e6badc4a..326a603f72 100644 --- a/tests/qtest/libqos/virtio-9p.h +++ b/tests/qtest/libqos/virtio-9p.h @@ -44,4 +44,9 @@ struct QVirtio9PDevice { QVirtio9P v9p; }; =20 +/** + * Prepares QEMU command line for 9pfs tests using the 'local' fs driver. + */ +void virtio_9p_assign_local_driver(GString *cmd_line, const char *args); + #endif diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 3281153b9c..af7e169d3a 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -895,29 +895,45 @@ static void fs_readdir_split_512(void *obj, void *dat= a, fs_readdir_split(obj, data, t_alloc, 512); } =20 +static void *assign_9p_local_driver(GString *cmd_line, void *arg) +{ + virtio_9p_assign_local_driver(cmd_line, "security_model=3Dmapped-xattr= "); + return arg; +} + static void register_virtio_9p_test(void) { - qos_add_test("synth/config", "virtio-9p", pci_config, NULL); - qos_add_test("synth/version/basic", "virtio-9p", fs_version, NULL); - qos_add_test("synth/attach/basic", "virtio-9p", fs_attach, NULL); - qos_add_test("synth/walk/basic", "virtio-9p", fs_walk, NULL); + + QOSGraphTestOptions opts =3D { + }; + + /* 9pfs test cases using the 'synth' filesystem driver */ + qos_add_test("synth/config", "virtio-9p", pci_config, &opts); + qos_add_test("synth/version/basic", "virtio-9p", fs_version, &opts); + qos_add_test("synth/attach/basic", "virtio-9p", fs_attach, &opts); + qos_add_test("synth/walk/basic", "virtio-9p", fs_walk, &opts); qos_add_test("synth/walk/no_slash", "virtio-9p", fs_walk_no_slash, - NULL); + &opts); qos_add_test("synth/walk/dotdot_from_root", "virtio-9p", - fs_walk_dotdot, NULL); - qos_add_test("synth/lopen/basic", "virtio-9p", fs_lopen, NULL); - qos_add_test("synth/write/basic", "virtio-9p", fs_write, NULL); + fs_walk_dotdot, &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, - NULL); + &opts); qos_add_test("synth/flush/ignored", "virtio-9p", fs_flush_ignored, - NULL); - qos_add_test("synth/readdir/basic", "virtio-9p", fs_readdir, NULL); + &opts); + qos_add_test("synth/readdir/basic", "virtio-9p", fs_readdir, &opts); qos_add_test("synth/readdir/split_512", "virtio-9p", - fs_readdir_split_512, NULL); + fs_readdir_split_512, &opts); qos_add_test("synth/readdir/split_256", "virtio-9p", - fs_readdir_split_256, NULL); + fs_readdir_split_256, &opts); qos_add_test("synth/readdir/split_128", "virtio-9p", - fs_readdir_split_128, NULL); + fs_readdir_split_128, &opts); + + + /* 9pfs test cases using the 'local' filesystem driver */ + opts.before =3D assign_9p_local_driver; + qos_add_test("local/config", "virtio-9p", pci_config, &opts); } =20 libqos_init(register_virtio_9p_test); --=20 2.20.1 From nobody Fri Mar 29 07:29:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1602945020; cv=none; d=zohomail.com; s=zohoarc; b=HO78E+NJ6j63gx6P0mRl0vq/Rpj0xcXJwFc5pMSOhcUMDRqsciPNpQFX31zvPSWiaIIQnzD9ljMgf2UMbcOnCPNJdWtkk38RKblt1nmqFMpLQKeaAyU7IY0jL8hfXprnUI1+iFO76S8hOBm3Yo1tKl404ATDe2bbCilb6EWnp9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602945020; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=yDG/u17bdmxsKZTdFz3D0Y47pkgPagiwF3adJJ/WwAw=; b=faKu+HGmXrItz1KADLWlXVncofDb3C/OvO0ShMx4up7YhI2zmGP3Mfb/0Mq9wVQIdfF5SikNTcC1zkusjRs7yS1/3dAsWFGTVxq+EhjH3/r97nN+5J3UrrXahbMRfvse7Ye7uP/SzexMB3EqsBtzBYamQ4QTGR97f3vVbUgVa2A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602945020054471.1350522945726; Sat, 17 Oct 2020 07:30:20 -0700 (PDT) Received: from localhost ([::1]:56332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kTnDu-0003oK-ST for importer@patchew.org; Sat, 17 Oct 2020 10:30:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTn8g-000606-NQ for qemu-devel@nongnu.org; Sat, 17 Oct 2020 10:24:55 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:40587) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTn8f-000632-6V for qemu-devel@nongnu.org; Sat, 17 Oct 2020 10:24:54 -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=yDG/u17bdmxsKZTdFz3D0Y47pkgPagiwF3adJJ/WwAw=; b=i+aW9 9FBEXa+nIiAmIArkLCRDXvcq1wYcdZBQHipjoeCFxGoYHcMxaJL/IXn98l8kVz2q3T/J+Unzf1soW RMPsPitJyxX5fRRD4qTZn6nuf7l4hk7GgCPIuVpH6XLLQo1S7gisrGMwdrRsxJqBmCsCewxw7V6jb 1w7ShDIcnVxc5Y5iI/JS1O9kQqvdyojRHx29+b0M/OL5PQwtl20dw4s0ykpfAeJF14fLBYb6MU261 iTw92iICmyozFqMN/IKqJ40ddkHOWJRu++EjwHQf9kcmnobs5aCl92Dp0AqFEdJtStlPcERtf/Z6E zwoF9LjYs3m1APZkqEqzpHg5I/A2A==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 8 Oct 2020 20:34:56 +0200 Subject: [PULL v2 3/5] tests/9pfs: wipe local 9pfs test directory To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=91.194.90.13; envelope-from=a45b2829da0af55c8344fa83876d59f9c4b0cf78@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/17 10:23:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: 13 X-Spam_score: 1.3 X-Spam_bar: + X-Spam_report: (1.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, 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 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Before running the first 9pfs test case, make sure the test directory for running the 9pfs 'local' tests on is entirely empty. For that reason simply delete the test directory (if any) before (re)creating it on test suite startup. Note: The preferable precise behaviour would be the test directory only being wiped once *before* a test suite run. Right now the test directory is also wiped at the *end* of a test suite run because libqos is calling the virtio_9p_register_nodes() callback for some reason also when a test suite completed. This is suboptimal as developers cannot immediately see what files and directories the 9pfs local tests created precisely after the test suite completed. But fortunately the test directory is not wiped if some test failed. So it is probably not worth it drilling another hole into libqos for this issue. Signed-off-by: Christian Schoenebeck Message-Id: Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index ee331166de..8ee2a134bc 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -53,6 +53,18 @@ static void create_local_test_dir(void) g_assert((st.st_mode & S_IFMT) =3D=3D S_IFDIR); } =20 +/* Deletes directory previously created by create_local_test_dir(). */ +static void remove_local_test_dir(void) +{ + g_assert(local_test_path !=3D NULL); + char *cmd =3D g_strdup_printf("rm -r '%s'\n", local_test_path); + int res =3D system(cmd); + if (res < 0) { + /* ignore error, dummy check to prevent compiler error */ + } + g_free(cmd); +} + static void virtio_9p_cleanup(QVirtio9P *interface) { qvirtqueue_cleanup(interface->vdev->bus, interface->vq, alloc); @@ -230,6 +242,7 @@ static void virtio_9p_register_nodes(void) =20 /* make sure test dir for the 'local' tests exists and is clean */ init_local_test_path(); + remove_local_test_dir(); create_local_test_dir(); =20 QPCIAddress addr =3D { --=20 2.20.1 From nobody Fri Mar 29 07:29:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1602945129; cv=none; d=zohomail.com; s=zohoarc; b=hI5qJKRu1FdbutWP3+EBZo2BpKSNxA5fYK20hQA39eU3nn21lF/XzHlYjot6p3I+k/ECt6cTsKCHUYNbOA9WAGLR1BVvO8e/PWhefMvJ/Gh86vioawQ88d69b9x8rejDcyQtBnX9sdeLbLD+IMJNUwLOsD0URxHC9hdO7r5d3Og= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602945129; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=M1h+8JuW+VSud8WRZ5tHr7+ecRGCn44dlLdNtw0kNQU=; b=KaeGNVbd8dqI19kvJaWwilHn82OHcXBIMEJodAlbMk9FuAgof7OS+dpyHfwaHGnz9DKY3eeLXTn3Me/qaHzbGfxY6VXTXZVSY1ylONGeODmChjh/7glGK1O/CVYMIQ7spneyU6mcjkJQRW+OgyBfUQyQRU56CXxvrJb/SIlWct8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602945129760406.72469398341036; Sat, 17 Oct 2020 07:32:09 -0700 (PDT) Received: from localhost ([::1]:34136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kTnFg-0006dJ-7y for importer@patchew.org; Sat, 17 Oct 2020 10:32:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTn8m-00062q-UD for qemu-devel@nongnu.org; Sat, 17 Oct 2020 10:25:00 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:40267) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTn8l-00063Y-F9 for qemu-devel@nongnu.org; Sat, 17 Oct 2020 10:25:00 -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=M1h+8JuW+VSud8WRZ5tHr7+ecRGCn44dlLdNtw0kNQU=; b=Zn5Z5 A3TvY0ObF+LPLYiXBilg9YkkRMpKWhSUAHoATcolqfFpoDgscONEwbWt5qCrcLB7CxLA08mS+upwQ cK41zEzW1UQ0wXCdXlixgNOVL1mGWVTD598yeWSULFDlQuZI8vcHT92Z8R/MHFZbaRALaqcyikswP KO83p41uIlzIFH/E0eEO6Ud/u5aRtkoRM+Ox2zMiyKpZ0dE4F+RcOM8CxhhF/jDhySnFGd58bMFHy +IC39GDHS7PfBHvtGMtpmz2rW1qqAe/NHD4xmFxhRJAbyiEe87Pd9+z22eMYaCdFarw2yyqi8Xewp C4e07CvofRVeJmJFk46f1PqWoqLuw==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 8 Oct 2020 20:34:56 +0200 Subject: [PULL v2 4/5] tests/9pfs: add virtio_9p_test_path() To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=91.194.90.13; envelope-from=c3917b9e1add779728b8ee4d49884eb68afddb06@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/17 10:23:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: 13 X-Spam_score: 1.3 X-Spam_bar: + X-Spam_report: (1.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, 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 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This new public function virtio_9p_test_path() allows 9pfs 'local' tests to translate a path from guest scope to host scope. For instance by passing an empty string it would return the root path on host of the exported 9pfs tree. Signed-off-by: Christian Schoenebeck Message-Id: Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p.c | 6 ++++++ tests/qtest/libqos/virtio-9p.h | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index 8ee2a134bc..d43647b3b7 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -65,6 +65,12 @@ static void remove_local_test_dir(void) g_free(cmd); } =20 +char *virtio_9p_test_path(const char *path) +{ + g_assert(local_test_path); + return concat_path(local_test_path, path); +} + static void virtio_9p_cleanup(QVirtio9P *interface) { qvirtqueue_cleanup(interface->vdev->bus, interface->vq, alloc); diff --git a/tests/qtest/libqos/virtio-9p.h b/tests/qtest/libqos/virtio-9p.h index 326a603f72..19a4d97454 100644 --- a/tests/qtest/libqos/virtio-9p.h +++ b/tests/qtest/libqos/virtio-9p.h @@ -49,4 +49,9 @@ struct QVirtio9PDevice { */ void virtio_9p_assign_local_driver(GString *cmd_line, const char *args); =20 +/** + * Returns path on host to the passed guest path. Result must be freed. + */ +char *virtio_9p_test_path(const char *path); + #endif --=20 2.20.1 From nobody Fri Mar 29 07:29:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1602945817; cv=none; d=zohomail.com; s=zohoarc; b=Rxy5cGkWzkGQaexwF6ba5zEPQOt6W017cukQhZGO+7kz7I3nY/nRNzAYQhEXBH3rAYzAKqHLGQuIzzUdHDc27x5q8lziwNPDPaenbJZxauM6EsNC1AHE5dkwuqRyIMsIfRoHt1GHhongxQiOLiOFH5kit8WTnT/4cabET8gh/JI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602945817; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ChL4aj+c4Ghn+OQaOLCugF8LTTtqC1UX+xccoudNuYY=; b=gmari916NvfFeGxvE1h9qknfo8VHxLuxU21WeVdg1xsarPaiXatJ323OdWEnPEF7SfIPdYqxfcatw63FwYEmXSsHK/M4L15ej4XHeCy3SbtkXRB8BhWqXi2HPAhI444eDsE2IYMHcqgG5E8PkbH+uQ5ZAwVyopFD354S5bzONO8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602945817880558.6258161172892; Sat, 17 Oct 2020 07:43:37 -0700 (PDT) Received: from localhost ([::1]:33134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kTnQm-00021e-6h for importer@patchew.org; Sat, 17 Oct 2020 10:43:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTn8t-00068S-Ks for qemu-devel@nongnu.org; Sat, 17 Oct 2020 10:25:07 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:55391) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kTn8r-00063v-Rw for qemu-devel@nongnu.org; Sat, 17 Oct 2020 10:25:07 -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=ChL4aj+c4Ghn+OQaOLCugF8LTTtqC1UX+xccoudNuYY=; b=G4T7f WG5afQWie4F04J8V1NdX053UxA+W3AnKk917TmLR9FOQwkL9evUUrDzGmneFuoj99Z0PsoWtuYxlw YetCsbP7t+25V5fxqRiVjT0/1g0JBisGosCag1qMomSXTn6ejTxpv2JBgVtzxiCyWA78fvbzdy1bD HXWnhovhUE6WTXPGnbawWCqep9IFJEh1eVPDYYrCZA3oa14w0KTkPhAU/qa+OKs/tjB5ouHjEQD3l 334HiJ8vmG/KBXKudADRrShq0JJ2emxGnazZg7ISw2/zU+Xq5FCl8RZIuKE0hxJB7nXCiQW0tcHuP 093tqd36nVj6jsirFXk8FC5pFfURQ==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Thu, 8 Oct 2020 20:34:56 +0200 Subject: [PULL v2 5/5] tests/9pfs: add local Tmkdir test To: qemu-devel@nongnu.org, Peter Maydell Cc: Greg Kurz Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=91.194.90.13; envelope-from=fa4551e3f4416cc8c62086ac430b1ceb4f03eb6b@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/17 10:23:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: 13 X-Spam_score: 1.3 X-Spam_bar: + X-Spam_report: (1.3 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, 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 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This test case uses the 9pfs 'local' driver to create a directory and then checks if the expected directory was actually created (as real directory) on host side. This patch introduces a custom split() implementation, because the test code requires non empty array elements as result. For that reason g_strsplit() would not be a good alternative, as it would require additional filter code for reshuffling the array, and the resulting code would be even more complex than this split() function. Signed-off-by: Christian Schoenebeck Message-Id: Signed-off-by: Christian Schoenebeck --- tests/qtest/virtio-9p-test.c | 139 +++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index af7e169d3a..c15908f27b 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -18,6 +18,62 @@ #define QVIRTIO_9P_TIMEOUT_US (10 * 1000 * 1000) static QGuestAllocator *alloc; =20 +/* + * Used to auto generate new fids. Start with arbitrary high value to avoid + * collision with hard coded fids in basic test code. + */ +static uint32_t fid_generator =3D 1000; + +static uint32_t genfid(void) +{ + return fid_generator++; +} + +/** + * Splits the @a in string by @a delim into individual (non empty) strings + * and outputs them to @a out. The output array @a out is NULL terminated. + * + * Output array @a out must be freed by calling split_free(). + * + * @returns number of individual elements in output array @a out (without = the + * final NULL terminating element) + */ +static int split(const char *in, const char *delim, char ***out) +{ + int n =3D 0, i =3D 0; + char *tmp, *p; + + tmp =3D g_strdup(in); + for (p =3D strtok(tmp, delim); p !=3D NULL; p =3D strtok(NULL, delim))= { + if (strlen(p) > 0) { + ++n; + } + } + g_free(tmp); + + *out =3D g_new0(char *, n + 1); /* last element NULL delimiter */ + + tmp =3D g_strdup(in); + for (p =3D strtok(tmp, delim); p !=3D NULL; p =3D strtok(NULL, delim))= { + if (strlen(p) > 0) { + (*out)[i++] =3D g_strdup(p); + } + } + g_free(tmp); + + return n; +} + +static void split_free(char ***out) +{ + int i; + for (i =3D 0; (*out)[i]; ++i) { + g_free((*out)[i]); + } + g_free(*out); + *out =3D NULL; +} + static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc) { QVirtio9P *v9p =3D obj; @@ -201,6 +257,7 @@ static const char *rmessage_name(uint8_t id) id =3D=3D P9_RWALK ? "RWALK" : id =3D=3D P9_RLOPEN ? "RLOPEN" : id =3D=3D P9_RWRITE ? "RWRITE" : + id =3D=3D P9_RMKDIR ? "RMKDIR" : id =3D=3D P9_RFLUSH ? "RFLUSH" : id =3D=3D P9_RREADDIR ? "READDIR" : ""; @@ -578,6 +635,39 @@ static bool fs_dirents_contain_name(struct V9fsDirent = *e, const char* name) return false; } =20 +/* size[4] Tmkdir tag[2] dfid[4] name[s] mode[4] gid[4] */ +static P9Req *v9fs_tmkdir(QVirtio9P *v9p, uint32_t dfid, const char *name, + uint32_t mode, uint32_t gid, uint16_t tag) +{ + P9Req *req; + + uint32_t body_size =3D 4 + 4 + 4; + uint16_t string_size =3D v9fs_string_size(name); + + g_assert_cmpint(body_size, <=3D, UINT32_MAX - string_size); + body_size +=3D string_size; + + req =3D v9fs_req_init(v9p, body_size, P9_TMKDIR, tag); + v9fs_uint32_write(req, dfid); + v9fs_string_write(req, name); + v9fs_uint32_write(req, mode); + v9fs_uint32_write(req, gid); + v9fs_req_send(req); + return req; +} + +/* size[4] Rmkdir tag[2] qid[13] */ +static void v9fs_rmkdir(P9Req *req, v9fs_qid *qid) +{ + v9fs_req_recv(req, P9_RMKDIR); + if (qid) { + v9fs_memread(req, qid, 13); + } else { + v9fs_memskip(req, 13); + } + v9fs_req_free(req); +} + /* basic readdir test where reply fits into a single response message */ static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc) { @@ -877,6 +967,30 @@ static void fs_flush_ignored(void *obj, void *data, QG= uestAllocator *t_alloc) g_free(wnames[0]); } =20 +static void fs_mkdir(void *obj, void *data, QGuestAllocator *t_alloc, + const char *path, const char *cname) +{ + QVirtio9P *v9p =3D obj; + alloc =3D t_alloc; + char **wnames; + char *const name =3D g_strdup(cname); + P9Req *req; + const uint32_t fid =3D genfid(); + + int nwnames =3D split(path, "/", &wnames); + + req =3D v9fs_twalk(v9p, 0, fid, nwnames, wnames, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rwalk(req, NULL, NULL); + + req =3D v9fs_tmkdir(v9p, fid, name, 0750, 0, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rmkdir(req, NULL); + + g_free(name); + split_free(&wnames); +} + static void fs_readdir_split_128(void *obj, void *data, QGuestAllocator *t_alloc) { @@ -895,6 +1009,30 @@ static void fs_readdir_split_512(void *obj, void *dat= a, fs_readdir_split(obj, data, t_alloc, 512); } =20 + +/* tests using the 9pfs 'local' fs driver */ + +static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc) +{ + QVirtio9P *v9p =3D obj; + struct stat st; + char *root_path =3D virtio_9p_test_path(""); + char *new_dir =3D virtio_9p_test_path("01"); + + g_assert(root_path !=3D NULL); + + fs_attach(v9p, NULL, t_alloc); + fs_mkdir(v9p, data, t_alloc, "/", "01"); + + /* check if created directory really exists now ... */ + g_assert(stat(new_dir, &st) =3D=3D 0); + /* ... and is actually a directory */ + g_assert((st.st_mode & S_IFMT) =3D=3D S_IFDIR); + + g_free(new_dir); + g_free(root_path); +} + static void *assign_9p_local_driver(GString *cmd_line, void *arg) { virtio_9p_assign_local_driver(cmd_line, "security_model=3Dmapped-xattr= "); @@ -934,6 +1072,7 @@ static void register_virtio_9p_test(void) /* 9pfs test cases using the 'local' filesystem driver */ opts.before =3D assign_9p_local_driver; qos_add_test("local/config", "virtio-9p", pci_config, &opts); + qos_add_test("local/create_dir", "virtio-9p", fs_create_dir, &opts); } =20 libqos_init(register_virtio_9p_test); --=20 2.20.1