}
+
+
// ? is this the best way ?
class C_E_FlushPartial : public Context {
Ebofs *ebofs;
dout(10) << "apply_write extending object size " << on->object_size
<< " -> " << off+len << endl;
on->object_size = off+len;
+ on->mark_dirty();
}
if (zleft)
dout(10) << "apply_write zeroing first " << zleft << " bytes" << endl;
}
+int Ebofs::write(object_t oid,
+ size_t len, off_t off,
+ bufferlist& bl, bool fsync)
+{
+ // FIXME
+ return write(oid, len, off, bl, (Context*)0);
+}
+
int Ebofs::write(object_t oid,
size_t len, off_t off,
bufferlist& bl, Context *onflush)
if (!on)
on = new_onode(oid); // new inode!
- // apply to buffer cache
- apply_write(on, len, off, bl);
-
// allocate more space?
block_t bnum = (len+off-1) / EBOFS_BLOCK_SIZE + 1;
if (bnum > on->object_blocks) {
}
}
+ // apply to buffer cache
+ apply_write(on, len, off, bl);
+
// attr changes
}
+int Ebofs::remove(object_t oid)
+{
+ // get inode
+ Onode *on = get_onode(oid);
+ if (!on) return -1;
+
+ // FIXME locking, buffer, flushing etc.
+ assert(0);
+
+ remove_onode(on);
+ return 0;
+}
+
+int Ebofs::truncate(object_t oid, off_t size)
+{
+ assert(0);
+}
+
+
+
+bool Ebofs::exists(object_t oid)
+{
+ Onode *on = get_onode(oid);
+ if (!on)
+ return false;
+ put_onode(on);
+ return true;
+}
+
+int Ebofs::stat(object_t oid, struct stat *st)
+{
+ Onode *on = get_onode(oid);
+ if (!on)
+ return -1;
+
+ // ??
+ st->st_size = on->object_size;
+
+ put_onode(on);
+ return 0;
+}
+
+// attributes
+
+int Ebofs::setattr(object_t oid, const char *name, void *value, size_t size)
+{
+ Onode *on = get_onode(oid);
+ if (!on) return -1;
+
+ string n(name);
+ AttrVal val((char*)value, size);
+ on->attr[n] = val;
+ on->mark_dirty();
+
+ put_onode(on);
+ return 0;
+}
+
+int Ebofs::getattr(object_t oid, const char *name, void *value, size_t size)
+{
+ Onode *on = get_onode(oid);
+ if (!on) return -1;
+
+ string n(name);
+ if (on->attr.count(n) == 0) return -1;
+ memcpy(value, on->attr[n].data, MIN( on->attr[n].len, (int)size ));
+
+ on->mark_dirty();
+ put_onode(on);
+ return 0;
+}
+
+int Ebofs::rmattr(object_t oid, const char *name)
+{
+ Onode *on = get_onode(oid);
+ if (!on) return -1;
+
+ string n(name);
+ on->attr.erase(n);
+
+ on->mark_dirty();
+ put_onode(on);
+ return 0;
+}
+
+int Ebofs::listattr(object_t oid, vector<string>& attrs)
+{
+ Onode *on = get_onode(oid);
+ if (!on) return -1;
+
+ attrs.clear();
+ for (map<string,AttrVal>::iterator i = on->attr.begin();
+ i != on->attr.end();
+ i++) {
+ attrs.push_back(i->first);
+ }
+
+ put_onode(on);
+ return 0;
+}
return num;
}
+
+int Ebofs::collection_setattr(coll_t cid, const char *name, void *value, size_t size)
+{
+ Cnode *cn = get_cnode(cid);
+ if (!cn) return -1;
+
+ string n(name);
+ AttrVal val((char*)value, size);
+ cn->attr[n] = val;
+ cn->mark_dirty();
+
+ put_cnode(cn);
+ return 0;
+}
+
+int Ebofs::collection_getattr(coll_t cid, const char *name, void *value, size_t size)
+{
+ Cnode *cn = get_cnode(cid);
+ if (!cn) return -1;
+
+ string n(name);
+ if (cn->attr.count(n) == 0) return -1;
+ memcpy(value, cn->attr[n].data, MIN( cn->attr[n].len, (int)size ));
+
+ cn->mark_dirty();
+ put_cnode(cn);
+ return 0;
+}
+
+int Ebofs::collection_rmattr(coll_t cid, const char *name)
+{
+ Cnode *cn = get_cnode(cid);
+ if (!cn) return -1;
+
+ string n(name);
+ cn->attr.erase(n);
+
+ cn->mark_dirty();
+ put_cnode(cn);
+ return 0;
+}
+
+int Ebofs::collection_listattr(coll_t cid, vector<string>& attrs)
+{
+ Cnode *cn = get_cnode(cid);
+ if (!cn) return -1;
+
+ attrs.clear();
+ for (map<string,AttrVal>::iterator i = cn->attr.begin();
+ i != cn->attr.end();
+ i++) {
+ attrs.push_back(i->first);
+ }
+
+ put_cnode(cn);
+ return 0;
+}
+
+
#include "common/Mutex.h"
#include "common/Cond.h"
+#include "osd/ObjectStore.h"
typedef pair<object_t,coll_t> idpair_t;
}
-class Ebofs {
+class Ebofs : public ObjectStore {
protected:
Mutex ebofs_lock; // a beautiful global lock
// object interface
+ bool exists(object_t);
+ int stat(object_t, struct stat*);
int read(object_t, size_t len, off_t off, bufferlist& bl);
+ int write(object_t oid,
+ size_t len, off_t off,
+ bufferlist& bl, bool fsync=true);
int write(object_t oid,
size_t len, off_t offset,
bufferlist& bl,
// object attr
int setattr(object_t oid, const char *name, void *value, size_t size);
int getattr(object_t oid, const char *name, void *value, size_t size);
+ int rmattr(object_t oid, const char *name);
int listattr(object_t oid, vector<string>& attrs);
// collections
int collection_setattr(object_t oid, const char *name, void *value, size_t size);
int collection_getattr(object_t oid, const char *name, void *value, size_t size);
+ int collection_rmattr(coll_t cid, const char *name);
int collection_listattr(object_t oid, vector<string>& attrs);
};
ObjectCache *oc;
+ bool dirty;
public:
Onode(object_t oid) : ref(0), object_id(oid),
- object_size(0), object_blocks(0), oc(0) {
+ object_size(0), object_blocks(0), oc(0),
+ dirty(false) {
onode_loc.length = 0;
}
~Onode() {
if (ref == 0) lru_unpin();
cout << "onode.put " << ref << endl;
}
+
+ void mark_dirty() {
+ if (!dirty) {
+ dirty = true;
+ get();
+ }
+ }
+ void mark_clean() {
+ if (dirty) {
+ dirty = false;
+ put();
+ }
+ }
+ bool is_dirty() { return dirty; }
+
ObjectCache *get_oc(BufferCache *bc) {
if (!oc) {
char crap[10000];
memset(crap, 0, 10000);
bl.append(crap, 10000);
- fs.write(10, bl.length(), 200, bl, 0);
+ fs.write(10, bl.length(), 200, bl, (Context*)0);
fs.trim_buffer_cache();
- fs.write(10, bl.length(), 3222, bl, 0);
+ fs.write(10, bl.length(), 3222, bl, (Context*)0);
fs.trim_buffer_cache();
- fs.write(10, 5000, 3222, bl, 0);
+ fs.write(10, 5000, 3222, bl, (Context*)0);
}
// test small writes
off_t off = rand() % 1000000;
size_t len = 100;
cout << "writing bit at " << off << " len " << len << endl;
- fs.write(10, len, off, bl, 0);
+ fs.write(10, len, off, bl, (Context*)0);
}
if (0) {
off_t off = rand() % 1000000;
size_t len = 100;
cout << "writing bit at " << off << " len " << len << endl;
- fs.write(10, len, off, bl, 0);
+ fs.write(10, len, off, bl, (Context*)0);
}
}
compile now?
*/
+/*
namespace __gnu_cxx {
template<> struct hash<unsigned long long> {
size_t operator()(unsigned long long __x) const {
}
};
}
+*/
// disk
}
-int FakeStore::init()
+int FakeStore::mount()
{
string mydir;
get_dir(mydir);
return 0;
}
-int FakeStore::finalize()
+int FakeStore::umount()
{
dout(5) << "finalize" << endl;
return 0;
}
-int FakeStore::collection_stat(coll_t c, struct stat *st) {
- if (!collections.is_open()) open_collections();
-
- string fn;
- get_collfn(c,fn);
- return ::stat(fn.c_str(), st);
-}
-
-int FakeStore::collection_create(coll_t c) {
+int FakeStore::create_collection(coll_t c) {
if (!collections.is_open()) open_collections();
collections.put(c, 1);
return 0;
}
-int FakeStore::collection_destroy(coll_t c) {
+int FakeStore::destroy_collection(coll_t c) {
if (!collections.is_open()) open_collections();
collections.del(c);
return 0;
}
+int FakeStore::collection_stat(coll_t c, struct stat *st) {
+ if (!collections.is_open()) open_collections();
+
+ string fn;
+ get_collfn(c,fn);
+ return ::stat(fn.c_str(), st);
+}
+
+bool FakeStore::collection_exists(coll_t c) {
+ struct stat st;
+ return collection_stat(c, &st) == 0;
+}
+
int FakeStore::collection_add(coll_t c, object_t o) {
if (!collections.is_open()) open_collections();
public:
FakeStore(char *base, int whoami);
- int init();
- int finalize();
+ int mount();
+ int umount();
int mkfs();
public:
int list_collections(list<coll_t>& ls);
+ int create_collection(coll_t c);
+ int destroy_collection(coll_t c);
int collection_stat(coll_t c, struct stat *st);
- int collection_create(coll_t c);
- int collection_destroy(coll_t c);
+ bool collection_exists(coll_t c);
int collection_add(coll_t c, object_t o);
int collection_remove(coll_t c, object_t o);
int collection_list(coll_t c, list<object_t>& o);
strcpy(this->param, param);
}
-int OBFSStore::init(void)
+int OBFSStore::mount(void)
{
dout(0) << "OBFS init!" << endl;
if ((this->bdev_id = device_open(this->dev, O_RDWR)) < 0) {
return 0;
}
-int OBFSStore::finalize(void)
+int OBFSStore::umount(void)
{
uofs_shutdown();
close(this->bdev_id);
public:
OBFSStore(int whoami, char *param, char *dev);
- int init(void);
- int finalize(void);
+ int mount(void);
+ int umount(void);
int mkfs(void);
bool exists(object_t oid);
{
osd_lock.Lock();
- int r = store->init();
+ int r = store->mount();
monitor->init();
monitor->shutdown();
messenger->shutdown();
- int r = store->finalize();
+ int r = store->umount();
return r;
}
virtual ~ObjectStore() {}
// mgmt
- virtual int init() = 0;
- virtual int finalize() = 0;
-
+ virtual int mount() = 0;
+ virtual int umount() = 0;
virtual int mkfs() = 0; // wipe
// objects
size_t len, off_t offset,
bufferlist& bl,
bool fsync=true) = 0;
+
virtual int write(object_t oid,
size_t len, off_t offset,
bufferlist& bl,
- Context *onsafe) { return -1; }
+ Context *onsafe) = 0;//{ return -1; }
virtual int setattr(object_t oid, const char *name,
void *value, size_t size) {return 0;} //= 0;
// collections
virtual int list_collections(list<coll_t>& ls) {return 0;}//= 0;
- virtual bool collection_exists(coll_t c) {
- struct stat st;
- return collection_stat(c, &st) == 0;
- }
+ virtual int create_collection(coll_t c) {return 0;}//= 0;
+ virtual int destroy_collection(coll_t c) {return 0;}//= 0;
+ virtual bool collection_exists(coll_t c) {return 0;}
virtual int collection_stat(coll_t c, struct stat *st) {return 0;}//= 0;
- virtual int collection_create(coll_t c) {return 0;}//= 0;
- virtual int collection_destroy(coll_t c) {return 0;}//= 0;
virtual int collection_add(coll_t c, object_t o) {return 0;}//= 0;
virtual int collection_remove(coll_t c, object_t o) {return 0;}// = 0;
virtual int collection_list(coll_t c, list<object_t>& o) {return 0;}//= 0;
void store(ObjectStore *store) {
if (!store->collection_exists(pgid))
- store->collection_create(pgid);
+ store->create_collection(pgid);
store->collection_setattr(pgid, "role", &role, sizeof(role));
store->collection_setattr(pgid, "primary_since", &primary_since, sizeof(primary_since));
store->collection_setattr(pgid, "state", &state, sizeof(state));