From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: xen-devel@lists.xensource.com, keir.fraser@eu.citrix.com
Cc: konrad.wilk@oracle.com
Subject: [PATCH 3 of 3] [xen-detect] Add arguments to print out only outputs we are interested in
Date: Tue, 22 Dec 2009 16:48:58 -0000 [thread overview]
Message-ID: <04c067941b17bdc679ff.1261500538@phenom.dumpdata.com> (raw)
In-Reply-To: <patchbomb.1261500535@phenom.dumpdata.com>
# HG changeset patch
# User konrad@phenom.dumpdata.com
# Date 1261498156 18000
# Node ID 04c067941b17bdc679ffdc2f6c81f8e2f78e9cc5
# Parent 7bd805a543da685a3dba7b8b0c4e3e7052c863b3
[xen-detect] Add arguments to print out only outputs we are interested in.
This is quite usefull in scripts where you can do
if xen-detect -P || modprobe xen-<some module>
And do not have to parse the output - instead you will get
the output only if the condition exists.
diff -r 7bd805a543da -r 04c067941b17 tools/misc/xen-detect.c
--- a/tools/misc/xen-detect.c Mon Dec 21 18:51:43 2009 -0500
+++ b/tools/misc/xen-detect.c Tue Dec 22 11:09:16 2009 -0500
@@ -29,6 +29,12 @@
#include <string.h>
#include <setjmp.h>
#include <signal.h>
+#include <unistd.h>
+
+/* Which outputs should be displayed. */
+int disp_HVM = 1;
+int disp_PV = 1;
+int disp_NOXEN = 1;
static void cpuid(uint32_t idx,
uint32_t *eax,
@@ -66,8 +72,9 @@
found:
cpuid(base + 1, &eax, &ebx, &ecx, &edx, pv_context);
- printf("Running in %s context on Xen v%d.%d.\n",
- pv_context ? "PV" : "HVM", (uint16_t)(eax >> 16), (uint16_t)eax);
+ if ((pv_context && disp_PV) || (!pv_context && disp_HVM))
+ printf("Running in %s context on Xen v%d.%d.\n",
+ pv_context ? "PV" : "HVM", (uint16_t)(eax >> 16), (uint16_t)eax);
return pv_context ? 1 : 2;
}
@@ -78,10 +85,42 @@
longjmp(sigill_jmp, 1);
}
-int main(void)
+static void usage(void)
+{
+ printf("usage:\n\n");
+ printf(" xen_detect [options]\n\n");
+ printf("options:\n");
+ printf(" -P, print output if running in PV context.\n");
+ printf(" -H, print output if running in HVM context.\n");
+ printf(" -N, print output if not running in any Xen context.\n");
+};
+
+int main(int argc, char **argv)
{
/* 0 - no Xen, 1 - PV Xen, 2 - HVM Xen */
int rc = 0;
+ int ch;
+
+ while ((ch = getopt(argc, argv, "PHN?h")) != -1 ) {
+ switch (ch) {
+ case 'h':
+ case '?':
+ usage();
+ return(-1);
+ case 'H':
+ disp_HVM = 1;
+ disp_PV = disp_NOXEN = 0;
+ break;
+ case 'P':
+ disp_PV = 1;
+ disp_HVM = disp_NOXEN = 0;
+ break;
+ case 'N':
+ disp_NOXEN = 1;
+ disp_PV = disp_HVM = 0;
+ break;
+ }
+ }
/* Check for execution in HVM context. */
if ( (rc = check_for_xen(0)) )
@@ -97,6 +136,7 @@
&& (rc = check_for_xen(1)) )
return rc;
- printf("Not running on Xen.\n");
+ if (disp_NOXEN)
+ printf("Not running on Xen.\n");
return 0;
}
next prev parent reply other threads:[~2009-12-22 16:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-12-22 16:48 [PATCH 0 of 3] Patches when Linux Xen drivers are modules Konrad Rzeszutek Wilk
2009-12-22 16:48 ` [PATCH 1 of 3] If Xen backend modules are not loaded, load them before starting Xend Konrad Rzeszutek Wilk
2009-12-22 19:41 ` Ian Campbell
2009-12-22 19:57 ` Konrad Rzeszutek Wilk
2009-12-22 21:59 ` Ian Campbell
2009-12-22 16:48 ` [PATCH 2 of 3] [xen-detect] Return 0 if no Xen detected; 1 if running in PV context; and 2 if in HVM context Konrad Rzeszutek Wilk
2009-12-22 20:16 ` Keir Fraser
2009-12-22 16:48 ` Konrad Rzeszutek Wilk [this message]
2009-12-22 20:21 ` [PATCH 3 of 3] [xen-detect] Add arguments to print out only outputs we are interested in Keir Fraser
2009-12-22 20:26 ` Konrad Rzeszutek Wilk
2009-12-22 20:38 ` Keir Fraser
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=04c067941b17bdc679ff.1261500538@phenom.dumpdata.com \
--to=konrad.wilk@oracle.com \
--cc=keir.fraser@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.