Method and device for changing disk allocation mode, computer equipment and storage medium

By generating target disk images and migrating data in the running state of the virtual machine, the problem of shutting down the disk allocation method in the existing technology is solved, and no impact on the disk allocation method changes are achieved.

CN119847672APending Publication Date: 2025-04-18SANGFOR TECH INC
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411841954.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-13
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

When changing the disk allocation method of virtual machines, the virtual machine needs to be shut down, affecting other running tasks.

Method used

By generating a target disk image corresponding to the source virtual disk, migrating data to the target disk image in the running state of the virtual machine, mounting the target disk image to replace the source virtual disk, and changing the disk allocation method is achieved.

Benefits of technology

No need to shut down and restart the virtual machine, avoiding the impact on other running tasks, greatly reducing the impact of changes in disk allocation methods on the operation of virtual machines.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847672A_ABST
    Figure CN119847672A_ABST
Patent Text Reader

Abstract

The invention discloses a disk allocation mode changing method and device, computer equipment and a storage medium, and relates to the technical field of virtual machines. The method comprises the steps that a target disk mirror image corresponding to a source virtual disk is generated in response to a disk allocation mode conversion instruction, the conversion instruction comprises a target disk allocation mode, and the target disk allocation mode is different from the disk allocation mode of the source virtual disk; migrating data in the source virtual disk to the target disk mirror image, wherein the source virtual disk keeps working in the migration process; the target disk mirror image is mounted, a corresponding target virtual disk is generated to replace the source virtual disk, and the target virtual disk adopts the target disk distribution mode. Therefore, the virtual machine does not need to be shut down and restarted, and the influence on other currently running services of the virtual machine caused by change of the disk distribution mode is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of virtual machine technology, and more specifically, to a method, device, computer equipment and storage medium for changing a disk allocation mode. Background Art

[0002] In a virtualized environment, the disk allocation method of the virtual machine can be adjusted according to actual needs to optimize storage resource utilization to meet changing business needs. Adjusting the disk allocation method according to actual needs can ensure that the virtual machine runs in the best state.

[0003] However, in the related art, the disk image allocation mode is generally changed through the disk conversion tool qemu-img convert in the virtual operating system simulator (Quick EMUlator, QEMU). However, the virtual machine must be in a shutdown state when the disk conversion attack changes the allocation mode. Obviously, the allocation mode change task affects other running tasks of the virtual machine. Summary of the invention

[0004] The present application proposes a method, device, computer equipment and storage medium for changing the disk allocation mode to improve the above-mentioned defects.

[0005] In a first aspect, an embodiment of the present application provides a method for changing a disk allocation mode, the method comprising: in response to a disk allocation mode conversion instruction, generating a target disk image corresponding to a source virtual disk, the conversion instruction comprising a target disk allocation mode, the target disk allocation mode being different from the disk allocation mode of the source virtual disk; migrating data in the source virtual disk to the target disk image, the source virtual disk remaining operational during the migration process; mounting the target disk image to generate a corresponding target virtual disk to replace the source virtual disk, the target virtual disk adopting the target disk allocation mode.

[0006] In the second aspect, an embodiment of the present application provides a device for changing a disk allocation mode, the device comprising: a disk image creation module, for generating a target disk image corresponding to a source virtual disk in response to a disk allocation mode conversion instruction, the conversion instruction comprising a target disk allocation mode, the target disk allocation mode being different from the disk allocation mode of the source virtual disk; a data migration module, for migrating data in the source virtual disk to the target disk image, the source virtual disk remaining operational during the migration process; a change module, for mounting the target disk image, generating a corresponding target virtual disk to replace the source virtual disk, the target virtual disk adopting the target disk allocation mode.

[0007] In a third aspect, an embodiment of the present application further provides a computer device, comprising: one or more processors; a memory; and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the above-mentioned method.

[0008] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, in which a program code is stored, and the program code can be called by a processor to execute the above method.

