From 5527c15b1d7b89f359237f1e401fb204b6fa9257 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Mon, 14 Aug 2023 17:47:53 +0200 Subject: [PATCH 1/3] * Mon Aug 14 2023 Tomas Bzatek - 2.5-3 - Backport 'fabrics: Use corresponding hostid when hostnqn is generated' --- ...ing_hostid_when_hostnqn_is_generated.patch | 103 ++++++++++++++++++ nvme-cli.spec | 15 +-- 2 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch diff --git a/nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch b/nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch new file mode 100644 index 0000000..f9fc2fe --- /dev/null +++ b/nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch @@ -0,0 +1,103 @@ +From 7d1c18f581e489e0cedfd9991bc97a2f8239cf82 Mon Sep 17 00:00:00 2001 +From: Shin'ichiro Kawasaki +Date: Thu, 3 Aug 2023 20:21:39 +0900 +Subject: [PATCH] fabrics: Use corresponding hostid when hostnqn is generated + +After the kernel commit ae8bd606e09b ("nvme-fabrics: prevent overriding +of existing host"), kernel ensures hostid and hostnqn maintain 1:1 +mapping and "non 1:1 mapping will be rejected". This makes 'nvme +discover' and 'nvme connect' commands fail when they generate hostnqn, +since it does not use corresponding hostid. + +To avoid the failures, prepare and use corresponding hostid to the +generated hostnqn, taking the hostid from the hostnqn string. Also add +checks for prepared hostnqn and hostid. If the hostid taken from the +generated hostnqn is different from the hostid from file, print a +warning message. Also, if the prepared hostnqn are inconsistent with the +prepared hostid, print a warning. + +Link: https://lore.kernel.org/linux-nvme/l7vk7fnzltpmvkwujsbf2btrzip6wh7ug62iwa3totqcda25l6@siqx7tj6lt3l/ +Signed-off-by: Shin'ichiro Kawasaki +Signed-off-by: Daniel Wagner +--- + fabrics.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- + 1 file changed, 45 insertions(+), 2 deletions(-) + +diff --git a/fabrics.c b/fabrics.c +index 14a91cc6b..40aef6932 100644 +--- a/fabrics.c ++++ b/fabrics.c +@@ -689,6 +689,43 @@ static int nvme_read_volatile_config(nvme_root_t r) + return ret; + } + ++char *nvmf_hostid_from_hostnqn(const char *hostnqn) ++{ ++ const char *uuid; ++ ++ if (!hostnqn) ++ return NULL; ++ ++ uuid = strstr(hostnqn, "uuid:"); ++ if (!uuid) ++ return NULL; ++ ++ return strdup(uuid + strlen("uuid:")); ++} ++ ++void nvmf_check_hostid_and_hostnqn(const char *hostid, const char *hostnqn) ++{ ++ char *hostid_from_file, *hostid_from_hostnqn; ++ ++ if (!hostid) ++ return; ++ ++ hostid_from_file = nvmf_hostid_from_file(); ++ if (hostid_from_file && strcmp(hostid_from_file, hostid)) { ++ fprintf(stderr, "warning: use generated hostid instead of hostid file\n"); ++ free(hostid_from_file); ++ } ++ ++ if (!hostnqn) ++ return; ++ ++ hostid_from_hostnqn = nvmf_hostid_from_hostnqn(hostnqn); ++ if (hostid_from_hostnqn && strcmp(hostid_from_hostnqn, hostid)) { ++ fprintf(stderr, "warning: use hostid which does not match uuid in hostnqn\n"); ++ free(hostid_from_hostnqn); ++ } ++} ++ + int nvmf_discover(const char *desc, int argc, char **argv, bool connect) + { + char *subsysnqn = NVME_DISC_SUBSYS_NAME; +@@ -765,10 +802,13 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect) + hostid_arg = hostid; + if (!hostnqn) + hostnqn = hnqn = nvmf_hostnqn_from_file(); +- if (!hostnqn) ++ if (!hostnqn) { + hostnqn = hnqn = nvmf_hostnqn_generate(); ++ hostid = hid = nvmf_hostid_from_hostnqn(hostnqn); ++ } + if (!hostid) + hostid = hid = nvmf_hostid_from_file(); ++ nvmf_check_hostid_and_hostnqn(hostid, hostnqn); + h = nvme_lookup_host(r, hostnqn, hostid); + if (!h) { + ret = ENOMEM; +@@ -978,10 +1018,13 @@ int nvmf_connect(const char *desc, int argc, char **argv) + + if (!hostnqn) + hostnqn = hnqn = nvmf_hostnqn_from_file(); +- if (!hostnqn) ++ if (!hostnqn) { + hostnqn = hnqn = nvmf_hostnqn_generate(); ++ hostid = hid = nvmf_hostid_from_hostnqn(hostnqn); ++ } + if (!hostid) + hostid = hid = nvmf_hostid_from_file(); ++ nvmf_check_hostid_and_hostnqn(hostid, hostnqn); + h = nvme_lookup_host(r, hostnqn, hostid); + if (!h) { + errno = ENOMEM; diff --git a/nvme-cli.spec b/nvme-cli.spec index 8f80740..e5145ac 100644 --- a/nvme-cli.spec +++ b/nvme-cli.spec @@ -3,7 +3,7 @@ Name: nvme-cli Version: 2.5 -Release: 2%{?dist} +Release: 3%{?dist} Summary: NVMe management command line interface License: GPLv2 @@ -20,19 +20,13 @@ BuildRequires: openssl-devel BuildRequires: libnvme-devel >= 1.5 BuildRequires: json-c-devel >= 0.13 -%if (0%{?rhel} == 0) -BuildRequires: python3-nose2 -# https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#_linters -#BuildRequires: python3-mypy -#BuildRequires: python3-flake8 -#BuildRequires: python3-autopep8 -#BuildRequires: python3-isort -%endif BuildRequires: asciidoc BuildRequires: xmlto Requires: util-linux +Patch0: nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch + %description nvme-cli provides NVM-Express user space tooling for Linux. @@ -84,6 +78,9 @@ rm -rf %{buildroot}%{_pkgdocdir}/nvme %changelog +* Mon Aug 14 2023 Tomas Bzatek - 2.5-3 +- Backport 'fabrics: Use corresponding hostid when hostnqn is generated' + * Thu Jul 20 2023 Fedora Release Engineering - 2.5-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild From acf0b6463007c2916509e61e8ed23a84e674edf0 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Thu, 17 Aug 2023 17:31:51 +0200 Subject: [PATCH 2/3] * Thu Aug 17 2023 Tomas Bzatek - 2.5-4 - Mark /etc/nvme/discovery.conf as (noreplace) --- nvme-cli.spec | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nvme-cli.spec b/nvme-cli.spec index e5145ac..0a029d2 100644 --- a/nvme-cli.spec +++ b/nvme-cli.spec @@ -3,7 +3,7 @@ Name: nvme-cli Version: 2.5 -Release: 3%{?dist} +Release: 4%{?dist} Summary: NVMe management command line interface License: GPLv2 @@ -66,7 +66,7 @@ rm -rf %{buildroot}%{_pkgdocdir}/nvme %{_datadir}/bash-completion/completions/nvme %{_datadir}/zsh/site-functions/_nvme %dir %{_sysconfdir}/nvme -%{_sysconfdir}/nvme/discovery.conf +%config(noreplace) %{_sysconfdir}/nvme/discovery.conf %{_unitdir}/nvmefc-boot-connections.service %{_unitdir}/nvmf-autoconnect.service %{_unitdir}/nvmf-connect.target @@ -78,6 +78,9 @@ rm -rf %{buildroot}%{_pkgdocdir}/nvme %changelog +* Thu Aug 17 2023 Tomas Bzatek - 2.5-4 +- Mark /etc/nvme/discovery.conf as (noreplace) + * Mon Aug 14 2023 Tomas Bzatek - 2.5-3 - Backport 'fabrics: Use corresponding hostid when hostnqn is generated' From 0014bceadd0ac316a0aa02568b50c66bbd2c0c2b Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Fri, 29 Sep 2023 15:49:48 +0200 Subject: [PATCH 3/3] * Fri Sep 29 2023 Tomas Bzatek - 2.6-1 - Update to 2.6 --- .gitignore | 1 + ...ing_hostid_when_hostnqn_is_generated.patch | 103 ------------------ nvme-cli.spec | 13 ++- sources | 2 +- 4 files changed, 9 insertions(+), 110 deletions(-) delete mode 100644 nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch diff --git a/.gitignore b/.gitignore index 3555f05..c0a99be 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ /nvme-cli-2.3.tar.gz /nvme-cli-2.4.tar.gz /nvme-cli-2.5.tar.gz +/nvme-cli-2.6.tar.gz diff --git a/nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch b/nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch deleted file mode 100644 index f9fc2fe..0000000 --- a/nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch +++ /dev/null @@ -1,103 +0,0 @@ -From 7d1c18f581e489e0cedfd9991bc97a2f8239cf82 Mon Sep 17 00:00:00 2001 -From: Shin'ichiro Kawasaki -Date: Thu, 3 Aug 2023 20:21:39 +0900 -Subject: [PATCH] fabrics: Use corresponding hostid when hostnqn is generated - -After the kernel commit ae8bd606e09b ("nvme-fabrics: prevent overriding -of existing host"), kernel ensures hostid and hostnqn maintain 1:1 -mapping and "non 1:1 mapping will be rejected". This makes 'nvme -discover' and 'nvme connect' commands fail when they generate hostnqn, -since it does not use corresponding hostid. - -To avoid the failures, prepare and use corresponding hostid to the -generated hostnqn, taking the hostid from the hostnqn string. Also add -checks for prepared hostnqn and hostid. If the hostid taken from the -generated hostnqn is different from the hostid from file, print a -warning message. Also, if the prepared hostnqn are inconsistent with the -prepared hostid, print a warning. - -Link: https://lore.kernel.org/linux-nvme/l7vk7fnzltpmvkwujsbf2btrzip6wh7ug62iwa3totqcda25l6@siqx7tj6lt3l/ -Signed-off-by: Shin'ichiro Kawasaki -Signed-off-by: Daniel Wagner ---- - fabrics.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- - 1 file changed, 45 insertions(+), 2 deletions(-) - -diff --git a/fabrics.c b/fabrics.c -index 14a91cc6b..40aef6932 100644 ---- a/fabrics.c -+++ b/fabrics.c -@@ -689,6 +689,43 @@ static int nvme_read_volatile_config(nvme_root_t r) - return ret; - } - -+char *nvmf_hostid_from_hostnqn(const char *hostnqn) -+{ -+ const char *uuid; -+ -+ if (!hostnqn) -+ return NULL; -+ -+ uuid = strstr(hostnqn, "uuid:"); -+ if (!uuid) -+ return NULL; -+ -+ return strdup(uuid + strlen("uuid:")); -+} -+ -+void nvmf_check_hostid_and_hostnqn(const char *hostid, const char *hostnqn) -+{ -+ char *hostid_from_file, *hostid_from_hostnqn; -+ -+ if (!hostid) -+ return; -+ -+ hostid_from_file = nvmf_hostid_from_file(); -+ if (hostid_from_file && strcmp(hostid_from_file, hostid)) { -+ fprintf(stderr, "warning: use generated hostid instead of hostid file\n"); -+ free(hostid_from_file); -+ } -+ -+ if (!hostnqn) -+ return; -+ -+ hostid_from_hostnqn = nvmf_hostid_from_hostnqn(hostnqn); -+ if (hostid_from_hostnqn && strcmp(hostid_from_hostnqn, hostid)) { -+ fprintf(stderr, "warning: use hostid which does not match uuid in hostnqn\n"); -+ free(hostid_from_hostnqn); -+ } -+} -+ - int nvmf_discover(const char *desc, int argc, char **argv, bool connect) - { - char *subsysnqn = NVME_DISC_SUBSYS_NAME; -@@ -765,10 +802,13 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect) - hostid_arg = hostid; - if (!hostnqn) - hostnqn = hnqn = nvmf_hostnqn_from_file(); -- if (!hostnqn) -+ if (!hostnqn) { - hostnqn = hnqn = nvmf_hostnqn_generate(); -+ hostid = hid = nvmf_hostid_from_hostnqn(hostnqn); -+ } - if (!hostid) - hostid = hid = nvmf_hostid_from_file(); -+ nvmf_check_hostid_and_hostnqn(hostid, hostnqn); - h = nvme_lookup_host(r, hostnqn, hostid); - if (!h) { - ret = ENOMEM; -@@ -978,10 +1018,13 @@ int nvmf_connect(const char *desc, int argc, char **argv) - - if (!hostnqn) - hostnqn = hnqn = nvmf_hostnqn_from_file(); -- if (!hostnqn) -+ if (!hostnqn) { - hostnqn = hnqn = nvmf_hostnqn_generate(); -+ hostid = hid = nvmf_hostid_from_hostnqn(hostnqn); -+ } - if (!hostid) - hostid = hid = nvmf_hostid_from_file(); -+ nvmf_check_hostid_and_hostnqn(hostid, hostnqn); - h = nvme_lookup_host(r, hostnqn, hostid); - if (!h) { - errno = ENOMEM; diff --git a/nvme-cli.spec b/nvme-cli.spec index 0a029d2..d94873e 100644 --- a/nvme-cli.spec +++ b/nvme-cli.spec @@ -2,11 +2,11 @@ %{!?version_no_tilde: %define version_no_tilde %{shrink:%(echo '%{version}' | tr '~' '-')}} Name: nvme-cli -Version: 2.5 -Release: 4%{?dist} +Version: 2.6 +Release: 1%{?dist} Summary: NVMe management command line interface -License: GPLv2 +License: GPL-2.0-only URL: https://github.com/linux-nvme/nvme-cli Source0: %{url}/archive/v%{version_no_tilde}/%{name}-%{version_no_tilde}.tar.gz @@ -17,7 +17,7 @@ BuildRequires: systemd-rpm-macros BuildRequires: zlib-devel BuildRequires: openssl-devel -BuildRequires: libnvme-devel >= 1.5 +BuildRequires: libnvme-devel >= 1.6 BuildRequires: json-c-devel >= 0.13 BuildRequires: asciidoc @@ -25,8 +25,6 @@ BuildRequires: xmlto Requires: util-linux -Patch0: nvme-cli-2.6-fabrics-Use_corresponding_hostid_when_hostnqn_is_generated.patch - %description nvme-cli provides NVM-Express user space tooling for Linux. @@ -78,6 +76,9 @@ rm -rf %{buildroot}%{_pkgdocdir}/nvme %changelog +* Fri Sep 29 2023 Tomas Bzatek - 2.6-1 +- Update to 2.6 + * Thu Aug 17 2023 Tomas Bzatek - 2.5-4 - Mark /etc/nvme/discovery.conf as (noreplace) diff --git a/sources b/sources index f820245..844ac50 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -SHA512 (nvme-cli-2.5.tar.gz) = 50c557e86e95b27a0ad57779c33bbb847e12dd45c30e792f5ce1d52dedd4bc704ac25fa0af2fdebd281c9dfe0059f7ed7c1620fccfde9323f6f9a97afdf8c3cb +SHA512 (nvme-cli-2.6.tar.gz) = da4daef2d7c554455e0c195c03f92188e0e946409a3bd8a5b421d9a106746e82fb1309901d2893639b1a3447bda094c80a9f49f59bf43cf2b00402f82beea3fc