Skip to content

Commit 271e6bf

Browse files
Andreas Gruenbachergregkh
authored andcommitted
gfs2: replace sd_aspace with sd_inode
[ Upstream commit ae9f3bd ] Currently, sdp->sd_aspace and the per-inode metadata address spaces use sb->s_bdev->bd_mapping->host as their ->host; folios in those address spaces will thus appear to be on bdev rather than on gfs2 filesystems. This is a problem because gfs2 doesn't support cgroup writeback (SB_I_CGROUPWB), but bdev does. Fix that by using a "dummy" gfs2 inode as ->host in those address spaces. When coming from a folio, folio->mapping->host->i_sb will then be a gfs2 super block and the SB_I_CGROUPWB flag will not be set in sb->s_iflags. Based on a previous version from Bob Peterson from several years ago. Thanks to Tetsuo Handa, Jan Kara, and Rafael Aquini for helping figure this out. Fixes: aaa2cac ("writeback: add lockdep annotation to inode_to_wb()") Signed-off-by: Andreas Gruenbacher <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 88ab25d commit 271e6bf

File tree

7 files changed

+32
-23
lines changed

7 files changed

+32
-23
lines changed

fs/gfs2/glock.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
11831183
const struct gfs2_glock_operations *glops, int create,
11841184
struct gfs2_glock **glp)
11851185
{
1186-
struct super_block *s = sdp->sd_vfs;
11871186
struct lm_lockname name = { .ln_number = number,
11881187
.ln_type = glops->go_type,
11891188
.ln_sbd = sdp };
@@ -1246,7 +1245,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
12461245
mapping = gfs2_glock2aspace(gl);
12471246
if (mapping) {
12481247
mapping->a_ops = &gfs2_meta_aops;
1249-
mapping->host = s->s_bdev->bd_mapping->host;
1248+
mapping->host = sdp->sd_inode;
12501249
mapping->flags = 0;
12511250
mapping_set_gfp_mask(mapping, GFP_NOFS);
12521251
mapping->i_private_data = NULL;

fs/gfs2/glops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
168168
static int gfs2_rgrp_metasync(struct gfs2_glock *gl)
169169
{
170170
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
171-
struct address_space *metamapping = &sdp->sd_aspace;
171+
struct address_space *metamapping = gfs2_aspace(sdp);
172172
struct gfs2_rgrpd *rgd = gfs2_glock2rgrp(gl);
173173
const unsigned bsize = sdp->sd_sb.sb_bsize;
174174
loff_t start = (rgd->rd_addr * bsize) & PAGE_MASK;
@@ -225,7 +225,7 @@ static int rgrp_go_sync(struct gfs2_glock *gl)
225225
static void rgrp_go_inval(struct gfs2_glock *gl, int flags)
226226
{
227227
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
228-
struct address_space *mapping = &sdp->sd_aspace;
228+
struct address_space *mapping = gfs2_aspace(sdp);
229229
struct gfs2_rgrpd *rgd = gfs2_glock2rgrp(gl);
230230
const unsigned bsize = sdp->sd_sb.sb_bsize;
231231
loff_t start, end;

fs/gfs2/incore.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ struct gfs2_sbd {
793793

794794
/* Log stuff */
795795

796-
struct address_space sd_aspace;
796+
struct inode *sd_inode;
797797

798798
spinlock_t sd_log_lock;
799799

@@ -849,6 +849,13 @@ struct gfs2_sbd {
849849
unsigned long sd_glock_dqs_held;
850850
};
851851

852+
#define GFS2_BAD_INO 1
853+
854+
static inline struct address_space *gfs2_aspace(struct gfs2_sbd *sdp)
855+
{
856+
return sdp->sd_inode->i_mapping;
857+
}
858+
852859
static inline void gfs2_glstats_inc(struct gfs2_glock *gl, int which)
853860
{
854861
gl->gl_stats.stats[which]++;

fs/gfs2/meta_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create)
132132
unsigned int bufnum;
133133

134134
if (mapping == NULL)
135-
mapping = &sdp->sd_aspace;
135+
mapping = gfs2_aspace(sdp);
136136

137137
shift = PAGE_SHIFT - sdp->sd_sb.sb_bsize_shift;
138138
index = blkno >> shift; /* convert block to page */

fs/gfs2/meta_io.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ static inline struct gfs2_sbd *gfs2_mapping2sbd(struct address_space *mapping)
4444
struct gfs2_glock_aspace *gla =
4545
container_of(mapping, struct gfs2_glock_aspace, mapping);
4646
return gla->glock.gl_name.ln_sbd;
47-
} else if (mapping->a_ops == &gfs2_rgrp_aops)
48-
return container_of(mapping, struct gfs2_sbd, sd_aspace);
49-
else
47+
} else
5048
return inode->i_sb->s_fs_info;
5149
}
5250

fs/gfs2/ops_fstype.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ void free_sbd(struct gfs2_sbd *sdp)
7272
static struct gfs2_sbd *init_sbd(struct super_block *sb)
7373
{
7474
struct gfs2_sbd *sdp;
75-
struct address_space *mapping;
7675

7776
sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL);
7877
if (!sdp)
@@ -109,16 +108,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
109108

110109
INIT_LIST_HEAD(&sdp->sd_sc_inodes_list);
111110

112-
mapping = &sdp->sd_aspace;
113-
114-
address_space_init_once(mapping);
115-
mapping->a_ops = &gfs2_rgrp_aops;
116-
mapping->host = sb->s_bdev->bd_mapping->host;
117-
mapping->flags = 0;
118-
mapping_set_gfp_mask(mapping, GFP_NOFS);
119-
mapping->i_private_data = NULL;
120-
mapping->writeback_index = 0;
121-
122111
spin_lock_init(&sdp->sd_log_lock);
123112
atomic_set(&sdp->sd_log_pinned, 0);
124113
INIT_LIST_HEAD(&sdp->sd_log_revokes);
@@ -1135,6 +1124,7 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
11351124
int silent = fc->sb_flags & SB_SILENT;
11361125
struct gfs2_sbd *sdp;
11371126
struct gfs2_holder mount_gh;
1127+
struct address_space *mapping;
11381128
int error;
11391129

11401130
sdp = init_sbd(sb);
@@ -1156,6 +1146,7 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
11561146
sb->s_flags |= SB_NOSEC;
11571147
sb->s_magic = GFS2_MAGIC;
11581148
sb->s_op = &gfs2_super_ops;
1149+
11591150
sb->s_d_op = &gfs2_dops;
11601151
sb->s_export_op = &gfs2_export_ops;
11611152
sb->s_qcop = &gfs2_quotactl_ops;
@@ -1181,9 +1172,21 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
11811172
sdp->sd_tune.gt_statfs_quantum = 30;
11821173
}
11831174

1175+
/* Set up an address space for metadata writes */
1176+
sdp->sd_inode = new_inode(sb);
1177+
error = -ENOMEM;
1178+
if (!sdp->sd_inode)
1179+
goto fail_free;
1180+
sdp->sd_inode->i_ino = GFS2_BAD_INO;
1181+
sdp->sd_inode->i_size = OFFSET_MAX;
1182+
1183+
mapping = gfs2_aspace(sdp);
1184+
mapping->a_ops = &gfs2_rgrp_aops;
1185+
mapping_set_gfp_mask(mapping, GFP_NOFS);
1186+
11841187
error = init_names(sdp, silent);
11851188
if (error)
1186-
goto fail_free;
1189+
goto fail_iput;
11871190

11881191
snprintf(sdp->sd_fsname, sizeof(sdp->sd_fsname), "%s", sdp->sd_table_name);
11891192

@@ -1192,7 +1195,7 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
11921195
WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_FREEZABLE, 0,
11931196
sdp->sd_fsname);
11941197
if (!sdp->sd_glock_wq)
1195-
goto fail_free;
1198+
goto fail_iput;
11961199

11971200
sdp->sd_delete_wq = alloc_workqueue("gfs2-delete/%s",
11981201
WQ_MEM_RECLAIM | WQ_FREEZABLE, 0, sdp->sd_fsname);
@@ -1309,6 +1312,8 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
13091312
fail_glock_wq:
13101313
if (sdp->sd_glock_wq)
13111314
destroy_workqueue(sdp->sd_glock_wq);
1315+
fail_iput:
1316+
iput(sdp->sd_inode);
13121317
fail_free:
13131318
free_sbd(sdp);
13141319
sb->s_fs_info = NULL;

fs/gfs2/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ static void gfs2_put_super(struct super_block *sb)
648648
gfs2_jindex_free(sdp);
649649
/* Take apart glock structures and buffer lists */
650650
gfs2_gl_hash_clear(sdp);
651-
truncate_inode_pages_final(&sdp->sd_aspace);
651+
iput(sdp->sd_inode);
652652
gfs2_delete_debugfs_file(sdp);
653653

654654
gfs2_sys_fs_del(sdp);

0 commit comments

Comments
 (0)