From 862d109cb4ce373200099ac86b6bb7b54217472d Mon Sep 17 00:00:00 2001 From: wenchao-hao Date: Sat, 31 Oct 2020 17:11:17 +0800 Subject: [PATCH] backport patches from epoch1 --- ...ervice-so-it-handles-restarts-better.patch | 40 +++++++++++ ...-iface.example-in-iface-match-checks.patch | 28 ++++++++ 0022-Fix-SIGPIPE-loop-in-signal-handler.patch | 30 +++++++++ ...-Proper-disconnect-of-TCP-connection.patch | 55 ++++++++++++++++ 0024-Add-iscsi-init.service.patch | 52 +++++++++++++++ ...-zero-length-arrays-at-end-of-struct.patch | 66 +++++++++++++++++++ ...ler-complaint-about-writing-one-byte.patch | 30 +++++++++ open-iscsi.spec | 12 +++- 8 files changed, 312 insertions(+), 1 deletion(-) create mode 100644 0020-Fix-iscsi.service-so-it-handles-restarts-better.patch create mode 100644 0021-Ignore-iface.example-in-iface-match-checks.patch create mode 100644 0022-Fix-SIGPIPE-loop-in-signal-handler.patch create mode 100644 0023-Proper-disconnect-of-TCP-connection.patch create mode 100644 0024-Add-iscsi-init.service.patch create mode 100644 0025-Fix-issue-with-zero-length-arrays-at-end-of-struct.patch create mode 100644 0026-Fix-a-compiler-complaint-about-writing-one-byte.patch diff --git a/0020-Fix-iscsi.service-so-it-handles-restarts-better.patch b/0020-Fix-iscsi.service-so-it-handles-restarts-better.patch new file mode 100644 index 0000000..62fae4e --- /dev/null +++ b/0020-Fix-iscsi.service-so-it-handles-restarts-better.patch @@ -0,0 +1,40 @@ +From 6a9b0728c55b8ad5c6d5dba3f38697eded09538a Mon Sep 17 00:00:00 2001 +From: Lee Duncan +Date: Wed, 4 Mar 2020 12:59:10 -0800 +Subject: [PATCH 151/170] Fix iscsi.service so it handles restarts better + +Requiring iscsid.service means that a restart of iscsi.service +restarted iscsid.service when unneccesary. + +Also, we should treat an exit value of 15 as normal, since +this just means the session is already present. +It should rely on iscsid.socket, no iscsid.service. +--- + etc/systemd/iscsi.service | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/etc/systemd/iscsi.service b/etc/systemd/iscsi.service +index e475888..1c286d1 100644 +--- a/etc/systemd/iscsi.service ++++ b/etc/systemd/iscsi.service +@@ -3,7 +3,7 @@ Description=Login and scanning of iSCSI devices + Documentation=man:iscsiadm(8) man:iscsid(8) + Before=remote-fs.target + After=network.target network-online.target iscsid.service +-Requires=iscsid.service ++Requires=iscsid.socket + ConditionPathExists=/etc/iscsi/initiatorname.iscsi + + [Service] +@@ -11,7 +11,7 @@ Type=oneshot + ExecStart=/sbin/iscsiadm -m node --loginall=automatic + ExecStop=/sbin/iscsiadm -m node --logoutall=automatic + ExecStop=/sbin/iscsiadm -m node --logoutall=manual +-SuccessExitStatus=21 ++SuccessExitStatus=21 15 + RemainAfterExit=true + + [Install] +-- +2.21.1 (Apple Git-122.3) + diff --git a/0021-Ignore-iface.example-in-iface-match-checks.patch b/0021-Ignore-iface.example-in-iface-match-checks.patch new file mode 100644 index 0000000..b8464b4 --- /dev/null +++ b/0021-Ignore-iface.example-in-iface-match-checks.patch @@ -0,0 +1,28 @@ +From 16d4899d52b3b88774ac6d9b3cc0f5626f4705da Mon Sep 17 00:00:00 2001 +From: Lee Duncan +Date: Tue, 19 Nov 2019 07:54:41 -0800 +Subject: [PATCH 158/170] Ignore iface.example in iface match checks + +Just a cleanup, as looking at the example file +didn't hurt anything, but did waste our time. +--- + usr/iface.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/usr/iface.c b/usr/iface.c +index 323f167..11f3d2a 100644 +--- a/usr/iface.c ++++ b/usr/iface.c +@@ -905,6 +905,9 @@ int iface_for_each_iface(void *data, int skip_def, int *nr_found, + !strcmp(iface_dent->d_name, "..")) + continue; + ++ if (!strcmp(iface_dent->d_name, "iface.example")) ++ continue; ++ + log_debug(5, "iface_for_each_iface found %s", + iface_dent->d_name); + iface = iface_alloc(iface_dent->d_name, &err); +-- +2.21.1 (Apple Git-122.3) + diff --git a/0022-Fix-SIGPIPE-loop-in-signal-handler.patch b/0022-Fix-SIGPIPE-loop-in-signal-handler.patch new file mode 100644 index 0000000..c16c70f --- /dev/null +++ b/0022-Fix-SIGPIPE-loop-in-signal-handler.patch @@ -0,0 +1,30 @@ +From 71e4ce5e7722dde25751025cac0e8b29d8d540df Mon Sep 17 00:00:00 2001 +From: fredvx <48496214+fredvx@users.noreply.github.com> +Date: Wed, 22 Apr 2020 14:24:50 -0400 +Subject: [PATCH 161/170] Fix SIGPIPE loop in signal handler + +--- + usr/iscsid.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/usr/iscsid.c b/usr/iscsid.c +index 99d27ab..e501498 100644 +--- a/usr/iscsid.c ++++ b/usr/iscsid.c +@@ -310,7 +310,12 @@ static void iscsid_shutdown(void) + + static void catch_signal(int signo) + { +- log_debug(1, "pid %d caught signal %d", getpid(), signo); ++ /* ++ * Do not try to call log_debug() if there is a PIPE error ++ * because we can get caught in a PIPE error loop. ++ */ ++ if (signo != SIGPIPE) ++ log_debug(1, "pid %d caught signal %d", getpid(), signo); + + /* In foreground mode, treat SIGINT like SIGTERM */ + if (!daemonize && signo == SIGINT) +-- +2.21.1 (Apple Git-122.3) + diff --git a/0023-Proper-disconnect-of-TCP-connection.patch b/0023-Proper-disconnect-of-TCP-connection.patch new file mode 100644 index 0000000..37a4518 --- /dev/null +++ b/0023-Proper-disconnect-of-TCP-connection.patch @@ -0,0 +1,55 @@ +From dc7560d404857c0540caed2f71f8e7c2e7307ab3 Mon Sep 17 00:00:00 2001 +From: gulams <64251312+gulams@users.noreply.github.com> +Date: Tue, 28 Apr 2020 13:03:50 +0530 +Subject: [PATCH 162/170] Proper disconnect of TCP connection + +1. Due to configuration issues, the logins from iSCSI initiator were getting rejected by the target +2. The initiator was retrying the login again and again +3. Each time the initiator tries to log in, the host number gets incremented by 1 +4. At one point of time, the host number reached 65535 +5. During the login process, once the TCP connection is established, the initiator tries to set the host parameters for the network interface if its not the default interface +6. While setting these host parameters, it will try to do a lookup of the host based upon the host number +7. The host number in "iscsi_uevent" structure is uint32_t. This is given as an argument to the scsi_host_lookup() function +8. This scsi_host_lookup() function takes it as unsigned short. So, when it receives the host number above 65535, the value is wrapped and starts from 0 again +9. Thus the incorrect value of host number is received by the scsi_host_lookup() function and hence it returns with error that the host is not existing in the list +10. Due to this "host not found error", the open-iscsi will retry this particular connection again and again +11. In this each retry, it will disconnect and then connect again with the same connection pointer, i.e it re-opens the connection multiple times till 120 seconds timeout +12. During these 120 seconds, observed that its trying to re-open the connection aroung 400+ times with each time disconnect and connect +13. After 120 seconds, the connection and session will be destroyed +14. So, while doing multiple retries of connect and disconnect during the 120 seconds, when the connect is successful it will try to bind the connection to the session +15. When it binds the connection and session, the reference count for the socket is incremented +16. When it disconnects, its trying to close the socket with close(sockfd) system call +17. This close() system call is entering into the kernel and NOT going forward till the networking layrer to call tcp_close() to send the FIN packet to the target +18. Its not going till tcp_close() because the reference count of the socket is still 1 +19. So, the initiator is not sending the FIN packet to target and hence target is timing out and sending FIN after its timeout. This happens for all the retries (400+) +20. At some point, when this FIN packet is received by the initiator, the connection was destroyed and the memory was re-used for some other purpose and hence we see the panic + +Fix: +== +Fix is to decrement the reference count of the socket fd after disconnect by calling the stop connection + +Corrected the indentation for the change in the function iscsi_login_eh() +--- + usr/initiator.c | 6 +----- + 1 file changed, 1 insertion(+), 5 deletions(-) + +diff --git a/usr/initiator.c b/usr/initiator.c +index a07f9aa..5f4bdca 100644 +--- a/usr/initiator.c ++++ b/usr/initiator.c +@@ -711,11 +711,7 @@ static void iscsi_login_eh(struct iscsi_conn *conn, struct queue_task *qtask, + !iscsi_retry_initial_login(conn)) + session_conn_shutdown(conn, qtask, err); + else { +- session->reopen_cnt++; +- session->t->template->ep_disconnect(conn); +- if (iscsi_conn_connect(conn, qtask)) +- queue_delayed_reopen(qtask, +- ISCSI_CONN_ERR_REOPEN_DELAY); ++ session_conn_reopen(conn, qtask, STOP_CONN_TERM); + } + break; + case R_STAGE_SESSION_REDIRECT: +-- +2.21.1 (Apple Git-122.3) + diff --git a/0024-Add-iscsi-init.service.patch b/0024-Add-iscsi-init.service.patch new file mode 100644 index 0000000..bda53b1 --- /dev/null +++ b/0024-Add-iscsi-init.service.patch @@ -0,0 +1,52 @@ +From f37d5b653f9f251845db3f29b1a3dcb90ec89731 Mon Sep 17 00:00:00 2001 +From: Christian Glombek +Date: Wed, 6 May 2020 02:08:59 +0200 +Subject: [PATCH 163/170] Add iscsi-init.service + +Per Fedora Packaging Guidelines [1], initial configuration of a service +should happen in a one-off init service in order to ensure idempotency, +and not in the %post directive of the RPM spec. + +Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1493296 + +[1]: https://docs.fedoraproject.org/en-US/packaging-guidelines/Initial_Service_Setup/ +--- + etc/systemd/iscsi-init.service | 8 ++++++++ + etc/systemd/iscsi.service | 6 +++--- + 2 files changed, 11 insertions(+), 3 deletions(-) + create mode 100644 etc/systemd/iscsi-init.service + +diff --git a/etc/systemd/iscsi-init.service b/etc/systemd/iscsi-init.service +new file mode 100644 +index 0000000..e058ff0 +--- /dev/null ++++ b/etc/systemd/iscsi-init.service +@@ -0,0 +1,8 @@ ++[Unit] ++Description=One time configuration for iscsi.service ++ConditionPathExists=!/etc/iscsi/initiatorname.iscsi ++ ++[Service] ++Type=oneshot ++RemainAfterExit=no ++ExecStart=/usr/bin/sh -c 'echo "InitiatorName=`/usr/sbin/iscsi-iname`" > /etc/iscsi/initiatorname.iscsi' +diff --git a/etc/systemd/iscsi.service b/etc/systemd/iscsi.service +index 1c286d1..2f2bf81 100644 +--- a/etc/systemd/iscsi.service ++++ b/etc/systemd/iscsi.service +@@ -2,9 +2,9 @@ + Description=Login and scanning of iSCSI devices + Documentation=man:iscsiadm(8) man:iscsid(8) + Before=remote-fs.target +-After=network.target network-online.target iscsid.service +-Requires=iscsid.socket +-ConditionPathExists=/etc/iscsi/initiatorname.iscsi ++After=network.target network-online.target ++After=iscsid.service iscsi-init.service ++Requires=iscsid.socket iscsi-init.service + + [Service] + Type=oneshot +-- +2.21.1 (Apple Git-122.3) + diff --git a/0025-Fix-issue-with-zero-length-arrays-at-end-of-struct.patch b/0025-Fix-issue-with-zero-length-arrays-at-end-of-struct.patch new file mode 100644 index 0000000..44bf39c --- /dev/null +++ b/0025-Fix-issue-with-zero-length-arrays-at-end-of-struct.patch @@ -0,0 +1,66 @@ +From 8d96cc47381a840e5e03384e8077ad238fd1adc4 Mon Sep 17 00:00:00 2001 +From: Lee Duncan +Date: Wed, 3 Jun 2020 08:29:39 -0700 +Subject: [PATCH 164/170] Fix issue with zero-length arrays at end of struct +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +A common practice in C coding, over the years, has been to +add a zero-length array at the end of the structure when trying +to represent a possibly-empty array of bytes that may be +appended to the struct. But the gcc-10 compiler does not +like such structures, taking the zero-length literally. + +The following errors are fixed by this commit: + +> iscsiadm.c: In function ‘session_stats’: +> iscsiadm.c:939:56: error: array subscript ‘() + -1’ is outside the bounds of an interior zero-length array ‘struct iscsi_stats_custom[0]’ [-Werror=zero-length-bounds] +> 939 | (unsigned long long)rsp.u.getstats.stats.custom[i].value); +> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ +> In file included from initiator.h:29, +> from iscsiadm.c:36: +> ../include/iscsi_if.h:844:28: note: while referencing ‘custom’ +> 844 | struct iscsi_stats_custom custom[0] +> | ^~~~~~ +> iscsiadm.c:938:56: error: array subscript ‘() + -1’ is outside the bounds of an interior zero-length array ‘struct iscsi_stats_custom[0]’ [-Werror=zero-length-bounds] +> 938 | printf("\t%s: %llu\n", rsp.u.getstats.stats.custom[i].desc, +> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ +> In file included from initiator.h:29, +> from iscsiadm.c:36: +> ../include/iscsi_if.h:844:28: note: while referencing ‘custom’ +> 844 | struct iscsi_stats_custom custom[0] +> | ^~~~~~ +> cc1: all warnings being treated as errors + +The work around is to convert the two "custom[0]" structure members to +use "custom[]". +--- + include/iscsi_if.h | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/include/iscsi_if.h b/include/iscsi_if.h +index 2d46214..5a1c614 100644 +--- a/include/iscsi_if.h ++++ b/include/iscsi_if.h +@@ -841,7 +841,7 @@ struct iscsi_stats { + * up to ISCSI_STATS_CUSTOM_MAX + */ + uint32_t custom_length; +- struct iscsi_stats_custom custom[0] ++ struct iscsi_stats_custom custom[] + __attribute__ ((aligned (sizeof(uint64_t)))); + }; + +@@ -972,7 +972,7 @@ struct iscsi_offload_host_stats { + * up to ISCSI_HOST_STATS_CUSTOM_MAX + */ + uint32_t custom_length; +- struct iscsi_host_stats_custom custom[0] ++ struct iscsi_host_stats_custom custom[] + __attribute__ ((aligned (sizeof(uint64_t)))); + }; + +-- +2.21.1 (Apple Git-122.3) + diff --git a/0026-Fix-a-compiler-complaint-about-writing-one-byte.patch b/0026-Fix-a-compiler-complaint-about-writing-one-byte.patch new file mode 100644 index 0000000..f4216e0 --- /dev/null +++ b/0026-Fix-a-compiler-complaint-about-writing-one-byte.patch @@ -0,0 +1,30 @@ +From 10009f1c5fc01238be976867bc02be046325850b Mon Sep 17 00:00:00 2001 +From: Lee Duncan +Date: Wed, 3 Jun 2020 08:36:45 -0700 +Subject: [PATCH 165/170] Fix a compiler complaint about writing one byte + +When playing with IPv6 IP addresses, which are described +in C using a union, and the gcc-10 compiler didn't like +that we were not specifying which member of the union +we wanted to address of, when in fact all members have +the same address. The fix is to be more explicit. +--- + iscsiuio/src/uip/ipv6.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/iscsiuio/src/uip/ipv6.c b/iscsiuio/src/uip/ipv6.c +index 05efa73..11cb4e9 100644 +--- a/iscsiuio/src/uip/ipv6.c ++++ b/iscsiuio/src/uip/ipv6.c +@@ -519,7 +519,7 @@ static void ipv6_insert_protocol_chksum(struct ipv6_hdr *ipv6) + * SRC IP, DST IP, Protocol Data Length, and Next Header. + */ + sum = 0; +- ptr = (u16_t *)&ipv6->ipv6_src; ++ ptr = (u16_t *)&ipv6->ipv6_src.addr16[0]; + + for (i = 0; i < sizeof(struct ipv6_addr); i++) { + sum += HOST_TO_NET16(*ptr); +-- +2.21.1 (Apple Git-122.3) + diff --git a/open-iscsi.spec b/open-iscsi.spec index a0e3681..be3b896 100644 --- a/open-iscsi.spec +++ b/open-iscsi.spec @@ -4,7 +4,7 @@ Name: open-iscsi Version: 2.1.1 -Release: 2 +Release: 3 Summary: ISCSI software initiator daemon and utility programs License: GPLv2+ and BSD URL: http://www.open-iscsi.org @@ -28,6 +28,13 @@ Patch16: 0016-iscsi-fix-fd-leak.patch Patch17: 0017-Fix-devel-without-node-header-files.patch Patch18: 0018-resolve-compilation-errors.patch Patch19: 0019-Update-systemd-unit-files-for-iscsid.patch +Patch20: 0020-Fix-iscsi.service-so-it-handles-restarts-better.patch +Patch21: 0021-Ignore-iface.example-in-iface-match-checks.patch +Patch22: 0022-Fix-SIGPIPE-loop-in-signal-handler.patch +Patch23: 0023-Proper-disconnect-of-TCP-connection.patch +Patch24: 0024-Add-iscsi-init.service.patch +Patch25: 0025-Fix-issue-with-zero-length-arrays-at-end-of-struct.patch +Patch26: 0026-Fix-a-compiler-complaint-about-writing-one-byte.patch BuildRequires: flex bison doxygen kmod-devel systemd-units gcc git isns-utils-devel systemd-devel BuildRequires: autoconf automake libtool libmount-devel openssl-devel pkg-config gdb @@ -160,6 +167,9 @@ fi %{_mandir}/man8/* %changelog +* Sat Oct 31 2020 haowenchao - 2.1.1-3 +- backport patches from epoch1 + * Tue Sep 1 2020 wuguanghao - 2.1.1-2 - backport one patch for solving install problem