-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support time namespace #3876
Support time namespace #3876
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -104,6 +104,10 @@ struct nlconfig_t { | |||||||||||||
/* Idmap sources opened outside the container userns which will be id mapped. */ | ||||||||||||||
char *idmapsources; | ||||||||||||||
size_t idmapsources_len; | ||||||||||||||
|
||||||||||||||
/* Time NS offsets. */ | ||||||||||||||
char *timensoffset; | ||||||||||||||
size_t timensoffset_len; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
/* | ||||||||||||||
|
@@ -122,6 +126,7 @@ struct nlconfig_t { | |||||||||||||
#define GIDMAPPATH_ATTR 27289 | ||||||||||||||
#define MOUNT_SOURCES_ATTR 27290 | ||||||||||||||
#define IDMAP_SOURCES_ATTR 27291 | ||||||||||||||
#define TIMENSOFFSET_ATTR 27292 | ||||||||||||||
|
||||||||||||||
chethanah marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
/* | ||||||||||||||
* Use the raw syscall for versions of glibc which don't include a function for | ||||||||||||||
|
@@ -351,6 +356,8 @@ static int nsflag(char *name) | |||||||||||||
return CLONE_NEWUSER; | ||||||||||||||
else if (!strcmp(name, "uts")) | ||||||||||||||
return CLONE_NEWUTS; | ||||||||||||||
else if (!strcmp(name, "time")) | ||||||||||||||
return CLONE_NEWTIME; | ||||||||||||||
|
||||||||||||||
/* If we don't recognise a name, fallback to 0. */ | ||||||||||||||
return 0; | ||||||||||||||
|
@@ -445,6 +452,10 @@ static void nl_parse(int fd, struct nlconfig_t *config) | |||||||||||||
config->idmapsources = current; | ||||||||||||||
config->idmapsources_len = payload_len; | ||||||||||||||
break; | ||||||||||||||
case TIMENSOFFSET_ATTR: | ||||||||||||||
config->timensoffset = current; | ||||||||||||||
config->timensoffset_len = payload_len; | ||||||||||||||
break; | ||||||||||||||
default: | ||||||||||||||
bail("unknown netlink message type %d", nlattr->nla_type); | ||||||||||||||
} | ||||||||||||||
|
@@ -747,6 +758,17 @@ void receive_idmapsources(int sockfd) | |||||||||||||
receive_fd_sources(sockfd, "_LIBCONTAINER_IDMAP_FDS"); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
static void update_timens(char *map, size_t map_len) | ||||||||||||||
{ | ||||||||||||||
if (map == NULL || map_len == 0) | ||||||||||||||
return; | ||||||||||||||
write_log(DEBUG, "update /proc/self/timens_offsets to '%s'", map); | ||||||||||||||
if (write_file(map, map_len, "/proc/self/timens_offsets") < 0) { | ||||||||||||||
if (errno != EPERM) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. I think this was mistakenly copied from the |
||||||||||||||
bail("failed to update /proc/self/timens_offsets"); | ||||||||||||||
} | ||||||||||||||
Comment on lines
+766
to
+769
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
void nsexec(void) | ||||||||||||||
{ | ||||||||||||||
int pipenum; | ||||||||||||||
|
@@ -1185,6 +1207,11 @@ void nsexec(void) | |||||||||||||
bail("failed to sync with parent: SYNC_MOUNT_IDMAP_ACK: got %u", s); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/* | ||||||||||||||
* set boottime and monotonic timens offsets. | ||||||||||||||
*/ | ||||||||||||||
update_timens(config.timensoffset, config.timensoffset_len); | ||||||||||||||
|
||||||||||||||
/* | ||||||||||||||
* TODO: What about non-namespace clone flags that we're dropping here? | ||||||||||||||
* | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ func initMaps() { | |
specs.IPCNamespace: configs.NEWIPC, | ||
specs.UTSNamespace: configs.NEWUTS, | ||
specs.CgroupNamespace: configs.NEWCGROUP, | ||
specs.TimeNamespace: configs.NEWTIME, | ||
} | ||
|
||
mountPropagationMapping = map[string]int{ | ||
|
@@ -435,6 +436,9 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) { | |
MemBwSchema: spec.Linux.IntelRdt.MemBwSchema, | ||
} | ||
} | ||
|
||
// update timens offsets | ||
config.TimeOffsets = spec.Linux.TimeOffsets | ||
Comment on lines
+439
to
+441
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: perhaps you can move this to be right after these lines: config.MaskPaths = spec.Linux.MaskedPaths
config.ReadonlyPaths = spec.Linux.ReadonlyPaths
config.MountLabel = spec.Linux.MountLabel
config.Sysctl = spec.Linux.Sysctl and drop the comment since it's kind of obvious what we do here. |
||
} | ||
|
||
// Set the host UID that should own the container's cgroup. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect we want this check to be done in the validator (at is stands, the code will silently ignore
timensOffsets
being configured withoutCLONE_NEWTIME
enabled). But I can do this in a separate PR when I add the necessary integration tests for this feature.