Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp199193pxb; Tue, 9 Mar 2021 21:08:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpK6jd4/r6PlCGMDFwNqF0WMHYrSkHG/6zNs/3CB6YFp3kdsHIu4lD3t3Av0rfMk1QQ8lt X-Received: by 2002:a17:906:260a:: with SMTP id h10mr1665991ejc.392.1615352906752; Tue, 09 Mar 2021 21:08:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615352906; cv=none; d=google.com; s=arc-20160816; b=VHt91a5mwdh7cJ+sXAbwpeVONVBgZnrRz8M/hRt8sJec8OfJ72OPPJR5ui6zLgv40T K8d2aPxAqY5yVaWekgIo6e1+BmW4B1eJPJQs0mY5i0Rmw+Xgg+A1mttDJOqwvt/pPnMq PM7C9yCd342D9CU1siLIOr855zhyl6h7+BnUvByDYF1WdG0zbN6u2J0WYX9rtf4pn63e 3m+y6ISyAUpbxQ2SXyXH28APcs4uepUY6ESx57DEl1Kb0tzo+0C6VUgpHyoGDXmvjaN0 34M7UZoQaxs/I5vcVo+P9L1VhjqPVMR8FnCRdkkn0n3sZoS+Mt97x0TydJhfdZ4nHG29 RjIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=2S21cNEoC4DbfsoORby8T13WajgTXFAjKBIA+uaX2aE=; b=SvbRM3bDoKCMYsj9bucmfSjJfLM0h3FqHw0CqfRu+TjC/iHq0K9OKKjZ0AfiQxfr6Z ezpMV5dXBk8KLINc60DApYq1BfglXiXRFi9+T4w9UIVG1FPUTaXDfwS3DNdXAhrY1eR4 xnrnQEtmpBKy7YH+Kd8wqrPNWN/4QL8AzoGNocroNnoOOp/E7M4GQX/tbpJW11Rp3xTm 9TAVvNVeoTu+w+PRWyhi6aVJMyuZezmw7nazC5wGB+w1q8J0Le67cSLDfjZ19aJvWGZL SkDs8GufHfX1cxPOiygT+8zNZI6zc5tRKxfuX+GA4V9fBICgsougz0vm+n6lN9PZRSor QkXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@veeam.com header.s=mx4 header.b=QtWonQjb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=veeam.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h19si10259697edb.134.2021.03.09.21.08.04; Tue, 09 Mar 2021 21:08:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@veeam.com header.s=mx4 header.b=QtWonQjb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=veeam.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231479AbhCJEy2 (ORCPT + 99 others); Tue, 9 Mar 2021 23:54:28 -0500 Received: from mx4.veeam.com ([104.41.138.86]:33674 "EHLO mx4.veeam.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbhCJEx5 (ORCPT ); Tue, 9 Mar 2021 23:53:57 -0500 Received: from mail.veeam.com (prgmbx01.amust.local [172.24.0.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx4.veeam.com (Postfix) with ESMTPS id 258C58A78F; Wed, 10 Mar 2021 07:53:23 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=veeam.com; s=mx4; t=1615352003; bh=2S21cNEoC4DbfsoORby8T13WajgTXFAjKBIA+uaX2aE=; h=Date:From:To:CC:Subject:References:In-Reply-To:From; b=QtWonQjbibxg7PZTL6pPo2iQzhB1y6WPs9Kj91BVqNOzkatCN2LXOOaycR+prKhxH aOicCeOvms9IaolW3eJyHnM9LuGO+03WfHCn6tYLD19DuhrJoPkDHrH64QhQmjvWao EGrjxZMSZgwO6R9Vx2tzmpfQi6OGjX9XxjIc7dJ4= Received: from veeam.com (172.24.14.5) by prgmbx01.amust.local (172.24.0.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.721.2; Wed, 10 Mar 2021 05:53:20 +0100 Date: Wed, 10 Mar 2021 07:53:13 +0300 From: Sergei Shtepa To: Christoph Hellwig CC: "snitzer@redhat.com" , "agk@redhat.com" , "hare@suse.de" , "song@kernel.org" , "axboe@kernel.dk" , "dm-devel@redhat.com" , "linux-block@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-raid@vger.kernel.org" , "linux-api@vger.kernel.org" , Pavel Tide Subject: Re: [PATCH v6 2/4] block: add blk_interposer Message-ID: <20210310045313.GA26929@veeam.com> References: <1614774618-22410-1-git-send-email-sergei.shtepa@veeam.com> <1614774618-22410-3-git-send-email-sergei.shtepa@veeam.com> <20210309172717.GB201344@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: <20210309172717.GB201344@infradead.org> X-Originating-IP: [172.24.14.5] X-ClientProxiedBy: prgmbx02.amust.local (172.24.0.172) To prgmbx01.amust.local (172.24.0.171) X-EsetResult: clean, is OK X-EsetId: 37303A29D2A50B58627664 X-Veeam-MMEX: True Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thank you, Christoph, for the review. I will correct all except two points. The 03/09/2021 20:27, Christoph Hellwig wrote: > > +static blk_qc_t __submit_bio_interposed(struct bio *bio) > > +{ > > + struct bio_list bio_list[2] = { }; > > + blk_qc_t ret = BLK_QC_T_NONE; > > + > > + current->bio_list = bio_list; > > + if (likely(bio_queue_enter(bio) == 0)) { > > + struct block_device *bdev = bio->bi_bdev; > > + > > + if (likely(bdev_has_interposer(bdev))) { > > + bio_set_flag(bio, BIO_INTERPOSED); > > + bdev->bd_interposer->ip_submit_bio(bio); > > + } else { > > + /* interposer was removed */ > > + bio_list_add(¤t->bio_list[0], bio); > > + } > > + > > + blk_queue_exit(bdev->bd_disk->queue); > > + } > > + current->bio_list = NULL; > > + > > + /* Resubmit remaining bios */ > > + while ((bio = bio_list_pop(&bio_list[0]))) > > + ret = submit_bio_noacct(bio); > > + > > + return ret; > > +} > > + > > /** > > * submit_bio_noacct - re-submit a bio to the block device layer for I/O > > * @bio: The bio describing the location in memory and on the device. > > @@ -1043,6 +1071,14 @@ blk_qc_t submit_bio_noacct(struct bio *bio) > > return BLK_QC_T_NONE; > > } > > > > + /* > > + * Checking the BIO_INTERPOSED flag is necessary so that the bio > > + * created by the bdev_interposer do not get to it for processing. > > + */ > > + if (bdev_has_interposer(bio->bi_bdev) && > > + !bio_flagged(bio, BIO_INTERPOSED)) > > + return __submit_bio_interposed(bio); > > + > > if (!bio->bi_bdev->bd_disk->fops->submit_bio) > > return __submit_bio_noacct_mq(bio); > > return __submit_bio_noacct(bio); > > diff --git a/block/genhd.c b/block/genhd.c > > index fcc530164b5a..1ae8516643c8 100644 > > --- a/block/genhd.c > > +++ b/block/genhd.c > > @@ -30,6 +30,11 @@ > > static struct kobject *block_depr; > > > > DECLARE_RWSEM(bdev_lookup_sem); > > +/* > > + * Prevents different block-layer interposers from attaching or detaching > > + * to the block device at the same time. > > + */ > > +DEFINE_MUTEX(bdev_interposer_attach_lock); > > This one can and should be marked static. > > > +int bdev_interposer_attach(struct block_device *bdev, struct bdev_interposer *interposer, > > Please avoid the overly long line. > > > + int ret = 0; > > + > > + if (WARN_ON(!interposer)) > > WARN_ON_ONCE? This function should be called quite rarely, and the absence of the interposer parameter indicates that the function is being used incorrectly. I would like to see this warning every time. > > > + return -EINVAL; > > + > > + if (!blk_mq_is_queue_frozen(bdev->bd_disk->queue)) > > + return -EPERM; > > This probly should be a WARN_ON_ONCE() as well. I think it's better to apply WARN_ON here. > > > + > > + mutex_lock(&bdev_interposer_attach_lock); > > + if (bdev_has_interposer(bdev)) { > > + if (bdev->bd_interposer->ip_submit_bio == ip_submit_bio) > > + ret = -EALREADY; > > + else > > + ret = -EBUSY; > > + goto out; > > + } > > Do we really need the two different error codes here? I think I need it. If we try to initialize the interposer again, the reason for this error is most likely in the logic of the module itself. If the interposer is occupied by someone else, then we need to let know about it. > > > + > > + interposer->ip_submit_bio = ip_submit_bio; > > I'd rather let the caller initialize the field instead of passing the > submit function separately. Yes, I think so. This will allow to keep only one parameter of the function. > > > +void bdev_interposer_detach(struct bdev_interposer *interposer, > > + const ip_submit_bio_t ip_submit_bio) > > +{ > > > + /* Check if it is really our interposer. */ > > + if (WARN_ON(bdev->bd_interposer->ip_submit_bio != ip_submit_bio)) > > + goto out; > > I don't really see any need to pass ip_submit_bio just for this check. > > > + struct bdev_interposer * bd_interposer; > > The * goes just before the member name. > > > +/* > > + * block layer interposers structure and functions > > + */ > > +typedef void (*ip_submit_bio_t) (struct bio *bio); > > + > > +struct bdev_interposer { > > + ip_submit_bio_t ip_submit_bio; > > + struct block_device *bdev; > > Do we need the ip_ prefix here? Also we probably don't really the > the typedef for the function pointer. Ok. Maybe submit_bio_hook would be better? or submit_bio_interposer. > > > +#define bdev_has_interposer(bd) ((bd)->bd_interposer != NULL) > > And inline function would be nice here. -- Sergei Shtepa Veeam Software developer.