On Thu, Sep 14, 2023 at 10:50:04AM +0200, Miklos Szeredi wrote: > On Thu, 14 Sept 2023 at 08:00, Amir Goldstein <amir73il@xxxxxxxxx> wrote: > > > > + if (ctr >= bufsize) > > > + return -EOVERFLOW; > > > + if (put_user(r->mnt_id_unique, buf + ctr)) > > > + return -EFAULT; > > > + ctr++; > > > + if (ctr < 0) > > > + return -ERANGE; > > > > I think it'd be good for userspace to be able to query required > > bufsize with NULL buf, listattr style, rather than having to > > guess and re-guess on EOVERFLOW. > > The getxattr/listxattr style encourages the following code: > > size = get(NULL, 0); > buf = alloc(size); > err = get(buf, size); > if (err) > /* failure */ > > Which is wrong, since the needed buffer size could change between the two calls. Not a fan of this either tbh. > > Doing it iteratively is the only correct way, and then adding > complexity to both userspace and the kernel for *optimizing* the > iteration is not really worth it, IMO. So realistically, userspace nows that an upper bound on the number of mounts in a mount namespace (expressed in /proc/sys/fs/mount-max usually 100000 - which is often too much ofc). This is probably insane but I'll power through it: ideally we'd have an iterator interface that keeps state between calls so we can continue iterating similar to how readdir/getdents does.