]> git.karo-electronics.de Git - linux-beck.git/commitdiff
lib/vsprintf: add %*pg format specifier
authorDmitry Monakhov <dmonakhov@openvz.org>
Mon, 13 Apr 2015 12:31:35 +0000 (16:31 +0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 6 Jan 2016 17:55:29 +0000 (12:55 -0500)
This allow to directly print block_device name.
Currently one should use bdevname() with temporal char buffer.
This is very ineffective because bloat stack usage for deep IO call-traces

Example:
%pg  ->    sda, sda1 or loop0p1

[AV: fixed a minor braino - position updates should not be dependent
upon having reached the of buffer]

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Documentation/printk-formats.txt
lib/vsprintf.c

index b784c270105f40e8320cd388cb9a8ef1e2d463f4..6389551bbad6a7971b89e53451428d3b77b4e8d0 100644 (file)
@@ -250,6 +250,12 @@ dentry names:
 
        Passed by reference.
 
+block_device names:
+
+       %pg     sda, sda1 or loop0p1
+
+       For printing name of block_device pointers.
+
 struct va_format:
 
        %pV
index f9cee8e1233c0fe0f626fe2680ca4b9ff9d3153e..ac3f9476b7765bc23ddcaf3db2166d11cd85d24c 100644 (file)
@@ -31,6 +31,9 @@
 #include <linux/dcache.h>
 #include <linux/cred.h>
 #include <net/addrconf.h>
+#ifdef CONFIG_BLOCK
+#include <linux/blkdev.h>
+#endif
 
 #include <asm/page.h>          /* for PAGE_SIZE */
 #include <asm/sections.h>      /* for dereference_function_descriptor() */
@@ -613,6 +616,26 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp
        return buf;
 }
 
+#ifdef CONFIG_BLOCK
+static noinline_for_stack
+char *bdev_name(char *buf, char *end, struct block_device *bdev,
+               struct printf_spec spec, const char *fmt)
+{
+       struct gendisk *hd = bdev->bd_disk;
+       
+       buf = string(buf, end, hd->disk_name, spec);
+       if (bdev->bd_part->partno) {
+               if (isdigit(hd->disk_name[strlen(hd->disk_name)-1])) {
+                       if (buf < end)
+                               *buf = 'p';
+                       buf++;
+               }
+               buf = number(buf, end, bdev->bd_part->partno, spec);
+       }
+       return buf;
+}
+#endif
+
 static noinline_for_stack
 char *symbol_string(char *buf, char *end, void *ptr,
                    struct printf_spec spec, const char *fmt)
@@ -1443,6 +1466,7 @@ int kptr_restrict __read_mostly;
  *           (default assumed to be phys_addr_t, passed by reference)
  * - 'd[234]' For a dentry name (optionally 2-4 last components)
  * - 'D[234]' Same as 'd' but for a struct file
+ * - 'g' For block_device name (gendisk + partition number)
  * - 'C' For a clock, it prints the name (Common Clock Framework) or address
  *       (legacy clock framework) of the clock
  * - 'Cn' For a clock, it prints the name (Common Clock Framework) or address
@@ -1600,6 +1624,11 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
                return dentry_name(buf, end,
                                   ((const struct file *)ptr)->f_path.dentry,
                                   spec, fmt);
+#ifdef CONFIG_BLOCK
+       case 'g':
+               return bdev_name(buf, end, ptr, spec, fmt);
+#endif
+
        }
        spec.flags |= SMALL;
        if (spec.field_width == -1) {