Add new debug printing routines

This commit is contained in:
Antonio SJ Musumeci 2021-10-11 22:47:59 -04:00
parent 2082357d3a
commit 18dead4d86
11 changed files with 1443 additions and 24 deletions

View File

@ -34,6 +34,7 @@ AR ?= ar
SRC = \ SRC = \
lib/buffer.c \ lib/buffer.c \
lib/crc32b.c \ lib/crc32b.c \
lib/debug.c \
lib/fuse.c \ lib/fuse.c \
lib/fuse_dirents.c \ lib/fuse_dirents.c \
lib/fuse_kern_chan.c \ lib/fuse_kern_chan.c \

View File

@ -694,7 +694,9 @@ int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, siz
int fuse_start_maintenance_thread(struct fuse *fuse); int fuse_start_maintenance_thread(struct fuse *fuse);
void fuse_stop_maintenance_thread(struct fuse *fuse); void fuse_stop_maintenance_thread(struct fuse *fuse);
void fuse_log_metrics(int enabled); int fuse_log_metrics_get(void);
void fuse_log_metrics_set(int enabled);
/** /**
* Iterate over cache removing stale entries * Iterate over cache removing stale entries

1278
libfuse/lib/debug.c Normal file

File diff suppressed because it is too large Load Diff

51
libfuse/lib/debug.h Normal file
View File

@ -0,0 +1,51 @@
/*
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 "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);

View File

@ -16,12 +16,12 @@
#include "lfmp.h" #include "lfmp.h"
#include "config.h" #include "config.h"
#include "fuse_i.h"
#include "fuse_lowlevel.h"
#include "fuse_opt.h"
#include "fuse_misc.h"
#include "fuse_kernel.h"
#include "fuse_dirents.h" #include "fuse_dirents.h"
#include "fuse_i.h"
#include "fuse_kernel.h"
#include "fuse_lowlevel.h"
#include "fuse_misc.h"
#include "fuse_opt.h"
#include <assert.h> #include <assert.h>
#include <dlfcn.h> #include <dlfcn.h>
@ -4282,7 +4282,13 @@ fuse_config_num_threads(const struct fuse *fuse_)
} }
void void
fuse_log_metrics(int log_) fuse_log_metrics_set(int log_)
{ {
g_LOG_METRICS = log_; g_LOG_METRICS = log_;
} }
int
fuse_log_metrics_get(void)
{
return g_LOG_METRICS;
}

View File

@ -11,6 +11,7 @@
#include "lfmp.h" #include "lfmp.h"
#include "config.h" #include "config.h"
#include "debug.h"
#include "fuse_i.h" #include "fuse_i.h"
#include "fuse_kernel.h" #include "fuse_kernel.h"
#include "fuse_opt.h" #include "fuse_opt.h"
@ -1735,6 +1736,9 @@ do_init(fuse_req_t req,
(void)nodeid; (void)nodeid;
if(f->debug)
debug_fuse_init_in(arg);
f->conn.proto_major = arg->major; f->conn.proto_major = arg->major;
f->conn.proto_minor = arg->minor; f->conn.proto_minor = arg->minor;
f->conn.capable = 0; f->conn.capable = 0;
@ -1906,6 +1910,9 @@ do_init(fuse_req_t req,
else else
outargsize = sizeof(outarg); outargsize = sizeof(outarg);
if(f->debug)
debug_fuse_init_out(req->unique,&outarg,outargsize);
send_reply_ok(req, &outarg, outargsize); send_reply_ok(req, &outarg, outargsize);
} }

View File

@ -91,6 +91,7 @@ Config::Config()
inodecalc("hybrid-hash"), inodecalc("hybrid-hash"),
link_cow(false), link_cow(false),
link_exdev(LinkEXDEV::ENUM::PASSTHROUGH), link_exdev(LinkEXDEV::ENUM::PASSTHROUGH),
log_metrics(false),
mount(), mount(),
moveonenospc(false), moveonenospc(false),
nfsopenhack(NFSOpenHack::ENUM::OFF), nfsopenhack(NFSOpenHack::ENUM::OFF),
@ -155,6 +156,7 @@ Config::Config()
_map["kernel_cache"] = &kernel_cache; _map["kernel_cache"] = &kernel_cache;
_map["link_cow"] = &link_cow; _map["link_cow"] = &link_cow;
_map["link-exdev"] = &link_exdev; _map["link-exdev"] = &link_exdev;
_map["log.metrics"] = &log_metrics;
_map["minfreespace"] = &minfreespace; _map["minfreespace"] = &minfreespace;
_map["mount"] = &mount; _map["mount"] = &mount;
_map["moveonenospc"] = &moveonenospc; _map["moveonenospc"] = &moveonenospc;

View File

@ -22,6 +22,7 @@
#include "config_follow_symlinks.hpp" #include "config_follow_symlinks.hpp"
#include "config_inodecalc.hpp" #include "config_inodecalc.hpp"
#include "config_link_exdev.hpp" #include "config_link_exdev.hpp"
#include "config_log_metrics.hpp"
#include "config_moveonenospc.hpp" #include "config_moveonenospc.hpp"
#include "config_nfsopenhack.hpp" #include "config_nfsopenhack.hpp"
#include "config_readdir.hpp" #include "config_readdir.hpp"
@ -121,6 +122,7 @@ public:
ConfigBOOL kernel_cache; ConfigBOOL kernel_cache;
ConfigBOOL link_cow; ConfigBOOL link_cow;
LinkEXDEV link_exdev; LinkEXDEV link_exdev;
LogMetrics log_metrics;
ConfigSTR mount; ConfigSTR mount;
MoveOnENOSPC moveonenospc; MoveOnENOSPC moveonenospc;
NFSOpenHack nfsopenhack; NFSOpenHack nfsopenhack;

View File

@ -0,0 +1,53 @@
/*
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.
*/
#include "config_log_metrics.hpp"
#include "from_string.hpp"
#include "to_string.hpp"
#include "fuse.h"
LogMetrics::LogMetrics(const bool val_)
{
fuse_log_metrics_set(val_);
}
std::string
LogMetrics::to_string(void) const
{
bool val;
val = fuse_log_metrics_get();
return str::to(val);
}
int
LogMetrics::from_string(const std::string &s_)
{
int rv;
bool val;
rv = str::from(s_,&val);
if(rv < 0)
return rv;
fuse_log_metrics_set(val);
return 0;
}

