Block device network sharing method and system based on FUSE framework
Through the FUSE framework, creating a virtual file system and establishing a mapping between block devices and virtual files, solving the problems of complexity and high operation and maintenance costs of NAS systems, and realizing flexible network sharing and efficient data reading and writing of block devices.
Patent Information
- Application Number
- CN202510322391.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-19
- Publication Date
- 2025-04-25
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing NAS systems are complex when configuring and managing block device files, which can easily lead to system instability and high operation and maintenance costs.
Create a target virtual file system through the FUSE framework, define file operation functions, establish a mapping relationship between block device files and virtual files, and export it as a target NFS share through the NFS protocol.
It realizes flexible network sharing of block devices, reduces deployment and operation and maintenance costs, improves system flexibility and adaptability, and avoids the performance overhead of traditional file systems.
Smart Images

Figure CN119884053A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of network sharing, and in particular to a block device network sharing method and system based on a FUSE framework. Background Art
[0002] In modern computing environments, there is a growing demand for accessing block device files over the network, especially in distributed storage and cloud computing scenarios. Traditional solutions usually rely on network-attached storage (NAS) systems, such as using the iSCSI (Internet Small Computer System Interface) protocol to share block device files. However, although NAS systems such as iSCSI can meet the needs in terms of functionality, their configuration and management processes are often complex. Administrators need to have an in-depth understanding of network configuration, storage architecture, and protocol details to ensure the correct deployment and operation of the system. In addition, since the iSCSI protocol involves operations at the kernel driver layer, any configuration errors or compatibility issues may cause system instability or even crashes. This complexity not only increases the operation and maintenance costs of network access to block devices, but also increases the risk of system failures. Summary of the invention
[0003] In order to solve the above problems existing in the prior art, the present invention provides a block device network sharing method and system based on the FUSE framework. The technical problem to be solved by the present invention is achieved through the following technical solutions: A first aspect of an embodiment of the present invention provides a block device network sharing method based on a FUSE framework, comprising the following steps: In response to a creation instruction based on the FUSE framework, create a target virtual file system; Defining the file operation function of the target virtual file system to implement the file operation interface; Creating a target file directory in the target virtual file system; Creating a target virtual common file in the target file directory; Calling the symbolic link function of the file operation function to establish a mapping relationship between the local storage path of the block device file and the path of the target virtual common file; Calling the attribute acquisition function of the file operation function to configure the attributes of the target virtual common file to obtain a configured target virtual file system; The configured target virtual file system is exported as a target NFS share through the NFS protocol.
[0004] In one embodiment of the present invention, the file operation functions include: an attribute acquisition function, an opendir() function, a readdir() function, a read() function, a write() function, an open() function, a close() function and a symbolic link function.
[0005] In one embodiment of the present invention, the symbolic link function that calls the file operation function establishes a mapping relationship between the local storage path of the block device file and the path of the target virtual common file, including: By using the ln -s command based on the local storage path of the block device file and the path of the target virtual ordinary file, parameters are passed into the symbolic link function of the file operation function to execute the mapping relationship between the local storage path of the block device file and the path of the target virtual ordinary file.
[0006] In one embodiment of the present invention, the method further comprises: The client mounts the target NFS share through the network to achieve remote access to the block device file.
[0007] A second aspect of an embodiment of the present invention provides a block device network sharing system based on a FUSE framework, comprising: A first creation module, used for creating a target virtual file system in response to a creation instruction based on a FUSE framework; A definition module, used for defining the file operation function of the target virtual file system to implement a file operation interface; A directory attribute module, used for creating a target file directory in the target virtual file system; A second creation module is used to create a target virtual common file in the target file directory; A mapping module, used for calling the symbolic link function of the file operation function to establish a mapping relationship between the local storage path of the block device file and the path of the target virtual common file; A file attribute module, used for calling the attribute acquisition function of the file operation function to configure the attribute of the target virtual common file and obtain the configured target virtual file system; The export module is used to export the configured target virtual file system as a target NFS share through the NFS protocol.
[0008] In one embodiment of the present invention, the file operation functions include: an attribute acquisition function, an opendir() function, a readdir() function, a read() function, a write() function, an open() function, a close() function and a symbolic link function.
[0009] In one embodiment of the present invention, the symbolic link function that calls the file operation function establishes a mapping relationship between the local storage path of the block device file and the path of the target virtual common file, including: By using the ln -s command based on the local storage path of the block device file and the path of the target virtual ordinary file, parameters are passed into the symbolic link function of the file operation function to execute the mapping relationship between the local storage path of the block device file and the path of the target virtual ordinary file.
[0010] In one embodiment of the present invention, it also includes a client; The client mounts the target NFS share through the network to achieve remote access to the block device file.
[0011] A third aspect of an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, a block device network sharing method based on a FUSE framework provided by the first aspect of an embodiment of the present invention is implemented.
[0012] A fourth aspect of an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method for network sharing a block device based on a FUSE framework provided by the first aspect of an embodiment of the present invention is implemented.
[0013] Beneficial effects of the present invention: The present invention dynamically maps the block device path through a virtual file system under the FUSE (Filesystem in Userspace) framework and a symbolic link (symlink) operation, maps the block device to an ordinary file, and thus realizes the read and write operation of the block device through the read and write operation of the ordinary file. Since the block device is abstracted as an ordinary file, it can be shared on the network with the help of the NFS (Network File System) protocol, and finally realizes the client to directly remotely access the block device file through the NFS sharing mode. Through the symbolic link operation of FUSE, the block device path is dynamically mapped without pre-mounting the block device, which significantly improves the flexibility and adaptability of the system. Moreover, the existing NFS protocol and FUSE framework are fully utilized, and there is no need to purchase additional hardware equipment or pay software licensing fees, which greatly reduces the deployment and operation and maintenance costs. The configuration process is simple and intuitive, easy to manage and maintain, and reduces the workload of the system administrator. Sharing block device files through the NFS protocol naturally supports a variety of cloud platform architectures, which is convenient for seamless migration and deployment in different environments. By directly operating the block device with the help of FUSE, the performance overhead of the traditional file system is avoided, and the efficiency of data reading and writing is significantly improved.
[0014] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description, claims, and drawings.
[0015] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings: Figure 1 A flow chart of a block device network sharing method based on the FUSE framework provided by an embodiment of the present invention; Figure 2 A block diagram of a block device network sharing system based on a FUSE framework is provided in accordance with an embodiment of the present invention. DETAILED DESCRIPTION
[0017] The present invention is further described in detail below with reference to specific embodiments, but the embodiments of the present invention are not limited thereto.
[0018] like Figure 1 As shown, a first aspect of an embodiment of the present invention provides a block device network sharing method based on a FUSE framework, comprising the following steps: Step 11: Create a target virtual file system in response to a creation instruction based on the FUSE framework.
[0019] Step 12: define the file operation function of the target virtual file system to implement the file operation interface.
[0020] Step 13: Create a target file directory in the target virtual file system.
[0021] Step 14, create a target virtual common file in the target file directory.
[0022] Step 15, calling the symbolic link function of the file operation function to establish a mapping relationship between the local storage path of the block device file and the path of the target virtual common file.
[0023] Step 16, calling the attribute acquisition function of the file operation function to configure the attributes of the target virtual common file to obtain the configured target virtual file system.
[0024] Step 17: Export the configured target virtual file system as a target NFS share through the NFS protocol.
[0025] In this implementation, the block device path is dynamically mapped through the virtual file system under the FUSE (Filesystem in Userspace) framework and the symbolic link (symlink) operation, and the block device is mapped to an ordinary file, so that the read and write operations on the block device are realized through the read and write operations on the ordinary file. Since the block device is abstracted as an ordinary file, it can be shared on the network with the help of the NFS (Network File System) protocol, and finally the client can directly access the block device file remotely through the NFS sharing method. Through the symbolic link operation of FUSE, the block device path is dynamically mapped without pre-mounting the block device, which significantly improves the flexibility and adaptability of the system. In addition, by making full use of the existing NFS protocol and FUSE framework, there is no need to purchase additional hardware equipment or pay software licensing fees, which greatly reduces the deployment and operation and maintenance costs. The configuration process is simple and intuitive, easy to manage and maintain, and reduces the workload of system administrators. Sharing block device files through the NFS protocol naturally supports multiple cloud platform architectures, which facilitates seamless migration and deployment in different environments. With the help of FUSE, the performance overhead of traditional file systems is avoided and the efficiency of data reading and writing is significantly improved.
[0026] Based on the first aspect of the embodiment of the present invention, the second aspect of the embodiment of the present invention further describes the method of the present invention. The second aspect of the embodiment of the present invention provides a block device network sharing method based on the FUSE framework, comprising the following steps: Step 21, in response to a creation instruction based on the FUSE framework, create a target virtual file system.
[0027] In this step, after receiving the virtual file system creation instruction, the FUSE system creates a target virtual file system.
[0028] Step 22: define the file operation function of the target virtual file system to implement the file operation interface.
[0029] In this step, after creating the target virtual file system, define the file operation function to implement the file operation interface. The file operation function includes: attribute acquisition function getattr(), opendir() function, readdir() function, read() function, write() function, open() function, close() function and symbolic link function. The getattr() function is used to obtain file or folder attributes, the opendir() function is used to open the directory, the readdir() function is used to read the directory, the read() function is used to read the file, the write() function is used to write the file, the open() function is used to open the file, the close() function is used to close the file, and the symbolic link function symlink() is used to create a soft link.
[0030] Step 23, create a target file directory in the target virtual file system. The storage location of each level in the target file directory can be created as needed.
[0031] Step 24, create a target virtual common file in the target file directory.
[0032] Step 25, calling the symbolic link function of the file operation function to establish a mapping relationship between the local storage path of the block device file and the path of the target virtual common file.
[0033] Specifically, through the ln -s command based on the local storage path of the block device file and the path of the target virtual ordinary file, the parameters are passed into the symbolic link function of the file operation function to execute the mapping relationship between the local storage path of the block device file and the path of the target virtual ordinary file.
[0034] In this step, the target virtual ordinary file is created in the target file directory, and the ln -s command passes the local storage path of the block device file and the path of the target virtual ordinary file as parameters to the symbolic link function, so that the symbolic link function creates a soft link between the local storage path of the block device file and the path of the target virtual ordinary file, that is, a mapping relationship.
[0035] For example, in the FUSE system, create the target file directory: / mnt / fuse, the local path of the block device file is / dev / sda, so create a file sda under / mnt / fuse, and read and write / mnt / fuse / sda is equivalent to read and write / dev / sda. Through the ln -s command ln -s / dev / sda / mnt / fuse / sda, the path parameters / dev / sda and / mnt / fuse / sda are passed into the symbolic link function, thereby establishing a mapping relationship between the two paths.
[0036] Step 26, call the attribute acquisition function of the file operation function to configure the attributes of the target virtual ordinary file and obtain the configured target virtual file system. The attributes of the target virtual ordinary file (file size, file read and write permissions, file type, file time and other parameters) are set through the getattr() function to use the block device as an ordinary file in form. When in use, the file system converts the read and write operations of the virtual ordinary file into read and write operations of the mapped block device and returns the operation results.
[0037] Step 27: Export the configured target virtual file system as a target NFS share through the NFS protocol.
[0038] Here, step 22 to step 26 are for performing corresponding configuration on the created target virtual file system, and after the configuration is completed, a configured target virtual file system is obtained.
[0039] Step 28, the client mounts the target NFS share through the network to achieve remote access to the block device file.
[0040] In this step, the client operates the target NFS share, that is, operates the target virtual ordinary file, that is, remotely operates the block device file, and shares the local block device with the remote client in the form of an ordinary file through the NFS protocol.
[0041] In this embodiment, the virtual file system implemented by FUSE runs completely in memory, so except for the block device read and write limited by the hardware read and write speed, the rest of the operations run very quickly. The mapping operation of the block device is converted to the symlink interface, and ordinary users only need to use the ln and unlink commands to complete the complex block device mapping operation, and because it no longer involves kernel driver level configuration, the system is more secure and can be implemented as long as the platform supports the NFS protocol.
[0042] like Figure 2 As shown, the third aspect of the embodiment of the present invention provides a block device network sharing system based on the FUSE framework, including: A first creation module 31, configured to create a target virtual file system in response to a creation instruction based on a FUSE framework; A definition module 32, used to define the file operation function of the target virtual file system to implement the file operation interface; A directory attribute module 33, used for creating a target file directory in the target virtual file system; The second creation module 34 is used to create a target virtual common file in the target file directory; A mapping module 35, used for calling a symbolic link function of a file operation function to establish a mapping relationship between a local storage path of a block device file and a path of a target virtual common file; The file attribute module 36 is used to call the attribute acquisition function of the file operation function to configure the attributes of the target virtual common file and obtain the configured target virtual file system; The export module 37 is used to export the configured target virtual file system as a target NFS share through the NFS protocol.
[0043] In one embodiment of the present invention, the file operation functions include: an attribute acquisition function, an opendir() function, a readdir() function, a read() function, a write() function, an open() function, a close() function and a symbolic link function.
[0044] In one embodiment of the present invention, calling a symbolic link function of a file operation function to establish a mapping relationship between a local storage path of a block device file and a path of a target virtual common file includes: Through the ln -s command based on the local storage path of the block device file and the path of the target virtual ordinary file, the parameters are passed into the symbolic link function of the file operation function to execute the mapping relationship between the local storage path of the block device file and the path of the target virtual ordinary file.
[0045] In one embodiment of the present invention, it also includes a client; The client mounts the target NFS share over the network to achieve remote access to block device files.
[0046] A fourth aspect of an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, a block device network sharing method based on the FUSE framework provided in the above embodiment of the present invention is implemented.
[0047] A fifth aspect of an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of a block device network sharing method based on a FUSE framework provided in the above embodiment of the present invention are implemented.
[0048] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0049] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware systems.
[0050] The method provided in the embodiment of the present invention can be applied to electronic devices. Specifically, the electronic device can be: a desktop computer, a portable computer, an intelligent mobile terminal, a server, etc. This is not limited here, and any electronic device that can implement the present invention belongs to the protection scope of the present invention.
[0051] As for the device / electronic device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0052] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0053] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0054] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0055] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A block device network sharing method based on FUSE framework, characterized in that: The following steps are involved: In response to a creation instruction based on the FUSE framework, create a target virtual file system; Defining the file operation function of the target virtual file system to implement the file operation interface; Creating a target file directory in the target virtual file system; Creating a target virtual common file in the target file directory; Calling the symbolic link function of the file operation function to establish a mapping relationship between the local storage path of the block device file and the path of the target virtual common file; Calling the attribute acquisition function of the file operation function to configure the attributes of the target virtual common file to obtain a configured target virtual file system; The configured target virtual file system is exported as a target NFS share through the NFS protocol.
2. The method according to claim 1, characterized in that The file operation functions include: attribute acquisition function, opendir() function, readdir() function, read() function, write() function, open() function, close() function and symbolic link function.
3. The method according to claim 2, characterized in that The symbolic link function that calls the file operation function establishes a mapping relationship between the local storage path of the block device file and the path of the target virtual common file, including: By using the ln -s command based on the local storage path of the block device file and the path of the target virtual ordinary file, parameters are passed into the symbolic link function of the file operation function to execute the mapping relationship between the local storage path of the block device file and the path of the target virtual ordinary file.
4. The method according to claim 1, characterized in that The method further comprises: The client mounts the target NFS share through the network to achieve remote access to the block device file.
5. A block device network sharing system based on FUSE framework, characterized in that: include: A first creation module, used for creating a target virtual file system in response to a creation instruction based on a FUSE framework; A definition module, used for defining the file operation function of the target virtual file system to implement a file operation interface; A directory attribute module, used for creating a target file directory in the target virtual file system; A second creation module is used to create a target virtual common file in the target file directory; A mapping module, used for calling the symbolic link function of the file operation function to establish a mapping relationship between the local storage path of the block device file and the path of the target virtual common file; A file attribute module, used for calling the attribute acquisition function of the file operation function to configure the attribute of the target virtual common file and obtain the configured target virtual file system; The export module is used to export the configured target virtual file system as a target NFS share through the NFS protocol.
6. The system according to claim 5, characterized in that The file operation functions include: attribute acquisition function, opendir() function, readdir() function, read() function, write() function, open() function, close() function and symbolic link function.
7. The system according to claim 5, characterized in that The symbolic link function that calls the file operation function establishes a mapping relationship between the local storage path of the block device file and the path of the target virtual common file, including: By using the ln -s command based on the local storage path of the block device file and the path of the target virtual ordinary file, parameters are passed into the symbolic link function of the file operation function to execute the mapping relationship between the local storage path of the block device file and the path of the target virtual ordinary file.
8. The system according to claim 5, characterized in that It also includes the client; The client mounts the target NFS share through the network to achieve remote access to the block device file.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the block device network sharing method based on the FUSE framework as described in any one of claims 1 to 4 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the block device network sharing method based on the FUSE framework described in any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Method and device for establishing and accessing file path
CN108268609A
User mode distributed file system access method, device and equipment
CN114546976A
File system sharing method and device, electronic equipment and storage medium
CN116150116A
NAS (Network Attached Storage) access method and system for FPGA (Field Programmable Gate Array) control storage equipment
CN117992420A
High-speed secure virtual file system
US20190138621A1