NFS server control method and device for preventing read / write anomalies during high availability failover

By introducing a backup file system on the nfs server, the read and write abnormalities during high-availability switching are solved, ensuring that the client does not interrupt reading and writing when the main file system fails, and improving the reliability of the file system.

CN118035199BActive Publication Date: 2024-11-19HUNAN GUOKE YICUN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410051481.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-12
Publication Date
2024-11-19
Estimated Expiration
2044-01-12

AI Technical Summary

Technical Problem

During the high availability switch of the NFS server, the client may experience read and write exceptions and business interruptions, resulting in unavailability of the file system or data loss.

Method used

Introduce an independent NFS file system as the backup file system. By judging the running status and high-availability switching status of the main file system, the main file system and backup file system perform operations to ensure that the backup file system is replaced when the main file system fails. Client requests to avoid read and write interrupts.

Benefits of technology

It effectively improves the reliability of the file system, ensures that the read and write of files and directories are normal when the main file system is completely invalid, and avoids data loss and business interruption during high-availability switching on the server side.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118035199B_ABST
    Figure CN118035199B_ABST
Patent Text Reader

Abstract

The present invention discloses an NFS server control method and device for preventing abnormal reading and writing during high-availability switching. The method comprises the following steps: taking the original NFS file system as the main file system and configuring an independent NFS file system as the standby file system; when it is necessary to complete the file or directory operation of the client, judging the operation state of the main file system and the high-availability switching state, and controlling the start of the main and standby file systems to perform operations according to the state judgment result, wherein when the main file system server is running normally and does not need to perform high-availability switching, controlling only the main file system to perform read type operations, and the main file system and the standby file system to perform modification type operations at the same time; when an abnormality occurs in the main file system, high-availability switching is performed, the main file system is disconnected, and the standby file system is started to perform the required operations. The present invention can prevent abnormal reading and writing of the client and business interruption during high-availability switching of the NFS server, and improve the reliability of the file system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of NFS (Network File System) network storage, and in particular to an NFS server control method and system for preventing abnormal reading and writing during high-availability switching. Background Art

[0002] nfs includes clients, servers, and storage, which are usually distributed on different servers and connected to each other through the network. During the reading and writing process, if the server fails, the application data will be unable to read and write files. In order to ensure the reliability of the server in the file system, multiple servers are usually used with technologies such as keepalived and HAProxy to configure a high-availability server. With a high-availability server, if a server node that is providing a service fails, the service is automatically switched to another node to ensure the availability of the file system. However, for a server configured with high availability, before the server performs high-availability switching and starts the service, it is necessary to connect to the storage, check whether the storage can read and write normally, and mount the storage file system, and then start the service. After that, the server will enter a grace period, and can only read and write files normally after the grace period ends. This makes the server unavailable for a period of time when the server is switched to high availability. During this period, if the client reads and writes files, I / O interruption or client jamming will occur, resulting in the client application being unable to read and write files or losing data.

[0003] In view of the above technical problems, in the prior art, when a server fails, the client usually blocks for a period of time to wait for the server to recover. This type of method can prevent I / O interruption, but if the server still does not recover after the blocking time, I / O interruption will still occur. If it is blocked all the time, it will still cause the client file system to freeze or application business data to be lost. Even if the server in an nfs file system configures a primary and backup service, it is usually necessary to connect a client to a server, that is, first connect the client to the primary server, and when the primary server fails, reconnect the client to the backup server. In the process of reconnecting the client from the primary server to the backup server, the client will still be blocked for a period of time, and I / O interruption, client file system freeze, or application business data loss may occur. Summary of the invention

[0004] The technical problem to be solved by the present invention is: in response to the technical problems existing in the prior art, the present invention provides an NFS server control method and system that are simple to operate and highly reliable for preventing read and write anomalies during high-availability switching, which can prevent client read and write anomalies and business interruption during high-availability switching of the NFS server, thereby improving the reliability of the file system.

[0005] In order to solve the above technical problems, the technical solution proposed by the present invention is:

[0006] An NFS server control method for preventing abnormal reading and writing during high availability switching, comprising the following steps:

[0007] Use the original nfs file system as the main file system, configure an independent nfs file system as the backup file system and specify the server address and export directory of the backup file system;

[0008] When it is necessary to complete the file or directory operation of the client, the running status and high availability switching status of the primary file system are judged, and the primary file system and / or the standby file system are controlled to be started to perform the operation according to the status judgment result, wherein when the primary file system server is running normally and does not need high availability switching, only the primary file system is controlled to perform read type operations, and the primary file system and the standby file system are controlled to perform modification type operations at the same time; when it is judged that an abnormality occurs in the primary file system, high availability switching is performed, the primary file system is disconnected, and the standby file system is started to perform the required operation.

