A formatting method and related equipment

By obtaining and processing format parameters after the container start request and determining the format attributes of the target file system, the difficulty of block device formatting processing in kubernetes and kata cluster systems is solved, and block device formatting is realized when the container starts up.

CN112114900BActive Publication Date: 2024-11-15BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010986398.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-18
Publication Date
2024-11-15
Estimated Expiration
2040-09-18

AI Technical Summary

Technical Problem

In a cluster system based on kubernetes and kata, users cannot directly format the mounted block devices within the container, resulting in difficulty in formatting.

Method used

Provide a formatting method, by receiving the container startup request to obtain the formatting parameters of the block device, determine the format attributes of the target file system, and format the block device when the preset conditions are met, and mount it to the startup. in the target container.

Benefits of technology

The formatting process of mounting block devices during the startup process of the container is realized, which solves the problem of formatting processing difficulties caused by user permission restrictions, and ensures the correct formatting of block devices in the target container.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112114900B_ABST
    Figure CN112114900B_ABST
Patent Text Reader

Abstract

The present application discloses a formatting method and related equipment, the method comprising: after receiving a container startup request, first obtaining formatting parameters of a block device to be mounted, and determining a target file system format attribute of the block device to be mounted according to the formatting parameters; when it is determined that the target file system format attribute meets a first preset condition, formatting the block device to be mounted, and mounting the formatted block device to be mounted to a target container in a startup state, so that the formatting of the block device to be mounted can be completed during the startup process of the target container.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a formatting method and related equipment. Background Art

[0002] In a cluster system based on Kubernetes (abbreviated as k8s) and Kata, for a virtual machine that serves as a computing node, a block device (such as a cloud hard disk) is not directly mounted to a container on the virtual machine in the form of a directory, but is directly mounted to a container deployed on the virtual machine in the form of a device.

[0003] However, due to user permission restrictions, users cannot directly format block devices inside the container, making how to format block devices mounted inside the container a technical problem that needs to be solved urgently. Summary of the invention

[0004] In order to solve the above technical problems existing in the prior art, the present application provides a formatting method and related equipment, which can format the block device mounted inside the container.

[0005] In order to achieve the above purpose, the technical solutions provided by the embodiments of the present application are as follows:

[0006] The present application embodiment provides a formatting method, including:

[0007] After receiving the container startup request, obtain the formatting parameters of the block device to be mounted;

[0008] Determining the target file system format attributes of the block device to be mounted according to the formatting parameters;

[0009] When it is determined that the format attribute of the target file system satisfies the first preset condition, the block device to be mounted is formatted, and the formatted block device to be mounted is mounted to the target container in the boot state.

[0010] Optionally, determining the target file system format attribute of the block device to be mounted according to the formatting parameter includes:

[0011] Obtaining the initial file system format attributes of the block device to be mounted;

[0012] Determine a target attribute prefix word according to the formatting parameter;

[0013] The target attribute prefix is ​​used as a prefix of the initial file system format attribute to obtain the target file system format attribute of the block device to be mounted.

[0014] Optionally, formatting the block device to be mounted includes:

[0015] Determining the target file system type according to the target file system format attribute;

[0016] Determine a target formatting tool according to the target file system type; wherein the target formatting tool is used to format the file system of the block device to be mounted into the target file system type;

[0017] The target formatting tool is used to format the block device to be mounted.

[0018] Optionally, the determining that the format attribute of the target file system satisfies a first preset condition includes:

[0019] Determining that the attribute prefix word in the target file system format attribute satisfies the first sub-condition;

[0020] or,

[0021] It is determined that the attribute prefix in the target file system format attribute satisfies the second sub-condition, and it is determined that the file system of the block device to be mounted satisfies the third sub-condition.

[0022] Optionally, obtaining formatting parameters of the block device to be mounted includes:

[0023] Obtaining a configuration file for the block device to be mounted;

[0024] The configuration file of the block device to be mounted is parsed to obtain formatting parameters of the block device to be mounted.

[0025] Optionally, the method further includes:

[0026] When it is determined that the target file system format attribute satisfies the second preset condition, the block device to be mounted is mounted to the target container in the boot state.

[0027] Optionally, the determining that the format attribute of the target file system satisfies a second preset condition includes:

[0028] Determining that the attribute prefix in the target file system format attribute satisfies the second sub-condition, and determining that the file system of the block device to be mounted satisfies the fourth sub-condition;

[0029] or,

[0030] It is determined that the attribute prefix word in the target file system format attribute satisfies a fifth sub-condition.

[0031] The embodiment of the present application also provides a formatting device, including:

[0032] An acquisition unit, configured to acquire formatting parameters of a block device to be mounted after receiving a container startup request;

[0033] A determination unit, configured to determine a target file system format attribute of the block device to be mounted according to the formatting parameter;

[0034] The formatting unit is used to format the block device to be mounted when it is determined that the format attribute of the target file system meets the first preset condition, and mount the formatted block device to be mounted into the target container in the boot state.

[0035] The present application also provides a device, the device comprising a processor and a memory:

[0036] The memory is used to store computer programs;

[0037] The processor is used to execute any implementation of the formatting method provided in the embodiments of the present application according to the computer program.

[0038] The embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and the computer program is used to execute any implementation of the formatting method provided in the embodiment of the present application.

[0039] Compared with the prior art, the embodiments of the present application have at least the following advantages:

[0040] In the formatting method provided in the embodiment of the present application, after receiving the container startup request, the formatting parameters of the block device to be mounted can be obtained first, and the target file system format attributes of the block device to be mounted can be determined according to the formatting parameters; when it is determined that the target file system format attributes meet the first preset condition, the block device to be mounted is formatted, and the formatted block device to be mounted is mounted to the target container in the startup state, so that the formatting processing of the block device to be mounted can be completed during the startup process of the target container. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0042] Figure 1 A flowchart of a formatting method provided in an embodiment of the present application;

