]> git.proxmox.com Git - ceph.git/blame - ceph/src/mds/SnapClient.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / mds / SnapClient.h
CommitLineData
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
24class MDSRank;
25class LogSegment;
26
27class SnapClient : public MDSTableClient {
28public:
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; }
90
20effc67
TL
91 void get_snaps(std::set<snapid_t>& snaps) const;
92 std::set<snapid_t> filter(const std::set<snapid_t>& snaps) const;
11fdf7f2 93 const SnapInfo* get_snap_info(snapid_t snapid) const;
20effc67 94 void get_snap_infos(std::map<snapid_t, const SnapInfo*>& infomap, const std::set<snapid_t>& snaps) const;
11fdf7f2
TL
95
96 int dump_cache(Formatter *f) const;
7c673cae 97
9f95a23c
TL
98private:
99 version_t cached_version = 0;
100 snapid_t cached_last_created = 0, cached_last_destroyed = 0;
20effc67
TL
101 std::map<snapid_t, SnapInfo> cached_snaps;
102 std::map<version_t, SnapInfo> cached_pending_update;
103 std::map<version_t, std::pair<snapid_t,snapid_t> > cached_pending_destroy;
9f95a23c 104
20effc67 105 std::set<version_t> committing_tids;
9f95a23c 106
20effc67 107 std::map<version_t, MDSContext::vec > waiting_for_version;
9f95a23c
TL
108
109 uint64_t sync_reqid = 0;
110 bool synced = false;
111};
7c673cae 112#endif