[0009] In the solution provided by the present application, in response to a conversion instruction of a disk allocation mode, a target disk image corresponding to a source virtual disk is generated, the conversion instruction includes a target disk allocation mode, and the target disk allocation mode is different from the disk allocation mode of the source virtual disk; the data in the source virtual disk is migrated to the target disk image, and the source virtual disk remains working during the migration process; the target disk image is mounted to generate a corresponding target virtual disk to replace the source virtual disk, and the target virtual disk adopts the target disk allocation mode. In other words, by creating a target disk image of the target disk allocation mode, and migrating the data in the source virtual disk to the target disk image by hot migration, the synchronization of the disk image is completed, and then the primary disk mapping of the virtual machine is switched to the target disk image; in this way, there is no need to shut down and restart the virtual machine, avoiding the impact of the change in the disk allocation mode on other businesses currently running on the virtual machine, that is, greatly reducing the impact on other businesses currently running on the virtual machine. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0011] Figure 1 A flowchart of a method for changing a disk allocation mode provided in an embodiment of the present application is shown.

[0012] Figure 2 A schematic diagram of hot migration of disk data provided by an embodiment of the present application is shown.

[0013] Figure 3 A schematic flow chart of a method for changing a disk allocation mode provided in another embodiment of the present application is shown.

[0014] Figure 4 A schematic diagram of hot migration of disk data provided by another embodiment of the present application is shown.

[0015] Figure 5 It is a block diagram of a disk allocation mode changing device provided according to an embodiment of the present application.

[0016] Figure 6 It is a block diagram of a computer device according to an embodiment of the present application for executing a method for changing a disk allocation mode according to an embodiment of the present application.

[0017] Figure 7 It is a storage unit of the embodiment of the present application for storing or carrying program codes for implementing the method for changing the disk allocation method according to the embodiment of the present application. DETAILED DESCRIPTION

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

[0019] It should be noted that in some processes described in the specification, claims and the above-mentioned drawings of the present application, multiple operations that appear in a specific order are included, and these operations may not be executed or executed in parallel in the order in which they appear in this article. The sequence numbers of operations such as S110, S120, etc. are only used to distinguish different operations, and the sequence numbers themselves do not represent any execution order. In addition, these processes may include more or less operations, and these operations may be executed in sequence or in parallel. And, the terms "first", "second", etc. in the specification, claims and the above-mentioned drawings of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described here can be implemented in an order other than those illustrated or described here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or server that includes a series of steps or sub-modules is not necessarily limited to those steps or sub-modules explicitly listed, but may include other steps or sub-modules that are not explicitly listed or that are inherent to these processes, methods, products, or devices.

[0020] The inventor proposes a method, device, computer equipment and storage medium for changing the disk allocation mode. The method for changing the disk allocation mode provided in the embodiment of the present application is described in detail below.

[0021] Please refer to Figure 1 , Figure 1 A flowchart of a method for changing a disk allocation method provided in an embodiment of the present application is provided below. Figure 1 The method for changing the disk allocation mode provided in the embodiment of the present application is described in detail. The method for changing the disk allocation mode may include the following steps:

[0022] Step S101: generating a target disk image corresponding to a source virtual disk in response to a disk allocation mode conversion instruction, wherein the conversion instruction includes a target disk allocation mode, and the target disk allocation mode is different from the disk allocation mode of the source virtual disk.

[0023] In this embodiment, a virtual machine refers to one or more virtual computers that can be simulated on a physical computer through virtual machine software, and these virtual machines can work like real computers. Operating systems and applications can be installed on the virtual machines, and the virtual machines can also access network resources; among them, the physical computer is a physical device.

[0024] Disk allocation refers to the way to allocate and manage the disk space of virtual machines in a virtualized environment. Common virtual machine disk allocation methods include thin allocation, dynamic allocation, and pre-allocation.

[0025] Thin Provisioning is a virtual machine disk allocation method that allows administrators to allocate only a small amount of physical storage space when creating a virtual machine, rather than immediately allocating the entire disk capacity. The virtual machine will dynamically request additional space from the physical storage device when more space is needed. This method saves the most storage space, has the fastest allocation speed, and improves flexibility, but may have a certain impact on performance.

[0026] Dynamic Allocation is a virtual machine disk allocation method that allows the virtual machine to dynamically increase or decrease disk space while it is running. The virtual machine can dynamically request more space from the virtual disk as needed, or release space that is no longer needed. This method can improve flexibility and efficiency, but it also requires certain management and monitoring.

