Skip to content

Commit 94c7695

Browse files
committed
Merge tag 'gfs2-v6.4-rc5-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2
Pull gfs2 updates from Andreas Gruenbacher: - Move the freeze/thaw logic from glock callback context to process / worker thread context to prevent deadlocks - Fix a quota reference couting bug in do_qc() - Carry on deallocating inodes even when gfs2_rindex_update() fails - Retry filesystem-internal reads when they are interruped by a signal - Eliminate kmap_atomic() in favor of kmap_local_page() / memcpy_{from,to}_page() - Get rid of noop_direct_IO - And a few more minor fixes and cleanups * tag 'gfs2-v6.4-rc5-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: (23 commits) gfs2: Add quota_change type gfs2: Use memcpy_{from,to}_page where appropriate gfs2: Convert remaining kmap_atomic calls to kmap_local_page gfs2: Replace deprecated kmap_atomic with kmap_local_page gfs: Get rid of unnucessary locking in inode_go_dump gfs2: gfs2_freeze_lock_shared cleanup gfs2: Replace sd_freeze_state with SDF_FROZEN flag gfs2: Rework freeze / thaw logic gfs2: Rename SDF_{FS_FROZEN => FREEZE_INITIATOR} gfs2: Reconfiguring frozen filesystem already rejected gfs2: Rename gfs2_freeze_lock{ => _shared } gfs2: Rename the {freeze,thaw}_super callbacks gfs2: Rename remaining "transaction" glock references gfs2: retry interrupted internal reads gfs2: Fix possible data races in gfs2_show_options() gfs2: Fix duplicate should_fault_in_pages() call gfs2: set FMODE_CAN_ODIRECT instead of a dummy direct_IO method gfs2: Don't remember delete unless it's successful gfs2: Update rl_unlinked before releasing rgrp lock gfs2: Fix gfs2_qa_get imbalance in gfs2_quota_hold ...
2 parents ccf46d8 + 432928c commit 94c7695

File tree

19 files changed

+277
-237
lines changed

19 files changed

+277
-237
lines changed

fs/gfs2/aops.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,10 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
432432
if (error)
433433
return error;
434434

