From 1414e04dad597bbb01bf6609505bb0d66c1b9304 Mon Sep 17 00:00:00 2001 From: sage Date: Tue, 31 Jan 2006 21:14:42 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@582 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/osd/Fake.h | 262 ++++++++++++++++++++++++++++++++++++++++++ ceph/osd/FakeStore.cc | 7 +- ceph/osd/FakeStore.h | 41 +------ ceph/osd/OBFSStore.cc | 133 --------------------- ceph/osd/OBFSStore.h | 64 +---------- 5 files changed, 276 insertions(+), 231 deletions(-) create mode 100644 ceph/osd/Fake.h diff --git a/ceph/osd/Fake.h b/ceph/osd/Fake.h new file mode 100644 index 0000000000000..cd0b9b17b56bf --- /dev/null +++ b/ceph/osd/Fake.h @@ -0,0 +1,262 @@ + + +class FakeStoreCollections { + private: + Mutex lock; + hash_map > fakecollections; + + public: + // faked collections + int list_collections(list& ls) { + lock.Lock(); + int r = 0; + for (hash_map< coll_t, set >::iterator p = fakecollections.begin(); + p != fakecollections.end(); + p++) { + r++; + ls.push_back(p->first); + } + lock.Unlock(); + return r; + } + + int create_collection(coll_t c) { + lock.Lock(); + fakecollections[c].size(); + lock.Unlock(); + return 0; + } + + int destroy_collection(coll_t c) { + int r = 0; + lock.Lock(); + if (fakecollections.count(c)) { + fakecollections.erase(c); + fakecattr.erase(c); + } else + r = -1; + lock.Unlock(); + return r; + } + + int collection_stat(coll_t c, struct stat *st) { + return collection_exists(c) ? 0:-1; + } + + bool collection_exists(coll_t c) { + lock.Lock(); + int r = fakecollections.count(c); + lock.Unlock(); + return r; + } + + int collection_add(coll_t c, object_t o) { + lock.Lock(); + fakecollections[c].insert(o); + lock.Unlock(); + return 0; + } + + int collection_remove(coll_t c, object_t o) { + lock.Lock(); + fakecollections[c].erase(o); + lock.Unlock(); + return 0; + } + + int collection_list(coll_t c, list& o) { + lock.Lock(); + int r = 0; + for (set::iterator p = fakecollections[c].begin(); + p != collectsion[c].end(); + p++) { + o.push_back(*p); + r++; + } + lock.Unlock(); + return r; + } + +}; + +class FakeStoreAttrs { + private: + + class FakeAttrSet { + public: + map attrs; + + int getattr(const char *name, void *value, size_t size) { + if (attrs.count(name)) { + size_t l = attrs[name].length(); + if (l > size) l = size; + bufferlist bl; + bl.append(attrs[name]); + bl.copy(0, l, (char*)value); + return l; + } + return -1; + } + + int setattr(const char *name, void *value, size_t size) { + bufferptr bp(new buffer((char*)value,size)); + attrs[name] = bp; + return 0; + } + + int listattr(char *attrs, size_t size) { + assert(0); + } + + bool empty() { return attrs.empty(); } + }; + + Mutex lock; + hash_map fakeoattrs; + hash_map fakecattrs; + + + public: + // faked attrs + int setattr(object_t oid, const char *name, + void *value, size_t size) { + lock.Lock(); + int r = fakeoattrs[oid].setattr(name, value, size); + lock.Unlock(); + return r; + } + int getattr(object_t oid, const char *name, + void *value, size_t size) { + lock.Lock(); + int r = fakeoattrs[oid].getattr(name, value, size); + lock.Unlock(); + return r; + } + int listattr(object_t oid, char *attrs, size_t size) { + lock.Lock(); + int r = fakeoattrs[oid].listattr(attrs,size); + lock.Unlock(); + return r; + } + + + int collection_setattr(coll_t c, const char *name, + void *value, size_t size) { + lock.Lock(); + int r = fakecattrs[cid].setattr(name, value, size); + lock.Unlock(); + return r; + } + int collection_getattr(coll_t c, const char *name, + void *value, size_t size) { + lock.Lock(); + int r = fakecattrs[cid].getattr(name, value, size); + lock.Unlock(); + return r; + } + int collection_listattr(coll_t c, char *attrs, size_t size) { + lock.Lock(); + int r = fakecattrs[cid].listattr(attrs,size); + lock.Unlock(); + return r; + } + +}; + + + +int OBFSStore::list_collections(list& ls) +{ + lock.Lock(); + int r = 0; + for (hash_map< coll_t, set >::iterator p = fakecollections.begin(); + p != fakecollections.end(); + p++) { + r++; + ls.push_back(p->first); + } + lock.Unlock(); + return r; +} + +int OBFSStore::create_collection(coll_t c) +{ + lock.Lock(); + fakecollections[c].size(); + lock.Unlock(); + return 0; +} + +int OBFSStore::destroy_collection(coll_t c) +{ + +} + +int OBFSStore::collection_stat(coll_t c, struct stat *st) +{ + +} + +bool OBFSStore::collection_exists(coll_t c) +{ + lock.Lock(); + int r = fakecollections.count(c); + lock.Unlock(); + return r; +} + +int OBFSStore::collection_add(coll_t c, object_t o) +{ + lock.Lock(); + fakecollections[c].insert(o); + lock.Unlock(); + return 0; +} + +int OBFSStore::collection_remove(coll_t c, object_t o) +{ + lock.Lock(); + fakecollections[c].erase(o); + lock.Unlock(); + return 0; +} + +int OBFSStore::collection_list(coll_t c, list& o) +{ + lock.Lock(); + int r = 0; + for (set::iterator p = fakecollections[c].begin(); + p != collectsion[c].end(); + p++) { + o.push_back(*p); + r++; + } + lock.Unlock(); + return r; +} + +int OBFSStore::collection_setattr(coll_t c, const char *name, + void *value, size_t size) +{ + lock.Lock(); + int r = fakecattr[c].setattr(name, value, size); + lock.Unlock(); + return r; +} + +int OBFSStore::collection_getattr(coll_t c, const char *name, + void *value, size_t size) +{ + lock.Lock(); + int r = fakecattr[c].getattr(name,value,size); + lock.Unlock(); + return r; +} + +int OBFSStore::collection_listattr(coll_t c, char *attrs, size_t size) +{ + lock.Lock(); + int r = fakecattr[c].listattr(attrs,size); + lock.Unlock(); + return r; +} diff --git a/ceph/osd/FakeStore.cc b/ceph/osd/FakeStore.cc index 3bc3544a4be39..388261d29787e 100644 --- a/ceph/osd/FakeStore.cc +++ b/ceph/osd/FakeStore.cc @@ -368,6 +368,8 @@ int FakeStore::write(object_t oid, // ------------------ // attributes + +/* int FakeStore::setattr(object_t oid, const char *name, void *value, size_t size) { @@ -418,7 +420,7 @@ int FakeStore::listattr(object_t oid, char *attrs, size_t size) return listxattr(fn.c_str(), attrs, size); } } - +*/ @@ -551,6 +553,7 @@ int FakeStore::collection_list(coll_t c, list& o) { return 0; } +/* int FakeStore::collection_setattr(coll_t cid, const char *name, void *value, size_t size) { @@ -603,4 +606,4 @@ int FakeStore::collection_listattr(coll_t cid, char *attrs, size_t size) return r; } - +*/ diff --git a/ceph/osd/FakeStore.h b/ceph/osd/FakeStore.h index 418e40a7b378e..42b27fca7dc6f 100644 --- a/ceph/osd/FakeStore.h +++ b/ceph/osd/FakeStore.h @@ -15,44 +15,11 @@ using namespace __gnu_cxx; // fake attributes in memory, if we need to. -class FakeStore : public ObjectStore { +class FakeStore : public ObjectStore, public FakeAttrs { string basedir; int whoami; - class FakeAttrSet { - public: - map attrs; - - int getattr(const char *name, void *value, size_t size) { - if (attrs.count(name)) { - size_t l = attrs[name].length(); - if (l > size) l = size; - bufferlist bl; - bl.append(attrs[name]); - bl.copy(0, l, (char*)value); - return l; - } - return -1; - } - - int setattr(const char *name, void *value, size_t size) { - bufferptr bp(new buffer((char*)value,size)); - attrs[name] = bp; - return 0; - } - - int listattr(char *attrs, size_t size) { - assert(0); - } - - bool empty() { return attrs.empty(); } - }; - - Mutex lock; - hash_map fakeoattrs; - hash_map fakecattrs; - // fns void get_dir(string& dir); void get_oname(object_t oid, string& fn); @@ -99,12 +66,13 @@ class FakeStore : public ObjectStore { bufferlist& bl, Context *onsafe); + /* 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 listattr(object_t oid, char *attrs, size_t size); - + */ // ------------------- // collections @@ -130,12 +98,13 @@ class FakeStore : public ObjectStore { int collection_remove(coll_t c, object_t o); int collection_list(coll_t c, list& o); + /* int collection_setattr(coll_t c, const char *name, void *value, size_t size); int collection_getattr(coll_t c, const char *name, void *value, size_t size); int collection_listattr(coll_t c, char *attrs, size_t size); - + */ }; diff --git a/ceph/osd/OBFSStore.cc b/ceph/osd/OBFSStore.cc index 3262ad4c99964..dce4f6d9f3a82 100644 --- a/ceph/osd/OBFSStore.cc +++ b/ceph/osd/OBFSStore.cc @@ -183,136 +183,3 @@ int OBFSStore::write(object_t oid, size_t len, -// ------------------ -// attributes - -int OBFSStore::setattr(object_t oid, const char *name, - void *value, size_t size) -{ - lock.Lock(); - int r = fakeoattrs[oid].setattr(name, value, size); - lock.Unlock(); - return r; -} - - -int OBFSStore::getattr(object_t oid, const char *name, - void *value, size_t size) -{ - lock.Lock(); - int r = fakeoattrs[oid].getattr(name, value, size); - lock.Unlock(); - return r; -} - -int OBFSStore::listattr(object_t oid, char *attrs, size_t size) -{ - lock.Lock(); - int r = fakeoattrs[oid].listattr(attrs,size); - lock.Unlock(); - return r; -} - -int OBFSStore::list_collections(list& ls) -{ - lock.Lock(); - int r = 0; - for (hash_map< coll_t, set >::iterator p = fakecollections.begin(); - p != fakecollections.end(); - p++) { - r++; - ls.push_back(p->first); - } - lock.Unlock(); - return r; -} - -int OBFSStore::create_collection(coll_t c) -{ - lock.Lock(); - fakecollections[c].size(); - lock.Unlock(); - return 0; -} - -int OBFSStore::destroy_collection(coll_t c) -{ - int r = 0; - lock.Lock(); - if (fakecollections.count(c)) { - fakecollections.erase(c); - fakecattr.erase(c); - } else - r = -1; - lock.Unlock(); - return r; -} - -int OBFSStore::collection_stat(coll_t c, struct stat *st) -{ - -} - -bool OBFSStore::collection_exists(coll_t c) -{ - lock.Lock(); - int r = fakecollections.count(c); - lock.Unlock(); - return r; -} - -int OBFSStore::collection_add(coll_t c, object_t o) -{ - lock.Lock(); - fakecollections[c].insert(o); - lock.Unlock(); - return 0; -} - -int OBFSStore::collection_remove(coll_t c, object_t o) -{ - lock.Lock(); - fakecollections[c].erase(o); - lock.Unlock(); - return 0; -} - -int OBFSStore::collection_list(coll_t c, list& o) -{ - lock.Lock(); - int r = 0; - for (set::iterator p = fakecollections[c].begin(); - p != collectsion[c].end(); - p++) { - o.push_back(*p); - r++; - } - lock.Unlock(); - return r; -} - -int OBFSStore::collection_setattr(coll_t c, const char *name, - void *value, size_t size) -{ - lock.Lock(); - int r = fakecattr[c].setattr(name, value, size); - lock.Unlock(); - return r; -} - -int OBFSStore::collection_getattr(coll_t c, const char *name, - void *value, size_t size) -{ - lock.Lock(); - int r = fakecattr[c].getattr(name,value,size); - lock.Unlock(); - return r; -} - -int OBFSStore::collection_listattr(coll_t c, char *attrs, size_t size) -{ - lock.Lock(); - int r = fakecattr[c].listattr(attrs,size); - lock.Unlock(); - return r; -} diff --git a/ceph/osd/OBFSStore.h b/ceph/osd/OBFSStore.h index f588c807039c9..786e5dadbfdea 100644 --- a/ceph/osd/OBFSStore.h +++ b/ceph/osd/OBFSStore.h @@ -3,42 +3,11 @@ #define _OBFSSTORE_H_ #include "ObjectStore.h" +#include "Fake.h" -class OBFSStore : public ObjectStore { - - class FakeAttrSet { - public: - map attrs; - - int getattr(const char *name, void *value, size_t size) { - if (attrs.count(name)) { - size_t l = attrs[name].length(); - if (l > size) l = size; - bufferlist bl; - bl.append(attrs[name]); - bl.copy(0, l, (char*)value); - return l; - } - return -1; - } - - int setattr(const char *name, void *value, size_t size) { - bufferptr bp(new buffer((char*)value,size)); - attrs[name] = bp; - return 0; - } - - int listattr(char *attrs, size_t size) { - assert(0); - } - - bool empty() { return attrs.empty(); } - }; - - Mutex lock; - hash_map fakeoattrs; - hash_map fakecattrs; - hash_map > fakecollections; +class OBFSStore : public ObjectStore, + public FakeAttrs, + public FakeCollections { int whoami; int bdev_id; @@ -65,31 +34,6 @@ class OBFSStore : public ObjectStore { off_t offset,char *buffer, bool fsync); - // faked attrs - 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 listattr(object_t oid, char *attrs, size_t size); - - - // faked collections - int list_collections(list& ls); - int create_collection(coll_t c); - int destroy_collection(coll_t c); - int collection_stat(coll_t c, struct stat *st); - 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& o); - - int collection_setattr(coll_t c, const char *name, - void *value, size_t size); - int collection_getattr(coll_t c, const char *name, - void *value, size_t size); - int collection_listattr(coll_t c, char *attrs, size_t size); - - }; #endif -- 2.39.5