]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_SNAPCLIENT_H | |
16 | #define CEPH_SNAPCLIENT_H | |
17 | ||
11fdf7f2 | 18 | #include <string_view> |
94b18763 | 19 | |
7c673cae FG |
20 | #include "MDSTableClient.h" |
21 | #include "snap.h" | |
11fdf7f2 | 22 | #include "MDSContext.h" |
7c673cae | 23 | |
7c673cae FG |
24 | class MDSRank; |
25 | class LogSegment; | |
26 | ||
27 | class SnapClient : public MDSTableClient { | |
28 | public: | |
11fdf7f2 | 29 | explicit SnapClient(MDSRank *m) : |
9f95a23c | 30 | MDSTableClient(m, TABLE_SNAP) {} |
7c673cae | 31 | |
11fdf7f2 | 32 | void resend_queries() override; |
9f95a23c TL |
33 | void handle_query_result(const cref_t<MMDSTableRequest> &m) override; |
34 | void handle_notify_prep(const cref_t<MMDSTableRequest> &m) override; | |
11fdf7f2 | 35 | void notify_commit(version_t tid) override; |
7c673cae | 36 | |
11fdf7f2 TL |
37 | void prepare_create(inodeno_t dirino, std::string_view name, utime_t stamp, |
38 | version_t *pstid, bufferlist *pbl, MDSContext *onfinish) { | |
7c673cae FG |
39 | bufferlist bl; |
40 | __u32 op = TABLE_OP_CREATE; | |
11fdf7f2 TL |
41 | encode(op, bl); |
42 | encode(dirino, bl); | |
43 | encode(name, bl); | |
44 | encode(stamp, bl); | |
7c673cae FG |
45 | _prepare(bl, pstid, pbl, onfinish); |
46 | } | |
47 | ||
11fdf7f2 | 48 | void prepare_create_realm(inodeno_t ino, version_t *pstid, bufferlist *pbl, MDSContext *onfinish) { |
7c673cae FG |
49 | bufferlist bl; |
50 | __u32 op = TABLE_OP_CREATE; | |
11fdf7f2 TL |
51 | encode(op, bl); |
52 | encode(ino, bl); | |
7c673cae FG |
53 | _prepare(bl, pstid, pbl, onfinish); |
54 | } | |
55 | ||
11fdf7f2 | 56 | void prepare_destroy(inodeno_t ino, snapid_t snapid, version_t *pstid, bufferlist *pbl, MDSContext *onfinish) { |
7c673cae FG |
57 | bufferlist bl; |
58 | __u32 op = TABLE_OP_DESTROY; | |
11fdf7f2 TL |
59 | encode(op, bl); |
60 | encode(ino, bl); | |
61 | encode(snapid, bl); | |
7c673cae FG |
62 | _prepare(bl, pstid, pbl, onfinish); |
63 | } | |
64 | ||
11fdf7f2 TL |
65 | void prepare_update(inodeno_t ino, snapid_t snapid, std::string_view name, utime_t stamp, |
66 | version_t *pstid, MDSContext *onfinish) { | |
7c673cae FG |
67 | bufferlist bl; |
68 | __u32 op = TABLE_OP_UPDATE; | |
11fdf7f2 TL |
69 | encode(op, bl); |
70 | encode(ino, bl); | |
71 | encode(snapid, bl); | |
72 | encode(name, bl); | |
73 | encode(stamp, bl); | |
74 | _prepare(bl, pstid, NULL, onfinish); | |
75 | } | |
76 | ||
77 | version_t get_cached_version() const { return cached_version; } | |
78 | void refresh(version_t want, MDSContext *onfinish); | |
79 | ||
80 | void sync(MDSContext *onfinish); | |
81 | ||
82 | bool is_synced() const { return synced; } | |
83 | void wait_for_sync(MDSContext *c) { | |
84 | ceph_assert(!synced); | |
85 | waiting_for_version[std::max<version_t>(cached_version, 1)].push_back(c); | |
7c673cae | 86 | } |
11fdf7f2 TL |
87 | |
88 | snapid_t get_last_created() const { return cached_last_created; } | |
89 | snapid_t get_last_destroyed() const { return cached_last_destroyed; } | |
1e59de90 | 90 | snapid_t get_last_seq() const { return std::max(cached_last_destroyed, cached_last_created); } |
11fdf7f2 | 91 | |
20effc67 TL |
92 | void get_snaps(std::set<snapid_t>& snaps) const; |
93 | std::set<snapid_t> filter(const std::set<snapid_t>& snaps) const; | |
11fdf7f2 | 94 | const SnapInfo* get_snap_info(snapid_t snapid) const; |
20effc67 | 95 | void get_snap_infos(std::map<snapid_t, const SnapInfo*>& infomap, const std::set<snapid_t>& snaps) const; |
11fdf7f2 TL |
96 | |
97 | int dump_cache(Formatter *f) const; | |
7c673cae | 98 | |
9f95a23c TL |
99 | private: |
100 | version_t cached_version = 0; | |
101 | snapid_t cached_last_created = 0, cached_last_destroyed = 0; | |
20effc67 TL |
102 | std::map<snapid_t, SnapInfo> cached_snaps; |
103 | std::map<version_t, SnapInfo> cached_pending_update; | |
104 | std::map<version_t, std::pair<snapid_t,snapid_t> > cached_pending_destroy; | |
9f95a23c | 105 | |
20effc67 | 106 | std::set<version_t> committing_tids; |
9f95a23c | 107 | |
20effc67 | 108 | std::map<version_t, MDSContext::vec > waiting_for_version; |
9f95a23c TL |
109 | |
110 | uint64_t sync_reqid = 0; | |
111 | bool synced = false; | |
112 | }; | |
7c673cae | 113 | #endif |