fs: add fcntl() interface for setting/getting write life time hints
authorJens Axboe <axboe@kernel.dk>
Mon, 19 Jun 2017 16:46:53 +0000 (10:46 -0600)
committerJens Axboe <axboe@kernel.dk>
Mon, 19 Jun 2017 16:46:53 +0000 (10:46 -0600)
commit9c17a17bd812e72b63bd81cd8e78e546a22fe077
treea2092f2458cafd74d09133cbe93e0551f2954fdb
parent443bd90f2cca9dec3db9ef9460a9c2a6f095f789
fs: add fcntl() interface for setting/getting write life time hints

Define a set of write life time hints:

and 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.

F_SET_RW_HINT Pass one of the above write hints.

The user passes in a 64-bit pointer to get/set these values, and
the interface returns 0/-1 on success/error.

Sample program testing/implementing basic setting/getting of write
hints is below.

Add support for storing the write life time hint in the inode flags,
and pass them to the kiocb flags as well. This is in preparation
for utilizing these hints in the block layer, to guide on-media
data placement.

/*
 * 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[])
{
uint64_t hint = -1ULL;
int fd, ret;

if (argc < 2) {
fprintf(stderr, "%s: dev <hint>\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 == -1ULL) {
ret = fcntl(fd, F_RW_GET_HINT, &hint);
if (ret < 0) {
perror("fcntl: F_RW_GET_HINT");
return 3;
}
} else {
ret = fcntl(fd, F_RW_SET_HINT, &hint);
if (ret < 0) {
perror("fcntl: F_RW_SET_HINT");
return 4;
}
}

printf("%s: %shint %s\n", argv[1], hint != -1ULL ? "set " : "", str[hint]);
close(fd);
return 0;
}

Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/fcntl.c
fs/inode.c
include/linux/fs.h
include/uapi/linux/fcntl.h