[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <78ed2de5-84c9-708d-bab0-3bab4455593c@huawei.com>
Date: Tue, 29 Mar 2022 21:44:17 +0800
From: "chenxiaosong (A)" <chenxiaosong2@...wei.com>
To: Trond Myklebust <trondmy@...merspace.com>,
"anna@...nel.org" <anna@...nel.org>,
"bjschuma@...app.com" <bjschuma@...app.com>
CC: "tao.lyu@...l.ch" <tao.lyu@...l.ch>,
"linux-nfs@...r.kernel.org" <linux-nfs@...r.kernel.org>,
"liuyongqiang13@...wei.com" <liuyongqiang13@...wei.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"yi.zhang@...wei.com" <yi.zhang@...wei.com>,
"zhangxiaoxu5@...wei.com" <zhangxiaoxu5@...wei.com>
Subject: Re: [PATCH -next 2/2] NFSv4: fix open failure with O_ACCMODE flag
在 2022/3/29 21:05, Trond Myklebust 写道:
> No. This will not fit the definition of open(2) in the manpage.
>
> Linux reserves the special, nonstandard access mode 3 (binary 11) in
> flags to mean: check for read and write permission on the file and re‐
> turn a file descriptor that can't be used for reading or writing. This
> nonstandard access mode is used by some Linux drivers to return a file
> descriptor that is to be used only for device-specific ioctl(2) opera‐
> tions.
> Your patch will now cause FMODE_READ and FMODE_WRITE to be set on the
> file, allowing the file descriptor to be usable for I/O.
Reproducer:
```
1. mount -t nfs -o vers=4.2 $server_ip:/ /mnt/
2. fd = open("/mnt/file", O_ACCMODE|O_DIRECT|O_CREAT) = 3
3. close(fd)
4. fd = open("/mnt/file", O_ACCMODE|O_DIRECT) = -1
```
When firstly open with O_ACCMODE|O_DIRECT flags:
```c
path_openat
open_last_lookups
lookup_open
atomic_open
nfs_atomic_open
create_nfs_open_context
f_mode = flags_to_mode
alloc_nfs_open_context(..., f_mode, ...)
ctx->mode = f_mode // FMODE_READ|FMODE_WRITE
```
When secondly open with O_ACCMODE|O_DIRECT flags:
```c
path_openat
do_open
vfs_open
do_dentry_open
nfs4_file_open
f_mode = filp->f_mode | flags_to_mode(openflags)
alloc_nfs_open_context(..., f_mode, ...)
ctx->mode = f_mode // FMODE_READ|FMODE_WRITE
```
Before merging this patch, when firstly open, we does not set FMODE_READ
and FMODE_WRITE to file mode of client, FMODE_READ and FMODE_WRITE just
be set to context mode.
After merging this patch, when secondly open, I just do the same thing,
file mode of client will not have FMODE_READ and FMODE_WRITE bits, file
descriptor can't be used for reading or writing.
Powered by blists - more mailing lists