]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
s390/debug: Add debug_dump() to write debug view to a string buffer
authorNiklas Schnelle <schnelle@linux.ibm.com>
Fri, 13 Dec 2024 13:47:31 +0000 (14:47 +0100)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Mon, 16 Dec 2024 15:14:26 +0000 (16:14 +0100)
The debug_dump() function allows to get the content of a debug log and
view pair in a string buffer. One future application of this is to
provide debug logs to the platform to be collected with hardware error
logs during recovery.

Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Co-developed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
arch/s390/include/asm/debug.h
arch/s390/kernel/debug.c

index a7f7bdc9e19cae7ee15288a2c8093e75da62dc61..ec30f6f421a7a7aa70ab8797636a361f5b1d4a5c 100644 (file)
@@ -114,6 +114,9 @@ debug_info_t *debug_register_mode(const char *name, int pages, int nr_areas,
                                  int buf_size, umode_t mode, uid_t uid,
                                  gid_t gid);
 
+ssize_t debug_dump(debug_info_t *id, struct debug_view *view,
+                  char *buf, size_t buf_size);
+
 void debug_unregister(debug_info_t *id);
 
 void debug_set_level(debug_info_t *id, int new_level);
index 463c9a19a3b59388283ff47a99965ad04ba76115..2040b96d4cb39879e49a452da97756ef9fe8ecb0 100644 (file)
@@ -632,6 +632,53 @@ static int debug_close(struct inode *inode, struct file *file)
        return 0; /* success */
 }
 
+/**
+ * debug_dump - Get a textual representation of debug info, or as much as fits
+ * @id:                Debug information to use
+ * @view:      View with which to dump the debug information
+ * @buf:       Buffer the textual debug data representation is written to
+ * @buf_size:  Size of the buffer, including the trailing '\0' byte
+ *
+ * This function may be used whenever a textual representation of the debug
+ * information is required without using an s390dbf file.
+ *
+ * Note: It is the callers responsibility to supply a view that is compatible
+ * with the debug information data.
+ *
+ * Return: On success returns the number of bytes written to the buffer not
+ * including the trailing '\0' byte. If bug_size == 0 the function returns 0.
+ * On failure an error code less than 0 is returned.
+ */
+ssize_t debug_dump(debug_info_t *id, struct debug_view *view,
+                  char *buf, size_t buf_size)
+{
+       file_private_info_t *p_info;
+       size_t size, offset = 0;
+
+       /* Need space for '\0' byte */
+       if (buf_size < 1)
+               return 0;
+       buf_size--;
+
+       p_info = debug_file_private_alloc(id, view);
+       if (!p_info)
+               return -ENOMEM;
+
+       /* There is always at least the DEBUG_PROLOG_ENTRY */
+       do {
+               size = debug_format_entry(p_info);
+               size = min(size, buf_size - offset);
+               memcpy(buf + offset, p_info->temp_buf, size);
+               offset += size;
+               if (offset >= buf_size)
+                       break;
+       } while (debug_next_entry(p_info));
+       debug_file_private_free(p_info);
+       buf[offset] = '\0';
+
+       return offset;
+}
+
 /* Create debugfs entries and add to internal list. */
 static void _debug_register(debug_info_t *id)
 {