All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Lukáš Doktor" <ldoktor@redhat.com>
To: Jiri Zupka <jzupka@redhat.com>
Cc: autotest@test.kernel.org, kvm@vger.kernel.org,
	kvm-autotest@redhat.com, akong@redhat.com, lmr@redhat.com
Subject: Re: [PATCH 1/4] [kvm-autotest] cgroup-kvm: add_*_drive / rm_drive
Date: Mon, 10 Oct 2011 12:37:50 +0200	[thread overview]
Message-ID: <4E92CAFE.4030202@redhat.com> (raw)
In-Reply-To: <47a34dd7-fbab-4a34-863f-5983df1c9f35@zmail05.collab.prod.int.phx2.redhat.com>

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<ldoktor@redhat.com>
>> ---
>>   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)
>> +
>>                                                         .split('\n')[1:])
>> +
>>       # Tests
>>       class _TestBlkioBandwidth:
>>           """
>> @@ -46,9 +148,8 @@ def run_cgroup(test, params, env):
>>               """
>>               err = ""
>>               try:
>> -                for i in range (2):
>> -                    vms[i].monitor.cmd("pci_del %s" %
>> self.devices[i])
>> -                    self.files[i].close()
>> +                for i in range(1, -1, -1):
>> +                    rm_drive(vms[i], self.files[i], self.devices[i])
>>               except Exception, failure_detail:
>>                   err += "\nCan't remove PCI drive: %s" %
>>                   failure_detail
>>               try:
>> @@ -89,8 +190,7 @@ def run_cgroup(test, params, env):
>>                   if blkio.set_cgroup(self.vms[i].get_shell_pid(),
>>                   pwd[i]):
>>                       raise error.TestError("Could not set cgroup")
>>                   # Move all existing threads into cgroup
>> -                for tmp in utils.system_output("ps -L --ppid=%d -o
>> lwp"
>> -                                %
>> self.vms[i].get_shell_pid()).split('\n')[1:]:
>> +                for tmp in
>> get_all_pids(self.vms[i].get_shell_pid()):
>>                       if blkio.set_cgroup(int(tmp), pwd[i]):
>>                           raise error.TestError("Could not set
>>                           cgroup")
>>               if self.blkio.set_property("blkio.weight", 100, pwd[0]):
>> @@ -101,18 +201,9 @@ def run_cgroup(test, params, env):
>>               # Add dummy drives
>>               # TODO: implement also using QMP.
>>               for i in range(2):
>> -                self.files.append(tempfile.NamedTemporaryFile(
>> -                                        prefix="cgroup-disk-",
>> -                                        suffix=".iso"))
>> -                utils.system("dd if=/dev/zero of=%s bs=1M count=10
>> &>/dev/null"
>> -                             % (self.files[i].name))
>> -                out = vms[i].monitor.cmd("pci_add auto storage
>> file=%s,"
>> -                                "if=virtio,snapshot=off,cache=off"
>> -                                % (self.files[i].name))
>> -                out = re.search(r'OK domain (\d+), bus (\d+), slot
>> (\d+), '
>> -                                 'function \d+', out).groups()
>> -                self.devices.append("%s:%s:%s" % out)
>> -
>> +                (host_file, device) = add_file_drive(vms[i],
>> "virtio")
>> +                self.files.append(host_file)
>> +                self.devices.append(device)
>>
>>           def run(self):
>>               """
>> --
>> 1.7.6.2
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe kvm" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>


  reply	other threads:[~2011-10-10 10:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-07 18:24 [kvm-autotest] cgroup-kvm: Four new BlkioThrottle tests Lukas Doktor
2011-10-07 18:24 ` [PATCH 1/4] [kvm-autotest] cgroup-kvm: add_*_drive / rm_drive Lukas Doktor
2011-10-10 10:26   ` Jiri Zupka
2011-10-10 10:37     ` Lukáš Doktor [this message]
2011-10-11 17:13       ` Lucas Meneghel Rodrigues
2011-10-07 18:24 ` [PATCH 2/4] [autotest] cgroup: cleanup and structural changes Lukas Doktor
2011-10-07 18:24 ` [PATCH 3/4] [autotest] cgroup: {set,get}_property functions unification, bugfixies Lukas Doktor
2011-10-07 18:24 ` [PATCH 4/4] [kvm-autotest] cgroup-kvm: New subtest: TestBlkioThrottle* Lukas Doktor
2011-10-07 18:43 ` [kvm-autotest] cgroup-kvm: Four new BlkioThrottle tests Lukáš Doktor
2011-10-11 20:30 ` Lucas Meneghel Rodrigues

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E92CAFE.4030202@redhat.com \
    --to=ldoktor@redhat.com \
    --cc=akong@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=jzupka@redhat.com \
    --cc=kvm-autotest@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=lmr@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.