Skip to content

Commit ef75bd7

Browse files
committed
Merge tag 'gfs2-for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2
Pull GFS2 updates from Andreas Gruenbacher: "We've got the following patches ready for this merge window: - "gfs2: Fix loop in gfs2_rbm_find (v2)" A rework of a fix we ended up reverting in 5.0 because of an iozone performance regression. - "gfs2: read journal in large chunks" "gfs2: fix race between gfs2_freeze_func and unmount" An improved version of a commit we also ended up reverting in 5.0 because of a regression in xfstest generic/311. It turns out that the journal changes were mostly innocent and that unfreeze didn't wait for the freeze to complete, which caused the filesystem to be unmounted before it was actually idle. - "gfs2: Fix occasional glock use-after-free" "gfs2: Fix iomap write page reclaim deadlock" "gfs2: Fix lru_count going negative" Fixes for various problems reported and partially fixed by Citrix engineers. Thank you very much. - "gfs2: clean_journal improperly set sd_log_flush_head" Another fix from Bob. - .. and a few other minor cleanups" * tag 'gfs2-for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: gfs2: read journal in large chunks gfs2: Fix iomap write page reclaim deadlock gfs2: fix race between gfs2_freeze_func and unmount gfs2: Rename gfs2_trans_{add_unrevoke => remove_revoke} gfs2: Rename sd_log_le_{revoke,ordered} gfs2: Remove unnecessary extern declarations gfs2: Remove misleading comments in gfs2_evict_inode gfs2: Replace gl_revokes with a GLF flag gfs2: Fix occasional glock use-after-free gfs2: clean_journal improperly set sd_log_flush_head gfs2: Fix lru_count going negative gfs2: Fix loop in gfs2_rbm_find (v2)
2 parents 78d9aff + f4686c2 commit ef75bd7

20 files changed

Lines changed: 437 additions & 293 deletions

‎fs/gfs2/aops.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,18 +649,21 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping,
649649
*/
650650
void adjust_fs_space(struct inode *inode)
651651
{
652-
struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
652+
struct gfs2_sbd *sdp = GFS2_SB(inode);
653653
struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
654654
struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
655655
struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
656656
struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
657657
struct buffer_head *m_bh, *l_bh;
658658
u64 fs_total, new_free;
659659

660+
if (gfs2_trans_begin(sdp, 2 * RES_STATFS, 0) != 0)
661+
return;
662+
660663
/* Total up the file system space, according to the latest rindex. */
661664
fs_total = gfs2_ri_total(sdp);
662665
if (gfs2_meta_inode_buffer(m_ip, &m_bh) != 0)
663-
return;
666+
goto out;
664667

665668
spin_lock(&sdp->sd_statfs_spin);
666669
gfs2_statfs_change_in(m_sc, m_bh->b_data +
@@ -675,11 +678,14 @@ void adjust_fs_space(struct inode *inode)
675678
gfs2_statfs_change(sdp, new_free, new_free, 0);
676679

677680
if (gfs2_meta_inode_buffer(l_ip, &l_bh) != 0)
678-
goto out;
681+
goto out2;
679682
update_statfs(sdp, m_bh, l_bh);
680683
brelse(l_bh);
681-
out:
684+
out2:
682685
brelse(m_bh);
686+
out:
687+
sdp->sd_rindex_uptodate = 0;
688+
gfs2_trans_end(sdp);
683689
}
684690

685691
/**

‎fs/gfs2/bmap.c‎

Lines changed: 76 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page)
142142
if (error)
143143
goto out_brelse;
144144
if (isdir) {
145-
gfs2_trans_add_unrevoke(GFS2_SB(&ip->i_inode), block, 1);
145+
gfs2_trans_remove_revoke(GFS2_SB(&ip->i_inode), block, 1);
146146
error = gfs2_dir_get_new_buffer(ip, block, &bh);
147147
if (error)
148148
goto out_brelse;
@@ -676,7 +676,7 @@ static int gfs2_iomap_alloc(struct inode *inode, struct iomap *iomap,
676676
goto out;
677677
alloced += n;
678678
if (state != ALLOC_DATA || gfs2_is_jdata(ip))
679-
gfs2_trans_add_unrevoke(sdp, bn, n);
679+
gfs2_trans_remove_revoke(sdp, bn, n);
680680
switch (state) {
681681
/* Growing height of tree */
682682
case ALLOC_GROW_HEIGHT:
@@ -925,6 +925,32 @@ static int gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length,
925925
goto out;
926926
}
927927

