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 | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/libdiskfs/diskfs.h b/libdiskfs/diskfs.h index e59ba99..d95e231 100644 --- a/libdiskfs/diskfs.h +++ b/libdiskfs/diskfs.h @@ -585,6 +585,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); + /* The library exports the following functions for general use */ diff --git a/libdiskfs/init-init.c b/libdiskfs/init-init.c index 7a7f248..d382735 100644 --- a/libdiskfs/init-init.c +++ b/libdiskfs/init-init.c @@ -24,6 +24,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <hurd/fsys.h> #include <stdio.h> #include <maptime.h> +#include <inttypes.h> /* For safe inlining of diskfs_node_disknode and diskfs_disknode_node. */ @@ -54,6 +55,32 @@ 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; + int hard, weak; + + pthread_spin_lock (&diskfs_node_refcnt_lock); + hard = protid->po->np->references; + weak = protid->po->np->light_references; + pthread_spin_unlock (&diskfs_node_refcnt_lock); + + 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, + hard, + weak, + protid->po->path); + + return 0; +} + /* Call this after arguments have been parsed to initialize the library. */ error_t @@ -89,13 +116,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.1