From patchwork Wed Apr 29 14:47:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinz Mauelshagen X-Patchwork-Id: 11517733 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75D1114DD for ; Wed, 29 Apr 2020 14:47:23 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2EF0821D7A for ; Wed, 29 Apr 2020 14:47:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WVoFBtOc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2EF0821D7A Authentication-Results: mail.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588171641; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=uElYbCtEguR7fobm6BQOjDKBUELmIgWLARoc3fNMcXs=; b=WVoFBtOc4iIOX8PxMaCP98HoINPgMliQU8LvwXHKyf5S69wFp8zksfJXo0JBKrZ9IX0Snz RgBWxFskksFgsEv1AfnPc6XKjcMZwISUHu6et9CDdNjhVmVTrRbtu0DrfokQ2HMeuqbMd7 pYKsJxa1J4UCs52VWSCWVUQN+knzkK4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-210-cEYtY-nuNU-MdGh_aIxvRg-1; Wed, 29 Apr 2020 10:47:19 -0400 X-MC-Unique: cEYtY-nuNU-MdGh_aIxvRg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E96C38014D5; Wed, 29 Apr 2020 14:47:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3634605FB; Wed, 29 Apr 2020 14:47:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 779C01809543; Wed, 29 Apr 2020 14:47:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03TElAkf012476 for ; Wed, 29 Apr 2020 10:47:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id B32301E4; Wed, 29 Apr 2020 14:47:10 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from o.ww.redhat.com (unknown [10.40.193.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29AED50FE4; Wed, 29 Apr 2020 14:47:04 +0000 (UTC) From: heinzm@redhat.com To: dm-devel@redhat.com, snitzer@redhat.com Date: Wed, 29 Apr 2020 16:47:03 +0200 Message-Id: <976f321e48432fbb7ae4e3776a9eef1f1906fb79.1588171508.git.heinzm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH] dm ebs: use new dm-bufo dm_bufio_issue_discard() API X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com From: Heinz Mauelshagen Enhance new dm-ebs target as of v4 submitted on 3/9/2020 to actually pass discarding blocks down to the underlying device now that the new dm-bufio API is available. Signed-off-by: Heinz Mauelshagen --- .../admin-guide/device-mapper/dm-ebs.rst | 6 +++ drivers/md/dm-ebs-target.c | 37 ++++++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/device-mapper/dm-ebs.rst b/Documentation/admin-guide/device-mapper/dm-ebs.rst index 9e7abd3e0ae1..d42627e06924 100644 --- a/Documentation/admin-guide/device-mapper/dm-ebs.rst +++ b/Documentation/admin-guide/device-mapper/dm-ebs.rst @@ -49,3 +49,9 @@ offset 128 sectors, enforce 2KiB underlying device block size. This presumes 2KiB logical blocksize on /dev/sda or less to work: ebs /dev/sda 128 2 4 + +Version History +--------------- + +V1.0.0 - initial version +V1.0.1 - pass down discard requests diff --git a/drivers/md/dm-ebs-target.c b/drivers/md/dm-ebs-target.c index 1ba45946d4a6..97703c31771f 100644 --- a/drivers/md/dm-ebs-target.c +++ b/drivers/md/dm-ebs-target.c @@ -128,7 +128,33 @@ static int __ebs_rw_bio(struct ebs_c *ec, int rw, struct bio *bio) return r; } -/* 'Discard' blocks, i.e. release them from the bufio cache. */ +/* + * Discard bio's blocks, i.e. pass discards down. + * + * Avoid discarding partial blocks at beginning and end; + * return 0 in case no blocks can be discarded as a result. + */ +static int __ebs_discard_bio(struct ebs_c *ec, struct bio *bio) +{ + sector_t block, blocks, sector = bio->bi_iter.bi_sector;; + + block = __sector_to_block(ec, sector); + blocks = __nr_blocks(ec, bio); + + /* Partial first underlying block (__nr_blocks() may have resulted in one block). */ + if (__block_mod(sector, ec->u_bs)) { + block++; + blocks--; + } + + /* Partial last underlying block if any. */ + if (blocks && __block_mod(bio_end_sector(bio), ec->u_bs)) + blocks--; + + return blocks ? dm_bufio_issue_discard(ec->bufio, block, blocks) : 0; +} + +/* Release blocks them from the bufio cache. */ static int __ebs_forget_bio(struct ebs_c *ec, struct bio *bio) { sector_t blocks, sector = bio->bi_iter.bi_sector;; @@ -179,9 +205,10 @@ static void __ebs_process_bios(struct work_struct *ws) else if (bio_op(bio) == REQ_OP_WRITE) { write = true; r = __ebs_rw_bio(ec, WRITE, bio); - } else if (bio_op(bio) == REQ_OP_DISCARD) - /* FIXME: (optionally) call dm_bufio_discard_buffers() once upstream. */ - r = __ebs_forget_bio(ec, bio); + } else if (bio_op(bio) == REQ_OP_DISCARD) { + __ebs_forget_bio(ec, bio); + r = __ebs_discard_bio(ec, bio); + } bio->bi_status = r; } @@ -404,7 +431,7 @@ static int ebs_iterate_devices(struct dm_target *ti, static struct target_type ebs_target = { .name = "ebs", - .version = {1, 0, 0}, + .version = {1, 0, 1}, .features = DM_TARGET_PASSES_INTEGRITY, .module = THIS_MODULE, .ctr = ebs_ctr,