feat: 支持进程挂载目录和进程命名空间增强

BREAKING CHANGE:
支持进程挂载目录和进程命名空间增强对外变更:
1.支持进程挂载目录,在/proc下可以看到进程挂载目录
2.支持pid容器和uts容器信息查询

Close #I6AEVV

Signed-off-by: zhushengle <zhushengle@huawei.com>
Change-Id: I6777889552d77e49da81249063f9f3db0af96f34
This commit is contained in:
zhushengle
2023-01-14 10:29:54 +08:00
parent be9cee4c21
commit 41619f004d
41 changed files with 2020 additions and 47 deletions

View File

@@ -32,6 +32,12 @@
#ifdef LOSCFG_KERNEL_CONTAINER
STATIC Container g_rootContainer;
STATIC Atomic g_containerCount = 0xF0000000U;
UINT32 OsAllocContainerID(VOID)
{
return LOS_AtomicIncRet(&g_containerCount);
}
VOID OsContainerInitSystemProcess(LosProcessCB *processCB)
{
@@ -108,7 +114,7 @@ VOID OsContainersDestroy(LosProcessCB *processCB)
{
/* All processes in the container must be destroyed before the container is destroyed. */
#ifdef LOSCFG_PID_CONTAINER
if (processCB->processID == 1) {
if (processCB->processID == OS_USER_ROOT_PROCESS_ID) {
OsPidContainersDestroyAllProcess(processCB);
}
#endif
@@ -125,4 +131,21 @@ VOID OsContainersDestroy(LosProcessCB *processCB)
}
#endif
}
UINT32 OsGetContainerID(Container *container, ContainerType type)
{
if (container == NULL) {
return OS_INVALID_VALUE;
}
switch (type) {
case PID_CONTAINER:
return OsGetPidContainerID(container->pidContainer);
case UTS_CONTAINER:
return OsGetUtsContainerID(container->utsContainer);
default:
break;
}
return OS_INVALID_VALUE;
}
#endif

View File

@@ -242,6 +242,7 @@ STATIC PidContainer *CreateNewPidContainer(PidContainer *parent)
}
(VOID)memset_s(newPidContainer, sizeof(PidContainer), 0, sizeof(PidContainer));
newPidContainer->containerID = OsAllocContainerID();
LOS_ListInit(&newPidContainer->pidFreeList);
for (index = 0; index < LOSCFG_BASE_CORE_PROCESS_LIMIT; index++) {
ProcessVid *vpid = &newPidContainer->pidArray[index];
@@ -392,6 +393,23 @@ UINT32 OsGetVpidFromCurrContainer(const LosProcessCB *processCB)
return OS_INVALID_VALUE;
}
UINT32 OsGetVpidFromRootContainer(const LosProcessCB *processCB)
{
UINT32 vpid = processCB->processID;
PidContainer *pidContainer = processCB->container->pidContainer;
while (pidContainer != NULL) {
ProcessVid *vid = &pidContainer->pidArray[vpid];
if (pidContainer->parent != NULL) {
vpid = vid->vpid;
pidContainer = pidContainer->parent;
continue;
}
return vid->vid;
}
return OS_INVALID_VALUE;
}
UINT32 OsGetVtidFromCurrContainer(const LosTaskCB *taskCB)
{
UINT32 vtid = taskCB->taskID;
@@ -423,4 +441,12 @@ LosTaskCB *OsGetTCBFromVtid(UINT32 vtid)
return (LosTaskCB *)taskVid->cb;
}
UINT32 OsGetPidContainerID(PidContainer *pidContainer)
{
if (pidContainer == NULL) {
return OS_INVALID_VALUE;
}
return pidContainer->containerID;
}
#endif

View File

@@ -46,6 +46,7 @@ STATIC UINT32 CreateUtsContainer(UtsContainer **newUtsContainer)
}
(VOID)memset_s(utsContainer, sizeof(UtsContainer), 0, sizeof(UtsContainer));
utsContainer->containerID = OsAllocContainerID();
LOS_AtomicSet(&utsContainer->rc, 1);
SCHEDULER_LOCK(intSave);
@@ -158,4 +159,14 @@ struct utsname *OsGetCurrUtsName(VOID)
}
return &utsContainer->utsName;
}
UINT32 OsGetUtsContainerID(UtsContainer *utsContainer)
{
if (utsContainer == NULL) {
return OS_INVALID_VALUE;
}
return utsContainer->containerID;
}
#endif

View File

