Fixup debug output (#1617)

This commit is contained in:
trapexit 2026-02-12 23:50:38 -05:00 • committed by GitHub
parent be4d388813
commit 3222de6c9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 1451 additions and 630 deletions

View file

@ -110,7 +110,7 @@ Config::Config()
lazy_umount_mountpoint(false),
link_cow(false),
link_exdev(LinkEXDEV::ENUM::PASSTHROUGH),
log_metrics(false),
log_file({}),
minfreespace(branches.minfreespace),
mountpoint(),
moveonenospc(true),
@ -137,7 +137,7 @@ Config::Config()
xattr(XAttr::ENUM::PASSTHROUGH),
_congestion_threshold(fuse_cfg.congestion_threshold),
_debug(fuse_cfg.debug),
_debug(false),
_gid(fuse_cfg.gid),
_max_background(fuse_cfg.max_background),
_mount(mountpoint),
@ -260,7 +260,7 @@ Config::Config()
_map["lazy-umount-mountpoint"] = &lazy_umount_mountpoint;
_map["link-cow"] = &link_cow;
_map["link-exdev"] = &link_exdev;
_map["log.metrics"] = &log_metrics;
_map["log.file"] = &log_file;
_map["minfreespace"] = &minfreespace;
_map["mount"] = &_mount;
_map["mountpoint"] = &_mountpoint;

View file

@ -19,12 +19,13 @@
#include "branches.hpp"
#include "category.hpp"
#include "config_cachefiles.hpp"
#include "config_debug.hpp"
#include "config_dummy.hpp"
#include "config_flushonclose.hpp"
#include "config_follow_symlinks.hpp"
#include "config_inodecalc.hpp"
#include "config_link_exdev.hpp"
#include "config_log_metrics.hpp"
#include "config_log_file.hpp"
#include "config_moveonenospc.hpp"
#include "config_nfsopenhack.hpp"
#include "config_noforget.hpp"
@ -140,7 +141,7 @@ public:
ConfigBOOL lazy_umount_mountpoint;
ConfigBOOL link_cow;
LinkEXDEV link_exdev;
LogMetrics log_metrics;
LogFile log_file;
TFSRef<u64> minfreespace;
fs::path mountpoint;
MoveOnENOSPC moveonenospc;
@ -169,7 +170,7 @@ public:
private:
TFSRef<int> _congestion_threshold;
TFSRef<bool> _debug;
Debug _debug;
CfgDummy _dummy;
TFSRef<s64> _gid;
TFSRef<int> _max_background;
@ -201,6 +202,7 @@ public:
void keys_xattr(std::string &s) const;
ssize_t keys_listxattr(char *list, size_t size) const;
ssize_t keys_listxattr_size() const;
const Str2TFStrMap& get_map() const { return _map; }
public:
int get(const std::string &key, std::string *val) const;

63
src/config_debug.cpp Normal file
View file

@ -0,0 +1,63 @@
/*
ISC License
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
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 appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config_debug.hpp"
#include "debug.hpp"
#include "from_string.hpp"
#include "fuse_cfg.hpp"
#include "to_string.hpp"
#include <memory>
#include <string>
Debug::Debug(const bool v_)
{
fuse_cfg.debug = v_;
}
std::string
Debug::to_string(void) const
{
return str::to(fuse_cfg.debug);
}
int
Debug::from_string(const std::string_view s_)
{
int rv;
bool val;
rv = str::from(s_,&val);
if(rv < 0)
return rv;
fuse_cfg.debug = val;
// If debug is being enabled, ensure output file is set
if(val)
{
auto log_file_path = fuse_cfg.log_filepath();
if(log_file_path && !log_file_path->empty())
fuse_debug_set_output(*log_file_path);
else
fuse_debug_set_output({}); // Use stderr
}
return 0;
}

31
src/config_debug.hpp Normal file
View file

@ -0,0 +1,31 @@
/*
ISC License
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
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 appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include "tofrom_string.hpp"
class Debug : public ToFromString
{
public:
Debug(const bool);
public:
std::string to_string(void) const final;
int from_string(const std::string_view) final;
};

View file

@ -16,38 +16,31 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config_log_metrics.hpp"
#include "from_string.hpp"
#include "to_string.hpp"
#include "config_log_file.hpp"
#include "fuse.h"
#include "debug.hpp"
#include "fuse_cfg.hpp"
LogMetrics::LogMetrics(const bool val_)
#include <memory>
#include <string>
LogFile::LogFile(const std::string &s_)
{
fuse_log_metrics_set(val_);
fuse_debug_set_output(s_);
}
std::string
LogMetrics::to_string(void) const
LogFile::to_string(void) const
{
bool val;
auto filepath = fuse_cfg.log_filepath();
val = fuse_log_metrics_get();
return str::to(val);
return (filepath ? *filepath : "");
}
int
LogMetrics::from_string(const std::string_view s_)
LogFile::from_string(const std::string_view s_)
{
int rv;
bool val;
const std::string s{s_};
rv = str::from(s_,&val);
if(rv < 0)
return rv;
fuse_log_metrics_set(val);
return 0;
return fuse_debug_set_output(s);
}

View file

@ -20,10 +20,10 @@
#include "tofrom_string.hpp"
class LogMetrics : public ToFromString
class LogFile : public ToFromString
{
public:
LogMetrics(const bool);
LogFile(const std::string &);
public:
std::string to_string(void) const final;

View file

@ -233,5 +233,13 @@ FUSE::init(fuse_conn_info *conn_)
SysLog::warning("passthrough and cache.writeback are incompatible.");
}
SysLog::info("Config:");
for(const auto &kv : cfg.get_map())
{
if(not kv.second->display)
continue;
SysLog::info("{}={}",kv.first,kv.second->to_string());
}
return NULL;
}

View file

@ -315,12 +315,16 @@ _main(int argc_,
SysLog::info("mergerfs v{} started",MERGERFS_VERSION);
SysLog::info("Go to https://trapexit.github.io/mergerfs/latest/support for support");
for(int i = 0; i < argc_; i++)
SysLog::info("argv[{}]: {}",i,argv_[i]);
options::parse(&args);
if(!cfg.errs.empty())
{
for(auto &err : cfg.errs)
{
std::string s = err.to_string();
const std::string s = err.to_string();
SysLog::error("error: {}",s);
fmt::println(stderr,"mergerfs: ERROR - {}",s);

View file

@ -172,6 +172,12 @@ _lshw(const std::string &output_)
::_run({"lshw"},output_);
}
static
void
_journalctl(const std::string &output_)
{
::_run({"journalctl","-t","mergerfs","--since","60 minutes ago"},output_);
}
int
mergerfs::collect_info::main(int argc_,
@ -208,6 +214,7 @@ mergerfs::collect_info::main(int argc_,
::_fstab(output_filepath);
::_software_versions(output_filepath);
::_lshw(output_filepath);
::_journalctl(output_filepath);
fmt::print("* Upload the following file to your"
" GitHub ticket or put on https://pastebin.com"