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),
148 static void Usage(
const string &exename) {
150 "The CernVM File System\n"
152 "Copyright (c) 2009- CERN, all rights reserved\n\n"
153 "Please visit http://cernvm.cern.ch for details.\n\n"
154 "Usage: %s [-h] [-V] [-s] [-f] [-d] [-k] [-o mount options] "
155 "<repository name> <mount point>\n\n"
156 "CernVM-FS general options:\n"
157 " --help|-h Print Help output (this)\n"
158 " --version|-V Print CernVM-FS version\n"
159 " -s Run singlethreaded\n"
160 " -f Run in foreground\n"
161 " -d Enable debugging\n"
162 " -k Parse options\n"
163 "CernVM-FS mount options:\n"
164 " -o config=FILES colon-separated path list of config files\n"
165 " -o uid=UID Drop credentials to another user\n"
166 " -o gid=GID Drop credentials to another group\n"
167 " -o system_mount Indicate that mount is system-wide\n"
168 " -o grab_mountpoint give ownership of the mountpoint to the user "
169 "before mounting (required for autofs)\n"
170 " -o parse Parse and print cvmfs parameters\n"
171 " -o cvmfs_suid Enable suid mode\n\n"
172 " -o disable_watchdog Do not spawn a post mortem crash handler\n"
173 " -o foreground Run in foreground\n"
174 " -o libfuse=[2,3] Enforce a certain libfuse version\n"
175 "Fuse mount options:\n"
176 " -o allow_other allow access to other users\n"
177 " -o allow_root allow access to root\n"
178 " -o nonempty allow mounts over non-empty directory\n",
179 PACKAGE_VERSION, exename.c_str());
189 bool retval = (sscanf(mountpoint.c_str(),
"/dev/fd/%u%n", &fd, &len) == 1) &&
191 (static_cast<unsigned>(len) == mountpoint.length());
194 "CernVM-FS: pre-mounted on file descriptor %d", fd);
201 static void stub_init(
void *userdata,
struct fuse_conn_info *conn) {
222 struct fuse_file_info *fi)
236 struct fuse_file_info *fi)
244 struct fuse_file_info *fi)
252 off_t off,
struct fuse_file_info *fi)
260 struct fuse_file_info *fi)
267 static void stub_read(fuse_req_t req, fuse_ino_t ino,
size_t size, off_t off,
268 struct fuse_file_info *fi)
276 struct fuse_file_info *fi)
290 static void stub_getxattr(fuse_req_t req, fuse_ino_t ino,
const char *name,
291 size_t size, uint32_t position)
315 #
if CVMFS_USE_LIBFUSE == 2
316 unsigned long nlookup
326 #if (FUSE_VERSION >= 29)
327 static void stub_forget_multi(
330 struct fuse_forget_data *forgets
345 int key,
struct fuse_args *outargs)
349 arglen = strlen(arg);
351 case FUSE_OPT_KEY_OPT:
353 if ((arglen > 0) && (arg[0] !=
'-')) {
356 unsigned olen = strlen(*o);
357 if ((arglen > olen && arg[olen] ==
'=') &&
358 (strncasecmp(arg, *o, olen) == 0))
364 case FUSE_OPT_KEY_NONOPT:
378 Usage(outargs->argv[0]);
391 fuse_opt_add_arg(outargs,
"-d");
404 struct fuse_args *mount_options =
new fuse_args();
406 memset(&cvmfs_options, 0,
sizeof(cvmfs_options));
408 mount_options->argc = argc;
409 mount_options->argv = argv;
410 mount_options->allocated = 0;
415 delete mount_options;
418 if (cvmfs_options.
config) {
420 free(cvmfs_options.
config);
433 fuse_opt_add_arg(mount_options,
"-d");
436 return mount_options;
441 memset(loader_operations, 0,
sizeof(*loader_operations));
463 return dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL);
468 #ifdef HAS_VALGRIND_HEADERS
471 if (!RUNNING_ON_VALGRIND) {
475 #ifdef HAS_VALGRIND_HEADERS
484 std::string local_lib_path =
"./";
485 if (getenv(
"CVMFS_LIBRARY_PATH") != NULL) {
486 local_lib_path = getenv(
"CVMFS_LIBRARY_PATH");
487 if (!local_lib_path.empty() && (*local_lib_path.rbegin() !=
'/'))
488 local_lib_path.push_back(
'/');
491 #if CVMFS_USE_LIBFUSE == 2
492 string library_name = string(
"cvmfs_fuse") + ((debug_mode) ?
"_debug" :
"");
494 string library_name = string(
"cvmfs_fuse3") + ((debug_mode) ?
"_debug" :
"");
497 string error_messages;
499 vector<string> library_paths;
500 if (library_paths.empty()) {
501 library_paths.push_back(local_lib_path + library_name);
502 library_paths.push_back(
"/usr/lib/" + library_name);
503 library_paths.push_back(
"/usr/lib64/" + library_name);
507 library_paths.push_back(
"/usr/local/lib/" + library_name);
511 vector<string>::const_iterator i = library_paths.begin();
512 vector<string>::const_iterator iend = library_paths.end();
513 for (; i != iend; ++i) {
519 error_messages += string(dlerror()) +
"\n";
524 "failed to load cvmfs library, tried: '%s'\n%s",
525 JoinStrings(library_paths,
"' '").c_str(), error_messages.c_str());
534 if (loader_exports) {
537 load_event->
so_version = (*exports_ptr)->so_version;
538 loader_exports->
history.push_back(load_event);
562 SendMsg2Socket(fd_progress,
"Waiting for active file system calls\n");
576 SendMsg2Socket(fd_progress,
"Waiting for the delivery of SIGUSR1...\n");
614 using namespace loader;
628 if ((argc > 1) && (strstr(argv[1],
"__") == argv[1])) {
629 if (
string(argv[1]) ==
string(
"__RELOAD__")) {
632 bool stop_and_go =
false;
633 if ((argc > 3) && (
string(argv[3]) ==
"stop_and_go"))
645 if (std::string(argv[argc - 1]) == std::string(
"--debug")) {
652 if ((retval != 0) && (stop_and_go)) {
653 CreateFile(
string(argv[2]) +
".paused.crashed", 0600);
658 if (
string(argv[1]) ==
string(
"__MK_ALIEN_CACHE__")) {
661 string alien_cache_dir = argv[2];
668 int retval =
MkdirDeep(alien_cache_dir, 0770);
671 alien_cache_dir.c_str());
674 retval = chown(alien_cache_dir.c_str(), uid_owner, gid_owner);
677 alien_cache_dir.c_str(), uid_owner, gid_owner);
683 uid_owner, gid_owner);
695 debug_mode_ = getenv(
"__CVMFS_DEBUG_MODE__") != NULL;
703 struct fuse_args *mount_options;
705 if (!mount_options) {
721 for (
unsigned i = 0, s = tokens.size(); i < s; ++i) {
722 options_manager->
ParsePath(tokens[i],
false);
730 fuse_opt_add_arg(mount_options, volname.c_str());
732 fuse_opt_add_arg(mount_options,
"-odaemon_timeout=300");
733 fuse_opt_add_arg(mount_options,
"-onoapplexattr");
737 if (options_manager->
GetValue(
"CVMFS_MOUNT_RW", ¶meter) &&
738 options_manager->
IsOn(parameter))
740 fuse_opt_add_arg(mount_options,
"-orw");
742 fuse_opt_add_arg(mount_options,
"-oro");
744 fuse_opt_add_arg(mount_options,
"-onodev");
745 if (options_manager->
GetValue(
"CVMFS_SUID", ¶meter) &&
746 options_manager->
IsOn(parameter))
753 "must be root to mount with suid option");
755 fuse_opt_add_arg(mount_options,
"-osuid");
759 if (options_manager->
GetValue(
"CVMFS_CPU_AFFINITY", ¶meter)) {
764 for (vector<string>::iterator i = cpus.begin(); i != cpus.end(); i++) {
768 "CernVM-FS: setting CPU Affinity to %s", parameter.c_str());
769 int err = sched_setaffinity(0,
sizeof(mask), &mask);
772 "Setting CPU Affinity failed with error %d", errno);
776 "CPU affinity setting not supported on macOS");
796 options_manager->
Dump().c_str());
801 if (options_manager->
GetValue(
"CVMFS_SYSLOG_LEVEL", ¶meter))
805 if (options_manager->
GetValue(
"CVMFS_SYSLOG_FACILITY", ¶meter))
811 if (options_manager->
GetValue(
"CVMFS_CHECK_PERMISSIONS", ¶meter)) {
812 if (options_manager->
IsOn(parameter)) {
813 fuse_opt_add_arg(mount_options,
"-odefault_permissions");
819 "Mount point %s does not exist",
mount_point_->c_str());
824 if (options_manager->
GetValue(
"CVMFS_NFILES", ¶meter)) {
828 }
else if (retval == -1) {
831 "Failed to set maximum number of open files, "
832 "insufficient permissions");
835 unsigned soft_limit, hard_limit;
838 "Failed to set requested number of open files, "
839 "using maximum number %u", hard_limit);
840 if (hard_limit > soft_limit) {
847 if (options_manager->
GetValue(
"CVMFS_OOM_SCORE_ADJ", ¶meter)) {
848 string proc_path =
"/proc/" +
StringifyInt(getpid()) +
"/oom_score_adj";
849 int fd_oom = open(proc_path.c_str(), O_WRONLY);
852 "failed to open %s", proc_path.c_str());
854 bool retval =
SafeWrite(fd_oom, parameter.data(), parameter.length());
857 "failed to set OOM score adjustment to %s", parameter.c_str());
864 if (options_manager->
GetValue(
"CVMFS_SYSTEMD_NOKILL", ¶meter) &&
865 options_manager->
IsOn(parameter))
876 "Failed to grab mountpoint %s (%d)",
889 "Failed to drop credentials");
900 if (options_manager->
GetValue(
"CVMFS_USYSLOG", ¶meter))
906 "CernVM-FS: running in single threaded mode");
910 "CernVM-FS: running in debug mode");
913 #ifndef FUSE_CAP_POSIX_ACL
914 if (options_manager->
GetValue(
"CVMFS_ENFORCE_ACLS", ¶meter) &&
915 options_manager->
IsOn(parameter))
918 "CernVM-FS: ACL support requested but not available in this "
919 "version of libfuse");
926 if (options_manager->
GetValue(
"CVMFS_RELOAD_SOCKETS", ¶meter))
932 "Failed to initialize loader socket");
937 delete options_manager;
938 options_manager = NULL;
941 #if CVMFS_USE_LIBFUSE == 2
942 struct fuse_chan *channel;
952 "CernVM-FS: loading Fuse module... ");
961 "\nCernVM-FS: repository %s already mounted on %s",
978 const bool retrievable =
true;
981 "failed to re-gain root permissions for mounting");
988 struct fuse_lowlevel_ops loader_operations;
990 #if (FUSE_VERSION >= 29)
992 loader_operations.forget_multi = stub_forget_multi;
995 #if CVMFS_USE_LIBFUSE == 2
996 channel = fuse_mount(
mount_point_->c_str(), mount_options);
999 "failed to create Fuse channel");
1004 session = fuse_lowlevel_new(mount_options, &loader_operations,
1005 sizeof(loader_operations), NULL);
1008 "failed to create Fuse session");
1015 session = fuse_session_new(mount_options, &loader_operations,
1016 sizeof(loader_operations), NULL);
1019 "failed to create Fuse session");
1023 retval = fuse_session_mount(session,
mount_point_->c_str());
1026 "failed to mount file system");
1037 "failed to drop permissions after mounting");
1044 int fd_mountinfo = open(
"/proc/self/mountinfo", O_RDONLY);
1045 if (fd_mountinfo > 0) {
1047 while (
GetLineFd(fd_mountinfo, &line)) {
1048 std::vector<std::string> tokens =
SplitString(line,
' ');
1049 if (tokens.size() < 5)
continue;
1052 for (; i < tokens.size(); ++i) {
1053 if (tokens[i] ==
"-")
break;
1055 if (tokens.size() < i + 3)
continue;
1056 if (tokens[i + 2] !=
"cvmfs2")
continue;
1060 close(fd_mountinfo);
1068 "CernVM-FS: linking %s to repository %s",
1077 retval = fuse_set_signal_handlers(session);
1079 #if CVMFS_USE_LIBFUSE == 2
1080 fuse_session_add_chan(session, channel);
1083 retval = fuse_session_loop(session);
1085 #if CVMFS_USE_LIBFUSE == 2
1086 retval = fuse_session_loop_mt(session);
1088 retval = fuse_session_loop_mt(session, 1 );
1097 #if CVMFS_USE_LIBFUSE == 2
1098 fuse_remove_signal_handlers(session);
1099 fuse_session_remove_chan(channel);
1100 fuse_session_destroy(session);
1105 fuse_remove_signal_handlers(session);
1106 fuse_session_unmount(session);
1107 fuse_session_destroy(session);
1109 fuse_opt_free_args(mount_options);
1110 delete mount_options;
1112 mount_options = NULL;
1125 fence_reload_ = NULL;
1143 g_cvmfs_stub_exports->fn_main =
FuseMain;
1147 delete g_cvmfs_stub_exports;
1148 g_cvmfs_stub_exports = NULL;
bool MakeCacheDirectories(const std::string &path, const mode_t mode)
bool simple_options_parsing_
std::string repository_name
#define LogCvmfs(source, mask,...)
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)
std::string * repository_name_