]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
7c673cae FG |
15 | #include "common/Formatter.h" |
16 | ||
17 | #include "cls/lock/cls_lock_types.h" | |
18 | ||
19 | using namespace rados::cls::lock; | |
20 | ||
21 | static void generate_lock_id(locker_id_t& i, int n, const string& cookie) | |
22 | { | |
23 | i.locker = entity_name_t(entity_name_t::CLIENT(n)); | |
24 | i.cookie = cookie; | |
25 | } | |
26 | ||
27 | void locker_id_t::dump(Formatter *f) const | |
28 | { | |
29 | f->dump_stream("locker") << locker; | |
30 | f->dump_string("cookie", cookie); | |
31 | } | |
32 | ||
33 | void locker_id_t::generate_test_instances(list<locker_id_t*>& o) | |
34 | { | |
35 | locker_id_t *i = new locker_id_t; | |
36 | generate_lock_id(*i, 1, "cookie"); | |
37 | o.push_back(i); | |
38 | o.push_back(new locker_id_t); | |
39 | } | |
40 | ||
41 | void locker_info_t::dump(Formatter *f) const | |
42 | { | |
43 | f->dump_stream("expiration") << expiration; | |
44 | f->dump_stream("addr") << addr; | |
45 | f->dump_string("description", description); | |
46 | } | |
47 | ||
48 | static void generate_test_addr(entity_addr_t& a, int nonce, int port) | |
49 | { | |
50 | a.set_type(entity_addr_t::TYPE_LEGACY); | |
51 | a.set_nonce(nonce); | |
52 | a.set_family(AF_INET); | |
53 | a.set_in4_quad(0, 127); | |
54 | a.set_in4_quad(1, 0); | |
55 | a.set_in4_quad(2, 1); | |
56 | a.set_in4_quad(3, 2); | |
57 | a.set_port(port); | |
58 | } | |
59 | ||
60 | void locker_info_t::generate_test_instances(list<locker_info_t*>& o) | |
61 | { | |
62 | locker_info_t *i = new locker_info_t; | |
63 | i->expiration = utime_t(5, 0); | |
64 | generate_test_addr(i->addr, 1, 2); | |
65 | i->description = "description"; | |
66 | o.push_back(i); | |
67 | o.push_back(new locker_info_t); | |
68 | } | |
69 | ||
224ce89b WB |
70 | void lock_info_t::dump(Formatter *f) const |
71 | { | |
72 | f->dump_int("lock_type", lock_type); | |
73 | f->dump_string("tag", tag); | |
74 | f->open_array_section("lockers"); | |
75 | for (auto &i : lockers) { | |
76 | f->open_object_section("locker"); | |
77 | f->dump_object("id", i.first); | |
78 | f->dump_object("info", i.second); | |
79 | f->close_section(); | |
80 | } | |
81 | f->close_section(); | |
82 | } | |
83 | ||
84 | void lock_info_t::generate_test_instances(list<lock_info_t *>& o) | |
85 | { | |
86 | lock_info_t *i = new lock_info_t; | |
87 | locker_id_t id; | |
88 | locker_info_t info; | |
89 | generate_lock_id(id, 1, "cookie"); | |
90 | info.expiration = utime_t(5, 0); | |
91 | generate_test_addr(info.addr, 1, 2); | |
92 | info.description = "description"; | |
93 | i->lockers[id] = info; | |
94 | i->lock_type = LOCK_EXCLUSIVE; | |
95 | i->tag = "tag"; | |
96 | o.push_back(i); | |
97 | o.push_back(new lock_info_t); | |
98 | } |