mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "chenxiaosong (A)" <chenxiaosong2@huawei.com>
To: Trond Myklebust <trondmy@hammerspace.com>,
	"anna@kernel.org" <anna@kernel.org>,
	"bjschuma@netapp.com" <bjschuma@netapp.com>
Cc: "tao.lyu@epfl.ch" <tao.lyu@epfl.ch>,
	"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>,
	"yi.zhang@huawei.com" <yi.zhang@huawei.com>,
	"zhangxiaoxu5@huawei.com" <zhangxiaoxu5@huawei.com>
Subject: Re: [PATCH -next 2/2] NFSv4: fix open failure with O_ACCMODE flag
Date: Tue, 29 Mar 2022 21:44:17 +0800	[thread overview]
Message-ID: <78ed2de5-84c9-708d-bab0-3bab4455593c@huawei.com> (raw)
In-Reply-To: <4b0d16161fab58dcfba912eb0266a6cd1f83d47e.camel@hammerspace.com>

在 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.

  reply	other threads:[~2022-03-29 13:44 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 " 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) [this message]
2022-03-29 13:56       ` Trond Myklebust
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=78ed2de5-84c9-708d-bab0-3bab4455593c@huawei.com \
    --to=chenxiaosong2@huawei.com \
    --cc=anna@kernel.org \
    --cc=bjschuma@netapp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=liuyongqiang13@huawei.com \
    --cc=tao.lyu@epfl.ch \
    --cc=trondmy@hammerspace.com \
    --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

all inboxes | Powered by JetHome®