target: don't call an unmap callback if a range length is zero
authorAndrei Vagin <avagin@openvz.org>
Wed, 13 Dec 2017 21:55:13 +0000 (13:55 -0800)
committerNicholas Bellinger <nab@linux-iscsi.org>
Fri, 12 Jan 2018 23:07:28 +0000 (15:07 -0800)
If a length of a range is zero, it means there is nothing to unmap
and we can skip this range.

Here is one more reason, why we have to skip such ranges.  An unmap
callback calls file_operations->fallocate(), but the man page for the
fallocate syscall says that fallocate(fd, mode, offset, let) returns
EINVAL, if len is zero. It means that file_operations->fallocate() isn't
obligated to handle zero ranges too.

Signed-off-by: Andrei Vagin <avagin@openvz.org>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_sbc.c

index 750a04ed0e93acdd7c705335af49a688c7e57930..b054682e974f91c05fa4c640e314e69397646a93 100644 (file)
@@ -1216,9 +1216,11 @@ sbc_execute_unmap(struct se_cmd *cmd)
                        goto err;
                }
 
-               ret = ops->execute_unmap(cmd, lba, range);
-               if (ret)
-                       goto err;
+               if (range) {
+                       ret = ops->execute_unmap(cmd, lba, range);
+                       if (ret)
+                               goto err;
+               }
 
                ptr += 16;
                size -= 16;