mirror of
https://github.com/ceph/ceph
synced 2025-04-01 23:02:17 +00:00
osdc/WritebackHandler: add may_copy_on_write()
Implement a new method to tell us whether a read to a particular region could be affected by a write-triggered copy-on-write. Signed-off-by: Sage Weil <sage@inktank.com>
This commit is contained in:
parent
f6d2e9a221
commit
09dc191cdf
@ -19,6 +19,10 @@ class ObjecterWriteback : public WritebackHandler {
|
||||
trunc_size, trunc_seq, onfinish);
|
||||
}
|
||||
|
||||
virtual bool may_copy_on_write(const object_t& oid, uint64_t read_off, uint64_t read_len, snapid_t snapid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual tid_t write(const object_t& oid, const object_locator_t& oloc,
|
||||
uint64_t off, uint64_t len, const SnapContext& snapc,
|
||||
const bufferlist &bl, utime_t mtime, uint64_t trunc_size,
|
||||
|
@ -86,6 +86,29 @@ namespace librbd {
|
||||
return ++m_tid;
|
||||
}
|
||||
|
||||
bool LibrbdWriteback::may_copy_on_write(const object_t& oid, uint64_t read_off, uint64_t read_len, snapid_t snapid)
|
||||
{
|
||||
m_ictx->snap_lock.Lock();
|
||||
librados::snap_t snap_id = m_ictx->snap_id;
|
||||
m_ictx->parent_lock.Lock();
|
||||
uint64_t overlap = 0;
|
||||
m_ictx->get_parent_overlap(snap_id, &overlap);
|
||||
m_ictx->parent_lock.Unlock();
|
||||
m_ictx->snap_lock.Unlock();
|
||||
|
||||
uint64_t object_no = oid_to_object_no(oid.name, m_ictx->object_prefix);
|
||||
|
||||
// reverse map this object extent onto the parent
|
||||
vector<pair<uint64_t,uint64_t> > objectx;
|
||||
Striper::extent_to_file(m_ictx->cct, &m_ictx->layout,
|
||||
object_no, 0, m_ictx->layout.fl_object_size,
|
||||
objectx);
|
||||
uint64_t object_overlap = m_ictx->prune_parent_extents(objectx, overlap);
|
||||
bool may = object_overlap > 0;
|
||||
ldout(m_ictx->cct, 10) << "may_copy_on_write " << oid << " " << read_off << "~" << read_len << " = " << may << dendl;
|
||||
return may;
|
||||
}
|
||||
|
||||
tid_t LibrbdWriteback::write(const object_t& oid,
|
||||
const object_locator_t& oloc,
|
||||
uint64_t off, uint64_t len,
|
||||
|
@ -26,6 +26,9 @@ namespace librbd {
|
||||
bufferlist *pbl, uint64_t trunc_size, __u32 trunc_seq,
|
||||
Context *onfinish);
|
||||
|
||||
// Determine whether a read to this extent could be affected by a write-triggered copy-on-write
|
||||
virtual bool may_copy_on_write(const object_t& oid, uint64_t read_off, uint64_t read_len, snapid_t snapid);
|
||||
|
||||
// Note that oloc, trunc_size, and trunc_seq are ignored
|
||||
virtual tid_t write(const object_t& oid, const object_locator_t& oloc,
|
||||
uint64_t off, uint64_t len, const SnapContext& snapc,
|
||||
|
@ -16,6 +16,18 @@ class WritebackHandler {
|
||||
uint64_t off, uint64_t len, snapid_t snapid,
|
||||
bufferlist *pbl, uint64_t trunc_size, __u32 trunc_seq,
|
||||
Context *onfinish) = 0;
|
||||
/**
|
||||
* check if a given extent read result may change due to a write
|
||||
*
|
||||
* Check if the content we see at the given read offset may change due to a write to
|
||||
* this object.
|
||||
*
|
||||
* @param oid object
|
||||
* @param read_off read offset
|
||||
* @param read_len read length
|
||||
* @param snapid read snapid
|
||||
*/
|
||||
virtual bool may_copy_on_write(const object_t& oid, uint64_t read_off, uint64_t read_len, snapid_t snapid) = 0;
|
||||
virtual tid_t write(const object_t& oid, const object_locator_t& oloc,
|
||||
uint64_t off, uint64_t len, const SnapContext& snapc,
|
||||
const bufferlist &bl, utime_t mtime, uint64_t trunc_size,
|
||||
|
Loading…
Reference in New Issue
Block a user