[0009] Furthermore, before configuring the primary file system and the backup file system, the steps of mounting the primary file system and the backup file system include:

[0010] When the client mounts the primary file system, it inputs configuration parameters to specify the server address and export directory of the backup file system;

[0011] The client kernel module parses the input configuration parameters to obtain the server address and export directory of the backup file system, as well as the parameters required to mount the backup file system;

[0012] The client kernel module mounts the main file system by calling the try_mount function pointer of the specified version of the nfs module;

[0013] If the primary file system is mounted successfully, continue to call the try_mount function pointer to mount the backup file system. If the mounting fails, the mounting process ends;

[0014] If the standby file system is mounted successfully, the directory entries dentry of the primary file system and the standby file system are submitted to the primary and standby file system management modules for management.

[0015] Further, the controlling and starting the primary file system and / or the backup file system to perform operations according to the status judgment result includes:

[0016] Complete client file or directory operations in the main file system;

[0017] Determine the operation completion status and operation type in the primary file system;

[0018] If the operation is successful in the main file system and is a read type operation, the result of the operation is returned;

[0019] If the operation fails in the primary file system or the operation type is a modification type operation, the absolute path of the operation file or directory and the directory entry in the standby file system are obtained, and the corresponding operation is completed in the standby file system according to the obtained information;

[0020] The read type operation includes any one of reading files, searching files, obtaining file permissions, obtaining file attributes, obtaining directory permissions, obtaining directory attributes, and reading directories; the modify type operation includes any one of opening files, writing files, deleting files, renaming files, setting file permissions, setting file attributes, deleting directories, creating directories, closing directories, renaming directories, setting directory permissions, and setting directory attributes.

[0021] Further, when the file or directory operation of the client is completed, if the file is opened on the client, the same file is opened in the primary file system and the backup file system at the same time, and the steps include:

[0022] Open the file in the primary file system, and obtain the file index node inode and directory entry dentry of the file in the standby file system according to the file index node inode of the primary file system;

[0023] Open the file in the standby file system and save the context pointer of the file opened in the standby file system;

[0024] Determine whether the file in the main file system is opened successfully. If it is opened successfully, return the context pointer of the open file in the main file system;

[0025] If the file in the primary file system fails to be opened, determine whether the file in the backup file system is opened successfully. If it is opened successfully, return the context pointer of the open file in the backup file system. If the file in the backup file system also fails to be opened, return an error.

[0026] Further, the acquiring of the file index node inode and the directory entry dentry of the file in the standby file system according to the file index node inode of the file in the primary file system includes:

[0027] Obtain the absolute path of the file according to the file index node inode of the file;

[0028] According to the absolute path of the file, the lookup function of the standby file system is called to obtain the file handle of the directory where the file is located;

[0029] Use the directory entry dentry and file handle of the standby file system as parameters, call the nfs_fhget function to obtain the file index node inode of the directory where the file is located;

[0030] Using the file index node inode and directory name of the directory where the file is located as parameters, call the d_obtain_alias function to obtain the directory entry dentry of the directory where the file is located;

[0031] Using the directory entry dentry of the directory where the file is located as a parameter, call the d_alloc_parallel function to obtain the directory entry dentry of the file.

[0032] Further, when the file or directory operation of the client is completed, if the file is written on the client, the same file is written in the primary file system and the backup file system at the same time, and the steps include:

[0033] The client obtains the context pointer and file index node inode of the primary and backup files saved when opening the file;

[0034] Create write cache page requests for the primary file system and backup file system;

[0035] Adding write cache page requests of the primary file system and the backup file system to the write cache page request queue;

[0036] The client obtains the write cache page request from the write cache page request queue, and sends it to the primary file system and the backup file system;

[0037] When the client receives a write request response, it determines whether the write request is executed successfully. If successful, it returns a write success. If failed, it determines whether the request response comes from the primary file system or the backup file system. If it comes from the primary file system, it records the primary file system write failure. Otherwise, it records the backup file system write failure.

[0038] Determine whether the primary file system and the backup file system fail to write at the same time. If both fail, return an error. If one file system succeeds, mask the error, delete and release the write cache page request from the write cache page request list, and submit the successfully written data.

