| 536 | |
| 537 | |
| 538 | Try<string> getParentShmPath( |
| 539 | const string runtimeDir, |
| 540 | const ContainerID& containerId) |
| 541 | { |
| 542 | CHECK(containerId.has_parent()); |
| 543 | |
| 544 | ContainerID parentId = containerId.parent(); |
| 545 | |
| 546 | Result<ContainerConfig> parentConfig = |
| 547 | getContainerConfig(runtimeDir, parentId); |
| 548 | |
| 549 | if (parentConfig.isNone()) { |
| 550 | return Error( |
| 551 | "Failed to find config for container " + stringify(parentId)); |
| 552 | } else if (parentConfig.isError()) { |
| 553 | return Error(parentConfig.error()); |
| 554 | } |
| 555 | |
| 556 | string parentShmPath; |
| 557 | |
| 558 | if (parentConfig->has_container_info() && |
| 559 | parentConfig->container_info().has_linux_info() && |
| 560 | parentConfig->container_info().linux_info().has_ipc_mode()) { |
| 561 | switch (parentConfig->container_info().linux_info().ipc_mode()) { |
| 562 | case LinuxInfo::PRIVATE: { |
| 563 | const string shmPath = getContainerShmPath(runtimeDir, parentId); |
| 564 | if (!os::exists(shmPath)) { |
| 565 | return Error( |
| 566 | "The shared memory path '" + shmPath + "' of container " |
| 567 | + stringify(parentId) + " does not exist"); |
| 568 | } |
| 569 | |
| 570 | parentShmPath = shmPath; |
| 571 | break; |
| 572 | } |
| 573 | case LinuxInfo::SHARE_PARENT: { |
| 574 | if (parentId.has_parent()) { |
| 575 | return getParentShmPath(runtimeDir, parentId); |
| 576 | } |
| 577 | |
| 578 | parentShmPath = AGENT_SHM_DIRECTORY; |
| 579 | break; |
| 580 | } |
| 581 | case LinuxInfo::UNKNOWN: { |
| 582 | LOG(FATAL) << "The IPC mode of container " << parentId << " is UNKNOWN"; |
| 583 | } |
| 584 | } |
| 585 | } else { |
| 586 | if (parentConfig->has_rootfs()) { |
| 587 | return Error( |
| 588 | "The shared memory of container " + stringify(parentId) + |
| 589 | " cannot be shared with any other containers because it" |
| 590 | " is only in the container's own mount namespace"); |
| 591 | } |
| 592 | |
| 593 | parentShmPath = AGENT_SHM_DIRECTORY; |
| 594 | } |
| 595 |
no test coverage detected