Skip to content

lsns: minor refactoring #3006

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

Merged
merged 10 commits into from
May 13, 2024

Conversation

masatake
Copy link
Member

@masatake masatake commented May 1, 2024

While inspecting #2982 and #2987, I found some areas where I could improve the readability of the source code.

Here is a figure I used during the inspection and refactoring.
image

masatake added 8 commits May 1, 2024 11:07
Functions taking LSNS_ID_ as arguments have .*_lsns_type_.* or
.*_type_.* as parts of their name. This implies the prefix LSNS_TYPE_
is more consistent than LSNS_ID_.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
…umerators

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
…rts of get_ns_ino()

get_ns_ino() returns three inode numbers. The code for the two of three,
inodes for PARENT and USERNS, is moved to the new functions.
So we can reuse the code in other places in lsns.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
…_nsfd

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
The function gets three inode numbers.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
read_related_namespaces() itself doesn't read names of new namespaces.
Connecting namespaces for making a tree is the the main job the function.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
…stent

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
In read_open_ns_inos(), a namespace is added to the list without
verifying its uniqueness in the list.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>

*ino = 0;
if (ul_path_stat(pc, &st, 0, path) != 0)
return -errno;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we need to add

   ul_path_statf(struct path_cxt *pc, struct stat *sb, int flags, const char *path, ...)

to lib/path.c to avoid snprintf() and the path[]. And then we can use ul_path_statf(PC, &st, 0, "ns/%s", nsname);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented (but not tested yet): #3007

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chrry-pick'ed #3007 to this pull request.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll apply the openf and statf to lsfd in another pull request.

@karelzak
Copy link
Collaborator

karelzak commented May 2, 2024

Looks good, thanks!

@masatake masatake changed the title lsns: mino rrefactoring lsns: minor rrefactoring May 2, 2024
@masatake masatake changed the title lsns: minor rrefactoring lsns: minor refactoring May 2, 2024
karelzak and others added 2 commits May 3, 2024 06:56
Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit 9b47899)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
@karelzak karelzak merged commit 14d3e1f into util-linux:master May 13, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants