]>
git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MForward.h
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-2010 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.
13 * Client requests often need to get forwarded from some monitor
14 * to the leader. This class encapsulates the original message
15 * along with the client's caps so the leader can do proper permissions
19 #ifndef CEPH_MFORWARD_H
20 #define CEPH_MFORWARD_H
22 #include "msg/Message.h"
23 #include "mon/MonCap.h"
24 #include "include/encoding.h"
25 #include "include/stringify.h"
27 struct MForward
: public Message
{
31 uint64_t con_features
;
32 EntityName entity_name
;
33 PaxosServiceMessage
*msg
; // incoming or outgoing message
35 string msg_desc
; // for operator<< only
37 static const int HEAD_VERSION
= 3;
38 static const int COMPAT_VERSION
= 3;
40 MForward() : Message(MSG_FORWARD
, HEAD_VERSION
, COMPAT_VERSION
),
41 tid(0), con_features(0), msg(NULL
) {}
42 //the message needs to have caps filled in!
43 MForward(uint64_t t
, PaxosServiceMessage
*m
, uint64_t feat
) :
44 Message(MSG_FORWARD
, HEAD_VERSION
, COMPAT_VERSION
),
46 client
= m
->get_source_inst();
47 client_caps
= m
->get_session()->caps
;
49 // we may need to reencode for the target mon
51 msg
= (PaxosServiceMessage
*)m
->get();
53 MForward(uint64_t t
, PaxosServiceMessage
*m
, uint64_t feat
,
55 Message(MSG_FORWARD
, HEAD_VERSION
, COMPAT_VERSION
),
56 tid(t
), client_caps(caps
), msg(NULL
) {
57 client
= m
->get_source_inst();
59 msg
= (PaxosServiceMessage
*)m
->get();
62 ~MForward() override
{
64 // message was unclaimed
71 void encode_payload(uint64_t features
) override
{
72 ::encode(tid
, payload
);
73 ::encode(client
, payload
, features
);
74 ::encode(client_caps
, payload
, features
);
75 // Encode client message with intersection of target and source
76 // features. This could matter if the semantics of the encoded
77 // message are changed when reencoding with more features than the
78 // client had originally. That should never happen, but we may as
79 // well be defensive here.
80 if (con_features
!= features
) {
83 encode_message(msg
, features
& con_features
, payload
);
84 ::encode(con_features
, payload
);
85 ::encode(entity_name
, payload
);
88 void decode_payload() override
{
89 bufferlist::iterator p
= payload
.begin();
92 ::decode(client_caps
, p
);
93 msg
= (PaxosServiceMessage
*)decode_message(NULL
, 0, p
);
94 ::decode(con_features
, p
);
95 ::decode(entity_name
, p
);
98 PaxosServiceMessage
*claim_message() {
99 // let whoever is claiming the message deal with putting it.
101 msg_desc
= stringify(*msg
);
102 PaxosServiceMessage
*m
= msg
;
107 const char *get_type_name() const override
{ return "forward"; }
108 void print(ostream
& o
) const override
{
115 o
<< " caps " << client_caps
117 << " con_features " << con_features
<< ")";