Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1322306rwb; Wed, 26 Jul 2023 10:39:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlHnV2YE1qyu9nbsKwd5z5WNrdt47aaBtXmS9IlaLPNlMdxZ63hlSwJLRLRyfvvE7Wk3BQn4 X-Received: by 2002:a17:90b:3e8b:b0:268:7ec:51ae with SMTP id rj11-20020a17090b3e8b00b0026807ec51aemr2184222pjb.41.1690393160352; Wed, 26 Jul 2023 10:39:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690393160; cv=none; d=google.com; s=arc-20160816; b=AzPB4AVBpweLliD8zuHQTTC0myDG7tk5HhK2QoT28RvyoVug8l24p6pkUyjQHPJXQ7 7NTFnM4FqTRJZ9+lqXpvbQJ45nn8iUYcDQL2znUPsBGPvFOkeh3sjll2+GqegQHvrLxk SylyjGlOuX+3mPwjfOlkufnJCtShACpekupbqCIowVEaXAeUGP88EwjF87PAXsOKnHJU qpvz6QnE11AHfyHuMfj/jevJlp/UvpdtsZs3UtaZ8TdTzL8ZsSHHzp83gbV5eJ5VxBQi acEWlPPHhzSBK0Ljh/kRkxgWUauqpCb2VWFeAiYWr3njrxoSx5yQDk32AC+VvyzCnkJ1 hzDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+NdZnqeDcM780/+gn42e6XqUcZ9SEBpegBeCzLz4Dic=; fh=Jpn3R4JmmVOUsuPzBxq53h+Q0nrbpuajN1OLJbY8QB4=; b=Ksy0O3f/QvFM4RwtKBdVAK34HBbTL//d+wjrr57eSafXlWEQf51JwAYJCUO+x6NeRS 9jsuNgoG5UGAij8QyNDshMpGJ35HDMBhRuekKMypn7R+xzo/v8FpF61Twk04nsyr9GKA ePlUmN3K5qPrC6FTevv0ky7p75kL//90hc4kBVHre0uqAJPMCCT1e62BFBQHsonSuip+ ePp4dJoZKHlpxX2/JleZmPcFsGCsTTXw9ZNGgyNProC5EiQ4lD8D992ECyrWMGaXiccX 6rWT61M8VApD70SW1NVoKomiSeiSWpPdxORN11sxKH/QPzin2EK1WCi5WTBmfPP42lCS f5xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=J8CXlfxe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=cisco.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bg22-20020a17090b0d9600b00253160141c7si1386957pjb.83.2023.07.26.10.39.04; Wed, 26 Jul 2023 10:39:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=J8CXlfxe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=cisco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232017AbjGZQuI (ORCPT + 99 others); Wed, 26 Jul 2023 12:50:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231882AbjGZQt6 (ORCPT ); Wed, 26 Jul 2023 12:49:58 -0400 Received: from aer-iport-2.cisco.com (aer-iport-2.cisco.com [173.38.203.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1E121A8 for ; Wed, 26 Jul 2023 09:49:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=4334; q=dns/txt; s=iport; t=1690390196; x=1691599796; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7RIRVvP4MKCFvgB/74OSuv2zzERdm/ln1FIu9qAS8CY=; b=J8CXlfxeGrGUyHEZfUiAYVSy+smmkMJo4tSdKQ5vpwRE2iUizMtqTVMZ 8ZHrCDxtW54z5C8T+nwsxC7e9ifhae3WdSvG9wR8enm+ljdrJdPjbFMxv MLhEV3oryYPySYuAAPqnol6PQQbU8DSmUkkyB3ZLmN0SU+mNB8jv5YTuW U=; X-IronPort-AV: E=Sophos;i="6.01,232,1684800000"; d="scan'208";a="8452952" Received: from aer-iport-nat.cisco.com (HELO aer-core-7.cisco.com) ([173.38.203.22]) by aer-iport-2.cisco.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2023 16:46:27 +0000 Received: from archlinux-cisco.cisco.com (dhcp-10-61-98-211.cisco.com [10.61.98.211]) (authenticated bits=0) by aer-core-7.cisco.com (8.15.2/8.15.2) with ESMTPSA id 36QGjqU2022602 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 26 Jul 2023 16:46:27 GMT From: Ariel Miculas To: rust-for-linux@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, tycho@tycho.pizza, brauner@kernel.org, viro@zeniv.linux.org.uk, ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com, Ariel Miculas Subject: [RFC PATCH v2 10/10] rust: puzzlefs: add oci_root_dir and image_manifest filesystem parameters Date: Wed, 26 Jul 2023 19:45:34 +0300 Message-ID: <20230726164535.230515-11-amiculas@cisco.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230726164535.230515-1-amiculas@cisco.com> References: <20230726164535.230515-1-amiculas@cisco.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated-User: amiculas X-Outbound-SMTP-Client: 10.61.98.211, dhcp-10-61-98-211.cisco.com X-Outbound-Node: aer-core-7.cisco.com X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These parameters are passed when mounting puzzlefs using '-o' option of mount: -o oci_root_dir="/path/to/oci/dir" -o image_manifest="root_hash_of_image_manifest" For a particular manifest in the manifests array in index.json (located in the oci_root_dir), the root hash of the image manifest is found in the digest field. It would be nicer if we could pass the tag, but we don't support json deserialization. Example of mount: mount -t puzzlefs -o oci_root_dir="/home/puzzlefs_oci" -o \ image_manifest="2d6602d678140540dc7e96de652a76a8b16e8aca190bae141297bcffdcae901b" \ none /mnt Signed-off-by: Ariel Miculas --- samples/rust/puzzlefs.rs | 63 ++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/samples/rust/puzzlefs.rs b/samples/rust/puzzlefs.rs index dad7ecc76eca..4e9a8aedf0c1 100644 --- a/samples/rust/puzzlefs.rs +++ b/samples/rust/puzzlefs.rs @@ -7,6 +7,7 @@ use kernel::{ c_str, file, fs, io_buffer::IoBufferWriter, + str::CString, sync::{Arc, ArcBorrow}, }; @@ -31,27 +32,29 @@ struct PuzzlefsInfo { puzzlefs: Arc, } +#[derive(Default)] +struct PuzzleFsParams { + oci_root_dir: Option, + image_manifest: Option, +} + #[vtable] impl fs::Context for PuzzleFsModule { - type Data = (); - - kernel::define_fs_params! {(), - {flag, "flag", |_, v| { pr_info!("flag passed-in: {v}\n"); Ok(()) } }, - {flag_no, "flagno", |_, v| { pr_info!("flagno passed-in: {v}\n"); Ok(()) } }, - {bool, "bool", |_, v| { pr_info!("bool passed-in: {v}\n"); Ok(()) } }, - {u32, "u32", |_, v| { pr_info!("u32 passed-in: {v}\n"); Ok(()) } }, - {u32oct, "u32oct", |_, v| { pr_info!("u32oct passed-in: {v}\n"); Ok(()) } }, - {u32hex, "u32hex", |_, v| { pr_info!("u32hex passed-in: {v}\n"); Ok(()) } }, - {s32, "s32", |_, v| { pr_info!("s32 passed-in: {v}\n"); Ok(()) } }, - {u64, "u64", |_, v| { pr_info!("u64 passed-in: {v}\n"); Ok(()) } }, - {string, "string", |_, v| { pr_info!("string passed-in: {v}\n"); Ok(()) } }, - {enum, "enum", [("first", 10), ("second", 20)], |_, v| { - pr_info!("enum passed-in: {v}\n"); Ok(()) } - }, + type Data = Box; + + kernel::define_fs_params! {Box, + {string, "oci_root_dir", |s, v| { + s.oci_root_dir = Some(CString::try_from_fmt(format_args!("{v}"))?); + Ok(()) + }}, + {string, "image_manifest", |s, v| { + s.image_manifest = Some(CString::try_from_fmt(format_args!("{v}"))?); + Ok(()) + }}, } - fn try_new() -> Result { - Ok(()) + fn try_new() -> Result { + Ok(Box::try_new(PuzzleFsParams::default())?) } } @@ -136,11 +139,27 @@ impl fs::Type for PuzzleFsModule { const FLAGS: i32 = fs::flags::USERNS_MOUNT; const DCACHE_BASED: bool = true; - fn fill_super(_data: (), sb: fs::NewSuperBlock<'_, Self>) -> Result<&fs::SuperBlock> { - let puzzlefs = PuzzleFS::open( - c_str!("/home/puzzlefs_oci"), - c_str!("2d6602d678140540dc7e96de652a76a8b16e8aca190bae141297bcffdcae901b"), - ); + fn fill_super( + data: Box, + sb: fs::NewSuperBlock<'_, Self>, + ) -> Result<&fs::SuperBlock> { + let oci_root_dir = match data.oci_root_dir { + Some(val) => val, + None => { + pr_err!("missing oci_root_dir parameter!\n"); + return Err(ENOTSUPP); + } + }; + + let image_manifest = match data.image_manifest { + Some(val) => val, + None => { + pr_err!("missing image_manifest parameter!\n"); + return Err(ENOTSUPP); + } + }; + + let puzzlefs = PuzzleFS::open(&oci_root_dir, &image_manifest); if let Err(ref e) = puzzlefs { pr_info!("error opening puzzlefs {e}\n"); -- 2.41.0