[CRIU] [PATCH 1/4] protobuf: move enum nd_type inside net_device_entry message

Pavel Emelyanov xemul at parallels.com
Tue Sep 30 01:01:29 PDT 2014


On 09/19/2014 05:53 PM, Ruslan Kuprieiev wrote:
> This is needed because of protoc compiler, that not allows us to have
> few global enums with same members because of some strange C++ enum
> rules.

I don't get this explanation. We have much more enum-s than just
this. Why is this one special?

> Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
> ---
>  net.c                 | 22 +++++++++++-----------
>  protobuf/netdev.proto | 26 +++++++++++++-------------
>  2 files changed, 24 insertions(+), 24 deletions(-)
> 
> diff --git a/net.c b/net.c
> index 543f24c..d53907d 100644
> --- a/net.c
> +++ b/net.c
> @@ -69,7 +69,7 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi,
>  	netdev.flags = ifi->ifi_flags;
>  	netdev.name = RTA_DATA(tb[IFLA_IFNAME]);
>  
> -	if (tb[IFLA_ADDRESS] && (type != ND_TYPE__LOOPBACK)) {
> +	if (tb[IFLA_ADDRESS] && (type != NET_DEVICE_ENTRY__ND_TYPE__LOOPBACK)) {
>  		netdev.has_address = true;
>  		netdev.address.data = RTA_DATA(tb[IFLA_ADDRESS]);
>  		netdev.address.len = RTA_PAYLOAD(tb[IFLA_ADDRESS]);
> @@ -109,7 +109,7 @@ static int dump_unknown_device(struct ifinfomsg *ifi, char *kind,
>  
>  	ret = run_plugins(DUMP_EXT_LINK, ifi->ifi_index, ifi->ifi_type, kind);
>  	if (ret == 0)
> -		return dump_one_netdev(ND_TYPE__EXTLINK, ifi, tb, fds, NULL);
> +		return dump_one_netdev(NET_DEVICE_ENTRY__ND_TYPE__EXTLINK, ifi, tb, fds, NULL);
>  
>  	if (ret == -ENOTSUP)
>  		pr_err("Unsupported link %d (type %d kind %s)\n",
> @@ -129,9 +129,9 @@ static int dump_one_ethernet(struct ifinfomsg *ifi, char *kind,
>  		 * Sigh... we have to assume, that the veth device is a
>  		 * connection to the outer world and just dump this end :(
>  		 */
> -		return dump_one_netdev(ND_TYPE__VETH, ifi, tb, fds, NULL);
> +		return dump_one_netdev(NET_DEVICE_ENTRY__ND_TYPE__VETH, ifi, tb, fds, NULL);
>  	if (!strcmp(kind, "tun"))
> -		return dump_one_netdev(ND_TYPE__TUN, ifi, tb, fds, dump_tun_link);
> +		return dump_one_netdev(NET_DEVICE_ENTRY__ND_TYPE__TUN, ifi, tb, fds, dump_tun_link);
>  
>  	return dump_unknown_device(ifi, kind, tb, fds);
>  }
> @@ -140,7 +140,7 @@ static int dump_one_gendev(struct ifinfomsg *ifi, char *kind,
>  		struct rtattr **tb, struct cr_fdset *fds)
>  {
>  	if (!strcmp(kind, "tun"))
> -		return dump_one_netdev(ND_TYPE__TUN, ifi, tb, fds, dump_tun_link);
> +		return dump_one_netdev(NET_DEVICE_ENTRY__ND_TYPE__TUN, ifi, tb, fds, dump_tun_link);
>  
>  	return dump_unknown_device(ifi, kind, tb, fds);
>  }
> @@ -154,7 +154,7 @@ static int dump_one_voiddev(struct ifinfomsg *ifi, char *kind,
>  		 * OpenVZ's venet, save general parameters of
>  		 * it as external link.
>  		 */
> -		return dump_one_netdev(ND_TYPE__EXTLINK, ifi, tb, fds, NULL);
> +		return dump_one_netdev(NET_DEVICE_ENTRY__ND_TYPE__EXTLINK, ifi, tb, fds, NULL);
>  
>  	return dump_unknown_device(ifi, kind, tb, fds);
>  }
> @@ -178,7 +178,7 @@ static int dump_one_link(struct nlmsghdr *hdr, void *arg)
>  	pr_info("\tLD: Got link %d, type %d\n", ifi->ifi_index, ifi->ifi_type);
>  
>  	if (ifi->ifi_type == ARPHRD_LOOPBACK) 
> -		return dump_one_netdev(ND_TYPE__LOOPBACK, ifi, tb, fds, NULL);
> +		return dump_one_netdev(NET_DEVICE_ENTRY__ND_TYPE__LOOPBACK, ifi, tb, fds, NULL);
>  
>  	kind = link_kind(ifi, tb);
>  	if (!kind)
> @@ -352,12 +352,12 @@ static int restore_link(NetDeviceEntry *nde, int nlsk)
>  	pr_info("Restoring link %s type %d\n", nde->name, nde->type);
>  
>  	switch (nde->type) {
> -	case ND_TYPE__LOOPBACK: /* fallthrough */
> -	case ND_TYPE__EXTLINK:  /* see comment in protobuf/netdev.proto */
> +	case NET_DEVICE_ENTRY__ND_TYPE__LOOPBACK: /* fallthrough */
> +	case NET_DEVICE_ENTRY__ND_TYPE__EXTLINK:  /* see comment in protobuf/netdev.proto */
>  		return restore_link_parms(nde, nlsk);
> -	case ND_TYPE__VETH:
> +	case NET_DEVICE_ENTRY__ND_TYPE__VETH:
>  		return restore_one_link(nde, nlsk, veth_link_info);
> -	case ND_TYPE__TUN:
> +	case NET_DEVICE_ENTRY__ND_TYPE__TUN:
>  		return restore_one_tun(nde, nlsk);
>  	default:
>  		pr_err("Unsupported link type %d\n", nde->type);
> diff --git a/protobuf/netdev.proto b/protobuf/netdev.proto
> index 4fa23d3..b526ace 100644
> --- a/protobuf/netdev.proto
> +++ b/protobuf/netdev.proto
> @@ -1,19 +1,19 @@
>  import "tun.proto";
>  
> -enum nd_type {
> -	LOOPBACK	= 1;
> -	VETH		= 2;
> -	TUN		= 3;
> -	/*
> -	 * External link -- for those CRIU only dumps and restores
> -	 * link parameters such as flags, address, MTU, etc. The
> -	 * existence of the link on restore should be provided
> -	 * by the setup-namespaces script.
> -	 */
> -	EXTLINK		= 4;
> -}
> -
>  message net_device_entry {
> +	enum nd_type {
> +		LOOPBACK	= 1;
> +		VETH		= 2;
> +		TUN		= 3;
> +		/*
> +		 * External link -- for those CRIU only dumps and restores
> +		 * link parameters such as flags, address, MTU, etc. The
> +		 * existence of the link on restore should be provided
> +		 * by the setup-namespaces script.
> +		 */
> +		EXTLINK		= 4;
> +	}
> +
>  	required nd_type type		= 1;
>  	required uint32  ifindex	= 2;
>  	required uint32  mtu		= 3;
> 



More information about the CRIU mailing list