[0039] Further, when the file or directory operation of the client is completed, if the client reads a file, the same file in the primary file system and the backup file system is read at the same time, and the steps include:

[0040] The client obtains the context pointers of the primary file system and the backup file system and the file index node inode saved when opening the file;

[0041] Create read requests for the primary file system and the backup file system, and add the read requests for the primary file system and the backup file system to the read request queue;

[0042] The client obtains the read request from the read request queue and sends the read request to the main file system;

[0043] When the client receives a read request response, it determines whether the read is successful. If so, it returns the read data. If the read fails, it determines whether the request response comes from the primary file system. If so, the client sends a read request to the backup file system. If the request response comes from the backup file system, it returns an error.

[0044] Further, when the file or directory operation of the client is completed, if the client closes the file, the same file in the primary and standby file systems is closed at the same time, the steps include:

[0045] Get the file context pointers of the primary file system and the backup file system;

[0046] The client closes the file in the primary file system, releases the directory entry dentry, the file system super block, the mdsthreshold reference and the file context pointer resources in the primary file system file context pointer;

[0047] The client closes the file in the standby file system and releases the dentry entry in the standby file system's file context pointer, the file system super block, the mdsthreshold reference, and the file context pointer's own resources.

[0048] Furthermore, when the client receives different error responses from the primary file system or the backup file system, judging whether the primary file system or the backup file system is in an abnormal state according to the error code and the number of error code responses, and if it is judged to be in an abnormal state, stopping the sending of read and write requests; and / or when the client is idle and has no read and write operations, the client periodically sends read and write test requests to the primary file system and the backup file system, judging the status of the primary file system and the backup file system according to the response results of the read and write test requests, and determining whether to send read and write requests to the primary file system and the backup file system according to the status judgment results. A device for implementing the above-mentioned NFS server control method for preventing read and write abnormalities during high-availability switching, comprising:

[0049] The primary and backup file system mounting module is used to parse the mounting parameters passed in by the user state and mount the primary file system and the backup file system according to the parameters;

[0050] The primary and backup file system resource management module is used to manage the primary and backup file system resources;

[0051] The master-slave read-write control module is used to control data writing into the master file system or the backup file system when the master file system and the backup file system switch writing;

[0052] A primary and backup file operation synchronization module is used to synchronize file operations in the primary file system and the backup file system;

[0053] The primary and backup directory operation synchronization module is used to synchronize various directory operations in the primary file system and the backup file system;

[0054] The primary and backup file system uninstallation module is used to uninstall the primary and backup file systems and release the resources related to the primary and backup file systems;

[0055] The primary and standby file handle acquisition module is used to obtain the absolute path of the file or directory, the file handle, the file node and the directory entry.

[0056] Compared with the prior art, the advantages of the present invention are:

[0057] 1. The present invention introduces an independent nfs file system as a backup file system and uses the original nfs file system as the main file system. When the main file system server runs normally and does not need high-availability switching, the main file system executes read-type operations, and the modification type operations are executed by the main file system and the backup file system at the same time. When the main file system fails, the backup file system replaces the main file system to complete all requests of the client, so that when high-availability switching occurs, it can ensure that the server can read and write data normally, and ensure that the client can read and write files and directories normally, I / O is not interrupted, and I / O is not blocked when the main file system completely fails, thereby effectively improving the reliability of the file system and avoiding data loss and business interruption in the case of high-availability switching of the server.

[0058] 2. The present invention adopts a backup file system, which is simple to implement and does not require modification of application software. It can not only solve the reading and writing abnormality problem when the server fails in the case of high-availability switching, but also realize real-time backup of data and improve the reliability of the file system. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] Figure 1 It is a schematic diagram of the overall architecture of the nfs server control for preventing read and write anomalies during high availability switching implemented in this embodiment.

[0060] Figure 2 It is a schematic diagram of the implementation flow of the nfs server control for preventing read and write anomalies during high availability switching in this embodiment.

[0061] Figure 3 It is a schematic diagram of the implementation process of mounting the primary and backup file systems in this embodiment.

[0062] Figure 4It is a schematic diagram of the implementation flow of controlling the operation of the primary and backup file systems when the client opens a file in this embodiment.

[0063] Figure 5 It is a schematic diagram of the implementation process of obtaining the backup file system information according to the primary file system in this embodiment.

[0064] Figure 6 It is a schematic diagram of the implementation flow of controlling the operation of the primary and backup file systems when the client writes files in this embodiment.

[0065] Figure 7 It is a schematic diagram of the implementation flow of controlling the operation of the primary and backup file systems when the client reads files in this embodiment.

