From nobody Thu Nov 6 06:18:24 2025 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.zoho.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 1493286481647778.2644975559227; Thu, 27 Apr 2017 02:48:01 -0700 (PDT) Received: from localhost ([::1]:59693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3g1o-0006LN-BR for importer@patchew.org; Thu, 27 Apr 2017 05:48:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3g04-0004mG-Ob for qemu-devel@nongnu.org; Thu, 27 Apr 2017 05:46:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3fzx-00014V-JI for qemu-devel@nongnu.org; Thu, 27 Apr 2017 05:46:09 -0400 Received: from 10.mo5.mail-out.ovh.net ([46.105.52.148]:54998) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d3fzx-00013k-DC for qemu-devel@nongnu.org; Thu, 27 Apr 2017 05:46:05 -0400 Received: from player786.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo5.mail-out.ovh.net (Postfix) with ESMTP id B019FEA135 for ; Thu, 27 Apr 2017 11:46:03 +0200 (CEST) Received: from [192.168.0.243] (gar31-1-82-66-74-139.fbx.proxad.net [82.66.74.139]) (Authenticated sender: groug@kaod.org) by player786.ha.ovh.net (Postfix) with ESMTPA id 7058B80096; Thu, 27 Apr 2017 11:46:00 +0200 (CEST) From: Greg Kurz To: qemu-devel@nongnu.org Date: Thu, 27 Apr 2017 11:46:00 +0200 Message-ID: <149328635990.30266.18017778280983307695.stgit@bahia> In-Reply-To: <149328633283.30266.4224847428546759127.stgit@bahia> References: <149328633283.30266.4224847428546759127.stgit@bahia> User-Agent: StGit/0.17.1-20-gc0b1b-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 13680528293085157809 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeeliedrgeeigddukecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.52.148 Subject: [Qemu-devel] [PATCH v2 3/4] virtio-9p: factor out virtio_9p_error_err() 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: Stefano Stabellini , Greg Kurz , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 When an unrecoverable is hit, we need to set the broken flag of the virtio device, detach the queue element and free it. This is currently open coded in handle_9p_output(). It is fine since this is the only function that can set the broken flag. But if we want to be able to do this from other places, we must consolidate the logic in a helper. Signed-off-by: Greg Kurz -- v2: - rely on the existing virtio_error() API --- hw/9pfs/virtio-9p-device.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c index 3782f437029b..c71659823fdc 100644 --- a/hw/9pfs/virtio-9p-device.c +++ b/hw/9pfs/virtio-9p-device.c @@ -22,21 +22,32 @@ =20 static const struct V9fsTransport virtio_9p_transport; =20 +static void virtio_9p_free_element(V9fsVirtioState *v, unsigned int idx) +{ + VirtQueueElement **pelem =3D &v->elems[idx]; + g_free(*pelem); + *pelem =3D NULL; +} + static void virtio_9p_push_and_notify(V9fsPDU *pdu) { V9fsState *s =3D pdu->s; V9fsVirtioState *v =3D container_of(s, V9fsVirtioState, state); - VirtQueueElement *elem =3D v->elems[pdu->idx]; =20 /* push onto queue and notify */ - virtqueue_push(v->vq, elem, pdu->size); - g_free(elem); - v->elems[pdu->idx] =3D NULL; + virtqueue_push(v->vq, v->elems[pdu->idx], pdu->size); + virtio_9p_free_element(v, pdu->idx); =20 /* FIXME: we should batch these completions */ virtio_notify(VIRTIO_DEVICE(v), v->vq); } =20 +#define virtio_9p_error(v, idx, ...) { \ + virtio_error(VIRTIO_DEVICE(v), ## __VA_ARGS__); \ + virtqueue_detach_element(v->vq, v->elems[idx], 0); \ + virtio_9p_free_element(v, idx); \ +} + static void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq) { V9fsVirtioState *v =3D (V9fsVirtioState *)vdev; @@ -52,22 +63,19 @@ static void handle_9p_output(VirtIODevice *vdev, VirtQu= eue *vq) if (!elem) { goto out_free_pdu; } + v->elems[pdu->idx] =3D elem; =20 if (elem->in_num =3D=3D 0) { - virtio_error(vdev, - "The guest sent a VirtFS request without space fo= r " - "the reply"); - goto out_free_req; + virtio_9p_error(v, pdu->idx, "The guest sent a VirtFS request = without space for the reply"); + goto out_free_pdu; } QEMU_BUILD_BUG_ON(sizeof(out) !=3D 7); =20 - v->elems[pdu->idx] =3D elem; len =3D iov_to_buf(elem->out_sg, elem->out_num, 0, &out, sizeof(out)); if (len !=3D sizeof(out)) { - virtio_error(vdev, "The guest sent a malformed VirtFS request:= " - "header size is %zd, should be 7", len); - goto out_free_req; + virtio_9p_error(v, pdu->idx, "The guest sent a malformed VirtF= S request: header size is %zd, should be 7", len); + goto out_free_pdu; } =20 pdu->size =3D le32_to_cpu(out.size_le); @@ -81,9 +89,6 @@ static void handle_9p_output(VirtIODevice *vdev, VirtQueu= e *vq) =20 return; =20 -out_free_req: - virtqueue_detach_element(vq, elem, 0); - g_free(elem); out_free_pdu: pdu_free(pdu); }