def locked_volume_operation(f):
    'Lock decorator for volume operations.\n\n    Takes a named lock prior to executing the operation. The lock is named with\n    the operation executed and the id of the volume. This lock can then be used\n    by other operations to avoid operation conflicts on shared volumes.\n\n    Example use:\n\n    If a volume operation uses this decorator, it will block until the named\n    lock is free. This is used to protect concurrent operations on the same\n    volume e.g. delete VolA while create volume VolB from VolA is in progress.\n    '

    def lvo_inner1(inst, context, volume_id, **kwargs):

        @utils.synchronized(('%s-%s' % (volume_id, f.__name__)), external=True)
        def lvo_inner2(*_args, **_kwargs):
            return f(*_args, **_kwargs)
        return lvo_inner2(inst, context, volume_id, **kwargs)
    return lvo_inner1
Lock decorator for volume operations.

Takes a named lock prior to executing the operation. The lock is named with
the operation executed and the id of the volume. This lock can then be used
by other operations to avoid operation conflicts on shared volumes.

Example use:

If a volume operation uses this decorator, it will block until the named
lock is free. This is used to protect concurrent operations on the same
volume e.g. delete VolA while create volume VolB from VolA is in progress.
def locked_volume_operation(f):
    'Lock decorator for volume operations.\n\n    Takes a named lock prior to executing the operation. The lock is named with\n    the operation executed and the id of the volume. This lock can then be used\n    by other operations to avoid operation conflicts on shared volumes.\n\n    Example use:\n\n    If a volume operation uses this decorator, it will block until the named\n    lock is free. This is used to protect concurrent operations on the same\n    volume e.g. delete VolA while create volume VolB from VolA is in progress.\n    '

    def lvo_inner1(inst, context, volume_id, **kwargs):

        @utils.synchronized(('%s-%s' % (volume_id, f.__name__)), external=True)
        def lvo_inner2(*_args, **_kwargs):
            return f(*_args, **_kwargs)
        return lvo_inner2(inst, context, volume_id, **kwargs)
    return lvo_inner1