@@ -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;
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(-)