LGTM

On Thu, Jun 5, 2014 at 4:53 PM, Dimitris Bliablias <[email protected]>
wrote:

> Extend the block device abstract class with two new methods, named
> 'Import' and 'Export'. Those methods will be responsible for building
> the commands which will be used for the disk data copy when we convert
> the disk template of the instance. The 'Export' method will build the
> command which will export the data from the source disk device, while
> the 'Import' will import the data to the newly created target device.
>
> By default the data import and export will be done using the Unix 'dd'
> command. All the inherited classes will use the base functionality
> unless there is a faster way to convert to. In that case the underlying
> block device can override those methods with its specific utility.
>
> Note, that those two methods will not perform the actual data copy
> between the source and target devices. Their output will be first
> concatenated using a pipe ("|"), and then executed by the caller method
> in the backend level.
>
> Signed-off-by: Dimitris Bliablias <[email protected]>
> ---
>  lib/storage/base.py |   47 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 47 insertions(+)
>
> diff --git a/lib/storage/base.py b/lib/storage/base.py
> index 8d72aa1..9d23dd2 100644
> --- a/lib/storage/base.py
> +++ b/lib/storage/base.py
> @@ -186,6 +186,53 @@ class BlockDev(object):
>      """
>      raise NotImplementedError
>
> +  def Import(self):
> +    """Builds the shell command for importing data to device.
> +
> +    This method returns the command that will be used by the caller to
> +    import data to the target device during the disk template conversion
> +    operation.
> +
> +    Block devices that provide a more efficient way to transfer their
> +    data can override this method to use their specific utility.
> +
> +    @rtype: list of strings
> +    @return: List containing the import command for device
> +
> +    """
> +    if not self.minor and not self.Attach():
> +      ThrowError("Can't attach to target device during Import()")
> +
> +    # we use the 'notrunc' argument to not attempt to truncate on the
> +    # given device
> +    return [constants.DD_CMD,
> +            "of=%s" % self.dev_path,
> +            "bs=%s" % constants.DD_BLOCK_SIZE,
> +            "oflag=direct", "conv=notrunc"]
> +
> +  def Export(self):
> +    """Builds the shell command for exporting data from device.
> +
> +    This method returns the command that will be used by the caller to
> +    export data from the source device during the disk template conversion
> +    operation.
> +
> +    Block devices that provide a more efficient way to transfer their
> +    data can override this method to use their specific utility.
> +
> +    @rtype: list of strings
> +    @return: List containing the export command for device
> +
> +    """
> +    if not self.minor and not self.Attach():
> +      ThrowError("Can't attach to source device during Import()")
> +
> +    return [constants.DD_CMD,
> +            "if=%s" % self.dev_path,
> +            "bs=%s" % constants.DD_BLOCK_SIZE,
> +            "count=%s" % self.size,
> +            "iflag=direct"]
> +
>    def SetSyncParams(self, params):
>      """Adjust the synchronization parameters of the mirror.
>
> --
> 1.7.10.4
>
>

Reply via email to