]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
merged trunk changes r1068:1083 into branches/riccardo/monitor2
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Thu, 8 Feb 2007 03:29:55 +0000 (03:29 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Thu, 8 Feb 2007 03:29:55 +0000 (03:29 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1084 29311d96-e01e-0410-9327-a35deaab8ce9

21 files changed:
branches/riccardo/monitor2/Makefile
branches/riccardo/monitor2/client/Client.cc
branches/riccardo/monitor2/client/Client.h
branches/riccardo/monitor2/client/fuse.cc
branches/riccardo/monitor2/ebofs/BufferCache.cc
branches/riccardo/monitor2/ebofs/BufferCache.h
branches/riccardo/monitor2/ebofs/Ebofs.cc
branches/riccardo/monitor2/ebofs/Ebofs.h
branches/riccardo/monitor2/messages/MClientBoot.h
branches/riccardo/monitor2/messages/MMonElectionAck.h
branches/riccardo/monitor2/messages/MMonElectionPropose.h
branches/riccardo/monitor2/messages/MMonElectionVictory.h
branches/riccardo/monitor2/mkmonmap.cc
branches/riccardo/monitor2/mon/Elector.cc
branches/riccardo/monitor2/mon/Monitor.cc
branches/riccardo/monitor2/mon/Monitor.h
branches/riccardo/monitor2/mon/OSDMonitor.cc
branches/riccardo/monitor2/msg/SimpleMessenger.cc
branches/riccardo/monitor2/msg/SimpleMessenger.h
branches/riccardo/monitor2/msg/tcp.h
branches/riccardo/monitor2/osd/ObjectStore.h

index 81fcfc0858f1aba46179b49daf9ce69df225772b..8d04bdfb425291b831b5d4672ac0a8d582d3bbcd 100644 (file)
@@ -18,9 +18,11 @@ EXTRA_CFLAGS =
 ifeq ($(target),darwin)
 # For Darwin
 CFLAGS = -g -Wall -I. -D_FILE_OFFSET_BITS=64 -DMPICH_IGNORE_CXX_SEEK -D_REENTRANT -D_THREAD_SAFE -DDARWIN -D__FreeBSD__=10 ${EXTRA_CFLAGS}
+LDINC = ar -rc
 else
 # For linux
 CFLAGS = -g -Wall -I. -D_FILE_OFFSET_BITS=64 -DMPICH_IGNORE_CXX_SEEK -D_REENTRANT -D_THREAD_SAFE 
+LDINC = ld -i -o
 endif
 
 CC = g++
@@ -78,7 +80,8 @@ MON_OBJS= \
        mon/OSDMonitor.o\
        mon/MDSMonitor.o\
        mon/ClientMonitor.o\
-       mon/Elector.o
+       mon/Elector.o\
+       mon/MonitorStore.o
 
 COMMON_OBJS= \
        msg/Messenger.o\
@@ -177,7 +180,7 @@ test.ebofs: ebofs/test.ebofs.cc config.cc common/Clock.o ebofs.o
 
 # libceph
 libceph.o: client/ldceph.o client/Client.o ${COMMON_OBJS} ${SYN_OBJS} ${OSDC_OBJS}
-       ar -rc $@ $^
+       ${LDINC} $@ $^
 
 bench/mdtest/mdtest.o: bench/mdtest/mdtest.c
        mpicc -c $^ -o $@
@@ -197,28 +200,28 @@ clean:
        rm -f *.o */*.o ${TARGETS} ${TEST_TARGETS}
 
 common.o: ${COMMON_OBJS}
-       ar -rc $@ $^
+       ${LDINC} $@ $^
 
 ebofs.o: ${EBOFS_OBJS}
-       ar -rc $@ $^
+       ${LDINC} $@ $^
 
 client.o: ${CLIENT_OBJS} 
-       ar -rc $@ $^
+       ${LDINC} $@ $^
 
 osd.o: ${OSD_OBJS}
-       ar -rc $@ $^
+       ${LDINC} $@ $^
 
 osdc.o: ${OSDC_OBJS}
-       ar -rc $@ $^
+       ${LDINC} $@ $^
 
 osd_obfs.o: osd/OBFSStore.o osd/OSD.cc osd/PG.o osd/ObjectStore.o osd/FakeStore.o
        ${MPICC} -DUSE_OBFS ${MPICFLAGS} ${MPILIBS} $^ -o $@ ../uofs/uofs.o
 
 mds.o: ${MDS_OBJS}
-       ar -rc $@ $^
+       ${LDINC} $@ $^
 
 mon.o: ${MON_OBJS}
-       ar -rc $@ $^
+       ${LDINC} $@ $^
 
 %.o: %.cc
        ${CC} ${CFLAGS} -c $< -o $@
index f0a3e81427c4f2f8e5d23d76368aec47219ba02a..e71f3ed7d055058f6e4dd18e1980066055254fb5 100644 (file)
@@ -21,9 +21,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
-#ifdef DARWIN
 #include <sys/statvfs.h>
-#endif // DARWIN
 
 
 #include <iostream>
@@ -2529,7 +2527,6 @@ int Client::chdir(const char *path)
   return 0;
 }
 
-#ifdef DARWIN
 int Client::statfs(const char *path, struct statvfs *stbuf)
 {
   bzero (stbuf, sizeof (struct statvfs));
@@ -2546,13 +2543,6 @@ int Client::statfs(const char *path, struct statvfs *stbuf)
 
   return 0;
 }
-#else
-int Client::statfs(const char *path, struct statfs *stbuf) 
-{
-  assert(0);  // implement me
-  return 0;
-}
-#endif
 
 
 int Client::lazyio_propogate(int fd, off_t offset, size_t count)
index f1d90232acc18cd9f4063731b3f1d6a7293655e7..d7dd07a17adfd8d19084e55a206542ee0b09013e 100644 (file)
@@ -523,11 +523,7 @@ protected:
   int unmount();
 
   // these shoud (more or less) mirror the actual system calls.
-#ifdef DARWIN
   int statfs(const char *path, struct statvfs *stbuf);
-#else
-  int statfs(const char *path, struct statfs *stbuf);
-#endif
 
   // crap
   int chdir(const char *s);
index 94d15f9f79179305c9cc79bd6552326b107f4951..64497820f381e791bea04a96f190e8a4f692214c 100644 (file)
 #include <fcntl.h>
 #include <dirent.h>
 #include <errno.h>
-#ifdef DARWIN
 #include <sys/statvfs.h>
-#else
-#include <sys/statfs.h>
-#endif // DARWIN
 
 
 // ceph stuff
@@ -190,17 +186,10 @@ static int ceph_flush(const char *path, struct fuse_file_info *fi)
 */
 
 
-#ifdef DARWIN
 static int ceph_statfs(const char *path, struct statvfs *stbuf)
 {
   return client->statfs(path, stbuf);
 }
-#else
-static int ceph_statfs(const char *path, struct statfs *stbuf)
-{
-  return client->statfs(path, stbuf);
-}
-#endif
 
 
 
index cee7f2c12ce79789d82e1da4fe9265d163c55264..fa48c08b18a09122a11265ecf4750e1e52d26145 100644 (file)
@@ -530,6 +530,23 @@ int ObjectCache::scan_versions(block_t start, block_t len,
 }
 */
 
+void ObjectCache::touch_bottom(block_t bstart, block_t blast)
+{
+  for (map<block_t, BufferHead*>::iterator p = data.lower_bound(bstart);
+       p != data.end();
+       ++p) {
+    BufferHead *bh = p->second;
+    
+    // don't trim unless it's entirely in our range
+    if (bh->start() < bstart) continue;
+    if (bh->end() > blast) break;     
+    
+    dout(12) << "moving " << *bh << " to bottom of lru" << endl;
+    bc->touch_bottom(bh);  // move to bottom of lru list
+  }
+}  
+
+
 void ObjectCache::truncate(block_t blocks, version_t super_epoch)
 {
   dout(7) << "truncate " << object_id 
index 922c5e531ee566837b94f0f158f4f6e063fa688c..846809735103a1136a9cda707da40f65f744a3a8 100644 (file)
@@ -75,12 +75,15 @@ class BufferHead : public LRUObject {
 
   utime_t    dirty_stamp;
 
+  bool       want_to_expire;  // wants to be at bottom of lru
+
  public:
   BufferHead(ObjectCache *o) :
     oc(o), //cancellable_ioh(0), tx_epoch(0),
     rx_ioh(0), tx_ioh(0), tx_block(0), partial_tx_to(0), partial_tx_epoch(0),
     shadow_of(0),
-    ref(0), state(STATE_MISSING), epoch_modified(0), version(0), last_flushed(0)
+    ref(0), state(STATE_MISSING), epoch_modified(0), version(0), last_flushed(0),
+    want_to_expire(false)
     {}
   ~BufferHead() {
     unpin_shadows();
@@ -405,6 +408,7 @@ class ObjectCache {
                 interval_set<block_t>& alloc,
                 map<block_t, BufferHead*>& hits,
                 version_t super_epoch);   // can write to these.
+  void touch_bottom(block_t bstart, block_t blast);
 
   BufferHead *split(BufferHead *bh, block_t off);
 
@@ -509,6 +513,13 @@ class BufferCache {
     } else
       lru_rest.lru_touch(bh);
   }
+  void touch_bottom(BufferHead *bh) {
+    if (bh->is_dirty()) {
+      bh->want_to_expire = true;
+      lru_dirty.lru_bottouch(bh);
+    } else
+      lru_rest.lru_bottouch(bh);
+  }
   void remove_bh(BufferHead *bh) {
     bh->get_oc()->remove_bh(bh);
     stat_sub(bh);
@@ -586,7 +597,10 @@ class BufferCache {
     }
     if (s != BufferHead::STATE_DIRTY && bh->get_state() == BufferHead::STATE_DIRTY) {
       lru_dirty.lru_remove(bh);
-      lru_rest.lru_insert_mid(bh);
+      if (bh->want_to_expire)
+       lru_rest.lru_insert_bot(bh);
+      else
+       lru_rest.lru_insert_mid(bh);
       dirty_bh.erase(bh);
     }
 
index 64485b818e20421d40689019cb3279dcc719f94f..a190b83387385e3fbe06f2705dd8bf6a8ef9cf44 100644 (file)
@@ -1870,6 +1870,35 @@ int Ebofs::_is_cached(object_t oid, off_t off, size_t len)
   */
 }
 
+void Ebofs::trim_from_cache(object_t oid, off_t off, size_t len)
+{
+  ebofs_lock.Lock();
+  _trim_from_cache(oid, off, len);
+  ebofs_lock.Unlock();
+}
+
+void Ebofs::_trim_from_cache(object_t oid, off_t off, size_t len)
+{
+  Onode *on = 0;
+  if (onode_map.count(oid) == 0) {
+    dout(7) << "_trim_from_cache " << oid << " " << off << "~" << len << " ... onode not in cache  " << endl;
+    return; 
+  } 
+  
+  if (!on->have_oc()) 
+    return; // nothing is cached. 
+
+  // map to blocks
+  block_t bstart = off / EBOFS_BLOCK_SIZE;
+  block_t blast = (len+off-1) / EBOFS_BLOCK_SIZE;
+
+  ObjectCache *oc = on->get_oc(&bc);
+  oc->touch_bottom(bstart, blast);
+  
+  return;
+}
+
+
 int Ebofs::read(object_t oid, 
                 off_t off, size_t len,
                 bufferlist& bl)
@@ -2017,6 +2046,15 @@ unsigned Ebofs::apply_transaction(Transaction& t, Context *onsafe)
       }
       break;
 
+    case Transaction::OP_TRIMCACHE:
+      {
+        object_t oid = t.oids.front(); t.oids.pop_front();
+        off_t offset = t.offsets.front(); t.offsets.pop_front();
+        size_t len = t.lengths.front(); t.lengths.pop_front();
+        _trim_from_cache(oid, offset, len);
+      }
+      break;
+
     case Transaction::OP_TRUNCATE:
       {
         object_t oid = t.oids.front(); t.oids.pop_front();
index f19130a1aab2e26810386e0e42a342c835fe1abc..bf7311e1d4c93820b3cd23cf31ea3fbdf56cdddc 100644 (file)
@@ -245,6 +245,7 @@ class Ebofs : public ObjectStore {
   int is_cached(object_t oid, off_t off, size_t len);
 
   int write(object_t oid, off_t off, size_t len, bufferlist& bl, Context *onsafe);
+  void trim_from_cache(object_t oid, off_t off, size_t len);
   int truncate(object_t oid, off_t size, Context *onsafe=0);
   int truncate_front(object_t oid, off_t size, Context *onsafe=0);
   int remove(object_t oid, Context *onsafe=0);
@@ -306,6 +307,7 @@ private:
 
   bool _write_will_block();
   int _write(object_t oid, off_t off, size_t len, bufferlist& bl);
+  void _trim_from_cache(object_t oid, off_t off, size_t len);
   int _truncate(object_t oid, off_t size);
   int _truncate_front(object_t oid, off_t size);
   int _remove(object_t oid);
index 0b73505642d7d39b1b3e969112f3ab50cb57ef0b..460f9f02e27f411050b3fecec7f0bfc8e3063467 100644 (file)
 class MClientBoot : public Message {
 
  public:
-  MClientBoot() : Message(MSG_CLIENT_BOOT) { 
-  }
+  MClientBoot() : Message(MSG_CLIENT_BOOT) { }
 
-  char *get_type_name() { return "Cboot"; }
+  char *get_type_name() { return "ClientBoot"; }
 
-  virtual void decode_payload(crope& s, int& off) {  
-  }
-  virtual void encode_payload(crope& s) {  
-  }
+  void encode_payload() { }
+  void decode_payload() { }
 };
 
 #endif
index 981e2e672a2bf18557f1ec1a6f8c400cbd4cdbcc..2399cca73d60c44f5193a3d0075880b00a7f6e86 100644 (file)
@@ -23,6 +23,9 @@ class MMonElectionAck : public Message {
   MMonElectionAck() : Message(MSG_MON_ELECTION_ACK) {}
   
   virtual char *get_type_name() { return "election_ack"; }
+
+  void encode_payload() {}
+  void decode_payload() {}
 };
 
 #endif
index b8e24499f03ec1c2aadc79b895a74ca69d30376b..d9310f222bc7b1fdfdad52ffd70667a35f2cc288 100644 (file)
@@ -23,6 +23,10 @@ class MMonElectionPropose : public Message {
   MMonElectionPropose() : Message(MSG_MON_ELECTION_PROPOSE) {}
   
   virtual char *get_type_name() { return "election_propose"; }
+
+  void encode_payload() {}
+  void decode_payload() {}
+
 };
 
 #endif
index c1faad63569927274ccc142f550d935cca94de83..8bdbf2f85a3aaa24be343412b982e69687dca30f 100644 (file)
@@ -28,15 +28,13 @@ class MMonElectionVictory : public Message {
   
   virtual char *get_type_name() { return "election_victory"; }
   
-  /*
   void encode_payload() {
-    ::_encode(active_set, payload);
+    //::_encode(active_set, payload);
   }
   void decode_payload() {
-    int off = 0;
-    ::_decode(active_set, payload, off);
+    //int off = 0;
+    //::_decode(active_set, payload, off);
   }
-  */
 };
 
 #endif
index 6d049f4bd7186eda45250c943574d78b2caa14c0..8a3e57fb86b8f171989b1f3381c18e333caddf71 100644 (file)
@@ -62,8 +62,10 @@ bool parse_ip_port(const char *s, tcpaddr_t& tcpaddr)
   }
   
   // copy into inst
+  memset(&tcpaddr, 0, sizeof(addr));
+  tcpaddr.sin_family = AF_INET;
   memcpy((char*)&tcpaddr.sin_addr.s_addr, (char*)addr, 4);
-  tcpaddr.sin_port = port;
+  tcpaddr.sin_port = htons(port);
 
   return true;
 }
@@ -88,6 +90,7 @@ int main(int argc, char **argv)
        cerr << "mkmonmap: invalid ip:port '" << args[i] << "'" << endl;
        return -1;
       }
+      
       entity_inst_t inst;
       inst.set_addr(addr);
       cout << "mkmonmap: mon" << monmap.num_mon << " " << inst << endl;
index 0084a5de9d4177b6569ffe53922d1fb1ae084168..ce424b4fad0c3b44aa6f39a95cb185a82e5727cf 100644 (file)
@@ -10,8 +10,8 @@
 
 #include "config.h"
 #undef dout
-#define  dout(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cout << "mon" << whoami << " "
-#define  derr(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cerr << "mon" << whoami << " "
+#define  derr(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cerr << g_clock.now() << " mon" << mon->whoami << (mon->is_starting() ? (const char*)"(starting)":(mon->is_leader() ? (const char*)"(leader)":(mon->is_peon() ? (const char*)"(peon)":(const char*)"(?\?)"))) << ".elector "
+#define  dout(l) if (l<=g_conf.debug || l<=g_conf.debug_mon) cout << g_clock.now() << " mon" << mon->whoami << (mon->is_starting() ? (const char*)"(starting)":(mon->is_leader() ? (const char*)"(leader)":(mon->is_peon() ? (const char*)"(peon)":(const char*)"(?\?)"))) << ".elector "
 
 
 void Elector::start()
@@ -27,7 +27,7 @@ void Elector::start()
   electing_me = true;
   
   // bcast to everyone else
-  for (unsigned i=0; i<mon->monmap->num_mon; ++i) {
+  for (int i=0; i<mon->monmap->num_mon; ++i) {
        if (i == whoami) continue;
        mon->messenger->send_message(new MMonElectionPropose,
                                                                 MSG_ADDR_MON(i), mon->monmap->get_inst(i));
@@ -38,7 +38,7 @@ void Elector::start()
 
 void Elector::defer(int who)
 {
-  dout(5) << "defer -- i'm deferring to " << who << endl;
+  dout(5) << "defer to " << who << endl;
 
   if (electing_me) {
        acked_me.clear();
@@ -86,7 +86,7 @@ void Elector::expire()
   
   // did i win?
   if (electing_me &&
-         acked_me.size() > mon->monmap->num_mon / 2) {
+         acked_me.size() > (unsigned)(mon->monmap->num_mon / 2)) {
        // i win
        victory();
   } else {
@@ -98,8 +98,11 @@ void Elector::expire()
 
 void Elector::victory()
 {
+  leader_acked = -1;
+  electing_me = false;
+
   // tell everyone
-  for (unsigned i=0; i<mon->monmap->num_mon; ++i) {
+  for (int i=0; i<mon->monmap->num_mon; ++i) {
        if (i == whoami) continue;
        mon->messenger->send_message(new MMonElectionVictory,
                                                                 MSG_ADDR_MON(i), mon->monmap->get_inst(i));
@@ -112,7 +115,7 @@ void Elector::victory()
 
 void Elector::handle_propose(MMonElectionPropose *m)
 {
-  dout(5) << "propose from " << m->get_source() << endl;
+  dout(5) << "handle_propose from " << m->get_source() << endl;
   int from = m->get_source().num();
 
   if (from > whoami) {
@@ -135,7 +138,7 @@ void Elector::handle_propose(MMonElectionPropose *m)
  
 void Elector::handle_ack(MMonElectionAck *m)
 {
-  dout(5) << "ack from " << m->get_source() << endl;
+  dout(5) << "handle_ack from " << m->get_source() << endl;
   int from = m->get_source().num();
   
   if (electing_me) {
@@ -144,7 +147,7 @@ void Elector::handle_ack(MMonElectionAck *m)
        dout(5) << " so far i have " << acked_me << endl;
        
        // is that _everyone_?
-       if (acked_me.size() == mon->monmap->num_mon) {
+       if (acked_me.size() == (unsigned)mon->monmap->num_mon) {
          // if yes, shortcut to election finish
          victory();
        }
@@ -157,7 +160,7 @@ void Elector::handle_ack(MMonElectionAck *m)
 
 void Elector::handle_victory(MMonElectionVictory *m)
 {
-  dout(5) << "victory from " << m->get_source() << endl;
+  dout(5) << "handle_victory from " << m->get_source() << endl;
   int from = m->get_source().num();
   
   if (from < whoami) {
index 66b7166bec686ceeb0f4c4bb22c2d39357750200..a0bf80de5a3a39b3eec912e27bbd6f11d5d117ad 100644 (file)
@@ -66,9 +66,15 @@ void Monitor::init()
   reset_tick();
 
   // call election?
-  assert(monmap->num_mon != 2);
-  if (monmap->num_mon >= 3) 
+  if (monmap->num_mon > 1) {
+    assert(monmap->num_mon != 2); 
     call_election();
+  } else {
+    // we're standalone.
+    set<int> q;
+    q.insert(whoami);
+    win_election(q);
+  }
 }
 
 void Monitor::shutdown()
@@ -123,7 +129,24 @@ void Monitor::call_election()
   //mdsmon->election_starting();
 }
 
+void Monitor::win_election(set<int>& active) 
+{
+  state = STATE_LEADER;
+  leader = whoami;
+  quorum = active;
+  dout(10) << "win_election, quorum is " << quorum << endl;
+
+  // init
+  osdmon->election_finished();
+  //mdsmon->election_finished();
+} 
 
+void Monitor::lose_election(int l) 
+{
+  state = STATE_PEON;
+  leader = l;
+  dout(10) << "lose_election, leader is mon" << leader << endl;
+}
 
 
 
index 7a800b9fc66c45d62cede34d22d42de67c5dd9a7..b4a30403c86508b983bfafe15aad34df3d419243 100644 (file)
@@ -86,20 +86,13 @@ protected:
   friend class MDSMonitor;
   friend class ClientMonitor;
 
-
   // initiate election
   void call_election();
 
-  // called by Elector when it's finished
-  void win_election(set<int>& active) {
-    leader = whoami;
-    quorum = active;
-    state = STATE_LEADER;
-  } 
-  void lose_election(int l) {
-    state = STATE_PEON;
-    leader = l;
-  }
+  // end election (called by Elector)
+  void win_election(set<int>& q);
+  void lose_election(int l);
+
 
  public:
   Monitor(int w, Messenger *m, MonMap *mm) : 
@@ -114,11 +107,6 @@ protected:
     leader(0),
     osdmon(0), mdsmon(0), clientmon(0)
   {
-    // hack leader, until election works.
-    if (whoami == 0)
-      state = STATE_LEADER;
-    else
-      state = STATE_PEON;
   }
 
 
index 7fafbff48b2f1d58c3437ea2357f53833284ee80..0673c9b8c254df6c068561a7c92946cfe73914c8 100644 (file)
@@ -104,13 +104,6 @@ void OSDMonitor::init()
 
     // set up pending_inc
     pending_inc.epoch = osdmap.get_epoch()+1;
-
-  } else {
-    // FIXME. when elections work!
-    if (mon->is_leader()) {
-      create_initial();
-      issue_leases();
-    }
   }
 }
 
@@ -631,10 +624,18 @@ void OSDMonitor::election_starting()
 
 void OSDMonitor::election_finished()
 {
-  dout(10) << "election_starting" << endl;
+  dout(10) << "election_finished" << endl;
 
   state = STATE_INIT;
 
+  // map?
+  if (osdmap.get_epoch() == 0 &&
+      mon->is_leader()) {
+    create_initial();
+  }
+
+
+
   if (mon->is_leader()) {
     // leader.
     if (mon->monmap->num_mon == 1) {
@@ -644,8 +645,8 @@ void OSDMonitor::election_finished()
   } 
   else if (mon->is_peon()) {
     // peon. send info
-    messenger->send_message(new MMonOSDMapInfo(osdmap.epoch, osdmap.mon_epoch),
-                           MSG_ADDR_MON(mon->leader), mon->monmap->get_inst(mon->leader));
+    //messenger->send_message(new MMonOSDMapInfo(osdmap.epoch, osdmap.mon_epoch),
+    //MSG_ADDR_MON(mon->leader), mon->monmap->get_inst(mon->leader));
   }
   
 }
index f6377e828c77d88bda66bb58da82877834f08992..ebb2fdede8ed21e3466a6d33a8dfdda790fbf633 100644 (file)
@@ -17,6 +17,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <signal.h>
 
 #include "config.h"
 
@@ -51,6 +52,23 @@ Rank rank;
  * Accepter
  */
 
+void simplemessenger_sigint(int r)
+{
+  rank.sigint();
+}
+
+void Rank::sigint()
+{
+  lock.Lock();
+  derr(0) << "got control-c, exiting" << endl;
+  ::close(accepter.listen_sd);
+  exit(-1);
+  lock.Unlock();
+}
+
+
+
+
 int Rank::Accepter::start()
 {
   // bind to a socket
@@ -66,16 +84,16 @@ int Rank::Accepter::start()
     derr(0) << "accepter.start unable to bind to " << rank.listen_addr << endl;
   assert(rc >= 0);
 
+  // what port did we get?
   socklen_t llen = sizeof(rank.listen_addr);
   getsockname(listen_sd, (sockaddr*)&rank.listen_addr, &llen);
   
-  int myport = rank.listen_addr.sin_port;
+  int myport = ntohs(rank.listen_addr.sin_port);
+  dout(10) << "accepter.start bound to port " << myport << endl;
 
   // listen!
   rc = ::listen(listen_sd, 1000);
   assert(rc >= 0);
-
-  //dout(10) << "accepter.start listening on " << myport << endl;
   
   // my address is...
   char host[100];
@@ -92,12 +110,15 @@ int Rank::Accepter::start()
   memcpy((char *) &my_addr.sin_addr.s_addr, 
          myhostname->h_addr_list[0], 
          myhostname->h_length);
-  my_addr.sin_port = myport;
+  my_addr.sin_port = htons(myport);
   
   rank.listen_addr = my_addr;
   
   dout(10) << "accepter.start listen addr is " << rank.listen_addr << endl;
 
+  // set up signal handler
+  signal(SIGINT, simplemessenger_sigint);
+
   // start thread
   create();
 
@@ -209,10 +230,14 @@ int Rank::Pipe::connect()
   assert(rc>=0);
 
   // connect!
-  rc = ::connect(sd, (sockaddr*)&peer_inst.addr, sizeof(myAddr));
-  if (rc < 0) return rc;
+  rc = ::connect(sd, (struct sockaddr*)&peer_inst.addr, sizeof(myAddr));
+  if (rc < 0) {
+    dout(10) << "connect error " << peer_inst
+            << ", " << errno << ": " << strerror(errno) << endl;
+    return rc;
+  }
 
-  // identify peer
+  // identify peer ..... FIXME
   entity_inst_t inst;
   rc = tcp_read(sd, (char*)&inst, sizeof(inst));
   if (inst.rank < 0) 
@@ -378,7 +403,9 @@ void Rank::Pipe::writer()
   if (!server) {
     int rc = connect();
     if (rc < 0) {
-      derr(1) << "pipe(" << peer_inst << ' ' << this << ").writer error connecting" << endl;
+      derr(1) << "pipe(" << peer_inst << ' ' << this << ").writer error connecting, " 
+             << errno << ": " << strerror(errno)
+             << endl;
       done = true;
       list<Message*> out;
       fail(out);
@@ -414,7 +441,9 @@ void Rank::Pipe::writer()
         
         if (write_message(m) < 0) {
           // failed!
-          derr(1) << "pipe(" << peer_inst << ' ' << this << ").writer error sending " << *m << " to " << m->get_dest() << endl;
+          derr(1) << "pipe(" << peer_inst << ' ' << this << ").writer error sending " << *m << " to " << m->get_dest()
+                 << ", " << errno << ": " << strerror(errno)
+                 << endl;
           out.push_front(m);
           fail(out);
           done = true;
index 0860f65d62cdb61cf467b19c917bc3d6c230cd4e..e2b4c4873c159a770e982401d7508179553bd645 100644 (file)
@@ -39,7 +39,10 @@ using namespace __gnu_cxx;
 /* Rank - per-process
  */
 class Rank {
+public:
+  void sigint();
+
+private:
   class EntityMessenger;
   class Pipe;
 
@@ -60,6 +63,8 @@ class Rank {
     }
     int start();
   } accepter;
+
+  void sigint(int r);
   
 
   // pipe
index f38388d456a8cadbc26c48557a2a7cf38f3755a2..65043cda8e2ace2607f663c0f5044f4b94f18d89 100644 (file)
@@ -18,7 +18,7 @@ inline ostream& operator<<(ostream& out, const tcpaddr_t &a)
       << (unsigned)addr[1] << "."
       << (unsigned)addr[2] << "."
       << (unsigned)addr[3] << ":"
-      << (int)a.sin_port;
+      << ntohs(a.sin_port);
   return out;
 }
 
index d5ba667145e34da1e0e99bf2d874b7a2225485a5..7e416494690dbc50dff33f320db6c1c087de3765 100644 (file)
@@ -84,6 +84,8 @@ public:
     static const int OP_RMATTR =       16;  // oid, attrname
     static const int OP_CLONE =        17;  // oid, newoid
 
+    static const int OP_TRIMCACHE =    18;  // oid, offset, len
+
     static const int OP_MKCOLL =       20;  // cid
     static const int OP_RMCOLL =       21;  // cid
     static const int OP_COLL_ADD =     22;  // cid, oid
@@ -142,6 +144,13 @@ public:
       lengths.push_back(len);
       bls.push_back(bl);
     }
+    void trim_from_cache(object_t oid, off_t off, size_t len) {
+      int op = OP_TRIMCACHE;
+      ops.push_back(op);
+      oids.push_back(oid);
+      offsets.push_back(off);
+      lengths.push_back(len);
+    }
     void truncate(object_t oid, off_t off) {
       int op = OP_TRUNCATE;
       ops.push_back(op);
@@ -276,6 +285,15 @@ public:
         }
         break;
 
+      case Transaction::OP_TRIMCACHE:
+        {
+          object_t oid = t.oids.front(); t.oids.pop_front();
+          off_t offset = t.offsets.front(); t.offsets.pop_front();
+          size_t len = t.lengths.front(); t.lengths.pop_front();
+          trim_from_cache(oid, offset, len);
+        }
+        break;
+
       case Transaction::OP_TRUNCATE:
         {
           object_t oid = t.oids.front(); t.oids.pop_front();
@@ -428,6 +446,8 @@ public:
                     off_t offset, size_t len,
                     bufferlist& bl, 
                     Context *onsafe) = 0;//{ return -1; }
+  virtual void trim_from_cache(object_t oid, 
+                              off_t offset, size_t len) { }
 
   virtual int setattr(object_t oid, const char *name,
                       const void *value, size_t size,