[0066] Figure 8 It is a schematic diagram of the implementation flow of controlling the operation of the primary and backup file systems when the client closes a file in this embodiment. DETAILED DESCRIPTION

[0067] The present invention is further described below in conjunction with the accompanying drawings and specific preferred embodiments, but the protection scope of the present invention is not limited thereby.

[0068] In the nfs server high availability system, server network interruption, main server downtime, and server service shutdown will trigger high availability switching. Client service will be interrupted during high availability switching. In the case of service interruption, the creation, opening, reading and writing of files and directories cannot be completed. During server high availability switching, in addition to file reading, writing and opening, file or directory creation, query, setting and obtaining attribute operations may occur during high availability switching, and may affect file reading, writing and opening.

[0069] The present invention introduces an independent nfs file system as a backup file system on the basis of the original nfs file system, and uses the original nfs file system as the main file system. When the main file system server runs normally and does not need high-availability switching, the main file system executes read-type operations, and the modification type operations are executed by the main file system and the backup file system at the same time. When the main file system fails, the backup file system replaces the main file system to complete all requests of the client. Since files are opened and data is read and written in the main and backup file systems at the same time, when high-availability switching occurs, it is possible to ensure that the server can read and write data normally, and ensure that the client can read and write files and directories normally, I / O is not interrupted, and I / O is not blocked when the main file system completely fails. The reliability of the file system can be effectively improved, and data loss and business interruption in the case of high-availability switching of the server can be avoided.

[0070] like Figure 1 , 2As shown, the steps of the nfs server control method for preventing abnormal reading and writing during high availability switching in this embodiment include:

[0071] Step S01, using the original nfs file system as the main file system, configuring an independent nfs file system as the backup file system and specifying the server address and export directory of the backup file system;

[0072] Step S02. When it is necessary to complete the file or directory operation of the client, the running state and the high availability switching state of the primary file system are judged, and the primary file system and / or the standby file system are controlled to be started to perform the operation according to the state judgment result, wherein when the primary file system server is running normally and does not need high availability switching, only the primary file system is controlled to perform read type operations, and the primary file system and the standby file system are controlled to perform modify type operations at the same time; when it is judged that an abnormality occurs in the primary file system, high availability switching is performed, the primary file system is disconnected, and the standby file system is started to perform the required operation.

[0073] This embodiment specifically divides various operations of the client into read type operations and modify type operations, where read type operations include reading files, searching files, obtaining file permissions, obtaining file attributes, obtaining directory permissions, obtaining directory attributes, reading directories, etc.; modify type operations include opening files, writing files, deleting files, renaming files, setting file permissions, setting file attributes, deleting directories, creating directories, closing directories, renaming directories, setting directory permissions, setting directory attributes, etc.

[0074] like Figure 1 As shown, the main file system and the backup file system are configured respectively, which correspond to the main file system server, the main file system storage, the backup file system server and the backup file system storage. When the application needs to perform file and directory operations, the nfs client sends file and directory operation requests to the main file system and the backup file system server respectively. When the main file system server is operating normally and no high-availability switching is required, all read-type operations in the main file system only need to be executed in the main file system server, and modification-type operations are executed in the main and backup file system servers at the same time; when the main file system server is abnormal and high-availability switching is performed, when the main file system service is disconnected, the error results in the main file system are shielded, and all operations are executed in the backup file system, and the operation results in the backup file system are returned to the application, so as to realize the normal reading and writing of files and directories by the client, and the I / O is not interrupted and blocked when the main file system fails completely, so as to avoid data loss and business interruption in the case of high-availability switching of the server.

[0075] Different from the traditional one-to-one client-server connection method, this embodiment connects the client to two independent primary and backup file systems at the same time. When the primary file system server is operating normally and no high-availability switching is required, all read-type operations in the primary file system only need to be successfully executed in the primary file system, and there is no need to execute the same operation in the backup file system. If the execution fails in the primary file system, it means that the primary file system is abnormal. It may be that high-availability switching is being performed, and file operations need to be performed in the backup file system. Modification-type operations need to be performed in both the primary and backup file systems. When the primary file system server is abnormal and high-availability switching is being performed, and the primary file system service is disconnected, the error results in the primary file system are shielded, and all operations are executed in the backup file system. The operation results in the backup file system are returned to the application. The startup of the primary file system and / or the backup file system is controlled according to the status judgment result to execute the operation, so that after the primary file system fails, the client can immediately continue to complete the operation in the backup file system.

