mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
virIndexToDiskName: Make 'idx' unsigned and remove check
We can remove the check that 'idx' is negative by forcing callers to pass unsigned numbers, which they do already or have a check that 'idx' is positive. This in turn allows us to remove most return value NULL checks. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
f9eec3714c
commit
3b5eab6e25
@ -430,19 +430,13 @@ int virDiskNameToIndex(const char *name)
|
||||
return idx;
|
||||
}
|
||||
|
||||
char *virIndexToDiskName(int idx, const char *prefix)
|
||||
char *virIndexToDiskName(unsigned int idx, const char *prefix)
|
||||
{
|
||||
char *name = NULL;
|
||||
size_t i;
|
||||
int ctr;
|
||||
int offset;
|
||||
|
||||
if (idx < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Disk index %d is negative"), idx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0, ctr = idx; ctr >= 0; ++i, ctr = ctr / 26 - 1) { }
|
||||
|
||||
offset = strlen(prefix);
|
||||
|
@ -56,7 +56,7 @@ virFormatIntPretty(unsigned long long val,
|
||||
|
||||
int virDiskNameParse(const char *name, int *disk, int *partition);
|
||||
int virDiskNameToIndex(const char* str);
|
||||
char *virIndexToDiskName(int idx, const char *prefix);
|
||||
char *virIndexToDiskName(unsigned int idx, const char *prefix);
|
||||
|
||||
/* No-op workarounds for functionality missing in mingw. */
|
||||
#ifndef WITH_GETUID
|
||||
|
@ -2217,9 +2217,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
|
||||
(*def)->dst =
|
||||
virIndexToDiskName
|
||||
(controllerOrBus * 15 + (unit < 7 ? unit : unit - 1), "sd");
|
||||
|
||||
if ((*def)->dst == NULL)
|
||||
goto cleanup;
|
||||
} else if (busType == VIR_DOMAIN_DISK_BUS_SATA) {
|
||||
if (controllerOrBus < 0 || controllerOrBus > 3) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
@ -2238,9 +2235,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
|
||||
prefix = g_strdup_printf("sata%d:%d", controllerOrBus, unit);
|
||||
|
||||
(*def)->dst = virIndexToDiskName(controllerOrBus * 30 + unit, "sd");
|
||||
|
||||
if ((*def)->dst == NULL)
|
||||
goto cleanup;
|
||||
} else if (busType == VIR_DOMAIN_DISK_BUS_IDE) {
|
||||
if (controllerOrBus < 0 || controllerOrBus > 1) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
@ -2258,9 +2252,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
|
||||
prefix = g_strdup_printf("ide%d:%d", controllerOrBus, unit);
|
||||
|
||||
(*def)->dst = virIndexToDiskName(controllerOrBus * 2 + unit, "hd");
|
||||
|
||||
if ((*def)->dst == NULL)
|
||||
goto cleanup;
|
||||
} else {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("Unsupported bus type '%s' for device type '%s'"),
|
||||
@ -2287,9 +2278,6 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
|
||||
prefix = g_strdup_printf("floppy%d", unit);
|
||||
|
||||
(*def)->dst = virIndexToDiskName(unit, "fd");
|
||||
|
||||
if ((*def)->dst == NULL)
|
||||
goto cleanup;
|
||||
} else {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("Unsupported bus type '%s' for device type '%s'"),
|
||||
|
@ -626,9 +626,6 @@ prlsdkGetDiskId(PRL_HANDLE disk, int *bus, char **dst)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (NULL == *dst)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user