diff mbox

Do not return error for UNMAP if length is zero

Message ID 96d354b7-32ca-63c5-5d16-ffefa0a280f8@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jiang Yi Aug. 11, 2017, 3:29 a.m. UTC
Hi Nic,

The function fd_execute_unmap() in target_core_file.c calles 

ret = file->f_op->fallocate(file, mode, pos, len);

Some filesystems implement fallocate() to return error if length is zero (e.g. btrfs) but according to SCSI Block Commands spec UNMAP should return success for zero length.

By the way, I think we should call vfs_fallocate() instead of invoking the function pointers of struct file_operations.

vfs_fallocate() also returns error if length is zero.
 
So I propose a patch:

Signed-off-by: Jiang Yi <jiangyilism@gmail.com>
---
 drivers/target/target_core_file.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index 24cf11d..8e69399 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -482,6 +482,10 @@  fd_execute_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb)
 	struct inode *inode = file->f_mapping->host;
 	int ret;
 
+	if (!nolb) {
+		return 0;
+	}
+
 	if (cmd->se_dev->dev_attrib.pi_prot_type) {
 		ret = fd_do_prot_unmap(cmd, lba, nolb);
 		if (ret)
@@ -512,7 +516,7 @@  fd_execute_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb)
 		if (!file->f_op->fallocate)
 			return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 
-		ret = file->f_op->fallocate(file, mode, pos, len);
+		ret = vfs_fallocate(file, mode, pos, len);
 		if (ret < 0) {
 			pr_warn("FILEIO: fallocate() failed: %d\n", ret);
 			return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;