CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cvmfs.cc
Go to the documentation of this file.
1 
22 // TODO(jblomer): the file system root should probably always return 1 for an
23 // inode. See also integration test #23.
24 
25 #define ENOATTR ENODATA
27 #ifndef __STDC_FORMAT_MACROS
28 #define __STDC_FORMAT_MACROS
29 #endif
30 
31 // sys/xattr.h conflicts with linux/xattr.h and needs to be loaded very early
32 // clang-format off
33 #include <sys/xattr.h> // NOLINT
34 // clang-format on
35 
36 
37 #include "cvmfs.h"
38 
39 #include <dirent.h>
40 #include <errno.h>
41 #include <fcntl.h>
42 #include <inttypes.h>
43 #include <pthread.h>
44 #include <stddef.h>
45 #include <stdint.h>
46 #include <sys/errno.h>
47 #include <sys/file.h>
48 #include <sys/mount.h>
49 #include <sys/resource.h>
50 #include <sys/stat.h>
51 #include <sys/time.h>
52 #include <sys/types.h>
53 #include <sys/wait.h>
54 #include <unistd.h>
55 
56 #include <algorithm>
57 #include <cassert>
58 #include <cstdio>
59 #include <cstdlib>
60 #include <cstring>
61 #include <ctime>
62 #include <functional>
63 #include <google/dense_hash_map>
64 #include <map>
65 #include <new>
66 #include <string>
67 #include <utility>
68 #include <vector>
69 
70 #include "authz/authz_session.h"
71 #include "auto_umount.h"
72 #include "backoff.h"
73 #include "cache.h"
74 #include "cache_posix.h"
75 #include "cache_stream.h"
76 #include "catalog_mgr_client.h"
77 #include "clientctx.h"
78 #include "compat.h"
80 #include "crypto/crypto_util.h"
81 #include "crypto/hash.h"
82 #include "crypto/signature.h"
83 #include "directory_entry.h"
84 #include "duplex_fuse.h"
85 #include "fence.h"
86 #include "fetch.h"
87 #include "file_chunk.h"
88 #include "fuse_inode_gen.h"
89 #include "fuse_remount.h"
90 #include "globals.h"
91 #include "glue_buffer.h"
92 #include "history_sqlite.h"
93 #include "interrupt.h"
94 #include "loader.h"
95 #include "lru_md.h"
96 #include "magic_xattr.h"
97 #include "manifest_fetch.h"
98 #include "monitor.h"
99 #include "mountpoint.h"
100 #include "network/download.h"
101 #include "nfs_maps.h"
102 #include "notification_client.h"
103 #include "options.h"
104 #include "quota_listener.h"
105 #include "quota_posix.h"
106 #include "sanitizer.h"
107 #include "shortstring.h"
108 #include "sqlitemem.h"
109 #include "sqlitevfs.h"
110 #include "statistics.h"
111 #include "talk.h"
112 #include "telemetry_aggregator.h"
113 #include "tracer.h"
114 #include "util/algorithm.h"
115 #include "util/atomic.h"
116 #include "util/concurrency.h"
117 #include "util/exception.h"
118 #include "util/logging.h"
119 #include "util/platform.h"
120 #include "util/smalloc.h"
121 #include "util/testing.h"
122 #include "util/uuid.h"
123 #include "wpad.h"
124 #include "xattr.h"
125 
126 using namespace std; // NOLINT
127 
128 namespace cvmfs {
129 
137 
138 
144  char *buffer;
146  // Not really used anymore. But directory listing needs to be migrated during
147  // hotpatch. If buffer is allocated by smmap, capacity is zero.
148  size_t size;
149  size_t capacity;
150 
151  DirectoryListing() : buffer(NULL), size(0), capacity(0) { }
152 };
153 
156 pid_t pid_ = 0;
159 
160 
161 typedef google::dense_hash_map<uint64_t, DirectoryListing,
165 pthread_mutex_t lock_directory_handles_ = PTHREAD_MUTEX_INITIALIZER;
167 
168 unsigned max_open_files_;
174 bool check_fd_overflow_ = true;
178 const int kNumReservedFd = 512;
182 const unsigned int kMinOpenFiles = 8192;
183 
184 
186  public:
187  explicit FuseInterruptCue(fuse_req_t *r) : req_ptr_(r) { }
188  virtual ~FuseInterruptCue() { }
189  virtual bool IsCanceled() { return fuse_req_interrupted(*req_ptr_); }
190 
191  private:
192  fuse_req_t *req_ptr_;
193 };
194 
201 struct FuseState {
202  FuseState() : version(0), cache_symlinks(false), has_dentry_expire(false) { }
203  unsigned version;
206 };
207 
208 
214 static inline bool IncAndCheckNoOpenFiles() {
215  const int64_t no_open_files = perf::Xadd(file_system_->no_open_files(), 1);
216  if (!check_fd_overflow_)
217  return true;
218  return no_open_files < (static_cast<int>(max_open_files_) - kNumReservedFd);
219 }
220 
221 static inline double GetKcacheTimeout() {
222  if (!fuse_remounter_->IsCaching())
223  return 0.0;
225 }
226 
227 
228 void GetReloadStatus(bool *drainout_mode, bool *maintenance_mode) {
229  *drainout_mode = fuse_remounter_->IsInDrainoutMode();
230  *maintenance_mode = fuse_remounter_->IsInMaintenanceMode();
231 }
232 
233 
234 static bool UseWatchdog() {
235  if (loader_exports_ == NULL || loader_exports_->version < 2) {
236  return true; // spawn watchdog by default
237  // Note: with library versions before 2.1.8 it might not
238  // create stack traces properly in all cases
239  }
240 
242 }
243 
244 std::string PrintInodeGeneration() {
245  return "init-catalog-revision: "
247  + "current-catalog-revision: "
249  + "incarnation: " + StringifyInt(inode_generation_info_.incarnation)
250  + " " + "inode generation: "
252 }
253 
254 
255 static bool CheckVoms(const fuse_ctx &fctx) {
257  return true;
258  const string mreq = mount_point_->membership_req();
260  "Got VOMS authz %s from filesystem "
261  "properties",
262  mreq.c_str());
263 
264  if (fctx.uid == 0)
265  return true;
266 
267  return mount_point_->authz_session_mgr()->IsMemberOf(fctx.pid, mreq);
268 }
269 
271  return dirent.IsRegular()
272  && (dirent.inode() < mount_point_->catalog_mgr()->GetRootInode());
273 }
274 
276  const shash::Any &hash,
277  const struct stat &info) {
278  if (hash == dirent.checksum())
279  return false;
280  // For chunked files, we don't want to load the full list of chunk hashes
281  // so we only check the last modified timestamp
282  if (dirent.IsChunkedFile() && (info.st_mtime == dirent.mtime()))
283  return false;
284  return true;
285 }
286 
297 static bool FixupOpenInode(const PathString &path,
298  catalog::DirectoryEntry *dirent) {
299  if (!MayBeInPageCacheTracker(*dirent))
300  return false;
301 
302  CVMFS_TEST_INJECT_BARRIER("_CVMFS_TEST_BARRIER_INODE_REPLACE");
303 
304  const bool is_stale = mount_point_->page_cache_tracker()->IsStale(*dirent);
305 
306  if (is_stale) {
307  // Overwrite dirent with inode from current generation
308  const bool found = mount_point_->catalog_mgr()->LookupPath(
309  path, catalog::kLookupDefault, dirent);
310  assert(found);
311  }
312 
313  return is_stale;
314 }
315 
316 static bool GetDirentForInode(const fuse_ino_t ino,
317  catalog::DirectoryEntry *dirent) {
318  // Lookup inode in cache
319  if (mount_point_->inode_cache()->Lookup(ino, dirent))
320  return true;
321 
322  // Look in the catalogs in 2 steps: lookup inode->path, lookup path
323  static const catalog::DirectoryEntry dirent_negative =
325  // Reset directory entry. If the function returns false and dirent is no
326  // the kDirentNegative, it was an I/O error
327  *dirent = catalog::DirectoryEntry();
328 
330 
331  if (file_system_->IsNfsSource()) {
332  // NFS mode
333  PathString path;
334  const bool retval = file_system_->nfs_maps()->GetPath(ino, &path);
335  if (!retval) {
336  *dirent = dirent_negative;
337  return false;
338  }
339  if (catalog_mgr->LookupPath(path, catalog::kLookupDefault, dirent)) {
340  // Fix inodes
341  dirent->set_inode(ino);
342  mount_point_->inode_cache()->Insert(ino, *dirent);
343  return true;
344  }
345  return false; // Not found in catalog or catalog load error
346  }
347 
348  // Non-NFS mode
349  PathString path;
350  if (ino == catalog_mgr->GetRootInode()) {
351  const bool retval =
352  catalog_mgr->LookupPath(PathString(), catalog::kLookupDefault, dirent);
353 
355  "GetDirentForInode: Race condition? Not found dirent %s",
356  dirent->name().c_str())) {
357  return false;
358  }
359 
360  dirent->set_inode(ino);
361  mount_point_->inode_cache()->Insert(ino, *dirent);
362  return true;
363  }
364 
366  const bool retval = mount_point_->inode_tracker()->FindPath(&inode_ex, &path);
367  if (!retval) {
368  // This may be a retired inode whose stat information is only available
369  // in the page cache tracker because there is still an open file
371  "GetDirentForInode inode lookup failure %" PRId64, ino);
372  *dirent = dirent_negative;
373  // Indicate that the inode was not found in the tracker rather than not
374  // found in the catalog
375  dirent->set_inode(ino);
376  return false;
377  }
378  if (catalog_mgr->LookupPath(path, catalog::kLookupDefault, dirent)) {
379  if (!inode_ex.IsCompatibleFileType(dirent->mode())) {
381  "Warning: inode %" PRId64 " (%s) changed file type", ino,
382  path.c_str());
383  // TODO(jblomer): we detect this issue but let it continue unhandled.
384  // Fix me.
385  }
386 
387  // Fix inodes
388  dirent->set_inode(ino);
389  mount_point_->inode_cache()->Insert(ino, *dirent);
390  return true;
391  }
392 
393  // Can happen after reload of catalogs or on catalog load failure
394  LogCvmfs(kLogCvmfs, kLogDebug, "GetDirentForInode path lookup failure");
395  return false;
396 }
397 
398 
406 static uint64_t GetDirentForPath(const PathString &path,
407  catalog::DirectoryEntry *dirent) {
408  uint64_t live_inode = 0;
409  if (!file_system_->IsNfsSource())
410  live_inode = mount_point_->inode_tracker()->FindInode(path);
411 
413  "GetDirentForPath: live inode for %s: %" PRIu64, path.c_str(),
414  live_inode);
415 
416  const shash::Md5 md5path(path.GetChars(), path.GetLength());
417  if (mount_point_->md5path_cache()->Lookup(md5path, dirent)) {
418  if (dirent->GetSpecial() == catalog::kDirentNegative)
419  return false;
420  // We may have initially stored the entry with an old inode in the
421  // md5path cache and now should update it with the new one.
422  if (!file_system_->IsNfsSource() && (live_inode != 0))
423  dirent->set_inode(live_inode);
424  return 1;
425  }
426 
428 
429  // Lookup inode in catalog TODO: not twice md5 calculation
430  bool retval;
431  retval = catalog_mgr->LookupPath(path, catalog::kLookupDefault, dirent);
432  if (retval) {
433  if (file_system_->IsNfsSource()) {
434  dirent->set_inode(file_system_->nfs_maps()->GetInode(path));
435  } else if (live_inode != 0) {
436  dirent->set_inode(live_inode);
437  if (FixupOpenInode(path, dirent)) {
439  "content of %s change, replacing inode %" PRIu64
440  " --> %" PRIu64,
441  path.c_str(), live_inode, dirent->inode());
442  return live_inode;
443  // Do not populate the md5path cache until the inode tracker is fixed
444  }
445  }
446  mount_point_->md5path_cache()->Insert(md5path, *dirent);
447  return 1;
448  }
449 
450  LogCvmfs(kLogCvmfs, kLogDebug, "GetDirentForPath, no entry");
451  // Only insert ENOENT results into negative cache. Otherwise it was an
452  // error loading nested catalogs
453  if (dirent->GetSpecial() == catalog::kDirentNegative)
455  return 0;
456 }
457 
458 
459 static bool GetPathForInode(const fuse_ino_t ino, PathString *path) {
460  // Check the path cache first
461  if (mount_point_->path_cache()->Lookup(ino, path))
462  return true;
463 
464  if (file_system_->IsNfsSource()) {
465  // NFS mode, just a lookup
466  LogCvmfs(kLogCvmfs, kLogDebug, "MISS %lu - lookup in NFS maps", ino);
467  if (file_system_->nfs_maps()->GetPath(ino, path)) {
468  mount_point_->path_cache()->Insert(ino, *path);
469  return true;
470  }
471  return false;
472  }
473 
474  if (ino == mount_point_->catalog_mgr()->GetRootInode())
475  return true;
476 
477  LogCvmfs(kLogCvmfs, kLogDebug, "MISS %lu - looking in inode tracker", ino);
479  const bool retval = mount_point_->inode_tracker()->FindPath(&inode_ex, path);
480 
482  "GetPathForInode: Race condition? "
483  "Inode not found in inode tracker at path %s",
484  path->c_str())) {
485  return false;
486  }
487 
488 
489  mount_point_->path_cache()->Insert(ino, *path);
490  return true;
491 }
492 
493 static void DoTraceInode(const int event,
494  fuse_ino_t ino,
495  const std::string &msg) {
496  PathString path;
497  const bool found = GetPathForInode(ino, &path);
498  if (!found) {
500  "Tracing: Could not find path for inode %" PRIu64, uint64_t(ino));
501  mount_point_->tracer()->Trace(event, PathString("@UNKNOWN"), msg);
502  } else {
503  mount_point_->tracer()->Trace(event, path, msg);
504  }
505 }
506 
507 static void inline TraceInode(const int event,
508  fuse_ino_t ino,
509  const std::string &msg) {
510  if (mount_point_->tracer()->IsActive())
511  DoTraceInode(event, ino, msg);
512 }
513 
519 static void cvmfs_lookup(fuse_req_t req, fuse_ino_t parent, const char *name) {
520  const HighPrecisionTimer guard_timer(file_system_->hist_fs_lookup());
521 
523  const struct fuse_ctx *fuse_ctx = fuse_req_ctx(req);
524  FuseInterruptCue ic(&req);
525  const ClientCtxGuard ctx_guard(fuse_ctx->uid, fuse_ctx->gid, fuse_ctx->pid,
526  &ic);
528 
531 
532  const fuse_ino_t parent_fuse = parent;
533  parent = catalog_mgr->MangleInode(parent);
535  "cvmfs_lookup in parent inode: %" PRIu64 " for name: %s",
536  uint64_t(parent), name);
537 
538  PathString path;
539  PathString parent_path;
540  uint64_t live_inode = 0;
542  struct fuse_entry_param result;
543 
544  memset(&result, 0, sizeof(result));
545  const double timeout = GetKcacheTimeout();
546  result.attr_timeout = timeout;
547  result.entry_timeout = timeout;
548 
549  // Special NFS lookups: . and ..
550  if ((strcmp(name, ".") == 0) || (strcmp(name, "..") == 0)) {
551  if (GetDirentForInode(parent, &dirent)) {
552  if (strcmp(name, ".") == 0) {
553  goto lookup_reply_positive;
554  } else {
555  // Lookup for ".."
556  if (dirent.inode() == catalog_mgr->GetRootInode()) {
557  dirent.set_inode(1);
558  goto lookup_reply_positive;
559  }
560  if (!GetPathForInode(parent, &parent_path))
561  goto lookup_reply_negative;
562  if (GetDirentForPath(GetParentPath(parent_path), &dirent) > 0)
563  goto lookup_reply_positive;
564  }
565  }
566  // No entry for "." or no entry for ".."
567  if (dirent.GetSpecial() == catalog::kDirentNegative)
568  goto lookup_reply_negative;
569  else
570  goto lookup_reply_error;
571  assert(false);
572  }
573 
574  if (!GetPathForInode(parent, &parent_path)) {
575  LogCvmfs(kLogCvmfs, kLogDebug, "no path for parent inode found");
576  goto lookup_reply_negative;
577  }
578 
579  path.Assign(parent_path);
580  path.Append("/", 1);
581  path.Append(name, strlen(name));
582  live_inode = GetDirentForPath(path, &dirent);
583  if (live_inode == 0) {
584  if (dirent.GetSpecial() == catalog::kDirentNegative)
585  goto lookup_reply_negative;
586  else
587  goto lookup_reply_error;
588  }
589 
590 lookup_reply_positive:
591  mount_point_->tracer()->Trace(Tracer::kEventLookup, path, "lookup()");
592  if (!file_system_->IsNfsSource()) {
593  if (live_inode > 1) {
594  // live inode is stale (open file), we replace it
595  assert(dirent.IsRegular());
596  assert(dirent.inode() != live_inode);
597 
598  // The new inode is put in the tracker with refcounter == 0
599  const bool replaced = mount_point_->inode_tracker()->ReplaceInode(
600  live_inode, glue::InodeEx(dirent.inode(), dirent.mode()));
601  if (replaced)
603  }
605  glue::InodeEx(dirent.inode(), dirent.mode()), path);
606  }
607  // We do _not_ track (and evict) positive replies; among other things, test
608  // 076 fails with the following line uncommented
609  //
610  // WARNING! ENABLING THIS BREAKS ANY TYPE OF MOUNTPOINT POINTING TO THIS INODE
611  //
612  // only safe if fuse_expire_entry is available
614  || (mount_point_->cache_symlinks() && dirent.IsLink())) {
615  LogCvmfs(kLogCache, kLogDebug, "Dentry to evict: %s", name);
616  mount_point_->dentry_tracker()->Add(parent_fuse, name,
617  static_cast<uint64_t>(timeout));
618  }
619 
621  result.ino = dirent.inode();
622  result.attr = dirent.GetStatStructure();
623  fuse_reply_entry(req, &result);
624  return;
625 
626 lookup_reply_negative:
627  mount_point_->tracer()->Trace(Tracer::kEventLookup, path,
628  "lookup()-NOTFOUND");
629  // Will be a no-op if there is no fuse cache eviction
630  mount_point_->dentry_tracker()->Add(parent_fuse, name, uint64_t(timeout));
633  result.ino = 0;
634  fuse_reply_entry(req, &result);
635  return;
636 
637 lookup_reply_error:
638  mount_point_->tracer()->Trace(Tracer::kEventLookup, path,
639  "lookup()-NOTFOUND");
641 
643  "EIO (01): lookup failed for %s", name);
646 
647  fuse_reply_err(req, EIO);
648 }
649 
650 
654 static void cvmfs_forget(fuse_req_t req,
655  fuse_ino_t ino,
656 #if CVMFS_USE_LIBFUSE == 2
657  unsigned long nlookup // NOLINT
658 #else
659  uint64_t nlookup
660 #endif
661 ) {
662  const HighPrecisionTimer guard_timer(file_system_->hist_fs_forget());
663 
665 
666  // The libfuse high-level library does the same
667  if (ino == FUSE_ROOT_ID) {
668  fuse_reply_none(req);
669  return;
670  }
671 
672  // Ensure that we don't need to call catalog_mgr()->MangleInode(ino)
674 
675  LogCvmfs(kLogCvmfs, kLogDebug, "forget on inode %" PRIu64 " by %" PRIu64,
676  uint64_t(ino), nlookup);
677 
678  if (!file_system_->IsNfsSource()) {
679  const bool removed =
680  mount_point_->inode_tracker()->GetVfsPutRaii().VfsPut(ino, nlookup);
681  if (removed)
683  }
684 
685  fuse_reply_none(req);
686 }
687 
688 
689 #if (FUSE_VERSION >= 29)
690 static void cvmfs_forget_multi(fuse_req_t req,
691  size_t count,
692  struct fuse_forget_data *forgets) {
694 
696  if (file_system_->IsNfsSource()) {
697  fuse_reply_none(req);
698  return;
699  }
700 
701  {
703  ->GetVfsPutRaii();
705  evict_raii = mount_point_->page_cache_tracker()->GetEvictRaii();
706  for (size_t i = 0; i < count; ++i) {
707  if (forgets[i].ino == FUSE_ROOT_ID) {
708  continue;
709  }
710 
711  // Ensure that we don't need to call catalog_mgr()->MangleInode(ino)
712  assert(forgets[i].ino > mount_point_->catalog_mgr()->kInodeOffset);
713  LogCvmfs(kLogCvmfs, kLogDebug, "forget on inode %" PRIu64 " by %" PRIu64,
714  forgets[i].ino, forgets[i].nlookup);
715 
716  const bool removed =
717  vfs_put_raii.VfsPut(forgets[i].ino, forgets[i].nlookup);
718  if (removed)
719  evict_raii.Evict(forgets[i].ino);
720  }
721  }
722 
723  fuse_reply_none(req);
724 }
725 #endif // FUSE_VERSION >= 29
726 
727 
734 static void ReplyNegative(const catalog::DirectoryEntry &dirent,
735  fuse_req_t req) {
736  if (dirent.GetSpecial() == catalog::kDirentNegative) {
737  fuse_reply_err(req, ENOENT);
738  } else {
739  const char *name = dirent.name().c_str();
740  const char *link = dirent.symlink().c_str();
741 
742  LogCvmfs(
744  "EIO (02): CVMFS-specific metadata not found for name=%s symlink=%s",
745  name ? name : "<unset>", link ? link : "<unset>");
746 
749  fuse_reply_err(req, EIO);
750  }
751 }
752 
753 
757 static void cvmfs_getattr(fuse_req_t req, fuse_ino_t ino,
758  struct fuse_file_info *fi) {
759  const HighPrecisionTimer guard_timer(file_system_->hist_fs_getattr());
760 
762  const struct fuse_ctx *fuse_ctx = fuse_req_ctx(req);
763  FuseInterruptCue ic(&req);
764  const ClientCtxGuard ctx_guard(fuse_ctx->uid, fuse_ctx->gid, fuse_ctx->pid,
765  &ic);
767 
769  ino = mount_point_->catalog_mgr()->MangleInode(ino);
770  LogCvmfs(kLogCvmfs, kLogDebug, "cvmfs_getattr (stat) for inode: %" PRIu64,
771  uint64_t(ino));
772 
773  if (!CheckVoms(*fuse_ctx)) {
775  fuse_reply_err(req, EACCES);
776  return;
777  }
779  const bool found = GetDirentForInode(ino, &dirent);
780  TraceInode(Tracer::kEventGetAttr, ino, "getattr()");
781  if ((!found && (dirent.inode() == ino)) || MayBeInPageCacheTracker(dirent)) {
782  // Serve retired inode from page cache tracker; even if we find it in the
783  // catalog, we replace the dirent by the page cache tracker version to
784  // not confuse open file handles
786  "cvmfs_getattr %" PRIu64 " "
787  "served from page cache tracker",
788  ino);
789  shash::Any hash;
790  struct stat info;
791  const bool is_open =
792  mount_point_->page_cache_tracker()->GetInfoIfOpen(ino, &hash, &info);
793  if (is_open) {
795  if (found && HasDifferentContent(dirent, hash, info)) {
796  // We should from now on provide the new inode information instead
797  // of the stale one. To this end, we need to invalidate the dentry to
798  // trigger a fresh LOOKUP call
799  uint64_t parent_ino;
800  NameString name;
801  if (mount_point_->inode_tracker()->FindDentry(dirent.inode(),
802  &parent_ino, &name)) {
803  fuse_remounter_->InvalidateDentry(parent_ino, name);
804  }
806  }
807  fuse_reply_attr(req, &info, GetKcacheTimeout());
808  return;
809  }
810  }
812 
813  if (!found) {
814  ReplyNegative(dirent, req);
815  return;
816  }
817 
818  struct stat const info = dirent.GetStatStructure();
819 
820  fuse_reply_attr(req, &info, GetKcacheTimeout());
821 }
822 
823 
827 static void cvmfs_readlink(fuse_req_t req, fuse_ino_t ino) {
828  const HighPrecisionTimer guard_timer(file_system_->hist_fs_readlink());
829 
831  const struct fuse_ctx *fuse_ctx = fuse_req_ctx(req);
832  FuseInterruptCue ic(&req);
833  const ClientCtxGuard ctx_guard(fuse_ctx->uid, fuse_ctx->gid, fuse_ctx->pid,
834  &ic);
835 
837  ino = mount_point_->catalog_mgr()->MangleInode(ino);
838  LogCvmfs(kLogCvmfs, kLogDebug, "cvmfs_readlink on inode: %" PRIu64,
839  uint64_t(ino));
840 
842  const bool found = GetDirentForInode(ino, &dirent);
843  TraceInode(Tracer::kEventReadlink, ino, "readlink()");
845 
846  if (!found) {
847  ReplyNegative(dirent, req);
848  return;
849  }
850 
851  if (!dirent.IsLink()) {
852  fuse_reply_err(req, EINVAL);
853  return;
854  }
855 
856  fuse_reply_readlink(req, dirent.symlink().c_str());
857 }
858 
859 
860 static void AddToDirListing(const fuse_req_t req, const char *name,
861  const struct stat *stat_info,
862  BigVector<char> *listing) {
863  LogCvmfs(kLogCvmfs, kLogDebug, "Add to listing: %s, inode %" PRIu64, name,
864  uint64_t(stat_info->st_ino));
865  size_t remaining_size = listing->capacity() - listing->size();
866  const size_t entry_size = fuse_add_direntry(req, NULL, 0, name, stat_info, 0);
867 
868  while (entry_size > remaining_size) {
869  listing->DoubleCapacity();
870  remaining_size = listing->capacity() - listing->size();
871  }
872 
873  char *buffer;
874  bool large_alloc;
875  listing->ShareBuffer(&buffer, &large_alloc);
876  fuse_add_direntry(req, buffer + listing->size(), remaining_size, name,
877  stat_info, listing->size() + entry_size);
878  listing->SetSize(listing->size() + entry_size);
879 }
880 
881 
885 static void cvmfs_opendir(fuse_req_t req, fuse_ino_t ino,
886  struct fuse_file_info *fi) {
887  const HighPrecisionTimer guard_timer(file_system_->hist_fs_opendir());
888 
889  const struct fuse_ctx *fuse_ctx = fuse_req_ctx(req);
890  FuseInterruptCue ic(&req);
891  const ClientCtxGuard ctx_guard(fuse_ctx->uid, fuse_ctx->gid, fuse_ctx->pid,
892  &ic);
894 
897  ino = catalog_mgr->MangleInode(ino);
898  LogCvmfs(kLogCvmfs, kLogDebug, "cvmfs_opendir on inode: %" PRIu64,
899  uint64_t(ino));
900  if (!CheckVoms(*fuse_ctx)) {
902  fuse_reply_err(req, EACCES);
903  return;
904  }
905 
906  TraceInode(Tracer::kEventOpenDir, ino, "opendir()");
907  PathString path;
909  bool found = GetPathForInode(ino, &path);
910  if (!found) {
912  fuse_reply_err(req, ENOENT);
913  return;
914  }
915  found = GetDirentForInode(ino, &d);
916 
917  if (!found) {
919  ReplyNegative(d, req);
920  return;
921  }
922  if (!d.IsDirectory()) {
924  fuse_reply_err(req, ENOTDIR);
925  return;
926  }
927 
928  LogCvmfs(kLogCvmfs, kLogDebug, "cvmfs_opendir on inode: %" PRIu64 ", path %s",
929  uint64_t(ino), path.c_str());
930 
931  // Build listing
932  BigVector<char> fuse_listing(512);
933 
934  // Add current directory link
935  struct stat info;
936  info = d.GetStatStructure();
937  AddToDirListing(req, ".", &info, &fuse_listing);
938 
939  // Add parent directory link
941  if (d.inode() != catalog_mgr->GetRootInode()
942  && (GetDirentForPath(GetParentPath(path), &p) > 0)) {
943  info = p.GetStatStructure();
944  AddToDirListing(req, "..", &info, &fuse_listing);
945  }
946 
947  // Add all names
948  catalog::StatEntryList listing_from_catalog;
949  const bool retval = catalog_mgr->ListingStat(path, &listing_from_catalog);
950 
951  if (!retval) {
953  fuse_listing.Clear(); // Buffer is shared, empty manually
954 
956  "EIO (03): failed to open directory at %s", path.c_str());
959  fuse_reply_err(req, EIO);
960  return;
961  }
962  for (unsigned i = 0; i < listing_from_catalog.size(); ++i) {
963  // Fix inodes
964  PathString entry_path;
965  entry_path.Assign(path);
966  entry_path.Append("/", 1);
967  entry_path.Append(listing_from_catalog.AtPtr(i)->name.GetChars(),
968  listing_from_catalog.AtPtr(i)->name.GetLength());
969 
970  catalog::DirectoryEntry entry_dirent;
971  if (!GetDirentForPath(entry_path, &entry_dirent)) {
972  LogCvmfs(kLogCvmfs, kLogDebug, "listing entry %s vanished, skipping",
973  entry_path.c_str());
974  continue;
975  }
976 
977  struct stat fixed_info = listing_from_catalog.AtPtr(i)->info;
978  fixed_info.st_ino = entry_dirent.inode();
979  AddToDirListing(req, listing_from_catalog.AtPtr(i)->name.c_str(),
980  &fixed_info, &fuse_listing);
981  }
983 
984  DirectoryListing stream_listing;
985  stream_listing.size = fuse_listing.size();
986  stream_listing.capacity = fuse_listing.capacity();
987  bool large_alloc;
988  fuse_listing.ShareBuffer(&stream_listing.buffer, &large_alloc);
989  if (large_alloc)
990  stream_listing.capacity = 0;
991 
992  // Save the directory listing and return a handle to the listing
993  {
996  "linking directory handle %lu to dir inode: %" PRIu64,
997  next_directory_handle_, uint64_t(ino));
998  (*directory_handles_)[next_directory_handle_] = stream_listing;
999  fi->fh = next_directory_handle_;
1001  }
1004 
1005 #if (FUSE_VERSION >= 30)
1006 #ifdef CVMFS_ENABLE_FUSE3_CACHE_READDIR
1007  // This affects only reads on the same open directory handle (e.g. multiple
1008  // reads with rewinddir() between them). A new opendir on the same directory
1009  // will trigger readdir calls independently of this setting.
1010  fi->cache_readdir = 1;
1011 #endif
1012 #endif
1013  fuse_reply_open(req, fi);
1014 }
1015 
1016 
1020 static void cvmfs_releasedir(fuse_req_t req, fuse_ino_t ino,
1021  struct fuse_file_info *fi) {
1022  const HighPrecisionTimer guard_timer(file_system_->hist_fs_releasedir());
1023 
1024  ino = mount_point_->catalog_mgr()->MangleInode(ino);
1026  "cvmfs_releasedir on inode %" PRIu64 ", handle %lu", uint64_t(ino),
1027  fi->fh);
1028 
1029  int reply = 0;
1030 
1031  {
1033  const DirectoryHandles::iterator iter_handle =
1034  directory_handles_->find(fi->fh);
1035  if (iter_handle != directory_handles_->end()) {
1036  if (iter_handle->second.capacity == 0)
1037  smunmap(iter_handle->second.buffer);
1038  else
1039  free(iter_handle->second.buffer);
1040  directory_handles_->erase(iter_handle);
1042  } else {
1043  reply = EINVAL;
1044  }
1045  }
1046 
1047  fuse_reply_err(req, reply);
1048 }
1049 
1050 
1054 static void ReplyBufferSlice(const fuse_req_t req, const char *buffer,
1055  const size_t buffer_size, const off_t offset,
1056  const size_t max_size) {
1057  if (offset < static_cast<int>(buffer_size)) {
1058  fuse_reply_buf(
1059  req, buffer + offset,
1060  std::min(static_cast<size_t>(buffer_size - offset), max_size));
1061  } else {
1062  fuse_reply_buf(req, NULL, 0);
1063  }
1064 }
1065 
1066 
1070 static void cvmfs_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
1071  off_t off, struct fuse_file_info *fi) {
1072  const HighPrecisionTimer guard_timer(file_system_->hist_fs_readdir());
1073 
1075  "cvmfs_readdir on inode %" PRIu64
1076  " reading %lu bytes from offset %ld",
1077  static_cast<uint64_t>(mount_point_->catalog_mgr()->MangleInode(ino)),
1078  size, off);
1079 
1080  DirectoryListing listing;
1081 
1083  const DirectoryHandles::const_iterator iter_handle =
1084  directory_handles_->find(fi->fh);
1085  if (iter_handle != directory_handles_->end()) {
1086  listing = iter_handle->second;
1087 
1088  ReplyBufferSlice(req, listing.buffer, listing.size, off, size);
1089  return;
1090  }
1091 
1092  fuse_reply_err(req, EINVAL);
1093 }
1094 
1096  struct fuse_file_info *fi) {
1098  fi->keep_cache = od.keep_cache;
1099  fi->direct_io = od.direct_io;
1100  if (fi->direct_io)
1102 }
1103 
1104 
1105 #ifdef __APPLE__
1106 // On macOS, xattr on a symlink opens and closes the file (with O_SYMLINK)
1107 // around the actual getxattr call. In order to not run into an I/O error
1108 // we use a special file handle for symlinks, from which one cannot read.
1109 static const uint64_t kFileHandleIgnore = static_cast<uint64_t>(2) << 60;
1110 #endif
1111 
1118 static void cvmfs_open(fuse_req_t req, fuse_ino_t ino,
1119  struct fuse_file_info *fi) {
1120  const HighPrecisionTimer guard_timer(file_system_->hist_fs_open());
1121 
1122  const struct fuse_ctx *fuse_ctx = fuse_req_ctx(req);
1123  FuseInterruptCue ic(&req);
1124  const ClientCtxGuard ctx_guard(fuse_ctx->uid, fuse_ctx->gid, fuse_ctx->pid,
1125  &ic);
1126  fuse_remounter_->fence()->Enter();
1128  ino = catalog_mgr->MangleInode(ino);
1129  LogCvmfs(kLogCvmfs, kLogDebug, "cvmfs_open on inode: %" PRIu64,
1130  uint64_t(ino));
1131 
1132  int fd = -1;
1133  catalog::DirectoryEntry dirent;
1134  PathString path;
1135 
1136  bool found = GetPathForInode(ino, &path);
1137  if (!found) {
1138  fuse_remounter_->fence()->Leave();
1139  fuse_reply_err(req, ENOENT);
1140  return;
1141  }
1142  found = GetDirentForInode(ino, &dirent);
1143  if (!found) {
1144  fuse_remounter_->fence()->Leave();
1145  ReplyNegative(dirent, req);
1146  return;
1147  }
1148 
1149  if (!CheckVoms(*fuse_ctx)) {
1150  fuse_remounter_->fence()->Leave();
1151  fuse_reply_err(req, EACCES);
1152  return;
1153  }
1154 
1155  mount_point_->tracer()->Trace(Tracer::kEventOpen, path, "open()");
1156  // Don't check. Either done by the OS or one wants to purposefully work
1157  // around wrong open flags
1158  // if ((fi->flags & 3) != O_RDONLY) {
1159  // fuse_reply_err(req, EROFS);
1160  // return;
1161  // }
1162 #ifdef __APPLE__
1163  if ((fi->flags & O_SHLOCK) || (fi->flags & O_EXLOCK)) {
1164  fuse_remounter_->fence()->Leave();
1165  fuse_reply_err(req, EOPNOTSUPP);
1166  return;
1167  }
1168  if (fi->flags & O_SYMLINK) {
1169  fuse_remounter_->fence()->Leave();
1170  fi->fh = kFileHandleIgnore;
1171  fuse_reply_open(req, fi);
1172  return;
1173  }
1174 #endif
1175  if (fi->flags & O_EXCL) {
1176  fuse_remounter_->fence()->Leave();
1177  fuse_reply_err(req, EEXIST);
1178  return;
1179  }
1180 
1181  perf::Inc(file_system_->n_fs_open()); // Count actual open / fetch operations
1182 
1184  if (!dirent.IsChunkedFile()) {
1185  if (dirent.IsDirectIo()) {
1186  open_directives = mount_point_->page_cache_tracker()->OpenDirect();
1187  } else {
1188  open_directives = mount_point_->page_cache_tracker()->Open(
1189  ino, dirent.checksum(), dirent.GetStatStructure());
1190  }
1191  fuse_remounter_->fence()->Leave();
1192  } else {
1194  "chunked file %s opened (download delayed to read() call)",
1195  path.c_str());
1196 
1197  if (!IncAndCheckNoOpenFiles()) {
1199  fuse_remounter_->fence()->Leave();
1200  LogCvmfs(kLogCvmfs, kLogSyslogErr, "open file descriptor limit exceeded");
1201  fuse_reply_err(req, EMFILE);
1203  return;
1204  }
1205 
1206  // Figure out unique inode from annotated catalog
1207  // TODO(jblomer): we only need to lookup if the inode is not from the
1208  // current generation
1209  catalog::DirectoryEntry dirent_origin;
1210  if (!catalog_mgr->LookupPath(path, catalog::kLookupDefault,
1211  &dirent_origin)) {
1212  fuse_remounter_->fence()->Leave();
1214  "chunked file %s vanished unexpectedly", path.c_str());
1215  fuse_reply_err(req, ENOENT);
1216  return;
1217  }
1218  const uint64_t unique_inode = dirent_origin.inode();
1219 
1220  ChunkTables *chunk_tables = mount_point_->chunk_tables();
1221  chunk_tables->Lock();
1222  if (!chunk_tables->inode2chunks.Contains(unique_inode)) {
1223  chunk_tables->Unlock();
1224 
1225  // Retrieve File chunks from the catalog
1227  if (!catalog_mgr->ListFileChunks(path, dirent.hash_algorithm(),
1228  chunks.weak_ref())
1229  || chunks->IsEmpty()) {
1230  fuse_remounter_->fence()->Leave();
1232  "EIO (04): failed to open file %s. "
1233  "It is marked as 'chunked', but no chunks found.",
1234  path.c_str());
1237  fuse_reply_err(req, EIO);
1238  return;
1239  }
1240  fuse_remounter_->fence()->Leave();
1241 
1242  chunk_tables->Lock();
1243  // Check again to avoid race
1244  if (!chunk_tables->inode2chunks.Contains(unique_inode)) {
1245  chunk_tables->inode2chunks.Insert(
1246  unique_inode, FileChunkReflist(chunks.Release(), path,
1247  dirent.compression_algorithm(),
1248  dirent.IsExternalFile()));
1249  chunk_tables->inode2references.Insert(unique_inode, 1);
1250  } else {
1251  uint32_t refctr;
1252  const bool retval =
1253  chunk_tables->inode2references.Lookup(unique_inode, &refctr);
1254  assert(retval);
1255  chunk_tables->inode2references.Insert(unique_inode, refctr + 1);
1256  }
1257  } else {
1258  fuse_remounter_->fence()->Leave();
1259  uint32_t refctr;
1260  const bool retval =
1261  chunk_tables->inode2references.Lookup(unique_inode, &refctr);
1262  assert(retval);
1263  chunk_tables->inode2references.Insert(unique_inode, refctr + 1);
1264  }
1265 
1266  // Update the chunk handle list
1268  "linking chunk handle %lu to unique inode: %" PRIu64,
1269  chunk_tables->next_handle, uint64_t(unique_inode));
1270  chunk_tables->handle2fd.Insert(chunk_tables->next_handle, ChunkFd());
1271  chunk_tables->handle2uniqino.Insert(chunk_tables->next_handle,
1272  unique_inode);
1273 
1274  // Generate artificial content hash as hash over chunk hashes
1275  // TODO(jblomer): we may want to cache the result in the chunk tables
1276  FileChunkReflist chunk_reflist;
1277  const bool retval =
1278  chunk_tables->inode2chunks.Lookup(unique_inode, &chunk_reflist);
1279  assert(retval);
1280 
1281  fi->fh = chunk_tables->next_handle;
1282  if (dirent.IsDirectIo()) {
1283  open_directives = mount_point_->page_cache_tracker()->OpenDirect();
1284  } else {
1285  open_directives = mount_point_->page_cache_tracker()->Open(
1286  ino, chunk_reflist.HashChunkList(), dirent.GetStatStructure());
1287  }
1288  FillOpenFlags(open_directives, fi);
1289  fi->fh = static_cast<uint64_t>(-static_cast<int64_t>(fi->fh));
1290  ++chunk_tables->next_handle;
1291  chunk_tables->Unlock();
1292 
1293  fuse_reply_open(req, fi);
1294  return;
1295  }
1296 
1297  Fetcher *this_fetcher = dirent.IsExternalFile()
1299  : mount_point_->fetcher();
1300  CacheManager::Label label;
1301  label.path = path.ToString();
1302  label.size = dirent.size();
1303  label.zip_algorithm = dirent.compression_algorithm();
1306  if (dirent.IsExternalFile())
1308  fd = this_fetcher->Fetch(
1309  CacheManager::LabeledObject(dirent.checksum(), label));
1310 
1311  if (fd >= 0) {
1312  if (IncAndCheckNoOpenFiles()) {
1313  LogCvmfs(kLogCvmfs, kLogDebug, "file %s opened (fd %d)", path.c_str(),
1314  fd);
1315  fi->fh = fd;
1316  FillOpenFlags(open_directives, fi);
1317  fuse_reply_open(req, fi);
1318  return;
1319  } else {
1320  if (file_system_->cache_mgr()->Close(fd) == 0)
1322  LogCvmfs(kLogCvmfs, kLogSyslogErr, "open file descriptor limit exceeded");
1323  // not returning an fd, so close the page cache tracker entry if required
1324  if (!dirent.IsDirectIo()) {
1325  fuse_remounter_->fence()->Enter();
1327  fuse_remounter_->fence()->Leave();
1328  }
1329  fuse_reply_err(req, EMFILE);
1331  return;
1332  }
1333  assert(false);
1334  }
1335 
1336  // fd < 0
1337  // the download has failed. Close the page cache tracker entry if required
1338  if (!dirent.IsDirectIo()) {
1339  fuse_remounter_->fence()->Enter();
1341  fuse_remounter_->fence()->Leave();
1342  }
1343 
1345  "failed to open inode: %" PRIu64 ", CAS key %s, error code %d",
1346  uint64_t(ino), dirent.checksum().ToString().c_str(), errno);
1347  if (errno == EMFILE) {
1348  LogCvmfs(kLogCvmfs, kLogSyslogErr, "open file descriptor limit exceeded");
1349  fuse_reply_err(req, EMFILE);
1351  return;
1352  }
1353 
1355 
1357  if (EIO == errno || EIO == -fd) {
1359  "EIO (06): Failed to open file %s", path.c_str());
1362  }
1363 
1364  fuse_reply_err(req, -fd);
1365 }
1366 
1367 
1371 static void cvmfs_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
1372  struct fuse_file_info *fi) {
1373  const HighPrecisionTimer guard_timer(file_system_->hist_fs_read());
1374 
1376  "cvmfs_read inode: %" PRIu64 " reading %lu bytes from offset %ld "
1377  "fd %lu",
1378  uint64_t(mount_point_->catalog_mgr()->MangleInode(ino)), size, off,
1379  fi->fh);
1381 
1382 #ifdef __APPLE__
1383  if (fi->fh == kFileHandleIgnore) {
1384  fuse_reply_err(req, EBADF);
1385  return;
1386  }
1387 #endif
1388 
1389  // Get data chunk (<=128k guaranteed by Fuse)
1390  char *data = static_cast<char *>(alloca(size));
1391  unsigned int overall_bytes_fetched = 0;
1392 
1393  const int64_t fd = static_cast<int64_t>(fi->fh);
1394  uint64_t abs_fd = (fd < 0) ? -fd : fd;
1396 
1397  const struct fuse_ctx *fuse_ctx = fuse_req_ctx(req);
1398  FuseInterruptCue ic(&req);
1399  const ClientCtxGuard ctx_guard(fuse_ctx->uid, fuse_ctx->gid, fuse_ctx->pid,
1400  &ic);
1401 
1402  // Do we have a a chunked file?
1403  if (fd < 0) {
1404  const uint64_t chunk_handle = abs_fd;
1405  uint64_t unique_inode;
1406  ChunkFd chunk_fd;
1407  FileChunkReflist chunks;
1408  bool retval;
1409 
1410  // Fetch unique inode, chunk list and file descriptor
1411  ChunkTables *chunk_tables = mount_point_->chunk_tables();
1412  chunk_tables->Lock();
1413  retval = chunk_tables->handle2uniqino.Lookup(chunk_handle, &unique_inode);
1414  if (!retval) {
1415  LogCvmfs(kLogCvmfs, kLogDebug, "no unique inode, fall back to fuse ino");
1416  unique_inode = ino;
1417  }
1418  retval = chunk_tables->inode2chunks.Lookup(unique_inode, &chunks);
1419  assert(retval);
1420  chunk_tables->Unlock();
1421 
1422  unsigned chunk_idx = chunks.FindChunkIdx(off);
1423 
1424  // Lock chunk handle
1425  pthread_mutex_t *handle_lock = chunk_tables->Handle2Lock(chunk_handle);
1426  const MutexLockGuard m(handle_lock);
1427  chunk_tables->Lock();
1428  retval = chunk_tables->handle2fd.Lookup(chunk_handle, &chunk_fd);
1429  assert(retval);
1430  chunk_tables->Unlock();
1431 
1432  // Fetch all needed chunks and read the requested data
1433  off_t offset_in_chunk = off - chunks.list->AtPtr(chunk_idx)->offset();
1434  do {
1435  // Open file descriptor to chunk
1436  if ((chunk_fd.fd == -1) || (chunk_fd.chunk_idx != chunk_idx)) {
1437  if (chunk_fd.fd != -1)
1438  file_system_->cache_mgr()->Close(chunk_fd.fd);
1439  Fetcher *this_fetcher = chunks.external_data
1441  : mount_point_->fetcher();
1442  CacheManager::Label label;
1443  label.path = chunks.path.ToString();
1444  label.size = chunks.list->AtPtr(chunk_idx)->size();
1445  label.zip_algorithm = chunks.compression_alg;
1449  if (chunks.external_data) {
1451  label.range_offset = chunks.list->AtPtr(chunk_idx)->offset();
1452  }
1453  chunk_fd.fd = this_fetcher->Fetch(CacheManager::LabeledObject(
1454  chunks.list->AtPtr(chunk_idx)->content_hash(), label));
1455  if (chunk_fd.fd < 0) {
1456  chunk_fd.fd = -1;
1457  chunk_tables->Lock();
1458  chunk_tables->handle2fd.Insert(chunk_handle, chunk_fd);
1459  chunk_tables->Unlock();
1460 
1462  "EIO (05): Failed to fetch chunk %d from file %s", chunk_idx,
1463  chunks.path.ToString().c_str());
1466  fuse_reply_err(req, EIO);
1467  return;
1468  }
1469  chunk_fd.chunk_idx = chunk_idx;
1470  }
1471 
1472  LogCvmfs(kLogCvmfs, kLogDebug, "reading from chunk fd %d", chunk_fd.fd);
1473  // Read data from chunk
1474  const size_t bytes_to_read = size - overall_bytes_fetched;
1475  const size_t remaining_bytes_in_chunk = chunks.list->AtPtr(chunk_idx)
1476  ->size()
1477  - offset_in_chunk;
1478  const size_t bytes_to_read_in_chunk =
1479  std::min(bytes_to_read, remaining_bytes_in_chunk);
1480  const int64_t bytes_fetched = file_system_->cache_mgr()->Pread(
1481  chunk_fd.fd,
1482  data + overall_bytes_fetched,
1483  bytes_to_read_in_chunk,
1484  offset_in_chunk);
1485 
1486  if (bytes_fetched < 0) {
1487  LogCvmfs(kLogCvmfs, kLogSyslogErr, "read err no %" PRId64 " (%s)",
1488  bytes_fetched, chunks.path.ToString().c_str());
1489  chunk_tables->Lock();
1490  chunk_tables->handle2fd.Insert(chunk_handle, chunk_fd);
1491  chunk_tables->Unlock();
1492  if (EIO == errno || EIO == -bytes_fetched) {
1494  "EIO (07): Failed to read chunk %d from file %s", chunk_idx,
1495  chunks.path.ToString().c_str());
1498  }
1499  fuse_reply_err(req, -bytes_fetched);
1500  return;
1501  }
1502  overall_bytes_fetched += bytes_fetched;
1503 
1504  // Proceed to the next chunk to keep on reading data
1505  ++chunk_idx;
1506  offset_in_chunk = 0;
1507  } while ((overall_bytes_fetched < size)
1508  && (chunk_idx < chunks.list->size()));
1509 
1510  // Update chunk file descriptor
1511  chunk_tables->Lock();
1512  chunk_tables->handle2fd.Insert(chunk_handle, chunk_fd);
1513  chunk_tables->Unlock();
1514  LogCvmfs(kLogCvmfs, kLogDebug, "released chunk file descriptor %d",
1515  chunk_fd.fd);
1516  } else {
1517  const int64_t nbytes =
1518  file_system_->cache_mgr()->Pread(abs_fd, data, size, off);
1519  if (nbytes < 0) {
1520  if (EIO == errno || EIO == -nbytes) {
1521  PathString path;
1522  const bool found = GetPathForInode(ino, &path);
1523  if (found) {
1525  "EIO (08): Failed to read file %s", path.ToString().c_str());
1526  } else {
1528  "EIO (08): Failed to read from %s - <unknown inode>",
1529  path.ToString().c_str());
1530  }
1533  }
1534  fuse_reply_err(req, -nbytes);
1535  return;
1536  }
1537  overall_bytes_fetched = nbytes;
1538  }
1539 
1540  // Push it to user
1541  fuse_reply_buf(req, data, overall_bytes_fetched);
1542  LogCvmfs(kLogCvmfs, kLogDebug, "pushed %d bytes to user",
1543  overall_bytes_fetched);
1544 }
1545 
1546 
1550 static void cvmfs_release(fuse_req_t req, fuse_ino_t ino,
1551  struct fuse_file_info *fi) {
1552  const HighPrecisionTimer guard_timer(file_system_->hist_fs_release());
1553 
1554  ino = mount_point_->catalog_mgr()->MangleInode(ino);
1555  LogCvmfs(kLogCvmfs, kLogDebug, "cvmfs_release on inode: %" PRIu64,
1556  uint64_t(ino));
1557 
1558 #ifdef __APPLE__
1559  if (fi->fh == kFileHandleIgnore) {
1560  fuse_reply_err(req, 0);
1561  return;
1562  }
1563 #endif
1564 
1565  const int64_t fd = static_cast<int64_t>(fi->fh);
1566  uint64_t abs_fd = (fd < 0) ? -fd : fd;
1569  }
1571 
1572  // do we have a chunked file?
1573  if (fd < 0) {
1574  const uint64_t chunk_handle = abs_fd;
1575  LogCvmfs(kLogCvmfs, kLogDebug, "releasing chunk handle %" PRIu64,
1576  chunk_handle);
1577  uint64_t unique_inode;
1578  ChunkFd chunk_fd;
1579  const FileChunkReflist chunks;
1580  uint32_t refctr;
1581  bool retval;
1582 
1583  ChunkTables *chunk_tables = mount_point_->chunk_tables();
1584  chunk_tables->Lock();
1585  retval = chunk_tables->handle2uniqino.Lookup(chunk_handle, &unique_inode);
1586  if (!retval) {
1587  LogCvmfs(kLogCvmfs, kLogDebug, "no unique inode, fall back to fuse ino");
1588  unique_inode = ino;
1589  } else {
1590  chunk_tables->handle2uniqino.Erase(chunk_handle);
1591  }
1592  retval = chunk_tables->handle2fd.Lookup(chunk_handle, &chunk_fd);
1593  assert(retval);
1594  chunk_tables->handle2fd.Erase(chunk_handle);
1595 
1596  retval = chunk_tables->inode2references.Lookup(unique_inode, &refctr);
1597  assert(retval);
1598  refctr--;
1599  if (refctr == 0) {
1600  LogCvmfs(kLogCvmfs, kLogDebug, "releasing chunk list for inode %" PRIu64,
1601  uint64_t(unique_inode));
1602  FileChunkReflist to_delete;
1603  retval = chunk_tables->inode2chunks.Lookup(unique_inode, &to_delete);
1604  assert(retval);
1605  chunk_tables->inode2references.Erase(unique_inode);
1606  chunk_tables->inode2chunks.Erase(unique_inode);
1607  delete to_delete.list;
1608  } else {
1609  chunk_tables->inode2references.Insert(unique_inode, refctr);
1610  }
1611  chunk_tables->Unlock();
1612 
1613  if (chunk_fd.fd != -1)
1614  file_system_->cache_mgr()->Close(chunk_fd.fd);
1616  } else {
1617  if (file_system_->cache_mgr()->Close(abs_fd) == 0) {
1619  }
1620  }
1621  fuse_reply_err(req, 0);
1622 }
1623 
1631 static void cvmfs_statfs(fuse_req_t req, fuse_ino_t ino) {
1632  ino = mount_point_->catalog_mgr()->MangleInode(ino);
1633  LogCvmfs(kLogCvmfs, kLogDebug, "cvmfs_statfs on inode: %" PRIu64,
1634  uint64_t(ino));
1635 
1636  TraceInode(Tracer::kEventStatFs, ino, "statfs()");
1637 
1639 
1640  // Unmanaged cache (no lock needed - statfs is never modified)
1643  LogCvmfs(kLogCvmfs, kLogDebug, "QuotaManager does not support statfs");
1644  fuse_reply_statfs(req, (mount_point_->statfs_cache()->info()));
1645  return;
1646  }
1647 
1649 
1650  const uint64_t deadline = *mount_point_->statfs_cache()->expiry_deadline();
1651  struct statvfs *info = mount_point_->statfs_cache()->info();
1652 
1653  // cached version still valid
1654  if (platform_monotonic_time() < deadline) {
1656  fuse_reply_statfs(req, info);
1657  return;
1658  }
1659 
1660  uint64_t available = 0;
1661  const uint64_t size = file_system_->cache_mgr()->quota_mgr()->GetSize();
1662  const uint64_t capacity =
1664  // Fuse/OS X doesn't like values < 512
1665  info->f_bsize = info->f_frsize = 512;
1666 
1667  if (capacity == (uint64_t)(-1)) {
1668  // Unknown capacity, set capacity = size
1669  info->f_blocks = size / info->f_bsize;
1670  } else {
1671  // Take values from LRU module
1672  info->f_blocks = capacity / info->f_bsize;
1673  available = capacity - size;
1674  }
1675 
1676  info->f_bfree = info->f_bavail = available / info->f_bsize;
1677 
1678  // Inodes / entries
1679  fuse_remounter_->fence()->Enter();
1680  const uint64_t all_inodes = mount_point_->catalog_mgr()->all_inodes();
1681  const uint64_t loaded_inode = mount_point_->catalog_mgr()->loaded_inodes();
1682  info->f_files = all_inodes;
1683  info->f_ffree = info->f_favail = all_inodes - loaded_inode;
1684  fuse_remounter_->fence()->Leave();
1685 
1689 
1690  fuse_reply_statfs(req, info);
1691 }
1692 
1693 #ifdef __APPLE__
1694 static void cvmfs_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name,
1695  size_t size, uint32_t position)
1696 #else
1697 static void cvmfs_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name,
1698  size_t size)
1699 #endif
1700 {
1701  const struct fuse_ctx *fuse_ctx = fuse_req_ctx(req);
1702  FuseInterruptCue ic(&req);
1703  const ClientCtxGuard ctx_guard(fuse_ctx->uid, fuse_ctx->gid, fuse_ctx->pid,
1704  &ic);
1705 
1706  fuse_remounter_->fence()->Enter();
1708  ino = catalog_mgr->MangleInode(ino);
1710  "cvmfs_getxattr on inode: %" PRIu64 " for xattr: %s", uint64_t(ino),
1711  name);
1712  if (!CheckVoms(*fuse_ctx)) {
1713  fuse_remounter_->fence()->Leave();
1714  fuse_reply_err(req, EACCES);
1715  return;
1716  }
1717  TraceInode(Tracer::kEventGetXAttr, ino, "getxattr()");
1718 
1719  vector<string> tokens_mode_machine = SplitString(name, '~');
1720  vector<string> tokens_mode_human = SplitString(name, '@');
1721 
1722  int32_t attr_req_page = 0;
1723  MagicXattrMode xattr_mode = kXattrMachineMode;
1724  string attr;
1725 
1726  bool attr_req_is_valid = false;
1727  const sanitizer::PositiveIntegerSanitizer page_num_sanitizer;
1728 
1729  if (tokens_mode_human.size() > 1) {
1730  const std::string token = tokens_mode_human[tokens_mode_human.size() - 1];
1731  if (token == "?") {
1732  attr_req_is_valid = true;
1733  attr_req_page = -1;
1734  } else {
1735  if (page_num_sanitizer.IsValid(token)) {
1736  attr_req_is_valid = true;
1737  attr_req_page = static_cast<int32_t>(String2Uint64(token));
1738  }
1739  }
1740  xattr_mode = kXattrHumanMode;
1741  attr = tokens_mode_human[0];
1742  } else if (tokens_mode_machine.size() > 1) {
1743  const std::string
1744  token = tokens_mode_machine[tokens_mode_machine.size() - 1];
1745  if (token == "?") {
1746  attr_req_is_valid = true;
1747  attr_req_page = -1;
1748  } else {
1749  if (page_num_sanitizer.IsValid(token)) {
1750  attr_req_is_valid = true;
1751  attr_req_page = static_cast<int32_t>(String2Uint64(token));
1752  }
1753  }
1754  xattr_mode = kXattrMachineMode;
1755  attr = tokens_mode_machine[0];
1756 
1757  } else {
1758  attr_req_is_valid = true;
1759  attr = tokens_mode_machine[0];
1760  }
1761 
1762  if (!attr_req_is_valid) {
1763  fuse_remounter_->fence()->Leave();
1764  fuse_reply_err(req, ENODATA);
1765  return;
1766  }
1767 
1769  const bool found = GetDirentForInode(ino, &d);
1770 
1771  if (!found) {
1772  fuse_remounter_->fence()->Leave();
1773  ReplyNegative(d, req);
1774  return;
1775  }
1776 
1777  bool retval;
1778  XattrList xattrs;
1779  PathString path;
1780  retval = GetPathForInode(ino, &path);
1781 
1783  "cvmfs_statfs: Race condition? "
1784  "GetPathForInode did not succeed for path %s "
1785  "(path might have not been set)",
1786  path.c_str())) {
1787  fuse_remounter_->fence()->Leave();
1788  fuse_reply_err(req, ESTALE);
1789  return;
1790  }
1791 
1792  if (d.IsLink()) {
1793  const catalog::LookupOptions lookup_options =
1796  catalog::DirectoryEntry raw_symlink;
1797  retval = catalog_mgr->LookupPath(path, lookup_options, &raw_symlink);
1798 
1800  "cvmfs_statfs: Race condition? "
1801  "LookupPath did not succeed for path %s",
1802  path.c_str())) {
1803  fuse_remounter_->fence()->Leave();
1804  fuse_reply_err(req, ESTALE);
1805  return;
1806  }
1807 
1808  d.set_symlink(raw_symlink.symlink());
1809  }
1810  if (d.HasXattrs()) {
1811  retval = catalog_mgr->LookupXattrs(path, &xattrs);
1812 
1814  "cvmfs_statfs: Race condition? "
1815  "LookupXattrs did not succeed for path %s",
1816  path.c_str())) {
1817  fuse_remounter_->fence()->Leave();
1818  fuse_reply_err(req, ESTALE);
1819  return;
1820  }
1821  }
1822 
1823  bool magic_xattr_success = true;
1824  const MagicXattrRAIIWrapper magic_xattr(
1825  mount_point_->magic_xattr_mgr()->GetLocked(attr, path, &d));
1826  if (!magic_xattr.IsNull()) {
1827  magic_xattr_success = magic_xattr->PrepareValueFencedProtected(
1828  fuse_ctx->gid);
1829  }
1830 
1831  fuse_remounter_->fence()->Leave();
1832 
1833  if (!magic_xattr_success) {
1834  fuse_reply_err(req, ENOATTR);
1835  return;
1836  }
1837 
1838  std::pair<bool, std::string> attribute_result;
1839 
1840  if (!magic_xattr.IsNull()) {
1841  attribute_result = magic_xattr->GetValue(attr_req_page, xattr_mode);
1842  } else {
1843  if (!xattrs.Get(attr, &attribute_result.second)) {
1844  fuse_reply_err(req, ENOATTR);
1845  return;
1846  }
1847  attribute_result.first = true;
1848  }
1849 
1850  if (!attribute_result.first) {
1851  fuse_reply_err(req, ENODATA);
1852  } else if (size == 0) {
1853  fuse_reply_xattr(req, attribute_result.second.length());
1854  } else if (size >= attribute_result.second.length()) {
1855  fuse_reply_buf(req, &attribute_result.second[0],
1856  attribute_result.second.length());
1857  } else {
1858  fuse_reply_err(req, ERANGE);
1859  }
1860 }
1861 
1862 
1863 static void cvmfs_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) {
1864  const struct fuse_ctx *fuse_ctx = fuse_req_ctx(req);
1865  FuseInterruptCue ic(&req);
1866  const ClientCtxGuard ctx_guard(fuse_ctx->uid, fuse_ctx->gid, fuse_ctx->pid,
1867  &ic);
1868 
1869  fuse_remounter_->fence()->Enter();
1871  ino = catalog_mgr->MangleInode(ino);
1872  TraceInode(Tracer::kEventListAttr, ino, "listxattr()");
1874  "cvmfs_listxattr on inode: %" PRIu64 ", size %zu [visibility %d]",
1875  uint64_t(ino), size, mount_point_->magic_xattr_mgr()->visibility());
1876 
1878  const bool found = GetDirentForInode(ino, &d);
1879  XattrList xattrs;
1880  if (d.HasXattrs()) {
1881  PathString path;
1882  bool retval = GetPathForInode(ino, &path);
1883 
1885  "cvmfs_listxattr: Race condition? "
1886  "GetPathForInode did not succeed for ino %lu",
1887  ino)) {
1888  fuse_remounter_->fence()->Leave();
1889  fuse_reply_err(req, ESTALE);
1890  return;
1891  }
1892 
1893  retval = catalog_mgr->LookupXattrs(path, &xattrs);
1895  "cvmfs_listxattr: Race condition? "
1896  "LookupXattrs did not succeed for ino %lu",
1897  ino)) {
1898  fuse_remounter_->fence()->Leave();
1899  fuse_reply_err(req, ESTALE);
1900  return;
1901  }
1902  }
1903  fuse_remounter_->fence()->Leave();
1904 
1905  if (!found) {
1906  ReplyNegative(d, req);
1907  return;
1908  }
1909 
1910  string attribute_list;
1911  attribute_list = mount_point_->magic_xattr_mgr()->GetListString(&d);
1912  attribute_list += xattrs.ListKeysPosix(attribute_list);
1913 
1914  if (size == 0) {
1915  fuse_reply_xattr(req, attribute_list.length());
1916  } else if (size >= attribute_list.length()) {
1917  if (attribute_list.empty())
1918  fuse_reply_buf(req, NULL, 0);
1919  else
1920  fuse_reply_buf(req, &attribute_list[0], attribute_list.length());
1921  } else {
1922  fuse_reply_err(req, ERANGE);
1923  }
1924 }
1925 
1926 bool Evict(const string &path) {
1927  catalog::DirectoryEntry dirent;
1928  fuse_remounter_->fence()->Enter();
1929  const bool found = (GetDirentForPath(PathString(path), &dirent) > 0);
1930 
1931  if (!found || !dirent.IsRegular()) {
1932  fuse_remounter_->fence()->Leave();
1933  return false;
1934  }
1935 
1936  if (!dirent.IsChunkedFile()) {
1937  fuse_remounter_->fence()->Leave();
1938  } else {
1939  FileChunkList chunks;
1941  PathString(path), dirent.hash_algorithm(), &chunks);
1942  fuse_remounter_->fence()->Leave();
1943  for (unsigned i = 0; i < chunks.size(); ++i) {
1945  chunks.AtPtr(i)->content_hash());
1946  }
1947  }
1948  file_system_->cache_mgr()->quota_mgr()->Remove(dirent.checksum());
1949  return true;
1950 }
1951 
1952 
1953 bool Pin(const string &path) {
1954  catalog::DirectoryEntry dirent;
1955  fuse_remounter_->fence()->Enter();
1956  const bool found = (GetDirentForPath(PathString(path), &dirent) > 0);
1957  if (!found || !dirent.IsRegular()) {
1958  fuse_remounter_->fence()->Leave();
1959  return false;
1960  }
1961 
1962  Fetcher *this_fetcher = dirent.IsExternalFile()
1964  : mount_point_->fetcher();
1965 
1966  if (!dirent.IsChunkedFile()) {
1967  fuse_remounter_->fence()->Leave();
1968  } else {
1969  FileChunkList chunks;
1971  PathString(path), dirent.hash_algorithm(), &chunks);
1972  fuse_remounter_->fence()->Leave();
1973  for (unsigned i = 0; i < chunks.size(); ++i) {
1974  const bool retval = file_system_->cache_mgr()->quota_mgr()->Pin(
1975  chunks.AtPtr(i)->content_hash(), chunks.AtPtr(i)->size(),
1976  "Part of " + path, false);
1977  if (!retval)
1978  return false;
1979  int fd = -1;
1980  CacheManager::Label label;
1981  label.path = path;
1982  label.size = chunks.AtPtr(i)->size();
1983  label.zip_algorithm = dirent.compression_algorithm();
1986  if (dirent.IsExternalFile()) {
1988  label.range_offset = chunks.AtPtr(i)->offset();
1989  }
1990  fd = this_fetcher->Fetch(
1991  CacheManager::LabeledObject(chunks.AtPtr(i)->content_hash(), label));
1992  if (fd < 0) {
1993  return false;
1994  }
1995  file_system_->cache_mgr()->Close(fd);
1996  }
1997  return true;
1998  }
1999 
2000  const bool retval = file_system_->cache_mgr()->quota_mgr()->Pin(
2001  dirent.checksum(), dirent.size(), path, false);
2002  if (!retval)
2003  return false;
2004  CacheManager::Label label;
2006  label.size = dirent.size();
2007  label.path = path;
2008  label.zip_algorithm = dirent.compression_algorithm();
2009  const int fd = this_fetcher->Fetch(
2010  CacheManager::LabeledObject(dirent.checksum(), label));
2011  if (fd < 0) {
2012  return false;
2013  }
2014  file_system_->cache_mgr()->Close(fd);
2015  return true;
2016 }
2017 
2018 
2022 static void cvmfs_init(void *userdata, struct fuse_conn_info *conn) {
2023  LogCvmfs(kLogCvmfs, kLogDebug, "cvmfs_init");
2024 
2025  // NFS support
2026 #ifdef CVMFS_NFS_SUPPORT
2027  conn->want |= FUSE_CAP_EXPORT_SUPPORT;
2028 #endif
2029 
2030  if (mount_point_->enforce_acls()) {
2031 #ifdef FUSE_CAP_POSIX_ACL
2032  if ((conn->capable & FUSE_CAP_POSIX_ACL) == 0) {
2034  "FUSE: ACL support requested but missing fuse kernel support, "
2035  "aborting");
2036  }
2037  conn->want |= FUSE_CAP_POSIX_ACL;
2038  LogCvmfs(kLogCvmfs, kLogDebug | kLogSyslog, "enforcing ACLs");
2039 #else
2041  "FUSE: ACL support requested but not available in this version of "
2042  "libfuse %d, aborting",
2043  FUSE_VERSION);
2044 #endif
2045  }
2046 
2047  if (mount_point_->cache_symlinks()) {
2048 #ifdef FUSE_CAP_CACHE_SYMLINKS
2049  if ((conn->capable & FUSE_CAP_CACHE_SYMLINKS) == FUSE_CAP_CACHE_SYMLINKS) {
2050  conn->want |= FUSE_CAP_CACHE_SYMLINKS;
2051  LogCvmfs(kLogCvmfs, kLogDebug, "FUSE: Enable symlink caching");
2052 #ifndef FUSE_CAP_EXPIRE_ONLY
2053  LogCvmfs(
2055  "FUSE: Symlink caching enabled but no support for fuse_expire_entry. "
2056  "Symlinks will be cached but mountpoints on top of symlinks will "
2057  "break! "
2058  "Current libfuse %d is too old; required: libfuse >= 3.16, "
2059  "kernel >= 6.2-rc1",
2060  FUSE_VERSION);
2061 #endif
2062  } else {
2064  LogCvmfs(
2066  "FUSE: Symlink caching requested but missing fuse kernel support, "
2067  "falling back to no caching");
2068  }
2069 #else
2072  "FUSE: Symlink caching requested but missing libfuse support, "
2073  "falling back to no caching. Current libfuse %d",
2074  FUSE_VERSION);
2075 #endif
2076  }
2077 
2078 #ifdef FUSE_CAP_EXPIRE_ONLY
2079  if ((conn->capable & FUSE_CAP_EXPIRE_ONLY) == FUSE_CAP_EXPIRE_ONLY
2080  && FUSE_VERSION >= FUSE_MAKE_VERSION(3, 16)) {
2082  LogCvmfs(kLogCvmfs, kLogDebug, "FUSE: Enable fuse_expire_entry ");
2083  } else if (mount_point_->cache_symlinks()) {
2084  LogCvmfs(
2086  "FUSE: Symlink caching enabled but no support for fuse_expire_entry. "
2087  "Symlinks will be cached but mountpoints on top of symlinks will "
2088  "break! "
2089  "Current libfuse %d; required: libfuse >= 3.16, kernel >= 6.2-rc1",
2090  FUSE_VERSION);
2091  }
2092 #endif
2093 }
2094 
2095 static void cvmfs_destroy(void *unused __attribute__((unused))) {
2096  // The debug log is already closed at this point
2097  LogCvmfs(kLogCvmfs, kLogDebug, "cvmfs_destroy");
2098 }
2099 
2103 static void SetCvmfsOperations(struct fuse_lowlevel_ops *cvmfs_operations) {
2104  memset(cvmfs_operations, 0, sizeof(*cvmfs_operations));
2105 
2106  // Init/Fini
2107  cvmfs_operations->init = cvmfs_init;
2108  cvmfs_operations->destroy = cvmfs_destroy;
2109 
2110  cvmfs_operations->lookup = cvmfs_lookup;
2111  cvmfs_operations->getattr = cvmfs_getattr;
2112  cvmfs_operations->readlink = cvmfs_readlink;
2113  cvmfs_operations->open = cvmfs_open;
2114  cvmfs_operations->read = cvmfs_read;
2115  cvmfs_operations->release = cvmfs_release;
2116  cvmfs_operations->opendir = cvmfs_opendir;
2117  cvmfs_operations->readdir = cvmfs_readdir;
2118  cvmfs_operations->releasedir = cvmfs_releasedir;
2119  cvmfs_operations->statfs = cvmfs_statfs;
2120  cvmfs_operations->getxattr = cvmfs_getxattr;
2121  cvmfs_operations->listxattr = cvmfs_listxattr;
2122  cvmfs_operations->forget = cvmfs_forget;
2123 #if (FUSE_VERSION >= 29)
2124  cvmfs_operations->forget_multi = cvmfs_forget_multi;
2125 #endif
2126 }
2127 
2128 // Called by cvmfs_talk when switching into read-only cache mode
2130  if (cvmfs::unpin_listener_) {
2132  cvmfs::unpin_listener_ = NULL;
2133  }
2137  }
2138 }
2139 
2140 bool SendFuseFd(const std::string &socket_path) {
2141  int fuse_fd;
2142 #if (FUSE_VERSION >= 30)
2143  fuse_fd = fuse_session_fd(*reinterpret_cast<struct fuse_session **>(
2145 #else
2146  fuse_fd = fuse_chan_fd(*reinterpret_cast<struct fuse_chan **>(
2148 #endif
2149  assert(fuse_fd >= 0);
2150  const int sock_fd = ConnectSocket(socket_path);
2151  if (sock_fd < 0) {
2152  LogCvmfs(kLogCvmfs, kLogDebug, "cannot connect to socket %s: %d",
2153  socket_path.c_str(), errno);
2154  return false;
2155  }
2156  const bool retval = SendFd2Socket(sock_fd, fuse_fd);
2157  close(sock_fd);
2158  return retval;
2159 }
2160 
2161 } // namespace cvmfs
2162 
2163 
2164 string *g_boot_error = NULL;
2165 
2166 __attribute__((
2167  visibility("default"))) loader::CvmfsExports *g_cvmfs_exports = NULL;
2168 
2175 
2176  virtual bool PrepareValueFenced() {
2177  catalogs_valid_until_ = cvmfs::fuse_remounter_->catalogs_valid_until();
2178  return true;
2179  }
2180 
2181  virtual void FinalizeValue() {
2182  if (catalogs_valid_until_ == MountPoint::kIndefiniteDeadline) {
2183  result_pages_.push_back("never (fixed root catalog)");
2184  return;
2185  } else {
2186  const time_t now = time(NULL);
2187  result_pages_.push_back(StringifyInt((catalogs_valid_until_ - now) / 60));
2188  }
2189  }
2190 };
2191 
2193  virtual void FinalizeValue() {
2194  result_pages_.push_back(StringifyInt(
2195  cvmfs::inode_generation_info_.inode_generation
2196  + xattr_mgr_->mount_point()->catalog_mgr()->inode_gauge()));
2197  }
2198 };
2199 
2201  virtual void FinalizeValue() {
2202  result_pages_.push_back(
2204  }
2205 };
2206 
2208  virtual void FinalizeValue() {
2209  result_pages_.push_back(StringifyInt(cvmfs::pid_));
2210  }
2211 };
2212 
2214  virtual void FinalizeValue() {
2215  const time_t now = time(NULL);
2216  const uint64_t uptime = now - cvmfs::loader_exports_->boot_time;
2217  result_pages_.push_back(StringifyUint(uptime / 60));
2218  }
2219 };
2220 
2225 static void RegisterMagicXattrs() {
2227  mgr->Register("user.expires", new ExpiresMagicXattr());
2228  mgr->Register("user.inode_max", new InodeMaxMagicXattr());
2229  mgr->Register("user.pid", new PidMagicXattr());
2230  mgr->Register("user.maxfd", new MaxFdMagicXattr());
2231  mgr->Register("user.uptime", new UptimeMagicXattr());
2232 
2233  mgr->Freeze();
2234 }
2235 
2240 static FileSystem *InitSystemFs(const string &mount_path,
2241  const string &fqrn,
2242  FileSystem::FileSystemInfo fs_info) {
2243  fs_info.wait_workspace = false;
2244  FileSystem *file_system = FileSystem::Create(fs_info);
2245 
2246  if (file_system->boot_status() == loader::kFailLockWorkspace) {
2247  string fqrn_from_xattr;
2248  const int retval =
2249  platform_getxattr(mount_path, "user.fqrn", &fqrn_from_xattr);
2250  if (!retval) {
2251  // Cvmfs not mounted anymore, but another cvmfs process is still in
2252  // shutdown procedure. Try again and wait for lock
2253  delete file_system;
2254  fs_info.wait_workspace = true;
2255  file_system = FileSystem::Create(fs_info);
2256  } else {
2257  if (fqrn_from_xattr == fqrn) {
2259  "repository already mounted on %s", mount_path.c_str());
2261  } else {
2263  "CernVM-FS repository %s already mounted on %s", fqrn.c_str(),
2264  mount_path.c_str());
2266  }
2267  }
2268  }
2269 
2270  return file_system;
2271 }
2272 
2273 
2274 static void InitOptionsMgr(const loader::LoaderExports *loader_exports) {
2275  if (loader_exports->version >= 3 && loader_exports->simple_options_parsing) {
2277  new DefaultOptionsTemplateManager(loader_exports->repository_name));
2278  } else {
2280  new DefaultOptionsTemplateManager(loader_exports->repository_name));
2281  }
2282 
2283  if (loader_exports->config_files != "") {
2284  vector<string> tokens = SplitString(loader_exports->config_files, ':');
2285  for (unsigned i = 0, s = tokens.size(); i < s; ++i) {
2286  cvmfs::options_mgr_->ParsePath(tokens[i], false);
2287  }
2288  } else {
2290  }
2291 }
2292 
2293 
2294 static unsigned CheckMaxOpenFiles() {
2295  static unsigned max_open_files;
2296  static bool already_done = false;
2297 
2298  // check number of open files (lazy evaluation)
2299  if (!already_done) {
2300  unsigned soft_limit = 0;
2301  unsigned hard_limit = 0;
2302  GetLimitNoFile(&soft_limit, &hard_limit);
2303 
2304  if (soft_limit < cvmfs::kMinOpenFiles) {
2306  "Warning: current limits for number of open files are "
2307  "(%u/%u)\n"
2308  "CernVM-FS is likely to run out of file descriptors, "
2309  "set ulimit -n to at least %u",
2310  soft_limit, hard_limit, cvmfs::kMinOpenFiles);
2311  }
2312  max_open_files = soft_limit;
2313  already_done = true;
2314  }
2315 
2316  return max_open_files;
2317 }
2318 
2319 
2320 static int Init(const loader::LoaderExports *loader_exports) {
2321  g_boot_error = new string("unknown error");
2322  cvmfs::loader_exports_ = loader_exports;
2323 
2325 
2326  InitOptionsMgr(loader_exports);
2327 
2328  // We need logging set up before forking the watchdog
2330  loader_exports->repository_name);
2331 
2332  // Monitor, check for maximum number of open files
2333  if (cvmfs::UseWatchdog()) {
2334  auto_umount::SetMountpoint(loader_exports->mount_point);
2336  if (cvmfs::watchdog_ == NULL) {
2337  *g_boot_error = "failed to initialize watchdog.";
2338  return loader::kFailMonitor;
2339  }
2340  }
2342 
2344  fs_info.type = FileSystem::kFsFuse;
2345  fs_info.name = loader_exports->repository_name;
2346  fs_info.exe_path = loader_exports->program_name;
2347  fs_info.options_mgr = cvmfs::options_mgr_;
2348  fs_info.foreground = loader_exports->foreground;
2350  loader_exports->mount_point, loader_exports->repository_name, fs_info);
2351  if (!cvmfs::file_system_->IsValid()) {
2353  return cvmfs::file_system_->boot_status();
2354  }
2355  if ((cvmfs::file_system_->cache_mgr()->id() == kPosixCacheManager)
2356  && dynamic_cast<PosixCacheManager *>(cvmfs::file_system_->cache_mgr())
2357  ->do_refcount()) {
2358  cvmfs::check_fd_overflow_ = false;
2359  }
2360 
2363  if (!cvmfs::mount_point_->IsValid()) {
2365  return cvmfs::mount_point_->boot_status();
2366  }
2367 
2369 
2371  cvmfs::directory_handles_->set_empty_key((uint64_t)(-1));
2372  cvmfs::directory_handles_->set_deleted_key((uint64_t)(-2));
2373 
2374  LogCvmfs(kLogCvmfs, kLogDebug, "fuse inode size is %lu bits",
2375  sizeof(fuse_ino_t) * 8);
2376 
2380  ->inode_annotation()
2381  ->GetGeneration();
2382  LogCvmfs(kLogCvmfs, kLogDebug, "root inode is %" PRIu64,
2383  uint64_t(cvmfs::mount_point_->catalog_mgr()->GetRootInode()));
2384 
2385  void **channel_or_session = NULL;
2386  if (loader_exports->version >= 4) {
2387  channel_or_session = loader_exports->fuse_channel_or_session;
2388  }
2389 
2390  bool fuse_notify_invalidation = true;
2391  std::string buf;
2392  if (cvmfs::options_mgr_->GetValue("CVMFS_FUSE_NOTIFY_INVALIDATION", &buf)) {
2393  if (!cvmfs::options_mgr_->IsOn(buf)) {
2394  fuse_notify_invalidation = false;
2396  }
2397  }
2399  cvmfs::mount_point_, &cvmfs::inode_generation_info_, channel_or_session,
2400  fuse_notify_invalidation);
2401 
2402  // Control & command interface
2404  cvmfs::mount_point_->talk_socket_path(),
2407  if ((cvmfs::mount_point_->talk_socket_uid() != 0)
2408  || (cvmfs::mount_point_->talk_socket_gid() != 0)) {
2409  const uid_t tgt_uid = cvmfs::mount_point_->talk_socket_uid();
2410  const gid_t tgt_gid = cvmfs::mount_point_->talk_socket_gid();
2411  const int rvi = chown(cvmfs::mount_point_->talk_socket_path().c_str(),
2412  tgt_uid, tgt_gid);
2413  if (rvi != 0) {
2414  *g_boot_error = std::string("failed to set talk socket ownership - ")
2415  + "target " + StringifyInt(tgt_uid) + ":"
2416  + StringifyInt(tgt_uid) + ", user "
2417  + StringifyInt(geteuid()) + ":" + StringifyInt(getegid());
2418  return loader::kFailTalk;
2419  }
2420  }
2421  if (cvmfs::talk_mgr_ == NULL) {
2422  *g_boot_error = "failed to initialize talk socket (" + StringifyInt(errno)
2423  + ")";
2424  return loader::kFailTalk;
2425  }
2426 
2427  // Notification system client
2428  {
2430  if (options->IsDefined("CVMFS_NOTIFICATION_SERVER")) {
2431  std::string config;
2432  options->GetValue("CVMFS_NOTIFICATION_SERVER", &config);
2433  const std::string repo_name = cvmfs::mount_point_->fqrn();
2435  config, repo_name, cvmfs::fuse_remounter_,
2436  cvmfs::mount_point_->download_mgr(),
2438  }
2439  }
2440 
2441  return loader::kFailOk;
2442 }
2443 
2444 
2448 static void Spawn() {
2449  // First thing: kick off the watchdog while we still have a single-threaded
2450  // well-defined state
2451  cvmfs::pid_ = getpid();
2452  if (cvmfs::watchdog_) {
2454  + cvmfs::mount_point_->fqrn());
2455  }
2456 
2458  if (cvmfs::mount_point_->dentry_tracker()->is_active()) {
2460  // Usually every minute
2461  static_cast<unsigned int>(cvmfs::mount_point_->kcache_timeout_sec()));
2462  }
2463 
2466  if (cvmfs::mount_point_->resolv_conf_watcher() != NULL) {
2468  }
2470  quota_mgr->Spawn();
2471  if (quota_mgr->HasCapability(QuotaManager::kCapListeners)) {
2473  quota_mgr, cvmfs::mount_point_->uuid()->uuid() + "-watchdog");
2475  quota_mgr,
2476  cvmfs::mount_point_->catalog_mgr(),
2477  cvmfs::mount_point_->uuid()->uuid() + "-unpin");
2478  }
2481 
2482  if (cvmfs::notification_client_ != NULL) {
2484  }
2485 
2486  if (cvmfs::file_system_->nfs_maps() != NULL) {
2488  }
2489 
2491 
2492  if (cvmfs::mount_point_->telemetry_aggr() != NULL) {
2494  }
2495 }
2496 
2497 
2498 static string GetErrorMsg() {
2499  if (g_boot_error)
2500  return *g_boot_error;
2501  return "";
2502 }
2503 
2504 
2510 static void ShutdownMountpoint() {
2511  delete cvmfs::talk_mgr_;
2512  cvmfs::talk_mgr_ = NULL;
2513 
2516 
2517  // The remonter has a reference to the mount point and the inode generation
2518  delete cvmfs::fuse_remounter_;
2519  cvmfs::fuse_remounter_ = NULL;
2520 
2521  // The unpin listener requires the catalog, so this must be unregistered
2522  // before the catalog manager is removed
2523  if (cvmfs::unpin_listener_ != NULL) {
2525  cvmfs::unpin_listener_ = NULL;
2526  }
2527  if (cvmfs::watchdog_listener_ != NULL) {
2530  }
2531 
2533  delete cvmfs::mount_point_;
2535  cvmfs::mount_point_ = NULL;
2536 }
2537 
2538 
2539 static void Fini() {
2541 
2542  delete cvmfs::file_system_;
2543  delete cvmfs::options_mgr_;
2544  cvmfs::file_system_ = NULL;
2545  cvmfs::options_mgr_ = NULL;
2546 
2547  delete cvmfs::watchdog_;
2548  cvmfs::watchdog_ = NULL;
2549 
2550  delete g_boot_error;
2551  g_boot_error = NULL;
2553 
2555 }
2556 
2557 
2558 static int AltProcessFlavor(int argc, char **argv) {
2559  if (strcmp(argv[1], "__cachemgr__") == 0) {
2560  return PosixQuotaManager::MainCacheManager(argc, argv);
2561  }
2562  if (strcmp(argv[1], "__wpad__") == 0) {
2563  return download::MainResolveProxyDescription(argc, argv);
2564  }
2565  return 1;
2566 }
2567 
2568 
2569 static bool MaintenanceMode(const int fd_progress) {
2570  SendMsg2Socket(fd_progress, "Entering maintenance mode\n");
2571  string msg_progress = "Draining out kernel caches (";
2573  msg_progress += "up to ";
2574  msg_progress += StringifyInt(static_cast<int>(
2575  cvmfs::mount_point_->kcache_timeout_sec()))
2576  + "s)\n";
2577  SendMsg2Socket(fd_progress, msg_progress);
2579  return true;
2580 }
2581 
2582 
2583 static bool SaveState(const int fd_progress, loader::StateList *saved_states) {
2584  string msg_progress;
2585 
2586  const unsigned num_open_dirs = cvmfs::directory_handles_->size();
2587  if (num_open_dirs != 0) {
2588 #ifdef DEBUGMSG
2589  for (cvmfs::DirectoryHandles::iterator
2590  i = cvmfs::directory_handles_->begin(),
2591  iEnd = cvmfs::directory_handles_->end();
2592  i != iEnd;
2593  ++i) {
2594  LogCvmfs(kLogCvmfs, kLogDebug, "saving dirhandle %lu", i->first);
2595  }
2596 #endif
2597 
2598  msg_progress = "Saving open directory handles ("
2599  + StringifyInt(num_open_dirs) + " handles)\n";
2600  SendMsg2Socket(fd_progress, msg_progress);
2601 
2602  // TODO(jblomer): should rather be saved just in a malloc'd memory block
2603  cvmfs::DirectoryHandles *saved_handles = new cvmfs::DirectoryHandles(
2605  loader::SavedState *save_open_dirs = new loader::SavedState();
2606  save_open_dirs->state_id = loader::kStateOpenDirs;
2607  save_open_dirs->state = saved_handles;
2608  saved_states->push_back(save_open_dirs);
2609  }
2610 
2611  if (!cvmfs::file_system_->IsNfsSource()) {
2612  msg_progress = "Saving inode tracker\n";
2613  SendMsg2Socket(fd_progress, msg_progress);
2614  glue::InodeTracker *saved_inode_tracker = new glue::InodeTracker(
2615  *cvmfs::mount_point_->inode_tracker());
2616  loader::SavedState *state_glue_buffer = new loader::SavedState();
2617  state_glue_buffer->state_id = loader::kStateGlueBufferV4;
2618  state_glue_buffer->state = saved_inode_tracker;
2619  saved_states->push_back(state_glue_buffer);
2620  }
2621 
2622  msg_progress = "Saving negative entry cache\n";
2623  SendMsg2Socket(fd_progress, msg_progress);
2624  glue::DentryTracker *saved_dentry_tracker = new glue::DentryTracker(
2625  *cvmfs::mount_point_->dentry_tracker());
2626  loader::SavedState *state_dentry_tracker = new loader::SavedState();
2627  state_dentry_tracker->state_id = loader::kStateDentryTracker;
2628  state_dentry_tracker->state = saved_dentry_tracker;
2629  saved_states->push_back(state_dentry_tracker);
2630 
2631  msg_progress = "Saving page cache entry tracker\n";
2632  SendMsg2Socket(fd_progress, msg_progress);
2633  glue::PageCacheTracker *saved_page_cache_tracker = new glue::PageCacheTracker(
2634  *cvmfs::mount_point_->page_cache_tracker());
2635  loader::SavedState *state_page_cache_tracker = new loader::SavedState();
2636  state_page_cache_tracker->state_id = loader::kStatePageCacheTracker;
2637  state_page_cache_tracker->state = saved_page_cache_tracker;
2638  saved_states->push_back(state_page_cache_tracker);
2639 
2640  msg_progress = "Saving chunk tables\n";
2641  SendMsg2Socket(fd_progress, msg_progress);
2642  ChunkTables *saved_chunk_tables = new ChunkTables(
2643  *cvmfs::mount_point_->chunk_tables());
2644  loader::SavedState *state_chunk_tables = new loader::SavedState();
2645  state_chunk_tables->state_id = loader::kStateOpenChunksV4;
2646  state_chunk_tables->state = saved_chunk_tables;
2647  saved_states->push_back(state_chunk_tables);
2648 
2649  msg_progress = "Saving inode generation\n";
2650  SendMsg2Socket(fd_progress, msg_progress);
2654  *saved_inode_generation = new cvmfs::InodeGenerationInfo(
2656  loader::SavedState *state_inode_generation = new loader::SavedState();
2657  state_inode_generation->state_id = loader::kStateInodeGeneration;
2658  state_inode_generation->state = saved_inode_generation;
2659  saved_states->push_back(state_inode_generation);
2660 
2661  msg_progress = "Saving fuse state\n";
2662  SendMsg2Socket(fd_progress, msg_progress);
2663  cvmfs::FuseState *saved_fuse_state = new cvmfs::FuseState();
2664  saved_fuse_state->cache_symlinks = cvmfs::mount_point_->cache_symlinks();
2665  saved_fuse_state->has_dentry_expire = cvmfs::mount_point_
2666  ->fuse_expire_entry();
2667  loader::SavedState *state_fuse = new loader::SavedState();
2668  state_fuse->state_id = loader::kStateFuse;
2669  state_fuse->state = saved_fuse_state;
2670  saved_states->push_back(state_fuse);
2671 
2672  // Close open file catalogs
2674 
2675  loader::SavedState *state_cache_mgr = new loader::SavedState();
2676  state_cache_mgr->state_id = loader::kStateOpenFiles;
2677  state_cache_mgr->state = cvmfs::file_system_->cache_mgr()->SaveState(
2678  fd_progress);
2679  saved_states->push_back(state_cache_mgr);
2680 
2681  msg_progress = "Saving open files counter\n";
2682  uint32_t *saved_num_fd = new uint32_t(
2683  cvmfs::file_system_->no_open_files()->Get());
2684  loader::SavedState *state_num_fd = new loader::SavedState();
2685  state_num_fd->state_id = loader::kStateOpenFilesCounter;
2686  state_num_fd->state = saved_num_fd;
2687  saved_states->push_back(state_num_fd);
2688 
2689  return true;
2690 }
2691 
2692 
2693 static bool RestoreState(const int fd_progress,
2694  const loader::StateList &saved_states) {
2695  // If we have no saved version of the page cache tracker, it is unsafe
2696  // to start using it. The page cache tracker has to run for the entire
2697  // lifetime of the mountpoint or not at all.
2699 
2700  for (unsigned i = 0, l = saved_states.size(); i < l; ++i) {
2701  if (saved_states[i]->state_id == loader::kStateOpenDirs) {
2702  SendMsg2Socket(fd_progress, "Restoring open directory handles... ");
2705  *saved_handles = (cvmfs::DirectoryHandles *)saved_states[i]->state;
2706  cvmfs::directory_handles_ = new cvmfs::DirectoryHandles(*saved_handles);
2709  cvmfs::DirectoryHandles::const_iterator i = cvmfs::directory_handles_
2710  ->begin();
2711  for (; i != cvmfs::directory_handles_->end(); ++i) {
2712  if (i->first >= cvmfs::next_directory_handle_)
2713  cvmfs::next_directory_handle_ = i->first + 1;
2714  }
2715 
2717  fd_progress,
2718  StringifyInt(cvmfs::directory_handles_->size()) + " handles\n");
2719  }
2720 
2721  if (saved_states[i]->state_id == loader::kStateGlueBuffer) {
2722  SendMsg2Socket(fd_progress, "Migrating inode tracker (v1 to v4)... ");
2724  *saved_inode_tracker = (compat::inode_tracker::InodeTracker *)
2725  saved_states[i]
2726  ->state;
2727  compat::inode_tracker::Migrate(saved_inode_tracker,
2728  cvmfs::mount_point_->inode_tracker());
2729  SendMsg2Socket(fd_progress, " done\n");
2730  }
2731 
2732  if (saved_states[i]->state_id == loader::kStateGlueBufferV2) {
2733  SendMsg2Socket(fd_progress, "Migrating inode tracker (v2 to v4)... ");
2735  *saved_inode_tracker = (compat::inode_tracker_v2::InodeTracker *)
2736  saved_states[i]
2737  ->state;
2738  compat::inode_tracker_v2::Migrate(saved_inode_tracker,
2739  cvmfs::mount_point_->inode_tracker());
2740  SendMsg2Socket(fd_progress, " done\n");
2741  }
2742 
2743  if (saved_states[i]->state_id == loader::kStateGlueBufferV3) {
2744  SendMsg2Socket(fd_progress, "Migrating inode tracker (v3 to v4)... ");
2746  *saved_inode_tracker = (compat::inode_tracker_v3::InodeTracker *)
2747  saved_states[i]
2748  ->state;
2749  compat::inode_tracker_v3::Migrate(saved_inode_tracker,
2750  cvmfs::mount_point_->inode_tracker());
2751  SendMsg2Socket(fd_progress, " done\n");
2752  }
2753 
2754  if (saved_states[i]->state_id == loader::kStateGlueBufferV4) {
2755  SendMsg2Socket(fd_progress, "Restoring inode tracker... ");
2758  *saved_inode_tracker = (glue::InodeTracker *)saved_states[i]->state;
2760  glue::InodeTracker(*saved_inode_tracker);
2761  SendMsg2Socket(fd_progress, " done\n");
2762  }
2763 
2764  if (saved_states[i]->state_id == loader::kStateDentryTracker) {
2765  SendMsg2Socket(fd_progress, "Restoring dentry tracker... ");
2768  *saved_dentry_tracker = static_cast<glue::DentryTracker *>(
2769  saved_states[i]->state);
2771  glue::DentryTracker(*saved_dentry_tracker);
2772  SendMsg2Socket(fd_progress, " done\n");
2773  }
2774 
2775  if (saved_states[i]->state_id == loader::kStatePageCacheTracker) {
2776  SendMsg2Socket(fd_progress, "Restoring page cache entry tracker... ");
2779  *saved_page_cache_tracker = (glue::PageCacheTracker *)saved_states[i]
2780  ->state;
2782  glue::PageCacheTracker(*saved_page_cache_tracker);
2783  SendMsg2Socket(fd_progress, " done\n");
2784  }
2785 
2786  ChunkTables *chunk_tables = cvmfs::mount_point_->chunk_tables();
2787 
2788  if (saved_states[i]->state_id == loader::kStateOpenChunks) {
2789  SendMsg2Socket(fd_progress, "Migrating chunk tables (v1 to v4)... ");
2791  *saved_chunk_tables = (compat::chunk_tables::ChunkTables *)
2792  saved_states[i]
2793  ->state;
2794  compat::chunk_tables::Migrate(saved_chunk_tables, chunk_tables);
2796  fd_progress,
2797  StringifyInt(chunk_tables->handle2fd.size()) + " handles\n");
2798  }
2799 
2800  if (saved_states[i]->state_id == loader::kStateOpenChunksV2) {
2801  SendMsg2Socket(fd_progress, "Migrating chunk tables (v2 to v4)... ");
2803  *saved_chunk_tables = (compat::chunk_tables_v2::ChunkTables *)
2804  saved_states[i]
2805  ->state;
2806  compat::chunk_tables_v2::Migrate(saved_chunk_tables, chunk_tables);
2808  fd_progress,
2809  StringifyInt(chunk_tables->handle2fd.size()) + " handles\n");
2810  }
2811 
2812  if (saved_states[i]->state_id == loader::kStateOpenChunksV3) {
2813  SendMsg2Socket(fd_progress, "Migrating chunk tables (v3 to v4)... ");
2815  *saved_chunk_tables = (compat::chunk_tables_v3::ChunkTables *)
2816  saved_states[i]
2817  ->state;
2818  compat::chunk_tables_v3::Migrate(saved_chunk_tables, chunk_tables);
2820  fd_progress,
2821  StringifyInt(chunk_tables->handle2fd.size()) + " handles\n");
2822  }
2823 
2824  if (saved_states[i]->state_id == loader::kStateOpenChunksV4) {
2825  SendMsg2Socket(fd_progress, "Restoring chunk tables... ");
2826  chunk_tables->~ChunkTables();
2827  ChunkTables *saved_chunk_tables = reinterpret_cast<ChunkTables *>(
2828  saved_states[i]->state);
2829  new (chunk_tables) ChunkTables(*saved_chunk_tables);
2830  SendMsg2Socket(fd_progress, " done\n");
2831  }
2832 
2833  if (saved_states[i]->state_id == loader::kStateInodeGeneration) {
2834  SendMsg2Socket(fd_progress, "Restoring inode generation... ");
2836  *old_info = (cvmfs::InodeGenerationInfo *)saved_states[i]->state;
2837  if (old_info->version == 1) {
2838  // Migration
2840  ->initial_revision;
2842  // Note: in the rare case of inode generation being 0 before, inode
2843  // can clash after reload before remount
2844  } else {
2845  cvmfs::inode_generation_info_ = *old_info;
2846  }
2848  SendMsg2Socket(fd_progress, " done\n");
2849  }
2850 
2851  if (saved_states[i]->state_id == loader::kStateOpenFilesCounter) {
2852  SendMsg2Socket(fd_progress, "Restoring open files counter... ");
2854  *(reinterpret_cast<uint32_t *>(saved_states[i]->state)));
2855  SendMsg2Socket(fd_progress, " done\n");
2856  }
2857 
2858  if (saved_states[i]->state_id == loader::kStateOpenFiles) {
2859  const int old_root_fd = cvmfs::mount_point_->catalog_mgr()->root_fd();
2860 
2861  // TODO(jblomer): make this less hacky
2862 
2863  const CacheManagerIds saved_type =
2864  cvmfs::file_system_->cache_mgr()->PeekState(saved_states[i]->state);
2865  int fixup_root_fd = -1;
2866 
2867  if ((saved_type == kStreamingCacheManager)
2868  && (cvmfs::file_system_->cache_mgr()->id()
2869  != kStreamingCacheManager)) {
2870  // stick to the streaming cache manager
2871  StreamingCacheManager *new_cache_mgr = new StreamingCacheManager(
2873  cvmfs::file_system_->cache_mgr(),
2874  cvmfs::mount_point_->download_mgr(),
2875  cvmfs::mount_point_->external_download_mgr(),
2877  cvmfs::file_system_->statistics());
2878  fixup_root_fd = new_cache_mgr->PlantFd(old_root_fd);
2879  cvmfs::file_system_->ReplaceCacheManager(new_cache_mgr);
2880  cvmfs::mount_point_->fetcher()->ReplaceCacheManager(new_cache_mgr);
2882  new_cache_mgr);
2883  }
2884 
2885  if ((cvmfs::file_system_->cache_mgr()->id() == kStreamingCacheManager)
2886  && (saved_type != kStreamingCacheManager)) {
2887  // stick to the cache manager wrapped into the streaming cache
2888  CacheManager *wrapped_cache_mgr = dynamic_cast<StreamingCacheManager *>(
2890  ->MoveOutBackingCacheMgr(
2891  &fixup_root_fd);
2892  delete cvmfs::file_system_->cache_mgr();
2893  cvmfs::file_system_->ReplaceCacheManager(wrapped_cache_mgr);
2894  cvmfs::mount_point_->fetcher()->ReplaceCacheManager(wrapped_cache_mgr);
2896  wrapped_cache_mgr);
2897  }
2898 
2899  const int new_root_fd = cvmfs::file_system_->cache_mgr()->RestoreState(
2900  fd_progress, saved_states[i]->state);
2901  LogCvmfs(kLogCvmfs, kLogDebug, "new root file catalog descriptor @%d",
2902  new_root_fd);
2903  if (new_root_fd >= 0) {
2904  cvmfs::file_system_->RemapCatalogFd(old_root_fd, new_root_fd);
2905  } else if (fixup_root_fd >= 0) {
2907  "new root file catalog descriptor (fixup) @%d", fixup_root_fd);
2908  cvmfs::file_system_->RemapCatalogFd(old_root_fd, fixup_root_fd);
2909  }
2910  }
2911 
2912  if (saved_states[i]->state_id == loader::kStateFuse) {
2913  SendMsg2Socket(fd_progress, "Restoring fuse state... ");
2914  cvmfs::FuseState *fuse_state = static_cast<cvmfs::FuseState *>(
2915  saved_states[i]->state);
2916  if (!fuse_state->cache_symlinks)
2918  if (fuse_state->has_dentry_expire)
2920  SendMsg2Socket(fd_progress, " done\n");
2921  }
2922  }
2923  if (cvmfs::mount_point_->inode_annotation()) {
2924  const uint64_t saved_generation =
2926  cvmfs::mount_point_->inode_annotation()->IncGeneration(saved_generation);
2927  }
2928 
2929  return true;
2930 }
2931 
2932 
2933 static void FreeSavedState(const int fd_progress,
2934  const loader::StateList &saved_states) {
2935  for (unsigned i = 0, l = saved_states.size(); i < l; ++i) {
2936  switch (saved_states[i]->state_id) {
2938  SendMsg2Socket(fd_progress, "Releasing saved open directory handles\n");
2939  delete static_cast<cvmfs::DirectoryHandles *>(saved_states[i]->state);
2940  break;
2942  SendMsg2Socket(fd_progress,
2943  "Releasing saved glue buffer (version 1)\n");
2944  delete static_cast<compat::inode_tracker::InodeTracker *>(
2945  saved_states[i]->state);
2946  break;
2948  SendMsg2Socket(fd_progress,
2949  "Releasing saved glue buffer (version 2)\n");
2950  delete static_cast<compat::inode_tracker_v2::InodeTracker *>(
2951  saved_states[i]->state);
2952  break;
2954  SendMsg2Socket(fd_progress,
2955  "Releasing saved glue buffer (version 3)\n");
2956  delete static_cast<compat::inode_tracker_v3::InodeTracker *>(
2957  saved_states[i]->state);
2958  break;
2960  SendMsg2Socket(fd_progress, "Releasing saved glue buffer\n");
2961  delete static_cast<glue::InodeTracker *>(saved_states[i]->state);
2962  break;
2964  SendMsg2Socket(fd_progress, "Releasing saved dentry tracker\n");
2965  delete static_cast<glue::DentryTracker *>(saved_states[i]->state);
2966  break;
2968  SendMsg2Socket(fd_progress, "Releasing saved page cache entry cache\n");
2969  delete static_cast<glue::PageCacheTracker *>(saved_states[i]->state);
2970  break;
2972  SendMsg2Socket(fd_progress, "Releasing chunk tables (version 1)\n");
2973  delete static_cast<compat::chunk_tables::ChunkTables *>(
2974  saved_states[i]->state);
2975  break;
2977  SendMsg2Socket(fd_progress, "Releasing chunk tables (version 2)\n");
2978  delete static_cast<compat::chunk_tables_v2::ChunkTables *>(
2979  saved_states[i]->state);
2980  break;
2982  SendMsg2Socket(fd_progress, "Releasing chunk tables (version 3)\n");
2983  delete static_cast<compat::chunk_tables_v3::ChunkTables *>(
2984  saved_states[i]->state);
2985  break;
2987  SendMsg2Socket(fd_progress, "Releasing chunk tables\n");
2988  delete static_cast<ChunkTables *>(saved_states[i]->state);
2989  break;
2991  SendMsg2Socket(fd_progress, "Releasing saved inode generation info\n");
2992  delete static_cast<cvmfs::InodeGenerationInfo *>(
2993  saved_states[i]->state);
2994  break;
2996  cvmfs::file_system_->cache_mgr()->FreeState(fd_progress,
2997  saved_states[i]->state);
2998  break;
3000  SendMsg2Socket(fd_progress, "Releasing open files counter\n");
3001  delete static_cast<uint32_t *>(saved_states[i]->state);
3002  break;
3003  case loader::kStateFuse:
3004  SendMsg2Socket(fd_progress, "Releasing fuse state\n");
3005  delete static_cast<cvmfs::FuseState *>(saved_states[i]->state);
3006  break;
3007  default:
3008  break;
3009  }
3010  }
3011 }
3012 
3013 
3014 static void __attribute__((constructor)) LibraryMain() {
3015  g_cvmfs_exports = new loader::CvmfsExports();
3016  g_cvmfs_exports->so_version = CVMFS_VERSION;
3017  g_cvmfs_exports->fnAltProcessFlavor = AltProcessFlavor;
3018  g_cvmfs_exports->fnInit = Init;
3019  g_cvmfs_exports->fnSpawn = Spawn;
3020  g_cvmfs_exports->fnFini = Fini;
3021  g_cvmfs_exports->fnGetErrorMsg = GetErrorMsg;
3022  g_cvmfs_exports->fnMaintenanceMode = MaintenanceMode;
3023  g_cvmfs_exports->fnSaveState = SaveState;
3024  g_cvmfs_exports->fnRestoreState = RestoreState;
3025  g_cvmfs_exports->fnFreeSavedState = FreeSavedState;
3026  cvmfs::SetCvmfsOperations(&g_cvmfs_exports->cvmfs_operations);
3027 }
3028 
3029 
3030 static void __attribute__((destructor)) LibraryExit() {
3031  delete g_cvmfs_exports;
3032  g_cvmfs_exports = NULL;
3033 }
bool GetInfoIfOpen(uint64_t inode, shash::Any *hash, struct stat *info)
Definition: glue_buffer.h:1006
perf::Counter * n_eio_total()
Definition: mountpoint.h:238
bool cache_symlinks()
Definition: mountpoint.h:525
VfsPutRaii GetVfsPutRaii()
Definition: glue_buffer.h:673
std::string repository_name
Definition: loader.h:177
OptionsManager * options_mgr()
Definition: mountpoint.h:248
uint32_t version
Definition: loader.h:172
bool IsCaching()
Definition: fuse_remount.h:60
void Dec(class Counter *counter)
Definition: statistics.h:49
NfsMaps * nfs_maps()
Definition: mountpoint.h:235
bool IsExternalFile() const
std::string mount_point
Definition: loader.h:178
perf::Counter * n_eio_05()
Definition: mountpoint.h:243
bool IsInDrainoutMode()
Definition: fuse_remount.h:64
void UnregisterQuotaListener()
Definition: cvmfs.cc:2129
static const time_t kIndefiniteDeadline
Definition: mountpoint.h:493
perf::Counter * n_fs_inode_replace()
Definition: mountpoint.h:223
int64_t Xadd(class Counter *counter, const int64_t delta)
Definition: statistics.h:51
static void cvmfs_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
Definition: cvmfs.cc:757
std::string ListKeysPosix(const std::string &merge_with) const
Definition: xattr.cc:139
perf::Counter * n_eio_01()
Definition: mountpoint.h:239
FileSystem * file_system()
Definition: mountpoint.h:521
void TryFinish(const shash::Any &root_hash=shash::Any())
bool InsertNegative(const shash::Md5 &hash)
Definition: lru_md.h:118
Log2Histogram * hist_fs_opendir()
Definition: mountpoint.h:214
time_t catalogs_valid_until_
Definition: cvmfs.cc:2174
static bool HasDifferentContent(const catalog::DirectoryEntry &dirent, const shash::Any &hash, const struct stat &info)
Definition: cvmfs.cc:275
virtual void ParsePath(const std::string &config_file, const bool external)=0
void Enter()
Definition: fence.h:34
bool ReplaceInode(uint64_t old_inode, const InodeEx &new_inode)
Definition: glue_buffer.h:723
static void cvmfs_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi)
Definition: cvmfs.cc:1371
time_t mtime() const
static double GetKcacheTimeout()
Definition: cvmfs.cc:221
void EnterMaintenanceMode()
void set_inode(const inode_t inode)
InodeGenerationInfo inode_generation_info_
Definition: cvmfs.cc:136
loader::Failures boot_status()
Definition: mountpoint.h:77
static void FreeSavedState(const int fd_progress, const loader::StateList &saved_states)
Definition: cvmfs.cc:2933
int PlantFd(int fd_in_cache_mgr)
bool IsDirectory() const
static void cvmfs_statfs(fuse_req_t req, fuse_ino_t ino)
Definition: cvmfs.cc:1631
off_t range_offset
Definition: cache.h:127
bool PrepareValueFencedProtected(gid_t gid)
Definition: magic_xattr.cc:161
void set_boot_status(loader::Failures code)
Definition: mountpoint.h:84
static void DoTraceInode(const int event, fuse_ino_t ino, const std::string &msg)
Definition: cvmfs.cc:493
cvmfs::Fetcher * fetcher()
Definition: mountpoint.h:516
void Migrate(ChunkTables *old_tables,::ChunkTables *new_tables)
Definition: compat.cc:183
void ShareBuffer(Item **duplicate, bool *large_alloc)
Definition: bigvector.h:77
static void cvmfs_releasedir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
Definition: cvmfs.cc:1020
bool IsChunkedFile() const
FuseRemounter * fuse_remounter_
Definition: cvmfs.cc:135
uid_t talk_socket_uid()
Definition: mountpoint.h:541
int RestoreState(const int fd_progress, void *state)
Definition: cache.cc:182
void Register(const std::string &name, BaseMagicXattr *magic_xattr)
Definition: magic_xattr.cc:139
SmallHashDynamic< uint64_t, uint64_t > handle2uniqino
Definition: file_chunk.h:113
bool Insert(const fuse_ino_t &inode, const catalog::DirectoryEntry &dirent)
Definition: lru_md.h:48
google::dense_hash_map< uint64_t, DirectoryListing, hash_murmur< uint64_t > > DirectoryHandles
Definition: cvmfs.cc:163
#define PANIC(...)
Definition: exception.h:29
void Spawn()
Definition: tracer.cc:208
SpecialDirents GetSpecial() const
bool fuse_expire_entry()
Definition: mountpoint.h:526
virtual void Spawn()=0
static int AltProcessFlavor(int argc, char **argv)
Definition: cvmfs.cc:2558
uint64_t size() const
std::string ToString(const bool with_suffix=false) const
Definition: hash.h:241
double kcache_timeout_sec()
Definition: mountpoint.h:530
void Assign(const char *chars, const unsigned length)
Definition: shortstring.h:61
static void cvmfs_forget(fuse_req_t req, fuse_ino_t ino, uint64_t nlookup)
Definition: cvmfs.cc:654
std::string PrintInodeGeneration()
Definition: cvmfs.cc:244
zlib::Algorithms compression_alg
Definition: file_chunk.h:65
static void SetupLoggingStandalone(const OptionsManager &options_mgr, const std::string &prefix)
Definition: mountpoint.cc:851
int MainResolveProxyDescription(int argc, char **argv)
Definition: wpad.cc:268
bool FindDentry(uint64_t ino, uint64_t *parent_ino, NameString *name)
Definition: glue_buffer.h:701
perf::Counter * n_fs_readlink()
Definition: mountpoint.h:228
std::string fqrn() const
Definition: mountpoint.h:518
unsigned LookupOptions
Definition: catalog_mgr.h:42
void SetMountpoint(const string &mountpoint)
Definition: auto_umount.cc:28
#define CVMFS_TEST_INJECT_BARRIER(...)
Definition: testing.h:62
void InvalidateDentry(uint64_t parent_ino, const NameString &name)
Definition: fuse_remount.h:70
void set_symlink(const LinkString &symlink)
static void cvmfs_release(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
Definition: cvmfs.cc:1550
BaseMagicXattr * GetLocked(const std::string &name, PathString path, catalog::DirectoryEntry *d)
Definition: magic_xattr.cc:124
Watchdog * watchdog_
Definition: cvmfs.cc:134
static const size_t kDefaultBufferSize
Definition: cache_stream.h:33
bool Lookup(const shash::Md5 &hash, catalog::DirectoryEntry *dirent, bool update_lru=true)
Definition: lru_md.h:125
lru::InodeCache * inode_cache()
Definition: mountpoint.h:529
NotificationClient * notification_client_
Definition: cvmfs.cc:133
void * SaveState(const int fd_progress)
Definition: cache.cc:211
DirectoryHandles * directory_handles_
Definition: cvmfs.cc:164
StateId state_id
Definition: loader.h:123
CVMFS_EXPORT void CleanupLibcryptoMt()
Definition: crypto_util.cc:66
bool check_fd_overflow_
Definition: cvmfs.cc:174
const shash::Any & content_hash() const
Definition: file_chunk.h:37
time_t catalogs_valid_until()
Definition: fuse_remount.h:68
static bool SaveState(const int fd_progress, loader::StateList *saved_states)
Definition: cvmfs.cc:2583
inode_t inode() const
void SendMsg2Socket(const int fd, const std::string &msg)
Definition: posix.cc:671
bool ListingStat(const PathString &path, StatEntryList *listing)
assert((mem||(size==0))&&"Out Of Memory")
void ** fuse_channel_or_session
Definition: loader.h:195
MountPoint * mount_point_
Definition: cvmfs.cc:131
MagicXattrManager * magic_xattr_mgr()
Definition: mountpoint.h:522
std::string program_name
Definition: loader.h:180
Log2Histogram * hist_fs_read()
Definition: mountpoint.h:218
bool IsDirectIo() const
bool SendFd2Socket(int socket_fd, int passing_fd)
Definition: posix.cc:680
bool LookupPath(const PathString &path, const LookupOptions options, DirectoryEntry *entry)
void EnableFuseExpireEntry()
Definition: mountpoint.cc:1236
static bool RestoreState(const int fd_progress, const loader::StateList &saved_states)
Definition: cvmfs.cc:2693
virtual uint64_t GetSize()=0
perf::Counter * n_fs_read()
Definition: mountpoint.h:227
bool Lookup(const fuse_ino_t &inode, catalog::DirectoryEntry *dirent, bool update_lru=true)
Definition: lru_md.h:56
void UmountOnCrash()
Definition: auto_umount.cc:38
int fd
Definition: file_chunk.h:76
std::string StringifyUint(const uint64_t value)
Definition: string.cc:83
lru::Md5PathCache * md5path_cache()
Definition: mountpoint.h:531
shash::Any checksum() const
void ParseDefault(const std::string &fqrn)
Definition: options.cc:281
SmallHashDynamic< uint64_t, ChunkFd > handle2fd
Definition: file_chunk.h:114
bool VfsPut(const uint64_t inode, const uint32_t by)
Definition: glue_buffer.h:596
void Migrate(InodeTracker *old_tracker, glue::InodeTracker *new_tracker)
Definition: compat.cc:109
bool has_dentry_expire
Definition: cvmfs.cc:205
bool has_membership_req()
Definition: mountpoint.h:523
virtual bool PrepareValueFenced()
Definition: cvmfs.cc:2176
unsigned int mode() const
struct cvmcache_object_info __attribute__
Definition: atomic.h:24
const unsigned kLookupDefault
Definition: catalog_mgr.h:43
void RemapCatalogFd(int from, int to)
Definition: mountpoint.cc:1121
MagicXattrMode
Definition: magic_xattr.h:32
bool Pin(const string &path)
Definition: cvmfs.cc:1953
static void cvmfs_destroy(void *unused __attribute__((unused)))
Definition: cvmfs.cc:2095
perf::Counter * n_eio_08()
Definition: mountpoint.h:246
static TalkManager * Create(const std::string &socket_path, MountPoint *mount_point, FuseRemounter *remounter)
Definition: talk.cc:79
unsigned max_open_files_
Definition: cvmfs.cc:168
static bool HasFuseNotifyInval()
Definition: fuse_evict.cc:54
perf::Counter * n_fs_open()
Definition: mountpoint.h:226
bool IsStale(const catalog::DirectoryEntry &dirent)
Definition: glue_buffer.h:1026
static void cvmfs_init(void *userdata, struct fuse_conn_info *conn)
Definition: cvmfs.cc:2022
TalkManager * talk_mgr_
Definition: cvmfs.cc:132
const unsigned int kMinOpenFiles
Definition: cvmfs.cc:182
virtual uint64_t GetCapacity()=0
std::string membership_req()
Definition: mountpoint.h:532
void Throttle()
Definition: backoff.cc:48
std::string GetListString(catalog::DirectoryEntry *dirent)
Definition: magic_xattr.cc:77
bool Lookup(const fuse_ino_t &inode, PathString *path, bool update_lru=true)
Definition: lru_md.h:86
uint64_t next_directory_handle_
Definition: cvmfs.cc:166
bool IsValid(const std::string &input) const
Definition: sanitizer.cc:112
void Unlock()
Definition: file_chunk.h:100
static void InitOptionsMgr(const loader::LoaderExports *loader_exports)
Definition: cvmfs.cc:2274
Fence * fence()
Definition: fuse_remount.h:67
const uint64_t cache_timeout()
Definition: mountpoint.h:463
pid_t pid_
Definition: cvmfs.cc:156
void ReplaceCacheManager(CacheManager *new_cache_mgr)
Definition: mountpoint.cc:1125
void DisableCacheSymlinks()
Definition: mountpoint.cc:1230
PathString path
Definition: file_chunk.h:64
static bool GetDirentForInode(const fuse_ino_t ino, catalog::DirectoryEntry *dirent)
Definition: cvmfs.cc:316
glue::PageCacheTracker * page_cache_tracker()
Definition: mountpoint.h:534
NameString name() const
static Watchdog * Create(FnOnCrash on_crash)
Definition: monitor.cc:67
bool IsLink() const
void SetBit(unsigned int bit, T *field)
Definition: algorithm.h:31
perf::Counter * n_eio_07()
Definition: mountpoint.h:245
BigVector< FileChunk > FileChunkList
Definition: file_chunk.h:47
virtual void Spawn()=0
static bool FixupOpenInode(const PathString &path, catalog::DirectoryEntry *dirent)
Definition: cvmfs.cc:297
bool HasXattrs() const
static void TraceInode(const int event, fuse_ino_t ino, const std::string &msg)
Definition: cvmfs.cc:507
void GetLimitNoFile(unsigned *soft_limit, unsigned *hard_limit)
Definition: posix.cc:1478
bool Get(const std::string &key, std::string *value) const
Definition: xattr.cc:109
catalog::ClientCatalogManager * catalog_mgr()
Definition: mountpoint.h:507
void Set(const int64_t val)
Definition: statistics.h:33
Log2Histogram * hist_fs_forget_multi()
Definition: mountpoint.h:211
static void cvmfs_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size)
Definition: cvmfs.cc:1863
bool IsRegular() const
vector< string > SplitString(const string &str, char delim)
Definition: string.cc:306
void ClearBit(unsigned int bit, T *field)
Definition: algorithm.h:36
uint64_t size
unzipped size, if known
Definition: cache.h:125
void DoubleCapacity()
Definition: bigvector.h:83
bool platform_getxattr(const std::string &path, const std::string &name, std::string *value)
static bool MayBeInPageCacheTracker(const catalog::DirectoryEntry &dirent)
Definition: cvmfs.cc:270
Log2Histogram * hist_fs_release()
Definition: mountpoint.h:219
pthread_mutex_t * Handle2Lock(const uint64_t handle) const
Definition: file_chunk.cc:139
void Lock()
Definition: file_chunk.h:95
uint64_t FindInode(const PathString &path)
Definition: glue_buffer.h:693
ListenerHandle * RegisterWatchdogListener(QuotaManager *quota_manager, const string &repository_name)
perf::Counter * n_emfile()
Definition: mountpoint.h:247
const loader::LoaderExports * loader_exports_
Definition: cvmfs.cc:154
int Fetch(const CacheManager::LabeledObject &object, const std::string &alt_url="")
Definition: fetch.cc:82
EVisibility visibility()
Definition: magic_xattr.h:255
virtual inode_t GetGeneration()=0
std::string config_files
Definition: loader.h:179
perf::Counter * no_open_dirs()
Definition: mountpoint.h:236
catalog::InodeAnnotation * inode_annotation()
Definition: mountpoint.h:527
CacheManagerIds
Definition: cache.h:24
Log2Histogram * hist_fs_releasedir()
Definition: mountpoint.h:215
quota::ListenerHandle * watchdog_listener_
Definition: cvmfs.cc:157
void Add(const uint64_t inode_parent, const char *name, uint64_t timeout_s)
Definition: glue_buffer.h:834
virtual bool IsCanceled()
Definition: cvmfs.cc:189
void SetSize(const size_t new_size)
Definition: bigvector.h:112
std::string boot_error()
Definition: mountpoint.h:78
off_t offset() const
Definition: file_chunk.h:38
lru::PathCache * path_cache()
Definition: mountpoint.h:535
struct statvfs * info()
Definition: mountpoint.h:464
static void cvmfs_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
Definition: cvmfs.cc:1118
zlib::Algorithms compression_algorithm() const
bool IsNfsSource()
Definition: mountpoint.h:195
CacheManager * cache_mgr()
Definition: mountpoint.h:205
const signature::SignatureManager * signature_mgr() const
Definition: repository.h:121
file_watcher::FileWatcher * resolv_conf_watcher()
Definition: mountpoint.h:513
unsigned chunk_idx
Definition: file_chunk.h:77
virtual bool Pin(const shash::Any &hash, const uint64_t size, const std::string &description, const bool is_catalog)=0
bool IsMemberOf(const pid_t pid, const std::string &membership)
void Migrate(InodeTracker *old_tracker, glue::InodeTracker *new_tracker)
Definition: compat.cc:145
void SpawnCleaner(unsigned interval_s)
Definition: glue_buffer.cc:165
static void ShutdownMountpoint()
Definition: cvmfs.cc:2510
static bool AssertOrLog(int t, const LogSource, const int, const char *,...)
Definition: exception.h:60
static bool IncAndCheckNoOpenFiles()
Definition: cvmfs.cc:214
unsigned FindChunkIdx(const uint64_t offset)
Definition: file_chunk.cc:23
virtual void FinalizeValue()
Definition: cvmfs.cc:2201
perf::TelemetryAggregator * telemetry_aggr()
Definition: mountpoint.h:539
bool SendFuseFd(const std::string &socket_path)
Definition: cvmfs.cc:2140
perf::Counter * no_open_files()
Definition: mountpoint.h:237
AuthzSessionManager * authz_session_mgr()
Definition: mountpoint.h:505
LinkString symlink() const
void Insert(const Key &key, const Value &value)
Definition: smallhash.h:106
IoErrorInfo * io_error_info()
Definition: mountpoint.h:233
download::DownloadManager * download_mgr()
Definition: mountpoint.h:509
perf::Counter * n_fs_stat_stale()
Definition: mountpoint.h:230
void ReplaceCacheManager(CacheManager *new_cache_mgr)
Definition: fetch.h:116
static void SetCvmfsOperations(struct fuse_lowlevel_ops *cvmfs_operations)
Definition: cvmfs.cc:2103
bool simple_options_parsing
Definition: loader.h:188
static const int kLabelPinned
Definition: cache.h:81
perf::Counter * n_fs_forget()
Definition: mountpoint.h:222
Log2Histogram * hist_fs_readlink()
Definition: mountpoint.h:213
static int Init(const loader::LoaderExports *loader_exports)
Definition: cvmfs.cc:2320
void Append(const char *chars, const unsigned length)
Definition: shortstring.h:80
ListenerHandle * RegisterUnpinListener(QuotaManager *quota_manager, CatalogManager *catalog_manager, const string &repository_name)
string StringifyInt(const int64_t value)
Definition: string.cc:77
SmallHashDynamic< uint64_t, uint32_t > inode2references
Definition: file_chunk.h:119
void Leave()
Definition: fence.h:41
uint64_t platform_monotonic_time()
static void cvmfs_readlink(fuse_req_t req, fuse_ino_t ino)
Definition: cvmfs.cc:827
size_t capacity() const
Definition: bigvector.h:118
static void ReplyNegative(const catalog::DirectoryEntry &dirent, fuse_req_t req)
Definition: cvmfs.cc:734
void Inc(class Counter *counter)
Definition: statistics.h:50
virtual int Close(int fd)=0
CacheManagerIds PeekState(void *state)
Definition: cache.h:205
bool GetValue(const std::string &key, std::string *value) const
Definition: options.cc:369
static void cvmfs_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi)
Definition: cvmfs.cc:1070
ChunkTables * chunk_tables()
Definition: mountpoint.h:508
const unsigned kLookupRawSymlink
Definition: catalog_mgr.h:44
pthread_mutex_t lock_directory_handles_
Definition: cvmfs.cc:165
static void cvmfs_opendir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
Definition: cvmfs.cc:885
OptionsManager * options_mgr_
Definition: cvmfs.cc:155
virtual bool GetPath(const uint64_t inode, PathString *path)=0
unsigned version
Definition: cvmfs.cc:203
shash::Algorithms hash_algorithm() const
glue::DentryTracker * dentry_tracker()
Definition: mountpoint.h:533
static int MainCacheManager(int argc, char **argv)
perf::Counter * n_fs_dir_open()
Definition: mountpoint.h:221
Log2Histogram * hist_fs_readdir()
Definition: mountpoint.h:216
cvmfs::Fetcher * external_fetcher()
Definition: mountpoint.h:520
bool enforce_acls()
Definition: mountpoint.h:524
static const int kLabelVolatile
Definition: cache.h:82
bool IsInMaintenanceMode()
Definition: fuse_remount.h:65
static bool CheckVoms(const fuse_ctx &fctx)
Definition: cvmfs.cc:255
static void FillOpenFlags(const glue::PageCacheTracker::OpenDirectives od, struct fuse_file_info *fi)
Definition: cvmfs.cc:1095
void FreeState(const int fd_progress, void *state)
Definition: cache.cc:95
static FileSystem * Create(const FileSystemInfo &fs_info)
Definition: mountpoint.cc:164
bool IsEmpty() const
Definition: bigvector.h:70
bool cache_symlinks
Definition: cvmfs.cc:204
zlib::Algorithms zip_algorithm
Definition: cache.h:126
bool Contains(const Key &key) const
Definition: smallhash.h:99
Log2Histogram * hist_fs_open()
Definition: mountpoint.h:217
OpenDirectives Open(uint64_t inode, const shash::Any &hash, const struct stat &info)
Definition: glue_buffer.cc:309
pthread_mutex_t * lock()
Definition: mountpoint.h:465
std::string ToString() const
Definition: shortstring.h:139
QuotaManager * quota_mgr()
Definition: cache.h:191
static string GetErrorMsg()
Definition: cvmfs.cc:2498
static uint64_t GetDirentForPath(const PathString &path, catalog::DirectoryEntry *dirent)
Definition: cvmfs.cc:406
int ConnectSocket(const std::string &path)
Definition: posix.cc:422
void Migrate(ChunkTables *old_tables,::ChunkTables *new_tables)
Definition: compat.cc:277
virtual void Spawn()
Definition: nfs_maps.h:36
Log2Histogram * hist_fs_lookup()
Definition: mountpoint.h:209
bool IsCompatibleFileType(unsigned mode) const
Definition: glue_buffer.h:85
uint64_t String2Uint64(const string &value)
Definition: string.cc:240
bool TestBit(unsigned int bit, const T field)
Definition: algorithm.h:41
CVMFS_EXPORT void SetupLibcryptoMt()
Definition: crypto_util.cc:48
void Close(uint64_t inode)
Definition: glue_buffer.cc:397
string * g_boot_error
Definition: cvmfs.cc:2164
virtual void FinalizeValue()
Definition: cvmfs.cc:2214
bool ListFileChunks(const PathString &path, const shash::Algorithms interpret_hashes_as, FileChunkList *chunks)
static void Fini()
Definition: cvmfs.cc:2539
perf::Counter * n_fs_lookup()
Definition: mountpoint.h:224
static void Spawn()
Definition: cvmfs.cc:2448
static bool UseWatchdog()
Definition: cvmfs.cc:234
void Migrate(InodeTracker *old_tracker, glue::InodeTracker *new_tracker)
Definition: compat.cc:79
OpenDirectives OpenDirect()
Definition: glue_buffer.cc:386
ShortString< kDefaultMaxPath, 0 > PathString
Definition: shortstring.h:213
uint32_t size() const
Definition: smallhash.h:291
uint64_t next_handle
Definition: file_chunk.h:120
shash::Any HashChunkList()
Definition: file_chunk.cc:49
size_t size() const
Definition: file_chunk.h:39
FuseInterruptCue(fuse_req_t *r)
Definition: cvmfs.cc:187
void UnregisterListener(ListenerHandle *handle)
Definition: mutex.h:42
bool Evict(const string &path)
Definition: cvmfs.cc:1926
std::vector< SavedState * > StateList
Definition: loader.h:126
perf::Counter * n_eio_02()
Definition: mountpoint.h:240
PathString GetParentPath(const PathString &path)
Definition: shortstring.cc:14
static unsigned CheckMaxOpenFiles()
Definition: cvmfs.cc:2294
FileSystem * file_system_
Definition: cvmfs.cc:130
perf::Counter * n_eio_03()
Definition: mountpoint.h:241
EvictRaii GetEvictRaii()
Definition: glue_buffer.h:1060
perf::Counter * n_eio_04()
Definition: mountpoint.h:242
void GetReloadStatus(bool *drainout_mode, bool *maintenance_mode)
Definition: cvmfs.cc:228
bool Erase(const Key &key)
Definition: smallhash.h:112
bool LookupXattrs(const PathString &path, XattrList *xattrs)
perf::Counter * n_fs_lookup_negative()
Definition: mountpoint.h:225
StatfsCache * statfs_cache()
Definition: mountpoint.h:546
std::string path
Definition: cache.h:133
virtual uint64_t GetInode(const PathString &path)=0
void Spawn(const std::string &crash_dump_path)
Definition: monitor.cc:514
virtual void FinalizeValue()
Definition: cvmfs.cc:2181
Log2Histogram * hist_fs_forget()
Definition: mountpoint.h:210
const int kNumReservedFd
Definition: cvmfs.cc:178
static void ReplyBufferSlice(const fuse_req_t req, const char *buffer, const size_t buffer_size, const off_t offset, const size_t max_size)
Definition: cvmfs.cc:1054
unsigned GetLength() const
Definition: shortstring.h:131
static const int kLabelExternal
Definition: cache.h:83
virtual void IncGeneration(const uint64_t by)=0
bool Lookup(const Key &key, Value *value) const
Definition: smallhash.h:70
inode_t MangleInode(const inode_t inode) const
Definition: catalog_mgr.h:326
static const int kLabelChunked
Definition: cache.h:84
virtual void FinalizeValue()
Definition: cvmfs.cc:2208
bool Insert(const fuse_ino_t &inode, const PathString &path)
Definition: lru_md.h:79
BackoffThrottle * backoff_throttle()
Definition: mountpoint.h:506
Log2Histogram * hist_fs_getattr()
Definition: mountpoint.h:212
gid_t talk_socket_gid()
Definition: mountpoint.h:542
const char * c_str() const
Definition: shortstring.h:143
static bool GetPathForInode(const fuse_ino_t ino, PathString *path)
Definition: cvmfs.cc:459
static const unsigned int kBitDirectIo
Definition: glue_buffer.h:932
virtual void FinalizeValue()
Definition: cvmfs.cc:2193
const char * GetChars() const
Definition: shortstring.h:123
static void RegisterMagicXattrs()
Definition: cvmfs.cc:2225
bool IsDefined(const std::string &key)
Definition: options.cc:363
std::string GetCurrentWorkingDirectory()
Definition: posix.cc:1068
virtual void Remove(const shash::Any &file)=0
glue::InodeTracker * inode_tracker()
Definition: mountpoint.h:528
bool Insert(const shash::Md5 &hash, const catalog::DirectoryEntry &dirent)
Definition: lru_md.h:110
perf::Counter * n_fs_stat()
Definition: mountpoint.h:229
static void size_t size
Definition: smalloc.h:54
virtual ~FuseInterruptCue()
Definition: cvmfs.cc:188
static void cvmfs_lookup(fuse_req_t req, fuse_ino_t parent, const char *name)
Definition: cvmfs.cc:519
#define ENOATTR
Definition: cvmfs.cc:25
virtual int64_t Pread(int fd, void *buf, uint64_t size, uint64_t offset)=0
SmallHashDynamic< uint64_t, FileChunkReflist > inode2chunks
Definition: file_chunk.h:118
static bool MaintenanceMode(const int fd_progress)
Definition: cvmfs.cc:2569
uint64_t * expiry_deadline()
Definition: mountpoint.h:462
void Migrate(ChunkTables *old_tables,::ChunkTables *new_tables)
Definition: compat.cc:230
FileChunkList * list
Definition: file_chunk.h:63
static FileSystem * InitSystemFs(const string &mount_path, const string &fqrn, FileSystem::FileSystemInfo fs_info)
Definition: cvmfs.cc:2240
static const inode_t kInodeOffset
Definition: catalog_mgr.h:245
void VfsGet(const InodeEx inode_ex, const PathString &path)
Definition: glue_buffer.h:669
const Item * AtPtr(const size_t index) const
Definition: bigvector.h:53
static void cvmfs_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, size_t size)
Definition: cvmfs.cc:1697
Tracer * tracer()
Definition: mountpoint.h:544
perf::Counter * n_fs_statfs_cached()
Definition: mountpoint.h:232
bool FindPath(InodeEx *inode_ex, PathString *path)
Definition: glue_buffer.h:675
struct stat GetStatStructure() const
virtual bool HasCapability(Capabilities capability)=0
static void AddToDirListing(const fuse_req_t req, const char *name, const struct stat *stat_info, BigVector< char > *listing)
Definition: cvmfs.cc:860
size_t size() const
Definition: bigvector.h:117
download::DownloadManager * external_download_mgr()
Definition: mountpoint.h:510
perf::Counter * n_fs_statfs()
Definition: mountpoint.h:231
quota::ListenerHandle * unpin_listener_
Definition: cvmfs.cc:158
static MountPoint * Create(const std::string &fqrn, FileSystem *file_system, OptionsManager *options_mgr=NULL)
Definition: mountpoint.cc:1243
void Spawn()
Definition: talk.cc:954
fuse_req_t * req_ptr_
Definition: cvmfs.cc:192
perf::Counter * n_eio_06()
Definition: mountpoint.h:244
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:545
OptionsManager * options_mgr
Definition: mountpoint.h:139