diff mbox series

[v2,35/49] libmultipath: add dmp_errstr() helper

Message ID 20240712171458.77611-36-mwilck@suse.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series multipath-tools: devmapper API refactored | expand

Commit Message

Martin Wilck July 12, 2024, 5:14 p.m. UTC
Signed-off-by: Martin Wilck <mwilck@suse.com>
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 libmultipath/devmapper.c | 14 ++++++++++++++
 libmultipath/devmapper.h |  3 +++
 2 files changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 4ad84dd..e51c2f0 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -79,6 +79,20 @@  static void libmp_udev_wait(unsigned int c)
 }
 #endif
 
+const char *dmp_errstr(int rc)
+{
+	static const char *str[] = {
+		[DMP_ERR] = "generic error",
+		[DMP_OK] = "success",
+		[DMP_NOT_FOUND] = "not found",
+		[DMP_NO_MATCH] = "target type mismatch",
+		[__DMP_LAST__] = "**invalid**",
+	};
+	if (rc < 0 || rc > __DMP_LAST__)
+		rc = __DMP_LAST__;
+	return str[rc];
+}
+
 int libmp_dm_task_run(struct dm_task *dmt)
 {
 	int r;
diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h
index a10821f..7231a98 100644
--- a/libmultipath/devmapper.h
+++ b/libmultipath/devmapper.h
@@ -34,8 +34,11 @@  enum {
 	DMP_OK,
 	DMP_NOT_FOUND,
 	DMP_NO_MATCH,
+	__DMP_LAST__,
 };
 
+const char* dmp_errstr(int rc);
+
 /**
  * enum mapinfo_flags: input flags for libmp_mapinfo()
  */