]> git.proxmox.com Git - ceph.git/blob - ceph/src/messages/MLock.h
import 15.2.0 Octopus source
[ceph.git] / 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 #include "mds/SimpleLock.h"
22
23 class MLock : public SafeMessage {
24 private:
25 static const int HEAD_VERSION = 1;
26 static const int COMPAT_VERSION = 1;
27
28 int32_t action = 0; // action type
29 mds_rank_t asker = 0; // who is initiating this request
30 metareqid_t reqid; // for remote lock requests
31
32 __u16 lock_type = 0; // lock object type
33 MDSCacheObjectInfo object_info;
34
35 bufferlist lockdata; // and possibly some data
36
37 public:
38 bufferlist& get_data() { return lockdata; }
39 const bufferlist& get_data() const { return lockdata; }
40 int get_asker() const { return asker; }
41 int get_action() const { return action; }
42 metareqid_t get_reqid() const { return reqid; }
43
44 int get_lock_type() const { return lock_type; }
45 const MDSCacheObjectInfo &get_object_info() const { return object_info; }
46 MDSCacheObjectInfo &get_object_info() { return object_info; }
47
48 protected:
49 MLock() : SafeMessage{MSG_MDS_LOCK, HEAD_VERSION, COMPAT_VERSION} {}
50 MLock(int ac, mds_rank_t as) :
51 SafeMessage{MSG_MDS_LOCK, HEAD_VERSION, COMPAT_VERSION},
52 action(ac), asker(as),
53 lock_type(0) { }
54 MLock(SimpleLock *lock, int ac, mds_rank_t as) :
55 SafeMessage{MSG_MDS_LOCK, HEAD_VERSION, COMPAT_VERSION},
56 action(ac), asker(as),
57 lock_type(lock->get_type()) {
58 lock->get_parent()->set_object_info(object_info);
59 }
60 MLock(SimpleLock *lock, int ac, mds_rank_t as, bufferlist& bl) :
61 SafeMessage{MSG_MDS_LOCK, HEAD_VERSION, COMPAT_VERSION},
62 action(ac), asker(as), lock_type(lock->get_type()) {
63 lock->get_parent()->set_object_info(object_info);
64 lockdata.claim(bl);
65 }
66 ~MLock() override {}
67
68 public:
69 std::string_view get_type_name() const override { return "ILock"; }
70 void print(ostream& out) const override {
71 out << "lock(a=" << SimpleLock::get_lock_action_name(action)
72 << " " << SimpleLock::get_lock_type_name(lock_type)
73 << " " << object_info
74 << ")";
75 }
76
77 void set_reqid(metareqid_t ri) { reqid = ri; }
78 void set_data(const bufferlist& lockdata) {
79 this->lockdata = lockdata;
80 }
81
82 void decode_payload() override {
83 using ceph::decode;
84 auto p = payload.cbegin();
85 decode(asker, p);
86 decode(action, p);
87 decode(reqid, p);
88 decode(lock_type, p);
89 decode(object_info, p);
90 decode(lockdata, p);
91 }
92 void encode_payload(uint64_t features) override {
93 using ceph::encode;
94 encode(asker, payload);
95 encode(action, payload);
96 encode(reqid, payload);
97 encode(lock_type, payload);
98 encode(object_info, payload);
99 encode(lockdata, payload);
100 }
101 private:
102 template<class T, typename... Args>
103 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
104 };
105
106 #endif