Skip to contentSkip to conversation

blockdev: Mark BD-{remove, insert}-medium stable

PATCH Applied Max Reitz 2 participants 7 messages Nov 10, 2017 – Jan 17, 2018

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

cover blockdev: Mark BD-{remove, insert}-medium stable

Berto's "Test I/O limits with removable media" patch proves that throttling survives a blockdev-remove-medium/blockdev-insert-medium pair now, so let's mark them stable (because that was the reason they were considered experimental, see commit 6e0abc251dd4f8eba1f53656dfede12e5840e83b for more).

But before we do that, let's use the chance and drop the @device parameter.

Based-on: <[email protected]>
("Fix throttling crashes in BlockBackend with no BlockDriverState",
because of the test case added there)

Max Reitz (4):
iotests: Make BD-{remove,insert}-medium use @id tests/ahci: Switch tray and medium commands to @id
blockdev: Drop BD-{remove,insert}-medium's @device
blockdev: Mark BD-{remove,insert}-medium stable

 qapi/block-core.json   |  42 ++++-------
 blockdev.c             |  30 ++++++--
 tests/ahci-test.c      |  16 ++---
 tests/qemu-iotests/093 |   6 +-
 tests/qemu-iotests/118 | 184 +++++++++++++++++++++++--------------------------
 tests/qemu-iotests/139 |   2 +-
 tests/qemu-iotests/155 |  60 ++++++++--------
 7 files changed, 163 insertions(+), 177 deletions(-)
Signature · 1 line
2.13.6
author
#2 lore raw

PATCH 2/4 tests/ahci: Switch tray and medium commands to @id

Currently, the tray and medium commands in the AHCI test use the deprecated @device parameter. This patch switches all invocations over to use @id.

---
 tests/ahci-test.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tests/ahci-test.c +6 -6
index cb84edc8fb..3635ea6d41 100644
@@ -1578,9 +1578,9 @@ static void test_atapi_tray(void)
     QDict *rsp;
 
     fd = prepare_iso(iso_size, &tx, &iso);
-    ahci = ahci_boot_and_enable("-drive if=none,id=drive0,file=%s,format=raw "
+    ahci = ahci_boot_and_enable("-blockdev node-name=drive0,driver=file,filename=%s "
                                 "-M q35 "
-                                "-device ide-cd,drive=drive0 ", iso);
+                                "-device ide-cd,id=cd0,drive=drive0 ", iso);
     port = ahci_port_select(ahci);
 
     ahci_atapi_eject(ahci, port);
@@ -1591,13 +1591,13 @@ static void test_atapi_tray(void)
 
     /* Remove media */
     qmp_async("{'execute': 'blockdev-open-tray', "
-               "'arguments': {'device': 'drive0'}}");
+               "'arguments': {'id': 'cd0'}}");
     atapi_wait_tray(true);
     rsp = qmp_receive();
     QDECREF(rsp);
 
     qmp_discard_response("{'execute': 'x-blockdev-remove-medium', "
-                         "'arguments': {'device': 'drive0'}}");
+                         "'arguments': {'id': 'cd0'}}");
 
     /* Test the tray without a medium */
     ahci_atapi_load(ahci, port);
@@ -1613,12 +1613,12 @@ static void test_atapi_tray(void)
                                         "'file': { 'driver': 'file', "
                                                   "'filename': %s }}}", iso);
     qmp_discard_response("{'execute': 'x-blockdev-insert-medium',"
-                          "'arguments': { 'device': 'drive0', "
+                          "'arguments': { 'id': 'cd0', "
                                          "'node-name': 'node0' }}");
 
     /* Again, the event shows up first */
     qmp_async("{'execute': 'blockdev-close-tray', "
-               "'arguments': {'device': 'drive0'}}");
+               "'arguments': {'id': 'cd0'}}");
     atapi_wait_tray(false);
     rsp = qmp_receive();
     QDECREF(rsp);
Signature · 1 line
2.13.6
author
#1 lore raw

PATCH 1/4 iotests: Make BD-{remove, insert}-medium use @id

In reply to Max Reitz

In some cases, these commands still use the deprecated @device parameter. Fix that so we can later drop that parameter from their interface.

---
 tests/qemu-iotests/118 | 184 +++++++++++++++++++++++--------------------------
 tests/qemu-iotests/155 |  60 ++++++++--------
 2 files changed, 113 insertions(+), 131 deletions(-)
tests/qemu-iotests/118 +85 -99
index 8a9e838c90..ca6965d23c 100755
@@ -28,6 +28,14 @@ from iotests import qemu_img
 old_img = os.path.join(iotests.test_dir, 'test0.img')
 new_img = os.path.join(iotests.test_dir, 'test1.img')
 
+def interface_to_device_name(interface):
+    if interface == 'ide':
+        return 'ide-cd'
+    elif interface == 'floppy':
+        return 'floppy'
+    else:
+        return None
+
 class ChangeBaseClass(iotests.QMPTestCase):
     has_opened = False
     has_closed = False
@@ -63,7 +71,7 @@ class ChangeBaseClass(iotests.QMPTestCase):
 
 class GeneralChangeTestsBaseClass(ChangeBaseClass):
 
