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

File diff suppressed because it is too large Load diff

View file

@ -1,58 +0,0 @@
/*
ISC License
Copyright (c) 2021, 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 <string>
#include "fuse_kernel.h"
void debug_fuse_open_out(const uint64_t unique,
const struct fuse_open_out *arg,
const uint64_t argsize);
void debug_fuse_init_in(const struct fuse_init_in *arg);
void debug_fuse_init_out(const uint64_t unique,
const struct fuse_init_out *arg,
const uint64_t argsize);
void debug_fuse_entry_out(const uint64_t unique,
const struct fuse_entry_out *arg,
const uint64_t argsize);
void debug_fuse_attr_out(const uint64_t unique,
const struct fuse_attr_out *arg,
const uint64_t argsize);
void debug_fuse_entry_open_out(const uint64_t unique,
const struct fuse_entry_out *earg,
const struct fuse_open_out *oarg);
void debug_fuse_readlink(const uint64_t unique,
const char *linkname);
void debug_fuse_write_out(const uint64_t unique,
const struct fuse_write_out *arg);
void debug_fuse_statfs_out(const uint64_t unique,
const struct fuse_statfs_out *arg);
void debug_fuse_getxattr_out(const uint64_t unique,
const struct fuse_getxattr_out *arg);
void debug_fuse_lk_out(const uint64_t unique,
const struct fuse_lk_out *arg);
void debug_fuse_bmap_out(const uint64_t unique,
const struct fuse_bmap_out *arg);
void debug_fuse_in_header(const struct fuse_in_header *hdr);
std::string fuse_debug_init_flag_name(const uint64_t);
void fuse_syslog_fuse_init_in(const struct fuse_init_in *arg);
void fuse_syslog_fuse_init_out(const struct fuse_init_out *arg);

View file

@ -14,6 +14,7 @@
#include "syslog.hpp"
#include "crc32b.h"
#include "debug.hpp"
#include "khash.h"
#include "kvec.h"
#include "mutex.hpp"
@ -67,8 +68,6 @@
#define PARAM(inarg) ((void*)(((char*)(inarg)) + sizeof(*(inarg))))
static int g_LOG_METRICS = 0;
struct fuse_config
{
};
@ -3752,7 +3751,7 @@ fuse_populate_maintenance_thread(struct fuse *f_)
MaintenanceThread::push_job([=](int count_)
{
if(g_LOG_METRICS)
if(fuse_cfg.debug)
metrics_log_nodes_info_to_tmp_dir(f_);
});
}
@ -3777,8 +3776,6 @@ fuse_new(struct fuse_chan *ch,
if(fuse_opt_parse(args,&f.conf,fuse_lib_opts,fuse_lib_opt_proc) == -1)
goto out_free_fs;
g_LOG_METRICS = fuse_cfg.debug;
f.se = fuse_lowlevel_new_common(args,&llop,sizeof(llop),&f);
if(f.se == NULL)
goto out_free_fs;
@ -3854,18 +3851,6 @@ fuse_destroy(struct fuse *)
kv_destroy(f.remembered_nodes);
}
void
fuse_log_metrics_set(int log_)
{
g_LOG_METRICS = log_;
}
int
fuse_log_metrics_get(void)
{
return g_LOG_METRICS;
}
int
fuse_passthrough_open(const int fd_)
{

View file

@ -19,3 +19,28 @@ fuse_cfg_t::valid_umask() const
{
return (umask != FUSE_CFG_INVALID_UMASK);
}
std::shared_ptr<FILE>
fuse_cfg_t::log_file() const
{
return std::atomic_load(&_log_file);
}
void
fuse_cfg_t::log_file(std::shared_ptr<FILE> f_)
{
std::atomic_store(&_log_file, f_);
}
std::shared_ptr<std::string>
fuse_cfg_t::log_filepath() const
{
return std::atomic_load(&_log_filepath);
}
void
fuse_cfg_t::log_filepath(const std::string &s_)
{
std::atomic_store(&_log_filepath,
std::make_shared<std::string>(s_));
}

View file

@ -240,6 +240,15 @@ int
fuse_reply_err(fuse_req_t *req_,
int err_)
{
if(fuse_cfg.debug)
{
struct fuse_out_header hdr = {};
hdr.unique = req_->ctx.unique;
hdr.error = (err_ > 0) ? -err_ : err_;
hdr.len = sizeof(struct fuse_out_header);
fuse_debug_out_header(&hdr);
}
return send_reply(req_,err_,NULL,0);
}
@ -308,6 +317,9 @@ fuse_reply_entry(fuse_req_t *req,
// the kernel.
#endif
if(fuse_cfg.debug)
fuse_debug_entry_out(req->ctx.unique,&arg,size);
return send_reply_ok(req, &arg, size);
}
@ -331,6 +343,9 @@ fuse_reply_create(fuse_req_t *req,
fill_entry(earg, e);
fill_open(oarg, f);
if(fuse_cfg.debug)
fuse_debug_entry_open_out(req->ctx.unique,earg,oarg);
return send_reply_ok(req, &buf, entrysize + sizeof(struct fuse_open_out));
}
@ -347,6 +362,9 @@ fuse_reply_attr(fuse_req_t *req,
arg.attr_valid_nsec = 0;
convert_stat(attr,&arg.attr);
if(fuse_cfg.debug)
fuse_debug_attr_out(req->ctx.unique,&arg,size);
return send_reply_ok(req,&arg,size);
}
@ -363,6 +381,9 @@ fuse_reply_statx(fuse_req_t *req_,
outarg.attr_valid_nsec = 0;
outarg.stat = *(struct fuse_statx*)st_;
if(fuse_cfg.debug)
fuse_debug_statx_out(req_->ctx.unique,&outarg);
return send_reply_ok(req_,&outarg,sizeof(outarg));
}
@ -370,6 +391,9 @@ int
fuse_reply_readlink(fuse_req_t *req,
const char *linkname)
{
if(fuse_cfg.debug)
fuse_debug_readlink(req->ctx.unique,linkname);
return send_reply_ok(req, linkname, strlen(linkname));
}
@ -381,6 +405,9 @@ fuse_reply_open(fuse_req_t *req,
fill_open(&arg, f);
if(fuse_cfg.debug)
fuse_debug_open_out(req->ctx.unique,&arg,sizeof(arg));
return send_reply_ok(req, &arg, sizeof(arg));
}
@ -392,6 +419,9 @@ fuse_reply_write(fuse_req_t *req,
arg.size = count;
if(fuse_cfg.debug)
fuse_debug_write_out(req->ctx.unique,&arg);
return send_reply_ok(req, &arg, sizeof(arg));
}
@ -400,6 +430,9 @@ fuse_reply_buf(fuse_req_t *req,
const char *buf,
size_t size)
{
if(fuse_cfg.debug)
fuse_debug_data_out(req->ctx.unique,size);
return send_reply_ok(req, buf, size);
}
@ -436,6 +469,9 @@ fuse_reply_data(fuse_req_t *req,
out.unique = req->ctx.unique;
out.error = 0;
if(fuse_cfg.debug)
fuse_debug_data_out(req->ctx.unique,bufsize_);
res = fuse_send_msg(req->f,req->ch,iov,2);
if(res <= 0)
{
@ -458,6 +494,9 @@ fuse_reply_statfs(fuse_req_t *req,
convert_statfs(stbuf, &arg.st);
if(fuse_cfg.debug)
fuse_debug_statfs_out(req->ctx.unique,&arg);
return send_reply_ok(req, &arg, size);
}
@ -469,6 +508,9 @@ fuse_reply_xattr(fuse_req_t *req,
arg.size = count;
if(fuse_cfg.debug)
fuse_debug_getxattr_out(req->ctx.unique,&arg);
return send_reply_ok(req, &arg, sizeof(arg));
}
@ -489,6 +531,9 @@ fuse_reply_lock(fuse_req_t *req,
}
arg.lk.pid = lock->l_pid;
if(fuse_cfg.debug)
fuse_debug_lk_out(req->ctx.unique,&arg);
return send_reply_ok(req, &arg, sizeof(arg));
}
@ -500,6 +545,9 @@ fuse_reply_bmap(fuse_req_t *req,
arg.block = idx;
if(fuse_cfg.debug)
fuse_debug_bmap_out(req->ctx.unique,&arg);
return send_reply_ok(req, &arg, sizeof(arg));
}
@ -541,6 +589,9 @@ fuse_reply_ioctl_retry(fuse_req_t *req,
arg.flags |= FUSE_IOCTL_RETRY;
arg.in_iovs = in_count;
arg.out_iovs = out_count;
if(fuse_cfg.debug)
fuse_debug_ioctl_out(req->ctx.unique,&arg);
iov[count].iov_base = &arg;
iov[count].iov_len = sizeof(arg);
count++;
@ -619,6 +670,9 @@ fuse_reply_ioctl(fuse_req_t *req,
arg.in_iovs = 0;
arg.out_iovs = 0;
if(fuse_cfg.debug)
fuse_debug_ioctl_out(req->ctx.unique,&arg);
count = 1;
iov[count].iov_base = &arg;
iov[count].iov_len = sizeof(arg);
@ -649,6 +703,10 @@ fuse_reply_ioctl_iov(fuse_req_t *req,
return fuse_reply_err(req, ENOMEM);
arg.result = result;
if(fuse_cfg.debug)
fuse_debug_ioctl_out(req->ctx.unique,&arg);
padded_iov[1].iov_base = &arg;
padded_iov[1].iov_len = sizeof(arg);
@ -668,6 +726,9 @@ fuse_reply_poll(fuse_req_t *req,
arg.revents = revents;
if(fuse_cfg.debug)
fuse_debug_poll_out(req->ctx.unique,&arg);
return send_reply_ok(req, &arg, sizeof(arg));
}
@ -1272,6 +1333,9 @@ do_init(fuse_req_t *req,
fuse_syslog_fuse_init_out(&outarg);
if(fuse_cfg.debug)
fuse_debug_init_out(req->ctx.unique,&outarg,outargsize);
send_reply_ok(req, &outarg, outargsize);
}
@ -1722,9 +1786,13 @@ fuse_send_errno(struct fuse_ll *f_,
out.unique = unique_id_;
out.error = -errno_;
out.len = sizeof(struct fuse_out_header);
iov.iov_base = &out;
iov.iov_len = sizeof(struct fuse_out_header);
if(fuse_cfg.debug)
fuse_debug_out_header(&out);
fuse_send_msg(f_,ch_,&iov,1);
}
@ -1777,6 +1845,9 @@ fuse_ll_buf_process_read(struct fuse_session *se_,
in = (struct fuse_in_header*)msgbuf_->mem;
if(fuse_cfg.debug)
fuse_debug_in_header(in);
req = fuse_ll_alloc_req(se_->f);
if(req == NULL)
return fuse_send_enomem(se_->f,se_->ch,in->unique);
@ -1817,6 +1888,9 @@ fuse_ll_buf_process_read_init(struct fuse_session *se_,
in = (struct fuse_in_header*)msgbuf_->mem;
if(fuse_cfg.debug)
fuse_debug_in_header(in);
req = fuse_ll_alloc_req(se_->f);
if(req == NULL)
return fuse_send_enomem(se_->f,se_->ch,in->unique);