|
@@ -862,12 +862,11 @@ static int posix_locks_deadlock(struct file_lock *caller_fl,
|
|
* whether or not a lock was successfully freed by testing the return
|
|
* whether or not a lock was successfully freed by testing the return
|
|
* value for -ENOENT.
|
|
* value for -ENOENT.
|
|
*/
|
|
*/
|
|
-static int flock_lock_file(struct file *filp, struct file_lock *request)
|
|
|
|
|
|
+static int flock_lock_inode(struct inode *inode, struct file_lock *request)
|
|
{
|
|
{
|
|
struct file_lock *new_fl = NULL;
|
|
struct file_lock *new_fl = NULL;
|
|
struct file_lock *fl;
|
|
struct file_lock *fl;
|
|
struct file_lock_context *ctx;
|
|
struct file_lock_context *ctx;
|
|
- struct inode *inode = file_inode(filp);
|
|
|
|
int error = 0;
|
|
int error = 0;
|
|
bool found = false;
|
|
bool found = false;
|
|
LIST_HEAD(dispose);
|
|
LIST_HEAD(dispose);
|
|
@@ -890,7 +889,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
|
|
goto find_conflict;
|
|
goto find_conflict;
|
|
|
|
|
|
list_for_each_entry(fl, &ctx->flc_flock, fl_list) {
|
|
list_for_each_entry(fl, &ctx->flc_flock, fl_list) {
|
|
- if (filp != fl->fl_file)
|
|
|
|
|
|
+ if (request->fl_file != fl->fl_file)
|
|
continue;
|
|
continue;
|
|
if (request->fl_type == fl->fl_type)
|
|
if (request->fl_type == fl->fl_type)
|
|
goto out;
|
|
goto out;
|
|
@@ -1164,20 +1163,19 @@ int posix_lock_file(struct file *filp, struct file_lock *fl,
|
|
EXPORT_SYMBOL(posix_lock_file);
|
|
EXPORT_SYMBOL(posix_lock_file);
|
|
|
|
|
|
/**
|
|
/**
|
|
- * posix_lock_file_wait - Apply a POSIX-style lock to a file
|
|
|
|
- * @filp: The file to apply the lock to
|
|
|
|
|
|
+ * posix_lock_inode_wait - Apply a POSIX-style lock to a file
|
|
|
|
+ * @inode: inode of file to which lock request should be applied
|
|
* @fl: The lock to be applied
|
|
* @fl: The lock to be applied
|
|
*
|
|
*
|
|
- * Add a POSIX style lock to a file.
|
|
|
|
- * We merge adjacent & overlapping locks whenever possible.
|
|
|
|
- * POSIX locks are sorted by owner task, then by starting address
|
|
|
|
|
|
+ * Variant of posix_lock_file_wait that does not take a filp, and so can be
|
|
|
|
+ * used after the filp has already been torn down.
|
|
*/
|
|
*/
|
|
-int posix_lock_file_wait(struct file *filp, struct file_lock *fl)
|
|
|
|
|
|
+int posix_lock_inode_wait(struct inode *inode, struct file_lock *fl)
|
|
{
|
|
{
|
|
int error;
|
|
int error;
|
|
might_sleep ();
|
|
might_sleep ();
|
|
for (;;) {
|
|
for (;;) {
|
|
- error = posix_lock_file(filp, fl, NULL);
|
|
|
|
|
|
+ error = __posix_lock_file(inode, fl, NULL);
|
|
if (error != FILE_LOCK_DEFERRED)
|
|
if (error != FILE_LOCK_DEFERRED)
|
|
break;
|
|
break;
|
|
error = wait_event_interruptible(fl->fl_wait, !fl->fl_next);
|
|
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)
|
|
}
|
|
}
|
|
return error;
|
|
return error;
|
|
}
|
|
}
|
|
-EXPORT_SYMBOL(posix_lock_file_wait);
|
|
|
|
|
|
+EXPORT_SYMBOL(posix_lock_inode_wait);
|
|
|
|
|
|
/**
|
|
/**
|
|
* locks_mandatory_locked - Check for an active lock
|
|
* locks_mandatory_locked - Check for an active lock
|
|
@@ -1851,18 +1849,18 @@ int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * flock_lock_file_wait - Apply a FLOCK-style lock to a file
|
|
|
|
- * @filp: The file to apply the lock to
|
|
|
|
|
|
+ * flock_lock_inode_wait - Apply a FLOCK-style lock to a file
|
|
|
|
+ * @inode: inode of the file to apply to
|
|
* @fl: The lock to be applied
|
|
* @fl: The lock to be applied
|
|
*
|
|
*
|
|
- * Add a FLOCK style lock to a file.
|
|
|
|
|
|
+ * Apply a FLOCK style lock request to an inode.
|
|
*/
|
|
*/
|
|
-int flock_lock_file_wait(struct file *filp, struct file_lock *fl)
|
|
|
|
|
|
+int flock_lock_inode_wait(struct inode *inode, struct file_lock *fl)
|
|
{
|
|
{
|
|
int error;
|
|
int error;
|
|
might_sleep();
|
|
might_sleep();
|
|
for (;;) {
|
|
for (;;) {
|
|
- error = flock_lock_file(filp, fl);
|
|
|
|
|
|
+ error = flock_lock_inode(inode, fl);
|
|
if (error != FILE_LOCK_DEFERRED)
|
|
if (error != FILE_LOCK_DEFERRED)
|
|
break;
|
|
break;
|
|
error = wait_event_interruptible(fl->fl_wait, !fl->fl_next);
|
|
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)
|
|
}
|
|
}
|
|
return error;
|
|
return error;
|
|
}
|
|
}
|
|
-
|
|
|
|
-EXPORT_SYMBOL(flock_lock_file_wait);
|
|
|
|
|
|
+EXPORT_SYMBOL(flock_lock_inode_wait);
|
|
|
|
|
|
/**
|
|
/**
|
|
* sys_flock: - flock() system call.
|
|
* sys_flock: - flock() system call.
|
|
@@ -2401,7 +2398,8 @@ locks_remove_flock(struct file *filp)
|
|
.fl_type = F_UNLCK,
|
|
.fl_type = F_UNLCK,
|
|
.fl_end = OFFSET_MAX,
|
|
.fl_end = OFFSET_MAX,
|
|
};
|
|
};
|
|
- struct file_lock_context *flctx = file_inode(filp)->i_flctx;
|
|
|
|
|
|
+ struct inode *inode = file_inode(filp);
|
|
|
|
+ struct file_lock_context *flctx = inode->i_flctx;
|
|
|
|
|
|
if (list_empty(&flctx->flc_flock))
|
|
if (list_empty(&flctx->flc_flock))
|
|
return;
|
|
return;
|
|
@@ -2409,7 +2407,7 @@ locks_remove_flock(struct file *filp)
|
|
if (filp->f_op->flock)
|
|
if (filp->f_op->flock)
|
|
filp->f_op->flock(filp, F_SETLKW, &fl);
|
|
filp->f_op->flock(filp, F_SETLKW, &fl);
|
|
else
|
|
else
|
|
- flock_lock_file(filp, &fl);
|
|
|
|
|
|
+ flock_lock_inode(inode, &fl);
|
|
|
|
|
|
if (fl.fl_ops && fl.fl_ops->fl_release_private)
|
|
if (fl.fl_ops && fl.fl_ops->fl_release_private)
|
|
fl.fl_ops->fl_release_private(&fl);
|
|
fl.fl_ops->fl_release_private(&fl);
|