CN109857343B - Disk space releasing method and device - Google Patents

Disk space releasing method and device Download PDF

Info

Publication number
CN109857343B
CN109857343B CN201910093758.7A CN201910093758A CN109857343B CN 109857343 B CN109857343 B CN 109857343B CN 201910093758 A CN201910093758 A CN 201910093758A CN 109857343 B CN109857343 B CN 109857343B
Authority
CN
China
Prior art keywords
virtual machine
disk
target
disk space
command
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910093758.7A
Other languages
Chinese (zh)
Other versions
CN109857343A (en
Inventor
莫展飞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
New H3C Cloud Technologies Co Ltd
Original Assignee
New H3C Cloud Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by New H3C Cloud Technologies Co Ltd filed Critical New H3C Cloud Technologies Co Ltd
Priority to CN201910093758.7A priority Critical patent/CN109857343B/en
Publication of CN109857343A publication Critical patent/CN109857343A/en
Application granted granted Critical
Publication of CN109857343B publication Critical patent/CN109857343B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The disclosure relates to the technical field of virtual machines, and provides a disk space release method and device, wherein the method comprises the following steps: receiving a disk space release command; analyzing a disk space release command, generating a command identifier, a plurality of target virtual machines of a disk space to be released and a target disk partition corresponding to each target virtual machine; encapsulating the command identifier and the target disk partition corresponding to each target virtual machine into a plurality of disk space release messages according to a preset format; and sending the plurality of disk space release messages to the corresponding target virtual machines so that the corresponding target virtual machines call a preset disk space arrangement command to release the disk spaces of the corresponding target virtual machines based on the corresponding disk space release messages. According to the method and the device, the redundant storage space in the target disk partitions of the multiple target virtual machines can be released simultaneously by executing the command on the host machine, and the efficiency of releasing the redundant disk space in the target disk partitions of the target virtual machines is greatly improved.

Description

Disk space releasing method and device
Technical Field
The disclosure relates to the technical field of virtual machines, in particular to a disk space release method and device.
Background
The method has the advantages that the multiple virtual machines can be simultaneously operated on one host machine, the multiple virtual machines are independent from each other, each virtual machine is independent from the host machine, the utilization rate of the host machine is improved, meanwhile, the disk partitions of the virtual machines can occupy a large amount of storage space of the host machine, even if files in the disk partitions of the multiple virtual machines are deleted, the storage space occupied by the virtual machines on the host machine is not reduced, because the content of the corresponding files is not really cleared when the files in the disk partitions of the virtual machines are deleted, only the marks are simply made, and therefore the speed of deleting the files is improved. In order to actually release the redundant disk space occupied by the deleted file in the disk partition of the virtual machine, in the prior art, an internal system of the virtual machine needs to enter to execute a disk organizing command, so as to achieve the purpose of releasing the redundant disk space in the disk partition of the virtual machine.
Disclosure of Invention
The present disclosure aims to provide a method and an apparatus for releasing a disk space, which can send a target disk partition of a disk space to be released to a corresponding target virtual machine by executing a unified disk space release command on a host machine, so as to achieve the purpose of simultaneously releasing redundant storage spaces in target disk partitions of multiple target virtual machines, and greatly improve the efficiency of releasing the redundant disk space in the target disk partition of the target virtual machine.
In order to achieve the above purpose, the technical scheme adopted by the disclosure is as follows:
in a first aspect, the present disclosure provides a disk space releasing method, which is applied to a host machine, where multiple virtual machines run on the host machine, and the method includes: receiving a disk space release command; analyzing a disk space release command, generating a command identifier, a plurality of target virtual machines of a disk space to be released and a target disk partition corresponding to each target virtual machine; encapsulating the command identifier and the target disk partition corresponding to each target virtual machine into a plurality of disk space release messages according to a preset format; and sending the plurality of disk space release messages to the corresponding target virtual machines so that the corresponding target virtual machines call a preset disk space arrangement command to release the disk spaces of the corresponding target virtual machines based on the corresponding disk space release messages.
In a second aspect, the present disclosure provides a disk space releasing method, which is applied to a virtual machine running on a host machine, where the method includes: receiving a disk space release message sent by a host, wherein the disk space release message is formed by packaging a command identifier and a target disk partition according to a preset format by the host, and the command identifier, the target disk partition and a target virtual machine are generated after the host analyzes the disk space release command; and calling a preset disk space tidying command to release the disk space of the target virtual machine based on the disk space release message.
In a third aspect, the present disclosure further provides a disk space releasing device, which is applied to a host machine, where at least one virtual machine runs on the host machine, and the device includes a command receiving module, an analysis module, an encapsulation module, and a sending module. The command receiving module is used for receiving a disk space releasing command; the analysis module is used for analyzing the disk space release command, generating a command identifier, a plurality of target virtual machines of the disk space to be released and a target disk partition corresponding to each target virtual machine; the encapsulation module is used for encapsulating the command identifier and the target disk partition corresponding to each target virtual machine into a plurality of disk space release messages according to a preset format; the sending module is used for sending the plurality of disk space release messages to the corresponding target virtual machines so that the corresponding target virtual machines call a preset disk space arrangement command to release the disk spaces of the corresponding virtual machines based on the corresponding disk space release messages.
In a fourth aspect, the present disclosure provides a disk space releasing apparatus, applied to a virtual machine running on a host, the apparatus including: the device comprises a message receiving module and a releasing module. The message receiving module is used for receiving a disk space release message sent by the host machine, wherein the disk space release message is formed by packaging a command identifier and a target disk partition according to a preset format by the host machine, and the command identifier, the target disk partition and the target virtual machine are generated after the host machine analyzes the disk space release command; and the release module is used for calling a preset disk space arrangement command to release the disk space of the target virtual machine based on the disk space release message.
In a fifth aspect, the present disclosure provides a host machine, the host machine comprising: a processor; the storage is used for storing one or more programs, and when the one or more programs are executed by the processor, the processor is enabled to realize the disk space releasing method applied to the host machine or the disk space releasing method applied to the virtual machine running on the host machine.
In a sixth aspect, the present disclosure provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the above-mentioned disk space releasing method applied to a host or a disk space releasing method applied to a virtual machine running on the host.
Compared with the prior art, the present disclosure provides a disk space releasing method and device, first, a user sends a disk space releasing command for releasing a disk space of a virtual machine on a host, the host parses the received disk space releasing command, generates a command identifier, and generates a plurality of target virtual machines of the disk space to be released and a target disk partition corresponding to each target virtual machine, then, the host encapsulates the command identifier and the target disk partition corresponding to each target virtual machine into a plurality of disk space releasing messages according to a preset format, and finally, the host sends the plurality of disk space releasing messages to the corresponding target virtual machine, so that the corresponding target virtual machine calls a preset disk space sorting command based on the corresponding disk space releasing message, and releases the disk space of the corresponding target disk partition of the corresponding target virtual machine. Compared with the prior art, the method and the device have the advantages that the target disk partitions of the disk space to be released can be sent to the corresponding target virtual machines by executing the unified disk space release command on the host machine, so that the aim of simultaneously releasing redundant storage space in the disks corresponding to the target disk partitions of the target virtual machines is fulfilled, and the efficiency of releasing the redundant disk space in the disks corresponding to the target virtual machines is greatly improved.
In order to make the aforementioned objects, features and advantages of the present disclosure more comprehensible, embodiments accompanied with figures are described in detail below.
Drawings
To more clearly illustrate the technical solutions of the present disclosure, the drawings needed for the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present disclosure, and therefore should not be considered as limiting the scope, and those skilled in the art can also obtain other related drawings based on the drawings without inventive efforts.
Fig. 1 shows a block schematic diagram of a host provided by the present disclosure.
Fig. 2 shows a flowchart of a disk space releasing method applied to a host provided by the present disclosure.
Fig. 3 is a flowchart illustrating sub-steps of step S102 shown in fig. 2.
Fig. 4 shows a flowchart of a disk space releasing method applied to a virtual machine provided by the present disclosure.
Fig. 5 shows a block schematic diagram of a disk space releasing device applied to a host provided by the present disclosure.
Fig. 6 shows a block schematic diagram of a disk space releasing apparatus applied to a virtual machine according to the present disclosure.
Icon: 100-host machine; 101-a memory; 102-a communication interface; 103-a processor; 104-a bus; 200-a disk space releasing device applied to a host machine; 201-a command receiving module; 202-a parsing module; 203-packaging the module; 204-a sending module; 400-disk space releasing device applied to virtual machine; 401-a message receiving module; 402-release module.
Detailed Description
The technical solutions in the present disclosure will be described below clearly and completely with reference to the accompanying drawings in the present disclosure, and it is to be understood that the described embodiments are only some embodiments of the present disclosure, not all embodiments. The components of the present disclosure, as generally described and illustrated in the figures herein, may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present disclosure, presented in the figures, is not intended to limit the scope of the claimed disclosure, but is merely representative of selected embodiments of the disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the disclosure without making any creative effort, shall fall within the protection scope of the disclosure.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined or explained in subsequent figures. Meanwhile, in the description of the present disclosure, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.
Referring to fig. 1, fig. 1 shows a block schematic diagram of a host 100 provided in the present disclosure. Host 100 may be, but is not limited to, a host, a physical server. The operating system of host 100 may be, but is not limited to, a Windows system, a Linux system, etc. The host 100 comprises a memory 101, a communication interface 102, a processor 103 and a bus 104, wherein the memory 101, the communication interface 102 and the processor 103 are connected by the bus 104, and the processor 103 is configured to execute an executable module stored in the memory 101, such as the computer program.
The Memory 101 may include a high-speed Random Access Memory (RAM) and may further include a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. The communication connection between host 100 and the external storage device is realized through at least one communication interface 102 (which may be wired or wireless).
The bus 104 may be an ISA bus, PCI bus, EISA bus, or the like. Only one bi-directional arrow is shown in fig. 1, but this does not indicate only one bus or one type of bus.
The memory 101 is used for storing programs, such as the disk space releasing apparatus 200 shown in fig. 5 applied to a host. The disk space releasing device 200 applied to the host includes at least one software functional module which can be stored in the memory 101 in the form of software or firmware (firmware) or solidified in an Operating System (OS) of the host 100. After receiving the execution instruction, the processor 103 executes the program to implement the method for releasing the disk space applied to the host 100 disclosed in the above embodiment of the present disclosure.
It should be noted that, since the virtual machine is a software module running on the host 100, the disk space releasing apparatus 400 applied to the virtual machine is also stored in the memory 101 of the host 100 and executed by the processor 103 of the host 100.
First embodiment
Referring to fig. 2, fig. 2 shows a flowchart of a disk space releasing method applied to host 100 according to the present disclosure. The method comprises the following steps:
step S101, receiving a disk space release command.
In this disclosure, for the host 100, a virtual machine is an application program run on the host 100, multiple virtual machines may run on one host 100, a disk of the virtual machine is a file in a preset format stored on a disk of the host 100, a virtual machine may have multiple disks, each disk corresponds to a file in a preset format on a disk of the host 100, and each disk may be divided into one or more disk partitions, for example, two virtual machines run on the host 100: vm1 and vm2, where vm1 has 3 disks, which are respectively a 1# disk, a 2# disk and a 3# disk, vm2 has 2 disks, which are respectively a 4# disk and a 5# disk, each disk is divided into one disk partition, and then vm1 has 3 disk partitions, which are respectively a 1# disk partition, a 2# disk partition and a 3# disk partition, and vm2 has 2 disk partitions, which are respectively a 4# disk partition and a 5# disk partition. The user may release the disk space corresponding to the partition of the specified disk of the specified virtual machine according to a specific requirement in different formats of the disk space release command, for example, the user may release the disk space corresponding to all the disk partitions on all the virtual machines on the host 100, may release the disk space corresponding to all the disk partitions of one or more virtual machines specified by the host 100, and may release the disk space corresponding to the specified disk partition of the one or more virtual machines specified by the host 100.
It should be noted that, when a file is deleted on a virtual machine, only a deletion flag is made on the file to be deleted, and the file is returned to the user to be successfully deleted, and the disk space of the host 100 occupied by the file to be deleted is not really released.
Step S102, analyzing the disk space release command, generating a command identifier, and generating a plurality of target virtual machines of the disk space to be released and a target disk partition corresponding to each target virtual machine.
In this disclosure, in order to simplify user operations, the disk space release command may not include all virtual machines and corresponding disk partitions that need to release the disk partition, and the user may use different formats of the disk space release command according to different disk space release requirements, and the host 100 generates a corresponding command identifier, a plurality of target virtual machines to release the disk space, and a target disk partition corresponding to each target virtual machine by analyzing the disk space release commands in different formats, and then sends the command identifier and the corresponding target disk partition to the target virtual machine, so as to achieve a purpose that the target virtual machine releases the disk space on the corresponding target disk partition.
Specifically, analyzing the disk space release command, generating a command identifier, and generating a plurality of target virtual machines of the disk space to be released and a target disk partition corresponding to each target virtual machine may include at least the following three situations: (1) When the disk space release command does not include the identifier of the virtual machine and the disk partition of the virtual machine corresponding to the identifier of the virtual machine, firstly, acquiring the identifier of each virtual machine and the disk partition of the virtual machine corresponding to the identifier of each virtual machine, and then determining the virtual machine corresponding to the identifier of each virtual machine as a target virtual machine and the disk partition corresponding to each target virtual machine as a target disk partition corresponding to each target virtual machine; (2) When the disk space release command includes the identifier of the virtual machine but does not include the disk partition of the virtual machine corresponding to the identifier of the virtual machine, firstly, acquiring the disk partition of the virtual machine corresponding to the identifier of the virtual machine, then determining the virtual machine corresponding to the identifier of the virtual machine as a target virtual machine and determining the disk partition corresponding to the virtual machine as a target disk partition corresponding to the target virtual machine; (3) When the disk space release command comprises the identifier of the virtual machine and the disk partition of the virtual machine corresponding to the identifier of the virtual machine, determining the virtual machine corresponding to the identifier of the virtual machine as a target virtual machine and determining the disk partition of the virtual machine corresponding to the identifier of the virtual machine as a target disk partition corresponding to the target virtual machine.
In this disclosure, the disk space release command may include only a command identifier, may also include both a command identifier and a virtual machine identifier, and may also include a command identifier, a virtual machine identifier, and a corresponding target disk partition.
In the present disclosure, the command identifier is a unique flag of the command, and may be a string of specific character strings defined by the program developer, for example, the command identifier is defined as host-fstrim. Because the commands provided by the operating system or the disk tool are not flexible enough and not automatic enough, different steps are required to be executed to achieve corresponding effects under different requirements, in order to unify scenes with different actual requirements of users and simplify the operation of the users, the method encapsulates the commands provided by the operating system or the disk tool again, provides a unified command identifier for the outside, analyzes the command according to a command format with the command identifier input by the users, and uses one command to achieve the effects of different actual requirement scenes. For example, the fstrim is a command provided by a disk tool and used for organizing disk spaces, the command for executing the fstrim needs to specify one or more disk partition names in the disk spaces to be organized, if all redundant spaces in one disk need to be released, the command for executing the fstrim needs to be executed once in sequence for all the disk partitions in the disk, in the disclosure, the fstrim command is encapsulated again, a uniform command identification host-fstrim is provided externally, the corresponding relationship between the command identification host-fstrim and the fstrim is stored in advance in a virtual machine, when a user needs to release the redundant spaces in all the disks, the host-fstrim only needs to be input in a command format, all the disk partition names in all the disks do not need to be input, the command corresponding to the host-trim analyzes the command format input by the user, the command corresponding to the user does not specify the disk partition names in the disk according to the pre-stored finding, the command for automatically acquiring all the disk partitions is acquired, then the command identification host-trim is sent to the virtual machine, the command for executing the virtual partition corresponding to the virtual disk space, and the virtual command for executing the virtual partition.
It should be noted that, in the present disclosure, the command identifier may also be a command name, where the command name is a name of a command provided by an operating system or a disk tool, and the command name corresponds to a disk space arrangement command actually executed on the virtual machine, at this time, the host 100 stores a correspondence between a command keyword of a disk space release command and the command name in advance, extracts the command keyword in the character string according to the character string of the input disk space release command, then determines a command name corresponding to the disk space release command according to the correspondence between the command keyword of the disk space release command and the command name stored in advance, and then sends the command name to the virtual machine, so that the virtual machine executes a command corresponding to the corresponding command name to release the disk space of the target disk partition.
Referring to fig. 3, step S102 further includes the following sub-steps:
and a substep S1021, when the disk space release command does not include the identifier of the virtual machine and the disk partition of the virtual machine corresponding to the identifier of the virtual machine, acquiring the identifier of each virtual machine stored in advance and the disk partition of the virtual machine corresponding to the identifier of each virtual machine.
In this disclosure, the identifier of the virtual machine is a unique identifier representing the virtual machine, the identifier of the virtual machine may be a unique name or a unique number representing the virtual machine, and when a user needs to release each virtual machine and each disk of each virtual machine on the host 100, the format of the disk release command input by the user may include only the command identifier, but does not include the identifier of the virtual machine and the disk partition of the virtual machine corresponding to the identifier of the virtual machine, at this time, the host 100 may first obtain the identifier of each virtual machine, and then obtain each disk partition of the virtual machine corresponding to the identifier of each virtual machine. For example, host 100 has two virtual machines running thereon: vm1 and vm2, where vm1 has 3 disks, each disk corresponds to a disk partition, which is a 1# disk partition, a 2# disk partition, and a 3# disk partition, vm2 has 2 disks, each disk corresponds to a disk partition, which is a 4# disk partition and a 5# disk partition, respectively, and the command format input by the user is: host-fstrim, that is, the user does not specify the identifier of the virtual machine and the disk partition of the virtual machine corresponding to the identifier of the virtual machine, the host 100 may first obtain the identifier of the virtual machine: vm1 and vm2 respectively acquire a 1# disk partition, a 2# disk partition and a 3# disk partition corresponding to vm1, and then respectively acquire a 4# disk partition and a 5# disk partition corresponding to vm 2.
In sub-step S1022, the virtual machine corresponding to the identifier of each virtual machine is determined as the target virtual machine, and the disk partition corresponding to each target virtual machine is determined as the target disk partition corresponding to each target virtual machine.
In the present disclosure, the command format input by the user does not include the identifier of the virtual machine and the disk partition of the virtual machine corresponding to the identifier of the virtual machine, where the command format means that the disk space to be released is each disk partition of each virtual machine on the host 100, that is, the target virtual machine is each virtual machine on the host 100, and each disk partition on each virtual machine is the target disk partition corresponding to the target virtual machine. For example, the command format entered by the user is: a host-fstrim, namely, a user does not specify an identifier of a virtual machine and a disk partition of the virtual machine corresponding to the identifier of the virtual machine, the virtual machine has two vm1 and vm2, vm1 has 2 disks, and the corresponding disk partitions are respectively a 1# disk partition/dev/hda 1 and a 2# disk partition/dev/hda 2; vm2 has 2 disks, and the corresponding disk partitions are 3# disk partition/dev/hda 34# disk partition/dev/hda 4, respectively, so that the target virtual machine has two: vm1 and vm2, and the target disk partition corresponding to the target virtual machine vm1 is: the target disk partitions corresponding to the target virtual machines vm2 are as follows: and the characteristic is that the disk space on the disk corresponding to the disk partition of the vv 1 virtual machine/dev/hda 1 and/dev/hda 2 needs to be released, and the disk space on the disk corresponding to the disk partition of the vm2 virtual machine/dev/hda 3 and/dev/hda 4 needs to be released.
In the sub-step S1023, when the disk space release command includes the identifier of the virtual machine but does not include the disk partition of the virtual machine corresponding to the identifier of the virtual machine, the disk partition of the virtual machine corresponding to the identifier of the virtual machine stored in advance is acquired.
In this disclosure, when a user needs to release each disk partition of a specified virtual machine, the format of the input disk space release command needs to include the identifier of the virtual machine, but not include the disk partition corresponding to the identifier of the virtual machine, and at this time, the host 100 automatically obtains each disk partition of the virtual machine corresponding to the identifier of the virtual machine.
And a substep S1024 of determining the virtual machine corresponding to the identifier of the virtual machine as a target virtual machine and determining the disk partition corresponding to the virtual machine as a target disk partition corresponding to the target virtual machine.
In the present disclosure, when the disk partition of the target virtual machine is one, there is only one target disk partition, and when there are multiple disk partitions of the target virtual machine, there are multiple target disk partitions, for example, the virtual machine vm1 has 2 disks, each disk corresponds to one disk partition, which corresponds to the 1# disk partition and the 2# disk partition, respectively, the names of the corresponding disk partitions are/dev/hda 1 and/dev/hda 2, and the command format input by the user is: host-fstrim-m vm1, that is, the command format input by the user includes the identifier vm1 of the virtual machine, but does not include the disk partition of the virtual machine vm1, then the target disk partition has 2: and/dev/hda 1,/dev/hda 2.
In sub-step S1025, when the disk space release command includes the identifier of the virtual machine and the disk partition of the virtual machine corresponding to the identifier of the virtual machine, determining the virtual machine corresponding to the identifier of the virtual machine as the target virtual machine, and determining the disk partition of the virtual machine corresponding to the identifier of the virtual machine as the target disk partition corresponding to the target virtual machine.
In the present disclosure, the command format of the disk space release command may include identifiers of a plurality of virtual machines and a disk partition of the virtual machine corresponding to the identifier of each virtual machine, for example, the virtual machine has two vm1 and vm2, vm1 has 2 disks, each disk corresponds to a partition, which is a # 1 disk and a # 2 disk, respectively, and the corresponding disk partition is/dev/hda 1 and/dev/hda 2; vm2 has 2 disks, which are respectively a 3# disk and a 4# disk, the corresponding disk partition is/dev/hda 3 and/dev/hda 4, and the command format input by the user is as follows: host-fstrim-m vm1vm2/dev/hda2/dev/hda3, that is, the user designates the virtual machine vm1, and designates the disk space corresponding to the disk partition/dev/hda 2 of the released virtual machine vm1, and designates the virtual machine vm2, and designates the disk space corresponding to the disk partition/dev/hda 3 of the released virtual machine vm2, then the target virtual machine has two: vm1 and vm2, the target disk partition of the target virtual machine vm1 is/dev/hda 2, and the target disk partition of the target virtual machine vm2 is/dev/hda 3.
Step S103, encapsulating the command identification and the target disk partition corresponding to each target virtual machine into a plurality of disk space release messages according to a preset format.
In this disclosure, as an implementation manner, the preset format may be a JSON object format, and when the target disk partition is multiple, the disk space release message encapsulated by the command identifier and the target disk partition is also multiple, for example, the disk space release message encapsulated by the command identifier and the target disk partition according to the JSON object format is: the method comprises the steps of { "execute": fstrim "," attributes ": {" message ":"/dev/hda2 "}), wherein fstrim is a command identifier, and/dev/hda 2 is a target disk partition.
And step S104, sending the plurality of disk space release messages to the target virtual machine so that the corresponding target virtual machine can call a preset disk space sorting command to release the disk space of the corresponding target virtual machine based on the corresponding disk space release messages.
In the present disclosure, in order to implement that the host 100 sends a plurality of disk space release messages to the target virtual machine, the host 100 and the target virtual machine interact with each other through Qemu-ga (Qemu Guest Agent), where Qemu-ga is a common application program (executable file name default is Qemu-ga, service name default is Qemu-Guest Agent) running inside the virtual machine, and the purpose is to implement message interaction between the host 100 and the target virtual machine without depending on a network.
As one implementation, sending the disk space release message to the virtual machine may be accomplished by executing a virshqemu-agent-command provided by qemu-ga on the host 100, for example, executing a command:
virshqemu-agent-command vm1--cmd
'{"execute":"fstrim","arguments":{"message":"/dev/hda2"}}'。
and sending the command identifier fstrim and the target disk partition/dev/hda 2 to the virtual machine vm1, and calling a preset disk space tidying command fstrim by the virtual machine vm1 to release the disk space corresponding to the disk partition/dev/hda 2.
In the disclosure, the qemu-ga running on the host 100 is responsible for encapsulating the command identifier and the target disk partition into a disk space release message according to a preset format and then sending the disk space release message to the target virtual machine, the qemu-ga running on the target virtual machine is responsible for receiving and decapsulating the disk space release message to obtain the command identifier and the target disk partition, and finally calling a preset disk space tidying command to release the disk space of the target disk partition of the target virtual machine according to the command identifier and the target disk partition, so the disclosure further includes step S201 and step S202.
Referring to fig. 4, fig. 4 is a flowchart illustrating a qemu-ga based disk space releasing method applied to a virtual machine according to the present disclosure.
Step S201, receiving a disk space release message sent by the host, where the disk space release message is formed by the host encapsulating the command identifier and the target disk partition according to a preset format, and the command identifier, the target disk partition, and the target virtual machine are generated after the host analyzes the disk space release command.
Step S202, a preset disk space tidying command is called to release the disk space of the target virtual machine based on the disk space release message.
In this disclosure, the implementation manner of invoking the preset disk space arrangement command based on the disk space release message may be:
firstly, decapsulating a disk space release message to obtain a command identifier and a target disk partition;
and secondly, executing a command corresponding to the command identifier based on the target disk partition so as to call a preset disk space finishing command to release the disk space of the target disk partition of the target virtual machine.
In the present disclosure, after the command identifier and the target disk partition are obtained by the qemu-ga running on the target virtual machine, the disk space of the target disk partition may be released by calling a preset disk space arrangement command corresponding to the command identifier.
It should be noted that one disk of the virtual machine may also correspond to multiple disk partitions, and the redundant storage space of the disk corresponding to one disk partition may be released by using a disk space arrangement command for the disk partition, so that the redundant storage space occupied by the virtual machine on the host 100 is released.
In the disclosure, by performing unified operation on the host 100, the command identifier of the disk space release command and the disk partition corresponding to the target virtual machine to release the disk space are sent to the target virtual machine through the qemu-ga operated by the host 100, and the qemu-ga operated by the target virtual machine executes the corresponding disk space arrangement command according to the command identifier and the disk partition corresponding to the target virtual machine, so as to release the redundant storage space in the disk partitions of multiple virtual machines at the same time, which has the following beneficial effects compared with the prior art:
firstly, since the virtual machine does not need to be accessed for operation, the disk space of the virtual machine can be released by executing the command on the host machine 100, so that the efficiency of releasing the redundant disk space in the disk partition of the virtual machine is improved, and finally, the efficient release of the redundant space on the corresponding host machine 100 is realized.
Secondly, the release of the disk spaces of all the virtual machines on the host 100 and the release of the disk spaces of all the disks of the designated virtual machines in batch can be realized by adopting one command, so that the operation of a user is greatly simplified.
Thirdly, different requirements of users are realized by adopting different command formats, and the flexibility of disk space release is improved.
Second embodiment
Referring to fig. 5, fig. 5 is a block diagram illustrating a disk space releasing apparatus 200 applied to a host according to the present disclosure, where the disk space releasing apparatus 200 applied to a host includes a command receiving module 201, a parsing module 202, an encapsulating module 203, and a sending module 204.
A command receiving module 201, configured to receive a disk space release command.
In the present disclosure, the command receiving module 201 is used to execute step S101.
The parsing module 202 is configured to parse the disk space release command, generate a command identifier, and generate a plurality of target virtual machines of the disk space to be released and a target disk partition corresponding to each target virtual machine.
In the present disclosure, the parsing module 202 is used to perform step S102 and its sub-steps S1021-S1025.
And the encapsulating module 203 is configured to encapsulate the command identifier and the target disk partition corresponding to each target virtual machine into a plurality of disk space release messages according to a preset format.
In the present disclosure, the encapsulation module 203 is configured to perform step S103.
The sending module 204 is configured to send the multiple disk space release messages to the corresponding target virtual machines, so that the corresponding target virtual machines call a preset disk space arrangement command to release the disk spaces of the corresponding target virtual machines based on the corresponding disk space release messages.
In the present disclosure, the sending module 204 is configured to execute step S104.
Referring to fig. 6, fig. 6 shows a block schematic diagram of a disk space releasing apparatus 400 applied to a virtual machine according to the present disclosure, where the disk space releasing apparatus 400 applied to a virtual machine includes a message receiving module 401 and a releasing module 402.
The message receiving module 401 is configured to receive a disk space release message sent by a host, where the disk space release message is formed by the host encapsulating a command presentation meeting and a target disk partition according to a preset format, and the command identifier, the target disk partition, and the target virtual machine are generated after the host parses the disk space release command.
In the present disclosure, the message receiving module 401 is configured to execute step S201.
A releasing module 402, configured to invoke a preset disk space tidying command to release the disk space of the target virtual machine based on the disk space releasing message.
As an embodiment, the releasing module 402 is further configured to:
decapsulating the disk space release message to obtain a command identifier and a target disk partition;
and executing a command corresponding to the command identifier based on the target disk partition so as to call a preset disk space sorting command to release the disk space of the target disk partition of the target virtual machine.
In the present disclosure, the releasing module 402 is used to execute step S202.
In summary, the method and apparatus for releasing disk space provided by the present disclosure, which are applied to a host, include: receiving a disk space release command; analyzing a disk space release command, generating a command identifier, a plurality of target virtual machines of a disk space to be released and a target disk partition corresponding to each target virtual machine; encapsulating the command identifier and the target disk partition corresponding to each target virtual machine into a plurality of disk space release messages according to a preset format; and sending the plurality of disk space release messages to the corresponding target virtual machines so that the corresponding target virtual machines call a preset disk space arrangement command to release the disk spaces of the corresponding target virtual machines based on the corresponding disk space release messages. Compared with the prior art, the method and the device have the advantages that the target disk partition of the disk space to be released can be sent to the corresponding target virtual machine by executing the unified disk space release command on the host machine, so that the aim of simultaneously releasing redundant storage space in the target disk partitions of the target virtual machines is fulfilled, and the efficiency of releasing the redundant disk space in the target disk partition of the target virtual machine is greatly improved.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method can be implemented in other ways. The apparatus embodiments described above are merely illustrative and, for example, the flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, functional modules in the embodiments of the present disclosure may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present disclosure may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present disclosure. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes. It should be noted that, in this document, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising one of 8230; \8230;" 8230; "does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises the element.
The above description is only a preferred embodiment of the present disclosure and is not intended to limit the present disclosure, and various modifications and changes may be made to the present disclosure by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present disclosure should be included in the protection scope of the present disclosure. It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined or explained in subsequent figures.

Claims (7)

1. A disk space release method is characterized by being applied to a host machine, wherein the host machine runs a plurality of virtual machines, one virtual machine has a plurality of disks, each disk is divided into one or a plurality of disk partitions, and the host machine stores an identifier of each virtual machine and the disk partition of the virtual machine corresponding to the identifier of each virtual machine in advance; the method comprises the following steps:
receiving a disk space release command; the disk space release commands in different formats are generated according to the requirements of users, and the disk space release commands in different formats are used for releasing the disk space corresponding to the specified disk partition of the specified virtual machine;
analyzing the disk space release command, generating a command identifier, a plurality of target virtual machines of the disk space to be released and a target disk partition corresponding to each target virtual machine;
encapsulating the command identifier and the target disk partition corresponding to each target virtual machine into a plurality of disk space release messages according to a preset format;
sending the plurality of disk space release messages to corresponding target virtual machines so that the corresponding target virtual machines call a preset disk space arrangement command to release the disk spaces of the corresponding target virtual machines based on the corresponding disk space release messages;
the step of analyzing the disk space release command to generate a plurality of target virtual machines of the disk space to be released and a target disk partition corresponding to each target virtual machine further includes:
when the disk space release command does not include the identifier of the virtual machine and the disk partition of the virtual machine corresponding to the identifier of the virtual machine, acquiring the identifier of each virtual machine stored in advance and the disk partition of the virtual machine corresponding to the identifier of each virtual machine;
determining a virtual machine corresponding to the identifier of each virtual machine as the target virtual machine, and determining a disk partition corresponding to each target virtual machine as a target disk partition corresponding to each target virtual machine;
alternatively, the first and second electrodes may be,
when the disk space release command comprises the identification of a virtual machine but does not comprise the disk partition of the virtual machine corresponding to the identification of the virtual machine, acquiring the disk partition of the virtual machine corresponding to the pre-stored identification of the virtual machine;
determining a virtual machine corresponding to the identifier of the virtual machine as the target virtual machine, and determining a disk partition corresponding to the virtual machine as a target disk partition corresponding to the target virtual machine;
alternatively, the first and second electrodes may be,
when the disk space release command comprises the identification of the virtual machine and the disk partition of the virtual machine corresponding to the identification of the virtual machine, determining the virtual machine corresponding to the identification of the virtual machine as a target virtual machine, and determining the disk partition of the virtual machine corresponding to the identification of the virtual machine as a target disk partition corresponding to the target virtual machine.
2. A disk space release method is applied to virtual machines running on a host machine, one virtual machine is provided with a plurality of disks, each disk is divided into one or a plurality of disk partitions, and the method comprises the following steps:
receiving a disk space release message sent by the host, wherein the disk space release message is formed by encapsulating a command identifier and a target disk partition according to a preset format by the host, and the command identifier, the target disk partition and a target virtual machine are generated after the host analyzes a disk space release command; the disk space release commands in different formats are generated according to the requirements of users, and the disk space release commands in different formats are used for releasing the disk space corresponding to the specified disk partition of the specified virtual machine;
calling a preset disk space arrangement command to release the disk space of the target virtual machine based on the disk space release message;
the host machine analyzes the disk space release command, and the process of generating a plurality of target virtual machines of the disk space to be released and a target disk partition corresponding to each target virtual machine comprises the following steps:
when the disk space release command does not include the identifier of the virtual machine and the disk partition of the virtual machine corresponding to the identifier of the virtual machine, the host machine acquires the identifier of each virtual machine which is stored in advance and the disk partition of the virtual machine corresponding to the identifier of each virtual machine, determines the virtual machine corresponding to the identifier of each virtual machine as the target virtual machine, and determines the disk partition corresponding to each target virtual machine as the target disk partition corresponding to each target virtual machine;
alternatively, the first and second electrodes may be,
when the disk space release command includes an identifier of a virtual machine but does not include a disk partition of the virtual machine corresponding to the identifier of the virtual machine, the host acquires the disk partition of the virtual machine corresponding to the identifier of the virtual machine stored in advance, determines the virtual machine corresponding to the identifier of the virtual machine as the target virtual machine, and determines the disk partition corresponding to the virtual machine as the target disk partition corresponding to the target virtual machine
Alternatively, the first and second electrodes may be,
when the disk space release command comprises the identification of the virtual machine and the disk partition of the virtual machine corresponding to the identification of the virtual machine, the host machine determines the virtual machine corresponding to the identification of the virtual machine as a target virtual machine and determines the disk partition of the virtual machine corresponding to the identification of the virtual machine as a target disk partition corresponding to the target virtual machine.
3. The method for releasing disk space according to claim 2, wherein the step of invoking a preset disk space reorganization command to release disk space of the target virtual machine based on the disk space release message includes:
decapsulating the disk space release message to obtain the command identifier and the target disk partition;
and executing a command corresponding to the command identifier based on the target disk partition so as to call a preset disk space sorting command to release the disk space of the target disk partition of the target virtual machine.
4. A disk space releasing device is characterized by being applied to a host machine, wherein at least one virtual machine runs on the host machine, one virtual machine is provided with a plurality of disks, each disk is divided into one or a plurality of disk partitions, and the host machine stores an identifier of each virtual machine and the disk partition of the virtual machine corresponding to the identifier of each virtual machine in advance; the device comprises:
the command receiving module is used for receiving a disk space releasing command; the disk space releasing commands in different formats are generated according to the requirements of users, and the disk space releasing commands in different formats are used for releasing the disk space corresponding to the specified disk partition of the specified virtual machine;
the analysis module is used for analyzing the disk space release command, generating a command identifier, a plurality of target virtual machines of the disk space to be released and a target disk partition corresponding to each target virtual machine;
the encapsulation module is used for encapsulating the command identifier and the target disk partition corresponding to each target virtual machine into a plurality of disk space release messages according to a preset format;
the sending module is used for sending the plurality of disk space release messages to corresponding target virtual machines so that the corresponding target virtual machines call a preset disk space arrangement command to release the disk spaces of the corresponding target virtual machines based on the corresponding disk space release messages;
the analysis module is specifically configured to:
when the disk space release command does not comprise the identification of the virtual machine and the disk partition of the virtual machine corresponding to the identification of the virtual machine, acquiring the pre-stored identification of each virtual machine and the disk partition of the virtual machine corresponding to the identification of each virtual machine;
determining a virtual machine corresponding to the identifier of each virtual machine as the target virtual machine, and determining a disk partition corresponding to each target virtual machine as a target disk partition corresponding to each target virtual machine;
alternatively, the first and second electrodes may be,
when the disk space release command comprises the identification of the virtual machine but does not comprise the disk partition of the virtual machine corresponding to the identification of the virtual machine, acquiring the disk partition of the virtual machine corresponding to the pre-stored identification of the virtual machine;
determining a virtual machine corresponding to the identifier of the virtual machine as the target virtual machine, and determining a disk partition corresponding to the virtual machine as a target disk partition corresponding to the target virtual machine
Alternatively, the first and second liquid crystal display panels may be,
when the disk space release command comprises the identification of the virtual machine and the disk partition of the virtual machine corresponding to the identification of the virtual machine, determining the virtual machine corresponding to the identification of the virtual machine as a target virtual machine, and determining the disk partition of the virtual machine corresponding to the identification of the virtual machine as a target disk partition corresponding to the target virtual machine.
5. A disk space releasing device is characterized in that the device is applied to virtual machines running on a host machine, one virtual machine is provided with a plurality of disks, each disk is divided into one or a plurality of disk partitions, and the device comprises:
the message receiving module is used for receiving a disk space release message sent by the host, wherein the disk space release message is formed by encapsulating a command identifier and a target disk partition according to a preset format by the host, and the command identifier, the target disk partition and a target virtual machine are generated after the host analyzes a disk space release command; the disk space release commands in different formats are generated according to the requirements of users, and the disk space release commands in different formats are used for releasing the disk space corresponding to the specified disk partition of the specified virtual machine;
the release module is used for calling a preset disk space tidying command to release the disk space of the target virtual machine based on the disk space release message;
the host machine analyzes the disk space release command, and the process of generating a plurality of target virtual machines of the disk space to be released and a target disk partition corresponding to each target virtual machine comprises the following steps:
when the disk space release command does not include the identifier of the virtual machine and the disk partition of the virtual machine corresponding to the identifier of the virtual machine, the host machine acquires the identifier of each virtual machine stored in advance and the disk partition of the virtual machine corresponding to the identifier of each virtual machine, determines the virtual machine corresponding to the identifier of each virtual machine as the target virtual machine, and determines the disk partition corresponding to each target virtual machine as the target disk partition corresponding to each target virtual machine;
alternatively, the first and second liquid crystal display panels may be,
when the disk space release command includes the identifier of the virtual machine but does not include the disk partition of the virtual machine corresponding to the identifier of the virtual machine, the host machine acquires the disk partition of the virtual machine corresponding to the identifier of the virtual machine stored in advance, determines the virtual machine corresponding to the identifier of the virtual machine as the target virtual machine, and determines the disk partition corresponding to the virtual machine as the target disk partition corresponding to the target virtual machine
Alternatively, the first and second liquid crystal display panels may be,
when the disk space release command comprises the identification of the virtual machine and the disk partition of the virtual machine corresponding to the identification of the virtual machine, the host machine determines the virtual machine corresponding to the identification of the virtual machine as a target virtual machine and determines the disk partition of the virtual machine corresponding to the identification of the virtual machine as a target disk partition corresponding to the target virtual machine.
6. A host machine, the host machine comprising:
a processor;
memory to store one or more programs that, when executed by the processor, cause the processor to implement the method of claim 1 or any of claims 2-3.
7. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to claim 1 or any one of claims 2-3.
CN201910093758.7A 2019-01-30 2019-01-30 Disk space releasing method and device Active CN109857343B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910093758.7A CN109857343B (en) 2019-01-30 2019-01-30 Disk space releasing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910093758.7A CN109857343B (en) 2019-01-30 2019-01-30 Disk space releasing method and device

Publications (2)

Publication Number Publication Date
CN109857343A CN109857343A (en) 2019-06-07
CN109857343B true CN109857343B (en) 2023-02-07

Family

ID=66896930

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910093758.7A Active CN109857343B (en) 2019-01-30 2019-01-30 Disk space releasing method and device

Country Status (1)

Country Link
CN (1) CN109857343B (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101727456A (en) * 2008-10-24 2010-06-09 国际商业机器公司 Disk physical block allocation method for host machine system with virtual machine and equipment
CN101986285A (en) * 2010-11-03 2011-03-16 华为技术有限公司 Virtual machine storage space management method, system and physical host
CN104050045A (en) * 2014-06-27 2014-09-17 华为技术有限公司 Method and device for distributing virtual resources based on disk IO
CN104572242A (en) * 2013-10-24 2015-04-29 华为技术有限公司 Method and device for expanding disk space of virtual machine and virtual machine system
CN105573819A (en) * 2015-12-11 2016-05-11 国云科技股份有限公司 Method for obtaining disk capacity information of virtual machine directly through host machine

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016171738A1 (en) * 2015-04-23 2016-10-27 Hewlett Packard Enterprise Development Lp Storage reclamation in a thin provisioned storage device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101727456A (en) * 2008-10-24 2010-06-09 国际商业机器公司 Disk physical block allocation method for host machine system with virtual machine and equipment
CN101986285A (en) * 2010-11-03 2011-03-16 华为技术有限公司 Virtual machine storage space management method, system and physical host
CN104572242A (en) * 2013-10-24 2015-04-29 华为技术有限公司 Method and device for expanding disk space of virtual machine and virtual machine system
CN104050045A (en) * 2014-06-27 2014-09-17 华为技术有限公司 Method and device for distributing virtual resources based on disk IO
CN105573819A (en) * 2015-12-11 2016-05-11 国云科技股份有限公司 Method for obtaining disk capacity information of virtual machine directly through host machine

Also Published As

Publication number Publication date
CN109857343A (en) 2019-06-07

Similar Documents

Publication Publication Date Title
WO2018077085A1 (en) Application processing method, device and storage medium
CN107515776A (en) The uninterrupted upgrade method of business, node to be upgraded and readable storage medium storing program for executing
US9244720B2 (en) Automated technique to configure and provision components of a converged infrastructure
US11403146B2 (en) Method, apparatus, and server for managing image across cloud servers
US11699073B2 (en) Network off-line model processing method, artificial intelligence processing device and related products
CN103970563B (en) The method of dynamic load Android class
JP2018537783A (en) Run the application using pre-generated components
CN102402446A (en) Method and device for installing application software
CN109995814B (en) Cloud host resource migration method and device, communication equipment and storage medium
CN105354498A (en) Operation method of registry, related device and equipment
CN111343181A (en) Message processing method and system, data pool and computer readable storage medium
CN108804100B (en) Method and device for creating interface element, storage medium and mobile terminal
US10031764B2 (en) Managing executable files
CN110727429A (en) Front-end page generation method, device and equipment
CN109857343B (en) Disk space releasing method and device
EP3193253A1 (en) Method, apparatus and system for displaying names of virtual machine
CN108234174B (en) Management method and device of virtual network function
CN111310638A (en) Data processing method and device and computer readable storage medium
CN108920246B (en) Form draft component sharing method and device, terminal device and readable storage medium
CN116521181A (en) Script data processing method, device, equipment and medium based on game system
CN109656674B (en) Computer equipment, virtualization chip and data transmission method
WO2020006911A1 (en) Hybrid app interface calling method and device, and computer-readable storage medium
CN114911541A (en) Configuration information processing method and device, electronic equipment and storage medium
CN109918147B (en) Expansion method and device for drive under OpenStack and electronic equipment
CN112764802A (en) Business logic customization method and device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant