Hello community,

here is the log from the commit of package tgt for openSUSE:Factory checked in 
at 2019-02-19 12:00:09
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/tgt (Old)
 and      /work/SRC/openSUSE:Factory/.tgt.new.28833 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "tgt"

Tue Feb 19 12:00:09 2019 rev:35 rq:676927 version:1.0.74

Changes:
--------
--- /work/SRC/openSUSE:Factory/tgt/tgt.changes  2018-08-15 10:36:59.604138401 
+0200
+++ /work/SRC/openSUSE:Factory/.tgt.new.28833/tgt.changes       2019-02-19 
12:00:38.753130681 +0100
@@ -1,0 +2,36 @@
+Fri Feb 15 23:19:22 UTC 2019 - ldun...@suse.com
+
+- Update to version v1.0.74 from version v1.0.60:
+  * tgt 1.0.74
+  * AIO backing store now reports a list of supported opcodes
+  * tgt 1.0.73
+  * Update tgt-admin
+  * fix build w/newer glibc
+  * Display nop_count and and nop_interval
+  * Quote $backing_store variable in system(), execute() and
+    backtick-calls
+  * Buffer size is stored in struct concat_buf.size field, so
+    use that instead of BUFSIZE since buffer size can be more
+    than BUFSIZE. Also, remove BUFSIZE since its not used anymore.
+  * tgt 1.0.72
+  * smc: fix snprintf warnings with gcc7
+
+  This removed the tarball v1.0.60.tar.gz, and replaced it
+  with v1.0.74.tar.gz, which can now be gotten using the new
+  _service file. This also updated the SPEC file with the new
+  version number and the different patch set. Remaining
+  patches were renumbered.
+
+  This following patches were UPDATED (refreshed):
+  * tgt-fix-build
+  * tgt-include-sys-macros-for-major.patch
+
+  The following patches were REMOVED (no longer needed):
+  * tgt-handle-access-of-a-target-that-has-been-removed
+  * tgt-missing-module-directory-not-an-error
+  * tgt-compare-pointer-to-null.patch
+
+  And the following patch was added (and submitted upstream):
+  * tgt-Fix-gcc7-string-truncation-warnings.patch
+
+-------------------------------------------------------------------

Old:
----
  tgt-compare-pointer-to-null.patch
  tgt-handle-access-of-a-target-that-has-been-removed
  tgt-missing-module-directory-not-an-error
  v1.0.60.tar.gz

New:
----
  _service
  _servicedata
  tgt-Fix-gcc7-string-truncation-warnings.patch
  v1.0.74.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ tgt.spec ++++++
--- /var/tmp/diff_new_pack.zTA7cT/_old  2019-02-19 12:00:39.949130054 +0100
+++ /var/tmp/diff_new_pack.zTA7cT/_new  2019-02-19 12:00:39.949130054 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package tgt
 #
-# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -22,22 +22,20 @@
 %endif
 
 Name:           tgt
-Version:        1.0.60
+Version:        1.0.74
 Release:        0
 Summary:        Generic Linux target framework (tgt)
 License:        GPL-2.0-only
 Group:          System/Daemons
 Url:            http://stgt.sourceforge.net/
-Source:         https://github.com/fujita/tgt/archive/v%{version}.tar.gz
+Source:         https://github.com/fujita/%{name}/archive/v%{version}.tar.gz
 Source1:        %{name}d.service
 Source3:        %{name}.services
 Source4:        sysconfig.%{name}
-Patch2:         %{name}-fix-build
-Patch3:         setup-tgt-conf-d.patch
-Patch4:         %{name}-handle-access-of-a-target-that-has-been-removed
-Patch5:         %{name}-missing-module-directory-not-an-error
-Patch6:         %{name}-include-sys-macros-for-major.patch
-Patch7:         %{name}-compare-pointer-to-null.patch
+Patch1:         %{name}-fix-build
+Patch2:         setup-tgt-conf-d.patch
+Patch3:         %{name}-include-sys-macros-for-major.patch
+Patch4:         %{name}-Fix-gcc7-string-truncation-warnings.patch
 BuildRequires:  docbook-xsl-stylesheets
 BuildRequires:  libaio-devel
 BuildRequires:  libxslt
@@ -58,12 +56,10 @@
 
 %prep
 %setup -q
+%patch1 -p1
 %patch2 -p1
 %patch3 -p1
 %patch4 -p1
-%patch5 -p1
-%patch6 -p1
-%patch7 -p1
 
 %build
 %ifarch ppc ppc64 ppc64le
@@ -107,6 +103,7 @@
 %doc doc/README.rbd doc/tmf.txt
 %doc %_defaultdocdir/%name/examples
 %doc %_defaultdocdir/%name/html
+%{_mandir}/man5/*
 %{_mandir}/man8/*
 
 %changelog

++++++ _service ++++++
<services>
  <service name="tar_scm" mode="disabled">
    <param name="scm">git</param>
    <param name="url">https://github.com/fujita/tgt.git</param>
    <param name="subdir"></param>
    <param name="filename">tgt</param>
    <param name="versionformat">v1.0.74</param>
    <param name="revision">1.0.74</param>
    <param name="changesgenerate">enable</param>
  </service>
  <service name="recompress" mode="disabled">
    <param name="file">*tgt*.tar</param>
    <param name="compression">gz</param>
  </service>
  <service name="set_version" mode="disabled"/>
</services>
++++++ _servicedata ++++++
<servicedata>
<service name="tar_scm">
                <param name="url">https://github.com/fujita/tgt.git</param>
              <param 
name="changesrevision">f33f6b73d3bfac8b3e44f068d02f90627b407f4e</param></service></servicedata>++++++
 tgt-Fix-gcc7-string-truncation-warnings.patch ++++++
>From 2de8bebe132e3b998bf4848d0bd22b50367ad4b8 Mon Sep 17 00:00:00 2001
From: Lee Duncan <ldun...@suse.com>
Date: Sat, 16 Feb 2019 10:29:19 -0800
Subject: [PATCH] Fix gcc7 string truncation warnings.

Mostly, this is fixed by checking the legnth
of strings to be copied, making sure they will
fit where they are being copied to, and
erroring out if the copy will not fit. Then
we can just use strcpy(). We also use
scsi_sprintf() for copying to SCSI structures,
with their special requirements.
---
 usr/mgmt.c   | 9 +++++++--
 usr/smc.c    | 9 +++++++--
 usr/spc.c    | 9 ++++++---
 usr/tgtadm.c | 6 +++++-
 4 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/usr/mgmt.c b/usr/mgmt.c
index de23f1469494..00a4e08c01dc 100644
--- a/usr/mgmt.c
+++ b/usr/mgmt.c
@@ -797,11 +797,16 @@ int ipc_init(void)
                goto close_lock_fd;
        }
 
-       snprintf(mgmt_path, sizeof(mgmt_path), "%s.%d", path, control_port);
+       snprintf(mgmt_path, sizeof(mgmt_path) - 1, "%s.%d", path, control_port);
+       if (strlen(mgmt_path) > (sizeof(addr.sun_path) - 1)) {
+               eprintf("managment path too long: %s\n", mgmt_path);
+               goto close_ipc_fd;
+       }
        unlink(mgmt_path);
        memset(&addr, 0, sizeof(addr));
        addr.sun_family = AF_LOCAL;
-       strncpy(addr.sun_path, mgmt_path, sizeof(addr.sun_path));
+       /* no need for strncpy because we already checked length */
+       strcpy(addr.sun_path, mgmt_path);
 
        err = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
        if (err) {
diff --git a/usr/smc.c b/usr/smc.c
index b80aba272909..bbc7b7fc7b88 100644
--- a/usr/smc.c
+++ b/usr/smc.c
@@ -732,8 +732,13 @@ static tgtadm_err config_slot(struct scsi_lu *lu, struct 
tmp_param *tmp)
                        adm_err = TGTADM_SUCCESS;
                        break;
                }
-               strncpy(s->barcode, tmp->barcode, sizeof(s->barcode));
-               strncpy(s->volume_tag, tmp->volume_tag, sizeof(s->volume_tag));
+               if (strlen(tmp->barcode) > sizeof(s->barcode) ||
+                   strlen(tmp->volume_tag) > sizeof(s->volume_tag)) {
+                       eprintf("barcode or volume tag too large?");
+                       break;
+               }
+               strcpy(s->barcode, tmp->barcode);
+               strcpy(s->volume_tag, tmp->volume_tag);
                set_slot_full(s, 0, NULL);
                adm_err = TGTADM_SUCCESS;
                break;
