diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2008-07-26 00:39:17 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2008-07-26 20:53:40 -0400 |
commit | 516e0cc5646f377ab80fcc2ee639892eccb99853 (patch) | |
tree | e06296dcedb42dbe397d237887873e70c5823d51 /fs | |
parent | 3c333937ee3be114b181c4861188cfe8f6a59697 (diff) |
[PATCH] f_count may wrap around
make it atomic_long_t; while we are at it, get rid of useless checks in affs,
hfs and hpfs - ->open() always has it equal to 1, ->release() - to 0.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/affs/file.c | 4 | ||||
-rw-r--r-- | fs/aio.c | 6 | ||||
-rw-r--r-- | fs/file_table.c | 10 | ||||
-rw-r--r-- | fs/hfs/inode.c | 4 | ||||
-rw-r--r-- | fs/hfsplus/inode.c | 4 |
5 files changed, 8 insertions, 20 deletions
diff --git a/fs/affs/file.c b/fs/affs/file.c index 6eac7bdeec94..1377b1240b6e 100644 --- a/fs/affs/file.c +++ b/fs/affs/file.c | |||
@@ -46,8 +46,6 @@ const struct inode_operations affs_file_inode_operations = { | |||
46 | static int | 46 | static int |
47 | affs_file_open(struct inode *inode, struct file *filp) | 47 | affs_file_open(struct inode *inode, struct file *filp) |
48 | { | 48 | { |
49 | if (atomic_read(&filp->f_count) != 1) | ||
50 | return 0; | ||
51 | pr_debug("AFFS: open(%lu,%d)\n", | 49 | pr_debug("AFFS: open(%lu,%d)\n", |
52 | inode->i_ino, atomic_read(&AFFS_I(inode)->i_opencnt)); | 50 | inode->i_ino, atomic_read(&AFFS_I(inode)->i_opencnt)); |
53 | atomic_inc(&AFFS_I(inode)->i_opencnt); | 51 | atomic_inc(&AFFS_I(inode)->i_opencnt); |
@@ -57,8 +55,6 @@ affs_file_open(struct inode *inode, struct file *filp) | |||
57 | static int | 55 | static int |
58 | affs_file_release(struct inode *inode, struct file *filp) | 56 | affs_file_release(struct inode *inode, struct file *filp) |
59 | { | 57 | { |
60 | if (atomic_read(&filp->f_count) != 0) | ||
61 | return 0; | ||
62 | pr_debug("AFFS: release(%lu, %d)\n", | 58 | pr_debug("AFFS: release(%lu, %d)\n", |
63 | inode->i_ino, atomic_read(&AFFS_I(inode)->i_opencnt)); | 59 | inode->i_ino, atomic_read(&AFFS_I(inode)->i_opencnt)); |
64 | 60 | ||
@@ -512,8 +512,8 @@ static void aio_fput_routine(struct work_struct *data) | |||
512 | */ | 512 | */ |
513 | static int __aio_put_req(struct kioctx *ctx, struct kiocb *req) | 513 | static int __aio_put_req(struct kioctx *ctx, struct kiocb *req) |
514 | { | 514 | { |
515 | dprintk(KERN_DEBUG "aio_put(%p): f_count=%d\n", | 515 | dprintk(KERN_DEBUG "aio_put(%p): f_count=%ld\n", |
516 | req, atomic_read(&req->ki_filp->f_count)); | 516 | req, atomic_long_read(&req->ki_filp->f_count)); |
517 | 517 | ||
518 | assert_spin_locked(&ctx->ctx_lock); | 518 | assert_spin_locked(&ctx->ctx_lock); |
519 | 519 | ||
@@ -528,7 +528,7 @@ static int __aio_put_req(struct kioctx *ctx, struct kiocb *req) | |||
528 | /* Must be done under the lock to serialise against cancellation. | 528 | /* Must be done under the lock to serialise against cancellation. |
529 | * Call this aio_fput as it duplicates fput via the fput_work. | 529 | * Call this aio_fput as it duplicates fput via the fput_work. |
530 | */ | 530 | */ |
531 | if (unlikely(atomic_dec_and_test(&req->ki_filp->f_count))) { | 531 | if (unlikely(atomic_long_dec_and_test(&req->ki_filp->f_count))) { |
532 | get_ioctx(ctx); | 532 | get_ioctx(ctx); |
533 | spin_lock(&fput_lock); | 533 | spin_lock(&fput_lock); |
534 | list_add(&req->ki_list, &fput_head); | 534 | list_add(&req->ki_list, &fput_head); |
diff --git a/fs/file_table.c b/fs/file_table.c index 83084225b4c3..f45a4493f9e7 100644 --- a/fs/file_table.c +++ b/fs/file_table.c | |||
@@ -120,7 +120,7 @@ struct file *get_empty_filp(void) | |||
120 | 120 | ||
121 | tsk = current; | 121 | tsk = current; |
122 | INIT_LIST_HEAD(&f->f_u.fu_list); | 122 | INIT_LIST_HEAD(&f->f_u.fu_list); |
123 | atomic_set(&f->f_count, 1); | 123 | atomic_long_set(&f->f_count, 1); |
124 | rwlock_init(&f->f_owner.lock); | 124 | rwlock_init(&f->f_owner.lock); |
125 | f->f_uid = tsk->fsuid; | 125 | f->f_uid = tsk->fsuid; |
126 | f->f_gid = tsk->fsgid; | 126 | f->f_gid = tsk->fsgid; |
@@ -219,7 +219,7 @@ EXPORT_SYMBOL(init_file); | |||
219 | 219 | ||
220 | void fput(struct file *file) | 220 | void fput(struct file *file) |
221 | { | 221 | { |
222 | if (atomic_dec_and_test(&file->f_count)) | 222 | if (atomic_long_dec_and_test(&file->f_count)) |
223 | __fput(file); | 223 | __fput(file); |
224 | } | 224 | } |
225 | 225 | ||
@@ -294,7 +294,7 @@ struct file *fget(unsigned int fd) | |||
294 | rcu_read_lock(); | 294 | rcu_read_lock(); |
295 | file = fcheck_files(files, fd); | 295 | file = fcheck_files(files, fd); |
296 | if (file) { | 296 | if (file) { |
297 | if (!atomic_inc_not_zero(&file->f_count)) { | 297 | if (!atomic_long_inc_not_zero(&file->f_count)) { |
298 | /* File object ref couldn't be taken */ | 298 | /* File object ref couldn't be taken */ |
299 | rcu_read_unlock(); | 299 | rcu_read_unlock(); |
300 | return NULL; | 300 | return NULL; |
@@ -326,7 +326,7 @@ struct file *fget_light(unsigned int fd, int *fput_needed) | |||
326 | rcu_read_lock(); | 326 | rcu_read_lock(); |
327 | file = fcheck_files(files, fd); | 327 | file = fcheck_files(files, fd); |
328 | if (file) { | 328 | if (file) { |
329 | if (atomic_inc_not_zero(&file->f_count)) | 329 | if (atomic_long_inc_not_zero(&file->f_count)) |
330 | *fput_needed = 1; | 330 | *fput_needed = 1; |
331 | else | 331 | else |
332 | /* Didn't get the reference, someone's freed */ | 332 | /* Didn't get the reference, someone's freed */ |
@@ -341,7 +341,7 @@ struct file *fget_light(unsigned int fd, int *fput_needed) | |||
341 | 341 | ||
342 | void put_filp(struct file *file) | 342 | void put_filp(struct file *file) |
343 | { | 343 | { |
344 | if (atomic_dec_and_test(&file->f_count)) { | 344 | if (atomic_long_dec_and_test(&file->f_count)) { |
345 | security_file_free(file); | 345 | security_file_free(file); |
346 | file_kill(file); | 346 | file_kill(file); |
347 | file_free(file); | 347 | file_free(file); |
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index aa73f3fd5dd9..7e19835efa2e 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c | |||
@@ -522,8 +522,6 @@ static int hfs_file_open(struct inode *inode, struct file *file) | |||
522 | { | 522 | { |
523 | if (HFS_IS_RSRC(inode)) | 523 | if (HFS_IS_RSRC(inode)) |
524 | inode = HFS_I(inode)->rsrc_inode; | 524 | inode = HFS_I(inode)->rsrc_inode; |
525 | if (atomic_read(&file->f_count) != 1) | ||
526 | return 0; | ||
527 | atomic_inc(&HFS_I(inode)->opencnt); | 525 | atomic_inc(&HFS_I(inode)->opencnt); |
528 | return 0; | 526 | return 0; |
529 | } | 527 | } |
@@ -534,8 +532,6 @@ static int hfs_file_release(struct inode *inode, struct file *file) | |||
534 | 532 | ||
535 | if (HFS_IS_RSRC(inode)) | 533 | if (HFS_IS_RSRC(inode)) |
536 | inode = HFS_I(inode)->rsrc_inode; | 534 | inode = HFS_I(inode)->rsrc_inode; |
537 | if (atomic_read(&file->f_count) != 0) | ||
538 | return 0; | ||
539 | if (atomic_dec_and_test(&HFS_I(inode)->opencnt)) { | 535 | if (atomic_dec_and_test(&HFS_I(inode)->opencnt)) { |
540 | mutex_lock(&inode->i_mutex); | 536 | mutex_lock(&inode->i_mutex); |
541 | hfs_file_truncate(inode); | 537 | hfs_file_truncate(inode); |
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c index d4014e3044d2..b085d64a2b67 100644 --- a/fs/hfsplus/inode.c +++ b/fs/hfsplus/inode.c | |||
@@ -254,8 +254,6 @@ static int hfsplus_file_open(struct inode *inode, struct file *file) | |||
254 | { | 254 | { |
255 | if (HFSPLUS_IS_RSRC(inode)) | 255 | if (HFSPLUS_IS_RSRC(inode)) |
256 | inode = HFSPLUS_I(inode).rsrc_inode; | 256 | inode = HFSPLUS_I(inode).rsrc_inode; |
257 | if (atomic_read(&file->f_count) != 1) | ||
258 | return 0; | ||
259 | atomic_inc(&HFSPLUS_I(inode).opencnt); | 257 | atomic_inc(&HFSPLUS_I(inode).opencnt); |
260 | return 0; | 258 | return 0; |
261 | } | 259 | } |
@@ -266,8 +264,6 @@ static int hfsplus_file_release(struct inode *inode, struct file *file) | |||
266 | 264 | ||
267 | if (HFSPLUS_IS_RSRC(inode)) | 265 | if (HFSPLUS_IS_RSRC(inode)) |
268 | inode = HFSPLUS_I(inode).rsrc_inode; | 266 | inode = HFSPLUS_I(inode).rsrc_inode; |
269 | if (atomic_read(&file->f_count) != 0) | ||
270 | return 0; | ||
271 | if (atomic_dec_and_test(&HFSPLUS_I(inode).opencnt)) { | 267 | if (atomic_dec_and_test(&HFSPLUS_I(inode).opencnt)) { |
272 | mutex_lock(&inode->i_mutex); | 268 | mutex_lock(&inode->i_mutex); |
273 | hfsplus_file_truncate(inode); | 269 | hfsplus_file_truncate(inode); |