[0043] Figure 2 A schematic diagram of an application scenario of a formatting method provided in an embodiment of the present application;

[0044] Figure 3 A method for applying to an embodiment of the present application is provided Figure 2 A flowchart of a formatting method for the application scenario shown;

[0045] Figure 4 A schematic diagram of the structure of a formatting device provided in an embodiment of the present application;

[0046] Figure 5 A schematic diagram of the device structure provided in an embodiment of the present application. DETAILED DESCRIPTION

[0047] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0048] Method Embodiment

[0049] See also Figure 1 , which is a flowchart of a formatting method provided in an embodiment of the present application.

[0050] The formatting method provided in the embodiment of the present application includes S101-S103:

[0051] S101: After receiving a container startup request, obtain formatting parameters of a block device to be mounted.

[0052] The container start request is used to request to start a target container in the virtual machine, and the target container refers to a container deployed in the virtual machine for the block device to be mounted.

[0053] The block device to be mounted refers to a block device that needs to be mounted inside a container in a virtual machine, and the embodiment of the present application does not limit the block device to be mounted. For example, the block device to be mounted can be a cloud hard disk (abbreviated as EBS disk).

[0054] The formatting parameter is used to characterize the relevant information of the formatting process of the block device to be mounted, and the embodiment of the present application does not limit the formatting parameter. For example, the formatting parameter may be Always, ifNotFormat or Never.

[0055] Always is used to mark forced formatting. Forced formatting means that during the boot process of the container, each block device mounted in the container must be formatted. At this time, a disk that has been formatted can be formatted again. In addition, the application scenario of forced formatting is: when you want to replace the file system or clean up the data of the block device mounted in the container, you can choose forced formatting. It should be noted that for data security reasons, forced formatting should be avoided as the default configuration value of the formatting parameters of each block device.

[0056] ifNotFormat is used to identify only unformatted block devices to be formatted. Among them, only formatting unformatted block devices means that during the boot process of the container, the block device that is mounted to the container for the first time will be automatically formatted. It can be seen that if a block device is mounted to the container for the first time, it is determined that the block device is an unformatted block device, so the block device needs to be formatted; if a block device is not mounted to the container for the Nth time (N≥2), it is determined that the block device is a formatted block device, so there is no need to format the block device again.

[0057] Never is used to indicate that formatting is prohibited. Among them, prohibiting formatting means that during the boot process of the container, no matter what happens, all block devices mounted to the container will not be formatted. It can be seen that this can protect user data from being destroyed by accidental formatting and causing unnecessary losses. Therefore, for data security considerations, prohibiting formatting can be used as the default configuration value of the formatting parameters of each block device.

[0058] In addition, the embodiment of the present application also provides an implementation method for obtaining the formatting parameters of the block device to be mounted (that is, S101), which is specifically: obtaining the configuration file of the block device to be mounted, and parsing the configuration file of the block device to be mounted to obtain the formatting parameters of the block device to be mounted. Among them, the configuration file is used to record the relevant configuration parameters of the block device to be mounted, and the configuration file of the block device to be mounted includes the formatting parameters of the block device to be mounted. It should be noted that the embodiment of the present application does not limit the configuration file. For example, the configuration file can be a json file.

[0059] Based on the relevant content of S101 above, it can be known that after receiving the container startup request for requesting to start the target container, it can be determined that the target container is in the startup state. At this time, the configuration file of the block device to be mounted can be obtained first, and then the configuration file can be formatted and parsed to obtain the formatting parameters of the block device to be mounted, so that the block device to be mounted can be formatted based on the formatting parameters.

[0060] S102: Determine the target file system format attribute of the block device to be mounted according to the formatting parameters of the block device to be mounted.

[0061] The target file system format attribute is used to characterize the file system that the block device to be mounted should have when it is mounted to the target container (for example, xfs file system, ext4 file system, and other file systems, etc.), and the type of formatting processing that the block device to be mounted should undergo before mounting the block device to the target container (for example, forced formatting, formatting only unformatted block devices, or prohibiting formatting, etc.).

[0062] In addition, the embodiment of the present application also provides an implementation method for determining the format attributes of the target file system (that is, S102), which specifically includes S1021-S1023:

[0063] S1021: Obtain the initial file system format attributes of the block device to be mounted.

[0064] The initial file system format attribute is used to characterize the file system (for example, an xfs file system, an ext4 file system, or other file systems) that the block device to be mounted should have when the block device to be mounted is mounted to the target container.

[0065] In addition, the embodiment of the present application also provides an implementation method for obtaining the initial file system format attributes (i.e., S1021), which is specifically: parsing the configuration file of the block device to be mounted to obtain the initial file system format attributes of the block device to be mounted. It can be seen that the configuration file of the block device to be mounted can include not only the formatting parameters of the block device to be mounted, but also the initial file system format attributes of the block device to be mounted.

[0066] S1022: Determine a target attribute prefix word according to formatting parameters of the block device to be mounted.

[0067] The target attribute prefix is ​​used to characterize the type information of the formatting process that the block device to be mounted should undergo before mounting the block device to the target container (for example, forced formatting, formatting only unformatted block devices, or prohibiting formatting, etc.), and the target attribute prefix can be added to the initial file system format attributes as a prefix of the initial file system format attributes.

[0068] In addition, the embodiment of the present application also provides an implementation method for determining a target attribute prefix (i.e., S1022), which is specifically: determining the target attribute prefix according to the first mapping relationship and the formatting parameters of the block device to be mounted. The first mapping relationship includes a correspondence between the formatting parameters of the block device to be mounted and the target attribute prefix.

