mirror of
https://github.com/Ascend/ascend-docker-runtime.git
synced 2025-10-13 05:13:40 +08:00
Match-id-b08926bead0de9d389a4ccbc630730c47db50300
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||||
|
* Description: ascend-docker-cli工具公共宏和结构体定义
|
||||||
|
*/
|
||||||
#ifndef _BASIC_H
|
#ifndef _BASIC_H
|
||||||
#define _BASIC_H
|
#define _BASIC_H
|
||||||
|
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||||
|
* Description: ascend-docker-cli工具容器CGroup配置模块
|
||||||
|
*/
|
||||||
#include "cgrp.h"
|
#include "cgrp.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||||
|
* Description: ascend-docker-cli工具容器CGroup配置模块头文件
|
||||||
|
*/
|
||||||
#ifndef _CGRP_H
|
#ifndef _CGRP_H
|
||||||
#define _CGRP_H
|
#define _CGRP_H
|
||||||
|
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||||
|
* Description: ascend-docker-cli工具日志模块
|
||||||
|
*/
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||||
|
* Description: ascend-docker-cli工具日志模块头文件
|
||||||
|
*/
|
||||||
#ifndef _LOGGING_H
|
#ifndef _LOGGING_H
|
||||||
#define _LOGGING_H
|
#define _LOGGING_H
|
||||||
|
|
||||||
|
@@ -1,8 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||||
|
* Description: ascend-docker-cli工具容器设备与驱动挂载模块
|
||||||
|
*/
|
||||||
#include "mount.h"
|
#include "mount.h"
|
||||||
|
|
||||||
#include <limits.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "securec.h"
|
#include "securec.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@@ -16,7 +20,7 @@ static int GetDeviceMntSrcDst(const char *rootfs, const char *deviceName,
|
|||||||
char unresolvedDst[BUF_SIZE] = {0};
|
char unresolvedDst[BUF_SIZE] = {0};
|
||||||
char resolvedDst[PATH_MAX] = {0};
|
char resolvedDst[PATH_MAX] = {0};
|
||||||
|
|
||||||
ret = VerfifyPathInfo(pathInfo);
|
ret = VerifyPathInfo(pathInfo);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||||
|
* Description: ascend-docker-cli工具容器设备与驱动挂载模块头文件
|
||||||
|
*/
|
||||||
#ifndef _MOUNT_H
|
#ifndef _MOUNT_H
|
||||||
#define _MOUNT_H
|
#define _MOUNT_H
|
||||||
|
|
||||||
|
@@ -1,3 +1,7 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||||
|
* Description: ascend-docker-cli工具容器Namespace实用函数模块
|
||||||
|
*/
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include "ns.h"
|
#include "ns.h"
|
||||||
|
|
||||||
|
@@ -1,9 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||||
|
* Description: ascend-docker-cli工具容器Namespace实用函数模块头文件
|
||||||
|
*/
|
||||||
#ifndef _NS_H
|
#ifndef _NS_H
|
||||||
#define _NS_H
|
#define _NS_H
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
int GetNsPath(const int pid, const char *nsType, char *buf, size_t bufSize);
|
int GetNsPath(int pid, const char *nsType, char *buf, size_t bufSize);
|
||||||
int GetSelfNsPath(const char *nsType, char *buf, size_t bufSize);
|
int GetSelfNsPath(const char *nsType, char *buf, size_t bufSize);
|
||||||
int EnterNsByFd(int fd, int nsType);
|
int EnterNsByFd(int fd, int nsType);
|
||||||
int EnterNsByPath(const char *path, int nsType);
|
int EnterNsByPath(const char *path, int nsType);
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||||
|
* Description: ascend-docker-cli工具实用函数模块
|
||||||
|
*/
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
@@ -14,7 +17,7 @@
|
|||||||
#include "securec.h"
|
#include "securec.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
int IsStrEqual(const char *s1, const char *s2)
|
static int IsStrEqual(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
return (!strcmp(s1, s2));
|
return (!strcmp(s1, s2));
|
||||||
}
|
}
|
||||||
@@ -107,28 +110,11 @@ int MkDir(const char *dir, int mode)
|
|||||||
return mkdir(dir, mode);
|
return mkdir(dir, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MakeParentDir(const char *path, mode_t mode)
|
int VerifyPathInfo(const struct PathInfo* pathInfo)
|
||||||
{
|
{
|
||||||
if (*path == '\0' || *path == '.') {
|
if (pathInfo == NULL || pathInfo->dst == NULL || pathInfo->src == NULL) {
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (CheckDirExists(path) == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
char parentPath[BUF_SIZE] = {0};
|
|
||||||
GetParentPathStr(path, parentPath, BUF_SIZE);
|
|
||||||
if (strlen(parentPath) > 0 && MakeParentDir(parentPath, mode) < 0) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat s;
|
|
||||||
int ret = stat(path, &s);
|
|
||||||
if (ret < 0) {
|
|
||||||
logError("error: failed to stat path: %s\n", path);
|
|
||||||
return (MkDir(path, mode));
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +151,31 @@ int GetParentPathStr(const char *path, char *parent, size_t bufSize)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MakeParentDir(const char *path, mode_t mode)
|
||||||
|
{
|
||||||
|
if (*path == '\0' || *path == '.') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (CheckDirExists(path) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char parentPath[BUF_SIZE] = {0};
|
||||||
|
GetParentPathStr(path, parentPath, BUF_SIZE);
|
||||||
|
if (strlen(parentPath) > 0 && MakeParentDir(parentPath, mode) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct stat s;
|
||||||
|
int ret = stat(path, &s);
|
||||||
|
if (ret < 0) {
|
||||||
|
logError("error: failed to stat path: %s\n", path);
|
||||||
|
return (MkDir(path, mode));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int CreateFile(const char *path, mode_t mode)
|
int CreateFile(const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
char resolvedPath[PATH_MAX] = {0};
|
char resolvedPath[PATH_MAX] = {0};
|
||||||
@@ -182,14 +193,6 @@ int CreateFile(const char *path, mode_t mode)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VerfifyPathInfo(const struct PathInfo* pathInfo)
|
|
||||||
{
|
|
||||||
if (pathInfo == NULL || pathInfo->dst == NULL || pathInfo->src == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Mount(const char *src, const char *dst)
|
int Mount(const char *src, const char *dst)
|
||||||
{
|
{
|
||||||
static const unsigned long remountFlags = MS_BIND | MS_REMOUNT | MS_RDONLY | MS_NOSUID;
|
static const unsigned long remountFlags = MS_BIND | MS_REMOUNT | MS_RDONLY | MS_NOSUID;
|
||||||
|
@@ -1,26 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
|
||||||
|
* Description: ascend-docker-cli工具实用函数模块头文件
|
||||||
|
*/
|
||||||
#ifndef _UTILS_H
|
#ifndef _UTILS_H
|
||||||
#define _UTILS_H
|
#define _UTILS_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <limits.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include "basic.h"
|
#include "basic.h"
|
||||||
|
|
||||||
// For cgroup setup
|
// For cgroup setup
|
||||||
int StrHasPrefix(const char *str, const char *prefix);
|
int StrHasPrefix(const char *str, const char *prefix);
|
||||||
typedef char *(*ParseFileLine)(char *, const char *);
|
bool CheckRootDir(char **pLine);
|
||||||
int CatFileContent(char* buffer, int bufferSize, ParseFileLine fn, const char* filepath);
|
|
||||||
bool CheckFsType(char **pLine);
|
bool CheckFsType(char **pLine);
|
||||||
bool CheckSubStr(char **pLine, const char *subsys);
|
bool CheckSubStr(char **pLine, const char *subsys);
|
||||||
bool CheckRootDir(char **pLine);
|
typedef char *(*ParseFileLine)(char *, const char *);
|
||||||
|
int CatFileContent(char* buffer, int bufferSize, ParseFileLine fn, const char* filepath);
|
||||||
|
|
||||||
// For mount setup
|
// For mount setup
|
||||||
int MkDir(const char *dir, int mode);
|
int MkDir(const char *dir, int mode);
|
||||||
int MakeParentDir(const char *path, mode_t mode);
|
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 CreateFile(const char *path, mode_t mode);
|
int CreateFile(const char *path, mode_t mode);
|
||||||
int VerfifyPathInfo(const struct PathInfo* pathInfo);
|
|
||||||
int Mount(const char *src, const char *dst);
|
int Mount(const char *src, const char *dst);
|
||||||
|
|
||||||
#endif
|
#endif
|
Reference in New Issue
Block a user