Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
sithanda authored Nov 5, 2024
2 parents 190ad75 + 9195ff3 commit 29f6251
Show file tree
Hide file tree
Showing 36 changed files with 1,309 additions and 77 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/L2-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: '3.x'
- run: pip install jsonref
pip install coverage
- run: |
pip install jsonref
pip install coverage
- name: Set up CMake
uses: jwlawson/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
cmake -DCMAKE_BUILD_TYPE=Debug -DRDK_PLATFORM=DEV_VM -DCMAKE_INSTALL_PREFIX:PATH=/usr -DLEGACY_COMPONENTS=ON -DPLUGIN_TESTPLUGIN=ON -DPLUGIN_GPU=ON -DPLUGIN_LOCALTIME=ON -DPLUGIN_RTSCHEDULING=ON -DPLUGIN_HTTPPROXY=ON -DPLUGIN_APPSERVICES=ON -DPLUGIN_IONMEMORY=ON -DPLUGIN_DEVICEMAPPER=ON ..
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: +security-and-quality
Expand All @@ -59,6 +59,6 @@ jobs:
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
8 changes: 8 additions & 0 deletions AppInfrastructure/Public/Dobby/IDobbyProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ class IDobbyProxy : public AICommon::Notifier<IDobbyProxyEvents>

virtual bool wakeupContainer(int32_t descriptor) const = 0;

virtual bool addContainerMount(int32_t descriptor,
const std::string& source,
const std::string& destination,
const std::vector<std::string>& mountFlags,
const std::string& mountData) const = 0;

virtual bool removeContainerMount(int32_t descriptor, const std::string& source) const = 0;

virtual bool execInContainer(int32_t cd,
const std::string& options,
const std::string& command) const = 0;
Expand Down
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ cmake_minimum_required( VERSION 3.7.0 )
include(GNUInstallDirs)

# Project setup
project( Dobby VERSION "3.10.0" )
project( Dobby VERSION "3.11.0" )


# Set the major and minor version numbers of dobby (also used by plugins)
set( DOBBY_MAJOR_VERSION 3 )
set( DOBBY_MINOR_VERSION 10 )
set( DOBBY_MINOR_VERSION 11 )
set( DOBBY_MICRO_VERSION 0 )

set(INSTALL_CMAKE_DIR lib/cmake/Dobby)
Expand Down Expand Up @@ -165,6 +165,12 @@ endif()

find_package( breakpad QUIET )

option( USE_OPEN_TREE_FOR_DYNAMIC_MOUNTS "use open_tree() syscall for dynamic mounts" OFF )
if ( USE_OPEN_TREE_FOR_DYNAMIC_MOUNTS )
message("will use open_tree syscall for dynamic mounts")
add_definitions( -DUSE_OPEN_TREE_FOR_DYNAMIC_MOUNTS )
endif()

