<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";
        mso-fareast-language:EN-US;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:"Calibri","sans-serif";}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-IN" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoPlainText">To Simplify the things I am adding the code snippet of the unchanged code.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText"><b>File:-                      VirtualDisk.py<o:p></o:p></b></p>
<p class="MsoPlainText"><b>Function:-           def  _clone_local(self, meter, size_bytes)<o:p></o:p></b></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">        zeros = '\0' * 4096<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">        src_fd, dst_fd = None, None<o:p></o:p></p>
<p class="MsoPlainText">        try:<o:p></o:p></p>
<p class="MsoPlainText">            try:<o:p></o:p></p>
<p class="MsoPlainText">                src_fd = os.open(self.clone_path, os.O_RDONLY)<o:p></o:p></p>
<p class="MsoPlainText">                dst_fd = os.open(self.path, os.O_WRONLY | os.O_CREAT)<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">                i = 0<o:p></o:p></p>
<p class="MsoPlainText">                while 1:<o:p></o:p></p>
<p class="MsoPlainText">                    l = os.read(src_fd, clone_block_size)<o:p></o:p></p>
<p class="MsoPlainText">                    s = len(l)<o:p></o:p></p>
<p class="MsoPlainText">                    if s == 0:<o:p></o:p></p>
<p class="MsoPlainText">                        meter.end(size_bytes)<o:p></o:p></p>
<p class="MsoPlainText">                        break<o:p></o:p></p>
<p class="MsoPlainText">                    # check sequence of zeros<o:p></o:p></p>
<p class="MsoPlainText"><b>                    if sparse and zeros == l:                                                                            # here sparse is false , I tried many option<o:p></o:p></b></p>
<p class="MsoPlainText">                        os.lseek(dst_fd, s, 1)<o:p></o:p></p>
<p class="MsoPlainText">                    else:<o:p></o:p></p>
<p class="MsoPlainText">                        b = os.write(dst_fd, l)<o:p></o:p></p>
<p class="MsoPlainText">                        if s != b:<o:p></o:p></p>
<p class="MsoPlainText">                            meter.end(i)<o:p></o:p></p>
<p class="MsoPlainText">                            break<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Now in above code the sparse is always false , I don’t know why ? I tried many options. Because of this the code never go in if statement and always else part gets executed  as a result
<b>os.write() </b>function call always get executed, hence the guest VM expand to full size. Can anyone  tell me why this sparse option always false? How can we make it true?<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText"><span lang="EN-US" style="mso-fareast-language:EN-IN">-----Original Message-----<br>
From: Pankaj Rawat <br>
Sent: 12 September 2012 15:43<br>
To: 'Richard W.M. Jones'<br>
Cc: 'virt-tools-list@redhat.com'<br>
Subject: RE: [virt-tools-list] Sparse in Virt-clone</span><o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Hi Richard,<o:p></o:p></p>
<p class="MsoPlainText">Thanks for the input,<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">I have mentioned In my previous mail the code snippet which is affecting the size of the cloned image, But I am not sure if this is the correct way to do this.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">I managed to get a fully working cloned VM (from virt-clone) with size even less than the original one . That is the reason I am confused about this Code change.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">And I also want to know why sparse in VolumeDisk.py  code snippet mentioned in my previous mail is initially FALSE<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Regards,<o:p></o:p></p>
<p class="MsoPlainText">Pankaj Rawat<o:p></o:p></p>
<p class="MsoPlainText">NECHCL ST<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">-----Original Message-----<o:p></o:p></p>
<p class="MsoPlainText">From: Richard W.M. Jones [mailto:rjones@redhat.com] <o:p>
</o:p></p>
<p class="MsoPlainText">Sent: 12 September 2012 15:16<o:p></o:p></p>
<p class="MsoPlainText">To: Pankaj Rawat<o:p></o:p></p>
<p class="MsoPlainText">Cc: 'virt-tools-list@redhat.com'<o:p></o:p></p>
<p class="MsoPlainText">Subject: Re: [virt-tools-list] Sparse in Virt-clone<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">On Wed, Sep 12, 2012 at 07:28:46AM +0000, Pankaj Rawat wrote:<o:p></o:p></p>
<p class="MsoPlainText">> <o:p></o:p></p>
<p class="MsoPlainText">> Hi all,<o:p></o:p></p>
<p class="MsoPlainText">> <o:p></o:p></p>
<p class="MsoPlainText">> I am trying to clone a lvm2 image following thing haapens when I clone
<o:p></o:p></p>
<p class="MsoPlainText">> a image with virt-clone command<o:p></o:p></p>
<p class="MsoPlainText">> <o:p></o:p></p>
<p class="MsoPlainText">> virt-clone --prompt --force --original  lvm_thin_1 --name  lvm_thin_2
<o:p></o:p></p>
<p class="MsoPlainText">> --file /dev/volgrp/lvm_thin2<o:p></o:p></p>
<p class="MsoPlainText">> <o:p></o:p></p>
<p class="MsoPlainText">> Now when I clone this,  It clone successfully but the cloned image is
<o:p></o:p></p>
<p class="MsoPlainText">> fully expanded ,  I mean it takes all 100% space<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">virt-clone doesn't give you much value here.  It basically makes a few changes to the libvirt XML configuration (like assigning a new name and UUID) which you could easily do yourself.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">So the real question is how to copy a thin-provisioned LV and keep it sparse.  I don't see a way to do this, but you could create a snapshot of the original using the regular tools (lvcreate).<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Rich.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">--<o:p></o:p></p>
<p class="MsoPlainText">Richard Jones, Virtualization Group, Red Hat <a href="http://people.redhat.com/~rjones">
<span style="color:windowtext;text-decoration:none">http://people.redhat.com/~rjones</span></a> New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd
<a href="http://fedoraproject.org/wiki/MinGW"><span style="color:windowtext;text-decoration:none">http://fedoraproject.org/wiki/MinGW</span></a>
<a href="http://www.annexia.org/fedora_mingw"><span style="color:windowtext;text-decoration:none">http://www.annexia.org/fedora_mingw</span></a><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>


<pre>

DISCLAIMER:

-----------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and
intended

for the named recipient(s) only. 

It shall not attach any liability on the originator or NECHCL or its

affiliates. Any views or opinions presented in 

this email are solely those of the author and may not necessarily reflect the

opinions of NECHCL or its affiliates. 

Any form of reproduction, dissemination, copying, disclosure, modification,

distribution and / or publication of 

this message without the prior written consent of the author of this e-mail is

strictly prohibited. If you have 

received this email in error please delete it and notify the sender

immediately. .

-----------------------------------------------------------------------------------------------------------------------</pre>