mirror of
https://github.com/Ascend/ascend-docker-runtime.git
synced 2025-10-13 00:43:44 +08:00
Match-id-211a5acee295801abbb9cb3fd85a2877e35002ed
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#define DAVINCI_MANAGER_PATH "/dev/davinci_manager"
|
||||
#define DEVMM_SVM_PATH "/dev/devmm_svm"
|
||||
#define HISI_HDC_PATH "/dev/hisi_hdc"
|
||||
#define ASCEND_DRIVER_PATH "/usr/local/Ascend/driver"
|
||||
#define DEFAULT_DIR_MODE 0755
|
||||
#define BUF_SIZE 1024
|
||||
#define ALLOW_PATH "/devices.allow"
|
||||
@@ -309,6 +310,18 @@ int DoCtrlDeviceMounting(const char *rootfs)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DoDirectoryMounting(const char *rootfs)
|
||||
{
|
||||
/* directory */
|
||||
unsigned long reMountRwFlag = MS_BIND | MS_REMOUNT | MS_RDONLY | MS_NODEV | MS_NOSUID;
|
||||
int ret = MountFiles(rootfs, ASCEND_DRIVER_PATH, reMountRwFlag);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "error: failed to do mount %s\n", ASCEND_DRIVER_PATH);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DoMounting(const struct CmdArgs *args)
|
||||
{
|
||||
int ret;
|
||||
@@ -325,6 +338,12 @@ int DoMounting(const struct CmdArgs *args)
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = DoDirectoryMounting(args->rootfs);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "error: failed to do mount directory\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -46,6 +46,7 @@ extern "C" int SetupCgroup(struct CmdArgs *args, const char *cgroupPath);
|
||||
extern "C" int SetupMounts(struct CmdArgs *args);
|
||||
extern "C" void FreeCmdArgs(struct CmdArgs *args);
|
||||
extern "C" int Process(int argc, char **argv);
|
||||
extern "C" int DoMounting(const struct CmdArgs *args);
|
||||
|
||||
struct CmdArgs {
|
||||
char *devices;
|
||||
@@ -105,6 +106,11 @@ int Stub_DoCtrlDeviceMounting_Success(const char *rootfs)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Stub_DoMounting_Success(const struct CmdArgs *args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Stub_SetupCgroup_Success(struct CmdArgs *args, const char *cgroupPath)
|
||||
{
|
||||
return 0;
|
||||
@@ -647,6 +653,22 @@ TEST(SetupMounts, Status6)
|
||||
MOCKER(EnterNsByFd).stubs().will(invoke(Stub_EnterNsByFd_Success));
|
||||
int ret = SetupMounts(&args);
|
||||
GlobalMockObject::verify();
|
||||
EXPECT_EQ(-1, ret);
|
||||
}
|
||||
|
||||
TEST(SetupMounts, Status7)
|
||||
{
|
||||
struct CmdArgs args = {
|
||||
.devices = "1,2",
|
||||
.rootfs = "/home",
|
||||
.pid = 1
|
||||
};
|
||||
MOCKER(EnterNsByPath).stubs().will(invoke(Stub_EnterNsByPath_Success));
|
||||
MOCKER(DoMounting).stubs().will(invoke(Stub_DoMounting_Success));
|
||||
MOCKER(SetupCgroup).stubs().will(invoke(Stub_SetupCgroup_Success));
|
||||
MOCKER(EnterNsByFd).stubs().will(invoke(Stub_EnterNsByFd_Success));
|
||||
int ret = SetupMounts(&args);
|
||||
GlobalMockObject::verify();
|
||||
EXPECT_EQ(0, ret);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user