]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
merged trunk changes 1256:1338 into branches/sage/cephmds2
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Wed, 4 Apr 2007 21:37:19 +0000 (21:37 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Wed, 4 Apr 2007 21:37:19 +0000 (21:37 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1339 29311d96-e01e-0410-9327-a35deaab8ce9

40 files changed:
branches/sage/cephmds2/Makefile
branches/sage/cephmds2/cfuse.cc
branches/sage/cephmds2/client/Client.cc
branches/sage/cephmds2/client/Client.h
branches/sage/cephmds2/client/FileCache.cc
branches/sage/cephmds2/client/FileCache.h
branches/sage/cephmds2/client/SyntheticClient.cc
branches/sage/cephmds2/client/SyntheticClient.h
branches/sage/cephmds2/client/hadoop/CephClientInterface.cc [deleted file]
branches/sage/cephmds2/client/hadoop/CephClientInterface.h [deleted file]
branches/sage/cephmds2/client/hadoop/CephFSInterface.cc [new file with mode: 0644]
branches/sage/cephmds2/client/hadoop/CephFSInterface.h [new file with mode: 0644]
branches/sage/cephmds2/cmds.cc
branches/sage/cephmds2/cmon.cc
branches/sage/cephmds2/common/Clock.h
branches/sage/cephmds2/common/Logger.cc
branches/sage/cephmds2/config.cc
branches/sage/cephmds2/config.h
branches/sage/cephmds2/cosd.cc
branches/sage/cephmds2/csyn.cc
branches/sage/cephmds2/fakefuse.cc
branches/sage/cephmds2/fakemon.cc [deleted file]
branches/sage/cephmds2/fakesyn.cc
branches/sage/cephmds2/mds/FileLock.h
branches/sage/cephmds2/mds/Locker.cc
branches/sage/cephmds2/mds/MDLog.cc
branches/sage/cephmds2/mds/MDLog.h
branches/sage/cephmds2/mds/MDS.cc
branches/sage/cephmds2/mon/OSDMonitor.cc
branches/sage/cephmds2/msg/SimpleMessenger.cc
branches/sage/cephmds2/msg/SimpleMessenger.h
branches/sage/cephmds2/newsyn.cc
branches/sage/cephmds2/osbdb/OSBDB.cc
branches/sage/cephmds2/osbdb/OSBDB.h
branches/sage/cephmds2/osd/OSD.cc
branches/sage/cephmds2/osd/PG.cc
branches/sage/cephmds2/osdc/ObjectCacher.cc
branches/sage/cephmds2/osdc/ObjectCacher.h
branches/sage/cephmds2/tcpfuse.cc [deleted file]
branches/sage/cephmds2/tcpsyn.cc [deleted file]

index 05233ad9310962d42a5abf046b793875dfd8ae64..eb433cc8a8e815aca84cc3185d48c147e4810ea8 100644 (file)
@@ -95,13 +95,13 @@ COMMON_OBJS= \
        common/Timer.o\
        config.o
 
-
 CLIENT_OBJS= \
        client/FileCache.o\
        client/Client.o\
        client/SyntheticClient.o\
        client/Trace.o
 
+
 ifeq ($(want_bdb),yes)
 OSBDB_OBJS = \
        osbdb/OSBDB.o
@@ -110,11 +110,15 @@ OSBDB_OBJ = osbdb.o
 endif
 
 TARGETS = cmon cosd cmds csyn newsyn fakesyn mkmonmap cmonctl cfuse fakefuse
+NO_FUSE = cmon cosd cmds csyn newsyn fakesyn mkmonmap
+
 
 SRCS=*.cc */*.cc *.h */*.h */*/*.h
 
 all: depend ${TARGETS}
 
+nofuse: depend ${NO_FUSE}
+
 test: depend ${TEST_TARGETS}
 
 obfs: depend obfstest
@@ -183,6 +187,9 @@ osd_obfs.o: osd/OBFSStore.o osd/OSD.cc osd/PG.o osd/ObjectStore.o osd/FakeStore.
        ${MPICC} -DUSE_OBFS ${MPICFLAGS} ${MPILIBS} $^ -o $@ ../uofs/uofs.a
 
 
+# hadoop
+libhadoopcephfs.so: client/hadoop/CephFSInterface.o client.o osdc.o msg/SimpleMessenger.o common.o
+       ${CC} -shared -Wl,-soname,$@.1 ${CFLAGS} -I/cse/grads/eestolan/java_local/jdk1.6.0/include  ${LIBS} $^ -o $@
 
 # libceph
 libceph.o: client/ldceph.o client/Client.o msg/SimpleMessenger.o ${COMMON_OBJS} ${SYN_OBJS} ${OSDC_OBJS}
index 4b7e490c26b76d80a3057daf6123f51e553648f5..a9b47f1270afbdb4553d6a7812ade33d6cc988e5 100644 (file)
@@ -46,6 +46,8 @@ int main(int argc, char **argv, char *envp[]) {
   // FUSE will chdir("/"); be ready.
   g_conf.use_abspaths = true;
 
+  if (g_conf.clock_tare) g_clock.tare();
+
   // load monmap
   MonMap monmap;
   int r = monmap.read(".ceph_monmap");
index 9be84a296b82822e1c621ca0b8ac20c3f3c4b90e..9871ade2455c7cabb58f80f947d3b45cd60bad94 100644 (file)
@@ -978,14 +978,16 @@ void Client::handle_file_caps(MClientFileCaps *m)
           << " was " << cap_string(old_caps) << endl;
   
   // did file size decrease?
-  if ((old_caps & new_caps & CAP_FILE_RDCACHE) &&
+  if ((old_caps & (CAP_FILE_RD|CAP_FILE_WR)) == 0 &&
+      (new_caps & (CAP_FILE_RD|CAP_FILE_WR)) != 0 &&
       in->inode.size > m->get_inode().size) {
-    dout(10) << "**** file size decreased from " << in->inode.size << " to " << m->get_inode().size << " FIXME" << endl;
-    // must have been a truncate() by someone.
-    // trim the buffer cache
-    // ***** fixme write me ****
+    dout(10) << "*** file size decreased from " << in->inode.size << " to " << m->get_inode().size << endl;
+    
+    // trim filecache?
+    if (g_conf.client_oc)
+      in->fc.truncate(in->inode.size, m->get_inode().size);
 
-    in->file_wr_size = m->get_inode().size; //??
+    in->inode.size = in->file_wr_size = m->get_inode().size; 
   }
 
   // update inode
@@ -2397,8 +2399,11 @@ int Client::read(fh_t fh, char *buf, off_t size, off_t offset)
   Fh *f = fh_map[fh];
   Inode *in = f->inode;
 
-  if (offset < 0) 
+  bool movepos = false;
+  if (offset < 0) {
     offset = f->pos;
+    movepos = true;
+  }
 
   bool lazy = f->mode == FILE_MODE_LAZY;
   
@@ -2464,9 +2469,11 @@ int Client::read(fh_t fh, char *buf, off_t size, off_t offset)
     while (!done)
       cond.Wait(client_lock);
   }
-
-  // adjust fd pos
-  f->pos = offset+blist.length();
+  
+  if (movepos) {
+    // adjust fd pos
+    f->pos = offset+blist.length();
+  }
 
   // copy data into caller's char* buf
   blist.copy(0, blist.length(), buf);
@@ -2522,8 +2529,11 @@ int Client::write(fh_t fh, const char *buf, off_t size, off_t offset)
   Fh *f = fh_map[fh];
   Inode *in = f->inode;
 
-  if (offset < 0) 
+  if (offset < 0) {
     offset = f->pos;
+    // adjust fd pos
+    f->pos = offset+size;
+  }
 
   bool lazy = f->mode == FILE_MODE_LAZY;
 
@@ -2543,9 +2553,6 @@ int Client::write(fh_t fh, const char *buf, off_t size, off_t offset)
     // write (this may block!)
     in->fc.write(offset, size, blist, client_lock);
     
-    // adjust fd pos
-    f->pos = offset+size;
-
   } else {
     // legacy, inconsistent synchronous write.
     dout(7) << "synchronous write" << endl;
@@ -2579,9 +2586,6 @@ int Client::write(fh_t fh, const char *buf, off_t size, off_t offset)
                 //, 1+((int)g_clock.now()) / 10 //f->pos // hack hack test osd revision snapshots
                 ); 
     
-    // adjust fd pos
-    f->pos = offset+size;
-
     while (!done) {
       cond.Wait(client_lock);
       dout(20) << " sync write bump " << onfinish << endl;
index 1bcfbee9134d4ff30f113128b6db805abdddb141..ed4b7771103e7f0cffa27b2e65c4cf86846f4019 100644 (file)
@@ -199,6 +199,8 @@ class Inode {
     if (num_open_rd) w |= CAP_FILE_RD|CAP_FILE_RDCACHE;
     if (num_open_wr) w |= CAP_FILE_WR|CAP_FILE_WRBUFFER;
     if (num_open_lazy) w |= CAP_FILE_LAZYIO;
+    if (fc.is_dirty()) w |= CAP_FILE_WRBUFFER;
+    if (fc.is_cached()) w |= CAP_FILE_RDCACHE;
     return w;
   }
 
@@ -552,6 +554,7 @@ protected:
 
   // crap
   int chdir(const char *s);
+  const string getcwd() { return cwd; }
 
   // namespace ops
   int getdir(const char *path, list<string>& contents);
index 5cc6d9ff7962b31a2784efba4285473ef9c88662..6645bef09b6df842742bf230efadf6faa9f79ba7 100644 (file)
@@ -71,6 +71,18 @@ void FileCache::tear_down()
   }
 }
 
+// truncate
+
+void FileCache::truncate(off_t olds, off_t news)
+{
+  dout(5) << "truncate " << olds << " -> " << news << endl;
+
+  // map range to objects
+  list<ObjectExtent> ls;
+  oc->filer.file_to_extents(inode, news, olds-news, ls);
+  oc->truncate_set(inode.ino, ls);
+}
+
 // caps
 
 class C_FC_CheckCaps : public Context {
@@ -107,16 +119,21 @@ void FileCache::set_caps(int caps, Context *onimplement)
   
 }
 
-
-void FileCache::check_caps()
+int FileCache::get_used_caps()
 {
-  // calc used
   int used = 0;
   if (num_reading) used |= CAP_FILE_RD;
   if (oc->set_is_cached(inode.ino)) used |= CAP_FILE_RDCACHE;
   if (num_writing) used |= CAP_FILE_WR;
   if (oc->set_is_dirty_or_committing(inode.ino)) used |= CAP_FILE_WRBUFFER;
-  dout(10) << "check_caps used " << cap_string(used) << endl;
+  return used;
+}
+
+void FileCache::check_caps()
+{
+  // calc used
+  int used = get_used_caps();
+  dout(10) << "check_caps used was " << cap_string(used) << endl;
 
   // try to implement caps?
   // BUG? latest_caps, not least caps i've seen?
@@ -127,6 +144,9 @@ void FileCache::check_caps()
       (used & CAP_FILE_WRBUFFER))
     flush_dirty(new C_FC_CheckCaps(this));
   
+  used = get_used_caps();
+  dout(10) << "check_caps used now " << cap_string(used) << endl;
+
   // check callbacks
   map<int, list<Context*> >::iterator p = caps_callbacks.begin();
   while (p != caps_callbacks.end()) {
index d710d38c0731a186471555c6a5edda6b343d01f6..9ba82f92eb1ab94775845153fb871fd4f7b88775 100644 (file)
@@ -57,6 +57,8 @@ class FileCache {
   bool all_safe();// { return num_unsafe == 0; }
 
   void add_safe_waiter(Context *c);
+  
+  void truncate(off_t olds, off_t news);
 
   // ...
   void flush_dirty(Context *onflush=0);
@@ -69,6 +71,7 @@ class FileCache {
   void tear_down();
 
   int get_caps() { return latest_caps; }
+  int get_used_caps();
   void set_caps(int caps, Context *onimplement=0);
   void check_caps();
   
index 9821b63ff9f6466c483a7671c8cec366535d4820..bb7d6540f7998a8609fb96fd023f841a2c7d7475 100644 (file)
@@ -154,6 +154,11 @@ void parse_syn_options(vector<char*>& args)
       } else if (strcmp(args[i],"optest") == 0) {
        syn_modes.push_back( SYNCLIENT_MODE_OPTEST );
         syn_iargs.push_back( atoi(args[++i]) );
+
+      } else if (strcmp(args[i],"truncate") == 0) { 
+        syn_modes.push_back( SYNCLIENT_MODE_TRUNCATE );
+       syn_sargs.push_back(args[++i]);
+        syn_iargs.push_back(atoi(args[++i]));
       } else {
         cerr << "unknown syn arg " << args[i] << endl;
         assert(0);
@@ -531,6 +536,16 @@ int SyntheticClient::run()
         }
       }
       break;
+
+    case SYNCLIENT_MODE_TRUNCATE:
+      {
+        string file = get_sarg(0);
+        sargs.push_front(file);
+        int iarg1 = iargs.front();  iargs.pop_front();
+       if (run_me()) 
+         client->truncate(file.c_str(), iarg1);
+      }
+      break;
       
     default:
       assert(0);
@@ -797,6 +812,27 @@ int SyntheticClient::full_walk(string& basedir)
        continue;
       }
       
+      // print
+      char *tm = ctime(&st.st_mtime);
+      tm[strlen(tm)-1] = 0;
+      printf("%c%c%c%c%c%c%c%c%c%c %2d %5d %5d %8d %12s %s\n",
+            S_ISDIR(st.st_mode) ? 'd':'-',
+            (st.st_mode & 0400) ? 'r':'-',
+            (st.st_mode & 0200) ? 'w':'-',
+            (st.st_mode & 0100) ? 'x':'-',
+            (st.st_mode & 040) ? 'r':'-',
+            (st.st_mode & 020) ? 'w':'-',
+            (st.st_mode & 010) ? 'x':'-',
+            (st.st_mode & 04) ? 'r':'-',
+            (st.st_mode & 02) ? 'w':'-',
+            (st.st_mode & 01) ? 'x':'-',
+            (int)st.st_nlink,
+            st.st_uid, st.st_gid,
+            (int)st.st_size,
+            tm,
+            file.c_str());
+
+      
       if ((st.st_mode & INODE_TYPE_MASK) == INODE_MODE_DIR) {
        dirq.push_back(file);
       }
index 8b7e0ed34be484a82e0f0429d5902b9930bf46ab..59300ee893dc16d750fbb456fe36ab49f517c568 100644 (file)
 #define SYNCLIENT_MODE_RANDOMSLEEP  61
 #define SYNCLIENT_MODE_SLEEP        62
 
+#define SYNCLIENT_MODE_TRUNCATE     200
 
 #define SYNCLIENT_MODE_FOO        100
 #define SYNCLIENT_MODE_THRASHLINKS  101
 
 
+
 void parse_syn_options(vector<char*>& args);
 
 class SyntheticClient {
@@ -197,7 +199,6 @@ class SyntheticClient {
   int play_trace(Trace& t, string& prefix);
 
   void make_dir_mess(const char *basedir, int n);
-
   void foo();
 
   int thrash_links(const char *basedir, int dirs, int files, int depth, int n);
diff --git a/branches/sage/cephmds2/client/hadoop/CephClientInterface.cc b/branches/sage/cephmds2/client/hadoop/CephClientInterface.cc
deleted file mode 100644 (file)
index 6466dd6..0000000
+++ /dev/null
@@ -1,217 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
- * Foundation.  See file COPYING.
- * 
- */
-
-
-//#include <fuse.h>
-
-
-using namespace std;
-
-// globals
-//Client *client;     // the ceph client
-//this has to go - the real client will have to hold the pointer.
-//Every function will need to take a Client pointer.
-
-// ------
-// fuse hooks
-
-static int ceph_getattr(Client* client, const char *path, struct stat *stbuf)
-{
-  return client->lstat(path, stbuf);
-}
-
-static int ceph_readlink(Client* client, const char *path, char *buf, size_t size)
-{
-  int res;
-
-  res = client->readlink(path, buf, size - 1);
-  if (res < 0) return res;
-  
-  buf[res] = '\0';
-  return 0;
-}
-
-// get rid of the callback thing, perhaps? and return the answer some other way?
-/*
-static int ceph_getdir(Client* client, const char *path, fuse_dirh_t h, fuse_dirfil_t filler)
-{
-  map<string, inode_t> contents;
-
-  int res = client->getdir(path, contents);
-  if (res < 0) return res;
-
-  // return contents to fuse via callback
-  for (map<string, inode_t>::iterator it = contents.begin();
-       it != contents.end();
-       it++) {
-    // (immutable) inode contents too.
-    res = filler(h,                                    // fuse's handle
-                 it->first.c_str(),                    // dentry as char*
-                 it->second.mode & INODE_TYPE_MASK,   // mask type bits from mode
-                 it->second.ino);                     // ino.. 64->32 bit issue here? FIXME
-    if (res != 0) break;   // fuse has had enough
-  }
-  return res;
-}
-*/
-
-static int ceph_mknod(Client* client, const char *path, mode_t mode, dev_t rdev) 
-{
-  return client->mknod(path, mode);
-}
-
-static int ceph_mkdir(Client* client, const char *path, mode_t mode)
-{
-  return client->mkdir(path, mode);
-}
-
-static int ceph_unlink(Client* client, const char *path)
-{
-  return client->unlink(path);
-}
-
-static int ceph_rmdir(Client* client, const char *path)
-{
-  return client->rmdir(path);
-}
-
-static int ceph_symlink(Client* client, const char *from, const char *to)
-{
-  return client->symlink(from, to);
-}
-
-
-static int ceph_rename(Client* client, const char *from, const char *to)
-{
-  return client->rename(from, to);
-}
-
-static int ceph_link(Client* client, const char *from, const char *to)
-{
-  return client->link(from, to);
-}
-
-static int ceph_chmod(Client* client, const char *path, mode_t mode)
-{
-  return client->chmod(path, mode);
-}
-
-static int ceph_chown(Client* client, const char *path, uid_t uid, gid_t gid)
-{
-  return client->chown(path, uid, gid);
-}
-
-static int ceph_truncate(Client* client, const char *path, off_t size)
-{
-  return client->truncate(path, size);      
-}
-
-static int ceph_utime(Client* client, const char *path, struct utimbuf *buf)
-{
-  return client->utime(path, buf);
-}
-
-
-static int ceph_open(Client* client, const char *path, struct fuse_file_info *fi)
-{
-  int res;
-  
-  res = client->open(path, fi->flags);
-  if (res < 0) return res;
-  fi->fh = res;
-  return 0;  // fuse wants 0 onsucess
-}
-
-static int ceph_read(Client* client, const char *path, char *buf, size_t size, off_t offset,
-                     struct fuse_file_info *fi)
-{
-  fh_t fh = fi->fh;
-  return client->read(fh, buf, size, offset);
-}
-
-static int ceph_write(Client* client, const char *path, const char *buf, size_t size,
-                     off_t offset, struct fuse_file_info *fi)
-{
-  fh_t fh = fi->fh;
-  return client->write(fh, buf, size, offset);
-}
-
-/*
-static int ceph_flush(const char *path, struct fuse_file_info *fi)
-{
-  fh_t fh = fi->fh;
-  return client->flush(fh);
-}
-*/
-
-
-#ifdef DARWIN
-static int ceph_statfs(Client* client, const char *path, struct statvfs *stbuf)
-{
-  return client->statfs(path, stbuf);
-}
-#else
-static int ceph_statfs(Client* client, const char *path, struct statfs *stbuf)
-{
-  return client->statfs(path, stbuf);
-}
-#endif
-
-
-/* remove fuse stuff from these two
-static int ceph_release(Client* client, const char *path, struct fuse_file_info *fi)
-{
-  fh_t fh = fi->fh;
-  int r = client->close(fh);  // close the file
-  return r;
-}
-
-static int ceph_fsync(Client* client, const char *path, int isdatasync,
-                     struct fuse_file_info *fi)
-{
-  fh_t fh = fi->fh;
-  return client->fsync(fh, isdatasync ? true:false);
-}
-*/
-
-/*
-static struct fuse_operations ceph_oper = {
-  getattr: ceph_getattr,
-  readlink: ceph_readlink,
-  getdir: ceph_getdir,
-  mknod: ceph_mknod,
-  mkdir: ceph_mkdir,
-  unlink: ceph_unlink,
-  rmdir: ceph_rmdir,
-  symlink: ceph_symlink,
-  rename: ceph_rename,
-  link: ceph_link,
-  chmod: ceph_chmod,
-  chown: ceph_chown,
-  truncate: ceph_truncate,
-  utime: ceph_utime,
-  open: ceph_open,
-  read: ceph_read,
-  write: ceph_write,
-  statfs: ceph_statfs,
-  flush: 0, //ceph_flush,   
-  release: ceph_release,
-  fsync: ceph_fsync
-};
-
-*/
-
-
-// Does this do anything we need? No. All it does is assemble a bunch of
-// arguments and call fuse_main.
-
diff --git a/branches/sage/cephmds2/client/hadoop/CephClientInterface.h b/branches/sage/cephmds2/client/hadoop/CephClientInterface.h
deleted file mode 100644 (file)
index e0b37c3..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
- * Foundation.  See file COPYING.
- * 
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <errno.h>
-#ifdef DARWIN
-#include <sys/statvfs.h>
-#else
-#include <sys/statfs.h>
-#endif // DARWIN
-
-// ceph stuff
-#include "include/types.h"
-
-#include "Client.h"
-
-#include "config.h"
-
-// stl
-#include <map>
-
-
-
-
-
-
-// stbuf holds the attributes
-static int ceph_getattr(Client* client, const char *path, struct stat *stbuf);
-
-// reads a symlink
-static int ceph_readlink(Client* client, const char *path, char *buf, size_t size);
-
-// to do: remove fuse stuff from this one
-//static int ceph_getdir(Client* client, const char *path, fuse_dirh_t h, fuse_dirfil_t filler);
-
-// looks irrelevant - it's for special device files
-static int ceph_mknod(Client* client, const char *path, mode_t mode, dev_t rdev);
-
-// mode is the file permission bits
-static int ceph_mkdir(Client* client, const char *path, mode_t mode);
-
-// delete!
-static int ceph_unlink(Client* client, const char *path);
-
-// delete! if it's an empty directory
-static int ceph_rmdir(Client* client, const char *path);
-
-// make a symlink
-static int ceph_symlink(Client* client, const char *from, const char *to);
-
-// self-explanatory
-static int ceph_rename(Client* client, const char *from, const char *to);
-
-static int ceph_link(Client* client, const char *from, const char *to); //hard link
-
-static int ceph_chmod(Client* client, const char *path, mode_t mode); //just chmod
-
-static int ceph_chown(Client* client, const char *path, uid_t uid, gid_t gid); //duh
-
-static int ceph_truncate(Client* client, const char *path, off_t size); //chop or zero-pad to size
-
-// set file access/modification times
-static int ceph_utime(Client* client, const char *path, struct utimbuf *buf);
-
-// ok, gotta figure out what's in fuse_file_info and how to use it. Presumably it includes
-// a file descriptor and the open flags?
-static int ceph_open(Client* client, const char *path, struct fuse_file_info *fi);
-
-// read!
-static int ceph_read(Client* client, const char *path, char *buf, size_t size, off_t offset,
-                     struct fuse_file_info *fi);
-
-// write!
-static int ceph_write(Client* client, const char *path, const char *buf, size_t size,
-                     off_t offset, struct fuse_file_info *fi);
-
-/* was already commented out
-static int ceph_flush(const char *path, struct fuse_file_info *fi);
-*/
-
-
-// is this statvfs perhaps? we probably don't need it
-#ifdef DARWIN
-static int ceph_statfs(Client* client, const char *path, struct statvfs *stbuf);
-#else
-static int ceph_statfs(Client* client, const char *path, struct statfs *stbuf);
-#endif
-
-// Remove fuse stuff from these two
-//static int ceph_release(Client* client, const char *path, struct fuse_file_info *fi);
-
-//static int ceph_fsync(Client* client, const char *path, int isdatasync,      struct fuse_file_info *fi); //kinda like flush?
-
-/* ceph_fuse_main
- * - start up fuse glue, attached to Client* cl.
- * - argc, argv should include a mount point, and 
- *   any weird fuse options you want.  by default,
- *   we will put fuse in the foreground so that it
- *   won't fork and we can see stdout.
- */
-// int ceph_fuse_main(Client *cl, int argc, char *argv[]);
diff --git a/branches/sage/cephmds2/client/hadoop/CephFSInterface.cc b/branches/sage/cephmds2/client/hadoop/CephFSInterface.cc
new file mode 100644 (file)
index 0000000..3202c66
--- /dev/null
@@ -0,0 +1,799 @@
+#include "CephFSInterface.h"
+
+using namespace std;
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_initializeClient
+ * Signature: ()J
+ * Initializes a ceph client.
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1initializeClient
+  (JNIEnv *, jobject)
+{
+
+  cout << "Initializing Ceph client:" << endl;
+
+  // parse args from CEPH_ARGS 
+  vector<char*> args; 
+  env_to_vec(args);
+  parse_config_options(args);
+
+  if (g_conf.clock_tare) g_clock.tare();
+
+  // be safe
+  g_conf.use_abspaths = true;
+
+  // load monmap
+  MonMap monmap;
+  int r = monmap.read(".ceph_monmap");
+  if (r < 0) {
+    cout << "could not find .ceph_monmap" << endl; 
+    return 0;
+  }
+  assert(r >= 0);
+
+  // start up network
+  rank.start_rank();
+
+  // start client
+  Client *client;
+  client = new Client(rank.register_entity(MSG_ADDR_CLIENT_NEW), &monmap);
+  client->init();
+    
+  // mount
+  client->mount();
+   
+  jlong clientp = *(jlong*)&client;
+  return clientp;
+}
+
+/* on shutdown,
+
+client->unmount();
+client->shutdown();
+delete client;
+  
+// wait for messenger to finish
+rank.wait();
+
+*/
+
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_copyFromLocalFile
+ * Signature: (JLjava/lang/String;Ljava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1copyFromLocalFile
+(JNIEnv * env, jobject obj, jlong clientp, jstring j_local_path, jstring j_ceph_path) {
+
+  cout << "In copyFromLocalFile" << endl;
+  cout.flush();
+  Client* client;
+  //client = (Client*) clientp;
+   client = *(Client**)&clientp;
+
+  const char* c_local_path = env->GetStringUTFChars(j_local_path, 0);
+  const char* c_ceph_path = env->GetStringUTFChars(j_ceph_path, 0);
+
+  cout << "Local source file is "<< c_local_path << " and Ceph destination file is " << c_ceph_path << endl;
+  struct stat st;
+  int r = ::stat(c_local_path, &st);
+  assert (r == 0);
+
+  // open the files
+  int fh_local = ::open(c_local_path, O_RDONLY);
+  int fh_ceph = client->open(c_ceph_path, O_WRONLY|O_CREAT|O_TRUNC);  
+  assert (fh_local > -1);
+  assert (fh_ceph > -1);
+  cout << "local fd is " << fh_local << " and Ceph fd is " << fh_ceph << endl;
+
+  // get the source file size
+  off_t remaining = st.st_size;
+   
+  // copy the file a MB at a time
+  const int chunk = 1048576;
+  bufferptr bp(chunk);
+
+  while (remaining > 0) {
+    off_t got = ::read(fh_local, bp.c_str(), MIN(remaining,chunk));
+    assert(got > 0);
+    remaining -= got;
+    off_t wrote = client->write(fh_ceph, bp.c_str(), got, -1);
+    assert (got == wrote);
+  }
+  client->close(fh_ceph);
+  ::close(fh_local);
+
+  env->ReleaseStringUTFChars(j_local_path, c_local_path);
+  env->ReleaseStringUTFChars(j_ceph_path, c_ceph_path);
+  
+  return JNI_TRUE;
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_copyToLocalFile
+ * Signature: (JLjava/lang/String;Ljava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1copyToLocalFile
+(JNIEnv *env, jobject obj, jlong clientp, jstring j_ceph_path, jstring j_local_path) 
+{
+
+
+  Client* client;
+  client = *(Client**)&clientp;
+  const char* c_ceph_path = env->GetStringUTFChars(j_ceph_path, 0);
+  const char* c_local_path = env->GetStringUTFChars(j_local_path, 0);
+
+  cout << "In copyToLocalFile, copying from Ceph file " << c_ceph_path << 
+    " to local file " << c_local_path << endl;
+  cout.flush();
+
+
+  // get source file size
+  struct stat st;
+  cout << "Attempting lstat with file " << c_ceph_path << ":" << endl;
+  int r = client->lstat(c_ceph_path, &st);
+  assert (r == 0);
+
+  cout << "Opening Ceph source file for read: " << endl;
+  cout.flush();
+  int fh_ceph = client->open(c_ceph_path, O_RDONLY);  
+  assert (fh_ceph > -1);
+
+  cout << " Opened Ceph file! Opening local destination file: " << endl;
+  cout.flush();
+  int fh_local = ::open(c_local_path, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+  assert (fh_local > -1);
+
+  // copy the file a chunk at a time
+  const int chunk = 1048576;
+  bufferptr bp(chunk);
+
+  off_t remaining = st.st_size;
+  while (remaining > 0) {
+    off_t got = client->read(fh_ceph, bp.c_str(), MIN(remaining,chunk), -1);
+    assert(got > 0);
+    remaining -= got;
+    off_t wrote = ::write(fh_local, bp.c_str(), got);
+    assert (got == wrote);
+  }
+  client->close(fh_ceph);
+  ::close(fh_local);
+
+  env->ReleaseStringUTFChars(j_local_path, c_local_path);
+  env->ReleaseStringUTFChars(j_ceph_path, c_ceph_path);
+  
+  return JNI_TRUE;
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_getcwd
+ * Signature: (J)Ljava/lang/String;
+ * Returns the current working directory.
+ */
+JNIEXPORT jstring JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1getcwd
+  (JNIEnv *env, jobject obj, jlong clientp)
+{
+  //cout << "In getcwd" << endl;
+  //cout.flush();
+
+  Client* client;
+  client = *(Client**)&clientp;
+
+  return (env->NewStringUTF(client->getcwd().c_str()));
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_setcwd
+ * Signature: (JLjava/lang/String;)Z
+ *
+ * Changes the working directory.
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1setcwd
+(JNIEnv *env, jobject obj, jlong clientp, jstring j_path)
+{
+  //cout << "In setcwd" << endl;
+  //cout.flush();
+
+  Client* client;
+  client = *(Client**)&clientp;
+
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  return (0 <= client->chdir(c_path)) ? JNI_TRUE : JNI_FALSE; 
+  env->ReleaseStringUTFChars(j_path, c_path);
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_rmdir
+ * Signature: (JLjava/lang/String;)Z
+ * Removes an empty directory.
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1rmdir
+  (JNIEnv *env, jobject, jlong clientp, jstring j_path)
+{
+  cout << "In rmdir" << endl;
+  cout.flush();
+
+  Client* client;
+  client = *(Client**)&clientp;
+
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  return (0 == client->rmdir(c_path)) ? JNI_TRUE : JNI_FALSE; 
+  env->ReleaseStringUTFChars(j_path, c_path);
+}
+
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_mkdir
+ * Signature: (JLjava/lang/String;)Z
+ * Creates a directory with full permissions.
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1mkdir
+  (JNIEnv * env, jobject, jlong clientp, jstring j_path)
+{
+  //cout << "In mkdir" << endl;
+  //cout.flush();
+
+
+  Client* client;
+  client = *(Client**)&clientp;
+
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  return (0 == client->mkdir(c_path, 0xFF)) ? JNI_TRUE : JNI_FALSE; 
+  env->ReleaseStringUTFChars(j_path, c_path);
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_unlink
+ * Signature: (JLjava/lang/String;)Z
+ * Unlinks a path.
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1unlink
+  (JNIEnv * env, jobject, jlong clientp, jstring j_path)
+{
+  cout.flush();
+
+  Client* client;
+  client = *(Client**)&clientp;
+
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  cout << "In unlink for path " << c_path <<  ":" << endl;
+
+  // is it a file or a directory?
+  struct stat stbuf;
+  int stat_result = client->lstat(c_path, &stbuf);
+  if (stat_result < 0) {// then the path doesn't even exist
+    cout << "ceph_unlink: path " << c_path << " does not exist" << endl;
+    return false;
+  }  
+  int result;
+  if (0 != S_ISDIR(stbuf.st_mode)) { // it's a directory
+    cout << "ceph_unlink: path " << c_path << " is a directory. Calling client->rmdir()" << endl;
+    result = client->rmdir(c_path);
+  }
+  else if (0 != S_ISREG(stbuf.st_mode)) { // it's a file
+    cout << "ceph_unlink: path " << c_path << " is a file. Calling client->unlink()" << endl;
+    result = client->unlink(c_path);
+  }
+  else {
+    cout << "ceph_unlink: path " << c_path << " is not a file or a directory. Failing:" << endl;
+    result = -1;
+  }
+    
+  cout << "In ceph_unlink for path " << c_path << 
+    ": got result " 
+       << result << ". Returning..."<< endl;
+
+  env->ReleaseStringUTFChars(j_path, c_path);
+  return (0 == result) ? JNI_TRUE : JNI_FALSE; 
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_rename
+ * Signature: (JLjava/lang/String;Ljava/lang/String;)Z
+ * Renames a file.
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1rename
+  (JNIEnv *env, jobject, jlong clientp, jstring j_from, jstring j_to)
+{
+  cout << "In rename" << endl;
+  cout.flush();
+
+
+  Client* client;
+  client = *(Client**)&clientp;
+
+  const char* c_from = env->GetStringUTFChars(j_from, 0);
+  const char* c_to   = env->GetStringUTFChars(j_to,   0);
+
+  return (0 <= client->rename(c_from, c_to)) ? JNI_TRUE : JNI_FALSE; 
+  env->ReleaseStringUTFChars(j_from, c_from);
+  env->ReleaseStringUTFChars(j_to, c_to);
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_exists
+ * Signature: (JLjava/lang/String;)Z
+ * Returns true if the path exists.
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1exists
+(JNIEnv *env, jobject, jlong clientp, jstring j_path)
+{
+
+  //cout << "In exists" << endl;
+  //cout.flush();
+
+  Client* client;
+  struct stat stbuf;
+  client = *(Client**)&clientp;
+
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  cout << "Attempting lstat with file " << c_path << ":" ;
+  //int i = (int) (*c_path);
+  //cout << "First character value is " << i;
+  // cout.flush();
+  int result = client->lstat(c_path, &stbuf);
+  cout << "result is " << result << endl;
+  //  cout << "Attempting to release string \"" << c_path << "\"" << endl;
+  //cout.flush();
+  env->ReleaseStringUTFChars(j_path, c_path);
+  //cout << "String released!" << endl;
+  if (result < 0) {
+    //cout << "Returning false (file does not exist)" << endl;
+    //cout.flush();
+    return JNI_FALSE;
+  }
+  else {
+    //cout << "Returning true (file exists)" << endl;
+    //cout.flush();
+    return JNI_TRUE;
+  }
+
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_getblocksize
+ * Signature: (JLjava/lang/String;)J
+ * Returns the block size. Size is -1 if the file
+ * does not exist.
+ * TODO: see if Hadoop wants something more like stripe size
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1getblocksize
+  (JNIEnv *env, jobject obj, jlong clientp, jstring j_path)
+{
+  cout << "In getblocksize" << endl;
+  cout.flush();
+
+
+  Client* client;
+  struct stat stbuf;
+  client = *(Client**)&clientp;
+  
+  jint result;
+
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  if (0 > client->lstat(c_path, &stbuf))
+    result =  -1;
+  else
+    result = stbuf.st_blksize;
+
+  env->ReleaseStringUTFChars(j_path, c_path);
+  return result;
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_getfilesize
+ * Signature: (JLjava/lang/String;)J
+ * Returns the file size, or -1 on failure.
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1getfilesize
+  (JNIEnv *env, jobject, jlong clientp, jstring j_path)
+{
+  cout << "In getfilesize" << endl;
+  cout.flush();
+
+  Client* client;
+  struct stat stbuf;
+  client = *(Client**)&clientp;
+
+  jlong result;
+
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  if (0 > client->lstat(c_path, &stbuf)) result =  -1; 
+  else result = stbuf.st_size;
+  env->ReleaseStringUTFChars(j_path, c_path);
+
+  return result;
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_isfile
+ * Signature: (JLjava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1isfile
+  (JNIEnv *env, jobject obj, jlong clientp, jstring j_path)
+{
+  //cout << "In isfile" << endl;
+  //cout.flush();
+
+  Client* client;
+  struct stat stbuf;
+  client = *(Client**)&clientp;
+
+
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  //cout << "Attempting lstat with file " << c_path << ":" << endl;
+  //cout.flush();
+  int result = client->lstat(c_path, &stbuf);
+  //cout << "Got through lstat without crashing: result is " << result << endl;
+  //cout.flush();
+
+  env->ReleaseStringUTFChars(j_path, c_path);
+
+  // if the stat call failed, it's definitely not a file...
+  if (0 > result) return JNI_FALSE; 
+
+  // check the stat result
+  //cout << "Stat call succeeded: attempting to look inside stbuf for result" << endl;
+  return (0 == S_ISREG(stbuf.st_mode)) ? JNI_FALSE : JNI_TRUE;
+}
+
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_isdirectory
+ * Signature: (JLjava/lang/String;)Z
+ * Returns true if the path is a directory.
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1isdirectory
+  (JNIEnv *env, jobject, jlong clientp, jstring j_path)
+{
+  //cout << "In isdirectory" << endl;
+  //cout.flush();
+
+  Client* client;
+  struct stat stbuf;
+  client = *(Client**)&clientp;
+
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  int result = client->lstat(c_path, &stbuf);
+  env->ReleaseStringUTFChars(j_path, c_path);
+  //cout << "String released!" << endl;
+  //cout.flush();
+
+  // if the stat call failed, it's definitely not a directory...
+  if (0 > result) return JNI_FALSE; 
+
+  // check the stat result
+  return (0 == S_ISDIR(stbuf.st_mode)) ? JNI_FALSE : JNI_TRUE;
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_getdir
+ * Signature: (JLjava/lang/String;)[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1getdir
+(JNIEnv *env, jobject obj, jlong clientp, jstring j_path) {
+
+  //cout << "In getdir" << endl;
+  //cout.flush();
+
+
+  Client* client;
+  client = *(Client**)&clientp;
+
+  // get the directory listing
+  map<string, inode_t> contents;
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  int result = client->getdir(c_path, contents);
+  //cout << "Releasing string" << endl;
+  env->ReleaseStringUTFChars(j_path, c_path);
+  
+  if (result < 0) return NULL;
+
+  //cout << "checking for empty dir" << endl;
+  jint dir_size = contents.size();
+  if (dir_size < 1) 
+    {
+      //    cout << "dir was empty" << endl;
+      //return NULL;
+    }
+  //out << "dir was not empty" << endl;
+
+  // Create a Java String array of the size of the directory listing
+  // jstring blankString = env->NewStringUTF("");
+  jclass stringClass = env->FindClass("java/lang/String");
+  if (NULL == stringClass) {
+    cout << "ERROR: java String class not found; dying a horrible, painful death" << endl;
+    assert(0);
+  }
+  jobjectArray dirListingStringArray = (jobjectArray) env->NewObjectArray(dir_size, stringClass, NULL);
+  
+  // populate the array with the elements of the directory list
+  int i = 0;
+  for (map<string, inode_t>::iterator it = contents.begin();
+       it != contents.end();
+       it++) {
+    if (0 == dir_size)
+      cout << "WARNING: adding stuff to an empty array" << endl;
+    env->SetObjectArrayElement(dirListingStringArray, i, 
+                              env->NewStringUTF(it->first.c_str()));
+    ++i;
+  }
+                            
+  return dirListingStringArray;
+}
+
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_open_for_read
+ * Signature: (JLjava/lang/String;)I
+ * Open a file for reading.
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1open_1for_1read
+  (JNIEnv *env, jobject obj, jlong clientp, jstring j_path)
+
+{
+  //cout << "In open_for_read" << endl;
+  //cout.flush();
+
+
+  Client* client;
+  client = *(Client**)&clientp;
+
+  jint result; 
+
+  // open as read-only: flag = O_RDONLY
+
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  result = client->open(c_path, O_RDONLY);
+  env->ReleaseStringUTFChars(j_path, c_path);
+
+  // returns file handle, or -1 on failure
+  return result;
+}
+
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_open_for_overwrite
+ * Signature: (JLjava/lang/String;)I
+ * Opens a file for overwriting; creates it if necessary.
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1open_1for_1overwrite
+  (JNIEnv *env, jobject obj, jlong clientp, jstring j_path)
+{
+  //cout << "In open_for_overwrite" << endl;
+  //cout.flush();
+
+  Client* client;
+  client = *(Client**)&clientp;
+
+  jint result; 
+
+
+  const char* c_path = env->GetStringUTFChars(j_path, 0);
+  result = client->open(c_path, O_WRONLY|O_CREAT|O_TRUNC);
+  env->ReleaseStringUTFChars(j_path, c_path);
+
+  // returns file handle, or -1 on failure
+  return result;       
+}
+
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephInputStream
+ * Method:    ceph_read
+ * Signature: (JI[BII)I
+ * Reads into the given byte array from the current position.
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephInputStream_ceph_1read
+  (JNIEnv *env, jobject obj, jlong clientp, jint fh, jbyteArray j_buffer, jint buffer_offset, jint length)
+{
+  //cout << "In read" << endl;
+  //cout.flush();
+
+
+  // IMPORTANT NOTE: Hadoop read arguments are a bit different from POSIX so we
+  // have to convert.  The read is *always* from the current position in the file,
+  // and buffer_offset is the location in the *buffer* where we start writing.
+
+
+  Client* client;
+  client = *(Client**)&clientp;
+  jint result; 
+
+  // Step 1: get a pointer to the buffer.
+  jbyte* j_buffer_ptr = env->GetByteArrayElements(j_buffer, NULL);
+  char* c_buffer = (char*) j_buffer_ptr;
+
+  // Step 2: pointer arithmetic to start in the right buffer position
+  c_buffer += (int)buffer_offset;
+
+  // Step 3: do the read
+  result = client->read((int)fh, c_buffer, length, -1);
+
+  // Step 4: release the pointer to the buffer
+  env->ReleaseByteArrayElements(j_buffer, j_buffer_ptr, 0);
+  
+  return result;
+}
+
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephInputStream
+ * Method:    ceph_seek_from_start
+ * Signature: (JIJ)J
+ * Seeks to the given position.
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephInputStream_ceph_1seek_1from_1start
+  (JNIEnv *env, jobject obj, jlong clientp, jint fh, jlong pos)
+{
+  //cout << "In CephInputStream::seek_from_start" << endl;
+  //cout.flush();
+
+
+  Client* client;
+  client = *(Client**)&clientp;
+  jint result; 
+
+  result = client->lseek(fh, pos, SEEK_SET);
+  
+  return result;
+}
+
+
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephInputStream_ceph_1getpos
+  (JNIEnv *env, jobject obj, jlong clientp, jint fh)
+{
+  cout << "In CephInputStream::ceph_getpos" << endl;
+  cout.flush();
+
+
+  Client* client;
+  client = *(Client**)&clientp;
+  jint result; 
+
+  // seek a distance of 0 to get current offset
+  result = client->lseek(fh, 0, SEEK_CUR);  
+
+  return result;
+}
+
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephInputStream
+ * Method:    ceph_close
+ * Signature: (JI)I
+ * Closes the file.
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephInputStream_ceph_1close
+  (JNIEnv *env, jobject obj, jlong clientp, jint fh)
+{
+  cout << "In CephInputStream::ceph_close" << endl;
+  cout.flush();
+
+  Client* client;
+  client = *(Client**)&clientp;
+  jint result; 
+
+  result = client->close(fh);
+
+  return result;
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephOutputStream
+ * Method:    ceph_seek_from_start
+ * Signature: (JIJ)J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1seek_1from_1start
+  (JNIEnv *env, jobject obj, jlong clientp, jint fh, jlong pos)
+{
+  cout << "In CephOutputStream::ceph_seek_from_start" << endl;
+  cout.flush();
+
+  Client* client;
+  client = *(Client**)&clientp;
+  jint result; 
+
+  result = client->lseek(fh, pos, SEEK_SET);
+  
+  return result;
+}
+
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephOutputStream
+ * Method:    ceph_getpos
+ * Signature: (JI)J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1getpos
+  (JNIEnv *env, jobject obj, jlong clientp, jint fh)
+{
+  cout << "In CephOutputStream::ceph_getpos" << endl;
+  cout.flush();
+
+  Client* client;
+  client = *(Client**)&clientp;
+  jint result; 
+
+  // seek a distance of 0 to get current offset
+  result = client->lseek(fh, 0, SEEK_CUR);  
+
+  return result;
+}
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephOutputStream
+ * Method:    ceph_close
+ * Signature: (JI)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1close
+  (JNIEnv *env, jobject obj, jlong clientp, jint fh)
+{
+  cout << "In CephOutputStream::ceph_close" << endl;
+  cout.flush();
+
+  Client* client;
+  client = *(Client**)&clientp;
+  jint result; 
+
+  result = client->close(fh);
+
+  return result;
+}
+
+
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephOutputStream
+ * Method:    ceph_write
+ * Signature: (JI[BII)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1write
+  (JNIEnv *env, jobject obj, jlong clientp, jint fh, jbyteArray j_buffer, jint buffer_offset, jint length)
+{
+  cout << "In write" << endl;
+  cout.flush();
+
+
+  // IMPORTANT NOTE: Hadoop write arguments are a bit different from POSIX so we
+  // have to convert.  The write is *always* from the current position in the file,
+  // and buffer_offset is the location in the *buffer* where we start writing.
+
+  Client* client;
+  client = *(Client**)&clientp;
+  jint result; 
+
+  // Step 1: get a pointer to the buffer.
+  jbyte* j_buffer_ptr = env->GetByteArrayElements(j_buffer, NULL);
+  char* c_buffer = (char*) j_buffer_ptr;
+
+  // Step 2: pointer arithmetic to start in the right buffer position
+  c_buffer += (int)buffer_offset;
+
+  // Step 3: do the write
+  result = client->write((int)fh, c_buffer, length, -1);
+  
+  // Step 4: release the pointer to the buffer
+  env->ReleaseByteArrayElements(j_buffer, j_buffer_ptr, 0);
+
+  return result;
+}
+
diff --git a/branches/sage/cephmds2/client/hadoop/CephFSInterface.h b/branches/sage/cephmds2/client/hadoop/CephFSInterface.h
new file mode 100644 (file)
index 0000000..8cba324
--- /dev/null
@@ -0,0 +1,229 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_apache_hadoop_fs_ceph_CephFileSystem */
+
+#include <sys/stat.h>
+#include "client/Client.h"
+#include "config.h"
+#include "client/fuse.h"
+#include "msg/SimpleMessenger.h"
+#include "common/Timer.h"
+
+#ifndef _Included_org_apache_hadoop_fs_ceph_CephFileSystem
+#define _Included_org_apache_hadoop_fs_ceph_CephFileSystem
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#undef org_apache_hadoop_fs_ceph_CephFileSystem_DEFAULT_BLOCK_SIZE
+#define org_apache_hadoop_fs_ceph_CephFileSystem_DEFAULT_BLOCK_SIZE 1048576LL
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_initializeClient
+ * Signature: ()J
+ * Initializes a ceph client.
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1initializeClient
+(JNIEnv *, jobject);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_copyFromLocalFile
+ * Signature: (JLjava/lang/String;Ljava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1copyFromLocalFile
+  (JNIEnv *, jobject, jlong, jstring, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_copyToLocalFile
+ * Signature: (JLjava/lang/String;Ljava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1copyToLocalFile
+  (JNIEnv *, jobject, jlong, jstring, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_getcwd
+ * Signature: (J)Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1getcwd
+  (JNIEnv *, jobject, jlong);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_setcwd
+ * Signature: (JLjava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1setcwd
+  (JNIEnv *, jobject, jlong, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_rmdir
+ * Signature: (JLjava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1rmdir
+  (JNIEnv *, jobject, jlong, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_mkdir
+ * Signature: (JLjava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1mkdir
+  (JNIEnv *, jobject, jlong, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_unlink
+ * Signature: (JLjava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1unlink
+  (JNIEnv *, jobject, jlong, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_rename
+ * Signature: (JLjava/lang/String;Ljava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1rename
+  (JNIEnv *, jobject, jlong, jstring, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_exists
+ * Signature: (JLjava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1exists
+  (JNIEnv *, jobject, jlong, jstring);
+
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_getblocksize
+ * Signature: (JLjava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1getblocksize
+  (JNIEnv *, jobject, jlong, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_getfilesize
+ * Signature: (JLjava/lang/String;)J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1getfilesize
+  (JNIEnv *, jobject, jlong, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_isdirectory
+ * Signature: (JLjava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1isdirectory
+  (JNIEnv *, jobject, jlong, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_isfile
+ * Signature: (JLjava/lang/String;)Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1isfile
+  (JNIEnv *, jobject, jlong, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_getdir
+ * Signature: (JLjava/lang/String;)[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1getdir
+  (JNIEnv *, jobject, jlong, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_open_for_read
+ * Signature: (JLjava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1open_1for_1read
+  (JNIEnv *, jobject, jlong, jstring);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephFileSystem
+ * Method:    ceph_open_for_overwrite
+ * Signature: (JLjava/lang/String;)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephFileSystem_ceph_1open_1for_1overwrite
+  (JNIEnv *, jobject, jlong, jstring);
+
+#undef org_apache_hadoop_fs_ceph_CephInputStream_SKIP_BUFFER_SIZE
+#define org_apache_hadoop_fs_ceph_CephInputStream_SKIP_BUFFER_SIZE 2048L
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephInputStream
+ * Method:    ceph_read
+ * Signature: (JI[BII)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephInputStream_ceph_1read
+  (JNIEnv *, jobject, jlong, jint, jbyteArray, jint, jint);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephInputStream
+ * Method:    ceph_seek_from_start
+ * Signature: (JIJ)J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephInputStream_ceph_1seek_1from_1start
+  (JNIEnv *, jobject, jlong, jint, jlong);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephInputStream
+ * Method:    ceph_getpos
+ * Signature: (JI)J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephInputStream_ceph_1getpos
+  (JNIEnv *, jobject, jlong, jint);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephInputStream
+ * Method:    ceph_close
+ * Signature: (JI)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephInputStream_ceph_1close
+  (JNIEnv *, jobject, jlong, jint);
+
+/* Header for class org_apache_hadoop_fs_ceph_CephOutputStream */
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephOutputStream
+ * Method:    ceph_seek_from_start
+ * Signature: (JIJ)J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1seek_1from_1start
+  (JNIEnv *, jobject, jlong, jint, jlong);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephOutputStream
+ * Method:    ceph_getpos
+ * Signature: (JI)J
+ */
+JNIEXPORT jlong JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1getpos
+  (JNIEnv *, jobject, jlong, jint);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephOutputStream
+ * Method:    ceph_close
+ * Signature: (JI)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1close
+  (JNIEnv *, jobject, jlong, jint);
+
+/*
+ * Class:     org_apache_hadoop_fs_ceph_CephOutputStream
+ * Method:    ceph_write
+ * Signature: (JI[BII)I
+ */
+JNIEXPORT jint JNICALL Java_org_apache_hadoop_fs_ceph_CephOutputStream_ceph_1write
+  (JNIEnv *, jobject, jlong, jint, jbyteArray, jint, jint);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
index 8faf6a5bc604908dd05e3796a0bcbb31040aaf79..aeeb42e87488a24415a2fe19ed390bb3bb23bd46 100644 (file)
@@ -74,6 +74,7 @@ int main(int argc, char **argv)
     }
   }
 
+  if (g_conf.clock_tare) g_clock.tare();
 
   // load monmap
   MonMap monmap;
index 442b584f02abd8ed504b2823e3e7a7f931a65e28..8fd627986a240627f627e3e2535589e54f5c3c6f 100644 (file)
@@ -73,7 +73,9 @@ int main(int argc, char **argv)
       return -1;
     }
   }
-  
+
+  if (g_conf.clock_tare) g_clock.tare();
+
   MonMap monmap;
 
   if (whoami < 0) {
index e5f647e63ccccb3521728822b13ee74e852b72f2..9f4e581cf2711a9e0eb56cc51e66497d425d602e 100644 (file)
@@ -41,7 +41,7 @@ class Clock {
  public:
   Clock() {
     // set offset
-    tare();
+    //tare();
   }
 
   // real time.
@@ -56,6 +56,9 @@ class Clock {
   void tare() {
     gettimeofday(&zero.timeval(), NULL);
   }
+  void tare(utime_t z) {
+    zero = z;
+  }
   utime_t now() {
     //lock.Lock();  
     utime_t n;
index 91164658a80e58b68f52952459fadcdcbcd98f81..e789d64a6ce473f517348cd6ee3615faa132ef91 100644 (file)
@@ -52,7 +52,9 @@ Logger::Logger(string fn, LogType *type)
     //cout << "log " << filename << endl;
     interval = g_conf.log_interval;
     
-    //start = g_clock.now();  // time 0!
+    if (!g_conf.clock_tare)
+      start = g_clock.now();  // time 0!  otherwise g_clock does it for us.
+
     last_logged = 0;
     wrote_header = -1;
     open = false;
index 50937c5edc294eab30d5470ba67fecc92cf35022..e3f4402bdb4f6889d85f55e2ae0aa735df230c0e 100644 (file)
@@ -31,6 +31,7 @@
 long buffer_total_alloc = 0;
 Mutex bufferlock;
 
+Mutex _dout_lock;
 
 
 FileLayout g_OSD_FileLayout( 1<<20, 1, 1<<20, 2 );  // stripe over 1M objects, 2x replication
@@ -108,6 +109,7 @@ md_config_t g_conf = {
 
   // --- clock ---
   clock_lock: false,
+  clock_tare: true,
   
   // --- messenger ---
   ms_single_dispatch: false,
@@ -561,6 +563,8 @@ void parse_config_options(std::vector<char*>& args)
 
     else if (strcmp(args[i], "--clock_lock") == 0) 
       g_conf.clock_lock = atoi(args[++i]);
+    else if (strcmp(args[i], "--clock_tare") == 0) 
+      g_conf.clock_tare = atoi(args[++i]);
 
     else if (strcmp(args[i], "--objecter_buffer_uncommitted") == 0) 
       g_conf.objecter_buffer_uncommitted = atoi(args[++i]);
index b507556e0c01c834b6e13c234226204850fa5876..8d01d06b4ed0bde04d6f6d57386f878d09f7950d 100644 (file)
@@ -21,6 +21,8 @@ extern class FileLayout g_OSD_MDLogLayout;
 #include <vector>
 #include <map>
 
+#include "common/Mutex.h"
+
 extern std::map<int,float> g_fake_osd_down;
 extern std::map<int,float> g_fake_osd_out;
 
@@ -86,6 +88,7 @@ struct md_config_t {
 
   // clock
   bool clock_lock;
+  bool clock_tare;
 
   // messenger
 
@@ -310,9 +313,41 @@ struct md_config_t {
 extern md_config_t g_conf;     
 extern md_config_t g_debug_after_conf;     
 
+
+/**
+ * debug output framework
+ */
 #define dout(x)  if ((x) <= g_conf.debug) std::cout
 #define dout2(x) if ((x) <= g_conf.debug) std::cout
 
+/**
+ * for cleaner output, bracket each line with
+ * dbeginl (in the dout macro) and dendl (in place of endl).
+ */
+extern Mutex _dout_lock;
+struct _dbeginl_t {
+  _dbeginl_t(int) {}
+};
+struct _dendl_t {
+  _dendl_t(int) {}
+};
+static const _dbeginl_t dbeginl = 0;
+static const _dendl_t dendl = 0;
+
+inline ostream& operator<<(ostream& out, _dbeginl_t) {
+  _dout_lock.Lock();
+  return out;
+}
+inline ostream& operator<<(ostream& out, _dendl_t) {
+  out << endl;
+  _dout_lock.Unlock();
+  return out;
+}
+
+
+/**
+ * command line / environment argument parsing
+ */
 void env_to_vec(std::vector<char*>& args);
 void argv_to_vec(int argc, char **argv,
                  std::vector<char*>& args);
index ae23a667a32da2e3ea2f6701e656a30d10d38d70..ff1e24b63b9055d85b9bd32aa61f3edea533fe4c 100644 (file)
@@ -62,6 +62,8 @@ int main(int argc, char **argv)
   if (g_conf.debug_after) 
     g_timer.add_event_after(g_conf.debug_after, new C_Debug);
 
+  if (g_conf.clock_tare) g_clock.tare();
+
   // osd specific args
   char *dev;
   int whoami = -1;
index 0f95ee56b26020c8f8823ec156eaa7c99b0a1062..afec2f81724b0b37680dfec4c67c961000070cb2 100644 (file)
@@ -45,6 +45,8 @@ int main(int argc, char **argv, char *envp[]) {
   // args for fuse
   vec_to_argv(args, argc, argv);
 
+  if (g_conf.clock_tare) g_clock.tare();
+
   // load monmap
   MonMap monmap;
   int r = monmap.read(".ceph_monmap");
index 2edf3c7930e7ae247a887eba746d4f7dae65bfad..ed2e90a8d5625212719803c10fefb883eabcec87 100644 (file)
@@ -78,6 +78,8 @@ int main(int argc, char **argv) {
   // FUSE will chdir("/"); be ready.
   g_conf.use_abspaths = true;
 
+  if (g_conf.clock_tare) g_clock.tare();
+
   MonMap *monmap = new MonMap(g_conf.num_mon);
   
   Monitor *mon[g_conf.num_mon];
diff --git a/branches/sage/cephmds2/fakemon.cc b/branches/sage/cephmds2/fakemon.cc
deleted file mode 100644 (file)
index 28cad55..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
- * Foundation.  See file COPYING.
- * 
- */
-
-
-
-#include <sys/stat.h>
-#include <iostream>
-#include <string>
-using namespace std;
-
-#include "config.h"
-
-#include "mds/MDCluster.h"
-
-#include "mds/MDS.h"
-#include "osd/OSD.h"
-#include "mon/Monitor.h"
-#include "client/Client.h"
-
-#include "client/SyntheticClient.h"
-
-#include "msg/FakeMessenger.h"
-
-#include "common/Timer.h"
-
-#define NUMMDS g_conf.num_mds
-#define NUMOSD g_conf.num_osd
-#define NUMCLIENT g_conf.num_client
-
-class C_Test : public Context {
-public:
-  void finish(int r) {
-    cout << "C_Test->finish(" << r << ")" << endl;
-  }
-};
-
-
-int main(int argc, char **argv) 
-{
-  cerr << "fakesyn start" << endl;
-
-  //cerr << "inode_t " << sizeof(inode_t) << endl;
-
-  vector<char*> args;
-  argv_to_vec(argc, argv, args);
-
-  parse_config_options(args);
-
-  int start = 0;
-
-  parse_syn_options(args);
-
-  vector<char*> nargs;
-
-  for (unsigned i=0; i<args.size(); i++) {
-    // unknown arg, pass it on.
-    cerr << " stray arg " << args[i] << endl;
-    nargs.push_back(args[i]);
-  }
-  assert(nargs.empty());
-
-
-  MDCluster *mdc = new MDCluster(NUMMDS, NUMOSD);
-
-
-  char hostname[100];
-  gethostname(hostname,100);
-  //int pid = getpid();
-
-  // create mon
-  Monitor *mon[g_conf.num_mon];
-  for (int i=0; i<g_conf.num_mon; i++) {
-    mon[i] = new Monitor(i, new FakeMessenger(MSG_ADDR_MON(i)));
-  }
-
-  // create mds
-  MDS *mds[NUMMDS];
-  OSD *mdsosd[NUMMDS];
-  for (int i=0; i<NUMMDS; i++) {
-    //cerr << "mds" << i << " on rank " << myrank << " " << hostname << "." << pid << endl;
-    mds[i] = new MDS(mdc, i, new FakeMessenger(MSG_ADDR_MDS(i)));
-    if (g_conf.mds_local_osd)
-      mdsosd[i] = new OSD(i+10000, new FakeMessenger(MSG_ADDR_OSD(i+10000)));
-    start++;
-  }
-  
-  // create osd
-  OSD *osd[NUMOSD];
-  for (int i=0; i<NUMOSD; i++) {
-    //cerr << "osd" << i << " on rank " << myrank << " " << hostname << "." << pid << endl;
-    osd[i] = new OSD(i, new FakeMessenger(MSG_ADDR_OSD(i)));
-    start++;
-  }
-  
-  // create client
-  Client *client[NUMCLIENT];
-  SyntheticClient *syn[NUMCLIENT];
-  for (int i=0; i<NUMCLIENT; i++) {
-    //cerr << "client" << i << " on rank " << myrank << " " << hostname << "." << pid << endl;
-    client[i] = new Client(new FakeMessenger(MSG_ADDR_CLIENT(i)));
-    start++;
-  }
-
-
-  // start message loop
-  fakemessenger_startthread();
-  
-  // init
-  for (int i=0; i<g_conf.num_mon; i++) {
-    mon[i]->init();
-  }
-  for (int i=0; i<NUMMDS; i++) {
-    mds[i]->init();
-    if (g_conf.mds_local_osd)
-      mdsosd[i]->init();
-  }
-  
-  for (int i=0; i<NUMOSD; i++) {
-    osd[i]->init();
-  }
-
-  
-  // create client(s)
-  for (int i=0; i<NUMCLIENT; i++) {
-    client[i]->init();
-    
-    // use my argc, argv (make sure you pass a mount point!)
-    //cout << "mounting" << endl;
-    client[i]->mount();
-    
-    //cout << "starting synthetic client  " << endl;
-    syn[i] = new SyntheticClient(client[i]);
-
-    syn[i]->start_thread();
-  }
-
-
-  for (int i=0; i<NUMCLIENT; i++) {
-    
-    cout << "waiting for synthetic client " << i << " to finish" << endl;
-    syn[i]->join_thread();
-    delete syn[i];
-    
-    client[i]->unmount();
-    //cout << "unmounted" << endl;
-    client[i]->shutdown();
-  }
-  
-        
-  // wait for it to finish
-  fakemessenger_wait();
-  
-  // cleanup
-  for (int i=0; i<NUMMDS; i++) {
-    delete mds[i];
-  }
-  for (int i=0; i<NUMOSD; i++) {
-    delete osd[i];
-  }
-  for (int i=0; i<NUMCLIENT; i++) {
-    delete client[i];
-  }
-  delete mdc;
-
-  cout << "fakesyn done" << endl;
-  return 0;
-}
-
index d4fc63a4cbba82a56f8fe9fad3ffea9dad1a83f9..3d2092123201ca74627ca2c0d49ffe459ab3ffc7 100644 (file)
@@ -76,8 +76,7 @@ int main(int argc, char **argv)
   if (g_conf.kill_after) 
     g_timer.add_event_after(g_conf.kill_after, new C_Die);
 
-
-  g_clock.tare();
+  if (g_conf.clock_tare) g_clock.tare();
 
   MonMap *monmap = new MonMap(g_conf.num_mon);
   entity_addr_t a;
index cef3384010c0ae39e0ed98b9cac36e5ad8d24596..c5db175bfc9e0625124a642476592b51c5b5da03 100644 (file)
@@ -34,7 +34,7 @@ using namespace std;
 
 #define LOCK_LOCK_    2  // AR   R W / C . . . . .   . . / C . . . . .   truncate()
 #define LOCK_GLOCKR_ -3  // AR   R . / C . . . . .   . . / C . . . . .
-#define LOCK_GLOCKL  -4  // A    . . / . . . . . .                       loner -> lock
+#define LOCK_GLOCKL  -4  // A    . . / C . . . . .                       loner -> lock
 #define LOCK_GLOCKM  -5  // A    . . / . . . . . .
 
 #define LOCK_MIXED    6  // AR   . . / . R W A . L   . . / . R . . . L
@@ -164,9 +164,9 @@ class FileLock : public SimpleLock {
         return CAP_FILE_RDCACHE | CAP_FILE_RD | CAP_FILE_LAZYIO;
       case LOCK_LOCK:
       case LOCK_GLOCKR:
+      case LOCK_GLOCKL:
         return CAP_FILE_RDCACHE;
 
-      case LOCK_GLOCKL:
       case LOCK_GLOCKM:
         return 0;
 
index 68d25a94078b68a7b84368724e5ec3bbb8e73a52..672cbdba80ea219cc3074beea2b59a4a823b45ce 100644 (file)
@@ -1298,7 +1298,7 @@ void Locker::file_eval(FileLock *lock)
     case LOCK_GLOCKR:
     case LOCK_GLOCKM:
     case LOCK_GLOCKL:
-      if (issued == 0) {
+      if ((issued & ~CAP_FILE_RDCACHE) == 0) {
         lock->set_state(LOCK_LOCK);
         
         // waiters
index f577e29417e1e1e659c61041532e2f96fc63484b..87a68882b4181797e324da4509b53c40d2d14f9e 100644 (file)
@@ -95,6 +95,12 @@ void MDLog::init_journaler()
   journaler = new Journaler(log_inode, mds->objecter, logger);
 }
 
+void MDLog::flush_logger()
+{
+  if (logger)
+    logger->flush(true);
+}
+
 
 
 void MDLog::reset()
index f06a2eea21427736414403ca86c5d34674b2ac12..114d6c630749f9eaab2a788a0b42140c8ab42d61 100644 (file)
@@ -128,7 +128,8 @@ class MDLog {
   }              
   ~MDLog();
 
+
+  void flush_logger();
 
   void set_max_events(size_t max) { max_events = max; }
   size_t get_max_events() { return max_events; }
index 14f98b7ab4ac874e7596f8a400b9f93067403bc1..215d72850923441b80416e4a7fb58cdb49225582 100644 (file)
@@ -264,6 +264,9 @@ int MDS::init(bool standby)
   // schedule tick
   reset_tick();
 
+  // init logger
+  reopen_logger();
+
   mds_lock.Unlock();
   return 0;
 }
@@ -912,6 +915,11 @@ int MDS::shutdown_final()
 {
   dout(1) << "shutdown_final" << endl;
 
+  // flush loggers
+  if (logger) logger->flush(true);
+  if (logger2) logger2->flush(true);
+  mdlog->flush_logger();
+  
   // send final down:out beacon (it doesn't matter if this arrives)
   set_want_state(MDSMap::STATE_OUT);
 
index fe9d54b189de6b9431340bf8ac6b35b1b208f79a..8f0ee4484ea4fc0e748f73b27de74786b354a110 100644 (file)
@@ -126,15 +126,20 @@ void OSDMonitor::create_initial()
   if (g_conf.osd_pg_bits) {
     osdmap.set_pg_bits(g_conf.osd_pg_bits);
   } else {
-    int osdbits = 1;
+    // figure out how many bits worth of osds we have.
+    //     1 osd  -> 0 bits
+    //  <= 2 osds -> 1 bit
+    //  <= 4 osds -> 2 bits
+    int osdbits = -1;
     int n = g_conf.num_osd;
+    assert(n > 0);
     while (n) {
       n = n >> 1;
       osdbits++;
     }
 
-    // 2 bits per osd.
-    osdmap.set_pg_bits(osdbits + 2);
+    // 7 bits per osd.
+    osdmap.set_pg_bits(osdbits + 7);
   }
   
   // start at epoch 0 until all osds boot
index 23a1752088253b0ee2eb0a3ac0b6d4dc99318df2..1b15c85e2d3cccd0354aa892556e94f225e3f2be 100644 (file)
@@ -709,7 +709,8 @@ void Rank::Pipe::fail(list<Message*>& out)
  */
 
 Rank::Rank() : 
-  single_dispatcher(this) {
+  single_dispatcher(this),
+  started(false) {
   // default to any listen_addr
   memset((char*)&listen_addr, 0, sizeof(listen_addr));
   listen_addr.sin_family = AF_INET;
@@ -799,7 +800,14 @@ void Rank::reaper()
 
 int Rank::start_rank()
 {
+  lock.Lock();
+  if (started) {
+    dout(10) << "start_rank already started" << endl;
+    lock.Unlock();
+    return 0;
+  }
   dout(10) << "start_rank" << endl;
+  lock.Unlock();
 
   // bind to a socket
   if (accepter.start() < 0) 
@@ -814,7 +822,7 @@ int Rank::start_rank()
   lock.Lock();
 
   dout(1) << "start_rank at " << listen_addr << endl;
-
+  started = true;
   lock.Unlock();
   return 0;
 }
index 1839b26683cae313cca9d3d04e6aabcda7cf4cfc..d49b4118bec7376430ca3fffd51b7ad98c78c7ff 100644 (file)
@@ -242,7 +242,8 @@ private:
  public:
   Mutex lock;
   Cond  wait_cond;  // for wait()
-  
+  bool started;
+
   // where i listen
   tcpaddr_t listen_addr;
   entity_addr_t my_addr;
index 82292033fa0625741938fb9ca914970ef01e00fc..9ec409c9c3e7c85340ff16d7798d3b9c8e058ca4 100644 (file)
@@ -58,9 +58,21 @@ pair<int,int> mpi_bootstrap_new(int& argc, char**& argv, MonMap *monmap)
   MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
 
   // first, synchronize clocks.
-  MPI_Barrier(MPI_COMM_WORLD);
-  //dout(-10) << "tare" << endl;
-  g_clock.tare();
+  if (g_conf.clock_tare) {
+    if (1) {
+      // use an MPI barrier.  probably not terribly precise.
+      MPI_Barrier(MPI_COMM_WORLD);
+      g_clock.tare();
+    } else {
+      // use wall clock; assume NTP has all nodes synchronized already.
+      // FIXME someday: this hangs for some reason.  whatever.
+      utime_t z = g_clock.now();
+      MPI_Bcast( &z, sizeof(z), MPI_CHAR,
+                0, MPI_COMM_WORLD);
+      cout << "z is " << z << endl;
+      g_clock.tare(z);
+    }
+  }
   
   // start up all monitors at known addresses.
   entity_inst_t moninst[mpi_world];  // only care about first g_conf.num_mon of these.
index a60888a7dbb5a1bff4c1c3c6cdfb2caf8dc96aec..ace780967190f2173b3b9399847311fd8f74c373 100644 (file)
@@ -9,8 +9,11 @@ License version 2.1, as published by the Free Software
 Foundation.  See file COPYING. */
 
 
+#include <map>
+#include <string>
 #include <cerrno>
 #include "OSBDB.h"
+#include "common/Timer.h"
 
 using namespace std;
 
@@ -19,6 +22,26 @@ using namespace std;
 #undef derr
 #define derr(x) if (x <= g_conf.debug || x <= g_conf.debug_bdbstore) cerr << "bdbstore(" << device << ")@" << __LINE__ << "."
 
+#define CLEANUP(onsafe) do { \
+    dout(6) << "DELETE " << hex << onsafe << dec << endl; \
+    delete onsafe; \
+  } while (0)
+#define COMMIT(onsafe) do { \
+    dout(6) << "COMMIT " << hex << onsafe << dec << endl; \
+    sync(onsafe); \
+  } while (0)
+
+\f // Have a lock, already.
+
+class scoped_lock
+{
+private:
+  Mutex *m;
+public:
+  scoped_lock(Mutex *m) : m(m) { m->Lock(); }
+  ~scoped_lock() { m->Unlock(); }
+};
+
 \f // Utilities.
 
 // Starting off with my own bsearch; mail reader to follow...
@@ -61,33 +84,33 @@ uint32_t binary_search (T *array, size_t size, T key)
 
 \f // Management.
 
-int OSBDB::opendb(DBTYPE type, int flags, bool new_env)
+DbEnv *OSBDB::getenv ()
 {
-  // BDB transactions require an environment.
-  if (g_conf.bdbstore_transactional)
-    {
-      env = new DbEnv (DB_CXX_NO_EXCEPTIONS);
-      env->set_error_stream (&std::cerr);
-      env->set_message_stream (&std::cout);
-      env->set_flags (DB_LOG_INMEMORY, 1);
-      //env->set_flags (DB_DIRECT_DB, 1);
-      int env_flags = (DB_CREATE
-                       | DB_THREAD
-                       | DB_INIT_LOCK
-                       | DB_INIT_MPOOL
-                       | DB_INIT_TXN
-                       | DB_INIT_LOG
-                       | DB_PRIVATE);
-      //if (new_env)
-      //  env->remove (env_dir.c_str(), 0);
-      if (env->open (NULL, env_flags, 0) != 0)
-        {
-          std::cerr << "failed to open environment " << std::endl;
-          return -EIO;
-        }
-
-    }
+  DbEnv *envp = new DbEnv (DB_CXX_NO_EXCEPTIONS);
+  if (g_conf.debug > 1 || g_conf.debug_bdbstore > 1)
+    envp->set_error_stream (&std::cerr);
+  if (g_conf.debug > 2 || g_conf.debug_bdbstore > 2)
+    envp->set_message_stream (&std::cout);
+  envp->set_flags (DB_LOG_INMEMORY, 1);
+  //env->set_flags (DB_DIRECT_DB, 1);
+  int env_flags = (DB_CREATE
+                   | DB_THREAD
+                   //| DB_INIT_LOCK
+                   | DB_INIT_MPOOL
+                   //| DB_INIT_TXN
+                   //| DB_INIT_LOG
+                   | DB_PRIVATE);
+  if (envp->open (NULL, env_flags, 0) != 0)
+    {
+      std::cerr << "failed to open environment " << std::endl;
+      assert(0);
+    }
+  return envp;
+}
 
+int OSBDB::opendb(DBTYPE type, int flags, bool new_env)
+{
+  env = getenv();
   db = new Db(env, 0);
   db->set_error_stream (&std::cerr);
   db->set_message_stream (&std::cout);
@@ -115,7 +138,7 @@ int OSBDB::opendb(DBTYPE type, int flags, bool new_env)
   if ((ret = db->open (NULL, device.c_str(), NULL, type, flags, 0)) != 0)
     {
       derr(1) << "failed to open database: " << device << ": "
-              << strerror(ret) << std::endl;
+              << db_strerror(ret) << std::endl;
       return -EINVAL;
     }
   opened = true;
@@ -248,7 +271,9 @@ int OSBDB::mkfs()
 
   dout(2) << "mkfs" << endl;
 
-  unlink (device.c_str());
+  string d = env_dir;
+  d += device;
+  unlink (d.c_str());
 
   int ret;
   if ((ret = opendb((g_conf.bdbstore_btree ? DB_BTREE : DB_HASH),
@@ -354,9 +379,13 @@ int OSBDB::remove(object_t oid, Context *onsafe)
   if (!mounted)
     {
       derr(1) << "not mounted!" << endl;
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -EINVAL;
     }
 
+  dout(6) << "Context " << hex << onsafe << dec << endl;
+  scoped_lock __lock(&lock);
   dout(2) << "remove " << oid << endl;
 
   DbTxn *txn = NULL;
@@ -366,11 +395,28 @@ int OSBDB::remove(object_t oid, Context *onsafe)
   oid_t id;
   mkoid(id, oid);
   Dbt key (&id, sizeof (oid_t));
-  db->del (NULL, &key, 0);
+  int ret;
+  if ((ret = db->del (txn, &key, 0)) != 0)
+    {
+      derr(1) << ".del returned error: " << db_strerror (ret) << endl;
+      if (txn != NULL)
+        txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
+      return -EIO;
+    }
 
   object_inode_key _ikey = new_object_inode_key (oid);
   Dbt ikey (&_ikey, sizeof_object_inode_key());
-  db->del (txn, &ikey, 0);
+  if ((ret = db->del (txn, &ikey, 0)) != 0)
+    {
+      derr(1) << ".del returned error: " << db_strerror (ret) << endl;
+      if (txn != NULL)
+        txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
+      return -EIO;
+    }
 
   attrs_id aids = new_attrs_id (oid);
   Dbt askey (&aids, sizeof_attrs_id());
@@ -385,32 +431,57 @@ int OSBDB::remove(object_t oid, Context *onsafe)
         {
           attr_id aid = new_attr_id (oid, sap->names[i].name);
           Dbt akey (&aid, sizeof (aid));
-          db->del (txn, &akey, 0);
+          if ((ret = db->del (txn, &akey, 0)) != 0)
+            {
+              derr(1) << ".del returns error: " << db_strerror (ret) << endl;
+              if (txn != NULL)
+                txn->abort();
+              if (onsafe != NULL)
+                CLEANUP(onsafe);
+              return -EIO;
+            }
+        }
+      if ((ret = db->del (txn, &askey, 0)) != 0)
+        {
+          derr(1) << ".del returns error: " << db_strerror (ret) << endl;
+          if (txn != NULL)
+            txn->abort();
+          if (onsafe != NULL)
+            CLEANUP(onsafe);
+          return -EIO;
         }
-      db->del (txn, &askey, 0);
     }
 
   // XXX check del return value
 
-  if (txn)
+  if (txn != NULL)
     txn->commit (0);
+  if (onsafe != NULL)
+    COMMIT(onsafe);
   dout(4) << "..remove OK" << endl;
   return 0;
 }
 
 int OSBDB::truncate(object_t oid, off_t size, Context *onsafe)
 {
+  dout(6) << "Context " << hex << onsafe << dec << endl;
+
   if (!mounted)
     {
       derr(1) << "not mounted!" << endl;
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -EINVAL;
     }
 
+  scoped_lock __lock(&lock);
   dout(2) << "truncate " << size << endl;
 
   if (size > 0xFFFFFFFF)
     {
       derr(1) << "object size too big!" << endl;
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -ENOSPC;
     }
 
@@ -431,6 +502,8 @@ int OSBDB::truncate(object_t oid, off_t size, Context *onsafe)
     {
       if (txn)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       dout(4) << "..returns -ENOENT" << endl;
       return -ENOENT;
     }
@@ -450,6 +523,8 @@ int OSBDB::truncate(object_t oid, off_t size, Context *onsafe)
         {
           if (txn)
             txn->abort();
+          if (onsafe != NULL)
+            CLEANUP(onsafe);
           derr(1) << ".updating object failed" << endl;
           return -EIO;
         }
@@ -460,6 +535,8 @@ int OSBDB::truncate(object_t oid, off_t size, Context *onsafe)
         {
           if (txn)
             txn->abort();
+          if (onsafe != NULL)
+            CLEANUP(onsafe);
           derr(1) << ".updating object info failed" << endl;
           return -EIO;
         }
@@ -474,6 +551,8 @@ int OSBDB::truncate(object_t oid, off_t size, Context *onsafe)
         {
           if (txn)
             txn->abort();
+          if (onsafe != NULL)
+            CLEANUP(onsafe);
           derr(1) << ".updating object info failed" << endl;
           return -EIO;
         }
@@ -488,6 +567,8 @@ int OSBDB::truncate(object_t oid, off_t size, Context *onsafe)
             {
               if (txn)
                 txn->abort();
+              if (onsafe != NULL)
+                CLEANUP(onsafe);
               derr(1) << ".updating object failed" << endl;
               return -EIO;
             }
@@ -503,6 +584,8 @@ int OSBDB::truncate(object_t oid, off_t size, Context *onsafe)
             {
               if (txn)
                 txn->abort();
+              if (onsafe != NULL)
+                CLEANUP(onsafe);
               derr(1) << ".getting old object failed" << endl;
               return -EIO;
             }
@@ -513,6 +596,8 @@ int OSBDB::truncate(object_t oid, off_t size, Context *onsafe)
             {
               if (txn)
                 txn->abort();
+              if (onsafe != NULL)
+                CLEANUP(onsafe);
               derr(1) << ".putting new object failed" << endl;
               return -EIO;
             }
@@ -521,6 +606,8 @@ int OSBDB::truncate(object_t oid, off_t size, Context *onsafe)
 
   if (txn)
     txn->commit (0);
+  if (onsafe != NULL)
+    COMMIT(onsafe);
 
   dout(4) << "..truncate OK" << endl;
   return 0;
@@ -537,6 +624,13 @@ int OSBDB::read(object_t oid, off_t offset, size_t len, bufferlist& bl)
   dout(2) << "read " << oid << " " << offset << " "
           << len << endl;
 
+  if (bl.length() < len)
+    {
+      int remain = len - bl.length();
+      bufferptr ptr (remain);
+      bl.push_back(ptr);
+    }
+
   DbTxn *txn = NULL;
   if (transactional)
     env->txn_begin (NULL, &txn, 0);
@@ -548,7 +642,7 @@ int OSBDB::read(object_t oid, off_t offset, size_t len, bufferlist& bl)
   ival.set_flags (DB_DBT_USERMEM);
   ival.set_ulen (sizeof(obj));
 
-  dout(3) << "  get " << _ikey << endl;
+  dout(3) << "..get " << _ikey << endl;
   int ret;
   if ((ret = db->get (txn, &ikey, &ival, 0)) != 0)
     {
@@ -558,20 +652,22 @@ int OSBDB::read(object_t oid, off_t offset, size_t len, bufferlist& bl)
       return -ENOENT;
     }
 
+  dout(3) << "..object has size " << obj.length << endl;
+
   if (offset == 0 && len >= obj.length)
     {
       len = obj.length;
-      dout(3) << "  doing full read of " << len << endl;
+      dout(3) << "..doing full read of " << len << endl;
       oid_t id;
       mkoid (id, oid);
       Dbt key (&id, sizeof (oid_t));
       Dbt value (bl.c_str(), len);
       value.set_ulen (len);
       value.set_flags (DB_DBT_USERMEM);
-      dout(3) << "  getting " << oid << endl;
+      dout(3) << "..getting " << oid << endl;
       if ((ret = db->get (txn, &key, &value, 0)) != 0)
         {
-          derr(1) << " get returned " << db_strerror (ret) << endl;
+          derr(1) << ".get returned " << db_strerror (ret) << endl;
           if (txn)
             txn->abort();
           return -EIO;
@@ -586,19 +682,22 @@ int OSBDB::read(object_t oid, off_t offset, size_t len, bufferlist& bl)
         }
       if (offset + len > obj.length)
         len = obj.length - (size_t) offset;
-      dout(3) << "  doing partial read of " << len << endl;
+      dout(3) << "..doing partial read of " << len << endl;
       oid_t id;
       mkoid (id, oid);
       Dbt key (&id, sizeof (oid));
-      Dbt value (bl.c_str(), len);
+      Dbt value;
+      char *data = bl.c_str();
+      dout(3) << ".bufferlist c_str returned " << ((void*) data) << endl;
+      value.set_data (data);
       value.set_doff ((size_t) offset);
       value.set_dlen (len);
       value.set_ulen (len);
       value.set_flags (DB_DBT_USERMEM | DB_DBT_PARTIAL);
-      dout(3) << "  getting " << oid << endl;
+      dout(3) << "..getting " << oid << endl;
       if ((ret = db->get (txn, &key, &value, 0)) != 0)
         {
-          derr(1) << "get returned " << db_strerror (ret) << endl;
+          derr(1) << ".get returned " << db_strerror (ret) << endl;
           if (txn)
             txn->abort();
           return -EIO;
@@ -614,18 +713,24 @@ int OSBDB::read(object_t oid, off_t offset, size_t len, bufferlist& bl)
 int OSBDB::write(object_t oid, off_t offset, size_t len,
                  bufferlist& bl, Context *onsafe)
 {
+  dout(6) << "Context " << hex << onsafe << dec << endl;
   if (!mounted)
     {
       derr(1) << "not mounted!" << endl;
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -EINVAL;
     }
 
+  scoped_lock __lock(&lock);
   dout(2) << "write " << oid << " " << offset << " "
           << len << endl;
 
   if (offset > 0xFFFFFFFFL || offset + len > 0xFFFFFFFFL)
     {
       derr(1) << "object too big" << endl;
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -ENOSPC;
     }
 
@@ -655,6 +760,8 @@ int OSBDB::write(object_t oid, off_t offset, size_t len,
           derr(1) << "..put returned " << db_strerror (ret) << endl;
           if (txn)
             txn->abort();
+          if (onsafe != NULL)
+            CLEANUP(onsafe);
           return -EIO;
         }
 
@@ -681,11 +788,15 @@ int OSBDB::write(object_t oid, off_t offset, size_t len,
           derr(1) << "..put returned " << db_strerror (ret) << endl;
           if (txn)
             txn->abort();
+          if (onsafe != NULL)
+            CLEANUP(onsafe);
           return -EIO;
         }
 
-      if (txn)
+      if (txn != NULL)
         txn->commit (0);
+      if (onsafe != NULL)
+        COMMIT(onsafe);
 
       dout(4) << "..write OK, returning " << len << endl;
       return len;
@@ -701,6 +812,8 @@ int OSBDB::write(object_t oid, off_t offset, size_t len,
               derr(1) << "  put returned " << db_strerror (ret) << endl;
               if (txn)
                 txn->abort();
+              if (onsafe != NULL)
+                CLEANUP(onsafe);
               return -EIO;
             }
         }
@@ -712,6 +825,8 @@ int OSBDB::write(object_t oid, off_t offset, size_t len,
         {
           if (txn)
             txn->abort();
+          if (onsafe != NULL)
+            CLEANUP(onsafe);
           derr(1) << "..writing object failed!" << endl;
           return -EIO;
         }
@@ -725,6 +840,8 @@ int OSBDB::write(object_t oid, off_t offset, size_t len,
             {
               if (txn)
                 txn->abort();
+              if (onsafe != NULL)
+                CLEANUP(onsafe);
               derr(1) << "..writing object info failed!" << endl;
               return -EIO;
             }
@@ -741,13 +858,17 @@ int OSBDB::write(object_t oid, off_t offset, size_t len,
         {
           if (txn)
             txn->abort();
+          if (onsafe != NULL)
+            CLEANUP(onsafe);
           derr(1) << "..writing object failed!" << endl;
           return -EIO;
         }
     }
 
-  if (txn)
+  if (txn != NULL)
     txn->commit (0);
+  if (onsafe != NULL)
+    COMMIT(onsafe);
 
   dout(4) << "..write OK, returning " << len << endl;
   return len;
@@ -861,12 +982,16 @@ int OSBDB::list_collections(list<coll_t>& ls)
 
 int OSBDB::create_collection(coll_t c, Context *onsafe)
 {
+  dout(6) << "Context " << hex << onsafe << dec << endl;
   if (!mounted)
     {
       derr(1) << "not mounted" << endl;
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -EINVAL;
     }
 
+  scoped_lock __lock(&lock);
   dout(2) << "create_collection " << hex << c << dec << endl;
 
   Dbt key (COLLECTIONS_KEY, 1);
@@ -897,10 +1022,12 @@ int OSBDB::create_collection(coll_t c, Context *onsafe)
   int ins = 0;
   if (scp->count > 0)
     ins = binary_search<coll_t> (scp->colls, scp->count, c);
-  if (scp->colls[ins] == c)
+  if (ins < scp->count && scp->colls[ins] == c)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << ".collection " << c << " already exists " << endl;
       return -EEXIST;
     }
@@ -936,6 +1063,8 @@ int OSBDB::create_collection(coll_t c, Context *onsafe)
       {
         if (txn != NULL)
           txn->abort();
+        if (onsafe != NULL)
+          CLEANUP(onsafe);
         derr(1) << ".writing new collections list failed" << endl;
         return -EIO;
       }
@@ -951,6 +1080,8 @@ int OSBDB::create_collection(coll_t c, Context *onsafe)
       {
         if (txn != NULL)
           txn->abort();
+        if (onsafe != NULL)
+          CLEANUP(onsafe);
         derr(1) << ".writing new collection failed" << endl;
         return -EIO;
       }
@@ -958,6 +1089,8 @@ int OSBDB::create_collection(coll_t c, Context *onsafe)
 
   if (txn != NULL)
     txn->commit (0);
+  if (onsafe != NULL)
+    COMMIT(onsafe);
 
   dout(4) << "..create_collection OK" << endl;
   return 0;
@@ -965,12 +1098,16 @@ int OSBDB::create_collection(coll_t c, Context *onsafe)
 
 int OSBDB::destroy_collection(coll_t c, Context *onsafe)
 {
+  dout(6) << "Context " << hex << onsafe << dec << endl;
   if (!mounted)
     {
       derr(1) << "not mounted" << endl;
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -EINVAL;
     }
 
+  scoped_lock __lock(&lock);
   dout(2) << "destroy_collection " << hex << c << dec << endl;
 
   Dbt key (COLLECTIONS_KEY, 1);
@@ -985,6 +1122,8 @@ int OSBDB::destroy_collection(coll_t c, Context *onsafe)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << ".collection list doesn't exist" << endl;
       return -ENOENT; // XXX
     }
@@ -995,15 +1134,19 @@ int OSBDB::destroy_collection(coll_t c, Context *onsafe)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << ".collection " << c << " not listed" << endl;
       return -ENOENT;
     }
   uint32_t ins = binary_search<coll_t> (scp->colls, scp->count, c);
   dout(4) << "..insertion point is " << ins << endl;
-  if (scp->colls[ins] != c)
+  if (ins >= scp->count || scp->colls[ins] != c)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << ".collection " << c << " not listed" << endl;
       return -ENOENT;
     }
@@ -1027,6 +1170,8 @@ int OSBDB::destroy_collection(coll_t c, Context *onsafe)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << ".putting modified collection list failed" << endl;
       return -EIO;
     }
@@ -1037,12 +1182,16 @@ int OSBDB::destroy_collection(coll_t c, Context *onsafe)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << ".deleting collection failed" << endl;
       return -EIO;
     }
 
   if (txn != NULL)
     txn->commit (0);
+  if (onsafe != NULL)
+    COMMIT(onsafe);
   dout(4) << "..destroy_collection OK" << endl;
   return 0;
 }
@@ -1111,12 +1260,16 @@ int OSBDB::collection_stat(coll_t c, struct stat *st)
 
 int OSBDB::collection_add(coll_t c, object_t o, Context *onsafe)
 {
+  dout(6) << "Context " << hex << onsafe << dec << endl;
   if (!mounted)
     {
       dout(2) << "not mounted" << endl;
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -EINVAL;
     }
 
+  scoped_lock __lock(&lock);
   dout(2) << "collection_add " << hex << c << dec << " " << o << endl;
 
   Dbt key (&c, sizeof (coll_t));
@@ -1131,6 +1284,8 @@ int OSBDB::collection_add(coll_t c, object_t o, Context *onsafe)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << "failed to find collection" << endl;
       return -ENOENT;
     }
@@ -1145,10 +1300,12 @@ int OSBDB::collection_add(coll_t c, object_t o, Context *onsafe)
     {
       ins = binary_search<object_t> (scp->objects, scp->count, o);
       // Already there?
-      if (scp->objects[ins] == o)
+      if (ins < scp->count && scp->objects[ins] == o)
         {
           if (txn != NULL)
             txn->abort();
+          if (onsafe != NULL)
+            CLEANUP(onsafe);
           derr(1) << "collection already has object" << endl;
           return -EEXIST;
         }
@@ -1176,24 +1333,32 @@ int OSBDB::collection_add(coll_t c, object_t o, Context *onsafe)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << "..putting modified collection failed" << endl;
       return -EIO;
     }
 
   if (txn != NULL)
     txn->commit (0);
+  if (onsafe != NULL)
+    COMMIT(onsafe);
   dout(4) << "..collection add OK" << endl;
   return 0;
 }
 
 int OSBDB::collection_remove(coll_t c, object_t o, Context *onsafe)
 {
+  dout(6) << "Context " << hex << onsafe << dec << endl;
   if (!mounted)
     {
       derr(1) << "not mounted" << endl;
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -EINVAL;
     }
 
+  scoped_lock __lock(&lock);
   dout(2) << "collection_remove " << hex << c << dec << " " << o << endl;
 
   Dbt key (&c, sizeof (coll_t));
@@ -1208,6 +1373,8 @@ int OSBDB::collection_remove(coll_t c, object_t o, Context *onsafe)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       dout(1) << "..collection doesn't exist" << endl;
       return -ENOENT;
     }
@@ -1220,15 +1387,19 @@ int OSBDB::collection_remove(coll_t c, object_t o, Context *onsafe)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       dout(1) << "..collection is empty" << endl;
       return -ENOENT;
     }
   uint32_t ins = binary_search<object_t> (scp->objects, scp->count, o);
   dout(4) << "..insertion point is " << ins << endl;
-  if (scp->objects[ins] != o)
+  if (ins >= scp->count || scp->objects[ins] != o)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       dout(1) << "..object not in collection" << endl;
       return -ENOENT;
     }
@@ -1248,12 +1419,16 @@ int OSBDB::collection_remove(coll_t c, object_t o, Context *onsafe)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << "..putting modified collection failed" << endl;
       return -EIO;
     }
 
   if (txn != NULL)
     txn->commit (0);
+  if (onsafe != NULL)
+    COMMIT(onsafe);
   dout(4) << "..collection remove OK" << endl;
   return 0;
 }
@@ -1296,11 +1471,23 @@ int OSBDB::_setattr(object_t oid, const char *name,
                     const void *value, size_t size, Context *onsafe,
                     DbTxn *txn)
 {
+  dout(6) << "Context " << hex << onsafe << dec << endl;
   if (!mounted)
-    return -EINVAL;
+    {
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
+      return -EINVAL;
+    }
 
   if (strlen (name) >= OSBDB_MAX_ATTR_LEN)
-    return -ENAMETOOLONG;
+    {
+      derr(1) << "name too long: " << name << endl;
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
+      return -ENAMETOOLONG;
+    }
+
+  scoped_lock __lock(&lock);
 
   // Add name to attribute list, if needed.
   attrs_id aids = new_attrs_id (oid);
@@ -1333,7 +1520,8 @@ int OSBDB::_setattr(object_t oid, const char *name,
   if (sap->count > 0)
     ins = binary_search<attr_name> (sap->names, sap->count, _name);
   dout(3) << "..insertion point is " << ins << endl;
-  if (sap->count == 0 || strcmp (sap->names[ins].name, name) != 0)
+  if (sap->count == 0 ||
+      (ins >= sap->count || strcmp (sap->names[ins].name, name) != 0))
     {
       sz += sizeof (attr_name);
       dout(3) << "..realloc " << ((void *) sap) << " to "
@@ -1361,6 +1549,8 @@ int OSBDB::_setattr(object_t oid, const char *name,
       if (db->put (txn, &attrs_key, &newAttrs_val, 0) != 0)
         {
           derr(1) << ".writing attributes list failed" << endl;
+          if (onsafe != NULL)
+            CLEANUP(onsafe);
           return -EIO;
         }
     }
@@ -1379,10 +1569,14 @@ int OSBDB::_setattr(object_t oid, const char *name,
   if (db->put (txn, &attr_key, &attr_val, 0) != 0)
     {
       derr(1) << ".writing attribute key failed" << endl;
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -EIO;
     }
 
   dout(4) << "..setattr OK" << endl;
+  if (onsafe != NULL)
+    COMMIT(onsafe);
   return 0;
 }
 
@@ -1390,8 +1584,13 @@ int OSBDB::setattr(object_t oid, const char *name,
                    const void *value, size_t size,
                    Context *onsafe)
 {
+  dout(6) << "Context " << hex << onsafe << dec << endl;
   if (!mounted)
-    return -EINVAL;
+    {
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
+      return -EINVAL;
+    }
 
   DbTxn *txn = NULL;
   if (transactional)
@@ -1416,8 +1615,13 @@ int OSBDB::setattr(object_t oid, const char *name,
 int OSBDB::setattrs(object_t oid, map<string,bufferptr>& aset,
                     Context *onsafe)
 {
+  dout(6) << "Context " << hex << onsafe << dec << endl;
   if (!mounted)
-    return -EINVAL;
+    {
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
+      return -EINVAL;
+    }
 
   DbTxn *txn = NULL;
 
@@ -1459,9 +1663,10 @@ int OSBDB::_getattr (object_t oid, const char *name, void *value, size_t size)
   val.set_dlen (size);
   val.set_flags (DB_DBT_USERMEM | DB_DBT_PARTIAL);
 
-  if (db->get (NULL, &key, &val, 0) != 0)
+  int ret;
+  if ((ret = db->get (NULL, &key, &val, 0)) != 0)
     {
-      derr(1) << ".getting value failed" << endl; 
+      derr(1) << ".getting value failed: " << db_strerror (ret) << endl; 
       return -ENOENT;
     }
 
@@ -1496,9 +1701,15 @@ int OSBDB::getattrs(object_t oid, map<string,bufferptr>& aset)
 
 int OSBDB::rmattr(object_t oid, const char *name, Context *onsafe)
 {
+  dout(6) << "Context " << hex << onsafe << dec << endl;
   if (!mounted)
-    return -EINVAL;
+    {
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
+      return -EINVAL;
+    }
 
+  scoped_lock __lock(&lock);
   dout(2) << "rmattr " << oid << " " << name << endl;
 
   attrs_id aids = new_attrs_id (oid);
@@ -1515,6 +1726,8 @@ int OSBDB::rmattr(object_t oid, const char *name, Context *onsafe)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -ENOENT;
     }
 
@@ -1527,6 +1740,8 @@ int OSBDB::rmattr(object_t oid, const char *name, Context *onsafe)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << ".empty attribute list" << endl;
       return -ENOENT;
     }
@@ -1536,10 +1751,12 @@ int OSBDB::rmattr(object_t oid, const char *name, Context *onsafe)
   strncpy (_name.name, name, OSBDB_MAX_ATTR_LEN);
   int ins = binary_search<attr_name> (sap->names, sap->count, _name);
   dout(4) << "..insertion point is " << ins << endl;
-  if (strcmp (sap->names[ins].name, name) != 0)
+  if (ins >= sap->count || strcmp (sap->names[ins].name, name) != 0)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << ".attribute not found in list" << endl;
       return -ENOENT;
     }
@@ -1561,6 +1778,8 @@ int OSBDB::rmattr(object_t oid, const char *name, Context *onsafe)
       derr(1) << "put stored_attrs " << db_strerror (ret) << endl;
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -EIO;
     }
 
@@ -1572,11 +1791,15 @@ int OSBDB::rmattr(object_t oid, const char *name, Context *onsafe)
       derr(1) << "deleting " << aid << ": " << db_strerror(ret) << endl;
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -EIO;
     }
 
   if (txn != NULL)
     txn->commit (0);
+  if (onsafe != NULL)
+    COMMIT(onsafe);
   dout(4) << "..rmattr OK" << endl;
   return 0;
 }
@@ -1626,14 +1849,22 @@ int OSBDB::collection_setattr(coll_t cid, const char *name,
                               const void *value, size_t size,
                               Context *onsafe)
 {
+  dout(6) << "Context " << hex << onsafe << dec << endl;
   if (!mounted)
-    return -EINVAL;
+    {
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
+      return -EINVAL;
+    }
 
+  scoped_lock __lock(&lock);
   dout(2) << "collection_setattr " << hex << cid << dec << " " << name
           << " (" << size << " bytes)" << endl;
   if (strlen (name) >= OSBDB_MAX_ATTR_LEN)
     {
       derr(1) << "name too long" << endl;
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -ENAMETOOLONG;
     }
 
@@ -1672,7 +1903,7 @@ int OSBDB::collection_setattr(coll_t cid, const char *name,
   if (sap->count > 0)
     ins = binary_search<attr_name> (sap->names, sap->count, _name);
   dout(3) << "  insertion point is " << ins << endl;
-  if (sap->count == 0 || strcmp (sap->names[ins].name, name) != 0)
+  if (ins >= sap->count || strcmp (sap->names[ins].name, name) != 0)
     {
       sz += sizeof (attr_name);
       dout(3) << "  realloc " << hex << ((void *) sap) << " to "
@@ -1701,6 +1932,8 @@ int OSBDB::collection_setattr(coll_t cid, const char *name,
         {
           if (txn != NULL)
             txn->abort();
+          if (onsafe != NULL)
+            CLEANUP(onsafe);
           derr(1) << ".putting new attributes failed" << endl;
           return -EIO;
         }
@@ -1721,12 +1954,16 @@ int OSBDB::collection_setattr(coll_t cid, const char *name,
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << ".putting attribute failed" << endl;
       return -EIO;
     }
 
   if (txn != NULL)
     txn->commit (0);
+  if (onsafe != NULL)
+    COMMIT(onsafe);
 
   dout(4) << "..collection setattr OK" << endl;
   return 0;
@@ -1735,9 +1972,15 @@ int OSBDB::collection_setattr(coll_t cid, const char *name,
 int OSBDB::collection_rmattr(coll_t cid, const char *name,
                              Context *onsafe)
 {
+  dout(6) << "Context " << hex << onsafe << dec << endl;
   if (!mounted)
-    return -EINVAL;
+    {
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
+      return -EINVAL;
+    }
 
+  scoped_lock __lock(&lock);
   dout(2) << "collection_rmattr " << hex << cid << dec
           << " " << name << endl;
 
@@ -1754,6 +1997,8 @@ int OSBDB::collection_rmattr(coll_t cid, const char *name,
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << ".no attributes list" << endl;
       return -ENOENT;
     }
@@ -1766,6 +2011,8 @@ int OSBDB::collection_rmattr(coll_t cid, const char *name,
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << ".empty attributes list" << endl;
       return -ENOENT;
     }
@@ -1774,10 +2021,12 @@ int OSBDB::collection_rmattr(coll_t cid, const char *name,
   memset(&_name, 0, sizeof (_name));
   strncpy (_name.name, name, OSBDB_MAX_ATTR_LEN);
   int ins = binary_search<attr_name> (sap->names, sap->count, _name);
-  if (strcmp (sap->names[ins].name, name) != 0)
+  if (ins >= sap->count || strcmp (sap->names[ins].name, name) != 0)
     {
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       derr(1) << ".attribute not listed" << endl;
       return -ENOENT;
     }
@@ -1799,6 +2048,8 @@ int OSBDB::collection_rmattr(coll_t cid, const char *name,
       derr(1) << "put stored_attrs " << db_strerror (ret) << endl;
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -EIO;
     }
 
@@ -1810,11 +2061,15 @@ int OSBDB::collection_rmattr(coll_t cid, const char *name,
       derr(1) << "deleting " << aid << ": " << db_strerror(ret) << endl;
       if (txn != NULL)
         txn->abort();
+      if (onsafe != NULL)
+        CLEANUP(onsafe);
       return -EIO;
     }
 
   if (txn != NULL)
     txn->commit (0);
+  if (onsafe != NULL)
+    COMMIT(onsafe);
 
   dout(4) << "..collection rmattr OK" << endl;
   return 0;
@@ -1893,7 +2148,11 @@ void OSBDB::sync (Context *onsync)
     return;
 
   sync();
-  // huh?
+
+  if (onsync != NULL)
+    {
+      g_timer.add_event_after(0.1, onsync);
+    }
 }
 
 void OSBDB::sync()
@@ -1901,5 +2160,10 @@ void OSBDB::sync()
   if (!mounted)
     return;
 
+  if (transactional)
+    {
+      env->log_flush (NULL);
+      env->lsn_reset (device.c_str(), 0);
+    }
   db->sync(0);
 }
index 61cf4b16c48b54033bdd65961001c90441cacf5e..f75bfc2c168ac802a6c636ff3c54e3be9806d0cd 100644 (file)
@@ -389,6 +389,7 @@ public:
 class OSBDB : public ObjectStore
 {
  private:
+  Mutex lock;
   DbEnv *env;
   Db *db;
   string device;
@@ -400,7 +401,7 @@ class OSBDB : public ObjectStore
  public:
 
   OSBDB(const char *dev) throw(OSBDBException)
-    : env(0), db (0), device (dev), mounted(false), opened(false),
+    : lock(true), env(0), db (0), device (dev), mounted(false), opened(false),
       transactional(g_conf.bdbstore_transactional)
   {
   }
@@ -475,4 +476,5 @@ private:
   int _setattr(object_t oid, const char *name, const void *value,
                size_t size, Context *onsync, DbTxn *txn);
   int _getattr(object_t oid, const char *name, void *value, size_t size);
+  DbEnv *getenv();
 };
index 058692fab3fc08cd5cf4de1f34b742e3056fa33f..d2355cb4d32ff250e17430f76e3b873ea5fdd550 100644 (file)
@@ -67,8 +67,8 @@
 
 #include "config.h"
 #undef dout
-#define  dout(l)    if (l<=g_conf.debug || l<=g_conf.debug_osd) cout << g_clock.now() << " osd" << whoami << " " << (osdmap ? osdmap->get_epoch():0) << " "
-#define  derr(l)    if (l<=g_conf.debug || l<=g_conf.debug_osd) cerr << g_clock.now() << " osd" << whoami << " " << (osdmap ? osdmap->get_epoch():0) << " "
+#define  dout(l)    if (l<=g_conf.debug || l<=g_conf.debug_osd) cout << dbeginl << g_clock.now() << " osd" << whoami << " " << (osdmap ? osdmap->get_epoch():0) << " "
+#define  derr(l)    if (l<=g_conf.debug || l<=g_conf.debug_osd) cerr << dbeginl << g_clock.now() << " osd" << whoami << " " << (osdmap ? osdmap->get_epoch():0) << " "
 
 char *osd_base_path = "./osddata";
 char *ebofs_base_path = "./dev";
@@ -89,14 +89,14 @@ public:
 
 void OSD::force_remount()
 {
-  dout(0) << "forcing remount" << endl;
+  dout(0) << "forcing remount" << dendl;
   osd_lock.Lock();
   {
     store->umount();
     store->mount();
   }
   osd_lock.Unlock();
-  dout(0) << "finished remount" << endl;
+  dout(0) << "finished remount" << dendl;
 }
 // </hack>
 
@@ -189,7 +189,7 @@ int OSD::init()
   {
     // mkfs?
     if (g_conf.osd_mkfs) {
-      dout(2) << "mkfs" << endl;
+      dout(2) << "mkfs" << dendl;
       store->mkfs();
 
       // make up a superblock
@@ -198,14 +198,14 @@ int OSD::init()
     }
     
     // mount.
-    dout(2) << "mounting " << dev_path << endl;
+    dout(2) << "mounting " << dev_path << dendl;
     int r = store->mount();
     assert(r>=0);
 
     if (g_conf.osd_mkfs) {
       // age?
       if (g_conf.osd_age_time != 0) {
-        dout(2) << "age" << endl;
+        dout(2) << "age" << dendl;
         Ager ager(store);
         if (g_conf.osd_age_time < 0) 
           ager.load_freelist();
@@ -218,7 +218,7 @@ int OSD::init()
       }
     }
     else {
-      dout(2) << "boot" << endl;
+      dout(2) << "boot" << dendl;
       
       // read superblock
       read_superblock();
@@ -226,7 +226,7 @@ int OSD::init()
       // load up pgs (as they previously existed)
       load_pgs();
 
-      dout(2) << "superblock: i am osd" << superblock.whoami << endl;
+      dout(2) << "superblock: i am osd" << superblock.whoami << dendl;
       assert(whoami == superblock.whoami);
     }
 
@@ -281,14 +281,14 @@ int OSD::init()
   }
   osd_lock.Unlock();
 
-  //dout(0) << "osd_rep " << g_conf.osd_rep << endl;
+  //dout(0) << "osd_rep " << g_conf.osd_rep << dendl;
 
   return 0;
 }
 
 int OSD::shutdown()
 {
-  dout(1) << "shutdown" << endl;
+  dout(1) << "shutdown" << dendl;
 
   state = STATE_STOPPING;
 
@@ -325,7 +325,7 @@ int OSD::shutdown()
 
 void OSD::write_superblock(ObjectStore::Transaction& t)
 {
-  dout(10) << "write_superblock " << superblock << endl;
+  dout(10) << "write_superblock " << superblock << dendl;
 
   bufferlist bl;
   bl.append((char*)&superblock, sizeof(superblock));
@@ -337,13 +337,13 @@ int OSD::read_superblock()
   bufferlist bl;
   int r = store->read(SUPERBLOCK_OBJECT, 0, sizeof(superblock), bl);
   if (bl.length() != sizeof(superblock)) {
-    dout(10) << "read_superblock failed, r = " << r << ", i got " << bl.length() << " bytes, not " << sizeof(superblock) << endl;
+    dout(10) << "read_superblock failed, r = " << r << ", i got " << bl.length() << " bytes, not " << sizeof(superblock) << dendl;
     return -1;
   }
 
   bl.copy(0, sizeof(superblock), (char*)&superblock);
   
-  dout(10) << "read_superblock " << superblock << endl;
+  dout(10) << "read_superblock " << superblock << dendl;
 
   // load up "current" osdmap
   assert(!osdmap);
@@ -373,8 +373,8 @@ PG *OSD::_lock_pg(pg_t pgid)
 
   if (pg_lock.count(pgid)) {
     Cond c;
-    dout(15) << "lock_pg " << pgid << " waiting as " << &c << endl;
-    //cerr << "lock_pg " << pgid << " waiting as " << &c << endl;
+    dout(15) << "lock_pg " << pgid << " waiting as " << &c << dendl;
+    //cerr << "lock_pg " << pgid << " waiting as " << &c << dendl;
 
     list<Cond*>& ls = pg_lock_waiters[pgid];   // this is commit, right?
     ls.push_back(&c);
@@ -389,7 +389,7 @@ PG *OSD::_lock_pg(pg_t pgid)
       pg_lock_waiters.erase(pgid);
   }
 
-  dout(15) << "lock_pg " << pgid << endl;
+  dout(15) << "lock_pg " << pgid << dendl;
   pg_lock.insert(pgid);
 
   return pg_map[pgid];  
@@ -412,17 +412,17 @@ void OSD::_unlock_pg(pg_t pgid)
     // someone is in line
     Cond *c = pg_lock_waiters[pgid].front();
     assert(c);
-    dout(15) << "unlock_pg " << pgid << " waking up next guy " << c << endl;
+    dout(15) << "unlock_pg " << pgid << " waking up next guy " << c << dendl;
     c->Signal();
   } else {
     // nobody waiting
-    dout(15) << "unlock_pg " << pgid << endl;
+    dout(15) << "unlock_pg " << pgid << dendl;
   }
 }
 
 void OSD::_remove_pg(pg_t pgid) 
 {
-  dout(10) << "_remove_pg " << pgid << endl;
+  dout(10) << "_remove_pg " << pgid << dendl;
 
   // remove from store
   list<object_t> olist;
@@ -496,7 +496,7 @@ void OSD::heartbeat()
   dout(5) << "heartbeat " << now 
          << ": ops " << hb_stat_ops
          << ", avg qlen " << avg_qlen
-         << endl;
+         << dendl;
   
   // reset until next time around
   hb_stat_ops = 0;
@@ -566,7 +566,7 @@ bool OSD::_share_map_incoming(const entity_inst_t& inst, epoch_t epoch)
   // does client have old map?
   if (inst.name.is_client()) {
     if (epoch < osdmap->get_epoch()) {
-      dout(10) << inst.name << " has old map " << epoch << " < " << osdmap->get_epoch() << endl;
+      dout(10) << inst.name << " has old map " << epoch << " < " << osdmap->get_epoch() << dendl;
       send_incremental_map(epoch, inst, true);
       shared = true;
     }
@@ -580,7 +580,7 @@ bool OSD::_share_map_incoming(const entity_inst_t& inst, epoch_t epoch)
     
     // older?
     if (peer_map_epoch[inst.name] < osdmap->get_epoch()) {
-      dout(10) << inst.name << " has old map " << epoch << " < " << osdmap->get_epoch() << endl;
+      dout(10) << inst.name << " has old map " << epoch << " < " << osdmap->get_epoch() << dendl;
       send_incremental_map(epoch, inst, true);
       peer_map_epoch[inst.name] = osdmap->get_epoch();  // so we don't send it again.
       shared = true;
@@ -622,7 +622,7 @@ void OSD::dispatch(Message *m)
 
     // -- don't need lock -- 
   case MSG_PING:
-    dout(10) << "ping from " << m->get_source() << endl;
+    dout(10) << "ping from " << m->get_source() << dendl;
     delete m;
     break;
 
@@ -655,14 +655,14 @@ void OSD::dispatch(Message *m)
     {
       // no map?  starting up?
       if (!osdmap) {
-        dout(7) << "no OSDMap, not booted" << endl;
+        dout(7) << "no OSDMap, not booted" << dendl;
         waiting_for_osdmap.push_back(m);
         break;
       }
       
       // down?
       if (osdmap->is_down(whoami)) {
-        dout(7) << "i am marked down, dropping " << *m << endl;
+        dout(7) << "i am marked down, dropping " << *m << dendl;
         delete m;
         break;
       }
@@ -702,7 +702,7 @@ void OSD::dispatch(Message *m)
         
         
       default:
-        dout(1) << " got unknown message " << m->get_type() << endl;
+        dout(1) << " got unknown message " << m->get_type() << dendl;
         assert(0);
       }
     }
@@ -732,7 +732,7 @@ void OSD::ms_handle_failure(Message *m, const entity_inst_t& inst)
   entity_name_t dest = inst.name;
 
   if (g_conf.ms_die_on_failure) {
-    dout(0) << "ms_handle_failure " << inst << " on " << *m << endl;
+    dout(0) << "ms_handle_failure " << inst << " on " << *m << dendl;
     exit(0);
   }
 
@@ -742,7 +742,7 @@ void OSD::ms_handle_failure(Message *m, const entity_inst_t& inst)
     dout(0) << "ms_handle_failure " << inst 
             << ", dropping and reporting to mon" << mon 
            << " " << *m
-            << endl;
+            << dendl;
     messenger->send_message(new MOSDFailure(inst, osdmap->get_epoch()),
                             monmap->get_inst(mon));
     delete m;
@@ -752,13 +752,13 @@ void OSD::ms_handle_failure(Message *m, const entity_inst_t& inst)
     dout(0) << "ms_handle_failure " << inst 
             << ", resending to mon" << mon 
            << " " << *m
-            << endl;
+            << dendl;
     messenger->send_message(m, monmap->get_inst(mon));
   }
   else {
     // client?
     dout(0) << "ms_handle_failure " << inst 
-            << ", dropping " << *m << endl;
+            << ", dropping " << *m << dendl;
     delete m;
   }
 }
@@ -768,7 +768,7 @@ void OSD::ms_handle_failure(Message *m, const entity_inst_t& inst)
 
 void OSD::handle_osd_ping(MOSDPing *m)
 {
-  dout(20) << "osdping from " << m->get_source() << endl;
+  dout(20) << "osdping from " << m->get_source() << dendl;
   _share_map_incoming(m->get_source_inst(), ((MOSDPing*)m)->map_epoch);
   
   int from = m->get_source().num();
@@ -815,12 +815,12 @@ void OSD::handle_osd_map(MOSDMap *m)
     dout(3) << "handle_osd_map epochs [" 
             << m->get_first() << "," << m->get_last() 
             << "], i have " << osdmap->get_epoch()
-            << endl;
+            << dendl;
   } else {
     dout(3) << "handle_osd_map epochs [" 
             << m->get_first() << "," << m->get_last() 
             << "], i have none"
-            << endl;
+            << dendl;
     osdmap = new OSDMap;
     boot_epoch = m->get_last(); // hrm...?
   }
@@ -833,15 +833,15 @@ void OSD::handle_osd_map(MOSDMap *m)
        p++) {
     object_t oid = get_osdmap_object_name(p->first);
     if (store->exists(oid)) {
-      dout(10) << "handle_osd_map already had full map epoch " << p->first << endl;
+      dout(10) << "handle_osd_map already had full map epoch " << p->first << dendl;
       logger->inc("mapfdup");
       bufferlist bl;
       get_map_bl(p->first, bl);
-      dout(10) << " .. it is " << bl.length() << " bytes" << endl;
+      dout(10) << " .. it is " << bl.length() << " bytes" << dendl;
       continue;
     }
 
-    dout(10) << "handle_osd_map got full map epoch " << p->first << endl;
+    dout(10) << "handle_osd_map got full map epoch " << p->first << dendl;
     //t.write(oid, 0, p->second.length(), p->second);
     store->write(oid, 0, p->second.length(), p->second, 0);
 
@@ -858,15 +858,15 @@ void OSD::handle_osd_map(MOSDMap *m)
        p++) {
     object_t oid = get_inc_osdmap_object_name(p->first);
     if (store->exists(oid)) {
-      dout(10) << "handle_osd_map already had incremental map epoch " << p->first << endl;
+      dout(10) << "handle_osd_map already had incremental map epoch " << p->first << dendl;
       logger->inc("mapidup");
       bufferlist bl;
       get_inc_map_bl(p->first, bl);
-      dout(10) << " .. it is " << bl.length() << " bytes" << endl;
+      dout(10) << " .. it is " << bl.length() << " bytes" << dendl;
       continue;
     }
 
-    dout(10) << "handle_osd_map got incremental map epoch " << p->first << endl;
+    dout(10) << "handle_osd_map got incremental map epoch " << p->first << dendl;
     //t.write(oid, 0, p->second.length(), p->second);
     store->write(oid, 0, p->second.length(), p->second, 0);
 
@@ -890,7 +890,7 @@ void OSD::handle_osd_map(MOSDMap *m)
     bufferlist bl;
     if (m->incremental_maps.count(cur+1) ||
         store->exists(get_inc_osdmap_object_name(cur+1))) {
-      dout(10) << "handle_osd_map decoding inc map epoch " << cur+1 << endl;
+      dout(10) << "handle_osd_map decoding inc map epoch " << cur+1 << dendl;
       
       bufferlist bl;
       if (m->incremental_maps.count(cur+1))
@@ -930,7 +930,7 @@ void OSD::handle_osd_map(MOSDMap *m)
             for (map<tid_t,PG::RepOpGather*>::iterator p = pg->repop_gather.begin();
                  p != pg->repop_gather.end();
                  p++) {
-              //dout(-1) << "checking repop tid " << p->first << endl;
+              //dout(-1) << "checking repop tid " << p->first << dendl;
               if (p->second->waitfor_ack.count(osd) ||
                   p->second->waitfor_commit.count(osd)) 
                 ls.push_back(p->second);
@@ -952,7 +952,7 @@ void OSD::handle_osd_map(MOSDMap *m)
     }
     else if (m->maps.count(cur+1) ||
              store->exists(get_osdmap_object_name(cur+1))) {
-      dout(10) << "handle_osd_map decoding full map epoch " << cur+1 << endl;
+      dout(10) << "handle_osd_map decoding full map epoch " << cur+1 << dendl;
       bufferlist bl;
       if (m->maps.count(cur+1))
         bl = m->maps[cur+1];
@@ -963,7 +963,7 @@ void OSD::handle_osd_map(MOSDMap *m)
       // FIXME BUG: need to notify messenger of ups/downs!!
     }
     else {
-      dout(10) << "handle_osd_map missing epoch " << cur+1 << endl;
+      dout(10) << "handle_osd_map missing epoch " << cur+1 << dendl;
       int mon = monmap->pick_mon();
       messenger->send_message(new MOSDGetMap(cur), monmap->get_inst(mon));
       break;
@@ -1011,15 +1011,15 @@ void OSD::advance_map(ObjectStore::Transaction& t)
 {
   dout(7) << "advance_map epoch " << osdmap->get_epoch() 
           << "  " << pg_map.size() << " pgs"
-          << endl;
+          << dendl;
   
   if (osdmap->is_mkfs()) {
     ps_t maxps = 1ULL << osdmap->get_pg_bits();
     ps_t maxlps = 1ULL << osdmap->get_localized_pg_bits();
-    dout(1) << "mkfs on " << osdmap->get_pg_bits() << " bits, " << maxps << " pgs" << endl;
+    dout(1) << "mkfs on " << osdmap->get_pg_bits() << " bits, " << maxps << " pgs" << dendl;
     assert(osdmap->get_epoch() == 1);
 
-    //cerr << "osdmap " << osdmap->get_ctime() << " logger start " << logger->get_start() << endl;
+    //cerr << "osdmap " << osdmap->get_ctime() << " logger start " << logger->get_start() << dendl;
     logger->set_start( osdmap->get_ctime() );
 
     assert(g_conf.osd_mkfs);  // make sure we did a mkfs!
@@ -1045,7 +1045,7 @@ void OSD::advance_map(ObjectStore::Transaction& t)
            pg->info.history.same_acker_since = osdmap->get_epoch();
        pg->activate(t);
        
-       dout(7) << "created " << *pg << endl;
+       dout(7) << "created " << *pg << dendl;
       }
 
       for (ps_t ps = 0; ps < maxlps; ++ps) {
@@ -1065,11 +1065,11 @@ void OSD::advance_map(ObjectStore::Transaction& t)
          pg->info.history.same_since = osdmap->get_epoch();
        pg->activate(t);
        
-       dout(7) << "created " << *pg << endl;
+       dout(7) << "created " << *pg << dendl;
       }
     }
 
-    dout(1) << "mkfs done, created " << pg_map.size() << " pgs" << endl;
+    dout(1) << "mkfs done, created " << pg_map.size() << " pgs" << dendl;
 
   } else {
     // scan existing pg's
@@ -1181,13 +1181,13 @@ void OSD::advance_map(ObjectStore::Transaction& t)
 
           if (nrep == 0) {
             pg->state_set(PG::STATE_CRASHED);
-            dout(1) << *pg << " is crashed" << endl;
+            dout(1) << *pg << " is crashed" << dendl;
           }
         }
         
         // my role changed.
         dout(10) << *pg << " " << oldacting << " -> " << pg->acting 
-                 << ", role " << oldrole << " -> " << role << endl; 
+                 << ", role " << oldrole << " -> " << role << dendl; 
         
       } else {
         // no role change.
@@ -1199,7 +1199,7 @@ void OSD::advance_map(ObjectStore::Transaction& t)
           dout(10) << *pg << " " << oldacting << " -> " << pg->acting 
                    << ", acting primary " 
                    << oldprimary << " -> " << pg->get_primary() 
-                   << endl;
+                   << dendl;
         } else {
           // primary is the same.
           if (role == 0) {
@@ -1208,7 +1208,7 @@ void OSD::advance_map(ObjectStore::Transaction& t)
             pg->state_clear(PG::STATE_REPLAY);
 
             dout(10) << *pg << " " << oldacting << " -> " << pg->acting
-                     << ", replicas changed" << endl;
+                     << ", replicas changed" << dendl;
           }
         }
       }
@@ -1221,7 +1221,7 @@ void OSD::advance_map(ObjectStore::Transaction& t)
 
 void OSD::activate_map(ObjectStore::Transaction& t)
 {
-  dout(7) << "activate_map version " << osdmap->get_epoch() << endl;
+  dout(7) << "activate_map version " << osdmap->get_epoch() << dendl;
 
   map< int, list<PG::Info> >  notify_list;  // primary -> list
   map< int, map<pg_t,PG::Query> > query_map;    // peer -> PG -> get_summary_since
@@ -1266,7 +1266,7 @@ void OSD::activate_map(ObjectStore::Transaction& t)
 void OSD::send_incremental_map(epoch_t since, const entity_inst_t& inst, bool full)
 {
   dout(10) << "send_incremental_map " << since << " -> " << osdmap->get_epoch()
-           << " to " << inst << endl;
+           << " to " << inst << dendl;
   
   MOSDMap *m = new MOSDMap;
   
@@ -1306,7 +1306,7 @@ void OSD::get_map(epoch_t epoch, OSDMap &m)
   for (e = epoch; e > 0; e--) {
     bufferlist bl;
     if (get_map_bl(e, bl)) {
-      //dout(10) << "get_map " << epoch << " full " << e << endl;
+      //dout(10) << "get_map " << epoch << " full " << e << dendl;
       m.decode(bl);
       break;
     } else {
@@ -1320,7 +1320,7 @@ void OSD::get_map(epoch_t epoch, OSDMap &m)
 
   // apply incrementals
   for (e++; e <= epoch; e++) {
-    //dout(10) << "get_map " << epoch << " inc " << e << endl;
+    //dout(10) << "get_map " << epoch << " inc " << e << dendl;
     m.apply_incremental( incs.front() );
     incs.pop_front();
   }
@@ -1345,14 +1345,14 @@ bool OSD::require_current_map(Message *m, epoch_t ep)
 {
   // older map?
   if (ep < osdmap->get_epoch()) {
-    dout(7) << "require_current_map epoch " << ep << " < " << osdmap->get_epoch() << endl;
+    dout(7) << "require_current_map epoch " << ep << " < " << osdmap->get_epoch() << dendl;
     delete m;   // discard and ignore.
     return false;
   }
 
   // newer map?
   if (ep > osdmap->get_epoch()) {
-    dout(7) << "require_current_map epoch " << ep << " > " << osdmap->get_epoch() << endl;
+    dout(7) << "require_current_map epoch " << ep << " > " << osdmap->get_epoch() << dendl;
     wait_for_new_map(m);
     return false;
   }
@@ -1368,17 +1368,17 @@ bool OSD::require_current_map(Message *m, epoch_t ep)
  */
 bool OSD::require_same_or_newer_map(Message *m, epoch_t epoch)
 {
-  dout(10) << "require_same_or_newer_map " << epoch << " (i am " << osdmap->get_epoch() << ")" << endl;
+  dout(10) << "require_same_or_newer_map " << epoch << " (i am " << osdmap->get_epoch() << ")" << dendl;
 
   // newer map?
   if (epoch > osdmap->get_epoch()) {
-    dout(7) << "  from newer map epoch " << epoch << " > " << osdmap->get_epoch() << endl;
+    dout(7) << "  from newer map epoch " << epoch << " > " << osdmap->get_epoch() << dendl;
     wait_for_new_map(m);
     return false;
   }
 
   if (epoch < boot_epoch) {
-    dout(7) << "  from pre-boot epoch " << epoch << " < " << boot_epoch << endl;
+    dout(7) << "  from pre-boot epoch " << epoch << " < " << boot_epoch << dendl;
     delete m;
     return false;
   }
@@ -1402,7 +1402,7 @@ bool OSD::pg_exists(pg_t pgid)
 PG *OSD::create_pg(pg_t pgid, ObjectStore::Transaction& t)
 {
   if (pg_map.count(pgid)) {
-    dout(0) << "create_pg on " << pgid << ", already have " << *pg_map[pgid] << endl;
+    dout(0) << "create_pg on " << pgid << ", already have " << *pg_map[pgid] << dendl;
   }
   assert(pg_map.count(pgid) == 0);
   assert(!pg_exists(pgid));
@@ -1427,7 +1427,7 @@ PG *OSD::get_pg(pg_t pgid)
 
 void OSD::load_pgs()
 {
-  dout(10) << "load_pgs" << endl;
+  dout(10) << "load_pgs" << dendl;
   assert(pg_map.empty());
 
   list<coll_t> ls;
@@ -1452,7 +1452,7 @@ void OSD::load_pgs()
     int role = osdmap->calc_pg_role(whoami, pg->acting, nrep);
     pg->set_role(role);
 
-    dout(10) << "load_pgs loaded " << *pg << " " << pg->log << endl;
+    dout(10) << "load_pgs loaded " << *pg << " " << pg->log << dendl;
   }
 }
  
@@ -1465,7 +1465,7 @@ void OSD::project_pg_history(pg_t pgid, PG::Info::History& h, epoch_t from)
   dout(15) << "project_pg_history " << pgid
            << " from " << from << " to " << osdmap->get_epoch()
            << ", start " << h
-           << endl;
+           << dendl;
 
   vector<int> last;
   osdmap->pg_to_acting_osds(pgid, last);
@@ -1484,14 +1484,14 @@ void OSD::project_pg_history(pg_t pgid, PG::Info::History& h, epoch_t from)
     if (acting != last && 
         e <= h.same_since) {
       dout(15) << "project_pg_history " << pgid << " changed in " << e+1 
-                << " from " << acting << " -> " << last << endl;
+                << " from " << acting << " -> " << last << dendl;
       h.same_since = e+1;
     }
 
     // primary change?
     if (!(!acting.empty() && !last.empty() && acting[0] == last[0]) &&
         e <= h.same_primary_since) {
-      dout(15) << "project_pg_history " << pgid << " primary changed in " << e+1 << endl;
+      dout(15) << "project_pg_history " << pgid << " primary changed in " << e+1 << dendl;
       h.same_primary_since = e+1;
     
       if (g_conf.osd_rep == OSD_REP_PRIMARY)
@@ -1502,7 +1502,7 @@ void OSD::project_pg_history(pg_t pgid, PG::Info::History& h, epoch_t from)
     if (g_conf.osd_rep != OSD_REP_PRIMARY) {
       if (!(!acting.empty() && !last.empty() && acting[acting.size()-1] == last[last.size()-1]) &&
           e <= h.same_acker_since) {
-        dout(15) << "project_pg_history " << pgid << " acker changed in " << e+1 << endl;
+        dout(15) << "project_pg_history " << pgid << " acker changed in " << e+1 << dendl;
         h.same_acker_since = e+1;
       }
     }
@@ -1512,7 +1512,7 @@ void OSD::project_pg_history(pg_t pgid, PG::Info::History& h, epoch_t from)
         h.same_acker_since > e) break;
   }
 
-  dout(15) << "project_pg_history end " << h << endl;
+  dout(15) << "project_pg_history end " << h << dendl;
 }
 
 
@@ -1527,10 +1527,10 @@ void OSD::do_notifies(map< int, list<PG::Info> >& notify_list)
        it != notify_list.end();
        it++) {
     if (it->first == whoami) {
-      dout(7) << "do_notify osd" << it->first << " is self, skipping" << endl;
+      dout(7) << "do_notify osd" << it->first << " is self, skipping" << dendl;
       continue;
     }
-    dout(7) << "do_notify osd" << it->first << " on " << it->second.size() << " PGs" << endl;
+    dout(7) << "do_notify osd" << it->first << " on " << it->second.size() << " PGs" << dendl;
     MOSDPGNotify *m = new MOSDPGNotify(osdmap->get_epoch(), it->second);
     _share_map_outgoing(osdmap->get_inst(it->first));
     messenger->send_message(m, osdmap->get_inst(it->first));
@@ -1548,7 +1548,7 @@ void OSD::do_queries(map< int, map<pg_t,PG::Query> >& query_map)
        pit++) {
     int who = pit->first;
     dout(7) << "do_queries querying osd" << who
-            << " on " << pit->second.size() << " PGs" << endl;
+            << " on " << pit->second.size() << " PGs" << dendl;
 
     MOSDPGQuery *m = new MOSDPGQuery(osdmap->get_epoch(),
                                      pit->second);
@@ -1567,7 +1567,7 @@ void OSD::do_queries(map< int, map<pg_t,PG::Query> >& query_map)
  */
 void OSD::handle_pg_notify(MOSDPGNotify *m)
 {
-  dout(7) << "handle_pg_notify from " << m->get_source() << endl;
+  dout(7) << "handle_pg_notify from " << m->get_source() << dendl;
   int from = m->get_source().num();
 
   if (!require_same_or_newer_map(m, m->get_epoch())) return;
@@ -1590,7 +1590,7 @@ void OSD::handle_pg_notify(MOSDPGNotify *m)
 
       if (m->get_epoch() < history.same_primary_since) {
         dout(10) << "handle_pg_notify pg " << pgid << " dne, and primary changed in "
-                 << history.same_primary_since << " (msg from " << m->get_epoch() << ")" << endl;
+                 << history.same_primary_since << " (msg from " << m->get_epoch() << ")" << dendl;
         continue;
       }
       
@@ -1605,7 +1605,7 @@ void OSD::handle_pg_notify(MOSDPGNotify *m)
 
       t.collection_setattr(pgid, "info", (char*)&pg->info, sizeof(pg->info));
       
-      dout(10) << *pg << " is new" << endl;
+      dout(10) << *pg << " is new" << dendl;
     
       // kick any waiters
       if (waiting_for_pg.count(pgid)) {
@@ -1620,7 +1620,7 @@ void OSD::handle_pg_notify(MOSDPGNotify *m)
       if (m->get_epoch() < pg->info.history.same_primary_since) {
         dout(10) << *pg << " handle_pg_notify primary changed in "
                  << pg->info.history.same_primary_since
-                 << " (msg from " << m->get_epoch() << ")" << endl;
+                 << " (msg from " << m->get_epoch() << ")" << dendl;
         _unlock_pg(pgid);
         continue;
       }
@@ -1631,7 +1631,7 @@ void OSD::handle_pg_notify(MOSDPGNotify *m)
     // stray?
     bool acting = pg->is_acting(from);
     if (!acting && (*it).last_epoch_started > 0) {
-      dout(10) << *pg << " osd" << from << " has stray content: " << *it << endl;
+      dout(10) << *pg << " osd" << from << " has stray content: " << *it << dendl;
       pg->stray_set.insert(from);
       pg->state_clear(PG::STATE_CLEAN);
     }
@@ -1645,15 +1645,15 @@ void OSD::handle_pg_notify(MOSDPGNotify *m)
           (*it).is_clean() && acting) {
         pg->clean_set.insert(from);
         dout(10) << *pg << " osd" << from << " now clean (" << pg->clean_set  
-                 << "): " << *it << endl;
+                 << "): " << *it << dendl;
         if (pg->is_all_clean()) {
-          dout(-10) << *pg << " now clean on all replicas" << endl;
+          dout(-10) << *pg << " now clean on all replicas" << dendl;
           pg->state_set(PG::STATE_CLEAN);
           pg->clean_replicas();
         }
       } else {
         // hmm, maybe keep an eye out for cases where we see this, but peer should happen.
-        dout(10) << *pg << " already had notify info from osd" << from << ": " << *it << endl;
+        dout(10) << *pg << " already had notify info from osd" << from << ": " << *it << dendl;
       }
     } else {
       // adjust prior?
@@ -1692,7 +1692,7 @@ void OSD::handle_pg_log(MOSDPGLog *m)
 
   if (!require_same_or_newer_map(m, m->get_epoch())) return;
   if (pg_map.count(pgid) == 0) {
-    dout(10) << "handle_pg_log don't have pg " << pgid << ", dropping" << endl;
+    dout(10) << "handle_pg_log don't have pg " << pgid << ", dropping" << dendl;
     assert(m->get_epoch() < osdmap->get_epoch());
     delete m;
     return;
@@ -1705,14 +1705,14 @@ void OSD::handle_pg_log(MOSDPGLog *m)
     dout(10) << "handle_pg_log " << *pg 
             << " from " << m->get_source() 
             << " is old, discarding"
-            << endl;
+            << dendl;
     delete m;
     return;
   }
 
   dout(7) << "handle_pg_log " << *pg 
           << " got " << m->log << " " << m->missing
-          << " from " << m->get_source() << endl;
+          << " from " << m->get_source() << dendl;
 
   //m->log.print(cout);
   
@@ -1732,7 +1732,7 @@ void OSD::handle_pg_log(MOSDPGLog *m)
 
   } else {
     // i am REPLICA
-    dout(10) << *pg << " got " << m->log << " " << m->missing << endl;
+    dout(10) << *pg << " got " << m->log << " " << m->missing << dendl;
 
     // merge log
     pg->merge_log(m->log, m->missing, from);
@@ -1758,7 +1758,7 @@ void OSD::handle_pg_log(MOSDPGLog *m)
  */
 void OSD::handle_pg_query(MOSDPGQuery *m) 
 {
-  dout(7) << "handle_pg_query from " << m->get_source() << " epoch " << m->get_epoch() << endl;
+  dout(7) << "handle_pg_query from " << m->get_source() << " epoch " << m->get_epoch() << dendl;
   int from = m->get_source().num();
   
   if (!require_same_or_newer_map(m, m->get_epoch())) return;
@@ -1778,7 +1778,7 @@ void OSD::handle_pg_query(MOSDPGQuery *m)
 
       if (m->get_epoch() < history.same_since) {
         dout(10) << " pg " << pgid << " dne, and pg has changed in "
-                 << history.same_primary_since << " (msg from " << m->get_epoch() << ")" << endl;
+                 << history.same_primary_since << " (msg from " << m->get_epoch() << ")" << dendl;
         continue;
       }
 
@@ -1788,7 +1788,7 @@ void OSD::handle_pg_query(MOSDPGQuery *m)
       int role = osdmap->calc_pg_role(whoami, acting, nrep);
 
       if (role < 0) {
-        dout(10) << " pg " << pgid << " dne, and i am not an active replica" << endl;
+        dout(10) << " pg " << pgid << " dne, and i am not an active replica" << dendl;
         PG::Info empty(pgid);
         notify_list[from].push_back(empty);
         continue;
@@ -1804,7 +1804,7 @@ void OSD::handle_pg_query(MOSDPGQuery *m)
       t.collection_setattr(pgid, "info", (char*)&pg->info, sizeof(pg->info));
       store->apply_transaction(t);
 
-      dout(10) << *pg << " dne (before), but i am role " << role << endl;
+      dout(10) << *pg << " dne (before), but i am role " << role << dendl;
       _lock_pg(pgid);
     } else {
       pg = _lock_pg(pgid);
@@ -1813,7 +1813,7 @@ void OSD::handle_pg_query(MOSDPGQuery *m)
       if (m->get_epoch() < pg->info.history.same_since) {
         dout(10) << *pg << " handle_pg_query primary changed in "
                  << pg->info.history.same_since
-                 << " (msg from " << m->get_epoch() << ")" << endl;
+                 << " (msg from " << m->get_epoch() << ")" << dendl;
         _unlock_pg(pgid);
         continue;
       }
@@ -1825,7 +1825,7 @@ void OSD::handle_pg_query(MOSDPGQuery *m)
 
     if (it->second.type == PG::Query::INFO) {
       // info
-      dout(10) << *pg << " sending info" << endl;
+      dout(10) << *pg << " sending info" << dendl;
       notify_list[from].push_back(pg->info);
     } else {
       MOSDPGLog *m = new MOSDPGLog(osdmap->get_epoch(), pg->get_pgid());
@@ -1835,15 +1835,15 @@ void OSD::handle_pg_query(MOSDPGQuery *m)
       if (it->second.type == PG::Query::LOG) {
         dout(10) << *pg << " sending info+missing+log since split " << it->second.split
                  << " from floor " << it->second.floor 
-                 << endl;
+                 << dendl;
         if (!m->log.copy_after_unless_divergent(pg->log, it->second.split, it->second.floor)) {
-          dout(10) << *pg << "  divergent, sending backlog" << endl;
+          dout(10) << *pg << "  divergent, sending backlog" << dendl;
           it->second.type = PG::Query::BACKLOG;
         }
       }
 
       if (it->second.type == PG::Query::BACKLOG) {
-        dout(10) << *pg << " sending info+missing+backlog" << endl;
+        dout(10) << *pg << " sending info+missing+backlog" << dendl;
         if (pg->log.backlog) {
           m->log = pg->log;
         } else {
@@ -1853,11 +1853,11 @@ void OSD::handle_pg_query(MOSDPGQuery *m)
         }
       } 
       else if (it->second.type == PG::Query::FULLLOG) {
-        dout(10) << *pg << " sending info+missing+full log" << endl;
+        dout(10) << *pg << " sending info+missing+full log" << dendl;
         m->log.copy_non_backlog(pg->log);
       }
 
-      dout(10) << *pg << " sending " << m->log << " " << m->missing << endl;
+      dout(10) << *pg << " sending " << m->log << " " << m->missing << dendl;
       //m->log.print(cout);
 
       _share_map_outgoing(osdmap->get_inst(from));
@@ -1875,7 +1875,7 @@ void OSD::handle_pg_query(MOSDPGQuery *m)
 
 void OSD::handle_pg_remove(MOSDPGRemove *m)
 {
-  dout(7) << "handle_pg_remove from " << m->get_source() << endl;
+  dout(7) << "handle_pg_remove from " << m->get_source() << dendl;
   
   if (!require_same_or_newer_map(m, m->get_epoch())) return;
 
@@ -1886,13 +1886,13 @@ void OSD::handle_pg_remove(MOSDPGRemove *m)
     PG *pg;
 
     if (pg_map.count(pgid) == 0) {
-      dout(10) << " don't have pg " << pgid << endl;
+      dout(10) << " don't have pg " << pgid << dendl;
       continue;
     }
 
     pg = _lock_pg(pgid);
 
-    dout(10) << *pg << " removing." << endl;
+    dout(10) << *pg << " removing." << dendl;
     assert(pg->get_role() == -1);
     
     _remove_pg(pgid);
@@ -1923,7 +1923,7 @@ void OSD::pull(PG *pg, object_t oid)
   dout(7) << *pg << " pull " << oid
           << " v " << v 
           << " from osd" << osd
-          << endl;
+          << dendl;
 
   // send op
   tid_t tid = ++last_tid;
@@ -1963,7 +1963,7 @@ void OSD::push(PG *pg, object_t oid, int dest)
   dout(7) << *pg << " push " << oid << " v " << v 
           << " size " << bl.length()
           << " to osd" << dest
-          << endl;
+          << dendl;
 
   logger->inc("r_push");
   logger->inc("r_pushb", bl.length());
@@ -1994,7 +1994,7 @@ void OSD::op_pull(MOSDOp *op, PG *pg)
 
   dout(7) << *pg << " op_pull " << oid << " v " << op->get_version()
           << " from " << op->get_source()
-          << endl;
+          << dendl;
 
   // is a replica asking?  are they missing it?
   if (pg->is_primary()) {
@@ -2002,7 +2002,7 @@ void OSD::op_pull(MOSDOp *op, PG *pg)
     assert(pg->peer_missing.count(from));  // we had better know this, from the peering process.
 
     if (!pg->peer_missing[from].is_missing(oid)) {
-      dout(7) << *pg << " op_pull replica isn't actually missing it, we must have already pushed to them" << endl;
+      dout(7) << *pg << " op_pull replica isn't actually missing it, we must have already pushed to them" << dendl;
       delete op;
       return;
     }
@@ -2013,7 +2013,7 @@ void OSD::op_pull(MOSDOp *op, PG *pg)
   } else {
     // non-primary
     if (pg->missing.is_missing(oid)) {
-      dout(7) << *pg << " op_pull not primary, and missing " << oid << ", ignoring" << endl;
+      dout(7) << *pg << " op_pull not primary, and missing " << oid << ", ignoring" << dendl;
       delete op;
       return;
     }
@@ -2033,7 +2033,7 @@ void OSD::op_push(MOSDOp *op, PG *pg)
   eversion_t v = op->get_version();
 
   if (!pg->missing.is_missing(oid)) {
-    dout(7) << *pg << " op_push not missing " << oid << endl;
+    dout(7) << *pg << " op_push not missing " << oid << dendl;
     return;
   }
   
@@ -2041,7 +2041,7 @@ void OSD::op_push(MOSDOp *op, PG *pg)
           << oid 
           << " v " << v 
           << " size " << op->get_length() << " " << op->get_data().length()
-          << endl;
+          << dendl;
 
   assert(op->get_data().length() == op->get_length());
   
@@ -2067,7 +2067,7 @@ void OSD::op_push(MOSDOp *op, PG *pg)
       pg->info.last_complete = pg->log.complete_to->version;
     pg->log.complete_to++;
   }
-  dout(10) << *pg << " last_complete now " << pg->info.last_complete << endl;
+  dout(10) << *pg << " last_complete now " << pg->info.last_complete << dendl;
   
   
   // apply to disk!
@@ -2151,7 +2151,7 @@ void OSD::op_rep_modify_commit(MOSDOp *op, int ackerosd, eversion_t last_complet
   // send commit.
   dout(10) << "rep_modify_commit on op " << *op
            << ", sending commit to osd" << ackerosd
-           << endl;
+           << dendl;
   MOSDOpReply *commit = new MOSDOpReply(op, 0, osdmap->get_epoch(), true);
   commit->set_pg_complete_thru(last_complete);
   messenger->send_message(commit, osdmap->get_inst(ackerosd));
@@ -2193,7 +2193,7 @@ void OSD::op_rep_modify(MOSDOp *op, PG *pg)
            << " v " << nv 
            << " " << op->get_offset() << "~" << op->get_length()
            << " in " << *pg
-           << endl;  
+           << dendl;  
   
   // we better not be missing this.
   assert(!pg->missing.is_missing(oid));
@@ -2265,7 +2265,7 @@ void OSD::op_rep_modify(MOSDOp *op, PG *pg)
     unsigned tr = store->apply_transaction(t, oncommit);
     if (tr != 0 &&   // no errors
         tr != 2) {   // or error on collection_add
-      cerr << "error applying transaction: r = " << tr << endl;
+      cerr << "error applying transaction: r = " << tr << dendl;
       assert(tr == 0);
     }
   }
@@ -2330,7 +2330,7 @@ void OSD::handle_op(MOSDOp *op)
     if (!pg) {
       dout(7) << "hit non-existent pg " 
               << pgid 
-              << ", waiting" << endl;
+              << ", waiting" << dendl;
       waiting_for_pg[pgid].push_back(op);
       return;
     }
@@ -2341,7 +2341,7 @@ void OSD::handle_op(MOSDOp *op)
           op->get_map_epoch() < pg->info.history.same_acker_since) {
         dout(7) << "acting acker is osd" << pg->get_acker()
                 << " since " << pg->info.history.same_acker_since 
-                << ", dropping" << endl;
+                << ", dropping" << dendl;
         assert(op->get_map_epoch() < osdmap->get_epoch());
         delete op;
         return;
@@ -2352,7 +2352,7 @@ void OSD::handle_op(MOSDOp *op)
           op->get_map_epoch() < pg->info.history.same_primary_since) {
         dout(7) << "acting primary is osd" << pg->get_primary()
                 << " since " << pg->info.history.same_primary_since 
-                << ", dropping" << endl;
+                << ", dropping" << dendl;
         assert(op->get_map_epoch() < osdmap->get_epoch());
         delete op;
         return;
@@ -2365,17 +2365,17 @@ void OSD::handle_op(MOSDOp *op)
       if (op->get_version().version > 0) {
         if (op->get_version() > pg->info.last_update) {
           dout(7) << *pg << " queueing replay at " << op->get_version()
-                  << " for " << *op << endl;
+                  << " for " << *op << dendl;
           pg->replay_queue[op->get_version()] = op;
           return;
         } else {
           dout(7) << *pg << " replay at " << op->get_version() << " <= " << pg->info.last_update 
                   << " for " << *op
-                  << ", will queue for WRNOOP" << endl;
+                  << ", will queue for WRNOOP" << dendl;
         }
       }
       
-      dout(7) << *pg << " not active (yet)" << endl;
+      dout(7) << *pg << " not active (yet)" << dendl;
       pg->waiting_for_active.push_back(op);
       return;
     }
@@ -2394,7 +2394,7 @@ void OSD::handle_op(MOSDOp *op)
          dout(10) << "handle_op read on " << op->get_oid()
                   << ", have " << loid
                   << ", but need missing " << moid
-                  << ", pulling" << endl;
+                  << ", pulling" << dendl;
          pull(pg, moid);
          pg->waiting_for_missing_object[moid].push_back(op);
          return;
@@ -2403,7 +2403,7 @@ void OSD::handle_op(MOSDOp *op)
        dout(10) << "handle_op read on " << op->get_oid()
                 << ", have " << loid
                 << ", don't need missing " << moid 
-                << endl;
+                << dendl;
       }
     } else {
       // live revision.  easy.
@@ -2411,7 +2411,7 @@ void OSD::handle_op(MOSDOp *op)
          waitfor_missing_object(op, pg)) return;
     }
 
-    dout(7) << "handle_op " << *op << " in " << *pg << endl;
+    dout(7) << "handle_op " << *op << " in " << *pg << dendl;
     
     
     // balance reads?
@@ -2422,7 +2422,7 @@ void OSD::handle_op(MOSDOp *op)
       if (false) {
        if (pg->acting.size() > 1) {
          int peer = pg->acting[1];
-         dout(-10) << "fwd client read op to osd" << peer << " for " << op->get_client() << " " << op->get_client_inst() << endl;
+         dout(-10) << "fwd client read op to osd" << peer << " for " << op->get_client() << " " << op->get_client_inst() << dendl;
          messenger->send_message(op, osdmap->get_inst(peer));
          return;
        }
@@ -2445,7 +2445,7 @@ void OSD::handle_op(MOSDOp *op)
                        << ", p=" << p 
                        << ", fwd to peer w/ qlen " << peer_qlen[peer]
                        << " osd" << peer
-                       << endl;
+                       << dendl;
              messenger->send_message(op, osdmap->get_inst(peer));
              return;
            }
@@ -2460,7 +2460,7 @@ void OSD::handle_op(MOSDOp *op)
     // have pg?
     if (!pg) {
       derr(-7) << "handle_rep_op " << *op 
-               << " pgid " << pgid << " dne" << endl;
+               << " pgid " << pgid << " dne" << dendl;
       delete op;
       //assert(0); // wtf, shouldn't happen.
       return;
@@ -2471,7 +2471,7 @@ void OSD::handle_op(MOSDOp *op)
         op->get_map_epoch() < pg->info.history.same_since) {
       dout(10) << "handle_rep_op pg changed " << pg->info.history
                << " after " << op->get_map_epoch() 
-               << ", dropping" << endl;
+               << ", dropping" << dendl;
       delete op;
       return;
     }
@@ -2480,13 +2480,13 @@ void OSD::handle_op(MOSDOp *op)
          op->get_map_epoch() < pg->info.history.same_acker_since)) {
       dout(10) << "handle_rep_op pg primary|acker changed " << pg->info.history
                << " after " << op->get_map_epoch() 
-               << ", dropping" << endl;
+               << ", dropping" << dendl;
       delete op;
       return;
     }
 
     assert(pg->get_role() >= 0);
-    dout(7) << "handle_rep_op " << op << " in " << *pg << endl;
+    dout(7) << "handle_rep_op " << op << " in " << *pg << dendl;
   }
   
   if (g_conf.osd_maxthreads < 1) {
@@ -2505,7 +2505,7 @@ void OSD::handle_op(MOSDOp *op)
 void OSD::handle_op_reply(MOSDOpReply *op)
 {
   if (op->get_map_epoch() < boot_epoch) {
-    dout(3) << "replica op reply from before boot" << endl;
+    dout(3) << "replica op reply from before boot" << dendl;
     delete op;
     return;
   }
@@ -2544,7 +2544,7 @@ void OSD::handle_op_reply(MOSDOpReply *op)
 void OSD::enqueue_op(pg_t pgid, Message *op)
 {
   while (pending_ops > g_conf.osd_max_opq) {
-    dout(10) << "enqueue_op waiting for pending_ops " << pending_ops << " to drop to " << g_conf.osd_max_opq << endl;
+    dout(10) << "enqueue_op waiting for pending_ops " << pending_ops << " to drop to " << g_conf.osd_max_opq << dendl;
     op_queue_cond.Wait(osd_lock);
   }
 
@@ -2578,10 +2578,10 @@ void OSD::dequeue_op(pg_t pgid)
     
     if (pgid) {
       dout(10) << "dequeue_op " << op << " write pg " << pgid 
-               << ls.size() << " / " << (pending_ops-1) << " more pending" << endl;
+               << ls.size() << " / " << (pending_ops-1) << " more pending" << dendl;
     } else {
       dout(10) << "dequeue_op " << op << " read "
-               << ls.size() << " / " << (pending_ops-1) << " more pending" << endl;
+               << ls.size() << " / " << (pending_ops-1) << " more pending" << dendl;
     }
     
     if (ls.empty())
@@ -2600,7 +2600,7 @@ void OSD::dequeue_op(pg_t pgid)
       _unlock_pg(pgid);
     }
     
-    dout(10) << "dequeue_op " << op << " finish" << endl;
+    dout(10) << "dequeue_op " << op << " finish" << dendl;
     assert(pending_ops > 0);
     
     if (pending_ops > g_conf.osd_max_opq) 
@@ -2622,7 +2622,7 @@ void OSD::dequeue_op(pg_t pgid)
  */
 void OSD::do_op(Message *m, PG *pg) 
 {
-  //dout(15) << "do_op " << *m << endl;
+  //dout(15) << "do_op " << *m << dendl;
 
   if (m->get_type() == MSG_OSD_OP) {
     MOSDOp *op = (MOSDOp*)m;
@@ -2696,14 +2696,14 @@ void OSD::do_op(Message *m, PG *pg)
 void OSD::wait_for_no_ops()
 {
   if (pending_ops > 0) {
-    dout(7) << "wait_for_no_ops - waiting for " << pending_ops << endl;
+    dout(7) << "wait_for_no_ops - waiting for " << pending_ops << dendl;
     waiting_for_no_ops = true;
     while (pending_ops > 0)
       no_pending_ops.Wait(osd_lock);
     waiting_for_no_ops = false;
     assert(pending_ops == 0);
   } 
-  dout(7) << "wait_for_no_ops - none" << endl;
+  dout(7) << "wait_for_no_ops - none" << dendl;
 }
 
 
@@ -2720,7 +2720,7 @@ bool OSD::block_if_wrlocked(MOSDOp* op)
 
   entity_name_t source;
   int len = store->getattr(oid, "wrlock", &source, sizeof(entity_name_t));
-  //cout << "getattr returns " << len << " on " << oid << endl;
+  //cout << "getattr returns " << len << " on " << oid << dendl;
 
   if (len == sizeof(source) &&
       source != op->get_client()) {
@@ -2779,7 +2779,7 @@ bool OSD::pick_object_rev(object_t& oid)
   int r = store->getattr(t, "crev", &crev, sizeof(crev));
   assert(r >= 0);
   if (crev <= oid.rev) {
-    dout(10) << "pick_object_rev choosing " << t << " crev " << crev << " for " << oid << endl;
+    dout(10) << "pick_object_rev choosing " << t << " crev " << crev << " for " << oid << dendl;
     oid = t;
     return true;
   }
@@ -2801,14 +2801,14 @@ bool OSD::waitfor_missing_object(MOSDOp *op, PG *pg)
               << " v " << v
               << " in " << *pg
               << ", already pulling"
-              << endl;
+              << dendl;
     } else {
       dout(7) << "missing " 
               << oid 
               << " v " << v
               << " in " << *pg
               << ", pulling"
-              << endl;
+              << dendl;
       pull(pg, oid);
     }
     pg->waiting_for_missing_object[oid].push_back(op);
@@ -2838,7 +2838,7 @@ void OSD::op_read(MOSDOp *op)//, PG *pg)
   dout(10) << "op_read " << oid 
            << " " << op->get_offset() << "~" << op->get_length() 
     //<< " in " << *pg 
-           << endl;
+           << dendl;
 
   long r = 0;
   bufferlist bl;
@@ -2868,7 +2868,7 @@ void OSD::op_read(MOSDOp *op)//, PG *pg)
     reply->set_length(0);
   }
   
-  dout(10) << " read got " << r << " / " << op->get_length() << " bytes from obj " << oid << endl;
+  dout(10) << " read got " << r << " / " << op->get_length() << " bytes from obj " << oid << dendl;
   
   logger->inc("rd");
   if (r >= 0) logger->inc("rdb", r);
@@ -2906,7 +2906,7 @@ void OSD::op_stat(MOSDOp *op)//, PG *pg)
           << " r = " << r
           << " size = " << st.st_size
     //<< " in " << *pg
-          << endl;
+          << dendl;
   
   MOSDOpReply *reply = new MOSDOpReply(op, r, osdmap->get_epoch(), true);
   reply->set_object_size(st.st_size);
@@ -2926,18 +2926,18 @@ void OSD::op_stat(MOSDOp *op)//, PG *pg)
 void OSD::get_repop_gather(PG::RepOpGather *repop)
 {
   //repop->lock.Lock();
-  dout(10) << "get_repop " << *repop << endl;
+  dout(10) << "get_repop " << *repop << dendl;
 }
 
 void OSD::apply_repop(PG *pg, PG::RepOpGather *repop)
 {
-  dout(10) << "apply_repop  applying update on " << *repop << endl;
+  dout(10) << "apply_repop  applying update on " << *repop << dendl;
   assert(!repop->applied);
 
   Context *oncommit = new C_OSD_WriteCommit(this, pg->info.pgid, repop->rep_tid, repop->pg_local_last_complete);
   unsigned r = store->apply_transaction(repop->t, oncommit);
   if (r)
-    dout(-10) << "apply_repop  apply transaction return " << r << " on " << *repop << endl;
+    dout(-10) << "apply_repop  apply transaction return " << r << " on " << *repop << dendl;
   
   // discard my reference to buffer
   repop->op->get_data().clear();
@@ -2947,14 +2947,14 @@ void OSD::apply_repop(PG *pg, PG::RepOpGather *repop)
 
 void OSD::put_repop_gather(PG *pg, PG::RepOpGather *repop)
 {
-  dout(10) << "put_repop " << *repop << endl;
+  dout(10) << "put_repop " << *repop << dendl;
 
   // commit?
   if (repop->can_send_commit() &&
       repop->op->wants_commit()) {
     // send commit.
     MOSDOpReply *reply = new MOSDOpReply(repop->op, 0, osdmap->get_epoch(), true);
-    dout(10) << "put_repop  sending commit on " << *repop << " " << reply << endl;
+    dout(10) << "put_repop  sending commit on " << *repop << " " << reply << dendl;
     messenger->send_message(reply, repop->op->get_client_inst());
     repop->sent_commit = true;
   }
@@ -2967,7 +2967,7 @@ void OSD::put_repop_gather(PG *pg, PG::RepOpGather *repop)
 
     // send ack
     MOSDOpReply *reply = new MOSDOpReply(repop->op, 0, osdmap->get_epoch(), false);
-    dout(10) << "put_repop  sending ack on " << *repop << " " << reply << endl;
+    dout(10) << "put_repop  sending ack on " << *repop << " " << reply << dendl;
     messenger->send_message(reply, repop->op->get_client_inst());
     repop->sent_ack = true;
 
@@ -2988,12 +2988,12 @@ void OSD::put_repop_gather(PG *pg, PG::RepOpGather *repop)
       }
       
       if (min > pg->peers_complete_thru) {
-        dout(10) << "put_repop  peers_complete_thru " << pg->peers_complete_thru << " -> " << min << " in " << *pg << endl;
+        dout(10) << "put_repop  peers_complete_thru " << pg->peers_complete_thru << " -> " << min << " in " << *pg << dendl;
         pg->peers_complete_thru = min;
       }
     }
 
-    dout(10) << "put_repop  deleting " << *repop << endl;
+    dout(10) << "put_repop  deleting " << *repop << dendl;
     //repop->lock.Unlock();  
 
     assert(pg->repop_gather.count(repop->rep_tid));
@@ -3016,7 +3016,7 @@ void OSD::issue_repop(PG *pg, MOSDOp *op, int osd)
           << " in " << *pg 
           << " o " << oid
           << " to osd" << osd
-          << endl;
+          << dendl;
   
   // forward the write/update/whatever
   MOSDOp *wr = new MOSDOp(op->get_client_inst(), op->get_client_inc(), op->get_reqid().tid,
@@ -3038,7 +3038,7 @@ void OSD::issue_repop(PG *pg, MOSDOp *op, int osd)
 PG::RepOpGather *OSD::new_repop_gather(PG *pg, 
                                        MOSDOp *op)
 {
-  dout(10) << "new_repop_gather rep_tid " << op->get_rep_tid() << " on " << *op << " in " << *pg << endl;
+  dout(10) << "new_repop_gather rep_tid " << op->get_rep_tid() << " on " << *op << " in " << *pg << dendl;
 
   PG::RepOpGather *repop = new PG::RepOpGather(op, op->get_rep_tid(), 
                                                op->get_version(), 
@@ -3098,7 +3098,7 @@ void OSD::repop_ack(PG *pg, PG::RepOpGather *repop,
   dout(7) << "repop_ack rep_tid " << repop->rep_tid << " op " << *op
           << " result " << result << " commit " << commit << " from osd" << fromosd
           << " in " << *pg
-          << endl;
+          << dendl;
 
   get_repop_gather(repop);
   {
@@ -3130,7 +3130,7 @@ void OSD::op_modify_commit(pg_t pgid, tid_t rep_tid, eversion_t pg_complete_thru
     if (pg->repop_gather.count(rep_tid)) {
       PG::RepOpGather *repop = pg->repop_gather[rep_tid];
       
-      dout(10) << "op_modify_commit " << *repop->op << endl;
+      dout(10) << "op_modify_commit " << *repop->op << dendl;
       get_repop_gather(repop);
       {
         assert(repop->waitfor_commit.count(whoami));
@@ -3138,14 +3138,14 @@ void OSD::op_modify_commit(pg_t pgid, tid_t rep_tid, eversion_t pg_complete_thru
         repop->pg_complete_thru[whoami] = pg_complete_thru;
       }
       put_repop_gather(pg, repop);
-      dout(10) << "op_modify_commit done on " << repop << endl;
+      dout(10) << "op_modify_commit done on " << repop << dendl;
     } else {
-      dout(10) << "op_modify_commit pg " << pgid << " rep_tid " << rep_tid << " dne" << endl;
+      dout(10) << "op_modify_commit pg " << pgid << " rep_tid " << rep_tid << " dne" << dendl;
     }
 
     unlock_pg(pgid);
   } else {
-    dout(10) << "op_modify_commit pg " << pgid << " dne" << endl;
+    dout(10) << "op_modify_commit pg " << pgid << " dne" << dendl;
   }
 }
 
@@ -3175,7 +3175,7 @@ void OSD::op_modify(MOSDOp *op, PG *pg)
   // dup op?
   if (pg->log.logged_req(op->get_reqid())) {
     dout(-3) << "op_modify " << opname << " dup op " << op->get_reqid()
-             << ", doing WRNOOP" << endl;
+             << ", doing WRNOOP" << dendl;
     op->set_op(OSD_OP_WRNOOP);
     opname = MOSDOp::get_opname(op->get_op());
   }
@@ -3230,7 +3230,7 @@ void OSD::op_modify(MOSDOp *op, PG *pg)
           << " crev " << crev
           << " rev " << op->get_rev()
            << " " << op->get_offset() << "~" << op->get_length()
-           << endl;  
+           << dendl;  
 
   if (op->get_op() == OSD_OP_WRITE) {
     logger->inc("c_wr");
@@ -3303,7 +3303,7 @@ void OSD::op_modify(MOSDOp *op, PG *pg)
     unsigned r = store->apply_transaction(t, oncommit);
     if (r != 0 &&   // no errors
         r != 2) {   // or error on collection_add
-      cerr << "error applying transaction: r = " << r << endl;
+      cerr << "error applying transaction: r = " << r << dendl;
       assert(r == 0);
     }
 
@@ -3330,7 +3330,7 @@ void OSD::prepare_log_transaction(ObjectStore::Transaction& t,
 
     dout(10) << "prepare_log_transaction " << op->get_op()
             << " " << cloneentry
-            << " in " << *pg << endl;
+            << " in " << *pg << dendl;
   }
 
   // actual op
@@ -3340,13 +3340,13 @@ void OSD::prepare_log_transaction(ObjectStore::Transaction& t,
 
   dout(10) << "prepare_log_transaction " << op->get_op()
            << " " << logentry
-           << " in " << *pg << endl;
+           << " in " << *pg << dendl;
 
   // append to log
   assert(version > pg->log.top);
   pg->log.add(logentry);
   assert(pg->log.top == version);
-  dout(10) << "prepare_log_transaction appended to " << *pg << endl;
+  dout(10) << "prepare_log_transaction appended to " << *pg << dendl;
 
   // write to pg log on disk
   pg->append_log(t, logentry, trim_to);
@@ -3371,7 +3371,7 @@ void OSD::prepare_op_transaction(ObjectStore::Transaction& t,
            << " v " << version
           << " crev " << crev
           << " rev " << rev
-           << " in " << *pg << endl;
+           << " in " << *pg << dendl;
   
   // WRNOOP does nothing.
   if (op->get_op() == OSD_OP_WRNOOP) 
@@ -3392,7 +3392,7 @@ void OSD::prepare_op_transaction(ObjectStore::Transaction& t,
   if (crev && rev && rev > crev) {
     object_t noid = oid;
     noid.rev = rev;
-    dout(10) << "prepare_op_transaction cloning " << oid << " crev " << crev << " to " << noid << endl;
+    dout(10) << "prepare_op_transaction cloning " << oid << " crev " << crev << " to " << noid << dendl;
     t.clone(oid, noid);
     did_clone = true;
   }  
@@ -3452,7 +3452,7 @@ void OSD::prepare_op_transaction(ObjectStore::Transaction& t,
        }
       } else {
        // noop?
-       dout(10) << "apply_transaction zero on " << oid << ", but dne?  stat returns " << r << endl;
+       dout(10) << "apply_transaction zero on " << oid << ", but dne?  stat returns " << r << dendl;
       }
     }
     break;
index 218f9eac36aae5b079fdb7e8662bea1770995aa3..a3402ec0d8fac37cf900ce6591cf8ca972f0e814 100644 (file)
@@ -24,7 +24,7 @@
 #include "messages/MOSDPGRemove.h"
 
 #undef dout
-#define  dout(l)    if (l<=g_conf.debug || l<=g_conf.debug_osd) cout << g_clock.now() << " osd" << osd->whoami << " " << (osd->osdmap ? osd->osdmap->get_epoch():0) << " " << *this << " "
+#define  dout(l)    if (l<=g_conf.debug || l<=g_conf.debug_osd) cout << dbeginl << g_clock.now() << " osd" << osd->whoami << " " << (osd->osdmap ? osd->osdmap->get_epoch():0) << " " << *this << " "
 
 
 /******* PGLog ********/
@@ -144,18 +144,18 @@ void PG::IndexedLog::trim_write_ahead(eversion_t last_update)
 void PG::trim_write_ahead()
 {
   if (info.last_update < log.top) {
-    dout(10) << "trim_write_ahead (" << info.last_update << "," << log.top << "]" << endl;
+    dout(10) << "trim_write_ahead (" << info.last_update << "," << log.top << "]" << dendl;
     log.trim_write_ahead(info.last_update);
   } else {
     assert(info.last_update == log.top);
-    dout(10) << "trim_write_ahead last_update=top=" << info.last_update << endl;
+    dout(10) << "trim_write_ahead last_update=top=" << info.last_update << dendl;
   }
 
 }
 
 void PG::proc_replica_log(Log &olog, Missing& omissing, int from)
 {
-  dout(10) << "proc_replica_log for osd" << from << ": " << olog << " " << omissing << endl;
+  dout(10) << "proc_replica_log for osd" << from << ": " << olog << " " << omissing << dendl;
   assert(!is_active());
 
   if (!have_master_log) {
@@ -175,12 +175,12 @@ void PG::proc_replica_log(Log &olog, Missing& omissing, int from)
     eversion_t lu = peer_info[from].last_update;
     while (pp != olog.log.rend()) {
       if (!log.objects.count(pp->oid)) {
-        dout(10) << " divergent " << *pp << " not in our log, generating backlog" << endl;
+        dout(10) << " divergent " << *pp << " not in our log, generating backlog" << dendl;
         generate_backlog();
       }
       
       if (!log.objects.count(pp->oid)) {
-        dout(10) << " divergent " << *pp << " dne, must have been new, ignoring" << endl;
+        dout(10) << " divergent " << *pp << " dne, must have been new, ignoring" << dendl;
         ++pp;
         continue;
       } 
@@ -194,9 +194,9 @@ void PG::proc_replica_log(Log &olog, Missing& omissing, int from)
       if (log.objects[pp->oid]->version > pp->version) {
         dout(10) << " divergent " << *pp
                  << " superceded by " << log.objects[pp->oid]
-                 << ", ignoring" << endl;
+                 << ", ignoring" << dendl;
       } else {
-        dout(10) << " divergent " << *pp << ", adding to missing" << endl;
+        dout(10) << " divergent " << *pp << ", adding to missing" << dendl;
         peer_missing[from].add(pp->oid, pp->version);
       }
 
@@ -208,10 +208,10 @@ void PG::proc_replica_log(Log &olog, Missing& omissing, int from)
     }    
 
     if (lu < peer_info[from].last_update) {
-      dout(10) << " peer osd" << from << " last_update now " << lu << endl;
+      dout(10) << " peer osd" << from << " last_update now " << lu << dendl;
       peer_info[from].last_update = lu;
       if (lu < oldest_update) {
-        dout(10) << " oldest_update now " << lu << endl;
+        dout(10) << " oldest_update now " << lu << dendl;
         oldest_update = lu;
       }
     }
@@ -223,11 +223,11 @@ void PG::proc_replica_log(Log &olog, Missing& omissing, int from)
 void PG::merge_log(Log &olog, Missing &omissing, int fromosd)
 {
   dout(10) << "merge_log " << olog << " from osd" << fromosd
-           << " into " << log << endl;
+           << " into " << log << dendl;
 
-  //cout << "log" << endl;
+  //cout << "log" << dendl;
   //log.print(cout);
-  //cout << "olog" << endl;
+  //cout << "olog" << dendl;
   //olog.print(cout);
   
   if (log.empty() ||
@@ -247,7 +247,7 @@ void PG::merge_log(Log &olog, Missing &omissing, int fromosd)
 
         // was our old log divergent?
         if (log.top > p->version) { 
-          dout(10) << "merge_log i was (possibly) divergent for (" << p->version << "," << log.top << "]" << endl;
+          dout(10) << "merge_log i was (possibly) divergent for (" << p->version << "," << log.top << "]" << dendl;
           if (p->version < oldest_update)
             oldest_update = p->version;
           
@@ -258,15 +258,15 @@ void PG::merge_log(Log &olog, Missing &omissing, int fromosd)
               if (log.objects[oe.oid]->version < oe.version) {
                 dout(10) << "merge_log  divergent entry " << oe
                          << " not superceded by " << *log.objects[oe.oid]
-                         << ", adding to missing" << endl;
+                         << ", adding to missing" << dendl;
                 missing.add(oe.oid, oe.version);
               } else {
                 dout(10) << "merge_log  divergent entry " << oe
                          << " superceded by " << *log.objects[oe.oid] 
-                         << ", ignoring" << endl;
+                         << ", ignoring" << dendl;
               }
             } else {
-              dout(10) << "merge_log  divergent entry " << oe << ", adding to missing" << endl;
+              dout(10) << "merge_log  divergent entry " << oe << ", adding to missing" << dendl;
               missing.add(oe.oid, oe.version);
             }
             olog.log.pop_back();  // discard divergent entry
@@ -276,10 +276,10 @@ void PG::merge_log(Log &olog, Missing &omissing, int fromosd)
       }
 
       if (p->is_delete()) {
-        dout(10) << "merge_log merging " << *p << ", not missing" << endl;
+        dout(10) << "merge_log merging " << *p << ", not missing" << dendl;
         missing.rm(p->oid, p->version);
       } else {
-        dout(10) << "merge_log merging " << *p << ", now missing" << endl;
+        dout(10) << "merge_log merging " << *p << ", now missing" << dendl;
         missing.add(p->oid, p->version);
       }
     }
@@ -297,7 +297,7 @@ void PG::merge_log(Log &olog, Missing &omissing, int fromosd)
     if (olog.bottom < log.bottom && olog.top >= log.bottom && !log.backlog) {
       dout(10) << "merge_log extending bottom to " << olog.bottom
                << (olog.backlog ? " +backlog":"")
-             << endl;
+             << dendl;
       
       // ok
       list<Log::Entry>::iterator from = olog.log.begin();
@@ -310,7 +310,7 @@ void PG::merge_log(Log &olog, Missing &omissing, int fromosd)
         // update our index while we're here
         log.index(*to);
         
-        dout(15) << *to << endl;
+        dout(15) << *to << dendl;
         
         // new missing object?
         if (to->version > info.last_complete) {
@@ -333,21 +333,21 @@ void PG::merge_log(Log &olog, Missing &omissing, int fromosd)
     // extend on top?
     if (olog.top > log.top &&
         olog.bottom <= log.top) {
-      dout(10) << "merge_log extending top to " << olog.top << endl;
+      dout(10) << "merge_log extending top to " << olog.top << dendl;
       
       list<Log::Entry>::iterator to = olog.log.end();
       list<Log::Entry>::iterator from = olog.log.end();
       while (1) {
         if (from == olog.log.begin()) break;
         from--;
-        //dout(0) << "? " << *from << endl;
+        //dout(0) << "? " << *from << dendl;
         if (from->version < log.top) {
           from++;
           break;
         }
         
         log.index(*from);
-        dout(10) << "merge_log " << *from << endl;
+        dout(10) << "merge_log " << *from << dendl;
         
         // add to missing
         if (from->is_update()) {
@@ -366,11 +366,11 @@ void PG::merge_log(Log &olog, Missing &omissing, int fromosd)
         
         if (log.objects[oldtail->oid]->version == oldtail->version) {
           // and significant.
-          dout(10) << "merge_log had divergent " << *oldtail << ", adding to missing" << endl;
+          dout(10) << "merge_log had divergent " << *oldtail << ", adding to missing" << dendl;
           //missing.add(oldtail->oid);
           assert(0);
         } else {
-          dout(10) << "merge_log had divergent " << *oldtail << ", already missing" << endl;
+          dout(10) << "merge_log had divergent " << *oldtail << ", already missing" << dendl;
           assert(missing.is_missing(oldtail->oid));
         }
         log.log.pop_back();
@@ -384,7 +384,7 @@ void PG::merge_log(Log &olog, Missing &omissing, int fromosd)
     }
   }
   
-  dout(10) << "merge_log result " << log << " " << missing << endl;
+  dout(10) << "merge_log result " << log << " " << missing << dendl;
   //log.print(cout);
 
 }
@@ -399,32 +399,32 @@ void PG::proc_missing(Log &olog, Missing &omissing, int fromosd)
       assert(omissing.is_missing(p->first, p->second));
       if (omissing.loc.count(p->first)) {
         dout(10) << "proc_missing missing " << p->first << " " << p->second
-                 << " on osd" << omissing.loc[p->first] << endl;
+                 << " on osd" << omissing.loc[p->first] << dendl;
         missing.loc[p->first] = omissing.loc[p->first];
       } else {
         dout(10) << "proc_missing missing " << p->first << " " << p->second
-                 << " also LOST on source, osd" << fromosd << endl;
+                 << " also LOST on source, osd" << fromosd << dendl;
       }
     } 
     else if (p->second <= olog.top) {
       dout(10) << "proc_missing missing " << p->first << " " << p->second
-               << " on source, osd" << fromosd << endl;
+               << " on source, osd" << fromosd << dendl;
       missing.loc[p->first] = fromosd;
     } else {
       dout(10) << "proc_missing " << p->first << " " << p->second
                << " > olog.top " << olog.top << ", not found...."
-               << endl;
+               << dendl;
     }
   }
 
-  dout(10) << "proc_missing missing " << missing.missing << endl;
+  dout(10) << "proc_missing missing " << missing.missing << dendl;
 }
 
 
 
 void PG::generate_backlog()
 {
-  dout(10) << "generate_backlog to " << log << endl;
+  dout(10) << "generate_backlog to " << log << dendl;
   assert(!log.backlog);
   log.backlog = true;
 
@@ -448,7 +448,7 @@ void PG::generate_backlog()
                         "version",
                         &e.version, sizeof(e.version));
     add[e.version] = e;
-    dout(10) << "generate_backlog found " << e << endl;
+    dout(10) << "generate_backlog found " << e << dendl;
   }
 
   for (map<eversion_t,Log::Entry>::reverse_iterator i = add.rbegin();
@@ -460,14 +460,14 @@ void PG::generate_backlog()
 
   dout(10) << local << " local objects, "
            << add.size() << " objects added to backlog, " 
-           << log.objects.size() << " in pg" << endl;
+           << log.objects.size() << " in pg" << dendl;
 
   //log.print(cout);
 }
 
 void PG::drop_backlog()
 {
-  dout(10) << "drop_backlog for " << log << endl;
+  dout(10) << "drop_backlog for " << log << dendl;
   //log.print(cout);
 
   assert(log.backlog);
@@ -477,7 +477,7 @@ void PG::drop_backlog()
     Log::Entry &e = *log.log.begin();
     if (e.version > log.bottom) break;
 
-    dout(15) << "drop_backlog trimming " << e.version << endl;
+    dout(15) << "drop_backlog trimming " << e.version << dendl;
     log.unindex(e);
     log.log.pop_front();
   }
@@ -489,11 +489,11 @@ void PG::drop_backlog()
 
 ostream& PG::Log::print(ostream& out) const 
 {
-  out << *this << endl;
+  out << *this << dendl;
   for (list<Entry>::const_iterator p = log.begin();
        p != log.end();
        p++) 
-    out << *p << endl;
+    out << *p << dendl;
   return out;
 }
 
@@ -522,14 +522,14 @@ void PG::build_prior()
     omap.pg_to_acting_osds(get_pgid(), acting);
     
     for (unsigned i=0; i<acting.size(); i++) {
-      //dout(10) << "build prior considering epoch " << epoch << " osd" << acting[i] << endl;
+      //dout(10) << "build prior considering epoch " << epoch << " osd" << acting[i] << dendl;
       if (osd->osdmap->is_up(acting[i]) &&  // is up now
           acting[i] != osd->whoami)         // and is not me
         prior_set.insert(acting[i]);
     }
   }
 
-  dout(10) << "build_prior built " << prior_set << endl;
+  dout(10) << "build_prior built " << prior_set << dendl;
 }
 
 void PG::adjust_prior()
@@ -546,7 +546,7 @@ void PG::adjust_prior()
   }
 
   dout(10) << "adjust_prior last_epoch_started_any " 
-           << last_epoch_started_any << " -> " << max << endl;
+           << last_epoch_started_any << " -> " << max << dendl;
   assert(max > last_epoch_started_any);
   last_epoch_started_any = max;
 
@@ -557,7 +557,7 @@ void PG::adjust_prior()
 
 void PG::clear_primary_state()
 {
-  dout(10) << "clear_primary_state" << endl;
+  dout(10) << "clear_primary_state" << dendl;
 
   // clear peering state
   have_master_log = false;
@@ -576,7 +576,7 @@ void PG::peer(ObjectStore::Transaction& t,
               map< int, map<pg_t,Query> >& query_map)
 {
   dout(10) << "peer.  acting is " << acting 
-           << ", prior_set is " << prior_set << endl;
+           << ", prior_set is " << prior_set << dendl;
 
 
   /** GET ALL PG::Info *********/
@@ -589,17 +589,17 @@ void PG::peer(ObjectStore::Transaction& t,
     if (peer_info.count(*it)) {
       dout(10) << " have info from osd" << *it 
                << ": " << peer_info[*it]
-               << endl;      
+               << dendl;      
       continue;
     }
     missing_info = true;
 
     if (peer_info_requested.count(*it)) {
-      dout(10) << " waiting for osd" << *it << endl;
+      dout(10) << " waiting for osd" << *it << dendl;
       continue;
     }
     
-    dout(10) << " querying info from osd" << *it << endl;
+    dout(10) << " querying info from osd" << *it << dendl;
     query_map[*it][info.pgid] = Query(Query::INFO, info.history);
     peer_info_requested.insert(*it);
   }
@@ -609,7 +609,7 @@ void PG::peer(ObjectStore::Transaction& t,
   // -- ok, we have all (prior_set) info.  (and maybe others.)
 
   // did we crash?
-  dout(10) << " last_epoch_started_any " << last_epoch_started_any << endl;
+  dout(10) << " last_epoch_started_any " << last_epoch_started_any << dendl;
   if (last_epoch_started_any) {
     OSDMap omap;
     osd->get_map(last_epoch_started_any, omap);
@@ -633,27 +633,27 @@ void PG::peer(ObjectStore::Transaction& t,
       for (set<int>::iterator i = last_started.begin();
            i != last_started.end();
            i++) {
-        //dout(10) << " down in epoch " << e << " is " << omap.get_down_osds() << endl;
+        //dout(10) << " down in epoch " << e << " is " << omap.get_down_osds() << dendl;
         if (omap.is_up(*i))
           still_up.insert(*i);
       }
 
       last_started.swap(still_up);
-      //dout(10) << " still active as of epoch " << e << ": " << last_started << endl;
+      //dout(10) << " still active as of epoch " << e << ": " << last_started << dendl;
     }
     
     if (last_started.empty()) {
-      dout(10) << " crashed since epoch " << last_epoch_started_any << endl;
+      dout(10) << " crashed since epoch " << last_epoch_started_any << dendl;
       state_set(STATE_CRASHED);
     } else {
-      dout(10) << " still active from last started: " << last_started << endl;
+      dout(10) << " still active from last started: " << last_started << dendl;
     }
   } else if (osd->osdmap->get_epoch() > 1) {
-    dout(10) << " crashed since epoch " << last_epoch_started_any << endl;
+    dout(10) << " crashed since epoch " << last_epoch_started_any << dendl;
     state_set(STATE_CRASHED);
   }    
 
-  dout(10) << " peers_complete_thru " << peers_complete_thru << endl;
+  dout(10) << " peers_complete_thru " << peers_complete_thru << dendl;
 
 
 
@@ -689,7 +689,7 @@ void PG::peer(ObjectStore::Transaction& t,
       dout(10) << " newest update on osd" << newest_update_osd
                << " v " << newest_update 
                << ", already queried" 
-               << endl;
+               << dendl;
     } else {
       // we'd like it back to oldest_update, but will settle for log_bottom
       eversion_t since = MAX(peer_info[newest_update_osd].log_bottom,
@@ -698,14 +698,14 @@ void PG::peer(ObjectStore::Transaction& t,
         dout(10) << " newest update on osd" << newest_update_osd
                  << " v " << newest_update 
                  << ", querying since " << since
-                 << endl;
+                 << dendl;
         query_map[newest_update_osd][info.pgid] = Query(Query::LOG, log.top, since, info.history);
         peer_log_requested.insert(newest_update_osd);
       } else {
         dout(10) << " newest update on osd" << newest_update_osd
                  << " v " << newest_update 
                  << ", querying entire summary/backlog"
-                 << endl;
+                 << dendl;
         assert((peer_info[newest_update_osd].last_complete >= 
                 peer_info[newest_update_osd].log_bottom) ||
                peer_info[newest_update_osd].log_backlog);  // or else we're in trouble.
@@ -715,10 +715,10 @@ void PG::peer(ObjectStore::Transaction& t,
     }
     return;
   } else {
-    dout(10) << " newest_update " << info.last_update << " (me)" << endl;
+    dout(10) << " newest_update " << info.last_update << " (me)" << dendl;
   }
 
-  dout(10) << " oldest_update " << oldest_update << endl;
+  dout(10) << " oldest_update " << oldest_update << dendl;
 
   have_master_log = true;
 
@@ -727,7 +727,7 @@ void PG::peer(ObjectStore::Transaction& t,
   if (oldest_update < log.bottom && !log.backlog) {
     dout(10) << "generating backlog for some peers, bottom " 
              << log.bottom << " > " << oldest_update
-             << endl;
+             << dendl;
     generate_backlog();
   }
 
@@ -746,7 +746,7 @@ void PG::peer(ObjectStore::Transaction& t,
         peer_summary_requested.count(peer)) continue;
 
     dout(10) << " pulling log+missing from osd" << peer
-             << endl;
+             << dendl;
     query_map[peer][info.pgid] = Query(Query::FULLLOG, info.history);
     peer_log_requested.insert(peer);
   }
@@ -758,17 +758,17 @@ void PG::peer(ObjectStore::Transaction& t,
     if (peer_info[peer].is_empty()) continue;
     if (peer_missing.count(peer)) continue;
     
-    dout(10) << " waiting for log+missing from osd" << peer << endl;
+    dout(10) << " waiting for log+missing from osd" << peer << dendl;
     have_missing = false;
   }
   if (!have_missing) return;
 
-  dout(10) << " peers_complete_thru " << peers_complete_thru << endl;
+  dout(10) << " peers_complete_thru " << peers_complete_thru << dendl;
 
   
   // -- ok.  and have i located all pg contents?
   if (missing.num_lost() > 0) {
-    dout(10) << "there are still " << missing.num_lost() << " lost objects" << endl;
+    dout(10) << "there are still " << missing.num_lost() << " lost objects" << dendl;
 
     // *****
     // FIXME: i don't think this actually accomplishes anything!
@@ -782,19 +782,19 @@ void PG::peer(ObjectStore::Transaction& t,
       int peer = it->first;
 
       if (peer_summary_requested.count(peer)) {
-        dout(10) << " already requested summary/backlog from osd" << peer << endl;
+        dout(10) << " already requested summary/backlog from osd" << peer << dendl;
         waiting = true;
         continue;
       }
 
-      dout(10) << " requesting summary/backlog from osd" << peer << endl;      
+      dout(10) << " requesting summary/backlog from osd" << peer << dendl;      
       query_map[peer][info.pgid] = Query(Query::BACKLOG, info.history);
       peer_summary_requested.insert(peer);
       waiting = true;
     }
     
     if (!waiting) {
-      dout(10) << missing.num_lost() << " objects are still lost, waiting+hoping for a notify from someone else!" << endl;
+      dout(10) << missing.num_lost() << " objects are still lost, waiting+hoping for a notify from someone else!" << dendl;
     }
     return;
   }
@@ -806,7 +806,7 @@ void PG::peer(ObjectStore::Transaction& t,
 
   // -- crash recovery?
   if (is_crashed()) {
-    dout(10) << "crashed, allowing op replay for " << g_conf.osd_replay_window << endl;
+    dout(10) << "crashed, allowing op replay for " << g_conf.osd_replay_window << dendl;
     state_set(STATE_REPLAY);
     osd->timer.add_event_after(g_conf.osd_replay_window,
                               new OSD::C_Activate(osd, info.pgid, osd->osdmap->get_epoch()));
@@ -849,13 +849,13 @@ void PG::activate(ObjectStore::Transaction& t)
 
   // init complete pointer
   if (info.last_complete == info.last_update) {
-    dout(10) << "activate - complete" << endl;
+    dout(10) << "activate - complete" << dendl;
     log.complete_to == log.log.end();
     log.requested_to = log.log.end();
   } 
   //else if (is_primary()) {
   else if (true) {
-    dout(10) << "activate - not complete, " << missing << ", starting recovery" << endl;
+    dout(10) << "activate - not complete, " << missing << ", starting recovery" << dendl;
     
     // init complete_to
     log.complete_to = log.log.begin();
@@ -868,7 +868,7 @@ void PG::activate(ObjectStore::Transaction& t)
     log.requested_to = log.complete_to;
     do_recovery();
   } else {
-    dout(10) << "activate - not complete, " << missing << endl;
+    dout(10) << "activate - not complete, " << missing << dendl;
   }
 
 
@@ -915,18 +915,18 @@ void PG::activate(ObjectStore::Transaction& t)
       }
       
       dout(10) << "activate sending " << m->log << " " << m->missing
-               << " to osd" << peer << endl;
+               << " to osd" << peer << dendl;
       //m->log.print(cout);
       osd->messenger->send_message(m, osd->osdmap->get_inst(peer));
 
       // update our missing
       if (peer_missing[peer].num_missing() == 0) {
-        dout(10) << "activate peer osd" << peer << " already clean, " << peer_info[peer] << endl;
+        dout(10) << "activate peer osd" << peer << " already clean, " << peer_info[peer] << dendl;
         assert(peer_info[peer].last_complete == info.last_update);
         clean_set.insert(peer);
       } else {
         dout(10) << "activate peer osd" << peer << " " << peer_info[peer]
-                 << " missing " << peer_missing[peer] << endl;
+                 << " missing " << peer_missing[peer] << dendl;
       }
             
     }
@@ -937,7 +937,7 @@ void PG::activate(ObjectStore::Transaction& t)
     // all clean?
     if (is_all_clean()) {
       state_set(STATE_CLEAN);
-      dout(10) << "activate all replicas clean" << endl;
+      dout(10) << "activate all replicas clean" << dendl;
       clean_replicas();    
     }
   }
@@ -951,7 +951,7 @@ void PG::activate(ObjectStore::Transaction& t)
          p != replay_queue.end();
          p++) {
       if (p->first <= info.last_update) {
-        dout(10) << "activate will WRNOOP " << p->first << " " << *p->second << endl;
+        dout(10) << "activate will WRNOOP " << p->first << " " << *p->second << dendl;
         replay.push_back(p->second);
         continue;
       }
@@ -959,9 +959,9 @@ void PG::activate(ObjectStore::Transaction& t)
         dout(10) << "activate replay " << p->first
                  << " skipping " << c.version+1 - p->first.version 
                  << " ops"
-                 << endl;      
+                 << dendl;      
       }
-      dout(10) << "activate replay " << p->first << " " << *p->second << endl;
+      dout(10) << "activate replay " << p->first << " " << *p->second << dendl;
       replay.push_back(p->second);
       c = p->first;
     }
@@ -979,7 +979,7 @@ void PG::activate(ObjectStore::Transaction& t)
  */
 void PG::clean_up_local(ObjectStore::Transaction& t)
 {
-  dout(10) << "clean_up_local" << endl;
+  dout(10) << "clean_up_local" << dendl;
 
   assert(info.last_update >= log.bottom);  // otherwise we need some help!
 
@@ -1004,7 +1004,7 @@ void PG::clean_up_local(ObjectStore::Transaction& t)
       if (p->is_delete()) {
         if (s.count(p->oid)) {
           dout(10) << " deleting " << p->oid
-                   << " when " << p->version << endl;
+                   << " when " << p->version << dendl;
           t.remove(p->oid);
         }
         s.erase(p->oid);
@@ -1017,7 +1017,7 @@ void PG::clean_up_local(ObjectStore::Transaction& t)
     for (set<object_t>::iterator i = s.begin(); 
          i != s.end();
          i++) {
-      dout(10) << " deleting stray " << *i << endl;
+      dout(10) << " deleting stray " << *i << dendl;
       t.remove(*i);
     }
 
@@ -1032,7 +1032,7 @@ void PG::clean_up_local(ObjectStore::Transaction& t)
 
       if (p->is_delete()) {
         dout(10) << " deleting " << p->oid
-                 << " when " << p->version << endl;
+                 << " when " << p->version << dendl;
         t.remove(p->oid);
       } else {
         // keep old(+missing) objects, just for kicks.
@@ -1059,12 +1059,12 @@ bool PG::do_recovery()
 {
   dout(-10) << "do_recovery pulling " << objects_pulling.size() << " in pg, "
            << osd->num_pulling << "/" << g_conf.osd_max_pull << " total"
-           << endl;
-  dout(10) << "do_recovery " << missing << endl;
+           << dendl;
+  dout(10) << "do_recovery " << missing << dendl;
 
   // can we slow down on this PG?
   if (osd->num_pulling >= g_conf.osd_max_pull && !objects_pulling.empty()) {
-    dout(-10) << "do_recovery already pulling max, waiting" << endl;
+    dout(-10) << "do_recovery already pulling max, waiting" << dendl;
     return true;
   }
 
@@ -1079,7 +1079,7 @@ bool PG::do_recovery()
     dout(10) << "do_recovery "
              << *log.requested_to
              << (objects_pulling.count(latest->oid) ? " (pulling)":"")
-             << endl;
+             << dendl;
 
     if (latest->is_update() &&
         !objects_pulling.count(latest->oid) &&
@@ -1092,7 +1092,7 @@ bool PG::do_recovery()
   }
 
   if (!objects_pulling.empty()) {
-    dout(7) << "do_recovery requested everything, still waiting" << endl;
+    dout(7) << "do_recovery requested everything, still waiting" << dendl;
     return false;
   }
 
@@ -1102,7 +1102,7 @@ bool PG::do_recovery()
   
   if (is_primary()) {
     // i am primary
-    dout(7) << "do_recovery complete, cleaning strays" << endl;
+    dout(7) << "do_recovery complete, cleaning strays" << dendl;
     clean_set.insert(osd->whoami);
     if (is_all_clean()) {
       state_set(PG::STATE_CLEAN);
@@ -1110,7 +1110,7 @@ bool PG::do_recovery()
     }
   } else {
     // tell primary
-    dout(7) << "do_recovery complete, telling primary" << endl;
+    dout(7) << "do_recovery complete, telling primary" << dendl;
     list<PG::Info> ls;
     ls.push_back(info);
     osd->messenger->send_message(new MOSDPGNotify(osd->osdmap->get_epoch(),
@@ -1123,7 +1123,7 @@ bool PG::do_recovery()
 
 void PG::do_peer_recovery()
 {
-  dout(10) << "do_peer_recovery" << endl;
+  dout(10) << "do_peer_recovery" << dendl;
 
   for (unsigned i=0; i<acting.size(); i++) {
     int peer = acting[i];
@@ -1155,12 +1155,12 @@ void PG::do_peer_recovery()
 
 void PG::clean_replicas()
 {
-  dout(10) << "clean_replicas.  strays are " << stray_set << endl;
+  dout(10) << "clean_replicas.  strays are " << stray_set << dendl;
   
   for (set<int>::iterator p = stray_set.begin();
        p != stray_set.end();
        p++) {
-    dout(10) << "sending PGRemove to osd" << *p << endl;
+    dout(10) << "sending PGRemove to osd" << *p << dendl;
     set<pg_t> ls;
     ls.insert(info.pgid);
     MOSDPGRemove *m = new MOSDPGRemove(osd->osdmap->get_epoch(), ls);
@@ -1174,7 +1174,7 @@ void PG::clean_replicas()
 
 void PG::write_log(ObjectStore::Transaction& t)
 {
-  dout(10) << "write_log" << endl;
+  dout(10) << "write_log" << dendl;
 
   // assemble buffer
   bufferlist bl;
@@ -1206,11 +1206,11 @@ void PG::write_log(ObjectStore::Transaction& t)
 
 void PG::trim_ondisklog_to(ObjectStore::Transaction& t, eversion_t v) 
 {
-  dout(15) << "  trim_ondisk_log_to v " << v << endl;
+  dout(15) << "  trim_ondisk_log_to v " << v << dendl;
 
   map<off_t,eversion_t>::iterator p = ondisklog.block_map.begin();
   while (p != ondisklog.block_map.end()) {
-    dout(15) << "    " << p->first << " -> " << p->second << endl;
+    dout(15) << "    " << p->first << " -> " << p->second << dendl;
     p++;
     if (p == ondisklog.block_map.end() ||
         p->second > v) {  // too far!
@@ -1218,13 +1218,13 @@ void PG::trim_ondisklog_to(ObjectStore::Transaction& t, eversion_t v)
       break;
     }
   }
-  dout(15) << "  * " << p->first << " -> " << p->second << endl;
+  dout(15) << "  * " << p->first << " -> " << p->second << dendl;
   if (p == ondisklog.block_map.begin()) 
     return;  // can't trim anything!
   
   // we can trim!
   off_t trim = p->first;
-  dout(10) << "  trimming ondisklog to [" << ondisklog.bottom << "," << ondisklog.top << ")" << endl;
+  dout(10) << "  trimming ondisklog to [" << ondisklog.bottom << "," << ondisklog.top << ")" << dendl;
 
   ondisklog.bottom = trim;
   
@@ -1240,7 +1240,7 @@ void PG::trim_ondisklog_to(ObjectStore::Transaction& t, eversion_t v)
 void PG::append_log(ObjectStore::Transaction& t, PG::Log::Entry& logentry, 
                     eversion_t trim_to)
 {
-  dout(10) << "append_log " << ondisklog.top << " " << logentry << endl;
+  dout(10) << "append_log " << ondisklog.top << " " << logentry << dendl;
 
   // write entry on disk
   bufferlist bl;
@@ -1260,13 +1260,13 @@ void PG::append_log(ObjectStore::Transaction& t, PG::Log::Entry& logentry,
   
   // trim?
   if (trim_to > log.bottom) {
-    dout(10) << " trimming " << log << " to " << trim_to << endl;
+    dout(10) << " trimming " << log << " to " << trim_to << dendl;
     log.trim(t, trim_to);
     info.log_bottom = log.bottom;
     info.log_backlog = log.backlog;
     trim_ondisklog_to(t, trim_to);
   }
-  dout(10) << " ondisklog [" << ondisklog.bottom << "," << ondisklog.top << ")" << endl;
+  dout(10) << " ondisklog [" << ondisklog.bottom << "," << ondisklog.top << ")" << dendl;
 }
 
 void PG::read_log(ObjectStore *store)
@@ -1279,7 +1279,7 @@ void PG::read_log(ObjectStore *store)
   r = store->collection_getattr(info.pgid, "ondisklog_top", &ondisklog.top, sizeof(ondisklog.top));
   assert(r == sizeof(ondisklog.top));
 
-  dout(10) << "read_log [" << ondisklog.bottom << "," << ondisklog.top << ")" << endl;
+  dout(10) << "read_log [" << ondisklog.bottom << "," << ondisklog.top << ")" << dendl;
 
   log.backlog = info.log_backlog;
   log.bottom = info.log_bottom;
@@ -1294,14 +1294,14 @@ void PG::read_log(ObjectStore *store)
     assert(log.log.empty());
     while (pos < ondisklog.top) {
       bl.copy(pos-ondisklog.bottom, sizeof(e), (char*)&e);
-      dout(10) << "read_log " << pos << " " << e << endl;
+      dout(10) << "read_log " << pos << " " << e << dendl;
 
       if (e.version > log.bottom || log.backlog) { // ignore items below log.bottom
         if (pos % 4096 == 0)
          ondisklog.block_map[pos] = e.version;
         log.log.push_back(e);
       } else {
-       dout(10) << "read_log ignoring entry at " << pos << endl;
+       dout(10) << "read_log ignoring entry at " << pos << dendl;
       }
       
       if (g_conf.osd_pad_pg_log)   // pad to 4k, until i fix ebofs reallocation crap.  FIXME.
index 0933675ae2880fab0904c018b4be0009105616fd..c406455ca540731498e55a9b569878c418651069 100644 (file)
@@ -324,6 +324,28 @@ ObjectCacher::BufferHead *ObjectCacher::Object::map_write(Objecter::OSDWrite *wr
 }
 
 
+void ObjectCacher::Object::truncate(off_t s)
+{
+  dout(10) << "truncate to " << s << endl;
+  
+  while (!data.empty()) {
+       BufferHead *bh = data.rbegin()->second;
+       if (bh->end() <= s) 
+         break;
+       
+       // split bh at truncation point?
+       if (bh->start() < s) {
+         split(bh, s);
+         continue;
+       }
+
+       // remove bh entirely
+       assert(bh->start() >= s);
+       oc->bh_remove(this, bh);
+       delete bh;
+  }
+}
+
 
 /*** ObjectCacher ***/
 
@@ -1244,7 +1266,8 @@ void ObjectCacher::purge(Object *ob)
        p != ob->data.end();
        p++) {
     BufferHead *bh = p->second;
-       dout(0) << "purge forcibly removing " << *bh << endl;
+       if (!bh->is_clean())
+         dout(0) << "purge forcibly removing " << *ob << " " << *bh << endl;
        bh_remove(ob, bh);
        delete bh;
   }
@@ -1448,6 +1471,39 @@ off_t ObjectCacher::release_set(inodeno_t ino)
   return unclean;
 }
 
+void ObjectCacher::truncate_set(inodeno_t ino, list<ObjectExtent>& exls)
+{
+  if (objects_by_ino.count(ino) == 0) {
+    dout(10) << "truncate_set on " << ino << " dne" << endl;
+    return;
+  }
+  
+  dout(10) << "truncate_set " << ino << endl;
+
+  for (list<ObjectExtent>::iterator p = exls.begin();
+          p != exls.end();
+          ++p) {
+       ObjectExtent &ex = *p;
+       if (objects.count(ex.oid) == 0) continue;
+       Object *ob = objects[ex.oid];
+
+       // purge or truncate?
+       if (ex.start == 0) {
+         dout(10) << "truncate_set purging " << *ob << endl;
+         purge(ob);
+       } else {
+         // hrm, truncate object
+         dout(10) << "truncate_set truncating " << *ob << " at " << ex.start << endl;
+         ob->truncate(ex.start);
+
+         if (ob->can_close()) {
+               dout(10) << "truncate_set trimming " << *ob << endl;
+               close_object(ob);
+         }
+       }
+  }
+}
+
 
 void ObjectCacher::kick_sync_writers(inodeno_t ino)
 {
index e9a4041008666975b7aa1ab3da0cc881e32c47d2..dbec05fa5eee930b42aa224730d10e464b35a7ba 100644 (file)
@@ -187,6 +187,7 @@ class ObjectCacher {
                  map<off_t, BufferHead*>& rx);
     BufferHead *map_write(Objecter::OSDWrite *wr);
     
+       void truncate(off_t s);
   };
   
   // ******* ObjectCacher *********
@@ -467,6 +468,8 @@ class ObjectCacher {
 
   off_t release_set(inodeno_t ino);  // returns # of bytes not released (ie non-clean)
 
+  void truncate_set(inodeno_t ino, list<ObjectExtent>& ex);
+
   void kick_sync_writers(inodeno_t ino);
   void kick_sync_readers(inodeno_t ino);
 
diff --git a/branches/sage/cephmds2/tcpfuse.cc b/branches/sage/cephmds2/tcpfuse.cc
deleted file mode 100644 (file)
index 3d7be50..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
- * Foundation.  See file COPYING.
- * 
- */
-
-
-
-#include <sys/stat.h>
-#include <iostream>
-#include <string>
-using namespace std;
-
-#include "config.h"
-
-#include "mds/MDCluster.h"
-#include "mds/MDS.h"
-#include "osd/OSD.h"
-#include "client/Client.h"
-#include "client/fuse.h"
-
-#include "msg/TCPMessenger.h"
-
-#include "common/Timer.h"
-       
-#include <envz.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-int main(int argc, char **argv, char *envp[]) {
-
-  //cerr << "tcpfuse starting " << myrank << "/" << world << endl;
-  vector<char*> args;
-  argv_to_vec(argc, argv, args);
-  parse_config_options(args);
-
-  // args for fuse
-  vec_to_argv(args, argc, argv);
-
-  // start up tcpmessenger
-  tcpaddr_t nsa;
-  if (tcpmessenger_findns(nsa) < 0) exit(1);
-  tcpmessenger_init();
-  tcpmessenger_start();
-  tcpmessenger_start_rankserver(nsa);
-  
-  Client *client = new Client(new TCPMessenger(MSG_ADDR_CLIENT_NEW));
-  client->init();
-    
-  // start up fuse
-  // use my argc, argv (make sure you pass a mount point!)
-  cout << "mounting" << endl;
-  client->mount();
-  
-  cerr << "starting fuse on pid " << getpid() << endl;
-  ceph_fuse_main(client, argc, argv);
-  cerr << "fuse finished on pid " << getpid() << endl;
-  
-  client->unmount();
-  cout << "unmounted" << endl;
-  client->shutdown();
-  
-  delete client;
-  
-  // wait for it to finish
-  tcpmessenger_wait();
-  tcpmessenger_shutdown();  // shutdown MPI
-
-  return 0;
-}
-
diff --git a/branches/sage/cephmds2/tcpsyn.cc b/branches/sage/cephmds2/tcpsyn.cc
deleted file mode 100644 (file)
index cc9f470..0000000
+++ /dev/null
@@ -1,292 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
- * Foundation.  See file COPYING.
- * 
- */
-
-
-#include <sys/stat.h>
-#include <iostream>
-#include <string>
-using namespace std;
-
-#include "config.h"
-
-#include "mds/MDCluster.h"
-#include "mds/MDS.h"
-#include "osd/OSD.h"
-#include "mon/Monitor.h"
-#include "client/Client.h"
-#include "client/SyntheticClient.h"
-
-#include "msg/TCPMessenger.h"
-
-#include "common/Timer.h"
-
-#define NUMMDS g_conf.num_mds
-#define NUMOSD g_conf.num_osd
-#define NUMCLIENT g_conf.num_client
-
-class C_Test : public Context {
-public:
-  void finish(int r) {
-    cout << "C_Test->finish(" << r << ")" << endl;
-  }
-};
-
-
-#include "msg/mpistarter.cc"
-
-utime_t tick_start;
-int tick_count = 0;
-
-class C_Tick : public Context {
-public:
-  void finish(int) {
-    utime_t now = g_clock.now() - tick_start;
-    dout(0) << "tick +" << g_conf.tick << " -> " << now << "  (" << tick_count << ")" << endl;
-    tick_count += g_conf.tick;
-    utime_t next = tick_start;
-    next.sec_ref() += tick_count;
-    g_timer.add_event_at(next, new C_Tick);
-  }
-};
-
-class C_Die : public Context {
-public:
-  void finish(int) {
-    cerr << "die" << endl;
-    exit(1);
-  }
-};
-
-class C_Debug : public Context {
-  public:
-  void finish(int) {
-    int size = &g_conf.debug_after - &g_conf.debug;
-    memcpy((char*)&g_conf.debug, (char*)&g_debug_after_conf.debug, size);
-    dout(0) << "debug_after flipping debug settings" << endl;
-  }
-};
-
-
-int main(int argc, char **argv) 
-{
-  vector<char*> args;
-  argv_to_vec(argc, argv, args);
-
-  parse_config_options(args);
-
-  parse_syn_options(args);
-
-  if (g_conf.kill_after) 
-    g_timer.add_event_after(g_conf.kill_after, new C_Die);
-  if (g_conf.debug_after) 
-    g_timer.add_event_after(g_conf.debug_after, new C_Debug);
-
-  if (g_conf.tick) {
-    tick_start = g_clock.now();
-    g_timer.add_event_after(g_conf.tick, new C_Tick);
-  }
-
-  vector<char*> nargs;
-  for (unsigned i=0; i<args.size(); i++) {
-    //cout << "a " << args[i] << endl;
-    // unknown arg, pass it on.
-    nargs.push_back(args[i]);
-  }
-
-  args = nargs;
-  if (!args.empty()) {
-    for (unsigned i=0; i<args.size(); i++)
-      cerr << "stray arg " << args[i] << endl;
-  }
-  assert(args.empty());
-
-
-  // start up tcp messenger via MPI
-  pair<int,int> mpiwho = mpi_bootstrap_tcp(argc, argv);
-  int myrank = mpiwho.first;
-  int world = mpiwho.second;
-
-  int need = 0;
-  if (g_conf.tcp_skip_rank0) need++;
-  need += NUMMDS;
-  need += NUMOSD;
-  if (NUMCLIENT) {
-    if (!g_conf.tcp_overlay_clients)
-      need += 1;
-  }
-  assert(need <= world);
-
-  if (myrank == 0)
-    cerr << "nummds " << NUMMDS << "  numosd " << NUMOSD << "  numclient " << NUMCLIENT << " .. need " << need << ", have " << world << endl;
-  
-  MDCluster *mdc = new MDCluster(NUMMDS, NUMOSD);
-
-
-  char hostname[100];
-  gethostname(hostname,100);
-  int pid = getpid();
-
-  int started = 0;
-
-  //if (myrank == 0) g_conf.debug = 20;
-  
-  // create mon
-  if (myrank == 0) {
-    Monitor *mon = new Monitor(0, new TCPMessenger(MSG_ADDR_MON(0)));
-    mon->init();
-  }
-
-  // create mds
-  MDS *mds[NUMMDS];
-  OSD *mdsosd[NUMMDS];
-  for (int i=0; i<NUMMDS; i++) {
-    if (myrank != g_conf.tcp_skip_rank0+i) continue;
-    TCPMessenger *m = new TCPMessenger(MSG_ADDR_MDS(i));
-    cerr << "mds" << i << " on tcprank " << tcpmessenger_get_rank() << " " << hostname << "." << pid << endl;
-    mds[i] = new MDS(mdc, i, m);
-    mds[i]->init();
-    started++;
-
-    if (g_conf.mds_local_osd) {
-      mdsosd[i] = new OSD(i+10000, new TCPMessenger(MSG_ADDR_OSD(i+10000)));
-      mdsosd[i]->init();                                                    
-    }
-  }
-  
-  // create osd
-  OSD *osd[NUMOSD];
-  for (int i=0; i<NUMOSD; i++) {
-    if (myrank != g_conf.tcp_skip_rank0+NUMMDS + i) continue;
-    TCPMessenger *m = new TCPMessenger(MSG_ADDR_OSD(i));
-    cerr << "osd" << i << " on tcprank " << tcpmessenger_get_rank() <<  " " << hostname << "." << pid << endl;
-    osd[i] = new OSD(i, m);
-    osd[i]->init();
-    started++;
-  }
-  
-  if (g_conf.tcp_overlay_clients) sleep(5);
-
-  // create client
-  int skip_osd = NUMOSD;
-  if (g_conf.tcp_overlay_clients) 
-    skip_osd = 0;        // put clients with osds too!
-  int client_nodes = world - NUMMDS - skip_osd - g_conf.tcp_skip_rank0;
-  int clients_per_node = 1;
-  if (NUMCLIENT) clients_per_node = (NUMCLIENT-1) / client_nodes + 1;
-  set<int> clientlist;
-  Client *client[NUMCLIENT];
-  SyntheticClient *syn[NUMCLIENT];
-  for (int i=0; i<NUMCLIENT; i++) {
-    //if (myrank != NUMMDS + NUMOSD + i % client_nodes) continue;
-    if (myrank != g_conf.tcp_skip_rank0+NUMMDS + skip_osd + i / clients_per_node) continue;
-    clientlist.insert(i);
-    client[i] = new Client(new TCPMessenger(MSG_ADDR_CLIENT_NEW));//(i)) );
-
-    // logger?
-    if (client_logger == 0) {
-      char s[80];
-      sprintf(s,"clnode.%d", myrank);
-      client_logger = new Logger(s, &client_logtype);
-
-      client_logtype.add_inc("lsum");
-      client_logtype.add_inc("lnum");
-      client_logtype.add_inc("lwsum");
-      client_logtype.add_inc("lwnum");
-      client_logtype.add_inc("lrsum");
-      client_logtype.add_inc("lrnum");
-      client_logtype.add_inc("trsum");
-      client_logtype.add_inc("trnum");
-      client_logtype.add_inc("wrlsum");
-      client_logtype.add_inc("wrlnum");
-      client_logtype.add_inc("lstatsum");
-      client_logtype.add_inc("lstatnum");
-      client_logtype.add_inc("ldirsum");
-      client_logtype.add_inc("ldirnum");
-      client_logtype.add_inc("readdir");
-      client_logtype.add_inc("stat");
-    }
-
-    client[i]->init();
-    started++;
-
-    syn[i] = new SyntheticClient(client[i]);
-  }
-
-  if (!clientlist.empty()) dout(2) << "i have " << clientlist << endl;
-
-  int nclients = 0;
-  for (set<int>::iterator it = clientlist.begin();
-       it != clientlist.end();
-       it++) {
-    int i = *it;
-
-    //cerr << "starting synthetic client" << i << " on rank " << myrank << endl;
-    client[i]->mount();
-    syn[i]->start_thread();
-    
-    nclients++;
-  }
-  if (nclients) {
-    cerr << nclients << " clients on tcprank " << tcpmessenger_get_rank() << " " << hostname << "." << pid << endl;
-  }
-
-  for (set<int>::iterator it = clientlist.begin();
-       it != clientlist.end();
-       it++) {
-    int i = *it;
-
-    //      cout << "waiting for synthetic client" << i << " to finish" << endl;
-    syn[i]->join_thread();
-    delete syn[i];
-    
-    client[i]->unmount();
-    //cout << "client" << i << " unmounted" << endl;
-    client[i]->shutdown();
-  }
-  
-
-  if (myrank && !started) {
-    //dout(1) << "IDLE" << endl;
-    cerr << "idle on tcprank " << tcpmessenger_get_rank() << " " << hostname << "." << pid << endl; 
-    tcpmessenger_stop_rankserver();
-  }
-
-  // wait for everything to finish
-  tcpmessenger_wait();
-
-  if (started) cerr << "tcpsyn finishing" << endl;
-  
-  tcpmessenger_shutdown(); 
-  
-
-  /*
-  // cleanup
-  for (int i=0; i<NUMMDS; i++) {
-    if (myrank != MPI_DEST_TO_RANK(MSG_ADDR_MDS(i),world)) continue;
-    delete mds[i];
-  }
-  for (int i=0; i<NUMOSD; i++) {
-    if (myrank != MPI_DEST_TO_RANK(MSG_ADDR_OSD(i),world)) continue;
-    delete osd[i];
-  }
-  for (int i=0; i<NUMCLIENT; i++) {
-    if (myrank != MPI_DEST_TO_RANK(MSG_ADDR_CLIENT(i),world)) continue;
-    delete client[i];
-  }
-  */
-  delete mdc;
-
-  
-  return 0;
-}
-