CernVM-FS  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
magic_xattr.cc
Go to the documentation of this file.
1 
5 #include "magic_xattr.h"
6 
7 #include <cassert>
8 #include <string>
9 #include <vector>
10 
11 #include "catalog_mgr_client.h"
12 #include "fetch.h"
13 #include "logging.h"
14 #include "mountpoint.h"
15 #include "quota.h"
16 #include "signature.h"
17 #include "util/string.h"
18 
20  bool hide_magic_xattrs)
21  : mount_point_(mountpoint),
22  hide_magic_xattrs_(hide_magic_xattrs)
23 {
24  Register("user.catalog_counters", new CatalogCountersMagicXattr());
25  Register("user.external_host", new ExternalHostMagicXattr());
26  Register("user.external_timeout", new ExternalTimeoutMagicXattr());
27  Register("user.fqrn", new FqrnMagicXattr());
28  Register("user.host", new HostMagicXattr());
29  Register("user.host_list", new HostListMagicXattr());
30  Register("user.ncleanup24", new NCleanup24MagicXattr());
31  Register("user.nclg", new NClgMagicXattr());
32  Register("user.ndiropen", new NDirOpenMagicXattr());
33  Register("user.ndownload", new NDownloadMagicXattr());
34  Register("user.nioerr", new NIOErrMagicXattr());
35  Register("user.nopen", new NOpenMagicXattr());
36  Register("user.hitrate", new HitrateMagicXattr());
37  Register("user.proxy", new ProxyMagicXattr());
38  Register("user.pubkeys", new PubkeysMagicXattr());
39  Register("user.repo_counters", new RepoCountersMagicXattr());
40  Register("user.repo_metainfo", new RepoMetainfoMagicXattr());
41  Register("user.revision", new RevisionMagicXattr());
42  Register("user.root_hash", new RootHashMagicXattr());
43  Register("user.rx", new RxMagicXattr());
44  Register("user.speed", new SpeedMagicXattr());
45  Register("user.tag", new TagMagicXattr());
46  Register("user.timeout", new TimeoutMagicXattr());
47  Register("user.timeout_direct", new TimeoutDirectMagicXattr());
48  Register("user.usedfd", new UsedFdMagicXattr());
49  Register("user.useddirp", new UsedDirPMagicXattr());
50  Register("user.version", new VersionMagicXattr());
51 
52  Register("user.hash", new HashMagicXattr());
53  Register("user.lhash", new LHashMagicXattr());
54 
55  Register("user.chunk_list", new ChunkListMagicXattr());
56  Register("user.chunks", new ChunksMagicXattr());
57  Register("user.compression", new CompressionMagicXattr());
58  Register("user.direct_io", new DirectIoMagicXattr());
59  Register("user.external_file", new ExternalFileMagicXattr());
60 
61  Register("user.rawlink", new RawlinkMagicXattr());
62  Register("xfsroot.rawlink", new RawlinkMagicXattr());
63 
64  Register("user.authz", new AuthzMagicXattr());
65 }
66 
68  if (hide_magic_xattrs()) {
69  return "";
70  }
71 
72  std::string result;
73  std::map<std::string, BaseMagicXattr *>::iterator it = xattr_list_.begin();
74  for (; it != xattr_list_.end(); ++it) {
75  MagicXattrFlavor flavor = (*it).second->GetXattrFlavor();
76  // Skip those which should not be displayed
77  switch (flavor) {
78  case kXattrBase:
79  break;
80  case kXattrWithHash:
81  if (dirent->checksum().IsNull()) continue;
82  break;
83  case kXattrRegular:
84  if (!dirent->IsRegular()) continue;
85  break;
86  case kXattrSymlink:
87  if (!dirent->IsLink()) continue;
88  break;
89  case kXattrAuthz:
90  if (!mount_point_->has_membership_req()) continue;
91  break;
92  default:
93  PANIC("unknown magic xattr flavor");
94  }
95  result += (*it).first;
96  result.push_back('\0');
97  }
98 
99  return result;
100 }
101 
103  PathString path,
105 {
106  BaseMagicXattr *result;
107  if (xattr_list_.count(name) > 0) {
108  result = xattr_list_[name];
109  } else {
110  return NULL;
111  }
112 
113  result->Lock(path, d);
114 
115  return result;
116 }
117 
118 void MagicXattrManager::Register(const std::string &name,
119  BaseMagicXattr *magic_xattr)
120 {
121  if (xattr_list_.count(name) > 0) {
123  "Magic extended attribute with name %s already registered",
124  name.c_str());
125  }
126  magic_xattr->mount_point_ = mount_point_;
127  xattr_list_[name] = magic_xattr;
128 }
129 
132 }
133 
135  return mount_point_->membership_req();
136 }
137 
139  return kXattrAuthz;
140 }
141 
143  counters_ =
145  return true;
146 }
147 
149  std::string res;
150  res = "catalog_mountpoint: " + subcatalog_path_ + "\n";
151  res += counters_.GetCsvMap();
152  return res;
153 }
154 
156  chunk_list_ = "hash,offset,size\n";
157  if (!dirent_->IsRegular()) {
158  return false;
159  }
160  if (dirent_->IsChunkedFile()) {
161  FileChunkList chunks;
162  if (!mount_point_->catalog_mgr()
164  || chunks.IsEmpty())
165  {
166  LogCvmfs(kLogCvmfs, kLogDebug | kLogSyslogErr, "file %s is marked as "
167  "'chunked', but no chunks found.", path_.c_str());
168  return false;
169  } else {
170  for (size_t i = 0; i < chunks.size(); ++i) {
171  chunk_list_ += chunks.At(i).content_hash().ToString() + ",";
172  chunk_list_ += StringifyInt(chunks.At(i).offset()) + ",";
173  chunk_list_ += StringifyUint(chunks.At(i).size()) + "\n";
174  }
175  }
176  } else {
177  chunk_list_ += dirent_->checksum().ToString() + ",";
178  chunk_list_ += "0,";
179  chunk_list_ += StringifyUint(dirent_->size()) + "\n";
180  }
181  return true;
182 }
183 
185  return chunk_list_;
186 }
187 
189  if (!dirent_->IsRegular()) {
190  return false;
191  }
192  if (dirent_->IsChunkedFile()) {
193  FileChunkList chunks;
194  if (!mount_point_->catalog_mgr()
196  || chunks.IsEmpty())
197  {
198  LogCvmfs(kLogCvmfs, kLogDebug | kLogSyslogErr, "file %s is marked as "
199  "'chunked', but no chunks found.", path_.c_str());
200  return false;
201  } else {
202  n_chunks_ = chunks.size();
203  }
204  } else {
205  n_chunks_ = 1;
206  }
207 
208  return true;
209 }
210 
212  return StringifyUint(n_chunks_);
213 }
214 
216  return dirent_->IsRegular();
217 }
218 
221 }
222 
224  return dirent_->IsRegular();
225 }
226 
228  return dirent_->IsDirectIo() ? "1" : "0";
229 }
230 
232  return dirent_->IsRegular();
233 }
234 
236  return dirent_->IsExternalFile() ? "1" : "0";
237 }
238 
240  std::vector<string> host_chain;
241  std::vector<int> rtt;
242  unsigned current_host;
244  &host_chain, &rtt, &current_host);
245  if (host_chain.size()) {
246  return std::string(host_chain[current_host]);
247  } else {
248  return "internal error: no hosts defined";
249  }
250 }
251 
253  unsigned seconds, seconds_direct;
254  mount_point_->external_download_mgr()->GetTimeout(&seconds, &seconds_direct);
255  return StringifyUint(seconds_direct);
256 }
257 
259  return mount_point_->fqrn();
260 }
261 
263  return !dirent_->checksum().IsNull();
264 }
265 
267  return dirent_->checksum().ToString();
268 }
269 
271  std::vector<std::string> host_chain;
272  std::vector<int> rtt;
273  unsigned current_host;
274  mount_point_->download_mgr()->GetHostInfo(&host_chain, &rtt, &current_host);
275  if (host_chain.size()) {
276  return std::string(host_chain[current_host]);
277  } else {
278  return "internal error: no hosts defined";
279  }
280 }
281 
283  std::string result;
284  std::vector<std::string> host_chain;
285  std::vector<int> rtt;
286  unsigned current_host;
287  mount_point_->download_mgr()->GetHostInfo(&host_chain, &rtt, &current_host);
288  if (host_chain.size()) {
289  result = host_chain[current_host];
290  for (unsigned i = 1; i < host_chain.size(); ++i) {
291  result +=
292  ";" + host_chain[(i+current_host) % host_chain.size()];
293  }
294  } else {
295  result = "internal error: no hosts defined";
296  }
297  return result;
298 }
299 
301  return !dirent_->checksum().IsNull();
302 }
303 
305  string result;
306  CacheManager::ObjectInfo object_info;
307  object_info.description = path_.ToString();
309  object_info.type = CacheManager::kTypeVolatile;
310  int fd = mount_point_->file_system()->cache_mgr()->Open(
311  CacheManager::Bless(dirent_->checksum(), object_info));
312  if (fd < 0) {
313  result = "Not in cache";
314  } else {
316  int retval_i =
317  mount_point_->file_system()->cache_mgr()->ChecksumFd(fd, &hash);
318  if (retval_i != 0)
319  result = "I/O error (" + StringifyInt(retval_i) + ")";
320  else
321  result = hash.ToString();
323  }
324  return result;
325 }
326 
328  QuotaManager *quota_mgr =
331  return StringifyInt(-1);
332  } else {
333  const uint64_t period_s = 24 * 60 * 60;
334  const uint64_t rate = quota_mgr->GetCleanupRate(period_s);
335  return StringifyInt(rate);
336  }
337 }
338 
341  return true;
342 }
343 
345  return StringifyInt(n_catalogs_);
346 }
347 
350 }
351 
353  return mount_point_->statistics()->Lookup("fetch.n_downloads")->Print();
354 }
355 
357  return mount_point_->file_system()->n_io_error()->ToString();;
358 }
359 
361  return mount_point_->file_system()->n_fs_open()->ToString();
362 }
363 
365  int64_t n_invocations =
366  mount_point_->statistics()->Lookup("fetch.n_invocations")->Get();
367  if (n_invocations == 0)
368  return "n/a";
369 
370  int64_t n_downloads =
371  mount_point_->statistics()->Lookup("fetch.n_downloads")->Get();
372  float hitrate = 100. * (1. -
373  (static_cast<float>(n_downloads) / static_cast<float>(n_invocations)));
374  return StringifyDouble(hitrate);
375 }
376 
378  vector< vector<download::DownloadManager::ProxyInfo> > proxy_chain;
379  unsigned current_group;
381  &proxy_chain, &current_group, NULL);
382  if (proxy_chain.size()) {
383  return proxy_chain[current_group][0].url;
384  } else {
385  return "DIRECT";
386  }
387 }
388 
391  return true;
392 }
393 
395  return pubkeys_;
396 }
397 
399  return dirent_->IsLink();
400 }
401 
403  return dirent_->symlink().ToString();
404 }
405 
408  return true;
409 }
410 
412  return counters_.GetCsvMap();
413 }
414 
416 
418  if (!mount_point_->catalog_mgr()->manifest()) {
419  error_reason_ = "manifest not available";
420  return true;
421  }
422 
424  if (metainfo_hash_.IsNull()) {
425  error_reason_ = "metainfo not available";
426  return true;
427  }
428  return true;
429 }
430 
432  if (metainfo_hash_.IsNull()) {
433  return error_reason_;
434  }
435 
436  int fd = mount_point_->fetcher()->
438  "metainfo (" + metainfo_hash_.ToString() + ")",
440  if (fd < 0) {
441  return "Failed to open metadata file";
442  }
443  uint64_t actual_size = mount_point_->file_system()->cache_mgr()->GetSize(fd);
444  if (actual_size > kMaxMetainfoLength) {
446  return "Failed to open: metadata file is too big";
447  }
448  char buffer[kMaxMetainfoLength];
449  int bytes_read =
450  mount_point_->file_system()->cache_mgr()->Pread(fd, buffer, actual_size, 0);
452  if (bytes_read < 0) {
453  return "Failed to read metadata file";
454  }
455  return string(buffer, buffer + bytes_read);
456 }
457 
460  return true;
461 }
462 
464  return StringifyUint(revision_);
465 }
466 
469  return true;
470 }
471 
473  return root_hash_.ToString();
474 }
475 
476 std::string RxMagicXattr::GetValue() {
477  perf::Statistics *statistics = mount_point_->statistics();
478  int64_t rx = statistics->Lookup("download.sz_transferred_bytes")->Get();
479  return StringifyInt(rx/1024);
480 }
481 
483  perf::Statistics *statistics = mount_point_->statistics();
484  int64_t rx = statistics->Lookup("download.sz_transferred_bytes")->Get();
485  int64_t time = statistics->Lookup("download.sz_transfer_time")->Get();
486  if (time == 0)
487  return "n/a";
488  else
489  return StringifyInt((1000 * (rx/1024))/time);
490 }
491 
494  return true;
495 }
496 
497 std::string TagMagicXattr::GetValue() {
498  return tag_;
499 }
500 
502  unsigned seconds, seconds_direct;
503  mount_point_->download_mgr()->GetTimeout(&seconds, &seconds_direct);
504  return StringifyUint(seconds);
505 }
506 
508  unsigned seconds, seconds_direct;
509  mount_point_->download_mgr()->GetTimeout(&seconds, &seconds_direct);
510  return StringifyUint(seconds_direct);
511 }
512 
515 }
516 
519 }
520 
522  return std::string(VERSION) + "." + std::string(CVMFS_PATCH_LEVEL);
523 }
#define LogCvmfs(source, mask,...)
Definition: logging.h:20
std::string ToString()
Definition: statistics.cc:24
int ChecksumFd(int fd, shash::Any *id)
Definition: cache.cc:39
virtual std::string GetValue()
Definition: magic_xattr.cc:327
bool IsExternalFile() const
const Counters & GetCounters() const
Definition: catalog.h:175
perf::Counter * n_io_error()
Definition: mountpoint.h:198
bool IsNull() const
Definition: hash.h:379
MagicXattrManager(MountPoint *mountpoint, bool hide_magic_xattrs)
Definition: magic_xattr.cc:19
virtual int64_t GetSize(int fd)=0
FileSystem * file_system()
Definition: mountpoint.h:422
MagicXattrFlavor
Definition: magic_xattr.h:19
Item At(const size_t index) const
Definition: bigvector.h:50
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:155
virtual std::string GetValue()
Definition: magic_xattr.cc:476
cvmfs::Fetcher * fetcher()
Definition: mountpoint.h:418
std::string subcatalog_path_
Definition: magic_xattr.h:166
virtual uint64_t GetCleanupRate(uint64_t period_s)=0
bool IsChunkedFile() const
perf::Statistics * statistics()
Definition: mountpoint.h:438
void Register(const std::string &name, BaseMagicXattr *magic_xattr)
Definition: magic_xattr.cc:118
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:467
std::string Print()
Definition: statistics.cc:25
#define PANIC(...)
Definition: exception.h:26
virtual std::string GetValue()
Definition: magic_xattr.cc:148
uint64_t size() const
std::string ToString(const bool with_suffix=false) const
Definition: hash.h:245
virtual std::string GetValue()
Definition: magic_xattr.cc:482
virtual std::string GetValue()
Definition: magic_xattr.cc:239
std::string fqrn() const
Definition: mountpoint.h:420
catalog::Counters counters_
Definition: magic_xattr.h:167
BaseMagicXattr * GetLocked(const std::string &name, PathString path, catalog::DirectoryEntry *d)
Definition: magic_xattr.cc:102
virtual std::string GetValue()
Definition: magic_xattr.cc:501
std::string error_reason_
Definition: magic_xattr.h:290
virtual std::string GetValue()
Definition: magic_xattr.cc:411
const shash::Any & content_hash() const
Definition: file_chunk.h:41
shash::Any root_hash_
Definition: magic_xattr.h:304
virtual std::string GetValue()
Definition: magic_xattr.cc:252
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:492
std::string AlgorithmName(const zlib::Algorithms alg)
Definition: compression.cc:158
MountPoint * mount_point_
Definition: cvmfs.cc:121
virtual std::string GetValue()
Definition: magic_xattr.cc:517
bool IsDirectIo() const
catalog::DirectoryEntry * dirent_
Definition: magic_xattr.h:78
Algorithms algorithm
Definition: hash.h:123
virtual std::string GetValue()
Definition: magic_xattr.cc:211
virtual int Open(const BlessedObject &object)=0
string StringifyDouble(const double value)
Definition: string.cc:96
virtual std::string GetValue()
Definition: magic_xattr.cc:282
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:215
std::string StringifyUint(const uint64_t value)
Definition: string.cc:84
virtual std::string GetValue()
Definition: magic_xattr.cc:304
shash::Any checksum() const
MountPoint * mount_point_
Definition: magic_xattr.h:76
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:142
bool has_membership_req()
Definition: mountpoint.h:424
std::string description
Definition: cache.h:97
std::string chunk_list_
Definition: magic_xattr.h:174
virtual std::string GetValue()
Definition: magic_xattr.cc:134
static uint64_t kMaxMetainfoLength
Definition: magic_xattr.h:287
MountPoint * mount_point_
Definition: magic_xattr.h:155
virtual std::string GetValue()
Definition: magic_xattr.cc:364
perf::Counter * n_fs_open()
Definition: mountpoint.h:194
std::string membership_req()
Definition: mountpoint.h:433
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:339
std::string GetListString(catalog::DirectoryEntry *dirent)
Definition: magic_xattr.cc:67
virtual std::string GetValue()
Definition: magic_xattr.cc:235
std::string GetActivePubkeys() const
Definition: signature.cc:357
Counter * Lookup(const std::string &name) const
Definition: statistics.cc:62
virtual std::string GetValue()
Definition: magic_xattr.cc:463
bool IsLink() const
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:458
void GetProxyInfo(std::vector< std::vector< ProxyInfo > > *proxy_chain, unsigned *current_group, unsigned *fallback_group)
Definition: download.cc:2583
std::string repository_tag()
Definition: mountpoint.h:436
catalog::ClientCatalogManager * catalog_mgr()
Definition: mountpoint.h:409
bool IsRegular() const
virtual std::string GetValue()
Definition: magic_xattr.cc:497
virtual std::string GetValue()
Definition: magic_xattr.cc:258
ObjectType type
Definition: cache.h:93
virtual std::string GetValue()
Definition: magic_xattr.cc:360
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:406
perf::Counter * no_open_dirs()
Definition: mountpoint.h:201
virtual std::string GetValue()
Definition: magic_xattr.cc:513
Failures Fetch(const std::string &base_url, const std::string &repository_name, const uint64_t minimum_timestamp, const shash::Any *base_catalog, signature::SignatureManager *signature_manager, download::DownloadManager *download_manager, ManifestEnsemble *ensemble)
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:300
off_t offset() const
Definition: file_chunk.h:42
zlib::Algorithms compression_algorithm() const
CacheManager * cache_mgr()
Definition: mountpoint.h:174
perf::Counter * no_open_files()
Definition: mountpoint.h:202
virtual std::string GetValue()
Definition: magic_xattr.cc:266
LinkString symlink() const
download::DownloadManager * download_mgr()
Definition: mountpoint.h:411
bool hide_magic_xattrs()
Definition: magic_xattr.h:151
virtual std::string GetValue()
Definition: magic_xattr.cc:521
virtual std::string GetValue()
Definition: magic_xattr.cc:472
string StringifyInt(const int64_t value)
Definition: string.cc:78
virtual std::string GetValue()
Definition: magic_xattr.cc:348
virtual int Close(int fd)=0
virtual std::string GetValue()
Definition: magic_xattr.cc:352
shash::Algorithms hash_algorithm() const
perf::Counter * n_fs_dir_open()
Definition: mountpoint.h:190
virtual std::string GetValue()
Definition: magic_xattr.cc:377
int64_t Get()
Definition: statistics.h:32
virtual std::string GetValue()
Definition: magic_xattr.cc:356
CatalogT * GetRootCatalog() const
Definition: catalog_mgr.h:192
std::string tag_
Definition: magic_xattr.h:319
bool IsEmpty() const
Definition: bigvector.h:67
static BlessedObject Bless(const shash::Any &id)
Definition: cache.h:125
shash::Any metainfo_hash_
Definition: magic_xattr.h:289
signature::SignatureManager * signature_mgr()
Definition: mountpoint.h:439
uint64_t n_chunks_
Definition: magic_xattr.h:181
virtual std::string GetValue()
Definition: magic_xattr.cc:184
std::string ToString() const
Definition: shortstring.h:114
virtual std::string GetValue()
Definition: magic_xattr.cc:431
QuotaManager * quota_mgr()
Definition: cache.h:198
virtual std::string GetValue()
Definition: magic_xattr.cc:344
virtual std::string GetValue()
Definition: magic_xattr.cc:270
PathString path_
Definition: magic_xattr.h:77
virtual std::string GetValue()
Definition: magic_xattr.cc:219
bool ListFileChunks(const PathString &path, const shash::Algorithms interpret_hashes_as, FileChunkList *chunks)
size_t size() const
Definition: file_chunk.h:43
std::map< std::string, BaseMagicXattr * > xattr_list_
Definition: magic_xattr.h:154
catalog::Counters LookupCounters(const PathString &path, std::string *subcatalog_path)
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:262
void GetTimeout(unsigned *seconds_proxy, unsigned *seconds_direct)
Definition: download.cc:1895
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:417
virtual std::string GetValue()
Definition: magic_xattr.cc:227
catalog::Counters counters_
Definition: magic_xattr.h:280
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:389
virtual MagicXattrFlavor GetXattrFlavor()
Definition: magic_xattr.cc:138
std::string pubkeys_
Definition: magic_xattr.h:268
manifest::Manifest * manifest() const
virtual std::string GetValue()
Definition: magic_xattr.cc:507
void Lock(PathString path, catalog::DirectoryEntry *dirent)
Definition: magic_xattr.h:62
std::string GetCsvMap() const
const char * c_str() const
Definition: shortstring.h:118
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:188
void GetHostInfo(std::vector< std::string > *host_chain, std::vector< int > *rtt, unsigned *current_host)
Definition: download.cc:1939
virtual std::string GetValue()
Definition: magic_xattr.cc:394
virtual int64_t Pread(int fd, void *buf, uint64_t size, uint64_t offset)=0
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:223
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:231
shash::Any meta_info() const
Definition: manifest.h:131
virtual bool HasCapability(Capabilities capability)=0
static const uint64_t kSizeUnknown
Definition: cache.h:72
size_t size() const
Definition: bigvector.h:100
download::DownloadManager * external_download_mgr()
Definition: mountpoint.h:412
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:130