On 11/1/24 23:31, John Levon wrote:
Signed-off-by: John Levon <john.levon(a)nutanix.com>
---
src/test/test_driver.c | 114 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 112 insertions(+), 2 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index b7e36e8451..789b1a2222 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -10741,6 +10741,85 @@ testDomainDetachPrepNet(virDomainObj *vm,
}
+static int
+testFindDisk(virDomainDef *def, const char *dst)
+{
+ size_t i;
+
+ for (i = 0; i < def->ndisks; i++) {
+ if (STREQ(def->disks[i]->dst, dst))
+ return i;
+ }
+
+ return -1;
+}
+
+static int
+testDomainDetachPrepDisk(virDomainObj *vm,
+ virDomainDiskDef *match,
+ virDomainDiskDef **detach)
+{
+ virDomainDiskDef *disk;
+ int idx;
+
+ if ((idx = testFindDisk(vm->def, match->dst)) < 0) {
+ virReportError(VIR_ERR_DEVICE_MISSING,
+ _("disk %1$s not found"), match->dst);
+ return -1;
+ }
+ *detach = disk = vm->def->disks[idx];
So idx is there only to access vm->def->disks array? Well, the same
result can be achieved using virDomainDiskByTarget().
Oh, and I'd set *detach only after all checks passed, i.e. right before
return 0.
Michal