From nobody Wed Feb 11 08:38:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151733453331833.93488126631246; Tue, 30 Jan 2018 09:48:53 -0800 (PST) Received: from localhost ([::1]:51357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ega1c-0007AH-H7 for importer@patchew.org; Tue, 30 Jan 2018 12:48:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52432) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egZt4-0008Kg-KB for qemu-devel@nongnu.org; Tue, 30 Jan 2018 12:40:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1egZt0-0004OQ-Hi for qemu-devel@nongnu.org; Tue, 30 Jan 2018 12:40:02 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:33110 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1egZt0-0004CV-B7 for qemu-devel@nongnu.org; Tue, 30 Jan 2018 12:39:58 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0UHdjRS046144 for ; Tue, 30 Jan 2018 12:39:49 -0500 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0b-001b2d01.pphosted.com with ESMTP id 2fttvc7n3m-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 30 Jan 2018 12:39:48 -0500 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 30 Jan 2018 17:39:46 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 30 Jan 2018 17:39:42 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w0UHdgvi43319390; Tue, 30 Jan 2018 17:39:42 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 535FCAE053; Tue, 30 Jan 2018 17:31:08 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 37A84AE045; Tue, 30 Jan 2018 17:31:08 +0000 (GMT) Received: from smtp.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.1]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 30 Jan 2018 17:31:08 +0000 (GMT) Received: from bahia.lab.toulouse-stg.fr.ibm.com (bahia.lab.toulouse-stg.fr.ibm.com [9.101.4.41]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id DC76F22048B; Tue, 30 Jan 2018 18:39:40 +0100 (CET) From: Greg Kurz To: qemu-devel@nongnu.org Date: Tue, 30 Jan 2018 18:39:34 +0100 X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180130173935.5172-1-groug@kaod.org> References: <20180130173935.5172-1-groug@kaod.org> X-TM-AS-GCONF: 00 x-cbid: 18013017-0020-0000-0000-000003F07136 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18013017-0021-0000-0000-00004282D30A Message-Id: <20180130173935.5172-10-groug@kaod.org> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-30_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801300218 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL 09/10] tests: virtio-9p: add FLUSH operation test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The idea is to send a victim request that will possibly block in the server and to send a flush request to cancel the victim request. This patch adds two test to verifiy that: - the server does not reply to a victim request that was actually cancelled - the server replies to the flush request after replying to the victim request if it could not cancel it 9p request cancellation reference: http://man.cat-v.org/plan_9/5/flush Signed-off-by: Greg Kurz Reviewed-by: Stefan Hajnoczi --- hw/9pfs/9p-synth.c | 24 ++++++++++ hw/9pfs/9p-synth.h | 5 +++ hw/9pfs/9p.c | 1 + tests/virtio-9p-test.c | 117 +++++++++++++++++++++++++++++++++++++++++++--= ---- 4 files changed, 134 insertions(+), 13 deletions(-) diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c index f2d59a90a670..0a9940dfa23c 100644 --- a/hw/9pfs/9p-synth.c +++ b/hw/9pfs/9p-synth.c @@ -521,6 +521,24 @@ static ssize_t v9fs_synth_qtest_write(void *buf, int l= en, off_t offset, return len; } =20 +static ssize_t v9fs_synth_qtest_flush_write(void *buf, int len, off_t offs= et, + void *arg) +{ + QtestV9fsSynthFlushData *data =3D buf; + + assert(len =3D=3D sizeof(*data)); + + if (data->usec_timeout) { + usleep(data->usec_timeout); + + /* This will cause the server to call us again until we're cancell= ed */ + errno =3D EINTR; + return -1; + } + + return len; +} + static int synth_init(FsContext *ctx, Error **errp) { QLIST_INIT(&synth_root.child); @@ -557,6 +575,12 @@ static int synth_init(FsContext *ctx, Error **errp) ret =3D qemu_v9fs_synth_add_file(NULL, 0, QTEST_V9FS_SYNTH_WRITE_F= ILE, NULL, v9fs_synth_qtest_write, ctx); assert(!ret); + + /* File for FLUSH test */ + ret =3D qemu_v9fs_synth_add_file(NULL, 0, QTEST_V9FS_SYNTH_FLUSH_F= ILE, + NULL, v9fs_synth_qtest_flush_write, + ctx); + assert(!ret); } =20 return 0; diff --git a/hw/9pfs/9p-synth.h b/hw/9pfs/9p-synth.h index a74032d7bd9a..502ec6309a36 100644 --- a/hw/9pfs/9p-synth.h +++ b/hw/9pfs/9p-synth.h @@ -54,5 +54,10 @@ int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int = mode, #define QTEST_V9FS_SYNTH_WALK_FILE "WALK%d" #define QTEST_V9FS_SYNTH_LOPEN_FILE "LOPEN" #define QTEST_V9FS_SYNTH_WRITE_FILE "WRITE" +#define QTEST_V9FS_SYNTH_FLUSH_FILE "FLUSH" + +typedef struct { + uint32_t usec_timeout; +} QtestV9fsSynthFlushData; =20 #endif diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index e88bb50f1365..85a1ed8171a4 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -24,6 +24,7 @@ #include "coth.h" #include "trace.h" #include "migration/blocker.h" +#include "sysemu/qtest.h" =20 int open_fd_hw; int total_open_fd; diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c index cef21aea76c9..41fa492cb778 100644 --- a/tests/virtio-9p-test.c +++ b/tests/virtio-9p-test.c @@ -247,14 +247,15 @@ 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_RFLUSH ? "RFLUSH" : ""; } =20 -static void v9fs_req_wait_for_reply(P9Req *req) +static void v9fs_req_wait_for_reply(P9Req *req, uint32_t *len) { QVirtIO9P *v9p =3D req->v9p; =20 - qvirtio_wait_used_elem(v9p->dev, v9p->vq, req->free_head, NULL, + qvirtio_wait_used_elem(v9p->dev, v9p->vq, req->free_head, len, QVIRTIO_9P_TIMEOUT_US); } =20 @@ -454,6 +455,24 @@ static void v9fs_rwrite(P9Req *req, uint32_t *count) v9fs_req_free(req); } =20 +/* size[4] Tflush tag[2] oldtag[2] */ +static P9Req *v9fs_tflush(QVirtIO9P *v9p, uint16_t oldtag, uint16_t tag) +{ + P9Req *req; + + req =3D v9fs_req_init(v9p, 2, P9_TFLUSH, tag); + v9fs_uint32_write(req, oldtag); + v9fs_req_send(req); + return req; +} + +/* size[4] Rflush tag[2] */ +static void v9fs_rflush(P9Req *req) +{ + v9fs_req_recv(req, P9_RFLUSH); + v9fs_req_free(req); +} + static void fs_version(QVirtIO9P *v9p) { const char *version =3D "9P2000.L"; @@ -462,7 +481,7 @@ static void fs_version(QVirtIO9P *v9p) P9Req *req; =20 req =3D v9fs_tversion(v9p, P9_MAX_SIZE, version, P9_NOTAG); - v9fs_req_wait_for_reply(req); + v9fs_req_wait_for_reply(req, NULL); v9fs_rversion(req, &server_len, &server_version); =20 g_assert_cmpmem(server_version, server_len, version, strlen(version)); @@ -476,7 +495,7 @@ static void fs_attach(QVirtIO9P *v9p) =20 fs_version(v9p); req =3D v9fs_tattach(v9p, 0, getuid(), 0); - v9fs_req_wait_for_reply(req); + v9fs_req_wait_for_reply(req, NULL); v9fs_rattach(req, NULL); } =20 @@ -494,7 +513,7 @@ static void fs_walk(QVirtIO9P *v9p) =20 fs_attach(v9p); req =3D v9fs_twalk(v9p, 0, 1, P9_MAXWELEM, wnames, 0); - v9fs_req_wait_for_reply(req); + v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, &nwqid, &wqid); =20 g_assert_cmpint(nwqid, =3D=3D, P9_MAXWELEM); @@ -514,7 +533,7 @@ static void fs_walk_no_slash(QVirtIO9P *v9p) =20 fs_attach(v9p); req =3D v9fs_twalk(v9p, 0, 1, 1, wnames, 0); - v9fs_req_wait_for_reply(req); + v9fs_req_wait_for_reply(req, NULL); v9fs_rlerror(req, &err); =20 g_assert_cmpint(err, =3D=3D, ENOENT); @@ -530,11 +549,11 @@ static void fs_walk_dotdot(QVirtIO9P *v9p) =20 fs_version(v9p); req =3D v9fs_tattach(v9p, 0, getuid(), 0); - v9fs_req_wait_for_reply(req); + v9fs_req_wait_for_reply(req, NULL); v9fs_rattach(req, &root_qid); =20 req =3D v9fs_twalk(v9p, 0, 1, 1, wnames, 0); - v9fs_req_wait_for_reply(req); + v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, NULL, &wqid); /* We now we'll get one qid */ =20 g_assert_cmpmem(&root_qid, 13, wqid[0], 13); @@ -550,11 +569,11 @@ static void fs_lopen(QVirtIO9P *v9p) =20 fs_attach(v9p); req =3D v9fs_twalk(v9p, 0, 1, 1, wnames, 0); - v9fs_req_wait_for_reply(req); + v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, NULL, NULL); =20 req =3D v9fs_tlopen(v9p, 1, O_WRONLY, 0); - v9fs_req_wait_for_reply(req); + v9fs_req_wait_for_reply(req, NULL); v9fs_rlopen(req, NULL, NULL); =20 g_free(wnames[0]); @@ -570,21 +589,91 @@ static void fs_write(QVirtIO9P *v9p) =20 fs_attach(v9p); req =3D v9fs_twalk(v9p, 0, 1, 1, wnames, 0); - v9fs_req_wait_for_reply(req); + v9fs_req_wait_for_reply(req, NULL); v9fs_rwalk(req, NULL, NULL); =20 req =3D v9fs_tlopen(v9p, 1, O_WRONLY, 0); - v9fs_req_wait_for_reply(req); + v9fs_req_wait_for_reply(req, NULL); v9fs_rlopen(req, NULL, NULL); =20 req =3D v9fs_twrite(v9p, 1, 0, write_count, buf, 0); - v9fs_req_wait_for_reply(req); + v9fs_req_wait_for_reply(req, NULL); v9fs_rwrite(req, &count); g_assert_cmpint(count, =3D=3D, write_count); =20 g_free(wnames[0]); } =20 +static void fs_flush_success(QVirtIO9P *v9p) +{ + char *const wnames[] =3D { g_strdup(QTEST_V9FS_SYNTH_FLUSH_FILE) }; + QtestV9fsSynthFlushData data; + P9Req *req, *flush_req; + uint32_t reply_len; + + fs_attach(v9p); + req =3D v9fs_twalk(v9p, 0, 1, 1, wnames, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rwalk(req, NULL, NULL); + + req =3D v9fs_tlopen(v9p, 1, O_WRONLY, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rlopen(req, NULL, NULL); + + /* This will cause the 9p server to try to write data to the backend, + * until the write request gets cancelled. + */ + data.usec_timeout =3D 10; + req =3D v9fs_twrite(v9p, 1, 0, sizeof(data), &data, 0); + + flush_req =3D v9fs_tflush(v9p, req->tag, 1); + + /* The write request is supposed to be flushed: the server should just + * mark the write request as used and reply to the flush request. + */ + v9fs_req_wait_for_reply(req, &reply_len); + g_assert_cmpint(reply_len, =3D=3D, 0); + v9fs_req_free(req); + v9fs_rflush(flush_req); + + g_free(wnames[0]); +} + +static void fs_flush_ignored(QVirtIO9P *v9p) +{ + char *const wnames[] =3D { g_strdup(QTEST_V9FS_SYNTH_FLUSH_FILE) }; + QtestV9fsSynthFlushData data; + P9Req *req, *flush_req; + uint32_t count; + + fs_attach(v9p); + req =3D v9fs_twalk(v9p, 0, 1, 1, wnames, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rwalk(req, NULL, NULL); + + req =3D v9fs_tlopen(v9p, 1, O_WRONLY, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rlopen(req, NULL, NULL); + + /* This will cause the write request to complete right away, before it + * could be actually cancelled. + */ + data.usec_timeout =3D 0; + req =3D v9fs_twrite(v9p, 1, 0, sizeof(data), &data, 0); + + flush_req =3D v9fs_tflush(v9p, req->tag, 1); + + /* The write request is supposed to complete. The server should + * reply to the write request and the flush request. + */ + v9fs_req_wait_for_reply(req, NULL); + v9fs_rwrite(req, &count); + g_assert_cmpint(count, =3D=3D, sizeof(data)); + v9fs_rflush(flush_req); + + g_free(wnames[0]); +} + typedef void (*v9fs_test_fn)(QVirtIO9P *v9p); =20 static void v9fs_run_pci_test(gconstpointer data) @@ -616,6 +705,8 @@ int main(int argc, char **argv) fs_walk_dotdot); v9fs_qtest_pci_add("/virtio/9p/pci/fs/lopen/basic", fs_lopen); v9fs_qtest_pci_add("/virtio/9p/pci/fs/write/basic", fs_write); + v9fs_qtest_pci_add("/virtio/9p/pci/fs/flush/success", fs_flush_success= ); + v9fs_qtest_pci_add("/virtio/9p/pci/fs/flush/ignored", fs_flush_ignored= ); =20 return g_test_run(); } --=20 2.13.6