[pve-devel] applied: [PATCH cluster] use constants for IPC request types

Wolfgang Bumiller w.bumiller at proxmox.com
Wed May 23 11:55:41 CEST 2018


applied, with a fixup to the Makefile.am to have IPCConst.pm depend on
cfs-ipc-ops.h in addition to its generator awk script.

On Fri, May 18, 2018 at 12:37:25PM +0200, Thomas Lamprecht wrote:
> Add a simple header with the constants as defines.
> Use a simple awk script to translate this to an perl module with the
> constants exported. awk is far easier to understand and maintain than
> h2ph or h2xs, also their result is quite a mess for such a trivial
> thing, IMO.
> 
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> ---
>  data/PVE/Cluster.pm              | 19 +++++++++---------
>  data/PVE/Cluster/IPCConst.pm.awk | 21 ++++++++++++++++++++
>  data/PVE/Makefile.am             |  8 ++++++++
>  data/src/cfs-ipc-ops.h           | 42 ++++++++++++++++++++++++++++++++++++++++
>  data/src/server.c                | 19 +++++++++---------
>  5 files changed, 91 insertions(+), 18 deletions(-)
>  create mode 100644 data/PVE/Cluster/IPCConst.pm.awk
>  create mode 100644 data/src/cfs-ipc-ops.h
> 
> diff --git a/data/PVE/Cluster.pm b/data/PVE/Cluster.pm
> index 4e3bf7a..7569abc 100644
> --- a/data/PVE/Cluster.pm
> +++ b/data/PVE/Cluster.pm
> @@ -17,6 +17,7 @@ use PVE::IPCC;
>  use PVE::SafeSyslog;
>  use PVE::JSONSchema;
>  use PVE::Network;
> +use PVE::Cluster::IPCConst;
>  use JSON;
>  use RRDs;
>  use Encode;
> @@ -408,7 +409,7 @@ my $ipcc_get_config = sub {
>      my ($path) = @_;
>  
>      my $bindata = pack "Z*", $path;
> -    my $res = PVE::IPCC::ipcc_send_rec(6, $bindata);
> +    my $res = PVE::IPCC::ipcc_send_rec(CFS_IPC_GET_CONFIG, $bindata);
>      if (!defined($res)) {
>  	if ($! != 0) {
>  	    return undef if $! == ENOENT;
> @@ -424,7 +425,7 @@ my $ipcc_get_status = sub {
>      my ($name, $nodename) = @_;
>  
>      my $bindata = pack "Z[256]Z[256]", $name, ($nodename || "");
> -    return PVE::IPCC::ipcc_send_rec(5, $bindata);
> +    return PVE::IPCC::ipcc_send_rec(CFS_IPC_GET_STATUS, $bindata);
>  };
>  
>  my $ipcc_update_status = sub {
> @@ -434,7 +435,7 @@ my $ipcc_update_status = sub {
>      # update status
>      my $bindata = pack "Z[256]Z*", $name, $raw;
>  
> -    return &$ipcc_send_rec(4, $bindata);
> +    return &$ipcc_send_rec(CFS_IPC_SET_STATUS, $bindata);
>  };
>  
>  my $ipcc_log = sub {
> @@ -443,7 +444,7 @@ my $ipcc_log = sub {
>      my $bindata = pack "CCCZ*Z*Z*", $priority, bytes::length($ident) + 1,
>      bytes::length($tag) + 1, $ident, $tag, $msg;
>  
> -    return &$ipcc_send_rec(7, $bindata);
> +    return &$ipcc_send_rec(CFS_IPC_LOG_CLUSTER_MSG, $bindata);
>  };
>  
>  my $ipcc_get_cluster_log = sub {
> @@ -452,7 +453,7 @@ my $ipcc_get_cluster_log = sub {
>      $max = 0 if !defined($max);
>  
>      my $bindata = pack "VVVVZ*", $max, 0, 0, 0, ($user || "");
> -    return &$ipcc_send_rec(8, $bindata);
> +    return &$ipcc_send_rec(CFS_IPC_GET_CLUSTER_LOG, $bindata);
>  };
>  
>  my $ccache = {};
> @@ -460,7 +461,7 @@ my $ccache = {};
>  sub cfs_update {
>      my ($fail) = @_;
>      eval {
> -	my $res = &$ipcc_send_rec_json(1);
> +	my $res = &$ipcc_send_rec_json(CFS_IPC_GET_FS_VERSION);
>  	#warn "GOT1: " . Dumper($res);
>  	die "no starttime\n" if !$res->{starttime};
>  
> @@ -487,7 +488,7 @@ sub cfs_update {
>      eval {
>  	if (!$clinfo->{version} || $clinfo->{version} != $versions->{clinfo}) {
>  	    #warn "detected new clinfo\n";
> -	    $clinfo = &$ipcc_send_rec_json(2);
> +	    $clinfo = &$ipcc_send_rec_json(CFS_IPC_GET_CLUSTER_INFO);
>  	}
>      };
>      $err = $@;
> @@ -500,7 +501,7 @@ sub cfs_update {
>      eval {
>  	if (!$vmlist->{version} || $vmlist->{version} != $versions->{vmlist}) {
>  	    #warn "detected new vmlist1\n";
> -	    $vmlist = &$ipcc_send_rec_json(3);
> +	    $vmlist = &$ipcc_send_rec_json(CFS_IPC_GET_GUEST_LIST);
>  	}
>      };
>      $err = $@;
> @@ -617,7 +618,7 @@ sub rrd_dump {
>  
>      my $raw;
>      eval {
> -	$raw = &$ipcc_send_rec(10);
> +	$raw = &$ipcc_send_rec(CFS_IPC_GET_RRD_DUMP);
>      };
>      my $err = $@;
>  
> diff --git a/data/PVE/Cluster/IPCConst.pm.awk b/data/PVE/Cluster/IPCConst.pm.awk
> new file mode 100644
> index 0000000..3c622ec
> --- /dev/null
> +++ b/data/PVE/Cluster/IPCConst.pm.awk
> @@ -0,0 +1,21 @@
> +BEGIN {
> +    print "package PVE::Cluster::IPCConst;"
> +    print "use strict; use warnings;"
> +    print
> +    print "use base 'Exporter';"
> +    print
> +    print "my %IPC_OPS;"
> +    print "BEGIN {"
> +    print "  %IPC_OPS = ("
> +}
> +
> +/^#define CFS_IPC/ {
> +    print "    " $2, "=>", $3 ","
> +}
> +
> +END {
> +    print "  );"
> +    print "}"
> +    print "use constant \\%IPC_OPS;"
> +    print "our @EXPORT = keys(%IPC_OPS);"
> +}
> diff --git a/data/PVE/Makefile.am b/data/PVE/Makefile.am
> index 1f576b0..393f0c8 100644
> --- a/data/PVE/Makefile.am
> +++ b/data/PVE/Makefile.am
> @@ -4,6 +4,10 @@ IPCC.c: IPCC.xs
>  	xsubpp IPCC.xs > IPCC.xsc
>  	mv IPCC.xsc IPCC.c
>  
> +Cluster/IPCConst.pm: Cluster/IPCConst.pm.awk
> +	awk -f $^ ../src/cfs-ipc-ops.h > $@.tmp
> +	mv $@.tmp $@
> +
>  AM_CFLAGS = -shared -fPIC -Wl,-z,relro -Wall -Werror -Wno-strict-aliasing $(PERL_INC) -DXS_VERSION=VERSION
>  LDADD = $(QB_LIBS)
>  
> @@ -21,6 +25,7 @@ export PERLLIB=..
>  	mv $@.tmp $@
>  
>  man1_MANS = pvecm.1
> +pvecm.1-synopsis.adoc: Cluster/IPCConst.pm
>  man5_MANS = datacenter.cfg.5
>  
>  IPCC_so_SOURCES = IPCC.c ppport.h
> @@ -28,6 +33,9 @@ IPCC_so_SOURCES = IPCC.c ppport.h
>  pvelib_DATA = IPCC.pm Cluster.pm Corosync.pm
>  pvelibdir = $(PERL_VENDORLIB)/PVE
>  
> +pveclusterlib_DATA = Cluster/IPCConst.pm
> +pveclusterlibdir = $(PERL_VENDORLIB)/PVE/Cluster
> +
>  noinst_DATA = pvecm.bash-completion
>  
>  cliclass_DATA = CLI/pvecm.pm
> diff --git a/data/src/cfs-ipc-ops.h b/data/src/cfs-ipc-ops.h
> new file mode 100644
> index 0000000..a1bf51d
> --- /dev/null
> +++ b/data/src/cfs-ipc-ops.h
> @@ -0,0 +1,42 @@
> +/*
> +  Copyright (C) 2018 Proxmox Server Solutions GmbH
> +
> +  This program is free software: you can redistribute it and/or modify
> +  it under the terms of the GNU Affero General Public License as published by
> +  the Free Software Foundation, either version 3 of the License, or
> +  (at your option) any later version.
> +
> +  This program 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 Affero General Public License for more details.
> +
> +  You should have received a copy of the GNU Affero General Public License
> +  along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +  Author: Thomas Lamprecht <t.lamprecht at proxmox.com>
> +
> +*/
> +
> +#ifndef _PVE_CFS_IPC_OPS_H_
> +#define _PVE_CFS_IPC_OPS_H_
> +
> +#define CFS_IPC_GET_FS_VERSION 1
> +
> +#define CFS_IPC_GET_CLUSTER_INFO 2
> +
> +#define CFS_IPC_GET_GUEST_LIST 3
> +
> +#define CFS_IPC_SET_STATUS 4
> +
> +#define CFS_IPC_GET_STATUS 5
> +
> +#define CFS_IPC_GET_CONFIG 6
> +
> +#define CFS_IPC_LOG_CLUSTER_MSG 7
> +
> +#define CFS_IPC_GET_CLUSTER_LOG 8
> +
> +#define CFS_IPC_GET_RRD_DUMP 10
> +
> +#endif
> diff --git a/data/src/server.c b/data/src/server.c
> index 0d366b1..54289c7 100644
> --- a/data/src/server.c
> +++ b/data/src/server.c
> @@ -38,6 +38,7 @@
>  #include <glib.h>
>  
>  #include "cfs-utils.h"
> +#include "cfs-ipc-ops.h"
>  #include "status.h"
>  #include "memdb.h"
>  #include "logger.h"
> @@ -171,7 +172,7 @@ static int32_t s1_msg_process_fn(
>  	g_string_truncate(outbuf, 0);
>  
>  	int32_t result = -ECHRNG;
> -	if (req_pt->id == 1) {
> +	if (req_pt->id == CFS_IPC_GET_FS_VERSION) {
>  
>  		if (req_pt->size != sizeof(struct qb_ipc_request_header)) {
>  			result = -EINVAL;
> @@ -179,7 +180,7 @@ static int32_t s1_msg_process_fn(
>  			result = cfs_create_version_msg(outbuf);
>  		}
>  
> -	} else if (req_pt->id == 2) {
> +	} else if (req_pt->id == CFS_IPC_GET_CLUSTER_INFO) {
>  
>  		if (req_pt->size != sizeof(struct qb_ipc_request_header)) {
>  			result = -EINVAL;
> @@ -187,14 +188,14 @@ static int32_t s1_msg_process_fn(
>  			result = cfs_create_memberlist_msg(outbuf);
>  		}
>  
> -	} else if (req_pt->id == 3) {
> +	} else if (req_pt->id == CFS_IPC_GET_GUEST_LIST) {
>  		
>  		if (req_pt->size != sizeof(struct qb_ipc_request_header)) {
>  			result = -EINVAL;
>  		} else {
>  			result = cfs_create_vmlist_msg(outbuf);
>  		}
> -	} else if (req_pt->id == 4) {
> +	} else if (req_pt->id == CFS_IPC_SET_STATUS) {
>  
>  		cfs_status_update_request_header_t *rh = 
>  			(cfs_status_update_request_header_t *)data;
> @@ -213,7 +214,7 @@ static int32_t s1_msg_process_fn(
>  
>  			result = cfs_status_set(rh->name, dataptr, datasize);
>  		}
> -	} else if (req_pt->id == 5) {
> +	} else if (req_pt->id == CFS_IPC_GET_STATUS) {
>  
>  		cfs_status_get_request_header_t *rh =
>  			(cfs_status_get_request_header_t *)data;
> @@ -229,7 +230,7 @@ static int32_t s1_msg_process_fn(
>  
>  			result = cfs_create_status_msg(outbuf, rh->nodename, rh->name);
>  		}
> -	} else if (req_pt->id == 6) {
> +	} else if (req_pt->id == CFS_IPC_GET_CONFIG) {
>  
>  		int pathlen = req_pt->size - sizeof(struct qb_ipc_request_header);
>  
> @@ -251,7 +252,7 @@ static int32_t s1_msg_process_fn(
>  				}
>  			}
>  		}			
> -	} else if (req_pt->id == 7) {
> +	} else if (req_pt->id == CFS_IPC_LOG_CLUSTER_MSG) {
>  
>  		cfs_log_msg_request_header_t *rh = 
>  			(cfs_log_msg_request_header_t *)data;
> @@ -286,7 +287,7 @@ static int32_t s1_msg_process_fn(
>  				result = -EINVAL;
>  			}
>  		}
> -	} else if (req_pt->id == 8) {
> +	} else if (req_pt->id == CFS_IPC_GET_CLUSTER_LOG) {
>  
>  		cfs_log_get_request_header_t *rh = 
>  			(cfs_log_get_request_header_t *)data;
> @@ -304,7 +305,7 @@ static int32_t s1_msg_process_fn(
>  			cfs_cluster_log_dump(outbuf, user, max);
>  			result = 0;
>  		}
> -	} else if (req_pt->id == 10) {	
> +	} else if (req_pt->id == CFS_IPC_GET_RRD_DUMP) {
>  	
>  		if (req_pt->size != sizeof(struct qb_ipc_request_header)) {
>  			result = -EINVAL;
> -- 
> 2.14.2




More information about the pve-devel mailing list