Skip to content

Commit ff2a7a0

Browse files
committed
Merge tag 'gfs2-for-6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2
Pull gfs2 updates from Andreas Gruenbacher: - Fix the code that cleans up left-over unlinked files. Various fixes and minor improvements in deleting files cached or held open remotely. - Simplify the use of dlm's DLM_LKF_QUECVT flag. - A few other minor cleanups. * tag 'gfs2-for-6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: (21 commits) gfs2: Prevent inode creation race gfs2: Only defer deletes when we have an iopen glock gfs2: Simplify DLM_LKF_QUECVT use gfs2: gfs2_evict_inode clarification gfs2: Make gfs2_inode_refresh static gfs2: Use get_random_u32 in gfs2_orlov_skip gfs2: Randomize GLF_VERIFY_DELETE work delay gfs2: Use mod_delayed_work in gfs2_queue_try_to_evict gfs2: Update to the evict / remote delete documentation gfs2: Call gfs2_queue_verify_delete from gfs2_evict_inode gfs2: Clean up delete work processing gfs2: Minor delete_work_func cleanup gfs2: Return enum evict_behavior from gfs2_upgrade_iopen_glock gfs2: Rename dinode_demise to evict_behavior gfs2: Rename GIF_{DEFERRED -> DEFER}_DELETE gfs2: Faster gfs2_upgrade_iopen_glock wakeups KMSAN: uninit-value in inode_go_dump (5) gfs2: Fix unlinked inode cleanup gfs2: Allow immediate GLF_VERIFY_DELETE work gfs2: Initialize gl_no_formal_ino earlier ...
2 parents 7eef7e3 + ffd1cf0 commit ff2a7a0

File tree

9 files changed

+142
-114
lines changed

9 files changed

+142
-114
lines changed

fs/gfs2/glock.c

Lines changed: 41 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/rhashtable.h>
3636
#include <linux/pid_namespace.h>
3737
#include <linux/file.h>
38+
#include <linux/random.h>
3839

3940
#include "gfs2.h"
4041
#include "incore.h"
@@ -562,11 +563,11 @@ static void state_change(struct gfs2_glock *gl, unsigned int new_state)
562563
gl->gl_tchange = jiffies;
563564
}
564565

565-
static void gfs2_set_demote(struct gfs2_glock *gl)
566+
static void gfs2_set_demote(int nr, struct gfs2_glock *gl)
566567
{
567568
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
568569

569-
set_bit(GLF_DEMOTE, &gl->gl_flags);
570+
set_bit(nr, &gl->gl_flags);
570571
smp_mb();
571572
wake_up(&sdp->sd_async_glock_wait);
572573
}
@@ -958,37 +959,45 @@ static void gfs2_glock_poke(struct gfs2_glock *gl)
958959
gfs2_holder_uninit(&gh);
959960
}
960961

