2020-04-23 11:50:43 +08:00
|
|
|
From 288b6934f79456f056a2043216bbfdde4342b694 Mon Sep 17 00:00:00 2001
|
2019-09-30 11:03:07 -04:00
|
|
|
From: liuhao <liuhao27@huawei.com>
|
|
|
|
|
Date: Fri, 26 Apr 2019 07:13:53 +0800
|
2020-04-23 11:50:43 +08:00
|
|
|
Subject: [PATCH 47/49] support namespaced kernel params can be changed in
|
|
|
|
|
system container
|
2019-09-30 11:03:07 -04:00
|
|
|
|
|
|
|
|
Signed-off-by: yangchenliang <yangchenliang@huawei.com>
|
|
|
|
|
---
|
2020-04-23 11:50:43 +08:00
|
|
|
src/lxc/conf.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
1 file changed, 71 insertions(+)
|
2019-09-30 11:03:07 -04:00
|
|
|
|
|
|
|
|
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
|
2020-04-23 11:50:43 +08:00
|
|
|
index 235965f..15d8e42 100644
|
2019-09-30 11:03:07 -04:00
|
|
|
--- a/src/lxc/conf.c
|
|
|
|
|
+++ b/src/lxc/conf.c
|
2020-04-23 11:50:43 +08:00
|
|
|
@@ -1449,6 +1449,68 @@ error:
|
2019-09-30 11:03:07 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-23 11:50:43 +08:00
|
|
|
+#ifdef HAVE_ISULAD
|
2019-09-30 11:03:07 -04:00
|
|
|
+static bool remount_readwrite(const char *path)
|
|
|
|
|
+{
|
|
|
|
|
+ int ret, i;
|
|
|
|
|
+
|
|
|
|
|
+ if (!path)
|
|
|
|
|
+ return true;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < 5; i++) {
|
|
|
|
|
+ ret = mount("", path, "", MS_REMOUNT, "");
|
|
|
|
|
+ if (ret < 0 && errno != ENOENT) {
|
|
|
|
|
+ if (errno == EINVAL) {
|
|
|
|
|
+ // Probably not a mountpoint, use bind-mount
|
|
|
|
|
+ ret = mount(path, path, "", MS_BIND, "");
|
|
|
|
|
+ if (ret < 0)
|
|
|
|
|
+ goto on_error;
|
|
|
|
|
+ ret = mount(path, path, "", MS_BIND | MS_REMOUNT | MS_REC | \
|
|
|
|
|
+ MS_NOEXEC | MS_NOSUID | MS_NODEV, "");
|
|
|
|
|
+ if (ret < 0)
|
|
|
|
|
+ goto on_error;
|
|
|
|
|
+ } else if (errno == EBUSY) {
|
|
|
|
|
+ DEBUG("Try to mount \"%s\" to readonly after 100ms.", path);
|
|
|
|
|
+ usleep(100 * 1000);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ goto on_error;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+on_error:
|
|
|
|
|
+ SYSERROR("Unable to mount \"%s\" to readwrite", path);
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
|
|
+
|
2020-04-23 11:50:43 +08:00
|
|
|
+static int remount_proc_sys_mount_entries(struct lxc_list *mount_list, bool lsm_aa_allow_nesting)
|
2019-09-30 11:03:07 -04:00
|
|
|
+{
|
|
|
|
|
+ char buf[4096];
|
|
|
|
|
+ FILE *file;
|
|
|
|
|
+ struct mntent mntent;
|
|
|
|
|
+
|
2020-04-23 11:50:43 +08:00
|
|
|
+ file = make_anonymous_mount_file(mount_list, lsm_aa_allow_nesting);
|
2019-09-30 11:03:07 -04:00
|
|
|
+ if (!file)
|
|
|
|
|
+ return -1;
|
|
|
|
|
+
|
|
|
|
|
+ while (getmntent_r(file, &mntent, buf, sizeof(buf))) {
|
|
|
|
|
+ if (strstr(mntent.mnt_dir, "proc/sys") == NULL) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!remount_readwrite((const char*)mntent.mnt_dir)) {
|
|
|
|
|
+ fclose(file);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fclose(file);
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
2020-04-23 11:50:43 +08:00
|
|
|
+#endif
|
2019-09-30 11:03:07 -04:00
|
|
|
+
|
|
|
|
|
// remount_readonly will bind over the top of an existing path and ensure that it is read-only.
|
|
|
|
|
static bool remount_readonly(const char *path)
|
|
|
|
|
{
|
2020-04-23 11:50:43 +08:00
|
|
|
@@ -4773,6 +4835,15 @@ int lxc_setup(struct lxc_handler *handler)
|
2019-09-30 11:03:07 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //isulad: system container, remount /proc/sys/xxx by mount_list
|
|
|
|
|
+ if (lxc_conf->systemd != NULL && strcmp(lxc_conf->systemd, "true") == 0) {
|
|
|
|
|
+ if (!lxc_list_empty(&lxc_conf->mount_list)) {
|
2020-04-23 11:50:43 +08:00
|
|
|
+ if (remount_proc_sys_mount_entries(&lxc_conf->mount_list, lxc_conf->lsm_aa_allow_nesting)) {
|
|
|
|
|
+ return log_error(-1, "failed to remount /proc/sys");
|
2019-09-30 11:03:07 -04:00
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
2020-04-23 11:50:43 +08:00
|
|
|
// isulad: create link /etc/mtab for /proc/mounts
|
|
|
|
|
if (create_mtab_link() != 0) {
|
|
|
|
|
return log_error(-1, "failed to create link /etc/mtab for target /proc/mounts");
|
2019-09-30 11:03:07 -04:00
|
|
|
--
|
2020-01-05 22:20:49 -05:00
|
|
|
1.8.3.1
|
2019-09-30 11:03:07 -04:00
|
|
|
|