diff options
Diffstat (limited to 'fs/locks.c')
-rw-r--r-- | fs/locks.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/fs/locks.c b/fs/locks.c index 653faabb07f4..d3d558ba4da7 100644 --- a/fs/locks.c +++ b/fs/locks.c | |||
@@ -862,12 +862,11 @@ static int posix_locks_deadlock(struct file_lock *caller_fl, | |||
862 | * whether or not a lock was successfully freed by testing the return | 862 | * whether or not a lock was successfully freed by testing the return |
863 | * value for -ENOENT. | 863 | * value for -ENOENT. |
864 | */ | 864 | */ |
865 | static int flock_lock_file(struct file *filp, struct file_lock *request) | 865 | static int flock_lock_inode(struct inode *inode, struct file_lock *request) |
866 | { | 866 | { |
867 | struct file_lock *new_fl = NULL; | 867 | struct file_lock *new_fl = NULL; |
868 | struct file_lock *fl; | 868 | struct file_lock *fl; |
869 | struct file_lock_context *ctx; | 869 | struct file_lock_context *ctx; |
870 | struct inode *inode = file_inode(filp); | ||
871 | int error = 0; | 870 | int error = 0; |
872 | bool found = false; | 871 | bool found = false; |
873 | LIST_HEAD(dispose); | 872 | LIST_HEAD(dispose); |
@@ -890,7 +889,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request) | |||
890 | goto find_conflict; | 889 | goto find_conflict; |
891 | 890 | ||
892 | list_for_each_entry(fl, &ctx->flc_flock, fl_list) { | 891 | list_for_each_entry(fl, &ctx->flc_flock, fl_list) { |
893 | if (filp != fl->fl_file) | 892 | if (request->fl_file != fl->fl_file) |
894 | continue; | 893 | continue; |
895 | if (request->fl_type == fl->fl_type) | 894 | if (request->fl_type == fl->fl_type) |
896 | goto out; | 895 | goto out; |
@@ -1164,20 +1163,19 @@ int posix_lock_file(struct file *filp, struct file_lock *fl, | |||
1164 | EXPORT_SYMBOL(posix_lock_file); | 1163 | EXPORT_SYMBOL(posix_lock_file); |
1165 | 1164 | ||
1166 | /** | 1165 | /** |
1167 | * posix_lock_file_wait - Apply a POSIX-style lock to a file | 1166 | * posix_lock_inode_wait - Apply a POSIX-style lock to a file |
1168 | * @filp: The file to apply the lock to | 1167 | * @inode: inode of file to which lock request should be applied |
1169 | * @fl: The lock to be applied | 1168 | * @fl: The lock to be applied |
1170 | * | 1169 | * |
1171 | * Add a POSIX style lock to a file. | 1170 | * Variant of posix_lock_file_wait that does not take a filp, and so can be |
1172 | * We merge adjacent & overlapping locks whenever possible. | 1171 | * used after the filp has already been torn down. |
1173 | * POSIX locks are sorted by owner task, then by starting address | ||
1174 | */ | 1172 | */ |
1175 | int posix_lock_file_wait(struct file *filp, struct file_lock *fl) | 1173 | int posix_lock_inode_wait(struct inode *inode, struct file_lock *fl) |
1176 | { | 1174 | { |
1177 | int error; | 1175 | int error; |
1178 | might_sleep (); | 1176 | might_sleep (); |
1179 | for (;;) { | 1177 | for (;;) { |
1180 | error = posix_lock_file(filp, fl, NULL); | 1178 | error = __posix_lock_file(inode, fl, NULL); |
1181 | if (error != FILE_LOCK_DEFERRED) | 1179 | if (error != FILE_LOCK_DEFERRED) |
1182 | break; | 1180 | break; |
1183 | error = wait_event_interruptible(fl->fl_wait, !fl->fl_next); | 1181 | error = wait_event_interruptible(fl->fl_wait, !fl->fl_next); |
@@ -1189,7 +1187,7 @@ int posix_lock_file_wait(struct file *filp, struct file_lock *fl) | |||
1189 | } | 1187 | } |
1190 | return error; | 1188 | return error; |
1191 | } | 1189 | } |
1192 | EXPORT_SYMBOL(posix_lock_file_wait); | 1190 | EXPORT_SYMBOL(posix_lock_inode_wait); |
1193 | 1191 | ||
1194 | /** | 1192 | /** |
1195 | * locks_mandatory_locked - Check for an active lock | 1193 | * locks_mandatory_locked - Check for an active lock |
@@ -1851,18 +1849,18 @@ int fcntl_setlease(unsigned int fd, struct file *filp, long arg) | |||
1851 | } | 1849 | } |
1852 | 1850 | ||
1853 | /** | 1851 | /** |
1854 | * flock_lock_file_wait - Apply a FLOCK-style lock to a file | 1852 | * flock_lock_inode_wait - Apply a FLOCK-style lock to a file |
1855 | * @filp: The file to apply the lock to | 1853 | * @inode: inode of the file to apply to |
1856 | * @fl: The lock to be applied | 1854 | * @fl: The lock to be applied |
1857 | * | 1855 | * |
1858 | * Add a FLOCK style lock to a file. | 1856 | * Apply a FLOCK style lock request to an inode. |
1859 | */ | 1857 | */ |
1860 | int flock_lock_file_wait(struct file *filp, struct file_lock *fl) | 1858 | int flock_lock_inode_wait(struct inode *inode, struct file_lock *fl) |
1861 | { | 1859 | { |
1862 | int error; | 1860 | int error; |
1863 | might_sleep(); | 1861 | might_sleep(); |
1864 | for (;;) { | 1862 | for (;;) { |
1865 | error = flock_lock_file(filp, fl); | 1863 | error = flock_lock_inode(inode, fl); |
1866 | if (error != FILE_LOCK_DEFERRED) | 1864 | if (error != FILE_LOCK_DEFERRED) |
1867 | break; | 1865 | break; |
1868 | error = wait_event_interruptible(fl->fl_wait, !fl->fl_next); | 1866 | error = wait_event_interruptible(fl->fl_wait, !fl->fl_next); |
@@ -1874,8 +1872,7 @@ int flock_lock_file_wait(struct file *filp, struct file_lock *fl) | |||
1874 | } | 1872 | } |
1875 | return error; | 1873 | return error; |
1876 | } | 1874 | } |
1877 | 1875 | EXPORT_SYMBOL(flock_lock_inode_wait); | |
1878 | EXPORT_SYMBOL(flock_lock_file_wait); | ||
1879 | 1876 | ||
1880 | /** | 1877 | /** |
1881 | * sys_flock: - flock() system call. | 1878 | * sys_flock: - flock() system call. |
@@ -2401,7 +2398,8 @@ locks_remove_flock(struct file *filp) | |||
2401 | .fl_type = F_UNLCK, | 2398 | .fl_type = F_UNLCK, |
2402 | .fl_end = OFFSET_MAX, | 2399 | .fl_end = OFFSET_MAX, |
2403 | }; | 2400 | }; |
2404 | struct file_lock_context *flctx = file_inode(filp)->i_flctx; | 2401 | struct inode *inode = file_inode(filp); |
2402 | struct file_lock_context *flctx = inode->i_flctx; | ||
2405 | 2403 | ||
2406 | if (list_empty(&flctx->flc_flock)) | 2404 | if (list_empty(&flctx->flc_flock)) |
2407 | return; | 2405 | return; |
@@ -2409,7 +2407,7 @@ locks_remove_flock(struct file *filp) | |||
2409 | if (filp->f_op->flock) | 2407 | if (filp->f_op->flock) |
2410 | filp->f_op->flock(filp, F_SETLKW, &fl); | 2408 | filp->f_op->flock(filp, F_SETLKW, &fl); |
2411 | else | 2409 | else |
2412 | flock_lock_file(filp, &fl); | 2410 | flock_lock_inode(inode, &fl); |
2413 | 2411 | ||
2414 | if (fl.fl_ops && fl.fl_ops->fl_release_private) | 2412 | if (fl.fl_ops && fl.fl_ops->fl_release_private) |
2415 | fl.fl_ops->fl_release_private(&fl); | 2413 | fl.fl_ops->fl_release_private(&fl); |