From: Sage Weil Date: Fri, 10 Oct 2014 01:14:15 +0000 (-0700) Subject: librados: use new watch op codes; simplify Objecter helpers X-Git-Tag: v0.91~147 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=73720130c34424bf1fe36058ebe8da66976f40fb;p=ceph.git librados: use new watch op codes; simplify Objecter helpers - drop the useless add_watch() helper; do it explicitly - drop the unused var arg everywhere - make a separate notify member of the union that excludes the other unused fields Signed-off-by: Sage Weil --- diff --git a/src/include/rados.h b/src/include/rados.h index 9153f887dd01..80aec64f6963 100644 --- a/src/include/rados.h +++ b/src/include/rados.h @@ -487,9 +487,12 @@ struct ceph_osd_op { } __attribute__ ((packed)) snap; struct { __le64 cookie; - __le64 ver; - __u8 flag; /* 0 = unwatch, 1 = watch */ + __le64 ver; /* no longer used */ + __u8 op; /* CEPH_OSD_WATCH_OP_* */ } __attribute__ ((packed)) watch; + struct { + __le64 cookie; + } __attribute__ ((packed)) notify; struct { __le64 unused; __le64 ver; diff --git a/src/librados/IoCtxImpl.cc b/src/librados/IoCtxImpl.cc index 9cfddd5bf309..ddcbebc4636b 100644 --- a/src/librados/IoCtxImpl.cc +++ b/src/librados/IoCtxImpl.cc @@ -1052,7 +1052,7 @@ int librados::IoCtxImpl::watch(const object_t& oid, wc->watch_ctx2 = ctx2; client->register_watch_notify_callback(wc, cookie); prepare_assert_ops(&wr); - wr.watch(*cookie, 0, 1); + wr.watch(*cookie, CEPH_OSD_WATCH_OP_WATCH); bufferlist bl; wc->linger_id = objecter->linger_mutate(oid, oloc, wr, snapc, ceph_clock_now(NULL), bl, @@ -1107,7 +1107,7 @@ int librados::IoCtxImpl::unwatch(const object_t& oid, uint64_t cookie) ::ObjectOperation wr; prepare_assert_ops(&wr); - wr.watch(cookie, 0, 0); + wr.watch(cookie, CEPH_OSD_WATCH_OP_UNWATCH); objecter->mutate(oid, oloc, wr, snapc, ceph_clock_now(client->cct), 0, NULL, oncommit, &ver); lock->Unlock(); @@ -1158,7 +1158,7 @@ int librados::IoCtxImpl::notify(const object_t& oid, bufferlist& bl, // Construct RADOS op ::ObjectOperation rd; prepare_assert_ops(&rd); - rd.notify(cookie, 0, inbl); + rd.notify(cookie, inbl); // Issue RADOS op C_SaferCond onack; diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index 896bd0d1a687..d9b29ff4c0e7 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -4284,17 +4284,18 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& ops) case CEPH_OSD_OP_WATCH: ++ctx->num_write; { - tracepoint(osd, do_osd_op_pre_watch, soid.oid.name.c_str(), soid.snap.val, op.watch.cookie, op.watch.flag); + tracepoint(osd, do_osd_op_pre_watch, soid.oid.name.c_str(), soid.snap.val, + op.watch.cookie, op.watch.op); if (!obs.exists) { result = -ENOENT; break; } uint64_t cookie = op.watch.cookie; - bool do_watch = op.watch.flag & 1; entity_name_t entity = ctx->reqid.name; ObjectContextRef obc = ctx->obc; - dout(10) << "watch: ctx->obc=" << (void *)obc.get() << " cookie=" << cookie + dout(10) << "watch " << ceph_osd_watch_op_name(op.watch.op) + << ": ctx->obc=" << (void *)obc.get() << " cookie=" << cookie << " oi.version=" << oi.version.version << " ctx->at_version=" << ctx->at_version << dendl; dout(10) << "watch: oi.user_version=" << oi.user_version<< dendl; dout(10) << "watch: peer_addr=" @@ -4302,7 +4303,7 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& ops) watch_info_t w(cookie, cct->_conf->osd_client_watch_timeout, ctx->op->get_req()->get_connection()->get_peer_addr()); - if (do_watch) { + if (op.watch.op == CEPH_OSD_WATCH_OP_WATCH) { if (oi.watchers.count(make_pair(cookie, entity))) { dout(10) << " found existing watch " << w << " by " << entity << dendl; } else { @@ -4311,7 +4312,7 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& ops) t->nop(); // make sure update the object_info on disk! } ctx->watch_connects.push_back(w); - } else { + } else if (op.watch.op == CEPH_OSD_WATCH_OP_UNWATCH) { map, watch_info_t>::iterator oi_iter = oi.watchers.find(make_pair(cookie, entity)); if (oi_iter != oi.watchers.end()) { diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h index 347f7f9d8b55..9b5842056079 100644 --- a/src/osdc/Objecter.h +++ b/src/osdc/Objecter.h @@ -169,14 +169,6 @@ struct ObjectOperation { osd_op.indata.append(method, osd_op.op.cls.method_len); osd_op.indata.append(indata); } - void add_watch(int op, uint64_t cookie, uint64_t ver, uint8_t flag, bufferlist& inbl) { - OSDOp& osd_op = add_op(op); - osd_op.op.op = op; - osd_op.op.watch.cookie = cookie; - osd_op.op.watch.ver = ver; - osd_op.op.watch.flag = flag; - osd_op.indata.append(inbl); - } void add_pgls(int op, uint64_t count, collection_list_handle_t cookie, epoch_t start_epoch) { OSDOp& osd_op = add_op(op); osd_op.op.op = op; @@ -853,22 +845,26 @@ struct ObjectOperation { } // watch/notify - void watch(uint64_t cookie, uint64_t ver, bool set) { - bufferlist inbl; - add_watch(CEPH_OSD_OP_WATCH, cookie, ver, (set ? 1 : 0), inbl); + void watch(uint64_t cookie, __u8 op) { + OSDOp& osd_op = add_op(CEPH_OSD_OP_WATCH); + osd_op.op.watch.cookie = cookie; + osd_op.op.watch.op = op; } - void notify(uint64_t cookie, uint64_t ver, bufferlist& inbl) { - add_watch(CEPH_OSD_OP_NOTIFY, cookie, ver, 1, inbl); + void notify(uint64_t cookie, bufferlist& inbl) { + OSDOp& osd_op = add_op(CEPH_OSD_OP_NOTIFY); + osd_op.op.notify.cookie = cookie; + osd_op.indata.append(inbl); } void notify_ack(uint64_t notify_id, uint64_t cookie, bufferlist& reply_bl) { + OSDOp& osd_op = add_op(CEPH_OSD_OP_NOTIFY_ACK); bufferlist bl; ::encode(notify_id, bl); ::encode(cookie, bl); ::encode(reply_bl, bl); - add_watch(CEPH_OSD_OP_NOTIFY_ACK, notify_id, 0, 0, bl); + osd_op.indata.append(bl); } void list_watchers(list *out, diff --git a/src/tracing/osd.tp b/src/tracing/osd.tp index 50ca23c114c1..c1a51ed353a5 100644 --- a/src/tracing/osd.tp +++ b/src/tracing/osd.tp @@ -466,12 +466,12 @@ TRACEPOINT_EVENT(osd, do_osd_op_pre_watch, const char*, oid, uint64_t, snap, uint64_t, cookie, - uint8_t, flag), + uint8_t, op), TP_FIELDS( ctf_string(oid, oid) ctf_integer(uint64_t, snap, snap) ctf_integer(uint64_t, cookie, cookie) - ctf_integer(uint8_t, flag, flag) + ctf_integer(uint8_t, op, op) ) )