Skip to content

Commit a90f1b6

Browse files
committed
Merge tag 'gfs2-for-6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2
Pull gfs2 updates from Andreas Gruenbacher: - Prevent cluster nodes from trying to recover their own filesystems during a withdraw - Add two missing migrate_folio aops and an additional exhash directory consistency check (both triggered by syzbot bug reports) - Sanitize how dlm results are processed and clean up a few quirks in the glock code - Minor stuff: Get rid of the GIF_ALLOC_FAILED flag; use SECTOR_SIZE and SECTOR_SHIFT * tag 'gfs2-for-6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: gfs2: No more self recovery gfs2: Validate i_depth for exhash directories gfs2: Set .migrate_folio in gfs2_{rgrp,meta}_aops gfs2: a minor finish_xmote cleanup gfs2: simplify finish_xmote gfs2: sanitize the gdlm_ast -> finish_xmote interface gfs2: Minor do_xmote cancelation fix gfs2: Remove GIF_ALLOC_FAILED flag gfs2: Use SECTOR_SIZE and SECTOR_SHIFT
2 parents f3f5edc + deb016c commit a90f1b6

12 files changed

Lines changed: 74 additions & 73 deletions

File tree

fs/gfs2/dir.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include <linux/crc32.h>
6161
#include <linux/vmalloc.h>
6262
#include <linux/bio.h>
63+
#include <linux/log2.h>
6364

6465
#include "gfs2.h"
6566
#include "incore.h"
@@ -912,7 +913,6 @@ static int dir_make_exhash(struct inode *inode)
912913
struct qstr args;
913914
struct buffer_head *bh, *dibh;
914915
struct gfs2_leaf *leaf;
915-
int y;
916916
u32 x;
917917
__be64 *lp;
918918
u64 bn;
@@ -979,9 +979,7 @@ static int dir_make_exhash(struct inode *inode)
979979
i_size_write(inode, sdp->sd_sb.sb_bsize / 2);
980980
gfs2_add_inode_blocks(&dip->i_inode, 1);
981981
dip->i_diskflags |= GFS2_DIF_EXHASH;
982-
983-
for (x = sdp->sd_hash_ptrs, y = -1; x; x >>= 1, y++) ;
984-
dip->i_depth = y;
982+
dip->i_depth = ilog2(sdp->sd_hash_ptrs);
985983

986984
gfs2_dinode_out(dip, dibh->b_data);
987985

fs/gfs2/glock.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -590,35 +590,31 @@ static void gfs2_demote_wake(struct gfs2_glock *gl)
590590
static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
591591
{
592592
const struct gfs2_glock_operations *glops = gl->gl_ops;
593-
struct gfs2_holder *gh;
594-
unsigned state = ret & LM_OUT_ST_MASK;
595593

596-
trace_gfs2_glock_state_change(gl, state);
597-
state_change(gl, state);
598-
gh = find_first_waiter(gl);
594+
if (!(ret & ~LM_OUT_ST_MASK)) {
595+
unsigned state = ret & LM_OUT_ST_MASK;
596+
597+
trace_gfs2_glock_state_change(gl, state);
598+
state_change(gl, state);
599+
}
600+
599601

600602
/* Demote to UN request arrived during demote to SH or DF */
601603
if (test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags) &&
602-
state != LM_ST_UNLOCKED && gl->gl_demote_state == LM_ST_UNLOCKED)
604+
gl->gl_state != LM_ST_UNLOCKED &&
605+
gl->gl_demote_state == LM_ST_UNLOCKED)
603606
gl->gl_target = LM_ST_UNLOCKED;
604607