-    device_name = None
+    device_name = 'qdev0'
 
     def test_change(self):
         result = self.vm.qmp('change', device='drive0', target=new_img,
@@ -79,14 +87,9 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
 
     def test_blockdev_change_medium(self):
-        if self.device_name is not None:
-            result = self.vm.qmp('blockdev-change-medium',
-                                 id=self.device_name, filename=new_img,
-                                 format=iotests.imgfmt)
-        else:
-            result = self.vm.qmp('blockdev-change-medium',
-                                 device='drive0', filename=new_img,
-                                 format=iotests.imgfmt)
+        result = self.vm.qmp('blockdev-change-medium',
+                             id=self.device_name, filename=new_img,
+                             format=iotests.imgfmt)
 
         self.assert_qmp(result, 'return', {})
 
@@ -99,10 +102,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
 
     def test_eject(self):
-        if self.device_name is not None:
-            result = self.vm.qmp('eject', id=self.device_name, force=True)
-        else:
-            result = self.vm.qmp('eject', device='drive0', force=True)
+        result = self.vm.qmp('eject', id=self.device_name, force=True)
         self.assert_qmp(result, 'return', {})
 
         self.wait_for_open()
@@ -113,10 +113,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         self.assert_qmp_absent(result, 'return[0]/inserted')
 
     def test_tray_eject_change(self):
-        if self.device_name is not None:
-            result = self.vm.qmp('eject', id=self.device_name, force=True)
-        else:
-            result = self.vm.qmp('eject', device='drive0', force=True)
+        result = self.vm.qmp('eject', id=self.device_name, force=True)
         self.assert_qmp(result, 'return', {})
 
         self.wait_for_open()
@@ -126,12 +123,8 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
             self.assert_qmp(result, 'return[0]/tray_open', True)
         self.assert_qmp_absent(result, 'return[0]/inserted')
 
-        if self.device_name is not None:
-            result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
-                                 filename=new_img, format=iotests.imgfmt)
-        else:
-            result = self.vm.qmp('blockdev-change-medium', device='drive0',
-                                 filename=new_img, format=iotests.imgfmt)
+        result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
+                             filename=new_img, format=iotests.imgfmt)
         self.assert_qmp(result, 'return', {})
 
         self.wait_for_close()
@@ -142,12 +135,8 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
 
     def test_tray_open_close(self):
-        if self.device_name is not None:
-            result = self.vm.qmp('blockdev-open-tray',
-                                 id=self.device_name, force=True)
-        else:
-            result = self.vm.qmp('blockdev-open-tray',
-                                 device='drive0', force=True)
+        result = self.vm.qmp('blockdev-open-tray',
+                             id=self.device_name, force=True)
         self.assert_qmp(result, 'return', {})
 
         self.wait_for_open()
@@ -160,10 +149,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         else:
             self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
-        if self.device_name is not None:
-            result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
-        else:
-            result = self.vm.qmp('blockdev-close-tray', device='drive0')
+        result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
         self.assert_qmp(result, 'return', {})
 
         if self.has_real_tray or not self.was_empty:
@@ -178,7 +164,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
             self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
     def test_tray_eject_close(self):
-        result = self.vm.qmp('eject', device='drive0', force=True)
+        result = self.vm.qmp('eject', id=self.device_name, force=True)
         self.assert_qmp(result, 'return', {})
 
         self.wait_for_open()
@@ -188,10 +174,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
             self.assert_qmp(result, 'return[0]/tray_open', True)
         self.assert_qmp_absent(result, 'return[0]/inserted')
 
-        if self.device_name is not None:
-            result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
-        else:
-            result = self.vm.qmp('blockdev-close-tray', device='drive0')
+        result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
         self.assert_qmp(result, 'return', {})
 
         self.wait_for_close()
@@ -202,7 +185,8 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         self.assert_qmp_absent(result, 'return[0]/inserted')
 
     def test_tray_open_change(self):
-        result = self.vm.qmp('blockdev-open-tray', device='drive0', force=True)
+        result = self.vm.qmp('blockdev-open-tray', id=self.device_name,
+                                                   force=True)
         self.assert_qmp(result, 'return', {})
 
         self.wait_for_open()
@@ -215,7 +199,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         else:
             self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
-        result = self.vm.qmp('blockdev-change-medium', device='drive0',
+        result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
                                                        filename=new_img,
                                                        format=iotests.imgfmt)
         self.assert_qmp(result, 'return', {})
@@ -235,12 +219,8 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
                                     'driver': 'file'})
         self.assert_qmp(result, 'return', {})
 
-        if self.device_name is not None:
-            result = self.vm.qmp('blockdev-open-tray',
-                                 id=self.device_name, force=True)
-        else:
-            result = self.vm.qmp('blockdev-open-tray',
-                                 device='drive0', force=True)
+        result = self.vm.qmp('blockdev-open-tray',
+                             id=self.device_name, force=True)
         self.assert_qmp(result, 'return', {})
 
         self.wait_for_open()
@@ -253,11 +233,8 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         else:
             self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
-        if self.device_name is not None:
-            result = self.vm.qmp('x-blockdev-remove-medium',
-                                 id=self.device_name)
-        else:
-            result = self.vm.qmp('x-blockdev-remove-medium', device='drive0')
+        result = self.vm.qmp('x-blockdev-remove-medium',
+                             id=self.device_name)
         self.assert_qmp(result, 'return', {})
 
         result = self.vm.qmp('query-block')
@@ -265,12 +242,8 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
             self.assert_qmp(result, 'return[0]/tray_open', True)
         self.assert_qmp_absent(result, 'return[0]/inserted')
 
