ldout(ictx->cct, 20) << "snap_create_helper " << ictx << " " << snap_name
<< dendl;
- int r = ictx_check(ictx);
+ int r = ictx_check(ictx, true);
if (r < 0) {
return r;
}
if (r < 0)
return r;
- RWLock::RLocker l(ictx->md_lock);
+ RWLock::RLocker owner_locker(ictx->owner_lock);
+ RWLock::RLocker md_locker(ictx->md_lock);
snap_t snap_id;
{
goto err_close_child;
}
- p_imctx->md_lock.get_write();
- r = ictx_refresh(p_imctx);
- p_imctx->md_lock.put_write();
-
+ {
+ RWLock::RLocker owner_locker(p_imctx->owner_lock);
+ r = ictx_refresh(p_imctx);
+ }
if (r == 0) {
p_imctx->snap_lock.get_read();
r = p_imctx->is_snap_protected(p_imctx->snap_id, &snap_protected);
<< size << dendl;
ictx->snap_lock.put_read();
- int r = ictx_check(ictx);
+ int r = ictx_check(ictx, true);
if (r < 0) {
return r;
}
return 0;
}
- int ictx_check(ImageCtx *ictx)
+ int ictx_check(ImageCtx *ictx, bool owner_locked)
{
CephContext *cct = ictx->cct;
ldout(cct, 20) << "ictx_check " << ictx << dendl;
ictx->refresh_lock.Unlock();
if (needs_refresh) {
- RWLock::WLocker l(ictx->md_lock);
-
- int r = ictx_refresh(ictx);
+ int r;
+ if (owner_locked) {
+ r = ictx_refresh(ictx);
+ } else {
+ RWLock::RLocker owner_lock(ictx->owner_lock);
+ r = ictx_refresh(ictx);
+ }
if (r < 0) {
lderr(cct) << "Error re-reading rbd header: " << cpp_strerror(-r)
<< dendl;
int ictx_refresh(ImageCtx *ictx)
{
+ assert(ictx->owner_lock.is_locked());
+ RWLock::WLocker md_locker(ictx->md_lock);
+
CephContext *cct = ictx->cct;
bufferlist bl, bl2;
}
}
- ictx->md_lock.get_write();
- r = ictx_refresh(ictx);
- ictx->md_lock.put_write();
+ {
+ RWLock::RLocker owner_locker(ictx->owner_lock);
+ r = ictx_refresh(ictx);
+ }
if (r < 0)
goto err_close;
int r;
// ictx_check also updates parent data
- if ((r = ictx_check(ictx)) < 0) {
+ if ((r = ictx_check(ictx, true)) < 0) {
lderr(cct) << "ictx_check failed" << dendl;
return r;
}
<< " len = " << len << dendl;
// ensure previous writes are visible to listsnaps
- _flush(ictx);
+ {
+ RWLock::RLocker owner_locker(ictx->owner_lock);
+ _flush(ictx);
+ }
int r = ictx_check(ictx);
if (r < 0)
}
ictx->user_flushed();
- r = _flush(ictx);
+ {
+ RWLock::RLocker owner_locker(ictx->owner_lock);
+ r = _flush(ictx);
+ }
ictx->perfcounter->inc(l_librbd_flush);
return r;
}
int _flush(ImageCtx *ictx)
{
+ assert(ictx->owner_lock.is_locked());
CephContext *cct = ictx->cct;
int r;
// flush any outstanding writes
int add_snap(ImageCtx *ictx, const char *snap_name);
int rm_snap(ImageCtx *ictx, const char *snap_name);
int refresh_parent(ImageCtx *ictx);
- int ictx_check(ImageCtx *ictx);
+ int ictx_check(ImageCtx *ictx, bool owner_locked=false);
int ictx_refresh(ImageCtx *ictx);
int copy(ImageCtx *ictx, IoCtx& dest_md_ctx, const char *destname,
ProgressContext &prog_ctx);