Match-id-77d0dcf76c49b84511b8f24c2acab8d001fbf905

This commit is contained in:
BianTanggui
2020-07-30 21:07:02 +08:00
parent 5b4006142d
commit 2bcecfbcff
4 changed files with 111 additions and 37 deletions

View File

@@ -12,8 +12,13 @@
#define DAVINCI_MANAGER "davinci_manager" #define DAVINCI_MANAGER "davinci_manager"
#define DEVMM_SVM "devmm_svm" #define DEVMM_SVM "devmm_svm"
#define HISI_HDC "hisi_hdc" #define HISI_HDC "hisi_hdc"
#define ASCEND_DRIVER_PATH "/usr/local/Ascend/driver" #define ASCEND_DRIVER_LIB64_PATH "/usr/local/Ascend/driver/lib64"
#define ASCEND_DRIVER_TOOLS_PATH "/usr/local/Ascend/driver/tools"
#define ASCEND_DRIVER_INC_PATH "/usr/local/Ascend/driver/include"
#define ASCEND_ADDONS_PATH "/usr/local/Ascend/add-ons" #define ASCEND_ADDONS_PATH "/usr/local/Ascend/add-ons"
#define ASCEND_DCMI_PATH "/usr/local/dcmi"
#define ASCEND_NPU_SMI_PATH "/usr/local/sbin/npu-smi"
#define ASCEND_SLOG_CONF_PATH "/var/log/npu/conf/slog/slog.conf"
#define DEFAULT_DIR_MODE 0755 #define DEFAULT_DIR_MODE 0755
#define BUF_SIZE 1024 #define BUF_SIZE 1024
#define MAX_DEVICE_NR 1024 #define MAX_DEVICE_NR 1024

View File

@@ -133,6 +133,39 @@ int DoDeviceMounting(const char *rootfs, const unsigned int ids[], size_t idsNr)
return 0; return 0;
} }
int MountFile(const char *rootfs, const char *filepath)
{
int ret;
char dst[BUF_SIZE] = {0};
ret = sprintf_s(dst, BUF_SIZE, "%s%s", rootfs, filepath);
if (ret < 0) {
LogError("error: failed to assemble file mounting path, file: %s.", filepath);
return -1;
}
struct stat srcStat;
ret = stat(filepath, &srcStat);
if (ret < 0) {
LogError("error: failed to stat src: %s.", filepath);
return -1;
}
ret = CreateFile(dst, srcStat.st_mode);
if (ret < 0) {
LogError("error: failed to create mount dst file: %s.", dst);
return -1;
}
ret = Mount(filepath, dst);
if (ret < 0) {
LogError("error: failed to mount dev.");
return -1;
}
return 0;
}
int MountDir(const char *rootfs, const char *src) int MountDir(const char *rootfs, const char *src)
{ {
int ret; int ret;
@@ -149,25 +182,10 @@ int MountDir(const char *rootfs, const char *src)
return -1; return -1;
} }
/* directory */ ret = MakeDirWithParent(dst, DEFAULT_DIR_MODE);
char parentDir[BUF_SIZE] = {0}; if (ret < 0) {
GetParentPathStr(dst, parentDir, BUF_SIZE); LogError("error: failed to make dir: %s.", dst);
if (CheckDirExists(parentDir) < 0) { return -1;
mode_t parentMode = DEFAULT_DIR_MODE;
ret = MakeParentDir(parentDir, parentMode);
if (ret < 0) {
LogError("error: failed to make dir: %s.", parentDir);
return -1;
}
}
if (CheckDirExists(dst) < 0) {
const mode_t curMode = srcStat.st_mode;
ret = MkDir(dst, curMode);
if (ret < 0) {
LogError("error: failed to make dir: %s.", dst);
return -1;
}
} }
ret = Mount(src, dst); ret = Mount(src, dst);
@@ -206,9 +224,21 @@ int DoCtrlDeviceMounting(const char *rootfs)
int DoDirectoryMounting(const char *rootfs) int DoDirectoryMounting(const char *rootfs)
{ {
/* directory */ /* directory */
int ret = MountDir(rootfs, ASCEND_DRIVER_PATH); int ret = MountDir(rootfs, ASCEND_DRIVER_LIB64_PATH);
if (ret < 0) { if (ret < 0) {
LogError("error: failed to do mount %s.", ASCEND_DRIVER_PATH); LogError("error: failed to do mount %s.", ASCEND_DRIVER_LIB64_PATH);
return -1;
}
ret = MountDir(rootfs, ASCEND_DRIVER_TOOLS_PATH);
if (ret < 0) {
LogError("error: failed to do mount %s.", ASCEND_DRIVER_TOOLS_PATH);
return -1;
}
ret = MountDir(rootfs, ASCEND_DRIVER_INC_PATH);
if (ret < 0) {
LogError("error: failed to do mount %s.", ASCEND_DRIVER_INC_PATH);
return -1; return -1;
} }
@@ -218,6 +248,29 @@ int DoDirectoryMounting(const char *rootfs)
return -1; return -1;
} }
ret = MountDir(rootfs, ASCEND_DCMI_PATH);
if (ret < 0) {
LogError("error: failed to do mount %s.", ASCEND_DCMI_PATH);
return -1;
}
return 0;
}
int DoFileMounting(const char *rootfs)
{
int ret = MountFile(rootfs, ASCEND_NPU_SMI_PATH);
if (ret < 0) {
LogError("error: failed to do mount %s.", ASCEND_NPU_SMI_PATH);
return -1;
}
MountFile(rootfs, ASCEND_SLOG_CONF_PATH);
if (ret < 0) {
LogError("error: failed to do mount %s.", ASCEND_SLOG_CONF_PATH);
return -1;
}
return 0; return 0;
} }
@@ -227,22 +280,30 @@ int DoMounting(const struct ParsedConfig *config)
ret = DoDeviceMounting(config->rootfs, config->devices, config->devicesNr); ret = DoDeviceMounting(config->rootfs, config->devices, config->devicesNr);
if (ret < 0) { if (ret < 0) {
LogError("error: failed to do mounts."); LogError("error: failed to mount devices.");
return -1; return -1;
} }
ret = DoCtrlDeviceMounting(config->rootfs); ret = DoCtrlDeviceMounting(config->rootfs);
if (ret < 0) { if (ret < 0) {
LogError("error: failed to do mount files."); LogError("error: failed to mount ctrl devices.");
return -1; return -1;
} }
if (!IsOptionNoDrvSet()) { if (IsOptionNoDrvSet()) {
ret = DoDirectoryMounting(config->rootfs); return 0;
if (ret < 0) { }
LogError("error: failed to do mount directory.");
return -1; ret = DoFileMounting(config->rootfs);
} if (ret < 0) {
LogError("error: failed to mount files.");
return -1;
}
ret = DoDirectoryMounting(config->rootfs);
if (ret < 0) {
LogError("error: failed to do mount directories.");
return -1;
} }
return 0; return 0;

