]> git.proxmox.com Git - ceph.git/blame - ceph/src/messages/MClientSession.h
update download target update for octopus release
[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
11fdf7f2
TL
21class MClientSession : public MessageInstance<MClientSession> {
22public:
23 friend factory;
24private:
25 static constexpr int HEAD_VERSION = 3;
26 static constexpr int COMPAT_VERSION = 1;
7c673cae
FG
27
28public:
29 ceph_mds_session_head head;
30
11fdf7f2
TL
31 std::map<std::string, std::string> metadata;
32 feature_bitset_t supported_features;
7c673cae
FG
33
34 int get_op() const { return head.op; }
35 version_t get_seq() const { return head.seq; }
36 utime_t get_stamp() const { return utime_t(head.stamp); }
37 int get_max_caps() const { return head.max_caps; }
38 int get_max_leases() const { return head.max_leases; }
39
11fdf7f2
TL
40protected:
41 MClientSession() : MessageInstance(CEPH_MSG_CLIENT_SESSION, HEAD_VERSION, COMPAT_VERSION) { }
7c673cae 42 MClientSession(int o, version_t s=0) :
11fdf7f2 43 MessageInstance(CEPH_MSG_CLIENT_SESSION, HEAD_VERSION, COMPAT_VERSION) {
7c673cae
FG
44 memset(&head, 0, sizeof(head));
45 head.op = o;
46 head.seq = s;
47 }
48 MClientSession(int o, utime_t st) :
11fdf7f2 49 MessageInstance(CEPH_MSG_CLIENT_SESSION, HEAD_VERSION, COMPAT_VERSION) {
7c673cae
FG
50 memset(&head, 0, sizeof(head));
51 head.op = o;
52 head.seq = 0;
53 st.encode_timeval(&head.stamp);
54 }
7c673cae
FG
55 ~MClientSession() override {}
56
57public:
11fdf7f2 58 std::string_view get_type_name() const override { return "client_session"; }
7c673cae
FG
59 void print(ostream& out) const override {
60 out << "client_session(" << ceph_session_op_name(get_op());
61 if (get_seq())
62 out << " seq " << get_seq();
63 if (get_op() == CEPH_SESSION_RECALL_STATE)
64 out << " max_caps " << head.max_caps << " max_leases " << head.max_leases;
65 out << ")";
66 }
67
68 void decode_payload() override {
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);
7c673cae
FG
75 }
76 void encode_payload(uint64_t features) override {
11fdf7f2
TL
77 using ceph::encode;
78 encode(head, payload);
79 if (metadata.empty() && supported_features.empty()) {
7c673cae
FG
80 // If we're not trying to send any metadata (always the case if
81 // we are a server) then send older-format message to avoid upsetting
82 // old kernel clients.
83 header.version = 1;
84 } else {
7c673cae 85 header.version = HEAD_VERSION;
11fdf7f2
TL
86 encode(metadata, payload);
87 encode(supported_features, payload);
7c673cae 88 }
7c673cae
FG
89 }
90};
91
92#endif