1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef __CEPH_CLS_RBD_H
4 #define __CEPH_CLS_RBD_H
6 #include "include/types.h"
7 #include "include/buffer_fwd.h"
8 #include "include/rbd_types.h"
9 #include "common/Formatter.h"
10 #include "cls/rbd/cls_rbd_types.h"
12 /// information about our parent image, if any
13 struct cls_rbd_parent
{
14 int64_t pool
; ///< parent pool id
15 string id
; ///< parent image id
16 snapid_t snapid
; ///< parent snapid we refer to
17 uint64_t overlap
; ///< portion of this image mapped onto parent (bytes)
19 /// true if our parent pointer information is defined
21 return snapid
!= CEPH_NOSNAP
&& pool
>= 0 && id
.length() > 0 && overlap
> 0;
24 cls_rbd_parent() : pool(-1), snapid(CEPH_NOSNAP
), overlap(0) {}
26 void encode(bufferlist
& bl
) const {
27 ENCODE_START(1, 1, bl
);
31 ::encode(overlap
, bl
);
34 void decode(bufferlist::iterator
& bl
) {
39 ::decode(overlap
, bl
);
42 void dump(Formatter
*f
) const {
43 f
->dump_int("pool", pool
);
44 f
->dump_string("id", id
);
45 f
->dump_unsigned("snapid", snapid
);
46 f
->dump_unsigned("overlap", overlap
);
48 static void generate_test_instances(list
<cls_rbd_parent
*>& o
) {
49 o
.push_back(new cls_rbd_parent
);
50 cls_rbd_parent
*t
= new cls_rbd_parent
;
58 WRITE_CLASS_ENCODER(cls_rbd_parent
)
65 uint8_t protection_status
;
66 cls_rbd_parent parent
;
69 cls::rbd::SnapshotNamespaceOnDisk snapshot_namespace
= {
70 cls::rbd::UserSnapshotNamespace
{}};
72 /// true if we have a parent
73 bool has_parent() const {
74 return parent
.exists();
77 cls_rbd_snap() : id(CEPH_NOSNAP
), image_size(0), features(0),
78 protection_status(RBD_PROTECTION_STATUS_UNPROTECTED
),
79 flags(0), timestamp(utime_t())
81 void encode(bufferlist
& bl
) const {
82 ENCODE_START(6, 1, bl
);
85 ::encode(image_size
, bl
);
86 ::encode(features
, bl
);
88 ::encode(protection_status
, bl
);
90 ::encode(snapshot_namespace
, bl
);
91 ::encode(timestamp
, bl
);
94 void decode(bufferlist::iterator
& p
) {
98 ::decode(image_size
, p
);
99 ::decode(features
, p
);
104 ::decode(protection_status
, p
);
110 ::decode(snapshot_namespace
, p
);
113 ::decode(timestamp
, p
);
117 void dump(Formatter
*f
) const {
118 f
->dump_unsigned("id", id
);
119 f
->dump_string("name", name
);
120 f
->dump_unsigned("image_size", image_size
);
121 f
->dump_unsigned("features", features
);
123 f
->open_object_section("parent");
127 switch (protection_status
) {
128 case RBD_PROTECTION_STATUS_UNPROTECTED
:
129 f
->dump_string("protection_status", "unprotected");
131 case RBD_PROTECTION_STATUS_UNPROTECTING
:
132 f
->dump_string("protection_status", "unprotecting");
134 case RBD_PROTECTION_STATUS_PROTECTED
:
135 f
->dump_string("protection_status", "protected");
141 static void generate_test_instances(list
<cls_rbd_snap
*>& o
) {
142 o
.push_back(new cls_rbd_snap
);
143 cls_rbd_snap
*t
= new cls_rbd_snap
;
146 t
->image_size
= 123456;
150 t
= new cls_rbd_snap
;
153 t
->image_size
= 12345678;
156 t
->parent
.id
= "parent";
157 t
->parent
.snapid
= 456;
158 t
->parent
.overlap
= 12345;
159 t
->protection_status
= RBD_PROTECTION_STATUS_PROTECTED
;
161 t
->timestamp
= utime_t();
165 WRITE_CLASS_ENCODER(cls_rbd_snap
)