summaryrefslogtreecommitdiff
path: root/src/messages/MForward.h
blob: f188b0c7e7216c16b959c0f595fe829692596a65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2010 Sage Weil <sage@newdream.net>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 * Client requests often need to get forwarded from some monitor
 * to the leader. This class encapsulates the original message
 * along with the client's caps so the leader can do proper permissions
 * checking.
 */

#ifndef CEPH_MFORWARD_H
#define CEPH_MFORWARD_H

#include "msg/Message.h"
#include "mon/MonCaps.h"
#include "include/encoding.h"

struct MForward : public Message {
  uint64_t tid;
  PaxosServiceMessage *msg;
  entity_inst_t client;
  MonCaps client_caps;
  
  MForward() : Message(MSG_FORWARD), tid(0), msg(NULL) {}
  //the message needs to have caps filled in!
  MForward(uint64_t t, PaxosServiceMessage *m) :
    Message(MSG_FORWARD), tid(t), msg(m) {
    client = m->get_source_inst();
    client_caps = m->get_session()->caps;
  }
  MForward(uint64_t t, PaxosServiceMessage *m, MonCaps caps) :
    Message(MSG_FORWARD), tid(t), msg(m), client_caps(caps) {
    client = m->get_source_inst();
  }
private:
  ~MForward() {
    if (msg) msg->put();
  }

public:
  void encode_payload() {
    ::encode(tid, payload);
    ::encode(client, payload);
    ::encode(client_caps, payload);
    encode_message(msg, payload);
  }

  void decode_payload() {
    bufferlist::iterator p = payload.begin();
    ::decode(tid, p);
    ::decode(client, p);
    ::decode(client_caps, p);
    msg = (PaxosServiceMessage *)decode_message(p);
  }

  const char *get_type_name() { return "forward"; }
  void print(ostream& o) {
    if (msg)
      o << "forward(" << *msg << ") to leader";
    else o << "forward(??? ) to leader";
  }
};
  
#endif