diff --git a/usr/spc.c b/usr/spc.c
index 82a6ec9ee863..902d5bf4a60b 100644
--- a/usr/spc.c
+++ b/usr/spc.c
@@ -289,9 +289,12 @@ int spc_inquiry(int host_no, struct scsi_cmd *cmd)
                data[7] = 0x02;
 
                memset(data + 8, 0x20, 28);
-               strncpy((char *)data + 8, attrs->vendor_id, VENDOR_ID_LEN);
-               strncpy((char *)data + 16, attrs->product_id, PRODUCT_ID_LEN);
-               strncpy((char *)data + 32, attrs->product_rev, PRODUCT_REV_LEN);
+               scsi_sprintf((char *)data + 8, VENDOR_ID_LEN, "%-*s",
+                            VENDOR_ID_LEN, attrs->vendor_id);
+               scsi_sprintf((char *)data + 16, PRODUCT_ID_LEN, "%-*s",
+                            PRODUCT_ID_LEN, attrs->product_id);
+               scsi_sprintf((char *)data + 32, PRODUCT_REV_LEN, "%-*s",
+                            PRODUCT_REV_LEN, attrs->product_rev);
 
                desc = (uint16_t *)(data + 58);
                for (i = 0; i < ARRAY_SIZE(attrs->version_desc); i++)
diff --git a/usr/tgtadm.c b/usr/tgtadm.c
index 5572c3888a80..cb3eb1cd126f 100644
--- a/usr/tgtadm.c
+++ b/usr/tgtadm.c
@@ -224,7 +224,11 @@ static int ipc_mgmt_connect(int *fd)
        snprintf(mgmt_path, sizeof(mgmt_path), "%s.%d",
                         path, control_port);
 
-       strncpy(addr.sun_path, mgmt_path, sizeof(addr.sun_path));
+       if (strlen(mgmt_path) > (sizeof(addr.sun_path) - 1)) {
+               eprintf("management path too long: %s\n", mgmt_path);
+               return EINVAL;
+       }
+       strcpy(addr.sun_path, mgmt_path);
 
        err = connect(*fd, (struct sockaddr *) &addr, sizeof(addr));
        if (err < 0)
-- 
2.16.4

++++++ tgt-fix-build ++++++
--- /var/tmp/diff_new_pack.zTA7cT/_old  2019-02-19 12:00:40.013130020 +0100
+++ /var/tmp/diff_new_pack.zTA7cT/_new  2019-02-19 12:00:40.017130018 +0100
@@ -16,22 +16,13 @@
 index e29826c..31067e8 100644
 --- a/usr/Makefile
 +++ b/usr/Makefile
-@@ -32,12 +32,15 @@ INCLUDES += -I.
+@@ -40,6 +40,9 @@ INCLUDES += -I.
  
  CFLAGS += -D_GNU_SOURCE
  CFLAGS += $(INCLUDES)
-+ifneq ($(OPTFLAGS),)
++ifneq ($(OPTFAGS),)
 +CFLAGS += $(OPTFLAGS)
++endif
  ifneq ($(DEBUG),)
  CFLAGS += -g -O0 -ggdb -rdynamic
  else
- CFLAGS += -g -O2 -fno-strict-aliasing
- endif
- CFLAGS += -Wall -Wstrict-prototypes -fPIC
-+endif
- CFLAGS += -DTGT_VERSION=\"$(VERSION)$(EXTRAVERSION)\"
- CFLAGS += -DBSDIR=\"$(DESTDIR)$(libdir)/backing-store\"
- 
--- 
-1.8.1.4
-

++++++ tgt-include-sys-macros-for-major.patch ++++++
--- /var/tmp/diff_new_pack.zTA7cT/_old  2019-02-19 12:00:40.021130016 +0100
+++ /var/tmp/diff_new_pack.zTA7cT/_new  2019-02-19 12:00:40.025130014 +0100
@@ -1,9 +1,9 @@
 diff -aurp tgt-1.0.60.orig/usr/bs_sg.c tgt-1.0.60/usr/bs_sg.c
 --- tgt-1.0.60.orig/usr/bs_sg.c        2015-07-01 17:10:39.000000000 -0700
 +++ tgt-1.0.60/usr/bs_sg.c     2018-08-11 18:03:25.489712435 -0700
-@@ -36,6 +36,7 @@
- #include <sys/stat.h>
+@@ -38,6 +38,7 @@
  #include <sys/epoll.h>
+ #include <sys/sysmacros.h>
  #include <scsi/sg.h>
 +#include <sys/sysmacros.h>
  

++++++ v1.0.60.tar.gz -> v1.0.74.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/Makefile new/tgt-1.0.74/Makefile
--- old/tgt-1.0.60/Makefile     2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/Makefile     2018-11-03 12:12:50.000000000 +0100
@@ -1,4 +1,4 @@
-VERSION ?= 1.0.60
+VERSION ?= 1.0.74
 
 CHECK_CC = cgcc
 CHECK_CC_FLAGS = '$(CHECK_CC) -Wbitwise -Wno-return-void -no-compile $(ARCH)'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/doc/Makefile new/tgt-1.0.74/doc/Makefile
--- old/tgt-1.0.60/doc/Makefile 2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/doc/Makefile 2018-11-03 12:12:50.000000000 +0100
@@ -2,7 +2,8 @@
 docdir ?= $(PREFIX)/share/doc/tgt
 
 MANPAGES = manpages/tgtadm.8 manpages/tgt-admin.8 manpages/tgtimg.8 \
-               manpages/tgt-setup-lun.8 manpages/tgtd.8
+               manpages/tgt-setup-lun.8 manpages/tgtd.8 \
+               manpages/targets.conf.5
 
 DOCS = README.iscsi README.iser \
            README.lu_configuration README.mmc tmf.txt \
@@ -21,8 +22,9 @@
 
 .PHONY: install
 install: $(MANPAGES) $(DOCS)
-       install -d -m 755 $(DESTDIR)$(mandir)/man8
-       install -m 644 $(MANPAGES) $(DESTDIR)$(mandir)/man8
+       install -d -m 755 $(DESTDIR)$(mandir)/man8 $(DESTDIR)$(mandir)/man5
+       install -m 644 $(filter %.8,$(MANPAGES)) $(DESTDIR)$(mandir)/man8
+       install -m 644 $(filter %.5,$(MANPAGES)) $(DESTDIR)$(mandir)/man5
        install -d -m 755 $(DESTDIR)$(docdir)
        install -m 644 $(DOCS) $(DESTDIR)$(docdir)
        install -d -m 755 $(DESTDIR)$(docdir)/html
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/doc/targets.conf.5.xml 
new/tgt-1.0.74/doc/targets.conf.5.xml
--- old/tgt-1.0.60/doc/targets.conf.5.xml       2015-07-02 02:10:39.000000000 
+0200
+++ new/tgt-1.0.74/doc/targets.conf.5.xml       2018-11-03 12:12:50.000000000 
+0100
@@ -50,8 +50,7 @@
         <listitem>
           <para>
            Defines a the start of a target definition. IQN is an ISCSI 
Qualified
-           Name such as "iqn.2001-04.com.example:storage1". See "ISCSI" on
-           Wikipedia for more information on IQNs.
+           Name such as "iqn.2001-04.com.example:storage1".
           </para>
          <para>
            Within this block should be target-level directives, as
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/doc/tgtd.8.xml 
new/tgt-1.0.74/doc/tgtd.8.xml
--- old/tgt-1.0.60/doc/tgtd.8.xml       2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/doc/tgtd.8.xml       2018-11-03 12:12:50.000000000 +0100
@@ -173,7 +173,7 @@
 
   <refsect1><title>SEE ALSO</title>
     <para>
