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

Add nvlist command to sdb #288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

PaulZ-98
Copy link
Contributor

@PaulZ-98 PaulZ-98 commented Jul 20, 2022

Print all the nvpair_t in the passed nvlist_t. Handle basic types,
array types, and nvlist_t types.

Signed-off-by: Paul Zuchowski [email protected]
Fixes #26

= Problem
nvlist are difficult to display using crash or sdb. Develop a dcmd for displaying all the nvpair in the given nvlist.

= Solution

Develop a SingleInputCommand for nvlist, that displays the various nvpair types, including when the nvpair is nvlist type.

Note the small change to Command, to fix the formatting when a FaultError occurs.

Closes #26

sdb/command.py Outdated
err_msg = "invalid memory access while handling object "
err_msg += "at address {hex(obj.address_of_().value_())}"
err_msg = "invalid memory access while handling object at address %s" % (
hex(obj.address_of_().value_()))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we're preferring to use "f-strings" as we do a couple lines above

Suggested change
hex(obj.address_of_().value_()))
f"at address {hex(obj.address_of_().value_())}"

self.name_size = int(nvp.nvp_name_sz)
self.data_ptr = self.addr + ((self.nvp_size_ + self.name_size + 7) & ~7)

def get_type(self, strip: int = 0) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

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

My python has gotten rusty... would something like strip: bool = false work?

"nvi_nvp")
curr = sdb.create_object("i_nvp_t *", curr_addr)

if priv.nvp_curr == curr or Nvlist.nvlist_contains_nvp(nvl, nvp):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the nvlist_contains_nvp() check really necessary? Seems like it would make overall iteration O(N^2) since every call to next_nvpair() will iterate the whole nvlist. Maybe this isn't a big deal as long as your list isn't TOO long (<1000?)

Copy link
Contributor Author

@PaulZ-98 PaulZ-98 Jul 22, 2022

Choose a reason for hiding this comment

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

Good question. I basically ported
https://src.illumos.org/source/xref/illumos-gate/usr/src/common/nvpair/nvpair.c?r=b8a5bee1#1431
Let me do some experiments to see if or how often nvlist_contains_nvp is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the extra check is there in case the nvlist is having element(s) removed while we're traversing it.

name=seconds_of_rewind type=DATA_TYPE_INT64 value=-1575588901
name=verify_data_errors type=DATA_TYPE_UINT64 value=0
----
sdb: nvlist: invalid memory access while handling object at address 0xffffa089413b8138
Copy link
Contributor

Choose a reason for hiding this comment

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

is this because there's actual a problem with the example dump, or is this a nvlist data type that we don't understand?

@PaulZ-98
Copy link
Contributor Author

Thanks for taking a look @ahrens I'll dig into your comments.

if sdb.is_null(nvl) or sdb.is_null(nvl.nvl_priv):
return None
priv = drgn.cast("nvpriv_t *", nvl.nvl_priv)
return priv.nvp_list.nvi_nvp
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out that priv.nvp_list can be NULL, which is why the test output has the FaultError warning. Will fix.

Print all the nvpair_t in the passed nvlist_t.  Handle basic types,
array types, and nvlist_t types.

Signed-off-by: Paul Zuchowski <[email protected]>
Fixes delphix#26
@dlpx-tfc-github-manager dlpx-tfc-github-manager bot deleted the branch delphix:master January 5, 2023 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Want nvlist and nvpair commands for ZFS
2 participants