Re: [PATCH 1/4] [kvm-autotest] cgroup-kvm: add_*_drive / rm_drive

2011-10-11 Thread Lucas Meneghel Rodrigues
On Mon, Oct 10, 2011 at 7:37 AM, Lukáš Doktor  wrote:
> I thought about that. But pci_add is not much stable and it's not supported
> in QMP (as far as I read) with a note that this way is buggy and should be
> rewritten completely. So I placed it here to let it develop and then I can
> move it into utils.

That is right, it was removed from QMP. Now, when the time is right I
would like to see these functions as vm object methods, just like we
did with nic hotplug.

I'm reading the patchset, but in general I'm ok with leaving these
functions in the test for now.

> Regards,
> Lukáš
>
> Dne 10.10.2011 12:26, Jiri Zupka napsal(a):
>>
>> This is useful function. This function can be in kvm utils.
>>
>> - Original Message -
>>>
>>> * functions for adding and removal of drive to vm using host-file or
>>>    host-scsi_debug device.
>>>
>>> Signed-off-by: Lukas Doktor
>>> ---
>>>  client/tests/kvm/tests/cgroup.py |  125
>>>  -
>>>  1 files changed, 108 insertions(+), 17 deletions(-)
>>>
>>> diff --git a/client/tests/kvm/tests/cgroup.py
>>> b/client/tests/kvm/tests/cgroup.py
>>> index b9a10ea..d6418b5 100644
>>> --- a/client/tests/kvm/tests/cgroup.py
>>> +++ b/client/tests/kvm/tests/cgroup.py
>>> @@ -17,6 +17,108 @@ def run_cgroup(test, params, env):
>>>      vms = None
>>>      tests = None
>>>
>>> +    # Func
>>> +    def get_device_driver():
>>> +        """
>>> +        Discovers the used block device driver {ide, scsi,
>>> virtio_blk}
>>> +        @return: Used block device driver {ide, scsi, virtio}
>>> +        """
>>> +        if test.tagged_testname.count('virtio_blk'):
>>> +            return "virtio"
>>> +        elif test.tagged_testname.count('scsi'):
>>> +            return "scsi"
>>> +        else:
>>> +            return "ide"
>>> +
>>> +
>>> +    def add_file_drive(vm, driver=get_device_driver(),
>>> host_file=None):
>>> +        """
>>> +        Hot-add a drive based on file to a vm
>>> +        @param vm: Desired VM
>>> +        @param driver: which driver should be used (default: same as
>>> in test)
>>> +        @param host_file: Which file on host is the image (default:
>>> create new)
>>> +        @return: Tupple(ret_file, device)
>>> +                    ret_file: created file handler (None if not
>>> created)
>>> +                    device: PCI id of the virtual disk
>>> +        """
>>> +        if not host_file:
>>> +            host_file =
>>> tempfile.NamedTemporaryFile(prefix="cgroup-disk-",
>>> +                                               suffix=".iso")
>>> +            utils.system("dd if=/dev/zero of=%s bs=1M count=8
>>> &>/dev/null"
>>> +                         % (host_file.name))
>>> +            ret_file = host_file
>>> +        else:
>>> +            ret_file = None
>>> +
>>> +        out = vm.monitor.cmd("pci_add auto storage
>>> file=%s,if=%s,snapshot=off,"
>>> +                             "cache=off" % (host_file.name, driver))
>>> +        dev = re.search(r'OK domain (\d+), bus (\d+), slot (\d+),
>>> function \d+',
>>> +                        out)
>>> +        if not dev:
>>> +            raise error.TestFail("Can't add device(%s, %s, %s): %s"
>>> % (vm,
>>> +                                                host_file.name,
>>> driver, out))
>>> +        device = "%s:%s:%s" % dev.groups()
>>> +        return (ret_file, device)
>>> +
>>> +
>>> +    def add_scsi_drive(vm, driver=get_device_driver(),
>>> host_file=None):
>>> +        """
>>> +        Hot-add a drive based on scsi_debug device to a vm
>>> +        @param vm: Desired VM
>>> +        @param driver: which driver should be used (default: same as
>>> in test)
>>> +        @param host_file: Which dev on host is the image (default:
>>> create new)
>>> +        @return: Tupple(ret_file, device)
>>> +                    ret_file: string of the created dev (None if not
>>> created)
>>> +                    device: PCI id of the virtual disk
>>> +        """
>>> +        if not host_file:
>>> +            if utils.system_output("lsmod | grep scsi_debug -c") ==
>>> 0:
>>> +                utils.system("modprobe scsi_debug dev_size_mb=8
>>> add_host=0")
>>> +            utils.system("echo 1>
>>> /sys/bus/pseudo/drivers/scsi_debug/add_host")
>>> +            host_file = utils.system_output("ls /dev/sd* | tail -n
>>> 1")
>>> +            # Enable idling in scsi_debug drive
>>> +            utils.system("echo 1>  /sys/block/%s/queue/rotational" %
>>> host_file)
>>> +            ret_file = host_file
>>> +        else:
>>> +            # Don't remove this device during cleanup
>>> +            # Reenable idling in scsi_debug drive (in case it's not)
>>> +            utils.system("echo 1>  /sys/block/%s/queue/rotational" %
>>> host_file)
>>> +            ret_file = None
>>> +
>>> +        out = vm.monitor.cmd("pci_add auto storage
>>> file=%s,if=%s,snapshot=off,"
>>> +                             "cache=off" % (host_file, driver))
>>> +        dev = re.search(r'OK domain (\d+), bus

Re: [PATCH 1/4] [kvm-autotest] cgroup-kvm: add_*_drive / rm_drive

2011-10-10 Thread Lukáš Doktor
I thought about that. But pci_add is not much stable and it's not 
supported in QMP (as far as I read) with a note that this way is buggy 
and should be rewritten completely. So I placed it here to let it 
develop and then I can move it into utils.


Regards,
Lukáš

Dne 10.10.2011 12:26, Jiri Zupka napsal(a):

This is useful function. This function can be in kvm utils.

- Original Message -

* functions for adding and removal of drive to vm using host-file or
host-scsi_debug device.

Signed-off-by: Lukas Doktor
---
  client/tests/kvm/tests/cgroup.py |  125
  -
  1 files changed, 108 insertions(+), 17 deletions(-)

diff --git a/client/tests/kvm/tests/cgroup.py
b/client/tests/kvm/tests/cgroup.py
index b9a10ea..d6418b5 100644
--- a/client/tests/kvm/tests/cgroup.py
+++ b/client/tests/kvm/tests/cgroup.py
@@ -17,6 +17,108 @@ def run_cgroup(test, params, env):
  vms = None
  tests = None

+# Func
+def get_device_driver():
+"""
+Discovers the used block device driver {ide, scsi,
virtio_blk}
+@return: Used block device driver {ide, scsi, virtio}
+"""
+if test.tagged_testname.count('virtio_blk'):
+return "virtio"
+elif test.tagged_testname.count('scsi'):
+return "scsi"
+else:
+return "ide"
+
+
+def add_file_drive(vm, driver=get_device_driver(),
host_file=None):
+"""
+Hot-add a drive based on file to a vm
+@param vm: Desired VM
+@param driver: which driver should be used (default: same as
in test)
+@param host_file: Which file on host is the image (default:
create new)
+@return: Tupple(ret_file, device)
+ret_file: created file handler (None if not
created)
+device: PCI id of the virtual disk
+"""
+if not host_file:
+host_file =
tempfile.NamedTemporaryFile(prefix="cgroup-disk-",
+   suffix=".iso")
+utils.system("dd if=/dev/zero of=%s bs=1M count=8
&>/dev/null"
+ % (host_file.name))
+ret_file = host_file
+else:
+ret_file = None
+
+out = vm.monitor.cmd("pci_add auto storage
file=%s,if=%s,snapshot=off,"
+ "cache=off" % (host_file.name, driver))
+dev = re.search(r'OK domain (\d+), bus (\d+), slot (\d+),
function \d+',
+out)
+if not dev:
+raise error.TestFail("Can't add device(%s, %s, %s): %s"
% (vm,
+host_file.name,
driver, out))
+device = "%s:%s:%s" % dev.groups()
+return (ret_file, device)
+
+
+def add_scsi_drive(vm, driver=get_device_driver(),
host_file=None):
+"""
+Hot-add a drive based on scsi_debug device to a vm
+@param vm: Desired VM
+@param driver: which driver should be used (default: same as
in test)
+@param host_file: Which dev on host is the image (default:
create new)
+@return: Tupple(ret_file, device)
+ret_file: string of the created dev (None if not
created)
+device: PCI id of the virtual disk
+"""
+if not host_file:
+if utils.system_output("lsmod | grep scsi_debug -c") ==
0:
+utils.system("modprobe scsi_debug dev_size_mb=8
add_host=0")
+utils.system("echo 1>
/sys/bus/pseudo/drivers/scsi_debug/add_host")
+host_file = utils.system_output("ls /dev/sd* | tail -n
1")
+# Enable idling in scsi_debug drive
+utils.system("echo 1>  /sys/block/%s/queue/rotational" %
host_file)
+ret_file = host_file
+else:
+# Don't remove this device during cleanup
+# Reenable idling in scsi_debug drive (in case it's not)
+utils.system("echo 1>  /sys/block/%s/queue/rotational" %
host_file)
+ret_file = None
+
+out = vm.monitor.cmd("pci_add auto storage
file=%s,if=%s,snapshot=off,"
+ "cache=off" % (host_file, driver))
+dev = re.search(r'OK domain (\d+), bus (\d+), slot (\d+),
function \d+',
+out)
+if not dev:
+raise error.TestFail("Can't add device(%s, %s, %s): %s"
% (vm,
+host_file,
driver, out))
+device = "%s:%s:%s" % dev.groups()
+return (ret_file, device)
+
+
+def rm_drive(vm, host_file, device):
+"""
+Remove drive from vm and device on disk
+! beware to remove scsi devices in reverse order !
+"""
+vm.monitor.cmd("pci_del %s" % device)
+
+if isinstance(host_file, file): # file
+host_file.close()
+elif isinstance(host_file, str):# scsi device
+utils.system("echo -1>
/sys/bus/pseudo/drivers/scsi_debug/add_host

Re: [PATCH 1/4] [kvm-autotest] cgroup-kvm: add_*_drive / rm_drive

2011-10-10 Thread Jiri Zupka
This is useful function. This function can be in kvm utils.

- Original Message -
> * functions for adding and removal of drive to vm using host-file or
>host-scsi_debug device.
> 
> Signed-off-by: Lukas Doktor 
> ---
>  client/tests/kvm/tests/cgroup.py |  125
>  -
>  1 files changed, 108 insertions(+), 17 deletions(-)
> 
> diff --git a/client/tests/kvm/tests/cgroup.py
> b/client/tests/kvm/tests/cgroup.py
> index b9a10ea..d6418b5 100644
> --- a/client/tests/kvm/tests/cgroup.py
> +++ b/client/tests/kvm/tests/cgroup.py
> @@ -17,6 +17,108 @@ def run_cgroup(test, params, env):
>  vms = None
>  tests = None
>  
> +# Func
> +def get_device_driver():
> +"""
> +Discovers the used block device driver {ide, scsi,
> virtio_blk}
> +@return: Used block device driver {ide, scsi, virtio}
> +"""
> +if test.tagged_testname.count('virtio_blk'):
> +return "virtio"
> +elif test.tagged_testname.count('scsi'):
> +return "scsi"
> +else:
> +return "ide"
> +
> +
> +def add_file_drive(vm, driver=get_device_driver(),
> host_file=None):
> +"""
> +Hot-add a drive based on file to a vm
> +@param vm: Desired VM
> +@param driver: which driver should be used (default: same as
> in test)
> +@param host_file: Which file on host is the image (default:
> create new)
> +@return: Tupple(ret_file, device)
> +ret_file: created file handler (None if not
> created)
> +device: PCI id of the virtual disk
> +"""
> +if not host_file:
> +host_file =
> tempfile.NamedTemporaryFile(prefix="cgroup-disk-",
> +   suffix=".iso")
> +utils.system("dd if=/dev/zero of=%s bs=1M count=8
> &>/dev/null"
> + % (host_file.name))
> +ret_file = host_file
> +else:
> +ret_file = None
> +
> +out = vm.monitor.cmd("pci_add auto storage
> file=%s,if=%s,snapshot=off,"
> + "cache=off" % (host_file.name, driver))
> +dev = re.search(r'OK domain (\d+), bus (\d+), slot (\d+),
> function \d+',
> +out)
> +if not dev:
> +raise error.TestFail("Can't add device(%s, %s, %s): %s"
> % (vm,
> +host_file.name,
> driver, out))
> +device = "%s:%s:%s" % dev.groups()
> +return (ret_file, device)
> +
> +
> +def add_scsi_drive(vm, driver=get_device_driver(),
> host_file=None):
> +"""
> +Hot-add a drive based on scsi_debug device to a vm
> +@param vm: Desired VM
> +@param driver: which driver should be used (default: same as
> in test)
> +@param host_file: Which dev on host is the image (default:
> create new)
> +@return: Tupple(ret_file, device)
> +ret_file: string of the created dev (None if not
> created)
> +device: PCI id of the virtual disk
> +"""
> +if not host_file:
> +if utils.system_output("lsmod | grep scsi_debug -c") ==
> 0:
> +utils.system("modprobe scsi_debug dev_size_mb=8
> add_host=0")
> +utils.system("echo 1 >
> /sys/bus/pseudo/drivers/scsi_debug/add_host")
> +host_file = utils.system_output("ls /dev/sd* | tail -n
> 1")
> +# Enable idling in scsi_debug drive
> +utils.system("echo 1 > /sys/block/%s/queue/rotational" %
> host_file)
> +ret_file = host_file
> +else:
> +# Don't remove this device during cleanup
> +# Reenable idling in scsi_debug drive (in case it's not)
> +utils.system("echo 1 > /sys/block/%s/queue/rotational" %
> host_file)
> +ret_file = None
> +
> +out = vm.monitor.cmd("pci_add auto storage
> file=%s,if=%s,snapshot=off,"
> + "cache=off" % (host_file, driver))
> +dev = re.search(r'OK domain (\d+), bus (\d+), slot (\d+),
> function \d+',
> +out)
> +if not dev:
> +raise error.TestFail("Can't add device(%s, %s, %s): %s"
> % (vm,
> +host_file,
> driver, out))
> +device = "%s:%s:%s" % dev.groups()
> +return (ret_file, device)
> +
> +
> +def rm_drive(vm, host_file, device):
> +"""
> +Remove drive from vm and device on disk
> +! beware to remove scsi devices in reverse order !
> +"""
> +vm.monitor.cmd("pci_del %s" % device)
> +
> +if isinstance(host_file, file): # file
> +host_file.close()
> +elif isinstance(host_file, str):# scsi device
> +utils.system("echo -1>
> /sys/bus/pseudo/drivers/scsi_debug/add_host")
> +else:# custom file, do not

[PATCH 1/4] [kvm-autotest] cgroup-kvm: add_*_drive / rm_drive

2011-10-07 Thread Lukas Doktor
 * functions for adding and removal of drive to vm using host-file or
   host-scsi_debug device.

Signed-off-by: Lukas Doktor 
---
 client/tests/kvm/tests/cgroup.py |  125 -
 1 files changed, 108 insertions(+), 17 deletions(-)

diff --git a/client/tests/kvm/tests/cgroup.py b/client/tests/kvm/tests/cgroup.py
index b9a10ea..d6418b5 100644
--- a/client/tests/kvm/tests/cgroup.py
+++ b/client/tests/kvm/tests/cgroup.py
@@ -17,6 +17,108 @@ def run_cgroup(test, params, env):
 vms = None
 tests = None
 
+# Func
+def get_device_driver():
+"""
+Discovers the used block device driver {ide, scsi, virtio_blk}
+@return: Used block device driver {ide, scsi, virtio}
+"""
+if test.tagged_testname.count('virtio_blk'):
+return "virtio"
+elif test.tagged_testname.count('scsi'):
+return "scsi"
+else:
+return "ide"
+
+
+def add_file_drive(vm, driver=get_device_driver(), host_file=None):
+"""
+Hot-add a drive based on file to a vm
+@param vm: Desired VM
+@param driver: which driver should be used (default: same as in test)
+@param host_file: Which file on host is the image (default: create new)
+@return: Tupple(ret_file, device)
+ret_file: created file handler (None if not created)
+device: PCI id of the virtual disk
+"""
+if not host_file:
+host_file = tempfile.NamedTemporaryFile(prefix="cgroup-disk-",
+   suffix=".iso")
+utils.system("dd if=/dev/zero of=%s bs=1M count=8 &>/dev/null"
+ % (host_file.name))
+ret_file = host_file
+else:
+ret_file = None
+
+out = vm.monitor.cmd("pci_add auto storage file=%s,if=%s,snapshot=off,"
+ "cache=off" % (host_file.name, driver))
+dev = re.search(r'OK domain (\d+), bus (\d+), slot (\d+), function 
\d+',
+out)
+if not dev:
+raise error.TestFail("Can't add device(%s, %s, %s): %s" % (vm,
+host_file.name, driver, out))
+device = "%s:%s:%s" % dev.groups()
+return (ret_file, device)
+
+
+def add_scsi_drive(vm, driver=get_device_driver(), host_file=None):
+"""
+Hot-add a drive based on scsi_debug device to a vm
+@param vm: Desired VM
+@param driver: which driver should be used (default: same as in test)
+@param host_file: Which dev on host is the image (default: create new)
+@return: Tupple(ret_file, device)
+ret_file: string of the created dev (None if not created)
+device: PCI id of the virtual disk
+"""
+if not host_file:
+if utils.system_output("lsmod | grep scsi_debug -c") == 0:
+utils.system("modprobe scsi_debug dev_size_mb=8 add_host=0")
+utils.system("echo 1 > 
/sys/bus/pseudo/drivers/scsi_debug/add_host")
+host_file = utils.system_output("ls /dev/sd* | tail -n 1")
+# Enable idling in scsi_debug drive
+utils.system("echo 1 > /sys/block/%s/queue/rotational" % host_file)
+ret_file = host_file
+else:
+# Don't remove this device during cleanup
+# Reenable idling in scsi_debug drive (in case it's not)
+utils.system("echo 1 > /sys/block/%s/queue/rotational" % host_file)
+ret_file = None
+
+out = vm.monitor.cmd("pci_add auto storage file=%s,if=%s,snapshot=off,"
+ "cache=off" % (host_file, driver))
+dev = re.search(r'OK domain (\d+), bus (\d+), slot (\d+), function 
\d+',
+out)
+if not dev:
+raise error.TestFail("Can't add device(%s, %s, %s): %s" % (vm,
+host_file, driver, 
out))
+device = "%s:%s:%s" % dev.groups()
+return (ret_file, device)
+
+
+def rm_drive(vm, host_file, device):
+"""
+Remove drive from vm and device on disk
+! beware to remove scsi devices in reverse order !
+"""
+vm.monitor.cmd("pci_del %s" % device)
+
+if isinstance(host_file, file): # file
+host_file.close()
+elif isinstance(host_file, str):# scsi device
+utils.system("echo -1> 
/sys/bus/pseudo/drivers/scsi_debug/add_host")
+else:# custom file, do nothing
+pass
+
+def get_all_pids(ppid):
+"""
+Get all PIDs of children/threads of parent ppid
+param ppid: parent PID
+return: list of PIDs of all children/threads of ppid
+"""
+return (utils.system_output("ps -L --ppid=%d -o lwp" % ppid)
+