Re: [PATCH] quorum-tool: use option to generate machine parsable output

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ACK

Fabio M. Di Nitto napsal(a):
> From: "Fabio M. Di Nitto" <fdinitto@xxxxxxxxxx>
> 
> Signed-off-by: Fabio M. Di Nitto <fdinitto@xxxxxxxxxx>
> ---
>  man/corosync-quorumtool.8   |    5 +++-
>  tools/corosync-quorumtool.c |   62 +++++++++++++++++++++++++++++-------------
>  2 files changed, 47 insertions(+), 20 deletions(-)
> 
> diff --git a/man/corosync-quorumtool.8 b/man/corosync-quorumtool.8
> index 81cee53..fcfcc33 100644
> --- a/man/corosync-quorumtool.8
> +++ b/man/corosync-quorumtool.8
> @@ -35,7 +35,7 @@
>  .SH NAME
>  corosync-quorumtool \- Set and display quorum settings.
>  .SH SYNOPSIS
> -.B "corosync-quorumtool [\-s] [\-m] [\-l] [\-v votes] [\-n nodeid] [\-e expected] [\-h] [\-i] [\-V]"
> +.B "corosync-quorumtool [\-s] [\-m] [\-l] [\-p] [\-v votes] [\-n nodeid] [\-e expected] [\-h] [\-i] [\-V]"
>  .SH DESCRIPTION
>  Display the current state of quorum in the cluster and set vote quorum options.
>  .SH OPTIONS
> @@ -64,6 +64,9 @@ show nodeids in hexadecimal rather than decimal
>  .B  -i
>  show node IP addresses instead of the resolved name
>  .TP
> +.B -p
> +when used with -s or -l, generates machine parsable output
> +.TP
>  .B  -h (if no other argument)
>  show this help text
>  .TP
> diff --git a/tools/corosync-quorumtool.c b/tools/corosync-quorumtool.c
> index fbcc302..5cf043e 100644
> --- a/tools/corosync-quorumtool.c
> +++ b/tools/corosync-quorumtool.c
> @@ -120,6 +120,11 @@ static corosync_cfg_callbacks_t c_callbacks = {
>  	.corosync_cfg_shutdown_callback = NULL
>  };
>  
> +/*
> + * global
> + */
> +static int machine_parsable = 0;
> +
>  static void show_usage(const char *name)
>  {
>  	printf("usage: \n");
> @@ -130,6 +135,7 @@ static void show_usage(const char *name)
>  	printf("  -s             show quorum status\n");
>  	printf("  -m             monitor quorum status\n");
>  	printf("  -l             list nodes\n");
> +	printf("  -p             when used with -s or -l, generates machine parsable output\n");
>  	printf("  -v <votes>     change the number of votes for a node (*)\n");
>  	printf("  -n <nodeid>    optional nodeid of node for -v (*)\n");
>  	printf("  -e <expected>  change expected votes for the cluster (*)\n");
> @@ -365,7 +371,21 @@ static void print_uint32_padded(uint32_t value)
>  static void display_nodes_data(nodeid_format_t nodeid_format, name_format_t name_format)
>  {
>  	int i, display_qdevice = 0;
> -	struct votequorum_info info;
> +	struct votequorum_info info[g_view_list_entries];
> +
> +	/*
> +	 * cache node info because we need to parse them twice
> +	 */
> +	if (v_handle) {
> +		for (i=0; i < g_view_list_entries; i++) {
> +			if (votequorum_getinfo(v_handle, g_view_list[i], &info[i]) != CS_OK) {
> +				printf("Unable to get node %u info\n", g_view_list[i]);
> +			}
> +			if (info[i].flags & VOTEQUORUM_INFO_QDEVICE_REGISTERED) {
> +				display_qdevice = 1;
> +			}
> +		}
> +	}
>  
>  	printf("\nMembership information\n");
>  	printf("----------------------\n");
> @@ -373,7 +393,9 @@ static void display_nodes_data(nodeid_format_t nodeid_format, name_format_t name
>  	print_string_padded("Nodeid");
>  	if (v_handle) {
>  		print_string_padded("Votes");
> -		print_string_padded("Qdevice");
> +		if ((display_qdevice) || (machine_parsable)) {
> +			print_string_padded("Qdevice");
> +		}
>  	}
>  	printf("Name\n");
>  
> @@ -386,23 +408,22 @@ static void display_nodes_data(nodeid_format_t nodeid_format, name_format_t name
>  		if (v_handle) {
>  			int votes = -1;
>  
> -			if (votequorum_getinfo(v_handle, g_view_list[i], &info) == CS_OK) {
> -				votes = info.node_votes;
> -			}
> +			votes = info[i].node_votes;
>  			print_uint32_padded(votes);
>  
> -			if (info.flags & VOTEQUORUM_INFO_QDEVICE_REGISTERED) {
> -				char buf[10];
> +			if ((display_qdevice) || (machine_parsable)) {
> +				if (info[i].flags & VOTEQUORUM_INFO_QDEVICE_REGISTERED) {
> +					char buf[10];
>  
> -				display_qdevice = 1;
> -				snprintf(buf, sizeof(buf) - 1,
> -					 "%s,%s,%s",
> -					 info.flags & VOTEQUORUM_INFO_QDEVICE_ALIVE?"A":"NA",
> -					 info.flags & VOTEQUORUM_INFO_QDEVICE_CAST_VOTE?"V":"NV",
> -					 info.flags & VOTEQUORUM_INFO_QDEVICE_MASTER_WINS?"MW":"NMW");
> -				print_string_padded(buf);
> -			} else {
> -				print_string_padded("NR");
> +					snprintf(buf, sizeof(buf) - 1,
> +						 "%s,%s,%s",
> +						 info[i].flags & VOTEQUORUM_INFO_QDEVICE_ALIVE?"A":"NA",
> +						 info[i].flags & VOTEQUORUM_INFO_QDEVICE_CAST_VOTE?"V":"NV",
> +						 info[i].flags & VOTEQUORUM_INFO_QDEVICE_MASTER_WINS?"MW":"NMW");
> +					print_string_padded(buf);
> +				} else {
> +					print_string_padded("NR");
> +				}
>  			}
>  		}
>  		printf("%s", node_name(g_view_list[i], name_format));
> @@ -423,8 +444,8 @@ static void display_nodes_data(nodeid_format_t nodeid_format, name_format_t name
>  		} else {
>  			printf("0x%08x ", VOTEQUORUM_QDEVICE_NODEID);
>  		}
> -		print_uint32_padded(info.qdevice_votes);
> -		printf("           %s\n", info.qdevice_name);
> +		print_uint32_padded(info[0].qdevice_votes);
> +		printf("           %s\n", info[0].qdevice_name);
>  	}
>  
>  }
> @@ -684,7 +705,7 @@ static void close_all(void) {
>  }
>  
>  int main (int argc, char *argv[]) {
> -	const char *options = "VHslmfe:v:hin:";
> +	const char *options = "VHslpmfe:v:hin:";
>  	char *endptr;
>  	int opt;
>  	int votes = 0;
> @@ -725,6 +746,9 @@ int main (int argc, char *argv[]) {
>  		case 'l':
>  			command_opt = CMD_SHOWNODES;
>  			break;
> +		case 'p':
> +			machine_parsable = 1;
> +			break;
>  		case 'e':
>  			if (using_votequorum() > 0) {
>  				votes = strtol(optarg, &endptr, 0);
> 

_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss


[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux