From patchwork Sat Jun 4 21:33:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 9154987 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 953E760574 for ; Sat, 4 Jun 2016 21:47:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8353527F2B for ; Sat, 4 Jun 2016 21:47:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 739D228327; Sat, 4 Jun 2016 21:47:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E835227F2B for ; Sat, 4 Jun 2016 21:47:11 +0000 (UTC) Received: from localhost ([::1]:34267 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JPS-0001cu-FK for patchwork-qemu-devel@patchwork.kernel.org; Sat, 04 Jun 2016 17:47:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JCN-0005q9-Pe for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9JCL-0005lA-JE for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:38 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:36164) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JCL-0005k9-9A for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:37 -0400 Received: by mail-wm0-x244.google.com with SMTP id m124so6197538wme.3 for ; Sat, 04 Jun 2016 14:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mg/IdUMOu6ejhznC4WPgihpUXfBdyATwyg3cQpBYYIo=; b=w+itCnwf3S8RwPys6GmPcYY+sjNE+CPJp5sOdQyuDpV7eJwSfhOicsys/VAWAhMk6X 0bwT7LUU/cKTJP+7PS2ON2ywllfXqQYI4ijJQsASlFxkHen2mif9WeH3E593O4WOqDeK oz3YrlG10zj+FuTaq8P4qz3DjwouE70bqiDoudZpDyxGxm7JzsxFyEH/b+7Q2jriZIVD irczU1XhRN9G3BsT6oZEbei4qgaJJ/wJ1OcWbSRTOqzA3PU7gHm8If/FW9g0oL4Zyi49 GvrfGlW4HNYiWqQTpo8DuTfr6wV8lF8194ct4+c6LggYawW43gIFaQkNgDTw1NZRaQUs AKRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=mg/IdUMOu6ejhznC4WPgihpUXfBdyATwyg3cQpBYYIo=; b=m6Glwvvd+5UfDfpY7I6YJ0hnt2siRHFjLNZhRITBzQiJsZ9t/hLVC5MJ+v7jZNcNek zAra9oBfRE41A2FM/ON43EkaaNOLammzf0wFGRW1CNvIbbQiGnfTs68e8Y5Uyrhb3qAu wQOpVQprLQExttRImNHr9Kt0tmyylqHAC0PwKaeDFX0QWb52wtYR5GcjUhboFhcK7TFH Ts/J9OcK92CWYGCX+Hu7YQbR2VKx9VoxQXHgikyWnCdB6084aFzuUu3Nc09UkyZHubzL T50TDBQXpfT/oumo27nQJ67pIXlSkxduXRr58me+ae7V/Xs/3SaOX0cmbU11WTF75Nwu dzYQ== X-Gm-Message-State: ALyK8tIIe0fzufwIWYGFFLGCbtPddo0RsbYFTXsfuGNTYCEKVY9+weCA1+4NNEw5EnTPdg== X-Received: by 10.28.168.71 with SMTP id r68mr4813502wme.44.1465076016155; Sat, 04 Jun 2016 14:33:36 -0700 (PDT) Received: from localhost (APoitiers-110-1-1-235.w193-248.abo.wanadoo.fr. [193.248.103.235]) by smtp.gmail.com with ESMTPSA id y3sm12346629wji.40.2016.06.04.14.33.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Jun 2016 14:33:35 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Sat, 4 Jun 2016 23:33:13 +0200 Message-Id: <1465076003-26291-5-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1465076003-26291-1-git-send-email-marcandre.lureau@redhat.com> References: <1465076003-26291-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [RFC 04/14] vhost-user: add vhost_user_input_get_config() 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , kraxel@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau Signed-off-by: Marc-André Lureau --- docs/specs/vhost-user.txt | 9 ++++++ hw/virtio/vhost-user.c | 58 +++++++++++++++++++++++++++++++++++++++ include/hw/virtio/vhost-backend.h | 4 +++ 3 files changed, 71 insertions(+) diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt index 777c49c..fab67a5 100644 --- a/docs/specs/vhost-user.txt +++ b/docs/specs/vhost-user.txt @@ -464,3 +464,12 @@ Message types is present in VHOST_USER_GET_PROTOCOL_FEATURES. The first 6 bytes of the payload contain the mac address of the guest to allow the vhost user backend to construct and broadcast the fake RARP. + + * VHOST_USER_INPUT_GET_CONFIG + + Id: 20 + Equivalent ioctl: N/A + Master payload: N/A + Slave payload: (struct virtio_input_config)* + + Ask vhost user input backend the list of virtio_input_config. diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 63ffe48..8072c16 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -58,6 +58,7 @@ typedef enum VhostUserRequest { VHOST_USER_GET_QUEUE_NUM = 17, VHOST_USER_SET_VRING_ENABLE = 18, VHOST_USER_SEND_RARP = 19, + VHOST_USER_INPUT_GET_CONFIG = 20, VHOST_USER_MAX } VhostUserRequest; @@ -205,6 +206,63 @@ static int vhost_user_write(struct vhost_dev *dev, VhostUserMsg *msg, 0 : -1; } +static void *vhost_user_read_size(struct vhost_dev *dev, uint32_t size) +{ + CharDriverState *chr = dev->opaque; + int r; + uint8_t *p = g_malloc(size); + + r = qemu_chr_fe_read_all(chr, p, size); + if (r != size) { + error_report("Failed to read msg payload." + " Read %d instead of %d.", r, size); + return NULL; + } + + return p; +} + +int vhost_user_input_get_config(struct vhost_dev *dev, + struct virtio_input_config **config) +{ + void *p = NULL; + VhostUserMsg msg = { + .request = VHOST_USER_INPUT_GET_CONFIG, + .flags = VHOST_USER_VERSION, + }; + + if (vhost_user_write(dev, &msg, NULL, 0) < 0) { + goto err; + } + + if (vhost_user_read_header(dev, &msg) < 0) { + goto err; + } + + p = vhost_user_read_size(dev, msg.size); + if (!p) { + goto err; + } + + if (msg.request != VHOST_USER_INPUT_GET_CONFIG) { + error_report("Received unexpected msg type. Expected %d received %d", + VHOST_USER_INPUT_GET_CONFIG, msg.request); + goto err; + } + + if (msg.size % sizeof(struct virtio_input_config)) { + error_report("Invalid msg size"); + goto err; + } + + *config = p; + return msg.size / sizeof(struct virtio_input_config); + +err: + g_free(p); + return -1; +} + static int vhost_user_set_log_base(struct vhost_dev *dev, uint64_t base, struct vhost_log *log) { diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h index 95fcc96..08d34db 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -11,6 +11,7 @@ #ifndef VHOST_BACKEND_H_ #define VHOST_BACKEND_H_ +#include "standard-headers/linux/virtio_input.h" typedef enum VhostBackendType { VHOST_BACKEND_TYPE_NONE = 0, @@ -107,4 +108,7 @@ extern const VhostOps user_ops; int vhost_set_backend_type(struct vhost_dev *dev, VhostBackendType backend_type); +int vhost_user_input_get_config(struct vhost_dev *dev, + struct virtio_input_config **config); + #endif /* VHOST_BACKEND_H_ */