A method, system, and electronic device for accessing virtual machine disks.
By migrating the virtual machine disk read/write module from the kernel layer to the application layer and leveraging cross-layer communication between the Ramdisk driver and the processing module, the complexity of virtual machine disk access and system stability issues are resolved, resulting in more stable virtual machine disk operations.
Patent Information
- Application Number
- CN202210461675.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-28
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2042-04-28
AI Technical Summary
In existing technologies, virtual machine disk access processes are complex and prone to system crashes, especially due to system instability caused by the virtual machine disk read/write module at the kernel level.
The virtual machine disk read/write module is elevated from the system kernel layer to the application layer. It operates through the communication channel between the Ramdisk read/write processing module and the Ramdisk driver module, and cross-layer communication is achieved by utilizing shared memory and event object handles. Device object virtual disks are created for file system operations.
It simplifies the virtual machine disk access process, avoids the risk of system crashes, improves system stability, and facilitates the operation and management of virtual machine disk files.
Smart Images

Figure CN114756330B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method, system, and electronic device for accessing a virtual machine disk. Background Technology
[0002] A virtual machine (VM) is a complete computer system simulated by software, possessing full hardware system functionality and running in a completely isolated environment. Any task that can be performed on a physical computer can also be performed in a VM. When creating a VM, a portion of the physical machine's hard drive and memory capacity is used as the VM's hard drive and memory capacity. Each VM has its own independent CMOS, hard drive, and operating system, and can be operated just like a physical machine.
[0003] Converting a current or backed-up Windows system into a virtual machine and completing the disk data conversion may require reading and writing to the target virtual machine's disk files. This could involve modifying the system and boot partitions, changing boot-related parameters, and adding virtual machine boot-related drivers. The conversion program needs to access the file systems within the partitions of the virtual machine's disk.
[0004] Virtual machine disks are primarily stored as files on the host machine. Current technology uses virtual disk drivers to simulate virtual machine disk files as disk devices for application access. The access process is as follows: Figure 1 As shown:
[0005] 1. The application calls the system read / write API, generating a request that is sent to the file system driver.
[0006] 2. The file system parses the requested content, locates the file's storage location, and converts it into a block read / write request for the virtual disk, which is then sent to the virtual disk driver.
[0007] 3. The virtual disk driver calls the virtual machine image read / write module to read and write the contents of the virtual machine disk file, and returns the results to the upper layer through the same path.
[0008] In the above architecture, the file system driver, virtual disk driver, and virtual machine read / write module are all located in the system kernel, making them complex to call and lacking in versatility. In addition, calling the system kernel can easily cause system crashes. Summary of the Invention
[0009] In view of this, the present invention provides a method, system and electronic device for virtual machine disk access, which moves the virtual machine disk read and write module that originally runs at the kernel layer to the application layer for execution.
[0010] To solve the above technical problems, the technical solution of the present invention is to adopt a virtual machine disk access method, including:
[0011] The disk information of virtual machine disk V is passed to the Ramdisk read / write processing module;
[0012] The Ramdisk read / write processing module creates a communication channel T with the Ramdisk driver module;
[0013] The Ramdisk driver module creates a device object virtual disk D;
[0014] When an application attempts to read or write to virtual disk D through the Windows file system to operate virtual disk V, the Ramdisk driver module transmits the read / write commands for virtual disk D from the Windows file system to the Ramdisk read / write processing module through communication channel T.
[0015] The Ramdisk read / write processing module reads and writes to the virtual machine disk V, and feeds back the results of the read / write operation to the Ramdisk driver module through the communication channel T.
[0016] The Ramdisk driver module forwards the results of the read and write operations to the Windows file system, which then feeds them back to the application.
[0017] As an improvement, the Ramdisk read / write processing module establishes a communication channel T with the Ramdisk driver module through shared memory.
[0018] As a further improvement, the method for the Ramdisk read / write processing module to create a communication channel T with the Ramdisk driver module includes:
[0019] The Ramdisk read / write processing module allocates memory and event object handles, and passes the allocated memory and event object handles to the Ramdisk driver module through the deviceioctrl function;
[0020] The Ramdisk driver module maps the memory and event object handles allocated by the Ramdisk read / write processing module to kernel addresses, thereby sharing the memory and event objects with the Ramdisk read / write processing program.
[0021] As another further improvement, the method by which the Ramdisk driver module creates the device object virtual disk D includes:
[0022] When the Ramdisk driver module is loaded into memory by the Windows system, the Ramdisk driver module's main function calls the ioCreateDevice function in the Windows system API to create a device object, virtual disk D.
[0023] As an improvement, the virtual disk D is mapped as a drive letter or symbolic link for application operations.
[0024] As an improvement, the Ramdisk read / write processing module performs read and write operations on the virtual machine disk V by calling the ReadFile / WriteFile commands.
[0025] The present invention also provides a virtual machine disk access system, comprising:
[0026] The Ramdisk read / write processing module, located in the system application layer, is used to perform read and write operations on the virtual machine disk; it creates a communication channel with the Ramdisk driver module and feeds back the results of the read and write operations on the virtual machine disk to the Ramdisk driver module through the communication channel.
[0027] The Ramdisk driver module, located in the system kernel layer, is used to create device object virtual disks for Windows file system operations; it transmits Windows file system read and write operation commands for device object virtual disks to the Ramdisk read and write processing module through a communication channel, and forwards the read and write results fed back by the Ramdisk read and write processing module to the Windows file system.
[0028] The control module, located in the system application layer, is used to pass the disk information of the virtual machine disk to be operated to the Ramdisk read / write processing module; control the Ramdisk read / write processing module to create a communication channel with the Ramdisk driver module; and control the Ramdisk driver module to create device objects.
[0029] As an improvement, the Ramdisk read / write processing module includes:
[0030] The virtual machine disk read / write module is used for reading and writing operations on the virtual machine disk.
[0031] The communication creation module is used to create a communication channel with the Ramdisk driver module;
[0032] The data transmission module is used to receive read and write commands forwarded by the Ramdisk driver module and send the results of read and write operations on the virtual machine disk to the Ramdisk driver module.
[0033] As an improvement, the Ramdisk driver module includes:
[0034] The device object creation module is used to create virtual disks for device objects to operate on using the Windows file system.
[0035] The data transmission module is used to receive read and write operation commands from the Windows file system for the virtual disk and forward them to the Ramdisk read and write processing module; it also receives the read and write operation results from the Ramdisk read and write processing module for the virtual machine disk and forwards them to the Windows file system.
[0036] The present invention also provides an electronic device, including a processor and a storage medium, characterized in that: the storage medium stores a program that enables the above-described virtual machine disk access method when the processor executes the program.
[0037] The advantages of this invention are as follows: It moves the virtual machine disk file read / write module, which originally ran at the kernel level, to the application layer for execution. This avoids many limitations inherent in kernel development, such as memory requirements, the inability to call application-layer DLL modules, and the need for re-encoding and parsing of virtual machine disk files within the kernel. With the virtual machine disk file read / write module at the application layer, only one module is needed to handle cloning and file operations. Moving complex kernel operations to application processing also avoids system instability caused by program instability, preventing system crashes and blue screens. Problems in the application-layer program only affect the execution of that program itself. Attached Figure Description
[0038] Figure 1 This is a schematic diagram of the existing virtual machine disk access process.
[0039] Figure 2 This is a schematic diagram of the structural principle of the present invention.
[0040] Figure 3 This is a flowchart of the present invention. Detailed Implementation
[0041] To enable those skilled in the art to better understand the technical solution of the present invention, the present invention will be further described in detail below with reference to specific embodiments.
[0042] Virtual machine disks are stored as files on storage devices such as hard drives, and their file format cannot be directly accessed by the Windows file system. Therefore, for the Windows file system to directly access a virtual machine disk, it must first be virtualized as a disk device. The current practice typically involves the Windows file system calling a virtual disk driver, which in turn calls the virtual machine disk read / write module to read the virtual machine disk files and then access them as a virtual disk. This necessitates that the virtual machine disk read / write module reside within the system kernel.
[0043] It should be noted that, in this invention, a virtual machine disk refers to a disk device simulated by software such as VMware or VPC, which is essentially a storage space of a hard disk or other storage medium, such as virtual machine disk V in this invention. A virtual disk, on the other hand, refers to a disk device created by partitioning off a portion of memory space; it is essentially a segment of memory storage space, such as virtual disk D in this invention.
[0044] To elevate the virtual machine disk read / write module to the application layer, such as Figure 2 As shown, the present invention provides a virtual machine disk access system, specifically including:
[0045] The Ramdisk read / write processing module, located in the system application layer, is used to perform read and write operations on the virtual machine disk. It creates a communication channel with the Ramdisk driver module and feeds back the results of the read and write operations on the virtual machine disk to the Ramdisk driver module through the communication channel.
[0046] The Ramdisk driver module, located in the system kernel layer, is used to create device object virtual disks for Windows file system operations. It transmits Windows file system read and write operation commands for device object virtual disks to the Ramdisk read and write processing module through a communication channel, and forwards the read and write results fed back by the Ramdisk read and write processing module to the Windows file system.
[0047] The control module, located in the system application layer, is used to pass the disk information of the virtual machine disk to be operated to the Ramdisk read / write processing module; control the Ramdisk read / write processing module to create a communication channel with the Ramdisk driver module; and control the Ramdisk driver module to create device objects.
[0048] Specifically, the Ramdisk read / write processing module includes:
[0049] The virtual machine disk read / write module is used for reading and writing operations on the virtual machine disk.
[0050] The communication creation module is used to create a communication channel with the Ramdisk driver module;
[0051] The data transmission module is used to receive read and write commands forwarded by the Ramdisk driver module and send the results of read and write operations on the virtual machine disk to the Ramdisk driver module.
[0052] The Ramdisk driver module includes:
[0053] The device object creation module is used to create virtual disks for device objects to operate on using the Windows file system.
[0054] The data transmission module is used to receive read and write operation commands from the Windows file system for the virtual disk and forward them to the Ramdisk read and write processing module; it also receives the read and write operation results from the Ramdisk read and write processing module for the virtual machine disk and forwards them to the Windows file system.
[0055] like Figure 3 As shown, the present invention also provides a virtual machine disk access method, including:
[0056] S1. Pass the disk information of virtual machine disk V to the Ramdisk read / write processing module. Specifically, the control module sends the disk information of virtual machine disk V, including disk size, sector size, and starting position, to the Ramdisk read / write processing module using the DeviceIOCtrl function, so that the Ramdisk read / write processing module can locate the position of virtual machine disk V on physical hard disks and other storage media.
[0057] S2. The Ramdisk read / write processing module creates a communication channel T with the Ramdisk driver module; in this embodiment, the Ramdisk read / write processing module establishes the communication channel T with the Ramdisk driver module through shared memory, specifically including:
[0058] S21. The Ramdisk read / write processing module allocates memory and event object handles, and passes the allocated memory and event object handles to the Ramdisk driver module through the deviceIOCtrl function.
[0059] S22. The Ramdisk driver module maps the memory and event object handles allocated by the Ramdisk read / write processing module to kernel addresses, thereby sharing the memory and event objects with the Ramdisk read / write processing program.
[0060] S3. The Ramdisk driver module creates a device object virtual disk D. Specifically, when the Ramdisk driver module is loaded into memory by the Windows system, its main function calls the ioCreateDevice function in the Windows system API to create the device object virtual disk D. To facilitate application operations on virtual disk D, it can be mapped to a drive letter or symbolic link, such as drive F. This creates a new drive letter F in the system, allowing applications to directly add, delete, and modify files within it through the Windows file system.
[0061] For applications and the Windows file system, accessing the virtual disk D and accessing the physical disk are the same steps. In this embodiment, by creating a communication channel T (shared memory) across the kernel layer and application layer between the Ramdisk driver module and the Ramdisk read / write processing module, it appears that the Windows file system is accessing the virtual disk D, but in reality, through data sharing between the Ramdisk driver module and the Ramdisk read / write processing module, read and write operations are actually performed on the virtual machine disk V, thereby achieving the goal of placing the virtual machine disk read / write processing module at the application layer.
[0062] Steps S1 to S3 are the preparatory work before the application accesses the virtual machine disk V. Starting from step S4, it is the specific process of the application operating on the virtual machine disk V.
[0063] S4. When an application attempts to read or write to the virtual disk D through the Windows file system to operate the virtual disk V, the Ramdisk driver module transmits the read / write commands of the Windows file system to the Ramdisk read / write processing module through the communication channel T.
[0064] S5. The Ramdisk read / write processing module reads and writes to the virtual machine disk V and feeds back the results of the read / write operation to the Ramdisk driver module through the communication channel T. Specifically, the Ramdisk read / write processing module performs read / write operations on the virtual machine disk V by calling the ReadFile / WriteFile command (i.e., the virtual machine disk read / write module in the system of this invention).
[0065] The S6 and Ramdisk driver modules forward the read and write results to the Windows file system, which then feeds them back to the application.
[0066] The present invention also provides an electronic device, including a processor and a storage medium, characterized in that: the storage medium stores a program that enables the above-described virtual machine disk access method when the processor executes the program.
[0067] In this invention, the Ramdisk driver module located in the system kernel does not directly read and write the virtual machine disk V. Instead, read and write commands are passed to the Ramdisk read and write processing module located in the system application layer to perform read and write operations on the virtual machine disk V, and then the results are fed back to the Windows file system. For the Windows file system and applications, they are accessing a virtual disk D, and the access method remains unchanged. By placing the Ramdisk read and write processing module in the system application layer, it is convenient to call the application layer DLL modules without re-encoding and parsing the virtual machine disk files. Even if errors occur, only the application is affected, and system instability is not caused.
[0068] The above are merely preferred embodiments of the present invention. It should be noted that the above preferred embodiments should not be considered as limitations on the present invention, and the scope of protection of the present invention should be determined by the scope defined in the claims. For those skilled in the art, several improvements and modifications can be made without departing from the spirit and scope of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A virtual machine disk access method, characterized in that... include: The disk information of virtual machine disk V is passed to the Ramdisk read / write processing module; The Ramdisk read / write processing module creates a communication channel T with the Ramdisk driver module; the Ramdisk read / write processing module establishes the communication channel T with the Ramdisk driver module through shared memory, including: The Ramdisk read / write processing module allocates memory and event object handles, and passes the allocated memory and event object handles to the Ramdisk driver module through the deviceioctrl function; The Ramdisk driver module maps the memory and event object handles allocated by the Ramdisk read / write processing module to kernel addresses, thereby sharing the memory and event objects with the Ramdisk read / write processing program; The Ramdisk driver module creates a device object virtual disk D; When an application attempts to read or write to virtual disk D through the Windows file system to operate virtual disk V, the Ramdisk driver module transmits the read / write commands for virtual disk D from the Windows file system to the Ramdisk read / write processing module through communication channel T. The Ramdisk read / write processing module reads and writes to the virtual machine disk V, and feeds back the results of the read / write operation to the Ramdisk driver module through the communication channel T. The Ramdisk driver module forwards the results of the read and write operations to the Windows file system, which then feeds them back to the application.
2. The virtual machine disk access method according to claim 1, characterized in that... The method for the Ramdisk driver module to create the device object virtual disk D includes: when the Ramdisk driver module is loaded into memory by the Windows system, the main function of the Ramdisk driver module calls the ioCreateDevice function in the Windows system API to create the device object virtual disk D.
3. The virtual machine disk access method according to claim 1, characterized in that: Map the virtual disk D as a drive letter or symbolic link for application operations.
4. The virtual machine disk access method according to claim 1, characterized in that: The Ramdisk read / write processing module performs read and write operations on the virtual machine disk V by calling the ReadFile / WriteFile commands.
5. A virtual machine disk access system, characterized in that... include: The Ramdisk read / write processing module, located in the system application layer, is used for read and write operations on virtual machine disks. Create a communication channel with the Ramdisk driver module and feed back the results of virtual machine disk read and write operations to the Ramdisk driver module through the communication channel; The Ramdisk read / write processing module establishes a communication channel with the Ramdisk driver module via shared memory, including: The Ramdisk read / write processing module allocates memory and event object handles, and passes the allocated memory and event object handles to the Ramdisk driver module through the deviceioctrl function; The Ramdisk driver module maps the memory and event object handles allocated by the Ramdisk read / write processing module to kernel addresses, thereby sharing the memory and event objects with the Ramdisk read / write processing program; The Ramdisk driver module, located in the system kernel layer, is used to create device object virtual disks for Windows file system operations; it transmits Windows file system read and write operation commands for device object virtual disks to the Ramdisk read and write processing module through a communication channel, and forwards the read and write results fed back by the Ramdisk read and write processing module to the Windows file system. The control module, located in the system application layer, is used to pass the disk information of the virtual machine disk to be operated to the Ramdisk read / write processing module; control the Ramdisk read / write processing module to create a communication channel with the Ramdisk driver module; and control the Ramdisk driver module to create device objects.
6. A virtual machine disk access system according to claim 5, characterized in that... The Ramdisk read / write processing module includes: a virtual machine disk read / write module, used for reading and writing virtual machine disks; The communication creation module is used to create a communication channel with the Ramdisk driver module; The data transmission module is used to receive read and write commands forwarded by the Ramdisk driver module and send the results of read and write operations on the virtual machine disk to the Ramdisk driver module.
7. A virtual machine disk access system according to claim 5, characterized in that... The Ramdisk driver module includes: a device object creation module, used to create device object virtual disks for Windows file system operations; The data transmission module is used to receive read and write operation commands from the Windows file system for the virtual disk and forward them to the Ramdisk read and write processing module; it also receives the read and write operation results from the Ramdisk read and write processing module for the virtual machine disk and forwards them to the Windows file system.
8. An electronic device comprising a processor and a storage medium, characterized in that: The storage medium stores a program that enables the virtual machine disk access method according to any one of claims 1 to 4 when the processor executes the program.
Citation Information
Patent Citations
Data reading / writing method and related device
CN110018782A