From patchwork Wed Jun 14 19:05:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9787271 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 549C360325 for ; Wed, 14 Jun 2017 19:05:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47CDD23D5E for ; Wed, 14 Jun 2017 19:05:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C478268AE; Wed, 14 Jun 2017 19:05:56 +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 7DFA324B44 for ; Wed, 14 Jun 2017 19:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751907AbdFNTFv (ORCPT ); Wed, 14 Jun 2017 15:05:51 -0400 Received: from mail-io0-f169.google.com ([209.85.223.169]:35642 "EHLO mail-io0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750768AbdFNTFo (ORCPT ); Wed, 14 Jun 2017 15:05:44 -0400 Received: by mail-io0-f169.google.com with SMTP id k93so6259432ioi.2 for ; Wed, 14 Jun 2017 12:05:44 -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=m+1iW5lErEU9baWncjaHvxvMdBep17pfgOKAEfpuuCY=; b=iudPJYJWjL6xBSgJximQMtZSryeuRd0vHX/DB7K1ylbetbit1Q8MudLtyOGAoiRuxc DiLAZrtW9d99B6qu/HAx13UV/017f59qgTbTfi8qnShnwq4ZbEjIkMeYg5q3YSKCDfrF 8UU9RNOpF/A7C9RORnQgz51zmC5uVzqgD9x2X2XujmOW9WuJN02DmbuU2eUS0HVlBsEx m27R/2298PenEh9IU1M6vDKCu3l6mzRenZyz47TT5TrA10DxY8Jy4ZMP7slVeHSfZ5Kb qv7hYE7DvVs9BkpZx54c51JtpkAqnwZAwIkU/ZxsnXsnCremsdliEp0/AhQHSqZNrmND Tlvw== 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=m+1iW5lErEU9baWncjaHvxvMdBep17pfgOKAEfpuuCY=; b=Ip49x8YJcShsIH774G4pMAx/nxldOWdadP34m5ue5BeFt/ituia58puaPSSwLtnalt 7e/PNkYkhdi0sBSJCjxagAx5RxQ2hFFI0Ekzu03kRgiR8/YKX0ZYBxlknRcylRMdNnUh G3E/ITc3parHfVdWIL5uuz37awURIsWMUAZz3y9faATvuTqEsN2/Nk8UC/ockjcnlINL XbPD6EqTNcI9xPe0K2EtZ1/hipXvEodkBhJOJ+HI4GhQQzHT2+BLrsyVc4jXG5l1YKuR CZyDU1zs4TnhY07Cd7ZnYSTQTr97Hiqy3ZWPafNvu1Ya3s8uXQ4wXrfiSI1p5mC4vE0p vGqg== X-Gm-Message-State: AKS2vOyPb9F+ACBhqT2lUOOexQzh911g/GIUpdgqnAKztDekwTt9nVJU 3w+YQjVbmkbjgGN4M9Iq2w== X-Received: by 10.107.133.228 with SMTP id p97mr1568633ioi.69.1497467143081; Wed, 14 Jun 2017 12:05:43 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id h67sm380361itb.19.2017.06.14.12.05.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 12:05:42 -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 04/11] fs: add support for allowing applications to pass in write life time hints Date: Wed, 14 Jun 2017 13:05:27 -0600 Message-Id: <1497467134-6323-5-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497467134-6323-1-git-send-email-axboe@kernel.dk> References: <1497467134-6323-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. Reviewed-by: Andreas Dilger Signed-off-by: Jens Axboe --- 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..58b7ee06b380 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 4 +#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 */