435-
kaddr = kmap_atomic(page);
435+
kaddr = kmap_local_page(page);
436436
memcpy(kaddr, dibh->b_data + sizeof(struct gfs2_dinode), dsize);
437437
memset(kaddr + dsize, 0, PAGE_SIZE - dsize);
438-
kunmap_atomic(kaddr);
438+
kunmap_local(kaddr);
439439
flush_dcache_page(page);
440440
brelse(dibh);
441441
SetPageUptodate(page);
@@ -489,18 +489,18 @@ int gfs2_internal_read(struct gfs2_inode *ip, char *buf, loff_t *pos,
489489
unsigned copied = 0;
490490
unsigned amt;
491491
struct page *page;
492-
void *p;
493492

494493
do {
494+
page = read_cache_page(mapping, index, gfs2_read_folio, NULL);
495+
if (IS_ERR(page)) {
496+
if (PTR_ERR(page) == -EINTR)
497+
continue;
498+
return PTR_ERR(page);
499+
}
495500
amt = size - copied;
496501
if (offset + size > PAGE_SIZE)
497502
amt = PAGE_SIZE - offset;
498-
page = read_cache_page(mapping, index, gfs2_read_folio, NULL);
499-
if (IS_ERR(page))
500-
return PTR_ERR(page);
501-
p = kmap_atomic(page);
502-
memcpy(buf + copied, p + offset, amt);
503-
kunmap_atomic(p);
503+
memcpy_from_page(buf + copied, page, offset, amt);
504504
put_page(page);
505505
copied += amt;
506506
index++;
@@ -751,7 +751,6 @@ static const struct address_space_operations gfs2_aops = {
751751
.release_folio = iomap_release_folio,
752752
.invalidate_folio = iomap_invalidate_folio,
753753
.bmap = gfs2_bmap,
754-
.direct_IO = noop_direct_IO,
755754
.migrate_folio = filemap_migrate_folio,
756755
.is_partially_uptodate = iomap_is_partially_uptodate,
757756
.error_remove_page = generic_error_remove_page,

fs/gfs2/bmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,8 +1729,8 @@ static int punch_hole(struct gfs2_inode *ip, u64 offset, u64 length)
17291729

17301730
if (offset >= maxsize) {
17311731
/*
1732-
* The starting point lies beyond the allocated meta-data;
1733-
* there are no blocks do deallocate.
1732+
* The starting point lies beyond the allocated metadata;
1733+
* there are no blocks to deallocate.
17341734
*/
17351735
return 0;
17361736
}

fs/gfs2/file.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,9 @@ int gfs2_open_common(struct inode *inode, struct file *file)
630630
ret = generic_file_open(inode, file);
631631
if (ret)
632632
return ret;
633+
634+
if (!gfs2_is_jdata(GFS2_I(inode)))
635+
file->f_mode |= FMODE_CAN_ODIRECT;
633636
}
634637

635638
fp = kzalloc(sizeof(struct gfs2_file), GFP_NOFS);
@@ -1030,8 +1033,8 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
10301033
}
10311034

10321035
gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, gh);
1033-
retry:
10341036
if (should_fault_in_pages(from, iocb, &prev_count, &window_size)) {
1037+
retry:
10351038
window_size -= fault_in_iov_iter_readable(from, window_size);
10361039
if (!window_size) {
10371040
ret = -EFAULT;

fs/gfs2/glock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ static void gfs2_glock_dealloc(struct rcu_head *rcu)
145145
*
146146
* We need to allow some glocks to be enqueued, dequeued, promoted, and demoted
147147
* when we're withdrawn. For example, to maintain metadata integrity, we should
148-
* disallow the use of inode and rgrp glocks when withdrawn. Other glocks, like
149-
* iopen or the transaction glocks may be safely used because none of their
148+
* disallow the use of inode and rgrp glocks when withdrawn. Other glocks like
149+
* the iopen or freeze glock may be safely used because none of their
150150
* metadata goes through the journal. So in general, we should disallow all
151151
* glocks that are journaled, and allow all the others. One exception is:
152152
* we need to allow our active journal to be promoted and demoted so others

fs/gfs2/glops.c

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static void rgrp_go_inval(struct gfs2_glock *gl, int flags)
236236
truncate_inode_pages_range(mapping, start, end);
237237
}
238238

239-
static void gfs2_rgrp_go_dump(struct seq_file *seq, struct gfs2_glock *gl,
239+
static void gfs2_rgrp_go_dump(struct seq_file *seq, const struct gfs2_glock *gl,
240240
const char *fs_id_buf)
241241
{
242242
struct gfs2_rgrpd *rgd = gl->gl_object;
@@ -536,72 +536,53 @@ static int inode_go_held(struct gfs2_holder *gh)
536536
*
537537
*/
538538

539-
static void inode_go_dump(struct seq_file *seq, struct gfs2_glock *gl,
539+
static void inode_go_dump(struct seq_file *seq, const struct gfs2_glock *gl,
540540
const char *fs_id_buf)
541541
{
542542
struct gfs2_inode *ip = gl->gl_object;
543-
struct inode *inode;
544-
unsigned long nrpages;
543+
const struct inode *inode = &ip->i_inode;
545544

546545
if (ip == NULL)
547546
return;
548547

549-
inode = &ip->i_inode;
550-
xa_lock_irq(&inode->i_data.i_pages);
551-
nrpages = inode->i_data.nrpages;
552-
xa_unlock_irq(&inode->i_data.i_pages);
553-
554548
gfs2_print_dbg(seq, "%s I: n:%llu/%llu t:%u f:0x%02lx d:0x%08x s:%llu "
555549
"p:%lu\n", fs_id_buf,
556550
(unsigned long long)ip->i_no_formal_ino,
557551
(unsigned long long)ip->i_no_addr,
558-
IF2DT(ip->i_inode.i_mode), ip->i_flags,
552+
IF2DT(inode->i_mode), ip->i_flags,
559553
(unsigned int)ip->i_diskflags,
560-
(unsigned long long)i_size_read(inode), nrpages);
554+
(unsigned long long)i_size_read(inode),
555+
inode->i_data.nrpages);
561556
}
562557

563558
/**
564-
* freeze_go_sync - promote/demote the freeze glock
559+
* freeze_go_callback - A cluster node is requesting a freeze
565560
* @gl: the glock
561+
* @remote: true if this came from a different cluster node
566562
*/
567563

568-
static int freeze_go_sync(struct gfs2_glock *gl)
564+
static void freeze_go_callback(struct gfs2_glock *gl, bool remote)
569565
{
570-
int error = 0;
571566
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
567+
struct super_block *sb = sdp->sd_vfs;
568+
569+
if (!remote ||
570+
gl->gl_state != LM_ST_SHARED ||
571+
gl->gl_demote_state != LM_ST_UNLOCKED)
572+
return;
572573

573574
/*
574-
* We need to check gl_state == LM_ST_SHARED here and not gl_req ==
575-
* LM_ST_EXCLUSIVE. That's because when any node does a freeze,
576-
* all the nodes should have the freeze glock in SH mode and they all
577-
* call do_xmote: One for EX and the others for UN. They ALL must
578-
* freeze locally, and they ALL must queue freeze work. The freeze_work
579-
* calls freeze_func, which tries to reacquire the freeze glock in SH,
580-
* effectively waiting for the thaw on the node who holds it in EX.
581-
* Once thawed, the work func acquires the freeze glock in
582-
* SH and everybody goes back to thawed.
575+
* Try to get an active super block reference to prevent racing with
576+
* unmount (see trylock_super()). But note that unmount isn't the only
577+
* place where a write lock on s_umount is taken, and we can fail here
578+
* because of things like remount as well.
583579
*/
584-
if (gl->gl_state == LM_ST_SHARED && !gfs2_withdrawn(sdp) &&
585-
!test_bit(SDF_NORECOVERY, &sdp->sd_flags)) {
586-
atomic_set(&sdp->sd_freeze_state, SFS_STARTING_FREEZE);
587-
error = freeze_super(sdp->sd_vfs);
588-
if (error) {
589-
fs_info(sdp, "GFS2: couldn't freeze filesystem: %d\n",
590-
error);
591-
if (gfs2_withdrawn(sdp)) {
592-
atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN);
593-
return 0;
594-
}
595-
gfs2_assert_withdraw(sdp, 0);
596-
}
597-
queue_work(gfs2_freeze_wq, &sdp->sd_freeze_work);
598-
if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))
599-
gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_FREEZE |
600-
GFS2_LFC_FREEZE_GO_SYNC);
601-
else /* read-only mounts */
602-
atomic_set(&sdp->sd_freeze_state, SFS_FROZEN);
580+
if (down_read_trylock(&sb->s_umount)) {
581+
atomic_inc(&sb->s_active);
582+
up_read(&sb->s_umount);
583+
if (!queue_work(gfs2_freeze_wq, &sdp->sd_freeze_work))
584+
deactivate_super(sb);
603585
}
604-
return 0;
605586
}
606587

