-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib/ramfs: Ensure stability of inode numbers #996
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems OK, thanks @andreittr! I left some minor nitpicks
@@ -47,6 +47,7 @@ struct ramfs_node { | |||
* else NULL | |||
*/ | |||
struct ramfs_node *rn_child; | |||
uint64_t rn_ino; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment about the need for this member in the structure.
@@ -93,6 +93,8 @@ ramfs_allocate_node(const char *name, int type) | |||
strlcpy(np->rn_name, name, np->rn_namelen + 1); | |||
np->rn_type = type; | |||
|
|||
np->rn_ino = inode_count++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have an empty line before?
@andreittr, is it intended to open the file without the I am asking this since for Linux, it creates a file, but the inode number differs at the second attempt or running (0 vs a large number). |
Yes, the test snippet assumes "file" exists and is a regular file created ahead of time (e.g. already included in the ramfs/initrd) |
@andreittr The changes look fine, however I wasn't able to reproduce the issue. Could you please share a bit more regarding your setup? This is what I've tested: int main(void)
{
struct stat st1 = {0};
struct stat st2 = {0};
int f = open("file", O_CREAT);
fstat(f, &st1);
stat("file", &st2);
printf("Should be same: %ld %ld\n", st1.st_ino, st2.st_ino);
} And this is the output: Notice how the break point at which the static variable should be incremented is reached only once. |
Hi! See the above comment as well as the test snippet in the description. |
Previously ramfs would assign a new unique inode number to a file on every successful filesystem lookup. This can lead to the same file being allocated multiple different inodes, breaking code that (correctly) uses inodes as reliable indicators of file identity. This change makes inode numbers persistent, allocated along with the filesystem node, and stable across multiple lookups of the same file. Signed-off-by: Andrei Tatar <andrei@unikraft.io>
191a002
to
43ee1db
Compare
Pushed changes addressing comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, all good on my side, then. Let's merge this!
Reviewed-by: Maria Sfiraiala maria.sfiraiala@gmail.com
It works for me as well. I used something more hackish: int main(void)
{
struct stat st1, st2;
int f = open("file", O_CREAT);
fstat(f, &st1);
close(f);
f = open("file", O_RDONLY);
stat("file", &st2);
printf("Should be same: %ld %ld\n", st1.st_ino, st2.st_ino);
close(f);
return 0;
} but it does the trick Thanks, @andreittr Reviewed-by: Radu Nichita radunichita99@gmail.com |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved-by: Razvan Deaconescu razvand@unikraft.io
Description of changes
Previously ramfs would assign a new unique inode number to a file on every successful filesystem lookup. This can lead to the same file being allocated multiple different inodes, breaking code that (correctly) uses inodes as reliable indicators of file identity.
This change makes inode numbers persistent, allocated along with the filesystem node, and stable across multiple lookups of the same file.
Prerequisite checklist
checkpatch.uk
on your commit series before opening this PR;Base target
Additional configuration
Test with: