WO2017097114A1 - 一种共享文件的访问方法、系统及相关设备 - Google Patents

一种共享文件的访问方法、系统及相关设备 Download PDF

Info

Publication number
WO2017097114A1
WO2017097114A1 PCT/CN2016/107085 CN2016107085W WO2017097114A1 WO 2017097114 A1 WO2017097114 A1 WO 2017097114A1 CN 2016107085 W CN2016107085 W CN 2016107085W WO 2017097114 A1 WO2017097114 A1 WO 2017097114A1
Authority
WO
WIPO (PCT)
Prior art keywords
file
vhfs
virtual machine
host
request
Prior art date
Application number
PCT/CN2016/107085
Other languages
English (en)
French (fr)
Inventor
刘培峰
Original Assignee
华为技术有限公司
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
Priority claimed from CN201511032923.6A external-priority patent/CN105447203B/zh
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2017097114A1 publication Critical patent/WO2017097114A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor

Definitions

  • the present invention relates to the field of computer technologies, and in particular, to a method, system, and related device for accessing shared files.
  • Hardware-assisted virtualization technology refers to the process of simulating computer hardware on a physical host to virtualize multiple virtual machines (VMs). Each virtual machine is isolated from each other and has its own operating system (OS), which runs the services independently. More common is to simulate a virtual machine on the Linux platform through Qemu.
  • OS operating system
  • KVM-Qemu model in which Qemu is a software that can simulate a virtual machine on a Linux platform
  • KVM Kernel- Based Virtual Machine
  • the KVM module creates multiple threads vcpu and provides it to Qemu as an analog CPU.
  • Linux There is a need for file sharing between Linux and virtual machines.
  • the virtual machine needs a variety of configuration files and data to run the business, these configuration files and data are stored in Linux, therefore, Linux needs to share these configuration files and data to the virtual machine.
  • NFS Network File System
  • VFS Virtual File System
  • Linux and virtual machines are interconnected through the bridge of the Linux kernel. Linux shares files to virtual machines. Actually, Linux and virtual machines complete file operations through the network.
  • the operation information of the file is generated in the socket (socket), and then passes through the TCP/IP layer and the ETH interface of the virtual machine, reaches the virtual network card, reaches the bridge of the Linux, and then passes through the Linux.
  • the TCP/IP layer and port (socket) arrive at NFS. It can be seen that in the prior art shown in FIG.
  • the file sharing involves a bridge of the Linux kernel, and it is necessary to use Linux and virtual.
  • the virtual network card of the virtual machine is configured.
  • the Linux and the virtual machine need to pass the NFS service. There are many components that need to be passed, that is, there are multiple copies of operation information, which makes the sharing efficiency low.
  • the embodiment of the invention provides a method, a system and a related device for accessing a shared file, which are used to simplify the file access process and improve file access efficiency.
  • a first aspect of the present invention provides a method for accessing a shared file, which is applied to a virtual machine, where the virtual machine runs on a host, and the virtual machine is installed with a virtual host file system (VHFS).
  • VHFS virtual host file system
  • the file of the host machine is shared into the above VHFS, and the access method of the shared file may include:
  • the virtual machine detects an operation of sharing a file in the VHFS, and obtains operation information
  • the virtual machine generates a VHFS request according to the operation information, and writes the VHFS request into a memory of the virtual machine, where the VHFS request is used to request the host to complete the operation on the shared file on the host machine;
  • the virtual machine writes the address of the memory in which the VHFS request is located into the preset general-purpose register, and invokes a system switching instruction to cause the host to process the VHFS request.
  • the virtual machine obtains the operation information by detecting the operation of sharing the file in the VHFS, and then generates a VHFS request according to the operation information, and writes the VHFS request into the memory of the virtual machine, and then The address of the memory in which the VHFS request is located is written into the preset general-purpose register, and the system switching instruction is called to exit, and then the host performs subsequent operations on the VHFS request.
  • the preset register can be operated by the virtual machine, it can also be operated by the host machine, and the memory of the virtual machine is also allocated to the virtual machine from the memory of the host machine. Therefore, the host machine can take the preset general-purpose register.
  • the operation steps of the entire file are relatively simple, and no copy is needed, and the efficiency of processing the file in the file sharing can be effectively improved.
  • the virtual machine detects an operation of sharing a file in the VHFS, and obtaining operation information includes: the virtual machine detecting an operation of sharing a file in the VHFS, obtaining operation information, where the operation information includes file information and The operation command, the operations indicated by the above file operation command include a file open operation, a file read operation, a file write operation, a file creation operation, and Browse for any of the directory operations.
  • the generating, by the virtual machine, the VHFS request according to the operation information includes: when the operation indicated by the operation command is a file reading operation or a file writing operation, the virtual machine acquires the buffer of the shared file.
  • the virtual machine logical address converts the virtual machine logical address into the virtual machine physical address; the virtual machine generates the VHFS request according to the file information, the operation command, and the virtual machine physical address.
  • the virtual machine writes the address of the memory in which the VHFS request is located into the preset general-purpose register, and invokes the system switching instruction to cause the host to process the VHFS request, including: the virtual machine sends the VHFS request The address of the memory is written to the preset general-purpose register; the virtual machine invokes the vmcall instruction to exit the non-root mode, so that the host obtains control to process the VHFS request.
  • the virtual machine writes the address of the memory in which the VHFS request is located into the preset general-purpose register, and invokes the system switching instruction to cause the host to process the VHFS request, including: the virtual machine sends the VHFS request
  • the address of the memory is written to the virtual peripheral component of the host to interconnect the standard PCI device, and the virtual machine is triggered to exit the non-root mode, so that the host obtains control to process the VHFS request.
  • the file information includes a file descriptor or a file path or a node index of the file.
  • a second aspect of the present invention provides a method for accessing a shared file.
  • the host machine runs a plurality of virtual machines, and each virtual machine is installed with a virtual host file system VHFS, and files of the host are shared to each virtual machine.
  • VHFS virtual host file system
  • the access method of the above shared file may include:
  • the host machine detects that the virtual machine invokes a system switching instruction, and reads an address of a memory in which the VHFS request is located from a preset general-purpose register, where the VHFS request is generated by the virtual machine according to a user's operation on a shared file of the VHFS in the virtual machine.
  • the VHFS request is used to request the host machine to complete the foregoing operation on the shared file on the host machine;
  • the host machine reads the VHFS request according to the address of the memory in which the VHFS request is read, and performs the above operation on the shared file according to the VHFS request.
  • the foregoing operation information includes file information and an operation command
  • the operations indicated by the file operation command include any one of a file opening operation, a file reading operation, a file writing operation, a file creation operation, and a browsing directory operation.
  • the performing the foregoing operation on the shared file according to the VHFS request includes: when the operation indicated by the operation command includes the file open operation or the file read operation, the host machine uses the virtual machine The physical address is converted into a host logical address; the host machine finds the shared file according to the host logical address and the file information; and the host performs the operation indicated by the operation command on the searched shared file.
  • the host computer after the foregoing operation of the shared file is completed according to the VHFS request, the host computer returns an operation result of performing the foregoing operation to the virtual machine.
  • the file information includes a file descriptor or a file path or a node index of the file.
  • a third aspect of the present invention provides a virtual machine, where the virtual machine runs on a host machine, and the virtual machine is installed with a virtual host file system VHFS, and the files of the host are shared into the VHFS, and the virtual machine includes:
  • a VHFS processing module configured to detect an operation on the shared file in the VHFS, obtain operation information, generate a VHFS request according to the operation information, and write the VHFS request into a memory of the virtual machine, where the VHFS request is used to request the host machine
  • the above operation of the shared file is completed on the host machine; the address of the memory in which the VHFS request is located is written into the preset general-purpose register, and the system switching instruction is invoked to cause the host to process the VHFS request.
  • the VHFS processing module is specifically configured to: detect an operation of sharing a file in the VHFS, obtain operation information, where the operation information includes file information and an operation command, and the operation indicated by the file operation command includes a file. Any of an open operation, a file read operation, a file write operation, a file creation operation, and a browse directory operation.
  • the VHFS processing module is specifically configured to: when the operation indicated by the operation command is a file read operation or a file write operation, acquire a virtual machine logical address of the buffer where the shared file is located, and Converting the virtual machine logical address into the virtual machine physical address; generating the VHFS request according to the file information, the operation command, and the virtual machine physical address, where the VHFS request includes the file information, the operation command, and the buffer of the shared file.
  • the virtual machine physical address of the zone is specifically configured to: when the operation indicated by the operation command is a file read operation or a file write operation, acquire a virtual machine logical address of the buffer where the shared file is located, and Converting the virtual machine logical address into the virtual machine physical address; generating the VHFS request according to the file information, the operation command, and the virtual machine physical address, where the VHFS request includes the file information, the operation command, and the buffer of the shared file.
  • the virtual machine physical address of the zone is specifically configured to: when the operation indicated by the operation
  • the VHFS processing module is specifically configured to: write an address of a memory where the VHFS request is located into the preset general-purpose register; and invoke a vmcall instruction to exit a non-root mode. In order for the above host to process the above VHFS request.
  • the VHFS processing module is specifically configured to: write the address of the memory where the VHFS request is located to the virtual peripheral component interconnect standard PCI device of the host, and trigger the virtual machine to exit the non-root mode.
  • the above host machine is given control to process the VHFS request.
  • the file information includes a file descriptor or a file path or a node index of the file.
  • a fourth aspect of the present invention provides a host machine, wherein the host machine runs a plurality of virtual machines, each of which is installed with a virtual host file system VHFS, and the files of the host machines are shared into the VHFS of each virtual machine.
  • the above host machine includes:
  • the VHFSD processing module is configured to detect the virtual machine calling system switching instruction, and read the address of the memory where the VHFS request is located from the preset general-purpose register, where the VHFS request is a shared file of the virtual machine according to the user to the VHFS in the virtual machine. The operation is generated, and the VHFS request is used to request the host machine to complete the foregoing operation on the shared file on the host machine;
  • the VHFSD processing module is further configured to read the VHFS request according to the address of the memory in which the VHFS request is read, and perform the foregoing operation on the shared file according to the VHFS request.
  • the operation information includes file information and an operation command
  • the operations indicated by the file operation command include a file open operation, a file read operation, a file write operation, a file creation operation, and a browse directory operation. Any one.
  • the VHFSD processing module is specifically configured to: when the operation indicated by the operation command includes the file open operation or the file read operation, convert the virtual machine physical address into a host logical address; The host logical address and the file information are used to find the shared file; and the operation indicated by the operation command is performed on the found shared file.
  • the VHFSD processing module is further configured to return an operation result of performing the foregoing operation to the virtual machine.
  • the file information includes a file descriptor or a file path or a node index of the file.
  • a fifth aspect of the present invention provides a shared file access system, including the virtual machine provided by the third aspect, and the host provided by the fourth aspect.
  • FIG. 2 is a schematic diagram of file sharing between a host machine and a virtual machine based on a network file system provided by the prior art
  • FIG. 3 is a schematic structural diagram of a shared file access system according to some embodiments of the present invention.
  • FIG. 4 is a schematic flowchart of a method for accessing a shared file according to an embodiment of the present invention
  • FIG. 5 is a signaling diagram of a method for accessing a shared file according to an embodiment of the present invention.
  • FIG. 6a is a file opening process according to an embodiment of the present invention.
  • FIG. 6b is a data correspondence relationship between a file system of a host machine and a file system of a virtual machine according to an embodiment of the present invention
  • FIG. 7a is a signaling diagram of a method for writing a shared file according to some embodiments of the present invention.
  • FIG. 7b is a schematic flowchart of writing a file according to an embodiment of the present invention.
  • FIG. 8 is a schematic flowchart of operation of an index node according to some embodiments of the present invention.
  • FIG. 9 is a schematic structural diagram of a virtual machine according to an embodiment of the present disclosure.
  • FIG. 10 is a schematic structural diagram of a host machine according to some embodiments of the present invention.
  • FIG. 11 is a schematic structural diagram of a shared file access system according to an embodiment of the present disclosure.
  • FIG. 12 is a schematic structural diagram of a device for accessing shared files according to an embodiment of the present invention.
  • the embodiment of the invention provides a method for accessing a shared file, which is used to simplify the file access process and improve file access efficiency.
  • the embodiment of the invention further provides a system corresponding to the access method of the shared file. System, virtual machine and host.
  • FIG. 3 is a schematic structural diagram of a shared file access system according to an embodiment of the present invention.
  • the access system of the shared file includes a host machine and a virtual machine, wherein the host machine is installed with a file system (File System, FS for short), VFS is also installed under the FS, and various general-purpose registers are also included in the host machine.
  • a VHFSD (Virtual Host File System Handle, VHFSD for short) processing module is set in the host machine, and the VHFSD processing module is mainly used for processing VHFS requests at the host end.
  • a VFS is installed in the virtual machine, and a VHFS processing module is installed under the VFS for processing VHFS requests at the virtual machine side.
  • the files in a file directory are shared to the VHFS.
  • VHFS can implement various standard operations of the file system, such as browsing directory operations (dentry_ops), file index operations (inode_ops), and file operations (file_ops).
  • file_ops can be regarded as a collection, and all files are aggregated. For example, file open operation, file read operation, file write operation, file creation operation, etc., other items are only a collection of a large function, and various specific operations are also collected therein, and will not be described here. .
  • the host runs in root mode (the root mode is the level at which the host is running), while the virtual machine runs in a non-root mode (the non-root mode is the level at which the virtual machine runs).
  • a Vmcall gate is provided for implementing switching between a root mode and a non-root mode, from a non-root mode to a root mode, and the control is given to the host; the root mode to the non-root mode, Give control to the virtual machine.
  • VHFS file system In the embodiment of the present invention, only one VHFS file system and a VHFS processing module need to be installed in the virtual machine, wherein the VHFS file system is used to share the file directory shared by the host, and the VHFS processing module is used. Handling file-related VHFS requests in the VHFS file system.
  • the VHFSD processing module is set in the host machine, and the VHFSD processing module completes the processing of the VHFS request, which simplifies the components of the system participating in the shared file operation and simplifies the file operation. Process to improve file access efficiency.
  • the file shared by the host machine to the virtual machine is a file required for configuring the virtual machine, or a file required for the virtual machine to run the service, or includes data information required for configuring the virtual machine, or includes The data information required to run the business, etc.
  • FIG. 4 is a schematic flowchart of a method for accessing a shared file according to an embodiment of the present invention. As shown in FIG. 4, a method for accessing a shared file may include:
  • the virtual machine detects an operation of sharing a file in the VHFS, and obtains operation information.
  • the shared file shared by the host to the VHF file system for use by the virtual machine can be operated by the user or by itself when configuring the virtual machine. Specifically, the directory entry of the shared file in the virtual machine can be operated, and the node of the file is operated.
  • the index operates to manipulate the file.
  • the file operations include file open operations, file read operations, file write operations, file creation operations, file delete operations, and the like.
  • the operation information obtained is different for different operations.
  • the operation information includes file path information and operation commands.
  • the operation information includes a file descriptor (fd) and an operation command.
  • the operation information includes a file descriptor (fd), an operation command, and a write content. If it is a node index operation of a file, the operation information includes an index node of the file, an operation command, and the like.
  • the operations indicated by the operation commands are the various operations specifically described above.
  • the contents of the operation information are roughly classified into two types, one is file information, and the other is an operation command.
  • the file information includes the above file path information or file descriptor (fd) or written content.
  • the virtual machine generates a VHFS request according to the operation information, and writes the VHFS request into a memory of the virtual machine, where the VHFS request is used to request the host to complete the operation on the shared file on the host machine.
  • the virtual machine generates a VHFS request according to the operation information. It can be understood that the VHFS request will include the content in the operation information. Since the operation information is different according to different operations, the content included in the VHFS request will also be changed due to different operations. Different.
  • the VHFS request includes file path information and operation commands. If it is a node index operation of a file, the VHFS request includes an index node of the file, an operation command, and the like.
  • the VHFS request includes the virtual machine physical address in addition to the contents of the operation information. Because, in the file read operation and write operation, you need to involve the file buffer on the virtual machine, that is, the shared file will need to be put into the file buffer.
  • the file buffer is managed by the virtual machine and corresponds to a virtual machine logical address, but the host cannot recognize the virtual machine logical address. Therefore, the virtual machine logical address of the buffer in which the shared file is located needs to be converted into virtual machine physics. address. Then, before generating the VHFS request, the virtual machine logical address of the buffer in which the shared file is located needs to be converted into the virtual machine physical address.
  • the host when the host virtualizes the virtual machine, it needs to allocate memory and registers to the virtual machine. Therefore, the virtual machine writes the VHFS request into the memory, that is, writes the memory allocated by the host to the virtual machine, and the subsequent host can A VHFS request is read from this memory.
  • the virtual machine writes an address of the memory where the VHFS request is located into a preset general-purpose register, and invokes a system switching instruction to enable the host to process the VHFS request.
  • the host machine detects that the virtual machine invokes a system switching instruction, and reads an address of a memory where the VHFS request is located from a preset general-purpose register, where the VHFS request is a shared file of the virtual machine according to a user's VHFS in the virtual machine.
  • the operation generates, the VHFS request is used to request the host machine to complete the foregoing operation on the shared file on the host machine;
  • the VHFS request is generated according to the operation information of the shared file by the user, the VHFS request is written into the memory, and then the address of the memory is written into the preset general-purpose register, which may be the host allocation.
  • the virtual machine is used to save the VHFS request. Therefore, the host reads the address of the memory where the VHFS request is located by accessing the preset general-purpose register, and then reads the VHFS request in the memory according to the address.
  • the virtual machine is running in the system non-root mode, and the host machine is running in the system root mode.
  • the host After the virtual machine writes the address of the memory where the VHFS request is located to the register, the host will complete the VHFS request operation. At this time, the virtual machine needs to exit the non-root mode, and then let the system enter the root mode, so that the host can obtain control.
  • the virtual machine is implemented by the vmcall gate.
  • the switching between the hosts specifically, if the non-root mode is exited by using vmcall, the step 403 specifically includes: writing the address of the memory where the VHFS request is located to the preset general-purpose register; and calling the vmcall instruction to exit the non-root mode, so that The host machine above takes control and then processes the VHFS request described above. Among them, issue a call to vmcall to call vmcall, and then the virtual machine will exit the non-root mode.
  • the embodiment of the present invention can also efficiently access the file system of the host through the HyperCall mechanism.
  • the host computer simulates a Peripheral Component Interconnect (PCI) device in advance, and then triggers the virtual machine to exit the non-root mode when the virtual machine reads and writes the configuration space of the PCI device.
  • the step 403 specifically includes: writing an address of the memory where the VHFS request is located to the peripheral component to interconnect the standard PCI device, and triggering the virtual machine to exit the non-root mode, so that the host obtains control.
  • the VHFS request is processed.
  • the preset general-purpose register in the embodiment of the present invention may be used separately for writing the address of the memory where the VHFS request is located.
  • the preset general-purpose register may also be used to write other information, and therefore, After the host reads the information from the preset general-purpose register, it determines whether the information is a memory address that points to the VHFS request.
  • the host machine reads the VHFS request according to the address of the memory in which the VHFS request is read, and performs the foregoing operation on the shared file according to the VHFS request.
  • performing the foregoing operation on the shared file according to the foregoing VHFS request means: the host converts the virtual machine physical address into a host logical address, according to the host logical address and the file information, Finding the shared file, performing the operation indicated by the operation command on the found shared file.
  • the operation result of processing the operation command in the VHFS request will be returned to the virtual machine, and the operation result will be different for different operations, for example, the file opening operation, and the operation result includes the file descriptor (fd).
  • the operation result is a failure indication or a success indication.
  • the virtual machine detects the operation of the shared file in the VHFS by the user to obtain the operation information, and then generates a VHFS request according to the operation information, writes the VHFS request into the memory of the virtual machine, and then the address of the memory where the VHFS request is located.
  • Write preset general-purpose registers, call system switching instructions After exiting, the host then performs subsequent operations on the VHFS request.
  • the preset register can be operated by the virtual machine, it can also be operated by the host machine, and the memory of the virtual machine is also allocated to the virtual machine from the memory of the host machine. Therefore, the host machine can take the preset general-purpose register.
  • the operation steps of the entire file are relatively simple, and there is no need to involve too many copies, which can effectively improve the efficiency of processing files in file sharing.
  • FIG. 5 is a signaling diagram of a method for accessing a shared file according to some embodiments of the present invention
  • FIG. 6a is a file opening process according to an embodiment of the present invention
  • File access methods can include:
  • the virtual machine detects an open operation of the shared file, and obtains operation information.
  • the operation information includes path information, operation commands, and the like.
  • the virtual machine invokes the application, generates a VHFS request according to the operation information, saves the VHFS request to the memory, and writes the address of the memory where the VHFS request is located into the preset general-purpose register;
  • the virtual machine calls the sys_open function through the application to try to open a file.
  • the dentry_open function under sys_open is called, which is actually the open function under the VHFS system.
  • the VHFS open function initializes the VHFS request, which is a VHFS request.
  • the virtual machine invokes the vmcall instruction to exit the non-root mode, and gives control to the host.
  • the virtual machine invokes the vmcall instruction to exit the non-root mode and give control to the host.
  • the host schedules the VCPU thread to capture the vmcall instruction, reads the address of the memory where the VHFS request is located from the preset general-purpose register, reads the VHFS request in the memory according to the address, and then performs the operation of opening the shared file in the VHFS request;
  • the host After the host reads the VHFS request, it calls the vfs_open function in the file system to perform the operation of opening the shared file.
  • the host returns the file descriptor fd of the shared file that is opened to the virtual machine.
  • a result area is also divided in the VHFS system of the virtual machine, and the host completes the operation of opening the shared file, and updates the file descriptor fd to the result area.
  • the vmcall instruction is invoked, the host exits the root mode, and control is passed to the virtual machine.
  • FIG. 6b is a data correspondence relationship between a file system of a host and a file system of a virtual machine according to an embodiment of the present invention.
  • the shared file on the host is considered to be opened by a vmm process, and the file descriptor (fd) is saved in the descriptor array of the vmm process.
  • the same file descriptor (fd) is stored in a private structure area (private_data) under the corresponding file, which is used for subsequent file reading and writing.
  • FIG. 7a is a signaling diagram of a method for writing a shared file according to some embodiments of the present invention
  • FIG. 7b is a schematic flowchart of writing a file according to an embodiment of the present invention.
  • a method for writing a shared file may include:
  • the virtual machine detects a file write operation on the shared file, and obtains operation information.
  • the operation information includes a shared file descriptor (fd), an operation command, and a write content.
  • the virtual machine reads the file descriptor fd of the opened shared file from the result area;
  • the virtual machine converts the virtual machine logical address of the buffer in which the shared file is opened into a virtual machine physical address.
  • the virtual machine generates a VHFS request according to the operation command, the written content, the read fd, and the virtual machine physical address.
  • the virtual machine writes the VHFS request into the memory, and then writes the memory address into the register.
  • the virtual machine invokes a vmcall instruction to exit processing of the VHFS request.
  • the virtual machine calls the sys_write function in the system to start writing files.
  • the related hook function of the f_ops in the VHFS is configured to generate a VHFS request, and the VHFS request includes the virtual machine physical address of the buffer in which the shared file is located, and the virtual machine physical address is converted from the virtual machine logical address. And fd of the actual file is taken out from the result area of the virtual machine as one of the contents of the VHFS request, and then the vmcall instruction is called to exit the virtual machine and hand it to the host for processing.
  • the host schedules the VCPU thread to capture the vmcall instruction, and reads the VHFS from the register. Find the address of the memory, and read the VHFS request from the memory according to the read address;
  • the host reads the fd saved by the host according to the fd in the VHFS request, and converts the virtual machine physical address in the VHFS request into a host logical address.
  • the host calls the write function, and writes the write information in the VHFS request to the shared file corresponding to fd according to the logical address of the host.
  • the host machine first converts the virtual machine physical address of the file buffer into the logical address of the host machine when processing the VHFS request for writing the file, and then calls the vfs_write function to write the corresponding shared file.
  • the file write operation is performed on the basis that the file is opened. After the file is opened, the host returns the file fd to the virtual machine for storage. At the same time, the host machine will also save the fd, then the file write operation. At the same time, the host machine can directly perform file write operations according to the fd it holds.
  • the file reading operation is similar to the file writing operation, and the file is opened, but only when the file reading operation is performed, the VHFS request does not include the written content.
  • the host calls the vfs_read function to read the corresponding file.
  • the file in the creation operation of the file in the embodiment of the present invention, if the file is created under a certain file, the file will also need to be opened.
  • the host calls the vfs_creat function to create a file. After the file is created, the file will correspond to a file descriptor (fd), as well as the virtual machine logical address, virtual machine physical address, and host logical address of the buffer in which the file resides.
  • fd file descriptor
  • the shared file access method provided by the embodiment of the present invention requires fewer components, and only needs to install the relevant kernel module (one VHFSD processing module in the host machine and one VHFS processing module in the virtual machine), and no complicated Configuration.
  • the system overhead is small, and it is not necessary to copy the operation information of the operation file multiple times, and only the address conversion such as GVA-GPA-HVA needs to be completed, and the host directly performs various operations on the file buffer. Greatly improve file access efficiency.
  • FIG. 8 is a schematic flowchart of an operation of an index node according to some embodiments of the present invention.
  • the retrieval node operation includes creating an index node (creat), finding an index node (lookup), an index node link (link), deleting an index node (unlink), and renaming an index node (rename) provided in the virtual machine VFS system. ), extended path (setxattr), get path (getxattr).
  • inode_ops the virtual machine starts the application, calls the corresponding function under the operation of the inode, and then calls the corresponding operation under the inode_ops in the VHFS.
  • the function generates a VHFS request according to the corresponding inode operation, and the VHFS request includes an operation command (specifically, the above-mentioned index node operation) and an index node identifier.
  • the virtual machine writes the VHFS request to the preset general-purpose register, it calls Vmcall to exit the non-root mode.
  • the VHFSD module in the host processes the VHFS request, completes the corresponding index node operation in the same VHS, and returns the operation result.
  • FIG. 9 is a schematic structural diagram of a virtual machine according to an embodiment of the present invention. As shown in FIG. 9, a virtual machine runs on a host machine, and a virtual host file system VHFS is installed in the virtual machine, and the host machine is The file is shared into the above VHFS, which may include:
  • a VHFS processing module configured to detect an operation on the shared file in the VHFS, obtain operation information, generate a VHFS request according to the operation information, and write the VHFS request into a memory of the virtual machine, where the VHFS request is used to request the host machine
  • the above operation of the shared file is completed on the host machine; the address of the memory in which the VHFS request is located is written into the preset general-purpose register, and the system switching instruction is invoked to cause the host to process the VHFS request.
  • the VHFS processing module is specifically configured to: detect an operation of sharing a file in the VHFS, obtain operation information, where the operation information includes file information and an operation command, and the operation indicated by the file operation command includes a file. Any of an open operation, a file read operation, a file write operation, a file creation operation, and a browse directory operation.
  • the VHFS processing module is specifically configured to: when the operation indicated by the operation command is a file read operation or a file write operation, acquire a virtual machine logical address of the buffer where the shared file is located, and the foregoing The virtual machine logical address is converted into the virtual machine physical address; the VHFS request is generated according to the file information, the operation command, and the virtual machine physical address, and the VHFS request includes the file information, the operation command, and the buffer of the shared file. Virtual machine physical address.
  • the VHFS processing module is specifically configured to: write the address of the memory where the VHFS request is located into the preset general-purpose register; and invoke the vmcall instruction to exit the non-root mode, so that the host machine processes the VHFS request.
  • the VHFS processing module is specifically configured to: write the address of the memory where the VHFS request is located to the virtual peripheral component interconnect standard PCI device of the host, and trigger the virtual machine to exit the non-root mode.
  • the VHFS processing module is specifically configured to: write the address of the memory where the VHFS request is located to the virtual peripheral component interconnect standard PCI device of the host, and trigger the virtual machine to exit the non-root mode.
  • FIG. 10 is a schematic structural diagram of a host machine according to some embodiments of the present invention. As shown in FIG. 10, a virtual machine is running on the host machine, and a VHFS is installed in the virtual machine, and files of the host machine are shared to In the VHFS of each virtual machine, the host includes:
  • the VHFSD processing module is configured to detect the virtual machine calling system switching instruction, and read the address of the memory where the VHFS request is located from the preset general-purpose register, where the VHFS request is a shared file of the virtual machine according to the user to the VHFS in the virtual machine. The operation is generated, and the VHFS request is used to request the host machine to complete the foregoing operation on the shared file on the host machine;
  • the VHFSD processing module is further configured to read the VHFS request according to the address of the memory in which the VHFS request is read, and perform the foregoing operation on the shared file according to the VHFS request.
  • the foregoing operation information includes file information and an operation command
  • the operations indicated by the file operation command include any one of a file opening operation, a file reading operation, a file writing operation, a file creation operation, and a browsing directory operation.
  • the VHFSD processing module is specifically configured to: when the operation indicated by the operation command includes the file open operation or the file read operation, convert the virtual machine physical address into a host logical address; The host logical address and the file information are used to find the shared file; and the operation indicated by the operation command is performed on the found shared file.
  • the VHFSD processing module is further configured to return an operation result of performing the foregoing operation to the virtual machine.
  • FIG. 11 is a schematic structural diagram of a shared file access system according to an embodiment of the present invention. As shown in FIG. 11, a shared file access system may include:
  • FIG. 9 The virtual machine provided in FIG. 9 and the host provided in FIG. 10, wherein a detailed description of the virtual machine and the host may be referred to in the description of the method embodiment and the device embodiment, and details are not described herein again.
  • FIG. 12 is a schematic structural diagram of a device for accessing a shared file according to an embodiment of the present invention, where at least one processor 1201 (for example, a CPU, Central Processing Unit), at least one network interface or other communication interface may be included.
  • a memory 1202, and at least one communication bus, is used to implement connection communication between the devices.
  • the processor 1201 described above is configured to execute an executable module, such as a computer program, stored in a memory.
  • the above memory 1202 may include high speed random access memory
  • a RAM Random Access Memory
  • the communication connection between the system gateway and at least one other network element is implemented by at least one network interface (which may be wired or wireless), and an Internet, a wide area network, a local network, a metropolitan area network, etc. may be used.
  • the memory 1202 stores program instructions, which may be executed by the processor 1201.
  • the processor 1201 specifically performs the following steps:
  • Detecting an operation of sharing a file in the VHFS obtaining operation information; generating a VHFS request according to the operation information, and writing the VHFS request to a memory of the virtual machine, where the VHFS request is used to request the host to complete on the host machine
  • the above operation of the shared file writing the address of the memory in which the VHFS request is located to the preset general-purpose register, and calling the system switching instruction to cause the host to process the VHFS request;
  • detecting that the virtual machine invokes a system switching instruction and reads an address of a memory in which the VHFS request is located from a preset general-purpose register, wherein the VHFS request is generated by the virtual machine according to a user operation of a shared file of the VHFS in the virtual machine.
  • the VHFS request is used to request the host to complete the operation on the shared file on the host machine; the VHFS request is read according to the address of the memory in which the VHFS request is read, and the shared file is executed according to the VHFS request.
  • the processor 1201 may further perform the steps of: detecting an operation of sharing a file in the VHFS, obtaining operation information, where the operation information includes file information and an operation command, and the operation indicated by the file operation command includes a file. Any of an open operation, a file read operation, a file write operation, a file creation operation, and a browse directory operation.
  • the processor 1201 may further perform the following steps: when the operation indicated by the operation command is a file read operation or a file write operation, acquiring a virtual machine logical address of the buffer where the shared file is located, Converting the virtual machine logical address into the virtual machine physical address; generating the VHFS request according to the file information, the operation command, and the virtual machine physical address, where the VHFS request includes the file information, the operation command, and the buffer of the shared file.
  • the virtual machine physical address of the zone when the operation indicated by the operation command is a file read operation or a file write operation, acquiring a virtual machine logical address of the buffer where the shared file is located, Converting the virtual machine logical address into the virtual machine physical address; generating the VHFS request according to the file information, the operation command, and the virtual machine physical address, where the VHFS request includes the file information, the operation command, and the buffer of the shared file.
  • the virtual machine physical address of the zone when the operation indicated by the operation command is a file read operation or a
  • the processor 1201 may further perform the steps of: writing the address of the memory where the VHFS request is located to the preset general-purpose register; and calling the vmcall instruction to exit the non-root mode. In order for the above host to process the above VHFS request.
  • the processor 1201 may further perform the steps of: writing the address of the memory in which the VHFS request is located to the virtual peripheral component of the host to interconnect the standard PCI device, and triggering the virtual machine to exit the non-root mode, The above host machine is given control to process the VHFS request.
  • the processor 1201 may further perform the following steps: when the operation indicated by the operation command includes the file open operation or the file read operation, converting the virtual machine physical address into a host logical address; The host logical address and the file information are used to find the shared file; and the operation indicated by the operation command is performed on the found shared file.
  • the processor 1201 may further perform the following steps: returning the operation result of performing the above operation to the virtual machine.
  • the disclosed system, apparatus, and method may be implemented in other manners.
  • the device embodiments described above are merely illustrative.
  • the division of the unit is only a logical function division.
  • there may be another division manner for example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored or not executed.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, and may be in an electrical, mechanical or other form.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
  • each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. in.
  • the above integrated unit can be implemented in the form of hardware or in the 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 standalone product, may be stored in a computer readable storage medium.
  • the technical solution of the present invention which is essential or contributes to the prior art, or all or part of the technical solution, may be embodied in the form of a software product stored in a storage medium.
  • a number of instructions are included to cause a computer device (which may be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention.
  • the foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like. .

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种共享文件的访问方法,用于简化文件访问流程,提高文件访问效率。所述方法包括:所述虚拟机检测对所述VHFS中共享文件的操作,获得操作信息(401);所述虚拟机根据所述操作信息生成VHFS请求,并将所述VHFS请求写入所述虚拟机的内存,所述VHFS请求用于请求所述宿主机在所述宿主机上完成对所述共享文件的所述操作(402);所述虚拟机将所述VHFS请求所在内存的地址写入预置通用寄存器,并调用系统切换指令以使所述宿主机处理所述VHFS请求(403)。

Description

一种共享文件的访问方法、系统及相关设备
本申请要求于2015年12月09日提交中国专利局、申请号201510904100.1以及2015年12月31日提交中国专利局、申请号为201511032923.6,发明名称为“一种共享文件的访问方法、系统及相关设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本发明涉及计算机技术领域,具体涉及一种共享文件的访问方法、系统及相关设备。
背景技术
硬件辅助虚拟化技术是指在一台物理宿主机上开一个进程模拟计算机硬件,从而虚拟化出多个虚拟机(Virtual Machine,简称VM)。各个虚拟机之间相互隔离,拥有各自的操作系统(Operating System,简称OS),各自独立运行业务。比较常见的是通过Qemu在Linux平台上模拟虚拟机,如图1所示,一种Linux KVM-Qemu模型,其中,Qemu是一款能够在Linux平台上模拟出虚拟机的软件,KVM(Kernel-based Virtual Machine)是Linux中的模块,该KVM模块创建出多个线程vcpu,作为模拟的CPU提供给Qemu使用。
Linux与虚拟机之间存在文件共享需求。其中,虚拟机需要各种各样的配置文件和数据来运行业务,这些配置文件和数据保存在Linux中,因此,Linux需要将这些配置文件和数据共享给虚拟机。
目前在Linux与虚拟机中的文件共享技术通过网络文件系统(Network File System,简称NFS)实现。NFS安装在虚拟文件系统(Virtual File System,简称VFS)下。如图2所示,Linux与虚拟机之间通过Linux内核的网桥互联,Linux将文件共享给虚拟机实际就是Linux与虚拟机之间通过网络完成文件操作。在文件共享时,对文件的操作信息在端口(socket)中生成网络报文,依次经过虚拟机的TCP/IP层、ETH接口,到达虚拟网卡,到达Linux的网桥,再依次经过达Linux的TCP/IP层、端口(socket)到达NFS。可以看出,图2所示的现有技术中,文件共享时涉及到Linux内核的网桥,需要将Linux和虚 拟机的虚拟网卡进行配置,Linux与虚拟机之间需要通过NFS服务,需要经过的组件较多,也就是存在多次操作信息拷贝,使得共享效率较低。
发明内容
本发明实施例提供了一种共享文件的访问方法、系统及相关设备,用于简化文件访问流程,提高文件访问效率。
本发明第一方面提供了一种共享文件的访问方法,应用于虚拟机,上述虚拟机运行在宿主机上,上述虚拟机中安装有虚拟主机文件系统(Virtual Host File System,简称VHFS),上述宿主机的文件被共享到上述VHFS中,上述共享文件的访问方法可包括:
上述虚拟机检测对上述VHFS中共享文件的操作,获得操作信息;
上述虚拟机根据上述操作信息生成VHFS请求,并将上述VHFS请求写入上述虚拟机的内存,上述VHFS请求用于请求上述宿主机在上述宿主机上完成对上述共享文件的上述操作;
上述虚拟机将上述VHFS请求所在内存的地址写入预置通用寄存器,并调用系统切换指令以使上述宿主机处理上述VHFS请求。
可以看出,本发明第一方面中,虚拟机通过检测对VHFS中共享文件的操作,以获得操作信息,然后根据操作信息生成VHFS请求,将VHFS请求写入虚拟机的内存中,之后再将VHFS请求所在内存的地址写入预置通用寄存器,调用系统切换指令后退出,然后由宿主机来执行后续对VHFS请求的操作。其中,由于预置的寄存器可以由虚拟机操作,也可以由宿主机操作,而虚拟机的内存也是从宿主机的内存中划分给虚拟机的,因此,宿主机可以从预置通用寄存器中拿到VHFS请求所在内存的地址,然后去内存中读取VHFS请求,然后处理该VHFS请求。本发明实施例中整个对文件的操作步骤比较简单,不需要拷贝,能够有效提高文件共享中处理文件的效率。
在本发明一些实施例中,上述虚拟机检测对上述VHFS中共享文件的操作,获得操作信息包括:上述虚拟机检测对上述VHFS中共享文件的操作,获得操作信息,上述操作信息包括文件信息和操作命令,上述文件操作命令所指示的操作包括文件打开操作、文件读取操作、文件写入操作、文件创建操作和 浏览目录操作中的任意一种。
在本发明一些实施例中,上述虚拟机根据上述操作信息生成VHFS请求包括:当上述操作命令所指示的操作为文件读取操作或文件写入操作时,上述虚拟机获取上述共享文件所在缓冲区的虚拟机逻辑地址,将上述虚拟机逻辑地址转换成上述虚拟机物理地址;上述虚拟机根据上述文件信息、上述操作命令和上述虚拟机物理地址,生成上述VHFS请求。
在本发明一些实施例中,上述虚拟机将上述VHFS请求所在内存的地址写入预置通用寄存器,并调用系统切换指令以使上述宿主机处理上述VHFS请求包括:上述虚拟机将上述VHFS请求所在内存的地址写入上述预置通用寄存器;上述虚拟机调用vmcall指令退出非根模式,以使上述宿主机获得控制权处理上述VHFS请求。
在本发明一些实施例中,上述虚拟机将上述VHFS请求所在内存的地址写入预置通用寄存器,并调用系统切换指令以使上述宿主机处理上述VHFS请求包括:上述虚拟机将上述VHFS请求所在内存的地址写入上述宿主机虚拟的外设部件互连标准PCI设备,并触发上述虚拟机退出非根模式,以使上述宿主机获得控制权处理上述VHFS请求。
可选地,上述文件信息包括文件描述符或文件路径或文件的节点索引。
本发明第二方面提供了一种共享文件的访问方法,上述宿主机运行着若干虚拟机,每一个虚拟机中安装有虚拟主机文件系统VHFS,上述宿主机的文件被共享到每一个虚拟机的VHFS中,上述共享文件的访问方法可包括:
上述宿主机检测到上述虚拟机调用系统切换指令,从预置通用寄存器中读取VHFS请求所在内存的地址,上述VHFS请求为上述虚拟机根据用户对上述虚拟机中的VHFS的共享文件的操作生成,上述VHFS请求用于请求上述宿主机在上述宿主机上完成对上述共享文件的上述操作;
上述宿主机根据读取的上述VHFS请求所在内存的地址,读取上述VHFS请求,根据上述VHFS请求执行对上述共享文件的上述操作。
可选地,上述操作信息包括文件信息和操作命令,上述文件操作命令所指示的操作包括文件打开操作、文件读取操作、文件写入操作、文件创建操作和浏览目录操作中的任意一种。
在本发明一些实施例中,上述根据上述VHFS请求执行对上述共享文件的上述操作包括:当上述操作命令所指示的操作包括上述文件打开操作或文件读取操作时,上述宿主机将上述虚拟机物理地址转换成主机逻辑地址;上述宿主机根据上述主机逻辑地址以及上述文件信息,查找到上述共享文件;上述宿主机对查找到的上述共享文件执行上述操作命令所指示的操作。
在本发明一些实施例中,上述根据上述VHFS请求完成对上述共享文件的上述操作之后包括:上述宿主机将执行上述操作的操作结果,返回给上述虚拟机。
可选地,上述文件信息包括文件描述符或文件路径或文件的节点索引。
本发明第三方面提供了一种虚拟机,上述虚拟机运行在宿主机上,上述虚拟机中安装有虚拟主机文件系统VHFS,上述宿主机的文件被共享到上述VHFS中,上述虚拟机包括:
VHFS处理模块,用于检测对上述VHFS中共享文件的操作,获得操作信息;根据上述操作信息生成VHFS请求,并将上述VHFS请求写入上述虚拟机的内存,上述VHFS请求用于请求上述宿主机在上述宿主机上完成对上述共享文件的上述操作;将上述VHFS请求所在内存的地址写入预置通用寄存器,并调用系统切换指令以使上述宿主机处理上述VHFS请求。
在本发明一些实施例中,上述VHFS处理模块具体用于,检测对上述VHFS中共享文件的操作,获得操作信息,上述操作信息包括文件信息和操作命令,上述文件操作命令所指示的操作包括文件打开操作、文件读取操作、文件写入操作、文件创建操作和浏览目录操作中的任意一种。
在本发明一些实施例中,上述VHFS处理模块具体用于,当上述操作命令所指示的操作为文件读取操作或文件写入操作时,获取上述共享文件所在缓冲区的虚拟机逻辑地址,将上述虚拟机逻辑地址转换成上述虚拟机物理地址;根据上述文件信息、上述操作命令和上述虚拟机物理地址,生成上述VHFS请求,上述VHFS请求包括上述文件信息、上述操作命令和上述共享文件所在缓冲区的虚拟机物理地址。
在本发明一些实施例中,上述VHFS处理模块具体用于,将上述VHFS请求所在内存的地址写入上述预置通用寄存器;调用vmcall指令退出非根模 式,以使上述宿主机处理上述VHFS请求。
在本发明一些实施例中,上述VHFS处理模块具体用于,将上述VHFS请求所在内存的地址写入上述宿主机虚拟的外设部件互连标准PCI设备,并触发上述虚拟机退出非根模式,以使上述宿主机获得控制权处理上述VHFS请求。
可选地,上述文件信息包括文件描述符或文件路径或文件的节点索引。
本发明第四方面提供了一种宿主机,上述宿主机运行着若干虚拟机,每一个虚拟机中安装有虚拟主机文件系统VHFS,上述宿主机的文件被共享到每一个虚拟机的VHFS中,上述宿主机包括:
VHFSD处理模块,用于检测到上述虚拟机调用系统切换指令,从预置通用寄存器中读取VHFS请求所在内存的地址,上述VHFS请求为上述虚拟机根据用户对上述虚拟机中的VHFS的共享文件的操作生成,上述VHFS请求用于请求上述宿主机在上述宿主机上完成对上述共享文件的上述操作;
上述VHFSD处理模块还用于,根据读取的上述VHFS请求所在内存的地址,读取上述VHFS请求,根据上述VHFS请求执行对上述共享文件的上述操作。
在本发明一些实施例中,上述操作信息包括文件信息和操作命令,上述文件操作命令所指示的操作包括文件打开操作、文件读取操作、文件写入操作、文件创建操作和浏览目录操作中的任意一种。
在本发明一些实施例中,上述VHFSD处理模块具体用于,当上述操作命令所指示的操作包括上述文件打开操作或文件读取操作时,将上述虚拟机物理地址转换成主机逻辑地址;根据上述主机逻辑地址以及上述文件信息,查找到上述共享文件;对查找到的上述共享文件执行上述操作命令所指示的操作。
在本发明一些实施例中,上述VHFSD处理模块还用于,将执行上述操作的操作结果,返回给上述虚拟机。
可选地,上述文件信息包括文件描述符或文件路径或文件的节点索引。
本发明第五方面提供了一种共享文件的访问系统,包括第三方面提供的虚拟机,以及第四方面提供的宿主机。
附图说明
为了更清楚地说明本发明实施例的技术方案,下面将对本发明实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为现有技术提供的宿主机-虚拟机模型;
图2为现有技术提供的宿主机与虚拟机基于网络文件系统进行文件共享的示意图;
图3为本发明一些实施例提供的共享文件的访问系统的结构示意图;
图4为本发明实施例提供的共享文件的访问方法的流程示意图;
图5为本发明实施例提供的共享文件的访问方法的信令图;
图6a为本发明实施例提供的文件打开流程;
图6b为本发明实施例提供的宿主机的文件系统与虚拟机的文件系统之间的数据对应关系;
图7a为本发明一些实施例提供的共享文件的写入方法的信令图;
图7b为本发明实施例提供的写文件的流程示意图;
图8为本发明一些实施例提供的索引节点操的流程示意图;
图9为本发明实施例提供的虚拟机的结构示意图;
图10为本发明一些实施例提供的宿主机的结构示意图;
图11为本发明实施例提供的共享文件的访问系统的结构示意图;
图12为本发明实施例提供的共享文件的访问装置的结构示意图。
具体实施方式
下面将结合本发明实施例的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
本发明实施例提供了一种共享文件的访问方法,用于简化文件访问流程,提高文件访问效率。本发明实施例还提供了一种共享文件的访问方法对应的系 统、虚拟机及宿主机。
首先,先简单地介绍一下本发明实施例提供的共享文件的访问系统,请参阅图3,图3为本发明实施例提供的共享文件的访问系统的结构示意图。在图3中,共享文件的访问系统包括宿主机和虚拟机,其中,宿主机安装有文件系统(File System,简称FS),FS下还安装着VFS,宿主机中还有各种通用寄存器,并在宿主机中设置一个VHFSD(Virtual Host File System Handle,简称VHFSD)处理模块,该VHFSD处理模块主要用于在宿主机这端处理VHFS请求。虚拟机中安装有VFS,并在VFS下安装有VHFS处理模块,用于在虚拟机这端处理VHFS请求。
在宿主机需要共享文件给虚拟机时,将某个文件目录下的文件共享到VHFS上。比如,在使用时,通过一条mount指令把宿主机VFS系统目录下的文件挂载到虚拟机的VHFS上:
mount-t vhfs host:/home/test/mnt/hostfs/test
即把宿主机的/home/test目录挂载到虚拟机的/mnt/hostfs/test上。
VHFS能够实现文件系统的各类标准操作,比如浏览目录操作(dentry_ops)、文件的节点索引操作(inode_ops)以及文件操作(file_ops)等,其中,file_ops可以看做一个集合,集合了所有文件的操作,比如,文件打开操作、文件读取操作、文件写入操作、文件创建操作等,其它项也仅是某一个大功能的集合,里面还集合了各种具体操作,在此不再一一赘述。
宿主机运行在根(root)模式下(根模式是宿主机运行的层级),而虚拟机运行在非根(non-root)模式(非根模式是虚拟机运行的层级)下。而本发明实施例中提供了一种Vmcall门,用于实现根模式与非根模式之间的切换,从非根模式到根模式,将控制权交给宿主机;根模式到非根模式,将控制权交给虚拟机。
可以看出,在本发明实施例中,只需要在虚拟机中安装一个VHFS文件系统和设置一个VHFS处理模块,其中,VHFS文件系统用于共享宿主机共享过来的文件目录,VHFS处理模块用于处理VHFS文件系统中文件相关的VHFS请求。另外,在宿主机中设置VHFSD处理模块,VHFSD处理模块去完成对VHFS请求的处理,能够简化系统参与共享文件操作的组件,简化了文件操作 的流程,提高文件访问效率。
需要说明,本发明实施例中宿主机共享给虚拟机的文件为配置虚拟机需要的文件,或者是虚拟机运行业务时需要的文件,或者是包括着配置虚拟机需要的数据信息,或者是包括着运行业务需要的数据信息等。
基于上述介绍,本发明实施例提供了一种共享文件的访问方法。请参阅图4,图4为本发明实施例提供的共享文件的访问方法的流程示意图;如图4所示,一种共享文件的访问方法可包括:
401、上述虚拟机检测对上述VHFS中共享文件的操作,获得操作信息;
宿主机中共享到VHFS文件系统上给予虚拟机使用的共享文件,可以由用户操作或者是在配置虚拟机时自行操作,具体可以对虚拟机中的共享文件的目录项进行操作、对文件的节点索引进行操作,对文件进行操作。而文件操作包括有对文件打开操作、文件读取操作、文件写入操作以及文件创建操作、文件删除操作等。
需要说明,对应不同的操作,所获取到的操作信息有所不同。比如,若是文件打开操作,那么操作信息会包括文件路径信息和操作命令等。若为文件读取操作,操作信息中包括文件描述符(fd)和操作命令等。若为文件写入操作,操作信息中包括文件描述符(fd)、操作命令和写入内容等。若为文件的节点索引操作,操作信息中包括文件的索引节点、操作命令等。
其中,操作命令所指示的操作为上述具体介绍的各种操作。
在本发明实施例中,将操作信息中的内容大致归为两类,一类是文件信息、另一类是操作命令。文件信息即包括上述文件路径信息或文件描述符(fd)或写入内容等。
当然,此时系统的操作模式为非根模式下,即为虚拟机的运行层级。
402、上述虚拟机根据上述操作信息生成VHFS请求,并将上述VHFS请求写入上述虚拟机的内存,上述VHFS请求用于请求上述宿主机在上述宿主机上完成对上述共享文件的上述操作;
虚拟机根据操作信息生成VHFS请求,可以理解,VHFS请求中将包括操作信息中的内容,由于操作信息根据不同的操作而有所不同,因此,VHFS请求包括的内容也将因不同的操作而有所不同。
若为文件打开操作时,VHFS请求包括文件路径信息和操作命令等。若为文件的节点索引操作,VHFS请求中包括文件的索引节点、操作命令等。
但是,若为文件读取操作和文件写入操作,VHFS请求中除了包括操作信息中的内容外,还包括虚拟机物理地址。因为,在对文件读取操作和写入操作时,需要涉及到虚拟机上的文件缓冲区,也就是共享文件将需要被放入到文件缓冲区。
需要说明,文件缓冲区是虚拟机管理着,对应着一个虚拟机逻辑地址,但宿主机无法识别虚拟机逻辑地址,因此,还需要将共享文件所在缓冲区的虚拟机逻辑地址转换成虚拟机物理地址。那么,在生成VHFS请求之前,需要将共享文件所在缓冲区的虚拟机逻辑地址转换成虚拟机物理地址。
还需要说明,宿主机虚拟出虚拟机时,需要给虚拟机分配内存和寄存器等,因此,虚拟机将VHFS请求写入内存,也就是写入宿主机分配给虚拟机的内存,后续宿主机能够从该内存中读取到VHFS请求。
403、上述虚拟机将上述VHFS请求所在内存的地址写入预置通用寄存器,并调用系统切换指令以使上述宿主机处理上述VHFS请求;
404、上述宿主机检测到上述虚拟机调用系统切换指令,从预置通用寄存器中读取VHFS请求所在内存的地址,上述VHFS请求为上述虚拟机根据用户对上述虚拟机中的VHFS的共享文件的操作生成,上述VHFS请求用于请求上述宿主机在上述宿主机上完成对上述共享文件的上述操作;
在本发明实施例中,将根据用户对共享文件的操作信息生成VHFS请求后,将VHFS请求写入内存,然后将内存的地址写入预置通用寄存器,该预置通用寄存器可以是宿主机分配给虚拟机用于保存VHFS请求的,因此,宿主机通过访问该预置通用寄存器,从中读取到VHFS请求所在内存的地址,然后根据地址去内存中读取到VHFS请求。
在上述介绍了虚拟机是运行在系统非根模式下,而宿主机是运行在系统根模式下。虚拟机将VHFS请求所在内存的地址写入寄存器后,后续将由宿主机完成对VHFS请求的操作,此时,虚拟机需要退出非根模式,然后让系统进入根模式,以便宿主机获取控制权。
在图3给出的共享文件的访问系统中,以通过vmcall门来实现虚拟机与 宿主机之间的切换,具体地,若是利用vmcall退出非根模式,则步骤403具体包括:将上述VHFS请求所在内存的地址写入上述预置通用寄存器;调用vmcall指令退出非根模式,以使得上述宿主机获得控制权然后处理上述VHFS请求。其中,发出一个调用vmcall的指令去调用vmcall,然后虚拟机将退出非根模式。
除了上述图3提供的通过vmcall在非根模式与根模式之间切换外,本发明实施例还可以通过HyperCall机制高效地访问宿主机的文件系统。比如,通过virtio机制来实现。宿主机事先模拟出一块外设部件互连标准(Peripheral Component Interconnect,简称PCI)设备,然后在虚拟机读写该PCI设备的配置空间时,将会触发虚拟机退出非根模式。在这种方式下,步骤403具体包括:将所述VHFS请求所在内存的地址写入外设部件互连标准PCI设备,并触发所述虚拟机退出非根模式,以使所述宿主机获得控制权处理所述VHFS请求。
需要说明,本发明实施例中的预置通用寄存器可以单独用于写入VHFS请求所在内存的地址,当然,由于资源受限,该预置通用寄存器还可能用于写入其它信息,因此,宿主机从该预置通用寄存器读取信息后,确定该信息是否为指向VHFS请求的内存地址。
405、上述宿主机根据读取的上述VHFS请求所在内存的地址,读取上述VHFS请求,根据上述VHFS请求执行对上述共享文件的上述操作。
可以理解,本发明实施例中根据上述VHFS请求执行对上述共享文件的上述操作是指:宿主机将所述虚拟机物理地址转换成主机逻辑地址,根据所述主机逻辑地址以及所述文件信息,查找到所述共享文件,对查找到的所述共享文件执行所述操作命令所指示的操作。
需要说明,处理完VHFS请求中操作命令的操作结果将返回给虚拟机,对于不同的操作,其操作结果也会有所不同,比如,文件打开操作,操作结果中包括文件描述符(fd)。对于文件写入操作或者文件读取操作等,操作结果为失败指示或成功指示。
可以看出,虚拟机通过检测用户对VHFS中共享文件的操作,以获得操作信息,然后根据操作信息生成VHFS请求,将VHFS请求写入虚拟机的内存中,之后再将VHFS请求所在内存的地址写入预置通用寄存器,调用系统切换指令 后退出,然后由宿主机来执行后续对VHFS请求的操作。其中,由于预置的寄存器可以由虚拟机操作,也可以由宿主机操作,而虚拟机的内存也是从宿主机的内存中划分给虚拟机的,因此,宿主机可以从预置通用寄存器中拿到VHFS请求所在内存的地址,然后去内存中读取VHFS请求,然后处理该VHFS请求。本发明实施例中整个对文件的操作步骤比较简单,不需要涉及太多的拷贝,能够有效提高文件共享中处理文件的效率。
请参阅图5和图6a,图5为本发明一些实施例提供的共享文件的访问方法的信令图;图6a为本发明实施例提供的文件打开流程;如图5所示,一种共享文件的访问方法可包括:
501、虚拟机检测对共享文件的打开操作,获得操作信息;
该操作信息中包括路径信息和操作命令等。
502、虚拟机调用应用程序,根据操作信息生成VHFS请求,将VHFS请求保存到内存,将VHFS请求所在内存的地址写入预置通用寄存器;
其中,虚拟机通过应用程序调用sys_open函数去试图打开某个文件。具体地,调用的是sys_open下的dentry_open函数,实际上就是VHFS系统下的open函数。VHFS的open函数会初始化VHFS请求,也就是生成了一个VHFS请求。
503、虚拟机调用vmcall指令退出非根模式,将控制权交给宿主机;
虚拟机调用vmcall指令退出非根模式,把控制权交给宿主机。
504、宿主机调度VCPU线程捕捉到vmcall指令,从预置通用寄存器读取VHFS请求所在内存的地址,根据地址去内存中读取到VHFS请求,然后执行VHFS请求中的打开共享文件的操作;
宿主机读取到VHFS请求之后,调用文件系统中的vfs_open函数去执行打开共享文件的操作。
505、宿主机将打开的共享文件的文件描述符fd返回给虚拟机;
其中,在虚拟机的VHFS系统中还划分出一个结果区,宿主机完成打开共享文件的操作,将文件描述符fd更新到结果区。
在宿主机完成打开共享文件的操作之后,调用vmcall指令,宿主机退出根模式,将控制权再交给虚拟机。
请参阅图6b,图6b为本发明实施例提供的宿主机的文件系统与虚拟机的文件系统之间的数据对应关系。在图6b中,共享文件打开后,在宿主机中共享文件视为被一个vmm进程打开着,而文件描述符(fd)在vmm进程的描述符数组中保存。在虚拟机中,在对应的文件下划分一个私有结构区(private_data)中保存相同的一份文件描述符(fd),供后续读写文件时使用。
可以理解,宿主机将共享文件打开后,使用虚拟机的用户可以继续对打开的共享文件进行其它操作,比如写入操作或者读取操作。在写入操作和读取操作中将会使用保存的文件描述符,以减少操作流程。当然,对文件的写入操作和读取操作等都需要先打开文件,因此,打开文件作为读取文件和写入文件的前提条件。
请参阅图7a和图7b,图7a为本发明一些实施例提供的共享文件的写入方法的信令图;图7b为本发明实施例提供的写文件的流程示意图。在图7a和图7b中,一种共享文件的写入方法可包括:
701、虚拟机检测到对共享文件的文件写入操作,获得操作信息;
文件写入操作中,操作信息包括共享文件描述符(fd)、操作命令和写入内容等。
702、虚拟机从结果区中读取被打开的共享文件的文件描述符fd;
703、虚拟机将被打开的共享文件所在缓冲区的虚拟机逻辑地址转换成虚拟机物理地址;
704、虚拟机根据操作命令、写入内容、读取到的fd以及虚拟机物理地址生成VHFS请求;
705、虚拟机将VHFS请求写入内存,然后将内存地址写入寄存器;
706、虚拟机调用vmcall指令退出对VHFS请求的处理;
虚拟机调用系统中的sys_write函数开始写文件。其中,调用VHFS中的f_ops的相关hook函数组成生成VHFS请求,VHFS请求包括共享文件所在缓冲区的虚拟机物理地址,虚拟机物理地址由虚拟机逻辑地址转化而来。并把实际文件的fd从虚拟机的结果区中取出,作为VHFS请求的内容之一,然后调用vmcall指令退出虚拟机交给宿主机处理。
707、宿主机调度VCPU线程捕捉到vmcall指令,从寄存器读取VHFS请 求所在内存的地址,根据读取到的地址去内存读取到VHFS请求;
708、宿主机根据VHFS请求中的fd,去读取宿主机自己保存的fd,并将VHFS请求中的虚拟机物理地址转换成宿主机逻辑地址;
709、宿主机调用写入函数,根据宿主机逻辑地址将VHFS请求中的写入信息写入fd对应的共享文件中。
其中,宿主机在处理写入文件的VHFS请求时,先把文件缓冲区的虚拟机物理地址转成宿主机逻辑地址,然后调用vfs_write函数对对应共享文件进行写入操作。
对文件的写入操作是在文件被打开的基础上进行,文件在打开后宿主机将文件的fd返回给虚拟机进行保存,同时,宿主机也将保存着该fd,那么在文件写入操作时,宿主机则可以直接根据其保存着的fd去执行文件写入操作。
可以理解,在本发明实施例中对文件读取操作与文件写入操作相似,都是在文件被打开基础上,只是在文件读取操作的时候,VHFS请求没有包括写入内容。宿主机调用vfs_read函数对对应文件进行读取操作。
还可以理解,在本发明实施例中对文件的创建操作时,若是在某一个文件下创建文件,也将需要打开该文件。宿主机调用vfs_creat函数创建出一个文件,创建文件后,该文件将对应着一个文件描述符(fd),还有文件所在缓冲区的虚拟机逻辑地址、虚拟机物理地址和宿主机逻辑地址。
可以看出,本发明实施例提供的共享文件的访问方法中需要的组件少,仅需要安装相关内核模块(宿主机中一个VHFSD处理模块和虚拟机中一个VHFS处理模块)即可,不需要复杂配置。系统开销小,不需要多次拷贝操作文件的操作信息,仅需要完成GVA-GPA-HVA等地址转换,宿主机直接对文件缓冲区进行各类操作。极大提高文件访问效率。
请参阅图8,图8为本发明一些实施例提供的索引节点操的流程示意图。在图8中,检索节点操作包括虚拟机VFS系统中提供的创建索引节点(creat)、查找索引节点(lookup)、索引节点链接(link)、删除索引节点(unlink)、重命名索引节点(rename)、扩展路径(setxattr)、获取路径(getxattr)。在实现上述索引节点操作时(innode_ops)时,虚拟机启动应用程序,调用索引节点操作下的相应函数,进而去调用VHFS中索引节点操作(innode_ops)下的相应 函数,根据相应的索引节点操作,生成VHFS请求,该VHFS请求中包括了操作命令(具体可以是上述索引节点操作)和索引节点标识等。与上述其它操作相同,虚拟机将VHFS请求写入预置通用寄存器后,调用Vmcall退出非根模式。然后宿主机中的VHFSD模块处理该VHFS请求,在VHS相同中完成相应的索引节点操作,返回操作结果。
请参阅图9,图9为本发明实施例提供的虚拟机的结构示意图;如图9所示,一种虚拟机运行在宿主机上,虚拟机中安装有虚拟主机文件系统VHFS,宿主机的文件被共享到上述VHFS中,该虚拟机可包括:
VHFS处理模块,用于检测对上述VHFS中共享文件的操作,获得操作信息;根据上述操作信息生成VHFS请求,并将上述VHFS请求写入上述虚拟机的内存,上述VHFS请求用于请求上述宿主机在上述宿主机上完成对上述共享文件的上述操作;将上述VHFS请求所在内存的地址写入预置通用寄存器,并调用系统切换指令以使上述宿主机处理上述VHFS请求。
在本发明一些实施例中,上述VHFS处理模块具体用于,检测对上述VHFS中共享文件的操作,获得操作信息,上述操作信息包括文件信息和操作命令,上述文件操作命令所指示的操作包括文件打开操作、文件读取操作、文件写入操作、文件创建操作和浏览目录操作中的任意一种。
在本发明一些实施例中,上述VHFS处理模块具体用于当上述操作命令所指示的操作为文件读取操作或文件写入操作时,获取上述共享文件所在缓冲区的虚拟机逻辑地址,将上述虚拟机逻辑地址转换成上述虚拟机物理地址;根据上述文件信息、上述操作命令和上述虚拟机物理地址,生成上述VHFS请求,上述VHFS请求包括上述文件信息、上述操作命令和上述共享文件所在缓冲区的虚拟机物理地址。
在本发明一些实施例中,上述VHFS处理模块具体用于,将上述VHFS请求所在内存的地址写入上述预置通用寄存器;调用vmcall指令退出非根模式,以使上述宿主机处理上述VHFS请求。
在本发明一些实施例中,上述VHFS处理模块具体用于,将上述VHFS请求所在内存的地址写入上述宿主机虚拟的外设部件互连标准PCI设备,并触发上述虚拟机退出非根模式,以使上述宿主机获得控制权处理上述VHFS请 求。
请参阅图10,图10为本发明一些实施例提供的宿主机的结构示意图;如图10所示,该宿主机上运行着虚拟机,虚拟机中安装有VHFS,宿主机的文件被共享到每一个虚拟机的VHFS中,该宿主机包括:
VHFSD处理模块,用于检测到上述虚拟机调用系统切换指令,从预置通用寄存器中读取VHFS请求所在内存的地址,上述VHFS请求为上述虚拟机根据用户对上述虚拟机中的VHFS的共享文件的操作生成,上述VHFS请求用于请求上述宿主机在上述宿主机上完成对上述共享文件的上述操作;
上述VHFSD处理模块还用于,根据读取的上述VHFS请求所在内存的地址,读取上述VHFS请求,根据上述VHFS请求执行对上述共享文件的上述操作。
可选地,上述操作信息包括文件信息和操作命令,上述文件操作命令所指示的操作包括文件打开操作、文件读取操作、文件写入操作、文件创建操作和浏览目录操作中的任意一种。
在本发明一些实施例中,上述VHFSD处理模块具体用于,当上述操作命令所指示的操作包括上述文件打开操作或文件读取操作时,将上述虚拟机物理地址转换成主机逻辑地址;根据上述主机逻辑地址以及上述文件信息,查找到上述共享文件;对查找到的上述共享文件执行上述操作命令所指示的操作。
在本发明一些实施例中,上述VHFSD处理模块还用于,将执行上述操作的操作结果,返回给上述虚拟机。
请参阅图11,图11为本发明实施例提供的共享文件的访问系统的结构示意图;如图11所示,一种共享文件的访问系统可包括:
图9提供的虚拟机和图10提供的宿主机,其中,对虚拟机和宿主机的详细介绍可以参阅方法实施例和装置实施例中的说明,在此不再赘述。
请参考图12,图12为本发明实施例提供的共享文件的访问装置的结构示意图,其中,可包括至少一个处理器1201(例如CPU,Central Processing Unit),至少一个网络接口或者其它通信接口,存储器1202,和至少一个通信总线,用于实现这些装置之间的连接通信。上述处理器1201用于执行存储器中存储的可执行模块,例如计算机程序。上述存储器1202可能包含高速随机存取存 储器(RAM,Random Access Memory),也可能还包括非不稳定的存储器(non-volatile memory),例如至少一个磁盘存储器。通过至少一个网络接口(可以是有线或者无线)实现该系统网关与至少一个其它网元之间的通信连接,可以使用互联网,广域网,本地网,城域网等。
如图12所示,在一些实施方式中,上述存储器1202中存储了程序指令,程序指令可以被处理器1201执行,上述处理器1201具体执行以下步骤:
检测对上述VHFS中共享文件的操作,获得操作信息;根据上述操作信息生成VHFS请求,并将上述VHFS请求写入上述虚拟机的内存,上述VHFS请求用于请求上述宿主机在上述宿主机上完成对上述共享文件的上述操作;将上述VHFS请求所在内存的地址写入预置通用寄存器,并调用系统切换指令以使上述宿主机处理上述VHFS请求;
或者,检测到上述虚拟机调用系统切换指令,从预置通用寄存器中读取VHFS请求所在内存的地址,上述VHFS请求为上述虚拟机根据用户对上述虚拟机中的VHFS的共享文件的操作生成,上述VHFS请求用于请求上述宿主机在上述宿主机上完成对上述共享文件的上述操作;根据读取的上述VHFS请求所在内存的地址,读取上述VHFS请求,根据上述VHFS请求执行对上述共享文件的上述操作。
在一些实施方式中,上述处理器1201还可以执行以下步骤:检测对上述VHFS中共享文件的操作,获得操作信息,上述操作信息包括文件信息和操作命令,上述文件操作命令所指示的操作包括文件打开操作、文件读取操作、文件写入操作、文件创建操作和浏览目录操作中的任意一种。
在一些实施方式中,上述处理器1201还可以执行以下步骤:当上述操作命令所指示的操作为文件读取操作或文件写入操作时,获取上述共享文件所在缓冲区的虚拟机逻辑地址,将上述虚拟机逻辑地址转换成上述虚拟机物理地址;根据上述文件信息、上述操作命令和上述虚拟机物理地址,生成上述VHFS请求,上述VHFS请求包括上述文件信息、上述操作命令和上述共享文件所在缓冲区的虚拟机物理地址。
在一些实施方式中,上述处理器1201还可以执行以下步骤:将上述VHFS请求所在内存的地址写入上述预置通用寄存器;调用vmcall指令退出非根模 式,以使上述宿主机处理上述VHFS请求。
在一些实施方式中,上述处理器1201还可以执行以下步骤:将上述VHFS请求所在内存的地址写入上述宿主机虚拟的外设部件互连标准PCI设备,并触发上述虚拟机退出非根模式,以使上述宿主机获得控制权处理上述VHFS请求。
在一些实施方式中,上述处理器1201还可以执行以下步骤:当上述操作命令所指示的操作包括上述文件打开操作或文件读取操作时,将上述虚拟机物理地址转换成主机逻辑地址;根据上述主机逻辑地址以及上述文件信息,查找到上述共享文件;对查找到的上述共享文件执行上述操作命令所指示的操作。
在一些实施方式中,上述处理器1201还可以执行以下步骤:将执行上述操作的操作结果,返回给上述虚拟机。
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元 中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。
以上对本发明所提供的一种共享文件的访问方法、系统及相关设备进行了详细介绍,对于本领域的一般技术人员,依据本发明实施例的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本发明的限制。

Claims (23)

  1. 一种共享文件的访问方法,其特征在于,应用于虚拟机,所述虚拟机运行在宿主机上,所述虚拟机中安装有虚拟主机文件系统VHFS,所述宿主机的文件被共享到所述VHFS中,所述方法包括:
    所述虚拟机检测对所述VHFS中共享文件的操作,获得操作信息;
    所述虚拟机根据所述操作信息生成VHFS请求,并将所述VHFS请求写入所述虚拟机的内存,所述VHFS请求用于请求所述宿主机在所述宿主机上完成对所述共享文件的所述操作;
    所述虚拟机将所述VHFS请求所在内存的地址写入预置通用寄存器,并调用系统切换指令以使所述宿主机处理所述VHFS请求。
  2. 根据权利要求1所述的方法,其特征在于,所述虚拟机检测对所述VHFS中共享文件的操作,获得操作信息包括:
    所述虚拟机检测对所述VHFS中共享文件的操作,获得操作信息,所述操作信息包括文件信息和操作命令,所述文件操作命令所指示的操作包括文件打开操作、文件读取操作、文件写入操作、文件创建操作和浏览目录操作中的任意一种。
  3. 根据权利要求2所述的方法,其特征在于,所述虚拟机根据所述操作信息生成VHFS请求包括:
    当所述操作命令所指示的操作为文件读取操作或文件写入操作时,所述虚拟机获取所述共享文件所在缓冲区的虚拟机逻辑地址,将所述虚拟机逻辑地址转换成所述虚拟机物理地址;
    所述虚拟机根据所述文件信息、所述操作命令和所述虚拟机物理地址,生成所述VHFS请求。
  4. 根据权利要求1~3任一项所述的方法,其特征在于,所述虚拟机将所述VHFS请求所在内存的地址写入预置通用寄存器,并调用系统切换指令以使所述宿主机处理所述VHFS请求包括:
    所述虚拟机将所述VHFS请求所在内存的地址写入所述预置通用寄存器;
    所述虚拟机调用vmcall指令退出非根模式,以使所述宿主机获得控制权处理所述VHFS请求。
  5. 根据权利要求1~3任一项所述的方法,其特征在于,所述虚拟机将所述VHFS请求所在内存的地址写入预置通用寄存器,并调用系统切换指令以使所述宿主机处理所述VHFS请求包括:
    所述虚拟机将所述VHFS请求所在内存的地址写入所述宿主机虚拟的外设部件互连标准PCI设备,并触发所述虚拟机退出非根模式,以使所述宿主机获得控制权处理所述VHFS请求。
  6. 根据权利要求2或3所述的方法,其特征在于,所述文件信息包括文件描述符或文件路径或文件的节点索引。
  7. 一种共享文件的访问方法,其特征在于,应用于宿主机,所述宿主机运行着若干虚拟机,每一个虚拟机中安装有虚拟主机文件系统VHFS,所述宿主机的文件被共享到每一个虚拟机的VHFS中,包括:
    所述宿主机检测到所述虚拟机调用系统切换指令,从预置通用寄存器中读取VHFS请求所在内存的地址,所述VHFS请求为所述虚拟机根据对所述虚拟机中的VHFS的共享文件的操作生成,所述VHFS请求用于请求所述宿主机在所述宿主机上完成对所述共享文件的所述操作;
    所述宿主机根据读取的所述VHFS请求所在内存的地址,读取所述VHFS请求,根据所述VHFS请求执行对所述共享文件的所述操作。
  8. 根据权利要求7所述的方法,其特征在于,所述操作信息包括文件信息和操作命令,所述文件操作命令所指示的操作包括文件打开操作、文件读取操作、文件写入操作、文件创建操作和浏览目录操作中的任意一种。
  9. 根据权利要求8所述的方法,其特征在于,所述根据所述VHFS请求执行对所述共享文件的所述操作包括:
    当所述操作命令所指示的操作包括所述文件打开操作或文件读取操作时,所述宿主机将所述虚拟机物理地址转换成主机逻辑地址;
    所述宿主机根据所述主机逻辑地址以及所述文件信息,查找到所述共享文件;
    所述宿主机对查找到的所述共享文件执行所述操作命令所指示的操作。
  10. 根据权利要求7~9人任一项所述的方法,其特征在于,所述根据所述VHFS请求完成对所述共享文件的所述操作之后包括:
    所述宿主机将执行所述操作的操作结果,返回给所述虚拟机。
  11. 根据权利要求7~10任一项所述的方法,其特征在于,所述文件信息包括文件描述符或文件路径或文件的节点索引。
  12. 一种虚拟机,其特征在于,所述虚拟机运行在宿主机上,所述虚拟机中安装有虚拟主机文件系统VHFS,所述宿主机的文件被共享到所述VHFS中,所述虚拟机包括:
    VHFS处理模块,用于检测对所述VHFS中共享文件的操作,获得操作信息;根据所述操作信息生成VHFS请求,并将所述VHFS请求写入所述虚拟机的内存,所述VHFS请求用于请求所述宿主机在所述宿主机上完成对所述共享文件的所述操作;将所述VHFS请求所在内存的地址写入预置通用寄存器,并调用系统切换指令以使所述宿主机处理所述VHFS请求。
  13. 根据权利要求12所述的虚拟机,其特征在于,
    所述VHFS处理模块具体用于,检测对所述VHFS中共享文件的操作,获得操作信息,所述操作信息包括文件信息和操作命令,所述文件操作命令所指示的操作包括文件打开操作、文件读取操作、文件写入操作、文件创建操作和浏览目录操作中的任意一种。
  14. 根据权利要求13所述的虚拟机,其特征在于,
    所述VHFS处理模块具体用于,当所述操作命令所指示的操作为文件读取操作或文件写入操作时,获取所述共享文件所在缓冲区的虚拟机逻辑地址,将所述虚拟机逻辑地址转换成所述虚拟机物理地址;根据所述文件信息、所述操作命令和所述虚拟机物理地址,生成所述VHFS请求,所述VHFS请求包括所述文件信息、所述操作命令和所述共享文件所在缓冲区的虚拟机物理地址。
  15. 根据12~14任一项所述的虚拟机,其特征在于,
    所述VHFS处理模块具体用于,将所述VHFS请求所在内存的地址写入所述预置通用寄存器;调用vmcall指令退出非根模式,以使所述宿主机处理所述VHFS请求。
  16. 根据权利要求12~14任一项所述的虚拟机,其特征在于,
    所述VHFS处理模块具体用于,将所述VHFS请求所在内存的地址写入所述宿主机虚拟的外设部件互连标准PCI设备,并触发所述虚拟机退出非根模 式,以使所述宿主机获得控制权处理所述VHFS请求。
  17. 根据权利要求12或13所述的虚拟机,所述文件信息包括文件描述符或文件路径或文件的节点索引。
  18. 一种宿主机,其特征在于,所述宿主机运行着若干虚拟机,每一个虚拟机中安装有虚拟主机文件系统VHFS,所述宿主机的文件被共享到每一个虚拟机的VHFS中,包括:
    VHFSD处理模块,用于检测到所述虚拟机调用系统切换指令,从预置通用寄存器中读取VHFS请求所在内存的地址,所述VHFS请求为所述虚拟机根据用户对所述虚拟机中的VHFS的共享文件的操作生成,所述VHFS请求用于请求所述宿主机在所述宿主机上完成对所述共享文件的所述操作;
    所述VHFSD处理模块还用于,根据读取的所述VHFS请求所在内存的地址,读取所述VHFS请求,根据所述VHFS请求执行对所述共享文件的所述操作。
  19. 根据权利要求18所述的宿主机,其特征在于,所述操作信息包括文件信息和操作命令,所述文件操作命令所指示的操作包括文件打开操作、文件读取操作、文件写入操作、文件创建操作和浏览目录操作中的任意一种。
  20. 根据权利要求19所述的宿主机,其特征在于,
    所述VHFSD处理模块具体用于,当所述操作命令所指示的操作包括所述文件打开操作或文件读取操作时,将所述虚拟机物理地址转换成主机逻辑地址;根据所述主机逻辑地址以及所述文件信息,查找到所述共享文件;对查找到的所述共享文件执行所述操作命令所指示的操作。
  21. 根据权利要求18~20任一项所述的宿主机,其特征在于,
    所述VHFSD处理模块还用于,将执行所述操作的操作结果,返回给所述虚拟机。
  22. 根据权利要求18~21任一项所述的宿主机,其特征在于,
    所述文件信息包括文件描述符或文件路径或文件的节点索引。
  23. 一种共享文件的访问系统,其特征在于,包括:权利要求12~17任一项所述的虚拟机,以及权利要求18~22任一项所述的宿主机。
PCT/CN2016/107085 2015-12-09 2016-11-24 一种共享文件的访问方法、系统及相关设备 WO2017097114A1 (zh)

Applications Claiming Priority (4)

Application Number Priority Date Filing Date Title
CN201510904100 2015-12-09
CN201510904100.1 2015-12-09
CN201511032923.6 2015-12-31
CN201511032923.6A CN105447203B (zh) 2015-12-31 2015-12-31 一种共享文件的访问方法、系统及相关设备

Publications (1)

Publication Number Publication Date
WO2017097114A1 true WO2017097114A1 (zh) 2017-06-15

Family

ID=59012683

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/107085 WO2017097114A1 (zh) 2015-12-09 2016-11-24 一种共享文件的访问方法、系统及相关设备

Country Status (1)

Country Link
WO (1) WO2017097114A1 (zh)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112463307A (zh) * 2020-12-11 2021-03-09 深信服科技股份有限公司 一种数据传输方法、装置、设备及可读存储介质
CN113127853A (zh) * 2019-12-31 2021-07-16 奇安信科技集团股份有限公司 对虚拟机文件的安全处理方法及装置
CN113282323A (zh) * 2021-05-31 2021-08-20 惠州华阳通用电子有限公司 一种基于双系统升级包共享的升级方法

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110173608A1 (en) * 2009-07-23 2011-07-14 Brocade Communications Systems, Inc. Method and Apparatus for Providing Virtual Machine Information to a Network Interface
CN103034684A (zh) * 2012-11-27 2013-04-10 北京航空航天大学 一种基于内容寻址存储的虚拟机镜像存储优化方法
CN103389884A (zh) * 2013-07-29 2013-11-13 华为技术有限公司 处理输入/输出请求的方法、宿主机、服务器和虚拟机
CN103593607A (zh) * 2013-11-26 2014-02-19 北京搜狐新媒体信息技术有限公司 宿主机与虚拟机文件系统隔离方法和装置
CN105447203A (zh) * 2015-12-31 2016-03-30 杭州华为数字技术有限公司 一种共享文件的访问方法、系统及相关设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110173608A1 (en) * 2009-07-23 2011-07-14 Brocade Communications Systems, Inc. Method and Apparatus for Providing Virtual Machine Information to a Network Interface
CN103034684A (zh) * 2012-11-27 2013-04-10 北京航空航天大学 一种基于内容寻址存储的虚拟机镜像存储优化方法
CN103389884A (zh) * 2013-07-29 2013-11-13 华为技术有限公司 处理输入/输出请求的方法、宿主机、服务器和虚拟机
CN103593607A (zh) * 2013-11-26 2014-02-19 北京搜狐新媒体信息技术有限公司 宿主机与虚拟机文件系统隔离方法和装置
CN105447203A (zh) * 2015-12-31 2016-03-30 杭州华为数字技术有限公司 一种共享文件的访问方法、系统及相关设备

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113127853A (zh) * 2019-12-31 2021-07-16 奇安信科技集团股份有限公司 对虚拟机文件的安全处理方法及装置
CN112463307A (zh) * 2020-12-11 2021-03-09 深信服科技股份有限公司 一种数据传输方法、装置、设备及可读存储介质
CN112463307B (zh) * 2020-12-11 2024-02-23 深信服科技股份有限公司 一种数据传输方法、装置、设备及可读存储介质
CN113282323A (zh) * 2021-05-31 2021-08-20 惠州华阳通用电子有限公司 一种基于双系统升级包共享的升级方法

Similar Documents

Publication Publication Date Title
US10324748B2 (en) Augmented tracking of modified memory pages during live migration of virtual machines from/to host computers with graphics processors
US10684876B2 (en) Migration of virtual machine data using native data paths
US9766921B2 (en) Fast-booting application image using variation points in application source code
US8832688B2 (en) Kernel bus system with a hyberbus and method therefor
US9542237B2 (en) Shared locking for storage centric exclusive locks
US11010355B2 (en) Layer-based file access method and apparatus of virtualization instance
CN105447203B (zh) 一种共享文件的访问方法、系统及相关设备
US9594583B2 (en) Lightweight snapshots for virtual disks
US9613053B1 (en) Techniques for providing access to a virtualized block storage device over a file-based network storage protocol
US9183130B2 (en) Data control system for virtual environment
CN106777394B (zh) 一种集群文件系统
US20190258503A1 (en) Method for operating virtual machines on a virtualization platform and corresponding virtualization platform
WO2016119322A1 (zh) 确定读写路径的方法和装置
US11231953B2 (en) Minimizing downtime when importing virtual machines from other platforms
WO2016101282A1 (zh) 一种i/o任务处理的方法、设备和系统
US9898307B2 (en) Starting application processors of a virtual machine
WO2017097114A1 (zh) 一种共享文件的访问方法、系统及相关设备
US9729660B2 (en) Method and system for detecting virtual machine migration
US20150254364A1 (en) Accessing a file in a virtual computing environment
US20140229566A1 (en) Storage resource provisioning for a test framework
Madhavapeddy et al. Turning Down the {LAMP}: Software Specialisation for the Cloud
US9575658B2 (en) Collaborative release of a virtual disk
US20120124355A1 (en) Single volume image file extraction
WO2022083158A1 (zh) 数据处理的方法、实例以及系统
US11748136B2 (en) Event notification support for nested virtual machines

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16872306

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16872306

Country of ref document: EP

Kind code of ref document: A1