Skip to content

Commit 8fdabcd

Browse files
committed
Merge tag 'gfs2-for-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2
Pull gfs2 updates from Andreas Gruenbacher: - Fix the long-standing warnings in inode_to_wb() when CONFIG_LOCKDEP is enabled: gfs2 doesn't support cgroup writeback and so inode->i_wb will never change. This is the counterpart of commit 9e88899 ("writeback: fix false warning in inode_to_wb()") - Fix a hang introduced by commit 8d39197 ("gfs2: Remove __gfs2_writepage()"): prevent gfs2_logd from creating transactions for jdata pages while trying to flush the log - Fix a race between gfs2_create_inode() and gfs2_evict_inode() by deallocating partially created inodes on the gfs2_create_inode() error path - Fix a bug in the journal head lookup code that could cause mount to fail after successful recovery - Various smaller fixes and cleanups from various people * tag 'gfs2-for-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: (23 commits) gfs2: No more gfs2_find_jhead caching gfs2: Get rid of duplicate log head lookup gfs2: Simplify clean_journal gfs2: Simplify gfs2_log_pointers_init gfs2: Move gfs2_log_pointers_init gfs2: Minor comments fix gfs2: Don't start unnecessary transactions during log flush gfs2: Move gfs2_trans_add_databufs gfs2: Rename jdata_dirty_folio to gfs2_jdata_dirty_folio gfs2: avoid inefficient use of crc32_le_shift() gfs2: Do not call iomap_zero_range beyond eof gfs: don't check for AOP_WRITEPAGE_ACTIVATE in gfs2_write_jdata_batch gfs2: Fix usage of bio->bi_status in gfs2_end_log_write gfs2: deallocate inodes in gfs2_create_inode gfs2: Move GIF_ALLOC_FAILED check out of gfs2_ea_dealloc gfs2: Move gfs2_dinode_dealloc gfs2: Don't reread inodes unnecessarily gfs2: gfs2_create_inode error handling fix gfs2: Remove unnecessary NULL check before free_percpu() gfs2: check sb_min_blocksize return value ...
2 parents a56d313 + e320050 commit 8fdabcd

24 files changed

+263
-213
lines changed

fs/gfs2/aops.c

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,6 @@
3737
#include "aops.h"
3838

3939

40-
void gfs2_trans_add_databufs(struct gfs2_inode *ip, struct folio *folio,
41-
size_t from, size_t len)
42-
{
43-
struct buffer_head *head = folio_buffers(folio);
44-
unsigned int bsize = head->b_size;
45-
struct buffer_head *bh;
46-
size_t to = from + len;
47-
size_t start, end;
48-
49-
for (bh = head, start = 0; bh != head || !start;
50-
bh = bh->b_this_page, start = end) {
51-
end = start + bsize;
52-
if (end <= from)
53-
continue;
54-
if (start >= to)
55-
break;
56-
set_buffer_uptodate(bh);
57-
gfs2_trans_add_data(ip->i_gl, bh);
58-
}
59-
}
60-
6140
/**
6241
* gfs2_get_block_noalloc - Fills in a buffer head with details about a block
6342
* @inode: The inode
@@ -133,11 +112,42 @@ static int __gfs2_jdata_write_folio(struct folio *folio,
133112
inode->i_sb->s_blocksize,
134113
BIT(BH_Dirty)|BIT(BH_Uptodate));
135114
}
136-
gfs2_trans_add_databufs(ip, folio, 0, folio_size(folio));
115+
gfs2_trans_add_databufs(ip->i_gl, folio, 0, folio_size(folio));
137116
}
138117
return gfs2_write_jdata_folio(folio, wbc);
139118
}
140119

120+
/**
121+
* gfs2_jdata_writeback - Write jdata folios to the log
122+
* @mapping: The mapping to write
123+
* @wbc: The writeback control
124+
*
125+
* Returns: errno
126+
*/
127+
int gfs2_jdata_writeback(struct address_space *mapping, struct writeback_control *wbc)
128+
{
129+
struct inode *inode = mapping->host;
130+
struct gfs2_inode *ip = GFS2_I(inode);
131+
struct gfs2_sbd *sdp = GFS2_SB(mapping->host);
132+
struct folio *folio = NULL;
133+
int error;
134+
135+
BUG_ON(current->journal_info);
136+
if (gfs2_assert_withdraw(sdp, ip->i_gl->gl_state == LM_ST_EXCLUSIVE))
137+
return 0;
138+
139+
while ((folio = writeback_iter(mapping, wbc, folio, &error))) {
140+
if (folio_test_checked(folio)) {
141+
folio_redirty_for_writepage(wbc, folio);
142+
folio_unlock(folio);
143+
continue;
144+
}
145+
error = __gfs2_jdata_write_folio(folio, wbc);
146+
}
147+
148+
return error;
149+
}
150+
141151
/**
142152
* gfs2_writepages - Write a bunch of dirty pages back to disk
143153
* @mapping: The mapping to write
@@ -228,24 +238,16 @@ static int gfs2_write_jdata_batch(struct address_space *mapping,
228238

229239
ret = __gfs2_jdata_write_folio(folio, wbc);
230240
if (unlikely(ret)) {
231-
if (ret == AOP_WRITEPAGE_ACTIVATE) {
232-
folio_unlock(folio);
233-
ret = 0;
234-
} else {
235-
236-
/*
237-
* done_index is set past this page,
238-
* so media errors will not choke
239-
* background writeout for the entire
240-
* file. This has consequences for
241-
* range_cyclic semantics (ie. it may
242-
* not be suitable for data integrity
243-
* writeout).
244-
*/
245-
*done_index = folio_next_index(folio);
246-
ret = 1;
247-
break;
248-
}
241+
/*
242+
* done_index is set past this page, so media errors
243+
* will not choke background writeout for the entire
244+
* file. This has consequences for range_cyclic
245+
* semantics (ie. it may not be suitable for data
246+
* integrity writeout).
247+
*/
248+
*done_index = folio_next_index(folio);
249+
ret = 1;
250+
break;
249251
}
250252

