When a physical nic is being set up, store its ifindex and original name
in struct lxc_conf. At reboot, reset the original name.
We can't just go over the original network list in lxc_conf at shutdown
because that may be tweaked in the meantime through the C api. The
saved_nics list is only setup during lxc_spawn(), and restored and
freed after lxc_start.
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/
1086244
Changelog: remove non-effect change in execute.c
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
return 0;
}
+void lxc_rename_phys_nics_on_shutdown(struct lxc_conf *conf)
+{
+ int i;
+
+ INFO("running to reset %d nic names", conf->num_savednics);
+ for (i=0; i<conf->num_savednics; i++) {
+ struct saved_nic *s = &conf->saved_nics[i];
+ INFO("resetting nic %d to %s\n", s->ifindex, s->orig_name);
+ lxc_netdev_rename_by_index(s->ifindex, s->orig_name);
+ free(s->orig_name);
+ }
+ conf->num_savednics = 0;
+ free(conf->saved_nics);
+}
+
static int setup_private_host_hw_addr(char *veth1)
{
struct ifreq ifr;
return 0;
}
+void lxc_clear_saved_nics(struct lxc_conf *conf)
+{
+ int i;
+
+ if (!conf->num_savednics)
+ return;
+ for (i=0; i < conf->num_savednics; i++)
+ free(conf->saved_nics[i].orig_name);
+ conf->saved_nics = 0;
+ free(conf->saved_nics);
+}
+
void lxc_conf_free(struct lxc_conf *conf)
{
if (!conf)
lxc_clear_cgroups(conf, "lxc.cgroup");
lxc_clear_hooks(conf, "lxc.hook");
lxc_clear_mount_entries(conf);
+ lxc_clear_saved_nics(conf);
free(conf);
}
LXCHOOK_POSTSTOP, NUM_LXC_HOOKS};
extern char *lxchook_names[NUM_LXC_HOOKS];
+struct saved_nic {
+ int ifindex;
+ char *orig_name;
+};
+
struct lxc_conf {
char *fstab;
int tty;
struct utsname *utsname;
struct lxc_list cgroup;
struct lxc_list network;
+ struct saved_nic *saved_nics;
+ int num_savednics;
struct lxc_list mount_list;
struct lxc_list caps;
struct lxc_tty_info tty_info;
*/
extern int lxc_setup(const char *name, struct lxc_conf *lxc_conf);
+
+extern void lxc_rename_phys_nics_on_shutdown(struct lxc_conf *conf);
#endif
#include <unistd.h>
#include <stdlib.h>
-
#include "log.h"
#include "start.h"
return -1;
}
+int save_phys_nics(struct lxc_conf *conf)
+{
+ struct lxc_list *iterator;
+
+ lxc_list_for_each(iterator, &conf->network) {
+ struct lxc_netdev *netdev = iterator->elem;
+
+ if (netdev->type != LXC_NET_PHYS)
+ continue;
+ conf->saved_nics = realloc(conf->saved_nics,
+ (conf->num_savednics+1)*sizeof(struct saved_nic));
+ if (!conf->saved_nics) {
+ SYSERROR("failed to allocate memory");
+ return -1;
+ }
+ conf->saved_nics[conf->num_savednics].ifindex = netdev->ifindex;
+ conf->saved_nics[conf->num_savednics].orig_name = strdup(netdev->link);
+ if (!conf->saved_nics[conf->num_savednics].orig_name) {
+ SYSERROR("failed to allocate memory");
+ return -1;
+ }
+ INFO("stored saved_nic #%d idx %d name %s\n", conf->num_savednics,
+ conf->saved_nics[conf->num_savednics].ifindex,
+ conf->saved_nics[conf->num_savednics].orig_name);
+ conf->num_savednics++;
+ }
+
+ return 0;
+}
+
+
int lxc_spawn(struct lxc_handler *handler)
{
int failed_before_rename = 0;
}
}
+ if (save_phys_nics(handler->conf)) {
+ ERROR("failed to save physical nic info");
+ goto out_abort;
+ }
+
/*
* if the rootfs is not a blockdev, prevent the container from
* marking it readonly.
}
}
+ lxc_rename_phys_nics_on_shutdown(handler->conf);
+
err = lxc_error_set_and_log(handler->pid, status);
out_fini:
lxc_delete_network(handler);