A file lock operation method, device, equipment and storage medium

By obtaining user lock operation requests and the lock list of the target file in the network file system of Linux, judging and executing lock operations, the resource contention and data consistency problems during multi-user access are solved, and the reliability and security of the system are improved.

CN115292264BActive Publication Date: 2026-02-17INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210892217.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-27
Publication Date
2026-02-17
Estimated Expiration
2042-07-27

AI Technical Summary

Technical Problem

In the Network File System (NFS) of Linux, when multiple users access the same file at the same time, there are resource contention and data consistency problems that are difficult to solve effectively with existing technologies.

Method used

A file lock operation method is provided. By obtaining the user's lock operation request information and the lock list of the target file, it determines whether there is a lock on the file, and determines the location information of the lock of the file to be operated on based on the lock request information and the lock list, and performs locking or unlocking operations to ensure the accuracy and consistency of lock operations.

Benefits of technology

It enhances the reliability, ease of use, and security of the network file system, ensuring data synchronization across multiple clients and avoiding resource contention and data conflicts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115292264B_ABST
    Figure CN115292264B_ABST
Patent Text Reader

Abstract

The application relates to a file lock operation method, device and equipment and a storage medium. The main technical scheme comprises the following steps: obtaining file lock request information input by a user on a client for performing a lock operation on a target file, obtaining a lock chain table in a target file storage entry, judging whether a file lock exists on the target file according to the lock chain table, when the file lock exists on the target file, determining position information of a to-be-operated file lock corresponding to a lock operation request and a historical file lock in the lock chain table according to the file lock request information and the lock chain table, and performing a lock operation on the target file according to the position information of the to-be-operated file lock corresponding to the lock operation request and the historical file lock in the lock chain table. The application can keep the data of multiple clients synchronized, and greatly enhances the reliability, ease of use and security of a network file system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of Linux network file system technology, and in particular to a method, apparatus, device, and storage medium for locking files. Background Technology

[0002] In Linux systems, software and hardware resources are all files, and these files are shareable in a multi-user environment. When multiple users read and write the same file simultaneously, to avoid resource contention and maintain data synchronization, the common method is to lock the file to ensure that data conflicts do not occur. File locks are a mechanism for maintaining file synchronization. In Network File System (NFS), file locks can prevent data consistency problems caused by multiple users reading and writing the same file simultaneously, so file locks play a significant role in network file system applications.

[0003] Currently, file locks have been implemented in the Linux kernel, and users can use system calls such as fcntl to lock and unlock. However, implementing file locks in NFS requires a file lock-related algorithm to solve the contention problem and data consistency problem when multiple users access the system simultaneously. Summary of the Invention

[0004] Based on this, this application provides a file locking operation method, apparatus, device, and storage medium to ensure the consistency of data generated when multiple users simultaneously read and write the same file in NFS.

[0005] Firstly, a file locking operation method is provided, the method comprising:

[0006] Obtain the file lock request information entered by the user on the client, which requests a lock operation on the target file;

[0007] Retrieve the linked list from the storage entries of the target file;

[0008] Based on the lock list, determine whether there is a file lock on the target file;

[0009] When a file lock exists on the target file, the position information of the file lock request and the historical file lock in the lock list are determined according to the file lock request information and the lock list.

[0010] Based on the position information of the target file lock corresponding to the lock operation request and the historical file lock in the lock chain, a lock operation is performed on the target file.

[0011] According to one achievable method in an embodiment of this application, the file lock request information includes a first offset and a first length of the file lock to be operated on, and the lock list includes a second offset and a second length of historical file locks; based on the file lock request information and the lock list, the position information of the file lock to be operated on corresponding to the lock operation request and the historical file locks in the lock list are determined, including:

[0012] Based on the first offset, the first length, the second offset, and the second length, determine the position information of the pending file lock and the historical file lock in the lock chain corresponding to the lock operation request.

[0013] According to one achievable method in an embodiment of this application, the location information includes file lock overlap and file lock non-adjacent conditions; based on a first offset, a first length, a second offset, and a second length, the location information of the file lock to be operated corresponding to the lock operation request and the historical file locks in the lock chain is determined, including:

