From mboxrd@z Thu Jan 1 00:00:00 1970 From: Don Slutz Subject: [OPTIONAL][PATCH for-4.5 v6 14/16] Add xen-vmware-guestinfo Date: Sat, 20 Sep 2014 14:07:25 -0400 Message-ID: <1411236447-7435-15-git-send-email-dslutz@verizon.com> References: <1411236447-7435-1-git-send-email-dslutz@verizon.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1411236447-7435-1-git-send-email-dslutz@verizon.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Kevin Tian , Keir Fraser , Ian Campbell , Stefano Stabellini , Jun Nakajima , Eddie Dong , Ian Jackson , Don Slutz , Tim Deegan , George Dunlap , Aravind Gopalakrishnan , Jan Beulich , Andrew Cooper , Boris Ostrovsky , Suravee Suthikulpanit List-Id: xen-devel@lists.xenproject.org A tool to get and set VMware guestinfo Signed-off-by: Don Slutz --- .gitignore | 1 + tools/misc/Makefile | 7 ++- tools/misc/xen-vmware-guestinfo.c | 97 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 tools/misc/xen-vmware-guestinfo.c diff --git a/.gitignore b/.gitignore index aff5758..07f20b9 100644 --- a/.gitignore +++ b/.gitignore @@ -181,6 +181,7 @@ tools/misc/xenperf tools/misc/xenpm tools/misc/xen-hvmctx tools/misc/xen-hvm-param +tools/misc/xen-vmware-guestinfo tools/misc/gtraceview tools/misc/gtracestat tools/misc/xenlockprof diff --git a/tools/misc/Makefile b/tools/misc/Makefile index b8d4579..f2ffe1a 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -10,7 +10,7 @@ CFLAGS += $(CFLAGS_libxenstore) HDRS = $(wildcard *.h) TARGETS-y := xenperf xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xenwatchdogd xencov -TARGETS-$(CONFIG_X86) += xen-detect xen-hvmctx xen-hvm-param xen-hvmcrash xen-lowmemd xen-mfndump +TARGETS-$(CONFIG_X86) += xen-detect xen-hvmctx xen-hvm-param xen-vmware-guestinfo xen-hvmcrash xen-lowmemd xen-mfndump TARGETS-$(CONFIG_MIGRATE) += xen-hptool TARGETS := $(TARGETS-y) @@ -22,7 +22,7 @@ INSTALL_BIN := $(INSTALL_BIN-y) INSTALL_SBIN-y := xen-bugtool xen-python-path xenperf xenpm xen-tmem-list-parse gtraceview \ gtracestat xenlockprof xenwatchdogd xen-ringwatch xencov -INSTALL_SBIN-$(CONFIG_X86) += xen-hvmctx xen-hvm-param xen-hvmcrash xen-lowmemd xen-mfndump +INSTALL_SBIN-$(CONFIG_X86) += xen-hvmctx xen-hvm-param xen-vmware-guestinfo xen-hvmcrash xen-lowmemd xen-mfndump INSTALL_SBIN-$(CONFIG_MIGRATE) += xen-hptool INSTALL_SBIN := $(INSTALL_SBIN-y) @@ -60,6 +60,9 @@ xen-hvmctx: xen-hvmctx.o xen-hvm-param: xen-hvm-param.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) +xen-vmware-guestinfo: xen-vmware-guestinfo.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) + xen-hvmcrash: xen-hvmcrash.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) diff --git a/tools/misc/xen-vmware-guestinfo.c b/tools/misc/xen-vmware-guestinfo.c new file mode 100644 index 0000000..e6b288c --- /dev/null +++ b/tools/misc/xen-vmware-guestinfo.c @@ -0,0 +1,97 @@ +/* + * tools/misc/xen-vmware-guestinfo.c + * + * Copyright (C) 2014 Verizon Corporation + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License Version 2 (GPLv2) + * as published by the Free Software Foundation. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. . + */ + +#include +#include +#include +#include + +#include + + +int +main(int argc, char **argv) +{ + xc_interface *xch; + int domid; + int ret = 0; + + char value[8192]; + unsigned int val_len; + char *vals = ""; + + if ( (argc < 3) || (argc > 4) ) + errx(1, "usage: %s domid guestinfo. [new]", argv[0]); + + xch = xc_interface_open(0, 0, 0); + if ( !xch ) + err(1, "failed to open control interface"); + + domid = atoi(argv[1]); + + ret = xc_get_vmport_guest_info(xch, domid, strlen(argv[2]), argv[2], + sizeof(value), &val_len, value); + if ( !ret ) + { + /* Make sure this is a c-string */ + if ( val_len < sizeof(value) ) + value[val_len] = 0; + else + { + value[sizeof(value) - 1] = 0; + vals = "..."; + } + } + + if ( argc == 4 ) + { + int ret1; + + if ( ret ) + warn("failed to get VMware guestinfo '%s' for domid %d", argv[2], domid); + ret1 = xc_set_vmport_guest_info(xch, domid, strlen(argv[2]), argv[2], + strlen(argv[3]), argv[3]); + if ( ret1 ) + err(1, "failed to set VMware guestinfo '%s' for domid %d", argv[2], domid); + else if ( ret ) + printf("VMware guestinfo '%s'='%s'\n", + argv[2], argv[3]); + else + printf("VMware guestinfo '%s' was '%s'%s now '%s'\n", + argv[2], value, vals, argv[3]); + } + else + { + if ( ret ) + err(1, "failed to get VMware guestinfo '%s' for domid %d", argv[2], domid); + else + { + printf("VMware guestinfo '%s'='%s'%s\n", + argv[2], value, vals); + } + } + xc_interface_close(xch); + + return ret; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ -- 1.8.4