Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp494323lqo; Thu, 16 May 2024 12:06:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXyVrgsk6aU4YNiKHK/owjaugQxyLjP7zQSe/u5wyJyHU/RiR9fUq24DKW9BIpwWmuS5zSiO4BONNcgWtEgLX2O+X4R+5cA44+ysS0/Bg== X-Google-Smtp-Source: AGHT+IFT8rR2I0uOXcG8XV2Jo49QOuihXIZHNZw7Gi+fON44Js87VvJGr1Q9TfrFW4c+2I1kF+hI X-Received: by 2002:a05:6870:61d6:b0:229:fd96:1e6f with SMTP id 586e51a60fabf-24172bb1a3cmr23855940fac.24.1715886393024; Thu, 16 May 2024 12:06:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715886392; cv=pass; d=google.com; s=arc-20160816; b=zaP2bUmPexKOaRkwGf5VX4a98hp9/7l0+CLEgvyH6HGaLW0StB3xj+gC7pHybyKZKl FQuSzDqVxbhvhmPFT1GNJfRSkZm8guivO2FI1XyBJX37Xhlq+999By/ZrXd0p1Neglfu EpQcZzw1qrDLXs6G/wDUEXe8QgOeR3hKZBu1tBDkxFPhfO006aoDhGXNA4n9ldzH5mwz /bmGKWt+zkvci9+ymrb2eC1SO0xgpMue0S7vqoCuUbtijAYTLsLraXKW3JoKQSqe+gqR vAkiJFKIWQPNDLQk8Qr/L+KDK/9x/WTERHNT7vQfU5xHgbu2e0o7pmthw6Fiv428GGpx Ng7A== 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=+pfayBA377Ipl2qQGaCZtcT9bhjEsaDIsf91AaD2x7E=; fh=DGE/Rt7UZyKJ8ICVIgmeDLsrdvw5JULr/fcEfbQDVFQ=; b=exgPWi4Rt5GkG9jii4vCiZFreaUHetrYlQEMbzms0+Gu4OzelN7UZ8icyMbEEBs9Y6 zyBC9qT9RM0PkWW9W7/hoM2umQOEFoHCvM4GKh1qpGSOdtArERAUTZgjHG+u2qBuzYBf S0OaFZBkcP/085FcSSZCXc5ypuWlj5C6+R5pvkC+WyNl6/fYaZsroq+DYfvxsJicg92t 2800zOszUflykTLzZAb3a16gf9oFJX6ODEfuq5XDe7KHrOxgbntIKnToeiFzsgDv2M5p J1I8Mch8ShsUxBHjVyMB+pjLZLGl2lszdTk2oVjWwgIfJtCX2nGkJOSvuyDXHw7LAjdO iSDw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=ZHbCJ+XJ; arc=pass (i=1 spf=pass spfdomain=cisco.com dkim=pass dkdomain=cisco.com dmarc=pass fromdomain=cisco.com); spf=pass (google.com: domain of linux-kernel+bounces-181499-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181499-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cisco.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 71dfb90a1353d-4e1553510dcsi581704e0c.209.2024.05.16.12.06.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 12:06:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181499-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=@cisco.com header.s=iport header.b=ZHbCJ+XJ; arc=pass (i=1 spf=pass spfdomain=cisco.com dkim=pass dkdomain=cisco.com dmarc=pass fromdomain=cisco.com); spf=pass (google.com: domain of linux-kernel+bounces-181499-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181499-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cisco.com 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 B736E1C21539 for ; Thu, 16 May 2024 19:06:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96D90159565; Thu, 16 May 2024 19:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=cisco.com header.i=@cisco.com header.b="ZHbCJ+XJ" Received: from aer-iport-4.cisco.com (aer-iport-4.cisco.com [173.38.203.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C8C0158D77; Thu, 16 May 2024 19:04:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.38.203.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715886272; cv=none; b=e+ufxdwX3I/GwA3G1hNabAlhoGE4yKSgNWKXXOEXn65/TO62O+q7K8O1Welkm+P3w5vJTYqC9xaRoX3h2oqLWYFtKtkZ0fzVe2+w8HPlG76yIYZ1SXatuRqSD0qqjilqitSsTSHhe59gyvc6V7WuS0SbwR5GMPA9Jq+vK7WnwT0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715886272; c=relaxed/simple; bh=YVkKY+DVfu3Ns5YhZFxnBhlRk3J/PwOtX93n3BmC/r0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rNKOdhjSll4kayBYjVd+RwlxhHcTp+tERECLsTX2Pb7heCjzREbiN5SgzCh+7DqAFc9iBc7nMb61gqdHTbhdx/igjjynJ1y+BZqoIGgMPbYFkEz8S9eFXPT+6bFoXab43eRmQBPc8398qs2P4K4E12jRABlzpJzH9iOrdDmqBCU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cisco.com; spf=pass smtp.mailfrom=cisco.com; dkim=pass (1024-bit key) header.d=cisco.com header.i=@cisco.com header.b=ZHbCJ+XJ; arc=none smtp.client-ip=173.38.203.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cisco.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cisco.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cisco.com; i=@cisco.com; l=3251; q=dns/txt; s=iport; t=1715886271; x=1717095871; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+pfayBA377Ipl2qQGaCZtcT9bhjEsaDIsf91AaD2x7E=; b=ZHbCJ+XJHSms5kH0i4Px/dU5jPf2aFyMfpSdlDBfOX0G1R2HWtveJ3lu epg4ZTnecHPCu/rt7QHo6i/j98sxghOkaBU2w2nSHqvK8+eyFT16uUx8t i+VJ4pG/jRaLEtEKF/42xlVl3TYjFNZ+eyCwnDolqtArxV1eXARBYXW1d M=; X-CSE-ConnectionGUID: IN3ktra0TnyQzrIlWsIUSA== X-CSE-MsgGUID: MVb2X31TSLeouobFH9aTTA== X-IronPort-AV: E=Sophos;i="6.08,165,1712620800"; d="scan'208";a="12379876" Received: from aer-iport-nat.cisco.com (HELO aer-core-10.cisco.com) ([173.38.203.22]) by aer-iport-4.cisco.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2024 19:04:28 +0000 Received: from localhost (ams3-vpn-dhcp4879.cisco.com [10.61.83.14]) (authenticated bits=0) by aer-core-10.cisco.com (8.15.2/8.15.2) with ESMTPSA id 44GJ4RKW101499 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 16 May 2024 19:04:28 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, shallyn@cisco.com, Ariel Miculas Subject: [RFC PATCH v3 22/22] fs: puzzlefs: implement statfs for puzzlefs Date: Thu, 16 May 2024 22:03:45 +0300 Message-Id: <20240516190345.957477-23-amiculas@cisco.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240516190345.957477-1-amiculas@cisco.com> References: <20240516190345.957477-1-amiculas@cisco.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated-User: amiculas@cisco.com X-Outbound-SMTP-Client: 10.61.83.14, ams3-vpn-dhcp4879.cisco.com X-Outbound-Node: aer-core-10.cisco.com In order to use a filesystem as a lower filesystem in an overlay, it must implement statfs. Signed-off-by: Ariel Miculas --- fs/puzzlefs/puzzle/inode.rs | 26 ++++++++++++++++++++++++-- fs/puzzlefs/puzzlefs.rs | 21 +++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/fs/puzzlefs/puzzle/inode.rs b/fs/puzzlefs/puzzle/inode.rs index 318edbdc5163..a34f1064b632 100644 --- a/fs/puzzlefs/puzzle/inode.rs +++ b/fs/puzzlefs/puzzle/inode.rs @@ -14,6 +14,8 @@ pub(crate) struct PuzzleFS { pub(crate) oci: Image, layers: Vec, + pub(crate) total_inodes: u64, + pub(crate) total_block_size: u64, } impl PuzzleFS { @@ -22,13 +24,33 @@ pub(crate) fn open(oci_root_dir: &CStr, rootfs_path: &CStr) -> Result let oci = Image::open(vfs_mount)?; let rootfs = oci.open_rootfs_blob(rootfs_path)?; + let mut total_block_size = 0; + let mut total_inodes: u64 = 0; let mut layers = Vec::new(); for md in rootfs.metadatas.iter() { let digest = Digest::try_from(md)?; - layers.push(oci.open_metadata_blob(&digest)?, GFP_KERNEL)?; + let layer = oci.open_metadata_blob(&digest)?; + + // This may take up too much time, but we need to implement statfs if we want to use + // puzzlefs as a lower filesystem in overlayfs + let inodes = layer.get_inode_vector()?; + total_inodes += u64::from(inodes.len()); + for inode_number in 0..inodes.len() { + let inode = Inode::from_capnp(inodes.get(inode_number))?; + if let InodeMode::File { chunks } = inode.mode { + total_block_size += chunks.iter().map(|chunk| chunk.len).sum::(); + } + } + + layers.push(layer, GFP_KERNEL)?; } - Ok(PuzzleFS { oci, layers }) + Ok(PuzzleFS { + oci, + layers, + total_inodes, + total_block_size, + }) } pub(crate) fn find_inode(&self, ino: u64) -> Result { diff --git a/fs/puzzlefs/puzzlefs.rs b/fs/puzzlefs/puzzlefs.rs index 932f31917992..633f60983849 100644 --- a/fs/puzzlefs/puzzlefs.rs +++ b/fs/puzzlefs/puzzlefs.rs @@ -4,7 +4,7 @@ use kernel::fs::{ address_space, dentry, dentry::DEntry, file, file::DirEntryType, file::File, inode, - inode::INode, sb, Offset, + inode::INode, sb, Offset, Stat, }; use kernel::prelude::*; use kernel::types::{ARef, Either, Locked}; @@ -23,6 +23,10 @@ license: "GPL", } +const PUZZLEFS_BSIZE: u64 = 1 << PUZZLEFS_BSIZE_BITS; +const PUZZLEFS_BSIZE_BITS: u8 = 12; +const PUZZLEFS_MAGIC: usize = 0x7a7a7570; + fn mode_to_fs_type(inode: &Inode) -> Result { Ok(match inode.mode { InodeMode::File { .. } => DirEntryType::Reg, @@ -156,7 +160,7 @@ fn fill_super( ); let puzzlefs = puzzlefs?; - sb.set_magic(0x7a7a7570); + sb.set_magic(PUZZLEFS_MAGIC); Ok(Box::new(puzzlefs, GFP_KERNEL)?) } @@ -194,6 +198,19 @@ fn read_xattr( } Err(ENODATA) } + + fn statfs(dentry: &DEntry) -> Result { + let puzzlefs = dentry.super_block().data(); + + Ok(Stat { + magic: PUZZLEFS_MAGIC, + namelen: isize::MAX, + bsize: PUZZLEFS_BSIZE as _, + // Round total_block_size up + blocks: (puzzlefs.total_block_size + PUZZLEFS_BSIZE - 1) / PUZZLEFS_BSIZE, + files: puzzlefs.total_inodes, + }) + } } #[vtable] -- 2.34.1