[0014] When the first offset is less than the second offset, if the difference between the first offset and the second offset is less than or equal to the first length, or when the first offset is greater than the second offset, if the difference between the first offset and the second offset is less than or equal to the second length, it is determined that the lock on the file to be operated on and the lock on the historical file overlap.

[0015] If the difference between the first offset and the second offset is greater than the first length, or if the difference between the first offset and the second offset is greater than the second length, it is determined that the file lock to be operated on and the historical file lock are not adjacent.

[0016] According to one achievable method in an embodiment of this application, the lock operation request includes a lock request; based on the position information of the file lock to be operated on corresponding to the lock operation request and the historical file locks in the lock chain, a lock operation is performed on the target file, including:

[0017] When the lock on the file to be operated corresponding to the lock request overlaps with the historical file lock in the lock chain, the historical file lock is removed from the lock chain.

[0018] Based on the first offset, the first length, the second offset, and the second length, determine the starting and ending positions to be locked;

[0019] Based on the start and end positions of the target file to be locked, create a lock in the lock chain to perform a locking operation on the target file.

[0020] According to one achievable method in an embodiment of this application, the method further includes:

[0021] When the lock on the file to be operated on corresponding to the lock request is not adjacent to the historical file lock in the lock chain, a lock on the file to be operated on is created in the lock chain to lock the target file.

[0022] According to one achievable method in an embodiment of this application, the lock operation request includes an unlock request; based on the position information of the file lock to be operated on corresponding to the lock operation request and the historical file locks in the lock chain, a lock operation is performed on the target file, including:

[0023] When the file lock to be unlocked corresponding to the unlock request partially overlaps with the historical file lock in the lock chain, the starting position and ending position to be unlocked are determined according to the first offset, the first length, the second offset and the second length.

[0024] Remove the lock from the lock list based on the start and end positions of the lock to be unlocked;

[0025] Based on the second offset, the second length, and the start and end positions to be unlocked, a historical file lock that does not overlap with the file lock to be operated on is created in the lock chain to unlock the target file.

[0026] According to one achievable method in an embodiment of this application, the method further includes:

[0027] When the lock on the file to be unlocked corresponding to the unlock request completely overlaps with the historical file locks in the lock list, the lock list is cleared in order to unlock the target file.

[0028] Secondly, a file locking operation device is provided, the device comprising:

[0029] The acquisition module is used to acquire the file lock request information for locking the target file input by the user on the client and the lock list in the target file storage entry;

[0030] The acquisition module is also used to acquire the linked list in the target file storage entry;

[0031] The judgment module is used to determine whether a file lock exists on the target file based on the lock list;

[0032] The determination module is used to determine the position information of the file lock to be operated on and the historical file lock in the lock list when a file lock exists on the target file, based on the file lock request information and the lock list;

[0033] The operation module is used to perform locking operations on the target file based on the position information of the file lock to be operated on and the historical file lock in the lock chain corresponding to the lock operation request.

[0034] Thirdly, a computer device is provided, comprising:

[0035] At least one processor; and

[0036] A memory communicatively connected to the at least one processor; wherein,

[0037] The memory stores computer instructions that can be executed by the at least one processor to enable the at least one processor to perform the method involved in the first aspect above.

[0038] Fourthly, a computer-readable storage medium is provided, having stored thereon computer instructions, wherein the computer instructions are used to cause a computer to perform the methods involved in the first aspect above.

[0039] According to the technical content provided in the embodiments of this application, file lock request information for locking a target file input by a user on the client is obtained, a lock list in the target file storage entry is obtained, and it is determined whether a file lock exists on the target file based on the lock list. When a file lock exists on the target file, the position information of the file lock to be operated on corresponding to the lock operation request and the historical file lock in the lock list is determined based on the file lock request information and the lock list. Based on the position information of the file lock to be operated on corresponding to the lock operation request and the historical file lock in the lock list, a lock operation is performed on the target file, so that the data of multiple clients are kept synchronized, which greatly enhances the reliability, ease of use and security of the network file system. Attached Figure Description

