Method and device for analyzing temporary storage usage of containers in btrfs file system
By obtaining environment variables and directory listings of the btrfs file system through container monitoring tools, calculating paths, and finding changed files, this solves the problem in existing technologies that cannot analyze the temporary storage usage of btrfs file system containers. It enables early detection and management of container storage usage, avoiding container service anomalies.
Patent Information
- Application Number
- CN202310183856.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-24
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2043-02-24
AI Technical Summary
Existing container monitoring tools do not yet support the btrfs file system, making it impossible to effectively analyze the temporary storage usage of the container's root file system. This results in the inability to detect storage usage in advance, which may lead to abnormal container services.
The container monitoring tool executes system calls to obtain the container process environment variables of the btrfs file system, obtains the directory list, calculates the original layer path and user layer path, traverses the directory to find changed files and records their sizes, and determines the amount of temporary storage used by the container in the btrfs file system.
It enables effective analysis of container temporary storage usage in the btrfs file system, allowing for early detection of storage usage and preventing container service anomalies caused by excessive storage consumption.
Smart Images

Figure CN116069740B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of distribution, and particularly relates to a container temporary storage usage analysis method and device in a btrfs file system. BACKGROUND
[0002] This section is intended to provide background or context to the embodiments of the application recited in the claims. The description herein does not constitute admission that the subject matter disclosed herein is prior art to the present application.
[0003] As an isolated running environment, the file system seen by the process in the container is a unified file system. However, in fact, the process in the container may add, modify or delete files on the container file system during running, which will generate certain storage write operations. The contents of these writes should not be directly written into the original container image. Therefore, the container service generally uses a multi-layer file system to form a special file system for the container through mounting mapping, and the temporary data generated should be written into the container-specific file system layer.
[0004] The commonly used docker file system driver in the industry is overlay2, and btrfs is also used as the docker file system driver due to special needs. However, the open source container monitoring tool (cadvisor) component does not support calculating and monitoring the temporary storage usage of the container root file system (referred to as container) of the btrfs file system.
[0005] The implementation principles of the container root file system under overlay2 and btrfs drivers are introduced below.
[0006] The overlay2 file system controls layering in file granularity, and docker will mount multiple levels of directories when used, and store the changed files in the difference file layer. After combining the original file layer and the difference file layer, the user view layer is provided to the user process. All storage changes of the user process will act on the difference file layer.
[0007] For example Figure 1 For the principle of the container root file system based on overlay2 in the prior art, docker establishes three file system layers on the overlay2 file system, the original file layer, the difference file layer, and the user view layer generated after combining the original file layer and the difference file layer. When the user process is about to modify file 1, the overlay2 file system will copy file 1 in the difference file layer, generate file 1', and map it to the user view layer. The user process actually modifies file 1'.
[0008] The container monitoring tool lists all the files in the difference file layer and counts the size, and the temporary storage occupation of the root file system is completed, that is, the overlay2-based container root file system temporary file storage usage is counted.
[0009] Figure 2 For the principle of the btrfs-based container root file system in the prior art, the Btrfs file system takes file blocks as the control granularity and supports snapshot form to establish file mapping for hierarchical control. When the user writes part of the file, a new file block is directly generated to replace the original block mapping relationship, without the need to copy the entire file like overlay2.
[0010] For example, when the user modifies file block 2 in file 1, btrfs will generate a new block at the user layer.
[0011] However, the current container monitoring tool does not support the btrfs file system, and there is no difference file layer, so the temporary storage usage cannot be directly queried.
[0012] In summary, the current analysis scheme of the temporary storage usage of the container root file system of the btrfs file system is not supported. SUMMARY
[0013] The embodiment of the application provides a container temporary storage usage analysis method in a btrfs file system, which is used to discover the container storage usage in advance for operation and maintenance monitoring and management, and avoid container service abnormity caused by excessive storage occupation. The method comprises the following steps:
[0014] The container monitoring tool executes a system call to obtain the environment variable of the container process of the btrfs file system;
[0015] The directory list scanned by default is obtained from the environment variable of the container monitoring tool;
[0016] According to the environment variable of the container process and the directory list, a directory list to be scanned by the target container is obtained;
[0017] The original layer path and the user layer path of the target container are calculated and obtained;
[0018] According to the original layer path and the user layer path of the target container, the changed files in each directory in the directory list to be scanned by the target container are found, and the size of the changed files is recorded;
[0019] According to the size of the changed files, the temporary storage usage of the container in the btrfs file system is determined.
[0020] This invention also provides a device for analyzing the temporary storage usage of containers in a btrfs file system, used to detect container storage usage in advance for operation and maintenance monitoring and management, and to avoid excessive storage usage leading to container service abnormalities. The device includes:
[0021] The environment variable acquisition module is used to obtain the environment variables of the container process of the btrfs file system by executing system calls through container monitoring tools;
[0022] The default scan directory list acquisition module is used to obtain the default scan directory list from the environment variables of the container monitoring tool.
[0023] The target container directory list acquisition module is used to obtain the directory list to be scanned by the target container based on the environment variables of the container process and the directory list.
[0024] The path calculation module is used to calculate and obtain the original layer path and user layer path of the target container;
[0025] The changed file traversal module is used to traverse the list of directories to be scanned in the target container based on the original layer path and the user layer path of the target container, find the changed files in each directory, and record the size of the changed files.
[0026] The temporary storage usage determination module is used to determine the temporary storage usage of containers in the btrfs file system based on the size of the changing files.
[0027] This invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the above-described method for analyzing the temporary storage usage of containers in the btrfs file system.
[0028] This invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for analyzing container temporary storage usage in the btrfs file system.
[0029] This invention also provides a computer program product, which includes a computer program that, when executed by a processor, implements the above-described method for analyzing the temporary storage usage of containers in the btrfs file system.
[0030] In this embodiment of the invention, the environment variables of the container process in the Btrfs file system are obtained by executing system calls through a container monitoring tool; the default list of directories to be scanned is obtained from the environment variables of the container monitoring tool; based on the environment variables of the container process and the directory list, the list of directories to be scanned by the target container is obtained; the original layer path and user layer path of the target container are calculated; based on the original layer path and user layer path of the target container, the list of directories to be scanned by the target container is traversed to find changed files in each directory and the size of the changed files is recorded; based on the size of the changed files, the temporary storage usage of the container in the Btrfs file system is determined. Compared with the prior art, by comparing all files and folders under a specified directory in the two file system levels of Btrfs, and based on the operating principle of the Btrfs file system, different files can be identified by the differences in various attributes when files change, thus finding changed files. This achieves the calculation and monitoring of the temporary storage usage of the container in the Btrfs file system through the system calls executed by the container monitoring tool. Attached Figure Description
[0031] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings:
[0032] Figure 1 This describes the principle of the container root file system based on overlay2 in existing technologies;
[0033] Figure 2 This describes the principle of the container root file system based on btrfs in existing technologies;
[0034] Figure 3 This is a flowchart illustrating the method for analyzing the temporary storage usage of containers in the btrfs file system in this invention.
[0035] Figure 4 This is a flowchart of sub-process 1 in an embodiment of the present invention;
[0036] Figure 5 This is a flowchart of sub-process 2 in an embodiment of the present invention;
[0037] Figure 6 This is a schematic diagram of a device for analyzing the temporary storage usage of containers in the btrfs file system in an embodiment of the present invention;
[0038] Figure 7 This is a schematic diagram of a computer device in an embodiment of the present invention. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. Here, the illustrative embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.
[0040] The inventors discovered that Kubelet (a daemon process on the node host in a Kubernetes cluster) uses container monitoring tools to collect container runtime data when managing containers, such as the temporary storage usage of container processes in the container's root file system. This allows for early detection of container storage usage for operation and maintenance monitoring and management, preventing excessive storage usage that could lead to container service anomalies.
[0041] Container Advisor, a container monitoring tool, allows container users to understand the resource usage and performance characteristics of their running containers. It is a running daemon that collects, aggregates, processes, and exports information about running containers. Specifically, it saves resource isolation parameters, historical resource usage, a histogram of complete historical resource usage, and network statistics for each container. This data is exported from both the container and the host.
[0042] Therefore, this invention provides a scheme for calculating and monitoring the temporary storage usage of containers in a btrfs file system, thereby enabling early detection of container storage usage for operation and maintenance monitoring and management, and avoiding excessive storage usage that could lead to abnormal container services.
[0043] Figure 3 This is a flowchart of a method for analyzing container temporary storage usage in a btrfs file system according to an embodiment of the present invention, including:
[0044] Step 301: Obtain the environment variable USER_DEFINE_SCAN_DIRS of the container process of the btrfs file system by executing a system call through the container monitoring tool;
[0045] Step 302: Obtain the default list of scanned directories DEFAULT_SCAN_DIRS from the container monitoring tool's runtime environment variables;
[0046] Step 303: Based on the environment variables of the container process and the directory list, obtain the directory list TOTAL_SCAN_DIRS to be scanned by the target container;
[0047] Step 304: Calculate and obtain the original layer path and user layer path of the target container;
[0048] Step 305: Based on the original layer path and user layer path of the target container, traverse the directory list TOTAL_SCAN_DIRS to be scanned in the target container to find the changed files in each directory and record the size of the changed files.
[0049] Step 306: Determine the amount of temporary storage used by containers in the btrfs file system based on the size of the changed files.
[0050] In this embodiment of the invention, by comparing all files and folders under a specified directory in two file system levels of btrfs, and based on the operating principle of the btrfs file system, different files can be identified by the differences in various attributes when files change. This allows the changed files to be found, thus enabling the system to calculate and monitor the temporary storage usage of containers in the btrfs file system through container monitoring tools.
[0051] The above steps 301-306 constitute the main process, and step 305 includes a sub-process 1, which will be described in detail below.
[0052] In one embodiment, based on the original layer and user layer paths of the target container, the list of directories to be scanned in the target container is traversed to find changed files in each directory, including:
[0053] Iterate through the directories to be checked in the directory list to be scanned in the target container;
[0054] For each user level, iterate through the list of file items under the directory to be confirmed in that user level.
[0055] If the file item to be confirmed in the user layer exists in the original layer, determine the path of the file item to be confirmed in the original layer based on the user layer path, and obtain the corresponding file item in the original layer;
[0056] If the file item to be confirmed in the user layer has the same file type as the corresponding file item in the original layer, determine whether both the file item to be confirmed in the user layer and the corresponding file item in the original layer are files;
[0057] If both the file item to be confirmed in the user layer and the corresponding file item in the original layer are files, determine whether the file item to be confirmed in the user layer is a changed file based on the file item's attributes.
[0058] In one embodiment, traversing the directories to be verified in the directory list to be scanned by the target container includes:
[0059] Determine if the target container's directory list to be scanned contains any directories to be confirmed;
[0060] If so, obtain each directory to be confirmed;
[0061] If not, exit the traversal of the directory list to be scanned in the target container.
[0062] In one embodiment, traversing the list of file items to be confirmed under the directory to be confirmed in the user layer includes:
[0063] Determine if the list of files to be confirmed in the directory to be confirmed in the user layer contains any files to be confirmed.
[0064] If so, obtain each file item to be confirmed;
[0065] If not, continue iterating through the directories to be checked in the target container's directory list to be scanned.
[0066] In one embodiment, determining whether a file item to be confirmed in the user layer is a changed file based on the attributes of the file item includes:
[0067] Determine whether the attributes of the file item to be confirmed in the user layer are consistent with those of the corresponding file item in the original layer. The attributes include one or any combination of inode, permissions, user, user group, home device number, file modification time, file size, and capabilities.
[0068] If not, determine that the file item to be confirmed in the user layer is a changed file, record the path and size of the file item, and record the index node number in the index node storage graph;
[0069] If so, ignore the file item to be confirmed and continue iterating through the list of file items to be confirmed in the directory to be confirmed in this user level.
[0070] In one embodiment, the method further includes:
[0071] If the file item to be confirmed in the user layer has a non-file counterpart in the original layer, determine whether both the file item to be confirmed in the user layer and the corresponding file item in the original layer are folders.
[0072] If so, take the file items to be confirmed in the user layer as the directory to be confirmed, and recursively traverse the list of file items to be confirmed under the directory to be confirmed.
[0073] If not, ignore the file item to be confirmed and continue iterating through the list of file items to be confirmed in the directory to be confirmed in this user level.
[0074] In one embodiment, the method further includes:
[0075] If the file item to be confirmed in the user layer does not exist in the original layer, or the file type of the file item to be confirmed in the user layer is different from the file type of the corresponding file item in the original layer, search for the file item to be confirmed and all the unique files below it, and continue to traverse the list of file items to be confirmed in the directory to be confirmed in the user layer.
[0076] Combining all the steps of sub-process 1 above, a complete process is given below, see... Figure 4 ,include:
[0077] Step 401: Determine if there is a directory to be confirmed in the TOTAL_SCAN_DIRS directory list to be scanned by the target container; if yes, proceed to step 402; otherwise, exit subprocess 1.
[0078] Step 402: Obtain each directory DIR_X to be confirmed; Locate all files and folders under DIR_X in the user layer;
[0079] Step 403: Determine whether there are any files to be confirmed in the file item list ENTRY_LIST_X under the directory DIR_X to be confirmed in the user layer; if yes, proceed to step 404; if no, proceed to step 401.
[0080] Step 404: Obtain each file item ENTRY_X to be confirmed; determine whether the file item ENTRY_X to be confirmed in the user layer exists in the original layer; if yes, proceed to step 405; otherwise, proceed to step 413.
[0081] Step 405: Based on the user layer path, determine the path of the file item to be confirmed in the original layer, and obtain the corresponding file item ENTRY_Y in the original layer;
[0082] Step 406: Determine whether the file type of the file item ENTRY_X to be confirmed in the user layer is the same as that of the corresponding file item ENTRY_Y in the original layer; if yes, proceed to step 407; if no, proceed to step 413.
[0083] Step 407: Determine whether the file item to be confirmed in the user layer and the corresponding file item in the original layer are both files; if yes, proceed to step 408; otherwise, proceed to step 410.
[0084] Step 408: Determine whether the attributes of the file item to be confirmed in the user layer are consistent with those of the corresponding file item in the original layer. The attributes include one or any combination of inode, permissions, user, user group, home device number, file modification time, file size, and capabilities. If not, proceed to step 409; otherwise, proceed to step 411.
[0085] Step 409: Determine that the file item ENTRY_X to be confirmed in the user layer is a changed file, record the path and size of the file item ENTRY_X, record the index node number in the index node storage graph, and proceed to step 403.
[0086] Step 410: Determine whether the file item ENTRY_X to be confirmed in the user layer and the corresponding file item ENTRY_Y in the original layer are both folders; if yes, proceed to step 412; if no, proceed to step 411.
[0087] Step 411: Ignore the file item to be confirmed and proceed to step 403;
[0088] Step 412: Take the file item to be confirmed in the user layer as the directory to be confirmed, that is, assume ENTRY_X is DIR_X', and proceed to step 403;
[0089] Step 413: Locate the file item to be confirmed and all its unique files, then proceed to step 403.
[0090] In step 413, searching for the file item to be confirmed and all its unique files initiates another sub-process 2. In one embodiment, searching for the file item to be confirmed and all its unique files includes:
[0091] If the file item to be confirmed is a file, determine whether the inode number of the file item to be confirmed has already appeared in the inode storage graph;
[0092] If so, ignore the file item to be checked and exit the search for the file item to be checked and all the unique files below it;
[0093] If not, determine that the file item to be confirmed is a changed file, record the path and size of the file item, record the inode number in the inode storage graph, and exit the search for the file item to be confirmed and all the unique files below it.
[0094] In one embodiment, the method further includes:
[0095] If the file item to be confirmed is not a file, determine whether the file item to be confirmed is a directory;
[0096] If so, treat the file item to be confirmed as the directory to be confirmed, and recursively traverse the list of file items to be confirmed under the directory to be confirmed.
[0097] If not, ignore the file item to be checked and exit the search for the file item to be checked and all subsequent unique files.
[0098] Combining all the steps of sub-process 2 above, a complete process is given below, seeFigure 5 ,include:
[0099] Step 501: Determine whether the file item to be confirmed is a file. If yes, proceed to step 502; otherwise, proceed to step 504.
[0100] Step 502: Determine whether the inode number of the file item to be confirmed has already appeared in the inode storage graph; if not, proceed to step 503; if yes, proceed to step 505.
[0101] Step 503: Determine that the file item to be confirmed is a changed file, record the path and size of the file item, record the index node number in the index node storage graph, and exit subprocess 2;
[0102] Step 504: Determine whether the file item to be confirmed is a directory. If yes, proceed to step 506; otherwise, proceed to step 505.
[0103] Step 505: Ignore the file item to be confirmed and exit subprocess 2;
[0104] Step 506: The file item to be confirmed, ENTRY_X, is set as the directory to be confirmed, DIR_Y, and subprocess 2 is recursively called.
[0105] In summary, the method proposed in this embodiment of the invention obtains the environment variables of the container process of the btrfs file system through a system call executed by a container monitoring tool; obtains the default scan directory list from the container monitoring tool's runtime environment variables; obtains the directory list to be scanned by the target container based on the container process's environment variables and the directory list; calculates and obtains the original layer path and user layer path of the target container; traverses the directory list to be scanned by the target container based on the original layer path and user layer path of the target container to find changed files in each directory and records the size of the changed files; and determines the temporary storage usage of the container in the btrfs file system based on the size of the changed files. Compared with the prior art, by comparing all files and folders under a specified directory in the two file system levels of btrfs, and based on the operating principle of the btrfs file system, different files can be identified by the differences in various attributes when files change, thus finding the changed files. This achieves the calculation and monitoring of the temporary storage usage of the container in the btrfs file system through a system call executed by a container monitoring tool.
[0106] This invention also provides a device for analyzing the temporary storage usage of containers in a btrfs file system, as described in the following embodiments. Since the principle by which this device solves the problem is similar to the method for analyzing the temporary storage usage of containers in a btrfs file system, the implementation of this device can refer to the implementation of the method for analyzing the temporary storage usage of containers in a btrfs file system; repeated details will not be elaborated further.
[0107] Figure 6 This is a schematic diagram of a device for analyzing the temporary storage usage of containers in a btrfs file system according to an embodiment of the present invention, including:
[0108] The environment variable acquisition module 601 is used to obtain the environment variables of the container process of the btrfs file system by executing system calls through the container monitoring tool;
[0109] The default scan directory list acquisition module 602 is used to obtain the default scan directory list from the container monitoring tool's runtime environment variables;
[0110] The target container directory list acquisition module 603 is used to obtain the directory list to be scanned by the target container based on the environment variables of the container process and the directory list.
[0111] The path calculation module 604 is used to calculate and obtain the original layer path and user layer path of the target container;
[0112] The changed file traversal module 605 is used to traverse the directory list to be scanned in the target container based on the original layer path and the user layer path of the target container, find the changed files in each directory, and record the size of the changed files.
[0113] The temporary storage usage determination module 606 is used to determine the temporary storage usage of containers in the btrfs file system based on the size of the changing files.
[0114] In one embodiment, the changed file traversal module 605 is specifically used for:
[0115] Iterate through the directories to be checked in the directory list to be scanned in the target container;
[0116] For each user level, iterate through the list of file items under the directory to be confirmed in that user level.
[0117] If the file item to be confirmed in the user layer exists in the original layer, determine the path of the file item to be confirmed in the original layer based on the user layer path, and obtain the corresponding file item in the original layer;
[0118] If the file item to be confirmed in the user layer has the same file type as the corresponding file item in the original layer, determine whether both the file item to be confirmed in the user layer and the corresponding file item in the original layer are files;
[0119] If both the file item to be confirmed in the user layer and the corresponding file item in the original layer are files, determine whether the file item to be confirmed in the user layer is a changed file based on the file item's attributes.
[0120] In one embodiment, the changed file traversal module 605 is specifically used for:
[0121] Determine if the target container's directory list to be scanned contains any directories to be confirmed;
[0122] If so, obtain each directory to be confirmed;
[0123] If not, exit the traversal of the directory list to be scanned in the target container.
[0124] In one embodiment, the changed file traversal module 605 is specifically used for:
[0125] Determine if the list of files to be confirmed in the directory to be confirmed in the user layer contains any files to be confirmed.
[0126] If so, obtain each file item to be confirmed;
[0127] If not, continue iterating through the directories to be checked in the target container's directory list to be scanned.
[0128] In one embodiment, the changed file traversal module 605 is specifically used for:
[0129] Determine whether the attributes of the file item to be confirmed in the user layer are consistent with those of the corresponding file item in the original layer. The attributes include one or any combination of inode, permissions, user, user group, home device number, file modification time, file size, and capabilities.
[0130] If not, determine that the file item to be confirmed in the user layer is a changed file, record the path and size of the file item, record the index node number in the index node storage graph, and continue to traverse the list of file items to be confirmed in the directory to be confirmed in the user layer.
[0131] If so, ignore the file item to be confirmed and continue iterating through the list of file items to be confirmed in the directory to be confirmed in this user level.
[0132] In one embodiment, the changed file traversal module 605 is specifically used for:
[0133] If the file item to be confirmed in the user layer has a non-file counterpart in the original layer, determine whether both the file item to be confirmed in the user layer and the corresponding file item in the original layer are folders.
[0134] If so, take the file items to be confirmed in the user layer as the directory to be confirmed, and recursively traverse the list of file items to be confirmed under the directory to be confirmed.
[0135] If not, ignore the file item to be confirmed and continue iterating through the list of file items to be confirmed in the directory to be confirmed in this user level.
[0136] In one embodiment, the changed file traversal module 605 is specifically used for:
[0137] If the file item to be confirmed in the user layer does not exist in the original layer, or the file type of the file item to be confirmed in the user layer is different from the file type of the corresponding file item in the original layer, search for the file item to be confirmed and all the unique files below it, and continue to traverse the list of file items to be confirmed in the directory to be confirmed in the user layer.
[0138] In one embodiment, the changed file traversal module 605 is specifically used for:
[0139] If the file item to be confirmed is a file, determine whether the inode number of the file item to be confirmed has already appeared in the inode storage graph;
[0140] If so, ignore the file item to be checked and exit the search for the file item to be checked and all the unique files below it;
[0141] If not, determine that the file item to be confirmed is a changed file, record the path and size of the file item, record the inode number in the inode storage graph, and exit the search for the file item to be confirmed and all the unique files below it.
[0142] In one embodiment, the changed file traversal module 605 is specifically used for:
[0143] If the file item to be confirmed is not a file, determine whether the file item to be confirmed is a directory;
[0144] If so, treat the file item to be confirmed as the directory to be confirmed, and recursively traverse the list of file items to be confirmed under the directory to be confirmed.
[0145] If not, ignore the file item to be checked and exit the search for the file item to be checked and all subsequent unique files.
[0146] In summary, the apparatus proposed in this embodiment of the invention obtains the environment variables of the container process of the btrfs file system through a system call executed by a container monitoring tool; obtains the default scan directory list from the container monitoring tool's runtime environment variables; obtains the directory list to be scanned by the target container based on the container process's environment variables and the directory list; calculates and obtains the original layer path and user layer path of the target container; traverses the directory list to be scanned by the target container based on the original layer path and user layer path of the target container to find changed files in each directory and records the size of the changed files; and determines the temporary storage usage of the container in the btrfs file system based on the size of the changed files. Compared with the prior art, by comparing all files and folders under a specified directory in the two file system levels of btrfs, and based on the operating principle of the btrfs file system, different files can be identified by the differences in various attributes when files change, thus finding the changed files. This achieves the calculation and monitoring of the temporary storage usage of the container in the btrfs file system through a system call executed by a container monitoring tool.
[0147] This invention also provides a computer device. Figure 7 This is a schematic diagram of a computer device in an embodiment of the present invention. The computer device 700 includes a memory 710, a processor 720, and a computer program 730 stored on the memory 710 and executable on the processor 720. When the processor 720 executes the computer program 730, it implements the above-mentioned method for analyzing the temporary storage usage of containers in the btrfs file system.
[0148] This invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for analyzing container temporary storage usage in the btrfs file system.
[0149] This invention also provides a computer program product, which includes a computer program that, when executed by a processor, implements the above-described method for analyzing the temporary storage usage of containers in the btrfs file system.
[0150] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0151] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0152] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0153] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0154] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for analyzing the temporary storage usage of containers in a btrfs file system, characterized in that, include: The environment variables of the container process in the btrfs file system are obtained by executing system calls through container monitoring tools; Obtain the list of directories to be scanned by default from the environment variables of the container monitoring tool; Based on the container process's environment variables and the directory list, the list of directories to be scanned by the target container is obtained; Calculate and obtain the original layer path and user layer path of the target container; Based on the original layer path and user layer path of the target container, traverse the list of directories to be scanned in the target container to find the changed files in each directory and record the size of the changed files. Determine the amount of temporary storage used by containers in the btrfs file system based on the size of the changing files. The step of traversing the directory list to be scanned in the target container and searching for changed files in each directory based on the original layer path and the user layer path of the target container includes: Iterate through the directories to be checked in the directory list to be scanned in the target container; For each user level, iterate through the list of file items under the directory to be confirmed in that user level. If the file item to be confirmed in the user layer exists in the original layer, determine the path of the file item to be confirmed in the original layer based on the user layer path, and obtain the corresponding file item in the original layer; If the file item to be confirmed in the user layer has the same file type as the corresponding file item in the original layer, determine whether both the file item to be confirmed in the user layer and the corresponding file item in the original layer are files; If both the file item to be confirmed in the user layer and the corresponding file item in the original layer are files, determine whether the file item to be confirmed in the user layer is a changed file based on the file item's attributes. The step of determining whether a file item to be confirmed in the user layer is a changed file based on the attributes of the file item includes: Determine whether the attributes of the file item to be confirmed in the user layer are consistent with those of the corresponding file item in the original layer. The attributes include one or any combination of inode, permissions, user, user group, home device number, file modification time, file size, and capabilities. If not, determine that the file item to be confirmed in the user layer is a changed file, record the path and size of the file item, record the index node number in the index node storage graph, and continue to traverse the list of file items to be confirmed in the directory to be confirmed in the user layer. If so, ignore the file item to be confirmed and continue iterating through the list of file items to be confirmed in the directory to be confirmed in this user level.
2. The method as described in claim 1, characterized in that, Iterate through the directories to be checked in the target container's directory list to be scanned, including: Determine if the target container's directory list to be scanned contains any directories to be confirmed; If so, obtain each directory to be confirmed; If not, exit the traversal of the directory list to be scanned in the target container.
3. The method as described in claim 1, characterized in that, Iterate through the list of file entries to be confirmed in the directories under this user level. The file entries to be confirmed include: Determine if the list of files to be confirmed in the directory to be confirmed in the user layer contains any files to be confirmed. If so, obtain each file item to be confirmed; If not, continue iterating through the directories to be checked in the target container's directory list to be scanned.
4. The method as described in claim 1, characterized in that, Also includes: If the file item to be confirmed in the user layer has a non-file counterpart in the original layer, determine whether both the file item to be confirmed in the user layer and the corresponding file item in the original layer are folders. If so, take the file items to be confirmed in the user layer as the directory to be confirmed, and recursively traverse the list of file items to be confirmed under the directory to be confirmed. If not, ignore the file item to be confirmed and continue iterating through the list of file items to be confirmed in the directory to be confirmed in this user level.
5. The method as described in claim 1, characterized in that, Also includes: If the file item to be confirmed in the user layer does not exist in the original layer, or the file type of the file item to be confirmed in the user layer is different from the file type of the corresponding file item in the original layer, search for the file item to be confirmed and all the unique files below it, and continue to traverse the list of file items to be confirmed in the directory to be confirmed in the user layer.
6. The method as described in claim 5, characterized in that, Find the file item to be verified and all unique files below it, including: If the file item to be confirmed is a file, determine whether the inode number of the file item to be confirmed has already appeared in the inode storage graph; If so, ignore the file item to be checked and exit the search for the file item to be checked and all the unique files below it; If not, determine that the file item to be confirmed is a changed file, record the path and size of the file item, record the inode number in the inode storage graph, and exit the search for the file item to be confirmed and all the unique files below it.
7. The method as described in claim 6, characterized in that, Also includes: If the file item to be confirmed is not a file, determine whether the file item to be confirmed is a directory; If so, treat the file item to be confirmed as the directory to be confirmed, and recursively traverse the list of file items to be confirmed under the directory to be confirmed. If not, ignore the file item to be checked and exit the search for the file item to be checked and all subsequent unique files.
8. A device for analyzing the temporary storage usage of containers in a btrfs file system, characterized in that, include: The environment variable acquisition module is used to obtain the environment variables of the container process of the btrfs file system by executing system calls through container monitoring tools; The default scan directory list acquisition module is used to obtain the default scan directory list from the environment variables of the container monitoring tool. The target container directory list acquisition module is used to obtain the directory list to be scanned by the target container based on the environment variables of the container process and the directory list. The path calculation module is used to calculate and obtain the original layer path and user layer path of the target container; The changed file traversal module is used to traverse the list of directories to be scanned in the target container based on the original layer path and the user layer path of the target container, find the changed files in each directory, and record the size of the changed files. The temporary storage usage determination module is used to determine the temporary storage usage of containers in the btrfs file system based on the size of the changing files. Specifically, the changed file traversal module is used to traverse the directories to be confirmed in the directory list to be scanned by the target container; For each user level, iterate through the list of file items under the directory to be confirmed in that user level. If the file item to be confirmed in the user layer exists in the original layer, determine the path of the file item to be confirmed in the original layer based on the user layer path, and obtain the corresponding file item in the original layer; If the file item to be confirmed in the user layer has the same file type as the corresponding file item in the original layer, determine whether both the file item to be confirmed in the user layer and the corresponding file item in the original layer are files; If both the file item to be confirmed in the user layer and the corresponding file item in the original layer are files, determine whether the file item to be confirmed in the user layer is a changed file based on the file item's attributes. The changed file traversal module is further used to determine whether the attributes of the file item to be confirmed in the user layer are consistent with the attributes of the corresponding file item in the original layer. The attributes include one or any combination of inode, permissions, user, user group, home device number, file modification time, file size, and capabilities. If not, determine that the file item to be confirmed in the user layer is a changed file, record the path and size of the file item, record the index node number in the index node storage graph, and continue to traverse the list of file items to be confirmed in the directory to be confirmed in the user layer. If so, ignore the file item to be confirmed and continue iterating through the list of file items to be confirmed in the directory to be confirmed in this user level.
9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method of any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method of any one of claims 1 to 7.
11. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 7.
Citation Information
Patent Citations
Server performance index evaluation method for container bearing service application
CN106557353A
Storage amount statistics method, apparatus, electronic device and readable storage medium
CN109508318A