Skip to content

Commit ef479de

Browse files
committed
Merge tag 'gfs2-for-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2
Pull gfs2 updates from Andreas Gruenbacher: - Fix two bugs related to locking request cancelation (locking request being retried instead of canceled; canceling the wrong locking request) - Prevent a race between inode creation and deferred delete analogous to commit ffd1cf0 from 6.13. This now allows to further simplify gfs2_evict_inode() without introducing mysterious problems - When in inode delete should be verified / retried "later" but that isn't possible, skip the delete instead of carrying it out immediately. This broke in 6.13 - More folio conversions from Matthew Wilcox (plus a fix from Dan Carpenter) - Various minor fixes and cleanups * tag 'gfs2-for-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: (22 commits) gfs2: some comment clarifications gfs2: Fix a NULL vs IS_ERR() bug in gfs2_find_jhead() gfs2: Convert gfs2_meta_read_endio() to use a folio gfs2: Convert gfs2_end_log_write_bh() to work on a folio gfs2: Convert gfs2_find_jhead() to use a folio gfs2: Convert gfs2_jhead_pg_srch() to gfs2_jhead_folio_search() gfs2: Use b_folio in gfs2_check_magic() gfs2: Use b_folio in gfs2_submit_bhs() gfs2: Use b_folio in gfs2_trans_add_meta() gfs2: Use b_folio in gfs2_log_write_bh() gfs2: skip if we cannot defer delete gfs2: remove redundant warnings gfs2: minor evict fix gfs2: Prevent inode creation race (2) gfs2: Fix additional unlikely request cancelation race gfs2: Fix request cancelation bug gfs2: Check for empty queue in run_queue gfs2: Remove more dead code in add_to_queue gfs2: Replace GIF_DEFER_DELETE with GLF_DEFER_DELETE gfs2: glock holder GL_NOPID fix ...
2 parents 3a90a72 + 8cb70b9 commit ef479de

File tree

9 files changed

+136
-132
lines changed

9 files changed

+136
-132
lines changed

fs/gfs2/file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to,
820820
/*
821821
* In this function, we disable page faults when we're holding the
822822
* inode glock while doing I/O. If a page fault occurs, we indicate
823-
* that the inode glock may be dropped, fault in the pages manually,
823+
* that the inode glock should be dropped, fault in the pages manually,
824824
* and retry.
825825
*
826826
* Unlike generic_file_read_iter, for reads, iomap_dio_rw can trigger
@@ -885,7 +885,7 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from,
885885
/*
886886
* In this function, we disable page faults when we're holding the
887887
* inode glock while doing I/O. If a page fault occurs, we indicate
888-
* that the inode glock may be dropped, fault in the pages manually,
888+
* that the inode glock should be dropped, fault in the pages manually,
889889
* and retry.
890890
*
891891
* For writes, iomap_dio_rw only triggers manual page faults, so we
@@ -957,7 +957,7 @@ static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
957957
/*
958958
* In this function, we disable page faults when we're holding the
959959
* inode glock while doing I/O. If a page fault occurs, we indicate
960-
* that the inode glock may be dropped, fault in the pages manually,
960+
* that the inode glock should be dropped, fault in the pages manually,
961961
* and retry.
962962
*/
963963

@@ -1024,7 +1024,7 @@ static ssize_t gfs2_file_buffered_write(struct kiocb *iocb,
10241024
/*
10251025
* In this function, we disable page faults when we're holding the
10261026
* inode glock while doing I/O. If a page fault occurs, we indicate
1027-
* that the inode glock may be dropped, fault in the pages manually,
1027+
* that the inode glock should be dropped, fault in the pages manually,
10281028
* and retry.
10291029
*/
10301030

fs/gfs2/glock.c

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,19 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
607607
if (gh && (ret & LM_OUT_CANCELED))
608608
gfs2_holder_wake(gh);
609609
if (gh && !test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)) {
610-
/* move to back of queue and try next entry */
611610
if (ret & LM_OUT_CANCELED) {
612-
list_move_tail(&gh->gh_list, &gl->gl_holders);
611+
list_del_init(&gh->gh_list);
612+
trace_gfs2_glock_queue(gh, 0);
613+
gl->gl_target = gl->gl_state;
613614
gh = find_first_waiter(gl);
614-
gl->gl_target = gh->gh_state;
615-
if (do_promote(gl))
616-
goto out;
617-
goto retry;
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+
}
622+
goto out;
618623
}
619624
/* Some error or failed "try lock" - report it */
620625
if ((ret & LM_OUT_ERROR) ||
@@ -627,7 +632,6 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
627632
switch(state) {
628633
/* Unlocked due to conversion deadlock, try again */
629634
case LM_ST_UNLOCKED:
630-
retry:
631635
do_xmote(gl, gh, gl->gl_target);
632636
break;
633637
/* Conversion fails, unlock and try again */
@@ -661,7 +665,8 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
661665
do_promote(gl);
662666
}
663667
out:
664-
clear_bit(GLF_LOCK, &gl->gl_flags);
668+
if (!test_bit(GLF_CANCELING, &gl->gl_flags))
669+
clear_bit(GLF_LOCK, &gl->gl_flags);
665670
}
666671

