fix virsh's regression

This patch does the following things:
1. The return value of cmdSchedInfoUpdate() can be -1, 0 and 1. So the
   type of return value should be int not bool.(This function is not a
   entry of a virsh command, but the name of this function likes cmdXXX)

2. The type of cmdSchedinfo()'s, cmdFreecell()'s, cmdPoolList()'s and
   cmdVolList()'s return value is bool not int, so change the type of
   variable ret_val, func_ret and functionReturn.

3. Add a variable functionReturn for cmdMigrate(), cmdAttachInterface(),
   cmdDetachInterface(), cmdAttachDisk() and cmdDetachDisk() to save the
   return value.

4. Change the type of variable ret in the function cmdAttachDevice(),
   cmdDetachDevice(), cmdUpdateDevice(), cmdAttachInterface(),
   cmdDetachInterface(), cmdAttachDisk() and cmdDetachDisk() to int, as
   we use it to save the return value of virXXX() and the type of virXXX()'s
   return value is int not bool.

5. Do some cleanup when virBuff.error is 1.

The bug 1-4 were introduced by commit b56fa5bb.
This commit is contained in:
Wen Congyang 2011-04-26 11:03:04 +08:00
parent ab9102c232
commit 2225a49106

View File

@ -1593,7 +1593,7 @@ static const vshCmdOptDef opts_schedinfo[] = {
{NULL, 0, 0, NULL} {NULL, 0, 0, NULL}
}; };
static bool static int
cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd, cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
virSchedParameterPtr param) virSchedParameterPtr param)
{ {
@ -1696,7 +1696,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
int nparams = 0; int nparams = 0;
int update = 0; int update = 0;
int i, ret; int i, ret;
int ret_val = false; bool ret_val = false;
if (!vshConnectionUsability(ctl, ctl->conn)) if (!vshConnectionUsability(ctl, ctl->conn))
return false; return false;
@ -2288,7 +2288,7 @@ static const vshCmdOptDef opts_freecell[] = {
static bool static bool
cmdFreecell(vshControl *ctl, const vshCmd *cmd) cmdFreecell(vshControl *ctl, const vshCmd *cmd)
{ {
int func_ret = false; bool func_ret = false;
int ret; int ret;
int cell = -1, cell_given; int cell = -1, cell_given;
unsigned long long memory; unsigned long long memory;
@ -3847,6 +3847,7 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
int p[2] = {-1, -1}; int p[2] = {-1, -1};
int ret = -1; int ret = -1;
bool functionReturn = false;
virThread workerThread; virThread workerThread;
struct pollfd pollfd; struct pollfd pollfd;
char retchar; char retchar;
@ -3921,15 +3922,15 @@ repoll:
if (ret > 0) { if (ret > 0) {
if (saferead(p[0], &retchar, sizeof(retchar)) > 0) { if (saferead(p[0], &retchar, sizeof(retchar)) > 0) {
if (retchar == '0') { if (retchar == '0') {
ret = true; functionReturn = true;
if (verbose) { if (verbose) {
/* print [100 %] */ /* print [100 %] */
print_job_progress(0, 1); print_job_progress(0, 1);
} }
} else } else
ret = false; functionReturn = false;
} else } else
ret = false; functionReturn = false;
break; break;
} }
@ -3937,11 +3938,11 @@ repoll:
if (errno == EINTR) { if (errno == EINTR) {
if (intCaught) { if (intCaught) {
virDomainAbortJob(dom); virDomainAbortJob(dom);
ret = false;
intCaught = 0; intCaught = 0;
} else } else
goto repoll; goto repoll;
} }
functionReturn = false;
break; break;
} }
@ -3975,7 +3976,7 @@ cleanup:
virDomainFree(dom); virDomainFree(dom);
VIR_FORCE_CLOSE(p[0]); VIR_FORCE_CLOSE(p[0]);
VIR_FORCE_CLOSE(p[1]); VIR_FORCE_CLOSE(p[1]);
return ret; return functionReturn;
} }
/* /*
@ -5952,7 +5953,8 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{ {
virStoragePoolInfo info; virStoragePoolInfo info;
char **poolNames = NULL; char **poolNames = NULL;
int i, functionReturn, ret; int i, ret;
bool functionReturn;
int numActivePools = 0, numInactivePools = 0, numAllPools = 0; int numActivePools = 0, numInactivePools = 0, numAllPools = 0;
size_t stringLength = 0, nameStrLength = 0; size_t stringLength = 0, nameStrLength = 0;
size_t autostartStrLength = 0, persistStrLength = 0; size_t autostartStrLength = 0, persistStrLength = 0;
@ -7525,7 +7527,8 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
double val; double val;
int details = vshCommandOptBool(cmd, "details"); int details = vshCommandOptBool(cmd, "details");
int numVolumes = 0, i; int numVolumes = 0, i;
int ret, functionReturn; int ret;
bool functionReturn;
int stringLength = 0; int stringLength = 0;
size_t allocStrLength = 0, capStrLength = 0; size_t allocStrLength = 0, capStrLength = 0;
size_t nameStrLength = 0, pathStrLength = 0; size_t nameStrLength = 0, pathStrLength = 0;
@ -8904,7 +8907,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
virDomainPtr dom; virDomainPtr dom;
const char *from = NULL; const char *from = NULL;
char *buffer; char *buffer;
bool ret = true; int ret;
unsigned int flags; unsigned int flags;
if (!vshConnectionUsability(ctl, ctl->conn)) if (!vshConnectionUsability(ctl, ctl->conn))
@ -8969,7 +8972,7 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
virDomainPtr dom; virDomainPtr dom;
const char *from = NULL; const char *from = NULL;
char *buffer; char *buffer;
bool ret = true; int ret;
unsigned int flags; unsigned int flags;
if (!vshConnectionUsability(ctl, ctl->conn)) if (!vshConnectionUsability(ctl, ctl->conn))
@ -9035,7 +9038,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd)
virDomainPtr dom; virDomainPtr dom;
const char *from = NULL; const char *from = NULL;
char *buffer; char *buffer;
bool ret = true; int ret;
unsigned int flags; unsigned int flags;
if (!vshConnectionUsability(ctl, ctl->conn)) if (!vshConnectionUsability(ctl, ctl->conn))
@ -9110,7 +9113,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
const char *mac = NULL, *target = NULL, *script = NULL, const char *mac = NULL, *target = NULL, *script = NULL,
*type = NULL, *source = NULL, *model = NULL; *type = NULL, *source = NULL, *model = NULL;
int typ; int typ;
bool ret = false; int ret;
bool functionReturn = false;
unsigned int flags; unsigned int flags;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
char *xml; char *xml;
@ -9165,7 +9169,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
if (virBufferError(&buf)) { if (virBufferError(&buf)) {
vshPrint(ctl, "%s", _("Failed to allocate XML buffer")); vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
return false; goto cleanup;
} }
xml = virBufferContentAndReset(&buf); xml = virBufferContentAndReset(&buf);
@ -9183,17 +9187,16 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
if (ret != 0) { if (ret != 0) {
vshError(ctl, "%s", _("Failed to attach interface")); vshError(ctl, "%s", _("Failed to attach interface"));
ret = false;
} else { } else {
vshPrint(ctl, "%s", _("Interface attached successfully\n")); vshPrint(ctl, "%s", _("Interface attached successfully\n"));
ret = true; functionReturn = true;
} }
cleanup: cleanup:
if (dom) if (dom)
virDomainFree(dom); virDomainFree(dom);
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return ret; return functionReturn;
} }
/* /*
@ -9226,7 +9229,8 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
char *doc; char *doc;
char buf[64]; char buf[64];
int i = 0, diff_mac; int i = 0, diff_mac;
bool ret = false; int ret;
int functionReturn = false;
unsigned int flags; unsigned int flags;
if (!vshConnectionUsability(ctl, ctl->conn)) if (!vshConnectionUsability(ctl, ctl->conn))
@ -9322,10 +9326,9 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
if (ret != 0) { if (ret != 0) {
vshError(ctl, "%s", _("Failed to detach interface")); vshError(ctl, "%s", _("Failed to detach interface"));
ret = false;
} else { } else {
vshPrint(ctl, "%s", _("Interface detached successfully\n")); vshPrint(ctl, "%s", _("Interface detached successfully\n"));
ret = true; functionReturn = true;
} }
cleanup: cleanup:
@ -9337,7 +9340,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
xmlFreeDoc(xml); xmlFreeDoc(xml);
if (xml_buf) if (xml_buf)
xmlBufferFree(xml_buf); xmlBufferFree(xml_buf);
return ret; return functionReturn;
} }
/* /*
@ -9368,7 +9371,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
const char *source = NULL, *target = NULL, *driver = NULL, const char *source = NULL, *target = NULL, *driver = NULL,
*subdriver = NULL, *type = NULL, *mode = NULL; *subdriver = NULL, *type = NULL, *mode = NULL;
bool isFile = false, ret = false; bool isFile = false, functionReturn = false;
int ret;
unsigned int flags; unsigned int flags;
const char *stype = NULL; const char *stype = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
@ -9460,17 +9464,16 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
if (ret != 0) { if (ret != 0) {
vshError(ctl, "%s", _("Failed to attach disk")); vshError(ctl, "%s", _("Failed to attach disk"));
ret = false;
} else { } else {
vshPrint(ctl, "%s", _("Disk attached successfully\n")); vshPrint(ctl, "%s", _("Disk attached successfully\n"));
ret = true; functionReturn = true;
} }
cleanup: cleanup:
if (dom) if (dom)
virDomainFree(dom); virDomainFree(dom);
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return ret; return functionReturn;
} }
/* /*
@ -9501,7 +9504,8 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
const char *target = NULL; const char *target = NULL;
char *doc; char *doc;
int i = 0, diff_tgt; int i = 0, diff_tgt;
bool ret = false; int ret;
bool functionReturn = false;
unsigned int flags; unsigned int flags;
if (!vshConnectionUsability(ctl, ctl->conn)) if (!vshConnectionUsability(ctl, ctl->conn))
@ -9582,10 +9586,9 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
if (ret != 0) { if (ret != 0) {
vshError(ctl, "%s", _("Failed to detach disk")); vshError(ctl, "%s", _("Failed to detach disk"));
ret = false;
} else { } else {
vshPrint(ctl, "%s", _("Disk detached successfully\n")); vshPrint(ctl, "%s", _("Disk detached successfully\n"));
ret = true; functionReturn = true;
} }
cleanup: cleanup:
@ -9597,7 +9600,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
xmlBufferFree(xml_buf); xmlBufferFree(xml_buf);
if (dom) if (dom)
virDomainFree(dom); virDomainFree(dom);
return ret; return functionReturn;
} }
/* /*