[0027] Eager Provisioning is a virtual machine disk allocation method that immediately allocates the entire disk capacity to the virtual machine when it is created, even if the virtual machine does not actually use the space. This method can improve performance because the virtual machine does not need to dynamically allocate space at runtime, but it will occupy more physical storage space, and the allocation speed of this method is slower than dynamic allocation.

[0028] It should be noted that the disk images mentioned in this application are all additional storage devices simulated in the computer system based on virtual disk technology, and these devices do not exist physically. Virtual disks use the computer's memory to simulate the function of a hard disk drive, thereby speeding up the reading and writing of data. By creating a virtual disk in memory, the speed of data exchange can be as fast as possible, thereby improving the operating efficiency of the virtual machine.

[0029] Based on this, the initial disk allocation mode of the virtual disk in the virtual machine is generally a thin allocation mode by default, but since the thin allocation mode only allocates a small amount of physical storage space, which is not enough, the allocation mode of the virtual disk can be changed at this time, for example, it can be changed to a dynamic allocation mode or a pre-allocation mode. Specifically, when the virtual machine is in a running state, the virtual machine can be used to respond to the conversion instruction of the disk allocation mode and generate a target disk image corresponding to the source virtual disk. The conversion instruction includes a target disk allocation mode, and the target disk allocation mode is different from the disk allocation mode of the source virtual disk. Among them, the conversion instruction of the disk allocation mode can be issued by a server, and the server can be a local server or a remote server. Preferably, the server can be deployed in the cloud, and the virtual machine is deployed locally. The server can connect to multiple virtual machines. The server is used to receive the performance indicators of the virtual machine and support the management of the virtual machine. Optionally, the conversion instruction of the disk allocation mode can also be issued locally by the user at the terminal where the virtual machine is located. Optionally, the aforementioned server can specifically be a hyperconvergence infrastructure (HCI). Optionally, the server can also specifically be a cloud management platform. Among them, the conversion instruction includes at least the following parameters: target virtual machine (when issued by the server), target disk and target disk allocation method. It should be noted that the parameters contained in the conversion instruction can be configured manually or automatically by the issuing side (server or local terminal where the virtual machine is located) according to business needs, and this embodiment does not limit this. The target disk allocation method can be understood as the required disk allocation method. Correspondingly, the computer device can respond to the disk creation instruction and use the tool qemu-img of the QEMU virtualization software package to create an empty virtual disk. It should be noted that the target disk image has the same disk space size as the source virtual disk, and the disk format is also the same. Among them, the source virtual disk includes the disk data in the virtual machine; qemu-img (disk image format conversion tool) is a special tool that can create, convert and modify virtual disks.

[0030] Optionally, the disk space and disk format of the target disk image can be selected by the user according to the disk space and disk format of the source virtual disk. Optionally, the disk space and disk format of the target disk image can also be automatically determined by the computer device according to the disk space and disk format of the original disk image selected by the user after the user inputs the disk creation instruction, and this embodiment does not limit this.

[0031] Step S102: Migrate the data in the source virtual disk to the target disk image, and the source virtual disk keeps working during the migration process.

[0032] Furthermore, when the virtual machine is still in the running state, the disk image migration is performed through the drive_mirror command in QEMU. In other words, the computer device can migrate the data in the source virtual disk to the target disk image.

[0033] For example, see Figure 2 , the virtual machine originally includes 3 source virtual disks, namely Figure 2 In the vdisk1, vdisk2 and vdisk3, the disk allocation mode of the source virtual disk vdisk1 is thin allocation, the disk allocation mode of the source virtual disk vdisk2 is dynamic allocation, and the disk allocation mode of the source virtual disk vdisk3 is pre-allocation. At this time, if the disk allocation modes of the source virtual disk vdisk1 and the source virtual disk vdisk2 need to be changed, a target disk mirror vdisk1' of the source virtual disk vdisk1 can be created, and the disk allocation mode of the target disk mirror vdisk1' can be set to dynamic allocation; and a target disk mirror vdisk2' of the source virtual disk vdisk2 can be created, and the disk allocation mode of the target disk mirror vdisk2' can be set to pre-allocation. Then, the data in the source virtual disk vdisk1 is hot migrated to the target disk mirror vdisk1' through the drive_mirror command in QEMU, and the data in the source virtual disk vdisk2 is hot migrated to the target disk mirror vdisk2' through the drive_mirror command in QEMU.