667672
static bool is_system_glock(struct gfs2_glock *gl)
@@ -807,6 +812,7 @@ __acquires(&gl->gl_lockref.lock)
807812
}
808813

809814
if (ls->ls_ops->lm_lock) {
815+
set_bit(GLF_PENDING_REPLY, &gl->gl_flags);
810816
spin_unlock(&gl->gl_lockref.lock);
811817
ret = ls->ls_ops->lm_lock(gl, target, lck_flags);
812818
spin_lock(&gl->gl_lockref.lock);
@@ -825,6 +831,7 @@ __acquires(&gl->gl_lockref.lock)
825831
/* The operation will be completed asynchronously. */
826832
return;
827833
}
834+
clear_bit(GLF_PENDING_REPLY, &gl->gl_flags);
828835
}
829836

830837
/* Complete the operation now. */
@@ -843,12 +850,13 @@ static void run_queue(struct gfs2_glock *gl, const int nonblock)
843850
__releases(&gl->gl_lockref.lock)
844851
__acquires(&gl->gl_lockref.lock)
845852
{
846-
struct gfs2_holder *gh = NULL;
853+
struct gfs2_holder *gh;
847854

848855
if (test_bit(GLF_LOCK, &gl->gl_flags))
849856
return;
850857
set_bit(GLF_LOCK, &gl->gl_flags);
851858

859+
/* While a demote is in progress, the GLF_LOCK flag must be set. */
852860
GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags));
853861

854862
if (test_bit(GLF_DEMOTE, &gl->gl_flags) &&
@@ -860,18 +868,22 @@ __acquires(&gl->gl_lockref.lock)
860868
set_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags);
861869
GLOCK_BUG_ON(gl, gl->gl_demote_state == LM_ST_EXCLUSIVE);
862870
gl->gl_target = gl->gl_demote_state;
871+
do_xmote(gl, NULL, gl->gl_target);
872+
return;
863873
} else {
864874
if (test_bit(GLF_DEMOTE, &gl->gl_flags))
865875
gfs2_demote_wake(gl);
866876
if (do_promote(gl))
867877
goto out_unlock;
868878
gh = find_first_waiter(gl);
879+
if (!gh)
880+
goto out_unlock;
869881
gl->gl_target = gh->gh_state;
870882
if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)))
871883
do_error(gl, 0); /* Fail queued try locks */
884+
do_xmote(gl, gh, gl->gl_target);
885+
return;
872886
}
873-
do_xmote(gl, gh, gl->gl_target);
874-
return;
875887

876888
out_sched:
877889
clear_bit(GLF_LOCK, &gl->gl_flags);
@@ -898,12 +910,8 @@ void glock_set_object(struct gfs2_glock *gl, void *object)
898910
prev_object = gl->gl_object;
899911
gl->gl_object = object;
900912
spin_unlock(&gl->gl_lockref.lock);
901-
if (gfs2_assert_warn(gl->gl_name.ln_sbd, prev_object == NULL)) {
902-
pr_warn("glock=%u/%llx\n",
903-
gl->gl_name.ln_type,
904-
(unsigned long long)gl->gl_name.ln_number);
913+
if (gfs2_assert_warn(gl->gl_name.ln_sbd, prev_object == NULL))
905914
gfs2_dump_glock(NULL, gl, true);
906-
}
907915
}
908916

909917
/**
@@ -919,12 +927,8 @@ void glock_clear_object(struct gfs2_glock *gl, void *object)
919927
prev_object = gl->gl_object;
920928
gl->gl_object = NULL;
921929
spin_unlock(&gl->gl_lockref.lock);
922-
if (gfs2_assert_warn(gl->gl_name.ln_sbd, prev_object == object)) {
923-
pr_warn("glock=%u/%llx\n",
924-
gl->gl_name.ln_type,
925-
(unsigned long long)gl->gl_name.ln_number);
930+
if (gfs2_assert_warn(gl->gl_name.ln_sbd, prev_object == object))
926931
gfs2_dump_glock(NULL, gl, true);
927-
}
928932
}
929933

930934
void gfs2_inode_remember_delete(struct gfs2_glock *gl, u64 generation)
@@ -959,6 +963,25 @@ static void gfs2_glock_poke(struct gfs2_glock *gl)
959963
gfs2_holder_uninit(&gh);
960964
}
961965

966+
static struct gfs2_inode *gfs2_grab_existing_inode(struct gfs2_glock *gl)
967+
{
968+
struct gfs2_inode *ip;
969+
970+
spin_lock(&gl->gl_lockref.lock);
971+
ip = gl->gl_object;
972+
if (ip && !igrab(&ip->i_inode))
973+
ip = NULL;
974+
spin_unlock(&gl->gl_lockref.lock);
975+
if (ip) {
976+
wait_on_inode(&ip->i_inode);
977+
if (is_bad_inode(&ip->i_inode)) {
978+
iput(&ip->i_inode);
979+
ip = NULL;
980+
}
981+
}
982+
return ip;
983+
}
984+
962985
static void gfs2_try_evict(struct gfs2_glock *gl)
963986
{
964987
struct gfs2_inode *ip;
@@ -976,32 +999,15 @@ static void gfs2_try_evict(struct gfs2_glock *gl)
976999
* happened below. (Verification is triggered by the call to
9771000
* gfs2_queue_verify_delete() in gfs2_evict_inode().)
9781001
*/
979-
spin_lock(&gl->gl_lockref.lock);
980-
ip = gl->gl_object;
981-
if (ip && !igrab(&ip->i_inode))
982-
ip = NULL;
983-
spin_unlock(&gl->gl_lockref.lock);
984-
if (ip) {
985-
wait_on_inode(&ip->i_inode);
986-
if (is_bad_inode(&ip->i_inode)) {
987-
iput(&ip->i_inode);
988-
ip = NULL;
989-
}
990-
}
1002+
ip = gfs2_grab_existing_inode(gl);
9911003
if (ip) {
992-
set_bit(GIF_DEFER_DELETE, &ip->i_flags);
1004+
set_bit(GLF_DEFER_DELETE, &gl->gl_flags);
9931005
d_prune_aliases(&ip->i_inode);
9941006
iput(&ip->i_inode);
1007+
clear_bit(GLF_DEFER_DELETE, &gl->gl_flags);
9951008

9961009
/* If the inode was evicted, gl->gl_object will now be NULL. */
997-
spin_lock(&gl->gl_lockref.lock);
998-
ip = gl->gl_object;
999-
if (ip) {
1000-
clear_bit(GIF_DEFER_DELETE, &ip->i_flags);
1001-
if (!igrab(&ip->i_inode))
1002-
ip = NULL;
1003-
}
1004-
spin_unlock(&gl->gl_lockref.lock);
1010+
ip = gfs2_grab_existing_inode(gl);
10051011
if (ip) {
10061012
gfs2_glock_poke(ip->i_gl);
10071013
iput(&ip->i_inode);
@@ -1462,9 +1468,7 @@ static inline bool pid_is_meaningful(const struct gfs2_holder *gh)
14621468
{
14631469
if (!(gh->gh_flags & GL_NOPID))
14641470
return true;
1465-
if (gh->gh_state == LM_ST_UNLOCKED)
1466-
return true;
1467-
return false;
1471+
return !test_bit(HIF_HOLDER, &gh->gh_iflags);
14681472
}
14691473

14701474
/**
@@ -1483,7 +1487,6 @@ __acquires(&gl->gl_lockref.lock)
14831487
{
14841488
struct gfs2_glock *gl = gh->gh_gl;
14851489
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
1486-
struct list_head *insert_pt = NULL;
14871490
struct gfs2_holder *gh2;
14881491
int try_futile = 0;
14891492

@@ -1519,21 +1522,11 @@ __acquires(&gl->gl_lockref.lock)
15191522
gfs2_holder_wake(gh);
15201523
return;
15211524
}
1522-
if (test_bit(HIF_HOLDER, &gh2->gh_iflags))
1523-
continue;
15241525
}
15251526
trace_gfs2_glock_queue(gh, 1);
15261527
gfs2_glstats_inc(gl, GFS2_LKS_QCOUNT);
15271528
gfs2_sbstats_inc(gl, GFS2_LKS_QCOUNT);
1528-
if (likely(insert_pt == NULL)) {
1529-
list_add_tail(&gh->gh_list, &gl->gl_holders);
1530-
return;
1531-
}
1532-
list_add_tail(&gh->gh_list, insert_pt);
1533-
spin_unlock(&gl->gl_lockref.lock);
1534-
if (sdp->sd_lockstruct.ls_ops->lm_cancel)
1535-
sdp->sd_lockstruct.ls_ops->lm_cancel(gl);
1536-
spin_lock(&gl->gl_lockref.lock);
1529+
list_add_tail(&gh->gh_list, &gl->gl_holders);
15371530
return;
15381531

15391532
trap_recursive:
@@ -1673,11 +1666,19 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
16731666
}
16741667

16751668
if (list_is_first(&gh->gh_list, &gl->gl_holders) &&
1676-
!test_bit(HIF_HOLDER, &gh->gh_iflags)) {
1669+
!test_bit(HIF_HOLDER, &gh->gh_iflags) &&
1670+
test_bit(GLF_LOCK, &gl->gl_flags) &&
1671+
!test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags) &&
1672+
!test_bit(GLF_CANCELING, &gl->gl_flags)) {
1673+
set_bit(GLF_CANCELING, &gl->gl_flags);
16771674
spin_unlock(&gl->gl_lockref.lock);
16781675
gl->gl_name.ln_sbd->sd_lockstruct.ls_ops->lm_cancel(gl);
16791676
wait_on_bit(&gh->gh_iflags, HIF_WAIT, TASK_UNINTERRUPTIBLE);
16801677
spin_lock(&gl->gl_lockref.lock);
1678+
clear_bit(GLF_CANCELING, &gl->gl_flags);
1679+
clear_bit(GLF_LOCK, &gl->gl_flags);
1680+
if (!gfs2_holder_queued(gh))
1681+
goto out;
16811682
}
16821683

16831684
/*
@@ -1923,6 +1924,7 @@ void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
19231924
struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct;
19241925

19251926
spin_lock(&gl->gl_lockref.lock);
1927+
clear_bit(GLF_PENDING_REPLY, &gl->gl_flags);
19261928
gl->gl_reply = ret;
19271929

19281930
if (unlikely(test_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags))) {
@@ -2323,6 +2325,8 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
23232325
*p++ = 'f';
23242326
if (test_bit(GLF_INVALIDATE_IN_PROGRESS, gflags))
23252327
*p++ = 'i';
2328+
if (test_bit(GLF_PENDING_REPLY, gflags))
2329+
*p++ = 'R';
23262330
if (test_bit(GLF_HAVE_REPLY, gflags))
23272331
*p++ = 'r';
23282332
if (test_bit(GLF_INITIAL, gflags))
@@ -2347,6 +2351,10 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
23472351
*p++ = 'e';
23482352
if (test_bit(GLF_VERIFY_DELETE, gflags))
23492353
*p++ = 'E';
2354+
if (test_bit(GLF_DEFER_DELETE, gflags))
2355+
*p++ = 's';
2356+
if (test_bit(GLF_CANCELING, gflags))
2357+
*p++ = 'C';
23502358
*p = 0;
23512359
return buf;
23522360
}

fs/gfs2/incore.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ enum {
330330
GLF_UNLOCKED = 16, /* Wait for glock to be unlocked */
331331
GLF_TRY_TO_EVICT = 17, /* iopen glocks only */
332332
GLF_VERIFY_DELETE = 18, /* iopen glocks only */
333+
GLF_PENDING_REPLY = 19,
334+
GLF_DEFER_DELETE = 20, /* iopen glocks only */
335+
GLF_CANCELING = 21,
333336
};
334337

335338
struct gfs2_glock {
@@ -376,7 +379,6 @@ enum {
376379
GIF_SW_PAGED = 3,
377380
GIF_FREE_VFS_INODE = 5,
378381
GIF_GLOP_PENDING = 6,
379-
GIF_DEFER_DELETE = 7,
380382
};
381383

382384
struct gfs2_inode {

0 commit comments

Comments
 (0)