961-
static bool gfs2_try_evict(struct gfs2_glock *gl)
962+
static void gfs2_try_evict(struct gfs2_glock *gl)
962963
{
963964
struct gfs2_inode *ip;
964-
bool evicted = false;
965965

966966
/*
967967
* If there is contention on the iopen glock and we have an inode, try
968-
* to grab and release the inode so that it can be evicted. This will
969-
* allow the remote node to go ahead and delete the inode without us
970-
* having to do it, which will avoid rgrp glock thrashing.
968+
* to grab and release the inode so that it can be evicted. The
969+
* GIF_DEFER_DELETE flag indicates to gfs2_evict_inode() that the inode
970+
* should not be deleted locally. This will allow the remote node to
971+
* go ahead and delete the inode without us having to do it, which will
972+
* avoid rgrp glock thrashing.
971973
*
972974
* The remote node is likely still holding the corresponding inode
973975
* glock, so it will run before we get to verify that the delete has
974-
* happened below.
976+
* happened below. (Verification is triggered by the call to
977+
* gfs2_queue_verify_delete() in gfs2_evict_inode().)
975978
*/
976979
spin_lock(&gl->gl_lockref.lock);
977980
ip = gl->gl_object;
978981
if (ip && !igrab(&ip->i_inode))
979982
ip = NULL;
980983
spin_unlock(&gl->gl_lockref.lock);
981984
if (ip) {
982-
gl->gl_no_formal_ino = ip->i_no_formal_ino;
983-
set_bit(GIF_DEFERRED_DELETE, &ip->i_flags);
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+
}
991+
if (ip) {
992+
set_bit(GIF_DEFER_DELETE, &ip->i_flags);
984993
d_prune_aliases(&ip->i_inode);
985994
iput(&ip->i_inode);
986995

987996
/* If the inode was evicted, gl->gl_object will now be NULL. */
988997
spin_lock(&gl->gl_lockref.lock);
989998
ip = gl->gl_object;
990999
if (ip) {
991-
clear_bit(GIF_DEFERRED_DELETE, &ip->i_flags);
1000+
clear_bit(GIF_DEFER_DELETE, &ip->i_flags);
9921001
if (!igrab(&ip->i_inode))
9931002
ip = NULL;
9941003
}
@@ -997,9 +1006,7 @@ static bool gfs2_try_evict(struct gfs2_glock *gl)
9971006
gfs2_glock_poke(ip->i_gl);
9981007
iput(&ip->i_inode);
9991008
}
1000-
evicted = !ip;
10011009
}
1002-
return evicted;
10031010
}
10041011

10051012
bool gfs2_queue_try_to_evict(struct gfs2_glock *gl)
@@ -1008,70 +1015,47 @@ bool gfs2_queue_try_to_evict(struct gfs2_glock *gl)
10081015

10091016
if (test_and_set_bit(GLF_TRY_TO_EVICT, &gl->gl_flags))
10101017
return false;
1011-
return queue_delayed_work(sdp->sd_delete_wq,
1012-
&gl->gl_delete, 0);
1018+
return !mod_delayed_work(sdp->sd_delete_wq, &gl->gl_delete, 0);
10131019
}
10141020

1015-
static bool gfs2_queue_verify_evict(struct gfs2_glock *gl)
1021+
bool gfs2_queue_verify_delete(struct gfs2_glock *gl, bool later)
10161022
{
10171023
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
1024+
unsigned long delay;
10181025

1019-
if (test_and_set_bit(GLF_VERIFY_EVICT, &gl->gl_flags))
1026+
if (test_and_set_bit(GLF_VERIFY_DELETE, &gl->gl_flags))
10201027
return false;
1021-
return queue_delayed_work(sdp->sd_delete_wq,
1022-
&gl->gl_delete, 5 * HZ);
1028+
delay = later ? HZ + get_random_long() % (HZ * 9) : 0;
1029+
return queue_delayed_work(sdp->sd_delete_wq, &gl->gl_delete, delay);
10231030
}
10241031

