Skip to content

Commit d4ffff1

Browse files
piastrySteve French
authored andcommitted
CIFS: Add rwpidforward mount option
Add rwpidforward mount option that switches on a mode when we forward pid of a process who opened a file to any read and write operation. This can prevent applications like WINE from failing on read or write operation on a previously locked file region from the same netfd from another process if we use mandatory brlock style. It is actual for WINE because during a run of WINE program two processes work on the same netfd - share the same file struct between several VFS fds: 1) WINE-server does open and lock; 2) WINE-application does read and write. Signed-off-by: Pavel Shilovsky <piastry@etersoft.ru> Signed-off-by: Steve French <sfrench@us.ibm.com>
1 parent 25c7f41 commit d4ffff1

10 files changed

Lines changed: 115 additions & 39 deletions

File tree

‎fs/cifs/README‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ A partial list of the supported mount options follows:
457457
otherwise - read from the server. All written data are stored
458458
in the cache, but if the client doesn't have Exclusive Oplock,
459459
it writes the data to the server.
460+
rwpidforward Forward pid of a process who opened a file to any read or write
461+
operation on that file. This prevent applications like WINE
462+
from failing on read and write if we use mandatory brlock style.
460463
acl Allow setfacl and getfacl to manage posix ACLs if server
461464
supports them. (default)
462465
noacl Do not allow setfacl and getfacl calls on this mount

‎fs/cifs/cifs_fs_sb.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#define CIFS_MOUNT_MF_SYMLINKS 0x10000 /* Minshall+French Symlinks enabled */
4242
#define CIFS_MOUNT_MULTIUSER 0x20000 /* multiuser mount */
4343
#define CIFS_MOUNT_STRICT_IO 0x40000 /* strict cache mode */
44+
#define CIFS_MOUNT_RWPIDFORWARD 0x80000 /* use pid forwarding for rw */
4445

4546
struct cifs_sb_info {
4647
struct rb_root tlink_tree;

‎fs/cifs/cifsfs.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,20 @@ cifs_show_options(struct seq_file *s, struct vfsmount *m)
415415
seq_printf(s, ",nocase");
416416
if (tcon->retry)
417417
seq_printf(s, ",hard");
418+
if (tcon->unix_ext)
419+
seq_printf(s, ",unix");
420+
else
421+
seq_printf(s, ",nounix");
418422
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
419423
seq_printf(s, ",posixpaths");
420424
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID)
421425
seq_printf(s, ",setuids");
422426
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
423427
seq_printf(s, ",serverino");
428+
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
429+
seq_printf(s, ",rwpidforward");
430+
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOPOSIXBRL)
431+
seq_printf(s, ",forcemand");
424432
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO)
425433
seq_printf(s, ",directio");
426434
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)

