Disclosure of Invention
In order to solve the above problems, the present invention provides a method and an apparatus for implementing compatibility of a container host and a virtual host image file.
In a first aspect, the present invention provides a method for implementing compatibility of a container host with a virtual host image file, where the method includes:
mapping the virtual host image file into a virtual hard disk by using a first operation instruction;
mapping all files in the virtual hard disk to a first folder of the host machine by using a second operation instruction, wherein the first folder is any folder of the host machine;
acquiring an operating system file of the virtual host from the first folder;
the container host is started using the operating system file of the virtual host.
The invention has the beneficial effects that: the virtual host mirror image file is mapped into a virtual hard disk, and then all files in the virtual hard disk are mapped into a first folder of a host. And taking the first folder as a root directory of the container host, acquiring the operating system file of the virtual host from the first folder, and starting the container host by using the operating system file of the virtual host. In the process, the container host can be compatible with the image file of the virtual host, and can execute corresponding action after being started.
Further, after mapping all the files in the virtual hard disk to the first folder of the host machine by using the second operation instruction, the method further includes:
mapping the service data file corresponding to the container host to a second folder of the host;
creating a combined file system according to the files in the first folder and the files in the second folder;
acquiring an operating system file of the virtual host from the combined file system;
and starting the container host according to the operating system file of the virtual host, wherein the second folder is any folder except the first folder in the host.
The beneficial effect of adopting the further scheme is that: after all the files in the virtual hard disk are mapped to the first folder of the host machine by using the second operation instruction, the service data of the container host machine can be mapped to the second folder of the host machine. And, from the files in the first folder and the files in the second folder, a federated file system is created. And further acquiring the operating system file of the virtual host from the combined file system, and starting the container host by using the operating system file of the virtual host. And the container host uses the combined file system, so that the better performance of the container host can be ensured.
Further, the combined file system comprises an upper storage path and a lower storage path, wherein the lower storage path is used for storing files of the first folder, and the upper storage path is used for storing files of the second folder.
The beneficial effect of adopting the further scheme is that: it has been briefly stated in the further above that the use of a federated file system by a container host may result in better performance of the container host. The combined file system includes an upper storage path and a lower storage path, where the upper storage path is used for storing data files of the second folder, that is, data files corresponding to the container host; and the lower layer stores the mirror image of the virtual host. The upper layer may be used for reading/writing files and the lower layer may be used for reading files only. The aim is that reading or writing at the upper layer can be adapted to different capabilities of different container hosts. And the lower layer is read only, so as to ensure that the mirror image file of the virtual host is not changed.
Further, when the container host is started, the method further comprises:
the federated file system is mapped to the root folder of the container host so that the software in the container host shares the files in the root folder.
The beneficial effect of adopting the further scheme is that: in the process of starting the container host, the first folder or the second folder, that is, the folder to which the virtual host image file is mapped, can be used as the root folder of the container host, so that all software in the container host can directly access all files in the root folder of the container host and perform corresponding processing.
In a second aspect, the present invention provides an apparatus for enabling a container host to be compatible with a virtual host image file, where the apparatus includes:
the processing unit is used for mapping the virtual host image file into a virtual hard disk by using a first operation instruction;
mapping all files in the virtual hard disk to a first folder of the host machine by using a second operation instruction, wherein the first folder is any folder of the host machine;
acquiring an operating system file of the virtual host from the first folder;
and the starting unit is used for starting the container host by utilizing the operating system file of the virtual host.
The invention has the beneficial effects that: the virtual host mirror image file is mapped into a virtual hard disk, and then all files in the virtual hard disk are mapped into a first folder of a host. And taking the first folder as a root directory of the container host, acquiring the operating system file of the virtual host from the first folder, and starting the container host by using the operating system file of the virtual host. In the process, the container host can be compatible with the image file of the virtual host, and can execute corresponding action after being started.
Further, the processing unit is further configured to:
mapping the service data file corresponding to the container host to a second folder of the host;
creating a combined file system according to the files in the first folder and the files in the second folder;
acquiring an operating system file of the virtual host from the combined file system;
the starting unit is used for starting the container host according to the operating system file of the virtual host, wherein the second folder is any folder except the first folder in the host.
The beneficial effect of adopting the further scheme is that: after all the files in the virtual hard disk are mapped to the first folder of the host machine by using the second operation instruction, the service data of the container host machine can be mapped to the second folder of the host machine. And, from the files in the first folder and the files in the second folder, a federated file system is created. And further acquiring the operating system file of the virtual host from the combined file system, and starting the container host by using the operating system file of the virtual host. And the container host uses the combined file system, so that the better performance of the container host can be ensured.
Furthermore, the combined file system comprises an upper storage path and a lower storage path, wherein the lower storage path is used for storing files of the first folder, and the upper storage path is used for storing files of the second folder.
The beneficial effect of adopting the further scheme is that: it has been briefly stated in the further above that the use of a federated file system by a container host may result in better performance of the container host. The combined file system includes an upper storage path and a lower storage path, where the upper storage path is used for storing data files of the second folder, that is, data files corresponding to the container host; and the lower layer stores the mirror image of the virtual host. The upper layer may be used for reading/writing files and the lower layer may be used for reading files only. The aim is that reading or writing at the upper layer can be adapted to different capabilities of different container hosts. And the lower layer is read only, so as to ensure that the mirror image file of the virtual host is not changed.
Further, the processing unit is further configured to map the federated file system to a root folder of the container host, so that the software in the container host shares files in the root folder.
The beneficial effect of adopting the further scheme is that: in the process of starting the container host, the first folder or the second folder, that is, the folder to which the virtual host image file is mapped, can be used as the root folder of the container host, so that all software in the container host can directly access all files in the root folder of the container host and perform corresponding processing.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth such as particular system structures, interfaces, techniques, etc. in order to provide a thorough understanding of the present invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
Fig. 1 is a schematic flowchart of a method for implementing compatibility of a container host and a virtual host image file according to an embodiment of the present invention, and specifically as shown in fig. 1, the method includes:
step 110, mapping the virtual host image file to a virtual hard disk by using the first operation instruction.
Specifically, a storage path of the virtual host image file in the host is obtained first. The first operation instruction may be, for example, an instruction of qemu-nbd, and the image file of the virtual host is read from the storage location of the image file of the virtual host in the host by using the first operation instruction, and then is mapped to the virtual hard disk. From the practical application, the I/O operation instruction is mapped to be a read/write operation instruction.
And step 120, mapping all files in the virtual hard disk to a first folder of the host machine by using a second operation instruction, wherein the first folder is any folder of the host machine.
Specifically, all files in the virtual hard disk are mapped to a first folder in the host machine. As shown in step 110, all files in the virtual hard disk are all files aggregated by the virtual host image file, and only are mapped to the virtual hard disk.
In this step, all files in the virtual hard disk are mapped to the first folder in the host machine by using a second operation instruction, for example, a mount instruction. That is, all the files in the virtual hard disk are stored in one folder of the host. And this folder may be any one of the folders in the host.
Step 130, obtaining the operating system file of the virtual host from the first folder.
Specifically, if the container host needs to be compatible with the image file of the virtual host, the container host is actually started by using the operating file system of the virtual host. Therefore, the operating file system of the virtual host is acquired first.
As seen in step 120, the image file of the virtual host has been indirectly mapped to the first folder of the host. Then the operating system files of the virtual host need to be retrieved from the first folder.
Preferably, the image file of the virtual host at least comprises a boot file and an operating system file, wherein the boot file is used for indicating a storage path of the operating system file of the virtual host. When the image file of the virtual host is indirectly mapped into the first folder, the boot file is also mapped into the first folder. The host machine only needs to read the boot file and acquire the operating system file of the virtual machine from the operating system file storage position of the virtual machine according to the instruction of the boot file.
After the operating system file of the virtual host is obtained, step 140 can be executed.
Step 140, the container host is started up using the operating system files of the virtual host.
By the steps, the container host can be compatible with the image file of the virtual host, and the service corresponding to the virtual host can be processed in the container host.
The method for realizing the compatibility of the container host and the virtual host mirror image file provided by the embodiment of the invention maps the virtual host mirror image file into the virtual hard disk, and then maps all files in the virtual hard disk into the first folder of the host. And taking the first folder as a root directory of the container host, acquiring the operating system file of the virtual host from the first folder, and starting the container host by using the operating system file of the virtual host. In the process, the container host can be compatible with the image file of the virtual host, and can execute corresponding action after being started.
However, the performance of the container host in the above scheme may be slightly better than that of the virtual host. In order to improve the performance of the container host, the service is better provided for the user, and the user experience is improved. An embodiment of the present invention further provides another method for implementing compatibility of a container host and a virtual host image file, and as shown in fig. 2 specifically, the method includes the following steps:
step 210, mapping the virtual host image file into a virtual hard disk by using a first operation instruction.
Specifically, a storage path of the virtual host image file in the host is obtained first. The first operation instruction may be, for example, an instruction of qemu-nbd, and the image file of the virtual host is read from the storage location of the image file of the virtual host in the host by using the first operation instruction, and then is mapped to the virtual hard disk. From the practical application, the I/O operation instruction is mapped to be a read/write operation instruction.
Step 220, mapping all files in the virtual hard disk to a first folder of the host machine by using a second operation instruction, wherein the first folder is any folder of the host machine.
Specifically, all files in the virtual hard disk are mapped to a first folder in the host machine. As can be seen from step 210, all files in the virtual hard disk are all files aggregated by the virtual host image file, and are only mapped to the virtual hard disk.
In this step, all files in the virtual hard disk are mapped to the first folder in the host. That is, all the files in the virtual hard disk are stored in one folder of the host. And this folder may be any one of the folders in the host.
Step 230, mapping the service data file corresponding to the container host to a second folder of the host.
Specifically, the service data file corresponding to the host in the container is mapped to a second folder in the host, where the second folder may be any folder in the host except for the first folder. Or may be a newly created folder. The purpose of mapping the service data corresponding to the container host to the second folder is that a user can modify the service data of the container host through the host according to actual needs so as to meet different requirements.
Step 240, a federated file system is created from the files in the first folder and the files in the second folder.
Specifically, a combined file system is created according to files in the first folder and files in the second folder, which is to create a virtual folder in the host that can contain all files in the first folder and the second folder.
And this virtual folder comprises two layers. The upper layer is used for storing files in the second folder, namely business data files corresponding to the container host, and the lower layer is used for storing files in the first folder, namely virtual host image files. The files stored in the upper layer are files which can be read/written, and the files stored in the lower layer are read-only files. The method aims to ensure that a user can randomly change the service data file corresponding to the container host under the condition that the mirror image file is not changed so as to realize different service functions. If the change of the lower storage is needed, the file in the read-only layer is modified by using the copy-on-write technology of the combined file system, the file works on the file level, the file in the read-only layer is modified, and the file is copied to the upper writable layer and then modified. Of course, the upper layer may be set as a readable/writable file according to actual needs, and the lower layer may also be set as a readable/writable file. Or may be arranged in other forms according to actual needs, and is not limited in any way here.
Step 250, starting the container host according to the operating system file of the virtual host.
Further preferably, when the container host is started, the method further includes step 260, mapping the federated file system to a root folder of the container host, so that the software in the container host shares files in the root folder.
Readers will appreciate that the benefits of mapping business data corresponding to a container host to a second folder, rather than mapping an image file to the same folder at the same time, include:
first, the image file may be multiplexed.
Specifically, if the host starts the container host, multiple tasks are executed. The mapped 'mirror files' in the first folder can also be shared, and one 'mirror file' is not needed to be arranged in a one-to-one correspondence mode for each task, so that the storage space is saved.
Second, the service data can be separated from the "mirror image file" and can be managed conveniently.
The container host business data can be added, deleted or changed according to actual needs. Without this affecting the alteration or deletion of the "image file" or the like. Moreover, the 'image file' can update the version at any time without influencing the change of the business data. In short, after separation, each can make changes at any time without affecting the other.
Of course, if the service data to be processed already exists in the virtual host before the image file is mapped to the host, then the service data to be processed by the virtual host and the image file are simultaneously mapped to the first folder. And the second folder is the business data of the container host. The two points above apply equally and do not create any conflict.
The reader should also understand that although some steps of this embodiment are different from those of the previous embodiment, this embodiment can be understood as an "upgraded version" of the previous embodiment, and the performance of the container host can be optimized by using the union file system. An implicit advantage of the two embodiments of the present invention is that the mirror image of the virtual host does not need to be copied to the host, thereby reducing the use of storage space in the host. By utilizing the layer-by-layer mapping relationship, the container host can be compatible with the mirror image file of the virtual host, and the container host is started by utilizing the operating file system of the virtual host. Some of the traffic of the virtual host is handled in the container host.
Corresponding to the two embodiments, an embodiment of the present invention further provides a schematic structural diagram of an apparatus for implementing compatibility of a container host and a virtual host image file, and as shown in fig. 3 specifically, the apparatus includes: a processing unit 301 and a start-up unit 302.
The processing unit 301 is configured to map the virtual host image file into a virtual hard disk by using a first operation instruction; mapping all files in the virtual hard disk to a first folder of the host machine by using a second operation instruction, wherein the first folder is any folder of the host machine; and acquiring the operating system file of the virtual host from the first folder.
Preferably, the first folder includes: a boot file; the boot file is used for indicating a storage path of the operating system file of the virtual host, so that the host acquires the operating system file of the virtual host according to the storage path of the operating system file of the virtual host indicated by the boot file.
A starting unit 302, configured to start the container host by using the operating system file of the virtual host.
Further preferably, the processing unit 301 is further configured to map the service data file corresponding to the container host to a second folder of the host; creating a combined file system according to the files in the first folder and the files in the second folder; and acquiring the operating system file of the virtual host from the joint file system.
The starting unit 302 is configured to start the container host according to the operating system file of the virtual host, where the second folder is any folder in the host except the first folder.
Specifically, the combined file system includes an upper storage path and a lower storage path, where the lower storage path is used to store files of a first folder, and the upper storage path is used to store files of a second folder.
Further preferably, the processing unit 301 is further configured to map the federated file system to a root folder of the container host, so that the software in the container host shares files in the root folder.
The method steps executed by each functional unit in the apparatus for implementing the compatibility of the container host and the virtual host image file provided by the embodiment of the present invention have been described in detail in the first two embodiments, and are not described herein again for simplicity and convenience of description.
The device for realizing the compatibility of the container host and the virtual host mirror image file provided by the embodiment of the invention maps the virtual host mirror image file into the virtual hard disk, and then maps all files in the virtual hard disk into the first folder of the host. And taking the first folder as a root directory of the container host, acquiring the operating system file of the virtual host from the first folder, and starting the container host by using the operating system file of the virtual host. In the process, the container host can be compatible with the image file of the virtual host, and can execute corresponding action after being started. In addition, the mirror image file of the virtual host does not need to be copied to the host, so that the use of the storage space in the host is reduced. By utilizing the layer-by-layer mapping relationship, the container host can be compatible with the mirror image file of the virtual host, and the container host is started by utilizing the operating file system of the virtual host. Some of the traffic of the virtual host is handled in the container host.
The reader should understand that in the description of this specification, reference to the description of the terms "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, a division of a unit is merely a logical division, and an actual implementation may have another division, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed.
Units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment of the present invention.
In addition, each functional unit in the embodiments of the present invention may be integrated into one processing unit 301, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit 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 invention essentially or partially contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product stored in a storage medium and including 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 invention. 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.
While the invention has been described with reference to specific embodiments, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the invention as defined by the appended claims. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.