10251032
static void delete_work_func(struct work_struct *work)
10261033
{
10271034
struct delayed_work *dwork = to_delayed_work(work);
10281035
struct gfs2_glock *gl = container_of(dwork, struct gfs2_glock, gl_delete);
10291036
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
1030-
struct inode *inode;
1031-
u64 no_addr = gl->gl_name.ln_number;
1037+
bool verify_delete = test_and_clear_bit(GLF_VERIFY_DELETE, &gl->gl_flags);
10321038

1033-
if (test_and_clear_bit(GLF_TRY_TO_EVICT, &gl->gl_flags)) {
1034-
/*
1035-
* If we can evict the inode, give the remote node trying to
1036-
* delete the inode some time before verifying that the delete
1037-
* has happened. Otherwise, if we cause contention on the inode glock
1038-
* immediately, the remote node will think that we still have
1039-
* the inode in use, and so it will give up waiting.
1040-
*
1041-
* If we can't evict the inode, signal to the remote node that
1042-
* the inode is still in use. We'll later try to delete the
1043-
* inode locally in gfs2_evict_inode.
1044-
*
1045-
* FIXME: We only need to verify that the remote node has
1046-
* deleted the inode because nodes before this remote delete
1047-
* rework won't cooperate. At a later time, when we no longer
1048-
* care about compatibility with such nodes, we can skip this
1049-
* step entirely.
1050-
*/
1051-
if (gfs2_try_evict(gl)) {
1052-
if (test_bit(SDF_KILL, &sdp->sd_flags))
1053-
goto out;
1054-
if (gfs2_queue_verify_evict(gl))
1055-
return;
1056-
}
1057-
goto out;
1058-
}
1039+
if (test_and_clear_bit(GLF_TRY_TO_EVICT, &gl->gl_flags))
1040+
gfs2_try_evict(gl);
1041+
1042+
if (verify_delete) {
1043+
u64 no_addr = gl->gl_name.ln_number;
1044+
struct inode *inode;
10591045

1060-
if (test_and_clear_bit(GLF_VERIFY_EVICT, &gl->gl_flags)) {
10611046
inode = gfs2_lookup_by_inum(sdp, no_addr, gl->gl_no_formal_ino,
10621047
GFS2_BLKST_UNLINKED);
10631048
if (IS_ERR(inode)) {
10641049
if (PTR_ERR(inode) == -EAGAIN &&
10651050
!test_bit(SDF_KILL, &sdp->sd_flags) &&
1066-
gfs2_queue_verify_evict(gl))
1051+
gfs2_queue_verify_delete(gl, true))
10671052
return;
10681053
} else {
10691054
d_prune_aliases(inode);
10701055
iput(inode);
10711056
}
10721057
}
10731058

1074-
out:
10751059
gfs2_glock_put(gl);
10761060
}
10771061

@@ -1100,7 +1084,7 @@ static void glock_work_func(struct work_struct *work)
11001084