-      tgtadm(8), tgt-admin(8), tgtimg(8), tgt-setup-lun(8).
+      targets.conf(5), tgtadm(8), tgt-admin(8), tgtimg(8), tgt-setup-lun(8).
       <ulink url="http://stgt.sourceforge.net/"/>
     </para>
   </refsect1>
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/scripts/tgt-admin 
new/tgt-1.0.74/scripts/tgt-admin
--- old/tgt-1.0.60/scripts/tgt-admin    2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/scripts/tgt-admin    2018-11-03 12:12:50.000000000 +0100
@@ -488,7 +488,7 @@
        }
 
        if ($can_alloc == 1 &&
-          ($bstype =~ "rbd" || (-e $backing_store && ! -d $backing_store))) {
+          ($bstype =~ "glfs" || $bstype =~ "rbd" || (-e $backing_store && ! -d 
$backing_store))) {
                my @exec_commands;
                my $device_type;
                my $bs_type;
@@ -585,7 +585,7 @@
                        my $sg_readcap;
                        my %direct_params;
                        if ($direct_store == 1) {
-                               $sg_inq=`sg_inq $backing_store`;
+                               $sg_inq=`sg_inq "$backing_store"`;
                                if ($sg_inq=~m {
                                        Vendor\ identification:\s+?(.*?)\n
                                        \s+Product\ identification:\s+(.*?)\n
@@ -608,7 +608,7 @@
                                        }
                                }
 
-                               $sg_inq=`sg_inq -p 0xb0 $backing_store`;
+                               $sg_inq=`sg_inq -p 0xb0 "$backing_store"`;
                                if ($sg_inq=~m {
                                        Optimal\ transfer\ length\ 
granularity:\s+?(\d+).*?\n
                                        \s+Maximum\ transfer\ 
length:\s+?(\d+).*?\n
@@ -623,7 +623,7 @@
                                        }
                                }
 
-                               $sg_readcap=`sg_readcap -16 $backing_store`;
+                               $sg_readcap=`sg_readcap -16 "$backing_store"`;
                                if ($sg_readcap=~ m {
                                        Logical\ block\ length=(\d+).*?\n
                                        \s+Logical\ blocks\ per\ physical\ 
block\ exponent=(\d+).*?\n
@@ -725,7 +725,7 @@
                if (length $bsopts) { $bsopts = "--bsopts $bsopts" };
                if (length $bsoflags) { $bsoflags = "--bsoflags $bsoflags" };
                if (length $block_size) { $block_size = "--blocksize 
$block_size" };
-               execute("tgtadm -C $control_port --lld $driver --op new --mode 
logicalunit --tid $next_tid --lun $lun -b $backing_store $device_type $bs_type 
$bsopts $bsoflags $block_size");
+               execute("tgtadm -C $control_port --lld $driver --op new --mode 
logicalunit --tid $next_tid --lun $lun -b \"$backing_store\" $device_type 
$bs_type $bsopts $bsoflags $block_size");
 
                # Commands should be executed in order
                my @execute_last;
@@ -952,7 +952,12 @@
                my @acl_information = show_target_info($current_target, 
"acl_information");
                if (scalar(@acl_information) != 1 || $acl_information[0] ne 
"ALL") {
                        foreach my $ini_address (@acl_information) {
-                               print "\tinitiator-address $ini_address\n";
+                               # determine here if acl is an IP or IQN
+                               if ( $ini_address =~ /^[0-9,.E]+$/ ) {
+                                       print "\tinitiator-address 
$ini_address\n";
+                               } else {
+                                       print "\tinitiator-name $ini_address\n";
+                               }
                        }
                }
                print "</target>\n\n";
@@ -1347,7 +1352,7 @@
        # Check if userspace uses this device
        my $lsof_check = check_exe("lsof");
        if ($lsof_check ne 1) {
-               system("lsof $backing_store >/dev/null 2>&1");
+               system("lsof \"$backing_store\" >/dev/null 2>&1");
                my $exit_value  = $? >> 8;
                if ($exit_value eq 0) {
                        execute("# Device $backing_store is used (already tgtd 
target?).");
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/scripts/tgt-setup-lun 
new/tgt-1.0.74/scripts/tgt-setup-lun
--- old/tgt-1.0.60/scripts/tgt-setup-lun        2015-07-02 02:10:39.000000000 
+0200
+++ new/tgt-1.0.74/scripts/tgt-setup-lun        2018-11-03 12:12:50.000000000 
+0100
@@ -24,7 +24,7 @@
 {
        name=$(basename $0);
        echo "usage:";
-       echo -e "\t$name -n tgt_name -d dev -b bs_name -t transport -C 
control_port [initiator_IP1 initiator_IP2 ...]";
+       echo -e "\t$name -n tgt_name -d dev -b bs_name -B block_size -t 
transport -C control_port [initiator_IP1 initiator_IP2 ...]";
        echo "defaults:";
        echo -e "\tbacking store: rdwr";
        echo -e "\ttransport: iscsi";
@@ -34,6 +34,8 @@
        echo -e "\t$name -n tgt-1 -d /dev/sdb1 192.168.1.2";
        echo -e "\t$name -n tgt-2 -d /tmp/null -b null -t iser";
        echo -e "\t$name -n tgt-3 -d ~/disk3.bin -b rdwr 192.168.1.2 
192.168.1.3";
+       echo -e "WARNING:"
+       echo -e "\tPlease remember to set blocksize to 4096 for newer Advanced 
Format (4K) disks larger than 2TB. Otherwise, your existing filesystems will 
not be readable."
 }
 
 verify_params()
@@ -197,7 +199,7 @@
 lld_name="iscsi"
 control_port=""
 
-while getopts "d:n:b:t:h:C:" opt
+while getopts "d:n:b:B:t:h:C:" opt
 do
        case ${opt} in
        d)
@@ -206,6 +208,8 @@
                tgt_name=$OPTARG;;
        b)
                bs_type=$OPTARG;;
+       B)
+               block_size=$OPTARG;;
        t)
                lld_name=$OPTARG;;
         C)
@@ -277,7 +281,10 @@
        echo "Setting backing store type: $bs_type"
        bs_opt="-E $bs_type"
 fi
-$TGTADM --lld $lld_name --op new --mode logicalunit --tid $tid --lun $lun -b 
$dev $bs_opt
+if [ $block_size ]; then
+       blksize_opt="--blocksize $block_size"
+fi
+$TGTADM --lld $lld_name --op new --mode logicalunit --tid $tid --lun $lun -b 
$dev $bs_opt $blksize_opt
 res=$?
 
 if [ $res -ne 0 ]; then
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/Makefile new/tgt-1.0.74/usr/Makefile
--- old/tgt-1.0.60/usr/Makefile 2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/Makefile 2018-11-03 12:12:50.000000000 +0100
@@ -5,7 +5,7 @@
 CFLAGS += -DUSE_SIGNALFD
 endif
 
-ifneq ($(shell test -e /usr/include/sys/timerfd.h && echo 1),)
+ifneq ($(shell test -n $(shell find /usr/include -name "timerfd.h" | head -n1) 
&& echo 1),)
 CFLAGS += -DUSE_TIMERFD
 endif
 
@@ -45,7 +45,7 @@
 else
 CFLAGS += -g -O2 -fno-strict-aliasing
 endif
-CFLAGS += -Wall -Wstrict-prototypes -fPIC
+CFLAGS += -Wall -Wstrict-prototypes -Werror -fPIC
 CFLAGS += -DTGT_VERSION=\"$(VERSION)$(EXTRAVERSION)\"
 CFLAGS += -DBSDIR=\"$(DESTDIR)$(libdir)/backing-store\"
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/bs.c new/tgt-1.0.74/usr/bs.c
--- old/tgt-1.0.60/usr/bs.c     2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/bs.c     2018-11-03 12:12:50.000000000 +0100
@@ -263,7 +263,8 @@
 
        dir = opendir(BSDIR);
        if (dir == NULL) {
-               eprintf("could not open backing-store module directory %s\n",
+               /* not considered an error if there are no modules */
+               dprintf("could not open backing-store module directory %s\n",
                        BSDIR);
        } else {
                struct dirent *dirent;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/bs_aio.c new/tgt-1.0.74/usr/bs_aio.c
--- old/tgt-1.0.60/usr/bs_aio.c 2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/bs_aio.c 2018-11-03 12:12:50.000000000 +0100
@@ -407,6 +407,7 @@
 {
        struct bs_aio_info *info = BS_AIO_I(lu);
 
+       tgt_event_del(info->evt_fd);
        close(info->evt_fd);
        io_destroy(info->ctx);
 }
@@ -423,6 +424,49 @@
 
 __attribute__((constructor)) static void register_bs_module(void)
 {
+       unsigned char opcodes[] = {
+               ALLOW_MEDIUM_REMOVAL,
+               COMPARE_AND_WRITE,
+               FORMAT_UNIT,
+               INQUIRY,
+               MAINT_PROTOCOL_IN,
+               MODE_SELECT,
+               MODE_SELECT_10,
+               MODE_SENSE,
+               MODE_SENSE_10,
+               ORWRITE_16,
+               PERSISTENT_RESERVE_IN,
+               PERSISTENT_RESERVE_OUT,
+               PRE_FETCH_10,
+               PRE_FETCH_16,
+               READ_10,
+               READ_12,
+               READ_16,
+               READ_6,
+               READ_CAPACITY,
+               RELEASE,
+               REPORT_LUNS,
+               REQUEST_SENSE,
+               RESERVE,
+               SEND_DIAGNOSTIC,
+               SERVICE_ACTION_IN,
+               START_STOP,
+               SYNCHRONIZE_CACHE,
+               SYNCHRONIZE_CACHE_16,
+               TEST_UNIT_READY,
+               UNMAP,
+               VERIFY_10,
+               VERIFY_12,
+               VERIFY_16,
+               WRITE_10,
+               WRITE_12,
+               WRITE_16,
+               WRITE_6,
+               WRITE_VERIFY,
+               WRITE_VERIFY_12,
+               WRITE_VERIFY_16
+       };
+       bs_create_opcode_map(&aio_bst, opcodes, ARRAY_SIZE(opcodes));
        register_backingstore_template(&aio_bst);
 }
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/bs_rdwr.c new/tgt-1.0.74/usr/bs_rdwr.c
--- old/tgt-1.0.60/usr/bs_rdwr.c        2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/bs_rdwr.c        2018-11-03 12:12:50.000000000 +0100
@@ -65,7 +65,6 @@
        int result = SAM_STAT_GOOD;
        uint8_t key;
        uint16_t asc;
-       uint32_t info = 0;
        char *tmpbuf;
        size_t blocksize;
        uint64_t offset = cmd->offset;
@@ -149,7 +148,6 @@
                        for (pos = 0; pos < length && *spos++ == *dpos++;
                             pos++)
                                ;
-                       info = pos;
                        result = SAM_STAT_CHECK_CONDITION;
                        key = MISCOMPARE;
                        asc = ASC_MISCOMPARE_DURING_VERIFY_OPERATION;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/bs_sg.c new/tgt-1.0.74/usr/bs_sg.c
--- old/tgt-1.0.60/usr/bs_sg.c  2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/bs_sg.c  2018-11-03 12:12:50.000000000 +0100
@@ -32,9 +32,11 @@
 #include <linux/fs.h>
 #include <linux/major.h>
 #include <sys/ioctl.h>
+#include <sys/sysmacros.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/epoll.h>
+#include <sys/sysmacros.h>
 #include <scsi/sg.h>
 
 #include "bsg.h" /* Copied from include/linux/bsg.h */
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/bs_sheepdog.c 
new/tgt-1.0.74/usr/bs_sheepdog.c
--- old/tgt-1.0.60/usr/bs_sheepdog.c    2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/bs_sheepdog.c    2018-11-03 12:12:50.000000000 +0100
@@ -273,9 +273,6 @@
        /* unix domain socket */
        char uds_path[UNIX_PATH_MAX];
 
-       /* if the opened VDI is a snapshot, write commands cannot be issued */
-       int is_snapshot;
-
        /*
         * maximum length of fd_list_head: nr_iothreads + 1
         * (+ 1 is for main thread)
@@ -286,11 +283,15 @@
        struct list_head fd_list_head;
        pthread_rwlock_t fd_list_lock;
 
-       uint32_t min_dirty_data_idx;
-       uint32_t max_dirty_data_idx;
-
        struct sheepdog_inode inode;
        pthread_rwlock_t inode_lock;
+
+       pthread_mutex_t inode_version_mutex;
+       uint64_t inode_version;
+
+       struct list_head inflight_list_head;
+       pthread_mutex_t inflight_list_mutex;
+       pthread_cond_t inflight_list_cond;
 };
 
 static inline int is_data_obj_writeable(struct sheepdog_inode *inode,
@@ -656,37 +657,83 @@
 
 static int reload_inode(struct sheepdog_access_info *ai, int is_snapshot)
 {
-       int ret, need_reload = 0;
+       int ret = 0, need_reload = 0;
        char tag[SD_MAX_VDI_TAG_LEN];
        uint32_t vid;
 
+       static __thread uint64_t inode_version;
+
+       pthread_mutex_lock(&ai->inode_version_mutex);
+
+       if (inode_version != ai->inode_version) {
+               /* some other threads reloaded inode */
+               inode_version = ai->inode_version;
+               goto ret;
+       }
+
        if (is_snapshot) {
                memset(tag, 0, sizeof(tag));
 
                ret = find_vdi_name(ai, ai->inode.name, CURRENT_VDI_ID, tag,
                                    &vid, 0);
-               if (ret)
-                       return -1;
+               if (ret) {
+                       ret = -1;
+                       goto ret;
+               }
 
                ret = read_object(ai, (char *)&ai->inode, vid_to_vdi_oid(vid),
                                  ai->inode.nr_copies,
                                  offsetof(struct sheepdog_inode, data_vdi_id),
                                  0, &need_reload);
-               if (ret)
-                       return -1;
+               if (ret) {
+                       ret = -1;
+                       goto ret;
+               }
        } else {
                ret = read_object(ai, (char *)&ai->inode,
                                  vid_to_vdi_oid(ai->inode.vdi_id),
                                  ai->inode.nr_copies, SD_INODE_SIZE, 0,
                                  &need_reload);
-               if (ret)
-                       return -1;
+               if (ret) {
+                       ret = -1;
+                       goto ret;
+               }
+
+               if (!!ai->inode.snap_ctime) {
+                       /*
+                        * This is a case like below:
+                        * take snapshot -> write something -> failover
+                        *
+                        * Because invalidated inode is readonly and latest
+                        * working VDI can have COWed objects, we need to
+                        * resolve VID and reload its entire inode object.
+                        */
+                       memset(tag, 0, sizeof(tag));
+
+                       ret = find_vdi_name(ai, ai->inode.name, CURRENT_VDI_ID,
+                                           tag, &vid, 0);
+                       if (ret) {
+                               ret = -1;
+                               goto ret;
+                       }
+
+                       ret = read_object(ai, (char *)&ai->inode,
+                                         vid_to_vdi_oid(vid),
+                                         ai->inode.nr_copies, SD_INODE_SIZE, 0,
+                                         &need_reload);
+                       if (ret) {
+                               ret = -1;
+                               goto ret;
+                       }
+               }
        }
 
-       ai->min_dirty_data_idx = UINT32_MAX;
-       ai->max_dirty_data_idx = 0;
+       inode_version++;
+       ai->inode_version = inode_version;
 
-       return 0;
+ret:
+       pthread_mutex_unlock(&ai->inode_version_mutex);
+       return ret;
 }
 
 static int read_write_object(struct sheepdog_access_info *ai, char *buf,
@@ -700,6 +747,7 @@
        unsigned int wlen, rlen;
        int ret;
 
+retry:
        memset(&hdr, 0, sizeof(hdr));
 
        hdr.proto_ver = SD_PROTO_VER;
@@ -741,6 +789,17 @@
        case SD_RES_READONLY:
                *need_reload = 1;
                return 0;
+       case SD_RES_NO_OBJ:
+               if (!write && oid & (UINT64_C(1) << 63))
+                       /*
+                        * sheepdog doesn't provide a mechanism of metadata
+                        * transaction, so tgt can see an inconsistent state
+                        * like this (old working VDI became snapshot already
+                        * but an inode object of new working VDI isn't
+                        * created yet).
+                        */
+                       goto retry;
+               return -1;
        default:
                eprintf("%s (oid: %" PRIx64 ", old_oid: %" PRIx64 ")\n",
                        sd_strerror(rsp->result), oid, old_oid);
@@ -798,14 +857,11 @@
        }
 }
 
-static int update_inode(struct sheepdog_access_info *ai)
+static int update_inode(struct sheepdog_access_info *ai, uint32_t min, 
uint32_t max)
 {
        int ret = 0, need_reload_inode = 0;
        uint64_t oid = vid_to_vdi_oid(ai->inode.vdi_id);
-       uint32_t min, max, offset, data_len;
-
-       min = ai->min_dirty_data_idx;
-       max = ai->max_dirty_data_idx;
+       uint32_t offset, data_len;
 
        if (max < min)
                goto end;
@@ -834,8 +890,6 @@
        }
 
 end:
-       ai->min_dirty_data_idx = UINT32_MAX;
-       ai->max_dirty_data_idx = 0;
 
        return ret;
 }
@@ -877,6 +931,8 @@
        int need_update_inode = 0, need_reload_inode;
        int nr_copies = ai->inode.nr_copies;
        int need_write_lock, check_idx;
+       int read_reload_snap = 0;
+       uint32_t min_dirty_data_idx = UINT32_MAX, max_dirty_data_idx = 0;
 
        goto do_req;
 
@@ -884,7 +940,7 @@
        pthread_rwlock_unlock(&ai->inode_lock); /* unlock current read lock */
 
        pthread_rwlock_wrlock(&ai->inode_lock);
-       ret = reload_inode(ai, 0);
+       ret = reload_inode(ai, read_reload_snap);
        if (ret) {
                eprintf("failed to reload in read path\n");
                goto out;
@@ -958,12 +1014,12 @@
                                }
 
                                if (create) {
-                                       ai->min_dirty_data_idx =
+                                       min_dirty_data_idx =
                                                min_t(uint32_t, idx,
-                                                     ai->min_dirty_data_idx);
-                                       ai->max_dirty_data_idx =
+                                                     min_dirty_data_idx);
+                                       max_dirty_data_idx =
                                                max_t(uint32_t, idx,
-                                                     ai->max_dirty_data_idx);
+                                                     max_dirty_data_idx);
                                        ai->inode.data_vdi_id[idx] = vid;
 
                                        need_update_inode = 1;
@@ -980,6 +1036,8 @@
                                        dprintf("reload in read path for not"\
                                                " written area\n");
                                        size = orig_size;
+                                       read_reload_snap =
+                                               need_reload_inode == 1;
                                        goto reload_in_read_path;
                                }
                        }
