1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
15 #ifndef CEPH_MCLIENTSESSION_H
16 #define CEPH_MCLIENTSESSION_H
18 #include "msg/Message.h"
20 class MClientSession
: public Message
{
21 static const int HEAD_VERSION
= 2;
22 static const int COMPAT_VERSION
= 1;
25 ceph_mds_session_head head
;
27 std::map
<std::string
, std::string
> client_meta
;
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
; }
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
));
42 MClientSession(int o
, utime_t st
) :
43 Message(CEPH_MSG_CLIENT_SESSION
, HEAD_VERSION
, COMPAT_VERSION
) {
44 memset(&head
, 0, sizeof(head
));
47 st
.encode_timeval(&head
.stamp
);
50 ~MClientSession() override
{}
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());
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
;
63 void decode_payload() override
{
64 bufferlist::iterator p
= payload
.begin();
66 if (header
.version
>= 2) {
67 ::decode(client_meta
, p
);
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.
78 ::encode(client_meta
, payload
);
79 header
.version
= HEAD_VERSION
;