xfs
[Top] [All Lists]

Re: Warnings when compiling xfs_macros.c

To: linux-xfs@xxxxxxxxxxx
Subject: Re: Warnings when compiling xfs_macros.c
From: Craig Rodrigues <rodrigc@xxxxxxxxxxxxxx>
Date: Thu, 8 Sep 2005 10:35:00 -0400
In-reply-to: <43204609.60203@xxxxxxx>
References: <20050907174535.GA1850@xxxxxxxxxxxxxx> <20050907182059.GA13074@xxxxxxxxxxxxx> <20050907184542.GA2316@xxxxxxxxxxxxxx> <20050908105745.GA5847@xxxxxxxxxxxxx> <43204609.60203@xxxxxxx>
Sender: linux-xfs-bounce@xxxxxxxxxxx
User-agent: Mutt/1.5.9i
On Thu, Sep 08, 2005 at 09:09:13AM -0500, Steve Lord wrote:
> If someone converts all the code to plain macros, I suggest you look
> carefully at the ones which default to being functions, these are
> probably the main culprits when it comes to code bloat. With today's
> fast cpus, keeping them as functions might still be worth while
> from a code size point of view.

Well, this type of code cleanup is probably a good thing to do,
but is not what I want to tackle yet for my short-term goal
of getting xfs_macros.c to compile without warning if
-Wmissing-prototypes is added to the gcc flags (as is done
during a FreeBSD kernel build).

For example, for this warning:

/usr/src/sys/gnu/fs/xfs/xfs_macros.c:2242: warning: no previous prototype for 
'xlog_grant_sub_space'

In xfs_log_priv.h, the prototype is defined as:

#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XLOG_GRANT_SUB_SPACE)
void xlog_grant_sub_space(struct log *log, int bytes, int type);
#define XLOG_GRANT_SUB_SPACE(log,bytes,type)    \
        xlog_grant_sub_space(log,bytes,type)
#else
#define XLOG_GRANT_SUB_SPACE(log,bytes,type)                            \
    {                                                                   \
        if (type == 'w') {                                              \
                (log)->l_grant_write_bytes -= (bytes);                  \
                if ((log)->l_grant_write_bytes < 0) {                   \
                        (log)->l_grant_write_bytes += (log)->l_logsize; \
                        (log)->l_grant_write_cycle--;                   \
                }                                                       \
        } else {                                                        \
                (log)->l_grant_reserve_bytes -= (bytes);                \
                if ((log)->l_grant_reserve_bytes < 0) {                 \
                        (log)->l_grant_reserve_bytes += (log)->l_logsize;\
                        (log)->l_grant_reserve_cycle--;                 \
                }                                                       \
         }                                                              \
    }
#endif


And in xfs_macros.c, we have:

#if XFS_WANT_FUNCS_C || (XFS_WANT_SPACE_C && XFSSO_XLOG_GRANT_SUB_SPACE)
void
xlog_grant_sub_space(xlog_t *log, int bytes, int type)
{
        XLOG_GRANT_SUB_SPACE(log, bytes, type);
} 
#endif



What I am finding, is that when DEBUG is defined,
XFS_WANT_FUNCS_C is defined, but XFS_WANT_FUNCS
is not defined due to these lines in xfs_macros.h:

#define XFS_WANT_FUNCS_C        \
        (!defined(_STANDALONE) && defined(DEBUG))

#define XFS_WANT_FUNCS  (XFS_WANT_FUNCS_C && !defined(XFS_MACRO_C))

Consequently, when xfs_macros.c is compiled, 
the function is compiled in the .c file, but the function protototype
is not visiable in the .h file, so -Wmissing-prototypes
will cause a warning.

I "fixed" this by doing this in xfs_log_priv.h:

#if XFS_WANT_FUNCS || XFS_WANT_FUNCS_C || (XFS_WANT_SPACE && XFSSO_XLOG_GRANT_SU
B_SPACE)
void xlog_grant_sub_space(struct log *log, int bytes, int type);
#endif

#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XLOG_GRANT_SUB_SPACE)
#define XLOG_GRANT_SUB_SPACE(log,bytes,type)    \
        xlog_grant_sub_space(log,bytes,type)
#else
#define XLOG_GRANT_SUB_SPACE(log,bytes,type)                            \
    {                                                                   \
        if (type == 'w') {                                              \
                (log)->l_grant_write_bytes -= (bytes);                  \
                if ((log)->l_grant_write_bytes < 0) {                   \
                        (log)->l_grant_write_bytes += (log)->l_logsize; \
                        (log)->l_grant_write_cycle--;                   \
                }                                                       \
        } else {                                                        \
                (log)->l_grant_reserve_bytes -= (bytes);                \
                if ((log)->l_grant_reserve_bytes < 0) {                 \
                        (log)->l_grant_reserve_bytes += (log)->l_logsize;\
                        (log)->l_grant_reserve_cycle--;                 \
                }                                                       \
         }                                                              \
    }
#endif


This allowed me to compile xfs_macros.c without errors.
Is this an acceptable "fix" to submit back to linux-xfs?
It preserves the status quo as much as possible.
I had to do this in every header file which has a prototype for
a function in xfs_macros.c.

-- 
Craig Rodrigues        
rodrigc@xxxxxxxxxxxxxx


<Prev in Thread] Current Thread [Next in Thread>