All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH RFC 00/15] btrfs-progs: experimental rust support
Date: Tue,  1 Dec 2026 18:26:35 +1030	[thread overview]
Message-ID: <cover.1796111695.git.wqu@suse.com> (raw)

This is my Hackweek project, and just according to the LoC, one should
know this has LLM heavily involved.

Currently the following features are implemented:

- Basic multi-device scan and read-only Fs::open()
  No RAID56 rebuild, no zoned support, no experiemental REMAP.
  No write support.

- Basic read-only tree search

- dump-tree and dump-super implementation
  Dump-super should be equivlant to the C version except the
  RAID56/REMAP/ZONED part.

  Dump-tree is mostly the same, except no more DFS (Which I do not think
  has any benefit), nor the deprecated options.

TL;DR from my experience is:

GOOD:

- Awesome resource auto-cleanup
  There is only Fs::open(), but no Fs::close(). Every resource is
  already managed by rust. When the the `fs` returned by Fs::open() is
  no longer used, it will be automatically cleaned, no need to
  Fs::close().

- Awesome upstream packages
  No need to bother which CRC32C library to copy/use, all hash algo are
  already provided.

  Zerocopy handled all structure by themself, we don't even need any
  extra accessors anymore. No different structures for on-disk and
  in-memory keys etc.

  Clap makes all the subcommands implementation so easy.

  Although it's not always good, libblkid-rs pulls in the full bindgen
  dependency.

- Good practice to include selftests
  Although I haven't given a full review over the LLM generated test
  cases, I would say it's still better than nothing and overall a good
  idea.

  In fact, 25% of the LoCs are test cases.

- Straight-forward code flow
  With a lot of error handling raised up to the caller, e.g. `?` suffix,
  most code are just real code, not error handling.
  It makes reading the code much easier.

NOT-SO-GOOD FOR C DEVELOPERS:

- Various different ways of error handling
  A lot of them are not explicit, e.g. using the `?` suffix.
  And a lot of Ok()/Some() matched to catch errors.

  I know these are all common features of advanced languages, but may be
  I'm just too old to learn new tricks.

  Thus I'm trying to make the code C developer friendly when possible.

- Overly strict width checks
  This is part of the safety provided at compile time, but if I'm
  manually writing codes, it will be a lot of heavy lifting.

- A lot of tuple usages from LLM
  I think it's a common practice for rust, but I'm not yet fully
  converted. So I would prefer C-like code style.

Overall, with LLM, the not-so-good part can be resolved more easily,
greatly reducing the bar for entering.

But still, even with LLM, non-rust-native developers still need to pay a
lot of attention to avoid or learn unfamiliar features.

Qu Wenruo (15):
  btrfs-progs: rust: introduce on-disk format definitions
  btrfs-progs: rust: add btrfs-rs with inspect-internal dump-super
  btrfs-progs: rust: disk: add the tree block layout
  btrfs-progs: rust: fs: add superblock reading
  btrfs-progs: rust: fs: add Fs::open()
  btrfs-progs: rust: fs: add device scanning with libblkid for
    multi-device filesystems
  btrfs-progs: rust: implement btrfs_print_node in print_tree
  btrfs-progs: rust: print_tree: add print_leaf and chunk tree items
  btrfs-progs: rust: print_tree: add subvolume tree items
  btrfs-progs: rust: print_tree: add root tree items
  btrfs-progs: rust: print_tree: add extent and block group tree items
  btrfs-progs: rust: print_tree: add remaining tree items
  btrfs-progs: rust: fs: add tree search
  btrfs-progs: rust: dump-tree: implement default full tree dump with
    BFS
  btrfs-progs: rust: dump-tree: add -t option to dump specified trees

 rust/.gitignore                     |    1 +
 rust/Cargo.lock                     |  802 ++++++++++++
 rust/Cargo.toml                     |   17 +
 rust/README.md                      |   24 +
 rust/src/cmds/inspect_dump_super.rs |  227 ++++
 rust/src/cmds/inspect_dump_tree.rs  |  604 +++++++++
 rust/src/cmds/inspect_internal.rs   |   26 +
 rust/src/cmds/mod.rs                |   25 +
 rust/src/disk/block.rs              |  153 +++
 rust/src/disk/btrfs_tree.rs         |  816 ++++++++++++
 rust/src/disk/consts.rs             |  535 ++++++++
 rust/src/disk/csum.rs               |   49 +
 rust/src/disk/mod.rs                |   25 +
 rust/src/fs/device.rs               |  110 ++
 rust/src/fs/error.rs                |   37 +
 rust/src/fs/mod.rs                  |  358 +++++
 rust/src/fs/root.rs                 |  102 ++
 rust/src/fs/search.rs               |  405 ++++++
 rust/src/fs/superblock.rs           |  249 ++++
 rust/src/fs/testutil.rs             |  165 +++
 rust/src/fs/tree_block.rs           |  135 ++
 rust/src/fs/volumes.rs              |  497 +++++++
 rust/src/lib.rs                     |    8 +
 rust/src/main.rs                    |   49 +
 rust/src/messages.rs                |   21 +
 rust/src/print_tree.rs              | 1877 +++++++++++++++++++++++++++
 rust/src/sizes.rs                   |   18 +
 rust/src/util.rs                    |   11 +
 rust/tests/parse.rs                 |   89 ++
 29 files changed, 7435 insertions(+)
 create mode 100644 rust/.gitignore
 create mode 100644 rust/Cargo.lock
 create mode 100644 rust/Cargo.toml
 create mode 100644 rust/README.md
 create mode 100644 rust/src/cmds/inspect_dump_super.rs
 create mode 100644 rust/src/cmds/inspect_dump_tree.rs
 create mode 100644 rust/src/cmds/inspect_internal.rs
 create mode 100644 rust/src/cmds/mod.rs
 create mode 100644 rust/src/disk/block.rs
 create mode 100644 rust/src/disk/btrfs_tree.rs
 create mode 100644 rust/src/disk/consts.rs
 create mode 100644 rust/src/disk/csum.rs
 create mode 100644 rust/src/disk/mod.rs
 create mode 100644 rust/src/fs/device.rs
 create mode 100644 rust/src/fs/error.rs
 create mode 100644 rust/src/fs/mod.rs
 create mode 100644 rust/src/fs/root.rs
 create mode 100644 rust/src/fs/search.rs
 create mode 100644 rust/src/fs/superblock.rs
 create mode 100644 rust/src/fs/testutil.rs
 create mode 100644 rust/src/fs/tree_block.rs
 create mode 100644 rust/src/fs/volumes.rs
 create mode 100644 rust/src/lib.rs
 create mode 100644 rust/src/main.rs
 create mode 100644 rust/src/messages.rs
 create mode 100644 rust/src/print_tree.rs
 create mode 100644 rust/src/sizes.rs
 create mode 100644 rust/src/util.rs
 create mode 100644 rust/tests/parse.rs

--
2.56.1


             reply	other threads:[~2026-12-01  7:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  7:56 Qu Wenruo [this message]
2026-12-01  7:56 ` [PATCH 01/15] btrfs-progs: rust: introduce on-disk format definitions Qu Wenruo
2026-12-01  7:56 ` [PATCH 02/15] btrfs-progs: rust: add btrfs-rs with inspect-internal dump-super Qu Wenruo
2026-12-01  7:56 ` [PATCH 03/15] btrfs-progs: rust: disk: add the tree block layout Qu Wenruo
2026-12-01  7:56 ` [PATCH 04/15] btrfs-progs: rust: fs: add superblock reading Qu Wenruo
2026-12-01  7:56 ` [PATCH 05/15] btrfs-progs: rust: fs: add Fs::open() Qu Wenruo
2026-12-01  7:56 ` [PATCH 06/15] btrfs-progs: rust: fs: add device scanning with libblkid for multi-device filesystems Qu Wenruo
2026-12-01  7:56 ` [PATCH 07/15] btrfs-progs: rust: implement btrfs_print_node in print_tree Qu Wenruo
2026-12-01  7:56 ` [PATCH 08/15] btrfs-progs: rust: print_tree: add print_leaf and chunk tree items Qu Wenruo
2026-12-01  7:56 ` [PATCH 09/15] btrfs-progs: rust: print_tree: add subvolume " Qu Wenruo
2026-12-01  7:56 ` [PATCH 10/15] btrfs-progs: rust: print_tree: add root " Qu Wenruo
2026-12-01  7:56 ` [PATCH 11/15] btrfs-progs: rust: print_tree: add extent and block group " Qu Wenruo
2026-12-01  7:56 ` [PATCH 12/15] btrfs-progs: rust: print_tree: add remaining " Qu Wenruo
2026-12-01  7:56 ` [PATCH 13/15] btrfs-progs: rust: fs: add tree search Qu Wenruo
2026-12-01  7:56 ` [PATCH 14/15] btrfs-progs: rust: dump-tree: implement default full tree dump with BFS Qu Wenruo
2026-12-01  7:56 ` [PATCH 15/15] btrfs-progs: rust: dump-tree: add -t option to dump specified trees Qu Wenruo

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=cover.1796111695.git.wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.