@@ -991,6 +1049,7 @@
                        if (need_reload_inode) {
                                dprintf("reload in ordinal read path\n");
                                size = orig_size;
+                               read_reload_snap = need_reload_inode == 1;
                                goto reload_in_read_path;
                        }
                }
@@ -1006,7 +1065,7 @@
        }
 
        if (need_update_inode)
-               ret = update_inode(ai);
+               ret = update_inode(ai, min_dirty_data_idx, max_dirty_data_idx);
 
 out:
        pthread_rwlock_unlock(&ai->inode_lock);
@@ -1067,8 +1126,6 @@
        uint32_t vid = 0;
        char *orig_filename;
 
-       uint32_t snapid = -1;
-       char tag[SD_MAX_VDI_TAG_LEN + 1];
        char vdi_name[SD_MAX_VDI_LEN + 1];
        char *saveptr = NULL, *result;
        enum {
@@ -1077,11 +1134,9 @@
                EXPECT_HOST,
                EXPECT_PORT,
                EXPECT_VDI,
-               EXPECT_TAG_OR_SNAP,
                EXPECT_NOTHING,
        } parse_state = EXPECT_PROTO;
 
-       memset(tag, 0, sizeof(tag));
        memset(vdi_name, 0, sizeof(vdi_name));
 
        orig_filename = strdup(filename);
