Skip to contentSkip to conversation

target: don't call an unmap callback if a range length is zero

PATCH Applied Andrei Vagin 2 participants 2 messages Dec 13, 2017 – Jan 12, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target: don't call an unmap callback if a range length is zero

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.

---
 drivers/target/target_core_sbc.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/target/target_core_sbc.c +5 -3
index 750a04ed0e93..b054682e974f 100644
@@ -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;
Signature · 1 line
2.13.6
#1 lore raw

Hi Andrei,

Apologies for the delayed follow up.

Quoted 9 lines · Andrei Vagin

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.

Quoted 5 lines
---
 drivers/target/target_core_sbc.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Applied.

Thank you.