From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=54337 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PJ5LB-00013F-PN for qemu-devel@nongnu.org; Thu, 18 Nov 2010 09:19:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PJ5LA-0004fd-Ou for qemu-devel@nongnu.org; Thu, 18 Nov 2010 09:19:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:19487) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PJ5LA-0004eT-Ho for qemu-devel@nongnu.org; Thu, 18 Nov 2010 09:19:56 -0500 Message-ID: <4CE53608.3020902@redhat.com> Date: Thu, 18 Nov 2010 15:19:52 +0100 From: Jes Sorensen MIME-Version: 1.0 Subject: Re: [Qemu-devel] [RFC][PATCH v4 10/18] virtagent: add agent_shutdown monitor command References: <1289923320-5638-1-git-send-email-mdroth@linux.vnet.ibm.com> <1289923320-5638-11-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1289923320-5638-11-git-send-email-mdroth@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Roth Cc: aliguori@linux.vnet.ibm.com, ryanh@us.ibm.com, agl@linux.vnet.ibm.com, qemu-devel@nongnu.org, abeekhof@redhat.com On 11/16/10 17:01, Michael Roth wrote: > Provide monitor command to initiate guest shutdown/reboot/powerdown > +int do_agent_shutdown(Monitor *mon, const QDict *mon_params, > + MonitorCompletion cb, void *opaque) > +{ > + xmlrpc_env env; > + xmlrpc_value *params; > + VARPCData *rpc_data; > + const char *shutdown_type; > + int ret; > + > + TRACE("called"); > + > + xmlrpc_env_init(&env); > + shutdown_type = qdict_get_str(mon_params, "shutdown_type"); > + params = xmlrpc_build_value(&env, "(s)", shutdown_type); > + if (rpc_has_error(&env)) { > + return -1; > + } > + > + rpc_data = qemu_mallocz(sizeof(VARPCData)); > + rpc_data->cb = do_agent_shutdown_cb; > + rpc_data->mon_cb = cb; > + rpc_data->mon_data = opaque; > + > + ret = rpc_execute(&env, "va_shutdown", params, rpc_data); > + if (ret == -EREMOTE) { > + monitor_printf(mon, "RPC Failed (%i): %s\n", env.fault_code, > + env.fault_string); > + return -1; > + } else if (ret == -1) { > + monitor_printf(mon, "RPC communication error\n"); > + return -1; > + } I would think you could put a lot of this into a utility function instead of having it open coded for each command you want to support? Cheers, Jes > + > + return 0; > +} > diff --git a/virtagent.h b/virtagent.h > index c077582..96c6260 100644 > --- a/virtagent.h > +++ b/virtagent.h > @@ -29,5 +29,7 @@ int do_agent_viewfile(Monitor *mon, const QDict *mon_params, > void do_agent_viewdmesg_print(Monitor *mon, const QObject *qobject); > int do_agent_viewdmesg(Monitor *mon, const QDict *mon_params, > MonitorCompletion cb, void *opaque); > +int do_agent_shutdown(Monitor *mon, const QDict *mon_params, > + MonitorCompletion cb, void *opaque); > > #endif /* VIRTAGENT_H */