From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796111837; b=yxyeUK7Zt3gDX66VqH/+FZosGXTDUj+gLjYOr1srZdMLX0NuqfSNMSvobk27NwgdC+yu +npby2UClhu3QB2Le/EIzH7THQ53DTnl/pbSSO8AVEwpNZutqMCxiqi6RcPO/Sjo9NGQG AiegSW3DiSpJ6dNYd7tnIJkaBjDNzrwdr2WMGjZZWx71+4H3jpzGc0Q0C97hNiQdkzKVE f8wd3MvImLF/I4jpHEZthTeiwpcmv7kZgvUrOHT9XlN4BD3Ug4Gub402XO7RFYuAc1v42 NGV0l4hEI1PqY9ckCm1DZ3a2aVJh0mJP4EFEnFp110vzJCa/B28ODgezTyV36v03yKw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796111837; h=DMARC-Filter:Received:DKIM-Signature:DKIM-Signature:Received: Received:From:To:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding:X-Spamd-Result:X-Spam-Score:X-Spam-Level: X-Spam-Flag; bh=ThC1c3mguAv6O1UH3Jkr7SzlK+innTuXbqIe3iPiTdw=; b=15k5NDvuiBxL+hD4IGMMAK/88GOgxW9X++jqTBRsvqWqA7sA9FdE65HMbJQDS74J9Mlz 1shvAoUpq1IdKi2vBKxZgtWhzN66dTaWBGrKQdb5am+sUPkC5mYCzQtaaEq4B8l++4zvT /PAxmZFLx6SvH0Xy+AvT6BOx1ogPI0z0k+fosIx9mKBdyh8cvdZSCz+WGzUXv0vW74fFj 9HHGqSExsC+7in1vDpUw/Gh4+wj4pCskxoeBAVlChzQEHB0g6mttTkDWs8ZZhIiIM+8Zr fMlW0+cMV+FKURfKo56jBsC4DcVzt5Eg6NI1ig8B5U3NNxpvU2OLy9QdcOswEE28jhw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=ITgdyJkk; dkim=pass header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=ITgdyJkk; arc=none smtp.remote-ip=195.135.223.131 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F585606A31A for ; Tue, 1 Dec 2026 07:57:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2F585606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=ITgdyJkk; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=ITgdyJkk Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 676FA1F78A for ; Tue, 1 Dec 2026 07:57:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1796111834; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ThC1c3mguAv6O1UH3Jkr7SzlK+innTuXbqIe3iPiTdw=; b=ITgdyJkkymYC1Ha618LCnLl89Ib8cpKUzpDNk4s9ztRrkyiSvFVENMun8xXjs+yylfEbiE TIuxj70+ljj6m5iic9UwVlKSnVxLi4W/4kl2CYVzEFZkH5LWZlnOQ5YSteTKmpbHL9NQBe OX01a4+FuemC2y1NPVDGq3zdhfOfob8= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1796111834; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ThC1c3mguAv6O1UH3Jkr7SzlK+innTuXbqIe3iPiTdw=; b=ITgdyJkkymYC1Ha618LCnLl89Ib8cpKUzpDNk4s9ztRrkyiSvFVENMun8xXjs+yylfEbiE TIuxj70+ljj6m5iic9UwVlKSnVxLi4W/4kl2CYVzEFZkH5LWZlnOQ5YSteTKmpbHL9NQBe OX01a4+FuemC2y1NPVDGq3zdhfOfob8= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4B599134E9 for ; Tue, 1 Dec 2026 07:57:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id WbkGJ9h9DmsnMgAAD6G6ig (envelope-from ) for ; Tue, 01 Dec 2026 07:57:12 +0000 From: Qu Wenruo 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 Message-ID: X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-11.80 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -11.80 X-Spam-Level: X-Spam-Flag: NO 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