@@ -1094,11 +1149,7 @@
         * expected form of filename:
         *
         * unix:<path_of_unix_domain_socket>:<vdi>
-        * unix:<path_of_unix_domain_socket>:<vdi>:<tag>
-        * unix:<path_of_unix_domain_socket>:<vdi>:<snapid>
         * tcp:<host>:<port>:<vdi>
-        * tcp:<host>:<port>:<vdi>:<tag>
-        * tcp:<host>:<port>:<vdi>:<snapid>
         */
 
        result = strtok_r(filename, ":", &saveptr);
@@ -1143,21 +1194,6 @@
                        break;
                case EXPECT_VDI:
                        strncpy(vdi_name, result, SD_MAX_VDI_LEN);
-                       parse_state = EXPECT_TAG_OR_SNAP;
-                       break;
-               case EXPECT_TAG_OR_SNAP:
-                       len = strlen(result);
-                       for (i = 0; i < len; i++) {
-                               if (!isdigit(result[i])) {
-                                       /* result is a tag */
-                                       strncpy(tag, result,
-                                               SD_MAX_VDI_TAG_LEN);
-                                       goto trans_to_expect_nothing;
-                               }
-                       }
-
-                       snapid = atoi(result);
-trans_to_expect_nothing:
                        parse_state = EXPECT_NOTHING;
                        break;
                case EXPECT_NOTHING:
@@ -1173,8 +1209,7 @@
                }
        } while ((result = strtok_r(NULL, ":", &saveptr)) != NULL);
 
