Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1169664lqj; Mon, 3 Jun 2024 12:17:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVv9DIAXgcx1GHIlznLwhRVmA/C9um/tFKvvmgywcGzeP5VWUJaXCWcQkmV14QdqA0bmT3QINH7wtS6knjjk52yTFrxAV2JKt2w0hZ0IA== X-Google-Smtp-Source: AGHT+IHMgzzB0FUywcYczx4yrX8RoSONHqTou4BBggdhyIP9nhsLzEBM8S4DA3bNgz/pezJGaaiq X-Received: by 2002:a17:906:65d3:b0:a66:4b54:9c87 with SMTP id a640c23a62f3a-a682234b89amr834818966b.76.1717442240084; Mon, 03 Jun 2024 12:17:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717442240; cv=pass; d=google.com; s=arc-20160816; b=GlDZ2wQNNOpkBAL+EBFQGErbporWNwDFD1RG4niNiKCOtVCE2rTnOoeDMAOKdrQU2U /el6DznQTd7E3eATVL5bjMPB/1aNxO4teTzRKjcUwJ+GfiJMOIMrRyq849umVHDXk9yk SimLd898ObdF6S2OYGAC2ixhjX05A7RYgdKtqeqxxsxaJfBTSizAXYItpaVTMQvp9R9g DTNl00Q5DBT40o8jzbp0E73Usko5KGU9CrlhXB9KoKV8V9g9oQcfhHQHbBsqJw4UbHMr dD5plddFhYjrq3hOoymyckfrlVuzy23I3OARAGncwsbsBGYrClCfLYAVVNm4VJqwE9DF m3UA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+tUpFHhiF2nyw1IxV5EDxG66GkJExfgKKAw3iF807fE=; fh=d8eZ0JbVFISxEZ9Sv0Agr3ZI0gHpKY0axGnN9Tbor9o=; b=UTx4B44IVLqat+H80SHdKg5FjawZWibGllXJE8sk46q7bG8H3OmWvSWwCLRp0bvhHB f5J3ks+/QQJU17bq9MoOwxZhF+CKAZp0JINs4bxmEGPR0/CNBXjLwJ4kYSf4/F0Cb7Ag q82uGmYMl5rOC0DMZfdZJGewxiYE+RhvpF6vAh1K1kVWI/0yFkT7Lp1umnwnY1Cj+lYO 3+oFW8kjLHzW9Lx0TYKePRKlCOOBgVRjhflnpIDw2R0I3yCdeZvEOLTCO7QgpNorEBKS PZAeXhunw2s4kYs0ORRfQpps5UJqt5E61mn8sVWugi1wiX3GbDMvJLWQj5Lk+IZCJIx9 yfcw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@metaspace-dk.20230601.gappssmtp.com header.s=20230601 header.b=fkZMaWbe; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-199629-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199629-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a68e543c46esi210832066b.739.2024.06.03.12.17.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 12:17:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-199629-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20230601.gappssmtp.com header.s=20230601 header.b=fkZMaWbe; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-199629-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-199629-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A20961F26EF8 for ; Mon, 3 Jun 2024 19:17:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2A1113CF9E; Mon, 3 Jun 2024 19:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=metaspace-dk.20230601.gappssmtp.com header.i=@metaspace-dk.20230601.gappssmtp.com header.b="fkZMaWbe" Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DB2913CA80 for ; Mon, 3 Jun 2024 19:15:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717442113; cv=none; b=S/A94ajEMzs0vQU8qbt4N2kqYPwm71EYYQrcDS04XglI1WEWi6AhV0vCCLasbkG6GdgiAsiWDIk77Hc5vFnjK0NN31mKIM6r1QKMR51tgthcaBF3UFyqc9rm8/F0b6SJdtcOiIBZmTbhnDgsiB/BbIG4xq3wQS38IzhC1cbv0vY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717442113; c=relaxed/simple; bh=qc6pEF7RUK+6H2CQ8rZ3p7kYl8fLqlSHhg1GGU3Rb4w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m1Fhb8zMLcbm7mehOecWMfYnjY/Q+In5tuMfou5RlCFoQPHwJEBFioHl/ygqEorSyzMAUxE6eCo70jRCGxxXNx+koEshLVUjsQwFf4ORbxsyLz74yoCp/LqpQIDNiXKndexWQGndfLZik1ABI/LYEJEXXFZgqXFR42xScerV0O0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=metaspace.dk; spf=none smtp.mailfrom=metaspace.dk; dkim=pass (2048-bit key) header.d=metaspace-dk.20230601.gappssmtp.com header.i=@metaspace-dk.20230601.gappssmtp.com header.b=fkZMaWbe; arc=none smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=metaspace.dk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=metaspace.dk Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-579fa270e53so5205492a12.3 for ; Mon, 03 Jun 2024 12:15:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20230601.gappssmtp.com; s=20230601; t=1717442109; x=1718046909; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+tUpFHhiF2nyw1IxV5EDxG66GkJExfgKKAw3iF807fE=; b=fkZMaWbexVmsKA6qFpafp8+tfilne1t/Mzl3eZsQDtMwpWHEo7Sy5NRzVfnlO3CPve xdrcwJpQHv2gk87HOLcbx00vcsK5gIdBwpK9LFTcuDAZjZY1qHbalrBPh7iFO7MITv14 Gt4yVB6s81ebJLDgpJucfaViePhYE8OS8dAvbMD9ndCrAOB5Jr/duCfWoN7H7+6fPGBA vG+9ra/7by8SAgo2dFRra3Idrw/o0iOAFJ+JELFAheH4hPZD2FswPVCt+E/VxgGl4SJ4 PVs3CdOfOmMAGJIFA3x5sPpNOoo4pwgsL2YaEjoTzgRMbfOK7dkY6G/BvhUJ1OUzp73i mWVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717442109; x=1718046909; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+tUpFHhiF2nyw1IxV5EDxG66GkJExfgKKAw3iF807fE=; b=iqyezZTseYD63R6sTwmwpYJ3NKNmfevAdaamjR52tiSl8TK+09+7W0nRepQd/spSoZ jh7a2ad+b/bpqR3VT2GaV2mPPx9L2NFZRaA6asGTZO3WKbP96w39XHyeDF7R8uxZh7f/ elXhjQKpIux5D/UxOWZ4pgDGfm/rP2ahtHdxlrUgKjn1O1ZeGlYc4+fNQpt1cLU6QaGn OriSnVnwLtREeQwDh8ZJuzfrCVeqqJ1E3BDsUp2CSnIL6vEmJOO0ie484igxtJO/L0I4 URuqIe9QCtmT/5auH7mHxZJ1JQcndCVsqrwn+9DCBvyCMFCdZo/j24mnLjmFNvubwRPz 9YAA== X-Forwarded-Encrypted: i=1; AJvYcCXYV1xeW9sLX7cU25yiyrVbBiXm9J/Nsd5+nZORLgVObKs44Zgw3+SttnXWX51EkqDMW5/g2pXy3jRnPruzndQskkXUofEFGDtAICmS X-Gm-Message-State: AOJu0Ywq34zgRv61TDRNidxcskUSBnZoXMZtxSrpC8vKYQNxw/qDWtvu oUJzMIjq9y5jfwbu8BJFan32ZvnMzeBWGkOV3VopoVPg/Y476Ca6RCZ/xFe875g= X-Received: by 2002:a17:906:d044:b0:a59:c833:d274 with SMTP id a640c23a62f3a-a68209f7b4dmr785722366b.37.1717442109264; Mon, 03 Jun 2024 12:15:09 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a67e73fb54esm525980566b.61.2024.06.03.12.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 12:15:08 -0700 (PDT) From: Andreas Hindborg To: Jens Axboe , Christoph Hellwig , Keith Busch , Damien Le Moal , Bart Van Assche , Hannes Reinecke , Ming Lei , "linux-block@vger.kernel.org" Cc: Andreas Hindborg , Greg KH , Matthew Wilcox , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Alice Ryhl , Chaitanya Kulkarni , Luis Chamberlain , Yexuan Yang <1182282462@bupt.edu.cn>, =?UTF-8?q?Sergio=20Gonz=C3=A1lez=20Collado?= , Joel Granados , "Pankaj Raghav (Samsung)" , Daniel Gomez , Niklas Cassel , Philipp Stanner , Conor Dooley , Johannes Thumshirn , =?UTF-8?q?Matias=20Bj=C3=B8rling?= , open list , "rust-for-linux@vger.kernel.org" , "lsf-pc@lists.linux-foundation.org" , "gost.dev@samsung.com" Subject: [PATCH v5 2/3] rust: block: add rnull, Rust null_blk implementation Date: Mon, 3 Jun 2024 21:14:54 +0200 Message-ID: <20240603191455.968301-3-nmi@metaspace.dk> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240603191455.968301-1-nmi@metaspace.dk> References: <20240603191455.968301-1-nmi@metaspace.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andreas Hindborg This patch adds an initial version of the Rust null block driver. Signed-off-by: Andreas Hindborg --- drivers/block/Kconfig | 9 ++++++ drivers/block/Makefile | 3 ++ drivers/block/rnull.rs | 73 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 drivers/block/rnull.rs diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig index 5b9d4aaebb81..ed209f4f2798 100644 --- a/drivers/block/Kconfig +++ b/drivers/block/Kconfig @@ -354,6 +354,15 @@ config VIRTIO_BLK This is the virtual block driver for virtio. It can be used with QEMU based VMMs (like KVM or Xen). Say Y or M. +config BLK_DEV_RUST_NULL + tristate "Rust null block driver (Experimental)" + depends on RUST + help + This is the Rust implementation of the null block driver. For now it + is only a minimal stub. + + If unsure, say N. + config BLK_DEV_RBD tristate "Rados block device (RBD)" depends on INET && BLOCK diff --git a/drivers/block/Makefile b/drivers/block/Makefile index 101612cba303..1105a2d4fdcb 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -9,6 +9,9 @@ # needed for trace events ccflags-y += -I$(src) +obj-$(CONFIG_BLK_DEV_RUST_NULL) += rnull_mod.o +rnull_mod-y := rnull.o + obj-$(CONFIG_MAC_FLOPPY) += swim3.o obj-$(CONFIG_BLK_DEV_SWIM) += swim_mod.o obj-$(CONFIG_BLK_DEV_FD) += floppy.o diff --git a/drivers/block/rnull.rs b/drivers/block/rnull.rs new file mode 100644 index 000000000000..b0227cf9ddd3 --- /dev/null +++ b/drivers/block/rnull.rs @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! This is a Rust implementation of the C null block driver. +//! +//! Supported features: +//! +//! - blk-mq interface +//! - direct completion +//! - block size 4k +//! +//! The driver is not configurable. + +use kernel::{ + alloc::flags, + block::mq::{ + self, + gen_disk::{self, GenDisk}, + Operations, TagSet, + }, + error::Result, + new_mutex, pr_info, + prelude::*, + sync::{Arc, Mutex}, + types::ARef, +}; + +module! { + type: NullBlkModule, + name: "rnull_mod", + author: "Andreas Hindborg", + license: "GPL v2", +} + +struct NullBlkModule { + _disk: Pin>>>, +} + +impl kernel::Module for NullBlkModule { + fn init(_module: &'static ThisModule) -> Result { + pr_info!("Rust null_blk loaded\n"); + let tagset = Arc::pin_init(TagSet::new(1, 256, 1), flags::GFP_KERNEL)?; + + let disk = gen_disk::GenDiskBuilder::new() + .capacity_sectors(4096 << 11) + .logical_block_size(4096)? + .physical_block_size(4096)? + .rotational(false) + .build(format_args!("rnullb{}", 0), tagset)?; + + let disk = Box::pin_init(new_mutex!(disk, "nullb:disk"), flags::GFP_KERNEL)?; + + Ok(Self { _disk: disk }) + } +} + +struct NullBlkDevice; + +#[vtable] +impl Operations for NullBlkDevice { + #[inline(always)] + fn queue_rq(rq: ARef>, _is_last: bool) -> Result { + mq::Request::end_ok(rq) + .map_err(|_e| kernel::error::code::EIO) + // We take no refcounts on the request, so we expect to be able to + // end the request. The request reference must be unique at this + // point, and so `end_ok` cannot fail. + .expect("Fatal error - expected to be able to end request"); + + Ok(()) + } + + fn commit_rqs() {} +} -- 2.45.1