From: James Gowans <jgowans@amazon.com>
To: <linux-kernel@vger.kernel.org>
Cc: James Gowans <jgowans@amazon.com>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Steve Sistare <steven.sistare@oracle.com>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
"Anthony Yznaga" <anthony.yznaga@oracle.com>,
Mike Rapoport <rppt@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>, <linux-mm@kvack.org>,
Jason Gunthorpe <jgg@ziepe.ca>, <linux-fsdevel@vger.kernel.org>,
Usama Arif <usama.arif@bytedance.com>, <kvm@vger.kernel.org>,
Alexander Graf <graf@amazon.com>,
David Woodhouse <dwmw@amazon.co.uk>,
Paul Durrant <pdurrant@amazon.co.uk>,
Nicolas Saenz Julienne <nsaenz@amazon.es>
Subject: [PATCH 08/10] guestmemfs: Block modifications when serialised
Date: Mon, 5 Aug 2024 11:32:43 +0200 [thread overview]
Message-ID: <20240805093245.889357-9-jgowans@amazon.com> (raw)
In-Reply-To: <20240805093245.889357-1-jgowans@amazon.com>
Once the memory regions for inodes, mappings and allocations have been
serialised, further modifications would break the serialised data; it
would no longer be valid.
Return an error code if attempting to create new files or allocate data
for files once serialised.
Signed-off-by: James Gowans <jgowans@amazon.com>
---
fs/guestmemfs/file.c | 19 ++++++++++++++++---
fs/guestmemfs/guestmemfs.c | 1 +
fs/guestmemfs/guestmemfs.h | 1 +
fs/guestmemfs/inode.c | 6 ++++++
fs/guestmemfs/serialise.c | 8 +++++++-
5 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/fs/guestmemfs/file.c b/fs/guestmemfs/file.c
index b1a52abcde65..8707a9d3ad90 100644
--- a/fs/guestmemfs/file.c
+++ b/fs/guestmemfs/file.c
@@ -8,19 +8,32 @@ static int truncate(struct inode *inode, loff_t newsize)
unsigned long free_block;
struct guestmemfs_inode *guestmemfs_inode;
unsigned long *mappings;
+ int rc = 0;
+ struct guestmemfs_sb *psb = GUESTMEMFS_PSB(inode->i_sb);
+
+ spin_lock(&psb->allocation_lock);
+
+ if (psb->serialised) {
+ rc = -EBUSY;
+ goto out;
+ }
guestmemfs_inode = guestmemfs_get_persisted_inode(inode->i_sb, inode->i_ino);
mappings = guestmemfs_inode->mappings;
i_size_write(inode, newsize);
for (int block_idx = 0; block_idx * PMD_SIZE < newsize; ++block_idx) {
free_block = guestmemfs_alloc_block(inode->i_sb);
- if (free_block < 0)
+ if (free_block < 0) {
/* TODO: roll back allocations. */
- return -ENOMEM;
+ rc = -ENOMEM;
+ goto out;
+ }
*(mappings + block_idx) = free_block;
++guestmemfs_inode->num_mappings;
}
- return 0;
+out:
+ spin_unlock(&psb->allocation_lock);
+ return rc;
}
static int inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *iattr)
diff --git a/fs/guestmemfs/guestmemfs.c b/fs/guestmemfs/guestmemfs.c
index cf47e5100504..d854033bfb7e 100644
--- a/fs/guestmemfs/guestmemfs.c
+++ b/fs/guestmemfs/guestmemfs.c
@@ -42,6 +42,7 @@ static int guestmemfs_fill_super(struct super_block *sb, struct fs_context *fc)
if (GUESTMEMFS_PSB(sb)) {
pr_info("Restored super block from KHO\n");
+ GUESTMEMFS_PSB(sb)->serialised = 0;
} else {
struct guestmemfs_sb *psb;
diff --git a/fs/guestmemfs/guestmemfs.h b/fs/guestmemfs/guestmemfs.h
index 263d995b75ed..91cc06ae45a5 100644
--- a/fs/guestmemfs/guestmemfs.h
+++ b/fs/guestmemfs/guestmemfs.h
@@ -21,6 +21,7 @@ struct guestmemfs_sb {
struct guestmemfs_inode *inodes;
void *allocator_bitmap;
spinlock_t allocation_lock;
+ bool serialised;
};
// If neither of these are set the inode is not in use.
diff --git a/fs/guestmemfs/inode.c b/fs/guestmemfs/inode.c
index 61f70441d82c..d521b35d4992 100644
--- a/fs/guestmemfs/inode.c
+++ b/fs/guestmemfs/inode.c
@@ -48,6 +48,12 @@ static unsigned long guestmemfs_allocate_inode(struct super_block *sb)
struct guestmemfs_sb *psb = GUESTMEMFS_PSB(sb);
spin_lock(&psb->allocation_lock);
+
+ if (psb->serialised) {
+ spin_unlock(&psb->allocation_lock);
+ return -EBUSY;
+ }
+
next_free_ino = psb->next_free_ino;
psb->allocated_inodes += 1;
if (!next_free_ino)
diff --git a/fs/guestmemfs/serialise.c b/fs/guestmemfs/serialise.c
index eb70d496a3eb..347eb8049a71 100644
--- a/fs/guestmemfs/serialise.c
+++ b/fs/guestmemfs/serialise.c
@@ -111,7 +111,7 @@ int guestmemfs_serialise_to_kho(struct notifier_block *self,
switch (cmd) {
case KEXEC_KHO_ABORT:
- /* No rollback action needed. */
+ GUESTMEMFS_PSB(guestmemfs_sb)->serialised = 0;
return NOTIFY_DONE;
case KEXEC_KHO_DUMP:
/* Handled below */
@@ -120,6 +120,7 @@ int guestmemfs_serialise_to_kho(struct notifier_block *self,
return NOTIFY_BAD;
}
+ spin_lock(&GUESTMEMFS_PSB(guestmemfs_sb)->allocation_lock);
err |= fdt_begin_node(fdt, "guestmemfs");
err |= fdt_property(fdt, "compatible", compatible, sizeof(compatible));
@@ -134,6 +135,11 @@ int guestmemfs_serialise_to_kho(struct notifier_block *self,
err |= fdt_end_node(fdt);
+ if (!err)
+ GUESTMEMFS_PSB(guestmemfs_sb)->serialised = 1;
+
+ spin_unlock(&GUESTMEMFS_PSB(guestmemfs_sb)->allocation_lock);
+
pr_info("Serialised extends [0x%llx + 0x%llx] via KHO: %i\n",
guestmemfs_base, guestmemfs_size, err);
--
2.34.1
next prev parent reply other threads:[~2024-08-05 9:35 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-05 9:32 [PATCH 00/10] Introduce guestmemfs: persistent in-memory filesystem James Gowans
2024-08-05 9:32 ` [PATCH 01/10] guestmemfs: Introduce filesystem skeleton James Gowans
2024-08-05 10:20 ` Christian Brauner
2024-08-05 9:32 ` [PATCH 02/10] guestmemfs: add inode store, files and dirs James Gowans
2024-08-05 9:32 ` [PATCH 03/10] guestmemfs: add persistent data block allocator James Gowans
2024-08-05 9:32 ` [PATCH 04/10] guestmemfs: support file truncation James Gowans
2024-08-05 9:32 ` [PATCH 05/10] guestmemfs: add file mmap callback James Gowans
2024-10-29 23:05 ` Elliot Berman
2024-10-30 22:18 ` Frank van der Linden
2024-11-01 12:55 ` Gowans, James
2024-10-31 15:30 ` Gowans, James
2024-10-31 16:06 ` Jason Gunthorpe
2024-11-01 13:01 ` Gowans, James
2024-11-01 13:42 ` Jason Gunthorpe
2024-11-02 8:24 ` Gowans, James
2024-11-04 11:11 ` Mike Rapoport
2024-11-04 14:39 ` Jason Gunthorpe
2024-11-04 10:49 ` Mike Rapoport
2024-08-05 9:32 ` [PATCH 06/10] kexec/kho: Add addr flag to not initialise memory James Gowans
2024-08-05 9:32 ` [PATCH 07/10] guestmemfs: Persist filesystem metadata via KHO James Gowans
2024-08-05 9:32 ` James Gowans [this message]
2024-08-05 9:32 ` [PATCH 09/10] guestmemfs: Add documentation and usage instructions James Gowans
2024-08-05 9:32 ` [PATCH 10/10] MAINTAINERS: Add maintainers for guestmemfs James Gowans
2024-08-05 14:32 ` [PATCH 00/10] Introduce guestmemfs: persistent in-memory filesystem Theodore Ts'o
2024-08-05 14:41 ` Paolo Bonzini
2024-08-05 19:47 ` Gowans, James
2024-08-05 19:53 ` Gowans, James
2024-08-05 20:01 ` Jan Kara
2024-08-05 23:29 ` Jason Gunthorpe
2024-08-06 8:26 ` Gowans, James
2024-08-06 8:12 ` Gowans, James
2024-08-06 13:43 ` David Hildenbrand
2024-10-17 4:53 ` Vishal Annapurve
2024-11-01 12:53 ` Gowans, James
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240805093245.889357-9-jgowans@amazon.com \
--to=jgowans@amazon.com \
--cc=akpm@linux-foundation.org \
--cc=anthony.yznaga@oracle.com \
--cc=brauner@kernel.org \
--cc=dwmw@amazon.co.uk \
--cc=graf@amazon.com \
--cc=jack@suse.cz \
--cc=jgg@ziepe.ca \
--cc=kvm@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nsaenz@amazon.es \
--cc=pbonzini@redhat.com \
--cc=pdurrant@amazon.co.uk \
--cc=rppt@kernel.org \
--cc=seanjc@google.com \
--cc=steven.sistare@oracle.com \
--cc=usama.arif@bytedance.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox