From patchwork Wed Jun 14 04:01:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9785309 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 2F48B6038E for ; Wed, 14 Jun 2017 04:02:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38E4B2844E for ; Wed, 14 Jun 2017 04:02:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DF352858D; Wed, 14 Jun 2017 04:02:31 +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=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 CDD9328589 for ; Wed, 14 Jun 2017 04:02:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750828AbdFNECT (ORCPT ); Wed, 14 Jun 2017 00:02:19 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:32990 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750717AbdFNECK (ORCPT ); Wed, 14 Jun 2017 00:02:10 -0400 Received: by mail-pg0-f42.google.com with SMTP id f185so69555087pgc.0 for ; Tue, 13 Jun 2017 21:02:10 -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=Cb1G/feADhzapc0RhwvDkMAnbCB2lihU2GtyJ6diWqw=; b=KdBb7hnU+ESgyfx6ezVe9M4UVomncFH6mf1RP4458xW6WWdBzgT3oeghu6lMhXq6BF uCN5tVrTSLyvtXmLH8Jqc5JMaVaqkn9MNL/81YTDanhkyYQATY5wgtcZ1X0qU0S/CHsZ fKSeJDZeTJNMm/vTSLpAfNd/YnJ8lXn2NJRaIaTqNzKabDWfYULz/Zs3Mtbzmnmz5dEE e8JVowm/bZRhupL9IEehhYFgM/BWQzNoFCLngPMf5EXVBYSA8bE6eulutYvafwrdIPvh VAdEi1MORa5DUnw9SIw7hJwHKge2/TQedXg8EJBs5/OAffX/UC9NIe0cy1pE0198+JPC HPlA== 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=Cb1G/feADhzapc0RhwvDkMAnbCB2lihU2GtyJ6diWqw=; b=YhLdEK/w7MosbfHWeSp287fuPfwRfizlAxwT8rk9BZhTG/+4H8PrxM+mWFr68JwxPg kdRCspECr8m0ZhU8d9iePgXDKB2S8+bUvtUWjdgyMtGqbaYXemx1zZ1tNA7Fw1TMWISr dNSYs+3arb77oQjT7lLIMEIXoSDmbPu0oPzWXW7PAH6emoJVy4O44pFb0D1/rHLE1Ep4 7Q5KKLzzkHz67ado4kBO7Ytbtd9Gm5qudcGdtxQOx3Hkm6TkUpR+PEGn0qaYb9BTdZ0d HZe5cW9WuSmRT15iQ3faNtILbZT5mH7bHyBnIEpoz0XXBjlxplrlbBqYVD4JTKm/T9rq +Lxg== X-Gm-Message-State: AKS2vOyVBxQGbqzHuc/yVprC4Cnhp8OKtYj9+0+qQg0bw8GA7WDy8oTw jojwmLQPSI5jIxVoe57wkA== X-Received: by 10.84.143.162 with SMTP id 31mr2754806plz.277.1497412929593; Tue, 13 Jun 2017 21:02:09 -0700 (PDT) Received: from localhost.localdomain (66.29.164.166.static.utbb.net. [66.29.164.166]) by smtp.gmail.com with ESMTPSA id f8sm30914083pfc.14.2017.06.13.21.02.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jun 2017 21:02:08 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: adilger@dilger.ca, Jens Axboe Subject: [PATCH 04/10] fs: add support for allowing applications to pass in write life time hints Date: Tue, 13 Jun 2017 22:01:53 -0600 Message-Id: <1497412919-19400-5-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497412919-19400-1-git-send-email-axboe@kernel.dk> References: <1497412919-19400-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 Add four flags for the pwritev2(2) system call, allowing an application to give the kernel a hint about what on-media life times can be expected from a given write. The intent is for these values to be relative to each other, no absolute meaning should be attached to these flag names. Define IOCB flags to carry this information over, and finally transform them into the block defined stream values. Signed-off-by: Jens Axboe Reviewed-by: Andreas Dilger --- fs/read_write.c | 9 ++++++++- include/linux/fs.h | 12 ++++++++++++ include/uapi/linux/fs.h | 10 ++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/fs/read_write.c b/fs/read_write.c index 47c1d4484df9..a9b0c3125e0f 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -678,7 +678,7 @@ static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter, struct kiocb kiocb; ssize_t ret; - if (flags & ~(RWF_HIPRI | RWF_DSYNC | RWF_SYNC)) + if (flags & ~(RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_WRITE_LIFE_MASK)) return -EOPNOTSUPP; init_sync_kiocb(&kiocb, filp); @@ -688,6 +688,13 @@ static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter, kiocb.ki_flags |= IOCB_DSYNC; if (flags & RWF_SYNC) kiocb.ki_flags |= (IOCB_DSYNC | IOCB_SYNC); + if (flags & RWF_WRITE_LIFE_MASK) { + struct inode *inode = file_inode(filp); + + inode->i_stream = (flags & RWF_WRITE_LIFE_MASK) >> + RWF_WRITE_LIFE_SHIFT; + kiocb.ki_flags |= inode->i_stream << IOCB_WRITE_LIFE_SHIFT; + } kiocb.ki_pos = *ppos; if (type == READ) diff --git a/include/linux/fs.h b/include/linux/fs.h index 771e172d23d7..751a1046e87b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -269,6 +269,12 @@ struct writeback_control; #define IOCB_SYNC (1 << 5) #define IOCB_WRITE (1 << 6) +/* + * Steal 4-bits for stream information, this allows 16 valid streams + */ +#define IOCB_WRITE_LIFE_SHIFT 7 +#define IOCB_WRITE_LIFE_MASK (BIT(7) | BIT(8) | BIT(9) | BIT(10)) + struct kiocb { struct file *ki_filp; loff_t ki_pos; @@ -292,6 +298,12 @@ static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp) }; } +static inline int iocb_streamid(const struct kiocb *iocb) +{ + return (iocb->ki_flags & IOCB_WRITE_LIFE_MASK) >> + IOCB_WRITE_LIFE_SHIFT; +} + /* * "descriptor" for what we're up to with a read. * This allows us to use the same read code yet diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 24e61a54feaa..8a7e6f26f6f5 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -361,4 +361,14 @@ struct fscrypt_key { #define RWF_DSYNC 0x00000002 /* per-IO O_DSYNC */ #define RWF_SYNC 0x00000004 /* per-IO O_SYNC */ +/* + * Data life time write flags, steal 4 bits for that + */ +#define RWF_WRITE_LIFE_SHIFT 3 +#define RWF_WRITE_LIFE_MASK 0x000000f0 /* 4 bits of stream ID */ +#define RWF_WRITE_LIFE_SHORT (1 << RWF_WRITE_LIFE_SHIFT) +#define RWF_WRITE_LIFE_MEDIUM (2 << RWF_WRITE_LIFE_SHIFT) +#define RWF_WRITE_LIFE_LONG (3 << RWF_WRITE_LIFE_SHIFT) +#define RWF_WRITE_LIFE_EXTREME (4 << RWF_WRITE_LIFE_SHIFT) + #endif /* _UAPI_LINUX_FS_H */