Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / mds / FSMapUser.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software
11  * Foundation.  See file COPYING.
12  */
13
14 #ifndef CEPH_FSMAPCOMPACT_H
15 #define CEPH_FSMAPCOMPACT_H
16
17 #include "mds/mdstypes.h"
18 #include <map>
19 #include <string>
20
21 class FSMapUser {
22 public:
23   struct fs_info_t {
24     fs_cluster_id_t cid;
25     std::string name;
26     fs_info_t() : cid(FS_CLUSTER_ID_NONE) {}
27     void encode(bufferlist& bl, uint64_t features) const;
28     void decode(bufferlist::iterator &bl);
29   };
30
31   epoch_t epoch;
32   fs_cluster_id_t legacy_client_fscid;
33   std::map<fs_cluster_id_t, fs_info_t> filesystems;
34
35   FSMapUser()
36     : epoch(0), legacy_client_fscid(FS_CLUSTER_ID_NONE) { }
37
38   epoch_t get_epoch() const { return epoch; }
39
40   fs_cluster_id_t get_fs_cid(const std::string &name) const {
41     for (auto &p : filesystems) {
42       if (p.second.name == name)
43         return p.first;
44     }
45     return FS_CLUSTER_ID_NONE;
46   }
47
48   void encode(bufferlist& bl, uint64_t features) const;
49   void decode(bufferlist::iterator& bl);
50
51   void print(ostream& out) const;
52   void print_summary(Formatter *f, ostream *out);
53
54   static void generate_test_instances(list<FSMapUser*>& ls);
55 };
56 WRITE_CLASS_ENCODER_FEATURES(FSMapUser::fs_info_t)
57 WRITE_CLASS_ENCODER_FEATURES(FSMapUser)
58
59 inline ostream& operator<<(ostream& out, FSMapUser& m) {
60   m.print_summary(NULL, &out);
61   return out;
62 }
63 #endif