diff options
author | Jeff Layton <jlayton@redhat.com> | 2010-10-15 15:34:06 -0400 |
---|---|---|
committer | Steve French <sfrench@us.ibm.com> | 2010-10-24 20:18:59 -0400 |
commit | 5f6dbc9e4afe4d1d39e85de3ac2720a2042ad191 (patch) | |
tree | 8e97fe18b6d0824981fd377b2ff35042da264bb4 /fs | |
parent | 229aebb873e29726b91e076161649cf45154b0bf (diff) |
cifs: convert cifsFileInfo->count to non-atomic counter
The count for cifsFileInfo is currently an atomic, but that just adds
complexity for little value. We generally need to hold cifs_file_list_lock
to traverse the lists anyway so we might as well make this counter
non-atomic and simply use the cifs_file_list_lock to protect it.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Reviewed-by: Suresh Jayaraman <sjayaraman@suse.de>
Signed-off-by: Steve French <sfrench@us.ibm.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/cifs/cifsglob.h | 9 | ||||
-rw-r--r-- | fs/cifs/file.c | 8 |
2 files changed, 11 insertions, 6 deletions
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 3365e77f6f24..6319db025e7b 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h | |||
@@ -395,16 +395,19 @@ struct cifsFileInfo { | |||
395 | struct list_head llist; /* list of byte range locks we have. */ | 395 | struct list_head llist; /* list of byte range locks we have. */ |
396 | bool invalidHandle:1; /* file closed via session abend */ | 396 | bool invalidHandle:1; /* file closed via session abend */ |
397 | bool oplock_break_cancelled:1; | 397 | bool oplock_break_cancelled:1; |
398 | atomic_t count; /* reference count */ | 398 | int count; /* refcount -- protected by cifs_file_list_lock */ |
399 | struct mutex fh_mutex; /* prevents reopen race after dead ses*/ | 399 | struct mutex fh_mutex; /* prevents reopen race after dead ses*/ |
400 | struct cifs_search_info srch_inf; | 400 | struct cifs_search_info srch_inf; |
401 | struct work_struct oplock_break; /* work for oplock breaks */ | 401 | struct work_struct oplock_break; /* work for oplock breaks */ |
402 | }; | 402 | }; |
403 | 403 | ||
404 | /* Take a reference on the file private data */ | 404 | /* |
405 | * Take a reference on the file private data. Must be called with | ||
406 | * cifs_file_list_lock held. | ||
407 | */ | ||
405 | static inline void cifsFileInfo_get(struct cifsFileInfo *cifs_file) | 408 | static inline void cifsFileInfo_get(struct cifsFileInfo *cifs_file) |
406 | { | 409 | { |
407 | atomic_inc(&cifs_file->count); | 410 | ++cifs_file->count; |
408 | } | 411 | } |
409 | 412 | ||
410 | void cifsFileInfo_put(struct cifsFileInfo *cifs_file); | 413 | void cifsFileInfo_put(struct cifsFileInfo *cifs_file); |
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 8c81e7b14d53..baf4b5067ff9 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
@@ -232,6 +232,7 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file, | |||
232 | if (pCifsFile == NULL) | 232 | if (pCifsFile == NULL) |
233 | return pCifsFile; | 233 | return pCifsFile; |
234 | 234 | ||
235 | pCifsFile->count = 1; | ||
235 | pCifsFile->netfid = fileHandle; | 236 | pCifsFile->netfid = fileHandle; |
236 | pCifsFile->pid = current->tgid; | 237 | pCifsFile->pid = current->tgid; |
237 | pCifsFile->uid = current_fsuid(); | 238 | pCifsFile->uid = current_fsuid(); |
@@ -242,7 +243,6 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file, | |||
242 | mutex_init(&pCifsFile->fh_mutex); | 243 | mutex_init(&pCifsFile->fh_mutex); |
243 | mutex_init(&pCifsFile->lock_mutex); | 244 | mutex_init(&pCifsFile->lock_mutex); |
244 | INIT_LIST_HEAD(&pCifsFile->llist); | 245 | INIT_LIST_HEAD(&pCifsFile->llist); |
245 | atomic_set(&pCifsFile->count, 1); | ||
246 | INIT_WORK(&pCifsFile->oplock_break, cifs_oplock_break); | 246 | INIT_WORK(&pCifsFile->oplock_break, cifs_oplock_break); |
247 | 247 | ||
248 | spin_lock(&cifs_file_list_lock); | 248 | spin_lock(&cifs_file_list_lock); |
@@ -267,7 +267,8 @@ cifs_new_fileinfo(__u16 fileHandle, struct file *file, | |||
267 | 267 | ||
268 | /* | 268 | /* |
269 | * Release a reference on the file private data. This may involve closing | 269 | * Release a reference on the file private data. This may involve closing |
270 | * the filehandle out on the server. | 270 | * the filehandle out on the server. Must be called without holding |
271 | * cifs_file_list_lock. | ||
271 | */ | 272 | */ |
272 | void cifsFileInfo_put(struct cifsFileInfo *cifs_file) | 273 | void cifsFileInfo_put(struct cifsFileInfo *cifs_file) |
273 | { | 274 | { |
@@ -276,7 +277,7 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file) | |||
276 | struct cifsLockInfo *li, *tmp; | 277 | struct cifsLockInfo *li, *tmp; |
277 | 278 | ||
278 | spin_lock(&cifs_file_list_lock); | 279 | spin_lock(&cifs_file_list_lock); |
279 | if (!atomic_dec_and_test(&cifs_file->count)) { | 280 | if (--cifs_file->count > 0) { |
280 | spin_unlock(&cifs_file_list_lock); | 281 | spin_unlock(&cifs_file_list_lock); |
281 | return; | 282 | return; |
282 | } | 283 | } |
@@ -2322,6 +2323,7 @@ void cifs_oplock_break(struct work_struct *work) | |||
2322 | cifs_oplock_break_put(cfile); | 2323 | cifs_oplock_break_put(cfile); |
2323 | } | 2324 | } |
2324 | 2325 | ||
2326 | /* must be called while holding cifs_file_list_lock */ | ||
2325 | void cifs_oplock_break_get(struct cifsFileInfo *cfile) | 2327 | void cifs_oplock_break_get(struct cifsFileInfo *cfile) |
2326 | { | 2328 | { |
2327 | cifs_sb_active(cfile->dentry->d_sb); | 2329 | cifs_sb_active(cfile->dentry->d_sb); |