Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/schema/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,9 @@
"disable_xdp": {
"type": "boolean"
},
"enable_pipewire": {
"type": "boolean"
},
"mounts": {
"type": "array",
"items": {
Expand Down
2 changes: 2 additions & 0 deletions api/schema/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ $defs:
$ref: '#/$defs/DeviceOption'
disable_xdp:
type: boolean
enable_pipewire:
type: boolean
mounts:
type: array
items:
Expand Down
5 changes: 5 additions & 0 deletions apps/ll-cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ ll-cli run org.deepin.demo -- bash -x /path/to/bash/script)"));
runOptions.disableXdp,
_("Enable or disable xdg-desktop-portal related integration inside the sandbox"))
->take_last();
cliRun
->add_flag("--enable-pipewire",
runOptions.enablePipewireSocketMount,
_("Enable PipeWire socket mount inside the sandbox"))
->take_last();
cliRun->add_option("--run-context", runOptions.runContext, _("Run context json string"))
->group("");
cliRun
Expand Down
4 changes: 4 additions & 0 deletions libs/api/src/linglong/api/types/v1/Generators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ inline void from_json(const json & j, RuntimeConfigure& x) {
x.deviceMode = get_stack_optional<std::vector<DeviceOption>>(j, "device_mode");
x.devices = get_stack_optional<std::vector<std::string>>(j, "devices");
x.disableXdp = get_stack_optional<bool>(j, "disable_xdp");
x.enablePipewireSocketMount = get_stack_optional<bool>(j, "enable_pipewire");
x.env = get_stack_optional<std::map<std::string, std::string>>(j, "env");
x.extDefs = get_stack_optional<std::map<std::string, std::vector<ExtensionDefine>>>(j, "ext_defs");
x.instances = get_stack_optional<std::map<std::string, RuntimeConfigure>>(j, "instances");
Expand All @@ -1330,6 +1331,9 @@ j["devices"] = x.devices;
if (x.disableXdp) {
j["disable_xdp"] = x.disableXdp;
}
if (x.enablePipewireSocketMount) {
j["enable_pipewire"] = x.enablePipewireSocketMount;
}
if (x.env) {
j["env"] = x.env;
}
Expand Down
1 change: 1 addition & 0 deletions libs/api/src/linglong/api/types/v1/RuntimeConfigure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct RuntimeConfigure {
std::optional<std::vector<DeviceOption>> deviceMode;
std::optional<std::vector<std::string>> devices;
std::optional<bool> disableXdp;
std::optional<bool> enablePipewireSocketMount;
std::optional<std::map<std::string, std::string>> env;
/**
* external extension definitions to extend the component
Expand Down
1 change: 1 addition & 0 deletions libs/linglong/src/linglong/cli/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct RunOptions
std::optional<std::string> workdir;
std::vector<std::string> extensions;
std::optional<bool> disableXdp;
std::optional<bool> enablePipewireSocketMount;
bool privileged{ false };
std::vector<std::string> capsAdd;
std::vector<std::string> cdiSpecDir = { "/etc/cdi", "/var/run/cdi" };
Expand Down
19 changes: 19 additions & 0 deletions libs/linglong/src/linglong/runtime/container_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

#include "linglong/runtime/container_builder.h"

#include "linglong/cli/cli.h"

Check warning on line 9 in libs/linglong/src/linglong/runtime/container_builder.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/cli/cli.h" not found.
#include "linglong/common/dir.h"

Check warning on line 10 in libs/linglong/src/linglong/runtime/container_builder.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/common/dir.h" not found.
#include "linglong/common/strings.h"

Check warning on line 11 in libs/linglong/src/linglong/runtime/container_builder.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/common/strings.h" not found.
#include "linglong/common/xdg.h"

Check warning on line 12 in libs/linglong/src/linglong/runtime/container_builder.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/oci-cfg-generators/container_cfg_builder.h" not found.
#include "linglong/oci-cfg-generators/container_cfg_builder.h"

Check warning on line 13 in libs/linglong/src/linglong/runtime/container_builder.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/package/architecture.h" not found.
#include "linglong/package/architecture.h"

Check warning on line 14 in libs/linglong/src/linglong/runtime/container_builder.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/runtime/run_context.h" not found.
#include "linglong/runtime/run_context.h"

Check warning on line 15 in libs/linglong/src/linglong/runtime/container_builder.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "linglong/utils/log/log.h" not found.
#include "linglong/utils/log/log.h"

#include <fmt/format.h>
Expand Down Expand Up @@ -130,6 +131,10 @@
this->disableXdp = *runtimeConfig.disableXdp;
}

if (runtimeConfig.enablePipewireSocketMount.has_value()) {
this->enablePipewireSocketMount = *runtimeConfig.enablePipewireSocketMount;

Check warning on line 135 in libs/linglong/src/linglong/runtime/container_builder.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Consider using std::any_of algorithm instead of a raw loop.
}

if (runtimeConfig.deviceMode) {
for (const auto &option : *runtimeConfig.deviceMode) {
if (option == api::types::v1::DeviceOption::Passthru) {
Expand Down Expand Up @@ -172,6 +177,10 @@
if (options.disableXdp.has_value()) {
this->disableXdp = *options.disableXdp;
}

if (options.enablePipewireSocketMount.has_value()) {
this->enablePipewireSocketMount = *options.enablePipewireSocketMount;
}
this->privileged = options.privileged;
this->capabilities.insert(this->capabilities.end(),
options.capsAdd.begin(),
Expand Down Expand Up @@ -211,6 +220,11 @@
return this->devicePassthru;
}

auto RunContainerOptions::isPipewireSocketMountEnabled() const noexcept -> bool
{
return this->enablePipewireSocketMount;
}

auto RunContainerOptions::isXdpDisabled() const noexcept -> bool
{
return this->disableXdp;
Expand Down Expand Up @@ -590,6 +604,11 @@
docMountPoint.error());
}
}
if (options.isPipewireSocketMountEnabled()) {
auto pwSocketPath = common::xdg::getXDGRuntimeDir() / "pipewire-0";
prepared.cfgBuilder.enablePipewireSocketMount(
generator::PipewireMountOption{ .hostSocketPath = std::move(pwSocketPath) });
}

if (options.isDevicePassthruEnabled()) {
prepared.cfgBuilder.bindDev(true);
Expand Down
2 changes: 2 additions & 0 deletions libs/linglong/src/linglong/runtime/container_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ struct RunContainerOptions
-> const std::vector<SecurityContextType> &;
[[nodiscard]] auto isDevicePassthruEnabled() const noexcept -> bool;
[[nodiscard]] auto isXdpDisabled() const noexcept -> bool;
[[nodiscard]] auto isPipewireSocketMountEnabled() const noexcept -> bool;
[[nodiscard]] auto isPrivileged() const noexcept -> bool;

CommonContainerOptions common;

bool disableXdp{ false };
bool enablePipewireSocketMount{ false };
bool privileged{ false };
bool devicePassthru{ false };
std::map<std::string, std::string> env;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,51 @@ TEST(RunContainerOptionsTest, ApplyCliRunOptionsOverridesRuntimeConfigXdpSetting
ASSERT_TRUE(cliResult);
EXPECT_TRUE(options.isXdpDisabled());
}

TEST(RunContainerOptionsTest, ApplyRuntimeConfigEnablesPipewireSocketMount)
{
runtime::RunContainerOptions options;

api::types::v1::RuntimeConfigure runtimeConfig;
runtimeConfig.enablePipewireSocketMount = true;

auto result = options.applyRuntimeConfig(runtimeConfig);
ASSERT_TRUE(result);
EXPECT_TRUE(options.isPipewireSocketMountEnabled());
}

TEST(RunContainerOptionsTest, ApplyCliRunOptionsPreservesRuntimeConfigPipewireSettingByDefault)
{
runtime::RunContainerOptions options;

api::types::v1::RuntimeConfigure runtimeConfig;
runtimeConfig.enablePipewireSocketMount = true;

auto runtimeResult = options.applyRuntimeConfig(runtimeConfig);
ASSERT_TRUE(runtimeResult);
ASSERT_TRUE(options.isPipewireSocketMountEnabled());

cli::RunOptions runOptions;
auto cliResult = options.applyCliRunOptions(runOptions);
ASSERT_TRUE(cliResult);
EXPECT_TRUE(options.isPipewireSocketMountEnabled());
}

TEST(RunContainerOptionsTest, ApplyCliRunOptionsOverridesRuntimeConfigPipewireSettingWhenSpecified)
{
runtime::RunContainerOptions options;

api::types::v1::RuntimeConfigure runtimeConfig;
runtimeConfig.enablePipewireSocketMount = false;

auto runtimeResult = options.applyRuntimeConfig(runtimeConfig);
ASSERT_TRUE(runtimeResult);
ASSERT_FALSE(options.isPipewireSocketMountEnabled());

cli::RunOptions runOptions;
runOptions.enablePipewireSocketMount = true;

auto cliResult = options.applyCliRunOptions(runOptions);
ASSERT_TRUE(cliResult);
EXPECT_TRUE(options.isPipewireSocketMountEnabled());
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ TEST(RuntimeConfigTest, LoadFromPath)

RuntimeConfigure config;
config.disableXdp = true;
config.enablePipewireSocketMount = true;
config.deviceMode = std::vector<DeviceOption>{ DeviceOption::Passthru };
config.env =
std::map<std::string, std::string>{ { "PATH", "/usr/bin" }, { "HOME", "/home/user" } };
Expand Down Expand Up @@ -84,6 +85,7 @@ TEST(RuntimeConfigTest, MergeConfigs)
RuntimeConfigure config1;
config1.disableXdp = false;
config1.deviceMode = std::vector<DeviceOption>{ DeviceOption::Passthru };
config1.enablePipewireSocketMount = false;
config1.devices = std::vector<std::string>{ "vendor.com/device=gpu0" };
config1.env =
std::map<std::string, std::string>{ { "PATH", "/usr/bin" }, { "HOME", "/home/user1" } };
Expand All @@ -98,6 +100,7 @@ TEST(RuntimeConfigTest, MergeConfigs)
RuntimeConfigure config2;
config2.disableXdp = true;
config2.deviceMode = std::vector<DeviceOption>{ DeviceOption::Passthru };
config2.enablePipewireSocketMount = true;
config2.devices = std::vector<std::string>{ "vendor.com/device=gpu1" };
config2.env =
std::map<std::string, std::string>{ { "PATH", "/usr/local/bin" }, { "USER", "testuser" } };
Expand All @@ -115,6 +118,8 @@ TEST(RuntimeConfigTest, MergeConfigs)
std::vector<RuntimeConfigure> configs = { config1, config2 };
auto merged = linglong::utils::MergeRuntimeConfig(configs);

ASSERT_TRUE(merged.enablePipewireSocketMount.has_value());
EXPECT_TRUE(*merged.enablePipewireSocketMount);
ASSERT_TRUE(merged.disableXdp.has_value());
EXPECT_TRUE(*merged.disableXdp);

Expand Down Expand Up @@ -154,6 +159,7 @@ TEST(RuntimeConfigTest, MergeEmptyConfigs)
std::vector<RuntimeConfigure> empty_configs;
auto merged = linglong::utils::MergeRuntimeConfig(empty_configs);

EXPECT_FALSE(merged.enablePipewireSocketMount);
EXPECT_FALSE(merged.disableXdp);
EXPECT_FALSE(merged.deviceMode);
EXPECT_FALSE(merged.env);
Expand All @@ -165,6 +171,7 @@ TEST(RuntimeConfigTest, MergePartialConfigs)
// Config with only env
RuntimeConfigure config1;
config1.disableXdp = false;
config1.enablePipewireSocketMount = false;
config1.deviceMode = std::vector<DeviceOption>{ DeviceOption::Passthru };
config1.env = std::map<std::string, std::string>{ { "PATH", "/usr/bin" } };

Expand All @@ -185,6 +192,8 @@ TEST(RuntimeConfigTest, MergePartialConfigs)
nlohmann::json j;
linglong::api::types::v1::to_json(j, merged);
LogD("{}", j.dump());
ASSERT_TRUE(merged.enablePipewireSocketMount.has_value());
EXPECT_FALSE(*merged.enablePipewireSocketMount);

ASSERT_TRUE(merged.disableXdp.has_value());
EXPECT_FALSE(*merged.disableXdp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ utils::error::Result<void> ContainerCfgBuilder::buildXDGRuntime() noexcept
.source = xdpOption->docMountPoint / "by-app" / appId,
.type = "bind" });
}
if (pipewireMountOption) {
bindIfExist(*runMount,
pipewireMountOption->hostSocketPath,
*containerXDGRuntimeDir / "pipewire-0",
false);
}
Comment thread
dengbo11 marked this conversation as resolved.
Comment thread
dengbo11 marked this conversation as resolved.

return LINGLONG_OK;
}
Expand Down Expand Up @@ -1563,6 +1569,13 @@ ContainerCfgBuilder &ContainerCfgBuilder::enableXDP(XdpOption option) noexcept
return *this;
}

ContainerCfgBuilder &
ContainerCfgBuilder::enablePipewireSocketMount(PipewireMountOption option) noexcept
{
pipewireMountOption = std::move(option);
return *this;
}

utils::error::Result<void> ContainerCfgBuilder::buildContainerInfo() noexcept
{
LINGLONG_TRACE("build container info");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ struct XdpOption
std::filesystem::path docMountPoint;
};

struct PipewireMountOption
{
std::filesystem::path hostSocketPath;
};

enum class ANNOTATION {
APPID,
BASEDIR,
Expand Down Expand Up @@ -139,6 +144,7 @@ class ContainerCfgBuilder
ContainerCfgBuilder &enableQuirkVolatile() noexcept;

ContainerCfgBuilder &enableXDP(XdpOption option) noexcept;
ContainerCfgBuilder &enablePipewireSocketMount(PipewireMountOption option) noexcept;

ContainerCfgBuilder &
setExtensionMounts(std::vector<ocppi::runtime::config::types::Mount>) noexcept;
Expand Down Expand Up @@ -330,6 +336,7 @@ class ContainerCfgBuilder
std::vector<MountNode> mountpoints;
// this 'mounts' is used internally, distinct from config.mounts
std::vector<ocppi::runtime::config::types::Mount> mounts;
std::optional<PipewireMountOption> pipewireMountOption;

std::optional<std::pair<std::filesystem::path, bool>> overlayMerged;

Expand Down
4 changes: 4 additions & 0 deletions libs/utils/src/linglong/utils/runtime_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ RuntimeConfigure MergeRuntimeConfig(const std::vector<RuntimeConfigure> &configs
result.disableXdp = config.disableXdp;
}

if (config.enablePipewireSocketMount.has_value()) {
result.enablePipewireSocketMount = config.enablePipewireSocketMount;
}

if (config.deviceMode) {
if (!result.deviceMode) {
result.deviceMode = config.deviceMode;
Expand Down
Loading