[0034] It should be noted that in the process of copying data in the source virtual disk to the target disk image, the ongoing task in the virtual machine is still reading data in the source virtual disk; obviously, data copying will not affect other ongoing tasks in the virtual machine, and data reading and data copying in the source virtual disk are performed simultaneously. Even if part of the data in the source virtual disk is changed during the data reading process, the changed part of the data can also be synchronized to the target disk image, thereby ensuring the consistency of the data migrated from the source virtual disk to the target disk image.

[0035] In some embodiments, when migrating data in the source virtual disk, the update accuracy of the task is monitored; if it is monitored that the migration time of migrating the data in the source virtual disk to the target disk image is greater than the preset time, the target prompt information is output. Based on this, the user can learn from the target prompt information that the hot migration process of the data in the source virtual disk takes too long, and can enter a migration cancellation instruction; correspondingly, the computer device can stop the migration process of the data in the source virtual disk in response to the migration cancellation instruction input based on the target prompt information. In other words, during the hot migration of data, the present application supports the cancellation of the ongoing hot migration task of data, thereby avoiding the occurrence of problems such as the impact on other tasks in the virtual machine due to the long time spent on data migration.

[0036] In this way, after stopping the migration of data in the source virtual disk, the user can continue to start the process of migrating the data of the source virtual disk to the target disk image during the maintenance window of the virtual machine or during the idle time period of the virtual machine, thereby reducing the impact on the virtual machine production environment and other tasks. For example, when backing up the entire virtual machine, the migration of data in the original disk image can be stopped to avoid affecting the entire virtual machine backup process.

[0037] In some other implementations, if the migration time of the data in the source virtual disk to the target disk image is longer than a preset time, the copying process of the data in the source virtual disk may be stopped.

[0038] Step S103: Mount the target disk image to generate a corresponding target virtual disk to replace the source virtual disk, and the target virtual disk adopts the target disk allocation method.

[0039] Understandably, after all the data in the source virtual disk is copied to the target disk image, the virtual machine needs to be adjusted from the running state to the suspended state, and then the block_job_complete command is used to switch the primary disk mapping of the virtual machine from the source virtual disk to the target disk image. Specifically, first, you need to confirm the status of the current block job related to the disk. You can use the QEMU management interface to query the status of the block job; use the query-block-jobs command or view the management interface to confirm whether the current block job has been completed, so as to ensure that all write operations have been completed and the data has been synchronized to the target disk image before switching the disk. If it is confirmed that all write operations have been completed, that is, all data has been successfully copied to the target disk image, the block_job_complete command is executed to notify QEMU to complete the block job and switch the disk mapping of the virtual machine to the new disk image. In layman's terms, the target disk image is used as the primary disk of the virtual machine, and after the switch of the primary disk mapping of the virtual machine is completed, QEMU will automatically switch the input / output (I / O) operation of the virtual machine to the target disk image. Furthermore, after the I / O operation is switched, the cont command can be used to adjust the virtual machine from the paused state to the running state, that is, to allow the virtual machine to continue to execute the previously paused task. Obviously, after all data is copied, the virtual machine only needs to be briefly adjusted to the paused state, and after the primary disk mapping is switched, the virtual machine is immediately restored to the running state. It can be seen that only the ongoing tasks of the virtual machine are temporarily suspended, and the operation of the suspended tasks in the virtual machine can be quickly resumed.

[0040] Among them, the primary disk of the virtual machine contains the installation files, system configuration, user data, etc. of the virtual machine's operating system. When creating a virtual machine, one or more virtual hard disks can be allocated to the virtual machine as primary disks to store files and data required by the operating system and applications.

[0041] In this embodiment, a target disk image of the target disk allocation method is created, and the data in the source virtual disk is migrated to the target disk image by hot migration, so as to complete the synchronization of the disk image, and then the primary disk mapping of the virtual machine is switched to the target disk image; in this way, there is no need to shut down and restart the virtual machine, and only a short time of pausing the virtual machine is required. After the primary disk mapping of the virtual machine is switched to the target disk image, the operation of the virtual machine can be quickly resumed, thereby greatly reducing the impact of the change in the disk allocation method on other businesses currently running on the virtual machine.

