From: Jens Korinth via B4 Relay <devnull+jens.korinth.tuta.io@kernel.org>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>
Cc: rust-for-linux@vger.kernel.org,
FUJITA Tomonori <fujita.tomonori@gmail.com>,
Dirk Behme <dirk.behme@gmail.com>,
Jens Korinth <jens.korinth@tuta.io>
Subject: [PATCH v2 2/3] rust: print: Add pr_*_once macros
Date: Thu, 07 Nov 2024 00:28:32 +0100 [thread overview]
Message-ID: <20241107-pr_once_macros-v2-2-dc0317ff301e@tuta.io> (raw)
In-Reply-To: <20241107-pr_once_macros-v2-0-dc0317ff301e@tuta.io>
From: FUJITA Tomonori <fujita.tomonori@gmail.com>
Add Rust version of pr_[emerg|alert|crit|err|warn|notic|info]_once
functions, which print a message only once.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
rust/kernel/print.rs | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 109 insertions(+)
diff --git a/rust/kernel/print.rs b/rust/kernel/print.rs
index 9c7434b221984ad325138e5dc90ab4340cd0be2e..3c7414f99934359112b39d01392029feda8802e8 100644
--- a/rust/kernel/print.rs
+++ b/rust/kernel/print.rs
@@ -448,3 +448,112 @@ macro_rules! do_once_lite (
}
);
);
+
+/// Prints an emergency-level message (level 0) only once.
+///
+/// Equivalent to the kernel's [`pr_emerg_once`] macro.
+///
+/// # Examples
+///
+/// ```
+/// kernel::pr_emerg_once!("hello {}\n", "there");
+/// ```
+#[macro_export]
+macro_rules! pr_emerg_once (
+ ($($arg:tt)*) => (
+ $crate::do_once_lite!($crate::pr_emerg!($($arg)*))
+ )
+);
+
+/// Prints an alert-level message (level 1) only once.
+///
+/// Equivalent to the kernel's [`pr_alert_once`] macro.
+///
+/// # Examples
+///
+/// ```
+/// kernel::pr_alert_once!("hello {}\n", "there");
+/// ```
+#[macro_export]
+macro_rules! pr_alert_once (
+ ($($arg:tt)*) => (
+ $crate::do_once_lite!($crate::pr_alert!($($arg)*))
+ )
+);
+
+/// Prints a critical-level message (level 2) only once.
+///
+/// Equivalent to the kernel's [`pr_crit_once`] macro.
+///
+/// # Examples
+///
+/// ```
+/// kernel::pr_crit_once!("hello {}\n", "there");
+/// ```
+#[macro_export]
+macro_rules! pr_crit_once (
+ ($($arg:tt)*) => (
+ $crate::do_once_lite!($crate::pr_crit!($($arg)*))
+ )
+);
+
+/// Prints an error-level message (level 3) only once.
+///
+/// Equivalent to the kernel's [`pr_err_once`] macro.
+///
+/// # Examples
+///
+/// ```
+/// pr_err_once!("hello {}\n", "there");
+/// ```
+#[macro_export]
+macro_rules! pr_err_once (
+ ($($arg:tt)*) => (
+ $crate::do_once_lite!($crate::pr_err!($($arg)*))
+ )
+);
+
+/// Prints a warning-level message (level 4) only once.
+///
+/// Equivalent to the kernel's [`pr_warn_once`] macro.
+///
+/// # Examples
+/// ```
+/// kernel::pr_warn_once!("hello {}\n", "there");
+/// ```
+#[macro_export]
+macro_rules! pr_warn_once (
+ ($($arg:tt)*) => (
+ $crate::do_once_lite!($crate::pr_warn!($($arg)*))
+ )
+);
+
+/// Prints a notice-level message (level 5) only once.
+///
+/// Equivalent to the kernel's [`pr_notice_once`] macro.
+///
+/// # Examples
+/// ```
+/// kernel::pr_notice_once!("hello {}\n", "there");
+/// ```
+#[macro_export]
+macro_rules! pr_notice_once (
+ ($($arg:tt)*) => (
+ $crate::do_once_lite!($crate::pr_notice!($($arg)*))
+ )
+);
+
+/// Prints an info-level message (level 6) only once.
+///
+/// Equivalent to the kernel's [`pr_info_once`] macro.
+///
+/// # Examples
+/// ```
+/// kernel::pr_info_once!("hello {}\n", "there");
+/// ```
+#[macro_export]
+macro_rules! pr_info_once (
+ ($($arg:tt)*) => (
+ $crate::do_once_lite!($crate::pr_info!($($arg)*))
+ )
+);
--
2.44.1
next prev parent reply other threads:[~2024-11-06 23:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-06 23:28 [PATCH v2 0/3] rust: Add pr_*_once macros Jens Korinth via B4 Relay
2024-11-06 23:28 ` [PATCH v2 1/3] rust: print: Add do_once_lite macro Jens Korinth via B4 Relay
2024-11-06 23:28 ` Jens Korinth via B4 Relay [this message]
2024-11-07 11:14 ` [PATCH v2 2/3] rust: print: Add pr_*_once macros Miguel Ojeda
2024-11-08 12:09 ` FUJITA Tomonori
2024-11-08 20:10 ` jens.korinth
2024-11-08 20:25 ` Miguel Ojeda
2024-11-07 14:29 ` kernel test robot
2024-11-08 12:21 ` Dirk Behme
2024-11-06 23:28 ` [PATCH v2 3/3] rust: error: Replace pr_warn by pr_warn_once Jens Korinth via B4 Relay
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=20241107-pr_once_macros-v2-2-dc0317ff301e@tuta.io \
--to=devnull+jens.korinth.tuta.io@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dirk.behme@gmail.com \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=jens.korinth@tuta.io \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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;
as well as URLs for NNTP newsgroup(s).