-        if self.device_name is not None:
-            result = self.vm.qmp('x-blockdev-insert-medium',
-                                 id=self.device_name, node_name='new')
-        else:
-            result = self.vm.qmp('x-blockdev-insert-medium',
-                                 device='drive0', node_name='new')
+        result = self.vm.qmp('x-blockdev-insert-medium',
+                             id=self.device_name, node_name='new')
         self.assert_qmp(result, 'return', {})
 
         result = self.vm.qmp('query-block')
@@ -278,10 +251,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
             self.assert_qmp(result, 'return[0]/tray_open', True)
         self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
 
-        if self.device_name is not None:
-            result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
-        else:
-            result = self.vm.qmp('blockdev-close-tray', device='drive0')
+        result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
         self.assert_qmp(result, 'return', {})
 
         self.wait_for_close()
@@ -292,7 +262,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
 
     def test_close_on_closed(self):
-        result = self.vm.qmp('blockdev-close-tray', device='drive0')
+        result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
         # Should be a no-op
         self.assert_qmp(result, 'return', {})
         self.assertEquals(self.vm.get_qmp_events(wait=False), [])
@@ -301,7 +271,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         if not self.has_real_tray:
             return
 
-        result = self.vm.qmp('x-blockdev-remove-medium', device='drive0')
+        result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
         self.assert_qmp(result, 'error/class', 'GenericError')
 
     def test_insert_on_closed(self):
@@ -315,7 +285,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
                                    'driver': 'file'})
         self.assert_qmp(result, 'return', {})
 
-        result = self.vm.qmp('x-blockdev-insert-medium', device='drive0',
+        result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
                                                        node_name='new')
         self.assert_qmp(result, 'error/class', 'GenericError')
 
@@ -326,12 +296,10 @@ class TestInitiallyFilled(GeneralChangeTestsBaseClass):
         qemu_img('create', '-f', iotests.imgfmt, old_img, '1440k')
         qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k')
         self.vm = iotests.VM()
-        if interface == 'ide':
-            self.device_name = 'qdev0'
-            self.vm.add_drive(old_img, 'media=%s' % media, 'none')
-            self.vm.add_device('ide-cd,drive=drive0,id=%s' % self.device_name)
-        else:
-            self.vm.add_drive(old_img, 'media=%s' % media, interface)
+        self.vm.add_drive(old_img, 'media=%s' % media, 'none')
+        self.vm.add_device('%s,drive=drive0,id=%s' %
+                           (interface_to_device_name(interface),
+                            self.device_name))
         self.vm.launch()
 
     def tearDown(self):
@@ -347,12 +315,12 @@ class TestInitiallyFilled(GeneralChangeTestsBaseClass):
                                    'driver': 'file'})
         self.assert_qmp(result, 'return', {})
 
-        result = self.vm.qmp('blockdev-open-tray', device='drive0')
+        result = self.vm.qmp('blockdev-open-tray', id=self.device_name)
         self.assert_qmp(result, 'return', {})
 
         self.wait_for_open()
 
-        result = self.vm.qmp('x-blockdev-insert-medium', device='drive0',
+        result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
                                                        node_name='new')
         self.assert_qmp(result, 'error/class', 'GenericError')
 
@@ -361,7 +329,10 @@ class TestInitiallyEmpty(GeneralChangeTestsBaseClass):
 
     def setUp(self, media, interface):
         qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k')
-        self.vm = iotests.VM().add_drive(None, 'media=%s' % media, interface)
+        self.vm = iotests.VM().add_drive(None, 'media=%s' % media, 'none')
+        self.vm.add_device('%s,drive=drive0,id=%s' %
+                           (interface_to_device_name(interface),
+                            self.device_name))
         self.vm.launch()
 
     def tearDown(self):
@@ -369,12 +340,12 @@ class TestInitiallyEmpty(GeneralChangeTestsBaseClass):
         os.remove(new_img)
 
     def test_remove_on_empty(self):
-        result = self.vm.qmp('blockdev-open-tray', device='drive0')
+        result = self.vm.qmp('blockdev-open-tray', id=self.device_name)
         self.assert_qmp(result, 'return', {})
 
         self.wait_for_open()
 
-        result = self.vm.qmp('x-blockdev-remove-medium', device='drive0')
+        result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
         # Should be a no-op
         self.assert_qmp(result, 'return', {})
 
@@ -410,6 +381,8 @@ class TestFloppyInitiallyEmpty(TestInitiallyEmpty):
         self.has_opened = True
 
 class TestChangeReadOnly(ChangeBaseClass):
+    device_name = 'qdev0'
+
     def setUp(self):
         qemu_img('create', '-f', iotests.imgfmt, old_img, '1440k')
         qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k')
@@ -425,14 +398,15 @@ class TestChangeReadOnly(ChangeBaseClass):
     def test_ro_ro_retain(self):
         os.chmod(old_img, 0444)
         os.chmod(new_img, 0444)
-        self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy')
+        self.vm.add_drive(old_img, 'media=disk,read-only=on', 'none')
+        self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
         self.vm.launch()
 
         result = self.vm.qmp('query-block')
         self.assert_qmp(result, 'return[0]/inserted/ro', True)
         self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
-        result = self.vm.qmp('blockdev-change-medium', device='drive0',
+        result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
                                                        filename=new_img,
                                                        format=iotests.imgfmt,
                                                        read_only_mode='retain')
