Match-id-b08926bead0de9d389a4ccbc630730c47db50300

This commit is contained in:
BianTanggui
2020-07-05 12:06:17 +08:00
parent d29403afa5
commit cd41979504
11 changed files with 80 additions and 38 deletions

View File

@@ -1,3 +1,7 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: ascend-docker-cli工具公共宏和结构体定义
*/
#ifndef _BASIC_H
#define _BASIC_H

View File

@@ -1,3 +1,7 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: ascend-docker-cli工具容器CGroup配置模块
*/
#include "cgrp.h"
#include <stdio.h>

View File

@@ -1,3 +1,7 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: ascend-docker-cli工具容器CGroup配置模块头文件
*/
#ifndef _CGRP_H
#define _CGRP_H

View File

@@ -1,3 +1,7 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: ascend-docker-cli工具日志模块
*/
#include "logging.h"
#include <stdio.h>

View File

@@ -1,3 +1,7 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: ascend-docker-cli工具日志模块头文件
*/
#ifndef _LOGGING_H
#define _LOGGING_H

View File

@@ -1,8 +1,12 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: ascend-docker-cli工具容器设备与驱动挂载模块
*/
#include "mount.h"
#include <limits.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <sys/stat.h>
#include "securec.h"
#include "utils.h"
@@ -16,7 +20,7 @@ static int GetDeviceMntSrcDst(const char *rootfs, const char *deviceName,
char unresolvedDst[BUF_SIZE] = {0};
char resolvedDst[PATH_MAX] = {0};
ret = VerfifyPathInfo(pathInfo);
ret = VerifyPathInfo(pathInfo);
if (ret < 0) {
return -1;
}

View File

@@ -1,3 +1,7 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: ascend-docker-cli工具容器设备与驱动挂载模块头文件
*/
#ifndef _MOUNT_H
#define _MOUNT_H

View File

@@ -1,3 +1,7 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: ascend-docker-cli工具容器Namespace实用函数模块
*/
#define _GNU_SOURCE
#include "ns.h"

View File

@@ -1,9 +1,13 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: ascend-docker-cli工具容器Namespace实用函数模块头文件
*/
#ifndef _NS_H
#define _NS_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 EnterNsByFd(int fd, int nsType);
int EnterNsByPath(const char *path, int nsType);

View File

@@ -1,8 +1,11 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: ascend-docker-cli工具实用函数模块
*/
#include "utils.h"
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <errno.h>
#include <dirent.h>
@@ -14,7 +17,7 @@
#include "securec.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));
}
@@ -107,28 +110,11 @@ int MkDir(const char *dir, int mode)
return mkdir(dir, mode);
}
int MakeParentDir(const char *path, mode_t mode)
int VerifyPathInfo(const struct PathInfo* pathInfo)
{
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) {
if (pathInfo == NULL || pathInfo->dst == NULL || pathInfo->src == NULL) {
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;
}
@@ -165,6 +151,31 @@ int GetParentPathStr(const char *path, char *parent, size_t bufSize)
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)
{
char resolvedPath[PATH_MAX] = {0};
@@ -182,14 +193,6 @@ int CreateFile(const char *path, mode_t mode)
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)
{
static const unsigned long remountFlags = MS_BIND | MS_REMOUNT | MS_RDONLY | MS_NOSUID;

View File

@@ -1,26 +1,29 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
* Description: ascend-docker-cli工具实用函数模块头文件
*/
#ifndef _UTILS_H
#define _UTILS_H
#include <stdbool.h>
#include <limits.h>
#include <sys/types.h>
#include "basic.h"
// For cgroup setup
int StrHasPrefix(const char *str, const char *prefix);
typedef char *(*ParseFileLine)(char *, const char *);
int CatFileContent(char* buffer, int bufferSize, ParseFileLine fn, const char* filepath);
bool CheckRootDir(char **pLine);
bool CheckFsType(char **pLine);
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
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 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 VerfifyPathInfo(const struct PathInfo* pathInfo);
int Mount(const char *src, const char *dst);
#endif