[0042] Please refer to Figure 3 , Figure 3A flowchart of a method for changing a disk allocation mode provided in another embodiment of the present application is shown below. Figure 3 The method for changing the disk allocation mode provided in the embodiment of the present application is described in detail. The method for changing the disk allocation mode may include the following steps:

[0043] Step S201: Create a temporary directory path for the virtual machine.

[0044] In this embodiment, in order not to affect the normal use of the virtual machine, a temporary directory path can be created for the virtual machine. The temporary directory path can be understood as a directory path for storing temporary files, that is, for storing temporary data. The files under the temporary directory path can be deleted or cleaned up at preset time intervals by setting a timing script. The preset time can be a pre-set time, for example, 7 days. Of course, the time can be adjusted and changed according to needs.

[0045] Step S202: generating a target disk image corresponding to the source virtual disk in response to a disk allocation mode conversion instruction, wherein the conversion instruction includes a target disk allocation mode, and the target disk allocation mode is different from the disk allocation mode of the source virtual disk.

[0046] In this embodiment, the specific implementation of step S202 can refer to the content of the above-mentioned embodiment, which will not be repeated here.

[0047] Step S203: Save the target disk image to the temporary directory path.

[0048] The newly created target disk image may be understood as being temporarily stored in a temporary directory path.

[0049] Step S204: Migrate the data in the source virtual disk to the target disk image, and the source virtual disk keeps working during the migration process.

[0050] Step S205: Switch the target disk image from the temporary directory path to the virtual machine directory path, and switch the source virtual disk from the virtual machine directory path to the temporary directory path.

[0051] The virtual machine directory path may be understood as a directory path for storing virtual machine configuration files, log files, and other files related to the virtual machine.

[0052] It can be understood that before step S204, that is, before completing the migration of the data in the source virtual disk, the target disk image is located under the temporary directory path, and the source virtual disk is located under the virtual machine directory path. Further, after completing the migration of the data in the source virtual disk, the target disk image under the temporary directory path can be moved to the virtual machine directory path, and the source virtual disk under the virtual machine directory path can be moved to the temporary directory path through the mv command. In other words, through the mv command, the target disk image replaces the source virtual disk.

[0053] Since the mv command only modifies the directory entry in the file system of the virtual machine, that is, the metadata information of the file, and does not modify the actual data of the file, this means that the content of the file is not copied or moved, but the location of the file in the file system is changed. Therefore, when the source virtual disk is moved, if other processes are reading or writing data in the source virtual disk, these operations will not be affected. Because the mv command only modifies the metadata of the file, it will not affect the ongoing file operations, thus avoiding the occurrence of problems such as data loss or damage in the source virtual disk.

[0054] like Figure 4 As shown, the virtual machine originally includes three source virtual disks, namely Figure 2 In vdisk1, vdisk2, and vdisk3, the disk allocation mode of the source virtual disk vdisk1 is thin allocation, the disk allocation mode of the source virtual disk vdisk2 is dynamic allocation, and the disk allocation mode of the source virtual disk vdisk3 is pre-allocation. After the disk allocation mode of the source virtual disk vdisk1 is changed to dynamic allocation, and the disk allocation mode of the source virtual disk vdisk2 is changed to pre-allocation, the source virtual disk under the virtual machine directory path will be moved to the temporary directory path for storage, and the data in the source virtual disk under the temporary directory path will be deleted at preset intervals; so that if any unforeseen errors occur within the preset time, the data in the virtual machine can be restored based on the data in the source virtual disk under the temporary directory path.

[0055] Step S206: adjusting the virtual machine from the running state to the suspended state, and mounting the target disk image to generate a corresponding target virtual disk to replace the source virtual disk, and the target virtual disk adopts the target disk allocation method.

[0056] In this embodiment, the specific implementation of step S206 can refer to the content of the above-mentioned embodiment, which will not be repeated here.

[0057] Step S207: Acquire the backup bitmap in the source virtual disk.

[0058] Step S208: Synchronize the backup bitmap to the target disk image.

[0059] The backup bitmap is a binary file used to record the changes that occur to the source virtual disk during the period from copying from the source virtual disk to the target disk image. Each bit in the binary file corresponds to a data area in the source virtual disk, and is set to 1 or 0 according to whether the source virtual disk and the target disk image are consistent in the same data area. For example, if the source virtual disk and the target disk image are in the target data area, it is 0, otherwise it is 1. Optionally, it can also be 1 if the source virtual disk and the target disk image are in the target data area, otherwise it is 0. It should be noted that the numerical assignment rules for each bit in the binary file need to be consistent.