@@ -40,6 +40,7 @@
#ifdef LOSCFG_FS_VFS
#include "fs/fd_table.h"
#include "fs/fs_operation.h"
#include "internal.h"
#endif
#include "time.h"
#include "user_copy.h"
@@ -436,6 +437,11 @@ LITE_OS_SEC_TEXT VOID OsProcessResourcesToFree(LosProcessCB *processCB)
(VOID)LOS_MemFree(m_aucSysMem1, processCpup);
#endif
#ifdef LOSCFG_PROC_PROCESS_DIR
ProcFreeProcessDir(processCB->procDir);
processCB->procDir = NULL;
#endif
#ifdef LOSCFG_KERNEL_CONTAINER
OsContainersDestroy(processCB);
#endif
@@ -1905,6 +1911,13 @@ STATIC UINT32 OsCopyFile(UINT32 flags, LosProcessCB *childProcessCB, LosProcessC
if (childProcessCB->files == NULL) {
return LOS_ENOMEM;
}
#ifdef LOSCFG_PROC_PROCESS_DIR
INT32 ret = ProcCreateProcessDir(OsGetRootPid(childProcessCB), (UINTPTR)childProcessCB);
if (ret < 0) {
PRINT_ERR("ProcCreateProcessDir failed, pid = %u\n", childProcessCB->processID);
return LOS_EBADF;
}
#endif
#endif
childProcessCB->consoleID = runProcessCB->consoleID;

View File

@@ -40,6 +40,12 @@
#include "los_uts_container_pri.h"
#endif
typedef enum {
CONTAINER = 0,
PID_CONTAINER,
UTS_CONTAINER,
} ContainerType;
typedef struct Container {
Atomic rc;
#ifdef LOSCFG_PID_CONTAINER
@@ -57,5 +63,9 @@ VOID OsInitRootContainer(VOID);
UINT32 OsCopyContainers(UINTPTR flags, LosProcessCB *child, LosProcessCB *parent, UINT32 *processID);
VOID OsContainersDestroy(LosProcessCB *processCB);
UINT32 OsAllocContainerID(VOID);
UINT32 OsGetContainerID(Container *container, ContainerType type);
#endif
#endif /* _LOS_CONTAINER_PRI_H */

View File

@@ -51,6 +51,7 @@ typedef struct PidContainer {
Atomic rc;
Atomic level;
Atomic lock;
UINT32 containerID;
struct PidContainer *parent;
struct ProcessGroup *rootPGroup;
LOS_DL_LIST tidFreeList;
@@ -82,10 +83,14 @@ LosTaskCB *OsGetTCBFromVtid(UINT32 vtid);
UINT32 OsGetVpidFromCurrContainer(const LosProcessCB *processCB);
UINT32 OsGetVpidFromRootContainer(const LosProcessCB *processCB);
UINT32 OsGetVtidFromCurrContainer(const LosTaskCB *taskCB);
VOID OsFreeVtid(LosTaskCB *taskCB);
UINT32 OsAllocVtid(LosTaskCB *taskCB, const LosProcessCB *processCB);
UINT32 OsGetPidContainerID(PidContainer *pidContainer);
#endif /* _LOS_PID_CONTAINER_PRI_H */

View File

@@ -133,6 +133,9 @@ typedef struct ProcessCB {
#ifdef LOSCFG_KERNEL_CONTAINER
struct Container *container;
#endif
#ifdef LOSCFG_PROC_PROCESS_DIR
struct ProcDirEntry *procDir;
#endif
} LosProcessCB;
extern LosProcessCB *g_processCBArray;
@@ -443,6 +446,15 @@ STATIC INLINE UINT32 OsGetPid(const LosProcessCB *processCB)
return processCB->processID;
}
STATIC INLINE UINT32 OsGetRootPid(const LosProcessCB *processCB)
{
#ifdef LOSCFG_PID_CONTAINER
return OsGetVpidFromRootContainer(processCB);
#else
return processCB->processID;
#endif
}
/*
* return immediately if no child has exited.
*/

View File

@@ -38,10 +38,10 @@
#ifdef LOSCFG_UTS_CONTAINER
typedef struct ProcessCB LosProcessCB;
typedef struct UtsContainer {
Atomic rc;
struct utsname utsName;
Atomic rc;
UINT32 containerID;
struct utsname utsName;
} UtsContainer;
UINT32 OsInitRootUtsContainer(UtsContainer **utsContainer);
@@ -52,5 +52,6 @@ VOID OsUtsContainersDestroy(LosProcessCB *curr);
struct utsname *OsGetCurrUtsName(VOID);
UINT32 OsGetUtsContainerID(UtsContainer *utsContainer);
#endif
#endif /* _LOS_UTS_CONTAINER_PRI_H */