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