summaryrefslogtreecommitdiffstats
path: root/src/mds/snap.h
blob: f8b5b701af46f22cde7c18a314fdbd43568c9322 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 */

#ifndef CEPH_MDS_SNAP_H
#define CEPH_MDS_SNAP_H

#include <map>
#include <string_view>

#include "mdstypes.h"
#include "common/snap_types.h"

#include "Capability.h"

/*
 * generic snap descriptor.
 */
struct SnapInfo {
  void encode(ceph::buffer::list &bl) const;
  void decode(ceph::buffer::list::const_iterator &bl);
  void dump(ceph::Formatter *f) const;
  static void generate_test_instances(std::list<SnapInfo*>& ls);

  std::string_view get_long_name() const;

  snapid_t snapid;
  inodeno_t ino;
  utime_t stamp;
  std::string name;

  mutable std::string long_name; ///< cached _$ino_$name
  std::map<std::string,std::string> metadata;
};
WRITE_CLASS_ENCODER(SnapInfo)

inline bool operator==(const SnapInfo &l, const SnapInfo &r)
{
  return l.snapid == r.snapid && l.ino == r.ino &&
	 l.stamp == r.stamp && l.name == r.name;
}

std::ostream& operator<<(std::ostream& out, const SnapInfo &sn);

/*
 * SnapRealm - a subtree that shares the same set of snapshots.
 */
struct SnapRealm;

struct snaplink_t {
  void encode(ceph::buffer::list &bl) const;
  void decode(ceph::buffer::list::const_iterator &bl);
  void dump(ceph::Formatter *f) const;
  static void generate_test_instances(std::list<snaplink_t*>& ls);

  inodeno_t ino;
  snapid_t first;
};
WRITE_CLASS_ENCODER(snaplink_t)

std::ostream& operator<<(std::ostream& out, const snaplink_t &l);

// carry data about a specific version of a SnapRealm
struct sr_t {
  void mark_parent_global() { flags |= PARENT_GLOBAL; }
  void clear_parent_global() { flags &= ~PARENT_GLOBAL; }
  bool is_parent_global() const { return flags & PARENT_GLOBAL; }

  void mark_subvolume() { flags |= SUBVOLUME; }
  void clear_subvolume() { flags &= ~SUBVOLUME; }
  bool is_subvolume() const { return flags & SUBVOLUME; }

  void encode(ceph::buffer::list &bl) const;
  void decode(ceph::buffer::list::const_iterator &bl);
  void dump(ceph::Formatter *f) const;
  static void generate_test_instances(std::list<sr_t*>& ls);

  snapid_t seq = 0;                     // basically, a version/seq # for changes to _this_ realm.
  snapid_t created = 0;                 // when this realm was created.
  snapid_t last_created = 0;            // last snap created in _this_ realm.
  snapid_t last_destroyed = 0;          // seq for last removal
  snapid_t current_parent_since = 1;
  std::map<snapid_t, SnapInfo> snaps;
  std::map<snapid_t, snaplink_t> past_parents;  // key is "last" (or NOSNAP)
  std::set<snapid_t> past_parent_snaps;

  __u32 flags = 0;
  enum {
    PARENT_GLOBAL	= 1 << 0,
    SUBVOLUME		= 1 << 1,
  };
};
WRITE_CLASS_ENCODER(sr_t)

class MDCache;
#endif