From patchwork Thu Dec 8 18:52:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 130212 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3E0151007D1 for ; Fri, 9 Dec 2011 05:53:28 +1100 (EST) Received: from localhost ([::1]:42944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYj5m-00089F-So for incoming@patchwork.ozlabs.org; Thu, 08 Dec 2011 13:53:14 -0500 Received: from eggs.gnu.org ([140.186.70.92]:47341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYj5h-00089A-8Y for qemu-devel@nongnu.org; Thu, 08 Dec 2011 13:53:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RYj5g-0006Aa-6F for qemu-devel@nongnu.org; Thu, 08 Dec 2011 13:53:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:64615) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYj5f-0006AM-EF for qemu-devel@nongnu.org; Thu, 08 Dec 2011 13:53:08 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pB8Ir2kJ016454 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 8 Dec 2011 13:53:02 -0500 Received: from doriath (ovpn-113-162.phx2.redhat.com [10.3.113.162]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pB8Iqx7L004516; Thu, 8 Dec 2011 13:53:00 -0500 Date: Thu, 8 Dec 2011 16:52:58 -0200 From: Luiz Capitulino To: qemu-devel Message-ID: <20111208165258.17ab95f7@doriath> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: Amit Shah , mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [RFC] qemu-ga: Introduce guest-hibernate command 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This is basically suspend to disk on a Linux guest. Signed-off-by: Luiz Capitulino --- This is an RFC because I did it as simple as possible and I'm open to suggestions... Now, while testing this or even "echo disk > /sys/power/state" I get several funny results. Some times qemu just dies after printing that message: "Guest moved used index from 20151 to 1" Some times it doesn't die, but I'm unable to log into the guest: I type username & password but the terminal kind of locks (the shell doesn't run). Some times it works... qapi-schema-guest.json | 11 +++++++++++ qga/guest-agent-commands.c | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/qapi-schema-guest.json b/qapi-schema-guest.json index fde5971..2c5bbcf 100644 --- a/qapi-schema-guest.json +++ b/qapi-schema-guest.json @@ -215,3 +215,14 @@ ## { 'command': 'guest-fsfreeze-thaw', 'returns': 'int' } + +## +# @guest-hibernate +# +# Save RAM contents to disk and powerdown the guest. +# +# Notes: This command doesn't return on success. +# +# Since: 1.1 +## +{ 'command': 'guest-hibernate' } diff --git a/qga/guest-agent-commands.c b/qga/guest-agent-commands.c index 6da9904..9dd4060 100644 --- a/qga/guest-agent-commands.c +++ b/qga/guest-agent-commands.c @@ -550,6 +550,25 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err) } #endif +#define LINUX_SYS_STATE_FILE "/sys/power/state" + +void qmp_guest_hibernate(Error **err) +{ + int fd; + + fd = open(LINUX_SYS_STATE_FILE, O_WRONLY); + if (fd < 0) { + error_set(err, QERR_OPEN_FILE_FAILED, LINUX_SYS_STATE_FILE); + return; + } + + if (write(fd, "disk", 4) < 0) { + error_set(err, QERR_UNDEFINED_ERROR); + } + + close(fd); +} + /* register init/cleanup routines for stateful command groups */ void ga_command_state_init(GAState *s, GACommandState *cs) {