From patchwork Wed Sep 10 19:15:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 37218 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F406920491 for ; Wed, 10 Sep 2014 19:17:58 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id kx10sf29516257pab.0 for ; Wed, 10 Sep 2014 12:17:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:in-reply-to:message-id :references:user-agent:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-type; bh=XHIjBi0YSR3Gz5c2vrdSt6JrWPcEF2IgpeJrI7Rm6GA=; b=U820bqtw374j+EnMQj0A6bwb6C5rt2H7+RJSvPmNyIddluhLjEPNbConMMfqy7sDkf BNHIoJ5r2Cvy8zOgAJsGan/U5EdUw/o+3NEX36Hdv1gUAc8EpJd3g26NNgZI4mSdYdhX oqWaqaYSwZieMprnWmBemJ2gUqsgF++oojAETBqzfOC3p7LpFU8RgFNePJDAVdKWBfir U7NQwH+uQ9ZGbuW8oykumi4z91upWKeBKOcc6ZfMUDhLrD/yMLTUkzt4TFif9T+sjm5L l+rMUdd8Qitb3JMK6HcnClaX1yyNnXXN/W/teTk+oW3KVfcNLYQ38+8CshQXkJMr0rr6 hwMg== X-Gm-Message-State: ALoCoQmjujtM0VRiG6lt5i95JORMJSWjAhI5gnI/+uW15uzBlZ3Oe9fn704dW9QVpgGiPIk+acYl X-Received: by 10.70.37.41 with SMTP id v9mr26617096pdj.0.1410376678309; Wed, 10 Sep 2014 12:17:58 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.39.69 with SMTP id u63ls1484334qgu.64.gmail; Wed, 10 Sep 2014 12:17:58 -0700 (PDT) X-Received: by 10.52.185.168 with SMTP id fd8mr7609073vdc.58.1410376678156; Wed, 10 Sep 2014 12:17:58 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id k9si4614375vdw.82.2014.09.10.12.17.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 10 Sep 2014 12:17:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id le20so5035088vcb.18 for ; Wed, 10 Sep 2014 12:17:58 -0700 (PDT) X-Received: by 10.52.231.65 with SMTP id te1mr1545131vdc.86.1410376678050; Wed, 10 Sep 2014 12:17:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp483272vcb; Wed, 10 Sep 2014 12:17:57 -0700 (PDT) X-Received: by 10.140.97.74 with SMTP id l68mr30170730qge.29.1410376677310; Wed, 10 Sep 2014 12:17:57 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d5si19820892qcc.2.2014.09.10.12.17.57 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 10 Sep 2014 12:17:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:58283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRnOu-0004XA-Lt for patch@linaro.org; Wed, 10 Sep 2014 15:17:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRnOK-0004Gk-1u for qemu-devel@nongnu.org; Wed, 10 Sep 2014 15:17:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XRnOE-0006Zg-0f for qemu-devel@nongnu.org; Wed, 10 Sep 2014 15:17:19 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:43099) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRnOD-0006Xw-Pv for qemu-devel@nongnu.org; Wed, 10 Sep 2014 15:17:13 -0400 X-IronPort-AV: E=Sophos;i="5.04,500,1406592000"; d="scan'208";a="171109454" Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.78) with Microsoft SMTP Server id 14.3.181.6; Wed, 10 Sep 2014 15:17:04 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1XRnO4-0004FZ-Dw; Wed, 10 Sep 2014 20:17:04 +0100 Date: Wed, 10 Sep 2014 20:15:18 +0100 From: Stefano Stabellini X-X-Sender: sstabellini@kaball.uk.xensource.com To: Wen Congyang In-Reply-To: <540E6A44.8090507@cn.fujitsu.com> Message-ID: References: <1409909158-19243-1-git-send-email-wency@cn.fujitsu.com> <1409909158-19243-24-git-send-email-wency@cn.fujitsu.com> <540E6A44.8090507@cn.fujitsu.com> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-DLP: MIA2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.63 Cc: Ian Campbell , Stefano Stabellini , Ian Jackson , Jiang Yunhong , Dong Eddie , qemu-devel@nongnu.org, xen devel , Paolo Bonzini , Yang Hongyang , Lai Jiangshan Subject: Re: [Qemu-devel] [Xen-devel] [RFC Patch v3 23/22] Introduce "xen-load-devices-state" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stefano.stabellini@eu.citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 On Tue, 9 Sep 2014, Wen Congyang wrote: > At 09/06/2014 05:57 AM, Stefano Stabellini Write: > > On Fri, 5 Sep 2014, Wen Congyang wrote: > >> introduce a "xen-load-devices-state" QAPI command that can be used to load > >> the state of all devices, but not the RAM or the block devices of the > >> VM. > > > > Hello Wen, > > please CC qemu-devel too for QEMU patches. > > > > Could you please explain why do you need this command? > > > > Is the main issue that there are no QMP commands today to load the state > > of a VM? It looks like that for vm restore we are using the -incoming > > command line option, but there is no alternative over QMP. > > We only have hmp commands savevm/loadvm, and qmp commands xen-save-devices-state. > > We use this new command for COLO: > 1. suspend both primay vm and secondary vm > 2. sync the state > 3. resume both primary vm and secondary vm > > In such case, we need to update all devices's state in any time. OK. Please state this in the commit message. > > [...] > > > > > >> diff --git a/savevm.c b/savevm.c > >> index 22123be..c6aa502 100644 > >> --- a/savevm.c > >> +++ b/savevm.c > >> @@ -863,6 +863,105 @@ out: > >> return ret; > >> } > >> > >> +static int qemu_load_devices_state(QEMUFile *f) > >> +{ > >> + uint8_t section_type; > >> + unsigned int v; > >> + int ret; > >> + > >> + if (qemu_savevm_state_blocked(NULL)) { > >> + return -EINVAL; > >> + } > >> + > >> + v = qemu_get_be32(f); > >> + if (v != QEMU_VM_FILE_MAGIC) { > >> + return -EINVAL; > >> + } > >> + > >> + v = qemu_get_be32(f); > >> + if (v == QEMU_VM_FILE_VERSION_COMPAT) { > >> + fprintf(stderr, "SaveVM v2 format is obsolete and don't work anymore\n"); > >> + return -ENOTSUP; > >> + } > >> + if (v != QEMU_VM_FILE_VERSION) { > >> + return -ENOTSUP; > >> + } > >> + > >> + while ((section_type = qemu_get_byte(f)) != QEMU_VM_EOF) { > >> + uint32_t instance_id, version_id, section_id; > >> + SaveStateEntry *se; > >> + char idstr[257]; > >> + int len; > >> + > >> + switch (section_type) { > >> + case QEMU_VM_SECTION_FULL: > >> + /* Read section start */ > >> + section_id = qemu_get_be32(f); > >> + len = qemu_get_byte(f); > >> + qemu_get_buffer(f, (uint8_t *)idstr, len); > >> + idstr[len] = 0; > >> + instance_id = qemu_get_be32(f); > >> + version_id = qemu_get_be32(f); > >> + > >> + /* Find savevm section */ > >> + se = find_se(idstr, instance_id); > >> + if (se == NULL) { > >> + fprintf(stderr, "Unknown savevm section or instance '%s' %d\n", > >> + idstr, instance_id); > >> + ret = -EINVAL; > >> + goto out; > >> + } > >> + > >> + /* Validate version */ > >> + if (version_id > se->version_id) { > >> + fprintf(stderr, "loadvm: unsupported version %d for '%s' v%d\n", > >> + version_id, idstr, se->version_id); > >> + ret = -EINVAL; > >> + goto out; > >> + } > >> + > >> + /* Validate if it is a device's state */ > >> + if (se->is_ram) { > >> + fprintf(stderr, "loadvm: %s is not devices state\n", idstr); > >> + ret = -EINVAL; > >> + goto out; > >> + } > >> + > >> + ret = vmstate_load(f, se, version_id); > >> + if (ret < 0) { > >> + fprintf(stderr, "qemu: warning: error while loading state for instance 0x%x of device '%s'\n", > >> + instance_id, idstr); > >> + goto out; > >> + } > >> + break; > >> + case QEMU_VM_SECTION_START: > >> + case QEMU_VM_SECTION_PART: > >> + case QEMU_VM_SECTION_END: > >> + /* > >> + * The file is saved by the command xen-save-devices-state, > >> + * So it should not contain section start/part/end. > >> + */ > >> + default: > >> + fprintf(stderr, "Unknown savevm section type %d\n", section_type); > >> + ret = -EINVAL; > >> + goto out; > >> + } > >> + } > >> + > >> + cpu_synchronize_all_post_init(); > >> + > >> + ret = 0; > >> + > >> +out: > >> + if (ret == 0) { > >> + if (qemu_file_get_error(f)) { > >> + ret = -EIO; > >> + } > >> + } > >> + > >> + return ret; > >> +} > > > > Assuming that the state file only contains device states, why don't you > > just call qemu_loadvm_state to implement the command? > > Do you mean there is no need to check the file? If the file contains > some memory, it will cause unexpected problem. I would prefer to avoid duplicating qemu_loadvm_state just to add an if (se->is_ram) check. I would rather introduce a generic loadvm QMP command and rely on the fact that we are saving only device states via xen-save-devices-state. Given that loading memory in QEMU on Xen always leads to errors, maybe we could still add a check in qemu_loadvm_state anyway. Something like: > Thanks > Wen Congyang > > > > > > > > >> static BlockDriverState *find_vmstate_bs(void) > >> { > >> BlockDriverState *bs = NULL; > >> @@ -1027,6 +1126,33 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp) > >> } > >> } > >> > >> +void qmp_xen_load_devices_state(const char *filename, Error **errp) > >> +{ > >> + QEMUFile *f; > >> + int saved_vm_running; > >> + int ret; > >> + > >> + saved_vm_running = runstate_is_running(); > >> + vm_stop(RUN_STATE_RESTORE_VM); > >> + > >> + f = qemu_fopen(filename, "rb"); > >> + if (!f) { > >> + error_setg_file_open(errp, errno, filename); > >> + goto out; > >> + } > >> + > >> + ret = qemu_load_devices_state(f); > >> + qemu_fclose(f); > >> + if (ret < 0) { > >> + error_set(errp, QERR_IO_ERROR); > >> + } > >> + > >> +out: > >> + if (saved_vm_running) { > >> + vm_start(); > >> + } > >> +} > >> + > >> int load_vmstate(const char *name) > >> { > >> BlockDriverState *bs, *bs_vm_state; > >> -- > >> 1.9.0 > >> > >> > >> _______________________________________________ > >> Xen-devel mailing list > >> Xen-devel@lists.xen.org > >> http://lists.xen.org/xen-devel > >> > > . > > > diff --git a/savevm.c b/savevm.c index e19ae0a..759eefa 100644 --- a/savevm.c +++ b/savevm.c @@ -938,6 +938,13 @@ int qemu_loadvm_state(QEMUFile *f) goto out; } + /* Validate if it is a device's state */ + if (xen_enabled() && se->is_ram) { + fprintf(stderr, "loadvm: %s RAM loading not allowed on Xen\n", idstr); + ret = -EINVAL; + goto out; + } + /* Add entry */ le = g_malloc0(sizeof(*le));