[0076] like Figure 2 As shown, the specific steps of step S02 in this embodiment include:

[0077] Complete client file or directory operations in the main file system;

[0078] Determine the operation completion status and operation type in the primary file system;

[0079] If the operation is successful in the main file system and is a read type operation, the result of the operation is returned;

[0080] If the operation fails in the primary file system or the operation type is a modification type operation, the absolute path of the operation file or directory and the directory entry in the standby file system are obtained, and the corresponding operation is completed in the standby file system according to the obtained information.

[0081] like Figure 3 As shown in the figure, before configuring the primary file system and the backup file system, the primary and backup file systems are mounted. First, the mount parameters are parsed to mount the primary file system. If the mount is successful, the backup file system is mounted according to the backup file system parameters. The mount command is used to mount the primary file system. The specific steps include:

[0082] When the client mounts the primary file system, enter the configuration parameters to specify the server address and export directory of the standby file system. Specifically, you can specify the server address and export directory of the standby file system through custom parameters.

[0083] The client kernel module parses the input configuration parameters, obtains the server address and export directory of the backup file system, and the parameters required to mount the backup file system;

[0084] The client kernel module mounts the main file system by calling the try_mount function pointer of the specified version of the nfs module according to the mount parameters;

[0085] If the primary file system is mounted successfully, continue to call the try_mount function pointer to mount the backup file system. If the mounting fails, the mounting process ends;

[0086] If the standby file system is mounted successfully, the directory entries dentry of the primary file system and the standby file system are submitted to the primary and standby file system management modules for management.

[0087] When the client is uninstalled, the primary file system and the backup file system need to be uninstalled at the same time.

[0088] When the nfs server performs high availability switching, the client will operate in the primary file system, but the primary file system cannot complete the file or directory operation and will return a corresponding error. In order to ensure that the file read and write operations are not interrupted, this embodiment shields the error results in the primary file system and executes all key operations related to client read and write in the backup file system. The key operations related to client read and write include opening files, writing files, reading files, and closing files, that is, when the client opens files, writes files, reads files, and closes files, operations need to be performed on the primary file system and the backup file system.

[0089] When a file is opened, a context pointer for the file is generated. The reading and writing of the file depends on the context pointer. This embodiment opens the same file in both the primary and backup file systems at the same time, and then generates context pointers accordingly to ensure the correctness of the file reading and writing. When the nfs client opens a file, it only operates the file index node inode of the primary file system. To open a file with the same path in the backup file system, this embodiment obtains the absolute path of the file based on the file index node inode of the primary file system, and then opens the corresponding file in the backup file system based on the absolute path of the file. Specifically, Figure 4 As shown, in this embodiment, when the file or directory operation of the client is completed, if the file is opened on the client, the specific steps of simultaneously opening the same file in the primary file system and the backup file system include:

[0090] Open the file in the primary file system, and obtain the file index node inode and directory entry dentry of the file in the standby file system according to the file index node inode of the primary file system;

[0091] Open the file in the standby file system and save the context pointer of the file opened in the standby file system;

[0092] Determine whether the file in the main file system is opened successfully. If it is opened successfully, return the context pointer of the open file in the main file system;

[0093] If the file in the primary file system fails to be opened, determine whether the file in the backup file system is opened successfully. If it is opened successfully, return the context pointer of the open file in the backup file system. If the file in the backup file system also fails to be opened, return an error.

[0094] like Figure 5 As shown, in this embodiment, the specific steps of obtaining the file index node inode and directory entry dentry of the file in the standby file system according to the file index node inode of the file in the primary file system include:

[0095] Get the absolute path of the file based on the file index node inode;

[0096] According to the absolute path of the file, call the lookup function of the standby file system to obtain the file handle of the directory where the file is located;

[0097] Use the directory entry dentry and file handle of the standby file system as parameters, call the nfs_fhget function to obtain the file index node inode of the directory where the file is located, where the nfs_fhget function searches for the file index node inode according to the file handle, returns the file index node inode if it exists, and creates a new index node inode if the file index node does not exist.

[0098] Using the file index node inode and directory name of the directory where the file is located as parameters, call the d_obtain_alias function to get the directory entry dentry of the directory where the file is located. The d_obtain_alias function is used to return the dentry of the given file index node inode. If the inode already has a dentry, one of them is returned; if not, a new anonymous dentry is allocated and attached;

[0099] Using the directory entry dentry of the directory where the file is located as a parameter, call the d_alloc_parallel function to obtain the directory entry dentry of the file, where the d_alloc_parallel function is used to allocate a directory entry dentry in which the required name and parent directory entry are stored.

