Instead of passing the __func__, __FILE__, and __LINE__ pre-processor macros to each of those functions, print the location of the caller via:
printk(%pS", (void *)_RET_IP_). This gives enough context information to locate where in the code an error occurred, and reduces the code size by about 2 percent. Signed-off-by: Andreas Gruenbacher <agrue...@redhat.com> --- fs/gfs2/util.c | 107 ++++++++++++++++++++----------------------------- fs/gfs2/util.h | 71 +++++++++----------------------- 2 files changed, 62 insertions(+), 116 deletions(-) diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c index 0a814ccac41d2..b4c72bb799052 100644 --- a/fs/gfs2/util.c +++ b/fs/gfs2/util.c @@ -88,14 +88,12 @@ int gfs2_lm_withdraw(struct gfs2_sbd *sdp, const char *fmt, ...) * -2 if it was already withdrawn */ -int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion, - const char *function, char *file, unsigned int line) +int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion) { int me; me = gfs2_lm_withdraw(sdp, - "fatal: assertion \"%s\" failed\n" - " function = %s, file = %s, line = %u\n", - assertion, function, file, line); + "fatal: assertion \"%s\" failed at %pS\n", + assertion, (void *)_RET_IP_); dump_stack(); return (me) ? -1 : -2; } @@ -106,8 +104,7 @@ int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion, * -2 if we didn't */ -int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion, - const char *function, char *file, unsigned int line) +int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion) { if (time_before(jiffies, sdp->sd_last_warning + @@ -115,8 +112,8 @@ int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion, return -2; if (sdp->sd_args.ar_errors == GFS2_ERRORS_WITHDRAW) - fs_warn(sdp, "warning: assertion \"%s\" failed at function = %s, file = %s, line = %u\n", - assertion, function, file, line); + fs_warn(sdp, "warning: assertion \"%s\" failed at %pS\n", + assertion, (void *)_RET_IP_); if (sdp->sd_args.ar_debug) BUG(); @@ -124,10 +121,8 @@ int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion, dump_stack(); if (sdp->sd_args.ar_errors == GFS2_ERRORS_PANIC) - panic("GFS2: fsid=%s: warning: assertion \"%s\" failed\n" - "GFS2: fsid=%s: function = %s, file = %s, line = %u\n", - sdp->sd_fsname, assertion, - sdp->sd_fsname, function, file, line); + panic("GFS2: fsid=%s: warning: assertion \"%s\" failed at %pS\n", + sdp->sd_fsname, assertion, (void *)_RET_IP_); sdp->sd_last_warning = jiffies; @@ -135,61 +130,56 @@ int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion, } /** - * gfs2_consist_i - Flag a filesystem consistency error and withdraw + * gfs2_consist - Flag a filesystem consistency error and withdraw * Returns: -1 if this call withdrew the machine, * 0 if it was already withdrawn */ -int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, const char *function, - char *file, unsigned int line) +int gfs2_consist(struct gfs2_sbd *sdp) { int rv; rv = gfs2_lm_withdraw(sdp, - "fatal: filesystem consistency error - function = %s, file = %s, line = %u\n", - function, file, line); + "fatal: filesystem consistency error at %pS\n", + (void *)_RET_IP_); return rv; } /** - * gfs2_consist_inode_i - Flag an inode consistency error and withdraw + * gfs2_consist_inode - Flag an inode consistency error and withdraw * Returns: -1 if this call withdrew the machine, * 0 if it was already withdrawn */ -int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide, - const char *function, char *file, unsigned int line) +int gfs2_consist_inode(struct gfs2_inode *ip) { struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); int rv; rv = gfs2_lm_withdraw(sdp, - "fatal: filesystem consistency error\n" - " inode = %llu %llu\n" - " function = %s, file = %s, line = %u\n", + "fatal: filesystem consistency error at %pS\n" + " inode = %llu %llu\n", + (void *)_RET_IP_, (unsigned long long)ip->i_no_formal_ino, - (unsigned long long)ip->i_no_addr, - function, file, line); + (unsigned long long)ip->i_no_addr); return rv; } /** - * gfs2_consist_rgrpd_i - Flag a RG consistency error and withdraw + * gfs2_consist_rgrpd - Flag a RG consistency error and withdraw * Returns: -1 if this call withdrew the machine, * 0 if it was already withdrawn */ -int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide, - const char *function, char *file, unsigned int line) +int gfs2_consist_rgrpd(struct gfs2_rgrpd *rgd) { struct gfs2_sbd *sdp = rgd->rd_sbd; int rv; gfs2_rgrp_dump(NULL, rgd->rd_gl); rv = gfs2_lm_withdraw(sdp, - "fatal: filesystem consistency error\n" - " RG = %llu\n" - " function = %s, file = %s, line = %u\n", - (unsigned long long)rgd->rd_addr, - function, file, line); + "fatal: filesystem consistency error at %pS\n" + " RG = %llu\n", + (void *)_RET_IP_, + (unsigned long long)rgd->rd_addr); return rv; } @@ -200,16 +190,14 @@ int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide, */ int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, - const char *type, const char *function, char *file, - unsigned int line) + const char *type, void *caller) { int me; me = gfs2_lm_withdraw(sdp, - "fatal: invalid metadata block\n" - " bh = %llu (%s)\n" - " function = %s, file = %s, line = %u\n", - (unsigned long long)bh->b_blocknr, type, - function, file, line); + "fatal: invalid metadata block at %pS\n" + " bh = %llu (%s)\n", + caller, + (unsigned long long)bh->b_blocknr, type); return (me) ? -1 : -2; } @@ -220,53 +208,46 @@ int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, */ int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, - u16 type, u16 t, const char *function, - char *file, unsigned int line) + u16 type, u16 t, void *caller) { int me; me = gfs2_lm_withdraw(sdp, - "fatal: invalid metadata block\n" - " bh = %llu (type: exp=%u, found=%u)\n" - " function = %s, file = %s, line = %u\n", - (unsigned long long)bh->b_blocknr, type, t, - function, file, line); + "fatal: invalid metadata block at %pS\n" + " bh = %llu (type: exp=%u, found=%u)\n", + caller, + (unsigned long long)bh->b_blocknr, type, t); return (me) ? -1 : -2; } /** - * gfs2_io_error_i - Flag an I/O error and withdraw + * gfs2_io_error - Flag an I/O error and withdraw * Returns: -1 if this call withdrew the machine, * 0 if it was already withdrawn */ -int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file, - unsigned int line) +int gfs2_io_error(struct gfs2_sbd *sdp) { int rv; rv = gfs2_lm_withdraw(sdp, - "fatal: I/O error\n" - " function = %s, file = %s, line = %u\n", - function, file, line); + "fatal: I/O error at %pS\n", + (void *)_RET_IP_); return rv; } /** - * gfs2_io_error_bh_i - Flag a buffer I/O error + * gfs2_io_error_bh - Flag a buffer I/O error * @withdraw: withdraw the filesystem */ -void gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh, - const char *function, char *file, unsigned int line, +void __gfs2_io_error_bh(struct gfs2_sbd *sdp, struct buffer_head *bh, bool withdraw) { if (!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) fs_err(sdp, - "fatal: I/O error\n" - " block = %llu\n" - " function = %s, file = %s, line = %u\n", - (unsigned long long)bh->b_blocknr, - function, file, line); + "fatal: I/O error at %pS\n" + " block = %llu\n", + (void *)_RET_IP_, + (unsigned long long)bh->b_blocknr); if (withdraw) gfs2_lm_withdraw(sdp, NULL); } - diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h index 9278fecba6321..453d814c1efa3 100644 --- a/fs/gfs2/util.h +++ b/fs/gfs2/util.h @@ -39,46 +39,24 @@ do { \ } while (0) -int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion, - const char *function, char *file, unsigned int line); +int gfs2_assert_withdraw_i(struct gfs2_sbd *sdp, char *assertion); #define gfs2_assert_withdraw(sdp, assertion) \ -((likely(assertion)) ? 0 : gfs2_assert_withdraw_i((sdp), #assertion, \ - __func__, __FILE__, __LINE__)) + ((likely(assertion)) ? 0 : gfs2_assert_withdraw_i((sdp), #assertion)) -int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion, - const char *function, char *file, unsigned int line); +int gfs2_assert_warn_i(struct gfs2_sbd *sdp, char *assertion); #define gfs2_assert_warn(sdp, assertion) \ -((likely(assertion)) ? 0 : gfs2_assert_warn_i((sdp), #assertion, \ - __func__, __FILE__, __LINE__)) + ((likely(assertion)) ? 0 : gfs2_assert_warn_i((sdp), #assertion)) -int gfs2_consist_i(struct gfs2_sbd *sdp, int cluster_wide, - const char *function, char *file, unsigned int line); - -#define gfs2_consist(sdp) \ -gfs2_consist_i((sdp), 0, __func__, __FILE__, __LINE__) - - -int gfs2_consist_inode_i(struct gfs2_inode *ip, int cluster_wide, - const char *function, char *file, unsigned int line); - -#define gfs2_consist_inode(ip) \ -gfs2_consist_inode_i((ip), 0, __func__, __FILE__, __LINE__) - - -int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide, - const char *function, char *file, unsigned int line); - -#define gfs2_consist_rgrpd(rgd) \ -gfs2_consist_rgrpd_i((rgd), 0, __func__, __FILE__, __LINE__) - +int gfs2_consist(struct gfs2_sbd *sdp); +int gfs2_consist_inode(struct gfs2_inode *ip); +int gfs2_consist_rgrpd(struct gfs2_rgrpd *rgd); int gfs2_meta_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, - const char *type, const char *function, - char *file, unsigned int line); + const char *type, void *caller); static inline int gfs2_meta_check(struct gfs2_sbd *sdp, struct buffer_head *bh) @@ -95,30 +73,23 @@ static inline int gfs2_meta_check(struct gfs2_sbd *sdp, int gfs2_metatype_check_ii(struct gfs2_sbd *sdp, struct buffer_head *bh, u16 type, u16 t, - const char *function, - char *file, unsigned int line); + void *caller); -static inline int gfs2_metatype_check_i(struct gfs2_sbd *sdp, +static inline int gfs2_metatype_check(struct gfs2_sbd *sdp, struct buffer_head *bh, - u16 type, - const char *function, - char *file, unsigned int line) + u16 type) { struct gfs2_meta_header *mh = (struct gfs2_meta_header *)bh->b_data; u32 magic = be32_to_cpu(mh->mh_magic); u16 t = be32_to_cpu(mh->mh_type); if (unlikely(magic != GFS2_MAGIC)) - return gfs2_meta_check_ii(sdp, bh, "magic number", function, - file, line); + return gfs2_meta_check_ii(sdp, bh, "magic number", (void *)_RET_IP_); if (unlikely(t != type)) - return gfs2_metatype_check_ii(sdp, bh, type, t, function, - file, line); + return gfs2_metatype_check_ii(sdp, bh, type, t, + (void *)_RET_IP_); return 0; } -#define gfs2_metatype_check(sdp, bh, type) \ -gfs2_metatype_check_i((sdp), (bh), (type), __func__, __FILE__, __LINE__) - static inline void gfs2_metatype_set(struct buffer_head *bh, u16 type, u16 format) { @@ -129,22 +100,16 @@ static inline void gfs2_metatype_set(struct buffer_head *bh, u16 type, } -int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, - char *file, unsigned int line); - -#define gfs2_io_error(sdp) \ -gfs2_io_error_i((sdp), __func__, __FILE__, __LINE__); - +int gfs2_io_error(struct gfs2_sbd *sdp); -void gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh, - const char *function, char *file, unsigned int line, +void __gfs2_io_error_bh(struct gfs2_sbd *sdp, struct buffer_head *bh, bool withdraw); #define gfs2_io_error_bh_wd(sdp, bh) \ -gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, true); + __gfs2_io_error_bh((sdp), (bh), true); #define gfs2_io_error_bh(sdp, bh) \ -gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, false); + __gfs2_io_error_bh((sdp), (bh), false); extern struct kmem_cache *gfs2_glock_cachep; -- 2.20.1