Skip to content

improve server readdir tracing#167

Merged
mergify[bot] merged 7 commits intochaos:masterfrom
garlick:improve_logging
Dec 15, 2025
Merged

improve server readdir tracing#167
mergify[bot] merged 7 commits intochaos:masterfrom
garlick:improve_logging

Conversation

@garlick
Copy link
Member

@garlick garlick commented Dec 15, 2025

Problem: while working on #164, it became annoying that the full Rreaddir response is not decoded.

Fix that.

Now we see the dentry list, e.g.

Treaddir tag 0 fid 5 offset 0 count 131072
Rreaddir tag 0 count 394
(00000000011a8d8f 0 'f') 1 1725168369444669560   fifo
(000000000120897a 0 'd') 4 2406942611298167068   dir3
(00000000011a8d8e 0 'f') 8 4671125154514956581   tmp.LILS8sHwr5
(00000000011a753d 0 'd') 4 5873022782738206309   .
(00000000011a8d96 0 'f') 8 6514729600774571764   atomic_create
(000000000120897c 0 'd') 4 6723614288805761838   tcldir
(00000000011a8d91 0 'f') 8 6744965991701839233   stream
(0000000001208d66 0 'd') 4 7096463625030314513   ptest
(000000000120897b 0 'd') 4 7319762193862366776   tmp.6H2KzPr6Dm
(000000000120897d 0 'd') 4 7424074472310643538   bigdir
(00000000011a7122 0 'd') 4 7783225010864674464   ..
(00000000011a8d89 0 'd') 4 8537224575454833544   dir2
(00000000011a7b1b 0 'd') 4 9223372036854775807   dir
Treaddir tag 0 fid 5 offset 9223372036854775807 count 131072
Rreaddir tag 0 count 0

where before the list of dirents was only a truncated hex dump

Problem: the Npsrv->logmsg() callback is a printf style function,
but protocol tracing requires the server implementation to print
large, pre-formatted buffers.

Convert the callback to a puts() style signature.
Update the diod logmsg callback.
Update unit tests that register libnpfs logmsg callbacks
Copy link
Member

@grondo grondo left a comment

Choose a reason for hiding this comment

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

LGTM!

I mainly noted some spots where it appeared that perhaps there was a mix of tab vs space in the github diff view.

Comment on lines 140 to 144
n = snprintf (buf,
size,
"[%"PRIdMAX".%-3"PRIdMAX"] ",
(intmax_t)c.tv_sec,
(intmax_t)c.tv_usec/1000);
Copy link
Member

Choose a reason for hiding this comment

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

Check spacing here. Alignment is off in the diff view.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. libnpfs uses linux kernel style indent (tabs only), so alignment is not expected. I was improperly mixing in spaces without thinking.

Comment on lines 134 to 135
if (vsnprintf (s, len, fmt, ap) >= len)
strncpy (&s[len - 4], "...", 4);
Copy link
Member

Choose a reason for hiding this comment

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

Another alignment issue (tab vs space?)

Comment on lines 107 to 110
res = np_deserialize_p9dirent (&qid,
&offset,
&type,
dname,
Copy link
Member

Choose a reason for hiding this comment

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

Check tab vs space here as well.

Comment on lines 47 to 48
if (q->type == Qtfile)
buf[n++] = 'f';
Copy link
Member

Choose a reason for hiding this comment

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

Just double checking that the test here shouldn't be (q->type & Qtfile) as in the previous test for Qtsymlink? (I guess this makes sense if f is a fallthrough test for regular files that are not other types, but just wanted to double check after noticing the difference)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is confusing. The value of Qtfile is zero so really part of this field is an enum and part is a bitfield. I restructured the function to make that more obvious and added a commit to fix a couple of other places where Qtfile's value was confusingly assumed to be zero.

Problem: protocol tracing truncates messages at 1024 bytes in
np_logmsg(), but decoding dentries in Rreaddir will require a
larger buffer.

Allocate a 1 mbyte buffer in Npsrv and use it for trace formatting.
Pass this buffer to the implementation Npsrv->logmsg() callback,
bypassing np_logmsg().
Problem: spaces and tabs are used inconsistently in npstring.c.

Use tabs for code indentation.
Problem: there is no indication in the output when the protocol trace
buffer is truncated due to overflow.

Print "..." in that case.
Problem: the Rreaddir protocol trace shows a (truncated) hex dump
for the list of dentries, which is not super helpful.

Decode the dentries.
Problem: nothing is printed in the qid type field for type Qtfile (0).

If none of the other "base type" bits (Qtdir, Qtauth, Qtsymlink, Qtlink)
are set, assume Qtfile and render that as 'f'.

Also, Qtlink was missing so render it as 'l' and change Qtexcl
from 'l' to 'x'.
Problem: initializion of qid.type from a 'struct stat' or
'struct dirent' is confusing.

These functions set the qid.type "base type" to either
Qtfile, Qtdir, or Qtsymlink.  Just do that instead of
relying on the fact that Qtfile has a value of zero
and ORing in the other values.
@mergify mergify bot added the queued label Dec 15, 2025
@mergify mergify bot merged commit 799aa47 into chaos:master Dec 15, 2025
7 checks passed
@mergify
Copy link
Contributor

mergify bot commented Dec 15, 2025

Merge Queue Status

✅ The pull request has been merged at 2dc8a32

This pull request spent 6 seconds in the queue, with no time running CI.
The checks were run in-place.

Required conditions to merge

@mergify mergify bot removed the queued label Dec 15, 2025
@garlick garlick deleted the improve_logging branch December 15, 2025 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants