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: 9794405 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 BAD96600F6 for ; Sat, 17 Jun 2017 20:00:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF8F227E71 for ; Sat, 17 Jun 2017 20:00:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A45FC27FAC; Sat, 17 Jun 2017 20:00:34 +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 5123027E71 for ; Sat, 17 Jun 2017 20:00:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752862AbdFQUAb (ORCPT ); Sat, 17 Jun 2017 16:00:31 -0400 Received: from mail-it0-f49.google.com ([209.85.214.49]:33343 "EHLO mail-it0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752675AbdFQUAK (ORCPT ); Sat, 17 Jun 2017 16:00:10 -0400 Received: by mail-it0-f49.google.com with SMTP id g184so7129652ita.0 for ; Sat, 17 Jun 2017 13:00: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=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=k5o3bkyN9ZPU5hXfL/V300nXVUeTze7SOL8w22wugGix2cMSEPfbfrdaTK/8AU/fxQ pcRzH0JpApjLVQhNQSFoDfnUnZJzgwuh2VpSwR0t4qGLIECcNLyuLILURiWTBDn7oGFm MZ8I+MaiE5n3JR152Gqk9Hz5Kz9DvM59JRBThdw7M5PpHo66kxSsjGd+x34o5koyDkdv L/FmF8Ws6TS7KB0VAmZs+ZKXAwbVUQQzi7Gj9nWu1CZGHvcb4b7KhMzVx0cbn+YFSNrR jSdbzDYdwC+ZNAaBmnYVKu+oC0oZgme9jUH1I/ikimAej3huEGxVWtMcD4UnPgz539vm mmZw== X-Gm-Message-State: AKS2vOwRiuvIySkqM9Bld58G06IUD8RSc7yq8ZBEZWCqCTFlPLCTe/Mq yfMr9sEQl1xmRo/Hpkg9ig== 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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 */