]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
fakestore: various fixes (esp on 32bit)
authorSage Weil <sage@newdream.net>
Thu, 28 Feb 2008 22:45:28 +0000 (14:45 -0800)
committerSage Weil <sage@newdream.net>
Thu, 28 Feb 2008 22:45:58 +0000 (14:45 -0800)
src/config.cc
src/config.h
src/ebofs/Ebofs.cc
src/mon/OSDMonitor.cc
src/osd/FakeStore.cc
src/osd/FakeStore.h
src/osd/FileJournal.cc
src/osd/JournalingObjectStore.cc

index ab52cddd69d806a177eb868bc4a00b6cca75f67e..e8e27a00f4c396f5215eb9c77fdd1c70d648144a 100644 (file)
@@ -161,6 +161,8 @@ md_config_t g_conf = {
   debug_client: 0,
   debug_osd: 0,
   debug_ebofs: 1,
+  debug_fakestore: 1,
+  debug_journal: 1,
   debug_bdev: 1,         // block device
   debug_ns: 0,
   debug_ms: 0,
@@ -337,10 +339,7 @@ md_config_t g_conf = {
 
   
   // --- fakestore ---
-  fakestore_fake_sync: 2,    // seconds
-  fakestore_fsync: false,//true,
-  fakestore_writesync: false,
-  fakestore_syncthreads: 4,
+  fakestore_sync_interval: 2,    // seconds
   fakestore_fake_attrs: false,
   fakestore_fake_collections: false,   
   fakestore_dev: 0,
@@ -357,9 +356,11 @@ md_config_t g_conf = {
   ebofs_max_prefetch: 1000, // 4k blocks
   ebofs_realloc: false,    // hrm, this can cause bad fragmentation, don't use!
   ebofs_verify_csum_on_read: true,
-  ebofs_journal_dio: false,
-  ebofs_journal_max_write_bytes: 0,
-  ebofs_journal_max_write_entries: 10,
+
+  // journal
+  journal_dio: false,
+  journal_max_write_bytes: 0,
+  journal_max_write_entries: 10,
 
   // --- block device ---
   bdev_lock: true,
@@ -640,6 +641,16 @@ void parse_config_options(std::vector<const char*>& args)
         g_conf.debug_ebofs = atoi(args[++i]);
       else 
         g_debug_after_conf.debug_ebofs = atoi(args[++i]);
+    else if (strcmp(args[i], "--debug_fakestore") == 0) 
+      if (!g_conf.debug_after) 
+        g_conf.debug_fakestore = atoi(args[++i]);
+      else 
+        g_debug_after_conf.debug_fakestore = atoi(args[++i]);
+    else if (strcmp(args[i], "--debug_journal") == 0) 
+      if (!g_conf.debug_after) 
+        g_conf.debug_journal = atoi(args[++i]);
+      else 
+        g_debug_after_conf.debug_journal = atoi(args[++i]);
     else if (strcmp(args[i], "--debug_bdev") == 0) 
       if (!g_conf.debug_after) 
         g_conf.debug_bdev = atoi(args[++i]);
@@ -819,22 +830,21 @@ void parse_config_options(std::vector<const char*>& args)
       g_conf.ebofs_max_prefetch = atoi(args[++i]);
     else if (strcmp(args[i], "--ebofs_realloc") == 0)
       g_conf.ebofs_realloc = atoi(args[++i]);
-    else if (strcmp(args[i], "--ebofs_journal_dio") == 0)
-      g_conf.ebofs_journal_dio = atoi(args[++i]);      
-    else if (strcmp(args[i], "--ebofs_journal_max_write_entries") == 0)
-      g_conf.ebofs_journal_max_write_entries = atoi(args[++i]);      
-    else if (strcmp(args[i], "--ebofs_journal_max_write_bytes") == 0)
-      g_conf.ebofs_journal_max_write_bytes = atoi(args[++i]);      
+\
+    else if (strcmp(args[i], "--journal_dio") == 0)
+      g_conf.journal_dio = atoi(args[++i]);      
+    else if (strcmp(args[i], "--journal_max_write_entries") == 0)
+      g_conf.journal_max_write_entries = atoi(args[++i]);      
+    else if (strcmp(args[i], "--journal_max_write_bytes") == 0)
+      g_conf.journal_max_write_bytes = atoi(args[++i]);      
 
     else if (strcmp(args[i], "--fakestore") == 0) {
       g_conf.ebofs = 0;
       //g_conf.osd_pg_bits = 5;
       //g_conf.osd_maxthreads = 1;   // fucking hell
     }
-    else if (strcmp(args[i], "--fakestore_fsync") == 0) 
-      g_conf.fakestore_fsync = atoi(args[++i]);
-    else if (strcmp(args[i], "--fakestore_writesync") == 0) 
-      g_conf.fakestore_writesync = atoi(args[++i]);
+    else if (strcmp(args[i], "--fakestore_sync_interval") == 0)
+      g_conf.fakestore_sync_interval = atoi(args[++i]);
     else if (strcmp(args[i], "--fakestore_dev") == 0) 
       g_conf.fakestore_dev = args[++i];
     else if (strcmp(args[i], "--fakestore_fake_attrs") == 0) 
index bc8fe3de21d81860c87653385484dd3998403480..e928a96a87226187cc434b1c2cffde611d9ac434 100644 (file)
@@ -88,6 +88,8 @@ struct md_config_t {
   int debug_client;
   int debug_osd;
   int debug_ebofs;
+  int debug_fakestore;
+  int debug_journal;
   int debug_bdev;
   int debug_ns;
   int debug_ms;
@@ -269,10 +271,8 @@ struct md_config_t {
 
   bool osd_hack_fast_startup;
 
-  double   fakestore_fake_sync;
-  bool  fakestore_fsync;
-  bool  fakestore_writesync;
-  int   fakestore_syncthreads;   // such crap
+  // fakestore
+  double   fakestore_sync_interval;
   bool  fakestore_fake_attrs;
   bool  fakestore_fake_collections;
   const char  *fakestore_dev;
@@ -289,10 +289,12 @@ struct md_config_t {
   unsigned ebofs_max_prefetch;
   bool  ebofs_realloc;
   bool ebofs_verify_csum_on_read;
-  bool ebofs_journal_dio;
-  bool ebofs_journal_max_write_bytes;
-  bool ebofs_journal_max_write_entries;
   
+  // journal
+  bool journal_dio;
+  bool journal_max_write_bytes;
+  bool journal_max_write_entries;
+
   // block device
   bool  bdev_lock;
   int   bdev_iothreads;
index 89dd8dd86b2700f08ff9ca3376081570fe3f8b45..ef0b8d260617a6b580bb752ed6b6282363cb88ce 100644 (file)
@@ -120,7 +120,7 @@ int Ebofs::mount()
 
   // open journal
   if (journalfn) {
-    journal = new FileJournal(sb->fsid, &finisher, journalfn, g_conf.ebofs_journal_dio);
+    journal = new FileJournal(sb->fsid, &finisher, journalfn, g_conf.journal_dio);
     int err = journal->open(super_epoch);
     if (err < 0) {
       dout(3) << "mount journal " << journalfn << " open failed" << dendl;
@@ -268,13 +268,14 @@ int Ebofs::mkfs()
 
   // create journal?
   if (journalfn) {
-    Journal *journal = new FileJournal(super_fsid, &finisher, journalfn, g_conf.ebofs_journal_dio);
+    Journal *journal = new FileJournal(super_fsid, &finisher, journalfn, g_conf.journal_dio);
     if (journal->create() < 0) {
       dout(3) << "mount journal " << journalfn << " created failed" << dendl;
     } else {
       dout(3) << "mount journal " << journalfn << " created" << dendl;
     }
     delete journal;
+    journal = 0;
   }
 
   dout(2) << "mkfs: " << dev.get_device_name() << " "  << dev.get_num_blocks() << " blocks, " << nice_blocks(dev.get_num_blocks()) << dendl;
index 74aec7f1ad0f7e532f5b2585f9399875393682fd..f1ab36657b89cd88f98e9b6b73ac1bfb5af6f514 100644 (file)
@@ -917,24 +917,3 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
   }
   return false;
 }
-/*
-int OSDMonitor::do_command(vector<string>& cmd, bufferlist& data, 
-                          bufferlist& rdata, string &rs)
-{
-  if (cmd[1] == "getmap") {
-    osdmap.encode(rdata);
-    rs = "ok";
-    return 0;
-  }
-  if (cmd[1] == "getcrushmap") {
-    osdmap.crush._encode(rdata);
-    rs = "ok";
-    return 0;
-  }
-  if (cmd[1] == "setcrushmap") {
-    return -EAGAIN;
-  }
-  rs = "unknown command";
-  return -EINVAL;
-}
-*/
index b91a415fc74b8d9125fa53f89d08da9fa46d3706..49b5000e9f75f43f83ddd238f1b459d6ee509b84 100644 (file)
@@ -17,6 +17,8 @@
 #include "FakeStore.h"
 #include "include/types.h"
 
+#include "FileJournal.h"
+
 #include "common/Timer.h"
 
 #include <unistd.h>
 
 #include "config.h"
 
-#define  dout(l)    if (l<=g_conf.debug) *_dout << dbeginl << g_clock.now() << " fakestore(" << basedir << ") "
-#define  derr(l)    if (l<=g_conf.debug) *_derr << dbeginl << g_clock.now() << " fakestore(" << basedir << ") "
+#define  dout(l)    if (l<=g_conf.debug_fakestore) *_dout << dbeginl << g_clock.now() << " fakestore(" << basedir << ") "
+#define  derr(l)    if (l<=g_conf.debug_fakestore) *_derr << dbeginl << g_clock.now() << " fakestore(" << basedir << ") "
 
 #include "include/buffer.h"
 
 #include <map>
 
-
 int FakeStore::statfs(struct statfs *buf)
 {
   return ::statfs(basedir.c_str(), buf);
@@ -60,20 +61,17 @@ int FakeStore::statfs(struct statfs *buf)
  */ 
 void FakeStore::get_oname(pobject_t oid, char *s) 
 {
-  //static hash<pobject_t> H;
   assert(sizeof(oid) == 24);
 #ifdef __LP64__
-  //sprintf(s, "%s/objects/%02lx/%016lx.%016lx", basedir.c_str(), H(oid) & HASH_MASK, 
   sprintf(s, "%s/objects/%04x.%04x.%016lx.%016lx", basedir.c_str(), 
          oid.volume, oid.rank,
          *((uint64_t*)&oid.oid),
          *(((uint64_t*)&oid.oid) + 1));
 #else
-  //sprintf(s, "%s/objects/%02x/%016llx.%016llx", basedir.c_str(), H(oid) & HASH_MASK, 
   sprintf(s, "%s/objects/%04x.%04x.%016llx.%016llx", basedir.c_str(), 
          oid.volume, oid.rank,
-         *((uint64_t*)&oid),
-         *(((uint64_t*)&oid) + 1));
+         *((uint64_t*)&oid.oid),
+         *(((uint64_t*)&oid.oid) + 1));
 #endif
 }
 
@@ -147,21 +145,28 @@ int FakeStore::mkfs()
   dout(5) << "wipe: " << cmd << dendl;
   system(cmd);
 
-  // hashed bits too
-  /*
-  for (int i=0; i<HASH_DIRS; i++) {
-    char s[4];
-    sprintf(s, "%02x", i);
-    string subdir = basedir + "/objects/" + s;
-
-    dout(15) << " creating " << subdir << dendl;
-    int r = ::mkdir(subdir.c_str(), 0755);
-    if (r != 0) {
-      derr(0) << "couldnt create subdir, r = " << r << dendl;
-      return r;
+  // fsid
+  fsid = rand();
+  char fn[100];
+  sprintf(fn, "%s/fsid", basedir.c_str());
+  int fd = ::open(fn, O_CREAT|O_TRUNC|O_WRONLY);
+  ::write(fd, &fsid, sizeof(fsid));
+  ::fchmod(fd, 666);
+  ::close(fd);
+
+  // journal?
+  struct stat st;
+  sprintf(fn, "%s/journal", basedir.c_str());
+  if (::stat(fn, &st) == 0) {
+    journal = new FileJournal(fsid, &finisher, fn, g_conf.journal_dio);
+    if (journal->create() < 0) {
+      dout(0) << "mkfs error creating journal on " << fn << dendl;
+    } else {
+      dout(0) << "mkfs created journal on " << fn << dendl;
     }
+    delete journal;
+    journal = 0;
   }
-  */
 
   if (g_conf.fakestore_dev) {
     char cmd[100];
@@ -201,12 +206,9 @@ int FakeStore::mount()
 
   // fake attrs? 
   // let's test to see if they work.
-#ifndef __CYGWIN__
   if (g_conf.fakestore_fake_attrs) {
-#endif
     dout(0) << "faking attrs (in memory)" << dendl;
     fake_attrs = true;
-#ifndef __CYGWIN__
   } else {
     char names[1000];
     r = ::listxattr(basedir.c_str(), names, 1000);
@@ -215,23 +217,32 @@ int FakeStore::mount()
       assert(0);
     }
   }
-#endif
 
-  // get epoch
   char fn[100];
+  int fd;
+
+  // get fsid
+  sprintf(fn, "%s/fsid", basedir.c_str());
+  fd = ::open(fn, O_RDONLY);
+  ::read(fd, &fsid, sizeof(fsid));
+  ::close(fd);
+  
+  // get epoch
   sprintf(fn, "%s/commit_epoch", basedir.c_str());
-  int fd = ::open(fn, O_RDONLY);
+  fd = ::open(fn, O_RDONLY);
   ::read(fd, &super_epoch, sizeof(super_epoch));
-  ::fsync(fd);  // this should cause the fs's journal to commit.
   ::close(fd);
   dout(5) << "mount epoch is " << super_epoch << dendl;
-  
+
+  // journal
+  sprintf(fn, "%s/journal", basedir.c_str());
+  if (::stat(fn, &st) == 0)
+    journal = new FileJournal(fsid, &finisher, fn, g_conf.journal_dio);
   r = journal_replay();
   if (r == -EINVAL) {
     dout(0) << "mount got EINVAL on journal open, not mounting" << dendl;
     return r;
   }
-
   journal_start();
   sync_thread.create();
 
@@ -278,18 +289,17 @@ bool FakeStore::exists(pobject_t oid)
 }
 
   
-int FakeStore::stat(pobject_t oid,
-                    struct stat *st)
+int FakeStore::stat(pobject_t oid, struct stat *st)
 {
   dout(20) << "stat " << oid << dendl;
   char fn[200];
   get_oname(oid,fn);
   int r = ::stat(fn, st);
+  dout(20) << "stat " << oid << " at " << fn << " = " << r << dendl;
   return r;
 }
  
  
-
 int FakeStore::remove(pobject_t oid, Context *onsafe) 
 {
   dout(20) << "remove " << oid << dendl;
@@ -411,7 +421,7 @@ void FakeStore::sync_entry()
 {
   lock.Lock();
   utime_t interval;
-  interval.set_from_double(g_conf.fakestore_fake_sync); // rename me
+  interval.set_from_double(g_conf.fakestore_sync_interval);
   while (!stop) {
     dout(10) << "sync_entry waiting for " << interval << dendl;
     sync_cond.WaitInterval(lock, interval);
@@ -424,6 +434,7 @@ void FakeStore::sync_entry()
     sprintf(fn, "%s/commit_epoch", basedir.c_str());
     int fd = ::open(fn, O_CREAT|O_WRONLY);
     ::write(fd, &super_epoch, sizeof(super_epoch));
+    ::fchmod(fd, 0664);
     ::fsync(fd);  // this should cause the fs's journal to commit.
     ::close(fd);
 
index b2297fd3725a4b17cf78cfdcb17e1a76d677ac94..b5747f1a4bad0aac9eba8c7bffafb0b929e31fcd 100644 (file)
@@ -36,7 +36,8 @@ using namespace __gnu_cxx;
 
 class FakeStore : public JournalingObjectStore {
   string basedir;
-
+  __u64 fsid;
+  
   // fake attrs?
   FakeStoreAttrs attrs;
   bool fake_attrs;
index f5062a44acbfb582f3b7858ec60064d94062c9cc..cdc63bc7d5a48c409893702e4ff20e47555e34fb 100644 (file)
@@ -22,8 +22,8 @@
 
 #include "config.h"
 
-#define dout(x) if (x <= g_conf.debug_ebofs) *_dout << dbeginl << g_clock.now() << " ebofs(" << fn << ").journal "
-#define derr(x) if (x <= g_conf.debug_ebofs) *_derr << dbeginl << g_clock.now() << " ebofs(" << fn << ").journal "
+#define dout(x) if (x <= g_conf.debug_journal) *_dout << dbeginl << g_clock.now() << " journal "
+#define derr(x) if (x <= g_conf.debug_journal) *_derr << dbeginl << g_clock.now() << " journal "
 
 
 int FileJournal::_open(bool forwrite)
@@ -293,8 +293,8 @@ void FileJournal::prepare_multi_write(bufferlist& bl)
   // gather queued writes
   off64_t queue_pos = write_pos;
 
-  int eleft = g_conf.ebofs_journal_max_write_entries;
-  int bleft = g_conf.ebofs_journal_max_write_bytes;
+  int eleft = g_conf.journal_max_write_entries;
+  int bleft = g_conf.journal_max_write_bytes;
 
   while (!writeq.empty()) {
     // grab next item
index 1d4499af1781ba52d94a5c43dd9e86e00df5e698..a8e4b00c9f8c2ff802ba489694f13af06cc66fc6 100644 (file)
@@ -8,6 +8,9 @@
 
 int JournalingObjectStore::journal_replay()
 {
+  if (!journal)
+    return 0;
+
   int err = journal->open(super_epoch);
   if (err < 0) {
     dout(3) << "journal_replay open failed with" << err