diff mbox

[06/12] block: add helpers for setting/checking write hint validity

Message ID 1497544930-19174-7-git-send-email-axboe@kernel.dk (mailing list archive)
State New, archived
Headers show

Commit Message

Jens Axboe June 15, 2017, 4:42 p.m. UTC
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 <axboe@kernel.dk>
---
 block/bio.c               | 16 ++++++++++++++++
 include/linux/bio.h       |  1 +
 include/linux/blk_types.h |  5 +++++
 3 files changed, 22 insertions(+)

Comments

Martin K. Petersen June 16, 2017, 4:47 p.m. UTC | #1
Jens,

> +static const unsigned int rwf_write_to_opf_flag[] = {
> +	0, REQ_WRITE_SHORT, REQ_WRITE_MEDIUM, REQ_WRITE_LONG, REQ_WRITE_EXTREME
> +};

Minor nit: When I see WRITE_SHORT I instinctively think data corruption.

Can we make these REQ_LIFETIME_SHORT or something instead? It loses the
WRITE moniker which I'm not so keen on. But I'm not sure how we'd define
read lifetime...
Jens Axboe June 16, 2017, 4:53 p.m. UTC | #2
On 06/16/2017 10:47 AM, Martin K. Petersen wrote:
> 
> Jens,
> 
>> +static const unsigned int rwf_write_to_opf_flag[] = {
>> +	0, REQ_WRITE_SHORT, REQ_WRITE_MEDIUM, REQ_WRITE_LONG, REQ_WRITE_EXTREME
>> +};
> 
> Minor nit: When I see WRITE_SHORT I instinctively think data corruption.
> 
> Can we make these REQ_LIFETIME_SHORT or something instead? It loses the
> WRITE moniker which I'm not so keen on. But I'm not sure how we'd define
> read lifetime...

I did have that same feeling when writing it... The good news is that v6
will just use the WRITE_HINT_* types everywhere, so this one is already
gone.
diff mbox

Patch

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 */