1e41f4b71Sopenharmony_ci# Container 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## Overview 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciContainer provides a mechanism to isolate global resources, such as process identifiers (PIDs), host information, and user information. The container mechanism allows the processes in different containers to have independent global resources. Changing system resources in a container does not affect processes in other containers. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciThe LiteOS-A kernel container isolation function involves seven containers: UTS container, PID container, Mount container, Network container, Time container, IPC container, and User container. The container information is stored in the **container** and **credentials** structs of the process control block (**ProcessCB**) struct. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ciThe following table lists the LiteOS-A containers. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci| No. | Name | Macro Definition/Flag | Resource | Data Struct | 12e41f4b71Sopenharmony_ci| :-------- | :------------- | :------------------- | :----------------------- | :----------------------- | 13e41f4b71Sopenharmony_ci| 1 | UTS | CLONE_NEWUTS | Host names, domain names, and version information.|struct Container | 14e41f4b71Sopenharmony_ci| 2 | PID | CLONE_NEWPID | PIDs. |struct Container | 15e41f4b71Sopenharmony_ci| 3 | Mount | CLONE_NEWNS | File system mount points. |struct Container | 16e41f4b71Sopenharmony_ci| 4 | Network | CLONE_NEWNET | Network system resources. |struct Container | 17e41f4b71Sopenharmony_ci| 5 | TIME | CLONE_NEWTIME | Clock resources. |struct Container | 18e41f4b71Sopenharmony_ci| 6 | IPC | CLONE_NEWIPC | Inter-process communication (IPC) resources. |struct Container | 19e41f4b71Sopenharmony_ci| 7 | User | CLONE_NEWUSER | Users and user groups. |struct Credentials | 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciThe container-based resource isolation can be further classified into the following types: 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci - Global isolation: The containers are parallel (without inheritance relationships), and the container resources are invisible to each other. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci - Non-global isolation: The containers have parent-child relationships. The resources of containers of the same level are invisible, but the upper-level container can access resources of the lower-level container. 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ciFor the PID container, **unshare()** or **setns()** changes the container of the child process (not the process). 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ciYou can add a **Container** struct and a **Credentials** struct to the **ProcessCB** of a process to implement container functionalities. You can also enable or disable specific container by using compiler switches. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci - The **ProcessCB** struct of each process contains a pointer to the **Container** struct allocated. This allows a process to have an independent **Container** struct or share a **Container** struct. The **Container** struct contains pointers to the UTS, PID, Network, Mount, Time, and IPC containers. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci - The **ProcessCB** struct of each process has a **Credentials** struct for independent User container management. This design facilitates modularization and independent processing of the unique logic of the User container. 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci### Containers 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci#### **UTS Container** 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ciThe UTS container isolates information, such as host names, domain names, and version information. The information in different UTS containers is isolated from each other. 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci#### **Mount Container** 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ciThe Mount container isolates file mount points. The mount and unmount operations in a container does not affect other containers. 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ciThe Mount container allows processes to use the file mounting system independently. Child processes perform mount operations in independent file mounting containers and have their own file mount structs. 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci- To implement a Mount container, use **clone()** with the **CLONE_NEWNS** flag to create a process, and change the mount information from global information to the information specific to the Mount container. 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci- After a Mount container is created, change the implementation of obtaining the mount information to enable the mount information to be obtained from the current Mount container. After that, the mount, unmount, and access to the mounted file system of the process do not affect that of other processes. 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci#### **PID Container** 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ciThe PID container isolates PIDs. Processes of different containers can use the same virtual process ID. 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci The PID container provides the following features: 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci- The PIDs of different containers are independent of each other. 62e41f4b71Sopenharmony_ci- Nested PID containers are supported. The processes in the child PID containers are visible to the parent PID container. For the same process, the PID in the parent PID container is independent from the PID in the child PID container. 63e41f4b71Sopenharmony_ci- The child PID container cannot view the processes in its parent container. 64e41f4b71Sopenharmony_ci- All PIDs of the system can be viewed in the root container. 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci#### **Network Container** 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ciThe Network container isolates the system's network devices and network stacks. 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ciThe Network container isolates the TCP/IP protocol stacks and network device resources. 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci - Transport layer isolation: The Network container isolates port numbers. The available port numbers in a Network container range from 0 to 65535. A process is bound to the port number of its own container. Processes of different Network containers can be bound to the same TCP/UDP port number without affecting each other. 73e41f4b71Sopenharmony_ci - IP layer isolation: The Network container isolates IP resources. Each container has its own IP resources. Changing the IP address in a Network container does not affect other Network containers. 74e41f4b71Sopenharmony_ci - Network device isolation: The Network container isolates network interface cards (NICs). Each container has its own NICs. The NICs in different Network containers are isolated from each other and cannot communicate with each other. You can configure veth-pair to implement communication between different containers. 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci#### **User Container** 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ciThe User container isolates users and user groups. 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ciThe User container isolates management rights by User ID or Group ID (UID/GID) and capability. 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci- UID/GID 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci The User container isolates UIDs/GIDs. Different User containers have different UIDs/GIDs. Each User container has independent UIDs/GIDs starting from 0. In this way, the processes in the container can have the **root** permission, which is restricted to the minimum range. Changing the UID/GID of a User container does not affect the processes of other User containers. 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci- Capability 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci With the User container, you can set different capabilities for processes. 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci Each process calls **OsInitCapability()** to initialize its permissions. You can use **SysCapGet()** to obtain the capabilities of a process, and use **SysCapSet()** to modify the process permissions. 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ciThe following table describes the capabilities. 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci| Capability | Description | 95e41f4b71Sopenharmony_ci| --------------------- | ---------------------------------------------- | 96e41f4b71Sopenharmony_ci| CAP_CHOWN | Changes the owner of a file. | 97e41f4b71Sopenharmony_ci| CAP_DAC_EXECUTE | Overrides the Discretionary Access Control (DAC) restriction on file execution. | 98e41f4b71Sopenharmony_ci| CAP_DAC_WRITE | Overrides the DAC restriction on file write. | 99e41f4b71Sopenharmony_ci| CAP_DAC_READ_SEARCH | Overrides the DAC restriction on file read or search of a directory. | 100e41f4b71Sopenharmony_ci| CAP_FOWNER | Overrides the requirement that the file owner ID must match the process user ID.| 101e41f4b71Sopenharmony_ci| CAP_KILL | Sends a **kill** signal to another process that is not owned by the sender. | 102e41f4b71Sopenharmony_ci| CAP_SETGID | Changes the GID of a process. | 103e41f4b71Sopenharmony_ci| CAP_SETUID | Changes the UID of a process. | 104e41f4b71Sopenharmony_ci| CAP_NET_BIND_SERVICE | Binds a socket to a port whose number is less than 1024. | 105e41f4b71Sopenharmony_ci| CAP_NET_BROADCAST | Allows network broadcast and multicast access. | 106e41f4b71Sopenharmony_ci| CAP_NET_ADMIN | Allows network management tasks to be executed. | 107e41f4b71Sopenharmony_ci| CAP_NET_RAW | Allows the use of raw sockets. | 108e41f4b71Sopenharmony_ci| CAP_FS_MOUNT | Allows **chroot()**. | 109e41f4b71Sopenharmony_ci| CAP_FS_FORMAT | Allows the use of the file format. | 110e41f4b71Sopenharmony_ci| CAP_SCHED_SETPRIORITY | Sets the process scheduling priority. | 111e41f4b71Sopenharmony_ci| CAP_SET_TIMEOFDAY | Sets the system time. | 112e41f4b71Sopenharmony_ci| CAP_CLOCK_SETTIME | Sets the clock time. | 113e41f4b71Sopenharmony_ci| CAP_CAPSET | Sets any capability. | 114e41f4b71Sopenharmony_ci| CAP_REBOOT | Restarts the system. | 115e41f4b71Sopenharmony_ci| CAP_SHELL_EXEC | Executes shell. | 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci#### **Time Container** 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ciThe Time container isolates the time maintenance information of the system. 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ciEach process has its own Time container to hold the **CLOCK_MONOTONIC** and **CLOCK_MONOTONIC_RAW** clocks so that the operations on these clocks do not affect the clocks of other processes. 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ciThe clock offset in the time_for_children container of the current process is recorded in the **/proc/PID/timens_offsets** file. You can also modify the file to change the offset of the Time container. These offsets indicate the time difference from the clock value in the initial Time container. 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ciCurrently, the only way to create a Time container is to call **unshare()** with the **CLONE_NEWTIME** flag. The Time container created holds the child process created by the calling process instead of the calling process. 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ciYou need to set the clock offset (**/proc/PID/timens_offsets**) for this container before the first process of the container is created. 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci#### **IPC Container** 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ciThe IPC container isolates IPC objects, including the message queues and shared memory. 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ciEach process has its own IPC container to hold the message queue and shared memory. 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ciAs a result, the operations on the message queue and shared memory in different containers do not affect each other. 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci- Message queue isolation: Change the global variable struct **LosQueueCB** to a local variable in each IPC container to implement the message queue isolation. 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci- Shared memory isolation: Change the global variables **shmInfo**, **sysvShmMux**, **shmSegs**, and **shmUsedPageCount** to local variables in each IPC container to implement the isolation of the shared memory. 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci### Working Principles 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci#### Process of Creating a Container 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ciDuring the system initialization process, a root container is created for initial processes (processes 0, 1, and 2). The root container types include all of the seven containers. 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ciYou can use **clone()** with the container flag specified to create a container for a process. If the container flag is not specified, the process reuses its parent process container. 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci#### Process of Switching a Container 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ciUse **unshare()** to move a process to a newly created container. The following figure uses the IPC container as an example. 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci<img src="figures/container-003.png" alt="ContainerBase" style="zoom:80%;" /> 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci## How to Develop 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ciThe following describes how to create, switch, and destroy a container. 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci### Creating a Container 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ciYou can create a container when using **clone()** to create a process. 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci**clone** 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ciA container can be created when you use **clone()** to create a process. The function prototype is as follows: 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci``` 172e41f4b71Sopenharmony_ciint clone(int (*fn)(void *), void *stack, int flags, void *arg, ... 173e41f4b71Sopenharmony_ci /* pid_t *parent_tid, void *tls, pid_t *child_tid */ ); 174e41f4b71Sopenharmony_ci``` 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci - When using **clone()** to create a process, you can specify a container to isolate resources (such as the UTS information) for the process. 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci - If no container flag is specified, the process shares the containers of its parent process. 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci### Switching a Container 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci You can use either of the following interfaces to move a process to another container: 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci- **unshare** 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci Use **unshare()** to move a process to a newly created container. The function prototype is as follows: 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci ``` 189e41f4b71Sopenharmony_ci int unshare(int flags); 190e41f4b71Sopenharmony_ci ``` 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci > **NOTE** 193e41f4b71Sopenharmony_ci > 194e41f4b71Sopenharmony_ci > For the PID or Time container, **unshare()** moves the child process (not the process itself) to a new container created. 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci- **setns** 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci Use **setns()** to move a process to another existing container. The function prototype is as follows: 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci ``` 201e41f4b71Sopenharmony_ci int setns(int fd, int nstype); 202e41f4b71Sopenharmony_ci ``` 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci > **NOTE** 205e41f4b71Sopenharmony_ci > 206e41f4b71Sopenharmony_ci > For the PID or Time container, **setns()** moves the child process (not the process itself) to another container. 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci### Destroying a Container 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ciWhen a process is terminated, it exits all containers and the container reference count decrements. When the reference count decrements to 0, you need to destroy the container. 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ciYou can use **kill()** to send a specified signal to the process to terminate or exit it. The function prototype is as follows: 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci``` 215e41f4b71Sopenharmony_ciint kill(pid_t pid, int sig); 216e41f4b71Sopenharmony_ci``` 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci### Querying Container Information 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ciYou can run the **ls** command to view container information in the **/proc/[pid]/container/** directory. 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci``` 223e41f4b71Sopenharmony_cils -l /proc/[pid]/container 224e41f4b71Sopenharmony_ci``` 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci| Property | User| User Group| File Name | Description | 227e41f4b71Sopenharmony_ci| :--------- | :------- | :--------- | :--------------------------------------- | :--------------------- | 228e41f4b71Sopenharmony_ci| lr--r--r-- | u:0 | g:0 | net -> 'net:[4026531847]' | The referenced object is the container with a unique ID.| 229e41f4b71Sopenharmony_ci| lr--r--r-- | u:0 | g:0 | user -> 'user:[4026531841]' | The referenced object is the container with a unique ID. | 230e41f4b71Sopenharmony_ci| lr--r--r-- | u:0 | u:0 | time_for_children -> 'time:[4026531846]' | The referenced object is the container with a unique ID. | 231e41f4b71Sopenharmony_ci| lr--r--r-- | u:0 | g:0 | time -> 'time:[4026531846]' | The referenced object is the container with a unique ID. | 232e41f4b71Sopenharmony_ci| lr--r--r-- | u:0 | g:0 | ipc -> 'ipc:[4026531845]' | The referenced object is the container with a unique ID. | 233e41f4b71Sopenharmony_ci| lr--r--r-- | u:0 | g:0 | mnt -> 'mnt:[4026531844]' | The referenced object is the container with a unique ID. | 234e41f4b71Sopenharmony_ci| lr--r--r-- | u:0 | g:0 | uts -> 'uts:[4026531843]' | The referenced object is the container with a unique ID. | 235e41f4b71Sopenharmony_ci| lr--r--r-- | u:0 | g:0 | pid_for_children -> 'pid:[4026531842]' | The referenced object is the container with a unique ID. | 236e41f4b71Sopenharmony_ci| lr--r--r-- | u:0 | g:0 | pid -> 'pid:[4026531842]' | The referenced object is the container with a unique ID. | 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci### plimits 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ciplimits sets resource limits of process groups. **/proc/plimits** is the root directory of plimits. 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci- The plimits file system is a pseudo file system used to implement mappings between files and plimits variables. With this file system, you can modify kernel variables through operations on files. For example, you can modify the **memory.limit** file to restrict memory allocation. 243e41f4b71Sopenharmony_ci- In the plimits file system, files can be read and written, and directories can be added or deleted. 244e41f4b71Sopenharmony_ci- A plimits directory maps a plimits group. When a directory is created, the files (mapped to the control variables of the limiter) in the directory are automatically created. 245e41f4b71Sopenharmony_ci- Files for a limiter are created by group. For example, when a memory limiter is created, all files required, instead of a single file, are created. 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ciThe macro **LOSCFG_PROCESS_LIMITS** specifies the setting of plimits. **y** means to enable plimits, and **n** (default) means the opposite. 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ciIf **LOSCFG_PROCESS_LIMITS** is set to **y**, the **/proc/plimits** directory contains the following files: 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci| Permission | User| User Group| File Name | Description | Remarks | 252e41f4b71Sopenharmony_ci| ---------- | ---- | ------ | ---------------- | --------------------------------- | ------------------------------------------------------------ | 253e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | sched.stat | Scheduling statistics information. | Output format: [PID runTime] | 254e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | sched.period | Scheduling period configuration, in μs. | / | 255e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | sched.quota | Scheduling quota configuration, in μs. | / | 256e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | devices.list | List of the devices accessed by processes in plimits. | Output format: [type name access] | 257e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | devices.deny | Devices that cannot be accessed by the processes in plimits.| Format: ["type name access" >> device.deny] | 258e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | devices.allow | Devices that can be accessed by the processes in plimits.| Format: ["type name access" >> device.allow] | 259e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | ipc.stat | Statistics about the IPC objects allocated. | Output format: [mq count: mq failed count:<br> shm size: shm failed count: ] | 260e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | ipc.shm_limit | Upper limit of the shared memory, in bytes. | / | 261e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | ipc.mq_limit | Maximum number of messages in a message queue. | 0 to 64-bit positive integer | 262e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | memory.stat | Memory statistics, in bytes. | / | 263e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | memory.limit | Total memory limit for a process group, in bytes. | / | 264e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | pids.max | Maximum number of processes in a group. | / | 265e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | pids.priority | Highest process priority in a group. | / | 266e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | plimits.procs | PIDs of all processes in a group. | / | 267e41f4b71Sopenharmony_ci| -r--r--r-- | u:0 | g:0 | plimits.limiters | Limiters in the plimits group. | / | 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ciThe **devices** parameter is described as follows: 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci| type (Device Type) | name (Device Name)| access (Permission) | 272e41f4b71Sopenharmony_ci| -------------------------------------------- | ----------------- | ---------------------------------- | 273e41f4b71Sopenharmony_ci| a - All devices, which can be character devices or block devices.| / | r - Allow the process to read the specified device. | 274e41f4b71Sopenharmony_ci| b - Block device | / | w - Allow the process to write to the specified device. | 275e41f4b71Sopenharmony_ci| c - Character device | / | m - Allow the process to generate a file that does not exist.| 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci## Reference 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci### Specifications 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci#### Parameter Settings 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci**LOSCFG_KERNEL_CONTAINER_DEFAULT_LIMIT** specifies the maximum number of containers of each type supported by the kernel. 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ciThe initialization of the **proc/sys/user** directory generates the **max_net_container**, **max_ipc_container**, **max_time_container**, **max_uts_container**, **max_user_container**, **max_pid_container**, and **max_mnt_container** files, and binds the pseudo files and kernel parameters. You can modify the kernel parameters by configuring the pseudo files. New containers can be created if the number of containers is less than the maximum. Otherwise, NULL is returned. 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci#### **Unique Container ID** 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ciAll the containers are uniquely numbered based on a fixed value. 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci``` 292e41f4b71Sopenharmony_ci#define CONTAINER_IDEX_BASE (0xF0000000) 293e41f4b71Sopenharmony_ciinum = CONTAINER_IDEX_BASE + (unsigned int)i; 294e41f4b71Sopenharmony_ci``` 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci#### **Rule Settings** 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci- The PID container and User container support nesting of up to three layers. Other containers do not support nested containers. 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci- When **clone()**, **setns()**, and **unshare()** are used, flags complying with POSIX must be passed in. The flags are described as follows: 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci| Flag | clone | setns | unshare | 303e41f4b71Sopenharmony_ci| ------------- | ---------------------------- | -------------------------------- | -------------------------------- | 304e41f4b71Sopenharmony_ci| CLONE_NEWNS | Create a Mount container for a child process. | Move this process to the specified Mount container.| Create a Mount container for this process. | 305e41f4b71Sopenharmony_ci| CLONE_NEWPID | Create a PID container for a child process. | Move this process to the specified PID container. | Create a PID container for a new child process. | 306e41f4b71Sopenharmony_ci| CLONE_NEWIPC | Create an IPC container for a child process. | Move this process to the specified IPC container. | Create an IPC container for this process. | 307e41f4b71Sopenharmony_ci| CLONE_NEWTIME | Create a Time container for the parent process of this process.| Not supported currently | Create a Time container for a new child process.| 308e41f4b71Sopenharmony_ci| CLONE_NEWUSER | Create a User container for a child process. | Move this process to the specified User container. | Create a User container for this process. | 309e41f4b71Sopenharmony_ci| CLONE_NEWUTS | Create a UTS container for a child process. | Move this process to the specified UTS container. | Create a UTS container for this process. | 310e41f4b71Sopenharmony_ci| CLONE_NEWNET | Create a Network container for a child process. | Move this process to the specified Network container.| Create a Network container for this process. | 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci- The container features are controlled by compiler macros. 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci ``` 315e41f4b71Sopenharmony_ci // Macro of the container feature 316e41f4b71Sopenharmony_ci LOSCFG_CONTAINER 317e41f4b71Sopenharmony_ci // Macro of the container of each type 318e41f4b71Sopenharmony_ci LOSCFG_UTS_CONTAINER 319e41f4b71Sopenharmony_ci LOSCFG_MNT_CONTAINER 320e41f4b71Sopenharmony_ci LOSCFG_PID_CONTAINER 321e41f4b71Sopenharmony_ci LOSCFG_NET_CONTAINER 322e41f4b71Sopenharmony_ci LOSCFG_USER_CONTAINER 323e41f4b71Sopenharmony_ci LOSCFG_TIME_CONTAINER 324e41f4b71Sopenharmony_ci LOSCFG_IPC_CONTAINER 325e41f4b71Sopenharmony_ci ``` 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci### Development Examples 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ciThe LiteOS-A smoke test cases contain the examples of the corresponding interfaces. You need to compile and verify the test cases. The recommended test cases are as follows: 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci[Creating a UTS Container](https://gitee.com/openharmony/kernel_liteos_a/blob/master/testsuites/unittest/container/smoke/It_uts_container_001.cpp) 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci[Moving a Process to a New UTS Container Using unshare()](https://gitee.com/openharmony/kernel_liteos_a/blob/master/testsuites/unittest/container/smoke/It_uts_container_004.cpp) 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci[Moving a Process to the UTS Container of the Child Process Using setns()](https://gitee.com/openharmony/kernel_liteos_a/blob/master/testsuites/unittest/container/smoke/It_uts_container_005.cpp) 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci[Creating a Network Container](https://gitee.com/openharmony/kernel_liteos_a/blob/master/testsuites/unittest/container/smoke/It_net_container_001.cpp) 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci[Creating a User Container](https://gitee.com/openharmony/kernel_liteos_a/blob/master/testsuites/unittest/container/smoke/It_user_container_001.cpp) 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ci[Creating a PID Container](https://gitee.com/openharmony/kernel_liteos_a/blob/master/testsuites/unittest/container/smoke/It_pid_container_023.cpp) 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci[Creating a Mount Container](https://gitee.com/openharmony/kernel_liteos_a/blob/master/testsuites/unittest/container/smoke/It_mnt_container_001.cpp) 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_ci[Creating an IPC Container](https://gitee.com/openharmony/kernel_liteos_a/blob/master/testsuites/unittest/container/smoke/It_ipc_container_001.cpp) 347e41f4b71Sopenharmony_ci 348e41f4b71Sopenharmony_ci[Creating a Time Container](https://gitee.com/openharmony/kernel_liteos_a/blob/master/testsuites/unittest/container/smoke/It_time_container_001.cpp) 349