[0069] The first mapping relationship is used to record the relationship between each formatting parameter and each attribute prefix word, and the embodiment of the present application does not limit the first mapping relationship. For example, the first mapping relationship may be the mapping relationship shown in Table 1.

[0070] Formatting parameters Attribute prefix Always format- ifNotFormat tryformat- Never (without attribute prefix)

[0071] Table 1 Correspondence between different formatting parameters and different attribute prefixes

[0072] Based on the relevant content of S1022 above, it can be known that after the formatting parameters of the block device to be mounted are obtained, the target attribute prefix of the block device to be mounted can be determined according to the formatting parameters of the block device to be mounted, which is specifically: when the first mapping relationship includes the corresponding relationship shown in Table 1, if the formatting parameter of the block device to be mounted is Always, then based on the first mapping relationship, it can be known that the target attribute prefix of the block device to be mounted is format-, so that format- can be added as a prefix to the initial file system format attributes of the block device to be mounted, and the target file system format attributes of the block device to be mounted are obtained; if the formatting parameter of the block device to be mounted is Always, then based on the first mapping relationship, it can be known that the target attribute prefix of the block device to be mounted is format-. If the number is ifNotFormat, then based on the first mapping relationship, it can be known that the target attribute prefix of the block device to be mounted is tryformat-, so that tryformat- can be subsequently added as a prefix to the initial file system format attributes of the block device to be mounted to obtain the target file system format attributes of the block device to be mounted; if the formatting parameter of the block device to be mounted is Never, then based on the first mapping relationship, it can be known that the target attribute prefix of the block device to be mounted is empty, so that the initial file system format attributes of the block device to be mounted can be directly used as the target file system format attributes of the block device to be mounted without adding any attribute prefix.

[0073] S1023: Using the target attribute prefix as a prefix of the initial file system format attribute of the block device to be mounted, to obtain the target file system format attribute of the block device to be mounted.

[0074] In an embodiment of the present application, after obtaining the initial file system format attributes and the target attribute prefix of the block device to be mounted, the target attribute prefix can be added as an attribute prefix to the initial file system format attributes of the block device to be mounted to obtain the target file system format attributes of the block device to be mounted, so that the target file system format attributes can include the target attribute prefix and the initial file system format attributes, so that the target file system format attributes can characterize the file system type that the block device to be mounted should have and the type of formatting processing that should be undergone when the block device to be mounted is mounted to the target container.

[0075] Based on the relevant content of S102 above, it can be known that in an embodiment of the present application, after the formatting parameters of the block device to be mounted are obtained, the target file system format attributes of the block device to be mounted can be determined according to the formatting parameters, which is specifically: first, the attribute prefix corresponding to the formatting parameter is queried from the first mapping relationship as the target attribute prefix; then the target attribute prefix is ​​added as a prefix of the initial file system format attributes of the block device to be mounted to obtain the target file system format attributes of the block device to be mounted, so that the target file system format attributes can include the target attribute prefix and the initial file system format attributes, so that the target file system format attributes can characterize the file system type that the block device to be mounted should have and the type of formatting processing that should be experienced when the block device to be mounted is mounted to the target container.

[0076] S103: When it is determined that the target file system format attribute of the block device to be mounted meets the first preset condition, the block device to be mounted is formatted, and the formatted block device to be mounted is mounted to the target container in the boot state.

[0077] The first preset condition is used to represent the condition satisfied by the target file system format attribute of the block device that needs to be formatted.

[0078] In some cases, determining that the target file system format attribute satisfies the first preset condition may specifically include the following two cases.

[0079] Case 1: when it is determined that the attribute prefix in the target file system format attribute satisfies the first sub-condition, it is determined that the target file system format attribute satisfies the first preset condition.

[0080] The first sub-condition may be preset, for example, the first sub-condition may be that the attribute prefix is ​​format-.

[0081] Based on the relevant content of the above situation 1, it can be known that after obtaining the target file system format attributes of the block device to be mounted, if the attribute prefix in the target file system format attributes satisfies the first sub-condition (for example, the attribute prefix in the target file system format attributes is format-), it can be determined that the block device to be mounted should be forcibly formatted, and thus it can be determined that the block device to be mounted must be formatted before being mounted to the target container.

[0082] Case 2: when it is determined that the attribute prefix in the target file system format attribute satisfies the second sub-condition and it is determined that the file system of the block device to be mounted satisfies the third sub-condition, it is determined that the target file system format attribute satisfies the first preset condition.

[0083] The second sub-condition may be preset, for example, the second sub-condition may be that the attribute prefix is ​​tryformat-.

[0084] The third sub-condition may be preset. For example, the third sub-condition may be that the file system of the block device to be mounted cannot be detected.

[0085] Based on the relevant content of the above situation 2, it can be known that after obtaining the target file system format attributes of the block device to be mounted, if the attribute prefix in the target file system format attributes satisfies the second sub-condition, it can be determined that the block device to be mounted should correspond to the formatting process of "formatting only unformatted block devices", so the file system detection can continue to be performed on the block device to be mounted, and when it is determined that the file system of the block device to be mounted cannot be detected (that is, it is determined that the file system of the block device to be mounted satisfies the third sub-condition), it can be determined that the block device to be mounted is an unformatted block device, and thus it can be determined that the block device to be mounted must be formatted before being mounted to the target container.

[0086] It should be noted that the embodiments of the present application do not limit the execution process of the above-mentioned file system detection on the mounted block device. For example, it can be implemented using the blkid tool that can support file system format detection.

[0087] Based on the above two situations, it can be known that in the embodiment of the present application, when it is determined that the block device to be mounted should be forcibly formatted based on the attribute prefix of the target file system format attribute of the block device to be mounted, regardless of whether the block device to be mounted has been formatted before, the block device to be mounted must be formatted during the startup process of the target container. In addition, when it is determined that the block device to be mounted corresponds to the formatting process of "formatting only unformatted block devices" based on the attribute prefix of the target file system format attribute of the block device to be mounted, the block device to be mounted will only be formatted when it is determined that the block device to be mounted is an unformatted block device.

