From 6738ca4a7e01540c9320557bf6f480538f2473dd Mon Sep 17 00:00:00 2001 From: Travis Glenn Hansen Date: Thu, 29 Dec 2022 00:14:28 -0700 Subject: [PATCH] always use ip for nvme transport address Signed-off-by: Travis Glenn Hansen --- .github/workflows/main.yml | 2 ++ src/utils/general.js | 14 ++++++++++++++ src/utils/nvmeof.js | 27 +++++++++++++++++++-------- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b9df326..8b70796 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -459,6 +459,7 @@ jobs: - csi-sanity-synology-dsm6 - csi-sanity-synology-dsm7 - csi-sanity-truenas-scale-22_02 + - csi-sanity-truenas-scale-22_12 - csi-sanity-truenas-core-12_0 - csi-sanity-truenas-core-13_0 - csi-sanity-zfs-generic @@ -498,6 +499,7 @@ jobs: - csi-sanity-synology-dsm6 - csi-sanity-synology-dsm7 - csi-sanity-truenas-scale-22_02 + - csi-sanity-truenas-scale-22_12 - csi-sanity-truenas-core-12_0 - csi-sanity-truenas-core-13_0 - csi-sanity-zfs-generic diff --git a/src/utils/general.js b/src/utils/general.js index 9be60ab..e07b7b9 100644 --- a/src/utils/general.js +++ b/src/utils/general.js @@ -1,6 +1,7 @@ const _ = require("lodash"); const axios = require("axios"); const crypto = require("crypto"); +const dns = require("dns"); function sleep(ms) { return new Promise((resolve) => { @@ -261,6 +262,18 @@ async function retry(retries, retriesDelay, code, options = {}) { } while (true); } +async function hostname_lookup(hostname) { + return new Promise((resolve, reject) => { + dns.lookup(hostname, function (err, result) { + if (err) { + return reject(err); + } + + return resolve(result); + }); + }); +} + module.exports.sleep = sleep; module.exports.md5 = md5; module.exports.crc32 = crc32; @@ -277,3 +290,4 @@ module.exports.default_supported_file_filesystems = default_supported_file_filesystems; module.exports.retry = retry; module.exports.trimchar = trimchar; +module.exports.hostname_lookup = hostname_lookup; diff --git a/src/utils/nvmeof.js b/src/utils/nvmeof.js index 794a0e3..4c42636 100644 --- a/src/utils/nvmeof.js +++ b/src/utils/nvmeof.js @@ -1,7 +1,6 @@ const cp = require("child_process"); -const { trimchar } = require("./general"); +const { hostname_lookup, trimchar } = require("./general"); const URI = require("uri-js"); -const { deleteItems } = require("@kubernetes/client-node"); const DEFAULT_TIMEOUT = process.env.NVMEOF_DEFAULT_TIMEOUT || 30000; @@ -65,7 +64,7 @@ class NVMEoF { */ async discover(transport, args = []) { const nvmeof = this; - transport = nvmeof.parseTransport(transport); + transport = await nvmeof.parseTransport(transport); let transport_args = []; if (transport.type) { @@ -90,7 +89,7 @@ class NVMEoF { */ async connectByNQNTransport(nqn, transport, args = []) { const nvmeof = this; - transport = nvmeof.parseTransport(transport); + transport = await nvmeof.parseTransport(transport); let transport_args = []; if (transport.type) { @@ -150,7 +149,7 @@ class NVMEoF { await nvmeof.exec(nvmeof.options.paths.nvme, args); } - parseTransport(transport) { + async parseTransport(transport) { if (typeof transport === "object") { return transport; } @@ -176,6 +175,18 @@ class NVMEoF { address = trimchar(address, "["); address = trimchar(address, "]"); break; + case "tcp": + /** + * kernel stores value as ip, so if address passed as hostname then + * translate to ip address + * + * TODO: this could be brittle + */ + let lookup = await hostname_lookup(address); + if (lookup) { + address = lookup; + } + break; } switch (type) { @@ -206,7 +217,7 @@ class NVMEoF { async namespaceDevicePathByTransportNQNNamespace(transport, nqn, namespace) { const nvmeof = this; - transport = nvmeof.parseTransport(transport); + transport = await nvmeof.parseTransport(transport); let nativeMultipathEnabled = await nvmeof.nativeMultipathEnabled(); if (nativeMultipathEnabled) { let subsystem = await nvmeof.getSubsystemByNQN(nqn); @@ -235,7 +246,7 @@ class NVMEoF { async controllerDevicePathByTransportNQN(transport, nqn) { const nvmeof = this; - transport = nvmeof.parseTransport(transport); + transport = await nvmeof.parseTransport(transport); let controller = await nvmeof.getControllerByTransportNQN(transport, nqn); if (controller) { return `/dev/${controller.Controller}`; @@ -258,7 +269,7 @@ class NVMEoF { async getControllerByTransportNQN(transport, nqn) { const nvmeof = this; - transport = nvmeof.parseTransport(transport); + transport = await nvmeof.parseTransport(transport); let subsystem = await nvmeof.getSubsystemByNQN(nqn); if (subsystem) { for (let controller of subsystem.Controllers) {