Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / messages / MLock.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
16 #ifndef CEPH_MLOCK_H
17 #define CEPH_MLOCK_H
18
19 #include "msg/Message.h"
20 #include "mds/locks.h"
21
22 class MLock : public Message {
23   int32_t     action;  // action type
24   int32_t     asker;  // who is initiating this request
25   metareqid_t reqid;  // for remote lock requests
26   
27   __u16      lock_type;  // lock object type
28   MDSCacheObjectInfo object_info;  
29   
30   bufferlist lockdata;  // and possibly some data
31   
32 public:
33   bufferlist& get_data() { return lockdata; }
34   int get_asker() { return asker; }
35   int get_action() { return action; }
36   metareqid_t get_reqid() { return reqid; }
37   
38   int get_lock_type() { return lock_type; }
39   MDSCacheObjectInfo &get_object_info() { return object_info; }
40   
41   MLock() : Message(MSG_MDS_LOCK) {}
42   MLock(int ac, int as) :
43     Message(MSG_MDS_LOCK),
44     action(ac), asker(as),
45     lock_type(0) { }
46   MLock(SimpleLock *lock, int ac, int as) :
47     Message(MSG_MDS_LOCK),
48     action(ac), asker(as),
49     lock_type(lock->get_type()) {
50     lock->get_parent()->set_object_info(object_info);
51   }
52   MLock(SimpleLock *lock, int ac, int as, bufferlist& bl) :
53     Message(MSG_MDS_LOCK),
54     action(ac), asker(as), lock_type(lock->get_type()) {
55     lock->get_parent()->set_object_info(object_info);
56     lockdata.claim(bl);
57   }
58 private:
59   ~MLock() override {}
60   
61 public:
62   const char *get_type_name() const override { return "ILock"; }
63   void print(ostream& out) const override {
64     out << "lock(a=" << get_lock_action_name(action)
65         << " " << get_lock_type_name(lock_type)
66         << " " << object_info
67         << ")";
68   }
69   
70   void set_reqid(metareqid_t ri) { reqid = ri; }
71   void set_data(const bufferlist& lockdata) {
72     this->lockdata = lockdata;
73   }
74   
75   void decode_payload() override {
76     bufferlist::iterator p = payload.begin();
77     ::decode(asker, p);
78     ::decode(action, p);
79     ::decode(reqid, p);
80     ::decode(lock_type, p);
81     ::decode(object_info, p);
82     ::decode(lockdata, p);
83   }
84   void encode_payload(uint64_t features) override {
85     ::encode(asker, payload);
86     ::encode(action, payload);
87     ::encode(reqid, payload);
88     ::encode(lock_type, payload);
89     ::encode(object_info, payload);
90     ::encode(lockdata, payload);
91   }
92
93 };
94
95 #endif