diff mbox series

[05/27] lustre: llite: default lsm update may memory leak

Message ID 1623625897-17706-6-git-send-email-jsimmons@infradead.org (mailing list archive)
State New, archived
Headers show
Series lustre: sync to 2.14.52 | expand

Commit Message

James Simmons June 13, 2021, 11:11 p.m. UTC
From: Lai Siyao <lai.siyao@whamcloud.com>

ll_update_default_lsm_md() should check whether lli_default_lsm_md
is set before setting it to the data from lustre_md, and if it's set,
release the old data to avoid memory leak

WC-bug-id: https://jira.whamcloud.com/browse/LU-14004
Lustre-commit: cd2ad336177f8f31 ("LU-14004 llite: default lsm update may memory leak")
Signed-off-by: Lai Siyao <lai.siyao@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/40103
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 fs/lustre/llite/llite_lib.c | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/fs/lustre/llite/llite_lib.c b/fs/lustre/llite/llite_lib.c
index 39bdee0..e98972d 100644
--- a/fs/lustre/llite/llite_lib.c
+++ b/fs/lustre/llite/llite_lib.c
@@ -1505,30 +1505,27 @@  static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
 			}
 			up_write(&lli->lli_lsm_sem);
 		}
-	} else if (lli->lli_default_lsm_md) {
-		/* update default lsm if it changes */
+		return;
+	}
+
+	if (lli->lli_default_lsm_md) {
+		/* do nonthing if default lsm isn't changed */
 		down_read(&lli->lli_lsm_sem);
 		if (lli->lli_default_lsm_md &&
-		    !lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
-			up_read(&lli->lli_lsm_sem);
-			down_write(&lli->lli_lsm_sem);
-			if (lli->lli_default_lsm_md)
-				lmv_free_memmd(lli->lli_default_lsm_md);
-			lli->lli_default_lsm_md = md->default_lmv;
-			lsm_md_dump(D_INODE, md->default_lmv);
-			md->default_lmv = NULL;
-			up_write(&lli->lli_lsm_sem);
-		} else {
+		    lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
 			up_read(&lli->lli_lsm_sem);
+			return;
 		}
-	} else {
-		/* init default lsm */
-		down_write(&lli->lli_lsm_sem);
-		lli->lli_default_lsm_md = md->default_lmv;
-		lsm_md_dump(D_INODE, md->default_lmv);
-		md->default_lmv = NULL;
-		up_write(&lli->lli_lsm_sem);
+		up_read(&lli->lli_lsm_sem);
 	}
+
+	down_write(&lli->lli_lsm_sem);
+	if (lli->lli_default_lsm_md)
+		lmv_free_memmd(lli->lli_default_lsm_md);
+	lli->lli_default_lsm_md = md->default_lmv;
+	lsm_md_dump(D_INODE, md->default_lmv);
+	md->default_lmv = NULL;
+	up_write(&lli->lli_lsm_sem);
 }
 
 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)