ubifs: Add logging functions for ubifs_msg, ubifs_err and ubifs_warn
authorJoe Perches <joe@perches.com>
Tue, 23 Feb 2016 12:13:49 +0000 (04:13 -0800)
committerRichard Weinberger <richard@nod.at>
Sun, 20 Mar 2016 20:36:05 +0000 (21:36 +0100)
The existing logging macros are fairly large and converting the
macros to functions make the object code smaller.

Use %pV and __builtin_return_address(0) as appropriate.

$ size fs/ubifs/built-in.o*
   text    data     bss     dec     hex filename
 575831  309688  161312 1046831   ff92f fs/ubifs/built-in.o.allyesconfig.new
 622457  312872  161120 1096449  10bb01 fs/ubifs/built-in.o.allyesconfig.old
 223785     640     644  225069   36f2d fs/ubifs/built-in.o.defconfig.new
 251873     640     644  253157   3dce5 fs/ubifs/built-in.o.defconfig.old

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
fs/ubifs/Makefile
fs/ubifs/misc.c [new file with mode: 0644]
fs/ubifs/ubifs.h

index 2c6f0cb..c54a243 100644 (file)
@@ -4,3 +4,4 @@ ubifs-y += shrinker.o journal.o file.o dir.o super.o sb.o io.o
 ubifs-y += tnc.o master.o scan.o replay.o log.o commit.o gc.o orphan.o
 ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o
 ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o xattr.o debug.o
+ubifs-y += misc.o
diff --git a/fs/ubifs/misc.c b/fs/ubifs/misc.c
new file mode 100644 (file)
index 0000000..486a284
--- /dev/null
@@ -0,0 +1,57 @@
+#include <linux/kernel.h>
+#include "ubifs.h"
+
+/* Normal UBIFS messages */
+void ubifs_msg(const struct ubifs_info *c, const char *fmt, ...)
+{
+       struct va_format vaf;
+       va_list args;
+
+       va_start(args, fmt);
+
+       vaf.fmt = fmt;
+       vaf.va = &args;
+
+       pr_notice("UBIFS (ubi%d:%d): %pV\n",
+                 c->vi.ubi_num, c->vi.vol_id, &vaf);
+
+       va_end(args);
+}                                                                  \
+
+/* UBIFS error messages */
+void ubifs_err(const struct ubifs_info *c, const char *fmt, ...)
+{
+       struct va_format vaf;
+       va_list args;
+
+       va_start(args, fmt);
+
+       vaf.fmt = fmt;
+       vaf.va = &args;
+
+       pr_err("UBIFS error (ubi%d:%d pid %d): %ps: %pV\n",
+              c->vi.ubi_num, c->vi.vol_id, current->pid,
+              __builtin_return_address(0),
+              &vaf);
+
+       va_end(args);
+}                                                                  \
+
+/* UBIFS warning messages */
+void ubifs_warn(const struct ubifs_info *c, const char *fmt, ...)
+{
+       struct va_format vaf;
+       va_list args;
+
+       va_start(args, fmt);
+
+       vaf.fmt = fmt;
+       vaf.va = &args;
+
+       pr_warn("UBIFS warning (ubi%d:%d pid %d): %ps: %pV\n",
+               c->vi.ubi_num, c->vi.vol_id, current->pid,
+               __builtin_return_address(0),
+               &vaf);
+
+       va_end(args);
+}
index a5697de..c2a57e1 100644 (file)
 /* Version of this UBIFS implementation */
 #define UBIFS_VERSION 1
 
-/* Normal UBIFS messages */
-#define ubifs_msg(c, fmt, ...)                                      \
-       pr_notice("UBIFS (ubi%d:%d): " fmt "\n",                    \
-                 (c)->vi.ubi_num, (c)->vi.vol_id, ##__VA_ARGS__)
-/* UBIFS error messages */
-#define ubifs_err(c, fmt, ...)                                      \
-       pr_err("UBIFS error (ubi%d:%d pid %d): %s: " fmt "\n",      \
-              (c)->vi.ubi_num, (c)->vi.vol_id, current->pid,       \
-              __func__, ##__VA_ARGS__)
-/* UBIFS warning messages */
-#define ubifs_warn(c, fmt, ...)                                     \
-       pr_warn("UBIFS warning (ubi%d:%d pid %d): %s: " fmt "\n",   \
-               (c)->vi.ubi_num, (c)->vi.vol_id, current->pid,      \
-               __func__, ##__VA_ARGS__)
-/*
- * A variant of 'ubifs_err()' which takes the UBIFS file-sytem description
- * object as an argument.
- */
-#define ubifs_errc(c, fmt, ...)                                     \
-       do {                                                        \
-               if (!(c)->probing)                                  \
-                       ubifs_err(c, fmt, ##__VA_ARGS__);           \
-       } while (0)
-
 /* UBIFS file system VFS magic number */
 #define UBIFS_SUPER_MAGIC 0x24051905
 
@@ -1802,4 +1778,21 @@ int ubifs_decompress(const struct ubifs_info *c, const void *buf, int len,
 #include "misc.h"
 #include "key.h"
 
+/* Normal UBIFS messages */
+__printf(2, 3)
+void ubifs_msg(const struct ubifs_info *c, const char *fmt, ...);
+__printf(2, 3)
+void ubifs_err(const struct ubifs_info *c, const char *fmt, ...);
+__printf(2, 3)
+void ubifs_warn(const struct ubifs_info *c, const char *fmt, ...);
+/*
+ * A variant of 'ubifs_err()' which takes the UBIFS file-sytem description
+ * object as an argument.
+ */
+#define ubifs_errc(c, fmt, ...)                                                \
+do {                                                                   \
+       if (!(c)->probing)                                              \
+               ubifs_err(c, fmt, ##__VA_ARGS__);                       \
+} while (0)
+
 #endif /* !__UBIFS_H__ */