[0088] In addition, the embodiment of the present application also provides an implementation method for formatting the mounted block device, which may specifically include S1031-S1033:

[0089] S1031: Determine the target file system type according to the target file system format attribute of the block device to be mounted.

[0090] The target file system type is used to represent the type of the file system that the to-be-mounted block device should have when the to-be-mounted block device is mounted to the target container.

[0091] In addition, an embodiment of the present application also provides an implementation method for determining the target file system type (that is, S1031), which is specifically: deleting the prefix attribute word (such as format- or tryformat-) in the target file system format attribute of the block device to be mounted, and obtaining the target file system type of the block device to be mounted, so that the target file system type can represent the type of file system that the block device to be mounted should have when the block device to be mounted is mounted to the target container.

[0092] S1032: Determine a target formatting tool according to the target file system type.

[0093] The target formatting tool is used to format the file system of the block device to be mounted into the target file system type.

[0094] In addition, the embodiment of the present application also provides an implementation method of determining a target formatting tool (i.e., S1032), which is specifically: determining a target formatting tool according to a second mapping relationship and a target file system type, wherein the second mapping relationship includes a correspondence between a target file system type and a target formatting tool.

[0095] The second mapping relationship is used to record the correspondence between each file system type and each formatting tool. For example, the second mapping relationship may include the correspondence shown in Table 2.

[0096] File system type Formatting tools ext4 mkfs.ext4 tool xfs mkfs.xfs tool

[0097] Table 2 Correspondence between different file system types and different formatting tools

[0098] Based on the relevant contents of S1032 above, it can be known that after determining the target file system type of the block device to be mounted, the formatting tool corresponding to the target file system type can be directly queried from the second mapping relationship as the target formatting tool for formatting the block device to be mounted. For example, when the second mapping relationship includes the corresponding relationship shown in Table 2, if the target file system type of the block device to be mounted is ext4, the target formatting tool should be the mkfs.ext4 tool; if the target file system type of the block device to be mounted is xfs, the target formatting tool should be the mkfs.xfs tool.

[0099] S1033: Format the block device to be mounted using a target formatting tool.

[0100] Based on the relevant content of S103 above, it can be known that after determining that the target file system format attribute of the block device to be mounted meets the first preset condition, the attribute prefix in the target file system format attribute can be removed first to obtain the target file system type of the block device to be mounted, and then the formatting tool corresponding to the target file system type is used to format the block device to be mounted, so as to format the file system of the block device to be mounted into the target file system type, so that the formatted block device to be mounted has a file system of the target file system type.

[0101] In some cases, the block device to be mounted can be directly mounted to the target container, and the block device to be mounted will not be formatted during the startup of the target container. Based on this, the embodiment of the present application also provides a possible implementation of the formatting method. In this implementation, in addition to the above S101-S103, the formatting method also includes S104:

[0102] S104: When it is determined that the target file system format attribute of the block device to be mounted meets the second preset condition, the block device to be mounted is mounted to the target container in the boot state.

[0103] The second preset condition is used to represent a condition satisfied by a target file system format attribute of a block device that does not need to be formatted.

[0104] In some cases, determining that the target file system format attribute satisfies the second preset condition may specifically include the following two cases.

[0105] In case 1, when it is determined that the attribute prefix in the target file system format attribute satisfies the second sub-condition and it is determined that the file system of the block device to be mounted satisfies the fourth sub-condition, it is determined that the target file system format attribute satisfies the second preset condition.

[0106] It should be noted that for the relevant content of the second sub-condition, please refer to the above.

[0107] The third sub-condition may be preset. For example, the third sub-condition may be that the file system of the block device to be mounted can be detected.

[0108] Based on the relevant content of the above situation one, it can be known that after obtaining the target file system format attributes of the block device to be mounted, if the attribute prefix in the target file system format attributes satisfies the second sub-condition, it can be determined that the block device to be mounted should correspond to the formatting processing process of "formatting only unformatted block devices", so the file system detection can continue to be performed on the block device to be mounted, and when it is determined that the file system of the block device to be mounted can be detected (that is, it is determined that the file system of the block device to be mounted satisfies the fourth sub-condition), it can be determined that the block device to be mounted belongs to a formatted block device, so that it can be determined that the block device to be mounted does not need to be formatted before being mounted to the target container.

[0109] In case 2, when it is determined that the attribute prefix in the target file system format attribute satisfies the fifth sub-condition, it is determined that the target file system format attribute satisfies the second preset condition.

[0110] The fifth sub-condition may be preset. For example, the fifth sub-condition may be that the attribute prefix is ​​empty (that is, there is no attribute prefix).

[0111] Based on the relevant content of the above situation 2, it can be known that after obtaining the target file system format attributes of the block device to be mounted, if the attribute prefix in the target file system format attributes satisfies the fifth sub-condition (for example, there is no attribute prefix in the target file system format attributes), it can be determined that the block device to be mounted should be prohibited from formatting, so that it can be determined that the block device to be mounted does not need to be formatted before being mounted to the target container.

[0112] Based on the above two situations, it can be known that in the embodiment of the present application, when it is determined that the block device to be mounted corresponds to the formatting process of "formatting only unformatted block devices" based on the attribute prefix of the target file system format attribute of the block device to be mounted, if it is determined that the block device to be mounted belongs to a formatted block device, then there is no need to format the block device to be mounted. In addition, when it is determined that the block device to be mounted should be prohibited from formatting based on the attribute prefix of the target file system format attribute of the block device to be mounted, regardless of whether the block device to be mounted has been formatted, the block device to be mounted must not be formatted during the startup process of the target container.

