From patchwork Thu Jun 15 16:42:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9789277 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 9763C60384 for ; Thu, 15 Jun 2017 16:42:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A70E28552 for ; Thu, 15 Jun 2017 16:42:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EBEE286D0; Thu, 15 Jun 2017 16:42:29 +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=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham 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 0B75628552 for ; Thu, 15 Jun 2017 16:42:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752094AbdFOQm1 (ORCPT ); Thu, 15 Jun 2017 12:42:27 -0400 Received: from mail-io0-f172.google.com ([209.85.223.172]:36039 "EHLO mail-io0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750980AbdFOQmW (ORCPT ); Thu, 15 Jun 2017 12:42:22 -0400 Received: by mail-io0-f172.google.com with SMTP id y77so15428467ioe.3 for ; Thu, 15 Jun 2017 09:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=I1CfxJ6Y5ML5PkH/qrpZxnxXEMyNcXUDy4/G/bfMwjk=; b=DQJmI/Ttf7ydanOjY0kOSKgV5T+Os6boPcJV5Z1edaJ0ztrw3tKBXlunDmgNjKLeNn xmsFhBuAaiqwbhWVDnKOOkJQRum5bun8GkTch53/VL/JZHFyjxylKImlUBIxr9+bawkC vFdHIShNZkZDqy3Uolv/rkqhQR3xmVar3sND6Vj6e6yw6EXexur8rrWPO3BICd0EXxnr xyYdZg0xLTgqjVNInzkrTrzYchWibKXy36FDzQy2nD3J6LQN/IFVf8oq7/9zTeqwiMZn XhBL9lVB2JeDk+hPC92f9k40l8SGn/mf2b6qQhV+98sMt/TAyPKx7/SrDJlKiCGmIAaC A3CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=I1CfxJ6Y5ML5PkH/qrpZxnxXEMyNcXUDy4/G/bfMwjk=; b=GMSrgDOfwRaj2Gpd2zaGiAFYjFX/iWaxL9HF9ikXRe7I/a+sEJ+qlWMsMYsMkOjnch QJWSFgVQjlwwYyzfVXanAhDxqNIBH4+y5f4+6YQkuAmBbJfdoprNr3Jrwyugeap3NI0y Kr3AoJdzEGtPYbDF0/+re2vC0JS+pJt3wb/P5UOM0DkVAIcw+Pw8FPcmv3Q5Lrve+PO/ OsjE4SwaTk8sLMqYYcG4+sIsS08aWTisxPsZX1Ky97d60fxALq1Ita5KTiMYBJpKUJ+R Nu7HrWSniZMBF3pg/oXJYw31pTOrpvw493TXxb8U3xbiJO/j17Gx/wfOS/Le6/9D1zXy ZoPg== X-Gm-Message-State: AKS2vOxGjIGyP6xFSunqYEauzf5PqlwihXYDVF0vd7E3Ph0ebjaNxKgA Ha4BUU3gJiVZP8OI X-Received: by 10.107.11.160 with SMTP id 32mr6474817iol.222.1497544941891; Thu, 15 Jun 2017 09:42:21 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id 97sm313476iot.25.2017.06.15.09.42.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Jun 2017 09:42:21 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: adilger@dilger.ca, hch@infradead.org, martin.petersen@oracle.com, Jens Axboe Subject: [PATCH 06/12] block: add helpers for setting/checking write hint validity Date: Thu, 15 Jun 2017 10:42:04 -0600 Message-Id: <1497544930-19174-7-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497544930-19174-1-git-send-email-axboe@kernel.dk> References: <1497544930-19174-1-git-send-email-axboe@kernel.dk> 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 We map the WRITE_HINT_* life time hints to the internal flags. Drivers can then, in turn, map those flags to a suitable stream type. Signed-off-by: Jens Axboe --- block/bio.c | 16 ++++++++++++++++ include/linux/bio.h | 1 + include/linux/blk_types.h | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/block/bio.c b/block/bio.c index 888e7801c638..758d83d91bb0 100644 --- a/block/bio.c +++ b/block/bio.c @@ -2082,6 +2082,22 @@ void bio_clone_blkcg_association(struct bio *dst, struct bio *src) #endif /* CONFIG_BLK_CGROUP */ +static const unsigned int rwf_write_to_opf_flag[] = { + 0, REQ_WRITE_SHORT, REQ_WRITE_MEDIUM, REQ_WRITE_LONG, REQ_WRITE_EXTREME +}; + +/* + * Convert WRITE_LIFE_* hints into req/bio flags + */ +unsigned int bio_op_write_hint(enum write_hint hint) +{ + if (WARN_ON_ONCE(hint >= ARRAY_SIZE(rwf_write_to_opf_flag))) + return 0; + + return rwf_write_to_opf_flag[hint]; +} +EXPORT_SYMBOL_GPL(bio_op_write_hint); + static void __init biovec_init_slabs(void) { int i; diff --git a/include/linux/bio.h b/include/linux/bio.h index d1b04b0e99cf..e9360dc5ea07 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -443,6 +443,7 @@ extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int, gfp_t, int); extern void bio_set_pages_dirty(struct bio *bio); extern void bio_check_pages_dirty(struct bio *bio); +extern unsigned int bio_op_write_hint(enum write_hint hint); void generic_start_io_acct(int rw, unsigned long sectors, struct hd_struct *part); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 57d1eb530799..23646eb433e7 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -323,4 +323,9 @@ struct blk_rq_stat { u64 batch; }; +static inline bool op_write_hint_valid(unsigned int opf) +{ + return (opf & REQ_WRITE_LIFE_MASK) != 0; +} + #endif /* __LINUX_BLK_TYPES_H */