View File

@@ -71,7 +71,7 @@ int GetParentPathStr(const char *path, char *parent, size_t bufSize)
return 0; return 0;
} }
int MakeParentDir(const char *path, mode_t mode) int MakeDirWithParent(const char *path, mode_t mode)
{ {
if (*path == '\0' || *path == '.') { if (*path == '\0' || *path == '.') {
return 0; return 0;
@@ -82,15 +82,13 @@ int MakeParentDir(const char *path, mode_t mode)
char parentPath[BUF_SIZE] = {0}; char parentPath[BUF_SIZE] = {0};
GetParentPathStr(path, parentPath, BUF_SIZE); GetParentPathStr(path, parentPath, BUF_SIZE);
if (strlen(parentPath) > 0 && MakeParentDir(parentPath, mode) < 0) { if (strlen(parentPath) > 0 && MakeDirWithParent(parentPath, mode) < 0) {
return -1; return -1;
} }
struct stat s; int ret = MkDir(path, mode);
int ret = stat(path, &s);
if (ret < 0) { if (ret < 0) {
LogError("error: failed to stat path: %s.", path); return -1;
return (MkDir(path, mode));
} }
return 0; return 0;
@@ -98,6 +96,16 @@ int MakeParentDir(const char *path, mode_t mode)
int CreateFile(const char *path, mode_t mode) int CreateFile(const char *path, mode_t mode)
{ {
/* directory */
char parentDir[BUF_SIZE] = {0};
GetParentPathStr(path, parentDir, BUF_SIZE);
int ret = MakeDirWithParent(parentDir, DEFAULT_DIR_MODE);
if (ret < 0) {
LogError("error: failed to make parent dir for file: %s", path);
return -1;
}
char resolvedPath[PATH_MAX] = {0}; char resolvedPath[PATH_MAX] = {0};
if (realpath(path, resolvedPath) == NULL && errno != ENOENT) { if (realpath(path, resolvedPath) == NULL && errno != ENOENT) {
LogError("error: failed to resolve path %s.", path); LogError("error: failed to resolve path %s.", path);

View File

@@ -15,7 +15,7 @@ int MkDir(const char *dir, int mode);
int VerifyPathInfo(const struct PathInfo* pathInfo); int VerifyPathInfo(const struct PathInfo* pathInfo);
int CheckDirExists(const char *dir); int CheckDirExists(const char *dir);
int GetParentPathStr(const char *path, char *parent, size_t bufSize); int GetParentPathStr(const char *path, char *parent, size_t bufSize);
int MakeParentDir(const char *path, mode_t mode); int MakeDirWithParent(const char *path, mode_t mode);
int CreateFile(const char *path, mode_t mode); int CreateFile(const char *path, mode_t mode);
#endif #endif