From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=32861 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PeowY-0006zv-Np for qemu-devel@nongnu.org; Mon, 17 Jan 2011 08:16:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PeowW-0006Gk-KJ for qemu-devel@nongnu.org; Mon, 17 Jan 2011 08:16:21 -0500 Received: from e9.ny.us.ibm.com ([32.97.182.139]:37396) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PeowW-0006Ge-Hn for qemu-devel@nongnu.org; Mon, 17 Jan 2011 08:16:20 -0500 Received: from d01dlp01.pok.ibm.com (d01dlp01.pok.ibm.com [9.56.224.56]) by e9.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p0HCq5c4019014 for ; Mon, 17 Jan 2011 07:52:05 -0500 Received: from d01relay07.pok.ibm.com (d01relay07.pok.ibm.com [9.56.227.147]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 6EC62728063 for ; Mon, 17 Jan 2011 08:16:19 -0500 (EST) Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay07.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p0HDGI9W2326674 for ; Mon, 17 Jan 2011 08:16:18 -0500 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p0HDGISO030828 for ; Mon, 17 Jan 2011 08:16:18 -0500 From: Michael Roth Date: Mon, 17 Jan 2011 07:15:06 -0600 Message-Id: <1295270117-24760-13-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1295270117-24760-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1295270117-24760-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [RFC][PATCH v6 12/23] virtagent: add va.shutdown RPC List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: agl@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com, Jes.Sorensen@redhat.com, marcel.mittelstaedt@de.ibm.com, mdroth@linux.vnet.ibm.com, markus_mueller@de.ibm.com, aliguori@linux.vnet.ibm.com, ryanh@us.ibm.com, abeekhof@redhat.com RPC to initiate guest reboot/halt/powerdown Signed-off-by: Michael Roth --- virtagent-server.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 58 insertions(+), 0 deletions(-) diff --git a/virtagent-server.c b/virtagent-server.c index f97e4b1..d48c61e 100644 --- a/virtagent-server.c +++ b/virtagent-server.c @@ -163,6 +163,62 @@ EXIT_NOCLOSE: return result; } +/* va_shutdown(): initiate guest shutdown + * rpc return values: none + */ +static xmlrpc_value *va_shutdown(xmlrpc_env *env, + xmlrpc_value *params, + void *user_data) +{ + int ret; + const char *shutdown_type, *shutdown_flag; + xmlrpc_value *result = xmlrpc_build_value(env, "s", "dummy"); + + TRACE("called"); + xmlrpc_decompose_value(env, params, "(s)", &shutdown_type); + if (env->fault_occurred) { + goto out_bad; + } + + if (strcmp(shutdown_type, "halt") == 0) { + shutdown_flag = "-H"; + } else if (strcmp(shutdown_type, "powerdown") == 0) { + shutdown_flag = "-P"; + } else if (strcmp(shutdown_type, "reboot") == 0) { + shutdown_flag = "-r"; + } else { + xmlrpc_faultf(env, "invalid shutdown type: %s", shutdown_type); + goto out_bad; + } + + SLOG("va_shutdown(), shutdown_type:%s", shutdown_type); + + ret = fork(); + if (ret == 0) { + /* child, start the shutdown */ + setsid(); + fclose(stdin); + fclose(stdout); + fclose(stderr); + + sleep(5); + ret = execl("/sbin/shutdown", "shutdown", shutdown_flag, "+0", + "hypervisor initiated shutdown", (char*)NULL); + if (ret < 0) { + LOG("execl() failed: %s", strerror(errno)); + exit(1); + } + TRACE("shouldn't be here"); + exit(0); + } else if (ret < 0) { + xmlrpc_faultf(env, "fork() failed: %s", strerror(errno)); + } + + return result; +out_bad: + return NULL; +} + typedef struct RPCFunction { xmlrpc_value *(*func)(xmlrpc_env *env, xmlrpc_value *param, void *unused); const char *func_name; @@ -173,6 +229,8 @@ static RPCFunction guest_functions[] = { .func_name = "va.getfile" }, { .func = va_getdmesg, .func_name = "va.getdmesg" }, + { .func = va_shutdown, + .func_name = "va.shutdown" }, { NULL, NULL } }; static RPCFunction host_functions[] = { -- 1.7.0.4