[0060] Based on this, since the data in the backup bitmap is constantly changing during the operation of the virtual machine, in order to avoid the next full backup, it is necessary to export the backup bitmap on the source virtual disk after adjusting the virtual machine to the paused state. After the disk switch is completed, the exported backup bitmap is synchronized to the target disk image. After completion, the backup bitmap in the source virtual disk can be deleted and the cache can be cleaned up. In this way, it is ensured that the backup work can continue after the virtual machine disk is switched, and the latest data status can be correctly backed up, while also avoiding the data inconsistency problem that may occur during the backup process.

[0061] Step S209: adjusting the virtual machine from a paused state to a running state.

[0062] Step S210: Switch the memory path corresponding to the virtual machine and the target virtual disk from the temporary directory path to the virtual machine directory path.

[0063] During the drive_mirror process, the internal data structure or state of QEMU (virtual machine monitor) will change in order to point to the newly generated image path; that is, QEMU will update the path of the disk image in its memory to the image path in the temporary directory. This is because QEMU needs to know the actual location and access path of the disk image when performing disk operations. Usually, QEMU maintains some data structures internally to track the location and status of the disk image used by the virtual machine. Therefore, after drive_mirror is completed, QEMU needs to update these data structures in order to correctly access the newly generated image file; that is, by sending a command to inform QEMU that QEMU needs to update the internal image path information so that it can change from the source virtual disk in the temporary directory path to correctly point to the newly generated disk image path in the virtual machine directory (that is, the target disk image in the virtual machine directory path). In this way, QEMU can correctly access the target disk image in subsequent operations.

[0064] In this embodiment, a target disk image of the target disk allocation method is created, and the data in the source virtual disk is migrated to the target disk image by hot migration, so as to complete the synchronization of the disk image, and then the primary disk mapping of the virtual machine is switched to the target disk image; in this way, there is no need to shut down and restart the virtual machine, and only a short time of pausing the virtual machine is required. After the primary disk mapping of the virtual machine is switched to the target disk image, the operation of the virtual machine can be quickly resumed, thereby greatly reducing the impact of the change in the disk allocation method on other businesses currently running on the virtual machine.

[0065] Please refer to Figure 5 , which shows a structural block diagram of a disk allocation mode change device 300 provided in an embodiment of the present application. The device 300 may include: a disk image creation module 310, a data migration module 320 and a change module 330.

[0066] The disk image creation module 310 is used to generate a target disk image corresponding to the source virtual disk in response to a disk allocation mode conversion instruction, wherein the conversion instruction includes a target disk allocation mode, and the target disk allocation mode is different from the disk allocation mode of the source virtual disk.

[0067] The data migration module 320 is used to migrate the data in the source virtual disk to the target disk image. During the migration process, the source virtual disk keeps working.

[0068] The change module 330 is used to mount the target disk image and generate a corresponding target virtual disk to replace the source virtual disk. The target virtual disk adopts the target disk allocation method.

[0069] In some implementations, the disk allocation mode change device 300 may further include: a state adjustment module. The state adjustment module may be used to adjust the virtual machine from a running state to a suspended state before mounting the target disk image and generating a corresponding target virtual disk to replace the source virtual disk source virtual disk. The state adjustment module may also be used to adjust the virtual machine from a suspended state to a running state after mounting the target disk image and generating a corresponding target virtual disk to replace the source virtual disk source virtual disk.

[0070] In some embodiments, the disk allocation mode change device 300 may further include: a bitmap backup module and a bitmap synchronization module. The bitmap backup module may be used to obtain the backup bitmap in the source virtual disk after the virtual machine is adjusted from the running state to the suspended state. The bitmap synchronization module may be used to synchronize the backup bitmap to the target disk image after the target disk image is mounted and the corresponding target virtual disk is generated to replace the source virtual disk.

