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 "common/Formatter.h"
17 #include "cls/lock/cls_lock_types.h"
19 using namespace rados::cls::lock;
21 static void generate_lock_id(locker_id_t& i, int n, const string& cookie)
23 i.locker = entity_name_t(entity_name_t::CLIENT(n));
27 void locker_id_t::dump(Formatter *f) const
29 f->dump_stream("locker") << locker;
30 f->dump_string("cookie", cookie);
33 void locker_id_t::generate_test_instances(list<locker_id_t*>& o)
35 locker_id_t *i = new locker_id_t;
36 generate_lock_id(*i, 1, "cookie");
38 o.push_back(new locker_id_t);
41 void locker_info_t::dump(Formatter *f) const
43 f->dump_stream("expiration") << expiration;
44 f->dump_stream("addr") << addr;
45 f->dump_string("description", description);
48 static void generate_test_addr(entity_addr_t& a, int nonce, int port)
50 a.set_type(entity_addr_t::TYPE_LEGACY);
52 a.set_family(AF_INET);
53 a.set_in4_quad(0, 127);
60 void locker_info_t::generate_test_instances(list<locker_info_t*>& o)
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";
67 o.push_back(new locker_info_t);
70 void lock_info_t::dump(Formatter *f) const
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);
84 void lock_info_t::generate_test_instances(list<lock_info_t *>& o)
86 lock_info_t *i = new lock_info_t;
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;
97 o.push_back(new lock_info_t);