From: Zhao Liu <zhao1.liu@intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-rust@nongnu.org,
manos.pitsidianakis@linaro.org, shentey@gmail.com
Subject: Re: [PATCH] rust: log: implement io::Write
Date: Tue, 24 Jun 2025 14:25:35 +0800 [thread overview]
Message-ID: <aFpE3y5B7tS2efvA@intel.com> (raw)
In-Reply-To: <20250617081213.115329-1-pbonzini@redhat.com>
> +/// A RAII guard for QEMU's logging infrastructure. Creating the guard
> +/// locks the log file, and dropping it (letting it go out of scope) unlocks
> +/// the file.
> +///
> +/// As long as the guard lives, it can be written to using [`std::io::Write`].
> +///
> +/// The locking is recursive, therefore owning a guard does not prevent
> +/// using [`log_mask_ln!()`](crate::log_mask_ln).
> +pub struct LogGuard(NonNull<bindings::FILE>);
Nice! I happen to be implementing a similar RAII for FlatView:
pub struct FlatViewRefGuard(NonNull<FlatView>);
> +impl LogGuard {
...
> + /// Writes a formatted string into the log, returning any error encountered.
> + ///
> + /// This method is primarily used by the [`log_mask_ln!()`](crate::log_mask_ln)
> + /// macro, and it is rare for it to be called explicitly.
> + pub fn log_fmt(args: std::fmt::Arguments) -> io::Result<()> {
> + if let Some(mut log) = Self::new() {
> + use io::Write;
I think it's better to place this "use" at the beginning of the file.
> + log.write_fmt(args)?;
> + }
> + Ok(())
> + }
> +}
Overall, LGTM,
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
next prev parent reply other threads:[~2025-06-24 6:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 8:12 [PATCH] rust: log: implement io::Write Paolo Bonzini
2025-06-24 6:25 ` Zhao Liu [this message]
2025-06-24 7:21 ` Zhao Liu
2025-06-24 8:22 ` Manos Pitsidianakis
2025-06-24 9:05 ` Zhao Liu
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=aFpE3y5B7tS2efvA@intel.com \
--to=zhao1.liu@intel.com \
--cc=manos.pitsidianakis@linaro.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-rust@nongnu.org \
--cc=shentey@gmail.com \
/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).