Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp142733lqj; Sat, 1 Jun 2024 11:27:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUNrbj9ByI9pW/tbhQ3FDbsCOAQjfTWBr2rMwNKqaejsQI5AFJFk5mO+YcvCaHyESkZVsidMM/a+/X6R0XZNNFyM3Dx7gTJi/qJAvKm4g== X-Google-Smtp-Source: AGHT+IGGyzXcdszOLAX/EAVNh+u0KZuwmIh2dfTeZfGLCtrKVo24HHkv09CssUded4RCvA5O3rlb X-Received: by 2002:a05:622a:298a:b0:43f:ee14:c1a7 with SMTP id d75a77b69052e-43ff5260c21mr58756431cf.32.1717266466379; Sat, 01 Jun 2024 11:27:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717266466; cv=pass; d=google.com; s=arc-20160816; b=a8J79ejhbLR2mcvw/ceqjE3w8SFo6IiNosUBFcaGigZa5opr62wmWSk/Uctuo3W61H 5tZLLrLJZ0Uf1oU2yAwh3VW5BmGxIYs+E2IBquUpEtGe5hCt1EW2zR9uCY8PBkyw1zmE X8H8XBTdTgGSMDCFxFJ50ZqgfBd7iOzMP96p+cAkoa+k9bCRKzLmz3Hbeeu+wFyAzh+x R3eS7kskfG4NNq2o5GJpOhfe1N93NhdoGHKhdicnaBnrVy9oPzrwI4YNuLo9JEz1D0Di n7q+UYgF08Ksf+weKKw4XaEa4OOr4jkfixnIyhpkqXtaqds0rJ4bGmaSeDhISau7XiUj j7Sg== 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=tbbL765+//qR9dgQ6VbCwr8fTmxpXU8nBqQZRURLzS8=; fh=rjnkx/dnKulB8i03pCTPcU7tMQ4ch2nDvQ/shZpPXi4=; b=0Rrunpgd3SNXeHkY0r3BMZO1sQcvpi3vn1wEvokXH/lOacA+9nQLDgGXaHz9BpKfEc OE/0PXju5Rssc0wuQXIhCoVw4Htljn6V5SyzdBiEuOMsqnj3+NH9WLtv+KPZzl7SBzVj T+7OhDqZ7CkUxo23QRo2zwK0r0XezbLBK+va7AS16+4OnMGGsFR5KDvldmyqMyIu6nTO nqjZ1grslGje+/1sFgVvdXKpK8j0h7y8dTiLU0CqsO6ufR2WIVj5jY6C4PPUXaR/LoBn fbtpQV397a9g5WvsXIDdO0aqw8CL0hqgiAAqtW7/plW6WbuFjxnHUxO7JF9BS7cLnrZO GAIg==; 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=oPqFa7zT; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-197874-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197874-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43ff24673e5si50898111cf.258.2024.06.01.11.27.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 11:27:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197874-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@metaspace-dk.20230601.gappssmtp.com header.s=20230601 header.b=oPqFa7zT; arc=pass (i=1 dkim=pass dkdomain=metaspace-dk.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-197874-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197874-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C56D31C2168E for ; Sat, 1 Jun 2024 13:41:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E9D9152533; Sat, 1 Jun 2024 13:40:37 +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="oPqFa7zT" Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 2F7B81514E2 for ; Sat, 1 Jun 2024 13:40:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717249236; cv=none; b=KVRcYQhCcNvRiCY6z3W3WeSKFCjaDqy1jvadNps8uLVCLWgIFhE+TtWOVzmmTOdS4Kb0YWT8FFYirXdl/aLJK5NI5V2YnJKpFPhqB05e5T2avLH1lsy/hjyi4JnHxWZ9GsWmjvA8JPUIS1qjin5WQ5gGfOkTDCKLgkIOGrHTIqw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717249236; c=relaxed/simple; bh=wyZWzeRtFIy/lfpFx/42Gg8uCjYL7fD92fkGg/GJRbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sVGZvMC3a+AN0GCjq8kegCVzAPX6kGNRzBnyhkndsgRxIqK0ErQgeVprJW12ne8O67Wgp2FeJuWSOlO2Y4lpw+lhjNbMU8niorZ9NodBG33dlHnHgrFGYL8Vya1m0OOCPj5UVCPaaC8pVfDCqXC8trP+i2+KI+Jtuip/CHXRSMc= 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=oPqFa7zT; arc=none smtp.client-ip=209.85.218.41 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-ej1-f41.google.com with SMTP id a640c23a62f3a-a68b334eb92so18935066b.0 for ; Sat, 01 Jun 2024 06:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=metaspace-dk.20230601.gappssmtp.com; s=20230601; t=1717249231; x=1717854031; 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=tbbL765+//qR9dgQ6VbCwr8fTmxpXU8nBqQZRURLzS8=; b=oPqFa7zTPcsuolwNuLCrS2BI2eJcmN2dr6a/+mHsA+GUmp5xZCjZOLVGGWax/enwdx BIrF9cOsQ2WDaBlRiOLLbV1s+3J+1sI+oS2kfZ4h2hcxCY0Pbtd8/CE0z5KJeGz+K4Rh DHIIr0XzS+mrf+0N4EWv5xbbjcpMuQGxW4ZbR5o6oMiO3FmQl39k04XY6kvNjgoKr5sM PGqqH26qHlNI/P62+r/R9gASP2ng128QnPrqD20cpBeUKfCdkh3Xf8uUD7UxNW6e9+zy oaba5e0uBf164EKAVpsdecJGCpvFMTrnC41qFoqO7C8RWwwnm/D591VU8oTCPlsIVitW h52A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717249231; x=1717854031; 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=tbbL765+//qR9dgQ6VbCwr8fTmxpXU8nBqQZRURLzS8=; b=GVKWR8yGDVJo9+TNdx+EUGHLFpHB709IT2Ei1Q9ytmmF/NVCSnQDd6h8uA3SnnF0/C yTBf+r+BpcgKPc4/t0pGwYFnQLX6fefU0PePztTr5cQ5OWyeHYzMo5QBujHOLlsbSaGh 2CBWM1Lp1gFKVAbacwV+grECM+YVY62QdMlTnXYEyUuXjjHEnKsXG9jZUoVndaeHHEKA VbYX3HmQF2EJlo/M17Gdg1y+EYyZp5l2X6DJjYWs2pDy0SqWmTKHbZ9uRL9SkKooVNAF P/5DVEkKmu97A3YjWpMz7DsMvcE5tKl2ZP18k5Zt2/DAYXGV9jvWsT6m1ArT98dEevfl orJA== X-Forwarded-Encrypted: i=1; AJvYcCUO/XMtgJpL+SOG9AUD6qUsRVNIZ+FKGJnzk1seFU19sFuzTLa7vaKR47wxn8bjI5N1qPYkViCBsxlMdj0pOLdnYdmZCQ+2qc5JuzSI X-Gm-Message-State: AOJu0YwF33xbDUZv0UAtXdJq0xn1r9gWnzBw0T/BD6rv9o2Bf+tUZVIu gyF3B/FfnhERGf9PBMCiiNIEMuh2YBwMWQH7aHo5P+g8IVWenrAfWgx7JWX646E= X-Received: by 2002:a50:99d5:0:b0:579:be37:fa68 with SMTP id 4fb4d7f45d1cf-57a3638cde3mr3702735a12.20.1717249231423; Sat, 01 Jun 2024 06:40:31 -0700 (PDT) Received: from localhost ([79.142.230.34]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57a4606f159sm1047164a12.43.2024.06.01.06.40.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 06:40:31 -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 v4 2/3] rust: block: add rnull, Rust null_blk implementation Date: Sat, 1 Jun 2024 15:40:04 +0200 Message-ID: <20240601134005.621714-3-nmi@metaspace.dk> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240601134005.621714-1-nmi@metaspace.dk> References: <20240601134005.621714-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 | 81 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 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..f90808208936 --- /dev/null +++ b/drivers/block/rnull.rs @@ -0,0 +1,81 @@ +// 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::try_new(1, 256, 1), flags::GFP_KERNEL)?; + + let disk = { + let block_size: u16 = 4096; + if block_size % 512 != 0 || !(512..=4096).contains(&block_size) { + return Err(kernel::error::code::EINVAL); + } + + let mut disk = gen_disk::GenDisk::try_new(tagset)?; + disk.set_name(format_args!("rnullb{}", 0))?; + disk.set_capacity_sectors(4096 << 11); + disk.set_queue_logical_block_size(block_size.into()); + disk.set_queue_physical_block_size(block_size.into()); + disk.set_rotational(false); + disk.add()? + }; + + 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 uniqueue 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