[0113] Based on the relevant content of S104 above, it can be known that if the target file system format attribute of the block device to be mounted meets the second preset condition, it can be determined that the block device to be mounted does not need to be formatted during the startup process of the target container, so the block device to be mounted can be directly mounted to the target container in the startup state, so that the data security in the block device to be mounted can be protected.

[0114] Based on the relevant contents of the above formatting method, it can be known that after receiving the container startup request, the formatting parameters of the block device to be mounted can be obtained first, and the target file system format attributes of the block device to be mounted can be determined according to the formatting parameters; when it is determined that the target file system format attributes meet the first preset condition, the block device to be mounted is formatted, and the formatted block device to be mounted is mounted to the target container in the startup state, so that the formatting processing of the block device to be mounted can be completed during the startup process of the target container.

[0115] In order to facilitate understanding of the technical solution of the present application, it will be described below in conjunction with scenario embodiments.

[0116] Scenario Example

[0117] See also Figure 2 , which is a schematic diagram of an application scenario of a formatting method provided in an embodiment of the present application, and in Figure 2 In the application scenario shown, the block device ebs1 needs to be mounted inside container 2.

[0118] When the formatting method provided in the embodiment of the present application is applied to Figure 2 In the application scenario shown in Figure 3 As shown, the formatting method may include S301-S310:

[0119] S301: Receive a container start request triggered by a user, where the container start request is used to request to start container 2 in a virtual machine.

[0120] S302: Obtain a configuration file ebs1.json of the block device ebs1, wherein the configuration file ebs1.json of the block device ebs1 includes formatting parameters of the block device ebs1 and initial file system format attributes.

[0121] S303: Parse the configuration file ebs1.json of the block device ebs1 to obtain formatting parameters of the block device ebs1 and initial file system format attributes of the block device ebs1.

[0122] The present application embodiment does not limit the implementation method of S303. For example, if Figure 2 The kata-runtime shown in FIG. 1 is deployed with a parsing tool for parsing the configuration file (for example, the parsing tool can implement parsing processes such as formatting parameter parsing and file system format attribute parsing). Figure 2 The kata-runtime shown uses the analysis tool to implement S303.

[0123] S304: Determine the target file system format attributes of block device ebs1 according to the formatting parameters of block device ebs1 and the initial file system format attributes of block device ebs1, and use the target file system format attributes of block device ebs1 to update the file system attribute information of block device ebs1, so that the updated file system attribute information of device ebs1 includes the target file system format attributes of block device ebs1.

[0124] The present application embodiment does not limit the implementation of S303. For example, S304 may be implemented by Figure 2 The kata-runtime shown implements S304.

[0125] S305: Perform attribute prefix word detection on the file system attribute information of the block device ebs1 to obtain an attribute prefix word detection result.

[0126] The present application embodiment does not limit the implementation method of S303. For example, if Figure 2 The kata-agent shown in the figure has a prefix detection tool deployed to detect attribute prefix words for the file system attribute information of the block device. Figure 2 The kata-agent shown uses the prefix detection tool to execute S305.

[0127] In addition, in the embodiment of the present application, since different attribute prefixes correspond to different formatting processes, the formatting process of the block device ebs1 can be determined based on the attribute prefix detection result, which is specifically as follows: if the attribute prefix detection result indicates that the attribute prefix does not exist in the target file system format attribute of the block device ebs1, it is determined that the block device ebs1 corresponds to prohibited formatting, so there is no need to format the block device ebs1 and directly mount the block device ebs1 into the container 2 (that is, the relevant content of S306); if it is determined that the attribute prefix detection result indicates that the attribute prefix in the target file system format attribute of the block device ebs1 is format-, it is determined that the block device ebs1 corresponds to forced formatting, so the block device ebs1 must be formatted first, and then the formatted block device ebs1 must be mounted into container 2, which is the relevant content of S307); if the attribute prefix word detection result indicates that the attribute prefix word in the target file system format attribute of the block device ebs1 is tryformat-, it is determined that the block device ebs1 corresponds to a block device that is only formatted but not formatted, so it can be determined whether the block device ebs1 needs to be formatted based on the file system of the block device ebs1 itself (that is, the relevant content of S308-S310).

[0128] S306 : When it is determined that the attribute prefix word detection result indicates that the attribute prefix word does not exist in the target file system format attribute of the block device ebs1 , the block device ebs1 is mounted into the container 2 .

[0129] The present application embodiment does not limit the implementation of S306. For example, Figure 2 The kata-agent shown executes S306, which can be specifically: when it is determined that the attribute prefix word detection result indicates that the attribute prefix word does not exist in the target file system format attribute of the block device ebs1, it can be determined that the block device ebs1 is in a prohibited formatting state. Therefore, in order to ensure the data security of the block device ebs1, there is no need to format the block device ebs1, but directly mount the block device ebs1 to the container 2 according to the file system format specified by its file system attribute information for user access. It should be noted that if the above mounting process fails, it is necessary to emphasize in the error information reported upward that the block device ebs1 is prohibited from formatting.

[0130] S307 : When it is determined that the attribute prefix detection result indicates that the attribute prefix in the target file system format attribute of the block device ebs1 is format-, the block device ebs1 is formatted, and the formatted block device ebs1 is mounted into the container 2 .