-       if (parse_state != EXPECT_NOTHING &&
-           parse_state != EXPECT_TAG_OR_SNAP) {
+       if (parse_state != EXPECT_NOTHING) {
                eprintf("invalid VDI path of sheepdog: %s (state: %d)\n",
                        orig_filename, parse_state);
                ret = -1;
@@ -1207,27 +1242,22 @@
 
        close(fd);              /* we don't need this connection */
 
-       if (snapid == -1)
-               dprintf("tag: %s\n", tag);
-       else
-               dprintf("snapid: %d\n", snapid);
-
        dprintf("VDI name: %s\n", vdi_name);
-       ai->is_snapshot = !(snapid == -1) || strlen(tag);
-       ret = find_vdi_name(ai, vdi_name, snapid == -1 ? 0 : snapid, tag, &vid,
-                           ai->is_snapshot);
+       ret = find_vdi_name(ai, vdi_name, 0, "", &vid, 0);
        if (ret)
                goto out;
 
-       ai->min_dirty_data_idx = UINT32_MAX;
-       ai->max_dirty_data_idx = 0;
-
        ret = read_object(ai, (char *)&ai->inode, vid_to_vdi_oid(vid),
                          0, SD_INODE_SIZE, 0, &need_reload);
        if (ret)
                goto out;
 
        ret = 0;
+
+       INIT_LIST_HEAD(&ai->inflight_list_head);
+       pthread_mutex_init(&ai->inflight_list_mutex, NULL);
+       pthread_cond_init(&ai->inflight_list_cond, NULL);
+
 out:
        strcpy(filename, orig_filename);
        free(orig_filename);
@@ -1262,67 +1292,39 @@
        *asc = ASC_READ_ERROR;
 }
 
-static int create_branch(struct sheepdog_access_info *ai)
-{
-       struct sheepdog_vdi_req hdr;
-       struct sheepdog_vdi_rsp *rsp = (struct sheepdog_vdi_rsp *)&hdr;
-       unsigned int wlen = 0, rlen;
-       int ret, need_reload = 0;
-
-       ret = pthread_rwlock_wrlock(&ai->inode_lock);
-       if (ret) {
-               eprintf("failed to get inode lock %s\n", strerror(ret));
-               return -1;
-       }
-
-       if (!ai->is_snapshot)
-               /* check again the snapshot flag to avoid race condition */
-               goto out;
-
-       memset(&hdr, 0, sizeof(hdr));
-       hdr.opcode = SD_OP_DEL_VDI;
-       hdr.vdi_id = ai->inode.vdi_id;
-       hdr.flags = SD_FLAG_CMD_WRITE;
-       wlen = SD_MAX_VDI_LEN;
-       rlen = 0;
-       hdr.data_length = wlen;
-
-       ret = do_req(ai, (struct sheepdog_req *)&hdr, ai->inode.name,
-                    &wlen, &rlen);
-       if (ret) {
-               eprintf("deleting snapshot VDI for creating branch failed\n");
-               goto out;
-       }
+struct inflight_thread {
+       unsigned long min_idx, max_idx;
+       struct list_head list;
+};
 
-       memset(&hdr, 0, sizeof(hdr));
-       hdr.opcode = SD_OP_NEW_VDI;
-       hdr.vdi_id = ai->inode.vdi_id;
+static void inflight_block(struct sheepdog_access_info *ai,
+                          struct inflight_thread *myself)
+{
+       struct inflight_thread *inflight;
 
-       hdr.flags = SD_FLAG_CMD_WRITE;
-       wlen = SD_MAX_VDI_LEN;
-       rlen = 0;
-       hdr.data_length = wlen;
-       hdr.vdi_size = ai->inode.vdi_size;
-       ret = do_req(ai, (struct sheepdog_req *)&hdr, ai->inode.name,
-                    &wlen, &rlen);
-       if (ret) {
-               eprintf("creating new VDI for creating branch failed\n");
-               goto out;
-       }
+       pthread_mutex_lock(&ai->inflight_list_mutex);
 
-       ret = read_object(ai, (char *)&ai->inode, vid_to_vdi_oid(rsp->vdi_id),
-                         ai->inode.nr_copies, SD_INODE_SIZE, 0, &need_reload);
-       if (ret) {
-               eprintf("reloading new inode object failed");
-               goto out;
+retry:
+       list_for_each_entry(inflight, &ai->inflight_list_head, list) {
+               if (!(myself->max_idx < inflight->min_idx ||
+                     inflight->max_idx < myself->min_idx)) {
+                       pthread_cond_wait(&ai->inflight_list_cond,
+                                         &ai->inflight_list_mutex);
+                       goto retry;
+               }
        }
 
-       ai->is_snapshot = 0;
-       dprintf("creating branch from snapshot, new VDI ID: %x\n", rsp->vdi_id);
-out:
-       pthread_rwlock_unlock(&ai->inode_lock);
+       list_add_tail(&myself->list, &ai->inflight_list_head);
+       pthread_mutex_unlock(&ai->inflight_list_mutex);
+}
+ void inflight_release(struct sheepdog_access_info *ai,
+                            struct inflight_thread *myself)
+{
+       pthread_mutex_lock(&ai->inflight_list_mutex);
+       list_del(&myself->list);
+       pthread_mutex_unlock(&ai->inflight_list_mutex);
 
-       return ret;
+       pthread_cond_signal(&ai->inflight_list_cond);
 }
 
 static void bs_sheepdog_request(struct scsi_cmd *cmd)
@@ -1336,6 +1338,13 @@
        struct sheepdog_access_info *ai =
                (struct sheepdog_access_info *)(info + 1);
 
+       uint32_t object_size = (UINT32_C(1) << ai->inode.block_size_shift);
+       struct inflight_thread myself;
+       int inflight = 0;
+
+       memset(&myself, 0, sizeof(myself));
+       INIT_LIST_HEAD(&myself.list);
+
        switch (cmd->scb[0]) {
        case SYNCHRONIZE_CACHE:
        case SYNCHRONIZE_CACHE_16:
@@ -1347,18 +1356,14 @@
        case WRITE_10:
        case WRITE_12:
        case WRITE_16:
-               if (ai->is_snapshot) {
-                       ret = create_branch(ai);
-                       if (ret) {
-                               eprintf("creating writable VDI from"\
-                                       " snapshot failed\n");
-                               set_medium_error(&result, &key, &asc);
+               length = scsi_get_out_length(cmd);
 
-                               break;
-                       }
-               }
+               myself.min_idx = cmd->offset / object_size;
+               myself.max_idx = (cmd->offset + length + (object_size - 1))
+                       / object_size;
+               inflight_block(ai, &myself);
+               inflight = 1;
 
-               length = scsi_get_out_length(cmd);
                ret = sd_io(ai, 1, scsi_get_out_buffer(cmd),
                            length, cmd->offset);
 
@@ -1370,6 +1375,13 @@
        case READ_12:
        case READ_16:
                length = scsi_get_in_length(cmd);
+
+               myself.min_idx = cmd->offset / object_size;
+               myself.max_idx = (cmd->offset + length + (object_size - 1))
+                       / object_size;
+               inflight_block(ai, &myself);
+               inflight = 1;
+
                ret = sd_io(ai, 0, scsi_get_in_buffer(cmd),
                            length, cmd->offset);
                if (ret)
@@ -1389,6 +1401,9 @@
                        cmd, cmd->scb[0], ret, length, cmd->offset);
                sense_data_build(cmd, key, asc);
        }
+
+       if (inflight)
+               inflight_release(ai, &myself);
 }
 
 static int bs_sheepdog_open(struct scsi_lu *lu, char *path,
@@ -1426,6 +1441,7 @@
        INIT_LIST_HEAD(&ai->fd_list_head);
        pthread_rwlock_init(&ai->fd_list_lock, NULL);
        pthread_rwlock_init(&ai->inode_lock, NULL);
+       pthread_mutex_init(&ai->inode_version_mutex, NULL);
 
        return bs_thread_open(info, bs_sheepdog_request, nr_iothreads);
 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/bs_ssc.c new/tgt-1.0.74/usr/bs_ssc.c
--- old/tgt-1.0.60/usr/bs_ssc.c 2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/bs_ssc.c 2018-11-03 12:12:50.000000000 +0100
@@ -684,8 +684,6 @@
 
 static void bs_ssc_close(struct scsi_lu *lu)
 {
-       struct ssc_info *ssc;
-       ssc = dtype_priv(lu);
        dprintf("##### Close #####\n");
        close(lu->fd);
 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/iscsi/conn.c 
new/tgt-1.0.74/usr/iscsi/conn.c
--- old/tgt-1.0.60/usr/iscsi/conn.c     2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/iscsi/conn.c     2018-11-03 12:12:50.000000000 +0100
@@ -151,6 +151,22 @@
                        else
                                iscsi_free_task(task);
                        break;
+               case ISCSI_OP_NOOP_IN:
+                       /* NOOP_IN req is allocated within iscsi_tcp
+                        * by a direct call to the transport
+                        * allocation routine, unaccounted in the
+                        * connection refcount and not added to
+                        * task_list, hence it should be freed when
+                        * it's done by a similar direct call.
+                        *
+                        * We're overprotective here by checking tp's
+                        * free_task pointer, avoiding interference
+                        * with iser (I'm unsure if it's relevant
+                        * though).
+                        */
+                       if (task->conn->tp->free_task)
+                               task->conn->tp->free_task(task);
+                       break;
                case ISCSI_OP_NOOP_OUT:
                case ISCSI_OP_LOGOUT:
                case ISCSI_OP_SCSI_TMFUNC:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/iscsi/iscsi_tcp.c 
new/tgt-1.0.74/usr/iscsi/iscsi_tcp.c
--- old/tgt-1.0.60/usr/iscsi/iscsi_tcp.c        2015-07-02 02:10:39.000000000 
+0200
+++ new/tgt-1.0.74/usr/iscsi/iscsi_tcp.c        2018-11-03 12:12:50.000000000 
+0100
@@ -508,6 +508,8 @@
        struct iscsi_tcp_connection *tcp_conn = TCP_CONN(conn);
 
        tgt_event_del(tcp_conn->fd);
+       conn->state = STATE_CLOSE;
+       tcp_conn->nop_interval = 0;
        return 0;
 }
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/iscsi/iscsid.c 
new/tgt-1.0.74/usr/iscsi/iscsid.c
--- old/tgt-1.0.60/usr/iscsi/iscsid.c   2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/iscsi/iscsid.c   2018-11-03 12:12:50.000000000 +0100
@@ -266,11 +266,12 @@
                        struct iscsi_connection *ent, *next;
 
                        /* do session reinstatement */
-
+                       session_get(session);
                        list_for_each_entry_safe(ent, next, &session->conn_list,
                                                 clist) {
                                conn_close(ent);
                        }
+                       session_put(session);
 
                        session = NULL;
                } else if (req->tsih != session->tsih) {
@@ -1227,6 +1228,9 @@
 
        list_del(&task->c_siblings);
 
+       if (task_opcode(task) == ISCSI_OP_SCSI_CMD)
+               list_del(&task->c_hlist);
+
        conn->tp->free_data_buf(conn, scsi_get_in_buffer(&task->scmd));
        conn->tp->free_data_buf(conn, scsi_get_out_buffer(&task->scmd));
 
@@ -1251,7 +1255,6 @@
 {
        target_cmd_done(&task->scmd);
 
-       list_del(&task->c_hlist);
        iscsi_free_task(task);
 }
 
@@ -1595,7 +1598,6 @@
        struct iscsi_hdr *req = (struct iscsi_hdr *) &task->req;
        uint32_t cmd_sn;
        struct iscsi_task *ent;
-       int err;
 
        dprintf("%x %x %x\n", be32_to_cpu(req->statsn), session->exp_cmd_sn,
                req->opcode);
@@ -1609,7 +1611,7 @@
                session->exp_cmd_sn = ++cmd_sn;
 
                /* Should we close the connection... */
-               err = iscsi_task_execute(task);
+               iscsi_task_execute(task);
 
                if (list_empty(&session->pending_cmd_list))
                        return 0;
@@ -1958,13 +1960,28 @@
 static int iscsi_task_tx_done(struct iscsi_connection *conn)
 {
        struct iscsi_task *task = conn->tx_task;
-       int err;
        uint8_t op;
 
        op = task->req.opcode & ISCSI_OPCODE_MASK;
        switch (op) {
        case ISCSI_OP_SCSI_CMD:
-               err = iscsi_scsi_cmd_tx_done(conn);
+               iscsi_scsi_cmd_tx_done(conn);
+               break;
+       case ISCSI_OP_NOOP_IN:
+               /* NOOP_IN req is allocated within iscsi_tcp
+                * by a direct call to the transport
+                * allocation routine, unaccounted in the
+                * connection refcount and not added to
+                * task_list, hence it should be freed when
+                * it's done by a similar direct call.
+                *
+                * We're overprotective here by checking tp's
+                * free_task pointer, avoiding interference
+                * with iser (I'm unsure if it's relevant
+                * though).
+                */
+               if (task->conn->tp->free_task)
+                       task->conn->tp->free_task(task);
                break;
        case ISCSI_OP_NOOP_OUT:
        case ISCSI_OP_LOGOUT:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/iscsi/iscsid.h 
new/tgt-1.0.74/usr/iscsi/iscsid.h
--- old/tgt-1.0.60/usr/iscsi/iscsid.h   2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/iscsi/iscsid.h   2018-11-03 12:12:50.000000000 +0100
@@ -60,6 +60,8 @@
 
 #define sid_to_tsih(sid) ((sid) >> 48)
 
+#define task_opcode(task) ((task)->req.opcode & ISCSI_OPCODE_MASK)
+
 struct iscsi_pdu {
        struct iscsi_hdr bhs;
        void *ahs;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/iscsi/iser.c 
new/tgt-1.0.74/usr/iscsi/iser.c
--- old/tgt-1.0.60/usr/iscsi/iser.c     2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/iscsi/iser.c     2018-11-03 12:12:50.000000000 +0100
@@ -2196,7 +2196,6 @@
        struct iser_task *prev_task = NULL;
        struct iser_task *task = NULL;
        int num_reqs = 0;
-       int err;
 
        if (unlikely(conn->h.state != STATE_FULL)) {
                dprintf("conn:%p closing, ignoring rdma_rd\n", conn);
@@ -2220,7 +2219,7 @@
        if (prev_task) {
                prev_task->rdmad.send_wr.next = NULL;
                /* submit the chain of rdma-rd requests, start from the first */
-               err = iser_post_send(conn, first_wr, num_reqs);
+               iser_post_send(conn, first_wr, num_reqs);
 
                /* ToDo: error handling */
        }
@@ -2234,7 +2233,6 @@
        struct iser_task *task;
        struct iser_work_req *cur_send_wr;
        int num_reqs = 0;
-       int err;
 
        if (unlikely(conn->h.state == STATE_CLOSE)) {
                dprintf("conn:%p closing, ignoring tx\n", conn);
@@ -2267,7 +2265,7 @@
        if (prev_task) {
                prev_task->txd.send_wr.next = NULL;
                /* submit the chain of rdma-wr & tx reqs, start from the first 
*/
-               err = iser_post_send(conn, first_wr, num_reqs);
+               iser_post_send(conn, first_wr, num_reqs);
 
                /* ToDo: error handling */
        }
@@ -2280,7 +2278,6 @@
        struct iser_task *prev_task = NULL;
        struct iser_task *task;
        int num_recv_bufs = 0;
-       int err;
 
        if (unlikely(conn->h.state != STATE_FULL)) {
                dprintf("conn:%p closing, ignoring post recv\n", conn);
@@ -2304,7 +2301,7 @@
        if (prev_task) {
                prev_task->rxd.recv_wr.next = NULL;
                /* post the chain of recv buffers, start from the first */
-               err = iser_post_recv(conn, first_task, num_recv_bufs);
+               iser_post_recv(conn, first_task, num_recv_bufs);
 
                /* ToDo: error handling */
        }
@@ -2802,7 +2799,7 @@
                        conn, conn->h.state);
                break;
        }
-       return 0;
+       return err;
 }
 
 static void iser_rx_handler(struct iser_work_req *rxd)
@@ -3583,6 +3580,9 @@
        int err = 0;
        char *q;
 
+       if (!p)
+           return 0;
+
        while (*p) {
                if (!strncmp(p, lld_param_port, strlen(lld_param_port))) {
                        short int port_val;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/iscsi/session.c 
new/tgt-1.0.74/usr/iscsi/session.c
--- old/tgt-1.0.60/usr/iscsi/session.c  2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/iscsi/session.c  2018-11-03 12:12:50.000000000 +0100
@@ -98,6 +98,7 @@
        if (conn->initiator_alias) {
                session->initiator_alias = strdup(conn->initiator_alias);
                if (!session->initiator_alias) {
+                       free(session->initiator);
                        free(session);
                        return -ENOMEM;
                }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/iscsi/target.c 
new/tgt-1.0.74/usr/iscsi/target.c
--- old/tgt-1.0.60/usr/iscsi/target.c   2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/iscsi/target.c   2018-11-03 12:12:50.000000000 +0100
@@ -369,9 +369,11 @@
 struct iscsi_target *target_find_by_name(const char *name)
 {
        struct iscsi_target *target;
+       char *tname;
 
        list_for_each_entry(target, &iscsi_targets_list, tlist) {
-               if (!strcmp(tgt_targetname(target->tid), name))
+               tname = tgt_targetname(target->tid);
+               if (tname && !strcmp(tname, name))
                        return target;
        }
 
@@ -408,9 +410,11 @@
        }
 
        list_for_each_entry_safe(session, stmp, &target->sessions_list, slist) {
+               session_get(session);
                list_for_each_entry_safe(conn, ctmp, &session->conn_list, 
clist) {
                        conn_close(conn);
                }
+               session_put(session);
        }
 
        if (!list_empty(&target->sessions_list)) {
@@ -670,6 +674,13 @@
        return adm_err;
 }
 
+static tgtadm_err show_nop_info(struct iscsi_target *target, struct concat_buf 
*b)
+{
+       concat_printf(b, "nop_interval=%d\n", target->nop_interval);
+       concat_printf(b, "nop_count=%d\n", target->nop_count);
+       return TGTADM_SUCCESS;
+}
+
 static tgtadm_err show_redirect_info(struct iscsi_target *target, struct 
concat_buf *b)
 {
        tgtadm_err adm_err = TGTADM_SUCCESS;
@@ -714,8 +725,10 @@
                        adm_err = show_redirect_callback(target, b);
                else if (strlen(target->redirect_info.addr))
                        adm_err = show_redirect_info(target, b);
-               else
+               else {
+                       adm_err = show_nop_info(target, b);
                        adm_err = show_iscsi_param(target->session_param, b);
+               }
                break;
        case MODE_SESSION:
                adm_err = iscsi_target_show_session(target, sid, b);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/parser.c new/tgt-1.0.74/usr/parser.c
--- old/tgt-1.0.60/usr/parser.c 2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/parser.c 2018-11-03 12:12:50.000000000 +0100
@@ -30,7 +30,6 @@
 {
        char *meta;
        int argc = 0;
-       unsigned long long ret;
 
        if (!p)
                return 1;
@@ -69,16 +68,16 @@
                        args[argc].to = s + len;
                        break;
                case 'd':
-                       ret = strtol(s, &args[argc].to, 0);
+                       strtol(s, &args[argc].to, 0);
                        goto num;
                case 'u':
-                       ret = strtoul(s, &args[argc].to, 0);
+                       strtoul(s, &args[argc].to, 0);
                        goto num;
                case 'o':
-                       ret = strtoul(s, &args[argc].to, 8);
+                       strtoul(s, &args[argc].to, 8);
                        goto num;
                case 'x':
-                       ret = strtoul(s, &args[argc].to, 16);
+                       strtoul(s, &args[argc].to, 16);
                num:
                        if (args[argc].to == args[argc].from)
                                return 0;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/sbc.c new/tgt-1.0.74/usr/sbc.c
--- old/tgt-1.0.60/usr/sbc.c    2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/sbc.c    2018-11-03 12:12:50.000000000 +0100
@@ -245,6 +245,7 @@
        int ret;
        uint64_t lba;
        uint32_t tl;
+       size_t blocksize = 1 << cmd->dev->blk_shift;
        unsigned char key = ILLEGAL_REQUEST;
        uint16_t asc = ASC_LUN_NOT_SUPPORTED;
        struct scsi_lu *lu = cmd->dev;
@@ -259,6 +260,9 @@
                goto sense;
        }
 
+       lba = scsi_rw_offset(cmd->scb);
+       tl  = scsi_rw_count(cmd->scb);
+
        switch (cmd->scb[0]) {
        case READ_10:
        case READ_12:
@@ -306,6 +310,17 @@
                        asc = ASC_INVALID_FIELD_IN_CDB;
                        goto sense;
                }
+               /* Fail of DataOut is neither ==0 or ==blocksize */
+               if (scsi_get_out_length(cmd) &&
+                   blocksize != scsi_get_out_length(cmd)) {
+                       key = ILLEGAL_REQUEST;
+                       asc = ASC_PARAMETER_LIST_LENGTH_ERR;
+                       goto sense;
+               }
+               /* TL == 0 means all LBAs until end of device */
+               if (tl == 0)
+                       tl = (lu->size >> cmd->dev->blk_shift) - lba;
+
                break;
        }
 
@@ -331,9 +346,6 @@
                }
        }
 
-       lba = scsi_rw_offset(cmd->scb);
-       tl  = scsi_rw_count(cmd->scb);
-
        /* Verify that we are not doing i/o beyond
           the end-of-lun */
        if (tl) {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/smc.c new/tgt-1.0.74/usr/smc.c
--- old/tgt-1.0.60/usr/smc.c    2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/smc.c    2018-11-03 12:12:50.000000000 +0100
@@ -161,9 +161,9 @@
        i = 12;
        if (voltag) {
                if (s->volume_tag[0] != ' ' && s->volume_tag[0] != '\0')
-                       snprintf((char *)&data[i], 32, "%-32s", s->volume_tag);
+                       scsi_sprintf((char *)&data[i], 32, "%-32s", 
s->volume_tag);
                else if (s->barcode[0] != ' ' && s->barcode[0] != '\0')
-                       snprintf((char *)&data[i], 32, "%-32s", s->barcode);
+                       scsi_sprintf((char *)&data[i], 32, "%-32s", s->barcode);
                else
                        memset(&data[i], 0x20, 32);
 
@@ -181,7 +181,12 @@
                data[i + 3] = 34;       /* Length */
                snprintf((char *)&data[i + 4], 9, "%-8s", attr->vendor_id);
                snprintf((char *)&data[i + 12], 17, "%-16s", attr->product_id);
-               snprintf((char *)&data[i + 28], 11, "%-10s", attr->scsi_sn);
+               {
+                       char buf[sizeof(attr->scsi_sn) + 1];
+                       memset(buf, 0, sizeof(buf));
+                       snprintf(buf, sizeof(buf), "%-s", attr->scsi_sn);
+                       memcpy((char *)&data[i + 28], buf, 10);
+               }
        }
 
        return determine_element_sz(dvcid, voltag);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/spc.c new/tgt-1.0.74/usr/spc.c
--- old/tgt-1.0.60/usr/spc.c    2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/spc.c    2018-11-03 12:12:50.000000000 +0100
@@ -2069,7 +2069,7 @@
        lu->attrs.sense_format = 0;
 
        snprintf(lu->attrs.vendor_id, sizeof(lu->attrs.vendor_id),
-                "%-16s", VENDOR_ID);
+                "%-s", VENDOR_ID);
        snprintf(lu->attrs.product_rev, sizeof(lu->attrs.product_rev),
                 "%s", "0001");
        snprintf(lu->attrs.scsi_id, sizeof(lu->attrs.scsi_id),
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/target.c new/tgt-1.0.74/usr/target.c
--- old/tgt-1.0.60/usr/target.c 2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/target.c 2018-11-03 12:12:50.000000000 +0100
@@ -29,6 +29,7 @@
 #include <unistd.h>
 #include <sys/socket.h>
 #include <sys/time.h>
+#include <ctype.h>
 
 #include "list.h"
 #include "util.h"
@@ -611,7 +612,7 @@
        lu->blk_shift = 0;
        if (blocksize) {
                unsigned int bsize;
-               unsigned int bshift;
+               int bshift;
 
                dprintf("blocksize=%s\n", blocksize);
                bsize = strtoul(blocksize, NULL, 0);
@@ -2138,6 +2139,13 @@
                }
        };
 
+       for (p = targetname; *p != '\0'; p++) {
+           if (isalnum(*p) || *p == ':' || *p == '.' || *p == '-')
+               continue;
+           eprintf("Target name %s has invalid characters\n", targetname);
+           return TGTADM_INVALID_REQUEST;
+       }
+
        if (!targetname)
                return TGTADM_INVALID_REQUEST;
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/tgtadm.c new/tgt-1.0.74/usr/tgtadm.c
--- old/tgt-1.0.60/usr/tgtadm.c 2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/tgtadm.c 2018-11-03 12:12:50.000000000 +0100
@@ -44,8 +44,6 @@
 #define NO_LOGGING
 #include "log.h"
 
-#define BUFSIZE 4096
-
 static const char program_name[] = "tgtadm";
 static int debug;
 
@@ -992,7 +990,7 @@
                              portalOps);
 
        if (b.err) {
-               eprintf("BUFSIZE (%d bytes) isn't long enough\n", BUFSIZE);
+               eprintf("BUFSIZE (%zu bytes) isn't long enough\n", b.size + 1);
                return EINVAL;
        }
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/tgtd.c new/tgt-1.0.74/usr/tgtd.c
--- old/tgt-1.0.60/usr/tgtd.c   2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/tgtd.c   2018-11-03 12:12:50.000000000 +0100
@@ -310,7 +310,7 @@
        pos = arg;
        str_spacecpy(&pos, cmd);
        if (strchr(cmd, ' ')) {
-               while (pos != '\0')
+               while (*pos != '\0')
                        argv[i++] = strsep(&pos, " ");
        } else
                argv[i++] = arg;
@@ -604,7 +604,7 @@
        }
 
        err = oom_adjust();
-       if (err && getuid() == 0)
+       if (err && (errno != EACCES) && getuid() == 0)
                exit(1);
 
        err = nr_file_adjust();
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/util.h new/tgt-1.0.74/usr/util.h
--- old/tgt-1.0.60/usr/util.h   2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/util.h   2018-11-03 12:12:50.000000000 +0100
@@ -148,7 +148,7 @@
        unsigned long long ull_val;                     \
        ull_val = strtoull(str, &ptr, 0);               \
        val = (typeof(val)) ull_val;                    \
-       if (errno || ptr == str)                        \
+       if (ull_val == ULLONG_MAX || ptr == str)        \
                ret = EINVAL;                           \
        else if (val != ull_val)                        \
                ret = ERANGE;                           \
@@ -240,4 +240,18 @@
                (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
 }
 
+static inline int scsi_sprintf(char *str, size_t size, const char *format, ...)
+{
+       va_list args;
+       char buf[size + 1];
+       int n;
+
+       memset(buf, 0, sizeof(buf));
+       va_start(args, format);
+       n = snprintf(buf, sizeof(buf), format, args);
+       va_end(args);
+       memcpy(str, buf, size);
+       return n;
+}
+
 #endif
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/tgt-1.0.60/usr/work.c new/tgt-1.0.74/usr/work.c
--- old/tgt-1.0.60/usr/work.c   2015-07-02 02:10:39.000000000 +0200
+++ new/tgt-1.0.74/usr/work.c   2018-11-03 12:12:50.000000000 +0100
@@ -59,7 +59,7 @@
        unsigned int n = 0;
        int err;
 
-       if (timer_pending)
+       if (timer_pending || timer_fd[1] < 0)
                return;
 
        timer_pending = 1;


Reply via email to