@@ -167,7 +167,8 @@ rgw_rados_ref RGWSI_Notify::pick_control_obj(const string& key)
167167 return watchers[i].get_obj ();
168168}
169169
170- int RGWSI_Notify::init_watch (const DoutPrefixProvider *dpp, optional_yield y)
170+ int RGWSI_Notify::init_watch (const DoutPrefixProvider *dpp,
171+ boost::asio::yield_context yield)
171172{
172173 num_watchers = cct->_conf ->rgw_num_control_oids ;
173174
@@ -178,7 +179,7 @@ int RGWSI_Notify::init_watch(const DoutPrefixProvider *dpp, optional_yield y)
178179
179180 const size_t max_aio = cct->_conf .get_val <int64_t >(" rgw_max_control_aio" );
180181 auto throttle = ceph::async::spawn_throttle{
181- y , max_aio, ceph::async::cancel_on_error::all};
182+ yield , max_aio, ceph::async::cancel_on_error::all};
182183 watchers.reserve (num_watchers);
183184
184185 for (int i=0 ; i < num_watchers; i++) {
@@ -230,11 +231,11 @@ int RGWSI_Notify::init_watch(const DoutPrefixProvider *dpp, optional_yield y)
230231 return 0 ;
231232}
232233
233- void RGWSI_Notify::finalize_watch ()
234+ void RGWSI_Notify::finalize_watch (boost::asio::yield_context yield )
234235{
235236 const size_t max_aio = cct->_conf .get_val <int64_t >(" rgw_max_control_aio" );
236237 auto throttle = ceph::async::spawn_throttle{
237- null_yield , max_aio, ceph::async::cancel_on_error::all};
238+ yield , max_aio, ceph::async::cancel_on_error::all};
238239 for (int i = 0 ; i < num_watchers; i++) {
239240 if (!watchers_set.contains (i)) {
240241 continue ;
@@ -268,7 +269,26 @@ int RGWSI_Notify::do_start(optional_yield y, const DoutPrefixProvider *dpp)
268269
269270 control_pool = zone_svc->get_zone_params ().control_pool ;
270271
271- int ret = init_watch (dpp, y);
272+ int ret = 0 ;
273+
274+ // if we're not running in a coroutine, spawn one
275+ if (!y) {
276+ boost::asio::io_context context;
277+ boost::asio::spawn (context,
278+ [this , dpp] (boost::asio::yield_context yield) {
279+ return init_watch (dpp, yield);
280+ },
281+ [&ret] (std::exception_ptr eptr, int result) {
282+ if (eptr) {
283+ std::rethrow_exception (eptr);
284+ } else {
285+ ret = result;
286+ }
287+ });
288+ context.run ();
289+ } else {
290+ ret = init_watch (dpp, y.get_yield_context ());
291+ }
272292 if (ret < 0 ) {
273293 ldpp_dout (dpp, -1 ) << " ERROR: failed to initialize watch: " << cpp_strerror (-ret) << dendl;
274294 return ret;
@@ -291,7 +311,17 @@ void RGWSI_Notify::shutdown()
291311 if (finisher_handle) {
292312 finisher_svc->unregister_caller (*finisher_handle);
293313 }
294- finalize_watch ();
314+
315+ // we're not running in a coroutine, so spawn one
316+ boost::asio::io_context context;
317+ boost::asio::spawn (context,
318+ [this ] (boost::asio::yield_context yield) {
319+ finalize_watch (yield);
320+ },
321+ [] (std::exception_ptr eptr) {
322+ if (eptr) std::rethrow_exception (eptr);
323+ });
324+ context.run ();
295325
296326 delete shutdown_cb;
297327
0 commit comments