928+
/**
929+
* gfs2_lblk_to_dblk - convert logical block to disk block
930+
* @inode: the inode of the file we're mapping
931+
* @lblock: the block relative to the start of the file
932+
* @dblock: the returned dblock, if no error
933+
*
934+
* This function maps a single block from a file logical block (relative to
935+
* the start of the file) to a file system absolute block using iomap.
936+
*
937+
* Returns: the absolute file system block, or an error
938+
*/
939+
int gfs2_lblk_to_dblk(struct inode *inode, u32 lblock, u64 *dblock)
940+
{
941+
struct iomap iomap = { };
942+
struct metapath mp = { .mp_aheight = 1, };
943+
loff_t pos = (loff_t)lblock << inode->i_blkbits;
944+
int ret;
945+
946+
ret = gfs2_iomap_get(inode, pos, i_blocksize(inode), 0, &iomap, &mp);
947+
release_metapath(&mp);
948+
if (ret == 0)
949+
*dblock = iomap.addr >> inode->i_blkbits;
950+
951+
return ret;
952+
}
953+
928954
static int gfs2_write_lock(struct inode *inode)
929955
{
930956
struct gfs2_inode *ip = GFS2_I(inode);
@@ -965,17 +991,28 @@ static void gfs2_write_unlock(struct inode *inode)
965991
gfs2_glock_dq_uninit(&ip->i_gh);
966992
}
967993

994+
static int gfs2_iomap_page_prepare(struct inode *inode, loff_t pos,
995+
unsigned len, struct iomap *iomap)
996+
{
997+
struct gfs2_sbd *sdp = GFS2_SB(inode);
998+
999+
return gfs2_trans_begin(sdp, RES_DINODE + (len >> inode->i_blkbits), 0);
1000+
}
1001+
9681002
static void gfs2_iomap_page_done(struct inode *inode, loff_t pos,
9691003
unsigned copied, struct page *page,
9701004
struct iomap *iomap)
9711005
{
9721006
struct gfs2_inode *ip = GFS2_I(inode);
1007+
struct gfs2_sbd *sdp = GFS2_SB(inode);
9731008

974-
if (page)
1009+
if (page && !gfs2_is_stuffed(ip))
9751010
gfs2_page_add_databufs(ip, page, offset_in_page(pos), copied);
1011+
gfs2_trans_end(sdp);
9761012
}
9771013

9781014
static const struct iomap_page_ops gfs2_iomap_page_ops = {
1015+
.page_prepare = gfs2_iomap_page_prepare,
9791016
.page_done = gfs2_iomap_page_done,
9801017
};
9811018

@@ -1031,31 +1068,45 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos,
10311068
if (alloc_required)
10321069
rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks);
10331070

