|
Tomas Bzatek |
cef1f1 |
From a2b8e52e46cfd888ac5a48d8ce632bd70a5caa93 Mon Sep 17 00:00:00 2001
|
|
Tomas Bzatek |
cef1f1 |
From: Tomas Bzatek <tbzatek@redhat.com>
|
|
Tomas Bzatek |
cef1f1 |
Date: Tue, 10 Oct 2023 18:16:24 +0200
|
|
Tomas Bzatek |
cef1f1 |
Subject: [PATCH] util: Introduce alloc helper with alignment support
|
|
Tomas Bzatek |
cef1f1 |
|
|
Tomas Bzatek |
cef1f1 |
Similar to nvme-cli an alloc helper is needed for a couple
|
|
Tomas Bzatek |
cef1f1 |
of ioctls sent out during tree scan.
|
|
Tomas Bzatek |
cef1f1 |
|
|
Tomas Bzatek |
cef1f1 |
Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
|
|
Tomas Bzatek |
cef1f1 |
---
|
|
Tomas Bzatek |
cef1f1 |
src/nvme/private.h | 2 ++
|
|
Tomas Bzatek |
cef1f1 |
src/nvme/util.c | 13 +++++++++++++
|
|
Tomas Bzatek |
cef1f1 |
2 files changed, 15 insertions(+)
|
|
Tomas Bzatek |
cef1f1 |
|
|
Tomas Bzatek |
cef1f1 |
diff --git a/src/nvme/private.h b/src/nvme/private.h
|
|
Tomas Bzatek |
cef1f1 |
index 6fb9784a..ee9d738b 100644
|
|
Tomas Bzatek |
cef1f1 |
--- a/src/nvme/private.h
|
|
Tomas Bzatek |
cef1f1 |
+++ b/src/nvme/private.h
|
|
Tomas Bzatek |
cef1f1 |
@@ -182,6 +182,8 @@ nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
|
|
Tomas Bzatek |
cef1f1 |
const char *host_iface, const char *trsvcid,
|
|
Tomas Bzatek |
cef1f1 |
const char *subsysnqn, nvme_ctrl_t p);
|
|
Tomas Bzatek |
cef1f1 |
|
|
Tomas Bzatek |
cef1f1 |
+void *__nvme_alloc(size_t len);
|
|
Tomas Bzatek |
cef1f1 |
+
|
|
Tomas Bzatek |
cef1f1 |
#if (LOG_FUNCNAME == 1)
|
|
Tomas Bzatek |
cef1f1 |
#define __nvme_log_func __func__
|
|
Tomas Bzatek |
cef1f1 |
#else
|
|
Tomas Bzatek |
cef1f1 |
diff --git a/src/nvme/util.c b/src/nvme/util.c
|
|
Tomas Bzatek |
cef1f1 |
index 8fe094d5..20679685 100644
|
|
Tomas Bzatek |
cef1f1 |
--- a/src/nvme/util.c
|
|
Tomas Bzatek |
cef1f1 |
+++ b/src/nvme/util.c
|
|
Tomas Bzatek |
cef1f1 |
@@ -7,6 +7,7 @@
|
|
Tomas Bzatek |
cef1f1 |
* Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
|
|
Tomas Bzatek |
cef1f1 |
*/
|
|
Tomas Bzatek |
cef1f1 |
|
|
Tomas Bzatek |
cef1f1 |
+#include <stdlib.h>
|
|
Tomas Bzatek |
cef1f1 |
#include <stdio.h>
|
|
Tomas Bzatek |
cef1f1 |
#include <stdbool.h>
|
|
Tomas Bzatek |
cef1f1 |
#include <string.h>
|
|
Tomas Bzatek |
cef1f1 |
@@ -1058,3 +1059,15 @@ bool nvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, const cha
|
|
Tomas Bzatek |
cef1f1 |
}
|
|
Tomas Bzatek |
cef1f1 |
|
|
Tomas Bzatek |
cef1f1 |
#endif /* HAVE_NETDB */
|
|
Tomas Bzatek |
cef1f1 |
+
|
|
Tomas Bzatek |
cef1f1 |
+void *__nvme_alloc(size_t len)
|
|
Tomas Bzatek |
cef1f1 |
+{
|
|
Tomas Bzatek |
cef1f1 |
+ size_t _len = round_up(len, 0x1000);
|
|
Tomas Bzatek |
cef1f1 |
+ void *p;
|
|
Tomas Bzatek |
cef1f1 |
+
|
|
Tomas Bzatek |
cef1f1 |
+ if (posix_memalign((void *)&p, getpagesize(), _len))
|
|
Tomas Bzatek |
cef1f1 |
+ return NULL;
|
|
Tomas Bzatek |
cef1f1 |
+
|
|
Tomas Bzatek |
cef1f1 |
+ memset(p, 0, _len);
|
|
Tomas Bzatek |
cef1f1 |
+ return p;
|
|
Tomas Bzatek |
cef1f1 |
+}
|