From patchwork Tue Jun 13 17:15:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9784391 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 08D9160212 for ; Tue, 13 Jun 2017 17:15:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1519274D1 for ; Tue, 13 Jun 2017 17:15:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D64C32853F; Tue, 13 Jun 2017 17:15:37 +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 6DB6D274D1 for ; Tue, 13 Jun 2017 17:15:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753311AbdFMRPf (ORCPT ); Tue, 13 Jun 2017 13:15:35 -0400 Received: from mail-it0-f52.google.com ([209.85.214.52]:37986 "EHLO mail-it0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753520AbdFMRPd (ORCPT ); Tue, 13 Jun 2017 13:15:33 -0400 Received: by mail-it0-f52.google.com with SMTP id l6so33100420iti.1 for ; Tue, 13 Jun 2017 10:15:32 -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=Rde1sAXKP/5+2WNByehMNtmVYYpxoQuJh4mRS46wXQw=; b=m53YRBq6kL8nZu1anDjnw/xKPGzRq1CCobAg6Xqg/ekA3hU6zml6A9PbivAiGk7QG9 g/7uyZ2YalXkDHhoANTZjd9etA56kn8CqUdsXtk4pjIYYRC+ydQXU8JscDgKVQWML5uH xv07tCi3crTcIuQJsVyismoYbbRQ0Z1IPjdDwjbkz6dqjrLkQIeKe8r3Q0Y5klpGJkc6 4C4XDQNHJGqXij0KOV9uhUDHGduUwIMuvEJC8nvBxIAAhcHG6pCt4WH7ZeGBSIy5IhQt dzOadvuXNrcpUcob10C7Hc9j2JctLtREHFX2CLRf6+6pK0bX2KQAnVYpNkEXO2Iw/xAJ t+ZA== 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=Rde1sAXKP/5+2WNByehMNtmVYYpxoQuJh4mRS46wXQw=; b=dfDJACvi8OGCeAgv2pl43ckPn3ct6wzNEuXE+EDQTakg9Hn4cAU1iVAEc8gwKDt7Tt 2aSCp8d0OXROQbD41iqwHpKF3s0oGXfYi1hAM8sf78bufLyVqsPdCXcQ+LPTY49MG121 w4Bn9b40Mdq9XYMM1XSQiyO6ZZdo/lP7jxC9qNmyx87P+dkKkPiz1NqkeCDlyeKS7bqa zqNYeMdz3CTDEQCkkw5RxKnraxnsJOL5UQUgG2qtbQXlFpjGI+lCGmlUe4u//FdIQczx KyDJJA9H5/5cO1KPp8vcLTyPIjyAkpjiodH1UeXhqNfK6wGbhUjtnd4PlhtRo26HCgos 6Fjg== X-Gm-Message-State: AKS2vOyaJNIOYT1gJMQmZwEVgeHg+eGQis2sUnUp21spY1hwUFK/k3Mg vE1K0K/3MC/0AYQ6r3gN0g== X-Received: by 10.36.26.21 with SMTP id 21mr1354400iti.6.1497374132083; Tue, 13 Jun 2017 10:15:32 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id y188sm6217526ity.9.2017.06.13.10.15.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jun 2017 10:15:31 -0700 (PDT) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 05/11] fs: add support for allowing applications to pass in write life time hints Date: Tue, 13 Jun 2017 11:15:17 -0600 Message-Id: <1497374123-15286-6-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497374123-15286-1-git-send-email-axboe@kernel.dk> References: <1497374123-15286-1-git-send-email-axboe@kernel.dk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 --- fs/read_write.c | 17 ++++++++++++++++- include/linux/fs.h | 18 ++++++++++++++++++ include/uapi/linux/fs.h | 4 ++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/fs/read_write.c b/fs/read_write.c index 47c1d4484df9..1734728aa48b 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -678,7 +678,9 @@ 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_SHORT | + RWF_WRITE_LIFE_MEDIUM | RWF_WRITE_LIFE_LONG | + RWF_WRITE_LIFE_EXTREME)) return -EOPNOTSUPP; init_sync_kiocb(&kiocb, filp); @@ -688,6 +690,19 @@ 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_SHORT) { + kiocb.ki_flags |= IOCB_WRITE_LIFE_SHORT; + file_inode(filp)->i_stream = WRITE_LIFE_SHORT; + } else if (flags & RWF_WRITE_LIFE_MEDIUM) { + kiocb.ki_flags |= IOCB_WRITE_LIFE_MEDIUM; + file_inode(filp)->i_stream = WRITE_LIFE_MEDIUM; + } else if (flags & RWF_WRITE_LIFE_LONG) { + kiocb.ki_flags |= IOCB_WRITE_LIFE_LONG; + file_inode(filp)->i_stream = WRITE_LIFE_LONG; + } else if (flags & RWF_WRITE_LIFE_EXTREME) { + kiocb.ki_flags |= IOCB_WRITE_LIFE_EXTREME; + file_inode(filp)->i_stream = WRITE_LIFE_EXTREME; + } kiocb.ki_pos = *ppos; if (type == READ) diff --git a/include/linux/fs.h b/include/linux/fs.h index bb8c246eeda8..7f542e0b0e17 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -269,6 +269,10 @@ struct writeback_control; #define IOCB_DSYNC (1 << 4) #define IOCB_SYNC (1 << 5) #define IOCB_WRITE (1 << 6) +#define IOCB_WRITE_LIFE_SHORT (1 << 7) +#define IOCB_WRITE_LIFE_MEDIUM (1 << 8) +#define IOCB_WRITE_LIFE_LONG (1 << 9) +#define IOCB_WRITE_LIFE_EXTREME (1 << 10) struct kiocb { struct file *ki_filp; @@ -293,6 +297,20 @@ static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp) }; } +static inline int iocb_streamid(const struct kiocb *iocb) +{ + if (iocb->ki_flags & IOCB_WRITE_LIFE_SHORT) + return WRITE_LIFE_SHORT; + else if (iocb->ki_flags & IOCB_WRITE_LIFE_MEDIUM) + return WRITE_LIFE_MEDIUM; + else if (iocb->ki_flags & IOCB_WRITE_LIFE_LONG) + return WRITE_LIFE_LONG; + else if (iocb->ki_flags & IOCB_WRITE_LIFE_EXTREME) + return WRITE_LIFE_EXTREME; + + return WRITE_LIFE_UNKNOWN; +} + /* * "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..34145b29657e 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -360,5 +360,9 @@ struct fscrypt_key { #define RWF_HIPRI 0x00000001 /* high priority request, poll if possible */ #define RWF_DSYNC 0x00000002 /* per-IO O_DSYNC */ #define RWF_SYNC 0x00000004 /* per-IO O_SYNC */ +#define RWF_WRITE_LIFE_SHORT 0x00000008 /* short life time write */ +#define RWF_WRITE_LIFE_MEDIUM 0x00000010 /* medium life time write */ +#define RWF_WRITE_LIFE_LONG 0x00000020 /* long life time write */ +#define RWF_WRITE_LIFE_EXTREME 0x00000040 /* extremely long life time write */ #endif /* _UAPI_LINUX_FS_H */