1    	// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2    	// vim: ts=8 sw=2 smarttab
3    	
4    	#ifndef CEPH_CLS_RBD_TYPES_H
5    	#define CEPH_CLS_RBD_TYPES_H
6    	
7    	#include <boost/variant.hpp>
8    	#include "include/int_types.h"
9    	#include "include/buffer.h"
10   	#include "include/encoding.h"
11   	#include "include/stringify.h"
12   	#include "include/utime.h"
13   	#include <iosfwd>
14   	#include <string>
15   	#include <set>
16   	
17   	#define RBD_GROUP_REF "rbd_group_ref"
18   	
19   	namespace ceph { class Formatter; }
20   	
21   	namespace cls {
22   	namespace rbd {
23   	
24   	static const uint32_t MAX_OBJECT_MAP_OBJECT_COUNT = 256000000;
25   	static const string RBD_GROUP_IMAGE_KEY_PREFIX = "image_";
26   	
27   	enum DirectoryState {
28   	  DIRECTORY_STATE_READY         = 0,
29   	  DIRECTORY_STATE_ADD_DISABLED  = 1
30   	};
31   	
32   	inline void encode(DirectoryState state, bufferlist& bl,
33   			   uint64_t features=0)
34   	{
35   	  ceph::encode(static_cast<uint8_t>(state), bl);
36   	}
37   	
38   	inline void decode(DirectoryState &state, bufferlist::const_iterator& it)
39   	{
40   	  uint8_t int_state;
41   	  ceph::decode(int_state, it);
42   	  state = static_cast<DirectoryState>(int_state);
43   	}
44   	
45   	enum MirrorMode {
46   	  MIRROR_MODE_DISABLED = 0,
47   	  MIRROR_MODE_IMAGE    = 1,
48   	  MIRROR_MODE_POOL     = 2
49   	};
50   	
51   	enum GroupImageLinkState {
52   	  GROUP_IMAGE_LINK_STATE_ATTACHED,
53   	  GROUP_IMAGE_LINK_STATE_INCOMPLETE
54   	};
55   	
56   	inline void encode(const GroupImageLinkState &state, bufferlist& bl,
57   			   uint64_t features=0)
58   	{
59   	  using ceph::encode;
60   	  encode(static_cast<uint8_t>(state), bl);
61   	}
62   	
63   	inline void decode(GroupImageLinkState &state, bufferlist::const_iterator& it)
64   	{
65   	  uint8_t int_state;
66   	  using ceph::decode;
67   	  decode(int_state, it);
68   	  state = static_cast<GroupImageLinkState>(int_state);
69   	}
70   	
71   	struct MirrorPeer {
72   	  MirrorPeer() {
73   	  }
74   	  MirrorPeer(const std::string &uuid, const std::string &cluster_name,
75   	             const std::string &client_name, int64_t pool_id)
76   	    : uuid(uuid), cluster_name(cluster_name), client_name(client_name),
77   	      pool_id(pool_id) {
78   	  }
79   	
80   	  std::string uuid;
81   	  std::string cluster_name;
82   	  std::string client_name;
83   	  int64_t pool_id = -1;
84   	
85   	  inline bool is_valid() const {
86   	    return (!uuid.empty() && !cluster_name.empty() && !client_name.empty());
87   	  }
88   	
89   	  void encode(bufferlist &bl) const;
90   	  void decode(bufferlist::const_iterator &it);
91   	  void dump(Formatter *f) const;
92   	
93   	  static void generate_test_instances(std::list<MirrorPeer*> &o);
94   	
95   	  bool operator==(const MirrorPeer &rhs) const;
96   	};
97   	
98   	std::ostream& operator<<(std::ostream& os, const MirrorMode& mirror_mode);
99   	std::ostream& operator<<(std::ostream& os, const MirrorPeer& peer);
100  	
101  	WRITE_CLASS_ENCODER(MirrorPeer);
102  	
103  	enum MirrorImageState {
104  	  MIRROR_IMAGE_STATE_DISABLING = 0,
105  	  MIRROR_IMAGE_STATE_ENABLED   = 1,
106  	  MIRROR_IMAGE_STATE_DISABLED  = 2,
107  	};
108  	
109  	struct MirrorImage {
110  	  MirrorImage() {}
111  	  MirrorImage(const std::string &global_image_id, MirrorImageState state)
112  	    : global_image_id(global_image_id), state(state) {}
113  	
114  	  std::string global_image_id;
115  	  MirrorImageState state = MIRROR_IMAGE_STATE_DISABLING;
116  	
117  	  void encode(bufferlist &bl) const;
118  	  void decode(bufferlist::const_iterator &it);
119  	  void dump(Formatter *f) const;
120  	
121  	  static void generate_test_instances(std::list<MirrorImage*> &o);
122  	
123  	  bool operator==(const MirrorImage &rhs) const;
124  	  bool operator<(const MirrorImage &rhs) const;
125  	};
126  	
127  	std::ostream& operator<<(std::ostream& os, const MirrorImageState& mirror_state);
128  	std::ostream& operator<<(std::ostream& os, const MirrorImage& mirror_image);
129  	
130  	WRITE_CLASS_ENCODER(MirrorImage);
131  	
132  	enum MirrorImageStatusState {
133  	  MIRROR_IMAGE_STATUS_STATE_UNKNOWN         = 0,
134  	  MIRROR_IMAGE_STATUS_STATE_ERROR           = 1,
135  	  MIRROR_IMAGE_STATUS_STATE_SYNCING         = 2,
136  	  MIRROR_IMAGE_STATUS_STATE_STARTING_REPLAY = 3,
137  	  MIRROR_IMAGE_STATUS_STATE_REPLAYING       = 4,
138  	  MIRROR_IMAGE_STATUS_STATE_STOPPING_REPLAY = 5,
139  	  MIRROR_IMAGE_STATUS_STATE_STOPPED         = 6,
140  	};
141  	
142  	inline void encode(const MirrorImageStatusState &state, bufferlist& bl,
143  			   uint64_t features=0)
144  	{
145  	  using ceph::encode;
(1) Event overrun-buffer-val: Overrunning buffer pointed to by "__u8 const(static_cast<uint8_t>(state))" of 1 bytes by passing it to a function which accesses it at byte offset 7. [details]
146  	  encode(static_cast<uint8_t>(state), bl);
147  	}
148  	
149  	inline void decode(MirrorImageStatusState &state, bufferlist::const_iterator& it)
150  	{
151  	  uint8_t int_state;
152  	  using ceph::decode;
153  	  decode(int_state, it);
154  	  state = static_cast<MirrorImageStatusState>(int_state);
155  	}
156  	
157  	struct MirrorImageStatus {
158  	  MirrorImageStatus() {}
159  	  MirrorImageStatus(MirrorImageStatusState state,
160  			    const std::string &description = "")
161  	    : state(state), description(description) {}
162  	
163  	  MirrorImageStatusState state = MIRROR_IMAGE_STATUS_STATE_UNKNOWN;
164  	  std::string description;
165  	  utime_t last_update;
166  	  bool up = false;
167  	
168  	  void encode(bufferlist &bl) const;
169  	  void decode(bufferlist::const_iterator &it);
170  	  void dump(Formatter *f) const;
171  	
172  	  std::string state_to_string() const;
173  	
174  	  static void generate_test_instances(std::list<MirrorImageStatus*> &o);
175  	
176  	  bool operator==(const MirrorImageStatus &rhs) const;
177  	};
178  	
179  	std::ostream& operator<<(std::ostream& os, const MirrorImageStatus& status);
180  	std::ostream& operator<<(std::ostream& os, const MirrorImageStatusState& state);
181  	
182  	WRITE_CLASS_ENCODER(MirrorImageStatus);
183  	
184  	struct ParentImageSpec {
185  	  int64_t pool_id = -1;
186  	  std::string pool_namespace;
187  	  std::string image_id;
188  	  snapid_t snap_id = CEPH_NOSNAP;
189  	
190  	  ParentImageSpec() {
191  	  }
192  	  ParentImageSpec(int64_t pool_id, const std::string& pool_namespace,
193  	                  const std::string& image_id, snapid_t snap_id)
194  	    : pool_id(pool_id), pool_namespace(pool_namespace), image_id(image_id),
195  	      snap_id(snap_id) {
196  	  }
197  	
198  	  bool exists() const {
199  	    return (pool_id >= 0 && !image_id.empty() && snap_id != CEPH_NOSNAP);
200  	  }
201  	
202  	  bool operator==(const ParentImageSpec& rhs) const {
203  	    return ((pool_id == rhs.pool_id) &&
204  	            (pool_namespace == rhs.pool_namespace) &&
205  	            (image_id == rhs.image_id) &&
206  	            (snap_id == rhs.snap_id));
207  	  }
208  	
209  	  bool operator!=(const ParentImageSpec& rhs) const {
210  	    return !(*this == rhs);
211  	  }
212  	
213  	  void encode(bufferlist &bl) const;
214  	  void decode(bufferlist::const_iterator &it);
215  	  void dump(Formatter *f) const;
216  	
217  	  static void generate_test_instances(std::list<ParentImageSpec*> &o);
218  	};
219  	
220  	WRITE_CLASS_ENCODER(ParentImageSpec);
221  	
222  	struct ChildImageSpec {
223  	  int64_t pool_id = -1;
224  	  std::string pool_namespace;
225  	  std::string image_id;
226  	
227  	  ChildImageSpec() {}
228  	  ChildImageSpec(int64_t pool_id, const std::string& pool_namespace,
229  	                 const std::string& image_id)
230  	    : pool_id(pool_id), pool_namespace(pool_namespace), image_id(image_id) {
231  	  }
232  	
233  	  void encode(bufferlist &bl) const;
234  	  void decode(bufferlist::const_iterator &it);
235  	  void dump(Formatter *f) const;
236  	
237  	  static void generate_test_instances(std::list<ChildImageSpec*> &o);
238  	
239  	  inline bool operator==(const ChildImageSpec& rhs) const {
240  	    return (pool_id == rhs.pool_id &&
241  	            pool_namespace == rhs.pool_namespace &&
242  	            image_id == rhs.image_id);
243  	  }
244  	  inline bool operator<(const ChildImageSpec& rhs) const {
245  	    if (pool_id != rhs.pool_id) {
246  	      return pool_id < rhs.pool_id;
247  	    }
248  	    if (pool_namespace != rhs.pool_namespace) {
249  	      return pool_namespace < rhs.pool_namespace;
250  	    }
251  	    return image_id < rhs.image_id;
252  	  }
253  	};
254  	WRITE_CLASS_ENCODER(ChildImageSpec);
255  	
256  	typedef std::set<ChildImageSpec> ChildImageSpecs;
257  	
258  	struct GroupImageSpec {
259  	  GroupImageSpec() {}
260  	
261  	  GroupImageSpec(const std::string &image_id, int64_t pool_id)
262  	    : image_id(image_id), pool_id(pool_id) {}
263  	
264  	  static int from_key(const std::string &image_key, GroupImageSpec *spec);
265  	
266  	  std::string image_id;
267  	  int64_t pool_id = -1;
268  	
269  	  void encode(bufferlist &bl) const;
270  	  void decode(bufferlist::const_iterator &it);
271  	  void dump(Formatter *f) const;
272  	
273  	  static void generate_test_instances(std::list<GroupImageSpec*> &o);
274  	
275  	  std::string image_key();
276  	
277  	};
278  	WRITE_CLASS_ENCODER(GroupImageSpec);
279  	
280  	struct GroupImageStatus {
281  	  GroupImageStatus() {}
282  	  GroupImageStatus(const std::string &image_id,
283  			   int64_t pool_id,
284  			   GroupImageLinkState state)
285  	    : spec(image_id, pool_id), state(state) {}
286  	
287  	  GroupImageStatus(GroupImageSpec spec,
288  			   GroupImageLinkState state)
289  	    : spec(spec), state(state) {}
290  	
291  	  GroupImageSpec spec;
292  	  GroupImageLinkState state = GROUP_IMAGE_LINK_STATE_INCOMPLETE;
293  	
294  	  void encode(bufferlist &bl) const;
295  	  void decode(bufferlist::const_iterator &it);
296  	  void dump(Formatter *f) const;
297  	
298  	  static void generate_test_instances(std::list<GroupImageStatus*> &o);
299  	
300  	  std::string state_to_string() const;
301  	};
302  	
303  	WRITE_CLASS_ENCODER(GroupImageStatus);
304  	
305  	struct GroupSpec {
306  	  GroupSpec() {}
307  	  GroupSpec(const std::string &group_id, int64_t pool_id)
308  	    : group_id(group_id), pool_id(pool_id) {}
309  	
310  	  std::string group_id;
311  	  int64_t pool_id = -1;
312  	
313  	  void encode(bufferlist &bl) const;
314  	  void decode(bufferlist::const_iterator &it);
315  	  void dump(Formatter *f) const;
316  	  bool is_valid() const;
317  	
318  	  static void generate_test_instances(std::list<GroupSpec *> &o);
319  	};
320  	
321  	WRITE_CLASS_ENCODER(GroupSpec);
322  	
323  	enum SnapshotNamespaceType {
324  	  SNAPSHOT_NAMESPACE_TYPE_USER  = 0,
325  	  SNAPSHOT_NAMESPACE_TYPE_GROUP = 1,
326  	  SNAPSHOT_NAMESPACE_TYPE_TRASH = 2
327  	};
328  	
329  	struct UserSnapshotNamespace {
330  	  static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE =
331  	    SNAPSHOT_NAMESPACE_TYPE_USER;
332  	
333  	  UserSnapshotNamespace() {}
334  	
335  	  void encode(bufferlist& bl) const {}
336  	  void decode(bufferlist::const_iterator& it) {}
337  	
338  	  void dump(Formatter *f) const {}
339  	
340  	  inline bool operator==(const UserSnapshotNamespace& usn) const {
341  	    return true;
342  	  }
343  	
344  	  inline bool operator<(const UserSnapshotNamespace& usn) const {
345  	    return false;
346  	  }
347  	};
348  	
349  	struct GroupSnapshotNamespace {
350  	  static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE =
351  	    SNAPSHOT_NAMESPACE_TYPE_GROUP;
352  	
353  	  GroupSnapshotNamespace() {}
354  	
355  	  GroupSnapshotNamespace(int64_t _group_pool,
356  				 const string &_group_id,
357  				 const string &_group_snapshot_id)
358  	    : group_id(_group_id), group_pool(_group_pool),
359  	      group_snapshot_id(_group_snapshot_id) {}
360  	
361  	  string group_id;
362  	  int64_t group_pool = 0;
363  	  string group_snapshot_id;
364  	
365  	  void encode(bufferlist& bl) const;
366  	  void decode(bufferlist::const_iterator& it);
367  	
368  	  void dump(Formatter *f) const;
369  	
370  	  inline bool operator==(const GroupSnapshotNamespace& gsn) const {
371  	    return group_pool == gsn.group_pool &&
372  		   group_id == gsn.group_id &&
373  		   group_snapshot_id == gsn.group_snapshot_id;
374  	  }
375  	
376  	  inline bool operator<(const GroupSnapshotNamespace& gsn) const {
377  	    if (group_pool < gsn.group_pool) {
378  	      return true;
379  	    } else if (group_id < gsn.group_id) {
380  	      return true;
381  	    } else {
382  	      return (group_snapshot_id < gsn.group_snapshot_id);
383  	    }
384  	    return false;
385  	  }
386  	};
387  	
388  	struct TrashSnapshotNamespace {
389  	  static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE =
390  	    SNAPSHOT_NAMESPACE_TYPE_TRASH;
391  	
392  	  std::string original_name;
393  	  SnapshotNamespaceType original_snapshot_namespace_type =
394  	    SNAPSHOT_NAMESPACE_TYPE_USER;
395  	
396  	  TrashSnapshotNamespace() {}
397  	  TrashSnapshotNamespace(SnapshotNamespaceType original_snapshot_namespace_type,
398  	                         const std::string& original_name)
399  	    : original_name(original_name),
400  	      original_snapshot_namespace_type(original_snapshot_namespace_type) {}
401  	
402  	  void encode(bufferlist& bl) const;
403  	  void decode(bufferlist::const_iterator& it);
404  	  void dump(Formatter *f) const;
405  	
406  	  inline bool operator==(const TrashSnapshotNamespace& usn) const {
407  	    return true;
408  	  }
409  	  inline bool operator<(const TrashSnapshotNamespace& usn) const {
410  	    return false;
411  	  }
412  	};
413  	
414  	struct UnknownSnapshotNamespace {
415  	  static const SnapshotNamespaceType SNAPSHOT_NAMESPACE_TYPE =
416  	    static_cast<SnapshotNamespaceType>(-1);
417  	
418  	  UnknownSnapshotNamespace() {}
419  	
420  	  void encode(bufferlist& bl) const {}
421  	  void decode(bufferlist::const_iterator& it) {}
422  	  void dump(Formatter *f) const {}
423  	
424  	  inline bool operator==(const UnknownSnapshotNamespace& gsn) const {
425  	    return true;
426  	  }
427  	
428  	  inline bool operator<(const UnknownSnapshotNamespace& gsn) const {
429  	    return false;
430  	  }
431  	};
432  	
433  	std::ostream& operator<<(std::ostream& os, const SnapshotNamespaceType& type);
434  	std::ostream& operator<<(std::ostream& os, const UserSnapshotNamespace& ns);
435  	std::ostream& operator<<(std::ostream& os, const GroupSnapshotNamespace& ns);
436  	std::ostream& operator<<(std::ostream& os, const TrashSnapshotNamespace& ns);
437  	std::ostream& operator<<(std::ostream& os, const UnknownSnapshotNamespace& ns);
438  	
439  	typedef boost::variant<UserSnapshotNamespace,
440  	                       GroupSnapshotNamespace,
441  	                       TrashSnapshotNamespace,
442  	                       UnknownSnapshotNamespace> SnapshotNamespaceVariant;
443  	
444  	struct SnapshotNamespace : public SnapshotNamespaceVariant {
445  	  SnapshotNamespace() {
446  	  }
447  	
448  	  template <typename T>
449  	  SnapshotNamespace(T&& t) : SnapshotNamespaceVariant(std::forward<T>(t)) {
450  	  }
451  	
452  	  void encode(bufferlist& bl) const;
453  	  void decode(bufferlist::const_iterator& it);
454  	  void dump(Formatter *f) const;
455  	
456  	  static void generate_test_instances(std::list<SnapshotNamespace*> &o);
457  	
458  	  inline bool operator==(const SnapshotNamespaceVariant& sn) const {
459  	    return static_cast<const SnapshotNamespaceVariant&>(*this) == sn;
460  	  }
461  	  inline bool operator<(const SnapshotNamespaceVariant& sn) const {
462  	    return static_cast<const SnapshotNamespaceVariant&>(*this) < sn;
463  	  }
464  	};
465  	WRITE_CLASS_ENCODER(SnapshotNamespace);
466  	
467  	SnapshotNamespaceType get_snap_namespace_type(
468  	    const SnapshotNamespace& snapshot_namespace);
469  	
470  	struct SnapshotInfo {
471  	  snapid_t id = CEPH_NOSNAP;
472  	  cls::rbd::SnapshotNamespace snapshot_namespace = {UserSnapshotNamespace{}};
473  	  std::string name;
474  	  uint64_t image_size = 0;
475  	  utime_t timestamp;
476  	  uint32_t child_count = 0;
477  	
478  	  SnapshotInfo() {
479  	  }
480  	  SnapshotInfo(snapid_t id,
481  	               const cls::rbd::SnapshotNamespace& snapshot_namespace,
482  	               const std::string& name, uint64_t image_size,
483  	               const utime_t& timestamp, uint32_t child_count)
484  	    : id(id), snapshot_namespace(snapshot_namespace),
485  	      name(name), image_size(image_size), timestamp(timestamp),
486  	      child_count(child_count) {
487  	  }
488  	
489  	  void encode(bufferlist& bl) const;
490  	  void decode(bufferlist::const_iterator& it);
491  	  void dump(Formatter *f) const;
492  	
493  	  static void generate_test_instances(std::list<SnapshotInfo*> &o);
494  	};
495  	WRITE_CLASS_ENCODER(SnapshotInfo);
496  	
497  	enum GroupSnapshotState {
498  	  GROUP_SNAPSHOT_STATE_INCOMPLETE = 0,
499  	  GROUP_SNAPSHOT_STATE_COMPLETE = 1,
500  	};
501  	
502  	inline void encode(const GroupSnapshotState &state, bufferlist& bl, uint64_t features=0)
503  	{
504  	  using ceph::encode;
505  	  encode(static_cast<uint8_t>(state), bl);
506  	}
507  	
508  	inline void decode(GroupSnapshotState &state, bufferlist::const_iterator& it)
509  	{
510  	  using ceph::decode;
511  	  uint8_t int_state;
512  	  decode(int_state, it);
513  	  state = static_cast<GroupSnapshotState>(int_state);
514  	}
515  	
516  	struct ImageSnapshotSpec {
517  	  int64_t pool;
518  	  string image_id;
519  	  snapid_t snap_id;
520  	
521  	  ImageSnapshotSpec() {}
522  	  ImageSnapshotSpec(int64_t _pool,
523  			    string _image_id,
524  			    snapid_t _snap_id) : pool(_pool),
525  						 image_id(_image_id),
526  						 snap_id(_snap_id) {}
527  	
528  	  void encode(bufferlist& bl) const;
529  	  void decode(bufferlist::const_iterator& it);
530  	
531  	  void dump(Formatter *f) const;
532  	
533  	  static void generate_test_instances(std::list<ImageSnapshotSpec *> &o);
534  	};
535  	WRITE_CLASS_ENCODER(ImageSnapshotSpec);
536  	
537  	struct GroupSnapshot {
538  	  std::string id;
539  	  std::string name;
540  	  GroupSnapshotState state = GROUP_SNAPSHOT_STATE_INCOMPLETE;
541  	
542  	  GroupSnapshot() {}
543  	  GroupSnapshot(std::string _id,
544  			std::string _name,
545  			GroupSnapshotState _state) : id(_id),
546  						     name(_name),
547  						     state(_state) {}
548  	
549  	  vector<ImageSnapshotSpec> snaps;
550  	
551  	  void encode(bufferlist& bl) const;
552  	  void decode(bufferlist::const_iterator& it);
553  	  void dump(Formatter *f) const;
554  	
555  	  static void generate_test_instances(std::list<GroupSnapshot *> &o);
556  	};
557  	WRITE_CLASS_ENCODER(GroupSnapshot);
558  	enum TrashImageSource {
559  	  TRASH_IMAGE_SOURCE_USER = 0,
560  	  TRASH_IMAGE_SOURCE_MIRRORING = 1,
561  	  TRASH_IMAGE_SOURCE_MIGRATION = 2,
562  	  TRASH_IMAGE_SOURCE_REMOVING = 3,
563  	  TRASH_IMAGE_SOURCE_USER_PARENT= 4,
564  	};
565  	
566  	inline std::ostream& operator<<(std::ostream& os,
567  	                                const TrashImageSource& source) {
568  	  switch (source) {
569  	  case TRASH_IMAGE_SOURCE_USER:
570  	    os << "user";
571  	    break;
572  	  case TRASH_IMAGE_SOURCE_MIRRORING:
573  	    os << "mirroring";
574  	    break;
575  	  case TRASH_IMAGE_SOURCE_MIGRATION:
576  	    os << "migration";
577  	    break;
578  	  case TRASH_IMAGE_SOURCE_REMOVING:
579  	    os << "removing";
580  	    break;
581  	  default:
582  	    os << "unknown (" << static_cast<uint32_t>(source) << ")";
583  	    break;
584  	  }
585  	  return os;
586  	}
587  	
588  	inline void encode(const TrashImageSource &source, bufferlist& bl,
589  			   uint64_t features=0)
590  	{
591  	  using ceph::encode;
592  	  encode(static_cast<uint8_t>(source), bl);
593  	}
594  	
595  	inline void decode(TrashImageSource &source, bufferlist::const_iterator& it)
596  	{
597  	  uint8_t int_source;
598  	  using ceph::decode;
599  	  decode(int_source, it);
600  	  source = static_cast<TrashImageSource>(int_source);
601  	}
602  	
603  	enum TrashImageState {
604  	  TRASH_IMAGE_STATE_NORMAL    = 0,
605  	  TRASH_IMAGE_STATE_MOVING    = 1,
606  	  TRASH_IMAGE_STATE_REMOVING  = 2,
607  	  TRASH_IMAGE_STATE_RESTORING = 3
608  	};
609  	
610  	inline void encode(const TrashImageState &state, bufferlist &bl)
611  	{
612  	  using ceph::encode;
613  	  encode(static_cast<uint8_t>(state), bl);
614  	}
615  	
616  	inline void decode(TrashImageState &state, bufferlist::const_iterator &it)
617  	{
618  	  uint8_t int_state;
619  	  using ceph::decode;
620  	  decode(int_state, it);
621  	  state = static_cast<TrashImageState>(int_state);
622  	}
623  	
624  	struct TrashImageSpec {
625  	  TrashImageSource source = TRASH_IMAGE_SOURCE_USER;
626  	  std::string name;
627  	  utime_t deletion_time; // time of deletion
628  	  utime_t deferment_end_time;
629  	  TrashImageState state = TRASH_IMAGE_STATE_NORMAL;
630  	
631  	  TrashImageSpec() {}
632  	  TrashImageSpec(TrashImageSource source, const std::string &name,
633  	                 const utime_t& deletion_time,
634  	                 const utime_t& deferment_end_time)
635  	    : source(source), name(name), deletion_time(deletion_time),
636  	      deferment_end_time(deferment_end_time) {
637  	  }
638  	
639  	  void encode(bufferlist &bl) const;
640  	  void decode(bufferlist::const_iterator& it);
641  	  void dump(Formatter *f) const;
642  	
643  	  inline bool operator==(const TrashImageSpec& rhs) const {
644  	    return (source == rhs.source &&
645  	            name == rhs.name &&
646  	            deletion_time == rhs.deletion_time &&
647  	            deferment_end_time == rhs.deferment_end_time);
648  	  }
649  	};
650  	WRITE_CLASS_ENCODER(TrashImageSpec);
651  	
652  	struct MirrorImageMap {
653  	  MirrorImageMap() {
654  	  }
655  	
656  	  MirrorImageMap(const std::string &instance_id, utime_t mapped_time,
657  	                 const bufferlist &data)
658  	    : instance_id(instance_id),
659  	      mapped_time(mapped_time),
660  	      data(data) {
661  	  }
662  	
663  	  std::string instance_id;
664  	  utime_t mapped_time;
665  	  bufferlist data;
666  	
667  	  void encode(bufferlist &bl) const;
668  	  void decode(bufferlist::const_iterator &it);
669  	  void dump(Formatter *f) const;
670  	
671  	  static void generate_test_instances(std::list<MirrorImageMap*> &o);
672  	
673  	  bool operator==(const MirrorImageMap &rhs) const;
674  	  bool operator<(const MirrorImageMap &rhs) const;
675  	};
676  	
677  	std::ostream& operator<<(std::ostream& os, const MirrorImageMap &image_map);
678  	
679  	WRITE_CLASS_ENCODER(MirrorImageMap);
680  	
681  	enum MigrationHeaderType {
682  	  MIGRATION_HEADER_TYPE_SRC = 1,
683  	  MIGRATION_HEADER_TYPE_DST = 2,
684  	};
685  	
686  	inline void encode(const MigrationHeaderType &type, bufferlist& bl) {
687  	  using ceph::encode;
688  	  encode(static_cast<uint8_t>(type), bl);
689  	}
690  	
691  	inline void decode(MigrationHeaderType &type, bufferlist::const_iterator& it) {
692  	  uint8_t int_type;
693  	  using ceph::decode;
694  	  decode(int_type, it);
695  	  type = static_cast<MigrationHeaderType>(int_type);
696  	}
697  	
698  	enum MigrationState {
699  	  MIGRATION_STATE_ERROR = 0,
700  	  MIGRATION_STATE_PREPARING = 1,
701  	  MIGRATION_STATE_PREPARED = 2,
702  	  MIGRATION_STATE_EXECUTING = 3,
703  	  MIGRATION_STATE_EXECUTED = 4,
704  	};
705  	
706  	inline void encode(const MigrationState &state, bufferlist& bl) {
707  	  using ceph::encode;
708  	  encode(static_cast<uint8_t>(state), bl);
709  	}
710  	
711  	inline void decode(MigrationState &state, bufferlist::const_iterator& it) {
712  	  uint8_t int_state;
713  	  using ceph::decode;
714  	  decode(int_state, it);
715  	  state = static_cast<MigrationState>(int_state);
716  	}
717  	
718  	std::ostream& operator<<(std::ostream& os,
719  	                         const MigrationState& migration_state);
720  	
721  	struct MigrationSpec {
722  	  MigrationHeaderType header_type = MIGRATION_HEADER_TYPE_SRC;
723  	  int64_t pool_id = -1;
724  	  std::string pool_namespace;
725  	  std::string image_name;
726  	  std::string image_id;
727  	  std::map<uint64_t, uint64_t> snap_seqs;
728  	  uint64_t overlap = 0;
729  	  bool flatten = false;
730  	  bool mirroring = false;
731  	  MigrationState state = MIGRATION_STATE_ERROR;
732  	  std::string state_description;
733  	
734  	  MigrationSpec() {
735  	  }
736  	  MigrationSpec(MigrationHeaderType header_type, int64_t pool_id,
737  	                const std::string& pool_namespace,
738  	                const std::string &image_name, const std::string &image_id,
739  	                const std::map<uint64_t, uint64_t> &snap_seqs, uint64_t overlap,
740  	                bool mirroring, bool flatten, MigrationState state,
741  	                const std::string &state_description)
742  	    : header_type(header_type), pool_id(pool_id),
743  	      pool_namespace(pool_namespace), image_name(image_name),
744  	      image_id(image_id), snap_seqs(snap_seqs), overlap(overlap),
745  	      flatten(flatten), mirroring(mirroring), state(state),
746  	      state_description(state_description) {
747  	  }
748  	
749  	  void encode(bufferlist &bl) const;
750  	  void decode(bufferlist::const_iterator& it);
751  	  void dump(Formatter *f) const;
752  	
753  	  static void generate_test_instances(std::list<MigrationSpec*> &o);
754  	
755  	  inline bool operator==(const MigrationSpec& ms) const {
756  	    return header_type == ms.header_type && pool_id == ms.pool_id &&
757  	      pool_namespace == ms.pool_namespace && image_name == ms.image_name &&
758  	      image_id == ms.image_id && snap_seqs == ms.snap_seqs &&
759  	      overlap == ms.overlap && flatten == ms.flatten &&
760  	      mirroring == ms.mirroring && state == ms.state &&
761  	      state_description == ms.state_description;
762  	  }
763  	};
764  	
765  	std::ostream& operator<<(std::ostream& os, const MigrationSpec& migration_spec);
766  	
767  	WRITE_CLASS_ENCODER(MigrationSpec);
768  	
769  	enum AssertSnapcSeqState {
770  	  ASSERT_SNAPC_SEQ_GT_SNAPSET_SEQ = 0,
771  	  ASSERT_SNAPC_SEQ_LE_SNAPSET_SEQ = 1,
772  	};
773  	
774  	inline void encode(const AssertSnapcSeqState &state, bufferlist& bl) {
775  	  using ceph::encode;
776  	  encode(static_cast<uint8_t>(state), bl);
777  	}
778  	
779  	inline void decode(AssertSnapcSeqState &state, bufferlist::const_iterator& it) {
780  	  uint8_t int_state;
781  	  using ceph::decode;
782  	  decode(int_state, it);
783  	  state = static_cast<AssertSnapcSeqState>(int_state);
784  	}
785  	
786  	std::ostream& operator<<(std::ostream& os, const AssertSnapcSeqState& state);
787  	
788  	} // namespace rbd
789  	} // namespace cls
790  	
791  	#endif // CEPH_CLS_RBD_TYPES_H
792