All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH][RFC] add a string-to-qstr constructor
Date: Fri, 31 Jan 2025 20:41:11 +0000	[thread overview]
Message-ID: <20250131204111.GY1977892@ZenIV> (raw)
In-Reply-To: <CAHk-=wg0FbExNA0nHe=VcJy1j=uNY-YvkzQcTCCOEALwPuWzBw@mail.gmail.com>

On Fri, Jan 31, 2025 at 11:29:05AM -0800, Linus Torvalds wrote:
> On Fri, 31 Jan 2025 at 00:32, Al Viro <viro@zeniv.linux.org.uk> wrote:
> >
> > This commit lifts definition(s) of QSTR() into linux/dcache.h,
> > converts it to compound literal (all bcachefs users are fine
> > with that) and converts assorted open-coded instances to using
> > that.
> 
> Looks fine to me. I do wonder if the cast to 'struct qstr' should be
> part of QSTR_INIT, so that you can use that the same way when you
> already know the length.
> 
> We have code like this in fs/overlayfs/namei.c:
> 
>         *name = (struct qstr) QSTR_INIT(n, s - n);
> 
> in bcachefs has
> 
>         return (struct qstr) QSTR_INIT(d.v->d_name, bch2_dirent_name_bytes(d));
> 
> So both of them would seem to want to have that cast as part of the
> QSTR_INIT() thing.
> 
> Or maybe we could just make QSTR() itself more powerful, and do
> something like this:
> 
>     #define QSTR_INIT(n, l, ...) { { { .len = l } }, .name = n }
>     #define QSTR(a, ...) (struct qstr) QSTR_INIT(a , ## __VA_ARGS__, strlen(a))
> 
> which allows you to write either "QSTR(str)" or "QSTR(str, len)", and
> defaults to using 'strlen()' when no length is given.
> 
> Because if we have heper macros, let's make them _helpful_.
>
> Side note: you missed a few places in the core VFS code that could
> also use this new cleanup:
> 
>         struct qstr this = QSTR_INIT("pts", 3);
>         ...
>         child = d_hash_and_lookup(parent, &this);
> 
> can now be just
> 
>         child = d_hash_and_lookup(parent, &QSTR("pts"));
> 
> but sadly a few more are static initializers and can't use 'strlen()'.

There's also this in fs/fuse/inode.c
                const struct qstr name = QSTR_INIT(".", 1);
and
        struct qstr null_name = QSTR_INIT(NULL_FILE_NAME,
						  sizeof(NULL_FILE_NAME)-1);
in selinuxfs - I wasn't trying to get them all, just the infrastructure
and enough examples to demonstrate the usefulness.  Once the definition
is merged, those could be switched at leisure.

      reply	other threads:[~2025-01-31 20:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-31  8:32 [PATCH][RFC] add a string-to-qstr constructor Al Viro
2025-01-31 19:29 ` Linus Torvalds
2025-01-31 20:41   ` Al Viro [this message]

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=20250131204111.GY1977892@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.