From patchwork Fri Mar 29 14:23:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Liu X-Patchwork-Id: 10877179 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3754D1708 for ; Fri, 29 Mar 2019 14:24:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2849C290D0 for ; Fri, 29 Mar 2019 14:24:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CBE429105; Fri, 29 Mar 2019 14:24:52 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 C2ADB290D0 for ; Fri, 29 Mar 2019 14:24:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729549AbfC2OYt (ORCPT ); Fri, 29 Mar 2019 10:24:49 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:58700 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729421AbfC2OYs (ORCPT ); Fri, 29 Mar 2019 10:24:48 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2TEE1Lu004595; Fri, 29 Mar 2019 14:24:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=o5MGkO/UI8Fuf/rRxWKaYIiK+9cGRsQljalxnNRo8lA=; b=0eklocWt/7F0Qdz/LYmVaQQQbH1T9v+hTQ6555kaNzmOHmm6CoNl7SUBZVjItn2P85Mf sh3HVmXdnPjz5YNMkZPNlRjva/iVlhOyJVVJ7fpBEKeo3+wL88b56M/gikM2u14JKpWp z1gmKT82VlGklvmuD3oV4qjz3uN8uJuI+2Ze0NxEQtT43iNdToiHHUhjRsRREVw9l/Y/ 5moa8JtS7kVbzJMxpaYM6M1mokIZq8a7Tixyzfb1prW71w5PRP53djsVC1wdPYdc296I Bw7bz1OzR/Bi3V03zehJBnE23Hy0Onirx390zYcN20H2LGd3oWfqiBHEVWCnmI8vQkor dQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2re6g1crf5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Mar 2019 14:24:37 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x2TEOWZM006959 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Mar 2019 14:24:32 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x2TEOVP3019283; Fri, 29 Mar 2019 14:24:31 GMT Received: from localhost.localdomain (/180.165.90.201) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 29 Mar 2019 07:24:30 -0700 From: Bob Liu To: linux-block@vger.kernel.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, martin.petersen@oracle.com, shirley.ma@oracle.com, allison.henderson@oracle.com, david@fromorbit.com, darrick.wong@oracle.com, hch@infradead.org, adilger@dilger.ca, axboe@kernel.dk, tytso@mit.edu, Bob Liu Subject: [PATCH v3 1/3] block: introduce submit_bio_verify() Date: Fri, 29 Mar 2019 22:23:44 +0800 Message-Id: <20190329142346.1677-2-bob.liu@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190329142346.1677-1-bob.liu@oracle.com> References: <20190329142346.1677-1-bob.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9210 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=971 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903290102 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 This patch adds a function verifier callback to submit_bio. The filesystem layer can use submit_bio_verify to pass a call back to the block layer which can then be used to verify if the data read is correct. Signed-off-by: Bob Liu --- block/blk-core.c | 13 ++++++++++--- include/linux/bio.h | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 6b78ec56a4f2..d265d2924c32 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1156,15 +1156,16 @@ blk_qc_t direct_make_request(struct bio *bio) EXPORT_SYMBOL_GPL(direct_make_request); /** - * submit_bio - submit a bio to the block device layer for I/O + * submit_bio_verify - submit a bio to the block device layer for I/O * @bio: The &struct bio which describes the I/O * - * submit_bio() is very similar in purpose to generic_make_request(), and + * submit_bio_verify() is very similar in purpose to generic_make_request(), and * uses that function to do most of the work. Both are fairly rough * interfaces; @bio must be presetup and ready for I/O. * */ -blk_qc_t submit_bio(struct bio *bio) +blk_qc_t submit_bio_verify(struct bio *bio, + int (*verifier_cb_func)(struct bio *)) { /* * If it's a regular read/write or a barrier with data attached, @@ -1197,6 +1198,12 @@ blk_qc_t submit_bio(struct bio *bio) return generic_make_request(bio); } +EXPORT_SYMBOL(submit_bio_verify); + +blk_qc_t submit_bio(struct bio *bio) +{ + return submit_bio_verify(bio, NULL); +} EXPORT_SYMBOL(submit_bio); /** diff --git a/include/linux/bio.h b/include/linux/bio.h index 7380b094dcca..ddaadab74dcf 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -398,6 +398,8 @@ static inline struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned int nr_iovecs) return bio_alloc_bioset(gfp_mask, nr_iovecs, NULL); } +extern blk_qc_t submit_bio_verify(struct bio *, + int (*verifier_cb_func)(struct bio *)); extern blk_qc_t submit_bio(struct bio *); extern void bio_endio(struct bio *); From patchwork Fri Mar 29 14:23:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Liu X-Patchwork-Id: 10877189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B7A51575 for ; Fri, 29 Mar 2019 14:25:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C0FE28F8F for ; Fri, 29 Mar 2019 14:25:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 505BD290E7; Fri, 29 Mar 2019 14:25:03 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 C1ED128F8F for ; Fri, 29 Mar 2019 14:25:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729212AbfC2OZB (ORCPT ); Fri, 29 Mar 2019 10:25:01 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:57216 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729046AbfC2OZB (ORCPT ); Fri, 29 Mar 2019 10:25:01 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2TENPkq017863; Fri, 29 Mar 2019 14:24:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=NURxUyFD4lB2MOp9stVN5wUgNSnnCHzTcE3XIZQbn4M=; b=Fed5aJcgZPEWwB52b/DZcXmFvwX909Juq0po9JEqULBxhCkF75XMFwc5cZGztUj5ZUHp tK8OeJGwKuuFd8X270OSgaY4WuRpfRD+29o6BFQ7pMIZLkrnVSPEsK2uLfgqQDTyuXJ/ 2jPfOVZDXquieCbbHQY9guqDYlR8MuGNlu3yYCrEOzmJPBJVnGehjssw3Z95s6UxZKZ3 7KyROtQtju3iYIoRzqWSLIHDLkFiCAyLqHj89Fuk2h8CwmIntqPsM4rhUSnjnMAIU0hX TM22NRQHLLeqk0EigYLQvPNH6oTEGxtM7qqIAqsQBd1tdCUKjbQBtB+TjRlIXBTKFLtm bQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2re6djvs7b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Mar 2019 14:24:50 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x2TEOj42030167 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Mar 2019 14:24:45 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x2TEOiAu019449; Fri, 29 Mar 2019 14:24:44 GMT Received: from localhost.localdomain (/180.165.90.201) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 29 Mar 2019 07:24:43 -0700 From: Bob Liu To: linux-block@vger.kernel.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, martin.petersen@oracle.com, shirley.ma@oracle.com, allison.henderson@oracle.com, david@fromorbit.com, darrick.wong@oracle.com, hch@infradead.org, adilger@dilger.ca, axboe@kernel.dk, tytso@mit.edu, Bob Liu Subject: [PATCH v3 2/3] block: verify data when endio Date: Fri, 29 Mar 2019 22:23:45 +0800 Message-Id: <20190329142346.1677-3-bob.liu@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190329142346.1677-1-bob.liu@oracle.com> References: <20190329142346.1677-1-bob.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9210 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903290103 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 Call verify callback same as bio integrity. If verify fail, drivers like MD will try other mirrors until get a correct one or return failure after all mirrors are tried. The MD driver already works like this, so no extra changed. Todo: - union with "struct bio_integrity_payload *bi_integrity" to save bio space. Signed-off-by: Bob Liu --- block/bio-integrity.c | 45 +++++++++++++++++++++++++++++++++++++++ block/bio.c | 3 +++ block/blk-core.c | 4 ++++ block/blk.h | 8 +++++++ block/bounce.c | 1 + drivers/md/raid1.c | 1 + drivers/md/raid5-ppl.c | 1 + include/linux/blk_types.h | 5 +++++ 8 files changed, 68 insertions(+) diff --git a/block/bio-integrity.c b/block/bio-integrity.c index 1b633a3526d4..90a47ad31dbf 100644 --- a/block/bio-integrity.c +++ b/block/bio-integrity.c @@ -372,6 +372,51 @@ bool __bio_integrity_endio(struct bio *bio) return true; } +/** + * bio_verify_fn - Verify I/O completion worker + * @work: Work struct stored in bio to be verified + * + * Description: This workqueue function is called to complete a READ + * request. The function call verifier callack that fs pass down + * and then calls the original bio end_io function. + */ +static void bio_verify_fn(struct work_struct *work) +{ + struct bio *bio = + container_of(work, struct bio, bi_work); + + bio->bi_status = bio->bi_verifier(bio); + /* Clear flag if verify succeed to avoid verifing + * it unnecessary by parent bio + */ + if (!bio->bi_status) + bio->bi_opf &= ~REQ_VERIFY; + bio_endio(bio); +} + +/** + * __bio_verify_endio - Verify I/O completion function + * @bio: Protected bio + * + * Description: Completion for verify I/O + * + * Normally I/O completion is done in interrupt context. However, + * verifying I/O is a time-consuming task which must be run + * in process context. This function postpones completion + * accordingly. + */ +bool __bio_verify_endio(struct bio *bio) +{ + if (bio_op(bio) == REQ_OP_READ && !bio->bi_status && + (bio->bi_opf & REQ_VERIFY) && bio->bi_verifier) { + INIT_WORK(&bio->bi_work, bio_verify_fn); + queue_work(kintegrityd_wq, &bio->bi_work); + return false; + } + + return true; +} + /** * bio_integrity_advance - Advance integrity vector * @bio: bio whose integrity vector to update diff --git a/block/bio.c b/block/bio.c index 4db1008309ed..8928806acda6 100644 --- a/block/bio.c +++ b/block/bio.c @@ -608,6 +608,7 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src) bio->bi_write_hint = bio_src->bi_write_hint; bio->bi_iter = bio_src->bi_iter; bio->bi_io_vec = bio_src->bi_io_vec; + bio->bi_verifier = bio_src->bi_verifier; bio_clone_blkg_association(bio, bio_src); blkcg_bio_issue_init(bio); @@ -1763,6 +1764,8 @@ void bio_endio(struct bio *bio) return; if (!bio_integrity_endio(bio)) return; + if (!bio_verify_endio(bio)) + return; if (bio->bi_disk) rq_qos_done_bio(bio->bi_disk->queue, bio); diff --git a/block/blk-core.c b/block/blk-core.c index d265d2924c32..cbec80f2d73a 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1167,6 +1167,10 @@ EXPORT_SYMBOL_GPL(direct_make_request); blk_qc_t submit_bio_verify(struct bio *bio, int (*verifier_cb_func)(struct bio *)) { + if (verifier_cb_func) { + bio->bi_verifier = verifier_cb_func; + bio->bi_opf |= REQ_VERIFY; + } /* * If it's a regular read/write or a barrier with data attached, * go through the normal accounting stuff before submission. diff --git a/block/blk.h b/block/blk.h index 848278c52030..cdf30c65d4a8 100644 --- a/block/blk.h +++ b/block/blk.h @@ -151,6 +151,14 @@ static inline bool bio_integrity_endio(struct bio *bio) } #endif /* CONFIG_BLK_DEV_INTEGRITY */ +bool __bio_verify_endio(struct bio *); +static inline bool bio_verify_endio(struct bio *bio) +{ + if (bio->bi_opf & REQ_VERIFY) + return __bio_verify_endio(bio); + return true; +} + unsigned long blk_rq_timeout(unsigned long timeout); void blk_add_timer(struct request *req); diff --git a/block/bounce.c b/block/bounce.c index ffb9e9ecfa7e..7a2c3f536030 100644 --- a/block/bounce.c +++ b/block/bounce.c @@ -252,6 +252,7 @@ static struct bio *bounce_clone_bio(struct bio *bio_src, gfp_t gfp_mask, bio->bi_write_hint = bio_src->bi_write_hint; bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; + bio->bi_verifier = bio_src->bi_verifier; switch (bio_op(bio)) { case REQ_OP_DISCARD: diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 1d54109071cc..11b29a3831e1 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -1103,6 +1103,7 @@ static void alloc_behind_master_bio(struct r1bio *r1_bio, } behind_bio->bi_write_hint = bio->bi_write_hint; + behind_bio->bi_verifier = bio->bi_verifier; while (i < vcnt && size) { struct page *page; diff --git a/drivers/md/raid5-ppl.c b/drivers/md/raid5-ppl.c index 3a7c36326589..4cdaa5dabfbe 100644 --- a/drivers/md/raid5-ppl.c +++ b/drivers/md/raid5-ppl.c @@ -505,6 +505,7 @@ static void ppl_submit_iounit(struct ppl_io_unit *io) bio = bio_alloc_bioset(GFP_NOIO, BIO_MAX_PAGES, &ppl_conf->bs); bio->bi_opf = prev->bi_opf; + bio->bi_verifier = prev->bi_verifier; bio_copy_dev(bio, prev); bio->bi_iter.bi_sector = bio_end_sector(prev); bio_add_page(bio, sh->ppl_page, PAGE_SIZE, 0); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index d66bf5f32610..e9f25f162138 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -18,6 +18,7 @@ struct block_device; struct io_context; struct cgroup_subsys_state; typedef void (bio_end_io_t) (struct bio *); +typedef int (bio_verifier_t) (struct bio *); /* * Block error status values. See block/blk-core:blk_errors for the details. @@ -187,6 +188,8 @@ struct bio { struct bio_integrity_payload *bi_integrity; /* data integrity */ #endif }; + bio_verifier_t *bi_verifier; /* verify callback when endio */ + struct work_struct bi_work; /* I/O completion */ unsigned short bi_vcnt; /* how many bio_vec's */ @@ -329,6 +332,7 @@ enum req_flag_bits { /* for driver use */ __REQ_DRV, __REQ_SWAP, /* swapping request. */ + __REQ_VERIFY, /* verify IO when endio is called */ __REQ_NR_BITS, /* stops here */ }; @@ -351,6 +355,7 @@ enum req_flag_bits { #define REQ_DRV (1ULL << __REQ_DRV) #define REQ_SWAP (1ULL << __REQ_SWAP) +#define REQ_VERIFY (1ULL << __REQ_VERIFY) #define REQ_FAILFAST_MASK \ (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER) From patchwork Fri Mar 29 14:23:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Liu X-Patchwork-Id: 10877195 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46B2C1575 for ; Fri, 29 Mar 2019 14:25:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35EFC290D4 for ; Fri, 29 Mar 2019 14:25:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A3C0290E7; Fri, 29 Mar 2019 14:25:16 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 CD78929102 for ; Fri, 29 Mar 2019 14:25:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729170AbfC2OZO (ORCPT ); Fri, 29 Mar 2019 10:25:14 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:35370 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729046AbfC2OZO (ORCPT ); Fri, 29 Mar 2019 10:25:14 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2TENOHR009567; Fri, 29 Mar 2019 14:25:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=Htuadjze+wfMFk2xX+FQkm1G2rt8079ZbjXQim9RLHc=; b=S2Hy4chgVtl3Ysv+BVH0oT1W3tnnPVl4p453cX+HuQZS3sSn6K+3Gu3ALR0sbgbFF3MK dD/rA37lnF5u8AzKEqyl7ZheVjrNpYSyzc2gG3lDp+PTuIYJiGtiMSUUYd8JEWn7w3HE MVZ+zAaQFoH3HF/Xum2keL/MixJeFy2btZ92surVBMBJOjEfDfl/XVnOO2NDW+GFKtXB egwKV4YF8RsJl9FmIlOJDsTkr6ICbq+IyyIqO+6f6w4Nwb7gtVP19i7/6cdiRSkkg/Vc H+YoOJPsDr/ORcczFgz0o+cFFP2H1231bNLGNZo9MRtmdjem/umIyoMF/i/GM48fDxZj +A== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2re6g1mq1n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Mar 2019 14:25:01 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x2TEOtAj030501 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Mar 2019 14:24:55 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x2TEOtnv019520; Fri, 29 Mar 2019 14:24:55 GMT Received: from localhost.localdomain (/180.165.90.201) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 29 Mar 2019 07:24:54 -0700 From: Bob Liu To: linux-block@vger.kernel.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, martin.petersen@oracle.com, shirley.ma@oracle.com, allison.henderson@oracle.com, david@fromorbit.com, darrick.wong@oracle.com, hch@infradead.org, adilger@dilger.ca, axboe@kernel.dk, tytso@mit.edu, Bob Liu Subject: [PATCH v3 3/3] fs: xfs: add read_verifier() function Date: Fri, 29 Mar 2019 22:23:46 +0800 Message-Id: <20190329142346.1677-4-bob.liu@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190329142346.1677-1-bob.liu@oracle.com> References: <20190329142346.1677-1-bob.liu@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9210 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=892 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903290103 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 This patch adds an new read_verifier function and pass to the block layer to verify reads. Signed-off-by: Bob Liu --- fs/xfs/xfs_buf.c | 23 +++++++++++++++++++++-- fs/xfs/xfs_buf.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 4f5f2ff3f70f..f3185dd9a557 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -1243,7 +1243,8 @@ xfs_buf_ioend( xfs_buf_ioerror(bp, bp->b_io_error); /* Only validate buffers that were read without errors */ - if (read && !bp->b_error && bp->b_ops) { + if (read && !bp->b_error && bp->b_ops && + !(bp->b_flags & _XBF_NOVERIFY)) { ASSERT(!bp->b_iodone); bp->b_ops->verify_read(bp); } @@ -1343,6 +1344,24 @@ xfs_buf_bio_end_io( bio_put(bio); } +int read_verifier(struct bio *bio) +{ + struct xfs_buf *bp = (struct xfs_buf *)bio->bi_private; + + if (bp && !bp->b_error && bp->b_ops && bp->b_ops->verify_read) { + if (xfs_buf_is_vmapped(bp)) + invalidate_kernel_vmap_range(bp->b_addr, + xfs_buf_vmap_len(bp)); + bp->b_ops->verify_read(bp); + /* set bit so that endio won't verify it again */ + if (!bp->b_error) + bp->b_flags |= _XBF_NOVERIFY; + return bp->b_error; + } else { + return 0; + } +} + static void xfs_buf_ioapply_map( struct xfs_buf *bp, @@ -1409,7 +1428,7 @@ xfs_buf_ioapply_map( flush_kernel_vmap_range(bp->b_addr, xfs_buf_vmap_len(bp)); } - submit_bio(bio); + submit_bio_verify(bio, &read_verifier); if (size) goto next_chunk; } else { diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index b9f5511ea998..499637c61001 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -50,6 +50,7 @@ typedef enum { #define _XBF_KMEM (1 << 21)/* backed by heap memory */ #define _XBF_DELWRI_Q (1 << 22)/* buffer on a delwri queue */ #define _XBF_COMPOUND (1 << 23)/* compound buffer */ +#define _XBF_NOVERIFY (1 << 24)/* verify_read should not be called */ typedef unsigned int xfs_buf_flags_t;