]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: make do_osd_ops receive lvalue reference to osd ops vector 39772/head
authorXuehan Xu <xxhdx1985126@gmail.com>
Sun, 16 May 2021 15:23:19 +0000 (23:23 +0800)
committerXuehan Xu <xxhdx1985126@gmail.com>
Mon, 17 May 2021 13:49:57 +0000 (21:49 +0800)
otherwise any async execution of lambdas in PG::do_osd_ops_execute() may
reference a outdated osd_op

Signed-off-by: Xuehan Xu <xxhdx1985126@gmail.com>
src/crimson/osd/osd_operations/internal_client_request.cc
src/crimson/osd/pg.cc
src/crimson/osd/pg.h

index fcc64c545a404ed87cda5ad12ffd28d25ef26c1c..9b44695a0bc05141790833907129acbe15062873 100644 (file)
@@ -58,39 +58,41 @@ seastar::future<> InternalClientRequest::start()
               handle.enter(pp().get_obc)
             ).then_interruptible([this] () -> PG::load_obc_iertr::future<> {
               logger().debug("{}: getting obc lock", *this);
-              auto osd_ops = create_osd_ops();
-              logger().debug("InternalClientRequest: got {} OSDOps to execute",
-                             std::size(osd_ops));
-              [[maybe_unused]] const int ret = op_info.set_from_op(
-                std::as_const(osd_ops), pg->get_pgid().pgid, *pg->get_osdmap());
-              assert(ret == 0);
-              return pg->with_locked_obc(get_target_oid(), op_info,
-                [osd_ops=std::move(osd_ops), this](auto obc) {
-                return with_blocking_future_interruptible<IOInterruptCondition>(
-                  handle.enter(pp().process)
-                ).then_interruptible(
-                  [obc=std::move(obc), osd_ops=std::move(osd_ops), this] {
-                  return pg->do_osd_ops(
-                    std::move(obc),
-                    std::move(osd_ops),
-                    std::as_const(op_info),
-                    get_do_osd_ops_params(),
-                    [] {
-                      return PG::do_osd_ops_iertr::now();
-                    },
-                    [] (const std::error_code& e) {
-                      return PG::do_osd_ops_iertr::now();
-                    }
-                  ).safe_then_unpack_interruptible(
-                    [](auto submitted, auto all_completed) {
-                      return all_completed.handle_error_interruptible(
-                        crimson::ct_error::eagain::handle([] {
-                          return seastar::now();
-                        }));
-                    }, crimson::ct_error::eagain::handle([] {
-                      return interruptor::now();
-                    })
-                  );
+              return seastar::do_with(create_osd_ops(),
+                [this](auto& osd_ops) mutable {
+                logger().debug("InternalClientRequest: got {} OSDOps to execute",
+                               std::size(osd_ops));
+                [[maybe_unused]] const int ret = op_info.set_from_op(
+                  std::as_const(osd_ops), pg->get_pgid().pgid, *pg->get_osdmap());
+                assert(ret == 0);
+                return pg->with_locked_obc(get_target_oid(), op_info,
+                  [&osd_ops, this](auto obc) {
+                  return with_blocking_future_interruptible<IOInterruptCondition>(
+                    handle.enter(pp().process)
+                  ).then_interruptible(
+                    [obc=std::move(obc), &osd_ops, this] {
+                    return pg->do_osd_ops(
+                      std::move(obc),
+                      osd_ops,
+                      std::as_const(op_info),
+                      get_do_osd_ops_params(),
+                      [] {
+                        return PG::do_osd_ops_iertr::now();
+                      },
+                      [] (const std::error_code& e) {
+                        return PG::do_osd_ops_iertr::now();
+                      }
+                    ).safe_then_unpack_interruptible(
+                      [](auto submitted, auto all_completed) {
+                        return all_completed.handle_error_interruptible(
+                          crimson::ct_error::eagain::handle([] {
+                            return seastar::now();
+                          }));
+                      }, crimson::ct_error::eagain::handle([] {
+                        return interruptor::now();
+                      })
+                    );
+                  });
                 });
               });
             }).handle_error_interruptible(PG::load_obc_ertr::all_same_way([] {
index 3ff19636d78290dcecc42c9caead46a92b420ff3..04f33c53b9b28005610aca5cc85ad43df074feab 100644 (file)
@@ -705,7 +705,7 @@ template <class Ret, class SuccessFunc, class FailureFunc>
 PG::do_osd_ops_iertr::future<PG::pg_rep_op_fut_t<Ret>>
 PG::do_osd_ops_execute(
   OpsExecuter&& ox,
-  std::vector<OSDOp> ops,
+  std::vector<OSDOp>& ops,
   const OpInfo &op_info,
   SuccessFunc&& success_func,
   FailureFunc&& failure_func)
@@ -830,7 +830,7 @@ PG::do_osd_ops(
 PG::do_osd_ops_iertr::future<PG::pg_rep_op_fut_t<>>
 PG::do_osd_ops(
   ObjectContextRef obc,
-  std::vector<OSDOp> ops,
+  std::vector<OSDOp>& ops,
   const OpInfo &op_info,
   const do_osd_ops_params_t& msg_params,
   do_osd_ops_success_func_t success_func,
@@ -840,7 +840,7 @@ PG::do_osd_ops(
     std::move(obc), op_info, get_pool().info, get_backend(), msg_params);
   return do_osd_ops_execute<void>(
     std::move(*ox),
-    std::move(ops),
+    ops,
     std::as_const(op_info),
     std::move(success_func),
     std::move(failure_func)
index 45655d25e336dc825b4a4d2724faf62cef7bb6ba..d7f9afcaa8dc2ff3ab4cb23cec947c7991ad7fd0 100644 (file)
@@ -588,7 +588,7 @@ private:
   struct do_osd_ops_params_t;
   do_osd_ops_iertr::future<pg_rep_op_fut_t<>> do_osd_ops(
     ObjectContextRef obc,
-    std::vector<OSDOp> ops,
+    std::vector<OSDOp>& ops,
     const OpInfo &op_info,
     const do_osd_ops_params_t& params,
     do_osd_ops_success_func_t success_func,
@@ -596,7 +596,7 @@ private:
   template <class Ret, class SuccessFunc, class FailureFunc>
   do_osd_ops_iertr::future<pg_rep_op_fut_t<Ret>> do_osd_ops_execute(
     OpsExecuter&& ox,
-    std::vector<OSDOp> ops,
+    std::vector<OSDOp>& ops,
     const OpInfo &op_info,
     SuccessFunc&& success_func,
     FailureFunc&& failure_func);