607588
/**
@@ -761,9 +742,9 @@ const struct gfs2_glock_operations gfs2_rgrp_glops = {
761742
};
762743

763744
const struct gfs2_glock_operations gfs2_freeze_glops = {
764-
.go_sync = freeze_go_sync,
765745
.go_xmote_bh = freeze_go_xmote_bh,
766746
.go_demote_ok = freeze_go_demote_ok,
747+
.go_callback = freeze_go_callback,
767748
.go_type = LM_TYPE_NONDISK,
768749
.go_flags = GLOF_NONDISK,
769750
};

fs/gfs2/incore.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ struct gfs2_glock_operations {
221221
int (*go_demote_ok) (const struct gfs2_glock *gl);
222222
int (*go_instantiate) (struct gfs2_glock *gl);
223223
int (*go_held)(struct gfs2_holder *gh);
224-
void (*go_dump)(struct seq_file *seq, struct gfs2_glock *gl,
224+
void (*go_dump)(struct seq_file *seq, const struct gfs2_glock *gl,
225225
const char *fs_id_buf);
226226
void (*go_callback)(struct gfs2_glock *gl, bool remote);
227227
void (*go_free)(struct gfs2_glock *gl);
@@ -600,20 +600,15 @@ enum {
600600
SDF_RORECOVERY = 7, /* read only recovery */
601601
SDF_SKIP_DLM_UNLOCK = 8,
602602
SDF_FORCE_AIL_FLUSH = 9,
603-
SDF_FS_FROZEN = 10,
603+
SDF_FREEZE_INITIATOR = 10,
604604
SDF_WITHDRAWING = 11, /* Will withdraw eventually */
605605
SDF_WITHDRAW_IN_PROG = 12, /* Withdraw is in progress */
606606
SDF_REMOTE_WITHDRAW = 13, /* Performing remote recovery */
607607
SDF_WITHDRAW_RECOVERY = 14, /* Wait for journal recovery when we are
608608
withdrawing */
609609
SDF_DEACTIVATING = 15,
610610
SDF_EVICTING = 16,
611-
};
612-
613-
enum gfs2_freeze_state {
614-
SFS_UNFROZEN = 0,
615-
SFS_STARTING_FREEZE = 1,
616-
SFS_FROZEN = 2,
611+
SDF_FROZEN = 17,
617612
};
618613

