Re: [for-linus][PATCH 1/3] eventfs: Have the inodes all for files and directories all be the same

From: Steven Rostedt
Date: Fri Jan 26 2024 - 11:26:34 EST


On Fri, 26 Jan 2024 11:11:39 +0100
Christian Brauner <brauner@xxxxxxxxxx> wrote:

> The size would be one thing. The other is that tar requires unique inode
> numbers for all files iirc (That's why we have this whole btrfs problem
> - let's not get into this here - where inode numbers aren't unique and
> are duplicated per subvolume.).

Well, I guess that answers Linus's question about wondering if there's any
user space program that actually cares what the inodes are for files. The
answer is "yes" and the program is "tar".

And because tar cares, I think I should fix it for tracefs even if it
doesn't work because of size. But the size issue is a trivial fix if I just
default it to 1 page.

I currently use get_next_ino(), but I can use my own version of that, and
because each directory has a fixed number of files, I could have it be:

/* Copied from get_next_ino but adds allocation for multiple inodes */
#define LAST_INO_BATCH 1024
#define LAST_INO_MASK (~(LAST_INO_BATCH - 1))
static DEFINE_PER_CPU(unsigned int, last_ino);

unsigned int tracefs_get_next_ino(int files)
{
unsigned int *p = &get_cpu_var(last_ino);
unsigned int res = *p;

#ifdef CONFIG_SMP
/* Check if adding files+1 overflows */
if (unlikely(!res || (res & LAST_INO_MASK) != ((res + files + 1) & LAST_INO_MASK))) {
static atomic_t shared_last_ino;
int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);

res = next - LAST_INO_BATCH;
}
#endif

res++;
/* get_next_ino should not provide a 0 inode number */
if (unlikely(!res))
res++;
*p = res + files;
put_cpu_var(last_ino);
return res;
}


This way the eventfs inode would tell tracefs_get_next_ino() how many inode
numbers it needs for its files and then when it creates the file inode, it
can use:

inode->i_ino = ei->ino + idx;

Where idx is the index into the d_children array of the directory's
eventfs_inode.

-- Steve