0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-10 05:58:56 +02:00

ircd::fs: Consolidate support tests and indications into namespace.

This commit is contained in:
Jason Volk 2018-12-03 12:43:42 -08:00
parent f2ecf617ba
commit 47d6fbb35f
4 changed files with 83 additions and 43 deletions

View file

@ -88,6 +88,7 @@ enum ircd::fs::index
#include "write.h"
#include "fsync.h"
#include "stdin.h"
#include "support.h"
struct ircd::fs::init
{

23
include/ircd/fs/support.h Normal file
View file

@ -0,0 +1,23 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_FS_SUPPORT_H
namespace ircd::fs::support
{
// Indicator lights for AIO
extern const bool aio; // Any AIO support.
extern const bool aio_fsync; // Kernel supports CMD_FSYNC
extern const bool aio_fdsync; // Kernel supports CMD_FDSYNC
// Test if O_DIRECT supported at target path
bool direct_io(const string_view &path);
}

View file

@ -255,7 +255,7 @@ try
direct_io_test_file_path()
};
if(fs::direct_io_support(test_file_path))
if(fs::support::direct_io(test_file_path))
log::debug
{
log, "Detected Direct-IO works by opening test file at `%s'",

View file

@ -227,30 +227,6 @@ catch(const filesystem::filesystem_error &e)
throw error{e};
}
bool
ircd::fs::direct_io_support(const string_view &path)
try
{
fd::opts opts{std::ios::out};
opts.direct = true;
fd{path, opts};
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):
return false;
default:
break;
}
throw;
}
size_t
ircd::fs::size(const string_view &path)
{
@ -332,6 +308,62 @@ ircd::fs::path(std::string s)
return filesystem::path(std::move(s));
}
///////////////////////////////////////////////////////////////////////////////
//
// fs/support.h
//
bool
ircd::fs::support::direct_io(const string_view &path)
try
{
fd::opts opts{std::ios::out};
opts.direct = true;
fd{path, opts};
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):
return false;
default:
break;
}
throw;
}
/// True if AIO is supported by this build and runtime.
decltype(ircd::fs::support::aio)
ircd::fs::support::aio
{
#ifdef IRCD_USE_AIO
true
#else
false
#endif
};
/// True if IOCB_CMD_FSYNC is supported by AIO. If this is false then
/// fs::fsync_opts::async=true flag is ignored.
decltype(ircd::fs::support::aio_fsync)
ircd::fs::support::aio_fsync
{
false //TODO: Detect kernel support
};
/// True if IOCB_CMD_FDSYNC is supported by AIO. If this is false then
/// fs::fsync_opts::async=true flag is ignored.
decltype(ircd::fs::support::aio_fdsync)
ircd::fs::support::aio_fdsync
{
false //TODO: Detect kernel support
};
///////////////////////////////////////////////////////////////////////////////
//
// fs/stdin.h
@ -406,7 +438,7 @@ ircd::fs::fsync(const fd &fd,
try
{
#ifdef IRCD_USE_AIO
if(aio::context && opts.async && aio::available_fsync)
if(aio::context && opts.async && support::aio_fsync)
return aio::fsync(fd, opts);
#endif
@ -434,7 +466,7 @@ ircd::fs::fdsync(const fd &fd,
try
{
#ifdef IRCD_USE_AIO
if(aio::context && opts.async && aio::available_fdsync)
if(aio::context && opts.async && support::aio_fdsync)
return aio::fdsync(fd, opts);
#endif
@ -901,22 +933,6 @@ ircd::fs::aio::stats;
decltype(ircd::fs::aio::context)
ircd::fs::aio::context;
/// True if IOCB_CMD_FSYNC is supported by AIO. If this is false then
/// fs::fsync_opts::async=true flag is ignored.
decltype(ircd::fs::aio::available_fsync)
ircd::fs::aio::available_fsync
{
false //TODO: Detect kernel support
};
/// True if IOCB_CMD_FDSYNC is supported by AIO. If this is false then
/// fs::fsync_opts::async=true flag is ignored.
decltype(ircd::fs::aio::available_fdsync)
ircd::fs::aio::available_fdsync
{
false //TODO: Detect kernel support
};
//
// init
//