From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Christophe de Dinechin <dinechin@redhat.com>
Cc: virtio-fs@redhat.com, stefanha@redhat.com, vgoyal@redhat.com,
qemu-devel@nongnu.org
Subject: Re: [PATCH v2 5/6] tools/virtiofsd: xattr name mappings: Map server xattr names
Date: Wed, 14 Oct 2020 17:04:33 +0100 [thread overview]
Message-ID: <20201014160433.GB20147@work-vm> (raw)
In-Reply-To: <lyft6rl4th.fsf@redhat.com>
* Christophe de Dinechin (dinechin@redhat.com) wrote:
>
> On 2020-08-27 at 17:36 CEST, Dr. David Alan Gilbert (git) wrote...
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> >
> > Map xattr names coming from the server, i.e. the host filesystem;
> > currently this is only from listxattr.
> >
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > ---
> > tools/virtiofsd/passthrough_ll.c | 88 ++++++++++++++++++++++++++++++++
> > 1 file changed, 88 insertions(+)
> >
> > diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
> > index 9b9c8f3ab1..7cd99186f7 100644
> > --- a/tools/virtiofsd/passthrough_ll.c
> > +++ b/tools/virtiofsd/passthrough_ll.c
> > @@ -2188,6 +2188,42 @@ static int xattr_map_client(const char *client_name, char **out_name)
> > abort();
> > }
> >
> > +/*
> > + * For use with listxattr where the server fs gives us a name and we may need
> > + * to sanitize this for the client.
> > + * Returns a pointer to the result in *out_name
> > + * This is always the original string or the current string with some prefix
> > + * removed; no reallocation is done.
> > + * Returns 0 on success
> > + * Can return -ENODATA to indicate the name should be dropped from the list.
> > + */
> > +static int xattr_map_server(const char *server_name, const char **out_name)
>
> > +{
> > + const XattrMapEntry *cur_entry;
> > + for (cur_entry = xattr_map_list; ; cur_entry++) {
> > + if ((cur_entry->flags & XATTR_MAP_FLAG_SERVER) &&
> > + (!strncmp(cur_entry->prepend,
> > + server_name,
> > + strlen(cur_entry->prepend)))) {
>
> Might be slightly clearer (and possibly faster) as
>
> strstart(cur_entry->prepend, server_name, &end)
I think this is actually,
strstart(server_name, cur_entry->prepend, &end)
because I think strstart writes the offset into the 1st string
into &end expecting the 2nd string to be the thing to test for.
Agreed?
> > + if (cur_entry->flags & XATTR_MAP_FLAG_END_BAD) {
> > + return -ENODATA;
> > + }
> > + if (cur_entry->flags & XATTR_MAP_FLAG_END_OK) {
> > + *out_name = server_name;
> > + return 0;
> > + }
> > + if (cur_entry->flags & XATTR_MAP_FLAG_PREFIX) {
> > + /* Remove prefix */
> > + *out_name = server_name + strlen(cur_entry->prepend);
>
> With the above, that would be
>
> *out_name = end;
OK.
>
> > + return 0;
> > + }
> > + }
> > + }
> > +
> > + /* Shouldn't get here - rules should have an END_* */
>
> You probably want to point the finger back to parse_xattrmap() in the comment?
Done.
> > + abort();
>
> > +}
> > +
> > static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name,
> > size_t size)
> > {
> > @@ -2342,8 +2378,60 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size)
> > if (ret == 0) {
> > goto out;
> > }
> > +
> > + if (lo->xattrmap) {
>
> If you put the "XattrMapEntry" pointer in lo, then you would probably test that.
Done
>
> > + /*
> > + * Map the names back, some attributes might be dropped,
> > + * some shortened, but not increased, so we shouldn't
> > + * run out of room.
> > + */
> > + size_t out_index, in_index;
> > + out_index = 0;
> > + in_index = 0;
> > + while (in_index < ret) {
> > + const char *map_out;
> > + char *in_ptr = value + in_index;
> > + /* Length of current attribute name */
> > + size_t in_len = strlen(value + in_index) + 1;
> > +
> > + int mapret = xattr_map_server(in_ptr, &map_out);
> > + if (mapret != -ENODATA && mapret != 0) {
> > + /* Shouldn't happen */
> > + saverr = -mapret;
> > + goto out;
> > + }
> > + if (mapret == 0) {
> > + /* Either unchanged, or truncated */
> > + size_t out_len;
> > + if (map_out != in_ptr) {
> > + /* +1 copies the NIL */
> > + out_len = strlen(map_out) + 1;
> > + } else {
> > + /* No change */
> > + out_len = in_len;
> > + }
> > + /*
> > + * Move result along, may still be needed for an unchanged
> > + * entry if a previous entry was changed.
> > + */
> > + memmove(value + out_index, map_out, out_len);
> > +
> > + out_index += out_len;
> > + }
> > + in_index += in_len;
> > + }
> > + ret = out_index;
> > + if (ret == 0) {
> > + goto out;
> > + }
> > + }
> > fuse_reply_buf(req, value, ret);
> > } else {
> > + /*
> > + * xattrmap only ever shortens the result,
> > + * so we don't need to do anything clever with the
> > + * allocation length here.
> > + */
>
> I don't understand the comment above. We are in the !lo->xattrmap) case, no?
No, we're in the else for if (size) { for the case where the caller is
trying not to actually get a list of the attributes, but to get a guess
of the size of storage needed.
Dave
> > fuse_reply_xattr(req, ret);
> > }
> > out_free:
>
>
> --
> Cheers,
> Christophe de Dinechin (IRC c3d)
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2020-10-14 16:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-27 15:36 [PATCH v2 0/6] virtiofsd xattr name mappings Dr. David Alan Gilbert (git)
2020-08-27 15:36 ` [PATCH v2 1/6] virtiofsd: Silence gcc warning Dr. David Alan Gilbert (git)
2020-09-09 11:16 ` Ján Tomko
2020-10-07 10:42 ` Dr. David Alan Gilbert
2020-08-27 15:36 ` [PATCH v2 2/6] virtiofsd: Add printf checking to fuse_log Dr. David Alan Gilbert (git)
2020-08-27 15:36 ` [PATCH v2 3/6] tools/virtiofsd: xattr name mappings: Add option Dr. David Alan Gilbert (git)
2020-09-09 11:20 ` Ján Tomko
2020-09-10 18:38 ` Dr. David Alan Gilbert
2020-09-11 21:13 ` [Virtio-fs] " Vivek Goyal
2020-09-18 17:38 ` Dr. David Alan Gilbert
2020-10-20 17:20 ` Vivek Goyal
2020-10-06 15:51 ` Christophe de Dinechin
2020-10-14 15:40 ` Dr. David Alan Gilbert
2020-08-27 15:36 ` [PATCH v2 4/6] tools/virtiofsd: xattr name mappings: Map client xattr names Dr. David Alan Gilbert (git)
2020-08-27 15:36 ` [PATCH v2 5/6] tools/virtiofsd: xattr name mappings: Map server " Dr. David Alan Gilbert (git)
2020-10-06 16:03 ` Christophe de Dinechin
2020-10-14 16:04 ` Dr. David Alan Gilbert [this message]
2020-10-06 16:17 ` Christophe de Dinechin
2020-08-27 15:36 ` [PATCH v2 6/6] tools/virtiofsd: xattr name mapping examples Dr. David Alan Gilbert (git)
2020-09-09 11:35 ` Ján Tomko
2020-09-10 18:42 ` Dr. David Alan Gilbert
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=20201014160433.GB20147@work-vm \
--to=dgilbert@redhat.com \
--cc=dinechin@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vgoyal@redhat.com \
--cc=virtio-fs@redhat.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;
as well as URLs for NNTP newsgroup(s).