CIFS: Simplify setlk error handling for mandatory locking
Now we allocate a lock structure at first, then we request to the server and save the lock if server returned OK though void function - it prevents the situation when we locked a file on the server and then return -ENOMEM from setlk. Signed-off-by: Pavel Shilovsky <piastry@etersoft.ru> Acked-by: Jeff Layton <jlayton@samba.org> Signed-off-by: Steve French <sfrench@us.ibm.com>
This commit is contained in:
Родитель
1a67a573b8
Коммит
161ebf9fcc
|
@ -672,7 +672,7 @@ cifs_del_lock_waiters(struct cifsLockInfo *lock)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
|
__cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
|
||||||
__u64 length, __u8 type, __u16 netfid,
|
__u64 length, __u8 type, __u16 netfid,
|
||||||
struct cifsLockInfo **conf_lock)
|
struct cifsLockInfo **conf_lock)
|
||||||
{
|
{
|
||||||
|
@ -694,6 +694,14 @@ cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
cifs_find_lock_conflict(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock,
|
||||||
|
struct cifsLockInfo **conf_lock)
|
||||||
|
{
|
||||||
|
return __cifs_find_lock_conflict(cinode, lock->offset, lock->length,
|
||||||
|
lock->type, lock->netfid, conf_lock);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
|
cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
|
||||||
__u8 type, __u16 netfid, struct file_lock *flock)
|
__u8 type, __u16 netfid, struct file_lock *flock)
|
||||||
|
@ -704,8 +712,8 @@ cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
|
||||||
|
|
||||||
mutex_lock(&cinode->lock_mutex);
|
mutex_lock(&cinode->lock_mutex);
|
||||||
|
|
||||||
exist = cifs_find_lock_conflict(cinode, offset, length, type, netfid,
|
exist = __cifs_find_lock_conflict(cinode, offset, length, type, netfid,
|
||||||
&conf_lock);
|
&conf_lock);
|
||||||
if (exist) {
|
if (exist) {
|
||||||
flock->fl_start = conf_lock->offset;
|
flock->fl_start = conf_lock->offset;
|
||||||
flock->fl_end = conf_lock->offset + conf_lock->length - 1;
|
flock->fl_end = conf_lock->offset + conf_lock->length - 1;
|
||||||
|
@ -723,40 +731,27 @@ cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static void
|
||||||
cifs_lock_add(struct cifsInodeInfo *cinode, __u64 len, __u64 offset,
|
cifs_lock_add(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock)
|
||||||
__u8 type, __u16 netfid)
|
|
||||||
{
|
{
|
||||||
struct cifsLockInfo *li;
|
|
||||||
|
|
||||||
li = cifs_lock_init(len, offset, type, netfid);
|
|
||||||
if (!li)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
mutex_lock(&cinode->lock_mutex);
|
mutex_lock(&cinode->lock_mutex);
|
||||||
list_add_tail(&li->llist, &cinode->llist);
|
list_add_tail(&lock->llist, &cinode->llist);
|
||||||
mutex_unlock(&cinode->lock_mutex);
|
mutex_unlock(&cinode->lock_mutex);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cifs_lock_add_if(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
|
cifs_lock_add_if(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock,
|
||||||
__u8 type, __u16 netfid, bool wait)
|
bool wait)
|
||||||
{
|
{
|
||||||
struct cifsLockInfo *lock, *conf_lock;
|
struct cifsLockInfo *conf_lock;
|
||||||
bool exist;
|
bool exist;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
lock = cifs_lock_init(length, offset, type, netfid);
|
|
||||||
if (!lock)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
try_again:
|
try_again:
|
||||||
exist = false;
|
exist = false;
|
||||||
mutex_lock(&cinode->lock_mutex);
|
mutex_lock(&cinode->lock_mutex);
|
||||||
|
|
||||||
exist = cifs_find_lock_conflict(cinode, offset, length, type, netfid,
|
exist = cifs_find_lock_conflict(cinode, lock, &conf_lock);
|
||||||
&conf_lock);
|
|
||||||
if (!exist && cinode->can_cache_brlcks) {
|
if (!exist && cinode->can_cache_brlcks) {
|
||||||
list_add_tail(&lock->llist, &cinode->llist);
|
list_add_tail(&lock->llist, &cinode->llist);
|
||||||
mutex_unlock(&cinode->lock_mutex);
|
mutex_unlock(&cinode->lock_mutex);
|
||||||
|
@ -781,7 +776,6 @@ try_again:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kfree(lock);
|
|
||||||
mutex_unlock(&cinode->lock_mutex);
|
mutex_unlock(&cinode->lock_mutex);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -1254,20 +1248,26 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u8 type,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lock) {
|
if (lock) {
|
||||||
rc = cifs_lock_add_if(cinode, flock->fl_start, length,
|
struct cifsLockInfo *lock;
|
||||||
type, netfid, wait_flag);
|
|
||||||
|
lock = cifs_lock_init(length, flock->fl_start, type, netfid);
|
||||||
|
if (!lock)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
rc = cifs_lock_add_if(cinode, lock, wait_flag);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return rc;
|
kfree(lock);
|
||||||
else if (!rc)
|
if (rc <= 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
|
rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
|
||||||
flock->fl_start, 0, 1, type, wait_flag, 0);
|
flock->fl_start, 0, 1, type, wait_flag, 0);
|
||||||
if (rc == 0) {
|
if (rc) {
|
||||||
/* For Windows locks we must store them. */
|
kfree(lock);
|
||||||
rc = cifs_lock_add(cinode, length, flock->fl_start,
|
goto out;
|
||||||
type, netfid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cifs_lock_add(cinode, lock);
|
||||||
} else if (unlock)
|
} else if (unlock)
|
||||||
rc = cifs_unlock_range(cfile, flock, xid);
|
rc = cifs_unlock_range(cfile, flock, xid);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче