... | ... | ||
---|---|---|---|
4 | whereas all other 9p request types work on numeric file IDs (FIDs) only. | 4 | whereas all other 9p request types work on numeric file IDs (FIDs) only. |
5 | 5 | ||
6 | Improve tracing of 'Twalk' requests, e.g. let's say client wanted to walk | 6 | Improve tracing of 'Twalk' requests, e.g. let's say client wanted to walk |
7 | to "/home/bob/src", then improve trace output from: | 7 | to "/home/bob/src", then improve trace output from: |
8 | 8 | ||
9 | v9fs_walk tag 0 id 110 fid 0 newfid 1 nwnames=3 | 9 | v9fs_walk tag 0 id 110 fid 0 newfid 1 nwnames 3 |
10 | 10 | ||
11 | to: | 11 | to: |
12 | 12 | ||
13 | v9fs_walk tag=0 id=110 fid=0 newfid=1 nwnames=3 wnames={home, bob, src} | 13 | v9fs_walk tag=0 id=110 fid=0 newfid=1 nwnames=3 wnames={home, bob, src} |
14 | 14 | ||
15 | To achieve this, add a new helper function trace_v9fs_walk_wnames() which | 15 | To achieve this, add a new helper function trace_v9fs_walk_wnames() which |
16 | converts the received V9fsString array of individual path elements into a | 16 | converts the received V9fsString array of individual path elements into a |
17 | comma-separated string presentation for being passed to the tracing system. | 17 | comma-separated string presentation for being passed to the tracing system. |
18 | As this conversion is somewhat expensive, this new helper function returns | 18 | As this conversion is somewhat expensive, this conversion function is only |
19 | immediately if tracing of event 'v9fs_walk' is currently not enabled. | 19 | called if tracing of event 'v9fs_walk' is currently enabled. |
20 | 20 | ||
21 | Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> | 21 | Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> |
22 | Reviewed-by: Greg Kurz <groug@kaod.org> | ||
22 | --- | 23 | --- |
23 | CCing tracing maintainers in case they have better ideas how to do this. | 24 | V2: |
25 | - Use trace_event_get_state_backends(TRACE_V9FS_WALK) instead of | ||
26 | trace_event_get_state(TRACE_V9FS_WALK) && qemu_loglevel_mask(LOG_TRACE). | ||
27 | - Move that check from helper function trace_v9fs_walk_wnames() to caller | ||
28 | function v9fs_walk(). | ||
24 | 29 | ||
25 | hw/9pfs/9p.c | 42 +++++++++++++++++++++++++++++++++++++----- | 30 | hw/9pfs/9p.c | 36 +++++++++++++++++++++++++++++++----- |
26 | hw/9pfs/trace-events | 2 +- | 31 | hw/9pfs/trace-events | 2 +- |
27 | 2 files changed, 38 insertions(+), 6 deletions(-) | 32 | 2 files changed, 32 insertions(+), 6 deletions(-) |
28 | 33 | ||
29 | diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c | 34 | diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c |
30 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/hw/9pfs/9p.c | 36 | --- a/hw/9pfs/9p.c |
32 | +++ b/hw/9pfs/9p.c | 37 | +++ b/hw/9pfs/9p.c |
33 | @@ -XXX,XX +XXX,XX @@ static bool same_stat_id(const struct stat *a, const struct stat *b) | 38 | @@ -XXX,XX +XXX,XX @@ static bool same_stat_id(const struct stat *a, const struct stat *b) |
34 | return a->st_dev == b->st_dev && a->st_ino == b->st_ino; | 39 | return a->st_dev == b->st_dev && a->st_ino == b->st_ino; |
35 | } | 40 | } |
36 | 41 | ||
37 | +/* | 42 | +/* |
38 | + * Returns a (newly allocated) comma-separated string presentation of the | 43 | + * Returns a (newly allocated) comma-separated string presentation of the |
39 | + * passed array for logging (tracing) purpose for trace event "v9fs_walk" only. | 44 | + * passed array for logging (tracing) purpose for trace event "v9fs_walk". |
40 | + * If tracing for that event is disabled, it immediately returns NULL instead. | ||
41 | + * | 45 | + * |
42 | + * It is caller's responsibility to free the returned string. | 46 | + * It is caller's responsibility to free the returned string. |
43 | + */ | 47 | + */ |
44 | +static char *trace_v9fs_walk_wnames(V9fsString *wnames, size_t nwnames) | 48 | +static char *trace_v9fs_walk_wnames(V9fsString *wnames, size_t nwnames) |
45 | +{ | 49 | +{ |
46 | + g_autofree char **arr = NULL; | 50 | + g_autofree char **arr = g_malloc0_n(nwnames + 1, sizeof(char *)); |
47 | + | 51 | + for (size_t i = 0; i < nwnames; ++i) { |
48 | + if (trace_event_get_state(TRACE_V9FS_WALK) && | 52 | + arr[i] = wnames[i].data; |
49 | + qemu_loglevel_mask(LOG_TRACE)) | ||
50 | + { | ||
51 | + arr = g_malloc0_n(nwnames + 1, sizeof(char *)); | ||
52 | + for (size_t i = 0; i < nwnames; ++i) { | ||
53 | + arr[i] = wnames[i].data; | ||
54 | + } | ||
55 | + return g_strjoinv(", ", arr); | ||
56 | + } | 53 | + } |
57 | + | 54 | + return g_strjoinv(", ", arr); |
58 | + return NULL; | ||
59 | +} | 55 | +} |
60 | + | 56 | + |
61 | static void coroutine_fn v9fs_walk(void *opaque) | 57 | static void coroutine_fn v9fs_walk(void *opaque) |
62 | { | 58 | { |
63 | int name_idx, nwalked; | 59 | int name_idx, nwalked; |
... | ... | ||
94 | - goto out_nofid; | 90 | - goto out_nofid; |
95 | + goto out_nofid_nownames; | 91 | + goto out_nofid_nownames; |
96 | } | 92 | } |
97 | offset += err; | 93 | offset += err; |
98 | } | 94 | } |
99 | + trace_wnames = trace_v9fs_walk_wnames(wnames, nwnames); | 95 | + if (trace_event_get_state_backends(TRACE_V9FS_WALK)) { |
100 | + trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames, trace_wnames); | 96 | + trace_wnames = trace_v9fs_walk_wnames(wnames, nwnames); |
97 | + trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames, | ||
98 | + trace_wnames); | ||
99 | + } | ||
101 | + } else { | 100 | + } else { |
102 | + trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames, ""); | 101 | + trace_v9fs_walk(pdu->tag, pdu->id, fid, newfid, nwnames, ""); |
103 | } | 102 | } |
104 | + | 103 | + |
105 | fidp = get_fid(pdu, fid); | 104 | fidp = get_fid(pdu, fid); |
... | ... | diff view generated by jsdifflib |