diff mbox series

[v2,06/13] libmultipath: snprint_foreign_topology(): split out lockless variant

Message ID 20211129200902.21817-7-mwilck@suse.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series multipath-tools: improvements for pretty-printing code | expand

Commit Message

Martin Wilck Nov. 29, 2021, 8:08 p.m. UTC
From: Martin Wilck <mwilck@suse.com>

Factor out the lockless part, which we'll call from elsewhere in a
future patch.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/foreign.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/libmultipath/foreign.c b/libmultipath/foreign.c
index e091a1d..c69c5c3 100644
--- a/libmultipath/foreign.c
+++ b/libmultipath/foreign.c
@@ -498,19 +498,12 @@  void foreign_multipath_layout(void)
 	pthread_cleanup_pop(1);
 }
 
-int snprint_foreign_topology(struct strbuf *buf, int verbosity)
+static int __snprint_foreign_topology(struct strbuf *buf, int verbosity)
 {
 	struct foreign *fgn;
 	int i;
 	size_t initial_len = get_strbuf_len(buf);
 
-	rdlock_foreigns();
-	if (foreigns == NULL) {
-		unlock_foreigns(NULL);
-		return 0;
-	}
-	pthread_cleanup_push(unlock_foreigns, NULL);
-
 	vector_foreach_slot(foreigns, fgn, i) {
 		const struct _vector *vec;
 		const struct gen_multipath *gm;
@@ -531,10 +524,24 @@  int snprint_foreign_topology(struct strbuf *buf, int verbosity)
 		pthread_cleanup_pop(1);
 	}
 
-	pthread_cleanup_pop(1);
 	return get_strbuf_len(buf) - initial_len;
 }
 
+int snprint_foreign_topology(struct strbuf *buf, int verbosity)
+{
+	int rc;
+
+	rdlock_foreigns();
+	if (foreigns == NULL) {
+		unlock_foreigns(NULL);
+		return 0;
+	}
+	pthread_cleanup_push(unlock_foreigns, NULL);
+	rc = __snprint_foreign_topology(buf, verbosity);
+	pthread_cleanup_pop(1);
+	return rc;
+}
+
 void print_foreign_topology(int verbosity)
 {
 	STRBUF_ON_STACK(buf);