619614
#define GFS2_FSNAME_LEN 256
@@ -841,7 +836,6 @@ struct gfs2_sbd {
841836

842837
/* For quiescing the filesystem */
843838
struct gfs2_holder sd_freeze_gh;
844-
atomic_t sd_freeze_state;
845839
struct mutex sd_freeze_mutex;
846840

847841
char sd_fsname[GFS2_FSNAME_LEN + 3 * sizeof(int) + 2];

fs/gfs2/lock_dlm.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -296,28 +296,22 @@ static void gdlm_put_lock(struct gfs2_glock *gl)
296296
struct lm_lockstruct *ls = &sdp->sd_lockstruct;
297297
int error;
298298

299-
if (gl->gl_lksb.sb_lkid == 0) {
300-
gfs2_glock_free(gl);
301-
return;
302-
}
299+
if (gl->gl_lksb.sb_lkid == 0)
300+
goto out_free;
303301

304302
clear_bit(GLF_BLOCKING, &gl->gl_flags);
305303
gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT);
306304
gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT);
307305
gfs2_update_request_times(gl);
308306

309307
/* don't want to call dlm if we've unmounted the lock protocol */
310-
if (test_bit(DFL_UNMOUNT, &ls->ls_recover_flags)) {
311-
gfs2_glock_free(gl);
312-
return;
313-
}
308+
if (test_bit(DFL_UNMOUNT, &ls->ls_recover_flags))
309+
goto out_free;
314310
/* don't want to skip dlm_unlock writing the lvb when lock has one */
315311

316312
if (test_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags) &&
317-
!gl->gl_lksb.sb_lvbptr) {
318-
gfs2_glock_free(gl);
319-
return;
320-
}
313+
!gl->gl_lksb.sb_lvbptr)
314+
goto out_free;
321315

322316
again:
323317
error = dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_VALBLK,
@@ -331,8 +325,11 @@ static void gdlm_put_lock(struct gfs2_glock *gl)
331325
fs_err(sdp, "gdlm_unlock %x,%llx err=%d\n",
332326
gl->gl_name.ln_type,
333327
(unsigned long long)gl->gl_name.ln_number, error);
334-
return;
335328
}
329+
return;
330+
331+
out_free:
332+
gfs2_glock_free(gl);
336333
}
337334

338335
static void gdlm_cancel(struct gfs2_glock *gl)

fs/gfs2/log.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -914,9 +914,8 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
914914
static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
915915
{
916916
blk_opf_t op_flags = REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC;
917-
enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state);
918917

919-
gfs2_assert_withdraw(sdp, (state != SFS_FROZEN));
918+
gfs2_assert_withdraw(sdp, !test_bit(SDF_FROZEN, &sdp->sd_flags));
920919

