~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/Documentation/filesystems/Locking

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1         The text below describes the locking rules for VFS-related methods.
  2 It is (believed to be) up-to-date. *Please*, if you change anything in
  3 prototypes or locking protocols - update this file. And update the relevant
  4 instances in the tree, don't leave that to maintainers of filesystems/devices/
  5 etc. At the very least, put the list of dubious cases in the end of this file.
  6 Don't turn it into log - maintainers of out-of-the-tree code are supposed to
  7 be able to use diff(1).
  8         Thing currently missing here: socket operations. Alexey?
  9 
 10 --------------------------- dentry_operations --------------------------
 11 prototypes:
 12         int (*d_revalidate)(struct dentry *, int);
 13         int (*d_hash) (struct dentry *, struct qstr *);
 14         int (*d_compare) (struct dentry *, struct qstr *, struct qstr *);
 15         int (*d_delete)(struct dentry *);
 16         void (*d_release)(struct dentry *);
 17         void (*d_iput)(struct dentry *, struct inode *);
 18 
 19 locking rules:
 20         none have BKL
 21                 dcache_lock     may block
 22 d_revalidate:   no              yes
 23 d_hash          no              yes
 24 d_compare:      yes             no
 25 d_delete:       yes             no
 26 d_release:      no              yes
 27 d_iput:         no              yes
 28 
 29 --------------------------- inode_operations --------------------------- 
 30 prototypes:
 31         int (*create) (struct inode *,struct dentry *,int);
 32         struct dentry * (*lookup) (struct inode *,struct dentry *);
 33         int (*link) (struct dentry *,struct inode *,struct dentry *);
 34         int (*unlink) (struct inode *,struct dentry *);
 35         int (*symlink) (struct inode *,struct dentry *,const char *);
 36         int (*mkdir) (struct inode *,struct dentry *,int);
 37         int (*rmdir) (struct inode *,struct dentry *);
 38         int (*mknod) (struct inode *,struct dentry *,int,int);
 39         int (*rename) (struct inode *, struct dentry *,
 40                         struct inode *, struct dentry *);
 41         int (*readlink) (struct dentry *, char *,int);
 42         int (*follow_link) (struct dentry *, struct nameidata *);
 43         void (*truncate) (struct inode *);
 44         int (*permission) (struct inode *, int);
 45         int (*revalidate) (struct dentry *);
 46         int (*setattr) (struct dentry *, struct iattr *);
 47         int (*getattr) (struct dentry *, struct iattr *);
 48 
 49 locking rules:
 50         all may block
 51                 BKL     i_sem(inode)    i_zombie(inode)
 52 lookup:         yes     yes             no
 53 create:         yes     yes             yes
 54 link:           yes     yes             yes
 55 mknod:          yes     yes             yes
 56 mkdir:          yes     yes             yes
 57 unlink:         yes     yes             yes
 58 rmdir:          yes     yes             yes             (see below)
 59 rename:         yes     yes (both)      yes (both)      (see below)
 60 readlink:       no      no              no
 61 follow_link:    no      no              no
 62 truncate:       yes     yes             no              (see below)
 63 setattr:        yes     if ATTR_SIZE    no
 64 permssion:      yes     no              no
 65 getattr:                                                (see below)
 66 revalidate:     no                                      (see below)
 67         Additionally, ->rmdir() has i_zombie on victim and so does ->rename()
 68 in case when target exists and is a directory.
 69         ->rename() on directories has (per-superblock) ->s_vfs_rename_sem.
 70         ->revalidate(), it may be called both with and without the i_sem
 71 on dentry->d_inode. VFS never calls it with i_zombie on dentry->d_inode,
 72 but watch for other methods directly calling this one...
 73         ->truncate() is never called directly - it's a callback, not a
 74 method. It's called by vmtruncate() - library function normally used by
 75 ->setattr(). Locking information above applies to that call (i.e. is
 76 inherited from ->setattr() - vmtruncate() is used when ATTR_SIZE had been
 77 passed).
 78         ->getattr() is currently unused.
 79 
 80 --------------------------- super_operations ---------------------------
 81 prototypes:
 82         void (*read_inode) (struct inode *);
 83         void (*write_inode) (struct inode *, int);
 84         void (*put_inode) (struct inode *);
 85         void (*delete_inode) (struct inode *);
 86         void (*put_super) (struct super_block *);
 87         void (*write_super) (struct super_block *);
 88         int (*statfs) (struct super_block *, struct statfs *);
 89         int (*remount_fs) (struct super_block *, int *, char *);
 90         void (*clear_inode) (struct inode *);
 91         void (*umount_begin) (struct super_block *);
 92 
 93 locking rules:
 94         All may block.
 95                 BKL     s_lock  mount_sem
 96 read_inode:     yes                             (see below)
 97 write_inode:    no      
 98 put_inode:      no      
 99 delete_inode:   no      