1034-
ret = gfs2_trans_begin(sdp, rblocks, iomap->length >> inode->i_blkbits);
1035-
if (ret)
1036-
goto out_trans_fail;
1071+
if (unstuff || iomap->type == IOMAP_HOLE) {
1072+
struct gfs2_trans *tr;
10371073

1038-
if (unstuff) {
1039-
ret = gfs2_unstuff_dinode(ip, NULL);
1040-
if (ret)
1041-
goto out_trans_end;
1042-
release_metapath(mp);
1043-
ret = gfs2_iomap_get(inode, iomap->offset, iomap->length,
1044-
flags, iomap, mp);
1074+
ret = gfs2_trans_begin(sdp, rblocks,
1075+
iomap->length >> inode->i_blkbits);
10451076
if (ret)
1046-
goto out_trans_end;
1047-
}
1077+
goto out_trans_fail;
10481078

1049-
if (iomap->type == IOMAP_HOLE) {
1050-
ret = gfs2_iomap_alloc(inode, iomap, flags, mp);
1051-
if (ret) {
1052-
gfs2_trans_end(sdp);
1053-
gfs2_inplace_release(ip);
1054-
punch_hole(ip, iomap->offset, iomap->length);
1055-
goto out_qunlock;
1079+
if (unstuff) {
1080+
ret = gfs2_unstuff_dinode(ip, NULL);
1081+
if (ret)
1082+
goto out_trans_end;
1083+
release_metapath(mp);
1084+
ret = gfs2_iomap_get(inode, iomap->offset,
1085+
iomap->length, flags, iomap, mp);
1086+
if (ret)
1087+
goto out_trans_end;
1088+
}
1089+
1090+
if (iomap->type == IOMAP_HOLE) {
1091+
ret = gfs2_iomap_alloc(inode, iomap, flags, mp);
1092+
if (ret) {
1093+
gfs2_trans_end(sdp);
1094+
gfs2_inplace_release(ip);
1095+
punch_hole(ip, iomap->offset, iomap->length);
1096+
goto out_qunlock;
1097+
}
10561098
}
1099+
1100+
tr = current->journal_info;
1101+
if (tr->tr_num_buf_new)
1102+
__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
1103+
else
1104+
gfs2_trans_add_meta(ip->i_gl, mp->mp_bh[0]);
1105+
1106+
gfs2_trans_end(sdp);
10571107
}
1058-
if (!gfs2_is_stuffed(ip) && gfs2_is_jdata(ip))
1108+
1109+
if (gfs2_is_stuffed(ip) || gfs2_is_jdata(ip))
10591110
iomap->page_ops = &gfs2_iomap_page_ops;
10601111
return 0;
10611112

@@ -1095,10 +1146,6 @@ static int gfs2_iomap_begin(struct inode *inode, loff_t pos, loff_t length,
10951146
iomap->type != IOMAP_MAPPED)
10961147
ret = -ENOTBLK;
10971148
}
1098-
if (!ret) {
1099-
get_bh(mp.mp_bh[0]);
1100-
iomap->private = mp.mp_bh[0];
1101-
}
11021149
release_metapath(&mp);
11031150
trace_gfs2_iomap_end(ip, iomap, ret);
11041151
return ret;
@@ -1109,27 +1156,16 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,
11091156
{
11101157
struct gfs2_inode *ip = GFS2_I(inode);
11111158
struct gfs2_sbd *sdp = GFS2_SB(inode);
1112-
struct gfs2_trans *tr = current->journal_info;
1113-
struct buffer_head *dibh = iomap->private;
11141159

11151160
if ((flags & (IOMAP_WRITE | IOMAP_DIRECT)) != IOMAP_WRITE)
11161161
goto out;
11171162

1118-
if (iomap->type != IOMAP_INLINE) {
1163+
if (!gfs2_is_stuffed(ip))
11191164
gfs2_ordered_add_inode(ip);
11201165

1121-
if (tr->tr_num_buf_new)
1122-
__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
1123-
else
1124-
gfs2_trans_add_meta(ip->i_gl, dibh);
1125-
}
1126-
1127-
if (inode == sdp->sd_rindex) {
1166+
if (inode == sdp->sd_rindex)
11281167
adjust_fs_space(inode);
1129-
sdp->sd_rindex_uptodate = 0;
1130-
}
11311168

1132-
gfs2_trans_end(sdp);
11331169
gfs2_inplace_release(ip);
11341170

11351171
if (length != written && (iomap->flags & IOMAP_F_NEW)) {
@@ -1149,8 +1185,6 @@ static int gfs2_iomap_end(struct inode *inode, loff_t pos, loff_t length,
11491185
gfs2_write_unlock(inode);
11501186

11511187
out:
1152-
if (dibh)
1153-
brelse(dibh);
11541188
return 0;
11551189
}
11561190

‎fs/gfs2/bmap.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ extern int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
6464
extern int gfs2_map_journal_extents(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd);
6565
extern void gfs2_free_journal_extents(struct gfs2_jdesc *jd);
6666
extern int __gfs2_punch_hole(struct file *file, loff_t offset, loff_t length);
67+
extern int gfs2_lblk_to_dblk(struct inode *inode, u32 lblock, u64 *dblock);
6768

6869
#endif /* __BMAP_DOT_H__ */

‎fs/gfs2/dir.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
883883
if (!bh)
884884
return NULL;
885885

886-
gfs2_trans_add_unrevoke(GFS2_SB(inode), bn, 1);
886+
gfs2_trans_remove_revoke(GFS2_SB(inode), bn, 1);
887887
gfs2_trans_add_meta(ip->i_gl, bh);
888888
gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF);
889889
leaf = (struct gfs2_leaf *)bh->b_data;

‎fs/gfs2/glock.c‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ void gfs2_glock_free(struct gfs2_glock *gl)
140140
{
141141
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
142142

143+
BUG_ON(test_bit(GLF_REVOKES, &gl->gl_flags));
143144
rhashtable_remove_fast(&gl_hash_table, &gl->gl_node, ht_parms);
144145
smp_mb();
145146
wake_up_glock(gl);
@@ -183,15 +184,19 @@ static int demote_ok(const struct gfs2_glock *gl)
183184

184185
void gfs2_glock_add_to_lru(struct gfs2_glock *gl)
185186
{
187+
if (!(gl->gl_ops->go_flags & GLOF_LRU))
188+
return;
189+
186190
spin_lock(&lru_lock);
187191

188-
if (!list_empty(&gl->gl_lru))
189-
list_del_init(&gl->gl_lru);
190-
else
192+
list_del(&gl->gl_lru);
193+
list_add_tail(&gl->gl_lru, &lru_list);
194+
195+
if (!test_bit(GLF_LRU, &gl->gl_flags)) {
196+
set_bit(GLF_LRU, &gl->gl_flags);
191197
atomic_inc(&lru_count);
198+
}
192199

193-
list_add_tail(&gl->gl_lru, &lru_list);
194-
set_bit(GLF_LRU, &gl->gl_flags);
195200
spin_unlock(&lru_lock);
196201
}
197202

@@ -201,7 +206,7 @@ static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl)
201206
return;
202207

203208
spin_lock(&lru_lock);
204-
if (!list_empty(&gl->gl_lru)) {
209+
if (test_bit(GLF_LRU, &gl->gl_flags)) {
205210
list_del_init(&gl->gl_lru);
206211
atomic_dec(&lru_count);
207212
clear_bit(GLF_LRU, &gl->gl_flags);
@@ -1159,8 +1164,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
11591164
!test_bit(GLF_DEMOTE, &gl->gl_flags))
11601165
fast_path = 1;
11611166
}
1162-
if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl) &&
1163-
(glops->go_flags & GLOF_LRU))
1167+
if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl))
11641168
gfs2_glock_add_to_lru(gl);
11651169