[0071] In some embodiments, the disk allocation mode change device 300 may further include: a temporary directory creation module and a path saving module. The temporary directory creation module may be used to create a temporary directory path for the virtual machine before generating a target disk image corresponding to the source virtual disk in response to the disk allocation mode conversion instruction. The path saving module may be used to save the target disk image to the temporary directory path after generating a target disk image corresponding to the source virtual disk in response to the disk allocation mode conversion instruction.

[0072] In this manner, the disk allocation mode change device 300 may further include: a path change module. The path change module may be used to switch the target disk image from the temporary directory path to the virtual machine directory path after migrating the data in the source virtual disk to the target disk image; and switch the source virtual disk from the virtual machine directory path to the temporary directory path.

[0073] In this manner, the path change module can also be specifically used to switch the memory path corresponding to the virtual machine and the target virtual disk from the temporary directory path to the virtual machine directory path after mounting the target disk image and generating a corresponding target virtual disk to replace the source virtual disk.

[0074] In some embodiments, the data migration module 320 can be specifically used to output a target prompt message if the migration time from the source virtual disk to the target disk image is greater than a preset time; and stop copying the data in the source virtual disk in response to a migration cancel instruction input based on the target prompt message.

[0075] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.

[0076] In several embodiments provided in the present application, the coupling between modules may be electrical, mechanical or other forms of coupling.

[0077] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.

[0078] In summary, when the virtual machine is in operation, in response to the disk creation instruction, a target disk image corresponding to the source virtual disk is generated, the disk space and disk format of the target disk image and the source virtual disk are the same, the disk creation instruction includes a target disk allocation method for the target disk image, and the target disk allocation method is different from the source disk allocation method for the source virtual disk; copy the data in the source virtual disk to the target disk image; switch the primary disk mapping of the virtual machine from the source virtual disk to the target disk image. In other words, by creating a target disk image with a target disk allocation method, and migrating the data in the source virtual disk to the target disk image by hot migration, the synchronization of the disk image is completed, and then the primary disk mapping of the virtual machine is switched to the target disk image; in this way, there is no need to shut down and restart the virtual machine, avoiding the impact of the change in the disk allocation method on other businesses currently running on the virtual machine, that is, greatly reducing the impact on other businesses currently running on the virtual machine.

[0079] The following will be combined Figure 6 A computer device provided by the present application is described.

[0080] Reference Figure 6 , Figure 6 The structural block diagram of a computer device 400 provided in an embodiment of the present application is shown, and the above method provided in an embodiment of the present application can be executed by the computer device 400. The computer device can be an electronic terminal with a data processing function, and the electronic terminal includes but is not limited to a tablet computer, a laptop computer, and a desktop computer; of course, the computer device can also be a server, and the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, network acceleration services (Content Delivery Network, CDN), and big data and artificial intelligence platforms. The computer device supports the construction of a virtual machine operating environment through a processor and a memory, and the one or more programs support execution in the virtual machine.

[0081] The computer device 400 in the embodiment of the present application may include one or more of the following components: a processor 401, a memory 402, and one or more applications, wherein the one or more applications may be stored in the memory 402 and configured to be executed by one or more processors 401, and the one or more programs are configured to execute the method as described in the aforementioned method embodiment.

[0082] The processor 401 may include one or more processing cores. The processor 401 uses various interfaces and lines to connect the various parts of the entire computer device 400, and executes various functions and processes data of the computer device 400 by running or executing instructions, programs, code sets or instruction sets stored in the memory 402, and calling data stored in the memory 402. Optionally, the processor 401 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 401 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU), and a modem. Among them, the CPU mainly processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem can also be integrated into the processor 401 and implemented separately through a communication chip.

[0083] The memory 402 may include a random access memory (RAM) or a read-only memory (ROM). The memory 402 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 402 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc. The data storage area may also store data (such as the various corresponding relationships described above) created by the computer device 400 during use.

[0084] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.

[0085] In several embodiments provided in the present application, the coupling or direct coupling or communication connection between the modules shown or discussed may be an indirect coupling or communication connection through some interfaces, devices or modules, which may be electrical, mechanical or other forms.

[0086] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.

[0087] An embodiment of the present application provides a management system for virtual machines, which may include a server and one or more virtual machines; the server is connected to the one or more virtual machines; the server is used to send a disk allocation mode conversion instruction to the one or more virtual machines; the virtual machine is used to execute the method described above after receiving the disk allocation mode conversion instruction.

