From 24e423c71489f35cf9120339b6cc4bf74f6fb57e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 3 Dec 2018 12:58:42 -0800 Subject: [PATCH] ircd::fs: Add support test for fallocate(). --- include/ircd/fs/support.h | 3 +++ ircd/fs.cc | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/ircd/fs/support.h b/include/ircd/fs/support.h index 5d21812d7..ad11f13b6 100644 --- a/include/ircd/fs/support.h +++ b/include/ircd/fs/support.h @@ -20,4 +20,7 @@ namespace ircd::fs::support // Test if O_DIRECT supported at target path bool direct_io(const string_view &path); + + // Test if fallocate() is supported at target path + bool fallocate(const string_view &path, const write_opts &wopts = write_opts_default); } diff --git a/ircd/fs.cc b/ircd/fs.cc index 91a2d90b3..fdf316945 100644 --- a/ircd/fs.cc +++ b/ircd/fs.cc @@ -313,6 +313,40 @@ ircd::fs::path(std::string s) // fs/support.h // +bool +ircd::fs::support::fallocate(const string_view &path, + const write_opts &wopts) +try +{ + const fd::opts opts + { + std::ios::out + }; + + fs::fd fd + { + path, opts + }; + + fs::allocate(fd, info::page_size, wopts); + return true; +} +catch(const std::system_error &e) +{ + const auto &ec(e.code()); + if(system_category(ec)) switch(ec.value()) + { + case int(std::errc::invalid_argument): + case int(std::errc::operation_not_supported): + return false; + + default: + break; + } + + throw; +} + bool ircd::fs::support::direct_io(const string_view &path) try