[0040] Figure 1 This is a diagram illustrating the application environment of a file locking operation method in one embodiment.

[0041] Figure 2 This is a flowchart illustrating a file locking operation method in one embodiment;

[0042] Figure 3 This is a structural block diagram of a file locking operation device in one embodiment;

[0043] Figure 4 This is a schematic structural diagram of a computer device in one embodiment. Detailed Implementation

[0044] The present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the scope of the present application.

[0045] The file locking method provided in this application can be applied to, for example... Figure 1In the application environment shown, terminal 102 communicates with server 104 via a network. The user inputs a file lock request information to perform a locking operation on a target file through terminal 102. Server 104 obtains this file lock request information and retrieves the lock list from the target file's storage entries. Based on the lock list, it determines whether a file lock exists on the target file. If a file lock exists, it determines the position information of the pending file lock corresponding to the lock operation request and the historical file locks in the lock list, based on the file lock request information and the lock list. The lock operation is then performed on the target file based on the position information of the pending file lock corresponding to the lock operation request and the historical file locks in the lock list. Terminal 102 can be, but is not limited to, various personal computers, laptops, and tablets. Server 104 can be implemented using a standalone server or a server cluster consisting of multiple servers. It should be noted that terminal 102 here is a shared terminal based on NFSv4.

[0046] In NFSv4, file locks are categorized by read / write mode (read locks and write locks) and by blocking mode (blocking locks and non-blocking locks). File locks can be applied to either the client or the server. If the client mounts NFS using the `nolock` option, the lock is applied on the client side. This ensures that multiple processes on the same client can access the same file without conflict. However, conflicts may still occur when different clients access the same file because the file lock is only present on the client side, and other clients are unaware of its existence. If the client mounts NFS using the `lock` option, the lock is applied on the server side. This allows all clients to check for the existence of the file lock on the server, preventing conflicts when all clients access the same file.

[0047] Figure 2 A flowchart illustrating a file locking operation method provided in this application embodiment is provided. This method can be performed by, for example... Figure 1 Server 104 in the system shown is executing. For example... Figure 2 As shown, the method may include the following steps:

[0048] S210: Obtain the file lock request information for locking the target file input by the user on the client.

[0049] The target file is the file that the user wants to perform lock operations on. There can be one or more target files.

[0050] File lock request information includes lock request information and unlock request information. Lock request information includes a LOCK request message. The LOCK request message contains the following data:

[0051] struct LOCK4args {

[0052] nfs_lock_type4 locktype;

[0053] bool_t reclaim

[0054] offset4 offset?

[0055] length4 length;

[0056] locker4 locker;

[0057] }

[0058] Where locktype represents the file lock type, and its values ​​are as follows:

[0059] READ_LT indicates that a read lock is created, and if it conflicts with other file locks, it exits immediately.

[0060] WRITE_LT indicates that a write lock is created, and if it conflicts with other file locks, it exits immediately.

[0061] READW_LT indicates that a read lock is created, and if a conflict occurs with other file locks, it will wait until the lock is successfully acquired.

[0062] WRITEW_LK indicates that a write lock is created, and if a conflict occurs with other file locks, it waits until the lock is successfully acquired.

[0063] The `reclaim` flag indicates the lock state recovery status. If the server crashes and restarts, the client needs to restore previously acquired file locks. In this case, the `reclaim` flag in the `LOCK` request message is set to 1; otherwise, this value is 0.

[0064] offset represents the starting offset of the data segment locked by the file lock within the file.

[0065] length indicates the length of the data segment locked by the file lock.

[0066] The locker is a data structure that identifies this LOCK operation. If this is the first time a lock is acquired, this data structure is as follows:

[0067] struct open_to_lock_owner4 {

[0068] seqid4 open_seqid;

[0069] stateid4 open_stateid;

[0070] seqid4 lock_seqid;

[0071] lock_owner4 lock_owner;

[0072] };

[0073] `open_seqid` represents the sequence number of the `seqid` in the `OPEN` operation. Since the file needs to be opened before locking, the `OPEN` operation must be performed first.

