Re: [PATCH 4.19 114/131] ocfs2: avoid inode removal while nfsd is accessing it
On 7/2/20 3:24 PM, Linus Torvalds wrote: On Thu, Jul 2, 2020 at 2:17 PM Pavel Machek wrote: commit 4cd9973f9ff69e37dd0ba2bd6e6423f8179c329a upstream. Patch series "ocfs2: fix nfsd over ocfs2 issues", v2. This causes locking imbalance: This sems to be true upstream too. When ocfs2_nfs_sync_lock() returns error, caller can not know if the lock was taken or not. Right you are. And your patch looks sane: diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c index c141b06811a6..8149fb6f1f0d 100644 --- a/fs/ocfs2/dlmglue.c +++ b/fs/ocfs2/dlmglue.c @@ -2867,9 +2867,15 @@ int ocfs2_nfs_sync_lock(struct ocfs2_super *osb, int ex) status = ocfs2_cluster_lock(osb, lockres, ex ? LKM_EXMODE : LKM_PRMODE, 0, 0); - if (status < 0) + if (status < 0) { mlog(ML_ERROR, "lock on nfs sync lock failed %d\n", status); + if (ex) + up_write(&osb->nfs_sync_rwlock); + else + up_read(&osb->nfs_sync_rwlock); + } + return status; } although the whole thing looks messy. If the issue is a lifetime thing (like that commit says), the proper model isn't a lock, but a refcount. Oh well. Junxiao? There is a block number embedded in nfs file handle, to verify it's an inode, need acquire this nfs_sync_lock global lock to avoid any inode removed from local node and other nodes in the cluster, before this verify done, seemed no way to use a refcount. Thanks, Junxiao. Linus
Re: [PATCH 4.19 114/131] ocfs2: avoid inode removal while nfsd is accessing it
On Thu, Jul 2, 2020 at 2:17 PM Pavel Machek wrote: > > > > commit 4cd9973f9ff69e37dd0ba2bd6e6423f8179c329a upstream. > > > > Patch series "ocfs2: fix nfsd over ocfs2 issues", v2. > > This causes locking imbalance: This sems to be true upstream too. > When ocfs2_nfs_sync_lock() returns error, caller can not know if the > lock was taken or not. Right you are. And your patch looks sane: > diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c > index c141b06811a6..8149fb6f1f0d 100644 > --- a/fs/ocfs2/dlmglue.c > +++ b/fs/ocfs2/dlmglue.c > @@ -2867,9 +2867,15 @@ int ocfs2_nfs_sync_lock(struct ocfs2_super *osb, int > ex) > > status = ocfs2_cluster_lock(osb, lockres, ex ? LKM_EXMODE : > LKM_PRMODE, > 0, 0); > - if (status < 0) > + if (status < 0) { > mlog(ML_ERROR, "lock on nfs sync lock failed %d\n", status); > > + if (ex) > + up_write(&osb->nfs_sync_rwlock); > + else > + up_read(&osb->nfs_sync_rwlock); > + } > + > return status; > } although the whole thing looks messy. If the issue is a lifetime thing (like that commit says), the proper model isn't a lock, but a refcount. Oh well. Junxiao? Linus
Re: [PATCH 4.19 114/131] ocfs2: avoid inode removal while nfsd is accessing it
Hi! > commit 4cd9973f9ff69e37dd0ba2bd6e6423f8179c329a upstream. > > Patch series "ocfs2: fix nfsd over ocfs2 issues", v2. > > This is a series of patches to fix issues on nfsd over ocfs2. patch 1 > is to avoid inode removed while nfsd access it patch 2 & 3 is to fix a > panic issue. > > This patch (of 4): > > When nfsd is getting file dentry using handle or parent dentry of some > dentry, one cluster lock is used to avoid inode removed from other node, > but it still could be removed from local node, so use a rw lock to avoid > this. This causes locking imbalance: > @@ -2851,6 +2857,11 @@ int ocfs2_nfs_sync_lock(struct ocfs2_super *osb, int > ex) > if (ocfs2_is_hard_readonly(osb)) > return -EROFS; > > + if (ex) > + down_write(&osb->nfs_sync_rwlock); > + else > + down_read(&osb->nfs_sync_rwlock); > + > if (ocfs2_mount_local(osb)) > return 0; > ... status = ocfs2_cluster_lock(osb, lockres, ex ? LKM_EXMODE :LKM_PRMODE, 0, 0); ... return status; } When ocfs2_nfs_sync_lock() returns error, caller can not know if the lock was taken or not. ocfs2_get_dentry() for example will not call ocfs2_nfs_sync_unlock() if sync_lock() failed, resulting in lock imbalance if ocfs2_cluster_lock() fails. (Totally untested). Signed-off-by: Pavel Machek (CIP) Best regards, Pavel diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c index c141b06811a6..8149fb6f1f0d 100644 --- a/fs/ocfs2/dlmglue.c +++ b/fs/ocfs2/dlmglue.c @@ -2867,9 +2867,15 @@ int ocfs2_nfs_sync_lock(struct ocfs2_super *osb, int ex) status = ocfs2_cluster_lock(osb, lockres, ex ? LKM_EXMODE : LKM_PRMODE, 0, 0); - if (status < 0) + if (status < 0) { mlog(ML_ERROR, "lock on nfs sync lock failed %d\n", status); + if (ex) + up_write(&osb->nfs_sync_rwlock); + else + up_read(&osb->nfs_sync_rwlock); + } + return status; } Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html signature.asc Description: Digital signature
[PATCH 4.19 114/131] ocfs2: avoid inode removal while nfsd is accessing it
From: Junxiao Bi commit 4cd9973f9ff69e37dd0ba2bd6e6423f8179c329a upstream. Patch series "ocfs2: fix nfsd over ocfs2 issues", v2. This is a series of patches to fix issues on nfsd over ocfs2. patch 1 is to avoid inode removed while nfsd access it patch 2 & 3 is to fix a panic issue. This patch (of 4): When nfsd is getting file dentry using handle or parent dentry of some dentry, one cluster lock is used to avoid inode removed from other node, but it still could be removed from local node, so use a rw lock to avoid this. Link: http://lkml.kernel.org/r/20200616183829.87211-1-junxiao...@oracle.com Link: http://lkml.kernel.org/r/20200616183829.87211-2-junxiao...@oracle.com Signed-off-by: Junxiao Bi Reviewed-by: Joseph Qi Cc: Changwei Ge Cc: Gang He Cc: Joel Becker Cc: Jun Piao Cc: Mark Fasheh Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/dlmglue.c | 17 - fs/ocfs2/ocfs2.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c index 178cb9e6772ac..c141b06811a6c 100644 --- a/fs/ocfs2/dlmglue.c +++ b/fs/ocfs2/dlmglue.c @@ -682,6 +682,12 @@ static void ocfs2_nfs_sync_lock_res_init(struct ocfs2_lock_res *res, &ocfs2_nfs_sync_lops, osb); } +static void ocfs2_nfs_sync_lock_init(struct ocfs2_super *osb) +{ + ocfs2_nfs_sync_lock_res_init(&osb->osb_nfs_sync_lockres, osb); + init_rwsem(&osb->nfs_sync_rwlock); +} + void ocfs2_trim_fs_lock_res_init(struct ocfs2_super *osb) { struct ocfs2_lock_res *lockres = &osb->osb_trim_fs_lockres; @@ -2851,6 +2857,11 @@ int ocfs2_nfs_sync_lock(struct ocfs2_super *osb, int ex) if (ocfs2_is_hard_readonly(osb)) return -EROFS; + if (ex) + down_write(&osb->nfs_sync_rwlock); + else + down_read(&osb->nfs_sync_rwlock); + if (ocfs2_mount_local(osb)) return 0; @@ -2869,6 +2880,10 @@ void ocfs2_nfs_sync_unlock(struct ocfs2_super *osb, int ex) if (!ocfs2_mount_local(osb)) ocfs2_cluster_unlock(osb, lockres, ex ? LKM_EXMODE : LKM_PRMODE); + if (ex) + up_write(&osb->nfs_sync_rwlock); + else + up_read(&osb->nfs_sync_rwlock); } int ocfs2_trim_fs_lock(struct ocfs2_super *osb, @@ -3314,7 +3329,7 @@ int ocfs2_dlm_init(struct ocfs2_super *osb) local: ocfs2_super_lock_res_init(&osb->osb_super_lockres, osb); ocfs2_rename_lock_res_init(&osb->osb_rename_lockres, osb); - ocfs2_nfs_sync_lock_res_init(&osb->osb_nfs_sync_lockres, osb); + ocfs2_nfs_sync_lock_init(osb); ocfs2_orphan_scan_lock_res_init(&osb->osb_orphan_scan.os_lockres, osb); osb->cconn = conn; diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h index 4f86ac0027b5b..2319336183005 100644 --- a/fs/ocfs2/ocfs2.h +++ b/fs/ocfs2/ocfs2.h @@ -406,6 +406,7 @@ struct ocfs2_super struct ocfs2_lock_res osb_super_lockres; struct ocfs2_lock_res osb_rename_lockres; struct ocfs2_lock_res osb_nfs_sync_lockres; + struct rw_semaphore nfs_sync_rwlock; struct ocfs2_lock_res osb_trim_fs_lockres; struct ocfs2_dlm_debug *osb_dlm_debug; -- 2.25.1