[0088] Please refer to Figure 7 , which shows a structural block diagram of a computer-readable storage medium provided in an embodiment of the present application. The computer-readable medium 500 stores program codes, which can be called by a processor to execute the method described in the above method embodiment.

[0089] The computer readable storage medium 500 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer readable storage medium 500 includes a non-transitory computer-readable storage medium. The computer readable storage medium 500 has storage space for program code 510 that performs any method step of the above method. These program codes can be read from or written to one or more computer program products. The program code 510 can be compressed, for example, in an appropriate form.

[0090] In some embodiments, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device performs the steps in the above-mentioned method embodiments.

[0091] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for changing a disk allocation mode, characterized in that: The method comprises: In response to a disk allocation mode conversion instruction, generating a target disk image corresponding to the source virtual disk, the conversion instruction including the target disk allocation mode, the target disk allocation mode being different from the disk allocation mode of the source virtual disk; Migrating the data in the source virtual disk to the target disk image, during which the source virtual disk remains operational; The target disk image is mounted to generate a corresponding target virtual disk to replace the source virtual disk, and the target virtual disk adopts the target disk allocation mode.

2. The method according to claim 1, characterized in that Before mounting the target disk image to generate a corresponding target virtual disk to replace the source virtual disk, the method further includes: Adjust the virtual machine from the running state to the suspended state; After mounting the target disk image and generating a corresponding target virtual disk to replace the source virtual disk, the method further includes: The virtual machine is adjusted from a paused state to a running state.

3. The method according to claim 2, characterized in that After adjusting the virtual machine from the running state to the suspended state, the method further includes: Obtaining a backup bitmap in the source virtual disk; After mounting the target disk image to generate a corresponding target virtual disk to replace the source virtual disk, the method further includes: The backup bitmap is synchronized to the target disk image.

4. The method according to claim 1, characterized in that: Before generating a target disk image corresponding to the source virtual disk in response to the disk allocation mode conversion instruction, the method further includes: Creating a temporary directory path for the virtual machine; After generating a target disk image corresponding to the source virtual disk in response to the conversion instruction of the disk allocation mode, the method further includes: The target disk image is saved in the temporary directory path.

5. The method according to claim 4, characterized in that After migrating the data in the source virtual disk to the target disk image, the method further includes: Switching the target disk image from the temporary directory path to the virtual machine directory path; The source virtual disk is switched from the virtual machine directory path to the temporary directory path.

6. The method according to claim 4, characterized in that After mounting the target disk image and generating a corresponding target virtual disk to replace the source virtual disk, the method further includes: The memory path corresponding to the virtual machine and the target virtual disk is switched from the temporary directory path to the virtual machine directory path.

7. The method according to any one of claims 1 to 6, characterized in that: The step of migrating data from the source virtual disk to the target disk image includes: If the migration time of the data in the source virtual disk to the target disk image is longer than the preset time, outputting the target prompt information; In response to a migration cancellation instruction input based on the target prompt information, the copying process of the data in the source virtual disk is stopped.

8. A device for changing a disk allocation mode, characterized in that: The device comprises: A disk image creation module, for generating a target disk image corresponding to a source virtual disk in response to a disk allocation mode conversion instruction, wherein the conversion instruction includes a target disk allocation mode, and the target disk allocation mode is different from the disk allocation mode of the source virtual disk; A data migration module, used for migrating the data in the source virtual disk to the target disk image, during which the source virtual disk remains operational; The change module is used to mount the target disk image and generate a corresponding target virtual disk to replace the source virtual disk. The target virtual disk adopts the target disk allocation method.

9. A computer device, characterized in that: The computer device comprises: one or more processors; Memory; One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the method according to any one of claims 1 to 7.

10. The computer device according to claim 9, characterized in that The computer device supports building a virtual machine operating environment through a processor and a memory, and the one or more programs support execution in the virtual machine.

11. A virtual machine management system, characterized in that: include: A server, one or more virtual machines; the server is connected to the one or more virtual machines; The server is used to send a disk allocation mode conversion instruction to the one or more virtual machines; The virtual machine is used to execute the method according to any one of claims 1 to 7 after receiving the disk allocation mode conversion instruction.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program code, which can be called by a processor to execute the method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Data synchronization method, mirror image mounting method, equipment and medium

    CN120448358A