mirror of
https://github.com/Ascend/ascend-docker-runtime.git
synced 2025-10-16 08:40:37 +08:00
Match-id-9fd6554d839fc28733ea9818d1617c673f70a24e
This commit is contained in:
@@ -48,7 +48,7 @@ typedef bool (*CmdArgParser)(struct CmdArgs *args, const char *arg);
|
|||||||
static bool DevicesCmdArgParser(struct CmdArgs *args, const char *arg)
|
static bool DevicesCmdArgParser(struct CmdArgs *args, const char *arg)
|
||||||
{
|
{
|
||||||
if (args == NULL || arg == NULL) {
|
if (args == NULL || arg == NULL) {
|
||||||
fprintf(stderr, "args, arg pointer is null!\n");
|
Logger("args, arg pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ static bool DevicesCmdArgParser(struct CmdArgs *args, const char *arg)
|
|||||||
static bool PidCmdArgParser(struct CmdArgs *args, const char *arg)
|
static bool PidCmdArgParser(struct CmdArgs *args, const char *arg)
|
||||||
{
|
{
|
||||||
if (args == NULL || arg == NULL) {
|
if (args == NULL || arg == NULL) {
|
||||||
fprintf(stderr, "args, arg pointer is null!\n");
|
Logger("args, arg pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ static bool PidCmdArgParser(struct CmdArgs *args, const char *arg)
|
|||||||
static bool RootfsCmdArgParser(struct CmdArgs *args, const char *arg)
|
static bool RootfsCmdArgParser(struct CmdArgs *args, const char *arg)
|
||||||
{
|
{
|
||||||
if (args == NULL || arg == NULL) {
|
if (args == NULL || arg == NULL) {
|
||||||
fprintf(stderr, "args, arg pointer is null!\n");
|
Logger("args, arg pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ static bool RootfsCmdArgParser(struct CmdArgs *args, const char *arg)
|
|||||||
static bool OptionsCmdArgParser(struct CmdArgs *args, const char *arg)
|
static bool OptionsCmdArgParser(struct CmdArgs *args, const char *arg)
|
||||||
{
|
{
|
||||||
if (args == NULL || arg == NULL) {
|
if (args == NULL || arg == NULL) {
|
||||||
fprintf(stderr, "args, arg pointer is null!\n");
|
Logger("args, arg pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ static bool OptionsCmdArgParser(struct CmdArgs *args, const char *arg)
|
|||||||
static bool MountFileCmdArgParser(struct CmdArgs *args, const char *arg)
|
static bool MountFileCmdArgParser(struct CmdArgs *args, const char *arg)
|
||||||
{
|
{
|
||||||
if (args == NULL || arg == NULL) {
|
if (args == NULL || arg == NULL) {
|
||||||
fprintf(stderr, "args, arg pointer is null!\n");
|
Logger("args, arg pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ static bool MountFileCmdArgParser(struct CmdArgs *args, const char *arg)
|
|||||||
static bool MountDirCmdArgParser(struct CmdArgs *args, const char *arg)
|
static bool MountDirCmdArgParser(struct CmdArgs *args, const char *arg)
|
||||||
{
|
{
|
||||||
if (args == NULL || arg == NULL) {
|
if (args == NULL || arg == NULL) {
|
||||||
fprintf(stderr, "args, arg pointer is null!\n");
|
Logger("args, arg pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ static struct {
|
|||||||
static int ParseOneCmdArg(struct CmdArgs *args, char indicator, const char *value)
|
static int ParseOneCmdArg(struct CmdArgs *args, char indicator, const char *value)
|
||||||
{
|
{
|
||||||
if (args == NULL || value == NULL) {
|
if (args == NULL || value == NULL) {
|
||||||
fprintf(stderr, "args, value pointer is null!\n");
|
Logger("args, value pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ static int ParseOneCmdArg(struct CmdArgs *args, char indicator, const char *valu
|
|||||||
static inline bool IsCmdArgsValid(const struct CmdArgs *args)
|
static inline bool IsCmdArgsValid(const struct CmdArgs *args)
|
||||||
{
|
{
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
fprintf(stderr, "args pointer is null!\n");
|
Logger("args pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (strlen(args->devices) > 0) && (strlen(args->rootfs) > 0) && (args->pid > 0);
|
return (strlen(args->devices) > 0) && (strlen(args->rootfs) > 0) && (args->pid > 0);
|
||||||
@@ -227,7 +227,7 @@ static inline bool IsCmdArgsValid(const struct CmdArgs *args)
|
|||||||
static int ParseDeviceIDs(unsigned int *idList, size_t *idListSize, char *devices)
|
static int ParseDeviceIDs(unsigned int *idList, size_t *idListSize, char *devices)
|
||||||
{
|
{
|
||||||
if (idList == NULL || idListSize == NULL || devices == NULL) {
|
if (idList == NULL || idListSize == NULL || devices == NULL) {
|
||||||
fprintf(stderr, "idList, idListSize, devices pointer is null!\n");
|
Logger("idList, idListSize, devices pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +265,7 @@ static int ParseDeviceIDs(unsigned int *idList, size_t *idListSize, char *device
|
|||||||
int DoPrepare(const struct CmdArgs *args, struct ParsedConfig *config)
|
int DoPrepare(const struct CmdArgs *args, struct ParsedConfig *config)
|
||||||
{
|
{
|
||||||
if (args == NULL || config == NULL) {
|
if (args == NULL || config == NULL) {
|
||||||
fprintf(stderr, "args, config pointer is null!\n");
|
Logger("args, config pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,7 +322,7 @@ int DoPrepare(const struct CmdArgs *args, struct ParsedConfig *config)
|
|||||||
int SetupContainer(struct CmdArgs *args)
|
int SetupContainer(struct CmdArgs *args)
|
||||||
{
|
{
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
fprintf(stderr, "args pointer is null!\n");
|
Logger("args pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,7 +379,7 @@ int SetupContainer(struct CmdArgs *args)
|
|||||||
int Process(int argc, char **argv)
|
int Process(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argv == NULL) {
|
if (argv == NULL) {
|
||||||
fprintf(stderr, "argv pointer is null!\n");
|
Logger("argv pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int c;
|
int c;
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
int Mount(const char *src, const char *dst)
|
int Mount(const char *src, const char *dst)
|
||||||
{
|
{
|
||||||
if (src == NULL || dst == NULL) {
|
if (src == NULL || dst == NULL) {
|
||||||
fprintf(stderr, "src pointer or dst pointer is null!\n");
|
Logger("src pointer or dst pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,8 +49,8 @@ int Mount(const char *src, const char *dst)
|
|||||||
static int GetDeviceMntSrcDst(const char *rootfs, const char *srcDeviceName,
|
static int GetDeviceMntSrcDst(const char *rootfs, const char *srcDeviceName,
|
||||||
const char *dstDeviceName, struct PathInfo* pathInfo)
|
const char *dstDeviceName, struct PathInfo* pathInfo)
|
||||||
{
|
{
|
||||||
if (rootfs == NULL || srcDeviceName == NULL || dstDeviceName == NULL || pathInfo == NULL) {
|
if (rootfs == NULL || srcDeviceName == NULL || pathInfo == NULL) {
|
||||||
fprintf(stderr, "rootfs, srcDeviceName, dstDeviceName, pathInfo pointer are null!\n");
|
Logger("rootfs, srcDeviceName, dstDeviceName, pathInfo pointer are null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,23 +106,22 @@ static int GetDeviceMntSrcDst(const char *rootfs, const char *srcDeviceName,
|
|||||||
|
|
||||||
int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDeviceName)
|
int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDeviceName)
|
||||||
{
|
{
|
||||||
if (rootfs == NULL || srcDeviceName == NULL || dstDeviceName == NULL) {
|
int ret;
|
||||||
fprintf(stderr, "rootfs, srcDeviceName, dstDeviceName pointer is null!\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *str = NULL;
|
char *str = NULL;
|
||||||
char src[BUF_SIZE] = {0};
|
char src[BUF_SIZE] = {0};
|
||||||
char dst[BUF_SIZE] = {0};
|
char dst[BUF_SIZE] = {0};
|
||||||
struct PathInfo pathInfo = {src, BUF_SIZE, dst, BUF_SIZE};
|
struct PathInfo pathInfo = {src, BUF_SIZE, dst, BUF_SIZE};
|
||||||
if (GetDeviceMntSrcDst(rootfs, srcDeviceName, dstDeviceName, &pathInfo) < 0) {
|
ret = GetDeviceMntSrcDst(rootfs, srcDeviceName, dstDeviceName, &pathInfo);
|
||||||
|
if (ret < 0) {
|
||||||
str = FormatLogMessage("failed to get mount src and dst path, device name: %s.", srcDeviceName);
|
str = FormatLogMessage("failed to get mount src and dst path, device name: %s.", srcDeviceName);
|
||||||
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
||||||
free(str);
|
free(str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat srcStat;
|
struct stat srcStat;
|
||||||
if (stat((const char *)src, &srcStat) < 0) {
|
ret = stat((const char *)src, &srcStat);
|
||||||
|
if (ret < 0) {
|
||||||
str = FormatLogMessage("failed to stat src: %s.", src);
|
str = FormatLogMessage("failed to stat src: %s.", src);
|
||||||
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
||||||
free(str);
|
free(str);
|
||||||
@@ -130,7 +129,6 @@ int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDe
|
|||||||
}
|
}
|
||||||
errno = 0;
|
errno = 0;
|
||||||
struct stat dstStat;
|
struct stat dstStat;
|
||||||
int ret;
|
|
||||||
ret = stat((const char *)dst, &dstStat);
|
ret = stat((const char *)dst, &dstStat);
|
||||||
if (ret == 0 && S_ISCHR(dstStat.st_mode)) {
|
if (ret == 0 && S_ISCHR(dstStat.st_mode)) {
|
||||||
return 0; // 特权容器自动挂载HOST所有设备,故此处跳过
|
return 0; // 特权容器自动挂载HOST所有设备,故此处跳过
|
||||||
@@ -143,15 +141,16 @@ int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDe
|
|||||||
Logger("failed to check dst stat", LEVEL_ERROR, SCREEN_YES);
|
Logger("failed to check dst stat", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
ret = MakeMountPoints(dst, srcStat.st_mode);
|
||||||
if (MakeMountPoints(dst, srcStat.st_mode) < 0) {
|
if (ret < 0) {
|
||||||
str = FormatLogMessage("failed to create mount dst file: %s.", dst);
|
str = FormatLogMessage("failed to create mount dst file: %s.", dst);
|
||||||
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
Logger(str, LEVEL_ERROR, SCREEN_YES);
|
||||||
free(str);
|
free(str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Mount(src, dst) < 0) {
|
ret = Mount(src, dst);
|
||||||
|
if (ret < 0) {
|
||||||
Logger("failed to mount dev.", LEVEL_ERROR, SCREEN_YES);
|
Logger("failed to mount dev.", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -162,7 +161,7 @@ int MountDevice(const char *rootfs, const char *srcDeviceName, const char *dstDe
|
|||||||
int DoDeviceMounting(const char *rootfs, const char *device_name, const unsigned int ids[], size_t idsNr)
|
int DoDeviceMounting(const char *rootfs, const char *device_name, const unsigned int ids[], size_t idsNr)
|
||||||
{
|
{
|
||||||
if (rootfs == NULL || device_name == NULL) {
|
if (rootfs == NULL || device_name == NULL) {
|
||||||
fprintf(stderr, "rootfs, device_name pointer is null!\n");
|
Logger("rootfs, device_name pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +192,7 @@ int DoDeviceMounting(const char *rootfs, const char *device_name, const unsigned
|
|||||||
int MountFile(const char *rootfs, const char *filepath)
|
int MountFile(const char *rootfs, const char *filepath)
|
||||||
{
|
{
|
||||||
if (rootfs == NULL || filepath == NULL) {
|
if (rootfs == NULL || filepath == NULL) {
|
||||||
fprintf(stderr, "rootfs, filepath pointer is null!\n");
|
Logger("rootfs, filepath pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +233,7 @@ int MountFile(const char *rootfs, const char *filepath)
|
|||||||
int MountDir(const char *rootfs, const char *src)
|
int MountDir(const char *rootfs, const char *src)
|
||||||
{
|
{
|
||||||
if (rootfs == NULL || src == NULL) {
|
if (rootfs == NULL || src == NULL) {
|
||||||
fprintf(stderr, "rootfs, src pointer is null!\n");
|
Logger("rootfs, src pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +308,7 @@ int DoCtrlDeviceMounting(const char *rootfs)
|
|||||||
int DoDirectoryMounting(const char *rootfs, const struct MountList *list)
|
int DoDirectoryMounting(const char *rootfs, const struct MountList *list)
|
||||||
{
|
{
|
||||||
if (rootfs == NULL || list == NULL) {
|
if (rootfs == NULL || list == NULL) {
|
||||||
fprintf(stderr, "rootfs, list pointer is null!\n");
|
Logger("rootfs, list pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,7 +329,7 @@ int DoDirectoryMounting(const char *rootfs, const struct MountList *list)
|
|||||||
int DoFileMounting(const char *rootfs, const struct MountList *list)
|
int DoFileMounting(const char *rootfs, const struct MountList *list)
|
||||||
{
|
{
|
||||||
if (rootfs == NULL || list == NULL) {
|
if (rootfs == NULL || list == NULL) {
|
||||||
fprintf(stderr, "rootfs, list pointer is null!\n");
|
Logger("rootfs, list pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,7 +350,7 @@ int DoFileMounting(const char *rootfs, const struct MountList *list)
|
|||||||
int DoMounting(const struct ParsedConfig *config)
|
int DoMounting(const struct ParsedConfig *config)
|
||||||
{
|
{
|
||||||
if (config == NULL) {
|
if (config == NULL) {
|
||||||
fprintf(stderr, "config pointer is null!\n");
|
Logger("config pointer is null!", LEVEL_ERROR, SCREEN_YES);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user