Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / messages / MClientSession.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 #ifndef CEPH_MCLIENTSESSION_H
16 #define CEPH_MCLIENTSESSION_H
17
18 #include "msg/Message.h"
19
20 class MClientSession : public Message {
21   static const int HEAD_VERSION = 2;
22   static const int COMPAT_VERSION = 1;
23
24 public:
25   ceph_mds_session_head head;
26
27   std::map<std::string, std::string> client_meta;
28
29   int get_op() const { return head.op; }
30   version_t get_seq() const { return head.seq; }
31   utime_t get_stamp() const { return utime_t(head.stamp); }
32   int get_max_caps() const { return head.max_caps; }
33   int get_max_leases() const { return head.max_leases; }
34
35   MClientSession() : Message(CEPH_MSG_CLIENT_SESSION, HEAD_VERSION, COMPAT_VERSION) { }
36   MClientSession(int o, version_t s=0) : 
37     Message(CEPH_MSG_CLIENT_SESSION, HEAD_VERSION, COMPAT_VERSION) {
38     memset(&head, 0, sizeof(head));
39     head.op = o;
40     head.seq = s;
41   }
42   MClientSession(int o, utime_t st) : 
43     Message(CEPH_MSG_CLIENT_SESSION, HEAD_VERSION, COMPAT_VERSION) {
44     memset(&head, 0, sizeof(head));
45     head.op = o;
46     head.seq = 0;
47     st.encode_timeval(&head.stamp);
48   }
49 private:
50   ~MClientSession() override {}
51
52 public:
53   const char *get_type_name() const override { return "client_session"; }
54   void print(ostream& out) const override {
55     out << "client_session(" << ceph_session_op_name(get_op());
56     if (get_seq())
57       out << " seq " << get_seq();
58     if (get_op() == CEPH_SESSION_RECALL_STATE)
59       out << " max_caps " << head.max_caps << " max_leases " << head.max_leases;
60     out << ")";
61   }
62
63   void decode_payload() override { 
64     bufferlist::iterator p = payload.begin();
65     ::decode(head, p);
66     if (header.version >= 2) {
67       ::decode(client_meta, p);
68     }
69   }
70   void encode_payload(uint64_t features) override { 
71     ::encode(head, payload);
72     if (client_meta.empty()) {
73       // If we're not trying to send any metadata (always the case if
74       // we are a server) then send older-format message to avoid upsetting
75       // old kernel clients.
76       header.version = 1;
77     } else {
78       ::encode(client_meta, payload);
79       header.version = HEAD_VERSION;
80     }
81
82   }
83 };
84
85 #endif