[0100] In this embodiment, when the file or directory operation of the client is completed, if the file is written on the client, the same file is written in the primary file system and the backup file system at the same time, such as Figure 6 As shown, the specific steps include:

[0101] The client obtains the context pointer and file index node inode of the primary and backup files saved when opening the file;

[0102] Create write cache page requests for the primary file system and backup file system;

[0103] Add the write cache page requests of the primary file system and the backup file system to the write cache page request queue;

[0104] The client obtains the write cache page request from the write cache page request queue and sends it to the primary file system and the backup file system;

[0105] When the client receives a write request response, it determines whether the write request is executed successfully. If successful, it returns a write success. If failed, it determines whether the request response comes from the primary file system or the backup file system. If it comes from the primary file system, it records the primary file system write failure. Otherwise, it records the backup file system write failure.

[0106] Determine whether the primary file system and the backup file system fail to write at the same time. If both fail, return an error. If one file system succeeds, mask the error, delete and release the write cache page request from the write cache page request list, and submit the successfully written data.

[0107] During read and write operations, if an I / O failure occurs in the primary file system, the client can receive the I / O error in a relatively timely manner. However, if each I / O error is judged and processed, the client's read and write performance will be reduced. Moreover, after the primary file system network is disconnected or the service is stopped, the client needs a certain timeout period to perceive the error. Therefore, if each read and write request is still sent to the primary file system after the primary file system fails, the client's read and write performance will be seriously affected. In this embodiment, when the client receives different error responses from the primary file system or the backup file system, it determines whether the primary file system or the backup file system is in an abnormal state according to the error code and the number of error code responses. If it is in an abnormal state, the sending of the read and write request is stopped, thereby ensuring the performance of the client's read and write operations.

[0108] Furthermore, in order to enable the client to promptly discover the abnormal status of the primary file system or the backup file system, this embodiment determines the status of the file system based on the response result of the write test request by having the client periodically send a read / write test request to the primary or backup file system when the client is idle and has no read / write operations. When reading and writing files subsequently, it can promptly decide whether to send a read / write request to the primary or backup file system based on the status of the file system.

[0109] In this embodiment, when the client's file or directory operation is completed, if the client reads a file, it reads the same file in the primary file system and the backup file system at the same time, such as Figure 7As shown, the steps include:

[0110] The client obtains the context pointers of the primary file system and the backup file system and the file index node inode saved when opening the file;

[0111] Create read requests for the primary file system and the backup file system, and add the read requests for the primary file system and the backup file system to the read request queue;

[0112] The client obtains the read request from the read request queue and sends the read request to the primary file system;

[0113] When the client receives a read request response, it determines whether the read is successful. If the read is successful, it returns the read data. If the read fails, it determines whether the request response comes from the primary file system. If it comes from the primary file system, the client sends a read request to the backup file system. If the request response comes from the backup file system, an error is returned.

[0114] Since the client needs to open the file in both the primary and backup clients at the same time when opening the file, it also needs to close the file at the same time when closing the file. If the file in the backup file system is not closed, the backup file system cannot be unmounted, and the mounting of the new file system is also affected. Figure 8 As shown, in this embodiment, when the file or directory operation of the client is completed, if the client closes the file, the specific steps of simultaneously closing the same file in the primary and backup file systems include:

[0115] Get the file context pointers of the primary file system and the backup file system;

[0116] The client closes the file in the primary file system, releases the directory entry dentry, the file system super block, the reference of mdsthreshold and the file context pointer in the primary file system file context pointer;

[0117] The client closes the file in the standby file system and releases the dentry entry in the standby file system's file context pointer, the file system super block, the reference to mdsthreshold, and the file context pointer itself.

[0118] In this embodiment, the backup file system is completely transparent to the application software, and the primary-backup effect can be achieved without modifying the application software. It can not only solve the read and write error problem when the server fails, but also realize real-time backup of data, effectively improving the reliability of the file system.

[0119] The device of this embodiment for implementing the above-mentioned NFS server control method for preventing abnormal reading and writing during high availability switching includes:

[0120] The primary and backup file system mounting module is used to parse the mounting parameters passed in by the user state and mount the primary file system and the backup file system according to the parameters;

[0121] The primary and backup file system resource management module is used to manage the primary and backup file system resources;

[0122] The master-slave read-write control module is used to control data writing into the master file system or the backup file system when the master file system and the backup file system switch writing;

