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.
15 #include "msg/msg_types.h"
16 #include "common/Formatter.h"
18 #include "cls/lock/cls_lock_ops.h"
20 using namespace rados::cls::lock;
22 static void generate_lock_id(locker_id_t& i, int n, const string& cookie)
24 i.locker = entity_name_t(entity_name_t::CLIENT(n));
28 void cls_lock_lock_op::dump(Formatter *f) const
30 f->dump_string("name", name);
31 f->dump_string("type", cls_lock_type_str(type));
32 f->dump_string("cookie", cookie);
33 f->dump_string("tag", tag);
34 f->dump_string("description", description);
35 f->dump_stream("duration") << duration;
36 f->dump_int("flags", (int)flags);
39 void cls_lock_lock_op::generate_test_instances(list<cls_lock_lock_op*>& o)
41 cls_lock_lock_op *i = new cls_lock_lock_op;
43 i->type = LOCK_SHARED;
46 i->description = "description";
47 i->duration = utime_t(5, 0);
48 i->flags = LOCK_FLAG_RENEW;
50 o.push_back(new cls_lock_lock_op);
53 void cls_lock_unlock_op::dump(Formatter *f) const
55 f->dump_string("name", name);
56 f->dump_string("cookie", cookie);
59 void cls_lock_unlock_op::generate_test_instances(list<cls_lock_unlock_op*>& o)
61 cls_lock_unlock_op *i = new cls_lock_unlock_op;
65 o.push_back(new cls_lock_unlock_op);
68 void cls_lock_break_op::dump(Formatter *f) const
70 f->dump_string("name", name);
71 f->dump_string("cookie", cookie);
72 f->dump_stream("locker") << locker;
75 void cls_lock_break_op::generate_test_instances(list<cls_lock_break_op*>& o)
77 cls_lock_break_op *i = new cls_lock_break_op;
80 i->locker = entity_name_t(entity_name_t::CLIENT(1));
82 o.push_back(new cls_lock_break_op);
85 void cls_lock_get_info_op::dump(Formatter *f) const
87 f->dump_string("name", name);
90 void cls_lock_get_info_op::generate_test_instances(list<cls_lock_get_info_op*>& o)
92 cls_lock_get_info_op *i = new cls_lock_get_info_op;
95 o.push_back(new cls_lock_get_info_op);
98 static void generate_test_addr(entity_addr_t& a, int nonce, int port)
100 a.set_type(entity_addr_t::TYPE_LEGACY);
102 a.set_family(AF_INET);
103 a.set_in4_quad(0, 127);
104 a.set_in4_quad(1, 0);
105 a.set_in4_quad(2, 1);
106 a.set_in4_quad(3, 2);
110 void cls_lock_get_info_reply::dump(Formatter *f) const
112 f->dump_string("lock_type", cls_lock_type_str(lock_type));
113 f->dump_string("tag", tag);
114 f->open_array_section("lockers");
115 map<locker_id_t, locker_info_t>::const_iterator iter;
116 for (iter = lockers.begin(); iter != lockers.end(); ++iter) {
117 const locker_id_t& id = iter->first;
118 const locker_info_t& info = iter->second;
119 f->open_object_section("object");
120 f->dump_stream("locker") << id.locker;
121 f->dump_string("description", info.description);
122 f->dump_string("cookie", id.cookie);
123 f->dump_stream("expiration") << info.expiration;
124 f->dump_stream("addr") << info.addr;
130 void cls_lock_get_info_reply::generate_test_instances(list<cls_lock_get_info_reply*>& o)
132 cls_lock_get_info_reply *i = new cls_lock_get_info_reply;
133 i->lock_type = LOCK_SHARED;
135 locker_id_t id1, id2;
136 entity_addr_t addr1, addr2;
137 generate_lock_id(id1, 1, "cookie1");
138 generate_test_addr(addr1, 10, 20);
139 i->lockers[id1] = locker_info_t(utime_t(10, 0), addr1, "description1");
140 generate_lock_id(id2, 2, "cookie2");
141 generate_test_addr(addr2, 30, 40);
142 i->lockers[id2] = locker_info_t(utime_t(20, 0), addr2, "description2");
145 o.push_back(new cls_lock_get_info_reply);
148 void cls_lock_list_locks_reply::dump(Formatter *f) const
150 list<string>::const_iterator iter;
151 f->open_array_section("locks");
152 for (iter = locks.begin(); iter != locks.end(); ++iter) {
153 f->open_array_section("object");
154 f->dump_string("lock", *iter);
160 void cls_lock_list_locks_reply::generate_test_instances(list<cls_lock_list_locks_reply*>& o)
162 cls_lock_list_locks_reply *i = new cls_lock_list_locks_reply;
163 i->locks.push_back("lock1");
164 i->locks.push_back("lock2");
165 i->locks.push_back("lock3");
168 o.push_back(new cls_lock_list_locks_reply);
171 void cls_lock_assert_op::dump(Formatter *f) const
173 f->dump_string("name", name);
174 f->dump_string("type", cls_lock_type_str(type));
175 f->dump_string("cookie", cookie);
176 f->dump_string("tag", tag);
179 void cls_lock_assert_op::generate_test_instances(list<cls_lock_assert_op*>& o)
181 cls_lock_assert_op *i = new cls_lock_assert_op;
183 i->type = LOCK_SHARED;
184 i->cookie = "cookie";
187 o.push_back(new cls_lock_assert_op);
190 void cls_lock_set_cookie_op::dump(Formatter *f) const
192 f->dump_string("name", name);
193 f->dump_string("type", cls_lock_type_str(type));
194 f->dump_string("cookie", cookie);
195 f->dump_string("tag", tag);
196 f->dump_string("new_cookie", new_cookie);
199 void cls_lock_set_cookie_op::generate_test_instances(list<cls_lock_set_cookie_op*>& o)
201 cls_lock_set_cookie_op *i = new cls_lock_set_cookie_op;
203 i->type = LOCK_SHARED;
204 i->cookie = "cookie";
206 i->new_cookie = "new cookie";
208 o.push_back(new cls_lock_set_cookie_op);