On Wed, Jun 04, 2025 at 09:10:19PM +0200, Michal Luczaj wrote:
On 6/4/25 11:07, Stefano Garzarella wrote:
On Wed, May 28, 2025 at 10:44:42PM +0200, Michal Luczaj wrote:
+static int __get_transports(void)
+{
+       /* Order must match transports defined in util.h.
+        * man nm: "d" The symbol is in the initialized data section.
+        */
+       const char * const syms[] = {
+               "d loopback_transport",
+               "d virtio_transport",
+               "d vhost_transport",
+               "d vmci_transport",
+               "d hvs_transport",
+       };

I would move this array (or a macro that define it), near the transport
defined in util.h, so they are near and we can easily update/review
changes.

BTW what about adding static asserts to check we are aligned?

Something like

#define KNOWN_TRANSPORTS        \

What about KNOWN_TRANSPORTS(_) ?

        _(LOOPBACK, "loopback")       \
        _(VIRTIO, "virtio")   \
        _(VHOST, "vhost")     \
        _(VMCI, "vmci")               \
        _(HYPERV, "hvs")

enum transport {
        TRANSPORT_COUNTER_BASE = __COUNTER__ + 1,
        #define _(name, symbol) \
                TRANSPORT_##name = _BITUL(__COUNTER__ - TRANSPORT_COUNTER_BASE),
        KNOWN_TRANSPORTS
        TRANSPORT_NUM = __COUNTER__ - TRANSPORT_COUNTER_BASE,
        #undef _
};

static char * const transport_ksyms[] = {
        #define _(name, symbol) "d " symbol "_transport",
        KNOWN_TRANSPORTS
        #undef _
};

static_assert(ARRAY_SIZE(transport_ksyms) == TRANSPORT_NUM);

?

Yep, this is even better, thanks :-)


Note that I keep pushing for naming HVS a TRANSPORT_HYPERV. Perhaps it's
better to stick to TRANSPORT_HVS after all?

I would have used HYPERV too, but honestly I don't have a strong opinion, so take your choice.

Thanks,
Stefano


diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h
index 
0afe7cbae12e5194172c639ccfbeb8b81f7c25ac..63953e32c3e18e1aa5c2addcf6f09f433660fa84
 100644
--- a/tools/testing/vsock/util.h
+++ b/tools/testing/vsock/util.h
@@ -3,8 +3,19 @@
#define UTIL_H

#include <sys/socket.h>
+#include <linux/bitops.h>
#include <linux/vm_sockets.h>

+#define KALLSYMS_PATH          "/proc/kallsyms"
+#define KALLSYMS_LINE_LEN      512

We don't need to expose them in util.h IMO, we can keep in util.c

OK, sure.

Thanks,
Michal



Reply via email to