[0123] A primary and backup file operation synchronization module is used to synchronize file operations in the primary file system and the backup file system;

[0124] The primary and backup directory operation synchronization module is used to synchronize various directory operations in the primary file system and the backup file system;

[0125] In this embodiment, it also includes:

[0126] The primary and backup file system uninstallation module is used to uninstall the primary and backup file systems and release the resources related to the primary and backup file systems;

[0127] The master and backup file handle acquisition module is used to obtain the absolute path of the file or directory, the file handle, the file node and the directory entry;

[0128] The fault sensing and processing module is used to determine whether a fault occurs in the primary file system or the backup file system, and to shield or report the fault if a fault occurs.

[0129] The above device can be set in the nfs client server to solve the problem of client reading and writing interruption when the nfs server is switched to high availability. Of course, it can also be configured in other locations according to actual needs.

[0130] The above is only a preferred embodiment of the present invention, and does not limit the present invention in any form. Although the present invention has been disclosed as a preferred embodiment, it is not intended to limit the present invention. Therefore, any simple modification, equivalent change and modification made to the above embodiment according to the technical essence of the present invention without departing from the content of the technical solution of the present invention shall fall within the scope of protection of the technical solution of the present invention.

Claims

1. A method for controlling an NFS server to prevent abnormal reading and writing during high availability switching, characterized in that the steps include: Use the original nfs file system as the main file system, configure an independent nfs file system as the backup file system and specify the server address and export directory of the backup file system; When it is necessary to complete the file or directory operation of the client, the running state and high availability switching state of the primary file system are judged, and the primary file system and / or the standby file system are controlled to be started to perform the operation according to the state judgment result, wherein when the primary file system server is running normally and does not need high availability switching, only the primary file system is controlled to perform the read type operation, and the primary file system and the standby file system are controlled to perform the modification type operation at the same time; when it is judged that the primary file system is abnormal, high availability switching is performed, the primary file system is disconnected, and the standby file system is started to perform the required operation; The method further includes: when the client receives different error responses from the primary file system or the backup file system, judging whether the primary file system or the backup file system is in an abnormal state according to the error code and the number of error code responses, and stopping sending the read / write request if it is judged to be in an abnormal state; and / or when the client is idle and has no read / write operation, the client periodically sends a read / write test request to the primary file system or the backup file system, judging the state of the primary file system or the backup file system according to the response result of the read / write test request, and determining whether to send the read / write request to the primary file system or the backup file system according to the state judgment result.

2. The NFS server control method for preventing abnormal reading and writing during high availability switching according to claim 1 is characterized in that: Before configuring the primary file system and the backup file system, the steps of mounting the primary file system and the backup file system include: When the client mounts the primary file system, it inputs configuration parameters to specify the server address and export directory of the backup file system; The client kernel module parses the input configuration parameters to obtain the server address and export directory of the backup file system, as well as the parameters required to mount the backup file system; The client kernel module mounts the main file system by calling the try_mount function pointer of the specified version of the nfs module; If the primary file system is mounted successfully, continue to call the try_mount function pointer to mount the backup file system. If the mounting fails, the mounting process ends; If the standby file system is mounted successfully, the directory entries dentry of the primary file system and the standby file system are submitted to the primary and standby file system management modules for management.

3. The NFS server control method for preventing abnormal reading and writing during high availability switching according to claim 1 is characterized in that: The controlling and starting the main file system and / or the standby file system to perform operations according to the status judgment result includes: Complete client file or directory operations in the main file system; Determine the operation completion status and operation type in the primary file system; If the operation is successful in the main file system and is a read type operation, the result of the operation is returned; If the operation fails in the primary file system or the operation type is a modification type operation, the absolute path of the operation file or directory and the directory entry in the backup file system are obtained, and the corresponding operation is completed in the backup file system according to the obtained information; The read type operation includes any one of reading files, searching files, obtaining file permissions, obtaining file attributes, obtaining directory permissions, obtaining directory attributes, and reading directories; the modify type operation includes any one of opening files, writing files, deleting files, renaming files, setting file permissions, setting file attributes, deleting directories, creating directories, closing directories, renaming directories, setting directory permissions, and setting directory attributes.