251253
/*
@@ -540,7 +542,7 @@ void adjust_fs_space(struct inode *inode)
540542
gfs2_trans_end(sdp);
541543
}
542544

543-
static bool jdata_dirty_folio(struct address_space *mapping,
545+
static bool gfs2_jdata_dirty_folio(struct address_space *mapping,
544546
struct folio *folio)
545547
{
546548
if (current->journal_info)
@@ -722,7 +724,7 @@ static const struct address_space_operations gfs2_jdata_aops = {
722724
.writepages = gfs2_jdata_writepages,
723725
.read_folio = gfs2_read_folio,
724726
.readahead = gfs2_readahead,
725-
.dirty_folio = jdata_dirty_folio,
727+
.dirty_folio = gfs2_jdata_dirty_folio,
726728
.bmap = gfs2_bmap,
727729
.migrate_folio = buffer_migrate_folio,
728730
.invalidate_folio = gfs2_invalidate_folio,

fs/gfs2/aops.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "incore.h"
1010

1111
void adjust_fs_space(struct inode *inode);
12-
void gfs2_trans_add_databufs(struct gfs2_inode *ip, struct folio *folio,
13-
size_t from, size_t len);
12+
int gfs2_jdata_writeback(struct address_space *mapping, struct writeback_control *wbc);
1413

1514
#endif /* __AOPS_DOT_H__ */

