Space allocation method and device of mirror file, server and storage medium
By forcibly inserting physical space pre-allocation during image file creation and expansion operations, the problem of image file logical size exceeding physical storage space in cloud computing platforms is solved, the consistency between image file and physical storage space is achieved, disk over-allocation is avoided, and the utilization rate of host disk is improved.
Patent Information
- Application Number
- CN202611399120.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-09
- Publication Date
- 2026-11-10
AI Technical Summary
In cloud computing platforms, due to the streamlined configuration of QCOW2 image files, the sum of the logical sizes of the system disks of all virtual machines on the host machine may far exceed the actual available physical storage space capacity of the host machine's disk. This can cause the scheduler to be unable to accurately perceive the disk usage and may continue to schedule new virtual machines, resulting in the disk being over-allocated.
By intercepting the workflow of image file creation and expansion, and forcibly inserting pre-allocation of physical space, the physical storage space of the image file is ensured to be consistent with its logical size, thus avoiding excessive disk allocation.
This ensures that the scheduler can schedule based on accurate physical disk usage, avoiding over-allocation of disks and improving host disk utilization.
Smart Images

Figure CN123067996A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of cloud computing technology, and in particular to a method, apparatus, server, and storage medium for allocating space for image files. Background Technology
[0002] In cloud computing platforms, virtual machine system disks are typically stored using QCOW2 (QEMU Copy On Write) format image files. QCOW2 image files have a thin provisioning feature, gradually allocating physical storage space on the disk as the virtual machine actually writes data, which can improve the utilization of the host machine's disk.
[0003] However, the combined logical size of the system disks of all virtual machines on the host machine may far exceed the actual usable physical storage capacity of the host machine's disk. Due to the thin provisioning nature of these image files, their initial space occupation is very small. Therefore, the scheduler cannot perceive the true disk usage and may continue to schedule new virtual machines to the host machine, leading to over-allocation of the host machine's disk. Summary of the Invention
[0004] To address the aforementioned technical issues, this disclosure provides a method, apparatus, server, and storage medium for allocating space for image files.
[0005] A first aspect of this disclosure provides a method for allocating space for an image file, including: In response to the completion of the operation command, the workflow corresponding to the operation command is intercepted. The operation command is used to change the logical size of the image file, and the workflow is used to make the execution result of the operation command take effect. Allocate physical storage space for the image file that is consistent with the logical size of the modified target; Specifically, when the operation command is a creation command for an image file, in response to the completion of the operation command, the workflow corresponding to the operation command is intercepted, including: in response to the completion of the creation of the image file corresponding to the creation command, the virtual machine instantiation operation corresponding to the image file is intercepted; When the operation command is an expansion command, in response to the completion of the operation command execution, the workflow corresponding to the operation command is intercepted, including: in response to the completion of the logical size expansion of the image file corresponding to the expansion command, the disk expansion process corresponding to the expansion command is intercepted.
[0006] A second aspect of this disclosure provides a space allocation device for an image file, comprising: The intercept module is used to intercept the workflow corresponding to the operation command in response to the completion of the operation command. The operation command is used to change the logical size of the image file, and the workflow is used to make the execution result of the operation command take effect. The allocation module is used to allocate physical storage space to the image file that is consistent with the logical size of the changed target. Specifically, the interception module is used to intercept the virtual machine instantiation operation corresponding to the image file when the operation command is a creation command for the image file, in response to the completion of the creation of the image file corresponding to the creation command; and to intercept the disk expansion process corresponding to the expansion command when the operation command is an expansion command, in response to the completion of the logical size expansion of the image file corresponding to the expansion command.
[0007] A third aspect of this disclosure provides a server, including: processor; Memory, used to store executable instructions; The processor is used to read executable instructions from memory and execute the executable instructions to implement the space allocation method for the image file provided in the first aspect above.
[0008] A fourth aspect of this disclosure provides a computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to implement the space allocation method for the image file provided in the first aspect.
[0009] The technical solution provided in this disclosure has the following advantages compared with the prior art: The image file space allocation method, apparatus, server, and storage medium provided in this disclosure pre-allocate physical space by forcibly inserting and completing the pre-allocation of physical space in the workflow of operations involving changes in image file size, such as image creation and expansion. This ensures that the newly created or expanded system disk image has physical space equal to its logical size, thereby ensuring that the scheduler can subsequently schedule based on accurate disk physical occupancy and avoid over-allocation of the disk. Attached Figure Description
[0010] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0011] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 A flowchart illustrating a space allocation method for an image file provided in this embodiment of the disclosure; Figure 2 A flowchart illustrating a space allocation method for an image file provided in another embodiment of this disclosure; Figure 3 A schematic diagram of a space allocation device for an image file provided in an embodiment of this disclosure; Figure 4 This is a schematic diagram of the structure of a server provided in an embodiment of the present disclosure. Detailed Implementation
[0013] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.
[0014] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.
[0015] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.
[0016] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0017] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".
[0018] This disclosure provides a method for allocating space for an image file, which will be described below with reference to specific embodiments.
[0019] Figure 1This flowchart illustrates a method for allocating space for an image file, as provided in this embodiment. This method can be executed by an image file space allocation device, which can be implemented in software and / or hardware. The image file space allocation device can be configured in a server or terminal of a cloud computing platform. The cloud computing platform is a virtualization platform based on a Quick Emulator (QEMU) and a kernel-based Virtual Machine (KVM).
[0020] It is understood that the space allocation method for image files provided in this disclosure can also be applied in other scenarios.
[0021] The following is about Figure 1 The space allocation method for the image file shown will be introduced. For example... Figure 1 As shown, the space allocation method for image files provided in this embodiment includes the following steps.
[0022] S101. In response to the completion of the operation command, intercept the workflow corresponding to the operation command.
[0023] The operation command is used to change the logical size of the image file, and the workflow is used to make the execution result of the operation command take effect.
[0024] In cloud computing platforms, the system disk of a virtual machine (VM) is typically stored as an image file on the local disk of the host machine (physical host). The image file is the underlying data carrier of the VM system disk, and its logical size determines the disk capacity that the VM operating system can recognize and use.
[0025] The image file is one that supports thin provisioning. In practical applications, image files can take various formats. As an example, the image file can be in QCOW2 (QEMU Copy On Write version 2) format. This format has thin provisioning characteristics, meaning that only its logical size needs to be declared at creation time, without immediately allocating an equal amount of physical storage space on the physical disk. The physical storage space is gradually allocated as the virtual machine performs actual data write operations.
[0026] Operation commands refer to commands used to change the logical size of an image file. During the lifecycle of a virtual machine, there are multiple scenarios where the logical size of the image file needs to be changed. For example, when creating a virtual machine, an image file of a corresponding logical size needs to be created based on the system disk capacity specified by the user; during virtual machine operation, when the user needs to expand the system disk capacity, an expansion operation needs to be performed on the image file. Accordingly, operation commands can include image file creation commands and expansion commands.
[0027] In practical cloud computing platforms, after an operation command is executed, it typically requires a series of follow-up processes before the changes actually take effect on the virtual machine's runtime environment. These follow-up processes can be viewed as workflows corresponding to the operation commands, and these workflows are used to make the execution results of the operation commands effective.
[0028] In this embodiment of the disclosure, after the operation command is executed and before its corresponding workflow continues to execute, an interception point is set to intercept the workflow, suspend the normal execution process of the workflow, and wait for other processing logic before entering the workflow.
[0029] S102. Allocate physical storage space for the image file that is consistent with the logical size of the changed target.
[0030] After intercepting the workflow corresponding to the operation command, that is, before the logical change result of the operation command takes effect, the server forcibly performs the physical storage space allocation operation.
[0031] Physical storage space refers to the actual usable storage blocks on the host machine's physical disk, corresponding to the logical size of the image file. Allocating physical storage space means that the server, through the operating system's underlying file operation interface, actually allocates storage blocks of a specified size on the physical disk for the image file, so that these storage blocks are reserved and dedicated to the image file.
[0032] For example, by locking a portion of physical space to prevent other files from occupying it, physical storage space can be allocated to the image file.
[0033] The target logical size refers to the logical size value of the image file after the operation commands are executed. After this step, the physical space corresponding to the image file is consistent with its logical size.
[0034] Physical storage allocation can be achieved by calling the physical space pre-allocation interface. As an example, this can be done by calling `posix_fallocate()`. `posix_fallocate()` is a file space pre-allocation function defined by the Portable Operating System Interface (POSIX) standard. After calling this function, the file system allocates actual physical disk blocks for the specified file within a specified range and ensures that subsequent write operations to that range will not fail due to insufficient disk space. Unlike `ftruncate()`, which only modifies the logical size of the file, `posix_fallocate()` guarantees that physical storage space is actually allocated, rather than merely modifying the file's metadata.
[0035] After the physical storage space is allocated, the workflow corresponding to the operation command continues to execute so that the execution result of the operation command takes effect. At this time, the image file has physical storage space equal to its logical size. Subsequent virtual machine write operations to this image file are all performed in the allocated physical storage space, without causing additional allocation of physical disk space.
[0036] One possible scenario is that when the operation command is a command to create an image file, in response to the completion of the operation command, the workflow corresponding to the operation command is intercepted, including: in response to the completion of the creation of the image file corresponding to the creation command, the virtual machine instantiation operation corresponding to the image file is intercepted.
[0037] The image file creation command is used to create new image files. In a cloud computing platform, when a user initiates a virtual machine creation request, the system will invoke the creation command to generate a corresponding image file on the host machine's local disk, based on the system disk capacity specified by the user. After the creation command is executed, the image file is created and has the specified logical size.
[0038] Virtual machine instantiation refers to the process of associating an image file with a virtual machine instance and starting the virtual machine. After the creation command is executed, the system will continue with the virtual machine instantiation operation according to the normal process, that is, using the newly created image file as the system disk of the virtual machine to complete the configuration and startup of the virtual machine.
[0039] That is, after the image file is created but before the virtual machine instantiation operation is executed, the execution of the virtual machine instantiation operation is paused, and the physical storage space allocation operation is performed. After the physical storage space allocation is completed, the virtual machine instantiation operation continues.
[0040] Accordingly, allocate physical storage space for the image file that is consistent with the changed target logical size, including: starting from the starting position corresponding to the image file, allocating physical storage space with a length matching the target logical size.
[0041] For a newly created image file, it is a completely new file on the physical disk, with an initial physical footprint of zero or a very small value. The starting position of the image file refers to the starting offset of the file in the physical storage space, that is, the position of the first byte of the file. Physical storage space is allocated starting from the starting position, that is, based on the interval from offset 0 to the target logical size, a complete allocation of physical storage space is performed for the image file on the physical disk.
[0042] After allocation, each logical offset of the image file corresponds to a real physical disk block, and the physical space occupied is consistent with the target logical size.
[0043] Another possible scenario is that when the operation command is an expansion command, in response to the completion of the operation command execution, the workflow corresponding to the operation command is intercepted, including: in response to the completion of the logical size expansion of the image file corresponding to the expansion command, the disk expansion process corresponding to the expansion command is intercepted.
[0044] The expansion command is used to extend the logical size of an existing image file. In cloud computing platforms, when a user needs to expand the system disk of a virtual machine due to business growth, the server will perform a logical size expansion operation on the image file based on the expansion command. After the expansion command is executed, the logical size of the image file increases from the original value to the target value, but the newly added capacity has not yet been actually allocated on the physical disk.
[0045] The disk expansion process refers to the operational procedures that make the expansion operation take effect within the virtual machine. After the expansion command is executed, the system will continue with the disk expansion process according to the normal workflow, which includes updating the virtual machine's disk configuration information and notifying the virtual machine operating system to rescan the disk capacity. Once the disk expansion process is complete, the virtual machine operating system will recognize the expanded disk capacity.
[0046] After the expansion command is executed and before the disk expansion process begins, the disk expansion process is paused, and the physical storage space allocation operation is performed instead. The disk expansion process resumes only after the physical storage space allocation is complete.
[0047] Accordingly, allocate physical storage space to the image file that is consistent with the changed target logical size. Specifically, this includes allocating new physical storage space to the image file starting from the end position of the original physical storage space corresponding to the image file.
[0048] The original physical storage space refers to the physical storage space already occupied by the image file before the expansion command is executed. For expansion operations, the image file already has a certain physical storage space occupied before expansion; for example, physical space was pre-allocated during creation according to the method of this disclosure embodiment, or a portion of physical space was gradually allocated during actual use. The end position of the original physical storage space is the offset of the end of the physical storage space allocated to the image file before expansion.
[0049] The allocation of new physical storage space begins at the end of the original physical storage space, meaning that physical storage space is allocated only for the logical size range added by the expansion operation. The sum of the original physical storage space and the newly allocated physical storage space is the target logical size. In other words, the physical footprint of the image file after expansion equals the physical footprint before expansion plus the newly allocated physical space, and the total amount equals the target logical size.
[0050] This embodiment of the disclosure forcibly inserts and completes the pre-allocation of physical space in the workflow of operations involving changes in image file size, such as image creation and expansion. This ensures that the newly created or expanded system disk image has physical space equal to its logical size, guaranteeing that the scheduler can subsequently schedule based on accurate disk physical occupancy and avoiding over-allocation of disk space. Specifically, for newly created image files, before they are used by virtual machine instantiation, a complete allocation of physical storage space starting from the beginning of the file is forcibly completed. This ensures that the system disk image file has physical storage space consistent with its logical size when the virtual machine starts, avoiding the risk of over-allocation due to thinner configuration.
[0051] For image files undergoing expansion operations, the allocation of physical storage space for the newly added capacity is forcibly completed before the disk expansion process takes effect, ensuring that the physical size of the image file after expansion is consistent with its logical size after expansion, thus avoiding the risk of over-allocation due to expansion operations.
[0052] In some embodiments, allocating physical storage space to the image file that is consistent with the changed target logical size includes: calling a disk space pre-allocation tool with the path of the image file and the target logical size as input parameters.
[0053] The disk space pre-allocation tool is a standalone tool used to perform physical storage space allocation operations. In its specific implementation, the disk space pre-allocation tool is an executable program appended to the image creation function or disk expansion function of the computing service, which then executes the operation commands.
[0054] The computing service is a service component in the cloud computing platform responsible for performing virtual machine lifecycle management operations, at least for executing the image file creation and expansion commands mentioned above. By directly embedding the disk space pre-allocation tool's call instructions into the functions within the computing service that execute image creation and disk expansion operations, the disk space pre-allocation operation can be triggered immediately after the operation commands are executed, without requiring additional scheduling or message passing processes. This ensures that the allocation of physical space can be reliably completed before the workflow takes effect.
[0055] The disk space pre-allocation tool receives externally input parameters and performs corresponding storage allocation operations. Its function is to allocate physical storage space for a specified image file based on the input file path and target size. The image file path uniquely identifies the location of the image file to be operated on within the host file system. This path allows the tool to locate the target file and open it for operation. The target logical size specifies the amount of physical storage space to be allocated; specifically, it represents the logical size of the image file after the operation command is executed, or the amount of new physical space to be allocated after expansion. In actual use, by inputting these two parameters, the disk space pre-allocation tool obtains the operation information to allocate the specified physical storage space to the specified image file.
[0056] After the disk space pre-allocation tool is invoked, it opens the image file based on the image file's path and allocates physical storage space for the image file starting from the target location corresponding to the image file. The target location includes either the starting position of the image file or the ending position of the original physical storage space.
[0057] For newly created image files, the target location is the starting position of the image file, that is, the allocation of the entire logical size range begins from the first byte of the file; for image files undergoing expansion operations, the target location is the ending position of the original physical storage space, that is, the allocation of the newly added logical size range begins from the end of the existing physical space occupied. The disk space pre-allocation tool can automatically determine the target location according to different operation scenarios.
[0058] The physical space pre-allocation interface is a standard programming interface defined in the operating system's file management subsystem. It is used to issue physical storage space allocation requests to the file system. This interface provides a function to bind a file's logical address range to physical disk blocks, allowing the caller to request the file system to actually allocate physical storage resources for a specific range of a specified file. Unlike operations that only modify the logical size field in the file's metadata, the physical space pre-allocation interface requires the file system to complete a series of low-level operations, such as finding, allocating, and mapping physical disk blocks, before the call returns.
[0059] After the physical space pre-allocation interface is invoked, the file system determines the target range of physical storage space to be allocated based on the starting offset and space length passed to the interface. Within this target range, the file system allocates physical disk blocks one by one for the image file and establishes a mapping relationship between these physical disk blocks and the corresponding logical offsets of the image file. During the allocation process, the file system ensures that the allocated physical disk blocks are actual and usable storage resources.
[0060] The return value of the physical space pre-allocation interface directly indicates whether the allocation operation has been successfully completed, and the physical storage status of the target interval after the allocation operation. Specifically, when the interface call succeeds and returns a success value, this return value indicates that physical disk blocks of the aforementioned target logical size, starting from the target location, have been actually allocated. This means that when the caller receives a success return value, it means that every logical offset of the image file within the specified interval corresponds to a real physical disk block.
[0061] It should be noted that the semantics of the above return values differ from those of interfaces that only modify the logical size of a file (such as ftruncate). For interfaces that only modify the logical size, a successful return value only indicates that the file's metadata information has been updated, and does not indicate that physical disk blocks have been allocated. When subsequent write operations occur, the file system allocates physical disk blocks on demand according to the logical size of the file, which may lead to write failure due to insufficient physical disk space. However, for the physical space pre-allocation interface used in this embodiment, its successful return value indicates the fact that physical disk blocks have been actually allocated.
[0062] This embodiment of the disclosure achieves modularity and reusability of physical space allocation operations by setting and calling a disk space pre-allocation tool to allocate physical storage space for image files. This allows creation and expansion scenarios to share the same allocation logic, reduces system maintenance costs, and ensures consistency and reliability of allocation behavior in each allocation scenario.
[0063] In addition, the embodiments of this disclosure perform physical storage space allocation by calling the physical space pre-allocation interface, which ensures that the successful return value of the allocation operation has clear semantics of physical space allocation. The disk space pre-allocation tool does not need to perform additional space verification operations after allocation is completed, and also avoids the situation of insufficient physical space during subsequent writing.
[0064] In some embodiments, a permission acquisition step is required before invoking the disk space pre-allocation tool. Specifically, this involves obtaining the target permissions necessary to execute the disk space pre-allocation tool based on a security privilege escalation framework.
[0065] In the architecture of a cloud computing platform, various service components typically run with ordinary user privileges to follow the principle of least privilege and reduce security risks.
[0066] Disk space pre-allocation involves the direct allocation of physical disk storage space, which requires low-level operating system permissions, typically root privileges. Therefore, when invoking a disk space pre-allocation tool, the initiator (e.g., a computing service component within a server) may not have sufficient running permissions to execute the tool.
[0067] A secure privilege escalation framework is a security mechanism used to temporarily elevate the execution privileges of specific commands under controlled conditions. Within a secure privilege escalation framework, a pre-configured filtering configuration file defines the filtering rules for various commands that are allowed to be executed.
[0068] Each command filtering rule in the filtering configuration file corresponds to a command that is authorized to be executed by the framework. The rule content includes information such as the command path and the required permission level. When a command invocation needs to be executed through the security privilege escalation framework, the framework checks whether the path of the invocation command matches a command filtering rule in the filtering configuration file. If they match, the framework grants the initiator of the invocation command the target permissions declared in that rule.
[0069] In this embodiment of the disclosure, the security privilege escalation framework's filtering configuration file contains command filtering rules corresponding to the disk space pre-allocation tool. These command filtering rules declare the absolute path of the disk space pre-allocation tool and the permission level required to execute it (e.g., root privileges). When the disk space pre-allocation tool is invoked, the invocation command undergoes a permission check by the security privilege escalation framework. Since the filtering configuration file already contains the command filtering rules corresponding to this tool, and the path of the invocation command matches the path in the rules, the security privilege escalation framework temporarily grants the initiator of the invocation command the target permissions (i.e., root privileges), enabling the disk space pre-allocation tool to be successfully executed under conditions of sufficient permissions.
[0070] This disclosed embodiment achieves secure privilege escalation execution of the disk space pre-allocation tool while ensuring operational security. It does not require the calling component to run directly with root privileges, which complies with the security and compliance requirements of the cloud platform. At the same time, it ensures that the physical storage space allocation operation can be executed smoothly.
[0071] Figure 2 A flowchart illustrating a space allocation method for an image file provided in another embodiment of this disclosure. (See flowchart for example.) Figure 2 As shown, the method includes the following steps.
[0072] S201. Configure secure execution permissions for disk pre-allocation commands.
[0073] In the OpenStack Nova rootwrap security filtering configuration file, command filtering rules for the disk pre-allocation tool are registered, allowing the Nova compute service to securely perform disk pre-allocation operations with root privileges.
[0074] Specifically, add the command filtering rule "truncate-disk:CommandFilter, / vm_data / openstack / nova / truncate-disk,root" to the compute.filters configuration file. This rule declares the absolute path of the truncate-disk tool (disk pre-allocation tool) and the required permission level, ensuring that Nova can securely escalate privileges through the rootwrap mechanism when it needs root privileges to perform disk pre-allocation.
[0075] Then, proceed to S202 or S203.
[0076] S202. Force pre-allocation of physical space when creating a disk image file.
[0077] In the virtual machine disk image creation process, after the qemu-img create command completes the logical creation of the image file, it immediately calls the disk pre-allocation tool to perform physical space pre-allocation on the image file.
[0078] Specifically, in the `create_image()` function of the Nova virtualization layer (nova / virt / libvirt / utils.py), after the `qemu-img create` command has finished executing, add the following operation: processutils.execute('truncate-disk', path, disk_size, run_as_root=True, root_helper=utils.get_root_helper()) Where path is the path to the image file, disk_size is the logical size of the image file, run_as_root=True and root_helper=utils.get_root_helper() ensure that the command is executed with root privileges through the rootwrap mechanism.
[0079] The disk pre-allocation tool receives command-line arguments to obtain the image file path and logical size. It then calls the `open()` system call to open the target file and invokes the physical space pre-allocation interface, specifically the `posix_fallocate()` system call, to perform physical space pre-allocation on the target file, starting from offset 0 and covering a range of length `disk_size`. If pre-allocation is successful, a success message is output; otherwise, an error code and error message are output for troubleshooting purposes.
[0080] The posix_fallocate() function ensures that the underlying file system allocates actual physical disk blocks for the specified range, rather than simply modifying the file's logical size metadata.
[0081] S203. Force pre-allocation of incremental space when expanding disk capacity.
[0082] In the virtual machine disk expansion process, after the qemu-img resize command completes the logical size expansion of the image file, it immediately calls the disk pre-allocation tool to perform physical space pre-allocation on the expanded image file.
[0083] Specifically, in the extend() function of the Nova disk management module (nova / virt / disk / api.py), after the qemu-img resize command has finished executing, add the following operation: processutils.execute('truncate-disk', image.path, '%s' % size, run_as_root=True, root_helper=utils.get_root_helper()) Here, image.path is the path to the expanded image file, and size is the logical size (in bytes) after expansion, ensuring that the incremental space after expansion is also physically pre-allocated.
[0084] The disk pre-allocation tool receives command-line arguments, obtains the image file path and logical size, calls the `open()` system call to open the target file, and calls the `posix_fallocate()` system call to perform physical space pre-allocation on the target file, starting from the end position of the physical storage space before expansion. The total length of the allocated physical storage space is `size`. If the pre-allocation is successful, a success message is output; if it fails, an error code and error message are output for troubleshooting purposes.
[0085] This embodiment of the disclosure forcibly inserts and completes the pre-allocation of physical space in the workflow of operations involving changes in image file size, such as image creation and expansion. This ensures that the newly created or expanded system disk image has physical space equal to its logical size, thereby ensuring that the scheduler can subsequently schedule based on accurate disk physical occupancy and avoid over-allocation of the disk.
[0086] Figure 3 This is a schematic diagram of a space allocation device for an image file provided in an embodiment of this disclosure. Figure 3 As shown, the space allocation device 30 for the image file may include an interception module 31 and an allocation module 32; wherein, the interception module 31 is used to intercept the workflow corresponding to the operation command in response to the completion of the operation command execution, the operation command is used to change the logical size of the image file, and the workflow is used to make the execution result of the operation command take effect; the allocation module 32 is used to allocate physical storage space for the image file that is consistent with the changed target logical size.
[0087] Specifically, the interception module 31 is used to intercept the virtual machine instantiation operation corresponding to the image file when the operation command is the image file creation command, in response to the completion of the image file creation corresponding to the creation command; and to intercept the disk expansion process corresponding to the expansion command when the operation command is the expansion command, in response to the completion of the logical size expansion of the image file corresponding to the expansion command.
[0088] In some embodiments, when the operation command is a command to create an image file, the allocation module 32 is used to allocate physical storage space with a length matching the target logical size, starting from the starting position corresponding to the image file.
[0089] In some embodiments, when the operation command is an expansion command, the allocation module 32 is used to allocate new physical storage space to the image file starting from the end position of the original physical storage space corresponding to the image file, and the sum of the original physical storage space and the new physical storage space is the target logical size.
[0090] In some embodiments, the allocation module 32 is used to call a disk space pre-allocation tool with the path of the image file and the target logical size as input parameters. The disk space pre-allocation tool is used to open the image file based on the path and allocate physical storage space for the image file starting from the target location corresponding to the image file. The disk space pre-allocation tool is an executable program appended to the image creation function or disk expansion function of the computing service, and the computing service is used to execute operation commands. The target location includes the starting location corresponding to the image file or the ending location of the original physical storage space.
[0091] In some embodiments, the disk space pre-allocation tool is used to call the physical space pre-allocation interface to allocate physical storage space for the image file starting from the target location corresponding to the image file. When the physical space pre-allocation interface returns a return value indicating that the operation was successful, the return value indicates that a physical disk block with a size of the target logical size has been allocated, starting from the target location.
[0092] In some embodiments, the space allocation device 30 for image files further includes a privilege escalation module for obtaining the target permissions required to execute the disk space pre-allocation tool based on a security privilege escalation framework. The security privilege escalation framework's filter configuration file contains command filtering rules corresponding to the disk space pre-allocation tool. The command filtering rules are used to grant the target permissions to the initiator of the command when the path of the command that invokes the disk space pre-allocation tool belongs to the path in the command filtering rules.
[0093] In some embodiments, the image file is an image file that supports simplified configuration.
[0094] It should be noted that, Figure 3 The space allocation device 30 for the image file shown can execute the various steps in the above method embodiments and realize the various processes and effects in the above method embodiments, which will not be elaborated here.
[0095] Figure 4 This is a schematic diagram of the structure of a server provided in an embodiment of the present disclosure.
[0096] like Figure 4 As shown, the server may include a processor 410 and a memory 420 storing computer program instructions.
[0097] Specifically, the processor 410 may include a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this disclosure.
[0098] Memory 420 may include a large-capacity storage device for information or instructions. For example, and not limitingly, memory 420 may include a hard disk drive (HDD), a floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or a Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, memory 420 may include removable or non-removable (or fixed) media. Where appropriate, memory 420 may be internal or external to the integrated gateway device. In a particular embodiment, memory 420 is a non-volatile solid-state memory. In a particular embodiment, memory 420 includes read-only memory (ROM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (Electrically Programmable ROM, EPROM), an electrically erasable programmable PROM (EEPROM), an electrically alterable ROM (EAROM), or flash memory, or a combination of two or more of these.
[0099] The processor 410 reads and executes computer program instructions stored in the memory 420 to perform the steps of the space allocation method for the image file provided in this embodiment of the disclosure.
[0100] In one example, the server may also include a transceiver 430 and a bus 440. Wherein, as... Figure 4 As shown, the processor 410, memory 420 and transceiver 430 are connected via bus 440 and communicate with each other.
[0101] Bus 440 may include hardware, software, or both. For example, and not limitingly, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industrial Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a MicroChannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses, or a combination of two or more of these. Where appropriate, bus 440 may include one or more buses.
[0102] This disclosure also provides a computer-readable storage medium that can store a computer program. When the computer program is executed by a processor, the processor enables the processor to implement the space allocation method for image files provided in this disclosure.
[0103] The aforementioned storage medium may include, for example, a memory 420 containing computer program instructions, which can be executed by the server's processor 410 to complete the image file space allocation method provided in this embodiment. Optionally, the storage medium may be a non-transitory computer-readable storage medium, such as a ROM, random access memory (RAM), compact disc ROM (CD-ROM), magnetic tape, floppy disk, and optical data storage device.
[0104] This disclosure also provides a vehicle that includes a server, which can implement the various processes and effects described in the above embodiments of this disclosure, which will not be elaborated here.
[0105] This disclosure also provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are executed by a processor, they implement the space allocation method for image files provided in this disclosure and can achieve the various processes and effects described in the above embodiments of this disclosure, which will not be elaborated here.
[0106] The above description is merely a specific embodiment of this disclosure, enabling those skilled in the art to understand or implement it. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for allocating space for an image file, characterized in that, include: In response to the completion of the operation command, the workflow corresponding to the operation command is intercepted. The operation command is used to change the logical size of the image file, and the workflow is used to make the execution result of the operation command take effect. Allocate physical storage space for the image file that is consistent with the changed target logical size; Wherein, when the operation command is a creation command for an image file, the step of intercepting the workflow corresponding to the operation command in response to the completion of the operation command includes: intercepting the virtual machine instantiation operation corresponding to the image file in response to the completion of the creation of the image file corresponding to the creation command; When the operation command is an expansion command, the step of intercepting the workflow corresponding to the operation command in response to the completion of the operation command includes: intercepting the disk expansion process corresponding to the expansion command in response to the completion of the logical size expansion of the image file corresponding to the expansion command.
2. The method according to claim 1, characterized in that, When the operation command is a command to create an image file, allocating physical storage space to the image file that is consistent with the changed target logical size includes: Starting from the beginning position corresponding to the image file, allocate physical storage space with a length matching the target logical size.
3. The method according to claim 1, characterized in that, When the operation command is an expansion command, allocating physical storage space to the image file that is consistent with the changed target logical size includes: Starting from the end of the original physical storage space corresponding to the image file, new physical storage space is allocated to the image file, and the sum of the original physical storage space and the new physical storage space is the target logical size.
4. The method according to any one of claims 1-3, characterized in that, The allocation of physical storage space for the image file, which is consistent with the changed target logical size, includes: Using the path of the image file and the target logical size as input parameters, a disk space pre-allocation tool is invoked. This tool is used to open the image file based on the path and allocate physical storage space for the image file starting from the target location corresponding to the image file. The disk space pre-allocation tool is an executable program that is appended to the image creation function or disk expansion function of the computing service, and the computing service is used to execute the operation command; the target location includes the starting position corresponding to the image file or the ending position of the original physical storage space.
5. The method according to claim 4, characterized in that, The step of allocating physical storage space for the image file starting from the target location corresponding to the image file includes: The physical space pre-allocation interface is invoked to allocate physical storage space for the image file starting from the target location corresponding to the image file. When the physical space pre-allocation interface returns a return value indicating that the operation was successful, the return value indicates that a physical disk block with a size equal to the target logical size has been allocated, starting from the target location.
6. The method according to claim 4, characterized in that, Before invoking the disk space pre-allocation tool, the method further includes: The security privilege escalation framework is used to obtain the target permissions required to execute the disk space pre-allocation tool. The security privilege escalation framework's filter configuration file contains command filtering rules corresponding to the disk space pre-allocation tool. The command filtering rules are used to grant the target permissions to the initiator of the command when the path of the command that invokes the disk space pre-allocation tool belongs to the path in the command filtering rules.
7. The method according to any one of claims 1-3, characterized in that, The image file is one that supports simplified configuration.
8. A space allocation device for image files, characterized in that, The device includes: An interception module is used to intercept the workflow corresponding to the operation command upon completion of the operation command execution. The operation command is used to change the logical size of the image file, and the workflow is used to make the execution result of the operation command take effect. The allocation module is used to allocate physical storage space to the image file that is consistent with the changed target logical size; The interception module is used to intercept the virtual machine instantiation operation corresponding to the image file when the operation command is an image file creation command, in response to the completion of the creation of the image file corresponding to the creation command; and to intercept the disk expansion process corresponding to the expansion command when the operation command is an expansion command, in response to the completion of the logical size expansion of the image file corresponding to the expansion command.
9. A server, characterized in that, include: processor; Memory, used to store executable instructions; The processor is configured to read the executable instructions from the memory and execute the executable instructions to implement the method of any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The storage medium stores a computer program that, when executed by a processor, causes the processor to implement the method described in any one of claims 1-7.
