]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
*** empty log message ***
authorsage <sage@29311d96-e01e-0410-9327-a35deaab8ce9>
Mon, 5 Dec 2005 23:22:31 +0000 (23:22 +0000)
committersage <sage@29311d96-e01e-0410-9327-a35deaab8ce9>
Mon, 5 Dec 2005 23:22:31 +0000 (23:22 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@517 29311d96-e01e-0410-9327-a35deaab8ce9

12 files changed:
ceph/ebofs/Ebofs.cc
ceph/ebofs/Ebofs.h
ceph/ebofs/Onode.h
ceph/ebofs/mkfs.ebofs.cc
ceph/ebofs/types.h
ceph/osd/FakeStore.cc
ceph/osd/FakeStore.h
ceph/osd/OBFSStore.cc
ceph/osd/OBFSStore.h
ceph/osd/OSD.cc
ceph/osd/ObjectStore.h
ceph/osd/PG.h

index 594ff843c669b8a1d78e514fd2ced95a6c33ce07..0e3bcd2600531d87732d34dda0f1b708a586ce52 100644 (file)
@@ -569,6 +569,8 @@ void Ebofs::flush_all()
 }
 
 
+
+
 // ? is this the best way ?
 class C_E_FlushPartial : public Context {
   Ebofs *ebofs;
@@ -671,6 +673,7 @@ void Ebofs::apply_write(Onode *on, size_t len, off_t off, bufferlist& bl)
        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;
@@ -993,6 +996,14 @@ int Ebofs::read(object_t oid,
 }
 
 
+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)
@@ -1004,9 +1015,6 @@ int Ebofs::write(object_t oid,
   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) {
@@ -1026,6 +1034,9 @@ int Ebofs::write(object_t oid,
        }       
   }
   
+  // apply to buffer cache
+  apply_write(on, len, off, bl);
+
 
   
   // attr changes
@@ -1044,6 +1055,106 @@ int Ebofs::write(object_t oid,
 }
 
 
+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;
+}
 
 
 
@@ -1137,3 +1248,62 @@ int Ebofs::collection_list(coll_t cid, list<object_t>& ls)
   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;
+}
+
+
index 81a756cbcba48b906b526cb14ec3744760e81426..39f66652780cb51c1a086ee95a9e9e221e5cf542 100644 (file)
@@ -17,6 +17,7 @@ using namespace __gnu_cxx;
 #include "common/Mutex.h"
 #include "common/Cond.h"
 
+#include "osd/ObjectStore.h"
 
 typedef pair<object_t,coll_t> idpair_t;
 
@@ -25,7 +26,7 @@ inline ostream& operator<<(ostream& out, idpair_t oc) {
 }
 
 
-class Ebofs {
+class Ebofs : public ObjectStore {
  protected:
   Mutex        ebofs_lock;    // a beautiful global lock
 
@@ -127,7 +128,12 @@ class Ebofs {
   
 
   // 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, 
@@ -138,6 +144,7 @@ class Ebofs {
   // 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
@@ -153,6 +160,7 @@ class Ebofs {
   
   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);
   
 };
index b9c9fe4d59d283dbd4edb94187986fc80dc2a73b..92ad38a077208389a86ef9bb73fcac5e4f01315a 100644 (file)
@@ -52,10 +52,12 @@ public:
 
   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() {
@@ -76,6 +78,21 @@ public:
        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) {
index 4bb5a0b39e29acfd7fd84bb5f3732e916ed259c9..0946b97acdba7289cf1d316a1a8daeb4415f7b10 100644 (file)
@@ -26,11 +26,11 @@ int main(int argc, char **argv)
        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
@@ -46,7 +46,7 @@ int main(int argc, char **argv)
          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) {
@@ -90,7 +90,7 @@ int main(int argc, char **argv)
          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);
        }
 
   }
index 10d68cc6efeb760a72e5662465adc456fe7dd35f..aadadc4f38afdb1c5bb3424485c86dd03d8381d7 100644 (file)
@@ -25,6 +25,7 @@ using namespace __gnu_cxx;
   compile now?
 */
 
+/*
 namespace __gnu_cxx {
   template<> struct hash<unsigned long long> {
        size_t operator()(unsigned long long __x) const { 
@@ -42,6 +43,7 @@ namespace __gnu_cxx {
     }
   };
 }
+*/
 
 
 // disk
index 252addf5ae384c66de7db66b42b33e6852ba9f32..3c5f73b9f34607c472324b969abbf977c20ba31b 100644 (file)
@@ -41,7 +41,7 @@ FakeStore::FakeStore(char *base, int whoami)
 }
 
 
-int FakeStore::init() 
+int FakeStore::mount() 
 {
   string mydir;
   get_dir(mydir);
@@ -68,7 +68,7 @@ int FakeStore::init()
   return 0;
 }
 
-int FakeStore::finalize() 
+int FakeStore::umount() 
 {
   dout(5) << "finalize" << endl;
 
@@ -462,15 +462,7 @@ int FakeStore::list_collections(list<coll_t>& ls)
   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);
@@ -478,7 +470,7 @@ int FakeStore::collection_create(coll_t c) {
   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);
@@ -494,6 +486,19 @@ int FakeStore::collection_destroy(coll_t 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();
 
index 384b01abfc264e2f7264b0cc23d007bed38f2127..62678778a6f34797e9d01435c2156919cbbe88b6 100644 (file)
@@ -35,8 +35,8 @@ class FakeStore : public ObjectStore {
  public:
   FakeStore(char *base, int whoami);
 
-  int init();
-  int finalize();
+  int mount();
+  int umount();
   int mkfs();
 
 
@@ -81,9 +81,10 @@ class FakeStore : public ObjectStore {
 
  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);
index d8fe3a5ceb07446aa06492b60480bd3b41728a30..7e6cad2db9658573bdcc5d43e18b071270f629a7 100644 (file)
@@ -36,7 +36,7 @@ OBFSStore::OBFSStore(int whoami, char *param, char *dev)
                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) {
@@ -126,7 +126,7 @@ int OBFSStore::mkfs(void)
        return 0;
 }
 
-int OBFSStore::finalize(void)
+int OBFSStore::umount(void)
 {
        uofs_shutdown();
        close(this->bdev_id);
index 1c57e59f6b06c89ca727f93b94e3e440cc6d0015..4466d4a593d146aa6d0f30780971ae9a8ea455a9 100644 (file)
@@ -14,8 +14,8 @@ class OBFSStore: public ObjectStore {
       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);
index 8cb193b7b08f660f7671f43b3710fc5ed63f8bea..e3c7fa478553a2486d64298bce33a3bba68fb31a 100644 (file)
@@ -130,7 +130,7 @@ int OSD::init()
 {
   osd_lock.Lock();
 
-  int r = store->init();
+  int r = store->mount();
 
   monitor->init();
 
@@ -154,7 +154,7 @@ int OSD::shutdown()
   monitor->shutdown();
   messenger->shutdown();
 
-  int r = store->finalize();
+  int r = store->umount();
   return r;
 }
 
index 39b0af5fa582239add9c15fb840392346d174a7a..51747f80ca6f1b928149e0ceac1dae5a99c82d01 100644 (file)
@@ -19,9 +19,8 @@ class ObjectStore {
   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
@@ -39,10 +38,11 @@ class ObjectStore {
                                        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;
@@ -52,13 +52,10 @@ class ObjectStore {
   
   // 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;
index 88cad5313f9f8c6c88a204df55700a25b575c861..b631f673fcb60247eed624b38d38e6b64ce126c5 100644 (file)
@@ -437,7 +437,7 @@ class PG {
   
   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));