From patchwork Thu Jan 14 13:17:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 42882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3BD4BB7CBA for ; Fri, 15 Jan 2010 00:47:39 +1100 (EST) Received: from localhost ([127.0.0.1]:42264 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NVPey-0004fB-KG for incoming@patchwork.ozlabs.org; Thu, 14 Jan 2010 08:22:48 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NVPcG-0004Lo-H5 for qemu-devel@nongnu.org; Thu, 14 Jan 2010 08:20:00 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NVPcB-0004JU-LL for qemu-devel@nongnu.org; Thu, 14 Jan 2010 08:20:00 -0500 Received: from [199.232.76.173] (port=34997 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NVPcB-0004JP-E5 for qemu-devel@nongnu.org; Thu, 14 Jan 2010 08:19:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3228) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NVPbl-0005UN-A2 for qemu-devel@nongnu.org; Thu, 14 Jan 2010 08:19:55 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0EDJ3bR029645 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 14 Jan 2010 08:19:03 -0500 Received: from localhost (vpn-246-68.phx2.redhat.com [10.3.246.68]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0EDJ1FY016383; Thu, 14 Jan 2010 08:19:02 -0500 From: Amit Shah To: qemu-devel@nongnu.org Date: Thu, 14 Jan 2010 18:47:39 +0530 Message-Id: <1263475063-15238-5-git-send-email-amit.shah@redhat.com> In-Reply-To: <1263475063-15238-4-git-send-email-amit.shah@redhat.com> References: <1263475063-15238-1-git-send-email-amit.shah@redhat.com> <1263475063-15238-2-git-send-email-amit.shah@redhat.com> <1263475063-15238-3-git-send-email-amit.shah@redhat.com> <1263475063-15238-4-git-send-email-amit.shah@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Amit Shah Subject: [Qemu-devel] [PATCH 4/8] virtio-serial-bus: Add a port 'name' property for port discovery in guests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The port 'id' or number is internal state between the guest kernel and our bus implementation. This is invocation-dependent and isn't part of the guest-host ABI. To correcly enumerate and map ports between the host and the guest, the 'name' property is used. Example: -device virtserialport,name=org.qemu.port.0 This invocation will get us a char device in the guest at: /dev/virtio-ports/org.qemu.port.0 which can be a symlink to /dev/vport0p3 This 'name' property is exposed by the guest kernel in a sysfs attribute: /sys/kernel/virtio-ports/vport0p3/name A simple udev script can pick up this name and create the symlink mentioned above. Signed-off-by: Amit Shah --- hw/virtio-serial-bus.c | 17 +++++++++++++++++ hw/virtio-serial.c | 1 + hw/virtio-serial.h | 8 ++++++++ 3 files changed, 26 insertions(+), 0 deletions(-) diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c index 276de6a..2576140 100644 --- a/hw/virtio-serial-bus.c +++ b/hw/virtio-serial-bus.c @@ -226,6 +226,8 @@ static void handle_control_message(VirtIOSerial *vser, void *buf) { struct VirtIOSerialPort *port; struct virtio_console_control cpkt, *gcpkt; + uint8_t *buffer; + size_t buffer_len; gcpkt = buf; port = find_port_by_id(vser, ldl_p(&gcpkt->id)); @@ -248,6 +250,21 @@ static void handle_control_message(VirtIOSerial *vser, void *buf) send_control_event(port, VIRTIO_CONSOLE_CONSOLE_PORT, 1); } + if (port->name) { + stw_p(&cpkt.event, VIRTIO_CONSOLE_PORT_NAME); + stw_p(&cpkt.value, 1); + + buffer_len = sizeof(cpkt) + strlen(port->name) + 1; + buffer = qemu_malloc(buffer_len); + + memcpy(buffer, &cpkt, sizeof(cpkt)); + memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name)); + buffer[buffer_len - 1] = 0; + + send_control_msg(port, buffer, buffer_len); + qemu_free(buffer); + } + if (port->host_connected) { send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, 1); } diff --git a/hw/virtio-serial.c b/hw/virtio-serial.c index d9a6f32..470446b 100644 --- a/hw/virtio-serial.c +++ b/hw/virtio-serial.c @@ -102,6 +102,7 @@ static VirtIOSerialPortInfo virtconsole_info = { .qdev.props = (Property[]) { DEFINE_PROP_UINT8("is_console", VirtConsole, port.is_console, 1), DEFINE_PROP_CHR("chardev", VirtConsole, chr), + DEFINE_PROP_STRING("name", VirtConsole, port.name), DEFINE_PROP_END_OF_LIST(), }, }; diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h index 1576eef..b669c7f 100644 --- a/hw/virtio-serial.h +++ b/hw/virtio-serial.h @@ -54,6 +54,7 @@ struct virtio_console_header { #define VIRTIO_CONSOLE_CONSOLE_PORT 1 #define VIRTIO_CONSOLE_RESIZE 2 #define VIRTIO_CONSOLE_PORT_OPEN 3 +#define VIRTIO_CONSOLE_PORT_NAME 4 /* == In-qemu interface == */ @@ -88,6 +89,13 @@ struct VirtIOSerialPort { VirtQueue *ivq, *ovq; /* + * This name is sent to the guest and exported via sysfs. + * The guest could create symlinks based on this information. + * The name is in the reverse fqdn format, like org.qemu.console.0 + */ + char *name; + + /* * This id helps identify ports between the guest and the host. * The guest sends a "header" with this id with each data packet * that it sends and the host can then find out which associated