Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
0fa988d1
Commit
0fa988d1
authored
Nov 02, 2016
by
Christian Brauner
Committed by
GitHub
Nov 02, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1269 from Blub/phynet-rename-2
conf: merge network namespace move & rename on shutdown
parents
59f1c5ca
5610055a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
23 deletions
+10
-23
conf.c
src/lxc/conf.c
+8
-21
conf.h
src/lxc/conf.h
+1
-1
start.c
src/lxc/start.c
+1
-1
No files found.
src/lxc/conf.c
View file @
0fa988d1
...
@@ -2397,15 +2397,17 @@ static int setup_network(struct lxc_list *network)
...
@@ -2397,15 +2397,17 @@ static int setup_network(struct lxc_list *network)
}
}
/* try to move physical nics to the init netns */
/* try to move physical nics to the init netns */
void
restore_phys_nics_to_netns
(
int
netnsfd
,
struct
lxc_conf
*
conf
)
void
lxc_
restore_phys_nics_to_netns
(
int
netnsfd
,
struct
lxc_conf
*
conf
)
{
{
int
i
,
ret
,
oldfd
;
int
i
,
ret
,
oldfd
;
char
path
[
MAXPATHLEN
];
char
path
[
MAXPATHLEN
];
char
ifname
[
IFNAMSIZ
];
char
ifname
[
IFNAMSIZ
];
if
(
netnsfd
<
0
)
if
(
netnsfd
<
0
||
conf
->
num_savednics
==
0
)
return
;
return
;
INFO
(
"running to reset %d nic names"
,
conf
->
num_savednics
);
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"/proc/self/ns/net"
);
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"/proc/self/ns/net"
);
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
{
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
{
WARN
(
"Failed to open monitor netns fd"
);
WARN
(
"Failed to open monitor netns fd"
);
...
@@ -2427,32 +2429,17 @@ void restore_phys_nics_to_netns(int netnsfd, struct lxc_conf *conf)
...
@@ -2427,32 +2429,17 @@ void restore_phys_nics_to_netns(int netnsfd, struct lxc_conf *conf)
WARN
(
"no interface corresponding to index '%d'"
,
s
->
ifindex
);
WARN
(
"no interface corresponding to index '%d'"
,
s
->
ifindex
);
continue
;
continue
;
}
}
if
(
lxc_netdev_move_by_name
(
ifname
,
1
,
NULL
))
if
(
lxc_netdev_move_by_name
(
ifname
,
1
,
s
->
orig_name
))
WARN
(
"Error moving nic name:%s back to host netns"
,
ifname
);
WARN
(
"Error moving nic name:%s back to host netns"
,
ifname
);
free
(
s
->
orig_name
);
}
}
conf
->
num_savednics
=
0
;
if
(
setns
(
oldfd
,
0
)
!=
0
)
if
(
setns
(
oldfd
,
0
)
!=
0
)
SYSERROR
(
"Failed to re-enter monitor's netns"
);
SYSERROR
(
"Failed to re-enter monitor's netns"
);
close
(
oldfd
);
close
(
oldfd
);
}
}
void
lxc_rename_phys_nics_on_shutdown
(
int
netnsfd
,
struct
lxc_conf
*
conf
)
{
int
i
;
if
(
conf
->
num_savednics
==
0
)
return
;
INFO
(
"running to reset %d nic names"
,
conf
->
num_savednics
);
restore_phys_nics_to_netns
(
netnsfd
,
conf
);
for
(
i
=
0
;
i
<
conf
->
num_savednics
;
i
++
)
{
struct
saved_nic
*
s
=
&
conf
->
saved_nics
[
i
];
INFO
(
"resetting nic %d to %s"
,
s
->
ifindex
,
s
->
orig_name
);
lxc_netdev_rename_by_index
(
s
->
ifindex
,
s
->
orig_name
);
free
(
s
->
orig_name
);
}
conf
->
num_savednics
=
0
;
}
static
char
*
default_rootfs_mount
=
LXCROOTFSMOUNT
;
static
char
*
default_rootfs_mount
=
LXCROOTFSMOUNT
;
struct
lxc_conf
*
lxc_conf_init
(
void
)
struct
lxc_conf
*
lxc_conf_init
(
void
)
...
...
src/lxc/conf.h
View file @
0fa988d1
...
@@ -440,7 +440,7 @@ extern int do_rootfs_setup(struct lxc_conf *conf, const char *name,
...
@@ -440,7 +440,7 @@ extern int do_rootfs_setup(struct lxc_conf *conf, const char *name,
struct
cgroup_process_info
;
struct
cgroup_process_info
;
extern
int
lxc_setup
(
struct
lxc_handler
*
handler
);
extern
int
lxc_setup
(
struct
lxc_handler
*
handler
);
extern
void
lxc_re
name_phys_nics_on_shutdown
(
int
netnsfd
,
struct
lxc_conf
*
conf
);
extern
void
lxc_re
store_phys_nics_to_netns
(
int
netnsfd
,
struct
lxc_conf
*
conf
);
extern
int
find_unmapped_nsuid
(
struct
lxc_conf
*
conf
,
enum
idtype
idtype
);
extern
int
find_unmapped_nsuid
(
struct
lxc_conf
*
conf
,
enum
idtype
idtype
);
extern
int
mapped_hostid
(
unsigned
id
,
struct
lxc_conf
*
conf
,
enum
idtype
idtype
);
extern
int
mapped_hostid
(
unsigned
id
,
struct
lxc_conf
*
conf
,
enum
idtype
idtype
);
...
...
src/lxc/start.c
View file @
0fa988d1
...
@@ -1420,7 +1420,7 @@ int __lxc_start(const char *name, struct lxc_conf *conf,
...
@@ -1420,7 +1420,7 @@ int __lxc_start(const char *name, struct lxc_conf *conf,
}
}
DEBUG
(
"Pushing physical nics back to host namespace"
);
DEBUG
(
"Pushing physical nics back to host namespace"
);
lxc_re
name_phys_nics_on_shutdown
(
netnsfd
,
handler
->
conf
);
lxc_re
store_phys_nics_to_netns
(
netnsfd
,
handler
->
conf
);
DEBUG
(
"Tearing down virtual network devices used by container"
);
DEBUG
(
"Tearing down virtual network devices used by container"
);
lxc_delete_network
(
handler
);
lxc_delete_network
(
handler
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment