From patchwork Sat Jun 17 19:59:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 9794403 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 49B10600F6 for ; Sat, 17 Jun 2017 20:00:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DC9D27E71 for ; Sat, 17 Jun 2017 20:00:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 329B227FAC; Sat, 17 Jun 2017 20:00:33 +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 C3C1827E71 for ; Sat, 17 Jun 2017 20:00:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752675AbdFQUAb (ORCPT ); Sat, 17 Jun 2017 16:00:31 -0400 Received: from mail-it0-f44.google.com ([209.85.214.44]:36868 "EHLO mail-it0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752373AbdFQUAK (ORCPT ); Sat, 17 Jun 2017 16:00:10 -0400 Received: by mail-it0-f44.google.com with SMTP id m47so41603886iti.0 for ; Sat, 17 Jun 2017 13:00:09 -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=drUo5J0qaGbahKyvTo8NxM/EWquoDOMS+0FVAh6pAhE=; b=Y0uecf5Am4AHytaGt3BiFZrv0Z+Jan5lZ8pxAMF6+LRHi/LAqmZMczJPHAGF69dEdz BHZDtsLxcAcEX8Stz+SHzv4jaX0AtzIDPuMAI4iStmRzjgownDr0ZPqsTYV53b/1VbV9 ztAkgyZJacrkB/mnMk2g5nPmg6aCV5aM6pslhOna88qBnpfXIDDXfImtQSrZZnL1heEQ 7g7rb/NFLZNNqJwxYy6vliT4DysKrMpW0YSAfTGbkE8VRDSaaFENsuyFeVb556h7ZrrY NwoNOZvO5uSmKjBMTFgKjLGStEWpAYBSaFp2lLv1wLmyKZqNZ9J34e3fQMdu9HSVUHnf FM+g== 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=drUo5J0qaGbahKyvTo8NxM/EWquoDOMS+0FVAh6pAhE=; b=pgnt4UcWn3ynF99jakvfT0wxUS8eleb8Cw71KWYfQOgFLSlgKi17T51S9ZLljkYh+4 yA6Km/qttBtdKEgE5EsJfI8jqzQSutwuyjfZv3gVrDTyMMt9tLwYlM9uUhH+zFdTuD2B bWr9/PpW1FKqwSorfy3phIGil2QmmTAFnPBGSDaQohi/E6LR6kO4/LYM8l4E0xaylvd4 nb+/2t8mWVLrRrkJZir7PEMQ9K8AFtkaHNXnNL+crjfVoBuoJ16f1Q4+jdM9IhnfpPtz qe00Ao3ZXjvorugLlyWwcScAVzWAOdFuVokuVo+AirncviTF2F5DMLcSsdfjnLrUIXmx 1/Eg== X-Gm-Message-State: AKS2vOzal+lsiQBH1w0mb6/jZgx5L699iyIJ/ZZL63FfwjM0+y3z375f iPaDyAihyt3w7nMR X-Received: by 10.36.89.137 with SMTP id p131mr16530389itb.12.1497729609290; Sat, 17 Jun 2017 13:00:09 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id w199sm537049iod.15.2017.06.17.13.00.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Jun 2017 13:00:08 -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 05/11] fs: add fcntl() interface for setting/getting write life time hints Date: Sat, 17 Jun 2017 13:59:48 -0600 Message-Id: <1497729594-4707-6-git-send-email-axboe@kernel.dk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497729594-4707-1-git-send-email-axboe@kernel.dk> References: <1497729594-4707-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 We have a pwritev2(2) interface based on passing in flags. Add an fcntl interface for querying these flags, and also for setting them as well: F_GET_RW_HINT Returns the read/write hint set. Right now it will be one of the WRITE_LIFE_* values. F_SET_RW_HINT Pass in rw_hint type to set the read/write hint. Only WRITE_LIFE_* hints are currently supported. Returns 0 on succes, -1 otherwise. Sample program testing/implementing basic setting/getting of write hints is below. /* * writehint.c: check or set a file/inode write hint */ static char *str[] = { "WRITE_LIFE_NONE", "WRITE_LIFE_SHORT", "WRITE_LIFE_MEDIUM", "WRITE_LIFE_LONG", "WRITE_LIFE_EXTREME" }; int main(int argc, char *argv[]) { int hint = -1, fd, ret; if (argc < 2) { fprintf(stderr, "%s: dev \n", argv[0]); return 1; } fd = open(argv[1], O_RDONLY); if (fd < 0) { perror("open"); return 2; } if (argc > 2) hint = atoi(argv[2]); if (hint == -1) { ret = fcntl(fd, F_GET_RW_HINT); if (ret < 0) { perror("fcntl: F_GET_RW_HINT"); return 3; } hint = ret; } else { ret = fcntl(fd, F_SET_RW_HINT, hint); if (ret < 0) { perror("fcntl: F_SET_RW_HINT"); return 4; } } printf("%s: %shint %s\n", argv[1], hint != -1 ? "set " : "", str[hint]); close(fd); return 0; } Signed-off-by: Jens Axboe --- fs/fcntl.c | 38 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/fcntl.h | 6 ++++++ 2 files changed, 44 insertions(+) diff --git a/fs/fcntl.c b/fs/fcntl.c index f4e7267d117f..417ce336c875 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -243,6 +243,40 @@ static int f_getowner_uids(struct file *filp, unsigned long arg) } #endif +long fcntl_rw_hint(struct file *file, unsigned int cmd, unsigned long arg) +{ + struct inode *inode = file_inode(file); + long ret; + + switch (cmd) { + case F_GET_RW_HINT: + ret = mask_to_write_hint(inode->i_flags, S_WRITE_LIFE_SHIFT); + break; + case F_SET_RW_HINT: { + enum rw_hint hint = arg; + + switch (hint) { + case WRITE_LIFE_NONE: + case WRITE_LIFE_SHORT: + case WRITE_LIFE_MEDIUM: + case WRITE_LIFE_LONG: + case WRITE_LIFE_EXTREME: + inode_set_write_hint(inode, hint); + ret = 0; + break; + default: + ret = -EINVAL; + } + break; + } + default: + ret = -EINVAL; + break; + } + + return ret; +} + static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, struct file *filp) { @@ -337,6 +371,10 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg, case F_GET_SEALS: err = shmem_fcntl(filp, cmd, arg); break; + case F_GET_RW_HINT: + case F_SET_RW_HINT: + err = fcntl_rw_hint(filp, cmd, arg); + break; default: break; } diff --git a/include/uapi/linux/fcntl.h b/include/uapi/linux/fcntl.h index 813afd6eee71..f1a0fbc5bff1 100644 --- a/include/uapi/linux/fcntl.h +++ b/include/uapi/linux/fcntl.h @@ -43,6 +43,12 @@ /* (1U << 31) is reserved for signed error codes */ /* + * Set/Get write life time hints + */ +#define F_GET_RW_HINT (F_LINUX_SPECIFIC_BASE + 11) +#define F_SET_RW_HINT (F_LINUX_SPECIFIC_BASE + 12) + +/* * Types of directory notifications that may be requested. */ #define DN_ACCESS 0x00000001 /* File accessed */