summaryrefslogtreecommitdiff
path: root/fs/smb/client/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/smb/client/file.c')
-rw-r--r--fs/smb/client/file.c99
1 files changed, 33 insertions, 66 deletions
diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index 23e75de833bc..0e50634d77e6 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -1352,25 +1352,21 @@ cifs_find_fid_lock_conflict(struct cifs_fid_locks *fdlocks, __u64 offset,
{
struct cifsLockInfo *li;
struct cifsFileInfo *cur_cfile = fdlocks->cfile;
- struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
list_for_each_entry(li, &fdlocks->locks, llist) {
- if (offset + length <= li->offset ||
- offset >= li->offset + li->length)
+ if (offset + length <= li->offset || offset >= li->offset + li->length)
continue;
if (rw_check != CIFS_LOCK_OP && current->tgid == li->pid &&
smb2_compare_fids(cfile, cur_cfile)) {
/* shared lock prevents write op through the same fid */
- if (!(li->type & server->vals->shared_lock_type) ||
- rw_check != CIFS_WRITE_OP)
+ if (!(li->type & SMB2_LOCKFLAG_SHARED) || rw_check != CIFS_WRITE_OP)
continue;
}
- if ((type & server->vals->shared_lock_type) &&
- ((smb2_compare_fids(cfile, cur_cfile) &&
+ if ((type & SMB2_LOCKFLAG_SHARED) && ((smb2_compare_fids(cfile, cur_cfile) &&
current->tgid == li->pid) || type == li->type))
continue;
- if (rw_check == CIFS_LOCK_OP &&
- (flags & FL_OFDLCK) && (li->flags & FL_OFDLCK) &&
+
+ if (rw_check == CIFS_LOCK_OP && (flags & FL_OFDLCK) && (li->flags & FL_OFDLCK) &&
smb2_compare_fids(cfile, cur_cfile))
continue;
if (conf_lock)
@@ -1414,7 +1410,6 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
int rc = 0;
struct cifsLockInfo *conf_lock;
struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
- struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
bool exist;
down_read(&cinode->lock_sem);
@@ -1426,7 +1421,7 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
flock->fl_start = conf_lock->offset;
flock->fl_end = conf_lock->offset + conf_lock->length - 1;
flock->c.flc_pid = conf_lock->pid;
- if (conf_lock->type & server->vals->shared_lock_type)
+ if (conf_lock->type & SMB2_LOCKFLAG_SHARED)
flock->c.flc_type = F_RDLCK;
else
flock->c.flc_type = F_WRLCK;
@@ -1549,27 +1544,27 @@ cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock,
cifs_dbg(FYI, "Unknown lock flags 0x%x\n",
flock->c.flc_flags);
- *type = server->vals->large_lock_type;
+ *type = 0;
if (lock_is_write(flock)) {
cifs_dbg(FYI, "F_WRLCK\n");
- *type |= server->vals->exclusive_lock_type;
+ *type |= SMB2_LOCKFLAG_EXCLUSIVE;
*lock = 1;
} else if (lock_is_unlock(flock)) {
cifs_dbg(FYI, "F_UNLCK\n");
- *type |= server->vals->unlock_lock_type;
+ *type |= SMB2_LOCKFLAG_UNLOCK;
*unlock = 1;
/* Check if unlock includes more than one lock range */
} else if (lock_is_read(flock)) {
cifs_dbg(FYI, "F_RDLCK\n");
- *type |= server->vals->shared_lock_type;
+ *type |= SMB2_LOCKFLAG_SHARED;
*lock = 1;
} else if (flock->c.flc_type == F_EXLCK) {
cifs_dbg(FYI, "F_EXLCK\n");
- *type |= server->vals->exclusive_lock_type;
+ *type |= SMB2_LOCKFLAG_EXCLUSIVE;
*lock = 1;
} else if (flock->c.flc_type == F_SHLCK) {
cifs_dbg(FYI, "F_SHLCK\n");
- *type |= server->vals->shared_lock_type;
+ *type |= SMB2_LOCKFLAG_SHARED;
*lock = 1;
} else
cifs_dbg(FYI, "Unknown type of lock\n");
@@ -1582,8 +1577,6 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
int rc = 0;
__u64 length = cifs_flock_len(flock);
struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
- struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
- struct TCP_Server_Info *server = tcon->ses->server;
rc = cifs_lock_test(cfile, flock->fl_start, length, type, flock);
if (!rc)
@@ -1602,19 +1595,18 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
return 0;
}
- if (type & server->vals->shared_lock_type) {
+ if (type & SMB2_LOCKFLAG_SHARED) {
flock->c.flc_type = F_WRLCK;
return 0;
}
- type &= ~server->vals->exclusive_lock_type;
+ type &= ~SMB2_LOCKFLAG_EXCLUSIVE;
- rc = smb2_mand_lock(xid, cfile, flock->fl_start, length,
- type | server->vals->shared_lock_type,
- 1, 0, false);
+ rc = smb2_mand_lock(xid, cfile, flock->fl_start, length, type | SMB2_LOCKFLAG_SHARED,
+ 1, 0, false);
if (rc == 0) {
rc = smb2_mand_lock(xid, cfile, flock->fl_start, length,
- type | server->vals->shared_lock_type, 0, 1, false);
+ type | SMB2_LOCKFLAG_SHARED, 0, 1, false);
flock->c.flc_type = F_RDLCK;
if (rc != 0)
cifs_dbg(VFS, "Error unlocking previously locked range %d during test of lock\n",
@@ -1720,7 +1712,6 @@ int cifs_flock(struct file *file, int cmd, struct file_lock *fl)
int rc, xid;
int lock = 0, unlock = 0;
bool wait_flag = false;
- bool posix_lck = false;
struct cifs_sb_info *cifs_sb;
struct cifs_tcon *tcon;
struct cifsFileInfo *cfile;
@@ -1741,11 +1732,6 @@ int cifs_flock(struct file *file, int cmd, struct file_lock *fl)
tcon->ses->server);
cifs_sb = CIFS_FILE_SB(file);
- if (cap_unix(tcon->ses) &&
- (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
- ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
- posix_lck = true;
-
if (!lock && !unlock) {
/*
* if no lock or unlock then nothing to do since we do not
@@ -1756,8 +1742,8 @@ int cifs_flock(struct file *file, int cmd, struct file_lock *fl)
return rc;
}
- rc = cifs_setlk(file, fl, type, wait_flag, posix_lck, lock, unlock,
- xid);
+ rc = cifs_setlk(file, fl, type, wait_flag, false /* XXX: remove this? (was posix_lck) */,
+ lock, unlock, xid);
free_xid(xid);
return rc;
@@ -1769,7 +1755,6 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock)
int rc, xid;
int lock = 0, unlock = 0;
bool wait_flag = false;
- bool posix_lck = false;
struct cifs_sb_info *cifs_sb;
struct cifs_tcon *tcon;
struct cifsFileInfo *cfile;
@@ -1790,17 +1775,14 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock)
tcon->ses->server);
cifs_sb = CIFS_FILE_SB(file);
set_bit(CIFS_INO_CLOSE_ON_LOCK, &CIFS_I(d_inode(cfile->dentry))->flags);
-
- if (cap_unix(tcon->ses) &&
- (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
- ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0))
- posix_lck = true;
/*
* BB add code here to normalize offset and length to account for
* negative length which we can not accept over the wire.
*/
if (IS_GETLK(cmd)) {
- rc = cifs_getlk(file, flock, type, wait_flag, posix_lck, xid);
+ rc = cifs_getlk(file, flock, type, wait_flag,
+ false /* XXX: remove this? (was posix_lck) */,
+ xid);
free_xid(xid);
return rc;
}
@@ -1814,8 +1796,9 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock)
return -EOPNOTSUPP;
}
- rc = cifs_setlk(file, flock, type, wait_flag, posix_lck, lock, unlock,
- xid);
+ rc = cifs_setlk(file, flock, type, wait_flag,
+ false /* XXX: remove this? (was posix_lck) */,
+ lock, unlock, xid);
free_xid(xid);
return rc;
}
@@ -2168,7 +2151,6 @@ cifs_writev(struct kiocb *iocb, struct iov_iter *from)
struct cifsFileInfo *cfile = (struct cifsFileInfo *)file->private_data;
struct inode *inode = file->f_mapping->host;
struct cifsInodeInfo *cinode = CIFS_I(inode);
- struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server;
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
ssize_t rc;
@@ -2188,8 +2170,7 @@ cifs_writev(struct kiocb *iocb, struct iov_iter *from)
if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) &&
(cifs_find_lock_conflict(cfile, iocb->ki_pos, iov_iter_count(from),
- server->vals->exclusive_lock_type, 0,
- NULL, CIFS_WRITE_OP))) {
+ SMB2_LOCKFLAG_EXCLUSIVE, 0, NULL, CIFS_WRITE_OP))) {
rc = -EACCES;
goto out;
}
@@ -2209,10 +2190,6 @@ cifs_strict_writev(struct kiocb *iocb, struct iov_iter *from)
{
struct inode *inode = file_inode(iocb->ki_filp);
struct cifsInodeInfo *cinode = CIFS_I(inode);
- struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
- struct cifsFileInfo *cfile = (struct cifsFileInfo *)
- iocb->ki_filp->private_data;
- struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
ssize_t written;
written = cifs_get_writer(cinode);
@@ -2220,12 +2197,6 @@ cifs_strict_writev(struct kiocb *iocb, struct iov_iter *from)
return written;
if (CIFS_CACHE_WRITE(cinode)) {
- if (cap_unix(tcon->ses) &&
- (CIFS_UNIX_FCNTL_CAP & le64_to_cpu(tcon->fsUnixInfo.Capability)) &&
- ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL) == 0)) {
- written = netfs_file_write_iter(iocb, from);
- goto out;
- }
written = cifs_writev(iocb, from);
goto out;
}
@@ -2311,9 +2282,7 @@ cifs_strict_readv(struct kiocb *iocb, struct iov_iter *to)
struct inode *inode = file_inode(iocb->ki_filp);
struct cifsInodeInfo *cinode = CIFS_I(inode);
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
- struct cifsFileInfo *cfile = (struct cifsFileInfo *)
- iocb->ki_filp->private_data;
- struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
+ struct cifsFileInfo *cfile = (struct cifsFileInfo *)iocb->ki_filp->private_data;
int rc = -EACCES;
/*
@@ -2343,11 +2312,10 @@ cifs_strict_readv(struct kiocb *iocb, struct iov_iter *to)
goto out;
rc = -EACCES;
down_read(&cinode->lock_sem);
- if (!cifs_find_lock_conflict(
- cfile, iocb->ki_pos, iov_iter_count(to),
- tcon->ses->server->vals->shared_lock_type,
- 0, NULL, CIFS_READ_OP))
+ if (!cifs_find_lock_conflict(cfile, iocb->ki_pos, iov_iter_count(to),
+ SMB2_LOCKFLAG_SHARED, 0, NULL, CIFS_READ_OP))
rc = netfs_unbuffered_read_iter_locked(iocb, to);
+
up_read(&cinode->lock_sem);
netfs_end_io_direct(inode);
} else {
@@ -2356,11 +2324,10 @@ cifs_strict_readv(struct kiocb *iocb, struct iov_iter *to)
goto out;
rc = -EACCES;
down_read(&cinode->lock_sem);
- if (!cifs_find_lock_conflict(
- cfile, iocb->ki_pos, iov_iter_count(to),
- tcon->ses->server->vals->shared_lock_type,
- 0, NULL, CIFS_READ_OP))
+ if (!cifs_find_lock_conflict(cfile, iocb->ki_pos, iov_iter_count(to),
+ SMB2_LOCKFLAG_SHARED, 0, NULL, CIFS_READ_OP))
rc = filemap_read(iocb, to, 0);
+
up_read(&cinode->lock_sem);
netfs_end_io_read(inode);
}