[CRIU] [PATCH 1/3] net: Extrack ioctl() call from kerndat_socket_netns()

Andrei Vagin avagin at virtuozzo.com
Wed Feb 28 23:08:18 MSK 2018


On Mon, Feb 19, 2018 at 03:16:02PM +0300, Kirill Tkhai wrote:
> Refactoring, no functional change.
> 
> Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
> ---
>  criu/include/net.h |    1 +
>  criu/net.c         |   26 +++++++++++++++-----------
>  2 files changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/criu/include/net.h b/criu/include/net.h
> index 796dcc415..74f0969ad 100644
> --- a/criu/include/net.h
> +++ b/criu/include/net.h
> @@ -48,5 +48,6 @@ extern int move_veth_to_bridge(void);
>  extern int kerndat_link_nsid(void);
>  extern int net_get_nsid(int rtsk, int fd, int *nsid);
>  extern int kerndat_nsid(void);
> +extern void check_has_netns_ioc(int fd, bool *kdat_val, const char *name);
>  
>  #endif /* __CR_NET_H__ */
> diff --git a/criu/net.c b/criu/net.c
> index 0176873e0..f9114dd25 100644
> --- a/criu/net.c
> +++ b/criu/net.c
> @@ -2720,26 +2720,30 @@ struct ns_id *get_socket_ns(int lfd)
>  	return ns;
>  }
>  
> +void check_has_netns_ioc(int fd, bool *kdat_val, const char *name)

static void check_has_netns_ioc ...

> +{
> +	int ns_fd;
> +
> +	ns_fd = ioctl(fd, SIOCGSKNS);
> +	*kdat_val = (ns_fd >= 0);
> +
> +	if (ns_fd < 0)
> +		pr_warn("Unable to get %s network namespace\n", name);
> +	else
> +		close(ns_fd);
> +}
> +
>  int kerndat_socket_netns(void)
>  {
> -	int sk, ns_fd;
> +	int sk;
>  
>  	sk = socket(AF_UNIX, SOCK_DGRAM, 0);
>  	if (sk < 0) {
>  		pr_perror("Unable to create socket");
>  		return -1;
>  	}
> -	ns_fd = ioctl(sk, SIOCGSKNS);
> -	if (ns_fd < 0) {
> -		pr_warn("Unable to get a socket network namespace\n");
> -		kdat.sk_ns = false;
> -		close(sk);
> -		return 0;
> -	}
> +	check_has_netns_ioc(sk, &kdat.sk_ns, "socket");
>  	close(sk);
> -	close(ns_fd);
> -
> -	kdat.sk_ns = true;
>  
>  	return 0;
>  }
> 


More information about the CRIU mailing list