Skip to contentSkip to conversation

mds: update dentry lease for async create

PATCH In review Yan, Zheng 2 participants 5 messages Mar 4, 2020 Ceph client

lore
Share & tools
lore

Yan, Zheng

author
#0 lore raw

PATCH 1/1 mds: update dentry lease for async create

Otherwise ceph_d_delete() may return 1 for the dentry, which makes dput() prune the dentry and clear parent dir's complete flag.

---
 fs/ceph/file.c | 3 +++
 1 file changed, 3 insertions(+)
fs/ceph/file.c +3 -0
index 53321bf517c2..671b141aedfe 100644
@@ -480,6 +480,9 @@ static int try_prep_async_create(struct inode *dir, struct dentry *dentry,
 	if (d_in_lookup(dentry)) {
 		if (!__ceph_dir_is_complete(ci))
 			goto no_async;
+		spin_lock(&dentry->d_lock);
+		di->lease_shared_gen = atomic_read(&ci->i_shared_gen);
+		spin_unlock(&dentry->d_lock);
 	} else if (atomic_read(&ci->i_shared_gen) !=
 		   READ_ONCE(di->lease_shared_gen)) {
 		goto no_async;
Signature · 1 line
2.21.1
#1 lore raw
Quoted 13 lines · Zheng

Otherwise ceph_d_delete() may return 1 for the dentry, which makes dput() prune the dentry and clear parent dir's complete flag.

---
 fs/ceph/file.c | 3 +++
 1 file changed, 3 insertions(+)
fs/ceph/file.c +0 -0
index 53321bf517c2..671b141aedfe 100644

fs/ceph/file.c static int try_prep_async_create(struct inode *dir, struct dentry *dentry, · line 488

Quoted 9 lines
fs/ceph/file.c +3 -0
@@ -480,6 +480,9 @@ static int try_prep_async_create(struct inode *dir, struct dentry *dentry,
 	if (d_in_lookup(dentry)) {
 		if (!__ceph_dir_is_complete(ci))
 			goto no_async;
+		spin_lock(&dentry->d_lock);
+		di->lease_shared_gen = atomic_read(&ci->i_shared_gen);
+		spin_unlock(&dentry->d_lock);
 	} else if (atomic_read(&ci->i_shared_gen) !=
 		   READ_ONCE(di->lease_shared_gen)) {
 		goto no_async;

Good catch, merged into testing (with small update to changelog s/mds:/ceph:/)

Thanks!

Signature · 1 line
Jeff Layton <[email protected]>
#2 lore raw
Quoted 18 lines · Jeff Layton
Quoted 17 lines · Zheng

Otherwise ceph_d_delete() may return 1 for the dentry, which makes dput() prune the dentry and clear parent dir's complete flag.

---
 fs/ceph/file.c | 3 +++
 1 file changed, 3 insertions(+)
fs/ceph/file.c +1 -0
index 53321bf517c2..671b141aedfe 100644
@@ -480,6 +480,9 @@ static int try_prep_async_create(struct inode *dir, struct dentry *dentry,
 	if (d_in_lookup(dentry)) {
 		if (!__ceph_dir_is_complete(ci))
 			goto no_async;
+		spin_lock(&dentry->d_lock);
Quoted 9 lines

fs/ceph/file.c static int try_prep_async_create(struct inode *dir, struct dentry *dentry, · line 488

Quoted 5 lines
fs/ceph/file.c +2 -0
+		di->lease_shared_gen = atomic_read(&ci->i_shared_gen);
+		spin_unlock(&dentry->d_lock);
 	} else if (atomic_read(&ci->i_shared_gen) !=
 		   READ_ONCE(di->lease_shared_gen)) {
 		goto no_async;

Good catch, merged into testing (with small update to changelog s/mds:/ceph:/)

One related comment though. This patch implies that lease_shared_gen is protected by the d_lock, but it's not held when it's assigned in ceph_lookup. Should it be?

Signature · 1 line
Jeff Layton <[email protected]>
author
#3 lore raw
Quoted 29 lines · Jeff Layton
Quoted 18 lines · Jeff Layton
Quoted 17 lines · Zheng

Otherwise ceph_d_delete() may return 1 for the dentry, which makes dput() prune the dentry and clear parent dir's complete flag.

---
  fs/ceph/file.c | 3 +++
  1 file changed, 3 insertions(+)
fs/ceph/file.c +1 -0
index 53321bf517c2..671b141aedfe 100644
@@ -480,6 +480,9 @@ static int try_prep_async_create(struct inode *dir, struct dentry *dentry,
  	if (d_in_lookup(dentry)) {
  		if (!__ceph_dir_is_complete(ci))
  			goto no_async;
+		spin_lock(&dentry->d_lock);
Quoted 9 lines

fs/ceph/file.c static int try_prep_async_create(struct inode *dir, struct dentry *dentry, · line 488

Quoted 5 lines
fs/ceph/file.c +2 -0
+		di->lease_shared_gen = atomic_read(&ci->i_shared_gen);
+		spin_unlock(&dentry->d_lock);
  	} else if (atomic_read(&ci->i_shared_gen) !=
  		   READ_ONCE(di->lease_shared_gen)) {
  		goto no_async;

Good catch, merged into testing (with small update to changelog s/mds:/ceph:/)

Quoted 4 lines

One related comment though. This patch implies that lease_shared_gen is protected by the d_lock, but it's not held when it's assigned in ceph_lookup. Should it be?

we only assign and compare lease_shared_gen, I think it doesn't matter if it's protected by d_lock or not

#4 lore raw
Quoted 30 lines · Zheng
Quoted 29 lines · Jeff Layton
Quoted 27 lines · Jeff Layton
Quoted 13 lines · Zheng

Otherwise ceph_d_delete() may return 1 for the dentry, which makes dput() prune the dentry and clear parent dir's complete flag.

---
  fs/ceph/file.c | 3 +++
  1 file changed, 3 insertions(+)
fs/ceph/file.c +0 -0
index 53321bf517c2..671b141aedfe 100644

fs/ceph/file.c static int try_prep_async_create(struct inode *dir, struct dentry *dentry, · line 488

Quoted 9 lines
fs/ceph/file.c +3 -0
@@ -480,6 +480,9 @@ static int try_prep_async_create(struct inode *dir, struct dentry *dentry,
  	if (d_in_lookup(dentry)) {
  		if (!__ceph_dir_is_complete(ci))
  			goto no_async;
+		spin_lock(&dentry->d_lock);
+		di->lease_shared_gen = atomic_read(&ci->i_shared_gen);
+		spin_unlock(&dentry->d_lock);
  	} else if (atomic_read(&ci->i_shared_gen) !=
  		   READ_ONCE(di->lease_shared_gen)) {
  		goto no_async;

Good catch, merged into testing (with small update to changelog s/mds:/ceph:/)

Quoted 8 lines
Quoted 4 lines

One related comment though. This patch implies that lease_shared_gen is protected by the d_lock, but it's not held when it's assigned in ceph_lookup. Should it be?

we only assign and compare lease_shared_gen, I think it doesn't matter if it's protected by d_lock or not

That's the case here too. Do we need the d_lock in try_prep_async_create? Maybe lease_shared_gen should also be an atomic_t?

Signature · 1 line
Jeff Layton <[email protected]>