@@ -444,14 +418,15 @@ class TestChangeReadOnly(ChangeBaseClass):
 
     def test_ro_rw_retain(self):
         os.chmod(old_img, 0444)
-        self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy')
+        self.vm.add_drive(old_img, 'media=disk,read-only=on', 'none')
+        self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
         self.vm.launch()
 
         result = self.vm.qmp('query-block')
         self.assert_qmp(result, 'return[0]/inserted/ro', True)
         self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
-        result = self.vm.qmp('blockdev-change-medium', device='drive0',
+        result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
                                                        filename=new_img,
                                                        format=iotests.imgfmt,
                                                        read_only_mode='retain')
@@ -463,14 +438,15 @@ class TestChangeReadOnly(ChangeBaseClass):
 
     def test_rw_ro_retain(self):
         os.chmod(new_img, 0444)
-        self.vm.add_drive(old_img, 'media=disk', 'floppy')
+        self.vm.add_drive(old_img, 'media=disk', 'none')
+        self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
         self.vm.launch()
 
         result = self.vm.qmp('query-block')
         self.assert_qmp(result, 'return[0]/inserted/ro', False)
         self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
-        result = self.vm.qmp('blockdev-change-medium', device='drive0',
+        result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
                                                        filename=new_img,
                                                        format=iotests.imgfmt,
                                                        read_only_mode='retain')
@@ -484,7 +460,8 @@ class TestChangeReadOnly(ChangeBaseClass):
 
     def test_ro_rw(self):
         os.chmod(old_img, 0444)
-        self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy')
+        self.vm.add_drive(old_img, 'media=disk,read-only=on', 'none')
+        self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
         self.vm.launch()
 
         result = self.vm.qmp('query-block')
@@ -492,7 +469,7 @@ class TestChangeReadOnly(ChangeBaseClass):
         self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
         result = self.vm.qmp('blockdev-change-medium',
-                             device='drive0',
+                             id=self.device_name,
                              filename=new_img,
                              format=iotests.imgfmt,
                              read_only_mode='read-write')
@@ -504,7 +481,8 @@ class TestChangeReadOnly(ChangeBaseClass):
 
     def test_rw_ro(self):
         os.chmod(new_img, 0444)
-        self.vm.add_drive(old_img, 'media=disk', 'floppy')
+        self.vm.add_drive(old_img, 'media=disk', 'none')
+        self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
         self.vm.launch()
 
         result = self.vm.qmp('query-block')
@@ -512,7 +490,7 @@ class TestChangeReadOnly(ChangeBaseClass):
         self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
         result = self.vm.qmp('blockdev-change-medium',
-                             device='drive0',
+                             id=self.device_name,
                              filename=new_img,
                              format=iotests.imgfmt,
                              read_only_mode='read-only')
@@ -523,7 +501,8 @@ class TestChangeReadOnly(ChangeBaseClass):
         self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
 
     def test_make_rw_ro(self):
-        self.vm.add_drive(old_img, 'media=disk', 'floppy')
+        self.vm.add_drive(old_img, 'media=disk', 'none')
+        self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
         self.vm.launch()
 
         result = self.vm.qmp('query-block')
@@ -531,7 +510,7 @@ class TestChangeReadOnly(ChangeBaseClass):
         self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
         result = self.vm.qmp('blockdev-change-medium',
-                             device='drive0',
+                             id=self.device_name,
                              filename=new_img,
                              format=iotests.imgfmt,
                              read_only_mode='read-only')
@@ -543,7 +522,8 @@ class TestChangeReadOnly(ChangeBaseClass):
 
     def test_make_ro_rw(self):
         os.chmod(new_img, 0444)
-        self.vm.add_drive(old_img, 'media=disk', 'floppy')
+        self.vm.add_drive(old_img, 'media=disk', 'none')
+        self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
         self.vm.launch()
 
         result = self.vm.qmp('query-block')
@@ -551,7 +531,7 @@ class TestChangeReadOnly(ChangeBaseClass):
         self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
         result = self.vm.qmp('blockdev-change-medium',
-                             device='drive0',
+                             id=self.device_name,
                              filename=new_img,
                              format=iotests.imgfmt,
                              read_only_mode='read-write')
@@ -563,14 +543,15 @@ class TestChangeReadOnly(ChangeBaseClass):
 
     def test_make_rw_ro_by_retain(self):
         os.chmod(old_img, 0444)
-        self.vm.add_drive(old_img, 'media=disk,read-only=on', 'floppy')
+        self.vm.add_drive(old_img, 'media=disk,read-only=on', 'none')
+        self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
         self.vm.launch()
 
         result = self.vm.qmp('query-block')
         self.assert_qmp(result, 'return[0]/inserted/ro', True)
         self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
-        result = self.vm.qmp('blockdev-change-medium', device='drive0',
+        result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
                                                        filename=new_img,
                                                        format=iotests.imgfmt,
                                                        read_only_mode='retain')
@@ -582,14 +563,15 @@ class TestChangeReadOnly(ChangeBaseClass):
 
     def test_make_ro_rw_by_retain(self):
         os.chmod(new_img, 0444)
-        self.vm.add_drive(old_img, 'media=disk', 'floppy')
+        self.vm.add_drive(old_img, 'media=disk', 'none')
+        self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
         self.vm.launch()
 
         result = self.vm.qmp('query-block')
         self.assert_qmp(result, 'return[0]/inserted/ro', False)
         self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
