Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Jeff Layton <jlayton@kernel.org>
Link: https://lore.kernel.org/r/20240131-flsplit-v3-44-c6129007ee8d@kernel.org
Reviewed-by: NeilBrown <neilb@suse.de>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Jeff Layton and committed by
Christian Brauner
84e286c1 c8df2cc9

+40 -40
-1
fs/smb/client/cifsglob.h
··· 26 26 #include <uapi/linux/cifs/cifs_mount.h> 27 27 #include "../common/smb2pdu.h" 28 28 #include "smb2pdu.h" 29 - #define _NEED_FILE_LOCK_FIELD_MACROS 30 29 #include <linux/filelock.h> 31 30 32 31 #define SMB_PATH_MAX 260
+4 -5
fs/smb/client/cifssmb.c
··· 15 15 /* want to reuse a stale file handle and only the caller knows the file info */ 16 16 17 17 #include <linux/fs.h> 18 - #define _NEED_FILE_LOCK_FIELD_MACROS 19 18 #include <linux/filelock.h> 20 19 #include <linux/kernel.h> 21 20 #include <linux/vfs.h> ··· 2066 2067 parm_data = (struct cifs_posix_lock *) 2067 2068 ((char *)&pSMBr->hdr.Protocol + data_offset); 2068 2069 if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) 2069 - pLockData->fl_type = F_UNLCK; 2070 + pLockData->c.flc_type = F_UNLCK; 2070 2071 else { 2071 2072 if (parm_data->lock_type == 2072 2073 cpu_to_le16(CIFS_RDLCK)) 2073 - pLockData->fl_type = F_RDLCK; 2074 + pLockData->c.flc_type = F_RDLCK; 2074 2075 else if (parm_data->lock_type == 2075 2076 cpu_to_le16(CIFS_WRLCK)) 2076 - pLockData->fl_type = F_WRLCK; 2077 + pLockData->c.flc_type = F_WRLCK; 2077 2078 2078 2079 pLockData->fl_start = le64_to_cpu(parm_data->start); 2079 2080 pLockData->fl_end = pLockData->fl_start + 2080 2081 (le64_to_cpu(parm_data->length) ? 2081 2082 le64_to_cpu(parm_data->length) - 1 : 0); 2082 - pLockData->fl_pid = -le32_to_cpu(parm_data->pid); 2083 + pLockData->c.flc_pid = -le32_to_cpu(parm_data->pid); 2083 2084 } 2084 2085 } 2085 2086
+35 -32
fs/smb/client/file.c
··· 9 9 * 10 10 */ 11 11 #include <linux/fs.h> 12 - #define _NEED_FILE_LOCK_FIELD_MACROS 13 12 #include <linux/filelock.h> 14 13 #include <linux/backing-dev.h> 15 14 #include <linux/stat.h> ··· 1312 1313 down_read(&cinode->lock_sem); 1313 1314 1314 1315 exist = cifs_find_lock_conflict(cfile, offset, length, type, 1315 - flock->fl_flags, &conf_lock, 1316 + flock->c.flc_flags, &conf_lock, 1316 1317 CIFS_LOCK_OP); 1317 1318 if (exist) { 1318 1319 flock->fl_start = conf_lock->offset; 1319 1320 flock->fl_end = conf_lock->offset + conf_lock->length - 1; 1320 - flock->fl_pid = conf_lock->pid; 1321 + flock->c.flc_pid = conf_lock->pid; 1321 1322 if (conf_lock->type & server->vals->shared_lock_type) 1322 - flock->fl_type = F_RDLCK; 1323 + flock->c.flc_type = F_RDLCK; 1323 1324 else 1324 - flock->fl_type = F_WRLCK; 1325 + flock->c.flc_type = F_WRLCK; 1325 1326 } else if (!cinode->can_cache_brlcks) 1326 1327 rc = 1; 1327 1328 else 1328 - flock->fl_type = F_UNLCK; 1329 + flock->c.flc_type = F_UNLCK; 1329 1330 1330 1331 up_read(&cinode->lock_sem); 1331 1332 return rc; ··· 1401 1402 { 1402 1403 int rc = 0; 1403 1404 struct cifsInodeInfo *cinode = CIFS_I(file_inode(file)); 1404 - unsigned char saved_type = flock->fl_type; 1405 + unsigned char saved_type = flock->c.flc_type; 1405 1406 1406 - if ((flock->fl_flags & FL_POSIX) == 0) 1407 + if ((flock->c.flc_flags & FL_POSIX) == 0) 1407 1408 return 1; 1408 1409 1409 1410 down_read(&cinode->lock_sem); 1410 1411 posix_test_lock(file, flock); 1411 1412 1412 1413 if (lock_is_unlock(flock) && !cinode->can_cache_brlcks) { 1413 - flock->fl_type = saved_type; 1414 + flock->c.flc_type = saved_type; 1414 1415 rc = 1; 1415 1416 } 1416 1417 ··· 1431 1432 struct cifsInodeInfo *cinode = CIFS_I(file_inode(file)); 1432 1433 int rc = FILE_LOCK_DEFERRED + 1; 1433 1434 1434 - if ((flock->fl_flags & FL_POSIX) == 0) 1435 + if ((flock->c.flc_flags & FL_POSIX) == 0) 1435 1436 return rc; 1436 1437 1437 1438 cifs_down_write(&cinode->lock_sem); ··· 1582 1583 el = locks_to_send.next; 1583 1584 spin_lock(&flctx->flc_lock); 1584 1585 for_each_file_lock(flock, &flctx->flc_posix) { 1586 + unsigned char ftype = flock->c.flc_type; 1587 + 1585 1588 if (el == &locks_to_send) { 1586 1589 /* 1587 1590 * The list ended. We don't have enough allocated ··· 1593 1592 break; 1594 1593 } 1595 1594 length = cifs_flock_len(flock); 1596 - if (lock_is_read(flock) || flock->fl_type == F_SHLCK) 1595 + if (ftype == F_RDLCK || ftype == F_SHLCK) 1597 1596 type = CIFS_RDLCK; 1598 1597 else 1599 1598 type = CIFS_WRLCK; 1600 1599 lck = list_entry(el, struct lock_to_push, llist); 1601 - lck->pid = hash_lockowner(flock->fl_owner); 1600 + lck->pid = hash_lockowner(flock->c.flc_owner); 1602 1601 lck->netfid = cfile->fid.netfid; 1603 1602 lck->length = length; 1604 1603 lck->type = type; ··· 1665 1664 cifs_read_flock(struct file_lock *flock, __u32 *type, int *lock, int *unlock, 1666 1665 bool *wait_flag, struct TCP_Server_Info *server) 1667 1666 { 1668 - if (flock->fl_flags & FL_POSIX) 1667 + if (flock->c.flc_flags & FL_POSIX) 1669 1668 cifs_dbg(FYI, "Posix\n"); 1670 - if (flock->fl_flags & FL_FLOCK) 1669 + if (flock->c.flc_flags & FL_FLOCK) 1671 1670 cifs_dbg(FYI, "Flock\n"); 1672 - if (flock->fl_flags & FL_SLEEP) { 1671 + if (flock->c.flc_flags & FL_SLEEP) { 1673 1672 cifs_dbg(FYI, "Blocking lock\n"); 1674 1673 *wait_flag = true; 1675 1674 } 1676 - if (flock->fl_flags & FL_ACCESS) 1675 + if (flock->c.flc_flags & FL_ACCESS) 1677 1676 cifs_dbg(FYI, "Process suspended by mandatory locking - not implemented yet\n"); 1678 - if (flock->fl_flags & FL_LEASE) 1677 + if (flock->c.flc_flags & FL_LEASE) 1679 1678 cifs_dbg(FYI, "Lease on file - not implemented yet\n"); 1680 - if (flock->fl_flags & 1679 + if (flock->c.flc_flags & 1681 1680 (~(FL_POSIX | FL_FLOCK | FL_SLEEP | 1682 1681 FL_ACCESS | FL_LEASE | FL_CLOSE | FL_OFDLCK))) 1683 - cifs_dbg(FYI, "Unknown lock flags 0x%x\n", flock->fl_flags); 1682 + cifs_dbg(FYI, "Unknown lock flags 0x%x\n", 1683 + flock->c.flc_flags); 1684 1684 1685 1685 *type = server->vals->large_lock_type; 1686 1686 if (lock_is_write(flock)) { ··· 1697 1695 cifs_dbg(FYI, "F_RDLCK\n"); 1698 1696 *type |= server->vals->shared_lock_type; 1699 1697 *lock = 1; 1700 - } else if (flock->fl_type == F_EXLCK) { 1698 + } else if (flock->c.flc_type == F_EXLCK) { 1701 1699 cifs_dbg(FYI, "F_EXLCK\n"); 1702 1700 *type |= server->vals->exclusive_lock_type; 1703 1701 *lock = 1; 1704 - } else if (flock->fl_type == F_SHLCK) { 1702 + } else if (flock->c.flc_type == F_SHLCK) { 1705 1703 cifs_dbg(FYI, "F_SHLCK\n"); 1706 1704 *type |= server->vals->shared_lock_type; 1707 1705 *lock = 1; ··· 1733 1731 else 1734 1732 posix_lock_type = CIFS_WRLCK; 1735 1733 rc = CIFSSMBPosixLock(xid, tcon, netfid, 1736 - hash_lockowner(flock->fl_owner), 1734 + hash_lockowner(flock->c.flc_owner), 1737 1735 flock->fl_start, length, flock, 1738 1736 posix_lock_type, wait_flag); 1739 1737 return rc; ··· 1750 1748 if (rc == 0) { 1751 1749 rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, 1752 1750 type, 0, 1, false); 1753 - flock->fl_type = F_UNLCK; 1751 + flock->c.flc_type = F_UNLCK; 1754 1752 if (rc != 0) 1755 1753 cifs_dbg(VFS, "Error unlocking previously locked range %d during test of lock\n", 1756 1754 rc); ··· 1758 1756 } 1759 1757 1760 1758 if (type & server->vals->shared_lock_type) { 1761 - flock->fl_type = F_WRLCK; 1759 + flock->c.flc_type = F_WRLCK; 1762 1760 return 0; 1763 1761 } 1764 1762 ··· 1770 1768 if (rc == 0) { 1771 1769 rc = server->ops->mand_lock(xid, cfile, flock->fl_start, length, 1772 1770 type | server->vals->shared_lock_type, 0, 1, false); 1773 - flock->fl_type = F_RDLCK; 1771 + flock->c.flc_type = F_RDLCK; 1774 1772 if (rc != 0) 1775 1773 cifs_dbg(VFS, "Error unlocking previously locked range %d during test of lock\n", 1776 1774 rc); 1777 1775 } else 1778 - flock->fl_type = F_WRLCK; 1776 + flock->c.flc_type = F_WRLCK; 1779 1777 1780 1778 return 0; 1781 1779 } ··· 1943 1941 posix_lock_type = CIFS_UNLCK; 1944 1942 1945 1943 rc = CIFSSMBPosixLock(xid, tcon, cfile->fid.netfid, 1946 - hash_lockowner(flock->fl_owner), 1944 + hash_lockowner(flock->c.flc_owner), 1947 1945 flock->fl_start, length, 1948 1946 NULL, posix_lock_type, wait_flag); 1949 1947 goto out; ··· 1953 1951 struct cifsLockInfo *lock; 1954 1952 1955 1953 lock = cifs_lock_init(flock->fl_start, length, type, 1956 - flock->fl_flags); 1954 + flock->c.flc_flags); 1957 1955 if (!lock) 1958 1956 return -ENOMEM; 1959 1957 ··· 1992 1990 rc = server->ops->mand_unlock_range(cfile, flock, xid); 1993 1991 1994 1992 out: 1995 - if ((flock->fl_flags & FL_POSIX) || (flock->fl_flags & FL_FLOCK)) { 1993 + if ((flock->c.flc_flags & FL_POSIX) || (flock->c.flc_flags & FL_FLOCK)) { 1996 1994 /* 1997 1995 * If this is a request to remove all locks because we 1998 1996 * are closing the file, it doesn't matter if the ··· 2001 1999 */ 2002 2000 if (rc) { 2003 2001 cifs_dbg(VFS, "%s failed rc=%d\n", __func__, rc); 2004 - if (!(flock->fl_flags & FL_CLOSE)) 2002 + if (!(flock->c.flc_flags & FL_CLOSE)) 2005 2003 return rc; 2006 2004 } 2007 2005 rc = locks_lock_file_wait(file, flock); ··· 2022 2020 2023 2021 xid = get_xid(); 2024 2022 2025 - if (!(fl->fl_flags & FL_FLOCK)) { 2023 + if (!(fl->c.flc_flags & FL_FLOCK)) { 2026 2024 rc = -ENOLCK; 2027 2025 free_xid(xid); 2028 2026 return rc; ··· 2073 2071 xid = get_xid(); 2074 2072 2075 2073 cifs_dbg(FYI, "%s: %pD2 cmd=0x%x type=0x%x flags=0x%x r=%lld:%lld\n", __func__, file, cmd, 2076 - flock->fl_flags, flock->fl_type, (long long)flock->fl_start, 2074 + flock->c.flc_flags, flock->c.flc_type, 2075 + (long long)flock->fl_start, 2077 2076 (long long)flock->fl_end); 2078 2077 2079 2078 cfile = (struct cifsFileInfo *)file->private_data;
+1 -2
fs/smb/client/smb2file.c
··· 7 7 * 8 8 */ 9 9 #include <linux/fs.h> 10 - #define _NEED_FILE_LOCK_FIELD_MACROS 11 10 #include <linux/filelock.h> 12 11 #include <linux/stat.h> 13 12 #include <linux/slab.h> ··· 228 229 * flock and OFD lock are associated with an open 229 230 * file description, not the process. 230 231 */ 231 - if (!(flock->fl_flags & (FL_FLOCK | FL_OFDLCK))) 232 + if (!(flock->c.flc_flags & (FL_FLOCK | FL_OFDLCK))) 232 233 continue; 233 234 if (cinode->can_cache_brlcks) { 234 235 /*