100 clear_inode:    no      
101 put_super:      yes     yes     maybe           (see below)
102 write_super:    yes     yes     maybe           (see below)
103 statfs:         yes     no      no
104 remount_fs:     yes     yes     maybe           (see below)
105 umount_begin:   yes     no      maybe           (see below)
106 
107 ->read_inode() is not a method - it's a callback used in iget()/iget4().
108 rules for mount_sem are not too nice - it is going to die and be replaced
109 by better scheme anyway.
110 
111 --------------------------- file_system_type ---------------------------
112 prototypes:
113         struct super_block *(*read_super) (struct super_block *, void *, int);
114 locking rules:
115 may block       BKL     ->s_lock        mount_sem
116 yes             yes     yes             maybe
117 
118 --------------------------- address_space_operations --------------------------
119 prototypes:
120         int (*writepage)(struct file *, struct page *);
121         int (*readpage)(struct file *, struct page *);
122         int (*sync_page)(struct page *);
123         int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
124         int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
125         int (*bmap)(struct address_space *, long);
126 locking rules:
127         All may block
128                 BKL     PageLocked(page)
129 writepage:      no      yes
130 readpage:       no      yes
131 sync_page:      no      maybe
132 prepare_write:  no      yes
133 commit_write:   no      yes
134 bmap:           yes
135 
136         ->prepare_write(), ->commit_write(), ->sync_page() and ->readpage()
137 may be called from the request handler (/dev/loop).
138         ->sync_page() locking rules are not well-defined - usually it is called
139 with lock on page, but that is not guaranteed. Considering the currently
140 existing instances of this method ->sync_page() itself doesn't look
141 well-defined...
142         ->bmap() is currently used by legacy ioctl() (FIBMAP) provided by some
143 filesystems and by the swapper. The latter will eventually go away. All
144 instances do not actually need the BKL. Please, keep it that way and don't
145 breed new callers.
146         Note: currently almost all instances of address_space methods are
147 using BKL for internal serialization and that's one of the worst sources
148 of contention. Normally they are calling library functions (in fs/buffer.c)
149 and pass foo_get_block() as a callback (on local block-based filesystems,
150 indeed). BKL is not needed for library stuff and is usually taken by
151 foo_get_block(). It's an overkill, since block bitmaps can be protected by
152 internal fs locking and real critical areas are much smaller than the areas
153 filesystems protect now.
154 
155 --------------------------- file_lock ------------------------------------
156 prototypes:
157         void (*fl_notify)(struct file_lock *);  /* unblock callback */
158         void (*fl_insert)(struct file_lock *);  /* lock insertion callback */
159         void (*fl_remove)(struct file_lock *);  /* lock removal callback */
160 
161 locking rules:
162                 BKL     may block
163 fl_notify:      yes     no
164 fl_insert:      yes     maybe
165 fl_remove:      yes     maybe
166         Currently only NLM provides instances of this class. None of the
167 them block. If you have out-of-tree instances - please, show up. Locking
168 in that area will change.
169 
170 --------------------------- buffer_head -----------------------------------
171 prototypes:
172         void (*b_end_io)(struct buffer_head *bh, int uptodate);
173 
174 locking rules:
175         called from interrupts. In other words, extreme care is needed here.
176 bh is locked, but that's all warranties we have here. Currently only RAID1,
177 highmem and fs/buffer.c are providing these. Block devices call this method
178 upon the IO completion.
179 
180 --------------------------- block_device_operations -----------------------
181 prototypes:
182         int (*open) (struct inode *, struct file *);
183         int (*release) (struct inode *, struct file *);
184         int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
185         int (*check_media_change) (kdev_t);
186         int (*revalidate) (kdev_t);
187 locking rules:
188                         BKL     bd_sem
189 open:                   yes     yes
190 release:                yes     yes
191 ioctl:                  yes     no
192 check_media_change:     yes     no
193 revalidate:             yes     no
194 
195 The last two are called only from check_disk_change(). Prototypes are very
196 bad - as soon as we'll get disk_struct they will change (and methods will
197 become per-disk instead of per-partition).
198 
199 --------------------------- file_operations -------------------------------
200 prototypes:
201         loff_t (*llseek) (struct file *, loff_t, int);
202         ssize_t (*read) (struct file *, char *, size_t, loff_t *);
203         ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
204         int (*readdir) (struct file *, void *, filldir_t);
205         unsigned int (*poll) (struct file *, struct poll_table_struct *);
206         int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
207         int (*mmap) (struct file *, struct vm_area_struct *);
208         int (*open) (struct inode *, struct file *);
209         int (*flush) (struct file *);
210         int (*release) (struct inode *, struct file *);
211         int (*fsync) (struct file *, struct dentry *, int datasync);
212         int (*fasync) (int, struct file *, int);
213         int (*lock) (struct file *, int, struct file_lock *);
214         ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
215         ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
216 };
217 
218 locking rules:
219         All except ->poll() may block.
220                 BKL
221 llseek:         yes
222 read:           no
223 write:          no
224 readdir:        yes     (see below)
225 poll:           no
226 ioctl:          yes     (see below)
227 mmap:           no
228 open:           maybe   (see below)
229 flush:          yes
230 release:        no
231 fsync:          yes     (see below)
232 fasync:         yes     (see below)
233 lock:           yes
234 readv:          no
235 writev:         no
236 
237 ->open() locking is in-transit: big lock partially moved into the methods.
238 The only exception is ->open() in the instances of file_operations that never
239 end up in ->i_fop/->proc_fops, i.e. ones that belong to character devices
240 (chrdev_open() takes lock before replacing ->f_op and calling the secondary
241 method. As soon as we fix the handling of module reference counters all
242 instances of ->open() will be called without the BKL.
243 
244 Note: ext2_release() was *the* source of contention on fs-intensive
245 loads and dropping BKL on ->release() helps to get rid of that (we still
246 grab BKL for cases when we close a file that had been opened r/w, but that
247 can and should be done using the internal locking with smaller critical areas).
248 Current worst offender is ext2_get_block()...
249 
250 ->fasync() is a mess. This area needs a big cleanup and that will probably
251 affect locking.
252 
253 ->readdir() and ->ioctl() on directories must be changed. Ideally we would
254 move ->readdir() to inode_operations and use a separate method for directory
255 ->ioctl() or kill the latter completely. One of the problems is that for
256 anything that resembles union-mount we won't have a struct file for all
257 components. And there are other reasons why the current interface is a mess...
258 
259 ->read on directories probably must go away - we should just enforce -EISDIR
260 in sys_read() and friends.
261 
262 ->fsync() has i_sem on inode.
263 
264 --------------------------- dquot_operations -------------------------------
265 prototypes:
266         void (*initialize) (struct inode *, short);
267         void (*drop) (struct inode *);
268         int (*alloc_block) (const struct inode *, unsigned long, char);
269         int (*alloc_inode) (const struct inode *, unsigned long);
270         void (*free_block) (const struct inode *, unsigned long);
271         void (*free_inode) (const struct inode *, unsigned long);
272         int (*transfer) (struct dentry *, struct iattr *);
273 
274 locking rules:
275                 BKL
276 initialize:     no
277 drop:           no
278 alloc_block:    yes
279 alloc_inode:    yes
280 free_block:     yes
281 free_inode:     yes
282 transfer:       no
283 
284 --------------------------- vm_operations_struct -----------------------------
285 prototypes:
286         void (*open)(struct vm_area_struct*);
287         void (*close)(struct vm_area_struct*);
288         void (*unmap)(struct vm_area_struct*, unsigned long, size_t);
289         void (*protect)(struct vm_area_struct*, unsigned long, size_t, unsigned);
290         int (*sync)(struct vm_area_struct*, unsigned long, size_t, unsigned);
291         struct page *(*nopage)(struct vm_area_struct*, unsigned long, int);
292         struct page *(*wppage)(struct vm_area_struct*, unsigned long, struct page*);
293         int (*swapout)(struct page *, struct file *);
294 
295 locking rules:
296                 BKL     mmap_sem
297 open:           no      yes
298 close:          no      yes
299 sync:           no      yes
300 unmap:          no      yes
301 nopage:         no      yes
302 swapout:        yes     yes
303 wpppage:                                (see below)
304 protect:                                (see below)
305 
306 ->wppage() and ->protect() have no instances and nothing calls them; looks like
307 they must die...
308 
309 ================================================================================
310                         Dubious stuff
311 
312 (if you break something or notice that it is broken and do not fix it yourself
313 - at least put it here)
314 
315 ipc/shm.c::shm_delete() - may need BKL.
316 ->read() and ->write() in many drivers are (probably) missing BKL.
317 drivers/sgi/char/graphics.c::sgi_graphics_nopage() - may need BKL.

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.