[0074] open_stateid represents the stateid returned by the OPEN operation.

[0075] lock_seqid represents the sequence number of the LOCK operation.

[0076] lock_owner indicates the owner of the lock and contains the following information:

[0077] struct lock_owner4 {

[0078] clientid4 clientid;

[0079] opaque owner<NFS4_OPAQUE_LIMIT> ;

[0080] }

[0081] clientid represents the client's identifier, which uniquely identifies a client on the server side.

[0082] Owner is a string. This string can be customized by the client, but it must ensure that the owner of the file lock is unique.

[0083] The unlock request information includes a LOCKU request message, which contains information about the file lock the user is requesting to delete. The LOCKU request message contains the following data:

[0084] struct LOCKU4args {

[0085] nfs_lock_type4 locktype;

[0086] seqid4 seqid;

[0087] stateid4 stateid;

[0088] offset4 offset?

[0089] length4 length;

[0090] };

[0091] Where Locktype represents the type of file lock, seqid represents the sequence number of the LOCKU operation, offset represents the offset of the file lock in the file, and length represents the length of the file lock.

[0092] When a file is created, a file handle is created and returned to the client, allowing both the client and server to identify a shared file.

[0093] Before locking a file, a cache entry (hereinafter referred to as an entry) is first created in memory based on the file handle. Only after opening the file and obtaining the file descriptor (fd) based on the entry can the locking operation be performed. Both locking and unlocking operations require calling the fcntl system call to perform locking and unlocking at the file system level.

[0094] When a user attempts to lock a target file via the client's display device, the server retrieves the user's file lock request information.

[0095] S220, retrieve the linked list in the target file storage entry.

[0096] Each file may have multiple file locks, which are organized by a doubly linked list to form the file's lock list.

[0097] The lock list records information about all locks on a file. When a user performs a locking operation on a target file through the client's display device, the lock list of that target file is retrieved to understand the lock situation on the target file.

[0098] S230, based on the lock list, determine whether there is a file lock on the target file.

[0099] The system determines whether a file lock exists on the target file based on the file lock information in the lock list. If a file lock exists in the lock list, then the target file is considered to have a file lock; otherwise, the target file is not considered to have a file lock.

[0100] When no file lock exists on the target file, a lock author (owner), a lock entry (entry), and a lock state (state) need to be created and associated with the entry. This lock entry is then added to the lock list of the target file's entry. The reference count (refcnt) of the entry is incremented by 1, and the pin count (pin_refcnt) of the target file's entry is also incremented by 1.

[0101] S240, when a file lock exists on the target file, determine the position information of the file lock to be operated on and the historical file lock in the lock list corresponding to the lock operation request based on the file lock request information and the lock list.

[0102] When a file lock exists on the target file, the file lock to be operated on may not be the final new lock. The position of existing historical file locks will affect the position of the file lock to be operated on on the target file, and different positional relationships will result in different new locks after locking the target file.

[0103] S250: Based on the position information of the file lock to be operated on and the historical file lock in the lock chain corresponding to the lock operation request, perform a lock operation on the target file.

[0104] By performing locking operations on the target file based on the location information of the locks to be operated on and the historical locks, the distribution of the locks to be operated on and the historical locks on the target file can be accurately determined. This is beneficial for determining the range of new locks for different distributions and ensuring the reliability of each locking operation.

[0105] As can be seen, this embodiment of the application obtains the file lock request information input by the user on the client to perform a lock operation on the target file, obtains the lock list in the target file storage entry, determines whether there is a file lock on the target file based on the lock list, and when there is a file lock on the target file, determines the position information of the file lock to be operated on corresponding to the lock operation request and the historical file lock in the lock list based on the file lock request information and the lock list, and performs a lock operation on the target file based on the position information of the file lock to be operated on corresponding to the lock operation request and the historical file lock in the lock list, so that the data of multiple clients are kept synchronized, which greatly enhances the reliability, ease of use and security of the network file system.

