X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Flibrbd%2FOperations.cc;h=ffb8f5c86e9e30e6ca4b6fe0d034ca906bd404c8;hb=92f5a8d42d07f9929ae4fa7e01342fe8d96808a8;hp=642cd03a7fefa44dd0e16276cd879fbd1d7b54c7;hpb=a0324939f9d0e1905d5df8f57442f09dc70af83d;p=ceph.git diff --git a/ceph/src/librbd/Operations.cc b/ceph/src/librbd/Operations.cc index 642cd03a7..ffb8f5c86 100644 --- a/ceph/src/librbd/Operations.cc +++ b/ceph/src/librbd/Operations.cc @@ -123,7 +123,8 @@ struct C_InvokeAsyncRequest : public Context { */ I &image_ctx; - std::string request_type; + std::string name; + exclusive_lock::OperationRequestType request_type; bool permit_snapshot; boost::function local; boost::function remote; @@ -131,13 +132,14 @@ struct C_InvokeAsyncRequest : public Context { Context *on_finish; bool request_lock = false; - C_InvokeAsyncRequest(I &image_ctx, const std::string& request_type, + C_InvokeAsyncRequest(I &image_ctx, const std::string& name, + exclusive_lock::OperationRequestType request_type, bool permit_snapshot, const boost::function& local, const boost::function& remote, const std::set &filter_error_codes, Context *on_finish) - : image_ctx(image_ctx), request_type(request_type), + : image_ctx(image_ctx), name(name), request_type(request_type), permit_snapshot(permit_snapshot), local(local), remote(remote), filter_error_codes(filter_error_codes), on_finish(on_finish) { } @@ -199,7 +201,7 @@ struct C_InvokeAsyncRequest : public Context { } if (image_ctx.exclusive_lock->is_lock_owner() && - image_ctx.exclusive_lock->accept_requests()) { + image_ctx.exclusive_lock->accept_request(request_type, nullptr)) { send_local_request(); owner_lock.put_read(); return; @@ -265,8 +267,7 @@ struct C_InvokeAsyncRequest : public Context { ldout(cct, 20) << __func__ << ": r=" << r << dendl; if (r == -EOPNOTSUPP) { - ldout(cct, 5) << request_type << " not supported by current lock owner" - << dendl; + ldout(cct, 5) << name << " not supported by current lock owner" << dendl; request_lock = true; send_refresh_image(); return; @@ -277,8 +278,7 @@ struct C_InvokeAsyncRequest : public Context { return; } - ldout(cct, 5) << request_type << " timed out notifying lock owner" - << dendl; + ldout(cct, 5) << name << " timed out notifying lock owner" << dendl; send_refresh_image(); } @@ -356,7 +356,9 @@ int Operations::flatten(ProgressContext &prog_ctx) { } uint64_t request_id = ++m_async_request_seq; - r = invoke_async_request("flatten", false, + r = invoke_async_request("flatten", + exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + false, boost::bind(&Operations::execute_flatten, this, boost::ref(prog_ctx), _1), boost::bind(&ImageWatcher::notify_flatten, @@ -434,7 +436,8 @@ int Operations::rebuild_object_map(ProgressContext &prog_ctx) { } uint64_t request_id = ++m_async_request_seq; - r = invoke_async_request("rebuild object map", true, + r = invoke_async_request("rebuild object map", + exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, true, boost::bind(&Operations::execute_rebuild_object_map, this, boost::ref(prog_ctx), _1), boost::bind(&ImageWatcher::notify_rebuild_object_map, @@ -484,7 +487,8 @@ int Operations::check_object_map(ProgressContext &prog_ctx) { return r; } - r = invoke_async_request("check object map", true, + r = invoke_async_request("check object map", + exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, true, boost::bind(&Operations::check_object_map, this, boost::ref(prog_ctx), _1), [this](Context *c) { @@ -537,7 +541,9 @@ int Operations::rename(const char *dstname) { } if (m_image_ctx.test_features(RBD_FEATURE_JOURNALING)) { - r = invoke_async_request("rename", true, + r = invoke_async_request("rename", + exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + true, boost::bind(&Operations::execute_rename, this, dstname, _1), boost::bind(&ImageWatcher::notify_rename, @@ -634,7 +640,9 @@ int Operations::resize(uint64_t size, bool allow_shrink, ProgressContext& pro } uint64_t request_id = ++m_async_request_seq; - r = invoke_async_request("resize", false, + r = invoke_async_request("resize", + exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + false, boost::bind(&Operations::execute_resize, this, size, allow_shrink, boost::ref(prog_ctx), _1, 0), boost::bind(&ImageWatcher::notify_resize, @@ -726,7 +734,8 @@ void Operations::snap_create(const cls::rbd::SnapshotNamespace &snap_namespac m_image_ctx.snap_lock.put_read(); C_InvokeAsyncRequest *req = new C_InvokeAsyncRequest( - m_image_ctx, "snap_create", true, + m_image_ctx, "snap_create", exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + true, boost::bind(&Operations::execute_snap_create, this, snap_namespace, snap_name, _1, 0, false), boost::bind(&ImageWatcher::notify_snap_create, m_image_ctx.image_watcher, @@ -802,7 +811,8 @@ int Operations::snap_rollback(const cls::rbd::SnapshotNamespace& snap_namespa } } - r = prepare_image_update(false); + r = prepare_image_update(exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + false); if (r < 0) { return r; } @@ -904,8 +914,13 @@ void Operations::snap_remove(const cls::rbd::SnapshotNamespace& snap_namespac m_image_ctx.snap_lock.put_read(); if (proxy_op) { + auto request_type = exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL; + if (cls::rbd::get_snap_namespace_type(snap_namespace) == + cls::rbd::SNAPSHOT_NAMESPACE_TYPE_TRASH) { + request_type = exclusive_lock::OPERATION_REQUEST_TYPE_TRASH_SNAP_REMOVE; + } C_InvokeAsyncRequest *req = new C_InvokeAsyncRequest( - m_image_ctx, "snap_remove", true, + m_image_ctx, "snap_remove", request_type, true, boost::bind(&Operations::execute_snap_remove, this, snap_namespace, snap_name, _1), boost::bind(&ImageWatcher::notify_snap_remove, m_image_ctx.image_watcher, snap_namespace, snap_name, _1), @@ -996,7 +1011,9 @@ int Operations::snap_rename(const char *srcname, const char *dstname) { } if (m_image_ctx.test_features(RBD_FEATURE_JOURNALING)) { - r = invoke_async_request("snap_rename", true, + r = invoke_async_request("snap_rename", + exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + true, boost::bind(&Operations::execute_snap_rename, this, snap_id, dstname, _1), boost::bind(&ImageWatcher::notify_snap_rename, @@ -1095,7 +1112,9 @@ int Operations::snap_protect(const cls::rbd::SnapshotNamespace& snap_namespac } if (m_image_ctx.test_features(RBD_FEATURE_JOURNALING)) { - r = invoke_async_request("snap_protect", true, + r = invoke_async_request("snap_protect", + exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + true, boost::bind(&Operations::execute_snap_protect, this, snap_namespace, snap_name, _1), boost::bind(&ImageWatcher::notify_snap_protect, @@ -1190,7 +1209,9 @@ int Operations::snap_unprotect(const cls::rbd::SnapshotNamespace& snap_namesp } if (m_image_ctx.test_features(RBD_FEATURE_JOURNALING)) { - r = invoke_async_request("snap_unprotect", true, + r = invoke_async_request("snap_unprotect", + exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + true, boost::bind(&Operations::execute_snap_unprotect, this, snap_namespace, snap_name, _1), boost::bind(&ImageWatcher::notify_snap_unprotect, @@ -1271,7 +1292,8 @@ int Operations::snap_set_limit(uint64_t limit) { C_SaferCond limit_ctx; { RWLock::RLocker owner_lock(m_image_ctx.owner_lock); - r = prepare_image_update(true); + r = prepare_image_update(exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + true); if (r < 0) { return r; } @@ -1375,7 +1397,8 @@ int Operations::update_features(uint64_t features, bool enabled) { C_SaferCond cond_ctx; { RWLock::RLocker owner_lock(m_image_ctx.owner_lock); - r = prepare_image_update(true); + r = prepare_image_update(exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + true); if (r < 0) { return r; } @@ -1385,7 +1408,9 @@ int Operations::update_features(uint64_t features, bool enabled) { r = cond_ctx.wait(); } else { - r = invoke_async_request("update_features", false, + r = invoke_async_request("update_features", + exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + false, boost::bind(&Operations::execute_update_features, this, features, enabled, _1, 0), boost::bind(&ImageWatcher::notify_update_features, @@ -1460,7 +1485,8 @@ int Operations::metadata_set(const std::string &key, C_SaferCond metadata_ctx; { RWLock::RLocker owner_lock(m_image_ctx.owner_lock); - r = prepare_image_update(true); + r = prepare_image_update(exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + true); if (r < 0) { return r; } @@ -1521,7 +1547,8 @@ int Operations::metadata_remove(const std::string &key) { C_SaferCond metadata_ctx; { RWLock::RLocker owner_lock(m_image_ctx.owner_lock); - r = prepare_image_update(true); + r = prepare_image_update(exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + true); if (r < 0) { return r; } @@ -1583,7 +1610,9 @@ int Operations::migrate(ProgressContext &prog_ctx) { } uint64_t request_id = ++m_async_request_seq; - r = invoke_async_request("migrate", false, + r = invoke_async_request("migrate", + exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + false, boost::bind(&Operations::execute_migrate, this, boost::ref(prog_ctx), _1), boost::bind(&ImageWatcher::notify_migrate, @@ -1642,7 +1671,7 @@ template int Operations::sparsify(size_t sparse_size, ProgressContext &prog_ctx) { CephContext *cct = m_image_ctx.cct; ldout(cct, 20) << "sparsify" << dendl; - + if (sparse_size < 4096 || sparse_size > m_image_ctx.get_object_size() || (sparse_size & (sparse_size - 1)) != 0) { lderr(cct) << "sparse size should be power of two not less than 4096" @@ -1651,7 +1680,9 @@ int Operations::sparsify(size_t sparse_size, ProgressContext &prog_ctx) { } uint64_t request_id = ++m_async_request_seq; - int r = invoke_async_request("sparsify", false, + int r = invoke_async_request("sparsify", + exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, + false, boost::bind(&Operations::execute_sparsify, this, sparse_size, boost::ref(prog_ctx), _1), @@ -1689,7 +1720,8 @@ void Operations::execute_sparsify(size_t sparse_size, } template -int Operations::prepare_image_update(bool request_lock) { +int Operations::prepare_image_update( + exclusive_lock::OperationRequestType request_type, bool request_lock) { ceph_assert(m_image_ctx.owner_lock.is_locked() && !m_image_ctx.owner_lock.is_wlocked()); if (m_image_ctx.image_watcher == nullptr) { @@ -1704,7 +1736,7 @@ int Operations::prepare_image_update(bool request_lock) { RWLock::WLocker owner_locker(m_image_ctx.owner_lock); if (m_image_ctx.exclusive_lock != nullptr && (!m_image_ctx.exclusive_lock->is_lock_owner() || - !m_image_ctx.exclusive_lock->accept_requests())) { + !m_image_ctx.exclusive_lock->accept_request(request_type, nullptr))) { attempting_lock = true; m_image_ctx.exclusive_lock->block_requests(0); @@ -1741,12 +1773,12 @@ int Operations::prepare_image_update(bool request_lock) { } template -int Operations::invoke_async_request(const std::string& request_type, - bool permit_snapshot, - const boost::function& local_request, - const boost::function& remote_request) { +int Operations::invoke_async_request( + const std::string& name, exclusive_lock::OperationRequestType request_type, + bool permit_snapshot, const boost::function& local_request, + const boost::function& remote_request) { C_SaferCond ctx; - C_InvokeAsyncRequest *req = new C_InvokeAsyncRequest(m_image_ctx, + C_InvokeAsyncRequest *req = new C_InvokeAsyncRequest(m_image_ctx, name, request_type, permit_snapshot, local_request,