Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package tcmu-runner for openSUSE:Factory checked in at 2022-10-19 13:17:42 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/tcmu-runner (Old) and /work/SRC/openSUSE:Factory/.tcmu-runner.new.2275 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "tcmu-runner" Wed Oct 19 13:17:42 2022 rev:15 rq:1029798 version:1.6.0 Changes: -------- --- /work/SRC/openSUSE:Factory/tcmu-runner/tcmu-runner.changes 2022-03-19 22:22:11.576896465 +0100 +++ /work/SRC/openSUSE:Factory/.tcmu-runner.new.2275/tcmu-runner.changes 2022-10-19 13:18:13.577290406 +0200 @@ -1,0 +2,34 @@ +Fri Oct 14 16:14:17 UTC 2022 - ldun...@suse.com + +- Update to version 1.6.0 from upstream: + * Bump version to 1.6.0 + * Use get_unaligned_be*() to avoid UB + * libtcmu: add support for write protect + * rbd: make it to be compatible to the old blacklist style + * rbd: switch to blocklist + * rbd: switch strtok to strtok_r + * tcmur_device: rename the state_lock to rdev_lock + * tcmur_device: rename lock to cmds_list_lock + * rbd: fix and add more debug logs + * rbd: fix the possible warning of incorrect return value type + * rbd: remove the reduntant logs + * rbd: fix memory leak when fails to get the address + * Revert "Create codeql-analysis.yml" + * rbd: fix use-after-free of addr + * Create codeql-analysis.yml + * main: fix g_object_unref: assertion 'G_IS_OBJECT (object)' failed + * remove pthread_getname_np calls + * implicitly cast pthread_t to long unsigned int + * add missing pthread.h include + * replace assert_perror with assert + * cast time_t to intmax_t when printing + * spec: make dist tag optional (#659) + * install-dep.sh: do not install multiple packages in one single line (#657) + * tcmu_read_config() check read() return value. (#656) + + The 3 current patches, which are SUSE-specific, stay. + + Note that this update moves libtcmu.so (a symlink) to a new + package: libtcmu-devel, as suggested by rpmlint. + +------------------------------------------------------------------- Old: ---- tcmu-runner-1.5.4.tar.xz New: ---- tcmu-runner-1.6.0.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ tcmu-runner.spec ++++++ --- /var/tmp/diff_new_pack.1DXcjk/_old 2022-10-19 13:18:14.145291584 +0200 +++ /var/tmp/diff_new_pack.1DXcjk/_new 2022-10-19 13:18:14.149291592 +0200 @@ -35,7 +35,7 @@ %bcond_with tcmalloc Name: tcmu-runner -Version: 1.5.4 +Version: 1.6.0 Release: 0 Summary: A userspace daemon that handles the LIO TCM-User backstore License: Apache-2.0 @@ -134,6 +134,15 @@ file backstore in tcmu-runner. %endif +%package -n libtcmu-devel +Summary: Development package for libtcmu +Group: Development/Libraries +Requires: %{name} = %{version} +Requires: libtcmu2 = %{version} + +%description -n libtcmu-devel +Development header(s) and lib(s) for developing against libtcmu. + %prep %setup %patch1 -p1 @@ -206,13 +215,13 @@ %config %{_sysconfdir}/dbus-1/system.d/tcmu-runner.conf %{_unitdir}/tcmu-runner.service %doc %{_mandir}/man8/tcmu-runner.8%{ext_man} -%config %{_sysconfdir}/logrotate.d/tcmu-runner +%config(noreplace) %{_sysconfdir}/logrotate.d/tcmu-runner %dir %{_sysconfdir}/tcmu -%config(noreplace) %{_sysconfdir}/tcmu/tcmu.conf +%config %{_sysconfdir}/tcmu/tcmu.conf %files -n libtcmu2 %defattr(-,root,root) -%{_libdir}/libtcmu.so* +%{_libdir}/libtcmu*.so.* %if 0%{?build_handler_glusterfs} %files handler-glusterfs @@ -229,4 +238,7 @@ %{_libdir}/tcmu-runner/handler_file_zbc.so %endif +%files -n libtcmu-devel +%{_libdir}/libtcmu*.so + %changelog ++++++ _service ++++++ --- /var/tmp/diff_new_pack.1DXcjk/_old 2022-10-19 13:18:14.201291700 +0200 +++ /var/tmp/diff_new_pack.1DXcjk/_new 2022-10-19 13:18:14.205291708 +0200 @@ -4,8 +4,8 @@ <param name="url">https://github.com/open-iscsi/tcmu-runner.git</param> <param name="subdir"></param> <param name="filename">tcmu-runner</param> - <param name="versionformat">1.5.4</param> - <param name="revision">v1.5.4</param> + <param name="versionformat">1.6.0</param> + <param name="revision">v1.6.0</param> <param name="changesgenerate">enable</param> </service> <service name="recompress" mode="disabled"> ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.1DXcjk/_old 2022-10-19 13:18:14.245291791 +0200 +++ /var/tmp/diff_new_pack.1DXcjk/_new 2022-10-19 13:18:14.253291808 +0200 @@ -1,6 +1,6 @@ <servicedata> <service name="tar_scm"> <param name="url">https://github.com/open-iscsi/tcmu-runner.git</param> - <param name="changesrevision">06d64ab78c2898c032fe5be93f9ae6f64b199d5b</param></service></servicedata> + <param name="changesrevision">82a2e3eb706530653829988089d9b3a4eabd525b</param></service></servicedata> (No newline at EOF) ++++++ tcmu-runner-1.5.4.tar.xz -> tcmu-runner-1.6.0.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/.gitignore new/tcmu-runner-1.6.0/.gitignore --- old/tcmu-runner-1.5.4/.gitignore 1970-01-01 01:00:00.000000000 +0100 +++ new/tcmu-runner-1.6.0/.gitignore 2022-10-14 03:14:14.000000000 +0200 @@ -0,0 +1,22 @@ +tcmu-runner +tcmu-synthesizer +consumer +*.o +*.a +*.swp +*.patch +handler_*.so +libtcmu.so* +*generated.[ch] +Makefile +version.h +CMakeCache* +CMakeFiles/* +cmake_install.cmake +install_manifest.txt +cscope.* +ncscope.* +tcmu.conf_install.cmake +core.* +extra/rpmbuild +logrotate.conf_install.cmake diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/CMakeLists.txt new/tcmu-runner-1.6.0/CMakeLists.txt --- old/tcmu-runner-1.5.4/CMakeLists.txt 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/CMakeLists.txt 2022-10-14 03:14:14.000000000 +0200 @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 2.8 FATAL_ERROR) project (tcmu-runner C) -set(VERSION 1.5.4) +set(VERSION 1.6.0) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wdeclaration-after-statement -std=c99") include(GNUInstallDirs) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/alua.c new/tcmu-runner-1.6.0/alua.c --- old/tcmu-runner-1.5.4/alua.c 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/alua.c 2022-10-14 03:14:14.000000000 +0200 @@ -432,12 +432,12 @@ * the first command sent to us so clear * lock state to avoid later blacklist errors. */ - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (rdev->lock_state == TCMUR_DEV_LOCK_WRITE_LOCKED) { tcmu_dev_dbg(dev, "Dropping lock\n"); rdev->lock_state = TCMUR_DEV_LOCK_UNLOCKED; } - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); } } @@ -560,7 +560,7 @@ if (!lock_is_required(dev)) return ret; - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (rdev->lock_state == TCMUR_DEV_LOCK_WRITE_LOCKED) { /* For both read/write cases in this state is good */ goto done; @@ -617,7 +617,7 @@ } done: - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); return ret; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/api.c new/tcmu-runner-1.6.0/api.c --- old/tcmu-runner-1.5.4/api.c 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/api.c 2022-10-14 03:14:14.000000000 +0200 @@ -28,6 +28,8 @@ #include "libtcmu_priv.h" #include "be_byteshift.h" +__thread int __tcmu_is_ework_thread = 0; + int tcmu_cdb_get_length(uint8_t *cdb) { uint8_t group_code = cdb[0] >> 5; @@ -65,16 +67,16 @@ switch (tcmu_cdb_get_length(cdb)) { case 6: - val = be16toh(*((uint16_t *)&cdb[2])); + val = get_unaligned_be16(&cdb[2]); return ((cdb[1] & 0x1f) << 16) | val; case 10: - return be32toh(*((u_int32_t *)&cdb[2])); + return get_unaligned_be32(&cdb[2]); case 12: - return be32toh(*((u_int32_t *)&cdb[2])); + return get_unaligned_be32(&cdb[2]); case 16: - return be64toh(*((u_int64_t *)&cdb[2])); + return get_unaligned_be64(&cdb[2]); default: - assert_perror(EINVAL); + assert(0); return 0; /* not reached */ } } @@ -85,13 +87,13 @@ case 6: return cdb[4]; case 10: - return be16toh(*((uint16_t *)&cdb[7])); + return get_unaligned_be16(&cdb[7]); case 12: - return be32toh(*((u_int32_t *)&cdb[6])); + return get_unaligned_be32(&cdb[6]); case 16: - return be32toh(*((u_int32_t *)&cdb[10])); + return get_unaligned_be32(&cdb[10]); default: - assert_perror(EINVAL); + assert(0); return 0; /* not reached */ } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/be_byteshift.h new/tcmu-runner-1.6.0/be_byteshift.h --- old/tcmu-runner-1.5.4/be_byteshift.h 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/be_byteshift.h 2022-10-14 03:14:14.000000000 +0200 @@ -9,6 +9,11 @@ #ifndef _TCMU_BE_BYTESHIFT_H #define _TCMU_BE_BYTESHIFT_H +#include <endian.h> +#include <stdint.h> +#include <string.h> + + static inline void __put_unaligned_be32(uint32_t val, uint8_t *p) { *p++ = val >> 24; @@ -48,9 +53,22 @@ return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; } -static inline uint16_t get_unaligned_be32(const void *p) +static inline uint32_t get_unaligned_be32(const void *p) { return __get_unaligned_be32(p); } +static inline uint64_t get_unaligned_be64(const void *p) +{ + uint64_t val; + memcpy(&val, p, sizeof(val)); + return be64toh(val); +} + +static inline void put_unaligned_be64(uint64_t val, void *p) +{ + val = htobe64(val); + memcpy(p, &val, sizeof(val)); +} + #endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/extra/install_dep.sh new/tcmu-runner-1.6.0/extra/install_dep.sh --- old/tcmu-runner-1.5.4/extra/install_dep.sh 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/extra/install_dep.sh 2022-10-14 03:14:14.000000000 +0200 @@ -13,13 +13,24 @@ case $ID in fedora|rhel|centos) # for generic - $SUDO yum install -y cmake make gcc libnl3 glib2 zlib kmod - $SUDO yum install -y libnl3-devel glib2-devel zlib-devel kmod-devel gperftools-devel + $SUDO yum install -y cmake make gcc + $SUDO yum install -y libnl3 + $SUDO yum install -y libnl3-devel + $SUDO yum install -y glib2 + $SUDO yum install -y glib2-devel + $SUDO yum install -y zlib + $SUDO yum install -y zlib-devel + $SUDO yum install -y kmod + $SUDO yum install -y kmod-devel + $SUDO yum install -y gperftools-devel # for glusterfs - $SUDO yum install -y glusterfs-api glusterfs-api-devel + $SUDO yum install -y glusterfs-api + $SUDO yum install -y glusterfs-api-devel # for ceph - $SUDO yum install -y librados2 librados2-devel librbd1 + $SUDO yum install -y librados2 + $SUDO yum install -y librados2-devel + $SUDO yum install -y librbd1 yum search librbd-devel | grep -q "N/S matched" && LIBRBD=librbd || LIBRBD=librbd1 $SUDO yum install -y $LIBRBD-devel ;; @@ -28,24 +39,41 @@ $SUDO apt update # for generic - $SUDO apt install -y cmake make gcc zlib1g kmod - $SUDO apt install -y libnl-3-dev libnl-genl-3-dev libglib2.0-0 libkmod-dev libgoogle-perftools-dev + $SUDO apt install -y cmake make gcc + $SUDO apt install -y zlib1g kmod + $SUDO apt install -y libnl-3-dev + $SUDO apt install -y libnl-genl-3-dev + $SUDO apt install -y libglib2.0-0 + $SUDO apt install -y libkmod-dev + $SUDO apt install -y libgoogle-perftools-dev # for glusterfs $SUDO apt install -y libglusterfs-dev # for ceph - $SUDO apt install -y librados2 librbd-dev + $SUDO apt install -y librados2 + $SUDO apt install -y librbd-dev ;; sles|opensuse-tumbleweed) # for generic - $SUDO zypper install -y cmake make gcc libnl3-200 glib2 zlib kmod - $SUDO zypper install -y libnl3-devel glib2-devel zlib-devel libkmod-devel gperftools-devel + $SUDO zypper install -y cmake make gcc + $SUDO zypper install -y libnl3-200 + $SUDO zypper install -y glib2 + $SUDO zypper install -y zlib + $SUDO zypper install -y kmod + $SUDO zypper install -y libnl3-devel + $SUDO zypper install -y glib2-devel + $SUDO zypper install -y zlib-devel + $SUDO zypper install -y libkmod-devel + $SUDO zypper install -y gperftools-devel #for glusterfs - $SUDO zypper install -y glusterfs-devel glusterfs + $SUDO zypper install -y glusterfs + $SUDO zypper install -y glusterfs-devel #for ceph - $SUDO zypper install -y librbd-devel librados-devel librados2 + $SUDO zypper install -y librbd-devel + $SUDO zypper install -y librados-devel + $SUDO zypper install -y librados2 ;; *) echo "TODO: distro not supported for now!" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/libtcmu.c new/tcmu-runner-1.6.0/libtcmu.c --- old/tcmu-runner-1.5.4/libtcmu.c 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/libtcmu.c 2022-10-14 03:14:14.000000000 +0200 @@ -843,24 +843,20 @@ void tcmu_set_thread_name(const char *prefix, struct tcmu_device *dev) { const char *uio = dev ? tcmu_dev_get_uio_name(dev) : NULL; - char cname[TCMU_THREAD_NAME_LEN]; char *pname; - if (pthread_getname_np(pthread_self(), cname, TCMU_THREAD_NAME_LEN)) - return; - /* * If we are trying to set the pthread name in the * event work thread, we must ignore it. */ - if (!strcmp(cname, "ework-thread")) { + if (__tcmu_is_ework_thread) { tcmu_dev_warn(dev, "Do not set name for event work thread in the callback fn\n"); return; } if (!prefix) { tcmu_dev_err(dev, "Failed to set name for thread %lu\n", - pthread_self()); + (long unsigned int)pthread_self()); return; } @@ -1025,6 +1021,16 @@ return dev->unmap_enabled; } +void tcmu_dev_set_write_protect_enabled(struct tcmu_device *dev, bool enabled) +{ + dev->write_protect_enabled = enabled; +} + +bool tcmu_dev_get_write_protect_enabled(struct tcmu_device *dev) +{ + return dev->write_protect_enabled; +} + int tcmu_dev_get_fd(struct tcmu_device *dev) { return dev->fd; @@ -1064,7 +1070,7 @@ /* get length of map from file */ ssize_t size; char *size_name; - + if (asprintf(&size_name, sizefmt, dev->dev_name) == -1) { tcmu_err("cannot construct device map size filename\n"); goto err_free; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/libtcmu_common.h new/tcmu-runner-1.6.0/libtcmu_common.h --- old/tcmu-runner-1.5.4/libtcmu_common.h 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/libtcmu_common.h 2022-10-14 03:14:14.000000000 +0200 @@ -14,6 +14,7 @@ #define __LIBTCMU_COMMON_H #include <stdbool.h> +#include <pthread.h> #ifdef __cplusplus extern "C" { @@ -137,6 +138,8 @@ bool tcmu_dev_get_solid_state_media(struct tcmu_device *dev); void tcmu_dev_set_unmap_enabled(struct tcmu_device *dev, bool enabled); bool tcmu_dev_get_unmap_enabled(struct tcmu_device *dev); +void tcmu_dev_set_write_protect_enabled(struct tcmu_device *dev, bool enabled); +bool tcmu_dev_get_write_protect_enabled(struct tcmu_device *dev); struct tcmulib_handler *tcmu_dev_get_handler(struct tcmu_device *dev); void tcmu_dev_flush_ring(struct tcmu_device *dev); bool tcmu_dev_oooc_supported(struct tcmu_device* dev); @@ -193,6 +196,8 @@ */ void tcmu_thread_cancel(pthread_t thread); +extern __thread int __tcmu_is_ework_thread; + #ifdef __cplusplus } #endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/libtcmu_config.c new/tcmu-runner-1.6.0/libtcmu_config.c --- old/tcmu-runner-1.5.4/libtcmu_config.c 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/libtcmu_config.c 2022-10-14 03:14:14.000000000 +0200 @@ -202,7 +202,7 @@ do { len = read(fd, buf, count); - } while (errno == EAGAIN); + } while (len < 0 && errno == EAGAIN); errno = save; return len; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/libtcmu_log.c new/tcmu-runner-1.6.0/libtcmu_log.c --- old/tcmu-runner-1.5.4/libtcmu_log.c 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/libtcmu_log.c 2022-10-14 03:14:14.000000000 +0200 @@ -403,7 +403,6 @@ int fd = (intptr_t) data; char *buf, *msg; int count, ret, written = 0, r, pid = 0; - char pname[TCMU_THREAD_NAME_LEN]; if (fd == -1) return -1; @@ -412,13 +411,10 @@ if (pid <= 0) return -1; - if (pthread_getname_np(pthread_self(), pname, TCMU_THREAD_NAME_LEN)) - return -1; - /* * format: timestamp pid [loglevel] msg */ - ret = asprintf(&msg, "%s %d:%s [%s] %s", timestamp, pid, pname, + ret = asprintf(&msg, "%s %d [%s] %s", timestamp, pid, loglevel_string(pri), str); if (ret < 0) return -1; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/libtcmu_priv.h new/tcmu-runner-1.6.0/libtcmu_priv.h --- old/tcmu-runner-1.5.4/libtcmu_priv.h 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/libtcmu_priv.h 2022-10-14 03:14:14.000000000 +0200 @@ -55,6 +55,7 @@ unsigned int write_cache_enabled:1; unsigned int solid_state_media:1; unsigned int unmap_enabled:1; + unsigned int write_protect_enabled:1; char dev_name[16]; /* e.g. "uio14" */ char tcm_hba_name[16]; /* e.g. "user_8" */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/main.c new/tcmu-runner-1.6.0/main.c --- old/tcmu-runner-1.5.4/main.c 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/main.c 2022-10-14 03:14:14.000000000 +0200 @@ -615,14 +615,14 @@ struct tcmur_device *rdev = tcmu_dev_get_private(dev); bool is_open = false; - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); /* check if this was already called due to thread cancelation */ if (rdev->flags & TCMUR_DEV_FLAG_STOPPED) { - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); return; } rdev->flags |= TCMUR_DEV_FLAG_STOPPING; - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); /* * The lock thread can fire off the recovery thread, so make sure @@ -633,19 +633,19 @@ tcmu_release_dev_lock(dev); - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (rdev->flags & TCMUR_DEV_FLAG_IS_OPEN) { rdev->flags &= ~TCMUR_DEV_FLAG_IS_OPEN; is_open = true; } - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); if (is_open) rhandler->close(dev); - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); rdev->flags |= TCMUR_DEV_FLAG_STOPPED; - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); tcmu_dev_dbg(dev, "cmdproc cleanup done\n"); } @@ -657,7 +657,7 @@ ret = clock_gettime(CLOCK_MONOTONIC_COARSE, time); if (!ret) { - tcmu_dev_dbg(dev, "Current time %lu secs.\n", time->tv_sec); + tcmu_dev_dbg(dev, "Current time %"PRIdMAX" secs.\n", (intmax_t)time->tv_sec); return 0; } @@ -681,7 +681,7 @@ memset(tmo, 0, sizeof(*tmo)); - pthread_spin_lock(&rdev->lock); + pthread_spin_lock(&rdev->cmds_list_lock); list_for_each(&rdev->cmds_list, tcmur_cmd, cmds_list_entry) { if (tcmur_cmd->timed_out) continue; @@ -700,12 +700,12 @@ tmo->tv_sec = 0; } - tcmu_dev_dbg(dev, "Next cmd id %hu timeout in %lu secs. Current time %lu. Start time %lu\n", - tcmur_cmd->lib_cmd->cmd_id, tmo->tv_sec, - curr_time->tv_sec, tcmur_cmd->start_time.tv_sec); + tcmu_dev_dbg(dev, "Next cmd id %hu timeout in %"PRIdMAX" secs. Current time %"PRIdMAX". Start time %"PRIdMAX"\n", + tcmur_cmd->lib_cmd->cmd_id, (intmax_t)tmo->tv_sec, + (intmax_t)curr_time->tv_sec, (intmax_t)tcmur_cmd->start_time.tv_sec); break; } - pthread_spin_unlock(&rdev->lock); + pthread_spin_unlock(&rdev->cmds_list_lock); return has_timeout; } @@ -728,7 +728,7 @@ if (tcmur_get_time(dev, &curr_time)) return; - pthread_spin_lock(&rdev->lock); + pthread_spin_lock(&rdev->cmds_list_lock); list_for_each(&rdev->cmds_list, tcmur_cmd, cmds_list_entry) { if (tcmur_cmd->timed_out) continue; @@ -758,7 +758,7 @@ */ tcmu_notify_cmd_timed_out(dev); } - pthread_spin_unlock(&rdev->lock); + pthread_spin_unlock(&rdev->cmds_list_lock); } static void tcmur_tcmulib_cmd_start(struct tcmu_device *dev, @@ -775,9 +775,9 @@ if (rdev->cmd_time_out) { tcmur_cmd->start_time.tv_sec = curr_time->tv_sec; - pthread_spin_lock(&rdev->lock); + pthread_spin_lock(&rdev->cmds_list_lock); list_add_tail(&rdev->cmds_list, &tcmur_cmd->cmds_list_entry); - pthread_spin_unlock(&rdev->lock); + pthread_spin_unlock(&rdev->cmds_list_lock); } } @@ -872,10 +872,10 @@ * requests that LIO has completed. We only need to wait for replies * for outstanding requests so throttle the cmdproc thread now. */ - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (rdev->flags & TCMUR_DEV_FLAG_STOPPING) dev_stopping = true; - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); } /* @@ -1020,7 +1020,7 @@ tcmu_dev_dbg(dev, "Got block_size %d, size in bytes %"PRId64"\n", block_size, dev_size); - ret = pthread_spin_init(&rdev->lock, 0); + ret = pthread_spin_init(&rdev->cmds_list_lock, 0); if (ret) { ret = -ret; goto free_rdev; @@ -1038,7 +1038,7 @@ goto cleanup_caw_lock; } - ret = pthread_mutex_init(&rdev->state_lock, NULL); + ret = pthread_mutex_init(&rdev->rdev_lock, NULL); if (ret) { ret = -ret; goto cleanup_format_lock; @@ -1046,7 +1046,7 @@ ret = setup_io_work_queue(dev); if (ret < 0) - goto cleanup_state_lock; + goto cleanup_rdev_lock; ret = setup_aio_tracking(rdev); if (ret < 0) @@ -1088,14 +1088,14 @@ cleanup_aio_tracking(rdev); cleanup_io_work_queue: cleanup_io_work_queue(dev, true); -cleanup_state_lock: - pthread_mutex_destroy(&rdev->state_lock); +cleanup_rdev_lock: + pthread_mutex_destroy(&rdev->rdev_lock); cleanup_format_lock: pthread_mutex_destroy(&rdev->format_lock); cleanup_caw_lock: pthread_mutex_destroy(&rdev->caw_lock); cleanup_dev_lock: - pthread_spin_destroy(&rdev->lock); + pthread_spin_destroy(&rdev->cmds_list_lock); free_rdev: free(rdev); return ret; @@ -1106,9 +1106,9 @@ struct tcmur_device *rdev = tcmu_dev_get_private(dev); int ret; - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); rdev->flags |= TCMUR_DEV_FLAG_STOPPING; - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); /* * The order of cleaning up worker threads and calling ->removed() @@ -1130,7 +1130,7 @@ tcmur_destroy_work(rdev->event_work); - ret = pthread_mutex_destroy(&rdev->state_lock); + ret = pthread_mutex_destroy(&rdev->rdev_lock); if (ret != 0) tcmu_err("could not cleanup state lock %d\n", ret); @@ -1142,7 +1142,7 @@ if (ret != 0) tcmu_err("could not cleanup caw lock %d\n", ret); - ret = pthread_spin_destroy(&rdev->lock); + ret = pthread_spin_destroy(&rdev->cmds_list_lock); if (ret != 0) tcmu_err("could not cleanup mailbox lock %d\n", ret); @@ -1398,7 +1398,7 @@ g_unix_signal_add(SIGTERM, handle_sig, loop) <= 0 || g_unix_signal_add(SIGHUP, handle_sighup, loop) <= 0) { tcmu_err("couldn't setup signal handlers\n"); - goto unwatch_cfg; + goto loop_unref; } /* Set up event for libtcmu */ @@ -1424,15 +1424,16 @@ tcmu_crit("Exiting...\n"); g_bus_unown_name(reg_id); - g_main_loop_unref(loop); g_source_remove(watch_id); g_io_channel_shutdown(libtcmu_gio, TRUE, NULL); g_io_channel_unref (libtcmu_gio); - g_object_unref(manager); + if (manager) + g_object_unref(manager); ret = 0; -unwatch_cfg: +loop_unref: + g_main_loop_unref(loop); if (watching_cfg) tcmu_unwatch_config(tcmu_cfg); tcmulib_close(tcmulib_context); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/rbd.c new/tcmu-runner-1.6.0/rbd.c --- old/tcmu-runner-1.5.4/rbd.c 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/rbd.c 2022-10-14 03:14:14.000000000 +0200 @@ -109,8 +109,8 @@ size_t iov_cnt; }; -static pthread_mutex_t blacklist_caches_lock = PTHREAD_MUTEX_INITIALIZER; -static darray(char *) blacklist_caches; +static pthread_mutex_t blocklist_caches_lock = PTHREAD_MUTEX_INITIALIZER; +static darray(char *) blocklist_caches; #ifdef LIBRADOS_SUPPORTS_SERVICES @@ -216,8 +216,6 @@ } ret = tcmu_rbd_report_event(dev); - if (ret < 0) - tcmu_dev_err(dev, "Could not update status. (Err %d)\n", ret); free_meta_buf: free(metadata_buf); @@ -238,20 +236,76 @@ } #ifdef RBD_LOCK_ACQUIRE_SUPPORT -static void tcmu_rbd_service_status_update(struct tcmu_device *dev, +static int tcmu_rbd_service_status_update(struct tcmu_device *dev, bool has_lock) { + return 0; } #endif /* RBD_LOCK_ACQUIRE_SUPPORT */ #endif /* LIBRADOS_SUPPORTS_SERVICES */ #if defined LIBRADOS_SUPPORTS_GETADDRS || defined RBD_LOCK_ACQUIRE_SUPPORT -static void tcmu_rbd_rm_stale_entry_from_blacklist(struct tcmu_device *dev, char *addrs) + +static int tcmu_rbd_remove_blocklist(struct tcmu_device *dev, char *addr) +{ + struct tcmu_rbd_state *state = tcmur_dev_get_private(dev); + char *cmd; + int ret; + + ret = asprintf(&cmd, + "{\"prefix\": \"osd blocklist\"," + "\"blocklistop\": \"rm\"," + "\"addr\": \"%s\"}", + addr); + if (ret < 0) { + tcmu_dev_warn(dev, "Could not allocate blocklist rm command. (Err %d)\n", + ret); + return -1; + } + ret = rados_mon_command(state->cluster, (const char**)&cmd, 1, NULL, 0, + NULL, NULL, NULL, NULL); + free(cmd); + if (ret < 0) { + tcmu_dev_dbg(dev, "Could not rm blocklist entry '%s'. (Err %d)\n", + addr, ret); + return 1; + } + return 0; +} + +/* Old style */ +static int tcmu_rbd_remove_blacklist(struct tcmu_device *dev, char *addr) { struct tcmu_rbd_state *state = tcmur_dev_get_private(dev); + char *cmd; + int ret; + + ret = asprintf(&cmd, + "{\"prefix\": \"osd blacklist\"," + "\"blacklistop\": \"rm\"," + "\"addr\": \"%s\"}", + addr); + if (ret < 0) { + tcmu_dev_warn(dev, "Could not allocate blacklist rm command. (Err %d)\n", + ret); + return -1; + } + ret = rados_mon_command(state->cluster, (const char**)&cmd, 1, NULL, 0, + NULL, NULL, NULL, NULL); + free(cmd); + if (ret < 0) { + tcmu_dev_err(dev, "Could not rm blacklist entry '%s'. (Err %d)\n", + addr, ret); + return 1; + } + return 0; +} + +static void tcmu_rbd_rm_stale_entry_from_blocklist(struct tcmu_device *dev, char *addrs) +{ const char *p, *q, *end; - char *cmd, *addr; + char *addr; int ret; /* @@ -303,52 +357,39 @@ p = NULL; } - ret = asprintf(&cmd, - "{\"prefix\": \"osd blacklist\"," - "\"blacklistop\": \"rm\"," - "\"addr\": \"%s\"}", - addr); + ret = tcmu_rbd_remove_blocklist(dev, addr); + if (ret > 0) + ret = tcmu_rbd_remove_blacklist(dev, addr); free(addr); - if (ret < 0) { - tcmu_dev_warn(dev, "Could not allocate command. (Err %d)\n", - ret); + if (ret) return; - } - ret = rados_mon_command(state->cluster, (const char**)&cmd, 1, NULL, 0, - NULL, NULL, NULL, NULL); - free(cmd); - if (ret < 0) { - tcmu_dev_err(dev, "Could not rm blacklist entry '%s'. (Err %d)\n", - addr, ret); - return; - } } } -static int tcmu_rbd_rm_stale_entries_from_blacklist(struct tcmu_device *dev) +static int tcmu_rbd_rm_stale_entries_from_blocklist(struct tcmu_device *dev) { char **entry, *tmp_entry; int ret = 0; int i; - pthread_mutex_lock(&blacklist_caches_lock); - if (darray_empty(blacklist_caches)) + pthread_mutex_lock(&blocklist_caches_lock); + if (darray_empty(blocklist_caches)) goto unlock; - /* Try to remove all the stale blacklist entities */ - darray_foreach(entry, blacklist_caches) { - tcmu_dev_info(dev, "removing addrs: {%s}\n", *entry); - tcmu_rbd_rm_stale_entry_from_blacklist(dev, *entry); + /* Try to remove all the stale blocklist entities */ + darray_foreach(entry, blocklist_caches) { + tcmu_dev_info(dev, "removing blocklist entry: {%s}\n", *entry); + tcmu_rbd_rm_stale_entry_from_blocklist(dev, *entry); } unlock: - for (i = darray_size(blacklist_caches) - 1; i >= 0; i--) { - tmp_entry = darray_item(blacklist_caches, i); - darray_remove(blacklist_caches, i); + for (i = darray_size(blocklist_caches) - 1; i >= 0; i--) { + tmp_entry = darray_item(blocklist_caches, i); + darray_remove(blocklist_caches, i); free(tmp_entry); } - pthread_mutex_unlock(&blacklist_caches_lock); + pthread_mutex_unlock(&blocklist_caches_lock); return ret; } #endif // LIBRADOS_SUPPORTS_GETADDRS || RBD_LOCK_ACQUIRE_SUPPORT @@ -641,7 +682,7 @@ * Returns: * 0 = client is not owner. * 1 = client is owner. - * -ESHUTDOWN/-EBLACKLISTED(-108) = client is blacklisted. + * -ESHUTDOWN/-EBLOCKLISTED(-108) = client is blocklisted. * -ETIMEDOUT = rados osd op timeout has expired. * -EIO = misc error. */ @@ -653,7 +694,7 @@ ret = rbd_is_exclusive_lock_owner(state->image, &is_owner); if (ret < 0) { if (ret == -ESHUTDOWN) { - tcmu_dev_dbg(dev, "Client is blacklisted. Could not check lock ownership.\n"); + tcmu_dev_dbg(dev, "Client is blocklisted. Could not check lock ownership.\n"); } else { tcmu_dev_err(dev, "Could not check lock ownership. Error: %s.\n", strerror(-ret)); @@ -912,7 +953,7 @@ ret = rbd_lock_get_owners(state->image, &lock_mode, owners1, &num_owners1); if ((!ret && !num_owners1) || ret < 0) { - tcmu_dev_warn(dev, "Could not get lock owners to store blacklist entry %d!\n", + tcmu_dev_warn(dev, "Could not get lock owners to store blocklist entry %d!\n", ret); } else { int is_owner; @@ -921,7 +962,7 @@ ret = rbd_is_exclusive_lock_owner(state->image, &is_owner); if (ret) { rbd_lock_get_owners_cleanup(owners1, num_owners1); - tcmu_dev_warn(dev, "Could not check lock owners to store blacklist entry %d!\n", + tcmu_dev_warn(dev, "Could not check lock owners to store blocklist entry %d!\n", ret); goto no_owner; } @@ -930,9 +971,9 @@ ret = rbd_lock_get_owners(state->image, &lock_mode, owners2, &num_owners2); if ((!ret && !num_owners2) || ret < 0) { - tcmu_dev_warn(dev, "Could not get lock owners to store blacklist entry %d!\n", + tcmu_dev_warn(dev, "Could not get lock owners to store blocklist entry %d!\n", ret); - /* Only we didn't lose the lock during the above check will we store the blacklist list */ + /* Only we didn't lose the lock during the above check will we store the blocklist list */ } else if (!strcmp(owners1[0], owners2[0]) && is_owner) { state->addrs = strdup(owners1[0]); // ignore the errors } @@ -944,7 +985,7 @@ #endif set_lock_tag: - tcmu_dev_warn(dev, "Acquired exclusive lock.\n"); + tcmu_dev_info(dev, "Acquired exclusive lock.\n"); if (tag != TCMU_INVALID_LOCK_TAG) ret = tcmu_rbd_set_lock_tag(dev, tag); @@ -1025,8 +1066,9 @@ char *config, *dev_cfg_dup; struct tcmu_rbd_state *state; uint32_t max_blocks, unmap_gran; - int ret; char buf[128]; + char *savedptr = NULL; + int ret; state = calloc(1, sizeof(*state)); if (!state) @@ -1052,7 +1094,7 @@ } config += 1; /* get past '/' */ - pool = strtok(config, "/"); + pool = strtok_r(config, "/", &savedptr); if (!pool) { tcmu_dev_err(dev, "Could not get pool name\n"); ret = -EINVAL; @@ -1065,7 +1107,7 @@ goto free_config; } - name = strtok(NULL, ";"); + name = strtok_r(NULL, ";", &savedptr); if (!name) { tcmu_dev_err(dev, "Could not get image name\n"); ret = -EINVAL; @@ -1080,7 +1122,7 @@ } /* The next options are optional */ - next_opt = strtok(NULL, ";"); + next_opt = strtok_r(NULL, ";", &savedptr); while (next_opt) { if (!strncmp(next_opt, "osd_op_timeout=", 15)) { state->osd_op_timeout = strdup(next_opt + 15); @@ -1105,7 +1147,7 @@ goto free_config; } } - next_opt = strtok(NULL, ";"); + next_opt = strtok_r(NULL, ";", &savedptr); } ret = tcmu_rbd_image_open(dev); @@ -1153,15 +1195,17 @@ tcmu_dev_set_write_cache_enabled(dev, 0); #if defined LIBRADOS_SUPPORTS_GETADDRS || defined RBD_LOCK_ACQUIRE_SUPPORT - tcmu_rbd_rm_stale_entries_from_blacklist(dev); + tcmu_rbd_rm_stale_entries_from_blocklist(dev); #endif #ifdef LIBRADOS_SUPPORTS_GETADDRS /* Get current entry address for the image */ ret = rados_getaddrs(state->cluster, &state->addrs); + if (ret < 0) { + tcmu_dev_err(dev, "Could not get address. (Err %d)\n", ret); + goto stop_image; + } tcmu_dev_info(dev, "address: {%s}\n", state->addrs); - if (ret < 0) - return ret; #endif free(dev_cfg_dup); @@ -1184,26 +1228,27 @@ /* * Since we are closing the device, but current device maybe - * already blacklisted by other tcmu nodes. Let's just save - * the entity addrs into the blacklist_caches, and let any + * already blocklisted by other tcmu nodes. Let's just save + * the entity addrs into the blocklist_caches, and let any * other new device help remove it. */ if (state->addrs) { - pthread_mutex_lock(&blacklist_caches_lock); - darray_append(blacklist_caches, state->addrs); - pthread_mutex_unlock(&blacklist_caches_lock); + pthread_mutex_lock(&blocklist_caches_lock); + darray_append(blocklist_caches, state->addrs); + pthread_mutex_unlock(&blocklist_caches_lock); + tcmu_dev_info(dev, "appended blocklist entry: {%s}\n", state->addrs); state->addrs = NULL; } tcmu_rbd_state_free(state); } -static int tcmu_rbd_handle_blacklisted_cmd(struct tcmu_device *dev) +static int tcmu_rbd_handle_blocklisted_cmd(struct tcmu_device *dev) { tcmu_notify_lock_lost(dev); /* * This will happen during failback normally, because - * running IO is failed due to librbd's immediate blacklisting + * running IO is failed due to librbd's immediate blocklisting * during lock acquisition on a higher priority path. */ return TCMU_STS_BUSY; @@ -1228,7 +1273,7 @@ * that end up reaching it after the initiator's failover/recovery * timeout. For implicit and explicit FO, we will just disable * the iscsi port, and let the initiator switch paths which will - * result in us getting blacklisted, so fail with a retryable + * result in us getting blocklisted, so fail with a retryable * error. */ return TCMU_STS_TIMEOUT; @@ -1317,7 +1362,7 @@ if (ret == -ETIMEDOUT) { tcmu_r = tcmu_rbd_handle_timedout_cmd(dev); } else if (ret == -ESHUTDOWN || ret == -EROFS) { - tcmu_r = tcmu_rbd_handle_blacklisted_cmd(dev); + tcmu_r = tcmu_rbd_handle_blocklisted_cmd(dev); } else if (ret == -EILSEQ && aio_cb->type == RBD_AIO_TYPE_CAW) { cmp_offset = aio_cb->caw.miscompare_offset - aio_cb->caw.offset; tcmu_dev_dbg(dev, "CAW miscompare at offset %u.\n", cmp_offset); @@ -1638,7 +1683,7 @@ case TCMULIB_CFG_DEV_SIZE: /* * Apps will already have resized on the ceph side, so no - * need to double check and have to also handle unblacklisting + * need to double check and have to also handle unblocklisting * the client from this context. */ return 0; @@ -1651,7 +1696,7 @@ static int tcmu_rbd_init(void) { - darray_init(blacklist_caches); + darray_init(blocklist_caches); return 0; } @@ -1660,18 +1705,18 @@ char **entry; tcmu_info("destroying the rbd handler\n"); - pthread_mutex_lock(&blacklist_caches_lock); - if (darray_empty(blacklist_caches)) + pthread_mutex_lock(&blocklist_caches_lock); + if (darray_empty(blocklist_caches)) goto unlock; - /* Try to remove all the stale blacklist entities */ - darray_foreach(entry, blacklist_caches) + /* Try to remove all the stale blocklist entities */ + darray_foreach(entry, blocklist_caches) free(*entry); - darray_free(blacklist_caches); + darray_free(blocklist_caches); unlock: - pthread_mutex_unlock(&blacklist_caches_lock); + pthread_mutex_unlock(&blocklist_caches_lock); } /* diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/scsi.c new/tcmu-runner-1.6.0/scsi.c --- old/tcmu-runner-1.5.4/scsi.c 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/scsi.c 2022-10-14 03:14:14.000000000 +0200 @@ -800,6 +800,14 @@ orig_buf[0] = used_len - 1; } + if (tcmu_dev_get_write_protect_enabled(dev)) { + if (sense_ten) { + orig_buf[3] |= 0x80; + } else { + orig_buf[2] |= 0x80; + } + } + tcmu_memcpy_into_iovec(iovec, iov_cnt, orig_buf, alloc_len); free(orig_buf); return TCMU_STS_OK; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/target.c new/tcmu-runner-1.6.0/target.c --- old/tcmu-runner-1.5.4/target.c 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/target.c 2022-10-14 03:14:14.000000000 +0200 @@ -29,7 +29,7 @@ static struct list_head tpg_recovery_list = LIST_HEAD_INIT(tpg_recovery_list); /* * Locking ordering: - * rdev->state_lock + * rdev->rdev_lock * tpg_recovery_lock */ static pthread_mutex_t tpg_recovery_lock = PTHREAD_MUTEX_INITIALIZER; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/tcmu-runner.spec new/tcmu-runner-1.6.0/tcmu-runner.spec --- old/tcmu-runner-1.5.4/tcmu-runner.spec 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/tcmu-runner.spec 2022-10-14 03:14:14.000000000 +0200 @@ -35,11 +35,11 @@ Summary: A daemon that handles the userspace side of the LIO TCM-User backstore Group: System Environment/Daemons License: ASL 2.0 or LGPLv2+ -Version: 1.5.4 +Version: 1.6.0 URL: https://github.com/open-iscsi/tcmu-runner #%define _RC -Release: %{?_RC:%{_RC}}%{dist} +Release: %{?_RC:%{_RC}}%{?dist} BuildRoot: %(mktemp -udp %{_tmppath}/%{name}-%{version}%{?_RC:-%{_RC}}) Source: %{name}-%{version}%{?_RC:-%{_RC}}.tar.gz ExclusiveOS: Linux diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/tcmur_cmd_handler.c new/tcmu-runner-1.6.0/tcmur_cmd_handler.c --- old/tcmu-runner-1.5.4/tcmur_cmd_handler.c 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/tcmur_cmd_handler.c 2022-10-14 03:14:14.000000000 +0200 @@ -40,8 +40,8 @@ struct tcmur_cmd *tcmur_cmd = cmd->hm_private; struct timespec curr_time; - pthread_cleanup_push(_cleanup_spin_lock, (void *)&rdev->lock); - pthread_spin_lock(&rdev->lock); + pthread_cleanup_push(_cleanup_spin_lock, (void *)&rdev->cmds_list_lock); + pthread_spin_lock(&rdev->cmds_list_lock); if (tcmur_cmd->timed_out) { if (tcmur_get_time(dev, &curr_time)) { @@ -60,7 +60,7 @@ tcmulib_command_complete(dev, cmd, rc); - pthread_spin_unlock(&rdev->lock); + pthread_spin_unlock(&rdev->cmds_list_lock); pthread_cleanup_pop(0); } @@ -2329,9 +2329,9 @@ { struct tcmur_device *rdev = tcmu_dev_get_private(dev); - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); rdev->pending_uas |= (1 << ua); - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); } /* @@ -2348,7 +2348,7 @@ /* The kernel will handle REPORT_LUNS */ return TCMU_STS_NOT_HANDLED; } - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (!rdev->pending_uas) { ret = TCMU_STS_NOT_HANDLED; @@ -2364,7 +2364,7 @@ rdev->pending_uas &= ~(1 << ua); unlock: - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); return ret; } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/tcmur_device.c new/tcmu-runner-1.6.0/tcmur_device.c --- old/tcmu-runner-1.5.4/tcmur_device.c 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/tcmur_device.c 2022-10-14 03:14:14.000000000 +0200 @@ -29,10 +29,10 @@ struct tcmur_device *rdev = tcmu_dev_get_private(dev); int in_recov = false; - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (rdev->flags & TCMUR_DEV_FLAG_IN_RECOVERY) in_recov = true; - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); return in_recov; } @@ -46,12 +46,12 @@ int ret, attempt = 0; bool needs_close = false; - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (rdev->flags & TCMUR_DEV_FLAG_STOPPING) { ret = 0; goto done; } - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); /* * There are no SCSI commands running but there may be @@ -60,11 +60,11 @@ */ tcmur_flush_work(rdev->event_work); - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (rdev->flags & TCMUR_DEV_FLAG_IS_OPEN) needs_close = true; rdev->flags &= ~TCMUR_DEV_FLAG_IS_OPEN; - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); if (pthread_self() != rdev->cmdproc_thread) /* @@ -77,7 +77,7 @@ tcmu_dev_dbg(dev, "Waiting for outstanding commands to complete\n"); ret = aio_wait_for_empty_queue(rdev); if (ret) { - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); goto done; } @@ -86,11 +86,11 @@ rhandler->close(dev); } - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); ret = -EIO; while (ret != 0 && !(rdev->flags & TCMUR_DEV_FLAG_STOPPING) && (retries < 0 || attempt <= retries)) { - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); tcmu_dev_dbg(dev, "Opening device. Attempt %d\n", attempt); ret = rhandler->open(dev, true); @@ -99,7 +99,7 @@ sleep(1); } - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (!ret) { rdev->flags |= TCMUR_DEV_FLAG_IS_OPEN; rdev->lock_lost = false; @@ -109,7 +109,7 @@ done: rdev->flags &= ~TCMUR_DEV_FLAG_IN_RECOVERY; - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); return ret; } @@ -123,13 +123,13 @@ { struct tcmur_device *rdev = tcmu_dev_get_private(dev); - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (rdev->flags & TCMUR_DEV_FLAG_IN_RECOVERY) { - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); return -EBUSY; } rdev->flags |= TCMUR_DEV_FLAG_IN_RECOVERY; - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); return __tcmu_reopen_dev(dev, retries); } @@ -144,13 +144,13 @@ * handlers to fail/complete normally to avoid a segfault. */ tcmu_dev_dbg(dev, "Waiting on recovery thread\n"); - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); while (rdev->flags & TCMUR_DEV_FLAG_IN_RECOVERY) { - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); sleep(1); - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); } - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); tcmu_dev_dbg(dev, "Recovery thread wait done\n"); } @@ -167,11 +167,11 @@ */ sleep(1); - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); ret = rhandler->report_event(dev); if (ret) tcmu_dev_err(dev, "Could not report events. Error %d.\n", ret); - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); } static void tcmu_report_event(struct tcmu_device *dev) @@ -236,9 +236,9 @@ struct tcmur_device *rdev = tcmu_dev_get_private(dev); bool report; - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); report =__tcmu_notify_conn_lost(dev); - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); if (report) tcmu_report_event(dev); @@ -267,7 +267,7 @@ { struct tcmur_device *rdev = tcmu_dev_get_private(dev); - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); tcmu_dev_warn(dev, "Async lock drop. Old state %d\n", rdev->lock_state); /* * We could be getting stale IO completions. If we are trying to @@ -276,7 +276,7 @@ if (rdev->lock_state != TCMUR_DEV_LOCK_WRITE_LOCKING) { __tcmu_notify_lock_lost(dev); } - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); } void tcmu_release_dev_lock(struct tcmu_device *dev) @@ -285,20 +285,20 @@ struct tcmur_device *rdev = tcmu_dev_get_private(dev); int ret; - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (rdev->lock_state != TCMUR_DEV_LOCK_WRITE_LOCKED) { - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); return; } if (!(rdev->flags & TCMUR_DEV_FLAG_IS_OPEN)) { tcmu_dev_dbg(dev, "Device is closed so unlock is not needed\n"); rdev->lock_state = TCMUR_DEV_LOCK_UNLOCKED; - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); return; } - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); ret = rhandler->unlock(dev); if (ret != TCMU_STS_OK) @@ -309,9 +309,9 @@ * to unlocked to prevent new IO from executing in case the lock * is in a state where it cannot be fenced. */ - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); rdev->lock_state = TCMUR_DEV_LOCK_UNLOCKED; - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); } int tcmu_get_lock_tag(struct tcmu_device *dev, uint16_t *tag) @@ -323,16 +323,16 @@ if (rdev->failover_type != TCMUR_DEV_FAILOVER_EXPLICIT) return 0; - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (!(rdev->flags & TCMUR_DEV_FLAG_IS_OPEN)) { /* * Return tmp error until the recovery thread is able to * start up. */ - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); return TCMU_STS_BUSY; } - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); retry: ret = rhandler->get_lock_tag(dev, tag); @@ -415,10 +415,10 @@ */ reopen = false; - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (rdev->lock_lost || !(rdev->flags & TCMUR_DEV_FLAG_IS_OPEN)) reopen = true; - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); retry: tcmu_dev_dbg(dev, "lock call state %d retries %d. tag %hu reopen %d\n", @@ -436,13 +436,13 @@ } } - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (rdev->lock_state == TCMUR_DEV_LOCK_READ_LOCKING) { - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); ret = TCMU_STS_OK; goto done; } - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); ret = rhandler->lock(dev, tag); if (ret == TCMU_STS_FENCED) { @@ -476,7 +476,7 @@ tcmu_dev_flush_ring(dev); /* TODO: set UA based on bgly's patches */ - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (ret != TCMU_STS_OK) { rdev->lock_state = TCMUR_DEV_LOCK_UNLOCKED; tcmu_dev_info(dev, "Lock acquisition unsuccessful\n"); @@ -498,7 +498,7 @@ tcmu_cfgfs_dev_exec_action(dev, "block_dev", 0); - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); return ret; } @@ -512,23 +512,23 @@ if (!rhandler->get_lock_state) return; - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); if (!(rdev->flags & TCMUR_DEV_FLAG_IS_OPEN)) { tcmu_dev_dbg(dev, "device closed.\n"); state = TCMUR_DEV_LOCK_UNKNOWN; goto check_state; } - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); state = rhandler->get_lock_state(dev); - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); check_state: if (rdev->lock_state == TCMUR_DEV_LOCK_WRITE_LOCKED && state != TCMUR_DEV_LOCK_WRITE_LOCKED) { tcmu_dev_dbg(dev, "Updated out of sync lock state.\n"); __tcmu_notify_lock_lost(dev); } - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); } void tcmur_dev_set_private(struct tcmu_device *dev, void *private) @@ -549,10 +549,10 @@ { struct tcmur_device *rdev = tcmu_dev_get_private(dev); - pthread_mutex_lock(&rdev->state_lock); + pthread_mutex_lock(&rdev->rdev_lock); rdev->cmd_timed_out_cnt++; __tcmu_notify_conn_lost(dev); - pthread_mutex_unlock(&rdev->state_lock); + pthread_mutex_unlock(&rdev->rdev_lock); tcmu_report_event(dev); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/tcmur_device.h new/tcmu-runner-1.6.0/tcmur_device.h --- old/tcmu-runner-1.5.4/tcmur_device.h 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/tcmur_device.h 2022-10-14 03:14:14.000000000 +0200 @@ -48,6 +48,9 @@ pthread_t cmdproc_thread; + /* General lock for the members from "flags" to "pending_uas" */ + pthread_mutex_t rdev_lock; + /* TCMUR_DEV flags */ uint32_t flags; uint8_t failover_type; @@ -63,8 +66,6 @@ bool lock_lost; uint8_t lock_state; - /* General lock for lock state, thread, dev state, etc */ - pthread_mutex_t state_lock; int pending_uas; /* @@ -75,13 +76,14 @@ struct tcmu_io_queue work_queue; struct tcmu_track_aio track_queue; - pthread_spinlock_t lock; /* protects concurrent updates to mailbox */ pthread_mutex_t caw_lock; /* for atomic CAW operation */ uint32_t format_progress; pthread_mutex_t format_lock; /* for atomic format operations */ int cmd_time_out; + + pthread_spinlock_t cmds_list_lock; /* protects cmds_list */ struct list_head cmds_list; }; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/tcmu-runner-1.5.4/tcmur_work.c new/tcmu-runner-1.6.0/tcmur_work.c --- old/tcmu-runner-1.5.4/tcmur_work.c 2021-03-19 04:24:59.000000000 +0100 +++ new/tcmu-runner-1.6.0/tcmur_work.c 2022-10-14 03:14:14.000000000 +0200 @@ -41,16 +41,11 @@ static void __tcmur_flush_work(struct tcmur_work *work) { - char pname[TCMU_THREAD_NAME_LEN]; - - if (pthread_getname_np(pthread_self(), pname, TCMU_THREAD_NAME_LEN)) - return; - /* * The event work thread may need to do a handler reopen * call and try to flush itself. Just ignore. */ - if (!strcmp(pname, "ework-thread")) + if (__tcmu_is_ework_thread) return; /* @@ -79,6 +74,7 @@ struct private *p = data; tcmu_set_thread_name("ework-thread", NULL); + __tcmu_is_ework_thread = 1; p->work_fn(p->data);