-        result = self.vm.qmp('blockdev-change-medium', device='drive0',
+        result = self.vm.qmp('blockdev-change-medium', id=self.device_name,
                                                        filename=new_img,
                                                        format=iotests.imgfmt,
                                                        read_only_mode='retain')
@@ -601,7 +583,8 @@ class TestChangeReadOnly(ChangeBaseClass):
 
     def test_rw_ro_cycle(self):
         os.chmod(new_img, 0444)
-        self.vm.add_drive(old_img, 'media=disk', 'floppy')
+        self.vm.add_drive(old_img, 'media=disk', 'none')
+        self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
         self.vm.launch()
 
         result = self.vm.qmp('query-block')
@@ -620,13 +603,13 @@ class TestChangeReadOnly(ChangeBaseClass):
         self.assert_qmp(result, 'return[0]/inserted/ro', False)
         self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
-        result = self.vm.qmp('x-blockdev-remove-medium', device='drive0')
+        result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
         self.assert_qmp(result, 'return', {})
 
         result = self.vm.qmp('query-block')
         self.assert_qmp_absent(result, 'return[0]/inserted')
 
-        result = self.vm.qmp('x-blockdev-insert-medium', device='drive0',
+        result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
                                                        node_name='new')
         self.assert_qmp(result, 'return', {})
 
@@ -644,11 +627,14 @@ TestInitiallyEmpty = None
 
 
 class TestBlockJobsAfterCycle(ChangeBaseClass):
+    device_name = 'qdev0'
+
     def setUp(self):
-        qemu_img('create', '-f', iotests.imgfmt, old_img, '1M')
+        qemu_img('create', '-f', iotests.imgfmt, old_img, '1440K')
 
         self.vm = iotests.VM()
         self.vm.add_drive_raw("id=drive0,driver=null-co,if=none")
+        self.vm.add_device('floppy,drive=drive0,id=%s' % self.device_name)
         self.vm.launch()
 
         result = self.vm.qmp('query-block')
@@ -656,7 +642,7 @@ class TestBlockJobsAfterCycle(ChangeBaseClass):
 
         # For device-less BBs, calling blockdev-open-tray or blockdev-close-tray
         # is not necessary
-        result = self.vm.qmp('x-blockdev-remove-medium', device='drive0')
+        result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
         self.assert_qmp(result, 'return', {})
 
         result = self.vm.qmp('query-block')
@@ -669,7 +655,7 @@ class TestBlockJobsAfterCycle(ChangeBaseClass):
                                    'driver': 'file'})
         self.assert_qmp(result, 'return', {})
 
-        result = self.vm.qmp('x-blockdev-insert-medium', device='drive0',
+        result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
                                                        node_name='node0')
         self.assert_qmp(result, 'return', {})
 
tests/qemu-iotests/155 +28 -32

142 lines not on this page · raw message

Signature · 1 line
2.13.6
author
#3 lore raw

PATCH 3/4 blockdev: Drop BD-{remove, insert}-medium's @device

In reply to Max Reitz

This is an incompatible change, which is fine as the commands are experimental.

---
 qapi/block-core.json | 10 ++--------
 blockdev.c           | 30 +++++++++++++++++++++++-------
 2 files changed, 25 insertions(+), 15 deletions(-)
qapi/block-core.json +2 -8
index 76bf50f813..cf3f941999 100644
@@ -3405,8 +3405,6 @@
 #
 # If the tray is open and there is no medium inserted, this will be a no-op.
 #
-# @device: Block device name (deprecated, use @id instead)
-#
 # @id:     The name or QOM path of the guest device (since: 2.8)
 #
 # Note: This command is still a work in progress and is considered experimental.
@@ -3441,8 +3439,7 @@
 #
 ##
 { 'command': 'x-blockdev-remove-medium',
-  'data': { '*device': 'str',
-            '*id': 'str' } }
+  'data': { 'id': 'str' } }
 
 ##
 # @x-blockdev-insert-medium:
@@ -3451,8 +3448,6 @@
 # device's tray must currently be open (unless there is no attached guest
 # device) and there must be no medium inserted already.
 #
-# @device:    Block device name (deprecated, use @id instead)
-#
 # @id:        The name or QOM path of the guest device (since: 2.8)
 #
 # @node-name: name of a node in the block driver state graph
@@ -3480,8 +3475,7 @@
 #
 ##
 { 'command': 'x-blockdev-insert-medium',
-  'data': { '*device': 'str',
-            '*id': 'str',
+  'data': { 'id': 'str',
             'node-name': 'str'} }
 
 
blockdev.c +23 -7
index 56a6b24a0b..a74224e8f8 100644
@@ -59,6 +59,11 @@ static QTAILQ_HEAD(, BlockDriverState) monitor_bdrv_states =
 
 static int do_open_tray(const char *blk_name, const char *qdev_id,
                         bool force, Error **errp);
+static void blockdev_remove_medium(bool has_device, const char *device,
+                                   bool has_id, const char *id, Error **errp);
+static void blockdev_insert_medium(bool has_device, const char *device,
+                                   bool has_id, const char *id,
+                                   const char *node_name, Error **errp);
 
 static const char *const if_name[IF_COUNT] = {
     [IF_NONE] = "none",
@@ -2256,7 +2261,7 @@ void qmp_eject(bool has_device, const char *device,
     }
     error_free(local_err);
 
-    qmp_x_blockdev_remove_medium(has_device, device, has_id, id, errp);
+    blockdev_remove_medium(has_device, device, has_id, id, errp);
 }
 
 void qmp_block_passwd(bool has_device, const char *device,
@@ -2379,8 +2384,8 @@ void qmp_blockdev_close_tray(bool has_device, const char *device,
     }
 }
 
-void qmp_x_blockdev_remove_medium(bool has_device, const char *device,
-                                  bool has_id, const char *id, Error **errp)
+static void blockdev_remove_medium(bool has_device, const char *device,
+                                   bool has_id, const char *id, Error **errp)
 {
     BlockBackend *blk;
     BlockDriverState *bs;
@@ -2436,6 +2441,11 @@ out:
     aio_context_release(aio_context);
 }
 
+void qmp_x_blockdev_remove_medium(const char *id, Error **errp)
+{
+    blockdev_remove_medium(false, NULL, true, id, errp);
+}
+
 static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
                                             BlockDriverState *bs, Error **errp)
 {
@@ -2481,9 +2491,9 @@ static void qmp_blockdev_insert_anon_medium(BlockBackend *blk,
     }
 }
 
