]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/snap.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / mds / snap.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #ifndef CEPH_MDS_SNAP_H
16 #define CEPH_MDS_SNAP_H
17
18 #include <map>
19 #include <string_view>
20
21 #include "mdstypes.h"
22 #include "common/snap_types.h"
23
24 #include "Capability.h"
25
26 /*
27 * generic snap descriptor.
28 */
29 struct SnapInfo {
30 void encode(ceph::buffer::list &bl) const;
31 void decode(ceph::buffer::list::const_iterator &bl);
32 void dump(ceph::Formatter *f) const;
33 static void generate_test_instances(std::list<SnapInfo*>& ls);
34
35 std::string_view get_long_name() const;
36
37 snapid_t snapid;
38 inodeno_t ino;
39 utime_t stamp;
40 std::string name;
41
42 mutable std::string long_name; ///< cached _$ino_$name
43 std::map<std::string,std::string> metadata;
44 };
45 WRITE_CLASS_ENCODER(SnapInfo)
46
47 inline bool operator==(const SnapInfo &l, const SnapInfo &r)
48 {
49 return l.snapid == r.snapid && l.ino == r.ino &&
50 l.stamp == r.stamp && l.name == r.name;
51 }
52
53 std::ostream& operator<<(std::ostream& out, const SnapInfo &sn);
54
55 /*
56 * SnapRealm - a subtree that shares the same set of snapshots.
57 */
58 struct SnapRealm;
59
60 struct snaplink_t {
61 void encode(ceph::buffer::list &bl) const;
62 void decode(ceph::buffer::list::const_iterator &bl);
63 void dump(ceph::Formatter *f) const;
64 static void generate_test_instances(std::list<snaplink_t*>& ls);
65
66 inodeno_t ino;
67 snapid_t first;
68 };
69 WRITE_CLASS_ENCODER(snaplink_t)
70
71 std::ostream& operator<<(std::ostream& out, const snaplink_t &l);
72
73 // carry data about a specific version of a SnapRealm
74 struct sr_t {
75 void mark_parent_global() { flags |= PARENT_GLOBAL; }
76 void clear_parent_global() { flags &= ~PARENT_GLOBAL; }
77 bool is_parent_global() const { return flags & PARENT_GLOBAL; }
78
79 void mark_subvolume() { flags |= SUBVOLUME; }
80 void clear_subvolume() { flags &= ~SUBVOLUME; }
81 bool is_subvolume() const { return flags & SUBVOLUME; }
82
83 void encode(ceph::buffer::list &bl) const;
84 void decode(ceph::buffer::list::const_iterator &bl);
85 void dump(ceph::Formatter *f) const;
86 static void generate_test_instances(std::list<sr_t*>& ls);
87
88 snapid_t seq = 0; // basically, a version/seq # for changes to _this_ realm.
89 snapid_t created = 0; // when this realm was created.
90 snapid_t last_created = 0; // last snap created in _this_ realm.
91 snapid_t last_destroyed = 0; // seq for last removal
92 snapid_t current_parent_since = 1;
93 std::map<snapid_t, SnapInfo> snaps;
94 std::map<snapid_t, snaplink_t> past_parents; // key is "last" (or NOSNAP)
95 std::set<snapid_t> past_parent_snaps;
96 utime_t last_modified; // timestamp when this realm
97 // was last changed.
98 uint64_t change_attr = 0; // tracks changes to snap
99 // realm attrs.
100
101 __u32 flags = 0;
102 enum {
103 PARENT_GLOBAL = 1 << 0,
104 SUBVOLUME = 1 << 1,
105 };
106 };
107 WRITE_CLASS_ENCODER(sr_t)
108
109 class MDCache;
110 #endif