[CRIU] [PATCH v2 5/6] net: add support for macvlan link types

Tycho Andersen tycho.andersen at canonical.com
Mon Oct 17 15:50:49 PDT 2016


On Mon, Oct 17, 2016 at 08:33:29AM -0600, Tycho Andersen wrote:
> > > +		struct newlink_extras extras = {
> > > +			.netns_id = -1,
> > > +			.link = -1,
> > > +			.target_netns = -1,
> > > +		};
> > > +		char key[100], *val;
> > > +
> > > +		snprintf(key, sizeof(key), "macvlan[%s]", nde->name);
> > > +		val = external_lookup_data(key);
> > > +		if (IS_ERR_OR_NULL(val)) {
> > > +			pr_err("a macvlan parent for %s is required\n", nde->name);
> > > +			return -1;
> > > +		}
> > > +
> > > +		extras.link = (int) (unsigned long) val;
> > >  
> > > +		extras.netns_id = get_criu_netnsid(nlsk);
> > > +		if (extras.netns_id < 0) {
> > > +			pr_err("failed to get criu's netnsid\n");
> > > +			return -1;
> > > +		}
> > > +
> > > +		if (root_ns_mask & CLONE_NEWUSER) {
> > > +			struct newlink_req req;
> > > +
> > > +			if (populate_newlink_req(&req, RTM_NEWLINK, nde, macvlan_link_info, &extras) < 0)
> > > +				return -1;
> > > +
> > > +			if (userns_call(userns_restore_one_link, 0, &req, sizeof(req), -1) < 0) {
> > > +				pr_err("couldn't restore macvlan interface %s via usernsd\n", nde->name);
> > > +				return -1;
> > > +			}
> > > +		} else {
> > > +			int my_netns, ret, root_nlsk;
> > > +			int ns_fd = get_service_fd(NS_FD_OFF);
> > > +
> > > +			my_netns = open_proc(PROC_SELF, "ns/net");
> > > +			if (my_netns < 0) {
> > > +				pr_perror("couldn't get my netns");
> > > +				return -1;
> > > +			}
> > > +
> > > +			extras.target_netns = my_netns;
> > 
> > For userns case the target netns is identified by pid.
> > Can we do it the same way here?
> 
> Yep, I think so. I just used this because we already had the ns fd
> open, but I can switch it.

Oh, I guess we can't because e.g. in the test suite, nested pid
namespacing means that the lookup in IFLA_NET_NS_PID by absolute pid
fails. I think this will fail in the other case too, and we should
really use NET_NS_FD in both cases. I'll switch the userns case to
that too.

Tycho


More information about the CRIU mailing list