Re: [PATCH][RFC] add a string-to-qstr constructor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 31 Jan 2025 at 00:32, Al Viro <viro@xxxxxxxxxxxxxxxxxx> 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()'.

          Linus




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux