• Alex Elder's avatar
    rbd: fix leak of snapshots during initial probe · 522a0cc0
    Alex Elder authored
    When an rbd image is initially mapped, its snapshot context is
    collected, and then a list of snapshot entries representing the
    snapshots in that context is created.  The list is created using
    rbd_dev_snaps_update().  (This function also supports updating an
    existing snapshot list based on a new snapshot context.)
    
    If an error occurs, updating the list is aborted, and the list is
    currently left as-is, in an inconsistent state.  At that point,
    there may be a partially-constructed list, but the calling functions
    (rbd_dev_probe_finish() from rbd_dev_probe() from rbd_add()) never
    clean them up.  So this constitutes a leak.
    
    A snapshot list that is inconsistent with the current snapshot
    context is of no use, and might even be actively bad.  So rather
    than just having the caller clean it up, have rbd_dev_snaps_update()
    just clear out the entire snapshot list in the event an error
    occurs.
    
    The other place rbd_dev_snaps_update() is used is when a refresh is
    triggered, either because of a watch callback or via a write to the
    /sys/bus/rbd/devices/<id>/refresh interface.  An error while
    updating the snapshots has no substantive effect in either of those
    cases, but one of them issues a warning.  Move that warning to the
    common rbd_dev_refresh() function so it gets issued regardless of
    how it got initiated.
    
    This is part of:
        http://tracker.ceph.com/issues/4803Signed-off-by: default avatarAlex Elder <elder@inktank.com>
    Reviewed-by: default avatarJosh Durgin <josh.durgin@inktank.com>
    522a0cc0
rbd.c 128 KB