Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp181206lqp; Tue, 11 Jun 2024 20:08:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUilFyNJU4/o5XXp9z/0rUMINIGTffWuDm3d80C96gxNl7FkI0TweVFdsd3GzGQJQ4AkZMVcToXfspyzKiBQGHXNqVFIDovz5qvt+wCGw== X-Google-Smtp-Source: AGHT+IGqQTtvn3wC8fRAyF/oXB1ZMmAWrt1K5smjtia0BEaA+2+aDXN1kBtRWlQ825NX8XkDr8Tk X-Received: by 2002:a05:6a20:9190:b0:1b5:ad0b:50bd with SMTP id adf61e73a8af0-1b8a9c68270mr792372637.47.1718161687687; Tue, 11 Jun 2024 20:08:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718161687; cv=pass; d=google.com; s=arc-20160816; b=ZsSZFlQrxi/6UHLc0NQGWEPrCwY+V9751Q8yPrLMWzKRXmSuK3k1J5BS3Q/BucjKTa SVMJG+S3u7pivy61fzyVNKbr0pKzKSPxqtJBb8Ss4BLVYLGqmfn42sneAHwA09buFuBW MiFy9XsbawhGBvBMjyavjb0+r9Lnanrzr/Igie126zUj7NbYHyS8EiZD6I+SmwtE3hSg 0Vxw8v6slAM7BSv7wFqwbGQ7Y3UsA7xKpp10zkikIa7+EC87ZtC1Qf/DfHS4JOii1bYI m/FsvDU9K2OG4OXEbUO/HY49ErPxfmv00rFcRNqDMzL/eg34GGzFpcprNMoTh92mceAY 6X4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=cgxgLWn6Ffrlu3oKMuNrnHIwmF3QqJ7i4ICNZ4MC3JM=; fh=+HdF1SWcNPggmowVZtzfZ2+SYSXLLgvZBECjaw6UQek=; b=NynFwNplkS89U+dgLmBzAE6ovnQne6QrHoY2ycfme4iqbnNQYcSEWaZemxqNDy2yd6 T3erl+W5VHjtzuo83JZDGTSG9KacAZjQ+1D+6oz0dLaN2Wz/TeH+X8d9PvPLzvARWvNZ TPOYG/uhVUEvcUNHEWH1GLVEsmOfKr5LWvUs9xIrKuOUHz9Ft+qJ9/4PlTHykLHQZudn D5oDX7Fn4/ukwbTScx37DZrWauBSp25dQzZbr7N39lYsgK7SF2u8z95vmzf4Haj/Qb9U n1BRh342vD/XxqreFyw/AA8ruBjZNUBoIzRQdvqCQoKZvDyJLwFQcmSMuiNEC/jV2Gkj 8BiQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NsIAK08W; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-3661-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3661-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-7041c6ad425si7515203b3a.337.2024.06.11.20.08.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 20:08:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-3661-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NsIAK08W; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-3661-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3661-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4A2C0284EBF for ; Wed, 12 Jun 2024 03:08:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58B3B20315; Wed, 12 Jun 2024 03:08:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NsIAK08W" X-Original-To: linux-nfs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3594C1F92F for ; Wed, 12 Jun 2024 03:08:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718161681; cv=none; b=a45af2064jPqtJ6AHS/3DIqErjf0kiPDl6MA9GDACvJDRcwHOE9oxpNenz4m8DAYyiUMMBSvnVMcOjM5vzQNcqVU0I4b4jeXUYP/AUWK4DU6FIeI7E1cAev8CbXt6q52ISOAYwjPAgr0nmhRnMTYZmothb5d2l/5HCLcggs8ioU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718161681; c=relaxed/simple; bh=aG8k34g9i3eVZnS6rlNNs65QjqJFgFWblLXRSOGkIxA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hjabIgz8n3JXh+hYpUJF6gNSwnljJGr6MAcze3dNqPqquuu0l0VSFEF15jReCjWCHbPOuW0cL5LsHvxwmvuLcgfdoSyNB20yNyi9zn47Fnn+zeEFbjTrYmNtf587/g0N5E0PB8KaRC2bNoJ7JaxAWDoIKITi7+bkt+qd6VsJa1g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NsIAK08W; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BB2AC2BD10; Wed, 12 Jun 2024 03:08:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718161680; bh=aG8k34g9i3eVZnS6rlNNs65QjqJFgFWblLXRSOGkIxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NsIAK08W39rQnzNy3k7sob9yPfFGz/jLaeiC3tJOhOTvZcs7RLLk0/DPHWN5WQrOn DDC3Xg9e5kNLexfnSqu2EgZy6/fAzFD+gzEYeFwDUuNDBALv4Pf0+J5zAB5kwuUTJg Xw+t1VDQoQu04TrtSftFmz/3j92zsy79IrwMjXJF4RQRwQbpGdYOEL6fNvmhsekR1B ViGFpB0iBJE8sy78s/mKrJ2rYM8HzgFYdCSV2xiU4rVkawr9jPse/LmtVtaq49S76u hPWa6B8yezzF5jK80PClUL4ClXGT8lG1mPfxbp5X6p/TrMwKWALo6/V9DkQ6d4dpR9 d+YnpAzAy/2/w== From: Mike Snitzer To: linux-nfs@vger.kernel.org Cc: Jeff Layton , Chuck Lever , Trond Myklebust , NeilBrown , snitzer@hammerspace.com Subject: [RFC PATCH v2 05/15] nfs: move nfs_stat_to_errno to nfs.h Date: Tue, 11 Jun 2024 23:07:42 -0400 Message-ID: <20240612030752.31754-6-snitzer@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240612030752.31754-1-snitzer@kernel.org> References: <20240612030752.31754-1-snitzer@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Peng Tao So that knfsd can use it to map nfs stat to sys errno as well. Signed-off-by: Peng Tao Signed-off-by: Lance Shelton Signed-off-by: Trond Myklebust Signed-off-by: Mike Snitzer --- fs/nfs/nfs2xdr.c | 69 --------------------------------------------- include/linux/nfs.h | 63 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 69 deletions(-) diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c index c19093814296..f7ef44829f6e 100644 --- a/fs/nfs/nfs2xdr.c +++ b/fs/nfs/nfs2xdr.c @@ -27,9 +27,6 @@ #define NFSDBG_FACILITY NFSDBG_XDR -/* Mapping from NFS error code to "errno" error code. */ -#define errno_NFSERR_IO EIO - /* * Declare the space requirements for NFS arguments and replies as * number of 32bit-words @@ -64,8 +61,6 @@ #define NFS_readdirres_sz (1+NFS_pagepad_sz) #define NFS_statfsres_sz (1+NFS_info_sz) -static int nfs_stat_to_errno(enum nfs_stat); - /* * Encode/decode NFSv2 basic data types * @@ -1054,70 +1049,6 @@ static int nfs2_xdr_dec_statfsres(struct rpc_rqst *req, struct xdr_stream *xdr, return nfs_stat_to_errno(status); } - -/* - * We need to translate between nfs status return values and - * the local errno values which may not be the same. - */ -static const struct { - int stat; - int errno; -} nfs_errtbl[] = { - { NFS_OK, 0 }, - { NFSERR_PERM, -EPERM }, - { NFSERR_NOENT, -ENOENT }, - { NFSERR_IO, -errno_NFSERR_IO}, - { NFSERR_NXIO, -ENXIO }, -/* { NFSERR_EAGAIN, -EAGAIN }, */ - { NFSERR_ACCES, -EACCES }, - { NFSERR_EXIST, -EEXIST }, - { NFSERR_XDEV, -EXDEV }, - { NFSERR_NODEV, -ENODEV }, - { NFSERR_NOTDIR, -ENOTDIR }, - { NFSERR_ISDIR, -EISDIR }, - { NFSERR_INVAL, -EINVAL }, - { NFSERR_FBIG, -EFBIG }, - { NFSERR_NOSPC, -ENOSPC }, - { NFSERR_ROFS, -EROFS }, - { NFSERR_MLINK, -EMLINK }, - { NFSERR_NAMETOOLONG, -ENAMETOOLONG }, - { NFSERR_NOTEMPTY, -ENOTEMPTY }, - { NFSERR_DQUOT, -EDQUOT }, - { NFSERR_STALE, -ESTALE }, - { NFSERR_REMOTE, -EREMOTE }, -#ifdef EWFLUSH - { NFSERR_WFLUSH, -EWFLUSH }, -#endif - { NFSERR_BADHANDLE, -EBADHANDLE }, - { NFSERR_NOT_SYNC, -ENOTSYNC }, - { NFSERR_BAD_COOKIE, -EBADCOOKIE }, - { NFSERR_NOTSUPP, -ENOTSUPP }, - { NFSERR_TOOSMALL, -ETOOSMALL }, - { NFSERR_SERVERFAULT, -EREMOTEIO }, - { NFSERR_BADTYPE, -EBADTYPE }, - { NFSERR_JUKEBOX, -EJUKEBOX }, - { -1, -EIO } -}; - -/** - * nfs_stat_to_errno - convert an NFS status code to a local errno - * @status: NFS status code to convert - * - * Returns a local errno value, or -EIO if the NFS status code is - * not recognized. This function is used jointly by NFSv2 and NFSv3. - */ -static int nfs_stat_to_errno(enum nfs_stat status) -{ - int i; - - for (i = 0; nfs_errtbl[i].stat != -1; i++) { - if (nfs_errtbl[i].stat == (int)status) - return nfs_errtbl[i].errno; - } - dprintk("NFS: Unrecognized nfs status value: %u\n", status); - return nfs_errtbl[i].errno; -} - #define PROC(proc, argtype, restype, timer) \ [NFSPROC_##proc] = { \ .p_proc = NFSPROC_##proc, \ diff --git a/include/linux/nfs.h b/include/linux/nfs.h index ceb70a926b95..b94f51d17bc5 100644 --- a/include/linux/nfs.h +++ b/include/linux/nfs.h @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -46,6 +47,68 @@ enum nfs3_stable_how { NFS_INVALID_STABLE_HOW = -1 }; +/* + * We need to translate between nfs status return values and + * the local errno values which may not be the same. + */ +static const struct { + int stat; + int errno; +} nfs_common_errtbl[] = { + { NFS_OK, 0 }, + { NFSERR_PERM, -EPERM }, + { NFSERR_NOENT, -ENOENT }, + { NFSERR_IO, -EIO }, + { NFSERR_NXIO, -ENXIO }, +/* { NFSERR_EAGAIN, -EAGAIN }, */ + { NFSERR_ACCES, -EACCES }, + { NFSERR_EXIST, -EEXIST }, + { NFSERR_XDEV, -EXDEV }, + { NFSERR_NODEV, -ENODEV }, + { NFSERR_NOTDIR, -ENOTDIR }, + { NFSERR_ISDIR, -EISDIR }, + { NFSERR_INVAL, -EINVAL }, + { NFSERR_FBIG, -EFBIG }, + { NFSERR_NOSPC, -ENOSPC }, + { NFSERR_ROFS, -EROFS }, + { NFSERR_MLINK, -EMLINK }, + { NFSERR_NAMETOOLONG, -ENAMETOOLONG }, + { NFSERR_NOTEMPTY, -ENOTEMPTY }, + { NFSERR_DQUOT, -EDQUOT }, + { NFSERR_STALE, -ESTALE }, + { NFSERR_REMOTE, -EREMOTE }, +#ifdef EWFLUSH + { NFSERR_WFLUSH, -EWFLUSH }, +#endif + { NFSERR_BADHANDLE, -EBADHANDLE }, + { NFSERR_NOT_SYNC, -ENOTSYNC }, + { NFSERR_BAD_COOKIE, -EBADCOOKIE }, + { NFSERR_NOTSUPP, -ENOTSUPP }, + { NFSERR_TOOSMALL, -ETOOSMALL }, + { NFSERR_SERVERFAULT, -EREMOTEIO }, + { NFSERR_BADTYPE, -EBADTYPE }, + { NFSERR_JUKEBOX, -EJUKEBOX }, + { -1, -EIO } +}; + +/** + * nfs_stat_to_errno - convert an NFS status code to a local errno + * @status: NFS status code to convert + * + * Returns a local errno value, or -EIO if the NFS status code is + * not recognized. This function is used jointly by NFSv2 and NFSv3. + */ +static inline int nfs_stat_to_errno(enum nfs_stat status) +{ + int i; + + for (i = 0; nfs_common_errtbl[i].stat != -1; i++) { + if (nfs_common_errtbl[i].stat == (int)status) + return nfs_common_errtbl[i].errno; + } + return nfs_common_errtbl[i].errno; +} + #ifdef CONFIG_CRC32 /** * nfs_fhandle_hash - calculate the crc32 hash for the filehandle -- 2.44.0