From patchwork Fri Aug 11 03:29:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Yi X-Patchwork-Id: 9894837 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 36B5860236 for ; Fri, 11 Aug 2017 03:30:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25A2728BD3 for ; Fri, 11 Aug 2017 03:30:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A67A28C0B; Fri, 11 Aug 2017 03:30:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1854C28BCB for ; Fri, 11 Aug 2017 03:30:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752283AbdHKD3r (ORCPT ); Thu, 10 Aug 2017 23:29:47 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34258 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752262AbdHKD3q (ORCPT ); Thu, 10 Aug 2017 23:29:46 -0400 Received: by mail-pf0-f194.google.com with SMTP id t86so2350333pfe.1 for ; Thu, 10 Aug 2017 20:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=xji+bjvJOBvnYV6hjOsLgcsHI29p/hSB93TTiodW9is=; b=pfKDM9TB8YeRdSns3fVWKbDbdFK6esOXtPLTb1/GE30nuHhEXNPBipNvpfWFYJqbmJ KxTob1uiGhygOR5oZ7AfsRhkkCbvCx3asF9aM3ZPycOqjpd0Os4+L7oLmryYoVQmny38 b5FZ3lqXx3bfvHZx5DBhYFNycbn9S/ROcbSyu+FdZpiEedsG22F7NMhUtIEFODTMTwQ5 Zlwnr/BM9rB0u15YY+n26qIiZNR5Coc76zfD8Tfcsw84d7tC/ZiWUIj0oLALS/mH9bYp qWucTCeNoQF0wjVjI7OUEWArnz+64xrpiTPLHGhC/4lfwIxE58xsvNetVi8rBlItk2Kz USeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=xji+bjvJOBvnYV6hjOsLgcsHI29p/hSB93TTiodW9is=; b=jZzIr5dUUy6hklIa/Mb94wI3JVCF9GErzrRfwseQctOjVVysqRlSbURzZEvpA5VwNK PO3PWd4MG0gGzb2L1YARvVtx6iIvdpUQd7Eym0gPyLsGSBHDX2kTEQvyyz6kzC/lnK7W 2Zf1H19h1PrhWPB8sS1yjDR1/HWhUwBP/Qi+a4R2SNpgUIfIvBVu9b2hN0Vgy8HMpttc 8IutedQy8ZwA5M09/K4Rb6C3hWcACgSwjHUvv4Y+JY69EfjbCmqq+ZFLC/rswstbOzJj F8gGYHSA5QaxKc3L8jz5cRct7h72qHiZKfdSdHI4f39gtM6L9CwZ55Xk60SaBCtV8XP6 00Zw== X-Gm-Message-State: AHYfb5i0d2yFOejSnWxoMO9OWIuIsYOQo06uetFAaOvLK4gJ5mP60K5z CvX89jS1p5nG/8vREus= X-Received: by 10.99.115.23 with SMTP id o23mr13857217pgc.355.1502422186305; Thu, 10 Aug 2017 20:29:46 -0700 (PDT) Received: from [10.12.12.133] (125-227-147-112.HINET-IP.hinet.net. [125.227.147.112]) by smtp.gmail.com with ESMTPSA id z127sm13002873pfb.64.2017.08.10.20.29.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Aug 2017 20:29:45 -0700 (PDT) To: nab@linux-iscsi.org Cc: target-devel@vger.kernel.org From: Jiang Yi Subject: [PATCH] Do not return error for UNMAP if length is zero Message-ID: <96d354b7-32ca-63c5-5d16-ffefa0a280f8@gmail.com> Date: Fri, 11 Aug 2017 11:29:44 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 Content-Language: en-US Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/target/target_core_file.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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;