[0131] The present application embodiment does not limit the implementation of S307. For example, Figure 2 The kata-agent shown executes S307, which can be specifically: when it is determined that the attribute prefix word detection result indicates that the attribute prefix word in the target file system format attribute of the block device ebs1 is format-, it can be determined that the block device ebs1 is in a forced formatting state. At this time, the prefix word format- in the target file system format attribute of the block device ebs1 is first removed to obtain the initial file system format attribute of the block device ebs1, and the file system attribute information of the device ebs1 is updated according to the initial file system format attribute of the block device ebs1, so that the updated file system attribute information of the device ebs1 includes the initial file system format attribute of the block device ebs1. Then, the file system of the block device ebs1 is determined according to the initial file system format attribute of the block device ebs1, and the formatting tool corresponding to the file system of the block device ebs1 is called to format the block device ebs1, so that the formatted block device ebs1 has the file system of the above-mentioned block device ebs1. Finally, the formatted block device ebs1 is mounted inside the container 2 according to the file system format specified by its file system attribute information for user access.

[0132] It should be noted that the formatting tools corresponding to each file system can be pre-deployed to Figure 2In the virtual machine base image of the virtual machine shown, kata-agent can call the formatting tool. In addition, the virtual machine base image can pre-deploy some basic formatting tools (such as mkfs.ext4 and mkfs.xfs tools), and can also continue to add and deploy some formatting tools corresponding to the user's new file system requirements in the future to support the implementation of more types of file system formatting.

[0133] S308: When it is determined that the attribute prefix detection result indicates that the attribute prefix in the target file system format attribute of the block device ebs1 is tryformat-, the current file system type of the block device ebs1 is detected to obtain a system type detection result. The current file system type of the block device ebs1 refers to the type of the file system that the block device ebs1 has at the current moment.

[0134] The present application embodiment does not limit the implementation of S308. For example, Figure 2 The kata-agent shown executes S308, which can be specifically: when it is determined that the attribute prefix word detection result indicates that the attribute prefix word in the target file system format attribute of the block device ebs1 is tryformat-, it can be determined that the block device ebs1 is in a state of only formatting an unformatted block device. At this time, first remove the prefix word tryformat- in the target file system format attribute of the block device ebs1 to obtain the initial file system format attribute of the block device ebs1, and update the file system attribute information of the device ebs1 according to the initial file system format attribute of the block device ebs1, so that the updated file system attribute information of the device ebs1 includes the initial file system format attribute of the block device ebs1. Then, the kata-agent calls the blkid tool to detect the current file system type of the device ebs1 and obtain the system type detection result.

[0135] It should be noted that the blkid tool can be pre-deployed to Figure 2 In the virtual machine base image of the virtual machine shown, kata-agent can call the blkid tool. In addition, the blkid tool is used to detect the file system format (such as the file system type) of the block device.

[0136] S309: If the system type detection result indicates that the file system type of the block device ebs1 cannot be detected, the block device ebs1 is formatted, and the formatted block device ebs1 is mounted into the container 2.

[0137] The present application embodiment does not limit the implementation of S309. For example, Figure 2The kata-agent shown executes S309, which can be specifically: when the block device ebs1 is in the state of only formatting the unformatted block device, if it is determined that the system type detection result indicates that the file system type of the block device ebs1 cannot be detected, it can be determined that the block device ebs1 belongs to an unformatted block device, so the file system of the block device ebs1 can be determined according to the initial file system format attribute of the block device ebs1, and the formatting tool corresponding to the file system of the block device ebs1 is called to format the block device ebs1, so that the formatted block device ebs1 has the file system of the above-mentioned block device ebs1; and then the formatted block device ebs1 is mounted into the container 2 according to the file system format specified by its file system attribute information for user access.

[0138] S310: If the system type detection result indicates that the file system type of the block device ebs1 can be detected, the block device ebs1 is mounted into the container 2.

[0139] The present application embodiment does not limit the implementation of S310. For example, Figure 2 The kata-agent shown executes S310, which may specifically be: when the block device ebs1 is in the state of only formatting an unformatted block device, if it is determined that the system type detection result indicates that the file system type of the block device ebs1 can be detected, it can be determined that the block device ebs1 belongs to a formatted block device. Therefore, in order to ensure the data security of the block device ebs1, there is no need to format the block device ebs1, but directly mount the block device ebs1 into the container 2 according to the file system format specified by its file system attribute information for user access.

[0140] Based on the above S301 to S310, it can be known that the present application can implant the formatting process of the block device into the boot process of the container for implementation, so that the block device mounted inside the container can be formatted without changing the user's permissions.

[0141] Based on the formatting method provided in the above method embodiment, the embodiment of the present application also provides a formatting device, which is explained and illustrated below in conjunction with the accompanying drawings.

[0142] Device Embodiment

[0143] For technical details of the formatting device provided in the device embodiment, please refer to the above method embodiment.

[0144] See also Figure 4 , which is a structural schematic diagram of a formatting device provided in an embodiment of the present application.

[0145] The formatting device 400 provided in the embodiment of the present application includes:

[0146] The acquisition unit 401 is used to acquire formatting parameters of the block device to be mounted after receiving the container startup request;

[0147] A determination unit 402 is used to determine the target file system format attribute of the block device to be mounted according to the formatting parameter;

[0148] The formatting unit 403 is used to format the block device to be mounted when it is determined that the format attribute of the target file system meets the first preset condition, and mount the formatted block device to be mounted to the target container in the boot state.

[0149] In a possible implementation manner, the determining unit 402 includes:

[0150] A first acquisition subunit is used to acquire the initial file system format attribute of the block device to be mounted;

[0151] A first determining subunit, configured to determine a target attribute prefix word according to the formatting parameter;

[0152] The second determining subunit is configured to use the target attribute prefix as a prefix of the initial file system format attribute to obtain the target file system format attribute of the block device to be mounted.

[0153] In a possible implementation, the formatting unit 403 includes:

[0154] A third determining subunit, configured to determine a target file system type according to the target file system format attribute;

[0155] A fourth determination subunit is used to determine a target formatting tool according to the target file system type; wherein the target formatting tool is used to format the file system of the block device to be mounted into the target file system type;

