Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 555AC3DA5B8 for ; Fri, 24 Apr 2026 14:05:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777039539; cv=none; b=eyTVpssD7axB13TR8/FWd7UZdIKl+WiBj/lwxSAGt7wQV43YeA79TnvSbCzT/v83GuhjMamw4kyA7u8ylx1CtPGZurfYFyoAghO+GDyq2hPLhO5Lsu5wZcfZqeQB8fZuNeS43FoqXG7dQxBENB2xvrzEQOyUgvkvke5tS54WYD0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777039539; c=relaxed/simple; bh=XoWGdviZqlWpCDX/eRqvM1uk9kRMM48lnQ+Hr0wcnl4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J3Rdd5i211UVGv31epZLogo/5D/yGsc9lcpprQCbBC/uGLzZEDrEjUERg/7jX7Y3zTR0cjWgahpeiV7LEBiOjcOnwb8IjFt/HBEjZ0WI64mvbN61cDGre5rePt4a94v0w9aSBnWYACaEhLCwPvNILdtHYikHIX7YOg+t68WEpTo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=permerror header.from=versity.com; spf=pass smtp.mailfrom=versity.com; dkim=pass (2048-bit key) header.d=versity.com header.i=@versity.com header.b=kAHyxSbg; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=permerror header.from=versity.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=versity.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=versity.com header.i=@versity.com header.b="kAHyxSbg" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-ba61a0a2d26so965325366b.2 for ; Fri, 24 Apr 2026 07:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=versity.com; s=google; t=1777039537; x=1777644337; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Zqg+4160hkn1DT9a6HzG8ycj9j5wgPZrfbBgLpR8IYA=; b=kAHyxSbgiWl3rXW2dtdhuyCo/tjmJj8yLAt1yQchFQJDsdQlNpipqmLFL0gZJTE7PA YTOM8Pp4x7PRNUDcNxNSQDQ8HHZMysYRvQfCEVC8dAhjmzLitzEgCpGjNmZqUwAMF5rj R2qZELW2WR8mvrXHaf6cPPyeThplh+d3zs+7Dz1UtnfRzSX7A77TayBo9Qp8O6L/SvMK E8Ew7WORgPL20v8bs+SmnmtOxjslEoaVLgWjgr+6s6I+G+9aHmHoDEpQ1b7Lx/NDqhQC qXXpKrAHQbDKgyzonT4lR6cUgjK7REkAwEKzDbYN5HGGQK3ZG9CmQ9anx4NI5S20VFFl JkxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777039537; x=1777644337; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Zqg+4160hkn1DT9a6HzG8ycj9j5wgPZrfbBgLpR8IYA=; b=b7WTDcRxC55/rfytLZBYPa15rr2v+dInJfIDT2r8Iasrtti6YoFqd362sLjLLKs8qo k9EqVEGfFQ7XfnQMt0ms7J9q1fdzMWb1OlIyNxUKy9+eI99wVkuqxC+zW1dHQZo0+ekg Tebk3b5lvnGk4RaaqV18vZPdkqfJpKl52RcfEl2xeZJc7ScU73x/CFakPEK0u7w7u4jb Hfmht8L6yVrEhA7Nv8xrRUW2TCaszO8bJMMi2/e3UjOj7+rZZtVSA3W0XEkiXAiGjxyl CV0kHkxTmtZwac8JmRVVOMJnwG+U7elVkmAbgAsnTOjKY6wUUReaJQUxeDVLFuzjG+t7 cAOw== X-Gm-Message-State: AOJu0Yxk43uoYJusLBzp1fI3xqiaT+4udELpOEQT//wfv7NE0QqUB4yR zl6RuJi5+fog47IR2R6JFQDCZzML8D27qm6UIXvT0G/Dpw9+VkhdU0o4loMuki9vz2DCYHbC+Ri w3YhW X-Gm-Gg: AeBDieuwK2LypjXWYNdDEYOHYzbcdUrl5ZoDKZk7ZWsbcy87fpMQc+XI3EOKJycA448 TBy+mzJnhWqrQ/lNWNlE91iHqsFQbzF2gTuwidPXGU+oaFHP1C9Tzn7rFJLS9FL3Q5SgjkbpUz/ YFO4fBKn6Zzf66O4k39X83jFR0H3yGwsyY7yE8yeiaKY5Gg6vh8krIazCY2OTUj7KgQx1cAlnlz IXl6p/bc1k+r3FGg7pdYM/e07Hp5SsqJ93UJvMDui9HnCiGMg1V2itkBsVbTmt37fVlmopzwG4a AKSJFoKXyiGYnTWyWra78cCz6ExIH8w0cCB2QuPFqtCiOkmljddwbgHHLtXZAHsMgpVQLuHZINK nP6X0X97GJzWBr98i+39q9dZX1/fFGodBNnr9iFTbbjQkNNrEI/OXxMZPWw/WzgGo2o5VX/JqPv Tp3bKnu3TpIdrsTYsKaOFlfJQ8ckbD4ukUYE+IY4bvZ/1x9muVYww9CVC4mdcqF9Dzygi8QiFIY 2F4W0E1wDXwXAXw/DeVXjKTc+Wx4MeU0WaI382MRnK0FMzW X-Received: by 2002:a17:906:fe4d:b0:b9d:ed9a:5f30 with SMTP id a640c23a62f3a-ba41b1dfccdmr1647731666b.48.1777039536541; Fri, 24 Apr 2026 07:05:36 -0700 (PDT) Received: from localhost.localdomain (46-117-212-87.ftth.glasoperator.nl. [87.212.117.46]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ba454d1bbb1sm766348966b.38.2026.04.24.07.05.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2026 07:05:35 -0700 (PDT) From: Valerie Aurora To: rpdfs-devel@lists.linux.dev Subject: [PATCH 5/8] rpdfs: add basic file data initialization Date: Fri, 24 Apr 2026 16:05:17 +0200 Message-ID: <20260424140520.3443624-6-val@versity.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20260424140520.3443624-1-val@versity.com> References: <20260424140520.3443624-1-val@versity.com> Precedence: bulk X-Mailing-List: rpdfs-devel@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Initialize the file data root, plus a few simple routines to calculate mapping block levels. Rename the field in the inode from "data" to "data_root" to avoid confusion with the "data" member of struct rpdfs_block_handle. Signed-off-by: Valerie Aurora --- fs/rpdfs/Makefile | 1 + fs/rpdfs/data.c | 90 +++++++++++++++++++++++++++++++++++++++++ fs/rpdfs/data.h | 11 +++++ fs/rpdfs/format-block.h | 6 +-- fs/rpdfs/inode.c | 8 ++++ fs/rpdfs/inode.h | 1 + 6 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 fs/rpdfs/data.c create mode 100644 fs/rpdfs/data.h diff --git a/fs/rpdfs/Makefile b/fs/rpdfs/Makefile index d995103ea5a8..f8301d86682b 100644 --- a/fs/rpdfs/Makefile +++ b/fs/rpdfs/Makefile @@ -12,6 +12,7 @@ rpdfs-y := balloc.o \ block.o \ btree.o \ btree_txn.o \ + data.o \ dir.o \ file.o \ ht.o \ diff --git a/fs/rpdfs/data.c b/fs/rpdfs/data.c new file mode 100644 index 000000000000..b7538004d14a --- /dev/null +++ b/fs/rpdfs/data.c @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include +#include +#include + +#include "balloc.h" +#include "inode.h" +#include "format-block.h" +#include "pr.h" +#include "super.h" +#include "data.h" + +/* + * File data is stored in simple tree of mapping blocks with data all + * at the same level of the tree. The topmost block in the tree and its + * level are stored in the inode. The tree is sparse and branches are + * grown as necessary to index newly written data blocks. While + * manipulating the tree, we use levels to identify the blocks at + * various levels of the tree, with the highest levels closer to the + * root. + * + * The data root field in the inode contains both the persistent + * reference (block number, etc.) to the root block of the tree, plus + * the height of the tree (the level of the block it points to, plus 1). + * The root block reference is not part of an mapping block. + * + * The level of a block is: + * + * 0 = data block + * 1 = references to data blocks + * 2 = references to single mapping blocks (pointing to data blocks) + * 3 = references to double mapping blocks + * 4 = references to triple mapping blocks + * + * Thus a data root reference with height 1 points to a block of level 0 + * = a single block of data at logical file offset 0. + */ + +/* + * Return the logical block number containing offset within a file. + */ +static u64 lblk_from_offset(u64 offset) +{ + return offset >> RPDFS_BLOCK_SHIFT; +} + +/* + * Calculate the index of the block reference for this logical block + * within an mapping block at this level (1 = pointers to data blocks). + */ +static u32 calc_ref_ind(u64 lblk, int level) +{ + u32 ind; + int i; + + BUG_ON(level < 1); + + for (i = 1; i < level; i++) + lblk >>= RPDFS_DATA_REFS_PER_BLK_SHIFT; + + ind = lblk & (RPDFS_DATA_REFS_PER_BLK - 1ULL); + + return ind; +} + +/* + * Calculate the height of the tree (level of the root pointer) needed + * to index the logical block lblk in this file. + */ +static u8 height_from_lblk(u64 lblk) +{ + u8 height = 2; + + if (lblk == 0) + return 1; + + while (lblk >>= RPDFS_DATA_REFS_PER_BLK_SHIFT) + height++; + + return height; +} + +void rpdfs_data_root_init(struct rpdfs_data_root *data) +{ + data->height = 0; + data->ref.bnr = 0; + data->ref.alloc_counter = 0; +} diff --git a/fs/rpdfs/data.h b/fs/rpdfs/data.h new file mode 100644 index 000000000000..bb6b0c7dea86 --- /dev/null +++ b/fs/rpdfs/data.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef RPDFS_DATA_H +#define RPDFS_DATA_H + +#include "format-block.h" + +void rpdfs_data_root_init(struct rpdfs_data_root *data); + +extern const struct address_space_operations rpdfs_aops; + +#endif diff --git a/fs/rpdfs/format-block.h b/fs/rpdfs/format-block.h index 395e6d2d17e7..04b4ddf5d614 100644 --- a/fs/rpdfs/format-block.h +++ b/fs/rpdfs/format-block.h @@ -6,7 +6,7 @@ #include #define RPDFS_BLOCK_SHIFT 12 -#define RPDFS_BLOCK_SIZE (1 << RPDFS_BLOCK_SHIFT) +#define RPDFS_BLOCK_SIZE (1ULL << RPDFS_BLOCK_SHIFT) #define RPDFS_BLOCK_MASK (RPDFS_BLOCK_SIZE - 1ULL) struct rpdfs_block_ref { @@ -138,7 +138,7 @@ struct rpdfs_data_root { #define RPDFS_DATA_REFS_PER_BLK_SHIFT const_ilog2(RPDFS_DATA_REFS_PER_BLK) -struct rpdfs_indirect_block { +struct rpdfs_map_block { struct rpdfs_block_ref refs[RPDFS_DATA_REFS_PER_BLK]; }; @@ -168,7 +168,7 @@ struct rpdfs_inode { __le64 crtime_nsec; struct rpdfs_btree_root dirents; struct rpdfs_btree_root xattrs; - struct rpdfs_data_root data; + struct rpdfs_data_root data_root; }; #define RPDFS_ROOT_INO 1 diff --git a/fs/rpdfs/inode.c b/fs/rpdfs/inode.c index 7abd2c58373f..947a8f1703a3 100644 --- a/fs/rpdfs/inode.c +++ b/fs/rpdfs/inode.c @@ -9,6 +9,7 @@ #include "btree.h" #include "compare.h" +#include "data.h" #include "dir.h" #include "file.h" #include "inode.h" @@ -80,6 +81,8 @@ static void copy_rinode_to_vfs_inode(struct inode *inode, struct rpdfs_inode *ri ri->xattrs = rinode->xattrs; ri->xattr_creates = rinode->xattr_creates; + + ri->data_root = rinode->data_root; } __always_unused @@ -118,6 +121,8 @@ static void print_inode_change(struct inode *inode, struct rpdfs_inode *rinode) print_diff64("dirents", ri->dirents.ref.bnr, rinode->dirents.ref.bnr); print_diff64("xattrs", ri->xattrs.ref.bnr, rinode->xattrs.ref.bnr); print_diff64("xattr_creates", ri->xattr_creates, rinode->xattr_creates); + print_diff64("data_root.height", ri->data_root.height, rinode->data_root.height); + print_diff64("data_root.ref.bnr", ri->data_root.ref.bnr, rinode->data_root.ref.bnr); } static __le64 cpu_ts64_to_le64_ns(struct timespec64 ts) @@ -145,6 +150,8 @@ static void copy_vfs_inode_to_rinode(struct rpdfs_inode *rinode, struct inode *i rinode->xattrs = ri->xattrs; rinode->xattr_creates = ri->xattr_creates; + + rinode->data_root = ri->data_root; } /* @@ -342,6 +349,7 @@ struct inode *rpdfs_new_inode(struct super_block *sb, struct rpdfs_ino_gen *ig) rpdfs_btree_root_init(&ri->dirents); rpdfs_btree_root_init(&ri->xattrs); + rpdfs_data_root_init(&ri->data_root); ts = inode_set_ctime_current(inode); inode_set_mtime_to_ts(inode, ts); diff --git a/fs/rpdfs/inode.h b/fs/rpdfs/inode.h index 3b0be2d83e61..3892fdcc8b1b 100644 --- a/fs/rpdfs/inode.h +++ b/fs/rpdfs/inode.h @@ -25,6 +25,7 @@ struct rpdfs_inode_info { struct rpdfs_ino_gen ig; struct rpdfs_btree_root dirents; struct rpdfs_btree_root xattrs; + struct rpdfs_data_root data_root; struct inode vfs_inode; }; -- 2.49.0