‎fs/cifs/cifsglob.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ struct smb_vol {
200200
bool fsc:1; /* enable fscache */
201201
bool mfsymlinks:1; /* use Minshall+French Symlinks */
202202
bool multiuser:1;
203+
bool rwpidforward:1; /* pid forward for read/write operations */
203204
unsigned int rsize;
204205
unsigned int wsize;
205206
bool sockopt_tcp_nodelay:1;

‎fs/cifs/cifsproto.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,8 @@ extern int CIFSSMBClose(const int xid, struct cifsTconInfo *tcon,
345345
extern int CIFSSMBFlush(const int xid, struct cifsTconInfo *tcon,
346346
const int smb_file_id);
347347

348-
extern int CIFSSMBRead(const int xid, struct cifsTconInfo *tcon,
349-
const int netfid, unsigned int count,
350-
const __u64 lseek, unsigned int *nbytes, char **buf,
348+
extern int CIFSSMBRead(const int xid, struct cifs_io_parms *io_parms,
349+
unsigned int *nbytes, char **buf,
351350
int *return_buf_type);
352351
extern int CIFSSMBWrite(const int xid, struct cifs_io_parms *io_parms,
353352
unsigned int *nbytes, const char *buf,

‎fs/cifs/cifssmb.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,8 +1382,7 @@ CIFSSMBOpen(const int xid, struct cifsTconInfo *tcon,
13821382
}
13831383

13841384
int
1385-
CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid,
1386-
const unsigned int count, const __u64 lseek, unsigned int *nbytes,
1385+
CIFSSMBRead(const int xid, struct cifs_io_parms *io_parms, unsigned int *nbytes,
13871386
char **buf, int *pbuf_type)
13881387
{
13891388
int rc = -EACCES;
@@ -1393,13 +1392,18 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid,
13931392
int wct;
13941393
int resp_buf_type = 0;
13951394
struct kvec iov[1];
1395+
__u32 pid = io_parms->pid;
1396+
__u16 netfid = io_parms->netfid;
1397+
__u64 offset = io_parms->offset;
1398+
struct cifsTconInfo *tcon = io_parms->tcon;
1399+
unsigned int count = io_parms->length;
13961400

13971401
cFYI(1, "Reading %d bytes on fid %d", count, netfid);
13981402
if (tcon->ses->capabilities & CAP_LARGE_FILES)
13991403
wct = 12;
14001404
else {
14011405
wct = 10; /* old style read */
1402-
if ((lseek >> 32) > 0) {
1406+
if ((offset >> 32) > 0) {
14031407
/* can not handle this big offset for old */
14041408
return -EIO;
14051409
}
@@ -1410,15 +1414,18 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid,
14101414
if (rc)
14111415
return rc;
14121416

1417+
pSMB->hdr.Pid = cpu_to_le16((__u16)pid);
1418+
pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid >> 16));
1419+
14131420
/* tcon and ses pointer are checked in smb_init */
14141421
if (tcon->ses->server == NULL)
14151422
return -ECONNABORTED;
14161423

14171424
pSMB->AndXCommand = 0xFF; /* none */
14181425
pSMB->Fid = netfid;
1419-
pSMB->OffsetLow = cpu_to_le32(lseek & 0xFFFFFFFF);
1426+
pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF);
14201427
if (wct == 12)
1421-
pSMB->OffsetHigh = cpu_to_le32(lseek >> 32);
1428+
pSMB->OffsetHigh = cpu_to_le32(offset >> 32);
14221429

14231430
pSMB->Remaining = 0;
14241431
pSMB->MaxCount = cpu_to_le16(count & 0xFFFF);

‎fs/cifs/connect.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,8 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
13591359
vol->server_ino = 1;
13601360
} else if (strnicmp(data, "noserverino", 9) == 0) {
13611361
vol->server_ino = 0;
1362+
} else if (strnicmp(data, "rwpidforward", 4) == 0) {
1363+
vol->rwpidforward = 1;
13621364
} else if (strnicmp(data, "cifsacl", 7) == 0) {
13631365
vol->cifs_acl = 1;
13641366
} else if (strnicmp(data, "nocifsacl", 9) == 0) {
@@ -2708,6 +2710,8 @@ void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
27082710
cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOSSYNC;
27092711
if (pvolume_info->mand_lock)
27102712
cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOPOSIXBRL;
2713+
if (pvolume_info->rwpidforward)
2714+
cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD;
27112715
if (pvolume_info->cifs_acl)
27122716
cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL;
27132717
if (pvolume_info->override_uid)

‎fs/cifs/file.c‎

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,8 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
725725
else
726726
posix_lock_type = CIFS_WRLCK;
727727
rc = CIFSSMBPosixLock(xid, tcon, netfid, 1 /* get */,
728-
length, pfLock,
729-
posix_lock_type, wait_flag);
728+
length, pfLock, posix_lock_type,
729+
wait_flag);
730730
FreeXid(xid);
731731
return rc;
732732
}
@@ -797,8 +797,8 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
797797
posix_lock_type = CIFS_UNLCK;
798798

799799
rc = CIFSSMBPosixLock(xid, tcon, netfid, 0 /* set */,
800-
length, pfLock,
801-
posix_lock_type, wait_flag);
800+
length, pfLock, posix_lock_type,
801+
wait_flag);
802802
} else {
803803
struct cifsFileInfo *fid = file->private_data;
804804

@@ -1346,6 +1346,14 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
13461346
{
13471347
int rc;
13481348
struct inode *inode = mapping->host;
1349+
struct cifsFileInfo *cfile = file->private_data;
1350+
struct cifs_sb_info *cifs_sb = CIFS_SB(cfile->dentry->d_sb);
1351+
__u32 pid;
1352+
1353+
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
1354+
pid = cfile->pid;
1355+
else
1356+
pid = current->tgid;
13491357

13501358
cFYI(1, "write_end for page %p from pos %lld with %d bytes",
13511359
page, pos, copied);
@@ -1369,8 +1377,7 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
13691377
/* BB check if anything else missing out of ppw
13701378
such as updating last write time */
13711379
page_data = kmap(page);
1372-
rc = cifs_write(file->private_data, current->tgid,
1373-
page_data + offset, copied, &pos);
1380+
rc = cifs_write(cfile, pid, page_data + offset, copied, &pos);
13741381
/* if (rc < 0) should we set writebehind rc? */
13751382
kunmap(page);
13761383

@@ -1523,6 +1530,7 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
15231530
struct cifs_sb_info *cifs_sb;
15241531
struct cifs_io_parms io_parms;
15251532
int xid, rc;
1533+
__u32 pid;
15261534

15271535
len = iov_length(iov, nr_segs);
15281536
if (!len)
@@ -1554,6 +1562,12 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
15541562

15551563
xid = GetXid();
15561564
open_file = file->private_data;
1565+
1566+
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
1567+
pid = open_file->pid;
1568+
else
1569+
pid = current->tgid;
1570+
15571571
pTcon = tlink_tcon(open_file->tlink);
15581572
inode = file->f_path.dentry->d_inode;
15591573

@@ -1581,7 +1595,7 @@ cifs_iovec_write(struct file *file, const struct iovec *iov,
15811595
break;
15821596
}
15831597
io_parms.netfid = open_file->netfid;
1584-
io_parms.pid = current->tgid;
1598+
io_parms.pid = pid;
15851599
io_parms.tcon = pTcon;
15861600
io_parms.offset = *poffset;
15871601
io_parms.length = cur_len;
@@ -1682,7 +1696,9 @@ cifs_iovec_read(struct file *file, const struct iovec *iov,
16821696
struct cifsTconInfo *pTcon;
16831697
struct cifsFileInfo *open_file;
16841698
struct smb_com_read_rsp *pSMBr;
1699+
struct cifs_io_parms io_parms;
16851700
char *read_data;
1701+
__u32 pid;
16861702

16871703
if (!nr_segs)
16881704
return 0;
@@ -1697,6 +1713,11 @@ cifs_iovec_read(struct file *file, const struct iovec *iov,
16971713
open_file = file->private_data;
16981714
pTcon = tlink_tcon(open_file->tlink);
16991715

1716+
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
1717+
pid = open_file->pid;
1718+
else
1719+
pid = current->tgid;
1720+
17001721
if ((file->f_flags & O_ACCMODE) == O_WRONLY)
17011722
cFYI(1, "attempting read on write only file instance");
17021723

@@ -1712,8 +1733,12 @@ cifs_iovec_read(struct file *file, const struct iovec *iov,
17121733
if (rc != 0)
17131734
break;
17141735
}
1715-
rc = CIFSSMBRead(xid, pTcon, open_file->netfid,
1716-
cur_len, *poffset, &bytes_read,
1736+
io_parms.netfid = open_file->netfid;
1737+
io_parms.pid = pid;
1738+
io_parms.tcon = pTcon;
1739+
io_parms.offset = *poffset;
1740+
io_parms.length = len;
1741+
rc = CIFSSMBRead(xid, &io_parms, &bytes_read,
17171742
&read_data, &buf_type);
17181743
pSMBr = (struct smb_com_read_rsp *)read_data;
17191744
if (read_data) {
@@ -1794,7 +1819,9 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
17941819
int xid;
17951820
char *current_offset;
17961821
struct cifsFileInfo *open_file;
1822+
struct cifs_io_parms io_parms;
17971823
int buf_type = CIFS_NO_BUFFER;
1824+
__u32 pid;
17981825

17991826
xid = GetXid();
18001827
cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
@@ -1807,6 +1834,11 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
18071834
open_file = file->private_data;
18081835
pTcon = tlink_tcon(open_file->tlink);
18091836

1837+
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
1838+
pid = open_file->pid;
1839+
else
1840+
pid = current->tgid;
1841+
18101842
if ((file->f_flags & O_ACCMODE) == O_WRONLY)
18111843
cFYI(1, "attempting read on write only file instance");
18121844

@@ -1829,11 +1861,13 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
18291861
if (rc != 0)
18301862
break;
18311863
}
1832-
rc = CIFSSMBRead(xid, pTcon,
1833-
open_file->netfid,
1834-
current_read_size, *poffset,
1835-
&bytes_read, &current_offset,
1836-
&buf_type);
1864+
io_parms.netfid = open_file->netfid;
1865+
io_parms.pid = pid;
1866+
io_parms.tcon = pTcon;
1867+
io_parms.offset = *poffset;
1868+
io_parms.length = current_read_size;
1869+
rc = CIFSSMBRead(xid, &io_parms, &bytes_read,
1870+
&current_offset, &buf_type);
18371871
}
18381872
if (rc || (bytes_read == 0)) {
18391873
if (total_read) {
@@ -1970,7 +2004,9 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
19702004
char *smb_read_data = NULL;
19712005
struct smb_com_read_rsp *pSMBr;
19722006
struct cifsFileInfo *open_file;
2007+
struct cifs_io_parms io_parms;
19732008
int buf_type = CIFS_NO_BUFFER;
2009+
__u32 pid;
19742010

19752011
xid = GetXid();
19762012
if (file->private_data == NULL) {
@@ -1992,6 +2028,11 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
19922028
goto read_complete;
19932029

19942030
cFYI(DBG2, "rpages: num pages %d", num_pages);
2031+
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_RWPIDFORWARD)
2032+
pid = open_file->pid;
2033+
else
2034+
pid = current->tgid;
2035+
19952036
for (i = 0; i < num_pages; ) {
19962037
unsigned contig_pages;
19972038
struct page *tmp_page;
@@ -2033,12 +2074,13 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
20332074
if (rc != 0)
20342075
break;
20352076
}
2036-
2037-
rc = CIFSSMBRead(xid, pTcon,
2038-
open_file->netfid,
2039-
read_size, offset,
2040-
&bytes_read, &smb_read_data,
2041-
&buf_type);
2077+
io_parms.netfid = open_file->netfid;
2078+
io_parms.pid = pid;
2079+
io_parms.tcon = pTcon;
2080+
io_parms.offset = offset;
2081+
io_parms.length = read_size;
2082+
rc = CIFSSMBRead(xid, &io_parms, &bytes_read,
2083+
&smb_read_data, &buf_type);
20422084
/* BB more RC checks ? */
20432085
if (rc == -EAGAIN) {
20442086
if (smb_read_data) {

‎fs/cifs/inode.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path,
374374
__u16 netfid;
375375
struct tcon_link *tlink;
376376
struct cifsTconInfo *tcon;
377+
struct cifs_io_parms io_parms;
377378
char buf[24];
378379
unsigned int bytes_read;
379380
char *pbuf;
@@ -405,9 +406,13 @@ cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path,
405406
if (rc == 0) {
406407
int buf_type = CIFS_NO_BUFFER;
407408
/* Read header */
408-
rc = CIFSSMBRead(xid, tcon, netfid,
409-
24 /* length */, 0 /* offset */,
410-
&bytes_read, &pbuf, &buf_type);
409+
io_parms.netfid = netfid;
410+
io_parms.pid = current->tgid;
411+
io_parms.tcon = tcon;
412+
io_parms.offset = 0;
413+
io_parms.length = 24;
414+
rc = CIFSSMBRead(xid, &io_parms, &bytes_read, &pbuf,
415+
&buf_type);
411416
if ((rc == 0) && (bytes_read >= 8)) {
412417
if (memcmp("IntxBLK", pbuf, 8) == 0) {
413418
cFYI(1, "Block device");

0 commit comments

Comments
 (0)