[RFC 03/18] pkernfs: Define an allocator for persistent pages
James Gowans
jgowans at amazon.com
Mon Feb 5 04:01:48 PST 2024
This introduces the concept of a bitmap allocator for pages from the
pkernfs filesystem. The allocation bitmap is stored in the second half
of the first page. This imposes an artificial limit of the maximum size
of the filesystem; this needs to be made extensible.
The allocations can be zeroed, that's it so far. The next commit will
add the ability to allocate and use it.
---
fs/pkernfs/Makefile | 2 +-
fs/pkernfs/allocator.c | 27 +++++++++++++++++++++++++++
fs/pkernfs/pkernfs.c | 1 +
fs/pkernfs/pkernfs.h | 1 +
4 files changed, 30 insertions(+), 1 deletion(-)
create mode 100644 fs/pkernfs/allocator.c
diff --git a/fs/pkernfs/Makefile b/fs/pkernfs/Makefile
index 0a66e98bda07..d8b92a74fbc6 100644
--- a/fs/pkernfs/Makefile
+++ b/fs/pkernfs/Makefile
@@ -3,4 +3,4 @@
# Makefile for persistent kernel filesystem
#
-obj-$(CONFIG_PKERNFS_FS) += pkernfs.o inode.o dir.o
+obj-$(CONFIG_PKERNFS_FS) += pkernfs.o inode.o allocator.o dir.o
diff --git a/fs/pkernfs/allocator.c b/fs/pkernfs/allocator.c
new file mode 100644
index 000000000000..1d4aac9c4545
--- /dev/null
+++ b/fs/pkernfs/allocator.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include "pkernfs.h"
+
+/**
+ * For allocating blocks from the pkernfs filesystem.
+ * The first two blocks are special:
+ * - the first block is persitent filesystme metadata and
+ * a bitmap of allocated blocks
+ * - the second block is an array of persisted inodes; the
+ * inode store.
+ */
+
+void *pkernfs_allocations_bitmap(struct super_block *sb)
+{
+ /* Allocations is 2nd half of first block */
+ return pkernfs_mem + (1 << 20);
+}
+
+void pkernfs_zero_allocations(struct super_block *sb)
+{
+ memset(pkernfs_allocations_bitmap(sb), 0, (1 << 20));
+ /* First page is persisted super block and allocator bitmap */
+ set_bit(0, pkernfs_allocations_bitmap(sb));
+ /* Second page is inode store */
+ set_bit(1, pkernfs_allocations_bitmap(sb));
+}
diff --git a/fs/pkernfs/pkernfs.c b/fs/pkernfs/pkernfs.c
index 518c610e3877..199c2c648bca 100644
--- a/fs/pkernfs/pkernfs.c
+++ b/fs/pkernfs/pkernfs.c
@@ -25,6 +25,7 @@ static int pkernfs_fill_super(struct super_block *sb, struct fs_context *fc)
} else {
pr_info("pkernfs: Clean super block; initialising\n");
pkernfs_initialise_inode_store(sb);
+ pkernfs_zero_allocations(sb);
psb->magic_number = PKERNFS_MAGIC_NUMBER;
pkernfs_get_persisted_inode(sb, 1)->flags = PKERNFS_INODE_FLAG_DIR;
strscpy(pkernfs_get_persisted_inode(sb, 1)->filename, ".", PKERNFS_FILENAME_LEN);
diff --git a/fs/pkernfs/pkernfs.h b/fs/pkernfs/pkernfs.h
index 192e089b3151..4655780f31f2 100644
--- a/fs/pkernfs/pkernfs.h
+++ b/fs/pkernfs/pkernfs.h
@@ -34,6 +34,7 @@ struct pkernfs_inode {
};
void pkernfs_initialise_inode_store(struct super_block *sb);
+void pkernfs_zero_allocations(struct super_block *sb);
struct inode *pkernfs_inode_get(struct super_block *sb, unsigned long ino);
struct pkernfs_inode *pkernfs_get_persisted_inode(struct super_block *sb, int ino);
--
2.40.1
More information about the kexec
mailing list