[Sheepdog] [PATCH 2/2] always delete data objects when deleting an cloned vdi
levin li
levin108 at gmail.com
Fri May 4 03:49:08 CEST 2012
On 05/04/2012 03:46 AM, MORITA Kazutaka wrote:
> At Mon, 23 Apr 2012 14:18:06 +0800,
> Li Wenpeng wrote:
>> From: levin li<xingke.lwp at taobao.com>
>>
>> When deleting a cloned vdi, sheep find the root vdi and then
>> traverse the vdi chain(such as base --> snapshot --> clone) to
>> check wheter there's an undeleted vdi in the chain, if some vdi
>> in the chain isn't deleted, sheep just mark the cloned vdi as
>> deleted by clear its vdi name.
>>
>> But in fact a cloned vdi may created its own objects by copy-on-write,
>> these objects can be deleted when deleting the vdi, so we make
>> the cloned vdi to be deleted as the root vdi, then we can deleting
>> its data objects, in delete_one() we check whether the object belongs
>> to itself to determine whether to delete the object.
>>
>> Signed-off-by: levin li<xingke.lwp at taobao.com>
>> ---
>> sheep/vdi.c | 14 ++++++++++++++
>> 1 files changed, 14 insertions(+), 0 deletions(-)
>>
>> diff --git a/sheep/vdi.c b/sheep/vdi.c
>> index d2a522d..c8085c8 100644
>> --- a/sheep/vdi.c
>> +++ b/sheep/vdi.c
>> @@ -478,6 +478,12 @@ static void delete_one(struct work *work)
>> if (!inode->data_vdi_id[i])
>> continue;
>>
>> + if (inode->data_vdi_id[i] != inode->vdi_id) {
>> + dprintf("object %" PRIx64 " is base's data, would not be deleted.\n",
>> + vid_to_data_oid(inode->data_vdi_id[i], i));
>> + continue;
>> + }
>> +
>> ret = remove_object(dw->entries, dw->nr_vnodes, dw->nr_zones, dw->epoch,
>> vid_to_data_oid(inode->data_vdi_id[i], i),
>> inode->nr_copies);
>> @@ -587,6 +593,14 @@ next:
>> vid_to_vdi_oid(vid), (char *)inode,
>> SD_INODE_HEADER_SIZE, 0, sys->nr_sobjs);
>>
>> + if (vid == inode->vdi_id&& inode->snap_id == 1
> What does 'inode->snap_id == 1' mean here? I think this patch is not
> correct at all.
>
> Thanks,
>
> Kazutaka
>
When inode->snap_ctime is zero, it means this can not be a snapshot.
Further more, in the current vdi chain, the base vdi that we see by
'collie vdi list' has parent id which may point to the snapshot vdi
which is the previous base vdi, in the case that an snapshot exist, the
snap_id of the current base vdi must be greater than 1.
But the cloned vdi always has a snap_id to be 1, so we can determine that
if inode->snap_id == 1 && inode->parent_vdi_id != 0 &&
!inode->snap_ctime, then
the vdi must be a cloned vdi.
thanks,
levin
>> + && inode->parent_vdi_id != 0
>> + && !inode->snap_ctime) {
>> + dprintf("vdi %" PRIx32 " is a cloned vdi.\n", vid);
>> + /* current vdi is a cloned vdi */
>> + goto out;
>> + }
>> +
>> if (ret != SD_RES_SUCCESS) {
>> eprintf("cannot find VDI object\n");
>> vid = 0;
>> --
>> 1.7.1
>>
>> --
>> sheepdog mailing list
>> sheepdog at lists.wpkg.org
>> http://lists.wpkg.org/mailman/listinfo/sheepdog
More information about the sheepdog
mailing list