11661170
trace_gfs2_glock_queue(gh, 0);
@@ -1456,14 +1460,14 @@ __acquires(&lru_lock)
14561460
if (!spin_trylock(&gl->gl_lockref.lock)) {
14571461
add_back_to_lru:
14581462
list_add(&gl->gl_lru, &lru_list);
1463+
set_bit(GLF_LRU, &gl->gl_flags);
14591464
atomic_inc(&lru_count);
14601465
continue;
14611466
}
14621467
if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) {
14631468
spin_unlock(&gl->gl_lockref.lock);
14641469
goto add_back_to_lru;
14651470
}
1466-
clear_bit(GLF_LRU, &gl->gl_flags);
14671471
gl->gl_lockref.count++;
14681472
if (demote_ok(gl))
14691473
handle_callback(gl, LM_ST_UNLOCKED, 0, false);
@@ -1498,6 +1502,7 @@ static long gfs2_scan_glock_lru(int nr)
14981502
if (!test_bit(GLF_LOCK, &gl->gl_flags)) {
14991503
list_move(&gl->gl_lru, &dispose);
15001504
atomic_dec(&lru_count);
1505+
clear_bit(GLF_LRU, &gl->gl_flags);
15011506
freed++;
15021507
continue;
15031508
}
@@ -1796,7 +1801,7 @@ void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl)
17961801
state2str(gl->gl_target),
17971802
state2str(gl->gl_demote_state), dtime,
17981803
atomic_read(&gl->gl_ail_count),
1799-
atomic_read(&gl->gl_revokes),
1804+
test_bit(GLF_REVOKES, &gl->gl_flags) ? 1 : 0,
18001805
(int)gl->gl_lockref.count, gl->gl_hold_time);
18011806

