Virtual machine processing method and device, electronic equipment and storage medium
By creating a virtual machine directory in the storage pool and using the distributed lock manager for locking, the stability and performance issues of the virtual machine during hot editing are solved, the lock and disk are separated, and the stability of the virtual machine is improved. and performance.
Patent Information
- Application Number
- CN202410675889.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-28
- Publication Date
- 2024-08-27
AI Technical Summary
Existing virtual machines are prone to trigger lock release and lock operations when performing hot editing after the disk is locked, resulting in cumbersome processing logic and poor stability. In addition, the storage pool can only apply for a maximum of 2048 locks, which limits the number of disks and leads to poor performance and stability. Sex is low.
By creating a virtual machine directory in the storage pool and generating a configuration file, and using the distributed lock manager for locking, the lock is separated from the disk, preventing lock operations from being triggered during hot editing, and lifting the limit on the number of disks in the storage pool.
It simplifies the processing logic of virtual machines, reduces the probability of exceptions, improves stability, and improves performance, allowing one storage pool to create more disks.
Smart Images

Figure CN118550645A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of virtual machine technology, and in particular to a virtual machine processing method, device, electronic device and storage medium. Background Art
[0002] With the rapid development of cloud computing, cloud computing platforms carry more user services, and the importance of virtual machines is self-evident. Due to the rapid update and iteration of technology, some of the original designs of virtual machines can no longer adapt well to current user needs.
[0003] For example, after locking a disk, if you perform hot editing on the locked disk, it will trigger operations such as releasing and locking the disk, which can easily cause problems and cause the processing logic of the virtual machine to be more complicated and less stable.
[0004] In addition, because a storage pool can apply for a maximum of 2048 locks, a storage pool can only have a maximum of 2048 disks, resulting in lower performance and poor stability of the virtual machine. Summary of the invention
[0005] In view of the above problems, embodiments of the present invention are proposed to provide a method, device, electronic device and storage medium for processing a virtual machine that overcomes the above problems or at least partially solves the above problems.
[0006] In a first aspect, an embodiment of the present invention discloses a method for processing a virtual machine, the method comprising:
[0007] Obtaining a creation instruction for creating a virtual machine; the creation instruction includes a storage pool required for creating the virtual machine;
[0008] Creating a virtual machine directory corresponding to the virtual machine in the storage pool, and creating a first configuration file of the virtual machine in the virtual machine directory, as well as a boot file required to start the virtual machine; the first configuration file includes first lock information for locking the virtual machine directory;
[0009] In response to a startup instruction for starting the virtual machine, the virtual machine is started based on the first configuration file and the boot file, and the virtual machine directory is locked based on the first lock information.
[0010] Optionally, the type of the storage pool in the creation instruction includes a hardware type; and the step of creating a virtual machine directory corresponding to the virtual machine in the storage pool includes:
[0011] Allocate a logical unit number LUN of preset capacity in the storage pool;
[0012] Creating a first shared storage pool of a logical type based on the LUN;
[0013] A virtual machine directory corresponding to the virtual machine is created in the first shared storage pool.
[0014] Optionally, the storage pool type in the creation instruction further includes a logical type; and the step of creating a virtual machine directory corresponding to the virtual machine in the storage pool includes:
[0015] determining an unused second shared storage pool of logical type;
[0016] A virtual machine directory corresponding to the virtual machine is created in the second shared storage pool.
[0017] Optionally, the creation instruction further includes a selection instruction for a controller;
[0018] The step of creating a first configuration file of the virtual machine in the virtual machine directory includes:
[0019] Sending a first lock request for locking the virtual machine directory to a preset distributed lock manager;
[0020] Obtaining first lock information returned by the distributed lock manager in response to the first lock request;
[0021] generating first configuration information of the virtual machine based on first storage pool information of the storage pool and the first lock information;
[0022] Acquire controller information of the controller from a preset database based on the selection instruction;
[0023] Establishing an association relationship between the controller information and the first configuration information;
[0024] Acquire association information associated with the virtual machine from the preset database; the association information is any information related to the virtual machine except the first configuration information;
[0025] A first configuration file of the virtual machine is generated based on the first configuration information, the controller information, the association information and the association relationship.
[0026] Optionally, it also includes:
[0027] In response to a migration instruction for the virtual machine directory, determining a current state of the virtual machine;
[0028] The virtual machine directory is migrated based on the current state.
[0029] Optionally, the current state includes a downtime state;
[0030] The migrating the virtual machine directory based on the current state includes:
[0031] Obtaining a target storage pool in the migration instruction;
[0032] The virtual machine directory is moved from the storage pool to the target storage pool.
[0033] Optionally, the current state includes a running state;
[0034] The migrating the virtual machine directory based on the current state includes:
[0035] Obtaining a target storage pool in the migration instruction;
[0036] Copying the virtual machine directory from the storage pool to the target storage pool;
[0037] Sending a second lock request for locking the virtual machine directory to a preset distributed lock manager;
[0038] Obtaining second lock information returned by the distributed lock manager in response to the second lock request;
[0039] generating second configuration information of the virtual machine based on the second storage pool information of the target storage pool and the second lock information;
[0040] Using the second configuration information to update the first configuration file of the virtual machine to obtain a second configuration file;
[0041] Release the lock on the virtual machine directory in the storage pool, and remove the lock after the lock is released successfully;
[0042] After the lock is removed successfully, the virtual machine directory in the storage pool is deleted.
[0043] Optionally, it also includes:
[0044] Obtaining memory data in the memory of the virtual machine when it is running;
[0045] generating a memory snapshot based on the memory data;
[0046] The memory snapshot is stored in the virtual machine directory.
[0047] In a second aspect, an embodiment of the present invention discloses a processing device for a virtual machine, the device comprising:
[0048] An acquisition module, used for acquiring a creation instruction for creating a virtual machine; the creation instruction includes a storage pool required for creating the virtual machine;
[0049] a creation module, configured to create a virtual machine directory corresponding to the virtual machine in the storage pool, and to create a first configuration file of the virtual machine in the virtual machine directory, and a boot file required to start the virtual machine; the first configuration file includes first lock information for locking the virtual machine directory;
[0050] The running module is used to respond to a startup instruction for starting the virtual machine, start the virtual machine based on the first configuration file and the boot file, and lock the virtual machine directory based on the first lock information.
[0051] In a third aspect, the present invention further discloses an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the steps of the virtual machine processing method as described above are implemented.
[0052] In a fourth aspect, the present invention further discloses a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the virtual machine processing method as described above are implemented.
[0053] The embodiments of the present invention include the following advantages:
[0054] When a creation instruction for creating a virtual machine is obtained, a virtual machine directory corresponding to the virtual machine can be created in the storage pool, and a first configuration file of the virtual machine and a boot file required to start the virtual machine can be created in the virtual machine directory. When a startup instruction for starting the virtual machine is obtained, the virtual machine is started based on the first configuration file and the boot file, and the virtual machine directory is locked based on the first lock information. In this way, the lock is separated from the disk and the lock is associated with the virtual machine. When the disk is hot-edited, the lock operation is no longer triggered, which not only simplifies the processing logic of the virtual machine, but also reduces the probability of abnormalities and improves the stability of the virtual machine.
[0055] At the same time, after separating the lock from the disk, the limitation of a storage pool having a maximum of 2048 disks is lifted, so that a storage pool can create more disks, thereby improving the performance of the virtual machine and further improving the stability of the virtual machine. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 It is a flowchart of a method for processing a virtual machine provided by an embodiment of the present invention;
[0057] Figure 2 is a flowchart of another method for processing a virtual machine provided by an embodiment of the present invention;
[0058] Figure 3is a flowchart of the steps of another method for processing a virtual machine provided by an embodiment of the present invention;
[0059] Figure 4 is a structural block diagram of an electronic device provided by an embodiment of the present invention;
[0060] Figure 5 It is a structural block diagram of a computer-readable storage medium provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0061] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0062] like Figure 1 , shows a flowchart of a method for processing a virtual machine provided by an embodiment of the present invention, the method may include the following steps:
[0063] Step 101, obtaining a creation instruction for creating a virtual machine; the creation instruction includes a storage pool required for creating the virtual machine.
[0064] In the embodiment of the present invention, the system is provided with a visual interface for creating a virtual machine, and the user can select the storage pool where the virtual machine is located in the visual interface, and after the user confirms the selection, the system can obtain a creation instruction for creating the virtual machine. For example, after the user selects a storage pool in the visual interface, he clicks the "OK" button in the visual interface, and the creation instruction can be generated at this time.
[0065] After obtaining the creation instruction, the system can determine the storage pool used to create the virtual machine according to the creation instruction.
[0066] Step 102, creating a virtual machine directory corresponding to the virtual machine in the storage pool, and creating a first configuration file of the virtual machine in the virtual machine directory, as well as a boot file required to start the virtual machine; the first configuration file includes first lock information for locking the virtual machine directory.
[0067] After determining the storage pool for creating the virtual machine, the system can create a virtual machine directory corresponding to the virtual machine in the storage pool. The virtual machine directory is used to store any file related to the virtual machine, and the identifier of the virtual machine directory is globally unique.
[0068] After the virtual machine directory is successfully created, a configuration file for the virtual machine (referred to as the "first configuration file" for easy distinction, and the same applies to the following text) and the boot file nvram required to start the virtual machine can be created. The configuration file is all files related to the configuration of the virtual machine, and the information in the configuration file includes but is not limited to: the configuration information of the virtual machine (referred to as the "first configuration information"), the controller information of the controller connected to the virtual machine, the association information of the virtual machine, and the association relationship between the first configuration information and the controller information; the first configuration information includes but is not limited to the storage pool information of the current storage pool (referred to as the "first storage pool information") and the lock information for locking the virtual machine directory (referred to as the "first lock information"), and the association information is any information related to the virtual machine except the configuration information.
[0069] It should be noted that, in the embodiment of the present invention, the configuration file may include other information in addition to the above information, and in practical applications, it may be adjusted according to actual needs, and the embodiment of the present invention does not limit this.
[0070] In one embodiment, the type of the storage pool in the creation instruction includes a hardware type; and the step of creating a virtual machine directory corresponding to the virtual machine in the storage pool includes:
[0071] Allocate a logical unit number LUN of preset capacity in the storage pool;
[0072] Creating a first shared storage pool of a logical type based on the LUN;
[0073] A virtual machine directory corresponding to the virtual machine is created in the first shared storage pool.
[0074] Specifically, different types of storage pools can be provided in the visualization interface, one of which is a hardware-type storage pool, which does not have a file system. When the user selects a hardware-type storage pool in the visualization interface to create a virtual machine directory, the system can allocate a logical unit number LUN (Logical Unit Number) of preset capacity from the storage pool, such as a 20G LUN, and then create a shared storage pool (referred to as the "first shared storage pool") in the LUN. After the first shared storage pool is successfully created, a virtual machine directory corresponding to the virtual machine can be created in the first shared storage pool.
[0075] It should be noted that, in the embodiment of the present invention, the preset capacity may be other capacities besides 20G, and in practical applications, it may be set according to actual needs, and the embodiment of the present invention does not limit this.
[0076] In one embodiment, the storage pool type in the creation instruction further includes a logical type; and the step of creating a virtual machine directory corresponding to the virtual machine in the storage pool includes:
[0077] determining an unused second shared storage pool of logical type;
[0078] A virtual machine directory corresponding to the virtual machine is created in the second shared storage pool.
[0079] Specifically, another type of storage pool may be a logical type, that is, a shared storage pool, which has a file system. When a user selects a logical type storage pool in the visual interface to create a virtual machine directory, the system may determine a currently unused logical type shared storage pool (referred to as a "second shared storage pool"), and then create a virtual machine directory corresponding to the virtual machine in the second shared storage pool.
[0080] In this way, by directly creating a virtual directory in the storage pool, the virtual directory can be directly locked later without locking the disk. At the same time, it also avoids the situation where a storage pool can only apply for 2048 locks at most, resulting in a storage pool only being able to create 2048 disks. Therefore, when hot editing the disk, the lock operation is no longer triggered, which simplifies the processing logic of the virtual machine and reduces the probability of exceptions.
[0081] In one embodiment, the creation instruction further includes a selection instruction for a controller;
[0082] The step of creating a first configuration file of the virtual machine in the virtual machine directory includes:
[0083] Sending a first lock request for locking the virtual machine directory to a preset distributed lock manager;
[0084] Obtaining first lock information returned by the distributed lock manager in response to the first lock request;
[0085] generating first configuration information of the virtual machine based on first storage pool information of the storage pool and the first lock information;
[0086] Acquire controller information of the controller from a preset database based on the selection instruction;
[0087] Establishing an association relationship between the controller information and the first configuration information;
[0088] Acquire association information associated with the virtual machine from the preset database; the association information is any information related to the virtual machine except the first configuration information;
[0089] A first configuration file of the virtual machine is generated based on the first configuration information, the controller information, the association information and the association relationship.
[0090] Specifically, when creating the first configuration file of the virtual machine in the virtual machine directory, the system can send a lock request (referred to as a "first lock request") to a preset distributed lock manager, such as sanlock, and the lock request is used to lock the virtual machine directory.
[0091] After receiving the request, the distributed lock manager can generate corresponding lock information (recorded as "first lock information"), and then send the first lock information to the system. The system can generate the first configuration information of the virtual machine based on the first storage pool information and the first lock information.
[0092] Furthermore, the visualization interface can also provide controller options, so when the user selects a storage pool in the visualization interface, he can also select the controller required by the virtual machine, and then generate creation instructions based on the storage pool and virtual machine selected by the user. In other words, the creation instructions include both the selection instructions for the storage pool selected by the user and the selection instructions for the controller.
[0093] Therefore, if the creation instruction also includes a controller selection instruction, the system can also obtain the controller information of the controller from the preset database according to the selection instruction. For example, if the user selects a controller connected to a keyboard in the visual interface, the controller information of the controller corresponding to the keyboard can be obtained from the preset database when creating the first configuration file.
[0094] Then, the system can establish an association relationship between the controller information and the first configuration information, for example, by establishing an association relationship through the config_id field. This achieves associating the virtual machine with the controller, so that the associated controller can be called when the virtual machine is running.
[0095] In addition, the system can also obtain related information associated with the virtual machine from a preset database. The related information can be any information related to the virtual machine except the first configuration information, including but not limited to: attribute information of the virtual machine, such as the name, status, creation time and other information of the virtual machine; hardware information of the virtual machine, such as the CPU (Central Processing Unit), memory, architecture, version and other information of the virtual machine.
[0096] It should be noted that the preset database is used to store the information required to generate the configuration file. That is to say, when the system generates the configuration file, it can obtain it from the preset database instead of the code. Since the information in the preset database can be updated at any time, the information in the preset database can be flexibly set according to different configuration files, avoiding the situation where the information is solidified in the code and the code needs to be changed to generate different configuration files.
[0097] After the first configuration information, the controller information, the associated information and the associated relationship are determined, a first configuration file of the virtual machine may be generated based on the first configuration information, the controller information, the associated information and the associated relationship.
[0098] In this way, when creating a virtual machine, a first configuration file can be created based on various information related to the virtual machine and stored in the virtual machine directory. By locking the virtual machine directory, the lock and disk are separated and the lock and virtual machine are associated. This not only simplifies the processing logic of the virtual machine and reduces the probability of abnormalities, but also reduces the frequency of replacing the storage pool and improves the stability of the virtual machine.
[0099] Moreover, the controller information can be stored in a preset database, and the system can obtain the controller information from the preset database as needed, rather than solidifying the controller information in the code, avoiding the situation where the controller occupies the address even if it is not used.
[0100] Step 103: In response to a startup instruction for starting the virtual machine, the virtual machine is started based on the first configuration file and the boot file, and the virtual machine directory is locked based on the first lock information.
[0101] After the first configuration file and the boot file are created, the creation of the virtual machine is completed. When the user initiates a startup instruction to start the virtual machine, the system can start the virtual machine according to the information in the first configuration file and the boot file. When the virtual machine is started and runs normally, the virtual machine directory can be locked based on the first lock information in the first configuration information.
[0102] It should be noted that each storage pool stores a lock file of a distributed lock manager, and the functions of the lock file include but are not limited to: applying for locks, locking, releasing locks, and removing locks. Among them, locking is to enable a virtual machine to run on a host, ensuring the stability of the virtual machine.
[0103] In an embodiment of the present invention, when a creation instruction for creating a virtual machine is obtained, a virtual machine directory corresponding to the virtual machine can be created in the storage pool, and a first configuration file of the virtual machine and a boot file required to start the virtual machine are created in the virtual machine directory. When a startup instruction for starting the virtual machine is obtained, the virtual machine is started based on the first configuration file and the boot file, and the virtual machine directory is locked based on the first lock information. In this way, the lock is separated from the disk and the lock is associated with the virtual machine. When the disk is hot-edited, the lock operation is no longer triggered, which not only simplifies the processing logic of the virtual machine, but also reduces the probability of abnormalities and improves the stability of the virtual machine.
[0104] At the same time, after separating the lock from the disk, the limitation of a storage pool having a maximum of 2048 disks is lifted, so that a storage pool can create more disks, thereby improving the performance of the virtual machine and further improving the stability of the virtual machine.
[0105] like Figure 2 , shows a flowchart of another method for processing a virtual machine provided by an embodiment of the present invention, the method may include the following steps:
[0106] Step 201, obtaining a creation instruction for creating a virtual machine; the creation instruction includes a storage pool required for creating the virtual machine;
[0107] Step 202, creating a virtual machine directory corresponding to the virtual machine in the storage pool, and creating a first configuration file of the virtual machine in the virtual machine directory, as well as a boot file required to start the virtual machine; the first configuration file includes first lock information for locking the virtual machine directory;
[0108] Step 203: In response to a startup instruction for starting the virtual machine, the virtual machine is started based on the first configuration file and the boot file, and the virtual machine directory is locked based on the first lock information.
[0109] Among them, steps 201 to 203 are substantially the same as steps 101 to 103, and will not be described here to avoid repetition.
[0110] Step 204, in response to the migration instruction for the virtual machine directory, determining the current state of the virtual machine;
[0111] Step 205: Migrate the virtual machine directory based on the current state.
[0112] Since all files related to the virtual machine are stored in the virtual machine directory, the user can determine the current state of the virtual machine after initiating the migration instruction to migrate the virtual machine directory. The current state includes the downtime state and the running state. For the downtime state, the virtual machine directory can be migrated by cold migration, and for the running state, the virtual machine directory can be migrated by hot migration. Since the lock and disk are separated and the lock and virtual machine are associated, the virtual machine directory in the storage pool can be migrated as a whole, which not only simplifies the processing logic of the virtual machine, reduces the probability of abnormalities, and improves the stability of the virtual machine.
[0113] In one embodiment, the current state includes a downtime state;
[0114] The migrating the virtual machine directory based on the current state includes:
[0115] Obtaining a target storage pool in the migration instruction;
[0116] The virtual machine directory is moved from the storage pool to the target storage pool.
[0117] Specifically, if the current state of the virtual machine is down, you can obtain the target storage pool in the migration instruction, and then move all virtual machine directories from the current storage pool to the target storage pool. There is no need to operate the lock, which simplifies the processing logic of the virtual machine and reduces the probability of exceptions.
[0118] In one embodiment, the current state includes an operating state;
[0119] The migrating the virtual machine directory based on the current state includes:
[0120] Obtaining a target storage pool in the migration instruction;
[0121] Copying the virtual machine directory from the storage pool to the target storage pool;
[0122] Sending a second lock request for locking the virtual machine directory to a preset distributed lock manager;
[0123] Obtaining second lock information returned by the distributed lock manager in response to the second lock request;
[0124] generating second configuration information of the virtual machine based on the second storage pool information of the target storage pool and the second lock information;
[0125] Using the second configuration information to update the first configuration file of the virtual machine to obtain a second configuration file;
[0126] Release the lock on the virtual machine directory in the storage pool, and remove the lock after the lock is released successfully;
[0127] After the lock is removed successfully, the virtual machine directory in the storage pool is deleted.
[0128] Specifically, if the current state of the virtual machine is the running state, the target storage pool in the migration instruction can be obtained, and then the virtual machine directory can be copied from the current storage pool to the target storage pool. Since the virtual machine directory in the target storage pool is not locked at this time, a lock request (referred to as a "second lock request") can be sent to the preset distributed lock manager, and the second lock request is used to lock the virtual machine directory in the target storage pool.
[0129] After receiving the second lock request, the distributed lock manager generates corresponding lock information (recorded as "second lock information") and sends the second lock information to the system. The system can then generate the current configuration information of the virtual machine (recorded as "second configuration information") based on the storage pool information of the target storage pool (recorded as "second storage pool information") and the second lock information.
[0130] Then the system uses the second configuration information to replace the first configuration information in the first configuration file to obtain a new configuration file (recorded as the "second configuration file"). At this time, the virtual machine directory in the target storage pool has been deployed, and the virtual machine directory in the original storage pool is still locked. Therefore, it is necessary to release the lock of the virtual machine target in the original storage pool, and remove the lock after the lock is released successfully. After the lock is removed successfully, the virtual machine directory in the original storage pool can be completely deleted, thereby realizing the overall hot migration of the virtual machine directory, reducing the complexity of the hot migration process, reducing the probability of virtual machine abnormalities, and improving the stability of the virtual machine.
[0131] like Figure 3 , shows a flowchart of another method for processing a virtual machine provided by an embodiment of the present invention, the method may include the following steps:
[0132] Step 301, obtaining a creation instruction for creating a virtual machine; the creation instruction includes a storage pool required for creating the virtual machine;
[0133] Step 302: Create a virtual machine directory corresponding to the virtual machine in the storage pool, and create a first configuration file of the virtual machine in the virtual machine directory, as well as a boot file required to start the virtual machine; the first configuration file includes first lock information for locking the virtual machine directory;
[0134] Step 303: In response to a startup instruction for starting the virtual machine, the virtual machine is started based on the first configuration file and the boot file, and the virtual machine directory is locked based on the first lock information.
[0135] Among them, steps 301 to 303 are substantially the same as steps 101 to 103, and will not be described here to avoid repetition.
[0136] Step 304, obtaining memory data in the memory of the virtual machine when it is running;
[0137] Step 305, generating a memory snapshot based on the memory data;
[0138] Step 306: store the memory snapshot in the virtual machine directory.
[0139] Specifically, during the operation of the virtual machine, the data in the memory of the virtual machine can be stored in the form of memory snapshots. Based on this, when the virtual machine is running, the memory data in the memory can be obtained, and then a memory snapshot can be generated and stored in the virtual machine directory. Since the lock is no longer associated with the disk but with the virtual machine, the memory snapshot is no longer stored with the locked disk, but is stored in the same storage pool as the virtual machine directory, which reduces the frequency of changing the storage pool for the memory snapshot and improves the stability of the virtual machine.
[0140] The present invention also provides a virtual machine processing device, the device comprising:
[0141] An acquisition module, used for acquiring a creation instruction for creating a virtual machine; the creation instruction includes a storage pool required for creating the virtual machine;
[0142] a creation module, configured to create a virtual machine directory corresponding to the virtual machine in the storage pool, and to create a first configuration file of the virtual machine in the virtual machine directory, and a boot file required to start the virtual machine; the first configuration file includes first lock information for locking the virtual machine directory;
[0143] The running module is used to respond to a startup instruction for starting the virtual machine, start the virtual machine based on the first configuration file and the boot file, and lock the virtual machine directory based on the first lock information.
[0144] Optionally, the type of the storage pool in the creation instruction includes a hardware type; and the creation module is specifically configured to:
[0145] Allocate a logical unit number LUN of preset capacity in the storage pool;
[0146] Creating a first shared storage pool of a logical type based on the LUN;
[0147] A virtual machine directory corresponding to the virtual machine is created in the first shared storage pool.
[0148] Optionally, the storage pool type in the creation instruction further includes a logical type; and the creation module is further specifically configured to:
[0149] determining an unused second shared storage pool of logical type;
[0150] A virtual machine directory corresponding to the virtual machine is created in the second shared storage pool.
[0151] Optionally, the creation instruction further includes a selection instruction for a controller;
[0152] The creation module is also specifically used for:
[0153] Sending a first lock request for locking the virtual machine directory to a preset distributed lock manager;
[0154] Obtaining first lock information returned by the distributed lock manager in response to the first lock request;
[0155] generating first configuration information of the virtual machine based on first storage pool information of the storage pool and the first lock information;
[0156] Acquire controller information of the controller from a preset database based on the selection instruction;
[0157] Establishing an association relationship between the controller information and the first configuration information;
[0158] Acquire association information associated with the virtual machine from the preset database; the association information is any information related to the virtual machine except the first configuration information;
[0159] A first configuration file of the virtual machine is generated based on the first configuration information, the controller information, the association information and the association relationship.
[0160] Optionally, it also includes:
[0161] a determination module, configured to determine a current state of the virtual machine in response to a migration instruction for the virtual machine directory;
[0162] A migration module is used to migrate the virtual machine directory based on the current state.
[0163] Optionally, the current state includes a downtime state;
[0164] The migration module is specifically used for:
[0165] Obtaining a target storage pool in the migration instruction;
[0166] The virtual machine directory is moved from the storage pool to the target storage pool.
[0167] Optionally, the current state includes a running state;
[0168] The migration module is also specifically used for:
[0169] Obtaining a target storage pool in the migration instruction;
[0170] Copying the virtual machine directory from the storage pool to the target storage pool;
[0171] Sending a second lock request for locking the virtual machine directory to a preset distributed lock manager;
[0172] Obtaining second lock information returned by the distributed lock manager in response to the second lock request;
[0173] generating second configuration information of the virtual machine based on the second storage pool information of the target storage pool and the second lock information;
[0174] Using the second configuration information to update the first configuration file of the virtual machine to obtain a second configuration file;
[0175] Release the lock on the virtual machine directory in the storage pool, and remove the lock after the lock is released successfully;
[0176] After the lock is removed successfully, the virtual machine directory in the storage pool is deleted.
[0177] Optionally, it also includes:
[0178] The acquisition module is further used to acquire memory data in the memory of the virtual machine when it is running;
[0179] A generation module, used to generate a memory snapshot based on the memory data;
[0180] A storage module is used to store the memory snapshot in the virtual machine directory.
[0181] like Figure 4 , showing a structural block diagram of an electronic device 40 provided in an embodiment of the present invention, including:
[0182] A processor 401, a memory 402, and a computer program 4021 stored in the memory 402 and capable of running on the processor 401. When the computer program 4021 is executed by the processor 401, each process of the above-mentioned virtual machine processing method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0183] like Figure 5 , shows a structural block diagram of a computer-readable storage medium 50 provided in an embodiment of the present invention. A computer program 501 is stored on the computer-readable storage medium 50. When the computer program 501 is executed by the processor, the various processes of the above-mentioned virtual machine processing method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0184] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0185] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0186] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0187] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0188] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0189] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0190] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0191] The above is a detailed introduction to a virtual machine processing method, device, electronic device and storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for a person skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A method for processing a virtual machine, characterized in that: The method comprises: Obtaining a creation instruction for creating a virtual machine; the creation instruction includes a storage pool required for creating the virtual machine; Creating a virtual machine directory corresponding to the virtual machine in the storage pool, and creating a first configuration file of the virtual machine in the virtual machine directory, as well as a boot file required to start the virtual machine; the first configuration file includes first lock information for locking the virtual machine directory; In response to a startup instruction for starting the virtual machine, the virtual machine is started based on the first configuration file and the boot file, and the virtual machine directory is locked based on the first lock information.
2. The method for processing a virtual machine according to claim 1, characterized in that: The type of the storage pool in the creation instruction includes a hardware type; and the step of creating a virtual machine directory corresponding to the virtual machine in the storage pool includes: Allocate a logical unit number LUN of preset capacity in the storage pool; Creating a first shared storage pool of a logical type based on the LUN; A virtual machine directory corresponding to the virtual machine is created in the first shared storage pool.
3. The method for processing a virtual machine according to claim 1, characterized in that: The storage pool type in the creation instruction also includes a logical type; and the step of creating a virtual machine directory corresponding to the virtual machine in the storage pool includes: determining an unused second shared storage pool of logical type; A virtual machine directory corresponding to the virtual machine is created in the second shared storage pool.
4. The method for processing a virtual machine according to claim 1, characterized in that: The creation instruction also includes a selection instruction for the controller; The step of creating a first configuration file of the virtual machine in the virtual machine directory includes: Sending a first lock request for locking the virtual machine directory to a preset distributed lock manager; Obtaining first lock information returned by the distributed lock manager in response to the first lock request; generating first configuration information of the virtual machine based on first storage pool information of the storage pool and the first lock information; Acquire controller information of the controller from a preset database based on the selection instruction; establish an association relationship between the controller information and the first configuration information; Acquire association information associated with the virtual machine from the preset database; the association information is any information related to the virtual machine except the first configuration information; A first configuration file of the virtual machine is generated based on the first configuration information, the controller information, the association information and the association relationship.
5. The method for processing a virtual machine according to claim 1, characterized in that: Also includes: In response to a migration instruction for the virtual machine directory, determining a current state of the virtual machine; The virtual machine directory is migrated based on the current state.
6. The method for processing a virtual machine according to claim 5, characterized in that: The current state includes a downtime state; The migrating the virtual machine directory based on the current state includes: Obtaining a target storage pool in the migration instruction; The virtual machine directory is moved from the storage pool to the target storage pool.
7. The method for processing a virtual machine according to claim 5, characterized in that: The current state includes an operating state; The migrating the virtual machine directory based on the current state includes: Obtaining a target storage pool in the migration instruction; Copying the virtual machine directory from the storage pool to the target storage pool; Sending a second lock request for locking the virtual machine directory to a preset distributed lock manager; Obtaining second lock information returned by the distributed lock manager in response to the second lock request; generating second configuration information of the virtual machine based on the second storage pool information of the target storage pool and the second lock information; Using the second configuration information to update the first configuration file of the virtual machine to obtain a second configuration file; The virtual machine directory in the storage pool is locked and released, and the lock is removed after the lock is released successfully; after the lock is removed successfully, the virtual machine directory in the storage pool is deleted.
8. The method for processing a virtual machine according to claim 1, characterized in that: Also includes: Obtaining memory data in the memory of the virtual machine when it is running; generating a memory snapshot based on the memory data; The memory snapshot is stored in the virtual machine directory.
9. A processing device for a virtual machine, characterized in that: The device comprises: An acquisition module, used for acquiring a creation instruction for creating a virtual machine; the creation instruction includes a storage pool required for creating the virtual machine; a creation module, configured to create a virtual machine directory corresponding to the virtual machine in the storage pool, and to create a first configuration file of the virtual machine in the virtual machine directory, and a boot file required to start the virtual machine; the first configuration file includes first lock information for locking the virtual machine directory; The running module is used to respond to a startup instruction for starting the virtual machine, start the virtual machine based on the first configuration file and the boot file, and lock the virtual machine directory based on the first lock information.
10. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the steps of the method for processing a virtual machine according to any one of claims 1 to 8 are implemented.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method for processing a virtual machine according to any one of claims 1 to 8 are implemented.