[0156] The formatting subunit is used to format the block device to be mounted using the target formatting tool.

[0157] In a possible implementation manner, determining that the target file system format attribute satisfies a first preset condition includes:

[0158] Determining that the attribute prefix word in the target file system format attribute satisfies the first sub-condition;

[0159] or,

[0160] It is determined that the attribute prefix in the target file system format attribute satisfies the second sub-condition, and it is determined that the file system of the block device to be mounted satisfies the third sub-condition.

[0161] In a possible implementation, the acquiring unit 401 includes:

[0162] A second acquisition subunit is used to acquire a configuration file of the block device to be mounted;

[0163] The fifth determining subunit is used to parse the configuration file of the block device to be mounted to obtain the formatting parameters of the block device to be mounted.

[0164] In a possible implementation manner, the formatting device 400 further includes:

[0165] The mounting unit is used to mount the block device to be mounted into the target container in the boot state when it is determined that the format attribute of the target file system meets the second preset condition.

[0166] In a possible implementation manner, determining that the target file system format attribute satisfies a second preset condition includes:

[0167] Determining that the attribute prefix in the target file system format attribute satisfies the second sub-condition, and determining that the file system of the block device to be mounted satisfies the fourth sub-condition;

[0168] or,

[0169] It is determined that the attribute prefix word in the target file system format attribute satisfies a fifth sub-condition.

[0170] Based on the relevant contents of the above-mentioned formatting device 400, it can be known that after receiving the container startup request, the formatting device 400 can first obtain the formatting parameters of the block device to be mounted, and determine the target file system format attributes of the block device to be mounted according to the formatting parameters; when it is determined that the target file system format attributes meet the first preset condition, the block device to be mounted is formatted, and the formatted block device to be mounted is mounted to the target container in the startup state, so that the formatting processing of the block device to be mounted can be completed during the startup process of the target container.

[0171] Based on the formatting method provided in the above method embodiment, the embodiment of the present application also provides a device, which is explained and illustrated below in conjunction with the accompanying drawings.

[0172] Device Embodiment

[0173] For technical details of the device provided in the device embodiment, please refer to the above method embodiment.

[0174] See also Figure 5 , which is a schematic diagram of the device structure provided in an embodiment of the present application.

[0175] The device 500 provided in the embodiment of the present application includes: a processor 501 and a memory 502;

[0176] The memory 502 is used to store computer programs;

[0177] The processor 501 is used to execute any implementation of the formatting method provided in the above method embodiment according to the computer program. That is, the processor 501 is used to execute the following steps:

[0178] After receiving the container startup request, obtain the formatting parameters of the block device to be mounted;

[0179] Determining the target file system format attributes of the block device to be mounted according to the formatting parameters;

[0180] When it is determined that the format attribute of the target file system satisfies the first preset condition, the block device to be mounted is formatted, and the formatted block device to be mounted is mounted to the target container in the boot state.

[0181] Optionally, determining the target file system format attribute of the block device to be mounted according to the formatting parameter includes:

[0182] Obtaining the initial file system format attributes of the block device to be mounted;

[0183] Determine a target attribute prefix word according to the formatting parameter;

[0184] The target attribute prefix is ​​used as a prefix of the initial file system format attribute to obtain the target file system format attribute of the block device to be mounted.

[0185] Optionally, formatting the block device to be mounted includes:

[0186] Determining the target file system type according to the target file system format attribute;

[0187] Determine a target formatting tool according to the target file system type; wherein the target formatting tool is used to format the file system of the block device to be mounted into the target file system type;

[0188] The target formatting tool is used to format the block device to be mounted.

[0189] Optionally, the determining that the format attribute of the target file system satisfies a first preset condition includes:

[0190] Determining that the attribute prefix word in the target file system format attribute satisfies the first sub-condition;

[0191] or,

[0192] It is determined that the attribute prefix in the target file system format attribute satisfies the second sub-condition, and it is determined that the file system of the block device to be mounted satisfies the third sub-condition.

[0193] Optionally, obtaining formatting parameters of the block device to be mounted includes:

[0194] Obtaining a configuration file for the block device to be mounted;

[0195] The configuration file of the block device to be mounted is parsed to obtain formatting parameters of the block device to be mounted.

[0196] Optionally, also include:

[0197] When it is determined that the target file system format attribute satisfies the second preset condition, the block device to be mounted is mounted to the target container in the boot state.

[0198] Optionally, the determining that the format attribute of the target file system satisfies a second preset condition includes:

[0199] Determining that the attribute prefix in the target file system format attribute satisfies the second sub-condition, and determining that the file system of the block device to be mounted satisfies the fourth sub-condition;

[0200] or,

[0201] It is determined that the attribute prefix word in the target file system format attribute satisfies a fifth sub-condition.

[0202] The above is the relevant content of the device 500 provided in the embodiment of the present application.

[0203] Based on the formatting method provided in the above method embodiment, the embodiment of the present application also provides a computer-readable storage medium.

[0204] Medium Embodiment

[0205] For technical details of the computer-readable storage medium provided by the medium embodiment, please refer to the method embodiment.

[0206] The embodiment of the present application provides a computer-readable storage medium, which is used to store a computer program, and the computer program is used to execute any implementation of the formatting method provided in the above method embodiment. That is, the computer program is used to execute the following steps:

[0207] After receiving the container startup request, obtain the formatting parameters of the block device to be mounted;

[0208] Determining the target file system format attributes of the block device to be mounted according to the formatting parameters;

[0209] When it is determined that the format attribute of the target file system satisfies the first preset condition, the block device to be mounted is formatted, and the formatted block device to be mounted is mounted to the target container in the boot state.

[0210] Optionally, determining the target file system format attribute of the block device to be mounted according to the formatting parameter includes:

[0211] Obtaining the initial file system format attributes of the block device to be mounted;

