On Fri, Jan 31, 2025 at 11:29:05AM -0800, Linus Torvalds wrote: > 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()'. 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.