summaryrefslogtreecommitdiffstats
path: root/src/tools/cephfs_mirror/Types.h
blob: 016a8dc860c5bcdbf20bc80542fe4a6476cb5e48 (plain)
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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPHFS_MIRROR_TYPES_H
#define CEPHFS_MIRROR_TYPES_H

#include <set>
#include <iostream>
#include <string_view>

#include "include/rados/librados.hpp"
#include "include/cephfs/libcephfs.h"
#include "mds/mdstypes.h"

namespace cephfs {
namespace mirror {

static const std::string CEPHFS_MIRROR_OBJECT("cephfs_mirror");

typedef boost::variant<bool, uint64_t, std::string> AttributeValue;
typedef std::map<std::string, AttributeValue> Attributes;

// distinct filesystem identifier
struct Filesystem {
  fs_cluster_id_t fscid;
  std::string fs_name;

  bool operator==(const Filesystem &rhs) const {
    return (fscid == rhs.fscid &&
            fs_name == rhs.fs_name);
  }

  bool operator!=(const Filesystem &rhs) const {
    return !(*this == rhs);
  }

  bool operator<(const Filesystem &rhs) const {
    if (fscid != rhs.fscid) {
      return fscid < rhs.fscid;
    }

    return fs_name < rhs.fs_name;
  }
};

// specification of a filesystem -- pool id the metadata pool id.
struct FilesystemSpec {
  FilesystemSpec() = default;
  FilesystemSpec(const Filesystem &filesystem, uint64_t pool_id)
    : filesystem(filesystem),
      pool_id(pool_id) {
  }
  FilesystemSpec(fs_cluster_id_t fscid, std::string_view fs_name, uint64_t pool_id)
    : filesystem(Filesystem{fscid, std::string(fs_name)}),
      pool_id(pool_id) {
  }

  Filesystem filesystem;
  uint64_t pool_id;

  bool operator==(const FilesystemSpec &rhs) const {
    return (filesystem == rhs.filesystem &&
            pool_id == rhs.pool_id);
  }

  bool operator<(const FilesystemSpec &rhs) const {
    if (filesystem != rhs.filesystem) {
      return filesystem < rhs.filesystem;
    }

    return pool_id < rhs.pool_id;
  }
};

std::ostream& operator<<(std::ostream& out, const Filesystem &filesystem);
std::ostream& operator<<(std::ostream& out, const FilesystemSpec &spec);

typedef std::shared_ptr<librados::Rados> RadosRef;
typedef std::shared_ptr<librados::IoCtx> IoCtxRef;

// not a shared_ptr since the type is incomplete
typedef ceph_mount_info *MountRef;

} // namespace mirror
} // namespace cephfs

#endif // CEPHFS_MIRROR_TYPES_H