linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Trond Myklebust <trondmy@hammerspace.com>
To: "anna@kernel.org" <anna@kernel.org>,
	"chenxiaosong2@huawei.com" <chenxiaosong2@huawei.com>,
	"bjschuma@netapp.com" <bjschuma@netapp.com>
Cc: "linux-nfs@vger.kernel.org" <linux-nfs@vger.kernel.org>,
	"liuyongqiang13@huawei.com" <liuyongqiang13@huawei.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"tao.lyu@epfl.ch" <tao.lyu@epfl.ch>,
	"zhangxiaoxu5@huawei.com" <zhangxiaoxu5@huawei.com>,
	"yi.zhang@huawei.com" <yi.zhang@huawei.com>
Subject: Re: [PATCH -next 2/2] NFSv4: fix open failure with O_ACCMODE flag
Date: Tue, 29 Mar 2022 13:56:16 +0000	[thread overview]
Message-ID: <51009f90a1694894d16abfbd31d7770c881a3f39.camel@hammerspace.com> (raw)
In-Reply-To: <78ed2de5-84c9-708d-bab0-3bab4455593c@huawei.com>

On Tue, 2022-03-29 at 21:44 +0800, chenxiaosong (A) wrote:
> 在 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.

I see. OK, I'll probably not apply this for the merge window (since I'm
pretty much queued up to send the pull request at this point), but it
might go in as a bug fix in rc1.

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com



  reply	other threads:[~2022-03-29 13:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29 11:32 [PATCH -next 0/2] fix nfsv4 bugs of opening with O_ACCMODE flag ChenXiaoSong
2022-03-29 11:32 ` [PATCH -next 1/2] Revert "NFSv4: Handle the special Linux file open access mode" ChenXiaoSong
2022-03-29 11:32 ` [PATCH -next 2/2] NFSv4: fix open failure with O_ACCMODE flag ChenXiaoSong
2022-03-29 13:05   ` Trond Myklebust
2022-03-29 13:44     ` chenxiaosong (A)
2022-03-29 13:56       ` Trond Myklebust [this message]
2022-03-29 14:32 ` [PATCH -next 0/2] fix nfsv4 bugs of opening " chenxiaosong (A)
     [not found]   ` <e0c2d7ec62b447cabddbc8a9274be955@epfl.ch>
2022-04-13 13:42     ` chenxiaosong (A)
2022-04-13 14:05       ` chenxiaosong (A)
2022-04-13 14:34         ` chenxiaosong (A)
     [not found]         ` <3ee78045f18b4932b1651de776ee73c4@epfl.ch>
2022-04-13 14:42           ` chenxiaosong (A)
     [not found]             ` <55415e44b4b04bbfa66c42d5f2788384@epfl.ch>
2022-04-14  2:41               ` chenxiaosong (A)
2022-04-14  7:33                 ` Lyu Tao
2022-05-05  2:48                   ` chenxiaosong (A)
2022-05-06  7:40                     ` Lyu Tao
2022-05-31  6:40                       ` chenxiaosong (A)
2022-05-31  8:16                         ` Lyu Tao
2022-05-31  8:47                           ` chenxiaosong (A)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51009f90a1694894d16abfbd31d7770c881a3f39.camel@hammerspace.com \
    --to=trondmy@hammerspace.com \
    --cc=anna@kernel.org \
    --cc=bjschuma@netapp.com \
    --cc=chenxiaosong2@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=liuyongqiang13@huawei.com \
    --cc=tao.lyu@epfl.ch \
    --cc=yi.zhang@huawei.com \
    --cc=zhangxiaoxu5@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).