From patchwork Tue Jul 3 17:35:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikulas Patocka X-Patchwork-Id: 10504879 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 242E3601D3 for ; Tue, 3 Jul 2018 17:35:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B6E028A35 for ; Tue, 3 Jul 2018 17:35:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3F4628AB0; Tue, 3 Jul 2018 17:35:57 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable 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 A021628A35 for ; Tue, 3 Jul 2018 17:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934390AbeGCRfy (ORCPT ); Tue, 3 Jul 2018 13:35:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58280 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934237AbeGCRfv (ORCPT ); Tue, 3 Jul 2018 13:35:51 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A429C320; Tue, 3 Jul 2018 17:35:51 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8198076CE; Tue, 3 Jul 2018 17:35:49 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id w63HZnPx029818; Tue, 3 Jul 2018 13:35:49 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id w63HZnjk029815; Tue, 3 Jul 2018 13:35:49 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Tue, 3 Jul 2018 13:35:49 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Axboe cc: linux-block@vger.kernel.org, Zdenek Kabelac , Mike Snitzer , dm-devel@redhat.com Subject: [PATCH] block: make discard killable Message-ID: User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 03 Jul 2018 17:35:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 03 Jul 2018 17:35:51 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mpatocka@redhat.com' RCPT:'' Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Discarding can take very long time for some device mapper targets, this patch makes it possible to kill a process that issues the BLKDISCARD ioctl. Note that some filesystems call blkdev_issue_discard or __blkdev_issue_discard directly, they may not be prepared to handle the failure, so this patch introduces a flag BLKDEV_DISCARD_KILLABLE that is only set when the discard is initiated by an ioctl. Signed-off-by: Mikulas Patocka --- block/blk-lib.c | 13 +++++++++++-- block/ioctl.c | 4 ++-- include/linux/blkdev.h | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) Index: linux-2.6/block/blk-lib.c =================================================================== --- linux-2.6.orig/block/blk-lib.c 2018-06-29 20:10:55.540000000 +0200 +++ linux-2.6/block/blk-lib.c 2018-06-29 23:12:24.520000000 +0200 @@ -7,6 +7,7 @@ #include #include #include +#include #include "blk.h" @@ -33,6 +34,7 @@ int __blkdev_issue_discard(struct block_ unsigned int op; int alignment; sector_t bs_mask; + int r; if (!q) return -ENXIO; @@ -68,8 +70,10 @@ int __blkdev_issue_discard(struct block_ */ req_sects = min_t(sector_t, nr_sects, q->limits.max_discard_sectors); - if (!req_sects) + if (!req_sects) { + r = -EOPNOTSUPP; goto fail; + } if (req_sects > UINT_MAX >> 9) req_sects = UINT_MAX >> 9; @@ -96,6 +100,11 @@ int __blkdev_issue_discard(struct block_ nr_sects -= req_sects; sector = end_sect; + if (flags & BLKDEV_DISCARD_KILLABLE && fatal_signal_pending(current)) { + r = -EINTR; + goto fail; + } + /* * We can loop for a long time in here, if someone does * full device discards (like mkfs). Be nice and allow @@ -114,7 +123,7 @@ fail: bio_put(bio); } *biop = NULL; - return -EOPNOTSUPP; + return r; } EXPORT_SYMBOL(__blkdev_issue_discard); Index: linux-2.6/block/ioctl.c =================================================================== --- linux-2.6.orig/block/ioctl.c 2018-05-31 18:04:38.068000000 +0200 +++ linux-2.6/block/ioctl.c 2018-06-29 23:06:07.180000000 +0200 @@ -522,10 +522,10 @@ int blkdev_ioctl(struct block_device *bd case BLKROSET: return blkdev_roset(bdev, mode, cmd, arg); case BLKDISCARD: - return blk_ioctl_discard(bdev, mode, arg, 0); + return blk_ioctl_discard(bdev, mode, arg, BLKDEV_DISCARD_KILLABLE); case BLKSECDISCARD: return blk_ioctl_discard(bdev, mode, arg, - BLKDEV_DISCARD_SECURE); + BLKDEV_DISCARD_SECURE | BLKDEV_DISCARD_KILLABLE); case BLKZEROOUT: return blk_ioctl_zeroout(bdev, mode, arg); case BLKREPORTZONE: Index: linux-2.6/include/linux/blkdev.h =================================================================== --- linux-2.6.orig/include/linux/blkdev.h 2018-06-18 01:09:22.040000000 +0200 +++ linux-2.6/include/linux/blkdev.h 2018-06-29 23:09:50.010000000 +0200 @@ -1390,6 +1390,7 @@ extern int blkdev_issue_write_same(struc sector_t nr_sects, gfp_t gfp_mask, struct page *page); #define BLKDEV_DISCARD_SECURE (1 << 0) /* issue a secure erase */ +#define BLKDEV_DISCARD_KILLABLE (1 << 1) /* allow killing the process */ extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, unsigned long flags);