A typical operating system includes a file system. The file system provides a mechanism for the storage and retrieval of files and a hierarchical directory structure for the naming of multiple files. More specifically, the file system stores information provided by the user (i.e., data) and information describing the characteristics of the data (i.e., metadata). The file system also provides extensive programming interfaces to enable the creation and deletion of files, reading and writing of files, performing seeks within a file, creating and deleting directories, managing directory contents, etc. In addition, the file system also provides management interfaces to create and delete file systems. File systems are typically controlled and restricted by operating system parameters. For example, most operating systems limit the maximum number of file names that can be handled within their file system. Some operating systems also limit the size of files that can be managed under a file system.
One common operation of a file system is the modification of the content of a directory associated with the file system, for example, changing a filename, adding a new filename, deleting a filename, etc. When a process using the file system (e.g., an application) attempts to modify the directory (e.g., modify a filename currently in the directory), the process obtains a lock on the entire directory and then proceeds to modify a specific entry (e.g., a filename) in the directory. If a subsequent process attempts to modify the directory while the current process is modifying the directory, the subsequent process must wait until the current process completes its modification of the directory and releases the lock associated with the directory. Thus, at most one process may be modifying the directory at any given time.
In general, in one aspect, the invention relates to a method for modifying a directory entry comprising receiving a request to modify the directory entry, determining whether a directory entry lock associated with the directory entry is present, instantiating the directory entry lock, if the directory entry lock associated with the directory entry is not present, waiting until the directory entry lock is released, if the directory entry lock is present, providing the directory entry lock to a caller of the request, placing an entry corresponding to the directory entry lock on a dynamic lock list associated with the directory, processing the request by the caller, releasing the directory entry lock once the request has been processed, and removing the entry corresponding to the directory entry lock from the dynamic lock list.
In general, in one aspect, the invention relates to a method for modifying a first directory entry and a second directory comprising receiving a first request to modify the first directory entry, receiving a second request to modify the second directory entry, instantiating a first directory entry lock and a second directory entry lock, providing the first directory entry lock to a first caller of the first request, providing the second directory entry lock to a second caller of the second request, placing an entry corresponding to the first directory entry lock on a first dynamic lock list associated with a first directory, and placing an entry corresponding to the second directory entry lock on a first dynamic lock list associated with a first directory, processing, in parallel, the first request and the second request.
In general, in one aspect, the invention relates to a system, comprising a first directory associated with a file system, wherein the first directory is configured to store a first directory entry, a dynamic lock list associated with the first directory and configured to store a first entry corresponding to a first directory entry lock associated with the first directory entry, wherein the system is configured to receive a first request to modify the first directory entry, instantiate the first directory entry lock, provide the first directory entry lock to a first caller of the first request, place the first entry corresponding to the first directory entry lock on the first dynamic lock list.
Other aspects of the invention will be apparent from the following description and the appended claims.
Specific embodiments of the invention will now be described in detail with reference to the accompanying figures. Like elements in the various figures are denoted by like reference numerals for consistency.
In the following detailed description of one or more embodiments of the invention, numerous specific details are set forth in order to provide a more thorough understanding of the invention. However, it will be apparent to one of ordinary skill in the art that the invention may be practiced without these specific details. In other instances, well-known features have not been described in detail to avoid obscuring the invention.
In general, embodiments of the invention relate to a method and system for directory entry locking. More specifically, embodiments of the invention are directed to a mechanism for locking individual entries within a directory associated with a file system, where the directory entries correspond to file names in the directory.
As shown in
In one embodiment of the invention, no directory entry locks exist when the directory (100) is initially deployed. Rather, directory entry locks are only created as required (i.e., when a request to modify the content in the directory is received). Further, once the request has been processed, the directory entry lock may be maintained in the system or it may be removed from the system. In the cases where it is removed from the system, if the same directory entry lock is subsequently requested, then the lock must be re-instantiated.
In one embodiment of the invention, a file system implementing the directory (100) and the dynamic lock list (104) shown in
If the directory entry lock is already in use, then the caller is blocked until the directory entry lock is released (ST106). Once the directory entry lock is released (i.e., when the process currently holding the directory entry lock has finished using the directory entry lock), the directory entry lock is obtained by the caller (ST108).
If the directory entry lock is not in use, then the directory entry lock is instantiated (ST112). In one embodiment of the invention, instantiating the lock includes instantiating a mutex associated with the directory entry that is to be locked in order to process the request. Once the directory entry lock has been instantiated, the directory entry lock is obtained by/given to the caller (ST108).
Once the directory entry lock has been given to the caller, the dynamic lock list is updated to reflect that the directory entry lock is not available to a subsequent caller (i.e., the directory entry is now locked) (ST110). In one embodiment of the invention, updating the dynamic lock list includes placing for example, the name of the directory entry lock on the dynamic lock list, where the name of the directory entry lock includes the directory entry name with which it is associated.
Once the dynamic lock list has been updated to reflect that the directory entry lock is now held by a caller, a determination is made about whether any additional directory entry locks are required by the caller for the caller to process the request (ST114). If additional directory entry locks are required, then the method proceeds to ST102.
Once all the directory entry locks are obtained, the caller then proceeds to modify the content of the directory in accordance with the request (ST116). After the content of the directory has been modified, the directory entry lock (or locks) is released by the caller (ST18). Once the directory entry lock(s) is released, the directory entry (or entries) corresponding to the directory entry lock (or locks) on the dynamic lock list is removed from the dynamic lock list (ST120).
Though not shown in
In one or more embodiments of the invention, the system shown in
In one embodiment of the invention, each of the aforementioned directory entry locks is obtained in lexicographic order (i.e., Filename X Lock (124), Filename X′ Lock (126), Filename Y Lock (128), Filename Y′ Lock (130)) to avoid dead locking due to inconsistent locking order. Those skilled in the art will appreciate that other ordering schemes of obtaining directory entry locks for simultaneously received requests may be used. Once Filename X Lock (124) and Filename X′ Lock (126) are obtained, request 1 may be processed. Similarly, once Filename Y Lock (128) and Filename Y′ Lock (130) are obtained, request 2 may be processed. In this example, once aforementioned the respective directory entry locks are received, the requests (i.e., requests 1 and 2) may proceed in parallel.
Once a given request is completed, the directory entry locks obtained to process the request are released and the dynamic lock list (132) is updated accordingly. For example, once request 2 is completed, Filename Y Lock (128) and Filename Y′ Lock (130) are released by the caller (i.e., the process that sent request 2) and entries corresponding directory entry locks Y and Y′ are removed from the dynamic lock list (132).
Those skilled in the art will appreciate that while the example shown in
In one embodiment of the invention, a given system may include more than one directory. In such cases, each directory is associated with its own dynamic lock list. Further, a single request may require directory entry locks from two different directories.
As shown in
In accordance with the method discussed in
In one embodiment of the invention, each of the aforementioned directory entry locks is obtained in lexicographic order (i.e., X, X′, Y, Y′). Those skilled in the art will appreciate that other ordering schemes of obtaining directory entry locks for simultaneously received requests may be used. Once Filename X Lock (152) and Filename X′ Lock (164) are obtained, request 1 (140) may be processed. Similarly, once Filename Y Lock (154) and Filename Y′ Lock (166) are obtained, request 2 (142) may be processed. In this example, once the respective directory entry locks are received, the requests (i.e., requests 1 (140) and 2 (142)) may proceed in parallel.
Once a given request is completed, the directory entry locks obtained to process the request are released and the corresponding dynamic lock lists (150, 162) are updated accordingly. For example, once request 2 is completed, Filename Y Lock (154) and Filename Y′ Lock (166) are released by the caller (i.e., the process that sent request 2) and entries corresponding Filename Y Lock (154) and Filename Y′ Lock (166) are removed from the appropriate dynamic lock lists (150, 162).
Those skilled in the art will appreciate that while the example shown in
The invention may be implemented on virtually any type of computer regardless of the platform being used. For example, as shown in
Further, those skilled in the art will appreciate that one or more elements of the aforementioned computer (200) may be located at a remote location and connected to the other elements over a network. Further, the invention may be implemented on a distributed system having a plurality of nodes, where each portion of the invention may be located on a different node within the distributed system. In one embodiment of the invention, the node corresponds to a computer system. Alternatively, the node may correspond to a processor with associated physical memory.
While the invention has been described with respect to a limited number of embodiments, those skilled in the art, having benefit of this disclosure, will appreciate that other embodiments can be devised which do not depart from the scope of the invention as disclosed herein. Accordingly, the scope of the invention should be limited only by the attached claims.
This application claims benefit of U.S. Provisional Application Ser. No. “Directory Entry Locks” (Application Ser. No. 60/734,043) filed on Nov. 4, 2005 in the names of Mark J. Maybee and Matthew A. Ahrens and is hereby incorporated by reference.
Number | Date | Country | |
---|---|---|---|
60734043 | Nov 2005 | US |