]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
RADOS: Data structures for Objecter to decode
authorAdam C. Emerson <aemerson@redhat.com>
Sat, 14 Mar 2020 06:45:41 +0000 (02:45 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Fri, 15 May 2020 14:55:10 +0000 (10:55 -0400)
These are broken out so the header can be included by Objecter and we
don't have to do a bunch of copies/moves.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/include/RADOS/RADOS_Decodable.hpp [new file with mode: 0644]

diff --git a/src/include/RADOS/RADOS_Decodable.hpp b/src/include/RADOS/RADOS_Decodable.hpp
new file mode 100644 (file)
index 0000000..023ebb8
--- /dev/null
@@ -0,0 +1,107 @@
+// -*- 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) 2020 Red Hat <contact@redhat.com>
+ * Author: Adam C. Emerson
+ *
+ * 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 RADOS_DECODABLE_HPP
+#define RADOS_DECODABLE_HPP
+
+#include <cstdint>
+#include <cstdlib>
+#include <string>
+#include <iostream>
+#include <tuple>
+#include <utility>
+#include <vector>
+
+namespace RADOS {
+struct Entry {
+  std::string nspace;
+  std::string oid;
+  std::string locator;
+
+  Entry() {}
+  Entry(std::string nspace, std::string oid, std::string locator) :
+    nspace(std::move(nspace)), oid(std::move(oid)), locator(locator) {}
+};
+inline bool operator ==(const Entry& l, const Entry r) {
+  return std::tie(l.nspace, l.oid, l.locator) ==
+    std::tie(r.nspace, r.oid, r.locator);
+}
+inline bool operator !=(const Entry& l, const Entry r) {
+  return std::tie(l.nspace, l.oid, l.locator) !=
+    std::tie(r.nspace, r.oid, r.locator);
+}
+inline bool operator <(const Entry& l, const Entry r) {
+  return std::tie(l.nspace, l.oid, l.locator) <
+    std::tie(r.nspace, r.oid, r.locator);
+}
+inline bool operator <=(const Entry& l, const Entry r) {
+  return std::tie(l.nspace, l.oid, l.locator) <=
+    std::tie(r.nspace, r.oid, r.locator);
+}
+inline bool operator >=(const Entry& l, const Entry r) {
+  return std::tie(l.nspace, l.oid, l.locator) >=
+    std::tie(r.nspace, r.oid, r.locator);
+}
+inline bool operator >(const Entry& l, const Entry r) {
+  return std::tie(l.nspace, l.oid, l.locator) >
+    std::tie(r.nspace, r.oid, r.locator);
+}
+
+inline std::ostream& operator <<(std::ostream& out, const Entry& entry) {
+  if (!entry.nspace.empty())
+    out << entry.nspace << '/';
+  out << entry.oid;
+  if (!entry.locator.empty())
+    out << '@' << entry.locator;
+  return out;
+}
+
+struct CloneInfo {
+  uint64_t cloneid = 0;
+  std::vector<uint64_t> snaps; // ascending
+  std::vector<std::pair<uint64_t, uint64_t>> overlap;// with next newest
+  uint64_t size = 0;
+  CloneInfo() = default;
+};
+
+struct SnapSet {
+  std::vector<CloneInfo> clones; // ascending
+  std::uint64_t seq = 0;   // newest snapid seen by the object
+  SnapSet() = default;
+};
+
+struct ObjWatcher {
+  /// Address of the Watcher
+  std::string addr;
+  /// Watcher ID
+  std::int64_t watcher_id;
+  /// Cookie
+  std::uint64_t cookie;
+  /// Timeout in Seconds
+  std::uint32_t timeout_seconds;
+};
+}
+
+namespace std {
+template<>
+struct hash<::RADOS::Entry> {
+  std::size_t operator ()(::RADOS::Entry e) const {
+    hash<std::string> h;
+    return (h(e.nspace) << 2) ^ (h(e.oid) << 1) ^ h(e.locator);
+  }
+};
+}
+
+#endif // RADOS_DECODABLE_HPP