]> git.proxmox.com Git - ceph.git/blame_incremental - ceph/src/messages/MClientSession.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / messages / MClientSession.h
... / ...
CommitLineData
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_MCLIENTSESSION_H
16#define CEPH_MCLIENTSESSION_H
17
18#include "msg/Message.h"
19#include "mds/mdstypes.h"
20
21class MClientSession final : public SafeMessage {
22private:
23 static constexpr int HEAD_VERSION = 5;
24 static constexpr int COMPAT_VERSION = 1;
25
26public:
27 ceph_mds_session_head head;
28 static constexpr unsigned SESSION_BLOCKLISTED = (1<<0);
29
30 unsigned flags = 0;
31 std::map<std::string, std::string> metadata;
32 feature_bitset_t supported_features;
33 metric_spec_t metric_spec;
34
35 int get_op() const { return head.op; }
36 version_t get_seq() const { return head.seq; }
37 utime_t get_stamp() const { return utime_t(head.stamp); }
38 int get_max_caps() const { return head.max_caps; }
39 int get_max_leases() const { return head.max_leases; }
40
41protected:
42 MClientSession() : SafeMessage{CEPH_MSG_CLIENT_SESSION, HEAD_VERSION, COMPAT_VERSION} { }
43 MClientSession(int o, version_t s=0, unsigned msg_flags=0) :
44 SafeMessage{CEPH_MSG_CLIENT_SESSION, HEAD_VERSION, COMPAT_VERSION},
45 flags(msg_flags) {
46 memset(&head, 0, sizeof(head));
47 head.op = o;
48 head.seq = s;
49 }
50 MClientSession(int o, utime_t st) :
51 SafeMessage{CEPH_MSG_CLIENT_SESSION, HEAD_VERSION, COMPAT_VERSION} {
52 memset(&head, 0, sizeof(head));
53 head.op = o;
54 head.seq = 0;
55 st.encode_timeval(&head.stamp);
56 }
57 ~MClientSession() final {}
58
59public:
60 std::string_view get_type_name() const override { return "client_session"; }
61 void print(std::ostream& out) const override {
62 out << "client_session(" << ceph_session_op_name(get_op());
63 if (get_seq())
64 out << " seq " << get_seq();
65 if (get_op() == CEPH_SESSION_RECALL_STATE)
66 out << " max_caps " << head.max_caps << " max_leases " << head.max_leases;
67 out << ")";
68 }
69
70 void decode_payload() override {
71 using ceph::decode;
72 auto p = payload.cbegin();
73 decode(head, p);
74 if (header.version >= 2)
75 decode(metadata, p);
76 if (header.version >= 3)
77 decode(supported_features, p);
78 if (header.version >= 4) {
79 decode(metric_spec, p);
80 }
81 if (header.version >= 5) {
82 decode(flags, p);
83 }
84 }
85 void encode_payload(uint64_t features) override {
86 using ceph::encode;
87 encode(head, payload);
88 if (metadata.empty() && supported_features.empty()) {
89 // If we're not trying to send any metadata (always the case if
90 // we are a server) then send older-format message to avoid upsetting
91 // old kernel clients.
92 header.version = 1;
93 } else {
94 header.version = HEAD_VERSION;
95 encode(metadata, payload);
96 encode(supported_features, payload);
97 encode(metric_spec, payload);
98 encode(flags, payload);
99 }
100 }
101private:
102 template<class T, typename... Args>
103 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
104 template<class T, typename... Args>
105 friend MURef<T> crimson::make_message(Args&&... args);
106};
107
108#endif