mirror of
https://github.com/Ascend/ascend-docker-runtime.git
synced 2025-10-12 03:40:05 +08:00
Match-id-7f42cd82b8c6b9d8e7fa94c7b5eea0a03384b838
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include <sys/fsuid.h>
|
#include <sys/fsuid.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/sysmacros.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
@@ -19,10 +20,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "securec.h"
|
#include "securec.h"
|
||||||
|
|
||||||
#undef major
|
|
||||||
#undef minor
|
|
||||||
#include <sys/sysmacros.h>
|
|
||||||
|
|
||||||
#define DEVICE_NAME "davinci"
|
#define DEVICE_NAME "davinci"
|
||||||
#define DAVINCI_MANAGER "davinci_manager"
|
#define DAVINCI_MANAGER "davinci_manager"
|
||||||
#define DEVMM_SVM "devmm_svm"
|
#define DEVMM_SVM "devmm_svm"
|
||||||
@@ -37,7 +34,7 @@
|
|||||||
#define MOUNT_SUBSTR_GAP 2
|
#define MOUNT_SUBSTR_GAP 2
|
||||||
#define ROOT_SUBSTR_GAP 2
|
#define ROOT_SUBSTR_GAP 2
|
||||||
|
|
||||||
static const struct option g_cmdOpts[] = {
|
static struct option g_cmdOpts[] = {
|
||||||
{"devices", required_argument, 0, 'd'},
|
{"devices", required_argument, 0, 'd'},
|
||||||
{"pid", required_argument, 0, 'p'},
|
{"pid", required_argument, 0, 'p'},
|
||||||
{"rootfs", required_argument, 0, 'r'},
|
{"rootfs", required_argument, 0, 'r'},
|
||||||
@@ -56,6 +53,13 @@ struct ParsedConfig {
|
|||||||
int originNsFd;
|
int originNsFd;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct PathInfo {
|
||||||
|
char* src;
|
||||||
|
size_t srcLen;
|
||||||
|
char* dst;
|
||||||
|
size_t dstLen;
|
||||||
|
};
|
||||||
|
|
||||||
static inline bool IsCmdArgsValid(struct CmdArgs *args)
|
static inline bool IsCmdArgsValid(struct CmdArgs *args)
|
||||||
{
|
{
|
||||||
return (strlen(args->devices) > 0) && (strlen(args->rootfs) > 0) && (args->pid > 0);
|
return (strlen(args->devices) > 0) && (strlen(args->rootfs) > 0) && (args->pid > 0);
|
||||||
@@ -137,14 +141,32 @@ static int CreateFile(const char *path, mode_t mode)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int VerfifyPathInfo(const struct PathInfo* pathInfo)
|
||||||
|
{
|
||||||
|
if (pathInfo == NULL || pathInfo->dst == NULL || pathInfo->src == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int GetDeviceMntSrcDst(const char *rootfs, const char *deviceName,
|
static int GetDeviceMntSrcDst(const char *rootfs, const char *deviceName,
|
||||||
char *src, size_t srcBufSize, char *dst, size_t dstBufSize)
|
struct PathInfo* pathInfo)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
error_t err;
|
error_t err;
|
||||||
char unresolvedDst[BUF_SIZE] = {0};
|
char unresolvedDst[BUF_SIZE] = {0};
|
||||||
char resolvedDst[PATH_MAX] = {0};
|
char resolvedDst[PATH_MAX] = {0};
|
||||||
|
|
||||||
|
ret = VerfifyPathInfo(pathInfo);
|
||||||
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t srcBufSize = pathInfo->srcLen;
|
||||||
|
size_t dstBufSize = pathInfo->dstLen;
|
||||||
|
char *src = pathInfo->src;
|
||||||
|
char *dst = pathInfo->dst;
|
||||||
|
|
||||||
ret = snprintf_s(src, srcBufSize, srcBufSize, "/dev/%s", deviceName);
|
ret = snprintf_s(src, srcBufSize, srcBufSize, "/dev/%s", deviceName);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -174,8 +196,9 @@ int MountDevice(const char *rootfs, const char *deviceName)
|
|||||||
int ret;
|
int ret;
|
||||||
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};
|
||||||
|
|
||||||
ret = GetDeviceMntSrcDst(rootfs, deviceName, src, BUF_SIZE, dst, BUF_SIZE);
|
ret = GetDeviceMntSrcDst(rootfs, deviceName, &pathInfo);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "error: failed to get device mount src and(or) dst path, device name: %s\n", deviceName);
|
fprintf(stderr, "error: failed to get device mount src and(or) dst path, device name: %s\n", deviceName);
|
||||||
return -1;
|
return -1;
|
||||||
|
Reference in New Issue
Block a user