summaryrefslogtreecommitdiff
path: root/debian/patches/introspection0005-libdiskfs-annotate-objects-managed-by-libports.patch
blob: 1307c70179dbb1fc45a8e6c17fb96c30c05e1b92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
From b9a3b5e3d9200a7ba8959dafa633ece8e46337cd Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Wed, 21 May 2014 18:17:33 +0200
Subject: [PATCH hurd 5/9] libdiskfs: annotate objects managed by libports

Label all port classes and diskfs_port_bucket.  Provide
diskfs_format_debug_info which prints a human-readable description of
a protid object, which notably includes the path and the inode number.

* libdiskfs/diskfs.h (diskfs_format_debug_info): New declaration.
* libdiskfs/init-init.c (diskfs_format_debug_info): New function.
(diskfs_init_diskfs): Add annotations to classes and bucket.
---
 libdiskfs/diskfs.h    |  8 ++++++++
 libdiskfs/init-init.c | 41 ++++++++++++++++++++++++++++++++++++-----
 2 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h
index 106aeb0..b0d8ad3 100644
--- a/libdiskfs/diskfs.h
+++ b/libdiskfs/diskfs.h
@@ -592,6 +592,14 @@ error_t (*diskfs_read_symlink_hook)(struct node *np, char *target);
    default function always returns EOPNOTSUPP. */
 error_t diskfs_get_source (struct protid *cred,
                            char *source, size_t source_len);
+
+/* The user may define this function.  The function must provide a
+   human-readable description of PROTID in BUFFER of size SIZE.  The
+   default implementation generates a reasonable amount of
+   information.  */
+error_t diskfs_format_debug_info (const void *protid,
+				  char *buffer, size_t size);
+
 
 /* Libdiskfs contains a node cache.
 
diff --git a/libdiskfs/init-init.c b/libdiskfs/init-init.c
index 357960b..07714f0 100644
--- a/libdiskfs/init-init.c
+++ b/libdiskfs/init-init.c
@@ -24,6 +24,7 @@
 #include <hurd/fsys.h>
 #include <stdio.h>
 #include <maptime.h>
+#include <inttypes.h>
 
 /* For safe inlining of diskfs_node_disknode and
    diskfs_disknode_node.  */
@@ -52,6 +53,29 @@ struct port_class *diskfs_shutdown_notification_class;
 
 struct port_bucket *diskfs_port_bucket;
 
+/* Provide a human-readable description of the given protid object.  */
+error_t
+diskfs_format_debug_info (const void *port, char *buffer, size_t size)
+{
+  const struct protid *protid = port;
+  const struct port_info *pi = port;
+  struct references references;
+
+  refcounts_references (&protid->po->np->refcounts, &references);
+
+  snprintf (buffer, size,
+	    "bucket: %s, class: %s"
+	    ", node{inode: %"PRIu64", hard: %u, weak: %u}, path: %s",
+	    pi->bucket->label,
+	    pi->class->label,
+	    protid->po->np->cache_id,
+	    references.hard,
+	    references.weak,
+	    protid->po->path);
+
+  return 0;
+}
+
 /* Call this after arguments have been parsed to initialize the
    library.  */
 error_t
@@ -87,13 +111,20 @@ diskfs_init_diskfs (void)
 
   diskfs_auth_server_port = getauth ();
 
-  diskfs_protid_class = ports_create_class (diskfs_protid_rele, 0);
-  diskfs_control_class = ports_create_class (_diskfs_control_clean, 0);
-  diskfs_initboot_class = ports_create_class (0, 0);
-  diskfs_execboot_class = ports_create_class (0, 0);
-  diskfs_shutdown_notification_class = ports_create_class (0, 0);
+#define MAKE_CLASS(NAME, FN, ARG, DBG)					\
+  NAME = ports_create_class ((FN), (ARG));				\
+  ports_label_class (NAME, #NAME, (DBG))
+
+  MAKE_CLASS (diskfs_protid_class, diskfs_protid_rele, NULL,
+	      diskfs_format_debug_info);
+  MAKE_CLASS (diskfs_control_class, _diskfs_control_clean, NULL, NULL);
+  MAKE_CLASS (diskfs_initboot_class, NULL, NULL, NULL);
+  MAKE_CLASS (diskfs_execboot_class, NULL, NULL, NULL);
+  MAKE_CLASS (diskfs_shutdown_notification_class, NULL, NULL, NULL);
+#undef MAKE_CLASS
 
   diskfs_port_bucket = ports_create_bucket ();
+  ports_label_bucket (diskfs_port_bucket, "diskfs_port_bucket");
 
   _hurd_port_init (&_diskfs_exec_portcell, MACH_PORT_NULL);
 
-- 
2.1.4