11011085
if (!delay) {
11021086
clear_bit(GLF_PENDING_DEMOTE, &gl->gl_flags);
1103-
gfs2_set_demote(gl);
1087+
gfs2_set_demote(GLF_DEMOTE, gl);
11041088
}
11051089
}
11061090
run_queue(gl, 0);
@@ -1442,10 +1426,7 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs)
14421426
static void request_demote(struct gfs2_glock *gl, unsigned int state,
14431427
unsigned long delay, bool remote)
14441428
{
1445-
if (delay)
1446-
set_bit(GLF_PENDING_DEMOTE, &gl->gl_flags);
1447-
else
1448-
gfs2_set_demote(gl);
1429+
gfs2_set_demote(delay ? GLF_PENDING_DEMOTE : GLF_DEMOTE, gl);
14491430
if (gl->gl_demote_state == LM_ST_EXCLUSIVE) {
14501431
gl->gl_demote_state = state;
14511432
gl->gl_demote_time = jiffies;
@@ -1635,12 +1616,6 @@ int gfs2_glock_poll(struct gfs2_holder *gh)
16351616
return test_bit(HIF_WAIT, &gh->gh_iflags) ? 0 : 1;
16361617
}
16371618

1638-
static inline bool needs_demote(struct gfs2_glock *gl)
1639-
{
1640-
return (test_bit(GLF_DEMOTE, &gl->gl_flags) ||
1641-
test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags));
1642-
}
1643-
16441619
static void __gfs2_glock_dq(struct gfs2_holder *gh)
16451620
{
16461621
struct gfs2_glock *gl = gh->gh_gl;
@@ -1649,8 +1624,8 @@ static void __gfs2_glock_dq(struct gfs2_holder *gh)
16491624

16501625
/*
16511626
* This holder should not be cached, so mark it for demote.
1652-
* Note: this should be done before the check for needs_demote
1653-
* below.
1627+
* Note: this should be done before the glock_needs_demote
1628+
* check below.
16541629
*/
16551630
if (gh->gh_flags & GL_NOCACHE)
16561631
request_demote(gl, LM_ST_UNLOCKED, 0, false);
@@ -1663,7 +1638,7 @@ static void __gfs2_glock_dq(struct gfs2_holder *gh)
16631638
* If there hasn't been a demote request we are done.
16641639
* (Let the remaining holders, if any, keep holding it.)
16651640
*/
1666-
if (!needs_demote(gl)) {
1641+
if (!glock_needs_demote(gl)) {
16671642
if (list_empty(&gl->gl_holders))
16681643
fast_path = 1;
16691644
}
@@ -2117,7 +2092,7 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
21172092
void gfs2_cancel_delete_work(struct gfs2_glock *gl)
21182093
{
21192094
clear_bit(GLF_TRY_TO_EVICT, &gl->gl_flags);
2120-
clear_bit(GLF_VERIFY_EVICT, &gl->gl_flags);
2095+
clear_bit(GLF_VERIFY_DELETE, &gl->gl_flags);
21212096
if (cancel_delayed_work(&gl->gl_delete))
21222097
gfs2_glock_put(gl);
21232098
}
@@ -2370,7 +2345,7 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
23702345
*p++ = 'N';
23712346
if (test_bit(GLF_TRY_TO_EVICT, gflags))
23722347
*p++ = 'e';
2373-
if (test_bit(GLF_VERIFY_EVICT, gflags))
2348+
if (test_bit(GLF_VERIFY_DELETE, gflags))
23742349
*p++ = 'E';
23752350
*p = 0;
23762351
return buf;

fs/gfs2/glock.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ static inline int gfs2_glock_nq_init(struct gfs2_glock *gl,
245245
void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state);
246246
void gfs2_glock_complete(struct gfs2_glock *gl, int ret);
247247
bool gfs2_queue_try_to_evict(struct gfs2_glock *gl);
248+
bool gfs2_queue_verify_delete(struct gfs2_glock *gl, bool later);
248249
void gfs2_cancel_delete_work(struct gfs2_glock *gl);
249250
void gfs2_flush_delete_work(struct gfs2_sbd *sdp);
250251
void gfs2_gl_hash_clear(struct gfs2_sbd *sdp);
@@ -284,4 +285,10 @@ static inline bool gfs2_holder_queued(struct gfs2_holder *gh)
284285
void gfs2_inode_remember_delete(struct gfs2_glock *gl, u64 generation);
285286
bool gfs2_inode_already_deleted(struct gfs2_glock *gl, u64 generation);
286287

288+
static inline bool glock_needs_demote(struct gfs2_glock *gl)
289+
{
290+
return (test_bit(GLF_DEMOTE, &gl->gl_flags) ||
291+
test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags));
292+
}
293+
287294
#endif /* __GLOCK_DOT_H__ */

fs/gfs2/glops.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
470470
* Returns: errno
471471
*/
472472

473-
int gfs2_inode_refresh(struct gfs2_inode *ip)
473+
static int gfs2_inode_refresh(struct gfs2_inode *ip)
474474
{
475475
struct buffer_head *dibh;
476476
int error;
@@ -494,11 +494,18 @@ int gfs2_inode_refresh(struct gfs2_inode *ip)
494494
static int inode_go_instantiate(struct gfs2_glock *gl)
495495
{
496496
struct gfs2_inode *ip = gl->gl_object;
497+
struct gfs2_glock *io_gl;
498+
int error;
497499

498500
if (!ip) /* no inode to populate - read it in later */
499501
return 0;
500502

501-
return gfs2_inode_refresh(ip);
503+
error = gfs2_inode_refresh(ip);
504+
if (error)
505+
return error;
506+
io_gl = ip->i_iopen_gh.gh_gl;
507+
io_gl->gl_no_formal_ino = ip->i_no_formal_ino;
508+
return 0;
502509
}
503510

504511
static int inode_go_held(struct gfs2_holder *gh)

fs/gfs2/incore.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ enum {
329329
GLF_BLOCKING = 15,
330330
GLF_UNLOCKED = 16, /* Wait for glock to be unlocked */
331331
GLF_TRY_TO_EVICT = 17, /* iopen glocks only */
332-
GLF_VERIFY_EVICT = 18, /* iopen glocks only */
332+
GLF_VERIFY_DELETE = 18, /* iopen glocks only */
333333
};
334334

335335
struct gfs2_glock {
@@ -376,7 +376,7 @@ enum {
376376
GIF_SW_PAGED = 3,
377377
GIF_FREE_VFS_INODE = 5,
378378
GIF_GLOP_PENDING = 6,
379-
GIF_DEFERRED_DELETE = 7,
379+
GIF_DEFER_DELETE = 7,
380380
};
381381

382382
struct gfs2_inode {

fs/gfs2/inode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
750750
if (error)
751751
goto fail_free_inode;
752752
gfs2_cancel_delete_work(io_gl);
753+
io_gl->gl_no_formal_ino = ip->i_no_formal_ino;
753754

754755
retry:
755756
error = insert_inode_locked4(inode, ip->i_no_addr, iget_test, &ip->i_no_addr);

fs/gfs2/inode.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ struct inode *gfs2_lookup_by_inum(struct gfs2_sbd *sdp, u64 no_addr,
9393
u64 no_formal_ino,
9494
unsigned int blktype);
9595

96-
int gfs2_inode_refresh(struct gfs2_inode *ip);
97-
9896
struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
9997
int is_root);
10098
int gfs2_permission(struct mnt_idmap *idmap,

fs/gfs2/lock_dlm.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,21 @@ static int make_mode(struct gfs2_sbd *sdp, const unsigned int lmstate)
224224
return -1;
225225
}
226226

227+
/* Taken from fs/dlm/lock.c. */
228+
229+
static bool middle_conversion(int cur, int req)
230+
{
231+
return (cur == DLM_LOCK_PR && req == DLM_LOCK_CW) ||
232+
(cur == DLM_LOCK_CW && req == DLM_LOCK_PR);
233+
}
234+
235+
static bool down_conversion(int cur, int req)
236+
{
237+
return !middle_conversion(cur, req) && req < cur;
238+
}
239+
227240
static u32 make_flags(struct gfs2_glock *gl, const unsigned int gfs_flags,
228-
const int req)
241+
const int cur, const int req)
229242
{
230243
u32 lkf = 0;
231244

@@ -251,7 +264,14 @@ static u32 make_flags(struct gfs2_glock *gl, const unsigned int gfs_flags,
251264

252265
if (!test_bit(GLF_INITIAL, &gl->gl_flags)) {
253266
lkf |= DLM_LKF_CONVERT;
254-
if (test_bit(GLF_BLOCKING, &gl->gl_flags))
267+
268+
/*
269+
* The DLM_LKF_QUECVT flag needs to be set for "first come,
270+
* first served" semantics, but it must only be set for
271+
* "upward" lock conversions or else DLM will reject the
272+
* request as invalid.
273+
*/
274+
if (!down_conversion(cur, req))
255275
lkf |= DLM_LKF_QUECVT;
256276
}
257277

@@ -271,13 +291,14 @@ static int gdlm_lock(struct gfs2_glock *gl, unsigned int req_state,
271291
unsigned int flags)
272292
{
273293
struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct;
274-
int req;
294+
int cur, req;
275295
u32 lkf;
276296
char strname[GDLM_STRNAME_BYTES] = "";
277297
int error;
278298

299+
cur = make_mode(gl->gl_name.ln_sbd, gl->gl_state);
279300
req = make_mode(gl->gl_name.ln_sbd, req_state);
280-
lkf = make_flags(gl, flags, req);
301+
lkf = make_flags(gl, flags, cur, req);
281302
gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT);
282303
gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT);
283304
if (test_bit(GLF_INITIAL, &gl->gl_flags)) {

0 commit comments

Comments
 (0)