605608
/* Check for state != intended state */
606-
if (unlikely(state != gl->gl_target)) {
607-
if (gh && (ret & LM_OUT_CANCELED))
608-
gfs2_holder_wake(gh);
609+
if (unlikely(gl->gl_state != gl->gl_target)) {
610+
struct gfs2_holder *gh = find_first_waiter(gl);
611+
609612
if (gh && !test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)) {
610613
if (ret & LM_OUT_CANCELED) {
611614
list_del_init(&gh->gh_list);
612615
trace_gfs2_glock_queue(gh, 0);
616+
gfs2_holder_wake(gh);
613617
gl->gl_target = gl->gl_state;
614-
gh = find_first_waiter(gl);
615-
if (gh) {
616-
gl->gl_target = gh->gh_state;
617-
if (do_promote(gl))
618-
goto out;
619-
do_xmote(gl, gh, gl->gl_target);
620-
return;
621-
}
622618
goto out;
623619
}
624620
/* Some error or failed "try lock" - report it */
@@ -629,7 +625,7 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
629625
goto out;
630626
}
631627
}
632-
switch(state) {
628+
switch(gl->gl_state) {
633629
/* Unlocked due to conversion deadlock, try again */
634630
case LM_ST_UNLOCKED:
635631
do_xmote(gl, gh, gl->gl_target);
@@ -640,8 +636,10 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
640636
do_xmote(gl, gh, LM_ST_UNLOCKED);
641637
break;
642638
default: /* Everything else */
643-
fs_err(gl->gl_name.ln_sbd, "wanted %u got %u\n",
644-
gl->gl_target, state);
639+
fs_err(gl->gl_name.ln_sbd,
640+
"glock %u:%llu requested=%u ret=%u\n",
641+
gl->gl_name.ln_type, gl->gl_name.ln_number,
642+
gl->gl_req, ret);
645643
GLOCK_BUG_ON(gl, 1);
646644
}
647645
return;
@@ -650,7 +648,7 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
650648
/* Fast path - we got what we asked for */
651649
if (test_and_clear_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags))
652650
gfs2_demote_wake(gl);
653-
if (state != LM_ST_UNLOCKED) {
651+
if (gl->gl_state != LM_ST_UNLOCKED) {
654652
if (glops->go_xmote_bh) {
655653
int rv;
656654

@@ -802,7 +800,8 @@ __acquires(&gl->gl_lockref.lock)
802800
* We skip telling dlm to do the locking, so we won't get a
803801
* reply that would otherwise clear GLF_LOCK. So we clear it here.
804802
*/
805-
clear_bit(GLF_LOCK, &gl->gl_flags);
803+
if (!test_bit(GLF_CANCELING, &gl->gl_flags))
804+
clear_bit(GLF_LOCK, &gl->gl_flags);
806805
clear_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags);
807806
gfs2_glock_queue_work(gl, GL_GLOCK_DFT_HOLD);
808807
return;

fs/gfs2/glock.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,22 @@ enum {
9292
* LM_OUT_ST_MASK
9393
* Masks the lower two bits of lock state in the returned value.
9494
*
95+
* LM_OUT_TRY_AGAIN
96+
* The trylock request failed.
97+
*
98+
* LM_OUT_DEADLOCK
99+
* The lock request failed because it would deadlock.
100+
*
95101
* LM_OUT_CANCELED
96102
* The lock request was canceled.
97103
*
104+
* LM_OUT_ERROR
105+
* The lock request timed out or failed.
98106
*/
99107

100108
#define LM_OUT_ST_MASK 0x00000003
109+
#define LM_OUT_TRY_AGAIN 0x00000020
110+
#define LM_OUT_DEADLOCK 0x00000010
101111
#define LM_OUT_CANCELED 0x00000008
102112
#define LM_OUT_ERROR 0x00000004
103113

fs/gfs2/glops.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/bio.h>
1212
#include <linux/posix_acl.h>
1313
#include <linux/security.h>
14+
#include <linux/log2.h>
1415

1516
#include "gfs2.h"
1617
#include "incore.h"
@@ -450,6 +451,11 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
450451
gfs2_consist_inode(ip);
451452
return -EIO;
452453
}
454+
if ((ip->i_diskflags & GFS2_DIF_EXHASH) &&
455+
depth < ilog2(sdp->sd_hash_ptrs)) {
456+
gfs2_consist_inode(ip);
457+
return -EIO;
458+
}
453459
ip->i_depth = (u8)depth;
454460
ip->i_entries = be32_to_cpu(str->di_entries);
455461

fs/gfs2/incore.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ struct gfs2_glock {
375375

376376
enum {
377377
GIF_QD_LOCKED = 1,
378-
GIF_ALLOC_FAILED = 2,
379378
GIF_SW_PAGED = 3,
380379
GIF_FREE_VFS_INODE = 5,
381380
GIF_GLOP_PENDING = 6,

fs/gfs2/inode.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,9 @@ static void gfs2_final_release_pages(struct gfs2_inode *ip)
444444
struct inode *inode = &ip->i_inode;
445445
struct gfs2_glock *gl = ip->i_gl;
446446

447-
if (unlikely(!gl)) {
448-
/* This can only happen during incomplete inode creation. */
449-
BUG_ON(!test_bit(GIF_ALLOC_FAILED, &ip->i_flags));
447+
/* This can only happen during incomplete inode creation. */
448+
if (unlikely(!gl))
450449
return;
451-
}
452450

453451
truncate_inode_pages(gfs2_glock2aspace(gl), 0);
454452
truncate_inode_pages(&inode->i_data, 0);
@@ -902,7 +900,6 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
902900
fail_gunlock2:
903901
gfs2_glock_put(io_gl);
904902
fail_dealloc_inode:
905-
set_bit(GIF_ALLOC_FAILED, &ip->i_flags);
906903
dealloc_error = 0;
907904
if (ip->i_eattr)
908905
dealloc_error = gfs2_ea_dealloc(ip, xattr_initialized);

fs/gfs2/inode.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ static inline int gfs2_is_dir(const struct gfs2_inode *ip)
4444

4545
static inline void gfs2_set_inode_blocks(struct inode *inode, u64 blocks)
4646
{
47-
inode->i_blocks = blocks << (inode->i_blkbits - 9);
47+
inode->i_blocks = blocks << (inode->i_blkbits - SECTOR_SHIFT);
4848
}
4949

5050
static inline u64 gfs2_get_inode_blocks(const struct inode *inode)
5151
{
52-
return inode->i_blocks >> (inode->i_blkbits - 9);
52+
return inode->i_blocks >> (inode->i_blkbits - SECTOR_SHIFT);
5353
}
5454

5555
static inline void gfs2_add_inode_blocks(struct inode *inode, s64 change)
5656
{
57-
change <<= inode->i_blkbits - 9;
57+
change <<= inode->i_blkbits - SECTOR_SHIFT;
5858
gfs2_assert(GFS2_SB(inode), (change >= 0 || inode->i_blocks >= -change));
5959
inode->i_blocks += change;
6060
}

fs/gfs2/lock_dlm.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static inline void gfs2_update_request_times(struct gfs2_glock *gl)
119119
static void gdlm_ast(void *arg)
120120
{
121121
struct gfs2_glock *gl = arg;
122-
unsigned ret = gl->gl_state;
122+
unsigned ret;
123123

124124
/* If the glock is dead, we only react to a dlm_unlock() reply. */
125125
if (__lockref_is_dead(&gl->gl_lockref) &&
@@ -139,13 +139,16 @@ static void gdlm_ast(void *arg)
139139
gfs2_glock_free(gl);
140140
return;
141141
case -DLM_ECANCEL: /* Cancel while getting lock */
142-
ret |= LM_OUT_CANCELED;
142+
ret = LM_OUT_CANCELED;
143143
goto out;
144144
case -EAGAIN: /* Try lock fails */
145+
ret = LM_OUT_TRY_AGAIN;
146+
goto out;
145147
case -EDEADLK: /* Deadlock detected */
148+
ret = LM_OUT_DEADLOCK;
146149
goto out;
147150
case -ETIMEDOUT: /* Canceled due to timeout */
148-
ret |= LM_OUT_ERROR;
151+
ret = LM_OUT_ERROR;
149152
goto out;
150153
case 0: /* Success */
151154
break;

fs/gfs2/meta_io.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ const struct address_space_operations gfs2_meta_aops = {
103103
.invalidate_folio = block_invalidate_folio,
104104
.writepages = gfs2_aspace_writepages,
105105
.release_folio = gfs2_release_folio,
106+
.migrate_folio = buffer_migrate_folio_norefs,
106107
};
107108

108109
const struct address_space_operations gfs2_rgrp_aops = {
109110
.dirty_folio = block_dirty_folio,
110111
.invalidate_folio = block_invalidate_folio,
111112
.writepages = gfs2_aspace_writepages,
112113
.release_folio = gfs2_release_folio,
114+
.migrate_folio = buffer_migrate_folio_norefs,
113115
};
114116

115117
/**
@@ -228,7 +230,7 @@ static void gfs2_submit_bhs(blk_opf_t opf, struct buffer_head *bhs[], int num)
228230
struct bio *bio;
229231

230232
bio = bio_alloc(bh->b_bdev, num, opf, GFP_NOIO);
231-
bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
233+
bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> SECTOR_SHIFT);
232234
while (num > 0) {
233235
bh = *bhs;
234236
if (!bio_add_folio(bio, bh->b_folio, bh->b_size, bh_offset(bh))) {
@@ -443,11 +445,9 @@ void gfs2_journal_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen)
443445
struct buffer_head *bh;
444446
int ty;
445447

446-
if (!ip->i_gl) {
447-
/* This can only happen during incomplete inode creation. */
448-
BUG_ON(!test_bit(GIF_ALLOC_FAILED, &ip->i_flags));
448+
/* This can only happen during incomplete inode creation. */
449+
if (!ip->i_gl)
449450
return;
450-
}
451451

452452
gfs2_ail1_wipe(sdp, bstart, blen);
453453
while (blen) {

fs/gfs2/ops_fstype.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static int gfs2_check_sb(struct gfs2_sbd *sdp, int silent)
163163
return -EINVAL;
164164
}
165165

166-
if (sb->sb_bsize < 512 || sb->sb_bsize > PAGE_SIZE ||
166+
if (sb->sb_bsize < SECTOR_SIZE || sb->sb_bsize > PAGE_SIZE ||
167167
(sb->sb_bsize & (sb->sb_bsize - 1))) {
168168
pr_warn("Invalid block size\n");
169169
return -EINVAL;
@@ -224,8 +224,8 @@ static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector, int silent)
224224
if (unlikely(!sb))
225225
return -ENOMEM;
226226
err = bdev_rw_virt(sdp->sd_vfs->s_bdev,
227-
sector * (sdp->sd_vfs->s_blocksize >> 9), sb, PAGE_SIZE,
228-
REQ_OP_READ | REQ_META);
227+
sector << (sdp->sd_vfs->s_blocksize_bits - SECTOR_SHIFT),
228+
sb, PAGE_SIZE, REQ_OP_READ | REQ_META);
229229
if (err) {
230230
pr_warn("error %d reading superblock\n", err);
231231
kfree(sb);
@@ -257,7 +257,7 @@ static int gfs2_read_sb(struct gfs2_sbd *sdp, int silent)
257257
return error;
258258
}
259259

260-
sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - 9;
260+
sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - SECTOR_SHIFT;
261261
sdp->sd_fsb2bb = BIT(sdp->sd_fsb2bb_shift);
262262
sdp->sd_diptrs = (sdp->sd_sb.sb_bsize -
263263
sizeof(struct gfs2_dinode)) / sizeof(u64);
@@ -1155,12 +1155,12 @@ static int gfs2_fill_super(struct super_block *sb, struct fs_context *fc)
11551155

11561156
/* Set up the buffer cache and fill in some fake block size values
11571157
to allow us to read-in the on-disk superblock. */
1158-
sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, 512);
1158+
sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, SECTOR_SIZE);
11591159
error = -EINVAL;
11601160
if (!sdp->sd_sb.sb_bsize)
11611161
goto fail_free;
11621162
sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits;
1163-
sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - 9;
1163+
sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - SECTOR_SHIFT;
11641164
sdp->sd_fsb2bb = BIT(sdp->sd_fsb2bb_shift);
11651165

11661166
sdp->sd_tune.gt_logd_secs = sdp->sd_args.ar_commit;

0 commit comments

Comments
 (0)