-void qmp_x_blockdev_insert_medium(bool has_device, const char *device,
-                                  bool has_id, const char *id,
-                                  const char *node_name, Error **errp)
+static void blockdev_insert_medium(bool has_device, const char *device,
+                                   bool has_id, const char *id,
+                                   const char *node_name, Error **errp)
 {
     BlockBackend *blk;
     BlockDriverState *bs;
@@ -2509,6 +2519,12 @@ void qmp_x_blockdev_insert_medium(bool has_device, const char *device,
     qmp_blockdev_insert_anon_medium(blk, bs, errp);
 }
 
+void qmp_x_blockdev_insert_medium(const char *id, const char *node_name,
+                                  Error **errp)
+{
+    blockdev_insert_medium(false, NULL, true, id, node_name, errp);
+}
+
 void qmp_blockdev_change_medium(bool has_device, const char *device,
                                 bool has_id, const char *id,
                                 const char *filename,
@@ -2583,7 +2599,7 @@ void qmp_blockdev_change_medium(bool has_device, const char *device,
     error_free(err);
     err = NULL;
 
-    qmp_x_blockdev_remove_medium(has_device, device, has_id, id, &err);
+    blockdev_remove_medium(has_device, device, has_id, id, &err);
     if (err) {
         error_propagate(errp, err);
         goto fail;
Signature · 1 line
2.13.6
author
#4 lore raw

PATCH 4/4 blockdev: Mark BD-{remove, insert}-medium stable

In reply to Max Reitz

Now that iotest 093 test proves that the throttling configuration survives a blockdev-remove-medium/blockdev-insert-medium pair, the original reason for declaring these commands experimental is gone (see commit 6e0abc251dd4f8eba1f53656dfede12e5840e83b).

---
 qapi/block-core.json   | 32 +++++++++++++-------------------
 blockdev.c             |  6 +++---
 tests/ahci-test.c      |  4 ++--
 tests/qemu-iotests/093 |  6 +++---
 tests/qemu-iotests/118 | 20 ++++++++++----------
 tests/qemu-iotests/139 |  2 +-
 6 files changed, 32 insertions(+), 38 deletions(-)
qapi/block-core.json +13 -19
index cf3f941999..8e6842e23e 100644
@@ -3397,7 +3397,7 @@
             '*id': 'str' } }
 
 ##
-# @x-blockdev-remove-medium:
+# @blockdev-remove-medium:
 #
 # Removes a medium (a block driver state tree) from a block device. That block
 # device's tray must currently be open (unless there is no attached guest
@@ -3405,16 +3405,13 @@
 #
 # If the tray is open and there is no medium inserted, this will be a no-op.
 #
-# @id:     The name or QOM path of the guest device (since: 2.8)
-#
-# Note: This command is still a work in progress and is considered experimental.
-# Stay away from it unless you want to help with its development.
+# @id:     The name or QOM path of the guest device
 #
-# Since: 2.5
+# Since: 2.12
 #
 # Example:
 #
-# -> { "execute": "x-blockdev-remove-medium",
+# -> { "execute": "blockdev-remove-medium",
 #      "arguments": { "id": "ide0-1-0" } }
 #
 # <- { "error": { "class": "GenericError",
@@ -3432,30 +3429,27 @@
 #
 # <- { "return": {} }
 #
-# -> { "execute": "x-blockdev-remove-medium",
+# -> { "execute": "blockdev-remove-medium",
 #      "arguments": { "id": "ide0-1-0" } }
 #
 # <- { "return": {} }
 #
 ##
-{ 'command': 'x-blockdev-remove-medium',
+{ 'command': 'blockdev-remove-medium',
   'data': { 'id': 'str' } }
 
 ##
-# @x-blockdev-insert-medium:
+# @blockdev-insert-medium:
 #
 # Inserts a medium (a block driver state tree) into a block device. That block
 # device's tray must currently be open (unless there is no attached guest
 # device) and there must be no medium inserted already.
 #
-# @id:        The name or QOM path of the guest device (since: 2.8)
+# @id:        The name or QOM path of the guest device
 #
 # @node-name: name of a node in the block driver state graph
 #
-# Note: This command is still a work in progress and is considered experimental.
-# Stay away from it unless you want to help with its development.
-#
-# Since: 2.5
+# Since: 2.12
 #
 # Example:
 #
@@ -3467,14 +3461,14 @@
 #                    "filename": "fedora.iso" } } }
 # <- { "return": {} }
 #
-# -> { "execute": "x-blockdev-insert-medium",
+# -> { "execute": "blockdev-insert-medium",
 #      "arguments": { "id": "ide0-1-0",
 #                     "node-name": "node0" } }
 #
 # <- { "return": {} }
 #
 ##
-{ 'command': 'x-blockdev-insert-medium',
+{ 'command': 'blockdev-insert-medium',
   'data': { 'id': 'str',
             'node-name': 'str'} }
 
@@ -3503,8 +3497,8 @@
 #
 # Changes the medium inserted into a block device by ejecting the current medium
 # and loading a new image file which is inserted as the new medium (this command
-# combines blockdev-open-tray, x-blockdev-remove-medium,
-# x-blockdev-insert-medium and blockdev-close-tray).
+# combines blockdev-open-tray, blockdev-remove-medium, blockdev-insert-medium
+# and blockdev-close-tray).
 #
 # @device:          Block device name (deprecated, use @id instead)
 #
blockdev.c +3 -3
index a74224e8f8..fb93283334 100644
@@ -2441,7 +2441,7 @@ out:
     aio_context_release(aio_context);
 }
 
-void qmp_x_blockdev_remove_medium(const char *id, Error **errp)
+void qmp_blockdev_remove_medium(const char *id, Error **errp)
 {
     blockdev_remove_medium(false, NULL, true, id, errp);
 }
@@ -2519,8 +2519,8 @@ static void blockdev_insert_medium(bool has_device, const char *device,
     qmp_blockdev_insert_anon_medium(blk, bs, errp);
 }
 
-void qmp_x_blockdev_insert_medium(const char *id, const char *node_name,
-                                  Error **errp)
+void qmp_blockdev_insert_medium(const char *id, const char *node_name,
+                                Error **errp)
 {
     blockdev_insert_medium(false, NULL, true, id, node_name, errp);
 }
tests/ahci-test.c +2 -2
index 3635ea6d41..3934e62ef7 100644
@@ -1596,7 +1596,7 @@ static void test_atapi_tray(void)
     rsp = qmp_receive();
     QDECREF(rsp);
 
-    qmp_discard_response("{'execute': 'x-blockdev-remove-medium', "
+    qmp_discard_response("{'execute': 'blockdev-remove-medium', "
                          "'arguments': {'id': 'cd0'}}");
 
     /* Test the tray without a medium */
@@ -1612,7 +1612,7 @@ static void test_atapi_tray(void)
                                         "'driver': 'raw', "
                                         "'file': { 'driver': 'file', "
                                                   "'filename': %s }}}", iso);
-    qmp_discard_response("{'execute': 'x-blockdev-insert-medium',"
+    qmp_discard_response("{'execute': 'blockdev-insert-medium',"
                           "'arguments': { 'id': 'cd0', "
                                          "'node-name': 'node0' }}");
 
tests/qemu-iotests/093 +3 -3
index 7862f2ba94..a354c79bff 100755
@@ -348,9 +348,9 @@ class ThrottleTestRemovableMedia(iotests.QMPTestCase):
         # Now eject cd0 and insert cd1
         result = self.vm.qmp("blockdev-open-tray", id = 'dev0')
         self.assert_qmp(result, 'return', {})
-        result = self.vm.qmp("x-blockdev-remove-medium", id = 'dev0')
+        result = self.vm.qmp("blockdev-remove-medium", id = 'dev0')
         self.assert_qmp(result, 'return', {})
-        result = self.vm.qmp("x-blockdev-insert-medium", id = 'dev0', node_name = 'cd1')
+        result = self.vm.qmp("blockdev-insert-medium", id = 'dev0', node_name = 'cd1')
         self.assert_qmp(result, 'return', {})
 
         # Check that the I/O limits are still the same
@@ -359,7 +359,7 @@ class ThrottleTestRemovableMedia(iotests.QMPTestCase):
         self.assert_qmp(result, 'return[0]/inserted/bps',   50)
 
         # Eject cd1
-        result = self.vm.qmp("x-blockdev-remove-medium", id = 'dev0')
+        result = self.vm.qmp("blockdev-remove-medium", id = 'dev0')
         self.assert_qmp(result, 'return', {})
 
         # Check that we can't set limits if the device has no medium
tests/qemu-iotests/118 +10 -10
index ca6965d23c..a0469b570e 100755
@@ -233,7 +233,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         else:
             self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
-        result = self.vm.qmp('x-blockdev-remove-medium',
+        result = self.vm.qmp('blockdev-remove-medium',
                              id=self.device_name)
         self.assert_qmp(result, 'return', {})
 
@@ -242,7 +242,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
             self.assert_qmp(result, 'return[0]/tray_open', True)
         self.assert_qmp_absent(result, 'return[0]/inserted')
 
-        result = self.vm.qmp('x-blockdev-insert-medium',
+        result = self.vm.qmp('blockdev-insert-medium',
                              id=self.device_name, node_name='new')
         self.assert_qmp(result, 'return', {})
 
@@ -271,7 +271,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         if not self.has_real_tray:
             return
 
-        result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
+        result = self.vm.qmp('blockdev-remove-medium', id=self.device_name)
         self.assert_qmp(result, 'error/class', 'GenericError')
 
     def test_insert_on_closed(self):
@@ -285,7 +285,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
                                    'driver': 'file'})
         self.assert_qmp(result, 'return', {})
 
-        result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
+        result = self.vm.qmp('blockdev-insert-medium', id=self.device_name,
                                                        node_name='new')
         self.assert_qmp(result, 'error/class', 'GenericError')
 
@@ -320,7 +320,7 @@ class TestInitiallyFilled(GeneralChangeTestsBaseClass):
 
         self.wait_for_open()
 
-        result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
+        result = self.vm.qmp('blockdev-insert-medium', id=self.device_name,
                                                        node_name='new')
         self.assert_qmp(result, 'error/class', 'GenericError')
 
@@ -345,7 +345,7 @@ class TestInitiallyEmpty(GeneralChangeTestsBaseClass):
 
         self.wait_for_open()
 
-        result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
+        result = self.vm.qmp('blockdev-remove-medium', id=self.device_name)
         # Should be a no-op
         self.assert_qmp(result, 'return', {})
 
@@ -603,13 +603,13 @@ class TestChangeReadOnly(ChangeBaseClass):
         self.assert_qmp(result, 'return[0]/inserted/ro', False)
         self.assert_qmp(result, 'return[0]/inserted/image/filename', old_img)
 
-        result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
+        result = self.vm.qmp('blockdev-remove-medium', id=self.device_name)
         self.assert_qmp(result, 'return', {})
 
         result = self.vm.qmp('query-block')
         self.assert_qmp_absent(result, 'return[0]/inserted')
 
-        result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
+        result = self.vm.qmp('blockdev-insert-medium', id=self.device_name,
                                                        node_name='new')
         self.assert_qmp(result, 'return', {})
 
@@ -642,7 +642,7 @@ class TestBlockJobsAfterCycle(ChangeBaseClass):
 
         # For device-less BBs, calling blockdev-open-tray or blockdev-close-tray
         # is not necessary
-        result = self.vm.qmp('x-blockdev-remove-medium', id=self.device_name)
+        result = self.vm.qmp('blockdev-remove-medium', id=self.device_name)
         self.assert_qmp(result, 'return', {})
 
         result = self.vm.qmp('query-block')
@@ -655,7 +655,7 @@ class TestBlockJobsAfterCycle(ChangeBaseClass):
                                    'driver': 'file'})
         self.assert_qmp(result, 'return', {})
 
-        result = self.vm.qmp('x-blockdev-insert-medium', id=self.device_name,
+        result = self.vm.qmp('blockdev-insert-medium', id=self.device_name,
                                                        node_name='node0')
         self.assert_qmp(result, 'return', {})
 
tests/qemu-iotests/139 +1 -1
index f8f02808a9..cc7fe337f3 100644
@@ -133,7 +133,7 @@ class TestBlockdevDel(iotests.QMPTestCase):
     # Insert a BlockDriverState
     def insertDrive(self, device, node):
         self.checkBlockDriverState(node)
-        result = self.vm.qmp('x-blockdev-insert-medium',
+        result = self.vm.qmp('blockdev-insert-medium',
                              id = device, node_name = node)
         self.assert_qmp(result, 'return', {})
         self.checkBlockDriverState(node)
Signature · 1 line
2.13.6
Reviewed-by on the v1 series
#5 lore raw
In reply to Max Reitz
Quoted 15 lines · Max Reitz

Berto's "Test I/O limits with removable media" patch proves that throttling survives a blockdev-remove-medium/blockdev-insert-medium pair now, so let's mark them stable (because that was the reason they were considered experimental, see commit 6e0abc251dd4f8eba1f53656dfede12e5840e83b for more).

But before we do that, let's use the chance and drop the @device parameter.

Based-on: <[email protected]>
("Fix throttling crashes in BlockBackend with no BlockDriverState",
because of the test case added there)

Quoted 5 lines

Max Reitz (4):
iotests: Make BD-{remove,insert}-medium use @id tests/ahci: Switch tray and medium commands to @id
blockdev: Drop BD-{remove,insert}-medium's @device
blockdev: Mark BD-{remove,insert}-medium stable

This series,

Berto

author Applied
#6 lore raw
In reply to Max Reitz
Quoted 21 lines · Max Reitz

Berto's "Test I/O limits with removable media" patch proves that throttling survives a blockdev-remove-medium/blockdev-insert-medium pair now, so let's mark them stable (because that was the reason they were considered experimental, see commit 6e0abc251dd4f8eba1f53656dfede12e5840e83b for more).

But before we do that, let's use the chance and drop the @device parameter.

Based-on: <[email protected]>
("Fix throttling crashes in BlockBackend with no BlockDriverState",
because of the test case added there)

Max Reitz (4):
iotests: Make BD-{remove,insert}-medium use @id tests/ahci: Switch tray and medium commands to @id
blockdev: Drop BD-{remove,insert}-medium's @device
blockdev: Mark BD-{remove,insert}-medium stable

Quoted 8 lines
 qapi/block-core.json   |  42 ++++-------
 blockdev.c             |  30 ++++++--
 tests/ahci-test.c      |  16 ++---
 tests/qemu-iotests/093 |   6 +-
 tests/qemu-iotests/118 | 184 +++++++++++++++++++++++--------------------------
 tests/qemu-iotests/139 |   2 +-
 tests/qemu-iotests/155 |  60 ++++++++--------
 7 files changed, 163 insertions(+), 177 deletions(-)

Applied to my block branch.

Max