[0212] Determine a target attribute prefix word according to the formatting parameter;

[0213] The target attribute prefix is ​​used as a prefix of the initial file system format attribute to obtain the target file system format attribute of the block device to be mounted.

[0214] Optionally, formatting the block device to be mounted includes:

[0215] Determining the target file system type according to the target file system format attribute;

[0216] Determine a target formatting tool according to the target file system type; wherein the target formatting tool is used to format the file system of the block device to be mounted into the target file system type;

[0217] The target formatting tool is used to format the block device to be mounted.

[0218] Optionally, the determining that the format attribute of the target file system satisfies a first preset condition includes:

[0219] Determining that the attribute prefix word in the target file system format attribute satisfies the first sub-condition;

[0220] or,

[0221] It is determined that the attribute prefix in the target file system format attribute satisfies the second sub-condition, and it is determined that the file system of the block device to be mounted satisfies the third sub-condition.

[0222] Optionally, obtaining formatting parameters of the block device to be mounted includes:

[0223] Obtaining a configuration file for the block device to be mounted;

[0224] The configuration file of the block device to be mounted is parsed to obtain formatting parameters of the block device to be mounted.

[0225] Optionally, also include:

[0226] When it is determined that the target file system format attribute satisfies the second preset condition, the block device to be mounted is mounted to the target container in the boot state.

[0227] Optionally, the determining that the format attribute of the target file system satisfies a second preset condition includes:

[0228] Determining that the attribute prefix in the target file system format attribute satisfies the second sub-condition, and determining that the file system of the block device to be mounted satisfies the fourth sub-condition;

[0229] or,

[0230] It is determined that the attribute prefix word in the target file system format attribute satisfies a fifth sub-condition.

[0231] The above is the relevant content of the computer-readable storage medium provided in the embodiments of the present application.

[0232] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0233] The above is only a preferred embodiment of the present invention and does not limit the present invention in any form. Although the present invention has been disclosed as above in the preferred embodiment, it is not used to limit the present invention. Any technician familiar with the art can make many possible changes and modifications to the technical solution of the present invention by using the methods and technical contents disclosed above without departing from the scope of the technical solution of the present invention, or modify it into an equivalent embodiment of equivalent changes. Therefore, any simple modification, equivalent change and modification made to the above embodiments according to the technical essence of the present invention without departing from the content of the technical solution of the present invention still falls within the scope of protection of the technical solution of the present invention.

Claims

1. A formatting method, characterized in that: include: After receiving the container startup request, obtain the formatting parameters of the block device to be mounted; Determining the target file system format attributes of the block device to be mounted according to the formatting parameters; When it is determined that the format attribute of the target file system satisfies the first preset condition, formatting the block device to be mounted, and mounting the formatted block device to be mounted to the target container in the boot state; Determining the target file system format attribute of the block device to be mounted according to the formatting parameter includes: Obtaining the initial file system format attributes of the block device to be mounted; Determine a target attribute prefix word according to the formatting parameter; Using the target attribute prefix as a prefix of the initial file system format attribute to obtain the target file system format attribute of the block device to be mounted; The step of formatting the block device to be mounted includes: Determining the target file system type according to the target file system format attribute; Determine a target formatting tool according to the target file system type; wherein the target formatting tool is used to format the file system of the block device to be mounted into the target file system type; The target formatting tool is used to format the block device to be mounted.

2. The method according to claim 1, characterized in that The determining that the target file system format attribute meets a first preset condition includes: Determining that the attribute prefix word in the target file system format attribute satisfies the first sub-condition; or, It is determined that the attribute prefix in the target file system format attribute satisfies the second sub-condition, and it is determined that the file system of the block device to be mounted satisfies the third sub-condition.

3. The method according to claim 1, characterized in that The step of obtaining the formatting parameters of the block device to be mounted includes: Obtaining a configuration file for the block device to be mounted; The configuration file of the block device to be mounted is parsed to obtain formatting parameters of the block device to be mounted.

4. The method according to claim 1, characterized in that: The method further comprises: When it is determined that the target file system format attribute satisfies the second preset condition, the block device to be mounted is mounted to the target container in the boot state.

5. The method according to claim 4, characterized in that The determining that the target file system format attribute meets a second preset condition includes: Determining that the attribute prefix in the target file system format attribute satisfies the second sub-condition, and determining that the file system of the block device to be mounted satisfies the fourth sub-condition; or, It is determined that the attribute prefix word in the target file system format attribute satisfies a fifth sub-condition.

6. A formatting device, characterized in that: include: An acquisition unit, configured to acquire formatting parameters of a block device to be mounted after receiving a container startup request; A determination unit, configured to determine a target file system format attribute of the block device to be mounted according to the formatting parameter; A formatting unit, configured to format the block device to be mounted when it is determined that the format attribute of the target file system satisfies a first preset condition, and mount the formatted block device to be mounted into a target container in a boot state; The determining unit comprises: A first acquisition subunit is used to acquire the initial file system format attribute of the block device to be mounted; A first determining subunit, configured to determine a target attribute prefix word according to the formatting parameter; A second determining subunit is configured to use the target attribute prefix as a prefix of the initial file system format attribute to obtain the target file system format attribute of the block device to be mounted; The formatting unit comprises: A third determining subunit, configured to determine a target file system type according to the target file system format attribute; A fourth determination subunit is used to determine a target formatting tool according to the target file system type; wherein the target formatting tool is used to format the file system of the block device to be mounted into the target file system type; The formatting subunit is used to format the block device to be mounted using the target formatting tool.

7. A device, characterized in that: The device comprises a processor and a memory: The memory is used to store computer programs; The processor is configured to execute the method according to any one of claims 1 to 5 according to the computer program.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and the computer program is used to execute the method according to any one of claims 1 to 5.