From 48751ce007bd090ced750a15ec169084105b9aae Mon Sep 17 00:00:00 2001 From: sageweil Date: Tue, 3 Oct 2006 22:48:30 +0000 Subject: [PATCH] git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@907 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/mds/MDSMap.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 ceph/mds/MDSMap.h diff --git a/ceph/mds/MDSMap.h b/ceph/mds/MDSMap.h new file mode 100644 index 0000000000000..b08a5d6698523 --- /dev/null +++ b/ceph/mds/MDSMap.h @@ -0,0 +1,90 @@ +// -*- mode:C++; tab-width:4; c-basic-offset:2; indent-tabs-mode:t -*- +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * 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 __MDSMAP_H +#define __MDSMAP_H + +#include "include/types.h" + +#include +#include +using namespace std; + +class MDSMap { + protected: + epoch_t epoch; + utime_t ctime; + + set all_mds; + set down_mds; + map mds_inst; + + public: + MDSMap() : epoch(0) {} + + epoch_t get_epoch() const { return epoch; } + void inc_epoch() { epoch++; } + + const utime_t& get_ctime() const { return ctime; } + + int get_num_mds() const { + return up_mds.size() + down_mds.size(); + } + int get_num_up_mds() const { + return up_mds.size(); + } + + const set& get_mds() const { return all_mds; } + const set& get_down_mds() const { return down_mds; } + + bool is_down(int m) const { return down_mds.count(m); } + bool is_up(int m) const { return !is_mds(m); } + + bool lookup(int m, entity_inst_t& inst) { + if (mds_inst.count(m)) { + inst = mds_inst[m]; + return true; + } + return false; + } + + // serialize, unserialize + void encode(bufferlist& blist) { + blist.append((char*)&epoch, sizeof(epoch)); + blist.append((char*)&ctime, sizeof(ctime)); + + _encode(all_mds, blist); + _encode(down_mds, blist); + _encode(mds_inst, blist); + } + + void decode(bufferlist& blist) { + int off = 0; + blist.copy(off, sizeof(epoch), (char*)&epoch); + off += sizeof(epoch); + blist.copy(off, sizeof(ctime), (char*)&ctime); + off += sizeof(ctime); + + _decode(all_mds, blist, off); + _decode(down_mds, blist, off); + _decode(mds_inst, blist, off); + } + + + /*** mapping functions ***/ + + int hash_dentry( inodeno_t dirino, const string& dn ); +}; + +#endif -- 2.39.5