]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
util: Introduce alloc helper with alignment support
authorTomas Bzatek <tbzatek@redhat.com>
Tue, 10 Oct 2023 16:16:24 +0000 (18:16 +0200)
committerDaniel Wagner <wagi@monom.org>
Tue, 10 Oct 2023 17:11:06 +0000 (19:11 +0200)
Similar to nvme-cli an alloc helper is needed for a couple
of ioctls sent out during tree scan.

Signed-off-by: Tomas Bzatek <tbzatek@redhat.com>
src/nvme/private.h
src/nvme/util.c

index 6fb9784a696ded02a1e3e8d7101c0dd91e782879..ee9d738bd0af3ff5d896ddb85353ee7d0bd52b9c 100644 (file)
@@ -182,6 +182,8 @@ nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
                               const char *host_iface, const char *trsvcid,
                               const char *subsysnqn, nvme_ctrl_t p);
 
+void *__nvme_alloc(size_t len);
+
 #if (LOG_FUNCNAME == 1)
 #define __nvme_log_func __func__
 #else
index 8fe094d55ef8556b1e88d36148565c5ba952377e..20679685bc8b9794911b08774dc8817a9b832232 100644 (file)
@@ -7,6 +7,7 @@
  *         Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
  */
 
+#include <stdlib.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <string.h>
@@ -1058,3 +1059,15 @@ bool nvme_iface_primary_addr_matches(const struct ifaddrs *iface_list, const cha
 }
 
 #endif /* HAVE_NETDB */
+
+void *__nvme_alloc(size_t len)
+{
+       size_t _len = round_up(len, 0x1000);
+       void *p;
+
+       if (posix_memalign((void *)&p, getpagesize(), _len))
+               return NULL;
+
+       memset(p, 0, _len);
+       return p;
+}