]>
git.proxmox.com Git - ceph.git/blob - ceph/src/include/object.h
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.
24 #include "include/rados.h"
25 #include "include/unordered_map.h"
29 #include "ceph_hash.h"
38 // cppcheck-suppress noExplicitConstructor
39 object_t(const char *s
) : name(s
) {}
40 // cppcheck-suppress noExplicitConstructor
41 object_t(const string
& s
) : name(s
) {}
43 void swap(object_t
& o
) {
50 void encode(bufferlist
&bl
) const {
54 void decode(bufferlist::const_iterator
&bl
) {
59 WRITE_CLASS_ENCODER(object_t
)
61 inline bool operator==(const object_t
& l
, const object_t
& r
) {
62 return l
.name
== r
.name
;
64 inline bool operator!=(const object_t
& l
, const object_t
& r
) {
65 return l
.name
!= r
.name
;
67 inline bool operator>(const object_t
& l
, const object_t
& r
) {
68 return l
.name
> r
.name
;
70 inline bool operator<(const object_t
& l
, const object_t
& r
) {
71 return l
.name
< r
.name
;
73 inline bool operator>=(const object_t
& l
, const object_t
& r
) {
74 return l
.name
>= r
.name
;
76 inline bool operator<=(const object_t
& l
, const object_t
& r
) {
77 return l
.name
<= r
.name
;
79 inline ostream
& operator<<(ostream
& out
, const object_t
& o
) {
84 template<> struct hash
<object_t
> {
85 size_t operator()(const object_t
& r
) const {
86 //static hash<string> H;
88 return ceph_str_hash_linux(r
.name
.c_str(), r
.name
.length());
94 struct file_object_t
{
98 file_object_t(uint64_t i
=0, uint64_t b
=0) : ino(i
), bno(b
) {
102 const char *c_str() const {
104 snprintf(buf
, sizeof(buf
), "%llx.%08llx", (long long unsigned)ino
, (long long unsigned)bno
);
108 operator object_t() {
109 return object_t(c_str());
114 // ---------------------------
119 // cppcheck-suppress noExplicitConstructor
120 snapid_t(uint64_t v
=0) : val(v
) {}
121 snapid_t
operator+=(snapid_t o
) { val
+= o
.val
; return *this; }
122 snapid_t
operator++() { ++val
; return *this; }
123 operator uint64_t() const { return val
; }
126 inline void encode(snapid_t i
, bufferlist
&bl
) { encode(i
.val
, bl
); }
127 inline void decode(snapid_t
&i
, bufferlist::const_iterator
&p
) { decode(i
.val
, p
); }
130 struct denc_traits
<snapid_t
> {
131 static constexpr bool supported
= true;
132 static constexpr bool featured
= false;
133 static constexpr bool bounded
= true;
134 static constexpr bool need_contiguous
= true;
135 static void bound_encode(const snapid_t
& o
, size_t& p
) {
138 static void encode(const snapid_t
&o
, buffer::list::contiguous_appender
& p
) {
141 static void decode(snapid_t
& o
, buffer::ptr::const_iterator
&p
) {
146 inline ostream
& operator<<(ostream
& out
, const snapid_t
& s
) {
147 if (s
== CEPH_NOSNAP
)
148 return out
<< "head";
149 else if (s
== CEPH_SNAPDIR
)
150 return out
<< "snapdir";
152 return out
<< hex
<< s
.val
<< dec
;
160 sobject_t() : snap(0) {}
161 sobject_t(object_t o
, snapid_t s
) : oid(o
), snap(s
) {}
163 void swap(sobject_t
& o
) {
170 void encode(bufferlist
& bl
) const {
175 void decode(bufferlist::const_iterator
& bl
) {
181 WRITE_CLASS_ENCODER(sobject_t
)
183 inline bool operator==(const sobject_t
&l
, const sobject_t
&r
) {
184 return l
.oid
== r
.oid
&& l
.snap
== r
.snap
;
186 inline bool operator!=(const sobject_t
&l
, const sobject_t
&r
) {
187 return l
.oid
!= r
.oid
|| l
.snap
!= r
.snap
;
189 inline bool operator>(const sobject_t
&l
, const sobject_t
&r
) {
190 return l
.oid
> r
.oid
|| (l
.oid
== r
.oid
&& l
.snap
> r
.snap
);
192 inline bool operator<(const sobject_t
&l
, const sobject_t
&r
) {
193 return l
.oid
< r
.oid
|| (l
.oid
== r
.oid
&& l
.snap
< r
.snap
);
195 inline bool operator>=(const sobject_t
&l
, const sobject_t
&r
) {
196 return l
.oid
> r
.oid
|| (l
.oid
== r
.oid
&& l
.snap
>= r
.snap
);
198 inline bool operator<=(const sobject_t
&l
, const sobject_t
&r
) {
199 return l
.oid
< r
.oid
|| (l
.oid
== r
.oid
&& l
.snap
<= r
.snap
);
201 inline ostream
& operator<<(ostream
& out
, const sobject_t
&o
) {
202 return out
<< o
.oid
<< "/" << o
.snap
;
205 template<> struct hash
<sobject_t
> {
206 size_t operator()(const sobject_t
&r
) const {
207 static hash
<object_t
> H
;
208 static rjhash
<uint64_t> I
;
209 return H(r
.oid
) ^ I(r
.snap
);