Commit 84e286c1 authored by Jeff Layton's avatar Jeff Layton Committed by Christian Brauner

smb/client: adapt to breakup of struct file_lock

Most of the existing APIs have remained the same, but subsystems that
access file_lock fields directly need to reach into struct
file_lock_core now.
Signed-off-by: default avatarJeff Layton <jlayton@kernel.org>
Link: https://lore.kernel.org/r/20240131-flsplit-v3-44-c6129007ee8d@kernel.orgReviewed-by: default avatarNeilBrown <neilb@suse.de>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent c8df2cc9
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <uapi/linux/cifs/cifs_mount.h> #include <uapi/linux/cifs/cifs_mount.h>
#include "../common/smb2pdu.h" #include "../common/smb2pdu.h"
#include "smb2pdu.h" #include "smb2pdu.h"
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#define SMB_PATH_MAX 260 #define SMB_PATH_MAX 260
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
/* want to reuse a stale file handle and only the caller knows the file info */ /* want to reuse a stale file handle and only the caller knows the file info */
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/vfs.h> #include <linux/vfs.h>
...@@ -2067,20 +2066,20 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon, ...@@ -2067,20 +2066,20 @@ CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon,
parm_data = (struct cifs_posix_lock *) parm_data = (struct cifs_posix_lock *)
((char *)&pSMBr->hdr.Protocol + data_offset); ((char *)&pSMBr->hdr.Protocol + data_offset);
if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK))
pLockData->fl_type = F_UNLCK; pLockData->c.flc_type = F_UNLCK;
else { else {
if (parm_data->lock_type == if (parm_data->lock_type ==
cpu_to_le16(CIFS_RDLCK)) cpu_to_le16(CIFS_RDLCK))
pLockData->fl_type = F_RDLCK; pLockData->c.flc_type = F_RDLCK;
else if (parm_data->lock_type == else if (parm_data->lock_type ==
cpu_to_le16(CIFS_WRLCK)) cpu_to_le16(CIFS_WRLCK))
pLockData->fl_type = F_WRLCK; pLockData->c.flc_type = F_WRLCK;
pLockData->fl_start = le64_to_cpu(parm_data->start); pLockData->fl_start = le64_to_cpu(parm_data->start);
pLockData->fl_end = pLockData->fl_start + pLockData->fl_end = pLockData->fl_start +
(le64_to_cpu(parm_data->length) ? (le64_to_cpu(parm_data->length) ?
le64_to_cpu(parm_data->length) - 1 : 0); le64_to_cpu(parm_data->length) - 1 : 0);
pLockData->fl_pid = -le32_to_cpu(parm_data->pid); pLockData->c.flc_pid = -le32_to_cpu(parm_data->pid);
} }
} }
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
* *
*/ */
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/backing-dev.h> #include <linux/backing-dev.h>
#include <linux/stat.h> #include <linux/stat.h>
...@@ -1313,20 +1312,20 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length, ...@@ -1313,20 +1312,20 @@ cifs_lock_test(struct cifsFileInfo *cfile, __u64 offset, __u64 length,
down_read(&cinode->lock_sem); down_read(&cinode->lock_sem);
exist = cifs_find_lock_conflict(cfile, offset, length, type, exist = cifs_find_lock_conflict(cfile, offset, length, type,
flock->fl_flags, &conf_lock, flock->c.flc_flags, &conf_lock,
CIFS_LOCK_OP); CIFS_LOCK_OP);
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;
flock->fl_pid = conf_lock->pid; flock->c.flc_pid = conf_lock->pid;
if (conf_lock->type & server->vals->shared_lock_type) if (conf_lock->type & server->vals->shared_lock_type)
flock->fl_type = F_RDLCK; flock->c.flc_type = F_RDLCK;
else else
flock->fl_type = F_WRLCK; flock->c.flc_type = F_WRLCK;
} else if (!cinode->can_cache_brlcks) } else if (!cinode->can_cache_brlcks)
rc = 1; rc = 1;
else else
flock->fl_type = F_UNLCK; flock->c.flc_type = F_UNLCK;
up_read(&cinode->lock_sem); up_read(&cinode->lock_sem);
return rc; return rc;
...@@ -1402,16 +1401,16 @@ cifs_posix_lock_test(struct file *file, struct file_lock *flock) ...@@ -1402,16 +1401,16 @@ cifs_posix_lock_test(struct file *file, struct file_lock *flock)
{ {
int rc = 0; int rc = 0;
struct cifsInodeInfo *cinode = CIFS_I(file_inode(file)); struct cifsInodeInfo *cinode = CIFS_I(file_inode(file));
unsigned char saved_type = flock->fl_type; unsigned char saved_type = flock->c.flc_type;
if ((flock->fl_flags & FL_POSIX) == 0) if ((flock->c.flc_flags & FL_POSIX) == 0)
return 1; return 1;
down_read(&cinode->lock_sem); down_read(&cinode->lock_sem);
posix_test_lock(file, flock); posix_test_lock(file, flock);
if (lock_is_unlock(flock) && !cinode->can_cache_brlcks) { if (lock_is_unlock(flock) && !cinode->can_cache_brlcks) {
flock->fl_type = saved_type; flock->c.flc_type = saved_type;
rc = 1; rc = 1;
} }
...@@ -1432,7 +1431,7 @@ cifs_posix_lock_set(struct file *file, struct file_lock *flock) ...@@ -1432,7 +1431,7 @@ cifs_posix_lock_set(struct file *file, struct file_lock *flock)
struct cifsInodeInfo *cinode = CIFS_I(file_inode(file)); struct cifsInodeInfo *cinode = CIFS_I(file_inode(file));
int rc = FILE_LOCK_DEFERRED + 1; int rc = FILE_LOCK_DEFERRED + 1;
if ((flock->fl_flags & FL_POSIX) == 0) if ((flock->c.flc_flags & FL_POSIX) == 0)
return rc; return rc;
cifs_down_write(&cinode->lock_sem); cifs_down_write(&cinode->lock_sem);
...@@ -1583,6 +1582,8 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) ...@@ -1583,6 +1582,8 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
el = locks_to_send.next; el = locks_to_send.next;
spin_lock(&flctx->flc_lock); spin_lock(&flctx->flc_lock);
for_each_file_lock(flock, &flctx->flc_posix) { for_each_file_lock(flock, &flctx->flc_posix) {
unsigned char ftype = flock->c.flc_type;
if (el == &locks_to_send) { if (el == &locks_to_send) {
/* /*
* The list ended. We don't have enough allocated * The list ended. We don't have enough allocated
...@@ -1592,12 +1593,12 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) ...@@ -1592,12 +1593,12 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
break; break;
} }
length = cifs_flock_len(flock); length = cifs_flock_len(flock);
if (lock_is_read(flock) || flock->fl_type == F_SHLCK) if (ftype == F_RDLCK || ftype == F_SHLCK)
type = CIFS_RDLCK; type = CIFS_RDLCK;
else else
type = CIFS_WRLCK; type = CIFS_WRLCK;
lck = list_entry(el, struct lock_to_push, llist); lck = list_entry(el, struct lock_to_push, llist);
lck->pid = hash_lockowner(flock->fl_owner); lck->pid = hash_lockowner(flock->c.flc_owner);
lck->netfid = cfile->fid.netfid; lck->netfid = cfile->fid.netfid;
lck->length = length; lck->length = length;
lck->type = type; lck->type = type;
...@@ -1664,22 +1665,23 @@ static void ...@@ -1664,22 +1665,23 @@ static void
cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock, cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock,
bool *wait_flag, struct TCP_Server_Info *server) bool *wait_flag, struct TCP_Server_Info *server)
{ {
if (flock->fl_flags & FL_POSIX) if (flock->c.flc_flags & FL_POSIX)
cifs_dbg(FYI, "Posix\n"); cifs_dbg(FYI, "Posix\n");
if (flock->fl_flags & FL_FLOCK) if (flock->c.flc_flags & FL_FLOCK)
cifs_dbg(FYI, "Flock\n"); cifs_dbg(FYI, "Flock\n");
if (flock->fl_flags & FL_SLEEP) { if (flock->c.flc_flags & FL_SLEEP) {
cifs_dbg(FYI, "Blocking lock\n"); cifs_dbg(FYI, "Blocking lock\n");
*wait_flag = true; *wait_flag = true;
} }
if (flock->fl_flags & FL_ACCESS) if (flock->c.flc_flags & FL_ACCESS)
cifs_dbg(FYI, "Process suspended by mandatory locking - not implemented yet\n"); cifs_dbg(FYI, "Process suspended by mandatory locking - not implemented yet\n");
if (flock->fl_flags & FL_LEASE) if (flock->c.flc_flags & FL_LEASE)
cifs_dbg(FYI, "Lease on file - not implemented yet\n"); cifs_dbg(FYI, "Lease on file - not implemented yet\n");
if (flock->fl_flags & if (flock->c.flc_flags &
(~(FL_POSIX | FL_FLOCK | FL_SLEEP | (~(FL_POSIX | FL_FLOCK | FL_SLEEP |
FL_ACCESS | FL_LEASE | FL_CLOSE | FL_OFDLCK))) FL_ACCESS | FL_LEASE | FL_CLOSE | FL_OFDLCK)))
cifs_dbg(FYI, "Unknown lock flags 0x%x\n", flock->fl_flags); cifs_dbg(FYI, "Unknown lock flags 0x%x\n",
flock->c.flc_flags);
*type = server->vals->large_lock_type; *type = server->vals->large_lock_type;
if (lock_is_write(flock)) { if (lock_is_write(flock)) {
...@@ -1695,11 +1697,11 @@ cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock, ...@@ -1695,11 +1697,11 @@ cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock,
cifs_dbg(FYI, "F_RDLCK\n"); cifs_dbg(FYI, "F_RDLCK\n");
*type |= server->vals->shared_lock_type; *type |= server->vals->shared_lock_type;
*lock = 1; *lock = 1;
} else if (flock->fl_type == F_EXLCK) { } else if (flock->c.flc_type == F_EXLCK) {
cifs_dbg(FYI, "F_EXLCK\n"); cifs_dbg(FYI, "F_EXLCK\n");
*type |= server->vals->exclusive_lock_type; *type |= server->vals->exclusive_lock_type;
*lock = 1; *lock = 1;
} else if (flock->fl_type == F_SHLCK) { } else if (flock->c.flc_type == F_SHLCK) {
cifs_dbg(FYI, "F_SHLCK\n"); cifs_dbg(FYI, "F_SHLCK\n");
*type |= server->vals->shared_lock_type; *type |= server->vals->shared_lock_type;
*lock = 1; *lock = 1;
...@@ -1731,7 +1733,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1731,7 +1733,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
else else
posix_lock_type = CIFS_WRLCK; posix_lock_type = CIFS_WRLCK;
rc = CIFSSMBPosixLock(xid, tcon, netfid, rc = CIFSSMBPosixLock(xid, tcon, netfid,
hash_lockowner(flock->fl_owner), hash_lockowner(flock->c.flc_owner),
flock->fl_start, length, flock, flock->fl_start, length, flock,
posix_lock_type, wait_flag); posix_lock_type, wait_flag);
return rc; return rc;
...@@ -1748,7 +1750,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1748,7 +1750,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
if (rc == 0) { if (rc == 0) {
rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length,
type, 0, 1, false); type, 0, 1, false);
flock->fl_type = F_UNLCK; flock->c.flc_type = F_UNLCK;
if (rc != 0) if (rc != 0)
cifs_dbg(VFS, "Error unlocking previously locked range %d during test of lock\n", cifs_dbg(VFS, "Error unlocking previously locked range %d during test of lock\n",
rc); rc);
...@@ -1756,7 +1758,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1756,7 +1758,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
} }
if (type & server->vals->shared_lock_type) { if (type & server->vals->shared_lock_type) {
flock->fl_type = F_WRLCK; flock->c.flc_type = F_WRLCK;
return 0; return 0;
} }
...@@ -1768,12 +1770,12 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1768,12 +1770,12 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u32 type,
if (rc == 0) { if (rc == 0) {
rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length,
type | server->vals->shared_lock_type, 0, 1, false); type | server->vals->shared_lock_type, 0, 1, false);
flock->fl_type = F_RDLCK; flock->c.flc_type = F_RDLCK;
if (rc != 0) if (rc != 0)
cifs_dbg(VFS, "Error unlocking previously locked range %d during test of lock\n", cifs_dbg(VFS, "Error unlocking previously locked range %d during test of lock\n",
rc); rc);
} else } else
flock->fl_type = F_WRLCK; flock->c.flc_type = F_WRLCK;
return 0; return 0;
} }
...@@ -1941,7 +1943,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1941,7 +1943,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
posix_lock_type = CIFS_UNLCK; posix_lock_type = CIFS_UNLCK;
rc = CIFSSMBPosixLock(xid, tcon, cfile->fid.netfid, rc = CIFSSMBPosixLock(xid, tcon, cfile->fid.netfid,
hash_lockowner(flock->fl_owner), hash_lockowner(flock->c.flc_owner),
flock->fl_start, length, flock->fl_start, length,
NULL, posix_lock_type, wait_flag); NULL, posix_lock_type, wait_flag);
goto out; goto out;
...@@ -1951,7 +1953,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1951,7 +1953,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
struct cifsLockInfo *lock; struct cifsLockInfo *lock;
lock = cifs_lock_init(flock->fl_start, length, type, lock = cifs_lock_init(flock->fl_start, length, type,
flock->fl_flags); flock->c.flc_flags);
if (!lock) if (!lock)
return -ENOMEM; return -ENOMEM;
...@@ -1990,7 +1992,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1990,7 +1992,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
rc = server->ops->mand_unlock_range(cfile, flock, xid); rc = server->ops->mand_unlock_range(cfile, flock, xid);
out: out:
if ((flock->fl_flags & FL_POSIX) || (flock->fl_flags & FL_FLOCK)) { if ((flock->c.flc_flags & FL_POSIX) || (flock->c.flc_flags & FL_FLOCK)) {
/* /*
* If this is a request to remove all locks because we * If this is a request to remove all locks because we
* are closing the file, it doesn't matter if the * are closing the file, it doesn't matter if the
...@@ -1999,7 +2001,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type, ...@@ -1999,7 +2001,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
*/ */
if (rc) { if (rc) {
cifs_dbg(VFS, "%s failed rc=%d\n", __func__, rc); cifs_dbg(VFS, "%s failed rc=%d\n", __func__, rc);
if (!(flock->fl_flags & FL_CLOSE)) if (!(flock->c.flc_flags & FL_CLOSE))
return rc; return rc;
} }
rc = locks_lock_file_wait(file, flock); rc = locks_lock_file_wait(file, flock);
...@@ -2020,7 +2022,7 @@ int cifs_flock(struct file *file, int cmd, struct file_lock *fl) ...@@ -2020,7 +2022,7 @@ int cifs_flock(struct file *file, int cmd, struct file_lock *fl)
xid = get_xid(); xid = get_xid();
if (!(fl->fl_flags & FL_FLOCK)) { if (!(fl->c.flc_flags & FL_FLOCK)) {
rc = -ENOLCK; rc = -ENOLCK;
free_xid(xid); free_xid(xid);
return rc; return rc;
...@@ -2071,7 +2073,8 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock) ...@@ -2071,7 +2073,8 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock)
xid = get_xid(); xid = get_xid();
cifs_dbg(FYI, "%s: %pD2 cmd=0x%x type=0x%x flags=0x%x r=%lld:%lld\n", __func__, file, cmd, cifs_dbg(FYI, "%s: %pD2 cmd=0x%x type=0x%x flags=0x%x r=%lld:%lld\n", __func__, file, cmd,
flock->fl_flags, flock->fl_type, (long long)flock->fl_start, flock->c.flc_flags, flock->c.flc_type,
(long long)flock->fl_start,
(long long)flock->fl_end); (long long)flock->fl_end);
cfile = (struct cifsFileInfo *)file->private_data; cfile = (struct cifsFileInfo *)file->private_data;
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
* *
*/ */
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -229,7 +228,7 @@ smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock, ...@@ -229,7 +228,7 @@ smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
* flock and OFD lock are associated with an open * flock and OFD lock are associated with an open
* file description, not the process. * file description, not the process.
*/ */
if (!(flock->fl_flags & (FL_FLOCK | FL_OFDLCK))) if (!(flock->c.flc_flags & (FL_FLOCK | FL_OFDLCK)))
continue; continue;
if (cinode->can_cache_brlcks) { if (cinode->can_cache_brlcks) {
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment