The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: john stultz <johnstul@us.ibm.com>
To: Joe Perches <joe@perches.com>
Cc: lkml <linux-kernel@vger.kernel.org>
Subject: Re: printk_ratelimited() not compiling
Date: Thu, 18 Feb 2010 14:36:07 -0800	[thread overview]
Message-ID: <1266532567.3201.97.camel@localhost.localdomain> (raw)
In-Reply-To: <1266531013.3201.86.camel@localhost.localdomain>

On Thu, 2010-02-18 at 14:10 -0800, john stultz wrote:
> Hey Joe, 
> 	So I thought printk_ratelimited would be perfect for an issue I'm
> having, but when I tried using it, replacing a printk I had, I got the
> following:
> 
> fs/namei.c:1075: error: variable ‘_rs’ has initializer but incomplete type
> fs/namei.c:1075: error: unknown field ‘interval’ specified in initializer
> fs/namei.c:1075: warning: excess elements in struct initializer
> fs/namei.c:1075: warning: (near initialization for ‘_rs’)
> fs/namei.c:1075: error: unknown field ‘burst’ specified in initializer
> fs/namei.c:1075: warning: excess elements in struct initializer
> fs/namei.c:1075: warning: (near initialization for ‘_rs’)
> fs/namei.c:1075: error: storage size of ‘_rs’ isn’t known
> fs/namei.c:1075: warning: unused variable ‘_rs’
> 
> 
> Thinking the issue was ratelimit.h wasn't included I tried that, but
> got:
> 
>  file included from include/linux/spinlock_types.h:18,
>                  from include/linux/ratelimit.h:5,
>                  from include/linux/kernel.h:21,
>                  from /home/jstultz/projects/linux/linux-2.6-git/arch/x86/include/asm/percpu.h:45,
>                  from /home/jstultz/projects/linux/linux-2.6-git/arch/x86/include/asm/current.h:5,
>                  from /home/jstultz/projects/linux/linux-2.6-git/arch/x86/include/asm/processor.h:15,
>                  from include/linux/prefetch.h:14,
>                  from include/linux/list.h:6,
>                  from include/linux/module.h:9,
>                  from include/linux/crypto.h:21,
>                  from arch/x86/kernel/asm-offsets_64.c:8,
>                  from arch/x86/kernel/asm-offsets.c:4:
> include/linux/lockdep.h:52: error: field ‘hash_entry’ has incomplete type
> include/linux/lockdep.h:57: error: field ‘lock_entry’ has incomplete type
> include/linux/lockdep.h:74: error: field ‘locks_after’ has incomplete type
> include/linux/lockdep.h:74: error: field ‘locks_before’ has incomplete type
> include/linux/lockdep.h:148: error: field ‘entry’ has incomplete type
> include/linux/lockdep.h:167: error: field ‘entry’ has incomplete type
> make[1]: *** [arch/x86/kernel/asm-offsets.s] Error 1
> make: *** [prepare0] Error 2
> 
> Yuck.
> 
> Am I missing something obvious, or did something get broken after this went in?

Ok. Solved it. I needed to #include <linux/ratelimit.h> in the file I
was adding the printk_ratelimited usage in, rather then where
printk_ratelimited is defined.

Maybe would it be better to move the printk_ratelimited definitions into
ratelimit.h so this would be more obvious?

Something like the following?

