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");
405 struct fuse_args *mount_options =
new fuse_args();
407 memset(&cvmfs_options, 0,
sizeof(cvmfs_options));
409 mount_options->argc = argc;
410 mount_options->argv = argv;
411 mount_options->allocated = 0;
416 delete mount_options;
419 if (cvmfs_options.
config) {
421 free(cvmfs_options.
config);
434 fuse_opt_add_arg(mount_options,
"-d");
437 return mount_options;
442 memset(loader_operations, 0,
sizeof(*loader_operations));
464 return dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL);
469 #ifdef HAS_VALGRIND_HEADERS
472 if (!RUNNING_ON_VALGRIND) {
476 #ifdef HAS_VALGRIND_HEADERS
485 std::string local_lib_path =
"./";
486 if (getenv(
"CVMFS_LIBRARY_PATH") != NULL) {
487 local_lib_path = getenv(
"CVMFS_LIBRARY_PATH");
488 if (!local_lib_path.empty() && (*local_lib_path.rbegin() !=
'/'))
489 local_lib_path.push_back(
'/');
492 #if CVMFS_USE_LIBFUSE == 2
493 string library_name = string(
"cvmfs_fuse") + ((debug_mode) ?
"_debug" :
"");
495 string library_name = string(
"cvmfs_fuse3") + ((debug_mode) ?
"_debug" :
"");
498 string error_messages;
500 static vector<string> library_paths;
501 if (library_paths.empty()) {
502 library_paths.push_back(local_lib_path + library_name);
503 library_paths.push_back(
"/usr/lib/" + library_name);
504 library_paths.push_back(
"/usr/lib64/" + library_name);
508 library_paths.push_back(
"/usr/local/lib/" + library_name);
512 vector<string>::const_iterator i = library_paths.begin();
513 vector<string>::const_iterator iend = library_paths.end();
514 for (; i != iend; ++i) {
520 error_messages += string(dlerror()) +
"\n";
525 "failed to load cvmfs library, tried: '%s'\n%s",
526 JoinStrings(library_paths,
"' '").c_str(), error_messages.c_str());
535 if (loader_exports) {
538 load_event->
so_version = (*exports_ptr)->so_version;
539 loader_exports->
history.push_back(load_event);
556 SendMsg2Socket(fd_progress,
"Waiting for active file system calls\n");
570 SendMsg2Socket(fd_progress,
"Waiting for the delivery of SIGUSR1...\n");
608 using namespace loader;
622 if ((argc > 1) && (strstr(argv[1],
"__") == argv[1])) {
623 if (
string(argv[1]) ==
string(
"__RELOAD__")) {
626 bool stop_and_go =
false;
627 if ((argc > 3) && (
string(argv[3]) ==
"stop_and_go"))
630 if ((retval != 0) && (stop_and_go)) {
631 CreateFile(
string(argv[2]) +
".paused.crashed", 0600);
636 if (
string(argv[1]) ==
string(
"__MK_ALIEN_CACHE__")) {
639 string alien_cache_dir = argv[2];
646 int retval =
MkdirDeep(alien_cache_dir, 0770);
649 alien_cache_dir.c_str());
652 retval = chown(alien_cache_dir.c_str(), uid_owner, gid_owner);
655 alien_cache_dir.c_str(), uid_owner, gid_owner);
661 uid_owner, gid_owner);
673 debug_mode_ = getenv(
"__CVMFS_DEBUG_MODE__") != NULL;
681 struct fuse_args *mount_options;
683 if (!mount_options) {
699 for (
unsigned i = 0, s = tokens.size(); i < s; ++i) {
700 options_manager->
ParsePath(tokens[i],
false);
708 fuse_opt_add_arg(mount_options, volname.c_str());
710 fuse_opt_add_arg(mount_options,
"-odaemon_timeout=300");
711 fuse_opt_add_arg(mount_options,
"-onoapplexattr");
715 if (options_manager->
GetValue(
"CVMFS_MOUNT_RW", ¶meter) &&
716 options_manager->
IsOn(parameter))
718 fuse_opt_add_arg(mount_options,
"-orw");
720 fuse_opt_add_arg(mount_options,
"-oro");
722 fuse_opt_add_arg(mount_options,
"-onodev");
723 if (options_manager->
GetValue(
"CVMFS_SUID", ¶meter) &&
724 options_manager->
IsOn(parameter))
731 "must be root to mount with suid option");
733 fuse_opt_add_arg(mount_options,
"-osuid");
753 options_manager->
Dump().c_str());
758 if (options_manager->
GetValue(
"CVMFS_SYSLOG_LEVEL", ¶meter))
762 if (options_manager->
GetValue(
"CVMFS_SYSLOG_FACILITY", ¶meter))
768 if (options_manager->
GetValue(
"CVMFS_CHECK_PERMISSIONS", ¶meter)) {
769 if (options_manager->
IsOn(parameter)) {
770 fuse_opt_add_arg(mount_options,
"-odefault_permissions");
776 "Mount point %s does not exist",
mount_point_->c_str());
781 if (options_manager->
GetValue(
"CVMFS_NFILES", ¶meter)) {
785 }
else if (retval == -1) {
788 "Failed to set maximum number of open files, "
789 "insufficient permissions");
792 unsigned soft_limit, hard_limit;
795 "Failed to set requested number of open files, "
796 "using maximum number %u", hard_limit);
797 if (hard_limit > soft_limit) {
804 if (options_manager->
GetValue(
"CVMFS_OOM_SCORE_ADJ", ¶meter)) {
805 string proc_path =
"/proc/" +
StringifyInt(getpid()) +
"/oom_score_adj";
806 int fd_oom = open(proc_path.c_str(), O_WRONLY);
809 "failed to open %s", proc_path.c_str());
811 bool retval =
SafeWrite(fd_oom, parameter.data(), parameter.length());
814 "failed to set OOM score adjustment to %s", parameter.c_str());
821 if (options_manager->
GetValue(
"CVMFS_SYSTEMD_NOKILL", ¶meter) &&
822 options_manager->
IsOn(parameter))
833 "Failed to grab mountpoint %s (%d)",
846 "Failed to drop credentials");
857 if (options_manager->
GetValue(
"CVMFS_USYSLOG", ¶meter))
863 "CernVM-FS: running in single threaded mode");
867 "CernVM-FS: running in debug mode");
870 #ifndef FUSE_CAP_POSIX_ACL
871 if (options_manager->
GetValue(
"CVMFS_ENFORCE_ACLS", ¶meter) &&
872 options_manager->
IsOn(parameter))
875 "CernVM-FS: ACL support requested but not available in this "
876 "version of libfuse");
883 if (options_manager->
GetValue(
"CVMFS_RELOAD_SOCKETS", ¶meter))
889 "Failed to initialize loader socket");
894 delete options_manager;
895 options_manager = NULL;
898 #if CVMFS_USE_LIBFUSE == 2
899 struct fuse_chan *channel;
909 "CernVM-FS: loading Fuse module... ");
918 "\nCernVM-FS: repository %s already mounted on %s",
935 const bool retrievable =
true;
938 "failed to re-gain root permissions for mounting");
945 struct fuse_lowlevel_ops loader_operations;
947 #if (FUSE_VERSION >= 29)
949 loader_operations.forget_multi = stub_forget_multi;
952 #if CVMFS_USE_LIBFUSE == 2
953 channel = fuse_mount(
mount_point_->c_str(), mount_options);
956 "failed to create Fuse channel");
961 session = fuse_lowlevel_new(mount_options, &loader_operations,
962 sizeof(loader_operations), NULL);
965 "failed to create Fuse session");
972 session = fuse_session_new(mount_options, &loader_operations,
973 sizeof(loader_operations), NULL);
976 "failed to create Fuse session");
980 retval = fuse_session_mount(session,
mount_point_->c_str());
983 "failed to mount file system");
994 "failed to drop permissions after mounting");
1001 int fd_mountinfo = open(
"/proc/self/mountinfo", O_RDONLY);
1002 if (fd_mountinfo > 0) {
1004 while (
GetLineFd(fd_mountinfo, &line)) {
1005 std::vector<std::string> tokens =
SplitString(line,
' ');
1006 if (tokens.size() < 5)
continue;
1009 for (; i < tokens.size(); ++i) {
1010 if (tokens[i] ==
"-")
break;
1012 if (tokens.size() < i + 3)
continue;
1013 if (tokens[i + 2] !=
"cvmfs2")
continue;
1017 close(fd_mountinfo);
1025 "CernVM-FS: linking %s to repository %s",
1034 retval = fuse_set_signal_handlers(session);
1036 #if CVMFS_USE_LIBFUSE == 2
1037 fuse_session_add_chan(session, channel);
1040 retval = fuse_session_loop(session);
1042 #if CVMFS_USE_LIBFUSE == 2
1043 retval = fuse_session_loop_mt(session);
1045 retval = fuse_session_loop_mt(session, 1 );
1054 #if CVMFS_USE_LIBFUSE == 2
1055 fuse_remove_signal_handlers(session);
1056 fuse_session_remove_chan(channel);
1057 fuse_session_destroy(session);
1062 fuse_remove_signal_handlers(session);
1063 fuse_session_unmount(session);
1064 fuse_session_destroy(session);
1066 fuse_opt_free_args(mount_options);
1067 delete mount_options;
1069 mount_options = NULL;
1082 fence_reload_ = NULL;
1100 g_cvmfs_stub_exports->fn_main =
FuseMain;
1104 delete g_cvmfs_stub_exports;
1105 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)
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)
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)
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)
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_