From patchwork Fri Dec 16 09:53:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9477663 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 54B8C6047D for ; Fri, 16 Dec 2016 09:55:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B67928793 for ; Fri, 16 Dec 2016 09:55:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D0A82878E; Fri, 16 Dec 2016 09:55: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_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 EABD62878E for ; Fri, 16 Dec 2016 09:55:11 +0000 (UTC) Received: from localhost ([::1]:59430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cHpEN-00066t-3h for patchwork-qemu-devel@patchwork.kernel.org; Fri, 16 Dec 2016 04:55:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cHpDo-00062K-9m for qemu-devel@nongnu.org; Fri, 16 Dec 2016 04:54:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cHpDk-0003Hr-CY for qemu-devel@nongnu.org; Fri, 16 Dec 2016 04:54:36 -0500 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:34964) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cHpDk-0003HP-7g for qemu-devel@nongnu.org; Fri, 16 Dec 2016 04:54:32 -0500 Received: by mail-pg0-x241.google.com with SMTP id p66so9259370pga.2 for ; Fri, 16 Dec 2016 01:54:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=laLhOCdLzTkmQ9RGnaogRjZJq9TLUueIwyT7X3Bvhsg=; b=HhNogFmWQLSExqtkjHLI154SrHWaFs93ZnBvJaXNJMQP/1JA/9MFe03f5XpA0KJlnv DIut0wE9MgxuMa1Rm6K2v193ZjIkD4DZ/soZnt5+nXwsKCBxNchZwsyM2goSd7iOidGU pHiT2UfmTAQpx1/fbSNpyisBTCkWveQv/ZtAkvXqBoI9eBLGzJ7cBZKkEi0NWxVJKJxX e7/NQ4AP+wawCTuSOW+exVNXhyGr6z0wkdN4T6hAQNaACzxhClWqsORdCCJTkF4bYrWg KqxI5hfPg81ynnl+4CXD1qp2SSf17B3iKNHrHfHqz6Luj91i3/2J+7UxVq7KGbTFiaOP r2Jw== 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=laLhOCdLzTkmQ9RGnaogRjZJq9TLUueIwyT7X3Bvhsg=; b=VGe417zkMq/C7xV+bBH9JnJd+u6J3c2aZnOK8uJDXt7MU+08YR9KNLPJq7bAMT5WkQ MC/bbZKpnGf92qhfHgsgQ30eWZeP7KqsuPVaJqlg3ooc7mtRX+tXy5DyczxwJ8TqT2PK pomQmno5RYjk10gBSoO/gChi/KGeB+HLkpFztExlJzuvDJ9n6yMD2pyU1dvFUVbSnKZZ wpcG25fFtzP6Q1GKF351VIpRCzgc/j7wxsUj7y02HqbcE0lmUqbzuAK25thJ2KqrJVRq tQFyHrIKUOW2G2WZGs9ww52t59sf98TbChYA5nFva1xfJvVPgS9/FQIfrrnctVDs0FM3 DIag== X-Gm-Message-State: AKaTC03tpa+Vk4TsDpB4DfSlBMbvcHsh6+p3DiuNTtM9R0TNVSD2H3EJSfMUiz40S+xKJA== X-Received: by 10.99.125.24 with SMTP id y24mr4065881pgc.27.1481882071352; Fri, 16 Dec 2016 01:54:31 -0800 (PST) Received: from linux.local ([47.247.11.105]) by smtp.gmail.com with ESMTPSA id e11sm10619306pgp.10.2016.12.16.01.54.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Dec 2016 01:54:30 -0800 (PST) From: Ashijeet Acharya To: dgilbert@redhat.com Date: Fri, 16 Dec 2016 15:23:42 +0530 Message-Id: <1481882024-10016-3-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1481882024-10016-1-git-send-email-ashijeetacharya@gmail.com> References: <1481882024-10016-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::241 Subject: [Qemu-devel] [PATCH v2 2/4] migration: Allow "device add" options to only add migratable devices 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: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com, qemu-devel@nongnu.org, mst@redhat.com, armbru@redhat.com, groug@kaod.org, aneesh.kumar@linux.vnet.ibm.com, Ashijeet Acharya , marcandre.lureau@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Introduce checks for the unmigratable flag in the VMStateDescription structs of respective devices when user attempts to add them. If the "--only-migratable" was specified, all unmigratable devices will rightly fail to add. This feature is made compatible for both "-device" and "-usbdevice" command line options and covers their hmp and qmp counterparts as well. Signed-off-by: Ashijeet Acharya --- hw/usb/bus.c | 18 ++++++++++++++++++ qdev-monitor.c | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/hw/usb/bus.c b/hw/usb/bus.c index 25913ad..3d26103 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -8,6 +8,7 @@ #include "monitor/monitor.h" #include "trace.h" #include "qemu/cutils.h" +#include "migration/migration.h" static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); @@ -686,6 +687,8 @@ USBDevice *usbdevice_create(const char *cmdline) const char *params; int len; USBDevice *dev; + ObjectClass *klass; + DeviceClass *dc; params = strchr(cmdline,':'); if (params) { @@ -720,6 +723,21 @@ USBDevice *usbdevice_create(const char *cmdline) return NULL; } + klass = object_class_by_name(f->name); + if (klass == NULL) { + return NULL; + } + + dc = DEVICE_CLASS(klass); + + if (only_migratable) { + if (dc->vmsd->unmigratable) { + error_report("Device %s is not migratable, but --only-migratable " + "was specified", f->name); + return NULL; + } + } + if (f->usbdevice_init) { dev = f->usbdevice_init(bus, params); } else { diff --git a/qdev-monitor.c b/qdev-monitor.c index c73410c..81d01df 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -29,6 +29,7 @@ #include "qemu/error-report.h" #include "qemu/help_option.h" #include "sysemu/block-backend.h" +#include "migration/migration.h" /* * Aliases were a bad idea from the start. Let's keep them @@ -577,6 +578,14 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) return NULL; } + if (only_migratable) { + if (dc->vmsd->unmigratable) { + error_setg(errp, "Device %s is not migratable, but " + "--only-migratable was specified", driver); + return NULL; + } + } + /* find bus */ path = qemu_opt_get(opts, "bus"); if (path != NULL) {