From patchwork Thu Oct 25 14:06:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sameeh Jubran X-Patchwork-Id: 10655881 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B33E71751 for ; Thu, 25 Oct 2018 14:14:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FF8A2BBF9 for ; Thu, 25 Oct 2018 14:14:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 946502BC00; Thu, 25 Oct 2018 14:14:00 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 E0C992BBF9 for ; Thu, 25 Oct 2018 14:13:59 +0000 (UTC) Received: from localhost ([::1]:54807 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFgOc-0007PU-JR for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 10:13:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43623) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFgHe-0007qf-KK for qemu-devel@nongnu.org; Thu, 25 Oct 2018 10:06:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFgHa-0007dX-Fb for qemu-devel@nongnu.org; Thu, 25 Oct 2018 10:06:46 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:42511) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gFgHa-0007co-5E for qemu-devel@nongnu.org; Thu, 25 Oct 2018 10:06:42 -0400 Received: by mail-wr1-x442.google.com with SMTP id y15-v6so5091823wru.9 for ; Thu, 25 Oct 2018 07:06:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9cc4x47JLMycRuzxnF7i0QmqBwrdqiDPyxvmh5nB/K8=; b=scggIEaOG/9iwLBj/MkL7Ck9r/xzeeys7v/XlCP5EeXrXN7ie6ZD8j1JfdW/sPedkB xnR4PrIc0bk9q/4PKCmET7ePGkL53OPiLyQT47RaCJCxo0KcG0gsurxXNH7CNW19aImO aM2x2gt3TmdXDIYb0h1RrrY/vkNO91gvgWcscLtrHZrPtFqgmeZxYw79JkFBLLKEDnZ7 ApPlItYGoYyhiHGe2KP5oyqOYYvo3KukaaRYjOLvZ6xzXs7DvWngKJB2bkXlejIA/FAN 9FmIZRoftEa/9DH+7XKEQlRhE4ijo54qo4TwfcnyHSKDRZ6cz1THJnJTd1JdLwFQ6YWp P2tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9cc4x47JLMycRuzxnF7i0QmqBwrdqiDPyxvmh5nB/K8=; b=M9knsZ8bU9uXf5uJnUT4ib/fmn80u3o2Sh7V130OzZvjHjYxC6pcvmwBwjFMCEq7Pi pUqsbcGNS2KuXeta4mvkjrGAYiSaSaDVHKRs+dFegCbOoUUMd5YGUfpNSCOYARRFWbJO X20vfCq21xJzvJWP29CITwL4Yk4fhwoT+WaRMIk4M7Fvgmzfo34n5z3sC8w9KacfnkFH drTfjLi2Reyfg8TxKpPi2VAmrOY84UMcsjWob+BKRBFJ8zAfq6tnVWQRgCoG8XBIOIH9 piXEfzcrgW3Q/6nvOMVS9PVZs8c6xMbdxwmZBu7NkIbkri1EdzeDQq5qmb2JFKHWf1sF 1ssA== X-Gm-Message-State: AGRZ1gIYmZQXBtWdLjhIKd5OrJdC+thugF6yrUP3wNyiRvYGSrCSpx4A BQ2CQJZjrs0bOTo9Hr+PPEWJXIeX/wk1Ng== X-Google-Smtp-Source: AJdET5ex6+SejpuNBIuUUhfAGP48JXb3S4xqkBxnxC5rrjBRWVWq1yuCf7aDVbyaCCXcpqNbsFPwQg== X-Received: by 2002:adf:82c9:: with SMTP id 67-v6mr2020494wrc.131.1540476400708; Thu, 25 Oct 2018 07:06:40 -0700 (PDT) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id t194-v6sm2061842wmd.48.2018.10.25.07.06.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Oct 2018 07:06:40 -0700 (PDT) From: Sameeh Jubran To: qemu-devel@nongnu.org, Jason Wang Date: Thu, 25 Oct 2018 17:06:30 +0300 Message-Id: <20181025140631.634922-2-sameeh@daynix.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20181025140631.634922-1-sameeh@daynix.com> References: <20181025140631.634922-1-sameeh@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [RFC 1/2] qdev/qbus: Add hidden device support 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: Yan Vugenfirer , Eduardo Habkost , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Sameeh Jubran Signed-off-by: Sameeh Jubran --- hw/core/qdev.c | 48 +++++++++++++++++++++++++++++++--- hw/pci/pci.c | 1 + include/hw/pci/pci.h | 2 ++ include/hw/qdev-core.h | 11 +++++++- qdev-monitor.c | 58 +++++++++++++++++++++++++++++++++++++++--- 5 files changed, 112 insertions(+), 8 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 529b82de18..a7c063f6ae 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -77,16 +77,23 @@ static void bus_add_child(BusState *bus, DeviceState *child) kid->child = child; object_ref(OBJECT(kid->child)); - QTAILQ_INSERT_HEAD(&bus->children, kid, sibling); + if(child->hidden) + { + QTAILQ_INSERT_HEAD(&bus->hidden_children, kid, sibling); + } + else + { + QTAILQ_INSERT_HEAD(&bus->children, kid, sibling); - /* This transfers ownership of kid->child to the property. */ - snprintf(name, sizeof(name), "child[%d]", kid->index); - object_property_add_link(OBJECT(bus), name, + /* This transfers ownership of kid->child to the property. */ + snprintf(name, sizeof(name), "child[%d]", kid->index); + object_property_add_link(OBJECT(bus), name, object_get_typename(OBJECT(child)), (Object **)&kid->child, NULL, /* read-only property */ 0, /* return ownership on prop deletion */ NULL); + } } void qdev_set_parent_bus(DeviceState *dev, BusState *bus) @@ -104,12 +111,38 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus) } dev->parent_bus = bus; object_ref(OBJECT(bus)); + bus_add_child(bus, dev); + if (replugging) { object_unref(OBJECT(dev)); } } +void qdev_unhide(const char *dev_id, BusState *bus, Error **errp) +{ + BusChild *kid; + DeviceState *dev = NULL; + + QTAILQ_FOREACH(kid, &bus->hidden_children, sibling) { + if (!strcmp(kid->child->id,dev_id)) { + dev = kid->child; + break; + } + } + + if (dev && dev->hidden) + { + dev->hidden = false; + QTAILQ_REMOVE(&bus->hidden_children, kid, sibling); + qdev_set_parent_bus(dev, dev->parent_bus); + object_property_set_bool(OBJECT(dev), true, "realized", errp); + if (!errp) + hotplug_handler_plug(bus->hotplug_handler, dev, + errp); + } +} + /* Create a new device. This only initializes the device state structure and allows properties to be set. The device still needs to be realized. See qdev-core.h. */ @@ -208,6 +241,13 @@ void device_listener_unregister(DeviceListener *listener) QTAILQ_REMOVE(&device_listeners, listener, link); } +bool qdev_should_hide_device(const char *dev_id, BusState *bus) +{ + bool res; + DEVICE_LISTENER_CALL(should_be_hidden, Forward, dev_id, bus, &res); + return res; +} + void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, int required_for_version) { diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 80bc45930d..054c22be1e 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -70,6 +70,7 @@ static Property pci_props[] = { QEMU_PCIE_LNKSTA_DLLLA_BITNR, true), DEFINE_PROP_BIT("x-pcie-extcap-init", PCIDevice, cap_present, QEMU_PCIE_EXTCAP_INIT_BITNR, true), + DEFINE_PROP_STRING("standby", PCIDevice, standby_id_str), DEFINE_PROP_END_OF_LIST() }; diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 990d6fcbde..8c0c3e9ef7 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -351,6 +351,8 @@ struct PCIDevice { MSIVectorUseNotifier msix_vector_use_notifier; MSIVectorReleaseNotifier msix_vector_release_notifier; MSIVectorPollNotifier msix_vector_poll_notifier; + + char *standby_id_str; }; void pci_register_bar(PCIDevice *pci_dev, int region_num, diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index f1fd0f8736..dedb84e539 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -143,6 +143,7 @@ struct DeviceState { char *canonical_path; bool realized; bool pending_deleted_event; + bool hidden; QemuOpts *opts; int hotplugged; BusState *parent_bus; @@ -156,6 +157,11 @@ struct DeviceState { struct DeviceListener { void (*realize)(DeviceListener *listener, DeviceState *dev); void (*unrealize)(DeviceListener *listener, DeviceState *dev); + /* This callback is called just upon init of the DeviceState + * and can be used by a standby device for informing qdev if this + * device should be hidden by cross checking the ids + */ + void (*should_be_hidden)(DeviceListener *listener, const char *dev_id, BusState *bus, bool *res); QTAILQ_ENTRY(DeviceListener) link; }; @@ -206,6 +212,7 @@ struct BusState { int max_index; bool realized; QTAILQ_HEAD(ChildrenHead, BusChild) children; + QTAILQ_HEAD(HiddenChildrenHead, BusChild) hidden_children; QLIST_ENTRY(BusState) sibling; }; @@ -360,7 +367,7 @@ int qdev_walk_children(DeviceState *dev, void qdev_reset_all(DeviceState *dev); void qdev_reset_all_fn(void *opaque); - +void qdev_unhide(const char *dev_id, BusState *bus, Error **errp); /** * @qbus_reset_all: * @bus: Bus to be reset. @@ -434,4 +441,6 @@ static inline bool qbus_is_hotpluggable(BusState *bus) void device_listener_register(DeviceListener *listener); void device_listener_unregister(DeviceListener *listener); +bool qdev_should_hide_device(const char *dev_id, BusState *bus); + #endif diff --git a/qdev-monitor.c b/qdev-monitor.c index 61e0300991..e211b7b223 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -554,6 +554,49 @@ void qdev_set_id(DeviceState *dev, const char *id) } } +struct DeviceBusTuple +{ + DeviceState *dev; + BusState *bus; +} DeviceBusTuple; + +static int has_standby_device(void *opaque, const char *name, const char *value, + Error **errp) +{ + if (strcmp(name, "standby") == 0) + { + struct DeviceBusTuple *tuple = (struct DeviceBusTuple *)opaque; + const char *dev_id = (tuple->dev)->id; + BusState *bus = tuple->bus; + + if (qdev_should_hide_device(dev_id, bus)) + { + return 1; + } + else + { + error_setg(errp, "An error occurred: Please note that the primary device should be" + " must be placed after the standby device in the command line"); + return -1; + } + } + return 0; +} + +static bool should_hide_device(DeviceState *dev, QemuOpts *opts,BusState *bus, Error **err) +{ + struct DeviceBusTuple tuple; + tuple.dev = dev; + tuple.bus = bus; + + if (//!qemu_opt_get(opts, "vfio-pci") || + qemu_opt_foreach(opts, has_standby_device, &tuple, err) == 0) + { + return false; + } + return true; +} + DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) { DeviceClass *dc; @@ -607,6 +650,13 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) /* create device */ dev = DEVICE(object_new(driver)); + qdev_set_id(dev, qemu_opts_id(opts)); + + dev->hidden = should_hide_device(dev, opts, bus, &err); + if (err) + { + goto err_del_dev; + } if (bus) { qdev_set_parent_bus(dev, bus); } else if (qdev_hotplug && !qdev_get_machine_hotplug_handler(dev)) { @@ -616,15 +666,17 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) goto err_del_dev; } - qdev_set_id(dev, qemu_opts_id(opts)); - /* set properties */ if (qemu_opt_foreach(opts, set_property, dev, &err)) { goto err_del_dev; } dev->opts = opts; - object_property_set_bool(OBJECT(dev), true, "realized", &err); + if (!dev->hidden) + { + object_property_set_bool(OBJECT(dev), true, "realized", &err); + } + if (err != NULL) { dev->opts = NULL; goto err_del_dev; From patchwork Thu Oct 25 14:06:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sameeh Jubran X-Patchwork-Id: 10655873 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D10613A4 for ; Thu, 25 Oct 2018 14:08:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 076942BA54 for ; Thu, 25 Oct 2018 14:08:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAC072BA34; Thu, 25 Oct 2018 14:08:14 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 74FDF2BA34 for ; Thu, 25 Oct 2018 14:08:14 +0000 (UTC) Received: from localhost ([::1]:54713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFgJ3-0007rz-5F for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Oct 2018 10:08:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43603) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFgHd-0007pq-Md for qemu-devel@nongnu.org; Thu, 25 Oct 2018 10:06:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFgHb-0007dv-S8 for qemu-devel@nongnu.org; Thu, 25 Oct 2018 10:06:45 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:35093) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gFgHb-0007dj-KN for qemu-devel@nongnu.org; Thu, 25 Oct 2018 10:06:43 -0400 Received: by mail-wr1-x42e.google.com with SMTP id w5-v6so9485517wrt.2 for ; Thu, 25 Oct 2018 07:06:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=D+dl7//netDr19dT4IhCLcNc8iz3ooHFs7meEX+stv4=; b=iW68Cej5LkyHzuyk5unAR5QwsYg1bOzoZLoiRkhyhSI60aDsgn3QOic2E9vyRsU5Bn XgTQX+A7/lt/h6C/iG5nlrxm92LpvBRo+SRx84pgAz4Aw9ZqsLLoqSkuAysbBe7DeUmj lqGacTII97Jurz5WoNNk7BMDRxioa+XxSfQRKxFcZgpbpviH0fVWJN4Fy34CqMl5BFf3 aryvNNytGkB8lMVwY0pWO1blUSliZLBpouP/NidNgXiMOwLpk+feu2Y5eln+JdhAbjxE JWPF+T+EdbPzmwGlRdgbFN25FDrcqVlYOfAdAS/S2DwB0PhdBRTIZo9FzktO7nvEo4rW GsOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=D+dl7//netDr19dT4IhCLcNc8iz3ooHFs7meEX+stv4=; b=eElI85ohrdLY8p34f5ezy5RPzbnN4cp/hJUTH5AKkh4t57E/O5M0DFCBWbpaymMdHA RmJTYJ+fmGEn3w3+/BWWmZ4nP2kskI7T7TLbmRBIAvCRcxFose7X9LU7RFKVkk2oiTgJ lmrzTDk36rBFSDeE5teI5rKBGdwQzcUAvQO+O//jFFJShv6gpCQXNnPN/9GlzW20uJ5X M/0VN0bq+9g4TIwdzJGhJb78hXpoGSzOXYQPMo0JfFDPF2iSCONmtG1eFQ39EADcxmyk 4r1+T+/QrwCtf4RWmHMmjcFAoNy9+T9cPIN/jskQP8aACQT6SBXULZHJOW2wKYR59kY0 S9TA== X-Gm-Message-State: AGRZ1gLMNx3zvRL8d1Pe6WNL4PVnq2+2dlrl2/f/UFuoz19EEQLhvarf +VFFDXkba6IuaXOsRb8R9Wb/qYzw5tTKtg== X-Google-Smtp-Source: AJdET5eUbQs05yVgnUvA9xsQR3gXsc/Cbv4jc+IWED9vRFAfd6oYEtFXHaAL/kE65qXdFRdOhiNCJw== X-Received: by 2002:adf:fe4d:: with SMTP id m13-v6mr1991658wrs.71.1540476402264; Thu, 25 Oct 2018 07:06:42 -0700 (PDT) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id t194-v6sm2061842wmd.48.2018.10.25.07.06.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Oct 2018 07:06:41 -0700 (PDT) From: Sameeh Jubran To: qemu-devel@nongnu.org, Jason Wang Date: Thu, 25 Oct 2018 17:06:31 +0300 Message-Id: <20181025140631.634922-3-sameeh@daynix.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20181025140631.634922-1-sameeh@daynix.com> References: <20181025140631.634922-1-sameeh@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42e Subject: [Qemu-devel] [RFC 2/2] virtio-net: Implement VIRTIO_NET_F_STANDBY feature 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: Yan Vugenfirer , Eduardo Habkost , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Sameeh Jubran Signed-off-by: Sameeh Jubran --- hw/net/virtio-net.c | 25 +++++++++++++++++++++++++ include/hw/virtio/virtio-net.h | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index f154756e85..f478445cbd 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -686,6 +686,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) { VirtIONet *n = VIRTIO_NET(vdev); int i; + Error *err; if (n->mtu_bypass_backend && !virtio_has_feature(vdev->backend_features, VIRTIO_NET_F_MTU)) { @@ -721,6 +722,10 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) } else { memset(n->vlans, 0xff, MAX_VLAN >> 3); } + + if (virtio_has_feature(features, VIRTIO_NET_F_STANDBY)) { + qdev_unhide(n->net_conf.primary_id_str, n->primary_parent_bus, &err); + } } static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd, @@ -1946,6 +1951,20 @@ void virtio_net_set_netclient_name(VirtIONet *n, const char *name, n->netclient_type = g_strdup(type); } +static void virtio_net_primary_should_be_hidden(DeviceListener *listener,const char *dev_id, BusState *bus, bool *res) +{ + VirtIONet *n = container_of(listener, VirtIONet, primary_listener); + if (!strcmp(n->net_conf.primary_id_str ,dev_id) && bus) + { + printf("net_confnet_confnet_confnet_confnet_conf\n"); + n->host_features |= (1ULL << VIRTIO_NET_F_STANDBY); + n->primary_parent_bus = bus; + *res = true; + return; + } + *res = false; +} + static void virtio_net_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -1976,6 +1995,11 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) n->host_features |= (1ULL << VIRTIO_NET_F_SPEED_DUPLEX); } + if (n->net_conf.primary_id_str) { + n->primary_listener.should_be_hidden = virtio_net_primary_should_be_hidden; + device_listener_register(&n->primary_listener); + } + virtio_net_set_config_size(n, n->host_features); virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size); @@ -2198,6 +2222,7 @@ static Property virtio_net_properties[] = { true), DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed, SPEED_UNKNOWN), DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str), + DEFINE_PROP_STRING("primary", VirtIONet, net_conf.primary_id_str), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 4d7f3c82ca..6aca93e461 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -42,6 +42,7 @@ typedef struct virtio_net_conf int32_t speed; char *duplex_str; uint8_t duplex; + char *primary_id_str; } virtio_net_conf; /* Maximum packet size we can receive from tap device: header + 64k */ @@ -103,9 +104,13 @@ typedef struct VirtIONet { int announce_counter; bool needs_vnet_hdr_swap; bool mtu_bypass_backend; + BusState *primary_parent_bus; + DeviceListener primary_listener; } VirtIONet; void virtio_net_set_netclient_name(VirtIONet *n, const char *name, const char *type); +void virtio_net_register_primary_device(DeviceState *vdev, DeviceState *pdev); + #endif