From 3d3e9329e66e2f5de04d6a3d4474cd71a0bf40e0 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/8] 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 82a16b4..18e9f48 100644 --- a/libdiskfs/diskfs.h +++ b/libdiskfs/diskfs.h @@ -591,6 +591,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 #include #include +#include /* 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