CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
magic_xattr.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_MAGIC_XATTR_H_
6 #define CVMFS_MAGIC_XATTR_H_
7 
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <utility>
12 #include <vector>
13 
14 #include "backoff.h"
15 #include "catalog_counters.h"
16 #include "directory_entry.h"
17 #include "shortstring.h"
18 #include "util/exception.h"
19 #include "util/string.h"
20 
21 class MountPoint;
22 
30 };
31 
35 };
36 
37 class MagicXattrManager; // needed for BaseMagicXattr
67  friend class MagicXattrManager;
68  FRIEND_TEST(T_MagicXattr, ProtectedXattr);
69  FRIEND_TEST(T_MagicXattr, TestFqrn);
70  FRIEND_TEST(T_MagicXattr, TestLogBuffer);
71 
72  public:
74  int retval = pthread_mutex_init(&access_mutex_, NULL);
75  assert(retval == 0);
76  }
77 
82  void MarkProtected() {
83  is_protected_ = true;
84  }
85 
86 
87  // TODO(hereThereBeDragons) from C++11 should be marked final
91  bool PrepareValueFencedProtected(gid_t gid);
92 
118  std::pair<bool, std::string> GetValue(int32_t requested_page,
119  const MagicXattrMode mode);
120 
122 
124  int retval = pthread_mutex_lock(&access_mutex_);
125  assert(retval == 0);
126  path_ = path;
127  dirent_ = dirent;
128  }
129  void Release() {
130  int retval = pthread_mutex_unlock(&access_mutex_);
131  assert(retval == 0);
132  }
133 
134  virtual ~BaseMagicXattr() {}
135 
136  // how many chars per page (with some leeway). system maximum would be 64k
137  static const uint32_t kMaxCharsPerPage = 40000;
138 
139  protected:
144  virtual bool PrepareValueFenced() { return true; }
145  virtual void FinalizeValue() {}
146 
147  std::string HeaderMultipageHuman(uint32_t requested_page);
148 
152 
153  pthread_mutex_t access_mutex_;
155  std::vector<std::string> result_pages_;
156 };
157 
163  public:
164  inline MagicXattrRAIIWrapper() : ptr_(NULL) { }
165 
166  inline explicit MagicXattrRAIIWrapper(
167  BaseMagicXattr *ptr,
168  PathString path,
170  : ptr_(ptr)
171  {
172  if (ptr_ != NULL) ptr_->Lock(path, d);
173  }
175  inline explicit MagicXattrRAIIWrapper(BaseMagicXattr *ptr) : ptr_(ptr) { }
176 
177  inline ~MagicXattrRAIIWrapper() { if (ptr_ != NULL) ptr_->Release(); }
178 
179  inline BaseMagicXattr* operator->() const { return ptr_; }
180  inline bool IsNull() const { return ptr_ == NULL; }
181  inline BaseMagicXattr* Move() {
182  BaseMagicXattr* ret = ptr_;
183  ptr_ = NULL;
184  return ret;
185  }
186 
187  protected:
189 };
190 
193 };
194 
197 };
198 
201 };
202 
205 };
206 
221  public:
223 
225  const std::set<std::string> &protected_xattrs,
226  const std::set<gid_t> &privileged_xattr_gids);
229  BaseMagicXattr* GetLocked(const std::string &name, PathString path,
231  std::string GetListString(catalog::DirectoryEntry *dirent);
236  void Register(const std::string &name, BaseMagicXattr *magic_xattr);
237 
245  bool IsPrivilegedGid(gid_t gid);
246 
247 
249  std::set<gid_t> privileged_xattr_gids()
250  { return privileged_xattr_gids_; }
252  bool is_frozen() const { return is_frozen_; }
253 
254  protected:
255  std::map<std::string, BaseMagicXattr *> xattr_list_;
258 
259  // privileged_xattr_gids_ contains the (fuse) gids that
260  // can access xattrs that are part of protected_xattrs_
261  const std::set<std::string> protected_xattrs_;
262  const std::set<gid_t> privileged_xattr_gids_;
263 
264  private:
266 
268 };
269 
271  virtual bool PrepareValueFenced();
272  virtual void FinalizeValue();
273 
275 };
276 
278  std::string subcatalog_path_;
281 
282  virtual bool PrepareValueFenced();
283  virtual void FinalizeValue();
284 };
285 
287  virtual bool PrepareValueFenced();
288  virtual void FinalizeValue();
289 
290  private:
291  std::vector<std::string> chunk_list_;
292 };
293 
295  uint64_t n_chunks_;
296 
297  virtual bool PrepareValueFenced();
298  virtual void FinalizeValue();
299 };
300 
302  virtual bool PrepareValueFenced();
303  virtual void FinalizeValue();
304 };
305 
307  virtual bool PrepareValueFenced();
308  virtual void FinalizeValue();
309 };
310 
312  virtual bool PrepareValueFenced();
313  virtual void FinalizeValue();
314 };
315 
317  virtual void FinalizeValue();
318 };
319 
321  virtual void FinalizeValue();
322 };
323 
325  virtual void FinalizeValue();
326 };
327 
329  virtual bool PrepareValueFenced();
330  virtual void FinalizeValue();
331 };
332 
334  virtual void FinalizeValue();
335 };
336 
338  virtual void FinalizeValue();
339 };
340 
342  virtual bool PrepareValueFenced();
343  virtual void FinalizeValue();
344 };
345 
347  public:
348  LogBufferXattr();
349 
350  private:
351  const unsigned int kMaxLogLine = 4096; // longer log lines are trimmed
352  // Generating the log buffer report involves 64 string copies. To mitigate
353  // memory fragmentation and performance loss, throttle the use of this
354  // attribute a little.
356 
357  virtual void FinalizeValue();
358 };
359 
361  virtual void FinalizeValue();
362 };
363 
366 
367  virtual bool PrepareValueFenced();
368  virtual void FinalizeValue();
369 };
370 
372  virtual void FinalizeValue();
373 };
374 
376  virtual void FinalizeValue();
377 };
378 
380  virtual void FinalizeValue();
381 };
382 
384  virtual void FinalizeValue();
385 };
386 
388  virtual void FinalizeValue();
389 };
390 
392  virtual void FinalizeValue();
393 };
394 
396  virtual void FinalizeValue();
397 };
398 
400  virtual void FinalizeValue();
401 };
402 
404  FRIEND_TEST(T_MagicXattr, MultiPageMachineModeXattr);
405  FRIEND_TEST(T_MagicXattr, MultiPageHumanModeXattr);
406 
407  std::vector<std::string> pubkeys_;
408 
409  virtual bool PrepareValueFenced();
410  virtual void FinalizeValue();
411 };
412 
414  virtual bool PrepareValueFenced();
415  virtual void FinalizeValue();
416 };
417 
420 
421  virtual bool PrepareValueFenced();
422  virtual void FinalizeValue();
423 };
424 
426  static uint64_t kMaxMetainfoLength;
427 
429  std::string error_reason_;
430 
431  virtual bool PrepareValueFenced();
432  virtual void FinalizeValue();
433 };
434 
436  uint64_t revision_;
437 
438  virtual bool PrepareValueFenced();
439  virtual void FinalizeValue();
440 };
441 
444 
445  virtual bool PrepareValueFenced();
446  virtual void FinalizeValue();
447 };
448 
449 class RxMagicXattr : public BaseMagicXattr {
450  virtual void FinalizeValue();
451 };
452 
454  virtual void FinalizeValue();
455 };
456 
458  std::string tag_;
459 
460  virtual bool PrepareValueFenced();
461  virtual void FinalizeValue();
462 };
463 
465  virtual void FinalizeValue();
466 };
467 
469  virtual void FinalizeValue();
470 };
471 
473  virtual void FinalizeValue();
474 };
475 
477  virtual void FinalizeValue();
478 };
479 
481  virtual void FinalizeValue();
482 };
483 
485  virtual void FinalizeValue();
486 };
487 
489  virtual bool PrepareValueFenced();
490  virtual void FinalizeValue();
491 };
492 
493 #endif // CVMFS_MAGIC_XATTR_H_
const std::set< gid_t > privileged_xattr_gids_
Definition: magic_xattr.h:262
virtual void FinalizeValue()
Definition: magic_xattr.cc:406
MagicXattrFlavor
Definition: magic_xattr.h:23
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:274
bool PrepareValueFencedProtected(gid_t gid)
Definition: magic_xattr.cc:158
virtual void FinalizeValue()
Definition: magic_xattr.cc:581
bool IsNull() const
Definition: magic_xattr.h:180
virtual void FinalizeValue()
Definition: magic_xattr.cc:708
std::string subcatalog_path_
Definition: magic_xattr.h:278
virtual void FinalizeValue()
Definition: magic_xattr.cc:734
virtual void FinalizeValue()
Definition: magic_xattr.cc:374
void Register(const std::string &name, BaseMagicXattr *magic_xattr)
Definition: magic_xattr.cc:135
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:699
pthread_mutex_t access_mutex_
Definition: magic_xattr.h:153
MountPoint * mount_point()
Definition: magic_xattr.h:251
virtual void FinalizeValue()
Definition: magic_xattr.cc:695
virtual void FinalizeValue()
Definition: magic_xattr.cc:763
BaseMagicXattr * ptr_
Definition: magic_xattr.h:188
virtual MagicXattrFlavor GetXattrFlavor()
Definition: magic_xattr.h:192
virtual void FinalizeValue()
Definition: magic_xattr.cc:353
std::set< gid_t > privileged_xattr_gids()
Definition: magic_xattr.h:249
virtual void FinalizeValue()
Definition: magic_xattr.cc:768
catalog::Counters counters_
Definition: magic_xattr.h:280
void MarkProtected()
Definition: magic_xattr.h:82
BaseMagicXattr * GetLocked(const std::string &name, PathString path, catalog::DirectoryEntry *d)
Definition: magic_xattr.cc:119
virtual void FinalizeValue()
Definition: magic_xattr.cc:250
const std::set< std::string > protected_xattrs_
Definition: magic_xattr.h:261
virtual void FinalizeValue()
Definition: magic_xattr.cc:542
std::string error_reason_
Definition: magic_xattr.h:429
virtual void FinalizeValue()
Definition: magic_xattr.cc:394
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:784
shash::Any root_hash_
Definition: magic_xattr.h:443
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:725
virtual void FinalizeValue()
Definition: magic_xattr.cc:730
assert((mem||(size==0))&&"Out Of Memory")
virtual void FinalizeValue()
Definition: magic_xattr.cc:577
catalog::DirectoryEntry * dirent_
Definition: magic_xattr.h:151
BaseMagicXattr * operator->() const
Definition: magic_xattr.h:179
std::vector< std::string > chunk_list_
Definition: magic_xattr.h:291
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:349
bool IsPrivilegedGid(gid_t gid)
Definition: magic_xattr.cc:154
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:258
virtual void FinalizeValue()
Definition: magic_xattr.cc:741
static uint64_t kMaxMetainfoLength
Definition: magic_xattr.h:426
MagicXattrMode
Definition: magic_xattr.h:32
MountPoint * mount_point_
Definition: magic_xattr.h:256
BaseMagicXattr * Move()
Definition: magic_xattr.h:181
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:497
MagicXattrManager * xattr_mgr_
Definition: magic_xattr.h:149
std::string GetListString(catalog::DirectoryEntry *dirent)
Definition: magic_xattr.cc:77
MagicXattrRAIIWrapper(BaseMagicXattr *ptr, PathString path, catalog::DirectoryEntry *d)
Definition: magic_xattr.h:166
static const uint32_t kMaxCharsPerPage
Definition: magic_xattr.h:137
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:690
virtual void FinalizeValue()
Definition: magic_xattr.cc:387
virtual void FinalizeValue()
Definition: magic_xattr.cc:591
virtual void FinalizeValue()
Definition: magic_xattr.cc:362
std::string HeaderMultipageHuman(uint32_t requested_page)
Definition: magic_xattr.cc:198
bool is_frozen() const
Definition: magic_xattr.h:252
virtual MagicXattrFlavor GetXattrFlavor()
Definition: magic_xattr.h:200
virtual void FinalizeValue()
Definition: magic_xattr.cc:442
virtual void FinalizeValue()
Definition: magic_xattr.cc:655
virtual void FinalizeValue()
Definition: magic_xattr.cc:511
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:628
EVisibility visibility()
Definition: magic_xattr.h:248
FRIEND_TEST(T_MagicXattr, MultiPageMachineModeXattr)
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:438
virtual void FinalizeValue()
Definition: magic_xattr.cc:468
virtual void FinalizeValue()
Definition: magic_xattr.cc:758
virtual void FinalizeValue()
Definition: magic_xattr.cc:318
virtual void FinalizeValue()
Definition: magic_xattr.cc:704
virtual void FinalizeValue()
Definition: magic_xattr.cc:753
std::pair< bool, std::string > GetValue(int32_t requested_page, const MagicXattrMode mode)
Definition: magic_xattr.cc:205
FRIEND_TEST(T_MagicXattr, ProtectedXattr)
virtual void FinalizeValue()
Definition: magic_xattr.cc:526
const unsigned int kMaxLogLine
Definition: magic_xattr.h:351
virtual void FinalizeValue()
Definition: magic_xattr.cc:634
virtual void FinalizeValue()
Definition: magic_xattr.cc:485
virtual void FinalizeValue()
Definition: magic_xattr.cc:714
virtual void FinalizeValue()
Definition: magic_xattr.cc:265
virtual void FinalizeValue()
Definition: magic_xattr.cc:506
virtual void FinalizeValue()
Definition: magic_xattr.cc:521
virtual void FinalizeValue()
Definition: magic_xattr.cc:370
virtual void FinalizeValue()
Definition: magic_xattr.cc:419
std::string tag_
Definition: magic_xattr.h:458
MagicXattrRAIIWrapper(BaseMagicXattr *ptr)
Wraps around a BaseMagicXattr* that is already locked (or NULL)
Definition: magic_xattr.h:175
MagicXattrManager(MountPoint *mountpoint, EVisibility visibility, const std::set< std::string > &protected_xattrs, const std::set< gid_t > &privileged_xattr_gids)
Definition: magic_xattr.cc:19
EVisibility visibility_
Definition: magic_xattr.h:257
virtual void FinalizeValue()
Definition: magic_xattr.cc:345
shash::Any metainfo_hash_
Definition: magic_xattr.h:428
BackoffThrottle throttle_
Definition: magic_xattr.h:355
uint64_t n_chunks_
Definition: magic_xattr.h:295
std::vector< std::string > pubkeys_
Definition: magic_xattr.h:407
PathString path_
Definition: magic_xattr.h:150
virtual void FinalizeValue()
Definition: magic_xattr.h:145
std::map< std::string, BaseMagicXattr * > xattr_list_
Definition: magic_xattr.h:255
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:398
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:640
virtual void FinalizeValue()
Definition: magic_xattr.cc:402
virtual bool PrepareValueFenced()
Definition: magic_xattr.h:144
virtual ~BaseMagicXattr()
Definition: magic_xattr.h:134
catalog::Counters counters_
Definition: magic_xattr.h:419
virtual void FinalizeValue()
Definition: magic_xattr.cc:502
virtual MagicXattrFlavor GetXattrFlavor()
Definition: magic_xattr.h:121
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:585
virtual MagicXattrFlavor GetXattrFlavor()
Definition: magic_xattr.cc:254
void Lock(PathString path, catalog::DirectoryEntry *dirent)
Definition: magic_xattr.h:123
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:322
virtual MagicXattrFlavor GetXattrFlavor()
Definition: magic_xattr.h:196
virtual void FinalizeValue()
Definition: magic_xattr.cc:516
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:358
std::vector< std::string > result_pages_
Definition: magic_xattr.h:155
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:366
void SanityCheckProtectedXattrs()
Definition: magic_xattr.cc:167
virtual bool PrepareValueFenced()
Definition: magic_xattr.cc:246