Skip to content
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

helpers: linux: fs: use mount rbtree instead of list #383

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

morbidrsa
Copy link
Contributor

Starting with kernel v6.8 the mnt_list int struct mnt_namespace git converted to a rb-tree.

Reflect this change in drgn's for_each_mount() helper.

@osandov
Copy link
Owner

osandov commented Feb 19, 2024

Thanks, Johannes! Could you please also keep a fallback for the old kernel version? for_each_vma() is a good example of how to do that:

drgn/drgn/helpers/linux/mm.py

Lines 1219 to 1232 in 145ac79

try:
# Since Linux kernel commit 763ecb035029 ("mm: remove the vma linked
# list") (in v6.1), VMAs are stored in a maple tree.
mt = mm.mm_mt.address_of_()
except AttributeError:
# Before that, they are in a linked list.
vma = mm.mmap
while vma:
yield vma
vma = vma.vm_next
else:
type = mm.prog_.type("struct vm_area_struct *")
for _, _, entry in mt_for_each(mt):
yield cast(type, entry)
. CONTRIBUTING.rst also has a Linux Kernel Helpers section.

@morbidrsa
Copy link
Contributor Author

Sure will send an update soon

@osandov
Copy link
Owner

osandov commented Feb 22, 2024

Here's another example I just had to do: 718da44. Let me know if you need any more pointers or if you'd like me to take it from here.

@morbidrsa
Copy link
Contributor Author

Here's another example I just had to do: 718da44. Let me know if you need any more pointers or if you'd like me to take it from here.

Hi Omar, no there's no problem, I just didn't have time to do the update. I'm stuck debugging a btrfs issue.

@morbidrsa morbidrsa force-pushed the for_each_mnt-fix branch 4 times, most recently from 7adaf64 to 43070f0 Compare February 23, 2024 10:08
Starting with kernel v6.8 the mnt_list int struct mnt_namespace git
converted to a rb-tree.

Reflect this change in drgn's for_each_mount() helper.

Signed-off-by: Johannes Thumshirn <[email protected]>
Copy link
Owner

@osandov osandov left a comment

Choose a reason for hiding this comment

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

Thanks! Just a couple of nits.

Comment on lines +314 to +319
try:
mounts = list_for_each_entry("struct mount", ns.list.address_of_(), "mnt_list")
except AttributeError:
mounts = rbtree_inorder_for_each_entry(
"struct mount", ns.mounts.address_of_(), "mnt_node"
)
Copy link
Owner

Choose a reason for hiding this comment

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

Just a couple of nits documented in CONTRIBUTING.rst:

  1. Add a comment documenting the version divergence.
  2. Put the case for the latest kernel first.
Suggested change
try:
mounts = list_for_each_entry("struct mount", ns.list.address_of_(), "mnt_list")
except AttributeError:
mounts = rbtree_inorder_for_each_entry(
"struct mount", ns.mounts.address_of_(), "mnt_node"
)
# Since Linux kernel commit 2eea9ce4310d ("mounts: keep list of mounts in
# an rbtree") (in v6.8), the mounts in a namespace are in a red-black tree.
# Before that, they're in a list.
try:
mounts = rbtree_inorder_for_each_entry(
"struct mount", ns.mounts.address_of_(), "mnt_node"
)
except AttributeError:
mounts = list_for_each_entry("struct mount", ns.list.address_of_(), "mnt_list")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately that made the CI unhappy when I tried it.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, I see, struct mnt_namespace previously had a member named mounts which was the number of mounts, so the AttributeError doesn't trigger in the try. Okay, let's just add the comment.

Copy link
Owner

@osandov osandov left a comment

Choose a reason for hiding this comment

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

I have a related fix for path_lookup(), so I'll add the comment on my end. Thanks!

@osandov osandov merged commit f8354ae into osandov:main Feb 27, 2024
38 checks passed
@morbidrsa morbidrsa deleted the for_each_mnt-fix branch March 4, 2024 11:19
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