[0106] The following is a detailed description of each step in the above method flow. First, step S240, namely "determining the position information of the file lock to be operated on and the historical file lock in the lock list corresponding to the lock operation request based on the file lock request information and the lock list", will be described in detail with reference to the embodiment.

[0107] As one feasible approach, the position information of the pending file lock and the historical file lock in the lock list corresponding to the lock operation request is determined based on the first offset, the first length, the second offset, and the second length.

[0108] The first offset is the starting offset of the data locked by the file lock to be operated on in the target file. In other words, it is the position of the starting point of the file lock to be operated on in the target file.

[0109] The first length is the length of the data locked by the file lock to be operated on.

[0110] The second offset is the starting offset of the data locked by the history file lock in the target file.

[0111] The second length is the length of the data locked by the history file lock.

[0112] The distribution ranges of the file locks to be operated on and the historical file locks are determined based on the first offset, the first length, the second offset, and the second length, respectively, thereby enabling the determination of the positional information of the file locks to be operated on and the historical file locks. The positional information includes whether the file locks overlap or are not adjacent.

[0113] Specifically, when the first offset is less than the second offset, it means that the starting point of the file lock to be operated on is before the starting point of the historical file lock. At this time, if the difference between the first offset and the second offset is less than or equal to the first length, it means that the ending point of the file lock to be operated on is always after the starting point of the historical file lock or coincides with the starting point of the historical file lock, thus determining that the file lock to be operated on and the historical file lock overlap.

[0114] If the difference between the first offset and the second offset is greater than the first length, it indicates that the start and end points of the file lock to be operated on are both located before the start point of the historical file lock, thus determining that the file lock to be operated on and the historical file lock are not adjacent.

[0115] When the first offset is greater than the second offset, it indicates that the starting point of the file lock to be operated on is after the starting point of the historical file lock. If the difference between the first and second offsets is less than or equal to the second length, it indicates that the starting point of the file lock to be operated on is always before or coincides with the ending point of the historical file lock, thus confirming that the file lock to be operated on and the historical file lock overlap.

[0116] If the difference between the first offset and the second offset is greater than the second length, it indicates that the starting point of the file lock to be operated on is located after the ending point of the historical file lock, thus determining that the file lock to be operated on and the historical file lock are not adjacent.

[0117] After determining the positional relationship between the lock on the file to be operated and the lock on the historical file, the following describes in detail, with reference to the embodiments, S250, namely, "to perform a lock operation on the target file according to the positional information of the lock on the file to be operated corresponding to the lock operation request and the lock on the historical file in the lock chain."

[0118] As one possible approach, lock operation requests include lock requests. Methods for locking a target file include:

[0119] When the lock on the file to be operated corresponding to the lock request overlaps with the historical file lock in the lock chain, the historical file lock is removed from the lock chain.

[0120] Based on the first offset, the first length, the second offset, and the second length, determine the starting and ending positions to be locked;

[0121] Based on the start and end positions of the target file to be locked, create a lock in the lock chain to perform a locking operation on the target file.

[0122] When the lock on the file to be operated on for a locking request overlaps with a historical file lock in the lock list, the two locks need to be merged into one. The lock merging operation involves: first, removing the historical file lock from the lock list; then, creating the lock to be locked (the merged lock) in the lock list. The starting point of the merged lock is the smaller of the two lock starting points, and the ending point is the larger of the two lock ending points. The merged lock's type is the same as the type of the file lock to be operated on. At this time, the reference counts (refcnt and pin_refcnt) of the target file entry remain unchanged from before locking.

[0123] The starting position of the lock to be acquired can be determined by the first and second offsets. The ending position of the lock to be acquired can be determined by the starting position of each lock and its own length. Based on the starting and ending positions of the lock to be acquired, a lock is created in the lock chain, completing the locking operation on the target file.

[0124] When the lock on the file to be operated on corresponding to the lock request is not adjacent to the lock on the historical file in the lock chain, the lock on the file to be operated on and the lock on the historical file are two locks. It is only necessary to create the lock on the file to be operated on in the lock chain to perform the locking operation on the target file. At this time, the reference counts refcnt and pin_refcnt of the target file entry remain unchanged from before locking.

[0125] As an alternative approach, if the lock types of the file to be operated on and the historical file lock are different, the locking operation fails, and a notification of the locking failure and the reason for the failure is sent to the client.

[0126] As one possible approach, a lock operation request includes an unlock request. Methods for unlocking a target file include:

[0127] When the file lock to be unlocked corresponding to the unlock request partially overlaps with the historical file lock in the lock chain, the starting position and ending position to be unlocked are determined according to the first offset, the first length, the second offset and the second length.

[0128] Remove the lock from the lock list based on the start and end positions of the lock to be unlocked;

[0129] Based on the second offset, the second length, and the start and end positions to be unlocked, a historical file lock that does not overlap with the file lock to be operated on is created in the lock chain to unlock the target file.

[0130] The lock to be unlocked is the overlapping portion of the historical file locks with the lock to be operated on. When the lock to be unlocked corresponding to the unlock request overlaps with a portion of the historical file locks in the lock list, the lock to be unlocked must be removed from the lock list, and then a new lock must be created with the overlapping portion of the historical file lock and the lock to be operated on. If there are still locks on the target file entry (i.e., the lock list is not empty), then the reference counts refcnt and pin_refcnt of the target file entry remain unchanged from before unlocking.

[0131] When the lock on the file to be unlocked corresponding to the unlock request completely overlaps with the historical file locks in the lock list, it indicates that the unlocking range includes the range of historical file locks. The target file entry is completely unlocked, the lock list is cleared, and the unlocking operation on the target file is performed. At this time, the reference counts refcnt and pin_refcnt of the target file entry are both decremented by one.

[0132] It should be understood that, although Figure 2 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated in this application, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Furthermore, Figure 2 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

[0133] Figure 3 This is a schematic diagram of a file locking operation device provided in an embodiment of this application. The device can be disposed in... Figure 1 Server 104 in the system shown is used to perform, for example... Figure 2 The method flow is shown below. Figure 3 As shown, the device may include: an acquisition module 310, a judgment module 320, a determination module 330, and an operation module 340, and may further include: a creation module and a clearing module. The main functions of each component module are as follows:

[0134] The acquisition module 310 is used to acquire the file lock request information for locking the target file input by the user on the client and the lock list in the target file storage entry;

[0135] The acquisition module 310 is also used to acquire the chain list in the target file storage entry;

[0136] The judgment module 320 is used to determine whether there is a file lock on the target file based on the lock chain list;

[0137] The determination module 330 is used to determine the position information of the file lock to be operated corresponding to the lock operation request and the historical file lock in the lock list based on the file lock request information and the lock list when a file lock exists on the target file.

[0138] The operation module 340 is used to perform locking operations on the target file based on the position information of the file lock to be operated on and the historical file lock in the lock chain corresponding to the lock operation request.

[0139] As one possible approach, the file lock request information includes the first offset and first length of the file lock to be operated on, and the lock list includes the second offset and second length of the historical file locks; the determination module 330 is specifically used to determine the position information of the file lock to be operated on and the historical file locks in the lock list corresponding to the lock operation request based on the first offset, the first length, the second offset and the second length.

[0140] As one possible approach, the location information includes file lock overlap and file lock non-adjacent; the determination module 330 is specifically used to determine that the file lock to be operated and the historical file lock overlap when the first offset is less than the second offset, if the difference between the first offset and the second offset is less than or equal to the first length, or when the first offset is greater than the second offset, if the difference between the first offset and the second offset is less than or equal to the second length.

[0141] If the difference between the first offset and the second offset is greater than the first length, or if the difference between the first offset and the second offset is greater than the second length, it is determined that the file lock to be operated on and the historical file lock are not adjacent.

[0142] As one possible approach, a lock operation request includes a lock request; the operation module 340 is used to remove the historical file lock from the lock list when the file lock to be operated corresponding to the lock request overlaps with the historical file lock in the lock list;

[0143] Based on the first offset, the first length, the second offset, and the second length, determine the starting and ending positions to be locked;

[0144] Based on the start and end positions of the target file to be locked, create a lock in the lock chain to perform a locking operation on the target file.

[0145] As one possible approach, the device also includes a creation module for creating a file lock in the lock chain when the file lock corresponding to the lock request is not adjacent to a historical file lock in the lock chain, so as to perform a locking operation on the target file.

[0146] As one possible approach, a lock operation request includes an unlock request; the operation module 340 is used to determine the start and end positions to be unlocked based on a first offset, a first length, a second offset, and a second length when the file lock to be operated corresponding to the unlock request partially overlaps with the historical file lock in the lock chain.

[0147] Remove the lock from the lock list based on the start and end positions of the lock to be unlocked;

[0148] Based on the second offset, the second length, and the start and end positions to be unlocked, a historical file lock that does not overlap with the file lock to be operated on is created in the lock chain to unlock the target file.

[0149] As one possible approach, the device also includes a clearing module for clearing the lock list when the lock on the file to be unlocked corresponding to the unlock request completely overlaps with the historical file locks in the lock list, so as to perform the unlocking operation on the target file.

[0150] The same or similar parts among the above embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the device embodiments are basically similar to the method embodiments, so the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments.

[0151] According to embodiments of this application, this application also provides a computer device and a computer-readable storage medium.

[0152] like Figure 4 The diagram shown is a block diagram of a computer device according to an embodiment of this application. The term "computer device" is intended to represent various forms of digital computers or mobile devices. The digital computer may include a desktop computer, a portable computer, a workbench, a personal digital assistant, a server, a mainframe computer, and other suitable computers. The mobile device may include a tablet computer, a smartphone, a wearable device, etc.

[0153] like Figure 4 As shown, device 400 includes a computing unit 401, a ROM 402, a RAM 403, a bus 404, and an input / output (I / O) interface 405. The computing unit 401, ROM 402, and RAM 403 are interconnected via the bus 404. The input / output (I / O) interface 405 is also connected to the bus 404.

[0154] The computing unit 401 can execute various processes in the method embodiments of this application according to computer instructions stored in the read-only memory (ROM) 402 or computer instructions loaded from the storage unit 408 into the random access memory (RAM) 403. The computing unit 401 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. The computing unit 401 can include, but is not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any suitable processor, controller, microcontroller, etc. In some embodiments, the methods provided in the embodiments of this application can be implemented as computer software programs, which are tangibly contained in a computer-readable storage medium, such as the storage unit 408.

[0155] RAM 403 may also store various programs and data required for the operation of device 400. Part or all of the computer program may be loaded and / or installed on device 400 via ROM 802 and / or communication unit 409.

[0156] The input unit 406, output unit 407, storage unit 408, and communication unit 409 in device 400 can be connected to I / O interface 405. The input unit 406 can be, for example, a keyboard, mouse, touchscreen, or microphone; the output unit 407 can be, for example, a display, speaker, or indicator light. Device 400 can exchange information and data with other devices through the communication unit 409.

[0157] It should be noted that the device may also include other components necessary for normal operation. It may also include only the components necessary for implementing the solution of this application, without necessarily including all the components shown in the figures.

[0158] Various implementations of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SOCs), payload programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof.

[0159] The computer instructions used to implement the methods of this application may be written in any combination of one or more programming languages. These computer instructions may be provided to the computing unit 401 such that when executed by the computing unit 401, such as a processor, the computer instructions cause the execution of the steps involved in the embodiments of the methods of this application.

[0160] The computer-readable storage medium provided in this application can be a tangible medium that can contain or store computer instructions for performing the steps involved in the method embodiments of this application. The computer-readable storage medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, and other forms of storage media.

[0161] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application.

Claims

