From patchwork Sun Feb 19 18:58:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 9581767 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 004D4604A0 for ; Sun, 19 Feb 2017 18:59:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E570D285A7 for ; Sun, 19 Feb 2017 18:59:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA4522864B; Sun, 19 Feb 2017 18:59:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8161E285A7 for ; Sun, 19 Feb 2017 18:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751755AbdBSS7V (ORCPT ); Sun, 19 Feb 2017 13:59:21 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:34806 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751745AbdBSS7U (ORCPT ); Sun, 19 Feb 2017 13:59:20 -0500 Received: by mail-io0-f194.google.com with SMTP id c80so3081695iod.1 for ; Sun, 19 Feb 2017 10:59:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=J4qsV8/uRpIWFo9IpmL8Q2iovD6FTGFg6x9P9P95LzU=; b=B3xTxUOrh6phc2jkDTZdrEhpR0j4V1ulAtj08lmAPqt/Wg1WBidVuOm4D03yfwl/Lb 4gjmATpxANqRciZ57hIYAB8hE/XqJF/14/JAmpnVvIyn4JrBzTZdz38FLbKr0qVB4vjR cGeD2pTnKtW2kdezTzEmcSMOoKEQSPqUkpPTP/XWVFyeEznrwpiwSpi2wmXBLHwolICI tiLJL0ApTr/BAlJIsp7DBxVAqlY7KBdtiOpUQYe+uQqlXEW91OAjbijW9dP5he+1Yl0r fbUSM30reJWV67FY3L8DkkhTn7UeAH95bB9zovYdiEPcQfF6/zAwcTxJbThlizxEfNr0 3W2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=J4qsV8/uRpIWFo9IpmL8Q2iovD6FTGFg6x9P9P95LzU=; b=UUF5qqONJwJsf6uc2DrGFmQAsKArgBdrguwvn7W4rRqLg5QJ9KlFG1FKACl9s8MzTq UB1HBM9mXNruN2SDsTQ/V/R9Q/mwgtNXio/YwM6V650upbwdNrPr6R2EHUNVGxKxLCVa 5pFfogXZVcM40eXlyhi5CE04OrPI1Ov596FlxMr+/FMzK+HexP5XPO7daAmSjGjFx6M8 k417/bYQBbbLIQW1bYa4G9PnrtSUZc1gtNivA00KyT44RnKLn9e+vEb9FFwBFKGWgMP9 k94qOauTNWRznOOxQlwy/z9ZuWcwnJN+S/SeqXb1yLxqZeqsKLbr+mEyD4lSSoVBT8J1 FNVA== X-Gm-Message-State: AMke39kTSIfLjWoLjrjOJitHP1hnQwilxaPOohPvRkgXvKkTwoe2yLX/RYUhws2/fsvDig== X-Received: by 10.107.140.193 with SMTP id o184mr14747974iod.17.1487530749171; Sun, 19 Feb 2017 10:59:09 -0800 (PST) Received: from localhost.localdomain ([50.124.63.84]) by smtp.gmail.com with ESMTPSA id o20sm4039282ioo.37.2017.02.19.10.59.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Feb 2017 10:59:08 -0800 (PST) From: Trond Myklebust To: Anna Schumaker , Chuck Lever Cc: linux-nfs@vger.kernel.org Subject: [PATCH v4 2/8] NFSv4: Replace ad-hoc xdr encode/decode helpers with xdr_stream_* generics Date: Sun, 19 Feb 2017 13:58:57 -0500 Message-Id: <20170219185903.42043-3-trond.myklebust@primarydata.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170219185903.42043-2-trond.myklebust@primarydata.com> References: <20170219185903.42043-1-trond.myklebust@primarydata.com> <20170219185903.42043-2-trond.myklebust@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Trond Myklebust --- fs/nfs/callback_xdr.c | 8 ++------ fs/nfs/flexfilelayout/flexfilelayout.c | 5 +---- fs/nfs/nfs4xdr.c | 33 +++++++++------------------------ 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c index eb094c6011d8..e732a65db546 100644 --- a/fs/nfs/callback_xdr.c +++ b/fs/nfs/callback_xdr.c @@ -582,12 +582,8 @@ static __be32 decode_notify_lock_args(struct svc_rqst *rqstp, struct xdr_stream static __be32 encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) { - __be32 *p; - - p = xdr_reserve_space(xdr, 4 + len); - if (unlikely(p == NULL)) - return htonl(NFS4ERR_RESOURCE); - xdr_encode_opaque(p, str, len); + if (unlikely(xdr_stream_encode_opaque(xdr, str, len) < 0)) + return cpu_to_be32(NFS4ERR_RESOURCE); return 0; } diff --git a/fs/nfs/flexfilelayout/flexfilelayout.c b/fs/nfs/flexfilelayout/flexfilelayout.c index 42e3e9daa328..471efdc2589d 100644 --- a/fs/nfs/flexfilelayout/flexfilelayout.c +++ b/fs/nfs/flexfilelayout/flexfilelayout.c @@ -1966,10 +1966,7 @@ static int ff_layout_encode_ioerr(struct xdr_stream *xdr, static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) { - __be32 *p; - - p = xdr_reserve_space(xdr, len); - xdr_encode_opaque_fixed(p, buf, len); + WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0); } static void diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index e9255cb453e6..5f0a6fcd0030 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c @@ -924,34 +924,22 @@ static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes) static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len) { - __be32 *p; - - p = xdr_reserve_space(xdr, len); - xdr_encode_opaque_fixed(p, buf, len); + WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0); } static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) { - __be32 *p; - - p = reserve_space(xdr, 4 + len); - xdr_encode_opaque(p, str, len); + WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0); } static void encode_uint32(struct xdr_stream *xdr, u32 n) { - __be32 *p; - - p = reserve_space(xdr, 4); - *p = cpu_to_be32(n); + WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0); } static void encode_uint64(struct xdr_stream *xdr, u64 n) { - __be32 *p; - - p = reserve_space(xdr, 8); - xdr_encode_hyper(p, n); + WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0); } static void encode_nfs4_seqid(struct xdr_stream *xdr, @@ -4294,15 +4282,12 @@ static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access) static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len) { - __be32 *p; - - p = xdr_inline_decode(xdr, len); - if (likely(p)) { - memcpy(buf, p, len); - return 0; + ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len); + if (unlikely(ret < 0)) { + print_overflow_msg(__func__, xdr); + return -EIO; } - print_overflow_msg(__func__, xdr); - return -EIO; + return 0; } static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)