View File

@ -0,0 +1,31 @@
/*
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 "tofrom_string.hpp"
class LogMetrics : public ToFromString
{
public:
LogMetrics(const bool);
public:
std::string to_string(void) const final;
int from_string(const std::string &) final;
};

View File

@ -27,8 +27,6 @@
#include "str.hpp" #include "str.hpp"
#include "ugid.hpp" #include "ugid.hpp"
#include "fuse.h"
#include <string> #include <string>
#include <vector> #include <vector>
@ -45,12 +43,6 @@ using std::vector;
typedef char IOCTL_BUF[4096]; typedef char IOCTL_BUF[4096];
#define IOCTL_APP_TYPE 0xDF #define IOCTL_APP_TYPE 0xDF
#define IOCTL_FILE_INFO _IOWR(IOCTL_APP_TYPE,0,IOCTL_BUF) #define IOCTL_FILE_INFO _IOWR(IOCTL_APP_TYPE,0,IOCTL_BUF)
#define IOCTL_METRICS_ENABLE _IOWR(IOCTL_APP_TYPE,1,IOCTL_BUF)
#define IOCTL_METRICS_DISABLE _IOWR(IOCTL_APP_TYPE,2,IOCTL_BUF)
static_assert(IOCTL_FILE_INFO == 0xD000DF00,"");
static_assert(IOCTL_METRICS_ENABLE == 0xD000DF01,"");
static_assert(IOCTL_METRICS_DISABLE == 0xD000DF02,"");
#ifndef FS_IOC_GETFLAGS #ifndef FS_IOC_GETFLAGS
# define FS_IOC_GETFLAGS _IOR('f',1,long) # define FS_IOC_GETFLAGS _IOR('f',1,long)
@ -332,12 +324,6 @@ namespace l
{ {
case IOCTL_FILE_INFO: case IOCTL_FILE_INFO:
return l::file_info(ffi_,data_); return l::file_info(ffi_,data_);
case IOCTL_METRICS_ENABLE:
fuse_log_metrics(1);
return 0;
case IOCTL_METRICS_DISABLE:
fuse_log_metrics(0);
return 0;
} }
return -ENOTTY; return -ENOTTY;