-#include "InoAllocator.h"
+#include "IdAllocator.h"
#include "MDS.h"
#include <cassert>
write(fd, (char*)&ntypes, sizeof(ntypes));
// over types
- for (map<char, map<id_t,id_t> >::iterator ty = free.begin();
+ for (map<char, map<idno_t,idno_t> >::iterator ty = free.begin();
ty != free.end();
ty++) {
char type = *ty;
write(fd, (char*)&mapsize, sizeof(mapsize));
// over entries
- for (map<id_t,id_t>::iterator it = free[type]..map_begin();
+ for (map<idno_t,idno_t>::iterator it = free[type]..map_begin();
it != free[type].map_end();
it++) {
- id_t a = it->first;
- id_t b = it->second;
+ idno_t a = it->first;
+ idno_t b = it->second;
write(fd, &a, sizeof(a));
write(fd, &b, sizeof(b));
}
int mapsize = 0;
read(fd, &mapsize, sizeof(mapsize));
for (int i=0; i<mapsize; i++) {
- id_t a,b;
+ idno_t a,b;
read(fd, &a, sizeof(a));
read(fd, &b, sizeof(b));
free[type].map_insert(a,b);
-#ifndef __INOALLOCATOR_H
-#define __INOALLOCATOR_H
+#ifndef __IDALLOCATOR_H
+#define __IDALLOCATOR_H
#include "include/types.h"
#include "rangeset.h"
#define ID_INO 1 // inode
#define ID_FH 2 // file handle
-typedef __uint64_t id_t
+typedef __uint64_t idno_t;
class IdAllocator {
MDS *mds;
- map< char, rangeset<id_t> > free; // type -> rangeset
+ map< char, rangeset<idno_t> > free; // type -> rangeset
public:
IdAllocator();
//~InoAllocator();
- id_t get_id(char type) {
+ idno_t get_id(char type) {
free[type].dump();
- id_t ino = free[type].first();
- free[type].erase(ino);
- cout << "id type " << type << " is " << ino << endl;
+ idno_t id = free[type].first();
+ free[type].erase(id);
+ cout << "id type " << type << " is " << id << endl;
free[type].dump();
save();
return id;
}
- void reclaim_id(char type, id_t ino) {
- free[type].insert(ino);
+ void reclaim_id(char type, idno_t id) {
+ free[type].insert(id);
save();
}