fs/gfs2/bmap.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,8 @@ static void gfs2_iomap_put_folio(struct inode *inode, loff_t pos,
988988
struct gfs2_sbd *sdp = GFS2_SB(inode);
989989

990990
if (!gfs2_is_stuffed(ip))
991-
gfs2_trans_add_databufs(ip, folio, offset_in_folio(folio, pos),
991+
gfs2_trans_add_databufs(ip->i_gl, folio,
992+
offset_in_folio(folio, pos),
992993
copied);
993994

994995
folio_unlock(folio);
@@ -1296,10 +1297,12 @@ int gfs2_alloc_extent(struct inode *inode, u64 lblock, u64 *dblock,
12961297
* uses iomap write to perform its actions, which begin their own transactions
12971298
* (iomap_begin, get_folio, etc.)
12981299
*/
1299-
static int gfs2_block_zero_range(struct inode *inode, loff_t from,
1300-
unsigned int length)
1300+
static int gfs2_block_zero_range(struct inode *inode, loff_t from, loff_t length)
13011301
{
13021302
BUG_ON(current->journal_info);
1303+
if (from >= inode->i_size)
1304+
return 0;
1305+
length = min(length, inode->i_size - from);
13031306
return iomap_zero_range(inode, from, length, NULL, &gfs2_iomap_ops,
13041307
NULL);
13051308
}

fs/gfs2/glock.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
11661166
const struct gfs2_glock_operations *glops, int create,
11671167
struct gfs2_glock **glp)
11681168
{
1169-
struct super_block *s = sdp->sd_vfs;
11701169
struct lm_lockname name = { .ln_number = number,
11711170
.ln_type = glops->go_type,
11721171
.ln_sbd = sdp };
@@ -1229,7 +1228,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
12291228
mapping = gfs2_glock2aspace(gl);
12301229
if (mapping) {
12311230
mapping->a_ops = &gfs2_meta_aops;
1232-
mapping->host = s->s_bdev->bd_mapping->host;
1231+
mapping->host = sdp->sd_inode;
12331232
mapping->flags = 0;
12341233
mapping_set_gfp_mask(mapping, GFP_NOFS);
12351234
mapping->i_private_data = NULL;

fs/gfs2/glops.c

Lines changed: 4 additions & 5 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;
@@ -601,14 +601,13 @@ static int freeze_go_xmote_bh(struct gfs2_glock *gl)
601601
if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
602602
j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
603603

604-
error = gfs2_find_jhead(sdp->sd_jdesc, &head, false);
604+
error = gfs2_find_jhead(sdp->sd_jdesc, &head);
605605
if (gfs2_assert_withdraw_delayed(sdp, !error))
606606
return error;
607607
if (gfs2_assert_withdraw_delayed(sdp, head.lh_flags &
608608
GFS2_LOG_HEAD_UNMOUNT))
609609
return -EIO;
610-
sdp->sd_log_sequence = head.lh_sequence + 1;
611-
gfs2_log_pointers_init(sdp, head.lh_blkno);
610+
gfs2_log_pointers_init(sdp, &head);
612611
}
613612
return 0;
614613
}

fs/gfs2/incore.h

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

796796
/* Log stuff */
797797

798-
struct address_space sd_aspace;
798+
struct inode *sd_inode;
799799

800800
spinlock_t sd_log_lock;
801801

@@ -851,6 +851,13 @@ struct gfs2_sbd {
851851
unsigned long sd_glock_dqs_held;
852852
};
853853

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

fs/gfs2/inode.c

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,74 @@ static int alloc_dinode(struct gfs2_inode *ip, u32 flags, unsigned *dblocks)
439439
return error;
440440
}
441441

442+
static void gfs2_final_release_pages(struct gfs2_inode *ip)
443+
{
444+
struct inode *inode = &ip->i_inode;
445+
struct gfs2_glock *gl = ip->i_gl;
446+
447+
if (unlikely(!gl)) {
448+
/* This can only happen during incomplete inode creation. */
449+
BUG_ON(!test_bit(GIF_ALLOC_FAILED, &ip->i_flags));
450+
return;
451+
}
452+
453+
truncate_inode_pages(gfs2_glock2aspace(gl), 0);
454+
truncate_inode_pages(&inode->i_data, 0);
455+
456+
if (atomic_read(&gl->gl_revokes) == 0) {
457+
clear_bit(GLF_LFLUSH, &gl->gl_flags);
458+
clear_bit(GLF_DIRTY, &gl->gl_flags);
459+
}
460+
}
461+
462+
int gfs2_dinode_dealloc(struct gfs2_inode *ip)
463+
{
464+
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
465+
struct gfs2_rgrpd *rgd;
466+
struct gfs2_holder gh;
467+
int error;
468+
469+
if (gfs2_get_inode_blocks(&ip->i_inode) != 1) {
470+
gfs2_consist_inode(ip);
471+
return -EIO;
472+
}
473+
474+
gfs2_rindex_update(sdp);
475+
476+
error = gfs2_quota_hold(ip, NO_UID_QUOTA_CHANGE, NO_GID_QUOTA_CHANGE);
477+
if (error)
478+
return error;
479+
480+
rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr, 1);
481+
if (!rgd) {
482+
gfs2_consist_inode(ip);
483+
error = -EIO;
484+
goto out_qs;
485+
}
486+
487+
error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE,
488+
LM_FLAG_NODE_SCOPE, &gh);
489+
if (error)
490+
goto out_qs;
491+
492+
error = gfs2_trans_begin(sdp, RES_RG_BIT + RES_STATFS + RES_QUOTA,
493+
sdp->sd_jdesc->jd_blocks);
494+
if (error)
495+
goto out_rg_gunlock;
496+
497+
gfs2_free_di(rgd, ip);
498+
499+
gfs2_final_release_pages(ip);
500+
501+
gfs2_trans_end(sdp);
502+
503+
out_rg_gunlock:
504+
gfs2_glock_dq_uninit(&gh);
505+
out_qs:
506+
gfs2_quota_unhold(ip);
507+
return error;
508+
}
509+
442510
static void gfs2_init_dir(struct buffer_head *dibh,
443511
const struct gfs2_inode *parent)
444512
{
@@ -629,10 +697,11 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
629697
struct gfs2_inode *dip = GFS2_I(dir), *ip;
630698
struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
631699
struct gfs2_glock *io_gl;
632-
int error;
700+
int error, dealloc_error;
633701
u32 aflags = 0;
634702
unsigned blocks = 1;
635703
struct gfs2_diradd da = { .bh = NULL, .save_loc = 1, };
704+
bool xattr_initialized = false;
636705

637706
if (!name->len || name->len > GFS2_FNAMESIZE)
638707
return -ENAMETOOLONG;
@@ -659,7 +728,8 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
659728
if (!IS_ERR(inode)) {
660729
if (S_ISDIR(inode->i_mode)) {
661730
iput(inode);
662-
inode = ERR_PTR(-EISDIR);
731+
inode = NULL;
732+
error = -EISDIR;
663733
goto fail_gunlock;
664734
}
665735
d_instantiate(dentry, inode);
@@ -744,11 +814,11 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
744814

745815
error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
746816
if (error)
747-
goto fail_free_inode;
817+
goto fail_dealloc_inode;
748818

749819
error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
750820
if (error)
751-
goto fail_free_inode;
821+
goto fail_dealloc_inode;
752822
gfs2_cancel_delete_work(io_gl);
753823
io_gl->gl_no_formal_ino = ip->i_no_formal_ino;
754824

@@ -767,13 +837,16 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
767837
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, &gh);
768838
if (error)
769839
goto fail_gunlock3;
840+
clear_bit(GLF_INSTANTIATE_NEEDED, &ip->i_gl->gl_flags);
770841

771842
error = gfs2_trans_begin(sdp, blocks, 0);
772843
if (error)
773844
goto fail_gunlock3;
774845

775-
if (blocks > 1)
846+
if (blocks > 1) {
776847
gfs2_init_xattr(ip);
848+
xattr_initialized = true;
849+
}
777850
init_dinode(dip, ip, symname);
778851
gfs2_trans_end(sdp);
779852

@@ -828,6 +901,18 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
828901
gfs2_glock_dq_uninit(&ip->i_iopen_gh);
829902
fail_gunlock2:
830903
gfs2_glock_put(io_gl);
904+
fail_dealloc_inode:
905+
set_bit(GIF_ALLOC_FAILED, &ip->i_flags);
906+
dealloc_error = 0;
907+
if (ip->i_eattr)
908+
dealloc_error = gfs2_ea_dealloc(ip, xattr_initialized);
909+
clear_nlink(inode);
910+
mark_inode_dirty(inode);
911+
if (!dealloc_error)
912+
dealloc_error = gfs2_dinode_dealloc(ip);
913+
if (dealloc_error)
914+
fs_warn(sdp, "%s: %d\n", __func__, dealloc_error);
915+
ip->i_no_addr = 0;
831916
fail_free_inode:
832917
if (ip->i_gl) {
833918
gfs2_glock_put(ip->i_gl);
@@ -842,10 +927,6 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
842927
gfs2_dir_no_add(&da);
843928
gfs2_glock_dq_uninit(&d_gh);
844929
if (!IS_ERR_OR_NULL(inode)) {
845-
set_bit(GIF_ALLOC_FAILED, &ip->i_flags);
846-
clear_nlink(inode);
847-
if (ip->i_no_addr)
848-
mark_inode_dirty(inode);
849930
if (inode->i_state & I_NEW)
850931
iget_failed(inode);
851932
else

0 commit comments

Comments
 (0)