diff options
author | Jeff Layton <jlayton@primarydata.com> | 2015-01-16 15:05:54 -0500 |
---|---|---|
committer | Jeff Layton <jlayton@primarydata.com> | 2015-01-16 15:05:54 -0500 |
commit | dd459bb1974c5e9cff3dfbf4f6fdb3e9363ef32e (patch) | |
tree | a3e8ece763ff45bf2082a0c41b56f8a07dea44f6 /fs/locks.c | |
parent | 6dee60f69d48fcef021b4b53b3431797ec440764 (diff) |
locks: have locks_release_file use flock_lock_file to release generic flock locks
...instead of open-coding it and removing flock locks directly. This
helps consolidate the flock lock removal logic into a single spot.
Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Diffstat (limited to 'fs/locks.c')
-rw-r--r-- | fs/locks.c | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/fs/locks.c b/fs/locks.c index bfe5f17401de..ae1e7cf721d6 100644 --- a/fs/locks.c +++ b/fs/locks.c | |||
@@ -2360,6 +2360,30 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner) | |||
2360 | 2360 | ||
2361 | EXPORT_SYMBOL(locks_remove_posix); | 2361 | EXPORT_SYMBOL(locks_remove_posix); |
2362 | 2362 | ||
2363 | static void | ||
2364 | locks_remove_flock(struct file *filp) | ||
2365 | { | ||
2366 | struct file_lock fl = { | ||
2367 | .fl_owner = filp, | ||
2368 | .fl_pid = current->tgid, | ||
2369 | .fl_file = filp, | ||
2370 | .fl_flags = FL_FLOCK, | ||
2371 | .fl_type = F_UNLCK, | ||
2372 | .fl_end = OFFSET_MAX, | ||
2373 | }; | ||
2374 | |||
2375 | if (!file_inode(filp)->i_flock) | ||
2376 | return; | ||
2377 | |||
2378 | if (filp->f_op->flock) | ||
2379 | filp->f_op->flock(filp, F_SETLKW, &fl); | ||
2380 | else | ||
2381 | flock_lock_file(filp, &fl); | ||
2382 | |||
2383 | if (fl.fl_ops && fl.fl_ops->fl_release_private) | ||
2384 | fl.fl_ops->fl_release_private(&fl); | ||
2385 | } | ||
2386 | |||
2363 | /* | 2387 | /* |
2364 | * This function is called on the last close of an open file. | 2388 | * This function is called on the last close of an open file. |
2365 | */ | 2389 | */ |
@@ -2370,24 +2394,14 @@ void locks_remove_file(struct file *filp) | |||
2370 | struct file_lock **before; | 2394 | struct file_lock **before; |
2371 | LIST_HEAD(dispose); | 2395 | LIST_HEAD(dispose); |
2372 | 2396 | ||
2373 | if (!inode->i_flock) | 2397 | /* remove any OFD locks */ |
2374 | return; | ||
2375 | |||
2376 | locks_remove_posix(filp, filp); | 2398 | locks_remove_posix(filp, filp); |
2377 | 2399 | ||
2378 | if (filp->f_op->flock) { | 2400 | /* remove flock locks */ |
2379 | struct file_lock fl = { | 2401 | locks_remove_flock(filp); |
2380 | .fl_owner = filp, | 2402 | |
2381 | .fl_pid = current->tgid, | 2403 | if (!inode->i_flock) |
2382 | .fl_file = filp, | 2404 | return; |
2383 | .fl_flags = FL_FLOCK, | ||
2384 | .fl_type = F_UNLCK, | ||
2385 | .fl_end = OFFSET_MAX, | ||
2386 | }; | ||
2387 | filp->f_op->flock(filp, F_SETLKW, &fl); | ||
2388 | if (fl.fl_ops && fl.fl_ops->fl_release_private) | ||
2389 | fl.fl_ops->fl_release_private(&fl); | ||
2390 | } | ||
2391 | 2405 | ||
2392 | spin_lock(&inode->i_lock); | 2406 | spin_lock(&inode->i_lock); |
2393 | before = &inode->i_flock; | 2407 | before = &inode->i_flock; |
@@ -2407,8 +2421,7 @@ void locks_remove_file(struct file *filp) | |||
2407 | * some info about it and then just remove it from | 2421 | * some info about it and then just remove it from |
2408 | * the list. | 2422 | * the list. |
2409 | */ | 2423 | */ |
2410 | WARN(!IS_FLOCK(fl), | 2424 | WARN(1, "leftover lock: dev=%u:%u ino=%lu type=%hhd flags=0x%x start=%lld end=%lld\n", |
2411 | "leftover lock: dev=%u:%u ino=%lu type=%hhd flags=0x%x start=%lld end=%lld\n", | ||
2412 | MAJOR(inode->i_sb->s_dev), | 2425 | MAJOR(inode->i_sb->s_dev), |
2413 | MINOR(inode->i_sb->s_dev), inode->i_ino, | 2426 | MINOR(inode->i_sb->s_dev), inode->i_ino, |
2414 | fl->fl_type, fl->fl_flags, | 2427 | fl->fl_type, fl->fl_flags, |