mirror of https://gitee.com/openkylin/libvirt.git
openvz: formatting cleanups
* src/openvz/openvz_conf.c: Whitespace fixes. * src/openvz/openvz_driver.c: Likewise.
This commit is contained in:
parent
ff82941604
commit
c6e8e26edf
|
@ -64,7 +64,7 @@ strtoI(const char *str)
|
|||
int val;
|
||||
|
||||
if (virStrToLong_i(str, NULL, 10, &val) < 0)
|
||||
return 0 ;
|
||||
return 0;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ openvz_replace(const char* str,
|
|||
from_len = strlen(from);
|
||||
to_len = strlen(to);
|
||||
|
||||
while((offset = strstr(str_start, from)))
|
||||
while ((offset = strstr(str_start, from)))
|
||||
{
|
||||
virBufferAdd(&buf, str_start, offset-str_start);
|
||||
virBufferAdd(&buf, to, to_len);
|
||||
|
@ -447,7 +447,7 @@ int openvzLoadDomains(struct openvz_driver *driver) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
while(!feof(fp)) {
|
||||
while (!feof(fp)) {
|
||||
if (fscanf(fp, "%d %s\n", &veid, status) != 2) {
|
||||
if (feof(fp))
|
||||
break;
|
||||
|
@ -556,7 +556,7 @@ openvzWriteConfigParam(const char * conf_file, const char *param, const char *va
|
|||
{
|
||||
char * temp_file = NULL;
|
||||
int fd = -1, temp_fd = -1;
|
||||
char line[PATH_MAX] ;
|
||||
char line[PATH_MAX];
|
||||
|
||||
if (virAsprintf(&temp_file, "%s.tmp", conf_file)<0) {
|
||||
virReportOOMError();
|
||||
|
@ -572,7 +572,7 @@ openvzWriteConfigParam(const char * conf_file, const char *param, const char *va
|
|||
goto error;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
while (1) {
|
||||
if (openvz_readline(fd, line, sizeof(line)) <= 0)
|
||||
break;
|
||||
|
||||
|
@ -606,7 +606,7 @@ error:
|
|||
close(fd);
|
||||
if (temp_fd != -1)
|
||||
close(temp_fd);
|
||||
if(temp_file)
|
||||
if (temp_file)
|
||||
unlink(temp_file);
|
||||
VIR_FREE(temp_file);
|
||||
return -1;
|
||||
|
@ -626,9 +626,9 @@ openvzWriteVPSConfigParam(int vpsid, const char *param, const char *value)
|
|||
static int
|
||||
openvzReadConfigParam(const char * conf_file ,const char * param, char *value, int maxlen)
|
||||
{
|
||||
char line[PATH_MAX] ;
|
||||
char line[PATH_MAX];
|
||||
int ret, found = 0;
|
||||
int fd ;
|
||||
int fd;
|
||||
char * sf, * token;
|
||||
char *saveptr = NULL;
|
||||
|
||||
|
@ -638,16 +638,16 @@ openvzReadConfigParam(const char * conf_file ,const char * param, char *value, i
|
|||
if (fd == -1)
|
||||
return -1;
|
||||
|
||||
while(1) {
|
||||
while (1) {
|
||||
ret = openvz_readline(fd, line, sizeof(line));
|
||||
if(ret <= 0)
|
||||
if (ret <= 0)
|
||||
break;
|
||||
saveptr = NULL;
|
||||
if (STREQLEN(line, param, strlen(param))) {
|
||||
sf = line;
|
||||
sf += strlen(param);
|
||||
if (sf[0] == '=' && sf[1] != '\0' ) {
|
||||
sf ++;
|
||||
sf++;
|
||||
if ((token = strtok_r(sf,"\"\t\n", &saveptr)) != NULL) {
|
||||
if (virStrcpy(value, token, maxlen) == NULL) {
|
||||
ret = -1;
|
||||
|
@ -663,7 +663,7 @@ openvzReadConfigParam(const char * conf_file ,const char * param, char *value, i
|
|||
if (ret == 0 && found)
|
||||
ret = 1;
|
||||
|
||||
return ret ;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -676,7 +676,7 @@ openvzReadConfigParam(const char * conf_file ,const char * param, char *value, i
|
|||
int
|
||||
openvzReadVPSConfigParam(int vpsid ,const char * param, char *value, int maxlen)
|
||||
{
|
||||
char conf_file[PATH_MAX] ;
|
||||
char conf_file[PATH_MAX];
|
||||
|
||||
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
|
||||
return -1;
|
||||
|
@ -700,7 +700,7 @@ openvz_copyfile(char* from_path, char* to_path)
|
|||
return -1;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
while (1) {
|
||||
if (openvz_readline(fd, line, sizeof(line)) <= 0)
|
||||
break;
|
||||
|
||||
|
@ -739,7 +739,8 @@ openvzCopyDefaultConfig(int vpsid)
|
|||
char conf_file[PATH_MAX];
|
||||
int ret = -1;
|
||||
|
||||
if(openvzReadConfigParam(VZ_CONF_FILE, "CONFIGFILE", configfile_value, PATH_MAX) < 0)
|
||||
if (openvzReadConfigParam(VZ_CONF_FILE, "CONFIGFILE", configfile_value,
|
||||
PATH_MAX) < 0)
|
||||
goto cleanup;
|
||||
|
||||
confdir = openvzLocateConfDir();
|
||||
|
@ -792,10 +793,10 @@ static char
|
|||
const char *conf_dir_list[] = {"/etc/vz/conf", "/usr/local/etc/conf", NULL};
|
||||
int i=0;
|
||||
|
||||
while(conf_dir_list[i]) {
|
||||
if(!access(conf_dir_list[i], F_OK))
|
||||
while (conf_dir_list[i]) {
|
||||
if (!access(conf_dir_list[i], F_OK))
|
||||
return strdup(conf_dir_list[i]);
|
||||
i ++;
|
||||
i++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -808,14 +809,13 @@ openvz_readline(int fd, char *ptr, int maxlen)
|
|||
int n, rc;
|
||||
char c;
|
||||
|
||||
for(n = 1; n < maxlen; n ++) {
|
||||
if( (rc = read(fd, &c, 1)) == 1) {
|
||||
for (n = 1; n < maxlen; n++) {
|
||||
if ( (rc = read(fd, &c, 1)) == 1) {
|
||||
*ptr++ = c;
|
||||
if(c == '\n')
|
||||
if (c == '\n')
|
||||
break;
|
||||
}
|
||||
else if(rc == 0) {
|
||||
if(n == 1)
|
||||
} else if (rc == 0) {
|
||||
if (n == 1)
|
||||
return 0; /* EOF condition */
|
||||
else
|
||||
break;
|
||||
|
@ -839,20 +839,20 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len)
|
|||
int retval = 0;
|
||||
|
||||
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
|
||||
return -1;
|
||||
|
||||
fd = open(conf_file, O_RDONLY);
|
||||
if(fd == -1)
|
||||
return -1;
|
||||
|
||||
while(1) {
|
||||
fd = open(conf_file, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
|
||||
while (1) {
|
||||
ret = openvz_readline(fd, line, sizeof(line));
|
||||
if(ret == -1) {
|
||||
if (ret == -1) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(ret == 0) { /* EoF, UUID was not found */
|
||||
if (ret == 0) { /* EoF, UUID was not found */
|
||||
uuidstr[0] = 0;
|
||||
break;
|
||||
}
|
||||
|
@ -884,7 +884,7 @@ openvzSetDefinedUUID(int vpsid, unsigned char *uuid)
|
|||
return -1;
|
||||
|
||||
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
if (openvzGetVPSUUID(vpsid, uuidstr, sizeof(uuidstr)))
|
||||
return -1;
|
||||
|
@ -892,7 +892,7 @@ openvzSetDefinedUUID(int vpsid, unsigned char *uuid)
|
|||
if (uuidstr[0] == 0) {
|
||||
FILE *fp = fopen(conf_file, "a"); /* append */
|
||||
if (fp == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
virUUIDFormat(uuid, uuidstr);
|
||||
|
||||
|
@ -939,16 +939,16 @@ static int openvzAssignUUIDs(void)
|
|||
return -1;
|
||||
|
||||
dp = opendir(conf_dir);
|
||||
if(dp == NULL) {
|
||||
if (dp == NULL) {
|
||||
VIR_FREE(conf_dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
while((dent = readdir(dp))) {
|
||||
while ((dent = readdir(dp))) {
|
||||
res = sscanf(dent->d_name, "%d.%5s", &vpsid, ext);
|
||||
if(!(res == 2 && STREQ(ext, "conf")))
|
||||
if (!(res == 2 && STREQ(ext, "conf")))
|
||||
continue;
|
||||
if(vpsid > 0) /* '0.conf' belongs to the host, ignore it */
|
||||
if (vpsid > 0) /* '0.conf' belongs to the host, ignore it */
|
||||
openvzSetUUID(vpsid);
|
||||
}
|
||||
closedir(dp);
|
||||
|
|
|
@ -88,8 +88,7 @@ struct openvz_driver ovz_driver;
|
|||
static void cmdExecFree(const char *cmdExec[])
|
||||
{
|
||||
int i=-1;
|
||||
while(cmdExec[++i])
|
||||
{
|
||||
while (cmdExec[++i]) {
|
||||
VIR_FREE(cmdExec[i]);
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +225,7 @@ static int openvzSetInitialConfig(virDomainDefPtr vmdef)
|
|||
vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_MOUNT)
|
||||
{
|
||||
|
||||
if(virStrToLong_i(vmdef->name, NULL, 10, &vpsid) < 0) {
|
||||
if (virStrToLong_i(vmdef->name, NULL, 10, &vpsid) < 0) {
|
||||
openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Could not convert domain name to VEID"));
|
||||
goto cleanup;
|
||||
|
@ -802,7 +801,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
|
|||
|
||||
//TODO: processing NAT and physical device
|
||||
|
||||
if (prog[0] != NULL){
|
||||
if (prog[0] != NULL) {
|
||||
ADD_ARG_LIT("--save");
|
||||
if (virRun(prog, NULL) < 0) {
|
||||
openvzError(VIR_ERR_INTERNAL_ERROR,
|
||||
|
@ -1397,15 +1396,16 @@ static int openvzListDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||
|
||||
ret = virExec(cmd, NULL, NULL,
|
||||
&pid, -1, &outfd, &errfd, VIR_EXEC_NONE);
|
||||
if(ret == -1) {
|
||||
if (ret == -1) {
|
||||
openvzError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Could not exec %s"), VZLIST);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while(got < nids){
|
||||
while (got < nids) {
|
||||
ret = openvz_readline(outfd, buf, 32);
|
||||
if(!ret) break;
|
||||
if (!ret)
|
||||
break;
|
||||
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
|
||||
openvzError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Could not parse VPS ID %s"), buf);
|
||||
|
@ -1443,15 +1443,16 @@ static int openvzListDefinedDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||
/* the -S options lists only stopped domains */
|
||||
ret = virExec(cmd, NULL, NULL,
|
||||
&pid, -1, &outfd, &errfd, VIR_EXEC_NONE);
|
||||
if(ret == -1) {
|
||||
if (ret == -1) {
|
||||
openvzError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Could not exec %s"), VZLIST);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while(got < nnames){
|
||||
while (got < nnames) {
|
||||
ret = openvz_readline(outfd, buf, 32);
|
||||
if(!ret) break;
|
||||
if (!ret)
|
||||
break;
|
||||
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
|
||||
openvzError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Could not parse VPS ID %s"), buf);
|
||||
|
@ -1491,7 +1492,7 @@ Version: 2.2
|
|||
return -1;
|
||||
|
||||
/*search line with VEID=vpsid*/
|
||||
while(1) {
|
||||
while (1) {
|
||||
ret = openvz_readline(fd, line, sizeof(line));
|
||||
if (ret <= 0)
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue