From patchwork Wed Dec 14 19:07:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9474539 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 C6FF560571 for ; Wed, 14 Dec 2016 19:13:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B305128626 for ; Wed, 14 Dec 2016 19:13:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A66B428688; Wed, 14 Dec 2016 19:13:04 +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 50F0F28626 for ; Wed, 14 Dec 2016 19:13:04 +0000 (UTC) Received: from localhost ([::1]:49708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cHEz9-0003Kx-Dr for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Dec 2016 14:13:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34720) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cHEvV-00072u-Az for qemu-devel@nongnu.org; Wed, 14 Dec 2016 14:09:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cHEvS-0001hc-5W for qemu-devel@nongnu.org; Wed, 14 Dec 2016 14:09:17 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36735) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cHEvR-0001fa-VR for qemu-devel@nongnu.org; Wed, 14 Dec 2016 14:09:14 -0500 Received: by mail-pg0-f67.google.com with SMTP id x23so3300823pgx.3 for ; Wed, 14 Dec 2016 11:08:51 -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=22pj8OtdFcr/PD0b7+mjaNrc529SGW9yr3tug1APg5k=; b=mQJ8vmdwyS7ejD6cvfApc2auK0S3brI5SrkyHHGb0iI/ZRr3qQC56Qs+tPIb1LFe1w Z/eKfQK/0+YpMdWqI7wzE5Iomby5SDTpQXA09Rrs7dYCeGFG+D5ISe5k3mmlbDK970hA KMIuWBZ8Ikeww+cOSJ8EERZ2WFBWLWWZRhFr6Ll76dDCoxhqYIYwhszM1uMfo4KZd50N J3cf9sGosfd+jZTdKjj+YvsY8eCsOABiAJgcDjQnAWyyptTpYLcaTxp0VIY5BLbEmcrr QCbE7x84qehLotzZRBlzJCzYfSxIwecXgYmQ3OZwr8ufv1tJw5+1+nfrScYmx785ErRd //1w== 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=22pj8OtdFcr/PD0b7+mjaNrc529SGW9yr3tug1APg5k=; b=Gd3SbArVvC32cmbkIR3XD0kbSXqrPT8CPy3bQ/mLxkBy+/YyKizeHi5NHTb4KvMSuN OEh4kHNMGo/XpGI6s6toRyByZYsziZYrxhkySDJN7J2xiWTrlCJJgwPQ/XupEY5Tr07c Jy+QoGgQBfopXkWJ4jw6GAEwNWqFl2kItEmPh+02P5jz4yl98WOG2DLHA7fh+qg7K1LT UlMod4r/7VsWxdn3MwR4VurQ/ckew6W0tXDoCbURjBhfcw8K/8FjsYu4Gyy0KDcrbT+j CWjrvhcn1xDYFYFHTi3Inn1HqcMbOR0+7qevnhFefqKaMf/Cchsyz86iyMJDwggAzOBy 14pg== X-Gm-Message-State: AKaTC02oGuRl6qMyxYAc1xaBqgzUQcSUYgrQRqsH6O4Ol6KtvIQcT4cVlEweONADmf+AuQ== X-Received: by 10.99.229.17 with SMTP id r17mr189051520pgh.149.1481742470476; Wed, 14 Dec 2016 11:07:50 -0800 (PST) Received: from linux.local ([47.247.128.14]) by smtp.gmail.com with ESMTPSA id p68sm89200075pfd.11.2016.12.14.11.07.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Dec 2016 11:07:50 -0800 (PST) From: Ashijeet Acharya To: dgilbert@redhat.com Date: Thu, 15 Dec 2016 00:37:01 +0530 Message-Id: <1481742422-15969-3-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1481742422-15969-1-git-send-email-ashijeetacharya@gmail.com> References: <1481742422-15969-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.83.67 Subject: [Qemu-devel] [PATCH 2/3] 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 | 15 +++++++++++++++ qdev-monitor.c | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/hw/usb/bus.c b/hw/usb/bus.c index 25913ad..8796788 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,18 @@ USBDevice *usbdevice_create(const char *cmdline) return NULL; } + klass = object_class_by_name(f->name); + + 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) {