18021807
list_for_each_entry(gh, &gl->gl_holders, gh_list)

‎fs/gfs2/glops.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "util.h"
2929
#include "trans.h"
3030
#include "dir.h"
31+
#include "lops.h"
3132

3233
struct workqueue_struct *gfs2_freeze_wq;
3334

@@ -531,7 +532,7 @@ static int freeze_go_xmote_bh(struct gfs2_glock *gl, struct gfs2_holder *gh)
531532
if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
532533
j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
533534

534-
error = gfs2_find_jhead(sdp->sd_jdesc, &head);
535+
error = gfs2_find_jhead(sdp->sd_jdesc, &head, false);
535536
if (error)
536537
gfs2_consist(sdp);
537538
if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT))

‎fs/gfs2/incore.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ enum {
345345
GLF_OBJECT = 14, /* Used only for tracing */
346346
GLF_BLOCKING = 15,
347347
GLF_INODE_CREATING = 16, /* Inode creation occurring */
348+
GLF_REVOKES = 17, /* Glock has revokes in queue */
348349
};
349350

350351
struct gfs2_glock {
@@ -374,7 +375,6 @@ struct gfs2_glock {
374375
struct list_head gl_lru;
375376
struct list_head gl_ail_list;
376377
atomic_t gl_ail_count;
377-
atomic_t gl_revokes;
378378
struct delayed_work gl_work;
379379
union {
380380
/* For inode and iopen glocks only */
@@ -535,7 +535,7 @@ struct gfs2_jdesc {
535535
unsigned long jd_flags;
536536
#define JDF_RECOVERY 1
537537
unsigned int jd_jid;
538-
unsigned int jd_blocks;
538+
u32 jd_blocks;
539539
int jd_recover_error;
540540
/* Replay stuff */
541541

@@ -621,6 +621,7 @@ enum {
621621
SDF_SKIP_DLM_UNLOCK = 8,
622622
SDF_FORCE_AIL_FLUSH = 9,
623623
SDF_AIL1_IO_ERROR = 10,
624+
SDF_FS_FROZEN = 11,
624625
};
625626

626627
enum gfs2_freeze_state {
@@ -809,8 +810,8 @@ struct gfs2_sbd {
809810
atomic_t sd_log_pinned;
810811
unsigned int sd_log_num_revoke;
811812

812-
struct list_head sd_log_le_revoke;
813-
struct list_head sd_log_le_ordered;
813+
struct list_head sd_log_revokes;
814+
struct list_head sd_log_ordered;
814815
spinlock_t sd_ordered_lock;
815816

816817
atomic_t sd_log_thresh1;

0 commit comments

Comments
 (0)