12 #define ENOATTR ENODATA
13 #define _FILE_OFFSET_BITS 64
15 #include "cvmfs_config.h"
24 #include <sys/resource.h>
29 #ifdef HAS_VALGRIND_HEADERS
30 #include <valgrind/valgrind.h>
88 #define CVMFS_OPT(t, p, v) { t, offsetof(struct CvmfsOptions, p), v }
89 #define CVMFS_SWITCH(t, p) { t, offsetof(struct CvmfsOptions, p), 1 }
98 CVMFS_SWITCH(
"simple_options_parsing", simple_options_parsing),
150 static void Usage(
const string &exename) {
152 "The CernVM File System\n"
154 "Copyright (c) 2009- CERN, all rights reserved\n\n"
155 "Please visit http://cernvm.cern.ch for details.\n\n"
156 "Usage: %s [-h] [-V] [-s] [-f] [-d] [-k] [-o mount options] "
157 "<repository name> <mount point>\n\n"
158 "CernVM-FS general options:\n"
159 " --help|-h Print Help output (this)\n"
160 " --version|-V Print CernVM-FS version\n"
161 " -s Run singlethreaded\n"
162 " -f Run in foreground\n"
163 " -d Enable debugging\n"
164 " -k Parse options\n"
165 "CernVM-FS mount options:\n"
166 " -o config=FILES colon-separated path list of config files\n"
167 " -o uid=UID Drop credentials to another user\n"
168 " -o gid=GID Drop credentials to another group\n"
169 " -o system_mount Indicate that mount is system-wide\n"
170 " -o grab_mountpoint give ownership of the mountpoint to the user "
171 "before mounting (required for autofs)\n"
172 " -o parse Parse and print cvmfs parameters\n"
173 " -o cvmfs_suid Enable suid mode\n\n"
174 " -o disable_watchdog Do not spawn a post mortem crash handler\n"
175 " -o foreground Run in foreground\n"
176 " -o libfuse=[2,3] Enforce a certain libfuse version\n"
177 "Fuse mount options:\n"
178 " -o allow_other allow access to other users\n"
179 " -o allow_root allow access to root\n"
180 " -o nonempty allow mounts over non-empty directory\n",
181 PACKAGE_VERSION, exename.c_str());
191 bool retval = (sscanf(mountpoint.c_str(),
"/dev/fd/%u%n", &fd, &len) == 1) &&
193 (static_cast<unsigned>(len) == mountpoint.length());
196 "CernVM-FS: pre-mounted on file descriptor %d", fd);
203 static void stub_init(
void *userdata,
struct fuse_conn_info *conn) {
224 struct fuse_file_info *fi)
238 struct fuse_file_info *fi)
246 struct fuse_file_info *fi)
254 off_t off,
struct fuse_file_info *fi)
262 struct fuse_file_info *fi)
269 static void stub_read(fuse_req_t req, fuse_ino_t ino,
size_t size, off_t off,
270 struct fuse_file_info *fi)
278 struct fuse_file_info *fi)
292 static void stub_getxattr(fuse_req_t req, fuse_ino_t ino,
const char *name,
293 size_t size, uint32_t position)
317 #
if CVMFS_USE_LIBFUSE == 2
318 unsigned long nlookup
328 #if (FUSE_VERSION >= 29)
329 static void stub_forget_multi(
332 struct fuse_forget_data *forgets
347 int key,
struct fuse_args *outargs)
351 arglen = strlen(arg);
353 case FUSE_OPT_KEY_OPT:
355 if ((arglen > 0) && (arg[0] !=
'-')) {
358 unsigned olen = strlen(*o);
359 if ((arglen > olen && arg[olen] ==
'=') &&
360 (strncasecmp(arg, *o, olen) == 0))
366 case FUSE_OPT_KEY_NONOPT:
380 Usage(outargs->argv[0]);
393 fuse_opt_add_arg(outargs,
"-d");
406 struct fuse_args *mount_options =
new fuse_args();
408 memset(&cvmfs_options, 0,
sizeof(cvmfs_options));
410 mount_options->argc = argc;
411 mount_options->argv = argv;
412 mount_options->allocated = 0;
417 delete mount_options;
420 if (cvmfs_options.
config) {
422 free(cvmfs_options.
config);
435 fuse_opt_add_arg(mount_options,
"-d");
438 return mount_options;
443 memset(loader_operations, 0,
sizeof(*loader_operations));
465 return dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL);
470 #ifdef HAS_VALGRIND_HEADERS
473 if (!RUNNING_ON_VALGRIND) {
477 #ifdef HAS_VALGRIND_HEADERS
486 std::string local_lib_path =
"./";
487 if (getenv(
"CVMFS_LIBRARY_PATH") != NULL) {
488 local_lib_path = getenv(
"CVMFS_LIBRARY_PATH");
489 if (!local_lib_path.empty() && (*local_lib_path.rbegin() !=
'/'))
490 local_lib_path.push_back(
'/');
493 #if CVMFS_USE_LIBFUSE == 2
494 string library_name = string(
"cvmfs_fuse") + ((debug_mode) ?
"_debug" :
"");
496 string library_name = string(
"cvmfs_fuse3") + ((debug_mode) ?
"_debug" :
"");
499 string error_messages;
501 vector<string> library_paths;
502 if (library_paths.empty()) {
503 library_paths.push_back(local_lib_path + library_name);
504 library_paths.push_back(
"/usr/lib/" + library_name);
505 library_paths.push_back(
"/usr/lib64/" + library_name);
509 library_paths.push_back(
"/usr/local/lib/" + library_name);
513 vector<string>::const_iterator i = library_paths.begin();
514 vector<string>::const_iterator iend = library_paths.end();
515 for (; i != iend; ++i) {
521 error_messages += string(dlerror()) +
"\n";
526 "failed to load cvmfs library, tried: '%s'\n%s",
527 JoinStrings(library_paths,
"' '").c_str(), error_messages.c_str());
536 if (loader_exports) {
539 load_event->
so_version = (*exports_ptr)->so_version;
540 loader_exports->
history.push_back(load_event);
564 SendMsg2Socket(fd_progress,
"Waiting for active file system calls\n");
578 SendMsg2Socket(fd_progress,
"Waiting for the delivery of SIGUSR1...\n");
616 using namespace loader;
630 if ((argc > 1) && (strstr(argv[1],
"__") == argv[1])) {
631 if (
string(argv[1]) ==
string(
"__RELOAD__")) {
634 bool stop_and_go =
false;
635 if ((argc > 3) && (
string(argv[3]) ==
"stop_and_go"))
647 if (std::string(argv[argc - 1]) == std::string(
"--debug")) {
654 if ((retval != 0) && (stop_and_go)) {
655 CreateFile(
string(argv[2]) +
".paused.crashed", 0600);
660 if (
string(argv[1]) ==
string(
"__MK_ALIEN_CACHE__")) {
663 string alien_cache_dir = argv[2];
670 int retval =
MkdirDeep(alien_cache_dir, 0770);
673 alien_cache_dir.c_str());
676 retval = chown(alien_cache_dir.c_str(), uid_owner, gid_owner);
679 alien_cache_dir.c_str(), uid_owner, gid_owner);
685 uid_owner, gid_owner);
697 debug_mode_ = getenv(
"__CVMFS_DEBUG_MODE__") != NULL;
705 struct fuse_args *mount_options;
707 if (!mount_options) {
723 for (
unsigned i = 0, s = tokens.size(); i < s; ++i) {
724 options_manager->
ParsePath(tokens[i],
false);
732 fuse_opt_add_arg(mount_options, volname.c_str());
734 fuse_opt_add_arg(mount_options,
"-odaemon_timeout=300");
735 fuse_opt_add_arg(mount_options,
"-onoapplexattr");
739 if (options_manager->
GetValue(
"CVMFS_MOUNT_RW", ¶meter) &&
740 options_manager->
IsOn(parameter))
742 fuse_opt_add_arg(mount_options,
"-orw");
744 fuse_opt_add_arg(mount_options,
"-oro");
746 fuse_opt_add_arg(mount_options,
"-onodev");
747 if (options_manager->
GetValue(
"CVMFS_SUID", ¶meter) &&
748 options_manager->
IsOn(parameter))
755 "must be root to mount with suid option");
757 fuse_opt_add_arg(mount_options,
"-osuid");
761 if (options_manager->
GetValue(
"CVMFS_CPU_AFFINITY", ¶meter)) {
766 for (vector<string>::iterator i = cpus.begin(); i != cpus.end(); i++) {
770 "CernVM-FS: setting CPU Affinity to %s", parameter.c_str());
771 int err = sched_setaffinity(0,
sizeof(mask), &mask);
774 "Setting CPU Affinity failed with error %d", errno);
778 "CPU affinity setting not supported on macOS");
798 options_manager->
Dump().c_str());
803 if (options_manager->
GetValue(
"CVMFS_SYSLOG_LEVEL", ¶meter))
807 if (options_manager->
GetValue(
"CVMFS_SYSLOG_FACILITY", ¶meter))
813 if (options_manager->
GetValue(
"CVMFS_CHECK_PERMISSIONS", ¶meter)) {
814 if (options_manager->
IsOn(parameter)) {
815 fuse_opt_add_arg(mount_options,
"-odefault_permissions");
821 "Mount point %s does not exist",
mount_point_->c_str());
826 if (options_manager->
GetValue(
"CVMFS_NFILES", ¶meter)) {
830 }
else if (retval == -1) {
833 "Failed to set maximum number of open files, "
834 "insufficient permissions");
837 unsigned soft_limit, hard_limit;
840 "Failed to set requested number of open files, "
841 "using maximum number %u", hard_limit);
842 if (hard_limit > soft_limit) {
849 if (options_manager->
GetValue(
"CVMFS_OOM_SCORE_ADJ", ¶meter)) {
850 string proc_path =
"/proc/" +
StringifyInt(getpid()) +
"/oom_score_adj";
851 int fd_oom = open(proc_path.c_str(), O_WRONLY);
854 "failed to open %s", proc_path.c_str());
856 bool retval =
SafeWrite(fd_oom, parameter.data(), parameter.length());
859 "failed to set OOM score adjustment to %s", parameter.c_str());
866 if (options_manager->
GetValue(
"CVMFS_SYSTEMD_NOKILL", ¶meter) &&
867 options_manager->
IsOn(parameter))
878 "Failed to grab mountpoint %s (%d)",
891 "Failed to drop credentials");
902 if (options_manager->
GetValue(
"CVMFS_USYSLOG", ¶meter))
908 "CernVM-FS: running in single threaded mode");
912 "CernVM-FS: running in debug mode");
915 #ifndef FUSE_CAP_POSIX_ACL
916 if (options_manager->
GetValue(
"CVMFS_ENFORCE_ACLS", ¶meter) &&
917 options_manager->
IsOn(parameter))
920 "CernVM-FS: ACL support requested but not available in this "
921 "version of libfuse");
928 if (options_manager->
GetValue(
"CVMFS_RELOAD_SOCKETS", ¶meter))
934 "Failed to initialize loader socket");
940 if (options_manager->
GetValue(
"CVMFS_FUSE3_MAX_THREADS", ¶meter)) {
943 if (options_manager->
GetValue(
"CVMFS_FUSE3_IDLE_THREADS", ¶meter)) {
946 #ifdef CVMFS_ENABLE_FUSE3_LOOP_CONFIG
958 "CernVM-FS: ignoring fuse3 thread settings (libfuse too old)");
963 delete options_manager;
964 options_manager = NULL;
967 #if CVMFS_USE_LIBFUSE == 2
968 struct fuse_chan *channel;
978 "CernVM-FS: loading Fuse module... ");
987 "\nCernVM-FS: repository %s already mounted on %s",
1004 const bool retrievable =
true;
1007 "failed to re-gain root permissions for mounting");
1014 struct fuse_lowlevel_ops loader_operations;
1016 #if (FUSE_VERSION >= 29)
1018 loader_operations.forget_multi = stub_forget_multi;
1021 #if CVMFS_USE_LIBFUSE == 2
1022 channel = fuse_mount(
mount_point_->c_str(), mount_options);
1025 "failed to create Fuse channel");
1030 session = fuse_lowlevel_new(mount_options, &loader_operations,
1031 sizeof(loader_operations), NULL);
1034 "failed to create Fuse session");
1041 session = fuse_session_new(mount_options, &loader_operations,
1042 sizeof(loader_operations), NULL);
1045 "failed to create Fuse session");
1049 retval = fuse_session_mount(session,
mount_point_->c_str());
1052 "failed to mount file system");
1063 "failed to drop permissions after mounting");
1070 int fd_mountinfo = open(
"/proc/self/mountinfo", O_RDONLY);
1071 if (fd_mountinfo > 0) {
1073 while (
GetLineFd(fd_mountinfo, &line)) {
1074 std::vector<std::string> tokens =
SplitString(line,
' ');
1075 if (tokens.size() < 5)
continue;
1078 for (; i < tokens.size(); ++i) {
1079 if (tokens[i] ==
"-")
break;
1081 if (tokens.size() < i + 3)
continue;
1082 if (tokens[i + 2] !=
"cvmfs2")
continue;
1086 close(fd_mountinfo);
1094 "CernVM-FS: linking %s to repository %s",
1103 retval = fuse_set_signal_handlers(session);
1105 #if CVMFS_USE_LIBFUSE == 2
1106 fuse_session_add_chan(session, channel);
1109 retval = fuse_session_loop(session);
1111 #if CVMFS_USE_LIBFUSE == 2
1112 retval = fuse_session_loop_mt(session);
1114 #ifdef CVMFS_ENABLE_FUSE3_LOOP_CONFIG
1115 struct fuse_loop_config *fuse_loop_cfg = fuse_loop_cfg_create();
1117 fuse_loop_cfg_set_clone_fd(fuse_loop_cfg, 1);
1126 retval = fuse_session_loop_mt(session, fuse_loop_cfg);
1127 fuse_loop_cfg_destroy(fuse_loop_cfg);
1129 retval = fuse_session_loop_mt(session, 1 );
1130 #endif // CVMFS_ENABLE_FUSE3_LOOP_CONFIG
1139 #if CVMFS_USE_LIBFUSE == 2
1140 fuse_remove_signal_handlers(session);
1141 fuse_session_remove_chan(channel);
1142 fuse_session_destroy(session);
1147 fuse_remove_signal_handlers(session);
1148 fuse_session_unmount(session);
1149 fuse_session_destroy(session);
1151 fuse_opt_free_args(mount_options);
1152 delete mount_options;
1154 mount_options = NULL;
1167 fence_reload_ = NULL;
1185 g_cvmfs_stub_exports->fn_main =
FuseMain;
1189 delete g_cvmfs_stub_exports;
1190 g_cvmfs_stub_exports = NULL;
bool MakeCacheDirectories(const std::string &path, const mode_t mode)
bool simple_options_parsing_
std::string repository_name
static void stub_opendir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
void SetLogSyslogFacility(const int local_facility)
static void stub_destroy(void *userdata)
const char * Code2Ascii(const ObjectFetcherFailures::Failures error)
void SetLogSyslogLevel(const int level)
static void stub_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size)
virtual void ParsePath(const std::string &config_file, const bool external)=0
Session * session() const
static struct fuse_opt cvmfs_array_opts[]
Failures Reload(const int fd_progress, const bool stop_and_go, const ReloadMode reload_mode)
static CvmfsExports * LoadLibrary(const bool debug_mode, LoaderExports *loader_exports)
static void stub_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi)
int simple_options_parsing
int(* fnAltProcessFlavor)(int argc, char **argv)
int FuseMain(int argc, char *argv[])
void CreateFile(const std::string &path, const int mode, const bool ignore_failure)
string Trim(const string &raw, bool trim_newline)
string JoinStrings(const vector< string > &strings, const string &joint)
static void stub_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, size_t size)
bool IsOn(const std::string ¶m_value) const
bool SafeWrite(int fd, const void *buf, size_t nbyte)
void SendMsg2Socket(const int fd, const std::string &msg)
assert((mem||(size==0))&&"Out Of Memory")
void ** fuse_channel_or_session
MountPoint * mount_point_
std::string loader_version
void SetLogMicroSyslog(const std::string &filename)
void ParseDefault(const std::string &fqrn)
bool(* fnSaveState)(const int fd_progress, StateList *saved_states)
struct cvmcache_object_info __attribute__
static void stub_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi)
int SetLimitNoFile(unsigned limit_nofile)
static void stub_statfs(fuse_req_t req, fuse_ino_t ino)
int64_t String2Int64(const string &value)
void GetLimitNoFile(unsigned *soft_limit, unsigned *hard_limit)
static void stub_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
static void stub_releasedir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
static void stub_readlink(fuse_req_t req, fuse_ino_t ino)
static void stub_lookup(fuse_req_t req, fuse_ino_t parent, const char *name)
bool CheckPremounted(const std::string &mountpoint)
vector< string > SplitString(const string &str, char delim)
bool(* fnRestoreState)(const int fd_progress, const StateList &saved_states)
#define CVMFS_OPT(t, p, v)
static fuse_args * ParseCmdLine(int argc, char *argv[])
const loader::LoaderExports * loader_exports_
struct fuse_lowlevel_ops cvmfs_operations
bool MkdirDeep(const std::string &path, const mode_t mode, bool verify_writable)
void WaitForSignal(int signum)
static void SetFuseOperations(struct fuse_lowlevel_ops *loader_operations)
int(* fnInit)(const LoaderExports *loader_exports)
bool simple_options_parsing
static int Init(const loader::LoaderExports *loader_exports)
static void stub_forget(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup)
bool(* fnMaintenanceMode)(const int fd_progress)
void(* fnFreeSavedState)(const int fd_progress, const StateList &saved_states)
string StringifyInt(const int64_t value)
int MainReload(const std::string &socket_path, const bool stop_and_go, const bool debug)
bool GetValue(const std::string &key, std::string *value) const
bool DirectoryExists(const std::string &path)
static void stub_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
bool GetLineFd(const int fd, std::string *line)
static void CloseLibrary()
uint64_t String2Uint64(const string &value)
std::string(* fnGetErrorMsg)()
bool SwitchCredentials(const uid_t uid, const gid_t gid, const bool temporarily)
static int ParseFuseOptions(void *data __attribute__((unused)), const char *arg, int key, struct fuse_args *outargs)
static void stub_release(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
#define CVMFS_SWITCH(t, p)
void SetLogSyslogPrefix(const std::string &prefix)
std::string MakeCanonicalPath(const std::string &path)
static void stub_init(void *userdata, struct fuse_conn_info *conn)
CvmfsExports * cvmfs_exports_
static void * OpenLibrary(const string &path)
void BlockSignal(int signum)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
std::string * repository_name_