From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=44508 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POZzJ-00023o-Rf for qemu-devel@nongnu.org; Fri, 03 Dec 2010 13:04:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POZzH-0003ET-E6 for qemu-devel@nongnu.org; Fri, 03 Dec 2010 13:04:05 -0500 Received: from e2.ny.us.ibm.com ([32.97.182.142]:37908) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POZzH-0003EN-9q for qemu-devel@nongnu.org; Fri, 03 Dec 2010 13:04:03 -0500 Received: from d01dlp02.pok.ibm.com (d01dlp02.pok.ibm.com [9.56.224.85]) by e2.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id oB3HlXnx009593 for ; Fri, 3 Dec 2010 12:47:33 -0500 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 37CEB4DE803B for ; Fri, 3 Dec 2010 13:02:20 -0500 (EST) Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id oB3I41BB1585282 for ; Fri, 3 Dec 2010 13:04:01 -0500 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id oB3I41jE013875 for ; Fri, 3 Dec 2010 13:04:01 -0500 From: Michael Roth Date: Fri, 3 Dec 2010 12:03:12 -0600 Message-Id: <1291399402-20366-12-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1291399402-20366-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1291399402-20366-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [RFC][PATCH v5 11/21] 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, mdroth@linux.vnet.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 aac8f70..453cf0d 100644 --- a/virtagent-server.c +++ b/virtagent-server.c @@ -127,6 +127,62 @@ EXIT_NOCLOSE: return result; } +/* va_shutdown(): initiate guest shutdown + * rpc return values: none + */ +static xmlrpc_value *va_shutdown(xmlrpc_env *env, + xmlrpc_value *param, + 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, param, "(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; @@ -137,6 +193,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