]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: Add entity_addr_t to watch_info_t and Watch
authorDavid Zafman <david.zafman@inktank.com>
Fri, 24 May 2013 00:52:46 +0000 (17:52 -0700)
committerDavid Zafman <david.zafman@inktank.com>
Thu, 6 Jun 2013 07:23:18 +0000 (00:23 -0700)
Signed-off-by: David Zafman <david.zafman@inktank.com>
src/osd/ReplicatedPG.cc
src/osd/Watch.cc
src/osd/Watch.h
src/osd/osd_types.cc
src/osd/osd_types.h

index 91241fa26cbf5569cc0b0a8333e81152a693e885..66af5c151a223f7bcad3e588bb76780842876d09 100644 (file)
@@ -2674,7 +2674,9 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
                 << " oi.version=" << oi.version.version << " ctx->at_version=" << ctx->at_version << dendl;
        dout(10) << "watch: oi.user_version=" << oi.user_version.version << dendl;
 
-       watch_info_t w(cookie, 30);  // FIXME: where does the timeout come from?
+       // FIXME: where does the timeout come from?
+       watch_info_t w(cookie, 30,
+         ctx->op->request->get_connection()->get_peer_addr());
        if (do_watch) {
          if (oi.watchers.count(make_pair(cookie, entity))) {
            dout(10) << " found existing watch " << w << " by " << entity << dendl;
@@ -3497,7 +3499,7 @@ void ReplicatedPG::do_osd_op_effects(OpContext *ctx)
               << dendl;
       watch = Watch::makeWatchRef(
        this, osd, ctx->obc, i->timeout_seconds,
-       i->cookie, entity);
+       i->cookie, entity, conn->get_peer_addr());
       ctx->obc->watchers.insert(
        make_pair(
          watcher,
@@ -4199,7 +4201,8 @@ void ReplicatedPG::populate_obc_watchers(ObjectContext *obc)
     dout(10) << "  unconnected watcher " << p->first << " will expire " << expire << dendl;
     WatchRef watch(
       Watch::makeWatchRef(
-       this, osd, obc, p->second.timeout_seconds, p->first.first, p->first.second));
+       this, osd, obc, p->second.timeout_seconds, p->first.first,
+       p->first.second, p->second.addr));
     watch->disconnect();
     obc->watchers.insert(
       make_pair(
index 07650ac470c46504f362f29273f373fd11b885e5..8a084ca9aa16e6aec8e54953d721e998c581bb69 100644 (file)
@@ -261,13 +261,15 @@ Watch::Watch(
   ObjectContext *obc,
   uint32_t timeout,
   uint64_t cookie,
-  entity_name_t entity)
+  entity_name_t entity,
+  entity_addr_t addr)
   : cb(NULL),
     osd(osd),
     pg(pg),
     obc(obc),
     timeout(timeout),
     cookie(cookie),
+    addr(addr),
     entity(entity),
     discarded(false) {
   obc->get();
@@ -426,9 +428,9 @@ void Watch::notify_ack(uint64_t notify_id)
 
 WatchRef Watch::makeWatchRef(
   ReplicatedPG *pg, OSDService *osd,
-  ObjectContext *obc, uint32_t timeout, uint64_t cookie, entity_name_t entity)
+  ObjectContext *obc, uint32_t timeout, uint64_t cookie, entity_name_t entity, entity_addr_t addr)
 {
-  WatchRef ret(new Watch(pg, osd, obc, timeout, cookie, entity));
+  WatchRef ret(new Watch(pg, osd, obc, timeout, cookie, entity, addr));
   ret->set_self(ret);
   return ret;
 }
index 089350f35bbab1b7832fb271ed62b34c76e837db..44de19ebe0e5437661dea1d4ed505c69b4e900c7 100644 (file)
@@ -155,15 +155,19 @@ class Watch {
 
   std::map<uint64_t, NotifyRef> in_progress_notifies;
 
+  // Could have watch_info_t here, but this file includes osd_types.h
   uint32_t timeout;
   uint64_t cookie;
+  entity_addr_t addr;
+
   entity_name_t entity;
   bool discarded;
 
   Watch(
     ReplicatedPG *pg, OSDService *osd,
     ObjectContext *obc, uint32_t timeout,
-    uint64_t cookie, entity_name_t entity);
+    uint64_t cookie, entity_name_t entity,
+    entity_addr_t addr);
 
   /// Registers the timeout callback with watch_timer
   void register_cb();
@@ -183,7 +187,7 @@ public:
   string gen_dbg_prefix();
   static WatchRef makeWatchRef(
     ReplicatedPG *pg, OSDService *osd,
-    ObjectContext *obc, uint32_t timeout, uint64_t cookie, entity_name_t entity);
+    ObjectContext *obc, uint32_t timeout, uint64_t cookie, entity_name_t entity, entity_addr_t addr);
   void set_self(WatchRef _self) {
     self = _self;
   }
@@ -195,6 +199,7 @@ public:
   ObjectContext *get_obc();
   uint64_t get_cookie() const { return cookie; }
   entity_name_t get_entity() const { return entity; }
+  entity_addr_t get_peer_addr() const { return addr; }
 
   /// Generates context for use if watch timeout is delayed by scrub or recovery
   Context *get_delayed_cb();
index 58f08cbed5da0703e86f9d13ad461499f4a9e3d4..7e94330be3b0f97c52e8855539cd56eaa317eeb2 100644 (file)
@@ -2478,21 +2478,25 @@ ostream& operator<<(ostream& out, const SnapSet& cs)
 
 void watch_info_t::encode(bufferlist& bl) const
 {
-  ENCODE_START(3, 3, bl);
+  ENCODE_START(4, 3, bl);
   ::encode(cookie, bl);
   ::encode(timeout_seconds, bl);
+  ::encode(addr, bl);
   ENCODE_FINISH(bl);
 }
 
 void watch_info_t::decode(bufferlist::iterator& bl)
 {
-  DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, bl);
+  DECODE_START_LEGACY_COMPAT_LEN(4, 3, 3, bl);
   ::decode(cookie, bl);
   if (struct_v < 2) {
     uint64_t ver;
     ::decode(ver, bl);
   }
   ::decode(timeout_seconds, bl);
+  if (struct_v >= 4) {
+    ::decode(addr, bl);
+  }
   DECODE_FINISH(bl);
 }
 
