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.
19 #include "msg/Message.h"
20 #include "mds/locks.h"
21 #include "mds/SimpleLock.h"
23 class MLock
: public SafeMessage
{
25 static const int HEAD_VERSION
= 1;
26 static const int COMPAT_VERSION
= 1;
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
32 __u16 lock_type
= 0; // lock object type
33 MDSCacheObjectInfo object_info
;
35 bufferlist lockdata
; // and possibly some data
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
; }
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
; }
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
),
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
);
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
);
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
)
77 void set_reqid(metareqid_t ri
) { reqid
= ri
; }
78 void set_data(const bufferlist
& lockdata
) {
79 this->lockdata
= lockdata
;
82 void decode_payload() override
{
84 auto p
= payload
.cbegin();
89 decode(object_info
, p
);
92 void encode_payload(uint64_t features
) override
{
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
);
102 template<class T
, typename
... Args
>
103 friend boost::intrusive_ptr
<T
> ceph::make_message(Args
&&... args
);