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 | |
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>
-rw-r--r-- | drivers/net/ppp_generic.c | 6 | ||||
-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 | ||||
-rw-r--r-- | include/linux/fs.h | 6 | ||||
-rw-r--r-- | include/net/af_unix.h | 2 | ||||
-rw-r--r-- | net/sched/sch_atm.c | 4 | ||||
-rw-r--r-- | net/unix/af_unix.c | 2 | ||||
-rw-r--r-- | net/unix/garbage.c | 18 |
11 files changed, 27 insertions, 39 deletions
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c index 739b3ab7bccc..ddccc074a76a 100644 --- a/drivers/net/ppp_generic.c +++ b/drivers/net/ppp_generic.c | |||
@@ -581,12 +581,12 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
581 | if (file == ppp->owner) | 581 | if (file == ppp->owner) |
582 | ppp_shutdown_interface(ppp); | 582 | ppp_shutdown_interface(ppp); |
583 | } | 583 | } |
584 | if (atomic_read(&file->f_count) <= 2) { | 584 | if (atomic_long_read(&file->f_count) <= 2) { |
585 | ppp_release(NULL, file); | 585 | ppp_release(NULL, file); |
586 | err = 0; | 586 | err = 0; |
587 | } else | 587 | } else |
588 | printk(KERN_DEBUG "PPPIOCDETACH file->f_count=%d\n", | 588 | printk(KERN_DEBUG "PPPIOCDETACH file->f_count=%ld\n", |
589 | atomic_read(&file->f_count)); | 589 | atomic_long_read(&file->f_count)); |
590 | unlock_kernel(); | 590 | unlock_kernel(); |
591 | return err; | 591 | return err; |
592 | } | 592 | } |
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); |
diff --git a/include/linux/fs.h b/include/linux/fs.h index 9d2de4cadabd..7676fa1c20ae 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -795,7 +795,7 @@ struct file { | |||
795 | #define f_dentry f_path.dentry | 795 | #define f_dentry f_path.dentry |
796 | #define f_vfsmnt f_path.mnt | 796 | #define f_vfsmnt f_path.mnt |
797 | const struct file_operations *f_op; | 797 | const struct file_operations *f_op; |
798 | atomic_t f_count; | 798 | atomic_long_t f_count; |
799 | unsigned int f_flags; | 799 | unsigned int f_flags; |
800 | mode_t f_mode; | 800 | mode_t f_mode; |
801 | loff_t f_pos; | 801 | loff_t f_pos; |
@@ -824,8 +824,8 @@ extern spinlock_t files_lock; | |||
824 | #define file_list_lock() spin_lock(&files_lock); | 824 | #define file_list_lock() spin_lock(&files_lock); |
825 | #define file_list_unlock() spin_unlock(&files_lock); | 825 | #define file_list_unlock() spin_unlock(&files_lock); |
826 | 826 | ||
827 | #define get_file(x) atomic_inc(&(x)->f_count) | 827 | #define get_file(x) atomic_long_inc(&(x)->f_count) |
828 | #define file_count(x) atomic_read(&(x)->f_count) | 828 | #define file_count(x) atomic_long_read(&(x)->f_count) |
829 | 829 | ||
830 | #ifdef CONFIG_DEBUG_WRITECOUNT | 830 | #ifdef CONFIG_DEBUG_WRITECOUNT |
831 | static inline void file_take_write(struct file *f) | 831 | static inline void file_take_write(struct file *f) |
diff --git a/include/net/af_unix.h b/include/net/af_unix.h index 2dfa96b0575e..7dd29b7e461d 100644 --- a/include/net/af_unix.h +++ b/include/net/af_unix.h | |||
@@ -51,7 +51,7 @@ struct unix_sock { | |||
51 | struct sock *peer; | 51 | struct sock *peer; |
52 | struct sock *other; | 52 | struct sock *other; |
53 | struct list_head link; | 53 | struct list_head link; |
54 | atomic_t inflight; | 54 | atomic_long_t inflight; |
55 | spinlock_t lock; | 55 | spinlock_t lock; |
56 | unsigned int gc_candidate : 1; | 56 | unsigned int gc_candidate : 1; |
57 | wait_queue_head_t peer_wait; | 57 | wait_queue_head_t peer_wait; |
diff --git a/net/sched/sch_atm.c b/net/sched/sch_atm.c index 04faa835be17..6b517b9dac5b 100644 --- a/net/sched/sch_atm.c +++ b/net/sched/sch_atm.c | |||
@@ -162,7 +162,7 @@ static void atm_tc_put(struct Qdisc *sch, unsigned long cl) | |||
162 | qdisc_destroy(flow->q); | 162 | qdisc_destroy(flow->q); |
163 | tcf_destroy_chain(&flow->filter_list); | 163 | tcf_destroy_chain(&flow->filter_list); |
164 | if (flow->sock) { | 164 | if (flow->sock) { |
165 | pr_debug("atm_tc_put: f_count %d\n", | 165 | pr_debug("atm_tc_put: f_count %ld\n", |
166 | file_count(flow->sock->file)); | 166 | file_count(flow->sock->file)); |
167 | flow->vcc->pop = flow->old_pop; | 167 | flow->vcc->pop = flow->old_pop; |
168 | sockfd_put(flow->sock); | 168 | sockfd_put(flow->sock); |
@@ -259,7 +259,7 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent, | |||
259 | sock = sockfd_lookup(fd, &error); | 259 | sock = sockfd_lookup(fd, &error); |
260 | if (!sock) | 260 | if (!sock) |
261 | return error; /* f_count++ */ | 261 | return error; /* f_count++ */ |
262 | pr_debug("atm_tc_change: f_count %d\n", file_count(sock->file)); | 262 | pr_debug("atm_tc_change: f_count %ld\n", file_count(sock->file)); |
263 | if (sock->ops->family != PF_ATMSVC && sock->ops->family != PF_ATMPVC) { | 263 | if (sock->ops->family != PF_ATMSVC && sock->ops->family != PF_ATMPVC) { |
264 | error = -EPROTOTYPE; | 264 | error = -EPROTOTYPE; |
265 | goto err_out; | 265 | goto err_out; |
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 70ceb1604ad8..6e7fec74bdb3 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
@@ -603,7 +603,7 @@ static struct sock * unix_create1(struct net *net, struct socket *sock) | |||
603 | u->dentry = NULL; | 603 | u->dentry = NULL; |
604 | u->mnt = NULL; | 604 | u->mnt = NULL; |
605 | spin_lock_init(&u->lock); | 605 | spin_lock_init(&u->lock); |
606 | atomic_set(&u->inflight, 0); | 606 | atomic_long_set(&u->inflight, 0); |
607 | INIT_LIST_HEAD(&u->link); | 607 | INIT_LIST_HEAD(&u->link); |
608 | mutex_init(&u->readlock); /* single task reading lock */ | 608 | mutex_init(&u->readlock); /* single task reading lock */ |
609 | init_waitqueue_head(&u->peer_wait); | 609 | init_waitqueue_head(&u->peer_wait); |
diff --git a/net/unix/garbage.c b/net/unix/garbage.c index ebdff3d877a1..2a27b84f740b 100644 --- a/net/unix/garbage.c +++ b/net/unix/garbage.c | |||
@@ -127,7 +127,7 @@ void unix_inflight(struct file *fp) | |||
127 | if(s) { | 127 | if(s) { |
128 | struct unix_sock *u = unix_sk(s); | 128 | struct unix_sock *u = unix_sk(s); |
129 | spin_lock(&unix_gc_lock); | 129 | spin_lock(&unix_gc_lock); |
130 | if (atomic_inc_return(&u->inflight) == 1) { | 130 | if (atomic_long_inc_return(&u->inflight) == 1) { |
131 | BUG_ON(!list_empty(&u->link)); | 131 | BUG_ON(!list_empty(&u->link)); |
132 | list_add_tail(&u->link, &gc_inflight_list); | 132 | list_add_tail(&u->link, &gc_inflight_list); |
133 | } else { | 133 | } else { |
@@ -145,7 +145,7 @@ void unix_notinflight(struct file *fp) | |||
145 | struct unix_sock *u = unix_sk(s); | 145 | struct unix_sock *u = unix_sk(s); |
146 | spin_lock(&unix_gc_lock); | 146 | spin_lock(&unix_gc_lock); |
147 | BUG_ON(list_empty(&u->link)); | 147 | BUG_ON(list_empty(&u->link)); |
148 | if (atomic_dec_and_test(&u->inflight)) | 148 | if (atomic_long_dec_and_test(&u->inflight)) |
149 | list_del_init(&u->link); | 149 | list_del_init(&u->link); |
150 | unix_tot_inflight--; | 150 | unix_tot_inflight--; |
151 | spin_unlock(&unix_gc_lock); | 151 | spin_unlock(&unix_gc_lock); |
@@ -237,17 +237,17 @@ static void scan_children(struct sock *x, void (*func)(struct unix_sock *), | |||
237 | 237 | ||
238 | static void dec_inflight(struct unix_sock *usk) | 238 | static void dec_inflight(struct unix_sock *usk) |
239 | { | 239 | { |
240 | atomic_dec(&usk->inflight); | 240 | atomic_long_dec(&usk->inflight); |
241 | } | 241 | } |
242 | 242 | ||
243 | static void inc_inflight(struct unix_sock *usk) | 243 | static void inc_inflight(struct unix_sock *usk) |
244 | { | 244 | { |
245 | atomic_inc(&usk->inflight); | 245 | atomic_long_inc(&usk->inflight); |
246 | } | 246 | } |
247 | 247 | ||
248 | static void inc_inflight_move_tail(struct unix_sock *u) | 248 | static void inc_inflight_move_tail(struct unix_sock *u) |
249 | { | 249 | { |
250 | atomic_inc(&u->inflight); | 250 | atomic_long_inc(&u->inflight); |
251 | /* | 251 | /* |
252 | * If this is still a candidate, move it to the end of the | 252 | * If this is still a candidate, move it to the end of the |
253 | * list, so that it's checked even if it was already passed | 253 | * list, so that it's checked even if it was already passed |
@@ -288,11 +288,11 @@ void unix_gc(void) | |||
288 | * before the detach without atomicity guarantees. | 288 | * before the detach without atomicity guarantees. |
289 | */ | 289 | */ |
290 | list_for_each_entry_safe(u, next, &gc_inflight_list, link) { | 290 | list_for_each_entry_safe(u, next, &gc_inflight_list, link) { |
291 | int total_refs; | 291 | long total_refs; |
292 | int inflight_refs; | 292 | long inflight_refs; |
293 | 293 | ||
294 | total_refs = file_count(u->sk.sk_socket->file); | 294 | total_refs = file_count(u->sk.sk_socket->file); |
295 | inflight_refs = atomic_read(&u->inflight); | 295 | inflight_refs = atomic_long_read(&u->inflight); |
296 | 296 | ||
297 | BUG_ON(inflight_refs < 1); | 297 | BUG_ON(inflight_refs < 1); |
298 | BUG_ON(total_refs < inflight_refs); | 298 | BUG_ON(total_refs < inflight_refs); |
@@ -324,7 +324,7 @@ void unix_gc(void) | |||
324 | /* Move cursor to after the current position. */ | 324 | /* Move cursor to after the current position. */ |
325 | list_move(&cursor, &u->link); | 325 | list_move(&cursor, &u->link); |
326 | 326 | ||
327 | if (atomic_read(&u->inflight) > 0) { | 327 | if (atomic_long_read(&u->inflight) > 0) { |
328 | list_move_tail(&u->link, &gc_inflight_list); | 328 | list_move_tail(&u->link, &gc_inflight_list); |
329 | u->gc_candidate = 0; | 329 | u->gc_candidate = 0; |
330 | scan_children(&u->sk, inc_inflight_move_tail, NULL); | 330 | scan_children(&u->sk, inc_inflight_move_tail, NULL); |