From: Kent Overstreet <kent.overstreet@linux.dev>
To: TruongSinh Tran-Nguyen <i@truongsinh.pro>
Cc: linux-bcachefs@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] chore(util): minimal Rust build example
Date: Tue, 9 May 2023 13:47:01 -0400 [thread overview]
Message-ID: <ZFqHFTMqetbQKtah@moria.home.lan> (raw)
In-Reply-To: <20230503065354.19071-1-i@truongsinh.pro>
On Tue, May 02, 2023 at 11:53:54PM -0700, TruongSinh Tran-Nguyen wrote:
> This is a minimal demonstration of how to use Rust in kernel side
> of bcachefs. Kernel side rust does not have Rust `std`, thus
> formating is a bit more challenging than doing from user space
So if I'm following, it looks like everything is basically there. It
looks like we can add Rust source files to fs/bcachefs/ and have them
built as part of the bcachefs module, and calling back and forth just
works as expected - nice.
The kbuild stuff looks nice and clean - congrats to those responsible :)
We pretty heavily use to_text() functions kernel side; these output to
printbufs, and in Rust they map nicely to the Display trait - do we have
that available in the kernel or is that in std?
> This minimal demo implement `uuid_le_cmp`, but eventually,
> in Rust, we probably do not even need to use it, just simply
> `u1.b != u2.b` is good enough. Furthermore, we might consider
> (even in C code) to use uuid_t instead of uuid_le
Sounds like that would be a welcome cleanup :)
> Signed-off-by: TruongSinh Tran-Nguyen <i@truongsinh.pro>
> ---
> fs/bcachefs/Makefile | 3 +++
> fs/bcachefs/util.h | 8 ++++++++
> fs/bcachefs/util_rust.rs | 17 +++++++++++++++++
> scripts/generate_rust_analyzer.py | 2 +-
> 4 files changed, 29 insertions(+), 1 deletion(-)
> create mode 100644 fs/bcachefs/util_rust.rs
>
> diff --git a/fs/bcachefs/Makefile b/fs/bcachefs/Makefile
> index a71956048a027..972976aac6921 100644
> --- a/fs/bcachefs/Makefile
> +++ b/fs/bcachefs/Makefile
> @@ -72,3 +72,6 @@ bcachefs-y := \
> xattr.o
>
> bcachefs-$(CONFIG_BCACHEFS_POSIX_ACL) += acl.o
> +
> +bcachefs-$(CONFIG_RUST) += \
> + util_rust.o \
> diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h
> index 9eb86c58e5509..6e87baee760a9 100644
> --- a/fs/bcachefs/util.h
> +++ b/fs/bcachefs/util.h
> @@ -839,9 +839,17 @@ static inline int u8_cmp(u8 l, u8 r)
>
> #include <linux/uuid.h>
>
> +#ifdef CONFIG_RUST
> +int deprecated_uuid_le_cmp(const uuid_le *b1, const uuid_le *b2);
> +#endif
> +
> static inline int uuid_le_cmp(const uuid_le u1, const uuid_le u2)
> {
> + #ifdef CONFIG_RUST
> + return deprecated_uuid_le_cmp(&u1, &u2);
> + #else
> return memcmp(&u1, &u2, sizeof(uuid_le));
> + #endif
> }
>
> #endif /* _BCACHEFS_UTIL_H */
> diff --git a/fs/bcachefs/util_rust.rs b/fs/bcachefs/util_rust.rs
> new file mode 100644
> index 0000000000000..23338c29384c0
> --- /dev/null
> +++ b/fs/bcachefs/util_rust.rs
> @@ -0,0 +1,17 @@
> +/* SPDX-License-Identifier: MIT */
> +
> +#[repr(C)]
> +pub struct UuidLe {
> + b: [u8; 16],
> +}
> +
> +// this function is prefixed `deprecated` because it uses
> +// uuid_le from /usr/include/linux/uuid.h, which itself is
> +// deprecated in favor of uuid_t from include/linux/uuid.h
> +// it also does not exactly matches memcmp
> +#[no_mangle]
> +pub extern "C" fn deprecated_uuid_le_cmp( u1 : &UuidLe, u2 : &UuidLe) -> bool
> +{
> + // pr_info!("using deprecated_uuid_le_cmp");
> + return u1.b != u2.b;
> +}
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index 946e250c1b2a6..d258d10bb6e31 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -98,7 +98,7 @@ def generate_crates(srctree, objtree, sysroot_src):
> # Then, the rest outside of `rust/`.
> #
> # We explicitly mention the top-level folders we want to cover.
> - for folder in ("samples", "drivers"):
> + for folder in ("samples", "drivers", 'fs'):
> for path in (srctree / folder).rglob("*.rs"):
> logging.info("Checking %s", path)
> name = path.name.replace(".rs", "")
> --
> 2.30.2
>
next parent reply other threads:[~2023-05-09 17:56 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230503065354.19071-1-i@truongsinh.pro>
2023-05-09 17:47 ` Kent Overstreet [this message]
2023-05-09 17:57 ` [PATCH] chore(util): minimal Rust build example TruongSinh Tran-Nguyen
2023-05-09 18:12 ` Kent Overstreet
2023-05-09 18:41 ` Wedson Almeida Filho
2023-05-09 20:57 ` TruongSinh Tran-Nguyen
2023-05-10 3:10 ` TruongSinh Tran-Nguyen
2023-05-10 17:59 ` Miguel Ojeda
2023-05-10 18:21 ` TruongSinh Tran-Nguyen
2023-05-11 23:37 ` Miguel Ojeda
2023-05-11 23:54 ` TruongSinh Tran-Nguyen
2023-05-12 0:02 ` Miguel Ojeda
2023-05-12 3:31 ` Kent Overstreet
2023-05-12 4:16 ` TruongSinh Tran-Nguyen
2023-05-12 4:18 ` Kent Overstreet
2023-05-12 4:39 ` TruongSinh Tran-Nguyen
2023-05-12 5:33 ` Kent Overstreet
2023-05-12 14:26 ` TruongSinh Tran-Nguyen
2023-05-10 18:38 ` Kent Overstreet
2023-05-11 23:39 ` Miguel Ojeda
2023-05-11 16:16 ` Björn Roy Baron
2023-05-11 16:46 ` TruongSinh Tran-Nguyen
2023-05-11 17:05 ` Björn Roy Baron
2023-05-11 23:10 ` TruongSinh Tran-Nguyen
2023-05-09 20:52 ` Andreas Hindborg
2023-05-10 17:56 ` Miguel Ojeda
2023-05-10 18:44 ` Kent Overstreet
2023-05-11 23:37 ` Miguel Ojeda
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=ZFqHFTMqetbQKtah@moria.home.lan \
--to=kent.overstreet@linux.dev \
--cc=i@truongsinh.pro \
--cc=linux-bcachefs@vger.kernel.org \
--cc=rust-for-linux@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