[Devel] [PATCH v5 5/6] automatically add bridge venet0 when needed

Kir Kolyshkin kir at openvz.org
Sun May 19 10:41:33 PDT 2013


Committed with fixes, see inline.

On 05/17/2013 09:26 AM, Glauber Costa wrote:
> From: Glauber Costa <glommer at parallels.com>
>
> The chosen architecture to deal with --ipadd with upstream containers is to
> create a veth pair and add the host side information to a bridge called venet0.
> This way, all the code that expects venet0 to exist can still work without
> modifications, (or with just a few).
>
> Our intention to do that was actually already stated in the comments, but the
> code was removed before merging because --ipadd would not work without full
> unshare support anyway.
>
> This patch implements that.
>
> Signed-off-by: Glauber Costa <glommer at parallels.com>
> ---
>   scripts/vps-functions.in |  7 +++++++
>   src/lib/hooks_ct.c       | 37 +++++++++++++++++++++++++++++++++++--
>   2 files changed, 42 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/vps-functions.in b/scripts/vps-functions.in
> index 826c0a1..37b2de5 100755
> --- a/scripts/vps-functions.in
> +++ b/scripts/vps-functions.in
> @@ -170,6 +170,13 @@ vzadjustmacs()
>   # other setups, the bridge is expected to already exist and be valid.
>   vzconfbridge()
>   {
> +	if [ "x$BRIDGE" == "xvenet0" ]; then

operator == is bash-specific. It is either = (for strings) or -eq (for 
numbers)

> +		if [ $(brctl show venet0 2>/dev/null | tail -n+2 | wc -l) == 0 ]; then

ditto

> +			brctl addbr venet0
> +			${IP_CMD} link set venet0 up
> +		fi
> +	fi
> +	

whitespace at eol

>   	if [ "x$BRIDGE" != "x" ]; then
>   		brctl addif $BRIDGE $HNAME >/dev/null 2>&1
>   	fi
> diff --git a/src/lib/hooks_ct.c b/src/lib/hooks_ct.c
> index 299d43d..f002fa0 100644
> --- a/src/lib/hooks_ct.c
> +++ b/src/lib/hooks_ct.c
> @@ -17,6 +17,7 @@
>   #include "logger.h"
>   #include "script.h"
>   #include "cgroup.h"
> +#include "linux/vzctl_venet.h"
>   
>   #define NETNS_RUN_DIR "/var/run/netns"
>   
> @@ -731,8 +732,40 @@ static int ct_netdev_ctl(vps_handler *h, envid_t veid, int op, char *name)
>   
>   static int ct_ip_ctl(vps_handler *h, envid_t veid, int op, const char *ipstr)
>   {
> -	logger(-1, 0, "%s not yet supported upstream", __func__);
> -	return 0;
> +	int ret = -1;
> +	char *envp[5];
> +	char buf[STR_SIZE];
> +	int i = 0;
> +
> +	if (!h->can_join_pidns) {
> +		logger(-1, 0, "Cannot join pid namespace: "
> +		"--ipadd is not supported in kernels without full pidns support");

Strange indentation :-\

> +		return VZ_BAD_KERNEL;
> +	}
> +	envp[i++] = strdup("VNAME=venet0");
> +	envp[i++] = strdup("BRIDGE=venet0");
> +
> +	snprintf(buf, sizeof(buf), "HNAME=venet0.%d", veid);
> +	envp[i++] = strdup(buf);
> +
> +	snprintf(buf, sizeof(buf), "VEID=%d", veid);
> +	envp[i++] = strdup(buf);
> +
> +	envp[i] = NULL;
> +
> +	if (op == VE_IP_ADD) {
> +		char *argv[] = { VPS_NETNS_DEV_ADD, NULL };
> +
> +		ret = run_script(VPS_NETNS_DEV_ADD, argv, envp, 0);
> +	} else  {
> +		char *argv[] = { VPS_NETNS_DEV_DEL, NULL };
> +
> +		ret = run_script(VPS_NETNS_DEV_DEL, argv, envp, 0);
> +	}
> +	free_arg(envp);
> +
> +	return ret;
> +
>   }
>   
>   /*




More information about the Devel mailing list