]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MClientLease.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / messages / MClientLease.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
16 #ifndef CEPH_MCLIENTLEASE_H
17 #define CEPH_MCLIENTLEASE_H
18
19 #include <string_view>
20
21 #include "msg/Message.h"
22
23 class MClientLease : public SafeMessage {
24 public:
25 struct ceph_mds_lease h;
26 std::string dname;
27
28 int get_action() const { return h.action; }
29 ceph_seq_t get_seq() const { return h.seq; }
30 int get_mask() const { return h.mask; }
31 inodeno_t get_ino() const { return inodeno_t(h.ino); }
32 snapid_t get_first() const { return snapid_t(h.first); }
33 snapid_t get_last() const { return snapid_t(h.last); }
34
35 protected:
36 MClientLease() : SafeMessage(CEPH_MSG_CLIENT_LEASE) {}
37 MClientLease(const MClientLease& m) :
38 SafeMessage(CEPH_MSG_CLIENT_LEASE),
39 h(m.h),
40 dname(m.dname) {}
41 MClientLease(int ac, ceph_seq_t seq, int m, uint64_t i, uint64_t sf, uint64_t sl) :
42 SafeMessage(CEPH_MSG_CLIENT_LEASE) {
43 h.action = ac;
44 h.seq = seq;
45 h.mask = m;
46 h.ino = i;
47 h.first = sf;
48 h.last = sl;
49 h.duration_ms = 0;
50 }
51 MClientLease(int ac, ceph_seq_t seq, int m, uint64_t i, uint64_t sf, uint64_t sl, std::string_view d) :
52 SafeMessage(CEPH_MSG_CLIENT_LEASE),
53 dname(d) {
54 h.action = ac;
55 h.seq = seq;
56 h.mask = m;
57 h.ino = i;
58 h.first = sf;
59 h.last = sl;
60 h.duration_ms = 0;
61 }
62 ~MClientLease() override {}
63
64 public:
65 std::string_view get_type_name() const override { return "client_lease"; }
66 void print(ostream& out) const override {
67 out << "client_lease(a=" << ceph_lease_op_name(get_action())
68 << " seq " << get_seq()
69 << " mask " << get_mask();
70 out << " " << get_ino();
71 if (h.last != CEPH_NOSNAP)
72 out << " [" << snapid_t(h.first) << "," << snapid_t(h.last) << "]";
73 if (dname.length())
74 out << "/" << dname;
75 out << ")";
76 }
77
78 void decode_payload() override {
79 auto p = payload.cbegin();
80 decode(h, p);
81 decode(dname, p);
82 }
83 void encode_payload(uint64_t features) override {
84 using ceph::encode;
85 encode(h, payload);
86 encode(dname, payload);
87 }
88
89 private:
90 template<class T, typename... Args>
91 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
92 };
93
94 #endif