diff mbox series

[38/41] lnet: libcfs: use wait_event_timeout() in tracefiled().

Message ID 1617583870-32029-39-git-send-email-jsimmons@infradead.org (mailing list archive)
State New, archived
Headers show
Series lustre: sync to OpenSFS branch as of March 1 | expand

Commit Message

James Simmons April 5, 2021, 12:51 a.m. UTC
From: Mr NeilBrown <neilb@suse.de>

By using wait_event_timeout() we can make it more clear what is being
waited for, and when the loop terminates.

WC-bug-id: https://jira.whamcloud.com/browse/LU-9859
Lustre-commit: 0269ac4a0069b0e4 ("LU-9859 libcfs: use wait_event_timeout() in tracefiled().")
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Reviewed-on: https://review.whamcloud.com/39293
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 net/lnet/libcfs/tracefile.c | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/net/lnet/libcfs/tracefile.c b/net/lnet/libcfs/tracefile.c
index 14fcb2a..4e1900d 100644
--- a/net/lnet/libcfs/tracefile.c
+++ b/net/lnet/libcfs/tracefile.c
@@ -1085,13 +1085,18 @@  static int tracefiled(void *arg)
 
 	complete(&tctl->tctl_start);
 
-	while (1) {
-		wait_queue_entry_t __wait;
-
-		pc.pc_want_daemon_pages = 0;
-		collect_pages(&pc);
+	pc.pc_want_daemon_pages = 0;
+
+	while (!last_loop) {
+		wait_event_timeout(tctl->tctl_waitq,
+				   ({ collect_pages(&pc);
+				     !list_empty(&pc.pc_pages); }) ||
+				   atomic_read(&tctl->tctl_shutdown),
+				   HZ);
+		if (atomic_read(&tctl->tctl_shutdown))
+			last_loop = 1;
 		if (list_empty(&pc.pc_pages))
-			goto end_loop;
+			continue;
 
 		filp = NULL;
 		down_read(&cfs_tracefile_sem);
@@ -1110,18 +1115,19 @@  static int tracefiled(void *arg)
 		if (!filp) {
 			put_pages_on_daemon_list(&pc);
 			__LASSERT(list_empty(&pc.pc_pages));
-			goto end_loop;
+			continue;
 		}
 
 		list_for_each_entry_safe(tage, tmp, &pc.pc_pages, linkage) {
+			struct dentry *de = file_dentry(filp);
 			static loff_t f_pos;
 
 			__LASSERT_TAGE_INVARIANT(tage);
 
 			if (f_pos >= (off_t)cfs_tracefile_size)
 				f_pos = 0;
-			else if (f_pos > i_size_read(file_inode(filp)))
-				f_pos = i_size_read(file_inode(filp));
+			else if (f_pos > i_size_read(de->d_inode))
+				f_pos = i_size_read(de->d_inode);
 
 			buf = kmap(tage->page);
 			rc = kernel_write(filp, buf, tage->used, &f_pos);
@@ -1158,19 +1164,6 @@  static int tracefiled(void *arg)
 			pr_err("Lustre: There are %d pages unwritten\n", i);
 		}
 		__LASSERT(list_empty(&pc.pc_pages));
-end_loop:
-		if (atomic_read(&tctl->tctl_shutdown)) {
-			if (!last_loop) {
-				last_loop = 1;
-				continue;
-			} else {
-				break;
-			}
-		}
-		init_wait(&__wait);
-		add_wait_queue(&tctl->tctl_waitq, &__wait);
-		schedule_timeout_interruptible(HZ);
-		remove_wait_queue(&tctl->tctl_waitq, &__wait);
 	}
 	complete(&tctl->tctl_stop);
 	return 0;