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