diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2011-06-20 10:52:57 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2011-07-20 01:43:14 -0400 |
commit | 07b8ce1ee87d291ff564c02cf878fae973317a52 (patch) | |
tree | 94f07ed2b5d18aef71f1b28193375f88c0c947bc /fs/namei.c | |
parent | f4d6ff89d8e54b68a4322388d26d518d6133fa4e (diff) |
lockless get_write_access/deny_write_access
new helpers: atomic_inc_unless_negative()/atomic_dec_unless_positive()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/namei.c')
-rw-r--r-- | fs/namei.c | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/fs/namei.c b/fs/namei.c index e04f15ae4b07..d286cbc3f3e5 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -341,52 +341,6 @@ ok: | |||
341 | return security_inode_exec_permission(inode, flags); | 341 | return security_inode_exec_permission(inode, flags); |
342 | } | 342 | } |
343 | 343 | ||
344 | /* | ||
345 | * get_write_access() gets write permission for a file. | ||
346 | * put_write_access() releases this write permission. | ||
347 | * This is used for regular files. | ||
348 | * We cannot support write (and maybe mmap read-write shared) accesses and | ||
349 | * MAP_DENYWRITE mmappings simultaneously. The i_writecount field of an inode | ||
350 | * can have the following values: | ||
351 | * 0: no writers, no VM_DENYWRITE mappings | ||
352 | * < 0: (-i_writecount) vm_area_structs with VM_DENYWRITE set exist | ||
353 | * > 0: (i_writecount) users are writing to the file. | ||
354 | * | ||
355 | * Normally we operate on that counter with atomic_{inc,dec} and it's safe | ||
356 | * except for the cases where we don't hold i_writecount yet. Then we need to | ||
357 | * use {get,deny}_write_access() - these functions check the sign and refuse | ||
358 | * to do the change if sign is wrong. Exclusion between them is provided by | ||
359 | * the inode->i_lock spinlock. | ||
360 | */ | ||
361 | |||
362 | int get_write_access(struct inode * inode) | ||
363 | { | ||
364 | spin_lock(&inode->i_lock); | ||
365 | if (atomic_read(&inode->i_writecount) < 0) { | ||
366 | spin_unlock(&inode->i_lock); | ||
367 | return -ETXTBSY; | ||
368 | } | ||
369 | atomic_inc(&inode->i_writecount); | ||
370 | spin_unlock(&inode->i_lock); | ||
371 | |||
372 | return 0; | ||
373 | } | ||
374 | |||
375 | int deny_write_access(struct file * file) | ||
376 | { | ||
377 | struct inode *inode = file->f_path.dentry->d_inode; | ||
378 | |||
379 | spin_lock(&inode->i_lock); | ||
380 | if (atomic_read(&inode->i_writecount) > 0) { | ||
381 | spin_unlock(&inode->i_lock); | ||
382 | return -ETXTBSY; | ||
383 | } | ||
384 | atomic_dec(&inode->i_writecount); | ||
385 | spin_unlock(&inode->i_lock); | ||
386 | |||
387 | return 0; | ||
388 | } | ||
389 | |||
390 | /** | 344 | /** |
391 | * path_get - get a reference to a path | 345 | * path_get - get a reference to a path |
392 | * @path: path to get the reference to | 346 | * @path: path to get the reference to |