From: Chuck Lever <chuck.lever@oracle.com>
To: Frank van der Linden <fllinden@amazon.com>,
Bruce Fields <bfields@redhat.com>
Cc: Linux NFS Mailing List <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH 11/14] nfsd: add user xattr RPC XDR encoding/decoding logic
Date: Fri, 20 Mar 2020 13:34:53 -0400 [thread overview]
Message-ID: <65ACAC76-DBBE-42D3-ACED-AB2290D0FC31@oracle.com> (raw)
In-Reply-To: <20200320164737.GA19415@dev-dsk-fllinden-2c-c1893d73.us-west-2.amazon.com>
> On Mar 20, 2020, at 12:47 PM, Frank van der Linden <fllinden@amazon.com> wrote:
>
> Hi Chuck,
>
> On Thu, Mar 12, 2020 at 03:16:37PM -0400, Chuck Lever wrote:
>>> +static __be32
>>> +nfsd4_decode_setxattr(struct nfsd4_compoundargs *argp,
>>> + struct nfsd4_setxattr *setxattr)
>>> +{
>>> + DECODE_HEAD;
>>> + u32 flags, maxcount, size;
>>> + struct kvec head;
>>> + struct page **pagelist;
>>> +
>>> + READ_BUF(4);
>>> + flags = be32_to_cpup(p++);
>>> +
>>> + if (flags > SETXATTR4_REPLACE)
>>> + return nfserr_inval;
>>> + setxattr->setxa_flags = flags;
>>> +
>>> + status = nfsd4_decode_xattr_name(argp, &setxattr->setxa_name);
>>> + if (status)
>>> + return status;
>>> +
>>> + maxcount = svc_max_payload(argp->rqstp);
>>> + maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount);
>>> +
>>> + READ_BUF(4);
>>> + size = be32_to_cpup(p++);
>>> + if (size > maxcount)
>>> + return nfserr_xattr2big;
>>> +
>>> + setxattr->setxa_len = size;
>>> + if (size > 0) {
>>> + status = svcxdr_construct_vector(argp, &head, &pagelist, size);
>>> + if (status)
>>> + return status;
>>> +
>>> + status = nfsd4_vbuf_from_stream(argp, &head, pagelist,
>>> + &setxattr->setxa_buf, size);
>>> + }
>>
>> Now I'm wondering if read_bytes_from_xdr_buf() might be adequate
>> for this purpose, so you can avoid open-coding all of this logic.
>
> This took a little longer, I had to check my notes,
Thanks for checking!
> but basically the reasons for doing it this way are:
>
> * The nfsd decode path uses nfsd4_compoundargs, which doesn't have an
> xdr_stream (it has a page array). So read_bytes_from_xdr_buf isn't
> a natural fit.
> * READ_BUF/read_buf don't deal with > PAGE_SIZE chunks, but xattrs may
> be larger than that.
>
> The other code that deals with > PAGE_SIZE chunks is the write code. So,
> I factored out some code from the write code, used that, and added a function
> to process the resulting kvec / pagelist (nfs4_vbuf_from_stream).
Yes, I only recently discovered that the xdr_stream helpers do not
work for decoding data items that are page size or larger.
For the record, my IMA prototype takes this approach for decode_fattr:
+ if (bmval[2] & FATTR4_WORD2_IMA) {
+ READ_BUF(4);
+ len += 4;
+ dummy32 = be32_to_cpup(p++);
+ READ_BUF(dummy32);
+ if (dummy32 > NFS4_MAXIMALEN)
+ return nfserr_badlabel;
+ *ima = svcxdr_tmpalloc(argp, sizeof(**ima));
+ if (*ima == NULL)
+ return nfserr_jukebox;
+
+ len += (XDR_QUADLEN(dummy32) << 2);
+ READMEM(buf, dummy32);
+ (*ima)->len = dummy32;
+ (*ima)->data = svcxdr_dupstr(argp, buf, dummy32);
+ if ((*ima)->data == NULL)
+ return nfserr_jukebox;
+ } else
+ ima = NULL;
Although, an IMA blob is never larger than a page, IIRC.
> There definitely seem to be several copy functions in both the client
> and server code that basically do the same, but in slightly different ways,
> depending on whether they use an XDR buf or not, whether the pages are
> mapped or not, etc. Seems like a good candidate for a cleanup, but I
> considered it to be out of scope for these patches.
"out of scope" - probably so. Depending on Bruce's thinking, we can
add this to the list of janitorial tasks.
For my peace of mind, "from_stream" implies there _is_ an xdr_stream
in use, even though the function does not have a struct xdr_stream
parameter. Perhaps a different naming scheme would be wise.
--
Chuck Lever
next prev parent reply other threads:[~2020-03-20 17:35 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-11 19:59 [PATCH 00/14] server side user xattr support (RFC 8276) Frank van der Linden
2020-03-11 19:59 ` [PATCH 01/14] nfs,nfsd: NFSv4.2 extended attribute protocol definitions Frank van der Linden
2020-03-11 19:59 ` [PATCH 02/14] xattr: modify vfs_{set,remove}xattr for NFS server use Frank van der Linden
2020-03-12 16:23 ` Chuck Lever
2020-03-13 15:35 ` J. Bruce Fields
2020-03-13 16:07 ` [PATCH 02/14] xattr: modify vfs_{set, remove}xattr " Frank van der Linden
2020-03-13 21:06 ` J. Bruce Fields
2020-03-11 19:59 ` [PATCH 03/14] nfsd: split off the write decode code in to a separate function Frank van der Linden
2020-03-11 19:59 ` [PATCH 04/14] nfsd: make sure the nfsd4_ops array has the right size Frank van der Linden
2020-03-11 19:59 ` [PATCH 05/14] nfsd: add defines for NFSv4.2 extended attribute support Frank van der Linden
2020-03-12 16:23 ` Chuck Lever
2020-03-11 19:59 ` [PATCH 06/14] nfsd: define xattr functions to call in to their vfs counterparts Frank van der Linden
2020-03-12 7:37 ` kbuild test robot
2020-03-12 16:23 ` Chuck Lever
2020-03-12 17:16 ` Frank van der Linden
2020-03-12 17:57 ` Chuck Lever
2020-03-11 19:59 ` [PATCH 07/14] nfsd: take xattr bits in to account for permission checks Frank van der Linden
2020-03-11 19:59 ` [PATCH 08/14] nfsd: add structure definitions for xattr requests / responses Frank van der Linden
2020-03-11 19:59 ` [PATCH 09/14] nfsd: use kvmalloc in svcxdr_tmpalloc Frank van der Linden
2020-03-11 19:59 ` [PATCH 10/14] nfsd: implement the xattr procedure functions Frank van der Linden
2020-03-12 10:28 ` kbuild test robot
2020-03-12 16:24 ` Chuck Lever
2020-03-11 19:59 ` [PATCH 11/14] nfsd: add user xattr RPC XDR encoding/decoding logic Frank van der Linden
2020-03-12 13:28 ` kbuild test robot
2020-03-12 16:24 ` Chuck Lever
2020-03-19 22:13 ` Frank van der Linden
2020-03-19 22:15 ` Chuck Lever
2020-03-25 23:44 ` Frank van der Linden
2020-03-26 14:12 ` Chuck Lever
2020-03-12 19:16 ` Chuck Lever
2020-03-20 16:47 ` Frank van der Linden
2020-03-20 17:34 ` Chuck Lever [this message]
2020-03-20 17:54 ` J. Bruce Fields
2020-03-20 19:44 ` Frank van der Linden
2020-03-11 19:59 ` [PATCH 12/14] nfsd: add xattr operations to ops array Frank van der Linden
2020-03-11 19:59 ` [PATCH 13/14] xattr: add a function to check if a namespace is supported Frank van der Linden
2020-03-12 16:24 ` Chuck Lever
2020-03-11 19:59 ` [PATCH 14/14] nfsd: add fattr support for user extended attributes Frank van der Linden
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=65ACAC76-DBBE-42D3-ACED-AB2290D0FC31@oracle.com \
--to=chuck.lever@oracle.com \
--cc=bfields@redhat.com \
--cc=fllinden@amazon.com \
--cc=linux-nfs@vger.kernel.org \
/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).