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: 9787265 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 164A960325 for ; Wed, 14 Jun 2017 19:05:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0628D24B44 for ; Wed, 14 Jun 2017 19:05:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF4E32625B; Wed, 14 Jun 2017 19:05:48 +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 8E039251F4 for ; Wed, 14 Jun 2017 19:05:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751777AbdFNTFr (ORCPT ); Wed, 14 Jun 2017 15:05:47 -0400 Received: from mail-io0-f174.google.com ([209.85.223.174]:32989 "EHLO mail-io0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751598AbdFNTFo (ORCPT ); Wed, 14 Jun 2017 15:05:44 -0400 Received: by mail-io0-f174.google.com with SMTP id t87so6315958ioe.0 for ; Wed, 14 Jun 2017 12:05:43 -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=BODuMXLCunaM8g9IW6JkB6XtuWMASIeOre/3zDli9z5jpa2oNnQreWYQz5GrVDiTy5 s566W6CVh1TUcggUKl8csx4Z1TQUIDtnAKfxlDM8SRqDG3GLqeZr1a3FF33IrA5i+Et3 8GaP6kyjDOV0QM7zKxZjDT128u1GpSDN/+3/HHS85PUEcfw432c29vTSFzERs1WXCLWN RtI3UXzvjn3jjmof+wJuyjsZ9qmFmuitVm0tSubKHDbkmGkI2Rs/IDBxzgSRaKZoPFus Wc9m4ylY9OvCj8E5w+H1VTEe59qjSFfdoOTVtI0nyEHj66wEyCeg6PEuJiW+/UykYDXJ E5Gw== X-Gm-Message-State: AKS2vOx4mPKkxTiwnNyovDN1PwbC9i3UBMF1n8oKHpqtc5kL4+tx8I4e SsrgKEhrbFDdVjC6 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-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. 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 */