4. The NFS server control method for preventing abnormal reading and writing during high availability switching according to claim 1 is characterized in that: When the file or directory operation of the client is completed, if the file is opened on the client, the same file is opened in the primary file system and the backup file system at the same time. The steps include: Open the file in the primary file system, and obtain the file index node inode and directory entry dentry of the file in the standby file system according to the file index node inode of the primary file system; Open the file in the standby file system and save the context pointer of the file opened in the standby file system; Determine whether the file in the main file system is opened successfully. If it is opened successfully, return the context pointer of the open file in the main file system; If the file in the primary file system fails to be opened, determine whether the file in the backup file system is opened successfully. If it is opened successfully, return the context pointer of the open file in the backup file system. If the file in the backup file system also fails to be opened, return an error.

5. The NFS server control method for preventing abnormal reading and writing during high availability switching according to claim 4 is characterized in that: The method of obtaining the file index node inode and the directory entry dentry of the file in the standby file system according to the file index node inode of the file in the primary file system comprises: Obtain the absolute path of the file according to the file index node inode of the file; According to the absolute path of the file, the lookup function of the standby file system is called to obtain the file handle of the directory where the file is located; Use the directory entry dentry and file handle of the standby file system as parameters and call the nfs_fhget function to obtain the file index node inode of the directory where the file is located; Using the file index node inode and directory name of the directory where the file is located as parameters, call the d_obtain_alias function to obtain the directory entry dentry of the directory where the file is located; Using the directory entry dentry of the directory where the file is located as a parameter, call the d_alloc_parallel function to obtain the directory entry dentry of the file.

6. The NFS server control method for preventing abnormal reading and writing during high availability switching according to any one of claims 1 to 5, characterized in that: When the file or directory operation on the client is completed, if the file is written on the client, the same file is written to both the primary file system and the standby file system at the same time. The steps include: The client obtains the context pointer and file index node inode of the primary and backup files saved when opening the file; Create write cache page requests for the primary file system and backup file system; Adding write cache page requests of the primary file system and the backup file system to the write cache page request queue; The client obtains the write cache page request from the write cache page request queue, and sends it to the primary file system and the backup file system; When the client receives a write request response, it determines whether the write request is executed successfully. If successful, it returns a write success. If failed, it determines whether the request response comes from the primary file system or the backup file system. If it comes from the primary file system, it records the primary file system write failure. Otherwise, it records the backup file system write failure. Determine whether the primary file system and the backup file system fail to write at the same time. If both fail, return an error. If one file system succeeds, mask the error, delete and release the write cache page request from the write cache page request list, and submit the successfully written data.

7. The nfs server control method for preventing abnormal reading and writing during high availability switching according to any one of claims 1 to 5, characterized in that: When the client's file or directory operation is completed, if the client reads a file, it reads the same file in the primary file system and the backup file system at the same time. The steps include: The client obtains the context pointers of the primary file system and the backup file system and the file index node inode saved when opening the file; Create read requests for the primary file system and the backup file system, and add the read requests for the primary file system and the backup file system to the read request queue; The client obtains the read request from the read request queue and sends the read request to the main file system; When the client receives a read request response, it determines whether the read is successful. If so, it returns the read data. If the read fails, it determines whether the request response comes from the primary file system. If so, the client sends a read request to the backup file system. If the request response comes from the backup file system, it returns an error.

8. The NFS server control method for preventing abnormal reading and writing during high availability switching according to any one of claims 1 to 5, characterized in that: When the client's file or directory operation is completed, if the client closes the file, the same file in the primary and standby file systems is closed at the same time. The steps include: Get the file context pointers of the primary file system and the backup file system; The client closes the file in the primary file system, releases the directory entry dentry, the file system super block, the mdsthreshold reference and the file context pointer resources in the primary file system file context pointer; The client closes the file in the standby file system and releases the dentry entry in the standby file system's file context pointer, the file system super block, the mdsthreshold reference, and the file context pointer's own resources.

9. A device for implementing the nfs server control method for preventing abnormal reading and writing during high availability switching as described in any one of claims 1 to 8, characterized in that: include: The primary and backup file system mounting module is used to parse the mounting parameters passed in by the user state and mount the primary file system and the backup file system according to the parameters; The primary and backup file system resource management module is used to manage the primary and backup file system resources; The master-slave read-write control module is used to control data writing into the master file system or the backup file system when the master file system and the backup file system switch writing; A primary and backup file operation synchronization module is used to synchronize file operations in the primary file system and the backup file system; The primary and backup directory operation synchronization module is used to synchronize various directory operations in the primary file system and the backup file system; The primary and backup file system uninstallation module is used to uninstall the primary and backup file systems and release the resources related to the primary and backup file systems; The primary and standby file handle acquisition module is used to obtain the absolute path of the file or directory, the file handle, the file node and the directory entry.