MCPcopy Create free account
hub / github.com/ceph/ceph / write

Method write

src/librbd/cache/ObjectCacherObjectDispatch.cc:295–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293
294template <typename I>
295bool ObjectCacherObjectDispatch<I>::write(
296 uint64_t object_no, uint64_t object_off, ceph::bufferlist&& data,
297 IOContext io_context, int op_flags, int write_flags,
298 std::optional<uint64_t> assert_version,
299 const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
300 uint64_t* journal_tid, io::DispatchResult* dispatch_result,
301 Context** on_finish, Context* on_dispatched) {
302 auto cct = m_image_ctx->cct;
303 ldout(cct, 20) << "object_no=" << object_no << " " << object_off << "~"
304 << data.length() << dendl;
305
306 // ensure we aren't holding the cache lock post-write
307 on_dispatched = util::create_async_context_callback(*m_image_ctx,
308 on_dispatched);
309
310 // cache layer does not handle version checking
311 if (assert_version.has_value() ||
312 (write_flags & io::OBJECT_WRITE_FLAG_CREATE_EXCLUSIVE) != 0) {
313 ObjectExtents object_extents;
314 object_extents.emplace_back(data_object_name(m_image_ctx, object_no),
315 object_no, object_off, data.length(), 0);
316
317 *dispatch_result = io::DISPATCH_RESULT_CONTINUE;
318
319 // ensure any in-flight writeback is complete before advancing
320 // the write request
321 std::lock_guard locker{m_cache_lock};
322 m_object_cacher->discard_writeback(m_object_set, object_extents,
323 on_dispatched);
324 return true;
325 }
326
327 SnapContext snapc;
328 if (io_context->get_write_snap_context()) {
329 auto write_snap_context = *io_context->get_write_snap_context();
330 snapc = SnapContext(write_snap_context.first,
331 {write_snap_context.second.begin(),
332 write_snap_context.second.end()});
333 }
334
335 m_image_ctx->image_lock.lock_shared();
336 ObjectCacher::OSDWrite *wr = m_object_cacher->prepare_write(
337 snapc, data, ceph::real_clock::zero(), op_flags, *journal_tid);
338 m_image_ctx->image_lock.unlock_shared();
339
340 ObjectExtent extent(data_object_name(m_image_ctx, object_no),
341 object_no, object_off, data.length(), 0);
342 extent.oloc.pool = m_image_ctx->data_ctx.get_id();
343 extent.buffer_extents.push_back({0, data.length()});
344 wr->extents.push_back(extent);
345
346 ZTracer::Trace trace(parent_trace);
347 *dispatch_result = io::DISPATCH_RESULT_COMPLETE;
348
349 std::lock_guard locker{m_cache_lock};
350 m_object_cacher->writex(wr, m_object_set, on_dispatched, &trace);
351 return true;
352}

Callers

nothing calls this directly

Calls 15

data_object_nameFunction · 0.85
discard_writebackMethod · 0.80
SnapContextClass · 0.50
lengthMethod · 0.45
has_valueMethod · 0.45
emplace_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
lock_sharedMethod · 0.45
prepare_writeMethod · 0.45

Tested by

no test coverage detected