Detailed Description
In order to make the present application better understood by those skilled in the art, the following description will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings, and it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Method embodiment
Referring to fig. 1, a flowchart of a formatting method according to an embodiment of the present application is shown.
The formatting method provided by the embodiment of the application comprises S101-S103:
S101: and after receiving the container starting request, obtaining the formatting parameters of the block equipment to be mounted.
The container start request is for requesting 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.
The block device to be mounted refers to a block device to be mounted in a container in a virtual machine, and the embodiment of the application is not limited to the block device to be mounted, for example, the block device to be mounted may be a cloud hard disk (EBS disk for short).
The formatting parameter is used to characterize the relevant information of the formatting process of the block to be mounted device, and the embodiment of the present application is not limited to the formatting parameter, for example, the formatting parameter may be Always, ifNotFormat or lever.
Always is used to identify mandatory formatting. The forced formatting means that each piece of equipment mounted in the container must be formatted in the starting-up process of the container. At this time, a once formatted disk may be once again subjected to forced formatting. In addition, the application scene of the forced formatting is as follows: when it is desired to perform file system replacement or data cleaning of the block devices mounted in the container, forced formatting may be selected. It should be noted that, for data security, mandatory formatting should be avoided as a configuration default for the formatting parameters of each block device.
IfNotFormat are used to identify a block device that only formats an unformatted block. Wherein, only formatting the block device without formatting means that the block device mounted to the container for the first time is automatically formatted in the boot process of the container. 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 a block device that has not undergone formatting, so that the block device needs to be subjected to formatting; if a block device is not N (N.gtoreq.2) th mounted to the container, determining that the block device is a formatted block device, so that the block device does not need to be formatted again.
Never is used to indicate that formatting is prohibited. The prohibition of formatting refers to that all block devices mounted in the container are not formatted in any condition in the starting-up process of the container. It can be seen that this protects the user data from being corrupted by accidental formatting, causing unnecessary losses, so that for data security reasons, the forbidden formatting can be taken as a configuration default for the formatting parameters of each block device.
In addition, the embodiment of the application also provides an implementation manner for obtaining the formatting parameters (that is, S101) of the block to be mounted equipment, which specifically includes: and acquiring the configuration file of the block equipment to be mounted, and analyzing the configuration file of the block equipment to be mounted to obtain the formatting parameters of the block equipment to be mounted. The configuration file is used for recording relevant configuration parameters of the block equipment to be mounted, and the configuration file of the block equipment to be mounted comprises formatting parameters of the block equipment to be mounted. It should be noted that the embodiment of the present application is not limited to the configuration file, and for example, the configuration file may be a json file.
Based on the above-mentioned content related to S101, after receiving the container start request for requesting to start the target container, it may be determined that the target container is in a start-up state, at this time, a configuration file of the block device to be mounted may be obtained first, and then the configuration file may be subjected to format parameter analysis to obtain the format parameters of the block device to be mounted, so that the block device to be mounted may be formatted based on the format parameters.
S102: and determining the format attribute of the target file system of the block equipment to be mounted according to the format parameters of the block equipment to be mounted.
The target file system format attribute is used to characterize a file system (e.g., xfs file system, ext4 file system, and other file systems, etc.) that the block device to be mounted should have when mounting the block device to be mounted to the target container, and type information of formatting processing that the block device to be mounted should undergo before mounting the block device to be mounted to the target container (e.g., types of forced formatting, formatting only non-formatted block devices, or inhibit formatting, etc.).
In addition, the embodiment of the present application further provides an implementation manner for determining the format attribute of the target file system (i.e. S102), which specifically includes S1021-S1023:
s1021: and acquiring the format attribute of the initial file system of the block equipment to be mounted.
The initial file system format attribute is used to characterize the file system (e.g., xfs file system, ext4 file system, and other file systems, etc.) that the block device to be mounted should have when mounting the block device to be mounted to the target container.
In addition, the embodiment of the present application further provides an implementation manner for obtaining the format attribute of the initial file system (i.e. S1021), which specifically includes: analyzing the configuration file of the block equipment to be mounted to obtain the format attribute of the initial file system of the block equipment to be mounted. It can be seen that the configuration file of the block device to be mounted may include not only the formatting parameters of the block device to be mounted, but also the format attribute of the initial file system of the block device to be mounted.
S1022: and determining the target attribute prefix word according to the formatting parameters of the block equipment to be mounted.
The target attribute prefix word is used to characterize type information of formatting processing that the block device to be mounted should undergo before mounting the block device to be mounted to the target container (e.g., types of forced formatting, formatting only non-formatted block devices, or prohibited formatting, etc.), and the target attribute prefix word may be added to the initial file system format attribute as a prefix word of the initial file system format attribute.
In addition, the embodiment of the application also provides an implementation manner for determining the target attribute prefix word (namely S1022), which specifically comprises the following steps: and determining the target attribute prefix word according to the first mapping relation and the formatting parameters of the block equipment to be mounted. The first mapping relation comprises a corresponding relation between formatting parameters of the block equipment to be mounted and target attribute prefix words.
The first mapping relationship is used for recording between each formatting parameter and each attribute prefix word, and the embodiment of the present application is not limited to the first mapping relationship, and the first mapping relationship may be a mapping relationship shown in table 1.
Formatting parameters |
Attribute prefix words |
Always |
format- |
ifNotFormat |
tryformat- |
Never |
(Without attribute prefix word) |
Table 1 correspondence between different formatting parameters and prefix words of different attributes
Based on the above-mentioned related content of S1022, after the formatting parameter of the block device to be mounted is obtained, the target attribute prefix word of the block device to be mounted may be determined according to the formatting parameter of the block device to be mounted, which specifically includes: when the first mapping relation comprises the corresponding relation shown in table 1, if the formatting parameter of the block equipment to be mounted is Always, knowing that the target attribute prefix word of the block equipment to be mounted is format-based on the first mapping relation, so that the format-serving as the prefix word can be added to the initial file system format attribute of the block equipment to be mounted subsequently to obtain the target file system format attribute of the block equipment to be mounted; if the formatting parameter of the block equipment to be mounted is ifNotFormat, knowing that the target attribute prefix word of the block equipment to be mounted is tryformat-based on the first mapping relation, so that tryformat-serving as the prefix word can be added to the initial file system format attribute of the block equipment to be mounted to obtain the target file system format attribute of the block equipment to be mounted; if the formatting parameter of the block to be mounted equipment is new, the target attribute prefix word of the block to be mounted equipment can be known to be null based on the first mapping relation, so that the initial file system format attribute of the block to be mounted equipment can be directly used as the target file system format attribute of the block to be mounted equipment, and any attribute prefix word is not required to be added.
S1023: and taking the target attribute prefix word as the prefix of the initial file system format attribute of the block equipment to be mounted to obtain the target file system format attribute of the block equipment to be mounted.
In the embodiment of the application, after the initial file system format attribute and the target attribute prefix word of the block equipment to be mounted are obtained, the target attribute prefix word can be added into the initial file system format attribute of the block equipment to be mounted as the attribute prefix word to obtain the target file system format attribute of the block equipment to be mounted, so that the target file system format attribute can comprise the target attribute prefix word and the initial file system format attribute, and the target file system format attribute can characterize the file system type which the block equipment to be mounted should have and the type of formatting process which should be experienced when the block equipment to be mounted is mounted to a target container.
Based on the above-mentioned related content of S102, in the embodiment of the present application, after the format parameter of the block device to be mounted is obtained, the format attribute of the target file system of the block device to be mounted may be determined according to the format parameter, which specifically includes: firstly, inquiring from a first mapping relation to obtain an attribute prefix word corresponding to the formatting parameter as a target attribute prefix word; and adding the target attribute prefix word as a prefix of the initial file system format attribute of the block equipment to be mounted to obtain the target file system format attribute of the block equipment to be mounted, so that the target file system format attribute can comprise the target attribute prefix word and the initial file system format attribute, and the target file system format attribute can represent the file system type which the block equipment to be mounted should have and the type of formatting process which should be experienced when the block equipment to be mounted is mounted to a target container.
S103: when the format attribute of the target file system of the block equipment to be mounted meets a first preset condition, formatting the block equipment to be mounted, and mounting the formatted block equipment to be mounted into a target container in a starting state of starting.
The first preset condition is used for representing conditions met by the format attribute of the target file system of the block device needing to be formatted.
In some cases, determining that the target file system format attribute meets the first preset condition may specifically include the following two cases.
In case 1, when it is determined that the attribute prefix word in the target file system format attribute meets the first sub-condition, it is determined that the target file system format attribute meets the first preset condition.
The first sub-condition may be preset, for example, the first sub-condition may be that the attribute prefix word is format-.
Based on the above description of case 1, after the target file system format attribute of the block device to be mounted is obtained, if the attribute prefix word in the target file system format attribute meets the first sub-condition (for example, the attribute prefix word in the target file system format attribute is format-), it can be determined that the block device to be mounted should be formatted forcedly, so that it can be determined that the block device to be mounted must be formatted before being mounted to the target container.
And 2, when the attribute prefix word in the format attribute of the target file system is determined to meet the second sub-condition and the file system of the block to be mounted equipment is determined to meet the third sub-condition, determining that the format attribute of the target file system meets the first preset condition.
The second sub-condition may be preset, for example, the second sub-condition may be that the attribute prefix word is tryformat-.
The third sub-condition may be preset, for example, the third sub-condition may be that a file system of the block device to be mounted cannot be detected.
Based on the above-mentioned related content of the case 2, after the target file system format attribute of the block device to be mounted is obtained, if the attribute prefix word in the target file system format attribute satisfies the second sub-condition, it may be determined that the block device to be mounted should correspond to the formatting process of "only formatting the unformatted block device", so that the file system detection of the block device to be mounted may be continued, 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 may be determined that the block device to be mounted belongs to the unformatted block device, so that it may be determined that the block device to be mounted must be formatted before being mounted to the target container.
It should be noted that, the embodiment of the present application is not limited to the above-mentioned execution process of file system detection for the block device to be mounted, and for example, it may be implemented by using blkid tools capable of supporting file system format detection.
Based on the above two situations, in the embodiment of the present application, when determining that the block device to be mounted should be formatted forcibly according to the attribute prefix word of the target file system format attribute of the block device to be mounted, no matter whether the block device to be mounted is formatted or not, the block device to be mounted needs to be formatted in the startup process of the target container. In addition, when determining that the block device to be mounted corresponds to the formatting process of the block device which is only formatted and not formatted according to the attribute prefix word of the target file system format attribute of the block device to be mounted, formatting the block device to be mounted only when determining that the block device to be mounted belongs to the block device which is not formatted.
In addition, the embodiment of the application also provides an implementation manner for formatting the equipment of the block to be mounted, which specifically can include S1031-S1033:
s1031: and determining the type of the target file system according to the format attribute of the target file system of the block equipment to be mounted.
The target file system type is used to characterize the type of file system that the block to be mounted device should have when it is mounted to the target container.
In addition, the embodiment of the present application further provides an implementation manner of determining the type of the target file system (i.e. S1031), which specifically includes: and deleting prefix attribute words (such as formats-or tryformat-) in the format attribute of the target file system of the block device to be mounted to obtain the target file system type of the block device to be mounted, so that the target file system type can represent the type of the file system which the block device to be mounted should have when the block device to be mounted is mounted to the target container.
S1032: a target formatting utility is determined based on the target file system type.
The target formatting tool is used for formatting the file system of the block equipment to be mounted into a target file system type.
In addition, the embodiment of the present application further provides an implementation manner of determining the target formatting tool (i.e. S1032), which specifically includes: and determining a target formatting tool according to the second mapping relation and the target file system type. The second mapping relationship comprises a corresponding relationship between the type of the target file system and the target formatting tool.
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.
File system type |
Formatting tool |
ext4 |
Mkfs. Ext4 tool |
xfs |
Mkfs. Xfs tool |
TABLE 2 correspondence between different file system types and different formatting tools
Based on the above-mentioned content related to S1032, after determining the target file system type of the block device to be mounted, the formatting tool corresponding to the target file system type may be directly queried from the second mapping relationship as a target formatting tool for formatting the block device to be mounted. For example, when the second mapping relationship includes the correspondence relationship shown in table 2, if the target file system type of the block device to be mounted is ext4, the target formatting utility should be an mkfs.ext4 utility; if the target file system type of the block device to be mounted is xfs, the target formatting utility should be an mkfs.
S1033: and formatting the block to be mounted equipment by utilizing the target formatting tool.
Based on the above-mentioned content related to S103, after determining that the format attribute of the target file system of the block device to be mounted meets the first preset condition, the attribute prefix word in the format attribute of the target file system may be removed to obtain the target file system type of the block device to be mounted, and then the format tool corresponding to the target file system type is used 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 the file system of the target file system type.
In some cases, the block device to be mounted can be directly mounted in the target container, and the block device to be mounted cannot be formatted in the starting process of the target container. Based on this, the embodiment of the present application further provides a possible implementation manner of the formatting method, where the formatting method includes S104 in addition to S101 to S103 described above:
S104: and when the format attribute of the target file system of the block equipment to be mounted meets a second preset condition, mounting the block equipment to be mounted into a target container in a starting state of starting.
The second preset condition is used for representing the condition met by the format attribute of the target file system of the block device without formatting.
In some cases, determining that the target file system format attribute meets the second preset condition may specifically include the following two cases.
In the first case, when it is determined that the attribute prefix word in the target file system format attribute meets the second sub-condition and it is determined that the file system of the block device to be mounted meets the fourth sub-condition, it is determined that the target file system format attribute meets the second preset condition.
It should be noted that, please refer to the above for the relevant content of the second sub-condition.
The third sub-condition may be preset, for example, the third sub-condition may be a file system capable of detecting the block device to be mounted.
Based on the above-mentioned related content of the first case, after the target file system format attribute of the block device to be mounted is obtained, if the attribute prefix word in the target file system format attribute meets the second sub-condition, it may be determined that the block device to be mounted should correspond to the formatting process of "only the unformatted block device is formatted", so that the file system detection of the block device to be mounted may be continued, 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 meets the fourth sub-condition), it may be determined that the block device to be mounted belongs to the formatted block device, so that it may be determined that the block device to be mounted does not need to be formatted before being mounted to the target container.
And secondly, when the attribute prefix word in the target file system format attribute is determined to meet the fifth sub-condition, determining that the target file system format attribute meets a second preset condition.
Wherein, the fifth sub-condition may be preset, for example, the fifth sub-condition may be that the attribute prefix word is null (i.e., there is no attribute prefix word).
Based on the above-mentioned related content of the second case, after the target file system format attribute of the block device to be mounted is obtained, if the attribute prefix word in the target file system format attribute meets the fifth sub-condition (for example, the target file system format attribute has no attribute prefix word), it may be determined that the block device to be mounted should be prohibited from being formatted, so that it may be determined that the block device to be mounted does not need to be formatted before being mounted to the target container.
Based on the above two situations, in the embodiment of the present application, when determining that the block device to be mounted corresponds to the formatting process of "only formatting unformatted block device" according to the attribute prefix word 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 the formatted block device, it is not necessary to perform formatting processing on the block device to be mounted. In addition, when determining that the block device to be mounted should be prohibited from being formatted according to the attribute prefix word of the format attribute of the target file system of the block device to be mounted, no matter whether the block device to be mounted is formatted or not, the block device to be mounted cannot be formatted in the starting process of the target container.
Based on the above-mentioned related content of S104, if the format attribute of the target file system of the block device to be mounted meets the second preset condition, it may be determined that no formatting process is required for the block device to be mounted in the boot process of the target container, so that the block device to be mounted may be directly mounted in the target container in the boot state, and thus the data security in the block device to be mounted may be protected.
Based on the related content of the formatting method, after receiving a container starting request, the formatting parameters of the block equipment to be mounted can be obtained first, and the format attribute of the target file system of the block equipment to be mounted can be determined according to the formatting parameters; when the format attribute of the target file system meets the first preset condition, formatting the block equipment to be mounted, and mounting the formatted block equipment to be mounted into a target container in a starting state, so that the formatting process of the block equipment to be mounted can be completed in the starting process of the target container.
In order to facilitate understanding of the technical solution of the present application, the following description will be made with reference to a scenario embodiment.
Scene embodiment
Referring to fig. 2, the application scenario of the formatting method provided by the embodiment of the present application is schematic, and in the application scenario shown in fig. 2, the block device ebs1 needs to be mounted inside the container 2.
When the formatting method provided by the embodiment of the present application is applied to the application scenario shown in fig. 2, as shown in fig. 3, the formatting method may include S301-S310:
s301: a user-triggered container start request is received and is used to request that container 2 be started in the virtual machine.
S302: the configuration file ebs1.Json of the block device ebs1 is acquired. Wherein the configuration file ebs1.Json of the block device ebs1 includes formatting parameters and initial file system format attributes of the block device ebs1.
S303: and analyzing the configuration file ebs1.Json of the block device ebs1 to obtain the formatting parameters of the block device ebs1 and the format attribute of the initial file system of the block device ebs1.
The embodiment of the present application is not limited to the implementation of S303, for example, if an analysis tool for analyzing a configuration file is deployed in kata-runtime shown in fig. 2 (for example, the analysis tool can implement analysis procedures such as format parameter analysis and file system format attribute analysis), S303 may be implemented by using the analysis tool in kata-runtime shown in fig. 2.
S304: determining a target file system format attribute of the block device ebs1 according to the formatting parameter of the block device ebs1 and the initial file system format attribute of the block device ebs1, and updating file system attribute information of the block device ebs1 by using the target file system format attribute of the block device ebs1 so that the updated file system attribute information of the block device ebs1 comprises the target file system format attribute of the block device ebs 1.
The embodiment of the present application is not limited to the implementation of S303, for example, S304 may be implemented by kata-runtime shown in fig. 2 for S304.
S305: and detecting attribute prefix words of the file system attribute information of the block equipment ebs1 to obtain an attribute prefix word detection result.
The embodiment of the present application is not limited to the implementation of S303, for example, if a prefix detection tool for detecting attribute prefix words of file system attribute information of a block device is deployed in advance in kata-agents shown in fig. 2, S305 may be executed by using the prefix detection tool in kata-agents shown in fig. 2.
In addition, in the embodiment of the present application, since different attribute prefix words correspond to different formatting processes, the formatting process for the block device ebs1 may be determined based on the attribute prefix word detection result, which specifically includes: if the attribute prefix word detection result indicates that the attribute prefix word does not exist in the format attribute of the target file system of the block device ebs1, determining that the block device ebs1 corresponds to the format prohibition, so that the block device ebs1 does not need to be formatted and directly mount the block device ebs1 into the container 2 (i.e., the related content of S306); if 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 is determined that the block device ebs1 corresponds to forced formatting, so that the block device ebs1 must be formatted first, and then the formatted block device ebs1 is mounted in the container 2, that is, the related 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 only the block device that is not formatted, so it may be determined whether the block device ebs1 needs to be formatted based on the file system of the block device ebs1 itself (i.e., the related content of S308-S310).
S306: and when 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 inside the container 2.
The embodiment of the present application is not limited to the implementation of S306, for example, S306 may be performed by using kata-agent shown in fig. 2, which may specifically be: 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 may be determined that the block device ebs1 is in a forbidden format state, so in order to ensure data security of the block device ebs1, no formatting process needs to be performed on the block device ebs1, and the block device ebs1 is directly mounted inside the container 2 according to a file system format specified by file system attribute information thereof, so as to be accessed by a user. It should be noted that, if the above mounting process fails, it is required to additionally emphasize that the block device ebs1 is prohibited from being formatted in the information of the reporting error.
S307: 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-, the block device ebs1 is formatted, and the formatted block device ebs1 is mounted inside the container 2.
The embodiment of the present application is not limited to the implementation of S307, for example, S307 may be performed by using kata-agent shown in fig. 2, which may specifically be: 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 may be determined that the block device ebs1 is in a forced format 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 an initial file system format attribute of the block device ebs1, and file system attribute information of the block 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 block device ebs1 includes the initial file system format attribute of the block device ebs 1. Then, determining the file system of the block device ebs1 according to the initial file system format attribute of the block device ebs1, and calling a formatting tool corresponding to the file system of the block device ebs1 to perform formatting processing on the block device ebs1, so that the formatted block device ebs1 has the file system of the block device ebs 1. Finally, the formatted block device ebs1 is mounted inside the container 2 according to the file system format specified by the file system attribute information thereof, so as to be accessed by the user.
It should be noted that, the formatting tools corresponding to each file system may be pre-deployed into the virtual machine base image of the virtual machine shown in fig. 2, so that kata-agents can call the formatting tools. In addition, the virtual machine base image can pre-deploy some basic formatting tools (such as mkfs. Ext4 and mkfs. Xfs tools), and can further increase and deploy some formatting tools corresponding to new demands of the file system of the user in the later period so as to support the realization of more types of file system formatting.
S308: and when the attribute prefix word detection result is determined to indicate that the attribute prefix word in the target file system format attribute of the block equipment ebs1 is tryformat-, detecting the current file system type of the block equipment ebs1 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 time.
The embodiment of the present application is not limited to the implementation of S308, for example, S308 may be performed by using kata-agents shown in fig. 2, which may specifically be: 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 may be determined that the block device ebs1 is in a state of formatting only an unformatted block device, at this time, the prefix word tryformat-in the target file system format attribute of the block device ebs1 is first removed to obtain an initial file system format attribute of the block device ebs1, and file system attribute information of the block 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 block device ebs1 includes the initial file system format attribute of the block device ebs 1. Then, blkid tool is called by kata-agent to detect the current file system type of the device ebs1, and a system type detection result is obtained.
It should be noted that blkid tools may be pre-deployed into the virtual machine base image of the virtual machine shown in fig. 2 to enable kata-agents to call the blkid tools. In addition, blkid tools are used to detect the file system format (e.g., file system type) of the block device.
S309: if the system type detection result indicates that the file system type of the block device ebs1 cannot be detected, formatting the block device ebs1, and mounting the formatted block device ebs1 into the container 2.
The embodiment of the present application is not limited to the implementation of S309, for example, S309 may be performed by using kata-agent shown in fig. 2, which may specifically be: when the block device ebs1 is in a 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 may be determined that the block device ebs1 belongs to the unformatted block device, so that the file system of the block device ebs1 may be determined according to the initial file system format attribute of the block device ebs1, and a formatting tool corresponding to the file system of the block device ebs1 may be called to perform formatting processing on the block device ebs1, so that the formatted block device ebs1 has the file system of the block device ebs 1; and then the formatted block equipment ebs1 is mounted in the container 2 according to the file system format specified by the file system attribute information thereof so as to be accessed by a user.
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 inside the container 2.
The embodiment of the present application is not limited to the implementation of S310, for example, S310 may be performed by using kata-agents shown in fig. 2, which may specifically be: when the block device ebs1 is in a 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 can be detected, it can be determined that the block device ebs1 belongs to the formatted block device, so that in order to ensure the data security of the block device ebs1, the block device ebs1 does not need to be formatted, but the block device ebs1 is directly mounted in the container 2 according to the file system format specified by the file system attribute information thereof, so as to be accessed by a user.
Based on the above-mentioned related content of S301 to S310, the present application can implement the formatting process of the block device by implanting the formatting process into the boot-up process of the container, so that the formatting process of the block device mounted inside the container can be implemented without changing the user permission.
Based on the formatting method provided by the embodiment of the method, the embodiment of the application also provides a formatting device, which is explained and illustrated below with reference to the accompanying drawings.
Device embodiment
For technical details of the formatting device provided in the device embodiment, please refer to the above method embodiment.
Referring to fig. 4, a schematic structural diagram of a formatting device according to an embodiment of the present application is shown.
The formatting device 400 provided in the embodiment of the application includes:
an obtaining unit 401, configured to obtain a formatting parameter of a block device to be mounted after receiving a container start request;
A determining unit 402, configured to determine, according to the formatting parameter, a target file system format attribute of the block device to be mounted;
And a formatting unit 403, configured to, when it is determined that the format attribute of the target file system meets a first preset condition, format the block device to be mounted, and mount the formatted block device to be mounted in a target container in a startup state.
In a possible implementation manner, the determining unit 402 includes:
the first acquisition subunit is used for acquiring the format attribute of the initial file system of the block equipment to be mounted;
a first determining subunit, configured to determine a target attribute prefix word according to the formatting parameter;
and the second determining subunit is used for taking the target attribute prefix word as the prefix of the initial file system format attribute to obtain the target file system format attribute of the block to be mounted equipment.
In a possible implementation manner, the formatting unit 403 includes:
a third determining subunit, configured to determine a target file system type according to the format attribute of the target file system;
A fourth determining subunit, configured to determine a target formatting tool according to the target file system type; the target formatting tool is used for formatting the file system of the block to be mounted device into the target file system type;
And the formatting subunit is used for formatting the block equipment to be mounted by utilizing the target formatting tool.
In one possible implementation manner, the determining that the target file system format attribute meets a first preset condition includes:
determining that an attribute prefix word in the target file system format attribute meets a first sub-condition;
Or alternatively
And determining that the attribute prefix word in the target file system format attribute meets a second sub-condition, and determining that the file system of the block to be mounted equipment meets a third sub-condition.
In a possible implementation manner, the obtaining unit 401 includes:
the second acquisition subunit is used for acquiring the configuration file of the block equipment to be mounted;
and a fifth determining subunit, configured to parse the configuration file of the block to be mounted device to obtain the formatting parameter of the block to be mounted device.
In one possible implementation, the formatting device 400 further includes:
and the mounting unit is used for mounting the block equipment to be mounted into a target container in a starting state when the format attribute of the target file system meets a second preset condition.
In one possible implementation manner, the determining that the target file system format attribute meets a second preset condition includes:
determining that an attribute prefix word in the format attribute of the target file system meets a second sub-condition, and determining that a file system of the block to be mounted equipment meets a fourth sub-condition;
Or alternatively
And determining that the attribute prefix word in the target file system format attribute meets a fifth sub-condition.
Based on the related content of the formatting device 400, after receiving the container start request, the formatting device 400 may first obtain the formatting parameters of the block device to be mounted, and determine the format attribute of the target file system of the block device to be mounted according to the formatting parameters; when the format attribute of the target file system meets the first preset condition, formatting the block equipment to be mounted, and mounting the formatted block equipment to be mounted into a target container in a starting state, so that the formatting process of the block equipment to be mounted can be completed in the starting process of the target container.
Based on the formatting method provided by the method embodiment, the embodiment of the application also provides equipment, and the equipment is explained and illustrated below with reference to the accompanying drawings.
Device embodiment
For the technical details of the device provided in the device embodiment, please refer to the above method embodiment.
Referring to fig. 5, a schematic diagram of an apparatus structure according to an embodiment of the present application is shown.
The apparatus 500 provided in the embodiment of the present application includes: a processor 501 and a memory 502;
the memory 502 is used for storing a computer program;
The processor 501 is configured to execute any implementation of the formatting method provided by the method embodiment described above according to the computer program. That is, the processor 501 is configured to perform the steps of:
After receiving a container starting request, obtaining formatting parameters of block equipment to be mounted;
Determining the format attribute of the target file system of the block equipment to be mounted according to the formatting parameters;
And when the format attribute of the target file system meets a first preset condition, formatting the block equipment to be mounted, and mounting the formatted block equipment to be mounted into a target container in a starting state.
Optionally, the determining, according to the formatting parameter, a format attribute of the target file system of the block device to be mounted includes:
acquiring the format attribute of an initial file system of the block equipment to be mounted;
determining target attribute prefix words according to the formatting parameters;
and taking the target attribute prefix word as the prefix of the initial file system format attribute to obtain the target file system format attribute of the block equipment to be mounted.
Optionally, the formatting the block to be mounted device includes:
determining a target file system type according to the target file system format attribute;
Determining a target formatting tool according to the type of the target file system; the target formatting tool is used for formatting the file system of the block to be mounted device into the target file system type;
And formatting the block equipment to be mounted by using the target formatting tool.
Optionally, the determining that the target file system format attribute meets a first preset condition includes:
determining that an attribute prefix word in the target file system format attribute meets a first sub-condition;
Or alternatively
And determining that the attribute prefix word in the target file system format attribute meets a second sub-condition, and determining that the file system of the block to be mounted equipment meets a third sub-condition.
Optionally, the obtaining the formatting parameter of the block to be mounted device includes:
acquiring a configuration file of the block equipment to be mounted;
and analyzing the configuration file of the block equipment to be mounted to obtain formatting parameters of the block equipment to be mounted.
Optionally, the method further comprises:
and when the format attribute of the target file system meets a second preset condition, mounting the block equipment to be mounted into a target container in a starting state.
Optionally, the determining that the target file system format attribute meets a second preset condition includes:
determining that an attribute prefix word in the format attribute of the target file system meets a second sub-condition, and determining that a file system of the block to be mounted equipment meets a fourth sub-condition;
Or alternatively
And determining that the attribute prefix word in the target file system format attribute meets a fifth sub-condition.
The foregoing is related to the device 500 provided in the embodiment of the present application.
Based on the formatting method provided by the method embodiment, the embodiment of the application also provides a computer readable storage medium.
Media embodiment
For technical details of the computer-readable storage medium provided in the medium embodiment, please refer to the method embodiment.
The present application provides a computer readable storage medium for storing a computer program for executing any one of the formatting methods provided by the above method embodiments. That is, the computer program is for performing the steps of:
After receiving a container starting request, obtaining formatting parameters of block equipment to be mounted;
Determining the format attribute of the target file system of the block equipment to be mounted according to the formatting parameters;
And when the format attribute of the target file system meets a first preset condition, formatting the block equipment to be mounted, and mounting the formatted block equipment to be mounted into a target container in a starting state.
Optionally, the determining, according to the formatting parameter, a format attribute of the target file system of the block device to be mounted includes:
acquiring the format attribute of an initial file system of the block equipment to be mounted;
determining target attribute prefix words according to the formatting parameters;
and taking the target attribute prefix word as the prefix of the initial file system format attribute to obtain the target file system format attribute of the block equipment to be mounted.
Optionally, the formatting the block to be mounted device includes:
determining a target file system type according to the target file system format attribute;
Determining a target formatting tool according to the type of the target file system; the target formatting tool is used for formatting the file system of the block to be mounted device into the target file system type;
And formatting the block equipment to be mounted by using the target formatting tool.
Optionally, the determining that the target file system format attribute meets a first preset condition includes:
determining that an attribute prefix word in the target file system format attribute meets a first sub-condition;
Or alternatively
And determining that the attribute prefix word in the target file system format attribute meets a second sub-condition, and determining that the file system of the block to be mounted equipment meets a third sub-condition.
Optionally, the obtaining the formatting parameter of the block to be mounted device includes:
acquiring a configuration file of the block equipment to be mounted;
and analyzing the configuration file of the block equipment to be mounted to obtain formatting parameters of the block equipment to be mounted.
Optionally, the method further comprises:
and when the format attribute of the target file system meets a second preset condition, mounting the block equipment to be mounted into a target container in a starting state.
Optionally, the determining that the target file system format attribute meets a second preset condition includes:
determining that an attribute prefix word in the format attribute of the target file system meets a second sub-condition, and determining that a file system of the block to be mounted equipment meets a fourth sub-condition;
Or alternatively
And determining that the attribute prefix word in the target file system format attribute meets a fifth sub-condition.
The above is related content of a computer readable storage medium provided by an embodiment of the present application.
It should be understood that in the present application, "at least one (item)" means one or more, and "a plurality" means two or more. "and/or" for describing the association relationship of the association object, the representation may have three relationships, for example, "a and/or B" may represent: only a, only B and both a and B are present, wherein a, B may be singular or plural. The character "/" generally indicates that the context-dependent object is an "or" relationship. "at least one of" or the like means any combination of these items, including any combination of single item(s) or plural items(s). For example, at least one (one) of a, b or c may represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", wherein a, b, c may be single or plural.
The above description is only of the preferred embodiment of the present invention, and is not intended to limit the present invention in any way. While the invention has been described with reference to preferred embodiments, it is not intended to be limiting. Any person skilled in the art can make many possible variations and modifications to the technical solution of the present invention or modifications to equivalent embodiments using the methods and technical contents disclosed above, without departing from the scope of the technical solution of the present invention. Therefore, any simple modification, equivalent variation and modification of the above embodiments according to the technical substance of the present invention still fall within the scope of the technical solution of the present invention.