-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.h
More file actions
189 lines (161 loc) · 4.51 KB
/
Copy pathobject.h
File metadata and controls
189 lines (161 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2006 Sage Weil <[email protected]>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#ifndef CEPH_OBJECT_H
#define CEPH_OBJECT_H
#include <stdint.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
using namespace std;
#include "include/unordered_map.h"
#include "include/hash_namespace.h"
#include "hash.h"
#include "encoding.h"
#include "ceph_hash.h"
#include "cmp.h"
struct object_t {
string name;
object_t() {}
object_t(const char *s) : name(s) {}
object_t(const string& s) : name(s) {}
void swap(object_t& o) {
name.swap(o.name);
}
void clear() {
name.clear();
}
void encode(bufferlist &bl) const {
::encode(name, bl);
}
void decode(bufferlist::iterator &bl) {
::decode(name, bl);
}
};
WRITE_CLASS_ENCODER(object_t)
inline bool operator==(const object_t& l, const object_t& r) {
return l.name == r.name;
}
inline bool operator!=(const object_t& l, const object_t& r) {
return l.name != r.name;
}
inline bool operator>(const object_t& l, const object_t& r) {
return l.name > r.name;
}
inline bool operator<(const object_t& l, const object_t& r) {
return l.name < r.name;
}
inline bool operator>=(const object_t& l, const object_t& r) {
return l.name >= r.name;
}
inline bool operator<=(const object_t& l, const object_t& r) {
return l.name <= r.name;
}
inline ostream& operator<<(ostream& out, const object_t& o) {
return out << o.name;
}
CEPH_HASH_NAMESPACE_START
template<> struct hash<object_t> {
size_t operator()(const object_t& r) const {
//static hash<string> H;
//return H(r.name);
return ceph_str_hash_linux(r.name.c_str(), r.name.length());
}
};
CEPH_HASH_NAMESPACE_END
struct file_object_t {
uint64_t ino, bno;
mutable char buf[33];
file_object_t(uint64_t i=0, uint64_t b=0) : ino(i), bno(b) {
buf[0] = 0;
}
const char *c_str() const {
if (!buf[0])
sprintf(buf, "%llx.%08llx", (long long unsigned)ino, (long long unsigned)bno);
return buf;
}
operator object_t() {
return object_t(c_str());
}
};
// ---------------------------
// snaps
struct snapid_t {
uint64_t val;
snapid_t(uint64_t v=0) : val(v) {}
snapid_t operator+=(snapid_t o) { val += o.val; return *this; }
snapid_t operator++() { ++val; return *this; }
operator uint64_t() const { return val; }
};
inline void encode(snapid_t i, bufferlist &bl) { encode(i.val, bl); }
inline void decode(snapid_t &i, bufferlist::iterator &p) { decode(i.val, p); }
inline ostream& operator<<(ostream& out, snapid_t s) {
if (s == CEPH_NOSNAP)
return out << "head";
else if (s == CEPH_SNAPDIR)
return out << "snapdir";
else
return out << hex << s.val << dec;
}
struct sobject_t {
object_t oid;
snapid_t snap;
sobject_t() : snap(0) {}
sobject_t(object_t o, snapid_t s) : oid(o), snap(s) {}
void swap(sobject_t& o) {
oid.swap(o.oid);
snapid_t t = snap;
snap = o.snap;
o.snap = t;
}
void encode(bufferlist& bl) const {
::encode(oid, bl);
::encode(snap, bl);
}
void decode(bufferlist::iterator& bl) {
::decode(oid, bl);
::decode(snap, bl);
}
};
WRITE_CLASS_ENCODER(sobject_t)
inline bool operator==(const sobject_t &l, const sobject_t &r) {
return l.oid == r.oid && l.snap == r.snap;
}
inline bool operator!=(const sobject_t &l, const sobject_t &r) {
return l.oid != r.oid || l.snap != r.snap;
}
inline bool operator>(const sobject_t &l, const sobject_t &r) {
return l.oid > r.oid || (l.oid == r.oid && l.snap > r.snap);
}
inline bool operator<(const sobject_t &l, const sobject_t &r) {
return l.oid < r.oid || (l.oid == r.oid && l.snap < r.snap);
}
inline bool operator>=(const sobject_t &l, const sobject_t &r) {
return l.oid > r.oid || (l.oid == r.oid && l.snap >= r.snap);
}
inline bool operator<=(const sobject_t &l, const sobject_t &r) {
return l.oid < r.oid || (l.oid == r.oid && l.snap <= r.snap);
}
inline ostream& operator<<(ostream& out, const sobject_t &o) {
return out << o.oid << "/" << o.snap;
}
CEPH_HASH_NAMESPACE_START
template<> struct hash<sobject_t> {
size_t operator()(const sobject_t &r) const {
static hash<object_t> H;
static rjhash<uint64_t> I;
return H(r.oid) ^ I(r.snap);
}
};
CEPH_HASH_NAMESPACE_END
#endif