提交 c725e2dc 编写于 作者: E Eric Blake

blockstats: support lookup by path in blockstats

Commit 89b6284f made it possible to pass either a source name or
the target device to most API demanding a disk designation, but
forgot to update the documentation.  It also failed to update
virDomainBlockStats to take both forms. This patch fixes both the
documentation and the remaining function.

Xen continues to use just device shorthand (that is, I did not
implement path lookup there, since xen does not track a domain_conf
to quickly tie a path back to the device shorthand).

* src/libvirt.c (virDomainBlockStats, virDomainBlockStatsFlags)
(virDomainGetBlockInfo, virDomainBlockPeek)
(virDomainBlockJobAbort, virDomainGetBlockJobInfo)
(virDomainBlockJobSetSpeed, virDomainBlockPull): Document
acceptable disk naming conventions.
* src/qemu/qemu_driver.c (qemuDomainBlockStats)
(qemuDomainBlockStatsFlags): Allow lookup by source name.
* src/test/test_driver.c (testDomainBlockStats): Likewise.
上级 489e14f2
...@@ -6659,16 +6659,19 @@ error: ...@@ -6659,16 +6659,19 @@ error:
/** /**
* virDomainBlockStats: * virDomainBlockStats:
* @dom: pointer to the domain object * @dom: pointer to the domain object
* @path: path to the block device * @path: path to the block device, or device shorthand
* @stats: block device stats (returned) * @stats: block device stats (returned)
* @size: size of stats structure * @size: size of stats structure
* *
* This function returns block device (disk) stats for block * This function returns block device (disk) stats for block
* devices attached to the domain. * devices attached to the domain.
* *
* The path parameter is the name of the block device. Get this * The @path parameter is either the device target shorthand (the
* by calling virDomainGetXMLDesc and finding the <target dev='...'> * <target dev='...'/> sub-element, such as "xvda"), or (since 0.9.8)
* attribute within //domain/devices/disk. (For example, "xvda"). * an unambiguous source name of the block device (the <source
* file='...'/> sub-element, such as "/path/to/image"). Valid names
* can be found by calling virDomainGetXMLDesc() and inspecting
* elements within //domain/devices/disk.
* *
* Domains may have more than one block device. To get stats for * Domains may have more than one block device. To get stats for
* each you should make multiple calls to this function. * each you should make multiple calls to this function.
...@@ -6719,7 +6722,7 @@ error: ...@@ -6719,7 +6722,7 @@ error:
/** /**
* virDomainBlockStatsFlags: * virDomainBlockStatsFlags:
* @dom: pointer to domain object * @dom: pointer to domain object
* @path: path to the block device * @path: path to the block device, or device shorthand
* @params: pointer to block stats parameter object * @params: pointer to block stats parameter object
* (return value) * (return value)
* @nparams: pointer to number of block stats; input and output * @nparams: pointer to number of block stats; input and output
...@@ -6728,9 +6731,12 @@ error: ...@@ -6728,9 +6731,12 @@ error:
* This function is to get block stats parameters for block * This function is to get block stats parameters for block
* devices attached to the domain. * devices attached to the domain.
* *
* The @path is the name of the block device. Get this * The @path parameter is either the device target shorthand (the
* by calling virDomainGetXMLDesc and finding the <target dev='...'> * <target dev='...'/> sub-element, such as "xvda"), or (since 0.9.8)
* attribute within //domain/devices/disk. (For example, "xvda"). * an unambiguous source name of the block device (the <source
* file='...'/> sub-element, such as "/path/to/image"). Valid names
* can be found by calling virDomainGetXMLDesc() and inspecting
* elements within //domain/devices/disk.
* *
* Domains may have more than one block device. To get stats for * Domains may have more than one block device. To get stats for
* each you should make multiple calls to this function. * each you should make multiple calls to this function.
...@@ -6927,7 +6933,7 @@ error: ...@@ -6927,7 +6933,7 @@ error:
/** /**
* virDomainBlockPeek: * virDomainBlockPeek:
* @dom: pointer to the domain object * @dom: pointer to the domain object
* @path: path to the block device * @path: path to the block device, or device shorthand
* @offset: offset within block device * @offset: offset within block device
* @size: size to read * @size: size to read
* @buffer: return buffer (must be at least size bytes) * @buffer: return buffer (must be at least size bytes)
...@@ -6946,10 +6952,12 @@ error: ...@@ -6946,10 +6952,12 @@ error:
* remote case, nor if you don't have sufficient permission. * remote case, nor if you don't have sufficient permission.
* Hence the need for this call). * Hence the need for this call).
* *
* 'path' must be a device or file corresponding to the domain. * The @path parameter is either an unambiguous source name of the
* In other words it must be the precise string returned in * block device (the <source file='...'/> sub-element, such as
* a <disk><source dev='...'/></disk> from * "/path/to/image"), or (since 0.9.5) the device target shorthand
* virDomainGetXMLDesc. * (the <target dev='...'/> sub-element, such as "xvda"). Valid names
* can be found by calling virDomainGetXMLDesc() and inspecting
* elements within //domain/devices/disk.
* *
* 'offset' and 'size' represent an area which must lie entirely * 'offset' and 'size' represent an area which must lie entirely
* within the device or file. 'size' may be 0 to test if the * within the device or file. 'size' may be 0 to test if the
...@@ -7133,16 +7141,24 @@ error: ...@@ -7133,16 +7141,24 @@ error:
/** /**
* virDomainGetBlockInfo: * virDomainGetBlockInfo:
* @domain: a domain object * @domain: a domain object
* @path: path to the block device or file * @path: path to the block device, or device shorthand
* @info: pointer to a virDomainBlockInfo structure allocated by the user * @info: pointer to a virDomainBlockInfo structure allocated by the user
* @flags: currently unused, pass zero * @flags: currently unused, pass zero
* *
* Extract information about a domain's block device. * Extract information about a domain's block device.
* *
* The @path parameter is either an unambiguous source name of the
* block device (the <source file='...'/> sub-element, such as
* "/path/to/image"), or (since 0.9.5) the device target shorthand
* (the <target dev='...'/> sub-element, such as "xvda"). Valid names
* can be found by calling virDomainGetXMLDesc() and inspecting
* elements within //domain/devices/disk.
*
* Returns 0 in case of success and -1 in case of failure. * Returns 0 in case of success and -1 in case of failure.
*/ */
int int
virDomainGetBlockInfo(virDomainPtr domain, const char *path, virDomainBlockInfoPtr info, unsigned int flags) virDomainGetBlockInfo(virDomainPtr domain, const char *path,
virDomainBlockInfoPtr info, unsigned int flags)
{ {
virConnectPtr conn; virConnectPtr conn;
...@@ -16837,11 +16853,18 @@ error: ...@@ -16837,11 +16853,18 @@ error:
/** /**
* virDomainBlockJobAbort: * virDomainBlockJobAbort:
* @dom: pointer to domain object * @dom: pointer to domain object
* @path: fully-qualified filename of disk * @path: path to the block device, or device shorthand
* @flags: currently unused, for future extension * @flags: currently unused, for future extension
* *
* Cancel the active block job on the given disk. * Cancel the active block job on the given disk.
* *
* The @path parameter is either an unambiguous source name of the
* block device (the <source file='...'/> sub-element, such as
* "/path/to/image"), or (since 0.9.5) the device target shorthand
* (the <target dev='...'/> sub-element, such as "xvda"). Valid names
* can be found by calling virDomainGetXMLDesc() and inspecting
* elements within //domain/devices/disk.
*
* Returns -1 in case of failure, 0 when successful. * Returns -1 in case of failure, 0 when successful.
*/ */
int virDomainBlockJobAbort(virDomainPtr dom, const char *path, int virDomainBlockJobAbort(virDomainPtr dom, const char *path,
...@@ -16889,13 +16912,20 @@ error: ...@@ -16889,13 +16912,20 @@ error:
/** /**
* virDomainGetBlockJobInfo: * virDomainGetBlockJobInfo:
* @dom: pointer to domain object * @dom: pointer to domain object
* @path: fully-qualified filename of disk * @path: path to the block device, or device shorthand
* @info: pointer to a virDomainBlockJobInfo structure * @info: pointer to a virDomainBlockJobInfo structure
* @flags: currently unused, for future extension * @flags: currently unused, for future extension
* *
* Request block job information for the given disk. If an operation is active * Request block job information for the given disk. If an operation is active
* @info will be updated with the current progress. * @info will be updated with the current progress.
* *
* The @path parameter is either an unambiguous source name of the
* block device (the <source file='...'/> sub-element, such as
* "/path/to/image"), or (since 0.9.5) the device target shorthand
* (the <target dev='...'/> sub-element, such as "xvda"). Valid names
* can be found by calling virDomainGetXMLDesc() and inspecting
* elements within //domain/devices/disk.
*
* Returns -1 in case of failure, 0 when nothing found, 1 when info was found. * Returns -1 in case of failure, 0 when nothing found, 1 when info was found.
*/ */
int virDomainGetBlockJobInfo(virDomainPtr dom, const char *path, int virDomainGetBlockJobInfo(virDomainPtr dom, const char *path,
...@@ -16944,13 +16974,20 @@ error: ...@@ -16944,13 +16974,20 @@ error:
/** /**
* virDomainBlockJobSetSpeed: * virDomainBlockJobSetSpeed:
* @dom: pointer to domain object * @dom: pointer to domain object
* @path: fully-qualified filename of disk * @path: path to the block device, or device shorthand
* @bandwidth: specify bandwidth limit in Mbps * @bandwidth: specify bandwidth limit in Mbps
* @flags: currently unused, for future extension * @flags: currently unused, for future extension
* *
* Set the maximimum allowable bandwidth that a block job may consume. If * Set the maximimum allowable bandwidth that a block job may consume. If
* bandwidth is 0, the limit will revert to the hypervisor default. * bandwidth is 0, the limit will revert to the hypervisor default.
* *
* The @path parameter is either an unambiguous source name of the
* block device (the <source file='...'/> sub-element, such as
* "/path/to/image"), or (since 0.9.5) the device target shorthand
* (the <target dev='...'/> sub-element, such as "xvda"). Valid names
* can be found by calling virDomainGetXMLDesc() and inspecting
* elements within //domain/devices/disk.
*
* Returns -1 in case of failure, 0 when successful. * Returns -1 in case of failure, 0 when successful.
*/ */
int virDomainBlockJobSetSpeed(virDomainPtr dom, const char *path, int virDomainBlockJobSetSpeed(virDomainPtr dom, const char *path,
...@@ -16999,7 +17036,7 @@ error: ...@@ -16999,7 +17036,7 @@ error:
/** /**
* virDomainBlockPull: * virDomainBlockPull:
* @dom: pointer to domain object * @dom: pointer to domain object
* @path: Fully-qualified filename of disk * @path: path to the block device, or device shorthand
* @bandwidth: (optional) specify copy bandwidth limit in Mbps * @bandwidth: (optional) specify copy bandwidth limit in Mbps
* @flags: currently unused, for future extension * @flags: currently unused, for future extension
* *
...@@ -17010,6 +17047,13 @@ error: ...@@ -17010,6 +17047,13 @@ error:
* the operation can be aborted with virDomainBlockJobAbort(). When finished, * the operation can be aborted with virDomainBlockJobAbort(). When finished,
* an asynchronous event is raised to indicate the final status. * an asynchronous event is raised to indicate the final status.
* *
* The @path parameter is either an unambiguous source name of the
* block device (the <source file='...'/> sub-element, such as
* "/path/to/image"), or (since 0.9.5) the device target shorthand
* (the <target dev='...'/> sub-element, such as "xvda"). Valid names
* can be found by calling virDomainGetXMLDesc() and inspecting
* elements within //domain/devices/disk.
*
* The maximum bandwidth (in Mbps) that will be used to do the copy can be * The maximum bandwidth (in Mbps) that will be used to do the copy can be
* specified with the bandwidth parameter. If set to 0, libvirt will choose a * specified with the bandwidth parameter. If set to 0, libvirt will choose a
* suitable default. Some hypervisors do not support this feature and will * suitable default. Some hypervisors do not support this feature and will
......
...@@ -7082,18 +7082,12 @@ qemuDomainBlockStats(virDomainPtr dom, ...@@ -7082,18 +7082,12 @@ qemuDomainBlockStats(virDomainPtr dom,
goto cleanup; goto cleanup;
} }
for (i = 0 ; i < vm->def->ndisks ; i++) { if ((i = virDomainDiskIndexByName(vm->def, path, false)) < 0) {
if (STREQ(path, vm->def->disks[i]->dst)) {
disk = vm->def->disks[i];
break;
}
}
if (!disk) {
qemuReportError(VIR_ERR_INVALID_ARG, qemuReportError(VIR_ERR_INVALID_ARG,
_("invalid path: %s"), path); _("invalid path: %s"), path);
goto cleanup; goto cleanup;
} }
disk = vm->def->disks[i];
if (!disk->info.alias) { if (!disk->info.alias) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, qemuReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -7174,18 +7168,12 @@ qemuDomainBlockStatsFlags(virDomainPtr dom, ...@@ -7174,18 +7168,12 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
} }
if (*nparams != 0) { if (*nparams != 0) {
for (i = 0 ; i < vm->def->ndisks ; i++) { if ((i = virDomainDiskIndexByName(vm->def, path, false)) < 0) {
if (STREQ(path, vm->def->disks[i]->dst)) {
disk = vm->def->disks[i];
break;
}
}
if (!disk) {
qemuReportError(VIR_ERR_INVALID_ARG, qemuReportError(VIR_ERR_INVALID_ARG,
_("invalid path: %s"), path); _("invalid path: %s"), path);
goto cleanup; goto cleanup;
} }
disk = vm->def->disks[i];
if (!disk->info.alias) { if (!disk->info.alias) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, qemuReportError(VIR_ERR_INTERNAL_ERROR,
......
...@@ -2803,7 +2803,7 @@ static int testDomainBlockStats(virDomainPtr domain, ...@@ -2803,7 +2803,7 @@ static int testDomainBlockStats(virDomainPtr domain,
virDomainObjPtr privdom; virDomainObjPtr privdom;
struct timeval tv; struct timeval tv;
unsigned long long statbase; unsigned long long statbase;
int i, found = 0, ret = -1; int ret = -1;
testDriverLock(privconn); testDriverLock(privconn);
privdom = virDomainFindByName(&privconn->domains, privdom = virDomainFindByName(&privconn->domains,
...@@ -2815,14 +2815,7 @@ static int testDomainBlockStats(virDomainPtr domain, ...@@ -2815,14 +2815,7 @@ static int testDomainBlockStats(virDomainPtr domain,
goto error; goto error;
} }
for (i = 0 ; i < privdom->def->ndisks ; i++) { if (virDomainDiskIndexByName(privdom->def, path, false) < 0) {
if (STREQ(path, privdom->def->disks[i]->dst)) {
found = 1;
break;
}
}
if (!found) {
testError(VIR_ERR_INVALID_ARG, testError(VIR_ERR_INVALID_ARG,
_("invalid path: %s"), path); _("invalid path: %s"), path);
goto error; goto error;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册