1. A method for locking files, characterized in that, The method includes: Obtain the file lock request information entered by the user on the client, which requests a lock operation on the target file; Obtain the linked list from the storage entries of the target file; Based on the lock list, determine whether there is a file lock on the target file; When a file lock exists on the target file, the position information of the file lock to be operated and the historical file lock in the lock list corresponding to the lock operation request is determined according to the file lock request information and the lock list. The file lock request information includes a first offset and a first length of the file lock to be operated, and the lock list includes a second offset and a second length of the historical file lock. Determining the position information of the file lock to be operated and the historical file lock in the lock list according to the file lock request information and the lock list includes: when the first offset is less than the second offset, if the difference between the first offset and the second offset is less than or equal to the first length; or when the first offset is greater than the second offset, if the difference between the first offset and the second offset is less than or equal to the second length, it is determined that the file lock to be operated and the historical file lock overlap; when the first offset is less than the second offset, if the difference between the first offset and the second offset is greater than the first length; or when the first offset is greater than the second offset, if the difference between the first offset and the second offset is greater than the second length, it is determined that the file lock to be operated and the historical file lock are not adjacent. Based on the position information of the target file lock corresponding to the lock operation request and the historical file lock in the lock chain, a lock operation is performed on the target file.

2. The method according to claim 1, characterized in that, The lock operation request includes a lock request; the step of performing a lock operation on the target file based on the position information of the file lock to be operated on and the historical file locks in the lock list corresponding to the lock operation request includes: When the lock on the file to be operated corresponding to the lock request overlaps with the historical file lock in the lock list, the historical file lock is removed from the lock list; Based on the first offset, the first length, the second offset, and the second length, determine the starting and ending positions to be locked; Based on the start and end positions of the target file to be locked, a lock is created in the lock chain to perform a locking operation on the target file.

3. The method according to claim 2, characterized in that, The method further includes: When the lock on the file to be operated corresponding to the lock request is not adjacent to the historical file lock in the lock chain, the lock on the file to be operated is created in the lock chain to lock the target file.

4. The method according to claim 1, characterized in that, Lock operation requests include unlock requests; The step of performing a locking operation on the target file based on the position information of the file lock to be operated on corresponding to the lock operation request and the historical file locks in the lock chain list includes: When the file lock to be operated corresponding to the unlock request partially overlaps with the historical file lock in the lock chain, the starting position and the ending position to be unlocked are determined according to the first offset, the first length, the second offset and the second length. Based on the start and end positions of the lock to be unlocked, the lock to be unlocked is removed from the lock list; Based on the second offset, the second length, and the start and end positions to be unlocked, a historical file lock that does not overlap with the file lock to be operated on is created in the lock chain to perform an unlocking operation on the target file.

5. The method according to claim 4, characterized in that, The method further includes: When the lock on the file to be unlocked corresponding to the unlock request completely overlaps with the historical file lock in the lock list, the lock list is cleared in order to unlock the target file.

6. A file locking operation device, characterized in that, The device includes: The acquisition module is used to acquire the file lock request information for locking the target file input by the user on the client and the lock list in the target file storage entry; The acquisition module is also used to acquire the linked list in the storage entry of the target file; The judgment module is used to determine whether there is a file lock on the target file based on the lock chain; A determination module is used to determine the position information of the file lock to be operated and the historical file lock in the lock list corresponding to the lock operation request when a file lock exists on the target file, based on the file lock request information and the lock list. The file lock request information includes a first offset and a first length of the file lock to be operated, and the lock list includes a second offset and a second length of the historical file lock. Determining the position information of the file lock to be operated and the historical file lock in the lock list based on the file lock request information and the lock list includes: when the first offset is less than the second offset, if the difference between the first offset and the second offset is less than or equal to the first length; or when the first offset is greater than the second offset, if the difference between the first offset and the second offset is less than or equal to the second length, it is determined that the file lock to be operated and the historical file lock overlap; when the first offset is less than the second offset, if the difference between the first offset and the second offset is greater than the first length; or when the first offset is greater than the second offset, if the difference between the first offset and the second offset is greater than the second length, it is determined that the file lock to be operated and the historical file lock are not adjacent. The operation module is used to perform locking operations on the target file based on the position information of the file lock to be operated corresponding to the lock operation request and the historical file lock in the lock chain.

7. A computer device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores computer instructions executable by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform the method of any one of claims 1 to 5.

8. A computer-readable storage medium storing computer instructions thereon, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method and system for locking file in network file system, equipment and medium

    CN113986855A