mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-27 18:03:50 +03:00
qemu_conf.c: introduce qemuAddRemoveSharedHostdevInternal
qemuAddSharedHostdev() has a code similar to qemuRemoveSharedHostdev(), with exception of one line that defines the operation (add or remove). This patch introduces a new function that aggregates the common code, using a flag to switch between the operations, avoiding code repetition. No functional change was made. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
2029f8269b
commit
b2de989b9d
@ -1729,35 +1729,6 @@ qemuGetHostdevPath(virDomainHostdevDefPtr hostdev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
qemuAddSharedHostdev(virQEMUDriverPtr driver,
|
|
||||||
virDomainHostdevDefPtr hostdev,
|
|
||||||
const char *name)
|
|
||||||
{
|
|
||||||
char *dev_path = NULL;
|
|
||||||
char *key = NULL;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (!qemuIsSharedHostdev(hostdev))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!(dev_path = qemuGetHostdevPath(hostdev)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(key = qemuGetSharedDeviceKey(dev_path)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
qemuDriverLock(driver);
|
|
||||||
ret = qemuSharedDeviceEntryInsert(driver, key, name);
|
|
||||||
qemuDriverUnlock(driver);
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(dev_path);
|
|
||||||
VIR_FREE(key);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuSharedDeviceEntryRemove(virQEMUDriverPtr driver,
|
qemuSharedDeviceEntryRemove(virQEMUDriverPtr driver,
|
||||||
const char *key,
|
const char *key,
|
||||||
@ -1782,6 +1753,42 @@ qemuSharedDeviceEntryRemove(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuAddRemoveSharedHostdevInternal(virQEMUDriverPtr driver,
|
||||||
|
virDomainHostdevDefPtr hostdev,
|
||||||
|
const char *name,
|
||||||
|
bool addDevice)
|
||||||
|
{
|
||||||
|
char *dev_path = NULL;
|
||||||
|
char *key = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!qemuIsSharedHostdev(hostdev))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!(dev_path = qemuGetHostdevPath(hostdev)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!(key = qemuGetSharedDeviceKey(dev_path)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
qemuDriverLock(driver);
|
||||||
|
|
||||||
|
if (addDevice)
|
||||||
|
ret = qemuSharedDeviceEntryInsert(driver, key, name);
|
||||||
|
else
|
||||||
|
ret = qemuSharedDeviceEntryRemove(driver, key, name);
|
||||||
|
|
||||||
|
qemuDriverUnlock(driver);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(dev_path);
|
||||||
|
VIR_FREE(key);
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* qemuAddSharedDevice:
|
/* qemuAddSharedDevice:
|
||||||
* @driver: Pointer to qemu driver struct
|
* @driver: Pointer to qemu driver struct
|
||||||
* @dev: The device def
|
* @dev: The device def
|
||||||
@ -1803,7 +1810,8 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
|
|||||||
if (dev->type == VIR_DOMAIN_DEVICE_DISK)
|
if (dev->type == VIR_DOMAIN_DEVICE_DISK)
|
||||||
return qemuAddSharedDisk(driver, dev->data.disk, name);
|
return qemuAddSharedDisk(driver, dev->data.disk, name);
|
||||||
else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV)
|
else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV)
|
||||||
return qemuAddSharedHostdev(driver, dev->data.hostdev, name);
|
return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostdev,
|
||||||
|
name, true);
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1838,33 +1846,6 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
qemuRemoveSharedHostdev(virQEMUDriverPtr driver,
|
|
||||||
virDomainHostdevDefPtr hostdev,
|
|
||||||
const char *name)
|
|
||||||
{
|
|
||||||
char *dev_path = NULL;
|
|
||||||
char *key = NULL;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
if (!qemuIsSharedHostdev(hostdev))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!(dev_path = qemuGetHostdevPath(hostdev)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(key = qemuGetSharedDeviceKey(dev_path)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
qemuDriverLock(driver);
|
|
||||||
ret = qemuSharedDeviceEntryRemove(driver, key, name);
|
|
||||||
qemuDriverUnlock(driver);
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(dev_path);
|
|
||||||
VIR_FREE(key);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* qemuRemoveSharedDevice:
|
/* qemuRemoveSharedDevice:
|
||||||
@ -1884,7 +1865,8 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
|
|||||||
if (dev->type == VIR_DOMAIN_DEVICE_DISK)
|
if (dev->type == VIR_DOMAIN_DEVICE_DISK)
|
||||||
return qemuRemoveSharedDisk(driver, dev->data.disk, name);
|
return qemuRemoveSharedDisk(driver, dev->data.disk, name);
|
||||||
else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV)
|
else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV)
|
||||||
return qemuRemoveSharedHostdev(driver, dev->data.hostdev, name);
|
return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostdev,
|
||||||
|
name, false);
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user