From: Bob Peterson <rpeterso@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [GFS2 PATCH 10/15] gfs2: replace sd_aspace with sd_inode
Date: Tue, 27 Jul 2021 12:37:04 -0500 [thread overview]
Message-ID: <20210727173709.210711-11-rpeterso@redhat.com> (raw)
In-Reply-To: <20210727173709.210711-1-rpeterso@redhat.com>
Before this patch, gfs2 kept its own address space for rgrps, but this
caused a lockdep problem because vfs assumes a 1:1 relationship between
address spaces and their inode. One problematic area is this:
gfs2_unpin
mark_buffer_dirty(bh);
mapping = page_mapping(page);
__set_page_dirty(page, mapping, memcg, 0);
xa_lock_irqsave(&mapping->i_pages, flags);
^---locks page->mapping->i_pages
account_page_dirtied(page, mapping)
struct inode *inode = mapping->host;
^---assumes the mapping points to an inode
inode_to_wb(inode)
WARN_ON_ONCE !lockdep_is_held(&inode->i_mapping->
i_pages.xa_lock)
It manifests as a lockdep warning you see in the last line.
This patch removes sd_aspace in favor of an entire inode, sd_inode.
Functions that need to access the address space may use a new function
that follows the inode to its address space. This creates the 1:1 relation
between the inode and its address space, so lockdep doesn't complain.
This is how some other file systems manage their metadata, such as btrfs.
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
---
fs/gfs2/glops.c | 4 ++--
fs/gfs2/incore.h | 7 ++++++-
fs/gfs2/meta_io.c | 2 +-
fs/gfs2/meta_io.h | 2 --
fs/gfs2/ops_fstype.c | 27 ++++++++++++++++-----------
fs/gfs2/super.c | 2 +-
6 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index 744cacd27213..5d755d30d91c 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -162,7 +162,7 @@ void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
static int gfs2_rgrp_metasync(struct gfs2_glock *gl)
{
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
- struct address_space *metamapping = &sdp->sd_aspace;
+ struct address_space *metamapping = gfs2_aspace(sdp);
struct gfs2_rgrpd *rgd = gfs2_glock2rgrp(gl);
const unsigned bsize = sdp->sd_sb.sb_bsize;
loff_t start = (rgd->rd_addr * bsize) & PAGE_MASK;
@@ -219,7 +219,7 @@ static int rgrp_go_sync(struct gfs2_glock *gl)
static void rgrp_go_inval(struct gfs2_glock *gl, int flags)
{
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
- struct address_space *mapping = &sdp->sd_aspace;
+ struct address_space *mapping = gfs2_aspace(sdp);
struct gfs2_rgrpd *rgd = gfs2_glock2rgrp(gl);
const unsigned bsize = sdp->sd_sb.sb_bsize;
loff_t start = (rgd->rd_addr * bsize) & PAGE_MASK;
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 6f31a067a5f2..4a03c3031347 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -795,7 +795,7 @@ struct gfs2_sbd {
/* Log stuff */
- struct address_space sd_aspace;
+ struct inode *sd_inode;
spinlock_t sd_log_lock;
@@ -851,6 +851,11 @@ struct gfs2_sbd {
unsigned long sd_glock_dqs_held;
};
+static inline struct address_space *gfs2_aspace(struct gfs2_sbd *sdp)
+{
+ return sdp->sd_inode->i_mapping;
+}
+
static inline void gfs2_glstats_inc(struct gfs2_glock *gl, int which)
{
gl->gl_stats.stats[which]++;
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index 7c9619997355..0123437d9c12 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -120,7 +120,7 @@ struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create)
unsigned int bufnum;
if (mapping == NULL)
- mapping = &sdp->sd_aspace;
+ mapping = gfs2_aspace(sdp);
shift = PAGE_SHIFT - sdp->sd_sb.sb_bsize_shift;
index = blkno >> shift; /* convert block to page */
diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h
index 21880d72081a..70b9c41ecb46 100644
--- a/fs/gfs2/meta_io.h
+++ b/fs/gfs2/meta_io.h
@@ -42,8 +42,6 @@ static inline struct gfs2_sbd *gfs2_mapping2sbd(struct address_space *mapping)
struct inode *inode = mapping->host;
if (mapping->a_ops == &gfs2_meta_aops)
return (((struct gfs2_glock *)mapping) - 1)->gl_name.ln_sbd;
- else if (mapping->a_ops == &gfs2_rgrp_aops)
- return container_of(mapping, struct gfs2_sbd, sd_aspace);
else
return inode->i_sb->s_fs_info;
}
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 5b90d2b7db47..8051f130cf53 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -72,7 +72,6 @@ void free_sbd(struct gfs2_sbd *sdp)
static struct gfs2_sbd *init_sbd(struct super_block *sb)
{
struct gfs2_sbd *sdp;
- struct address_space *mapping;
sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL);
if (!sdp)
@@ -112,16 +111,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
INIT_LIST_HEAD(&sdp->sd_sc_inodes_list);
- mapping = &sdp->sd_aspace;
-
- address_space_init_once(mapping);
- mapping->a_ops = &gfs2_rgrp_aops;
- mapping->host = sb->s_bdev->bd_inode;
- mapping->flags = 0;
- mapping_set_gfp_mask(mapping, GFP_NOFS);
- mapping->private_data = NULL;
- mapping->writeback_index = 0;
-
spin_lock_init(&sdp->sd_log_lock);
atomic_set(&sdp->sd_log_pinned, 0);
INIT_LIST_HEAD(&sdp->sd_log_revokes);
@@ -1140,6 +1129,7 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
struct gfs2_sbd *sdp;
struct gfs2_holder mount_gh;
struct gfs2_holder freeze_gh;
+ struct address_space *mapping;
int error;
sdp = init_sbd(sb);
@@ -1161,6 +1151,21 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
sb->s_flags |= SB_NOSEC;
sb->s_magic = GFS2_MAGIC;
sb->s_op = &gfs2_super_ops;
+
+ /* Set up an address space for metadata writes */
+ sdp->sd_inode = new_inode(sb);
+ if (!sdp->sd_inode)
+ goto fail_free;
+ sdp->sd_inode->i_ino = GFS2_MAGIC;
+ set_nlink(sdp->sd_inode, 1);
+ sdp->sd_inode->i_size = i_size_read(sb->s_bdev->bd_inode);
+ insert_inode_hash(sdp->sd_inode);
+
+ mapping = gfs2_aspace(sdp);
+ mapping->a_ops = &gfs2_rgrp_aops;
+ mapping_set_gfp_mask(mapping, GFP_NOFS);
+ mapping->writeback_index = 0;
+
sb->s_d_op = &gfs2_dops;
sb->s_export_op = &gfs2_export_ops;
sb->s_qcop = &gfs2_quotactl_ops;
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 0a5b7dfa7a45..9857d8725b2d 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -617,13 +617,13 @@ static void gfs2_put_super(struct super_block *sb)
gfs2_jindex_free(sdp);
/* Take apart glock structures and buffer lists */
gfs2_gl_hash_clear(sdp);
- truncate_inode_pages_final(&sdp->sd_aspace);
gfs2_delete_debugfs_file(sdp);
/* Unmount the locking protocol */
gfs2_lm_unmount(sdp);
/* At this point, we're through participating in the lockspace */
gfs2_sys_fs_del(sdp);
+ iput(sdp->sd_inode);
free_sbd(sdp);
}
--
2.31.1
next prev parent reply other threads:[~2021-07-27 17:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-27 17:36 [Cluster-devel] [GFS2 PATCH 00/15] gfs2: misc. patch collection (V2) Bob Peterson
2021-07-27 17:36 ` [Cluster-devel] [GFS2 PATCH 01/15] gfs2: Add wrapper for iomap_file_buffered_write Bob Peterson
2021-07-27 17:36 ` [Cluster-devel] [GFS2 PATCH 02/15] gfs2: Fix glock recursion in freeze_go_xmote_bh Bob Peterson
2021-07-27 17:36 ` [Cluster-devel] [GFS2 PATCH 03/15] gfs2: Eliminate go_xmote_bh in favor of go_lock Bob Peterson
2021-07-27 17:36 ` [Cluster-devel] [GFS2 PATCH 04/15] gfs2: be more verbose replaying invalid rgrp blocks Bob Peterson
2021-07-27 17:36 ` [Cluster-devel] [GFS2 PATCH 05/15] gfs2: trivial clean up of gfs2_ail_error Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 06/15] gfs2: tiny cleanup in gfs2_log_reserve Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 07/15] gfs2: init system threads before freeze lock Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 08/15] gfs2: Don't release and reacquire local statfs bh Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 09/15] gfs2: fix deadlock in gfs2_ail1_empty withdraw Bob Peterson
2021-07-28 5:38 ` Andreas Gruenbacher
2021-07-28 13:30 ` Bob Peterson
2021-07-27 17:37 ` Bob Peterson [this message]
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 11/15] gfs2: reduce redundant code in gfs2_trans_add_* Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 12/15] gfs2: Make recovery error more readable Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 13/15] gfs2: ignore usr|grp|prjquota mount options Bob Peterson
2021-07-28 18:28 ` Andreas Gruenbacher
2021-07-28 20:32 ` Bob Peterson
2021-07-28 20:57 ` Andreas Gruenbacher
2021-08-02 8:46 ` Andrew Price
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 14/15] fs: Move notify_change permission checks into may_setattr Bob Peterson
2021-07-27 17:37 ` [Cluster-devel] [GFS2 PATCH 15/15] gfs2: Switch to may_setattr in gfs2_setattr Bob Peterson
2021-07-27 18:30 ` [Cluster-devel] [GFS2 PATCH 00/15] gfs2: misc. patch collection (V2) Andreas Gruenbacher
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=20210727173709.210711-11-rpeterso@redhat.com \
--to=rpeterso@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).