mirror of
https://github.com/ceph/ceph
synced 2025-02-21 01:47:25 +00:00
beginnings of monitorstore thinger
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1085 29311d96-e01e-0410-9327-a35deaab8ce9
This commit is contained in:
parent
18268f7793
commit
e4f8d29840
79
branches/riccardo/monitor2/mon/MonitorStore.cc
Normal file
79
branches/riccardo/monitor2/mon/MonitorStore.cc
Normal file
@ -0,0 +1,79 @@
|
||||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "MonitorStore.h"
|
||||
#include "common/Clock.h"
|
||||
|
||||
#include "config.h"
|
||||
#undef dout
|
||||
#define dout(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cout << g_clock.now() << " store(" << dir <<") "
|
||||
#define derr(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cerr << g_clock.now() << " store(" << dir <<") "
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
void MonitorStore::init()
|
||||
{
|
||||
// verify dir exists
|
||||
DIR *d = ::opendir(dir);
|
||||
if (!d) {
|
||||
derr(1) << "basedir " << dir << " dne" << endl;
|
||||
assert(0);
|
||||
}
|
||||
::closedir(d);
|
||||
}
|
||||
|
||||
|
||||
version_t MonitorStore::get_int(const char *a, const char *b)
|
||||
{
|
||||
char fn[200];
|
||||
if (b)
|
||||
sprintf(fn, "%s/%s/%s", dir, a, b);
|
||||
else
|
||||
sprintf(fn, "%s/%s", dir, a);
|
||||
|
||||
FILE *f = ::fopen(fn, "r");
|
||||
if (!f)
|
||||
return 0;
|
||||
|
||||
char buf[20];
|
||||
::fgets(buf, 20, f);
|
||||
::fclose(f);
|
||||
|
||||
version_t val = atoi(buf);
|
||||
|
||||
if (b) {
|
||||
dout(10) << "get_int " << a << "/" << b << " = " << val << endl;
|
||||
} else {
|
||||
dout(10) << "get_int " << a << " = " << val << endl;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
void MonitorStore::set_int(version_t val, const char *a, const char *b)
|
||||
{
|
||||
char fn[200];
|
||||
if (b) {
|
||||
dout(10) << "set_int " << a << "/" << b << " = " << val << endl;
|
||||
sprintf(fn, "%s/%s/%s", dir, a, b);
|
||||
} else {
|
||||
dout(10) << "set_int " << a << " = " << val << endl;
|
||||
sprintf(fn, "%s/%s", dir, a);
|
||||
}
|
||||
|
||||
FILE *f = ::fopen(fn, "w");
|
||||
assert(f);
|
||||
::fprintf(f, "%lld\n", val);
|
||||
::fclose(f);
|
||||
}
|
45
branches/riccardo/monitor2/mon/MonitorStore.h
Normal file
45
branches/riccardo/monitor2/mon/MonitorStore.h
Normal file
@ -0,0 +1,45 @@
|
||||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
|
||||
/*
|
||||
* 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 __MON_MONITORSTORE_H
|
||||
#define __MON_MONITORSTORE_H
|
||||
|
||||
#include "include/types.h"
|
||||
#include "include/buffer.h"
|
||||
|
||||
class MonitorStore {
|
||||
const char *dir;
|
||||
|
||||
version_t get_int(const char *a, const char *b=0);
|
||||
void set_int(version_t v, const char *a, const char *b=0);
|
||||
|
||||
int get_bl(const char *nm, bufferlist& bl);
|
||||
int put_bl(const char *nm, bufferlist& bl);
|
||||
|
||||
void init();
|
||||
|
||||
public:
|
||||
MonitorStore(const char *d) :
|
||||
dir(d) {
|
||||
init();
|
||||
}
|
||||
|
||||
version_t get_incarnation() { return get_int("incarnation"); }
|
||||
void set_incarnation(version_t i) { set_int(i, "incarnation"); }
|
||||
|
||||
version_t get_last_proposal() { return get_int("last_proposal"); }
|
||||
void set_last_proposal(version_t i) { set_int(i, "last_proposal"); }
|
||||
};
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user