From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96943C433F5 for ; Tue, 29 Mar 2022 13:44:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237467AbiC2NqY (ORCPT ); Tue, 29 Mar 2022 09:46:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234225AbiC2NqV (ORCPT ); Tue, 29 Mar 2022 09:46:21 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 766EF28E10; Tue, 29 Mar 2022 06:44:36 -0700 (PDT) Received: from kwepemi100005.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KSW0b6dCTzBrhd; Tue, 29 Mar 2022 21:40:31 +0800 (CST) Received: from kwepemm600015.china.huawei.com (7.193.23.52) by kwepemi100005.china.huawei.com (7.221.188.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 29 Mar 2022 21:44:34 +0800 Received: from [10.174.176.52] (10.174.176.52) by kwepemm600015.china.huawei.com (7.193.23.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 29 Mar 2022 21:44:33 +0800 Message-ID: <78ed2de5-84c9-708d-bab0-3bab4455593c@huawei.com> Date: Tue, 29 Mar 2022 21:44:17 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH -next 2/2] NFSv4: fix open failure with O_ACCMODE flag To: Trond Myklebust , "anna@kernel.org" , "bjschuma@netapp.com" CC: "tao.lyu@epfl.ch" , "linux-nfs@vger.kernel.org" , "liuyongqiang13@huawei.com" , "linux-kernel@vger.kernel.org" , "yi.zhang@huawei.com" , "zhangxiaoxu5@huawei.com" References: <20220329113208.2466000-1-chenxiaosong2@huawei.com> <20220329113208.2466000-3-chenxiaosong2@huawei.com> <4b0d16161fab58dcfba912eb0266a6cd1f83d47e.camel@hammerspace.com> From: "chenxiaosong (A)" In-Reply-To: <4b0d16161fab58dcfba912eb0266a6cd1f83d47e.camel@hammerspace.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.176.52] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600015.china.huawei.com (7.193.23.52) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 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.