in turbonfs/src/nofuse.cpp [56:156]
static void __nofuse_init()
{
/*
* Must be called only once.
*/
assert(!aznfsc_cfg.config_yaml);
assert(aznfsc_cfg.mountpoint.empty());
init_log();
const char *nofuse_debug = ::getenv("AZNFSC_NOFUSE_DEBUG");
if (nofuse_debug && (::atoi(nofuse_debug) == 1)) {
enable_debug_logs = true;
spdlog::set_level(spdlog::level::debug);
}
aznfsc_cfg.config_yaml = ::getenv("AZNFSC_NOFUSE_CONFIG_YAML");
if (!aznfsc_cfg.config_yaml) {
AZLogError("[NOFUSE] Environment variable AZNFSC_NOFUSE_CONFIG_YAML not set!");
::exit(-1);
}
/*
* Parse config yaml.
*/
if (!aznfsc_cfg.parse_config_yaml()) {
assert(aznfsc_cfg.mountpoint.empty());
AZLogError("[NOFUSE] Failed to parse aznfsc config {}!", aznfsc_cfg.config_yaml);
::exit(-2);
}
/*
* account and container are mandatory parameters which do not have a
* default value, so ensure they are set before proceeding further.
*/
if (aznfsc_cfg.account == nullptr) {
assert(aznfsc_cfg.mountpoint.empty());
AZLogError("[NOFUSE] Account name not found in {}!", aznfsc_cfg.config_yaml);
::exit(-3);
}
if (aznfsc_cfg.container == nullptr) {
assert(aznfsc_cfg.mountpoint.empty());
AZLogError("[NOFUSE] Container name not found in {}!", aznfsc_cfg.config_yaml);
::exit(-4);
}
const char *nofuse_root = ::getenv("AZNFSC_NOFUSE_ROOT");
if (!nofuse_root) {
AZLogError("[NOFUSE] Environment variable AZNFSC_NOFUSE_ROOT not set!");
::exit(-5);
}
char *nofuse_root_abs = ::realpath(nofuse_root, NULL);
if (!nofuse_root_abs) {
AZLogError("[NOFUSE] __nofuse_init: realpath({}) failed: {}",
nofuse_root, ::strerror(errno));
::exit(-6);
}
if (::strcmp(nofuse_root, nofuse_root_abs) != 0) {
AZLogError("[NOFUSE] __nofuse_init: AZNFSC_NOFUSE_ROOT *must* be a "
"canonical path (absolute path with no '.', '..', "
"extra slashes or symlinks)!");
::exit(-7);
}
if (nofuse_root_abs[1] == '\0') {
AZLogError("[NOFUSE] __nofuse_init: AZNFSC_NOFUSE_ROOT cannot be /");
::exit(-8);
}
// Set default values for config variables not set using the above.
aznfsc_cfg.set_defaults_and_sanitize();
aznfsc_cfg.mountpoint = nofuse_root_abs;
::free(nofuse_root_abs);
/*
* Initialize nfs_client singleton.
* This creates the libnfs polling thread(s).
*/
if (!nfs_client::get_instance().init()) {
AZLogError("[NOFUSE] Failed to init the NFS client");
::exit(-9);
}
// Store nfs_client ref for easy access later.
PXT::client = &(nfs_client::get_instance());
const int ret = ::atexit(__nofuse_cleanup);
if (ret != 0) {
AZLogError("[NOFUSE] Failed to set exit handler: {}", ret);
::exit(-10);
}
AZLogInfo("[NOFUSE] Aznfsclient nofuse driver ready!");
init_done = true;
}