]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: add FSMapUser
authorYan, Zheng <zyan@redhat.com>
Wed, 6 Apr 2016 12:50:54 +0000 (20:50 +0800)
committerYan, Zheng <zyan@redhat.com>
Fri, 10 Jun 2016 01:25:06 +0000 (09:25 +0800)
FSMapUser is compact version of FSMap, it includes FSMap data that are
visiable to normal users.

Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/CMakeLists.txt
src/common/Makefile.am
src/mds/FSMapUser.cc [new file with mode: 0644]
src/mds/FSMapUser.h [new file with mode: 0644]
src/mds/Makefile-server.am

index 1cc06f58f6d330814f9b7af053fe21e5c79fc0b7..b5a356a2689765ee3a9900471e278e2276499a9c 100644 (file)
@@ -296,6 +296,7 @@ set(mds_files)
 list(APPEND mds_files
   mds/MDSMap.cc
   mds/FSMap.cc
+  mds/FSMapUser.cc
   mds/inode_backtrace.cc
   mds/mdstypes.cc)
 
index a00859788dc8ff9d8e848707996c564c4f19b62a..8c9db1ef27bdf47ac755573dc190048aa6422595 100644 (file)
@@ -121,6 +121,7 @@ libcommon_internal_la_SOURCES += \
        osd/HitSet.cc \
        mds/MDSMap.cc \
        mds/FSMap.cc \
+       mds/FSMapUser.cc \
        mds/inode_backtrace.cc \
        mds/mdstypes.cc \
        mds/flock.cc
diff --git a/src/mds/FSMapUser.cc b/src/mds/FSMapUser.cc
new file mode 100644 (file)
index 0000000..8471708
--- /dev/null
@@ -0,0 +1,81 @@
+#include "FSMapUser.h"
+
+void FSMapUser::encode(bufferlist& bl, uint64_t features) const
+{
+  ENCODE_START(1, 1, bl);
+  ::encode(epoch, bl);
+  ::encode(legacy_client_fscid, bl);
+  std::vector<fs_info_t> fs_list;
+  for (auto p = filesystems.begin(); p != filesystems.end(); ++p)
+    fs_list.push_back(p->second);
+  ::encode(fs_list, bl, features);
+  ENCODE_FINISH(bl);
+}
+
+void FSMapUser::decode(bufferlist::iterator& p)
+{
+  DECODE_START(1, p);
+  ::decode(epoch, p);
+  ::decode(legacy_client_fscid, p);
+  std::vector<fs_info_t> fs_list;
+  ::decode(fs_list, p);
+  filesystems.clear();
+  for (auto p = fs_list.begin(); p != fs_list.end(); ++p)
+    filesystems[p->cid] = *p;
+  DECODE_FINISH(p);
+}
+
+void FSMapUser::fs_info_t::encode(bufferlist& bl, uint64_t features) const
+{
+  ENCODE_START(1, 1, bl);
+  ::encode(cid, bl);
+  ::encode(name, bl);
+  ENCODE_FINISH(bl);
+}
+
+void FSMapUser::fs_info_t::decode(bufferlist::iterator& p)
+{
+  DECODE_START(1, p);
+  ::decode(cid, p);
+  ::decode(name, p);
+  DECODE_FINISH(p);
+}
+
+void FSMapUser::generate_test_instances(list<FSMapUser*>& ls)
+{
+  FSMapUser *m = new FSMapUser();
+  m->epoch = 2;
+  m->legacy_client_fscid = 1;
+  m->filesystems[1].cid = 1;
+  m->filesystems[2].name = "cephfs2";
+  m->filesystems[2].cid = 2;
+  m->filesystems[1].name = "cephfs1";
+  ls.push_back(m);
+}
+
+
+void FSMapUser::print(ostream& out) const
+{
+  out << "e" << epoch << std::endl;
+  out << "legacy_client_fscid: " << legacy_client_fscid << std::endl;
+  for (auto &p : filesystems)
+    out << " id " <<  p.second.cid << " name " << p.second.name << std::endl;
+}
+
+void FSMapUser::print_summary(Formatter *f, ostream *out)
+{
+  map<mds_role_t,string> by_rank;
+  map<string,int> by_state;
+
+  if (f) {
+    f->dump_unsigned("epoch", get_epoch());
+    for (auto &p : filesystems) {
+      f->dump_unsigned("id", p.second.cid);
+      f->dump_string("name", p.second.name);
+    }
+  } else {
+    *out << "e" << get_epoch() << ":";
+    for (auto &p : filesystems)
+      *out << " " << p.second.name << "(" << p.second.cid << ")";
+  }
+}
diff --git a/src/mds/FSMapUser.h b/src/mds/FSMapUser.h
new file mode 100644 (file)
index 0000000..4884f68
--- /dev/null
@@ -0,0 +1,75 @@
+// -*- 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) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * 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 CEPH_FSMAPCOMPACT_H
+#define CEPH_FSMAPCOMPACT_H
+
+#include "mds/mdstypes.h"
+#include <map>
+#include <string>
+
+class FSMapUser {
+public:
+  struct fs_info_t {
+    fs_cluster_id_t cid;
+    std::string name;
+    fs_info_t() : cid(FS_CLUSTER_ID_NONE) {}
+    void encode(bufferlist& bl, uint64_t features) const;
+    void decode(bufferlist::iterator &bl);
+  };
+
+  epoch_t epoch;
+  fs_cluster_id_t legacy_client_fscid;
+  std::map<fs_cluster_id_t, fs_info_t> filesystems;
+
+  FSMapUser()
+    : epoch(0), legacy_client_fscid(FS_CLUSTER_ID_NONE) { }
+
+  FSMapUser(const FSMapUser &o)
+    : epoch(o.epoch), legacy_client_fscid(o.legacy_client_fscid),
+      filesystems(o.filesystems) { }
+
+  FSMapUser &operator=(const FSMapUser &o)
+  {
+    epoch = o.epoch;
+    legacy_client_fscid = o.legacy_client_fscid;
+    filesystems = o.filesystems;
+    return *this;
+  }
+
+  epoch_t get_epoch() const { return epoch; }
+
+  fs_cluster_id_t get_fs_cid(const std::string &name) const {
+    for (auto &p : filesystems) {
+      if (p.second.name == name)
+       return p.first;
+    }
+    return FS_CLUSTER_ID_NONE;
+  }
+
+  void encode(bufferlist& bl, uint64_t features) const;
+  void decode(bufferlist::iterator& bl);
+
+  void print(ostream& out) const;
+  void print_summary(Formatter *f, ostream *out);
+
+  static void generate_test_instances(list<FSMapUser*>& ls);
+};
+WRITE_CLASS_ENCODER_FEATURES(FSMapUser::fs_info_t)
+WRITE_CLASS_ENCODER_FEATURES(FSMapUser)
+
+inline ostream& operator<<(ostream& out, FSMapUser& m) {
+  m.print_summary(NULL, &out);
+  return out;
+}
+#endif
index 97378a295e41bdca470575d7617e197be88f2d0d..36031eb60f12833f3dcf0e0c14843849364eff27 100644 (file)
@@ -32,6 +32,7 @@ noinst_HEADERS += \
        mds/MDSAuthCaps.h \
        mds/MDSMap.h \
        mds/FSMap.h \
+       mds/FSMapUser.h \
        mds/MDSTable.h \
        mds/MDSTableServer.h \
        mds/MDSTableClient.h \