:p
atchew
Login
Add a command line option to xentop to be able to display dom0 first, on top of the list. This is unconditional, so sorting domains with the S option will also ignore dom0. Signed-off-by: Cyril Rébert (zithro) <slack@rabbit.lu> --- Changes in v2: - bug fix - add documentation --- docs/man/xentop.1.pod | 6 +++++- tools/xentop/xentop.c | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/man/xentop.1.pod b/docs/man/xentop.1.pod index XXXXXXX..XXXXXXX 100644 --- a/docs/man/xentop.1.pod +++ b/docs/man/xentop.1.pod @@ -XXX,XX +XXX,XX @@ xentop - displays real-time information about a Xen system and domains =head1 SYNOPSIS B<xentop> [B<-h>] [B<-V>] [B<-d>SECONDS] [B<-n>] [B<-r>] [B<-v>] [B<-f>] -[B<-b>] [B<-i>ITERATIONS] +[B<-b>] [B<-i>ITERATIONS] [B<-z>] =head1 DESCRIPTION @@ -XXX,XX +XXX,XX @@ output data in batch mode (to stdout) maximum number of iterations xentop should produce before ending +=item B<-z>, B<--dom0-first> + +display dom0 first, ignoring interactive sorting + =back =head1 INTERACTIVE COMMANDS diff --git a/tools/xentop/xentop.c b/tools/xentop/xentop.c index XXXXXXX..XXXXXXX 100644 --- a/tools/xentop/xentop.c +++ b/tools/xentop/xentop.c @@ -XXX,XX +XXX,XX @@ int show_networks = 0; int show_vbds = 0; int repeat_header = 0; int show_full_name = 0; -int dom0_first = -1; +int dom0_first = 0; #define PROMPT_VAL_LEN 80 const char *prompt = NULL; char prompt_val[PROMPT_VAL_LEN]; @@ -XXX,XX +XXX,XX @@ void do_vbd(xenstat_domain *domain) static void top(void) { xenstat_domain **domains; - unsigned int i, num_domains, sort_start, sort_count = 0; + unsigned int i, num_domains = 0; int dom0_index = -1; + int sort_start = 0, sort_count = 0; /* Now get the node information */ if (prev_node != NULL) -- 2.39.2
From: Cyril Rébert <slack@rabbit.lu> Add a command line option to xentop to be able to display dom0 first, on top of the list. This is unconditional, so sorting domains with the S option will also ignore dom0. Signed-off-by: Cyril Rébert (zithro) <slack@rabbit.lu> --- Changes in v3: (none, just reformatting patch correctly ... hopefully ?!) --- Changes in v2: - bug fix - add documentation --- docs/man/xentop.1.pod | 6 +++++- tools/xentop/xentop.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/man/xentop.1.pod b/docs/man/xentop.1.pod index XXXXXXX..XXXXXXX 100644 --- a/docs/man/xentop.1.pod +++ b/docs/man/xentop.1.pod @@ -XXX,XX +XXX,XX @@ xentop - displays real-time information about a Xen system and domains =head1 SYNOPSIS B<xentop> [B<-h>] [B<-V>] [B<-d>SECONDS] [B<-n>] [B<-r>] [B<-v>] [B<-f>] -[B<-b>] [B<-i>ITERATIONS] +[B<-b>] [B<-i>ITERATIONS] [B<-z>] =head1 DESCRIPTION @@ -XXX,XX +XXX,XX @@ output data in batch mode (to stdout) maximum number of iterations xentop should produce before ending +=item B<-z>, B<--dom0-first> + +display dom0 first, ignoring interactive sorting + =back =head1 INTERACTIVE COMMANDS diff --git a/tools/xentop/xentop.c b/tools/xentop/xentop.c index XXXXXXX..XXXXXXX 100644 --- a/tools/xentop/xentop.c +++ b/tools/xentop/xentop.c @@ -XXX,XX +XXX,XX @@ int show_networks = 0; int show_vbds = 0; int repeat_header = 0; int show_full_name = 0; +int dom0_first = 0; #define PROMPT_VAL_LEN 80 const char *prompt = NULL; char prompt_val[PROMPT_VAL_LEN]; @@ -XXX,XX +XXX,XX @@ static void usage(const char *program) "-b, --batch output in batch mode, no user input accepted\n" "-i, --iterations number of iterations before exiting\n" "-f, --full-name output the full domain name (not truncated)\n" + "-z, --dom0-first display dom0 first (ignore sorting)\n" "\n" XENTOP_BUGSTO, program); return; @@ -XXX,XX +XXX,XX @@ static void top(void) { xenstat_domain **domains; unsigned int i, num_domains = 0; + int dom0_index = -1; + int sort_start = 0, sort_count = 0; /* Now get the node information */ if (prev_node != NULL) @@ -XXX,XX +XXX,XX @@ static void top(void) if(domains == NULL) fail("Failed to allocate memory\n"); - for (i=0; i < num_domains; i++) + for (i=0; i < num_domains; i++) { domains[i] = xenstat_node_domain_by_index(cur_node, i); + if ( strcmp(xenstat_domain_name(domains[i]), "Domain-0") == 0 ) + dom0_index = i; + } + + /* Handle dom0 position, not for dom0-less */ + if ( dom0_first == 1 && dom0_index != -1 ){ + /* if dom0 is not first in domains, swap it there */ + if ( dom0_index != 0 ){ + xenstat_domain *tmp; + tmp = domains[0]; + domains[0] = domains[dom0_index]; + domains[dom0_index] = tmp; + } + sort_start = 1; + sort_count = 1; + } /* Sort */ - qsort(domains, num_domains, sizeof(xenstat_domain *), + qsort((domains+sort_start), (num_domains-sort_count), sizeof(xenstat_domain *), (int(*)(const void *, const void *))compare_domains); if(first_domain_index >= num_domains) @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) { "batch", no_argument, NULL, 'b' }, { "iterations", required_argument, NULL, 'i' }, { "full-name", no_argument, NULL, 'f' }, + { "dom0-first", no_argument, NULL, 'z' }, { 0, 0, 0, 0 }, }; - const char *sopts = "hVnxrvd:bi:f"; + const char *sopts = "hVnxrvd:bi:fz"; if (atexit(cleanup) != 0) fail("Failed to install cleanup handler.\n"); @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) case 'f': show_full_name = 1; break; + case 'z': + dom0_first = 1; + break; } } -- 2.39.2