921920
if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags)) {
922921
gfs2_ordered_wait(sdp);
@@ -1036,7 +1035,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
10361035
{
10371036
struct gfs2_trans *tr = NULL;
10381037
unsigned int reserved_blocks = 0, used_blocks = 0;
1039-
enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state);
1038+
bool frozen = test_bit(SDF_FROZEN, &sdp->sd_flags);
10401039
unsigned int first_log_head;
10411040
unsigned int reserved_revokes = 0;
10421041

@@ -1067,7 +1066,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
10671066
if (tr) {
10681067
sdp->sd_log_tr = NULL;
10691068
tr->tr_first = first_log_head;
1070-
if (unlikely (state == SFS_FROZEN)) {
1069+
if (unlikely(frozen)) {
10711070
if (gfs2_assert_withdraw_delayed(sdp,
10721071
!tr->tr_num_buf_new && !tr->tr_num_databuf_new))
10731072
goto out_withdraw;
@@ -1092,7 +1091,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
10921091
if (flags & GFS2_LOG_HEAD_FLUSH_SHUTDOWN)
10931092
clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
10941093

1095-
if (unlikely(state == SFS_FROZEN))
1094+
if (unlikely(frozen))
10961095
if (gfs2_assert_withdraw_delayed(sdp, !reserved_revokes))
10971096
goto out_withdraw;
10981097

@@ -1136,8 +1135,6 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
11361135
if (flags & (GFS2_LOG_HEAD_FLUSH_SHUTDOWN |
11371136
GFS2_LOG_HEAD_FLUSH_FREEZE))
11381137
gfs2_log_shutdown(sdp);
1139-
if (flags & GFS2_LOG_HEAD_FLUSH_FREEZE)
1140-
atomic_set(&sdp->sd_freeze_state, SFS_FROZEN);
11411138
}
11421139

11431140
out_end:

fs/gfs2/lops.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,11 @@ static bool gfs2_jhead_pg_srch(struct gfs2_jdesc *jd,
427427
{
428428
struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
429429
struct gfs2_log_header_host lh;
430-
void *kaddr = kmap_atomic(page);
430+
void *kaddr;
431431
unsigned int offset;
432432
bool ret = false;
433433

434+
kaddr = kmap_local_page(page);
434435
for (offset = 0; offset < PAGE_SIZE; offset += sdp->sd_sb.sb_bsize) {
435436
if (!__get_log_header(sdp, kaddr + offset, 0, &lh)) {
436437
if (lh.lh_sequence >= head->lh_sequence)
@@ -441,7 +442,7 @@ static bool gfs2_jhead_pg_srch(struct gfs2_jdesc *jd,
441442
}
442443
}
443444
}
444-
kunmap_atomic(kaddr);
445+
kunmap_local(kaddr);
445446
return ret;
446447
}
447448

@@ -626,11 +627,11 @@ static void gfs2_check_magic(struct buffer_head *bh)
626627
__be32 *ptr;
627628

628629
clear_buffer_escaped(bh);
629-
kaddr = kmap_atomic(bh->b_page);
630+
kaddr = kmap_local_page(bh->b_page);
630631
ptr = kaddr + bh_offset(bh);
631632
if (*ptr == cpu_to_be32(GFS2_MAGIC))
632633
set_buffer_escaped(bh);
633-
kunmap_atomic(kaddr);
634+
kunmap_local(kaddr);
634635
}
635636

636637
static int blocknr_cmp(void *priv, const struct list_head *a,
@@ -696,14 +697,12 @@ static void gfs2_before_commit(struct gfs2_sbd *sdp, unsigned int limit,
696697
lock_buffer(bd2->bd_bh);
697698

698699
if (buffer_escaped(bd2->bd_bh)) {
699-
void *kaddr;
700+
void *p;
701+
700702
page = mempool_alloc(gfs2_page_pool, GFP_NOIO);
701-
ptr = page_address(page);
702-
kaddr = kmap_atomic(bd2->bd_bh->b_page);
703-
memcpy(ptr, kaddr + bh_offset(bd2->bd_bh),
704-
bd2->bd_bh->b_size);
705-
kunmap_atomic(kaddr);
706-
*(__be32 *)ptr = 0;
703+
p = page_address(page);
704+
memcpy_from_page(p, page, bh_offset(bd2->bd_bh), bd2->bd_bh->b_size);
705+
*(__be32 *)p = 0;
707706
clear_buffer_escaped(bd2->bd_bh);
708707
unlock_buffer(bd2->bd_bh);
709708
brelse(bd2->bd_bh);

0 commit comments

Comments
 (0)