From 0bd60f8e31c08d816b9a2f76376d574ef4b7e18f Mon Sep 17 00:00:00 2001 From: David Zafman Date: Thu, 23 May 2013 17:52:46 -0700 Subject: [PATCH] osd: Add entity_addr_t to watch_info_t and Watch Signed-off-by: David Zafman --- src/osd/ReplicatedPG.cc | 9 ++++++--- src/osd/Watch.cc | 8 +++++--- src/osd/Watch.h | 9 +++++++-- src/osd/osd_types.cc | 20 ++++++++++++++++++-- src/osd/osd_types.h | 10 +++++++--- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index 91241fa26cbf5..66af5c151a223 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -2674,7 +2674,9 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& 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( diff --git a/src/osd/Watch.cc b/src/osd/Watch.cc index 07650ac470c46..8a084ca9aa16e 100644 --- a/src/osd/Watch.cc +++ b/src/osd/Watch.cc @@ -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; } diff --git a/src/osd/Watch.h b/src/osd/Watch.h index 089350f35bbab..44de19ebe0e54 100644 --- a/src/osd/Watch.h +++ b/src/osd/Watch.h @@ -155,15 +155,19 @@ class Watch { std::map 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(); diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 58f08cbed5da0..7e94330be3b0f 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -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& o) @@ -2508,6 +2515,15 @@ void watch_info_t::generate_test_instances(list& 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; } diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 44755bc7b1e44..cb752112b31cf 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -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 { -- 2.39.5