12 #define ENOATTR ENODATA
13 #define _FILE_OFFSET_BITS 64
15 #include "cvmfs_config.h"
21 #include <openssl/crypto.h>
25 #include <sys/resource.h>
30 #ifdef HAS_VALGRIND_HEADERS
31 #include <valgrind/valgrind.h>
90 #define CVMFS_OPT(t, p, v) { t, offsetof(struct CvmfsOptions, p), v }
91 #define CVMFS_SWITCH(t, p) { t, offsetof(struct CvmfsOptions, p), 1 }
100 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");
407 struct fuse_args *mount_options =
new fuse_args();
409 memset(&cvmfs_options, 0,
sizeof(cvmfs_options));
411 mount_options->argc = argc;
412 mount_options->argv = argv;
413 mount_options->allocated = 0;
418 delete mount_options;
421 if (cvmfs_options.
config) {
423 free(cvmfs_options.
config);
436 fuse_opt_add_arg(mount_options,
"-d");
439 return mount_options;
444 memset(loader_operations, 0,
sizeof(*loader_operations));
466 return dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL);
471 #ifdef HAS_VALGRIND_HEADERS
474 if (!RUNNING_ON_VALGRIND) {
478 #ifdef HAS_VALGRIND_HEADERS
487 std::string local_lib_path =
"./";
488 if (getenv(
"CVMFS_LIBRARY_PATH") != NULL) {
489 local_lib_path = getenv(
"CVMFS_LIBRARY_PATH");
490 if (!local_lib_path.empty() && (*local_lib_path.rbegin() !=
'/'))
491 local_lib_path.push_back(
'/');
494 #if CVMFS_USE_LIBFUSE == 2
495 string library_name = string(
"cvmfs_fuse") + ((debug_mode) ?
"_debug" :
"");
497 string library_name = string(
"cvmfs_fuse3") + ((debug_mode) ?
"_debug" :
"");
500 string error_messages;
502 static vector<string> library_paths;
503 if (library_paths.empty()) {
504 library_paths.push_back(local_lib_path + library_name);
505 library_paths.push_back(
"/usr/lib/" + library_name);
506 library_paths.push_back(
"/usr/lib64/" + library_name);
510 library_paths.push_back(
"/usr/local/lib/" + library_name);
514 vector<string>::const_iterator i = library_paths.begin();
515 vector<string>::const_iterator iend = library_paths.end();
516 for (; i != iend; ++i) {
522 error_messages += string(dlerror()) +
"\n";
527 "failed to load cvmfs library, tried: '%s'\n%s",
528 JoinStrings(library_paths,
"' '").c_str(), error_messages.c_str());
537 if (loader_exports) {
540 load_event->
so_version = (*exports_ptr)->so_version;
541 loader_exports->
history.push_back(load_event);
558 SendMsg2Socket(fd_progress,
"Waiting for active file system calls\n");
572 SendMsg2Socket(fd_progress,
"Waiting for the delivery of SIGUSR1...\n");
610 using namespace loader;
613 #ifndef OPENSSL_API_INTERFACE_V11
618 const char *file,
int line) {
624 if (mode & CRYPTO_LOCK) {
639 #ifndef OPENSSL_API_INTERFACE_V11
641 CRYPTO_num_locks() *
sizeof(pthread_mutex_t)));
642 for (
int i = 0; i < CRYPTO_num_locks(); ++i) {
653 #ifndef OPENSSL_API_INTERFACE_V11
654 CRYPTO_set_locking_callback(NULL);
655 for (
int i = 0; i < CRYPTO_num_locks(); ++i)
675 if ((argc > 1) && (strstr(argv[1],
"__") == argv[1])) {
676 if (
string(argv[1]) ==
string(
"__RELOAD__")) {
679 bool stop_and_go =
false;
680 if ((argc > 3) && (
string(argv[3]) ==
"stop_and_go"))
683 if ((retval != 0) && (stop_and_go)) {
684 CreateFile(
string(argv[2]) +
".paused.crashed", 0600);
689 if (
string(argv[1]) ==
string(
"__MK_ALIEN_CACHE__")) {
692 string alien_cache_dir = argv[2];
699 int retval =
MkdirDeep(alien_cache_dir, 0770);
702 alien_cache_dir.c_str());
705 retval = chown(alien_cache_dir.c_str(), uid_owner, gid_owner);
708 alien_cache_dir.c_str(), uid_owner, gid_owner);
714 uid_owner, gid_owner);
726 debug_mode_ = getenv(
"__CVMFS_DEBUG_MODE__") != NULL;
736 struct fuse_args *mount_options;
738 if (!mount_options) {
754 for (
unsigned i = 0, s = tokens.size(); i < s; ++i) {
755 options_manager->
ParsePath(tokens[i],
false);
763 fuse_opt_add_arg(mount_options, volname.c_str());
765 fuse_opt_add_arg(mount_options,
"-odaemon_timeout=300");
766 fuse_opt_add_arg(mount_options,
"-onoapplexattr");
770 if (options_manager->
GetValue(
"CVMFS_MOUNT_RW", ¶meter) &&
771 options_manager->
IsOn(parameter))
773 fuse_opt_add_arg(mount_options,
"-orw");
775 fuse_opt_add_arg(mount_options,
"-oro");
777 fuse_opt_add_arg(mount_options,
"-onodev");
778 if (options_manager->
GetValue(
"CVMFS_SUID", ¶meter) &&
779 options_manager->
IsOn(parameter))
786 "must be root to mount with suid option");
788 fuse_opt_add_arg(mount_options,
"-osuid");
808 options_manager->
Dump().c_str());
813 if (options_manager->
GetValue(
"CVMFS_SYSLOG_LEVEL", ¶meter))
817 if (options_manager->
GetValue(
"CVMFS_SYSLOG_FACILITY", ¶meter))
823 if (options_manager->
GetValue(
"CVMFS_CHECK_PERMISSIONS", ¶meter)) {
824 if (options_manager->
IsOn(parameter)) {
825 fuse_opt_add_arg(mount_options,
"-odefault_permissions");
831 "Moint point %s does not exist",
mount_point_->c_str());
836 if (options_manager->
GetValue(
"CVMFS_NFILES", ¶meter)) {
840 }
else if (retval == -1) {
843 "Failed to set maximum number of open files, "
844 "insufficient permissions");
847 unsigned soft_limit, hard_limit;
850 "Failed to set requested number of open files, "
851 "using maximum number %u", hard_limit);
852 if (hard_limit > soft_limit) {
859 if (options_manager->
GetValue(
"CVMFS_OOM_SCORE_ADJ", ¶meter)) {
860 string proc_path =
"/proc/" +
StringifyInt(getpid()) +
"/oom_score_adj";
861 int fd_oom = open(proc_path.c_str(), O_WRONLY);
864 "failed to open %s", proc_path.c_str());
866 bool retval =
SafeWrite(fd_oom, parameter.data(), parameter.length());
869 "failed to set OOM score adjustment to %s", parameter.c_str());
876 if (options_manager->
GetValue(
"CVMFS_SYSTEMD_NOKILL", ¶meter) &&
877 options_manager->
IsOn(parameter))
888 "Failed to grab mountpoint %s (%d)",
901 "Failed to drop credentials");
908 if (options_manager->
GetValue(
"CVMFS_USYSLOG", ¶meter))
914 "CernVM-FS: running in single threaded mode");
918 "CernVM-FS: running in debug mode");
921 #ifndef FUSE_CAP_POSIX_ACL
922 if (options_manager->
GetValue(
"CVMFS_ENFORCE_ACLS", ¶meter) &&
923 options_manager->
IsOn(parameter))
926 "CernVM-FS: ACL support requested but not available in this "
927 "version of libfuse");
934 if (options_manager->
GetValue(
"CVMFS_RELOAD_SOCKETS", ¶meter))
940 "Failed to initialize loader socket");
945 delete options_manager;
946 options_manager = NULL;
949 #if CVMFS_USE_LIBFUSE == 2
950 struct fuse_chan *channel;
960 "CernVM-FS: loading Fuse module... ");
969 "\nCernVM-FS: repository %s already mounted on %s",
986 const bool retrievable =
true;
989 "failed to re-gain root permissions for mounting");
996 struct fuse_lowlevel_ops loader_operations;
998 #if (FUSE_VERSION >= 29)
1000 loader_operations.forget_multi = stub_forget_multi;
1003 #if CVMFS_USE_LIBFUSE == 2
1004 channel = fuse_mount(
mount_point_->c_str(), mount_options);
1007 "failed to create Fuse channel");
1012 session = fuse_lowlevel_new(mount_options, &loader_operations,
1013 sizeof(loader_operations), NULL);
1016 "failed to create Fuse session");
1023 session = fuse_session_new(mount_options, &loader_operations,
1024 sizeof(loader_operations), NULL);
1027 "failed to create Fuse session");
1031 retval = fuse_session_mount(session,
mount_point_->c_str());
1034 "failed to mount file system");
1045 "failed to drop permissions after mounting");
1052 int fd_mountinfo = open(
"/proc/self/mountinfo", O_RDONLY);
1053 if (fd_mountinfo > 0) {
1055 while (
GetLineFd(fd_mountinfo, &line)) {
1056 std::vector<std::string> tokens =
SplitString(line,
' ');
1057 if (tokens.size() < 5)
continue;
1060 for (; i < tokens.size(); ++i) {
1061 if (tokens[i] ==
"-")
break;
1063 if (tokens.size() < i + 3)
continue;
1064 if (tokens[i + 2] !=
"cvmfs2")
continue;
1068 close(fd_mountinfo);
1076 "CernVM-FS: linking %s to repository %s",
1085 retval = fuse_set_signal_handlers(session);
1087 #if CVMFS_USE_LIBFUSE == 2
1088 fuse_session_add_chan(session, channel);
1091 retval = fuse_session_loop(session);
1093 #if CVMFS_USE_LIBFUSE == 2
1094 retval = fuse_session_loop_mt(session);
1096 retval = fuse_session_loop_mt(session, 1 );
1105 #if CVMFS_USE_LIBFUSE == 2
1106 fuse_remove_signal_handlers(session);
1107 fuse_session_remove_chan(channel);
1108 fuse_session_destroy(session);
1113 fuse_remove_signal_handlers(session);
1114 fuse_session_unmount(session);
1115 fuse_session_destroy(session);
1117 fuse_opt_free_args(mount_options);
1118 delete mount_options;
1120 mount_options = NULL;
1153 g_cvmfs_stub_exports->fn_main =
FuseMain;
1157 delete g_cvmfs_stub_exports;
1158 g_cvmfs_stub_exports = NULL;
bool MakeCacheDirectories(const std::string &path, const mode_t mode)
bool simple_options_parsing_
std::string repository_name
Failures Reload(const int fd_progress, const bool stop_and_go)
#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)
static unsigned long CallbackLibcryptoThreadId()
virtual void ParsePath(const std::string &config_file, const bool external)=0
Session * session() const
static struct fuse_opt cvmfs_array_opts[]
static CvmfsExports * LoadLibrary(const bool debug_mode, LoaderExports *loader_exports)
vector< string > SplitString(const string &str, const char delim, const unsigned max_chunks)
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 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)
static void CallbackLibcryptoLock(int mode, int type, const char *file, int line)
static void CleanupLibcryptoMt(void)
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)
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_
static void SetupLibcryptoMt()
struct fuse_lowlevel_ops cvmfs_operations
bool MkdirDeep(const std::string &path, const mode_t mode, bool verify_writable)
pthread_mutex_t * gLibcryptoLocks
void WaitForSignal(int signum)
int MainReload(const std::string &socket_path, const bool stop_and_go)
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)
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_