From patchwork Mon Jan 14 23:37:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrick Wong X-Patchwork-Id: 1024865 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="yp86LVTk"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43dqd6656jz9sBQ for ; Tue, 15 Jan 2019 10:37:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727068AbfANXhO (ORCPT ); Mon, 14 Jan 2019 18:37:14 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:36172 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726745AbfANXhO (ORCPT ); Mon, 14 Jan 2019 18:37:14 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0ENT7xn182342; Mon, 14 Jan 2019 23:37:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2018-07-02; bh=6qpznR23oeDiPg2AGVx9HZYii9uBlH+YzVr5oI16cfk=; b=yp86LVTkSel6qMalH8moWwYFzAUdyjP/9Bfum4ZHCBzWBxDsdDTHRYImOo5UTD77gQIY 6y96/OfWYhPM4wpqX+F894M5cBeNQZgCyCV6v93HNWD/B5Zusk58HCjkNQWzw3HJs3OG xMc9UFyyQejWBI36yyqPO6ubWgWh4iwyU21DuoMIqhpuHH8tO5Lntk5WuPHDVfSvTjcH 9wMju0jR4ZKRQ0j/TvRtAK7xnmi/LTuZD8/x2AR17chd2i9zzdUxo2miKIOS8A1K3ZWL CxnIPT701cB9NSfcfFhR1Zk+1tjw4zuhIZZKzK2wMFdmYPzbegFMl/XSBqEGJi7CXBK+ gg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2pybjs0vr8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Jan 2019 23:37:11 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0ENbARi020633 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Jan 2019 23:37:10 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x0ENbAiF026878; Mon, 14 Jan 2019 23:37:10 GMT Received: from localhost (/10.159.238.130) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 14 Jan 2019 15:37:09 -0800 Date: Mon, 14 Jan 2019 15:37:08 -0800 From: "Darrick J. Wong" To: "Theodore Ts'o" Cc: linux-ext4 Subject: [PATCH] libext2fs: revert "try to always use PUNCH_HOLE for unix_discard" Message-ID: <20190114233708.GA20465@magnolia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9136 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=762 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901140180 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Darrick J. Wong Revert bcca9876a3428c10417c660b78933e6e70e8a5f5, because fallocate(PUNCH_HOLE) on block devices was changed to use zeroout instead of discard shortly after block device fallocate was merged. zeroout isn't necessarily a "drop storage" operation like discard is, so we prefer to use that on block devices. Signed-off-by: Darrick J. Wong --- lib/ext2fs/unix_io.c | 61 ++++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c index 16e2052cd..74fc8a75d 100644 --- a/lib/ext2fs/unix_io.c +++ b/lib/ext2fs/unix_io.c @@ -1081,38 +1081,6 @@ static errcode_t unix_set_option(io_channel channel, const char *option, #define BLKDISCARD _IO(0x12,119) #endif -/* - * Try a PUNCH_HOLE to unmap blocks, then BLKDISCARD if that doesn't work. - * We prefer PUNCH_HOLE because it invalidates the page cache, even on block - * devices. - */ -static int __unix_discard(int fd, int is_bdev, off_t offset, off_t len) -{ -#ifdef BLKDISCARD - __u64 range[2]; -#endif - int ret = -1; - -#if defined(HAVE_FALLOCATE) && defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE) - ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - offset, len); - if (ret == 0) - return 0; -#endif -#ifdef BLKDISCARD - if (is_bdev) { - range[0] = (__u64)offset; - range[1] = (__u64)len; - - ret = ioctl(fd, BLKDISCARD, &range); - if (ret == 0) - return 0; - } -#endif - errno = EOPNOTSUPP; - return ret; -} - static errcode_t unix_discard(io_channel channel, unsigned long long block, unsigned long long count) { @@ -1123,10 +1091,31 @@ static errcode_t unix_discard(io_channel channel, unsigned long long block, data = (struct unix_private_data *) channel->private_data; EXT2_CHECK_MAGIC(data, EXT2_ET_MAGIC_UNIX_IO_CHANNEL); - ret = __unix_discard(data->dev, - (channel->flags & CHANNEL_FLAGS_BLOCK_DEVICE), - (off_t)(block) * channel->block_size + data->offset, - (off_t)(count) * channel->block_size); + if (channel->flags & CHANNEL_FLAGS_BLOCK_DEVICE) { +#ifdef BLKDISCARD + __u64 range[2]; + + range[0] = (__u64)(block) * channel->block_size + data->offset; + range[1] = (__u64)(count) * channel->block_size; + + ret = ioctl(data->dev, BLKDISCARD, &range); +#else + goto unimplemented; +#endif + } else { +#if defined(HAVE_FALLOCATE) && defined(FALLOC_FL_PUNCH_HOLE) + /* + * If we are not on block device, try to use punch hole + * to reclaim free space. + */ + ret = fallocate(data->dev, + FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + (off_t)(block) * channel->block_size + data->offset, + (off_t)(count) * channel->block_size); +#else + goto unimplemented; +#endif + } if (ret < 0) { if (errno == EOPNOTSUPP) goto unimplemented;