Method for realizing virtual file system by using Docker container
Technical Field
The invention relates to the technical field of computer virtual storage, in particular to a method for realizing a virtual file system by using a Docker container.
Background
Operating systems may support a variety of underlying different file systems (e.g., NTFS, FAT, ext3, ext 4), and Linux adds a layer of abstraction between user processes and the underlying file system to provide a unified view of the file system, called a virtual file system, to kernel and user processes. The virtual file system provides a set of uniform interfaces for accessing files, directories and other objects on one hand, and is adaptive to the underlying file system on the other hand.
Virtual file system architecture, as shown in FIG. 1.
Docker shares an operating system, abstracts the concept of containers, and isolates different containers from each other. The Docker technology can enable containers to cross barriers of physical machines, communication mechanisms are established among different containers, the Docker is a virtualization mode on an operating system, management of the containers can be conveniently carried out, and the operating system of the local physical machine can be conveniently used.
The difference between Docker and virtual machine access address is shown in fig. 2.
In the prior art, a virtual file system of a Linux operating system is not a physical file system, but a conversion mechanism, and is a series of data interfaces only stored in a memory space. At present, the virtual file system has high storage cost and low file storage efficiency.
Disclosure of Invention
In order to solve the problems in the prior art, the invention provides a method for realizing a virtual file system by using a Docker container, which can realize the virtual file system by using a container-level virtualization technology Docker, reduce the storage overhead of the existing virtual file system and improve the file storage efficiency.
The technical scheme adopted by the invention is as follows:
a method for realizing a virtual file system by using a Docker container comprises the steps of creating a Docker container virtual environment, mapping physical addresses of disks in the Docker container virtual environment through container configuration, caching the Docker container virtual environment when storing files, and then storing the disks.
A disk cache region is also arranged between the virtual environment of the Docker container and the disk, and is a virtual region between the container and the disk, a pointer for internally storing files and a file operation queue.
The Docker container virtual environment comprises a file modification content block, a file difference block and a file pointer, when the modification and storage operation of a file is carried out, the operation is carried out in the file modification content block, after the operation is finished, the file modification is compared with the file data in the file difference block, if the file modification and storage operation is different, the file modification is required to be stored in a disk, the file to be stored firstly traverses a disk cache region by using the file pointer, whether a corresponding file exists in the disk cache region is searched, if the disk cache region exists, the whole file is modified and stored in the disk cache region, and after all the file operation is finished, the batch file storage operation is carried out.
The technical scheme provided by the invention has the beneficial effects that:
the invention is realized based on a Linux file system. The basic idea of the invention is: a virtual application environment is constructed by utilizing a container technology, internal management is carried out in the environment through container configuration, the physical addresses of the disks are directly mapped, caching is carried out in the virtual environment when files are stored, the disk storage is directly carried out by adopting a write-back method, the virtual physical addresses are not needed, the disk access times are reduced, and the expense of file storage operation is reduced.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a prior art virtual file system architecture diagram;
FIG. 2 is a schematic diagram illustrating differences between a Docker container and a virtual machine access address in the prior art;
fig. 3 is an implementation schematic diagram of a method for implementing a virtual file system by using a Docker container according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail with reference to the accompanying drawings.
Example one
As shown in fig. 3, a virtual environment is created using a Docker container, and the environment has a configuration file, and the container generation is performed using the configuration file. Different file systems at the bottom layer are adapted to different containers, and each container comprises contents such as file modification content blocks, file difference blocks, file pointers and the like.
When the file is modified and stored, the operation is actually carried out in the file modification content block. After the operation is finished, the file data in the file difference block is compared, and if the difference exists, the file is required to be modified and saved in a disk. The file to be stored firstly traverses a disk cache region by using a file pointer, wherein the disk cache region is a virtual region between a container and a disk, and the pointer for internally storing the file and a file operation queue are arranged inside the disk cache region.
And searching whether a corresponding file exists in the disk cache region, modifying the whole file if the disk cache region exists, storing the modified file in the cache region, performing batch file storage operation after all file operations are completed, and performing disk access only once, so that the disk access times are reduced, and the file storage efficiency is improved.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.