From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4Y5g-000436-0q for qemu-devel@nongnu.org; Thu, 23 Aug 2012 10:09:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T4Y5e-0001ZU-H8 for qemu-devel@nongnu.org; Thu, 23 Aug 2012 10:08:55 -0400 Received: from mail-ob0-f173.google.com ([209.85.214.173]:64358) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T4Y5e-0001Yy-CC for qemu-devel@nongnu.org; Thu, 23 Aug 2012 10:08:54 -0400 Received: by obbta14 with SMTP id ta14so1512458obb.4 for ; Thu, 23 Aug 2012 07:08:53 -0700 (PDT) Sender: fluxion Date: Thu, 23 Aug 2012 09:08:45 -0500 From: Michael Roth Message-ID: <20120823140845.GP16157@illuin> References: <20120821115754.GA5855@bogon.sigxcpu.org> <20120823094854.788be622@doriath.home> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20120823094854.788be622@doriath.home> Subject: Re: [Qemu-devel] [PATCH] Add guest-get-hostname to retrieve the guests current hostname List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino Cc: Guido =?iso-8859-1?Q?G=FCnther?= , qemu-devel@nongnu.org On Thu, Aug 23, 2012 at 09:48:54AM -0300, Luiz Capitulino wrote: > On Tue, 21 Aug 2012 13:57:54 +0200 > Guido Günther wrote: > > > This allows to retrieve the guest's hostname via gethostname(2). > > > > This can be useful to identify a VM e.g. one without network. > > > > Signed-off-by: Guido Günther > > --- > > We have an API in libvirt for that (virDomainGetHostname). > > Cheers > > -- Guido > > > > qapi-schema-guest.json | 12 ++++++++++++ > > qga/commands-posix.c | 12 ++++++++++++ > > qga/commands-win32.c | 6 ++++++ > > 3 files changed, 30 insertions(+) > > > > diff --git a/qapi-schema-guest.json b/qapi-schema-guest.json > > index d955cf1..8c7a4a5 100644 > > --- a/qapi-schema-guest.json > > +++ b/qapi-schema-guest.json > > @@ -515,3 +515,15 @@ > > ## > > { 'command': 'guest-network-get-interfaces', > > 'returns': ['GuestNetworkInterface'] } > > + > > +## > > +# @guest-get-hostname: > > +# > > +# Get the guest's hostname > > +# > > +# Returns: The guest's hostname > > +# > > +# Since: 1.2 > > Won't make it for 1.2 because we're in hard-freeze. > > > +## > > +{ 'command': 'guest-get-hostname', > > + 'returns': 'str' } > > diff --git a/qga/commands-posix.c b/qga/commands-posix.c > > index ce90421..9223f18 100644 > > --- a/qga/commands-posix.c > > +++ b/qga/commands-posix.c > > @@ -15,6 +15,7 @@ > > #include > > #include > > #include > > +#include > > #include "qga/guest-agent-core.h" > > #include "qga-qmp-commands.h" > > #include "qerror.h" > > @@ -993,6 +994,17 @@ void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err) > > } > > #endif > > > > +char *qmp_guest_get_hostname(Error **err) > > +{ > > + char hostname[HOST_NAME_MAX]; > > + > > + if (gethostname(hostname, HOST_NAME_MAX)) { > > + error_set(err, QERR_QGA_COMMAND_FAILED, strerror(errno)); > > You shouldn't use that macro, you can do something like this instead: > > error_set(err, "can't get hostname: %s", strerror(errno)); > > Michael, do you think that's fine for new error messages or do you think it's > worth it to add a "guest-agent: " prefix to all guest agent error messages? > I think that's fine. libvirt or QMP (if we integrate the qemu-ga commands with QMP) can tack on a prefix for cases where we need to distinguish where in the stack the error occurred, but for direct communication with qemu-ga it's unambiguous, so might as well save the keystrokes. > > + return NULL; > > + } > > + return g_strdup(hostname); > > +} > > + > > /* register init/cleanup routines for stateful command groups */ > > void ga_command_state_init(GAState *s, GACommandState *cs) > > { > > diff --git a/qga/commands-win32.c b/qga/commands-win32.c > > index 54bc546..55e8162 100644 > > --- a/qga/commands-win32.c > > +++ b/qga/commands-win32.c > > @@ -280,6 +280,12 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **err) > > return NULL; > > } > > > > +char *qmp_guest_get_hostname(Error **err) > > +{ > > + error_set(err, QERR_UNSUPPORTED); > > + return NULL; > > +} > > + > > /* register init/cleanup routines for stateful command groups */ > > void ga_command_state_init(GAState *s, GACommandState *cs) > > { > >