@@ -2500,6 +2504,9 @@ void watch_info_t::dump(Formatter *f) const
 {
   f->dump_unsigned("cookie", cookie);
   f->dump_unsigned("timeout_seconds", timeout_seconds);
+  f->open_object_section("addr");
+  addr.dump(f);
+  f->close_section();
 }
 
 void watch_info_t::generate_test_instances(list<watch_info_t*>& o)
@@ -2508,6 +2515,15 @@ void watch_info_t::generate_test_instances(list<watch_info_t*>& o)
   o.push_back(new watch_info_t);
   o.back()->cookie = 123;
   o.back()->timeout_seconds = 99;
+  entity_addr_t ea;
+  ea.set_nonce(1);
+  ea.set_family(AF_INET);
+  ea.set_in4_quad(0, 127);
+  ea.set_in4_quad(1, 0);
+  ea.set_in4_quad(2, 1);
+  ea.set_in4_quad(3, 2);
+  ea.set_port(2);
+  o.back()->addr = ea;
 }
 
 
index 44755bc7b1e44d7863fd4744611e13e2b97647ff..cb752112b31cfda84a2ff859b5ccff6c0d78d70f 100644 (file)
@@ -1742,8 +1742,10 @@ ostream& operator<<(ostream& out, const SnapSet& cs);
 struct watch_info_t {
   uint64_t cookie;
   uint32_t timeout_seconds;
+  entity_addr_t addr;
 
-  watch_info_t(uint64_t c=0, uint32_t t=0) : cookie(c), timeout_seconds(t) {}
+  watch_info_t() : cookie(0), timeout_seconds(0) { }
+  watch_info_t(uint64_t c, uint32_t t, entity_addr_t a) : cookie(c), timeout_seconds(t), addr(a) {}
 
   void encode(bufferlist& bl) const;
   void decode(bufferlist::iterator& bl);
@@ -1753,11 +1755,13 @@ struct watch_info_t {
 WRITE_CLASS_ENCODER(watch_info_t)
 
 static inline bool operator==(const watch_info_t& l, const watch_info_t& r) {
-  return l.cookie == r.cookie && l.timeout_seconds == r.timeout_seconds;
+  return l.cookie == r.cookie && l.timeout_seconds == r.timeout_seconds
+           && l.addr == r.addr;
 }
 
 static inline ostream& operator<<(ostream& out, const watch_info_t& w) {
-  return out << "watch(cookie " << w.cookie << " " << w.timeout_seconds << "s)";
+  return out << "watch(cookie " << w.cookie << " " << w.timeout_seconds << "s"
+    << " " << w.addr << ")";
 }
 
 struct notify_info_t {