Signed-off-by: John Stultz <johnstul@us.ibm.com>

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 328bca6..9119b72 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -404,49 +405,6 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
 	({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
 #endif
 
-/*
- * ratelimited messages with local ratelimit_state,
- * no local ratelimit_state used in the !PRINTK case
- */
-#ifdef CONFIG_PRINTK
-#define printk_ratelimited(fmt, ...)  ({		\
-	static struct ratelimit_state _rs = {		\
-		.interval = DEFAULT_RATELIMIT_INTERVAL, \
-		.burst = DEFAULT_RATELIMIT_BURST,       \
-	};                                              \
-							\
-	if (!__ratelimit(&_rs))                         \
-		printk(fmt, ##__VA_ARGS__);		\
-})
-#else
-/* No effect, but we still get type checking even in the !PRINTK case: */
-#define printk_ratelimited printk
-#endif
-
-#define pr_emerg_ratelimited(fmt, ...) \
-	printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
-#define pr_alert_ratelimited(fmt, ...) \
-	printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
-#define pr_crit_ratelimited(fmt, ...) \
-	printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
-#define pr_err_ratelimited(fmt, ...) \
-	printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
-#define pr_warning_ratelimited(fmt, ...) \
-	printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
-#define pr_notice_ratelimited(fmt, ...) \
-	printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
-#define pr_info_ratelimited(fmt, ...) \
-	printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
-/* no pr_cont_ratelimited, don't do that... */
-/* If you are writing a driver, please use dev_dbg instead */
-#if defined(DEBUG)
-#define pr_debug_ratelimited(fmt, ...) \
-	printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
-#else
-#define pr_debug_ratelimited(fmt, ...) \
-	({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \
-				     ##__VA_ARGS__); 0; })
-#endif
 
 /*
  * General tracing related utility functions - trace_printk(),
diff --git a/include/linux/ratelimit.h b/include/linux/ratelimit.h
index 668cf1b..39cc4df 100644
--- a/include/linux/ratelimit.h
+++ b/include/linux/ratelimit.h
@@ -28,4 +28,48 @@ struct ratelimit_state {
 extern int ___ratelimit(struct ratelimit_state *rs, const char *func);
 #define __ratelimit(state) ___ratelimit(state, __func__)
 
+/*
+ * ratelimited messages with local ratelimit_state,
+ * no local ratelimit_state used in the !PRINTK case
+ */
+#ifdef CONFIG_PRINTK
+#define printk_ratelimited(fmt, ...)  ({		\
+	static struct ratelimit_state _rs = {		\
+		.interval = DEFAULT_RATELIMIT_INTERVAL, \
+		.burst = DEFAULT_RATELIMIT_BURST,       \
+	};                                              \
+							\
+	if (!__ratelimit(&_rs))                         \
+		printk(fmt, ##__VA_ARGS__);		\
+})
+#else
+/* No effect, but we still get type checking even in the !PRINTK case: */
+#define printk_ratelimited printk
+#endif
+
+#define pr_emerg_ratelimited(fmt, ...) \
+	printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_alert_ratelimited(fmt, ...) \
+	printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_crit_ratelimited(fmt, ...) \
+	printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_err_ratelimited(fmt, ...) \
+	printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_warning_ratelimited(fmt, ...) \
+	printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_notice_ratelimited(fmt, ...) \
+	printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_info_ratelimited(fmt, ...) \
+	printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
+/* no pr_cont_ratelimited, don't do that... */
+/* If you are writing a driver, please use dev_dbg instead */
+#if defined(DEBUG)
+#define pr_debug_ratelimited(fmt, ...) \
+	printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+#else
+#define pr_debug_ratelimited(fmt, ...) \
+	({ if (0) printk_ratelimited(KERN_DEBUG pr_fmt(fmt), \
+				     ##__VA_ARGS__); 0; })
+#endif
+
 #endif /* _LINUX_RATELIMIT_H */





  parent reply	other threads:[~2010-02-18 22:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-18 22:10 printk_ratelimited() not compiling john stultz
2010-02-18 22:28 ` Joe Perches
2010-02-18 22:36 ` john stultz [this message]
2010-02-18 23:23   ` Joe Perches
2010-02-18 23:33     ` john stultz
2010-02-18 23:49       ` john stultz
2010-02-19  0:15         ` [RFC PATCH] printk_ratelimited: Move definitions to ratelimit.h, use DEFINE_RATELIMIT_STATE Joe Perches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1266532567.3201.97.camel@localhost.localdomain \
    --to=johnstul@us.ibm.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox