[libvirt] [RFC PATCH 4/5] util: storagefile: Add deep copy for struct virStorageSource

Peter Krempa pkrempa at redhat.com
Fri Jun 13 12:36:31 UTC 2014


On 06/13/14 00:38, Eric Blake wrote:
> On 06/12/2014 09:02 AM, Peter Krempa wrote:
>> Now that we have pointers to store disk source information and thus can
>> easily exchange the structs behind we need a function to copy all the
>> data.
>> ---
>>  src/libvirt_private.syms  |   1 +
>>  src/util/virstoragefile.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++
>>  src/util/virstoragefile.h |   2 +
>>  3 files changed, 153 insertions(+)
>>
> 
>> +virStorageSourcePtr
>> +virStorageSourceCopy(const virStorageSource *src,
>> +                     bool backingChain)
>> +{
>> +    size_t i;
>> +    virStorageSourcePtr ret = NULL;
>> +
>> +    if (VIR_ALLOC(ret) < 0)
>> +        return NULL;
>> +
>> +    ret->type = src->type;
>> +    ret->protocol = src->protocol;
>> +    ret->format = src->format;
>> +    ret->allocation = src->allocation;
>> +    ret->capacity = src->capacity;
>> +    ret->backingRelative = src->backingRelative;
> 
> If I'm not mistaken, backingRelative disappears in your other series;
> I'm guessing you plan on rebasing that on top of this to pick up on the
> easier semantics.
> 
>> +
>> +    /* storage driver metadata are not copied */
>> +    ret->drv = NULL;
> 
> Seems okay, particularly since doing a deep copy of that would require
> callback functions in the storage drivers.

Actually I'm planning on adding reference counting to the storage driver
access data so that we will be able to initialize and de-initialize it
in a nested way. This place would also benefit from that as you'd gain a
initialized file. Not sure though whether that's feasible yet as we
don't always initialize it. For now I'll leave it this way and in the
future we might want to change it.

> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140613/9044638e/attachment-0001.sig>


More information about the libvir-list mailing list