Skip to content

Commit 300e549

Browse files
committed
Merge branch 'gfs2-iopen' into for-next
2 parents 83d060c + 9e8990d commit 300e549

10 files changed

Lines changed: 295 additions & 38 deletions

File tree

‎fs/gfs2/export.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ static struct dentry *gfs2_get_dentry(struct super_block *sb,
134134
struct gfs2_sbd *sdp = sb->s_fs_info;
135135
struct inode *inode;
136136

137-
inode = gfs2_lookup_by_inum(sdp, inum->no_addr, &inum->no_formal_ino,
137+
if (!inum->no_formal_ino)
138+
return ERR_PTR(-ESTALE);
139+
inode = gfs2_lookup_by_inum(sdp, inum->no_addr, inum->no_formal_ino,
138140
GFS2_BLKST_DINODE);
139141
if (IS_ERR(inode))
140142
return ERR_CAST(inode);

‎fs/gfs2/glock.c‎

Lines changed: 165 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,11 @@ static void gfs2_glock_dealloc(struct rcu_head *rcu)
125125
{
126126
struct gfs2_glock *gl = container_of(rcu, struct gfs2_glock, gl_rcu);
127127

128-
if (gl->gl_ops->go_flags & GLOF_ASPACE) {
128+
kfree(gl->gl_lksb.sb_lvbptr);
129+
if (gl->gl_ops->go_flags & GLOF_ASPACE)
129130
kmem_cache_free(gfs2_glock_aspace_cachep, gl);
130-
} else {
131-
kfree(gl->gl_lksb.sb_lvbptr);
131+
else
132132
kmem_cache_free(gfs2_glock_cachep, gl);
133-
}
134133
}
135134

136135
/**
@@ -465,6 +464,15 @@ static void state_change(struct gfs2_glock *gl, unsigned int new_state)
465464
gl->gl_tchange = jiffies;
466465
}
467466

467+
static void gfs2_set_demote(struct gfs2_glock *gl)
468+
{
469+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
470+
471+
set_bit(GLF_DEMOTE, &gl->gl_flags);
472+
smp_mb();
473+
wake_up(&sdp->sd_async_glock_wait);
474+
}
475+
468476
static void gfs2_demote_wake(struct gfs2_glock *gl)
469477
{
470478
gl->gl_demote_state = LM_ST_EXCLUSIVE;
@@ -757,20 +765,127 @@ __acquires(&gl->gl_lockref.lock)
757765
return;
758766
}
759767

768+
void gfs2_inode_remember_delete(struct gfs2_glock *gl, u64 generation)
769+
{
770+
struct gfs2_inode_lvb *ri = (void *)gl->gl_lksb.sb_lvbptr;
771+
772+
if (ri->ri_magic == 0)
773+
ri->ri_magic = cpu_to_be32(GFS2_MAGIC);
774+
if (ri->ri_magic == cpu_to_be32(GFS2_MAGIC))
775+
ri->ri_generation_deleted = cpu_to_be64(generation);
776+
}
777+
778+
bool gfs2_inode_already_deleted(struct gfs2_glock *gl, u64 generation)
779+
{
780+
struct gfs2_inode_lvb *ri = (void *)gl->gl_lksb.sb_lvbptr;
781+
782+
if (ri->ri_magic != cpu_to_be32(GFS2_MAGIC))
783+
return false;
784+
return generation <= be64_to_cpu(ri->ri_generation_deleted);
785+
}
786+
787+
static void gfs2_glock_poke(struct gfs2_glock *gl)
788+
{
789+
int flags = LM_FLAG_TRY_1CB | LM_FLAG_ANY | GL_SKIP;
790+
struct gfs2_holder gh;
791+
int error;
792+
793+
error = gfs2_glock_nq_init(gl, LM_ST_SHARED, flags, &gh);
794+
if (!error)
795+
gfs2_glock_dq(&gh);
796+
}
797+
798+
static bool gfs2_try_evict(struct gfs2_glock *gl)
799+
{
800+
struct gfs2_inode *ip;
801+
bool evicted = false;
802+
803+
/*
804+
* If there is contention on the iopen glock and we have an inode, try
805+
* to grab and release the inode so that it can be evicted. This will
806+
* allow the remote node to go ahead and delete the inode without us
807+
* having to do it, which will avoid rgrp glock thrashing.
808+
*
809+
* The remote node is likely still holding the corresponding inode
810+
* glock, so it will run before we get to verify that the delete has
811+
* happened below.
812+
*/
813+
spin_lock(&gl->gl_lockref.lock);
814+
ip = gl->gl_object;
815+
if (ip && !igrab(&ip->i_inode))
816+
ip = NULL;
817+
spin_unlock(&gl->gl_lockref.lock);
818+
if (ip) {
819+
struct gfs2_glock *inode_gl = NULL;
820+
821+
gl->gl_no_formal_ino = ip->i_no_formal_ino;
822+
set_bit(GIF_DEFERRED_DELETE, &ip->i_flags);
823+
d_prune_aliases(&ip->i_inode);
824+
iput(&ip->i_inode);
825+
826+
/* If the inode was evicted, gl->gl_object will now be NULL. */
827+
spin_lock(&gl->gl_lockref.lock);
828+
ip = gl->gl_object;
829+
if (ip) {
830+
inode_gl = ip->i_gl;
831+
lockref_get(&inode_gl->gl_lockref);
832+
clear_bit(GIF_DEFERRED_DELETE, &ip->i_flags);
833+
}
834+
spin_unlock(&gl->gl_lockref.lock);
835+
if (inode_gl) {
836+
gfs2_glock_poke(inode_gl);
837+
gfs2_glock_put(inode_gl);
838+
}
839+
evicted = !ip;
840+
}
841+
return evicted;
842+
}
843+
760844
static void delete_work_func(struct work_struct *work)
761845
{
762-
struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_delete);
846+
struct delayed_work *dwork = to_delayed_work(work);
847+
struct gfs2_glock *gl = container_of(dwork, struct gfs2_glock, gl_delete);
763848
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
764849
struct inode *inode;
765850
u64 no_addr = gl->gl_name.ln_number;
766851

852+
spin_lock(&gl->gl_lockref.lock);
853+
clear_bit(GLF_PENDING_DELETE, &gl->gl_flags);
854+
spin_unlock(&gl->gl_lockref.lock);
855+
767856
/* If someone's using this glock to create a new dinode, the block must
768857
have been freed by another node, then re-used, in which case our
769858
iopen callback is too late after the fact. Ignore it. */
770859
if (test_bit(GLF_INODE_CREATING, &gl->gl_flags))
771860
goto out;
772861

773-
inode = gfs2_lookup_by_inum(sdp, no_addr, NULL, GFS2_BLKST_UNLINKED);
862+
if (test_bit(GLF_DEMOTE, &gl->gl_flags)) {
863+
/*
864+
* If we can evict the inode, give the remote node trying to
865+
* delete the inode some time before verifying that the delete
866+
* has happened. Otherwise, if we cause contention on the inode glock
867+
* immediately, the remote node will think that we still have
868+
* the inode in use, and so it will give up waiting.
869+
*
870+
* If we can't evict the inode, signal to the remote node that
871+
* the inode is still in use. We'll later try to delete the
872+
* inode locally in gfs2_evict_inode.
873+
*
874+
* FIXME: We only need to verify that the remote node has
875+
* deleted the inode because nodes before this remote delete
876+
* rework won't cooperate. At a later time, when we no longer
877+
* care about compatibility with such nodes, we can skip this
878+
* step entirely.
879+
*/
880+
if (gfs2_try_evict(gl)) {
881+
if (gfs2_queue_delete_work(gl, 5 * HZ))
882+
return;
883+
}
884+
goto out;
885+
}
886+
887+
inode = gfs2_lookup_by_inum(sdp, no_addr, gl->gl_no_formal_ino,
888+
GFS2_BLKST_UNLINKED);
774889
if (!IS_ERR_OR_NULL(inode)) {
775890
d_prune_aliases(inode);
776891
iput(inode);
@@ -801,7 +916,7 @@ static void glock_work_func(struct work_struct *work)
801916

802917
if (!delay) {
803918
clear_bit(GLF_PENDING_DEMOTE, &gl->gl_flags);
804-
set_bit(GLF_DEMOTE, &gl->gl_flags);
919+
gfs2_set_demote(gl);
805920
}
806921
}
807922
run_queue(gl, 0);
@@ -932,7 +1047,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
9321047
gl->gl_object = NULL;
9331048
gl->gl_hold_time = GL_GLOCK_DFT_HOLD;
9341049
INIT_DELAYED_WORK(&gl->gl_work, glock_work_func);
935-
INIT_WORK(&gl->gl_delete, delete_work_func);
1050+
INIT_DELAYED_WORK(&gl->gl_delete, delete_work_func);
9361051

9371052
mapping = gfs2_glock2aspace(gl);
9381053
if (mapping) {
@@ -1146,9 +1261,10 @@ int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs)
11461261
static void handle_callback(struct gfs2_glock *gl, unsigned int state,
11471262
unsigned long delay, bool remote)
11481263
{
1149-
int bit = delay ? GLF_PENDING_DEMOTE : GLF_DEMOTE;
1150-
1151-
set_bit(bit, &gl->gl_flags);
1264+
if (delay)
1265+
set_bit(GLF_PENDING_DEMOTE, &gl->gl_flags);
1266+
else
1267+
gfs2_set_demote(gl);
11521268
if (gl->gl_demote_state == LM_ST_EXCLUSIVE) {
11531269
gl->gl_demote_state = state;
11541270
gl->gl_demote_time = jiffies;
@@ -1755,6 +1871,44 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
17551871
rhashtable_walk_exit(&iter);
17561872
}
17571873

1874+
bool gfs2_queue_delete_work(struct gfs2_glock *gl, unsigned long delay)
1875+
{
1876+
bool queued;
1877+
1878+
spin_lock(&gl->gl_lockref.lock);
1879+
queued = queue_delayed_work(gfs2_delete_workqueue,
1880+
&gl->gl_delete, delay);
1881+
if (queued)
1882+
set_bit(GLF_PENDING_DELETE, &gl->gl_flags);
1883+
spin_unlock(&gl->gl_lockref.lock);
1884+
return queued;
1885+
}
1886+
1887+
void gfs2_cancel_delete_work(struct gfs2_glock *gl)
1888+
{
1889+
if (cancel_delayed_work_sync(&gl->gl_delete)) {
1890+
clear_bit(GLF_PENDING_DELETE, &gl->gl_flags);
1891+
gfs2_glock_put(gl);
1892+
}
1893+
}
1894+
1895+
bool gfs2_delete_work_queued(const struct gfs2_glock *gl)
1896+
{
1897+
return test_bit(GLF_PENDING_DELETE, &gl->gl_flags);
1898+
}
1899+
1900+
static void flush_delete_work(struct gfs2_glock *gl)
1901+
{
1902+
flush_delayed_work(&gl->gl_delete);
1903+
gfs2_glock_queue_work(gl, 0);
1904+
}
1905+
1906+
void gfs2_flush_delete_work(struct gfs2_sbd *sdp)
1907+
{
1908+
glock_hash_walk(flush_delete_work, sdp);
1909+
flush_workqueue(gfs2_delete_workqueue);
1910+
}
1911+
17581912
/**
17591913
* thaw_glock - thaw out a glock which has an unprocessed reply waiting
17601914
* @gl: The glock to thaw

‎fs/gfs2/glock.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ static inline int gfs2_glock_nq_init(struct gfs2_glock *gl,
244244

245245
extern void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state);
246246
extern void gfs2_glock_complete(struct gfs2_glock *gl, int ret);
247+
extern bool gfs2_queue_delete_work(struct gfs2_glock *gl, unsigned long delay);
248+
extern void gfs2_cancel_delete_work(struct gfs2_glock *gl);
249+
extern bool gfs2_delete_work_queued(const struct gfs2_glock *gl);
250+
extern void gfs2_flush_delete_work(struct gfs2_sbd *sdp);
247251
extern void gfs2_gl_hash_clear(struct gfs2_sbd *sdp);
248252
extern void gfs2_glock_finish_truncate(struct gfs2_inode *ip);
249253
extern void gfs2_glock_thaw(struct gfs2_sbd *sdp);
@@ -315,4 +319,7 @@ static inline void glock_clear_object(struct gfs2_glock *gl, void *object)
315319
spin_unlock(&gl->gl_lockref.lock);
316320
}
317321

322+
extern void gfs2_inode_remember_delete(struct gfs2_glock *gl, u64 generation);
323+
extern bool gfs2_inode_already_deleted(struct gfs2_glock *gl, u64 generation);
324+
318325
#endif /* __GLOCK_DOT_H__ */

‎fs/gfs2/glops.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,17 @@ static void iopen_go_callback(struct gfs2_glock *gl, bool remote)
612612
if (gl->gl_demote_state == LM_ST_UNLOCKED &&
613613
gl->gl_state == LM_ST_SHARED && ip) {
614614
gl->gl_lockref.count++;
615-
if (queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0)
615+
if (!queue_delayed_work(gfs2_delete_workqueue,
616+
&gl->gl_delete, 0))
616617
gl->gl_lockref.count--;
617618
}
618619
}
619620

621+
static int iopen_go_demote_ok(const struct gfs2_glock *gl)
622+
{
623+
return !gfs2_delete_work_queued(gl);
624+
}
625+
620626
/**
621627
* inode_go_free - wake up anyone waiting for dlm's unlock ast to free it
622628
* @gl: glock being freed
@@ -696,7 +702,7 @@ const struct gfs2_glock_operations gfs2_inode_glops = {
696702
.go_lock = inode_go_lock,
697703
.go_dump = inode_go_dump,
698704
.go_type = LM_TYPE_INODE,
699-
.go_flags = GLOF_ASPACE | GLOF_LRU,
705+
.go_flags = GLOF_ASPACE | GLOF_LRU | GLOF_LVB,
700706
.go_free = inode_go_free,
701707
};
702708

@@ -720,6 +726,7 @@ const struct gfs2_glock_operations gfs2_freeze_glops = {
720726
const struct gfs2_glock_operations gfs2_iopen_glops = {
721727
.go_type = LM_TYPE_IOPEN,
722728
.go_callback = iopen_go_callback,
729+
.go_demote_ok = iopen_go_demote_ok,
723730
.go_flags = GLOF_LRU | GLOF_NONDISK,
724731
};
725732

‎fs/gfs2/incore.h‎

Lines changed: 7 additions & 2 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_PENDING_DELETE = 17,
348349
GLF_FREEING = 18, /* Wait for glock to be freed */
349350
};
350351

@@ -378,8 +379,11 @@ struct gfs2_glock {
378379
atomic_t gl_revokes;
379380
struct delayed_work gl_work;
380381
union {
381-
/* For inode and iopen glocks only */
382-
struct work_struct gl_delete;
382+
/* For iopen glocks only */
383+
struct {
384+
struct delayed_work gl_delete;
385+
u64 gl_no_formal_ino;
386+
};
383387
/* For rgrp glocks only */
384388
struct {
385389
loff_t start;
@@ -398,6 +402,7 @@ enum {
398402
GIF_ORDERED = 4,
399403
GIF_FREE_VFS_INODE = 5,
400404
GIF_GLOP_PENDING = 6,
405+
GIF_DEFERRED_DELETE = 7,
401406
};
402407

403408
struct gfs2_inode {

0 commit comments

Comments
 (0)