# Run libocispec to generate OCI config parsers and necessary C headers
include(Findlibocispec)
GenerateLibocispec(EXTRA_SCHEMA_PATH "${EXTERNAL_PLUGIN_SCHEMA}")
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,19 @@ vagrant@dobby-vagrant:~$ DobbyTool help
quit quit
help help [command]
shutdown shutdown
start start [options...] <id> <specfile/bundlepath> [command]
start start [options...] <id> <bundlepath> [command]
stop stop <id> [options...]
pause pause <id>
resume resume <id>
hibernate hibernate [options...] <id>
wakeup wakeup <id>
mount mount <id> <source> <destination> <mountFlags> <mountData>
unmount unmount <id> <source>
exec exec [options...] <id> <command>
list list
info info <id>
dumpspec dumpspec <id> [options...]
bundle bundle <id> <specfile> [options...]
wait wait <id> <state>
set-log-level set-log-level <level>
set-dbus set-dbus <private>|<public> <address>
```
For more information about a command, run `DobbyTool help [command]`. For example:
Expand Down
5 changes: 2 additions & 3 deletions bundle/lib/source/templates/OciConfigJson1.0.2-dobby.template
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ static const char* ociJsonTemplate = R"JSON(
"readonly": true
},

"rootfsPropagation": "rprivate",

"hostname": "dobby",

"mounts": [
Expand Down Expand Up @@ -377,7 +375,8 @@ static const char* ociJsonTemplate = R"JSON(
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
],
"rootfsPropagation": "slave"
},
{{#ENABLE_LEGACY_PLUGINS}}
"legacyPlugins": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ static const char* ociJsonTemplate = R"JSON(
"readonly": true
},

"rootfsPropagation": "rprivate",

"hostname": "dobby",

"mounts": [
Expand Down Expand Up @@ -388,7 +386,8 @@ static const char* ociJsonTemplate = R"JSON(
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
],
"rootfsPropagation": "slave"
},
{{#ENABLE_LEGACY_PLUGINS}}
"legacyPlugins": {
Expand Down
8 changes: 8 additions & 0 deletions client/lib/include/DobbyProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ class DobbyProxy : public IDobbyProxy
bool hibernateContainer(int32_t descriptor, const std::string& options) const override;

bool wakeupContainer(int32_t descriptor) const override;

bool addContainerMount(int32_t descriptor,
const std::string& source,
const std::string& destination,
const std::vector<std::string>& mountFlags,
const std::string& mountData) const override;

bool removeContainerMount(int32_t descriptor, const std::string& source) const override;

bool execInContainer(int32_t cd,
const std::string& options,
Expand Down
72 changes: 72 additions & 0 deletions client/lib/source/DobbyProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,78 @@ bool DobbyProxy::wakeupContainer(int32_t cd) const
return result;
}

// -----------------------------------------------------------------------------
/**
* @brief mounts a new host directory/device inside container
*
* @param[in] cd The container descriptor.
* @param[in] source path of the mount device on the host
* @param[in] destination path of the mount on the container
* @param[in] mountFlags The mount flags is a vector of srings containing the mount optiosn
* e.g. "rbind,ro"
* it should include "bind"
* @param[in] mountData string containing the mount data
*
* @return true on success, false on failure.
*/
bool DobbyProxy::addContainerMount(int32_t cd, const std::string& source, const std::string& destination, const std::vector<std::string>& mountFlags, const std::string& mountData) const
{
AI_LOG_FN_ENTRY();

// Send off the request
const AI_IPC::VariantList params = { cd, source, destination, mountFlags, mountData};
AI_IPC::VariantList returns;

bool result = false;

if (invokeMethod(DOBBY_CTRL_INTERFACE,
DOBBY_CTRL_METHOD_MOUNT,
params, returns))
{
if (!AI_IPC::parseVariantList<bool>(returns, &result))
{
result = false;
}
}

AI_LOG_FN_EXIT();
return result;
}

// -----------------------------------------------------------------------------
/**
* @brief unmounts a directory/device inside the container
*
* @param[in] cd The container descriptor.
* @param[in] source path of the mount device on the host
*
* @return true on success, false on failure.
*/
bool DobbyProxy::removeContainerMount(int32_t cd, const std::string &source) const
{

AI_LOG_FN_ENTRY();

// Send off the request
const AI_IPC::VariantList params = { cd, source };
AI_IPC::VariantList returns;

bool result = false;

if (invokeMethod(DOBBY_CTRL_INTERFACE,
DOBBY_CTRL_METHOD_UNMOUNT,
params, returns))
{
if (!AI_IPC::parseVariantList<bool>(returns, &result))
{
result = false;
}
}

AI_LOG_FN_EXIT();
return result;
}

// -----------------------------------------------------------------------------
/**
* @brief Executes a command in the given container.
Expand Down
120 changes: 119 additions & 1 deletion client/tool/source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,112 @@ static void wakeupCommand(const std::shared_ptr<IDobbyProxy>& dobbyProxy,
}
}

// -----------------------------------------------------------------------------
/**
* @brief
*
*
*
*/
static void mountCommand(const std::shared_ptr<IDobbyProxy>& dobbyProxy,
const std::shared_ptr<const IReadLineContext>& readLine,
const std::vector<std::string>& args)
{
if (args.size() < 4 || args[0].empty() || args[1].empty() || args[2].empty() || args[3].empty())
{
readLine->printLnError("must provide at least 4 args; <id> <source> <destination> <mountFlags>");
return;
}

std::string id = args[0];
if (id.empty())
{
readLine->printLnError("invalid container id '%s'", id.c_str());
return;
}
std::string source(args[1]);
std::string destination(args[2]);
std::vector<std::string> mountFlags;
std::string mountData;

// parse args[3] which is a comma separated list of flags into a vector of strings
std::string flags = args[3];
size_t pos = 0;
while ((pos = flags.find(",")) != std::string::npos)
{
std::string flag = flags.substr(0, pos);
mountFlags.push_back(flag);
flags.erase(0, pos + 1);
}
mountFlags.push_back(flags);

// mountData is optional for now
if(args.size() >= 5 && !args[4].empty())
{
mountData = args[4];
}

int32_t cd = getContainerDescriptor(dobbyProxy, id);
if (cd < 0)
{
readLine->printLnError("failed to find container '%s'", id.c_str());
}
else
{
if (!dobbyProxy->addContainerMount(cd, source, destination, mountFlags, mountData))
{
readLine->printLnError("failed to mount %s inside the container %s", source.c_str(), id.c_str());
}
else
{
readLine->printLn("mount successful for container '%s'", id.c_str());
}
}
}

// -----------------------------------------------------------------------------
/**
* @brief
*
*
*
*/
static void unmountCommand(const std::shared_ptr<IDobbyProxy>& dobbyProxy,
const std::shared_ptr<const IReadLineContext>& readLine,
const std::vector<std::string>& args)
{
if (args.size() < 2 || args[0].empty() || args[1].empty())
{
readLine->printLnError("must provide at least two args; <id> <source>");
return;
}

std::string id = args[0];
if (id.empty())
{
readLine->printLnError("invalid container id '%s'", id.c_str());
return;
}
std::string source(args[1]);

int32_t cd = getContainerDescriptor(dobbyProxy, id);
if (cd < 0)
{
readLine->printLnError("failed to find container '%s'", id.c_str());
}
else
{
if (!dobbyProxy->removeContainerMount(cd, source))
{
readLine->printLnError("failed to unmount %s inside the container %s", source.c_str(), id.c_str());
}
else
{
readLine->printLn("unmount successful for container '%s'", id.c_str());
}
}
}

// -----------------------------------------------------------------------------
/**
* @brief
Expand Down Expand Up @@ -1179,7 +1285,19 @@ static void initCommands(const std::shared_ptr<IReadLine>& readLine,
"wakeup <id>",
"wakeup a container with the given id\n",
"\n");


readLine->addCommand("mount",
std::bind(mountCommand, dobbyProxy, std::placeholders::_1, std::placeholders::_2),
"mount <id> <source> <destination> <mountFlags> <mountData>",
"mount a directory from the host inside the container with the given id\n",
"\n");

readLine->addCommand("unmount",
std::bind(unmountCommand, dobbyProxy, std::placeholders::_1, std::placeholders::_2),
"unmount <id> <source>",
"unmount a directory inside the container with the given id\n",
"\n");

readLine->addCommand("exec",
std::bind(execCommand, dobbyProxy, std::placeholders::_1, std::placeholders::_2),
"exec [options...] <id> <command>",
Expand Down
2 changes: 2 additions & 0 deletions daemon/lib/include/Dobby.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class Dobby
DOBBY_DBUS_METHOD(resume);
DOBBY_DBUS_METHOD(hibernate);
DOBBY_DBUS_METHOD(wakeup);
DOBBY_DBUS_METHOD(addMount);
DOBBY_DBUS_METHOD(removeMount);
DOBBY_DBUS_METHOD(exec);
DOBBY_DBUS_METHOD(list);
DOBBY_DBUS_METHOD(getState);
Expand Down
Loading

0 comments on commit 29f6251

Please sign in to comment.