1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

openvz: formatting cleanups

* src/openvz/openvz_conf.c: Whitespace fixes.
* src/openvz/openvz_driver.c: Likewise.
This commit is contained in:
Eric Blake 2010-08-31 16:43:18 -06:00
parent ff82941604
commit c6e8e26edf
2 changed files with 49 additions and 48 deletions

View File

@ -64,7 +64,7 @@ strtoI(const char *str)
int val; int val;
if (virStrToLong_i(str, NULL, 10, &val) < 0) if (virStrToLong_i(str, NULL, 10, &val) < 0)
return 0 ; return 0;
return val; return val;
} }
@ -338,7 +338,7 @@ openvz_replace(const char* str,
from_len = strlen(from); from_len = strlen(from);
to_len = strlen(to); 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, str_start, offset-str_start);
virBufferAdd(&buf, to, to_len); virBufferAdd(&buf, to, to_len);
@ -447,7 +447,7 @@ int openvzLoadDomains(struct openvz_driver *driver) {
return -1; return -1;
} }
while(!feof(fp)) { while (!feof(fp)) {
if (fscanf(fp, "%d %s\n", &veid, status) != 2) { if (fscanf(fp, "%d %s\n", &veid, status) != 2) {
if (feof(fp)) if (feof(fp))
break; break;
@ -556,7 +556,7 @@ openvzWriteConfigParam(const char * conf_file, const char *param, const char *va
{ {
char * temp_file = NULL; char * temp_file = NULL;
int fd = -1, temp_fd = -1; int fd = -1, temp_fd = -1;
char line[PATH_MAX] ; char line[PATH_MAX];
if (virAsprintf(&temp_file, "%s.tmp", conf_file)<0) { if (virAsprintf(&temp_file, "%s.tmp", conf_file)<0) {
virReportOOMError(); virReportOOMError();
@ -572,7 +572,7 @@ openvzWriteConfigParam(const char * conf_file, const char *param, const char *va
goto error; goto error;
} }
while(1) { while (1) {
if (openvz_readline(fd, line, sizeof(line)) <= 0) if (openvz_readline(fd, line, sizeof(line)) <= 0)
break; break;
@ -606,7 +606,7 @@ error:
close(fd); close(fd);
if (temp_fd != -1) if (temp_fd != -1)
close(temp_fd); close(temp_fd);
if(temp_file) if (temp_file)
unlink(temp_file); unlink(temp_file);
VIR_FREE(temp_file); VIR_FREE(temp_file);
return -1; return -1;
@ -626,9 +626,9 @@ openvzWriteVPSConfigParam(int vpsid, const char *param, const char *value)
static int static int
openvzReadConfigParam(const char * conf_file ,const char * param, char *value, int maxlen) 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 ret, found = 0;
int fd ; int fd;
char * sf, * token; char * sf, * token;
char *saveptr = NULL; char *saveptr = NULL;
@ -638,16 +638,16 @@ openvzReadConfigParam(const char * conf_file ,const char * param, char *value, i
if (fd == -1) if (fd == -1)
return -1; return -1;
while(1) { while (1) {
ret = openvz_readline(fd, line, sizeof(line)); ret = openvz_readline(fd, line, sizeof(line));
if(ret <= 0) if (ret <= 0)
break; break;
saveptr = NULL; saveptr = NULL;
if (STREQLEN(line, param, strlen(param))) { if (STREQLEN(line, param, strlen(param))) {
sf = line; sf = line;
sf += strlen(param); sf += strlen(param);
if (sf[0] == '=' && sf[1] != '\0' ) { if (sf[0] == '=' && sf[1] != '\0' ) {
sf ++; sf++;
if ((token = strtok_r(sf,"\"\t\n", &saveptr)) != NULL) { if ((token = strtok_r(sf,"\"\t\n", &saveptr)) != NULL) {
if (virStrcpy(value, token, maxlen) == NULL) { if (virStrcpy(value, token, maxlen) == NULL) {
ret = -1; ret = -1;
@ -663,7 +663,7 @@ openvzReadConfigParam(const char * conf_file ,const char * param, char *value, i
if (ret == 0 && found) if (ret == 0 && found)
ret = 1; ret = 1;
return ret ; return ret;
} }
/* /*
@ -676,7 +676,7 @@ openvzReadConfigParam(const char * conf_file ,const char * param, char *value, i
int int
openvzReadVPSConfigParam(int vpsid ,const char * param, char *value, int maxlen) 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) if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX, "conf")<0)
return -1; return -1;
@ -700,7 +700,7 @@ openvz_copyfile(char* from_path, char* to_path)
return -1; return -1;
} }
while(1) { while (1) {
if (openvz_readline(fd, line, sizeof(line)) <= 0) if (openvz_readline(fd, line, sizeof(line)) <= 0)
break; break;
@ -739,7 +739,8 @@ openvzCopyDefaultConfig(int vpsid)
char conf_file[PATH_MAX]; char conf_file[PATH_MAX];
int ret = -1; 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; goto cleanup;
confdir = openvzLocateConfDir(); confdir = openvzLocateConfDir();
@ -792,10 +793,10 @@ static char
const char *conf_dir_list[] = {"/etc/vz/conf", "/usr/local/etc/conf", NULL}; const char *conf_dir_list[] = {"/etc/vz/conf", "/usr/local/etc/conf", NULL};
int i=0; int i=0;
while(conf_dir_list[i]) { while (conf_dir_list[i]) {
if(!access(conf_dir_list[i], F_OK)) if (!access(conf_dir_list[i], F_OK))
return strdup(conf_dir_list[i]); return strdup(conf_dir_list[i]);
i ++; i++;
} }
return NULL; return NULL;
@ -808,14 +809,13 @@ openvz_readline(int fd, char *ptr, int maxlen)
int n, rc; int n, rc;
char c; char c;
for(n = 1; n < maxlen; n ++) { for (n = 1; n < maxlen; n++) {
if( (rc = read(fd, &c, 1)) == 1) { if ( (rc = read(fd, &c, 1)) == 1) {
*ptr++ = c; *ptr++ = c;
if(c == '\n') if (c == '\n')
break; break;
} } else if (rc == 0) {
else if(rc == 0) { if (n == 1)
if(n == 1)
return 0; /* EOF condition */ return 0; /* EOF condition */
else else
break; break;
@ -842,17 +842,17 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len)
return -1; return -1;
fd = open(conf_file, O_RDONLY); fd = open(conf_file, O_RDONLY);
if(fd == -1) if (fd == -1)
return -1; return -1;
while(1) { while (1) {
ret = openvz_readline(fd, line, sizeof(line)); ret = openvz_readline(fd, line, sizeof(line));
if(ret == -1) { if (ret == -1) {
close(fd); close(fd);
return -1; return -1;
} }
if(ret == 0) { /* EoF, UUID was not found */ if (ret == 0) { /* EoF, UUID was not found */
uuidstr[0] = 0; uuidstr[0] = 0;
break; break;
} }
@ -939,16 +939,16 @@ static int openvzAssignUUIDs(void)
return -1; return -1;
dp = opendir(conf_dir); dp = opendir(conf_dir);
if(dp == NULL) { if (dp == NULL) {
VIR_FREE(conf_dir); VIR_FREE(conf_dir);
return 0; return 0;
} }
while((dent = readdir(dp))) { while ((dent = readdir(dp))) {
res = sscanf(dent->d_name, "%d.%5s", &vpsid, ext); res = sscanf(dent->d_name, "%d.%5s", &vpsid, ext);
if(!(res == 2 && STREQ(ext, "conf"))) if (!(res == 2 && STREQ(ext, "conf")))
continue; 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); openvzSetUUID(vpsid);
} }
closedir(dp); closedir(dp);

View File

@ -88,8 +88,7 @@ struct openvz_driver ovz_driver;
static void cmdExecFree(const char *cmdExec[]) static void cmdExecFree(const char *cmdExec[])
{ {
int i=-1; int i=-1;
while(cmdExec[++i]) while (cmdExec[++i]) {
{
VIR_FREE(cmdExec[i]); VIR_FREE(cmdExec[i]);
} }
} }
@ -226,7 +225,7 @@ static int openvzSetInitialConfig(virDomainDefPtr vmdef)
vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_MOUNT) 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", openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not convert domain name to VEID")); _("Could not convert domain name to VEID"));
goto cleanup; goto cleanup;
@ -802,7 +801,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
//TODO: processing NAT and physical device //TODO: processing NAT and physical device
if (prog[0] != NULL){ if (prog[0] != NULL) {
ADD_ARG_LIT("--save"); ADD_ARG_LIT("--save");
if (virRun(prog, NULL) < 0) { if (virRun(prog, NULL) < 0) {
openvzError(VIR_ERR_INTERNAL_ERROR, openvzError(VIR_ERR_INTERNAL_ERROR,
@ -1397,15 +1396,16 @@ static int openvzListDomains(virConnectPtr conn ATTRIBUTE_UNUSED,
ret = virExec(cmd, NULL, NULL, ret = virExec(cmd, NULL, NULL,
&pid, -1, &outfd, &errfd, VIR_EXEC_NONE); &pid, -1, &outfd, &errfd, VIR_EXEC_NONE);
if(ret == -1) { if (ret == -1) {
openvzError(VIR_ERR_INTERNAL_ERROR, openvzError(VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZLIST); _("Could not exec %s"), VZLIST);
return -1; return -1;
} }
while(got < nids){ while (got < nids) {
ret = openvz_readline(outfd, buf, 32); ret = openvz_readline(outfd, buf, 32);
if(!ret) break; if (!ret)
break;
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) { if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
openvzError(VIR_ERR_INTERNAL_ERROR, openvzError(VIR_ERR_INTERNAL_ERROR,
_("Could not parse VPS ID %s"), buf); _("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 */ /* the -S options lists only stopped domains */
ret = virExec(cmd, NULL, NULL, ret = virExec(cmd, NULL, NULL,
&pid, -1, &outfd, &errfd, VIR_EXEC_NONE); &pid, -1, &outfd, &errfd, VIR_EXEC_NONE);
if(ret == -1) { if (ret == -1) {
openvzError(VIR_ERR_INTERNAL_ERROR, openvzError(VIR_ERR_INTERNAL_ERROR,
_("Could not exec %s"), VZLIST); _("Could not exec %s"), VZLIST);
return -1; return -1;
} }
while(got < nnames){ while (got < nnames) {
ret = openvz_readline(outfd, buf, 32); ret = openvz_readline(outfd, buf, 32);
if(!ret) break; if (!ret)
break;
if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) { if (virStrToLong_i(buf, &endptr, 10, &veid) < 0) {
openvzError(VIR_ERR_INTERNAL_ERROR, openvzError(VIR_ERR_INTERNAL_ERROR,
_("Could not parse VPS ID %s"), buf); _("Could not parse VPS ID %s"), buf);
@ -1491,7 +1492,7 @@ Version: 2.2
return -1; return -1;
/*search line with VEID=vpsid*/ /*search line with VEID=vpsid*/
while(1) { while (1) {
ret = openvz_readline(fd, line, sizeof(line)); ret = openvz_readline(fd, line, sizeof(line));
if (ret <= 0) if (ret <= 0)
break; break;