pmxcfs: format: insert braces after control statements
Improves readability and avoids bugs, as it's really explicit which statements are guarded by a control statement and what isn't. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
3ef5faffd4
commit
60e36c87b0
17 changed files with 747 additions and 373 deletions
|
|
@ -4,3 +4,5 @@ IndentWidth: 4
|
|||
AlignAfterOpenBracket: BlockIndent
|
||||
BinPackParameters: false # TODO: evaluate using OnePerLine (needs clang 20+) for a balanance?
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
InsertBraces: true
|
||||
|
|
|
|||
|
|
@ -54,8 +54,9 @@ static void cfs_plug_func_destroy(cfs_plug_t *plug) {
|
|||
|
||||
cfs_debug("enter cfs_plug_func_destroy %s", plug->name);
|
||||
|
||||
if (fplug->data)
|
||||
if (fplug->data) {
|
||||
g_free(fplug->data);
|
||||
}
|
||||
|
||||
g_free(plug->name);
|
||||
|
||||
|
|
@ -75,8 +76,9 @@ static int cfs_plug_func_getattr(cfs_plug_t *plug, const char *path, struct stat
|
|||
memset(stbuf, 0, sizeof(struct stat));
|
||||
|
||||
g_rw_lock_writer_lock(&fplug->data_rw_lock);
|
||||
if (fplug->data)
|
||||
if (fplug->data) {
|
||||
g_free(fplug->data);
|
||||
}
|
||||
|
||||
fplug->data = fplug->update_callback(plug);
|
||||
|
||||
|
|
@ -120,8 +122,9 @@ static int cfs_plug_func_read(
|
|||
int len = strlen(data);
|
||||
|
||||
if (offset < len) {
|
||||
if (offset + size > len)
|
||||
if (offset + size > len) {
|
||||
size = len - offset;
|
||||
}
|
||||
memcpy(buf, data + offset, size);
|
||||
} else {
|
||||
size = 0;
|
||||
|
|
@ -150,8 +153,9 @@ static int cfs_plug_func_write(
|
|||
|
||||
cfs_plug_func_t *fplug = (cfs_plug_func_t *)plug;
|
||||
|
||||
if (offset != 0 || !fplug->write_callback)
|
||||
if (offset != 0 || !fplug->write_callback) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return fplug->write_callback(plug, buf, size);
|
||||
}
|
||||
|
|
@ -163,8 +167,9 @@ static int cfs_plug_func_truncate(cfs_plug_t *plug, const char *path, off_t size
|
|||
|
||||
cfs_plug_func_t *fplug = (cfs_plug_func_t *)plug;
|
||||
|
||||
if (fplug->write_callback)
|
||||
if (fplug->write_callback) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -EIO;
|
||||
}
|
||||
|
|
@ -208,8 +213,9 @@ cfs_plug_func_t *cfs_plug_func_new(
|
|||
|
||||
fplug->update_callback = update_callback;
|
||||
fplug->write_callback = write_callback;
|
||||
if (!write_callback)
|
||||
if (!write_callback) {
|
||||
mode = mode & ~0222;
|
||||
}
|
||||
|
||||
fplug->mode = S_IFREG | mode;
|
||||
|
||||
|
|
|
|||
|
|
@ -80,12 +80,14 @@ static int cfs_plug_link_readlink(cfs_plug_t *plug, const char *path, char *buf,
|
|||
|
||||
cfs_plug_link_t *lnk = (cfs_plug_link_t *)plug;
|
||||
|
||||
if (!lnk->symlink)
|
||||
if (!lnk->symlink) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
strncpy(buf, lnk->symlink, max);
|
||||
if (max > 0)
|
||||
if (max > 0) {
|
||||
buf[max - 1] = '\0';
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
ret:
|
||||
|
|
|
|||
|
|
@ -44,8 +44,9 @@ static struct cfs_operations cfs_ops;
|
|||
|
||||
// FIXME: remove openvz stuff for 7.x
|
||||
static gboolean name_is_openvz_script(const char *name, guint32 *vmid_ret) {
|
||||
if (!name)
|
||||
if (!name) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
guint32 vmid = 0;
|
||||
char *end = NULL;
|
||||
|
|
@ -53,33 +54,40 @@ static gboolean name_is_openvz_script(const char *name, guint32 *vmid_ret) {
|
|||
if (name[0] == 'v' && name[1] == 'p' && name[2] == 's') {
|
||||
end = (char *)name + 3;
|
||||
} else {
|
||||
if (name[0] < '1' || name[0] > '9')
|
||||
if (name[0] < '1' || name[0] > '9') {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
vmid = strtoul(name, &end, 10);
|
||||
}
|
||||
|
||||
if (!end || end[0] != '.')
|
||||
if (!end || end[0] != '.') {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
end++;
|
||||
|
||||
gboolean res = FALSE;
|
||||
|
||||
if (end[0] == 'm' && strcmp(end, "mount") == 0)
|
||||
if (end[0] == 'm' && strcmp(end, "mount") == 0) {
|
||||
res = TRUE;
|
||||
}
|
||||
|
||||
if (end[0] == 'u' && strcmp(end, "umount") == 0)
|
||||
if (end[0] == 'u' && strcmp(end, "umount") == 0) {
|
||||
res = TRUE;
|
||||
}
|
||||
|
||||
if (end[0] == 's' && (strcmp(end, "start") == 0 || strcmp(end, "stop") == 0))
|
||||
if (end[0] == 's' && (strcmp(end, "start") == 0 || strcmp(end, "stop") == 0)) {
|
||||
res = TRUE;
|
||||
}
|
||||
|
||||
if (end[0] == 'p' && (strcmp(end, "premount") == 0 || strcmp(end, "postumount") == 0))
|
||||
if (end[0] == 'p' && (strcmp(end, "premount") == 0 || strcmp(end, "postumount") == 0)) {
|
||||
res = TRUE;
|
||||
}
|
||||
|
||||
if (res && vmid_ret)
|
||||
if (res && vmid_ret) {
|
||||
*vmid_ret = vmid;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -184,8 +192,9 @@ static int cfs_plug_memdb_open(cfs_plug_t *plug, const char *path, struct fuse_f
|
|||
|
||||
if ((te = memdb_getattr(mdb->memdb, path))) {
|
||||
memdb_tree_entry_free(te);
|
||||
} else
|
||||
} else {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -211,19 +220,22 @@ static int cfs_plug_memdb_read(
|
|||
cfs_plug_memdb_t *mdb = (cfs_plug_memdb_t *)plug;
|
||||
|
||||
len = memdb_read(mdb->memdb, path, &data);
|
||||
if (len < 0)
|
||||
if (len < 0) {
|
||||
return len;
|
||||
}
|
||||
|
||||
if (offset < len) {
|
||||
if (offset + size > len)
|
||||
if (offset + size > len) {
|
||||
size = len - offset;
|
||||
}
|
||||
memcpy(buf, (uint8_t *)data + offset, size);
|
||||
} else {
|
||||
size = 0;
|
||||
}
|
||||
|
||||
if (data)
|
||||
if (data) {
|
||||
g_free(data);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
|
@ -401,8 +413,9 @@ static int cfs_plug_memdb_utimens(cfs_plug_t *plug, const char *path, const stru
|
|||
}
|
||||
|
||||
if (mdb->dfsm) {
|
||||
if (unlock_req && memdb_tree_entry_csum(te, csum))
|
||||
if (unlock_req && memdb_tree_entry_csum(te, csum)) {
|
||||
dcdb_send_unlock(mdb->dfsm, path, csum, TRUE);
|
||||
}
|
||||
|
||||
res = dcdb_send_fuse_message(
|
||||
mdb->dfsm, DCDB_MESSAGE_CFS_MTIME, path, NULL, NULL, 0, mtime, 0
|
||||
|
|
|
|||
|
|
@ -50,8 +50,9 @@ static cfs_plug_t *cfs_plug_base_lookup_plug(cfs_plug_t *plug, char **path) {
|
|||
|
||||
cfs_debug("cfs_plug_base_lookup_plug %s", *path);
|
||||
|
||||
if (!*path || !(*path)[0])
|
||||
if (!*path || !(*path)[0]) {
|
||||
return plug;
|
||||
}
|
||||
|
||||
char *name = strsep(path, "/");
|
||||
|
||||
|
|
@ -61,14 +62,16 @@ static cfs_plug_t *cfs_plug_base_lookup_plug(cfs_plug_t *plug, char **path) {
|
|||
|
||||
if (!(sub = (cfs_plug_t *)g_hash_table_lookup(bplug->entries, name))) {
|
||||
/* revert strsep modification */
|
||||
if (*path)
|
||||
if (*path) {
|
||||
(*path)[-1] = '/';
|
||||
}
|
||||
*path = name;
|
||||
return plug;
|
||||
}
|
||||
|
||||
if ((sub = sub->lookup_plug(sub, path)))
|
||||
if ((sub = sub->lookup_plug(sub, path))) {
|
||||
return sub;
|
||||
}
|
||||
|
||||
*path = NULL;
|
||||
return NULL;
|
||||
|
|
@ -89,8 +92,9 @@ static int cfs_plug_base_getattr(cfs_plug_t *plug, const char *path, struct stat
|
|||
if (*path) {
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (base && base->ops && base->ops->getattr)
|
||||
if (base && base->ops && base->ops->getattr) {
|
||||
ret = base->ops->getattr(base, path, stbuf);
|
||||
}
|
||||
goto ret;
|
||||
}
|
||||
|
||||
|
|
@ -113,11 +117,13 @@ static int tmp_hash_filler(void *buf, const char *name, const struct stat *stbuf
|
|||
|
||||
struct hash_filler *hf = (struct hash_filler *)buf;
|
||||
|
||||
if (hf->entries && g_hash_table_lookup(hf->entries, name))
|
||||
if (hf->entries && g_hash_table_lookup(hf->entries, name)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0)))
|
||||
if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] == 0))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
hf->filler(hf->buf, name, stbuf, off);
|
||||
|
||||
|
|
@ -166,8 +172,9 @@ static int cfs_plug_base_readdir(
|
|||
if (base && base->ops && base->ops->readdir) {
|
||||
struct hash_filler hf = {.buf = buf, .filler = filler, .entries = NULL};
|
||||
|
||||
if (!path[0])
|
||||
if (!path[0]) {
|
||||
hf.entries = bplug->entries;
|
||||
}
|
||||
|
||||
ret = base->ops->readdir(base, path, &hf, tmp_hash_filler, 0, fi);
|
||||
|
||||
|
|
@ -189,8 +196,9 @@ static int cfs_plug_base_mkdir(cfs_plug_t *plug, const char *path, mode_t mode)
|
|||
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (*path && base && base->ops && base->ops->mkdir)
|
||||
if (*path && base && base->ops && base->ops->mkdir) {
|
||||
ret = base->ops->mkdir(base, path, mode);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -206,8 +214,9 @@ static int cfs_plug_base_rmdir(cfs_plug_t *plug, const char *path) {
|
|||
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (*path && base && base->ops && base->ops->rmdir)
|
||||
if (*path && base && base->ops && base->ops->rmdir) {
|
||||
ret = base->ops->rmdir(base, path);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -224,8 +233,9 @@ static int cfs_plug_base_rename(cfs_plug_t *plug, const char *from, const char *
|
|||
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (base && base->ops && base->ops->rename)
|
||||
if (base && base->ops && base->ops->rename) {
|
||||
ret = base->ops->rename(base, from, to);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -242,8 +252,9 @@ static int cfs_plug_base_open(cfs_plug_t *plug, const char *path, struct fuse_fi
|
|||
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (base && base->ops && base->ops->open)
|
||||
if (base && base->ops && base->ops->open) {
|
||||
ret = base->ops->open(base, path, fi);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -270,8 +281,9 @@ static int cfs_plug_base_read(
|
|||
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (base && base->ops && base->ops->read)
|
||||
if (base && base->ops && base->ops->read) {
|
||||
ret = base->ops->read(base, path, buf, size, offset, fi);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -298,8 +310,9 @@ static int cfs_plug_base_write(
|
|||
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (base && base->ops && base->ops->write)
|
||||
if (base && base->ops && base->ops->write) {
|
||||
ret = base->ops->write(base, path, buf, size, offset, fi);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -315,8 +328,9 @@ static int cfs_plug_base_truncate(cfs_plug_t *plug, const char *path, off_t size
|
|||
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (base && base->ops && base->ops->truncate)
|
||||
if (base && base->ops && base->ops->truncate) {
|
||||
ret = base->ops->truncate(base, path, size);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -334,8 +348,9 @@ cfs_plug_base_create(cfs_plug_t *plug, const char *path, mode_t mode, struct fus
|
|||
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (base && base->ops && base->ops->create)
|
||||
if (base && base->ops && base->ops->create) {
|
||||
ret = base->ops->create(base, path, mode, fi);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -351,8 +366,9 @@ static int cfs_plug_base_unlink(cfs_plug_t *plug, const char *path) {
|
|||
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (base && base->ops && base->ops->unlink)
|
||||
if (base && base->ops && base->ops->unlink) {
|
||||
ret = base->ops->unlink(base, path);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -369,8 +385,9 @@ static int cfs_plug_base_readlink(cfs_plug_t *plug, const char *path, char *buf,
|
|||
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (base && base->ops && base->ops->readlink)
|
||||
if (base && base->ops && base->ops->readlink) {
|
||||
ret = base->ops->readlink(base, path, buf, max);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -387,8 +404,9 @@ static int cfs_plug_base_utimens(cfs_plug_t *plug, const char *path, const struc
|
|||
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (base && base->ops && base->ops->utimens)
|
||||
if (base && base->ops && base->ops->utimens) {
|
||||
ret = base->ops->utimens(base, path, tv);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -405,8 +423,9 @@ static int cfs_plug_base_statfs(cfs_plug_t *plug, const char *path, struct statv
|
|||
|
||||
cfs_plug_t *base = ((cfs_plug_base_t *)plug)->base;
|
||||
|
||||
if (base && base->ops && base->ops->statfs)
|
||||
if (base && base->ops && base->ops->statfs) {
|
||||
ret = base->ops->statfs(base, path, stbuf);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -414,8 +433,9 @@ static int cfs_plug_base_statfs(cfs_plug_t *plug, const char *path, struct statv
|
|||
static gboolean plug_remove_func(gpointer key, gpointer value, gpointer user_data) {
|
||||
cfs_plug_t *plug = (cfs_plug_t *)value;
|
||||
|
||||
if (plug && plug->destroy_plug)
|
||||
if (plug && plug->destroy_plug) {
|
||||
plug->destroy_plug(plug);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -456,8 +476,9 @@ static void cfs_plug_base_start_workers(cfs_plug_t *plug) {
|
|||
|
||||
cfs_plug_t *p = (cfs_plug_t *)value;
|
||||
|
||||
if (p->start_workers)
|
||||
if (p->start_workers) {
|
||||
p->start_workers(p);
|
||||
}
|
||||
}
|
||||
|
||||
if (bplug->base && bplug->base->start_workers) {
|
||||
|
|
@ -483,8 +504,9 @@ static void cfs_plug_base_stop_workers(cfs_plug_t *plug) {
|
|||
|
||||
cfs_plug_t *p = (cfs_plug_t *)value;
|
||||
|
||||
if (p->stop_workers)
|
||||
if (p->stop_workers) {
|
||||
p->stop_workers(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -135,8 +135,9 @@ void cfs_log(
|
|||
break;
|
||||
case G_LOG_LEVEL_DEBUG:
|
||||
level = LOG_DEBUG;
|
||||
if (!cfs.debug)
|
||||
if (!cfs.debug) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
level = LOG_INFO;
|
||||
|
|
@ -195,8 +196,9 @@ gboolean full_write(int fd, const char *buf, size_t len) {
|
|||
n = write(fd, buf, len);
|
||||
} while (n < 0 && errno == EINTR);
|
||||
|
||||
if (n < 0)
|
||||
if (n < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
buf += n;
|
||||
len -= n;
|
||||
|
|
@ -263,16 +265,18 @@ fail:
|
|||
}
|
||||
|
||||
gboolean path_is_private(const char *path) {
|
||||
while (*path == '/')
|
||||
while (*path == '/') {
|
||||
path++;
|
||||
}
|
||||
|
||||
if ((strncmp(path, "priv", 4) == 0) && (path[4] == 0 || path[4] == '/')) {
|
||||
return TRUE;
|
||||
} else {
|
||||
if (strncmp(path, "nodes/", 6) == 0) {
|
||||
const char *tmp = path + 6;
|
||||
while (*tmp && *tmp != '/')
|
||||
while (*tmp && *tmp != '/') {
|
||||
tmp++;
|
||||
}
|
||||
if (*tmp == '/' && (strncmp(tmp, "/priv", 5) == 0) && (tmp[5] == 0 || tmp[5] == '/')) {
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -282,13 +286,15 @@ gboolean path_is_private(const char *path) {
|
|||
}
|
||||
|
||||
gboolean path_is_lxc_conf(const char *path) {
|
||||
while (*path == '/')
|
||||
while (*path == '/') {
|
||||
path++;
|
||||
}
|
||||
|
||||
if (strncmp(path, "nodes/", 6) == 0) {
|
||||
const char *tmp = path + 6;
|
||||
while (*tmp && *tmp != '/')
|
||||
while (*tmp && *tmp != '/') {
|
||||
tmp++;
|
||||
}
|
||||
if (*tmp == '/' && (strncmp(tmp, "/lxc", 4) == 0) && (tmp[4] == 0 || tmp[4] == '/')) {
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -298,8 +304,9 @@ gboolean path_is_lxc_conf(const char *path) {
|
|||
}
|
||||
|
||||
gboolean path_is_lockdir(const char *path) {
|
||||
while (*path == '/')
|
||||
while (*path == '/') {
|
||||
path++;
|
||||
}
|
||||
|
||||
return (strncmp(path, "priv/lock/", 10) == 0) && path[10];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,8 +69,9 @@ static cs_error_t cmap_read_clusternodes(cmap_handle_t handle, cfs_clinfo_t *cli
|
|||
while ((result = cmap_iter_next(handle, iter, key_name, &value_len, &type)) == CS_OK) {
|
||||
int id;
|
||||
char subkey[CMAP_KEYNAME_MAXLEN + 1];
|
||||
if (sscanf(key_name, "nodelist.node.%d.%s", &id, subkey) != 2)
|
||||
if (sscanf(key_name, "nodelist.node.%d.%s", &id, subkey) != 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (id != last_id) {
|
||||
if (name && nodeid) {
|
||||
|
|
@ -285,8 +286,9 @@ loop:
|
|||
if (result == CS_ERR_TRY_AGAIN) {
|
||||
usleep(100000);
|
||||
++retries;
|
||||
if ((retries % 100) == 0)
|
||||
if ((retries % 100) == 0) {
|
||||
cfs_message("cmap_dispatch retry %d", retries);
|
||||
}
|
||||
goto loop;
|
||||
}
|
||||
|
||||
|
|
@ -297,8 +299,9 @@ loop:
|
|||
|
||||
private->changes = FALSE;
|
||||
|
||||
if (result == CS_OK)
|
||||
if (result == CS_OK) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cfs_critical("cmap_dispatch failed: %d", result);
|
||||
|
|
@ -319,8 +322,9 @@ cfs_service_t *service_confdb_new(void) {
|
|||
cfs_service_t *service;
|
||||
|
||||
cs_private_t *private = g_new0(cs_private_t, 1);
|
||||
if (!private)
|
||||
if (!private) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
service = cfs_service_new(&cfs_confdb_callbacks, G_LOG_DOMAIN, private);
|
||||
|
||||
|
|
|
|||
|
|
@ -250,8 +250,9 @@ int bdb_backend_write(
|
|||
}
|
||||
|
||||
if (delete_inode != 0) {
|
||||
if ((rc = bdb_backend_delete_inode(bdb, delete_inode)) != SQLITE_OK)
|
||||
if ((rc = bdb_backend_delete_inode(bdb, delete_inode)) != SQLITE_OK) {
|
||||
goto rollback;
|
||||
}
|
||||
}
|
||||
|
||||
if (inode != 0) {
|
||||
|
|
@ -261,8 +262,9 @@ int bdb_backend_write(
|
|||
rc = backend_write_inode(
|
||||
bdb->db, stmt, inode, parent, version, writer, mtime, size, type, name, value
|
||||
);
|
||||
if (rc != SQLITE_OK)
|
||||
if (rc != SQLITE_OK) {
|
||||
goto rollback;
|
||||
}
|
||||
|
||||
if (sqlite3_changes(bdb->db) != 1) {
|
||||
cfs_critical("no such inode %016" PRIX64, inode);
|
||||
|
|
@ -275,8 +277,9 @@ int bdb_backend_write(
|
|||
NULL
|
||||
);
|
||||
|
||||
if (rc != SQLITE_OK)
|
||||
if (rc != SQLITE_OK) {
|
||||
goto rollback;
|
||||
}
|
||||
|
||||
if (need_txn) {
|
||||
rc = sqlite3_step(bdb->stmt_commit);
|
||||
|
|
@ -291,8 +294,9 @@ int bdb_backend_write(
|
|||
|
||||
rollback:
|
||||
|
||||
if (!need_txn)
|
||||
if (!need_txn) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
int rbrc = sqlite3_step(bdb->stmt_rollback);
|
||||
sqlite3_reset(bdb->stmt_rollback);
|
||||
|
|
@ -342,8 +346,9 @@ bdb_backend_load_index(db_backend_t *bdb, memdb_tree_entry_t *root, GHashTable *
|
|||
te->size = size;
|
||||
|
||||
if (te->type == DT_REG) {
|
||||
if (size > 0)
|
||||
if (size > 0) {
|
||||
te->data.value = g_memdup2(value, size);
|
||||
}
|
||||
} else if (te->type == DT_DIR) {
|
||||
if (size) {
|
||||
cfs_critical("directory inode contains data (inode = %016" PRIX64 ")", te->inode);
|
||||
|
|
@ -506,22 +511,25 @@ gboolean bdb_backend_commit_update(
|
|||
while (j < slave->size && (slave_inode = slave->entries[j].inode) <= inode) {
|
||||
|
||||
if (slave_inode < inode) {
|
||||
if (bdb_backend_delete_inode(bdb, slave_inode) != SQLITE_OK)
|
||||
if (bdb_backend_delete_inode(bdb, slave_inode) != SQLITE_OK) {
|
||||
goto abort;
|
||||
}
|
||||
|
||||
cfs_debug("deleted inode %016" PRIX64, slave_inode);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
if (j >= slave->size)
|
||||
if (j >= slave->size) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (j < slave->size) {
|
||||
guint64 slave_inode = slave->entries[j].inode;
|
||||
|
||||
if (bdb_backend_delete_inode(bdb, slave_inode) != SQLITE_OK)
|
||||
if (bdb_backend_delete_inode(bdb, slave_inode) != SQLITE_OK) {
|
||||
goto abort;
|
||||
}
|
||||
|
||||
cfs_debug("deleted inode %016" PRIX64, slave_inode);
|
||||
|
||||
|
|
@ -558,8 +566,9 @@ gboolean bdb_backend_commit_update(
|
|||
|
||||
g_hash_table_replace(index, &root->inode, root);
|
||||
|
||||
if (!bdb_backend_load_index(bdb, root, index))
|
||||
if (!bdb_backend_load_index(bdb, root, index)) {
|
||||
goto abort;
|
||||
}
|
||||
|
||||
if (!memdb->root->version) {
|
||||
cfs_critical("new index has version 0 - internal error");
|
||||
|
|
@ -611,8 +620,9 @@ gboolean bdb_backend_commit_update(
|
|||
ret:
|
||||
g_mutex_unlock(&memdb->mutex);
|
||||
|
||||
if (index)
|
||||
if (index) {
|
||||
g_hash_table_destroy(index);
|
||||
}
|
||||
|
||||
cfs_debug("leave bdb_backend_commit_update (%d)", result);
|
||||
|
||||
|
|
@ -624,8 +634,9 @@ abort:
|
|||
|
||||
rc = sqlite3_step(bdb->stmt_rollback);
|
||||
sqlite3_reset(bdb->stmt_rollback);
|
||||
if (rc != SQLITE_DONE)
|
||||
if (rc != SQLITE_DONE) {
|
||||
cfs_critical("rollback transaction failed: %s\n", sqlite3_errmsg(bdb->db));
|
||||
}
|
||||
|
||||
result = FALSE;
|
||||
|
||||
|
|
@ -666,8 +677,9 @@ db_backend_t *bdb_backend_open(const char *filename, memdb_tree_entry_t *root, G
|
|||
|
||||
sqlite3_initialize();
|
||||
|
||||
if (!(bdb->db = bdb_create(filename)))
|
||||
if (!(bdb->db = bdb_create(filename))) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
// tell the query planner that the prepared statement will be retained for a long time and
|
||||
// probably reused many times
|
||||
|
|
@ -714,8 +726,9 @@ db_backend_t *bdb_backend_open(const char *filename, memdb_tree_entry_t *root, G
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if (!bdb_backend_load_index(bdb, root, index))
|
||||
if (!bdb_backend_load_index(bdb, root, index)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!root->version) {
|
||||
root->version++;
|
||||
|
|
@ -723,8 +736,9 @@ db_backend_t *bdb_backend_open(const char *filename, memdb_tree_entry_t *root, G
|
|||
guint32 mtime = time(NULL);
|
||||
|
||||
if (bdb_backend_write(bdb, 0, 0, root->version, 0, mtime, 0, DT_REG, NULL, NULL, 0) !=
|
||||
SQLITE_OK)
|
||||
SQLITE_OK) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
return bdb;
|
||||
|
|
|
|||
|
|
@ -61,8 +61,9 @@ void dcdb_send_unlock(dfsm_t *dfsm, const char *path, const guchar csum[32], gbo
|
|||
iov[1].iov_base = (char *)path;
|
||||
iov[1].iov_len = strlen(path) + 1;
|
||||
|
||||
if (!cfs_is_quorate())
|
||||
if (!cfs_is_quorate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
dcdb_message_t msg_type = request ? DCDB_MESSAGE_CFS_UNLOCK_REQUEST : DCDB_MESSAGE_CFS_UNLOCK;
|
||||
|
||||
|
|
@ -140,11 +141,13 @@ int dcdb_send_fuse_message(
|
|||
memset(&rc, 0, sizeof(rc));
|
||||
rc.result = -EBUSY;
|
||||
|
||||
if (!cfs_is_quorate())
|
||||
if (!cfs_is_quorate()) {
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
if (dfsm_send_message_sync(dfsm, msg_type, iov, 8, &rc))
|
||||
if (dfsm_send_message_sync(dfsm, msg_type, iov, 8, &rc)) {
|
||||
return rc.result;
|
||||
}
|
||||
|
||||
return -EACCES;
|
||||
}
|
||||
|
|
@ -269,8 +272,9 @@ static gboolean dcdb_send_update_inode(dfsm_t *dfsm, memdb_tree_entry_t *te) {
|
|||
len++;
|
||||
}
|
||||
|
||||
if (dfsm_send_update(dfsm, iov, len) != CS_OK)
|
||||
if (dfsm_send_update(dfsm, iov, len) != CS_OK) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -332,8 +336,9 @@ memdb_tree_entry_t *dcdb_parse_update_inode(const void *msg, size_t msg_len) {
|
|||
}
|
||||
|
||||
memdb_tree_entry_t *te = memdb_tree_entry_new(name);
|
||||
if (!te)
|
||||
if (!te) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
te->parent = parent;
|
||||
te->version = version;
|
||||
|
|
@ -361,8 +366,9 @@ void dcdb_sync_corosync_conf(memdb_t *memdb, gboolean notify_corosync) {
|
|||
gpointer data = NULL;
|
||||
|
||||
len = memdb_read(memdb, "corosync.conf", &data);
|
||||
if (len <= 0)
|
||||
if (len <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
guint64 new_version = cluster_config_version(data, len);
|
||||
if (!new_version) {
|
||||
|
|
@ -383,21 +389,24 @@ void dcdb_sync_corosync_conf(memdb_t *memdb, gboolean notify_corosync) {
|
|||
}
|
||||
g_error_free(err);
|
||||
} else {
|
||||
if (old_length)
|
||||
if (old_length) {
|
||||
old_version = cluster_config_version(old_data, old_length);
|
||||
}
|
||||
}
|
||||
|
||||
/* test if something changed - return if no changes */
|
||||
if (data && old_data && (old_length == len) && !memcmp(data, old_data, len))
|
||||
if (data && old_data && (old_length == len) && !memcmp(data, old_data, len)) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
if (new_version < old_version) {
|
||||
cfs_critical("local corosync.conf is newer");
|
||||
goto ret;
|
||||
}
|
||||
|
||||
if (!atomic_write_file(HOST_CLUSTER_CONF_FN, data, len, 0644, 0))
|
||||
if (!atomic_write_file(HOST_CLUSTER_CONF_FN, data, len, 0644, 0)) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
cfs_message(
|
||||
"wrote new corosync config '%s' (version = %" G_GUINT64_FORMAT ")", HOST_CLUSTER_CONF_FN,
|
||||
|
|
@ -422,11 +431,13 @@ void dcdb_sync_corosync_conf(memdb_t *memdb, gboolean notify_corosync) {
|
|||
|
||||
ret:
|
||||
|
||||
if (data)
|
||||
if (data) {
|
||||
g_free(data);
|
||||
}
|
||||
|
||||
if (old_data)
|
||||
if (old_data) {
|
||||
g_free(old_data);
|
||||
}
|
||||
}
|
||||
|
||||
static gpointer dcdb_get_state(dfsm_t *dfsm, gpointer data, unsigned int *res_len) {
|
||||
|
|
@ -493,30 +504,34 @@ static gboolean dcdb_create_and_send_updates(
|
|||
gboolean res = FALSE;
|
||||
|
||||
GHashTable *updates = g_hash_table_new(g_int64_hash, g_int64_equal);
|
||||
if (!updates)
|
||||
if (!updates) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
g_mutex_lock(&memdb->mutex);
|
||||
|
||||
for (int n = 0; n < node_count; n++) {
|
||||
memdb_index_t *slave = idx[n];
|
||||
|
||||
if (slave == master)
|
||||
if (slave == master) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
|
||||
for (int i = 0; i < master->size; i++) {
|
||||
guint64 inode = master->entries[i].inode;
|
||||
while (j < slave->size && slave->entries[j].inode < inode)
|
||||
while (j < slave->size && slave->entries[j].inode < inode) {
|
||||
j++;
|
||||
}
|
||||
|
||||
if (memcmp(&slave->entries[j], &master->entries[i], sizeof(memdb_index_extry_t)) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (g_hash_table_lookup(updates, &inode))
|
||||
if (g_hash_table_lookup(updates, &inode)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cfs_debug("found different inode %d %016" PRIX64, i, (uint64_t)inode);
|
||||
|
||||
|
|
@ -567,8 +582,9 @@ static gboolean dcdb_create_and_send_updates(
|
|||
res = TRUE;
|
||||
|
||||
ret:
|
||||
if (updates)
|
||||
if (updates) {
|
||||
g_hash_table_destroy(updates);
|
||||
}
|
||||
|
||||
cfs_debug("leave %s (%d)", __func__, res);
|
||||
|
||||
|
|
@ -585,8 +601,9 @@ static int dcdb_process_state_update(dfsm_t *dfsm, gpointer data, dfsm_sync_info
|
|||
cfs_debug("enter %s", __func__);
|
||||
|
||||
dcdb_sync_info_t *localsi = g_new0(dcdb_sync_info_t, 1);
|
||||
if (!localsi)
|
||||
if (!localsi) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
syncinfo->data = localsi;
|
||||
|
||||
|
|
@ -636,16 +653,18 @@ static int dcdb_process_state_update(dfsm_t *dfsm, gpointer data, dfsm_sync_info
|
|||
g_string_append_printf(synced_member_ids, ", %d/%d", ni->nodeid, ni->pid);
|
||||
}
|
||||
}
|
||||
if (dfsm_nodeid_is_local(dfsm, ni->nodeid, ni->pid))
|
||||
if (dfsm_nodeid_is_local(dfsm, ni->nodeid, ni->pid)) {
|
||||
localsi->idx = idx[i];
|
||||
}
|
||||
}
|
||||
cfs_message("synced members: %s", synced_member_ids->str);
|
||||
g_string_free(synced_member_ids, TRUE);
|
||||
|
||||
/* send update */
|
||||
if (dfsm_nodeid_is_local(dfsm, syncinfo->nodes[leader].nodeid, syncinfo->nodes[leader].pid)) {
|
||||
if (!dcdb_create_and_send_updates(dfsm, memdb, leaderidx, syncinfo->node_count, idx))
|
||||
if (!dcdb_create_and_send_updates(dfsm, memdb, leaderidx, syncinfo->node_count, idx)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -670,8 +689,9 @@ static int dcdb_process_update(
|
|||
|
||||
memdb_tree_entry_t *te;
|
||||
|
||||
if (!(te = dcdb_parse_update_inode(msg, msg_len)))
|
||||
if (!(te = dcdb_parse_update_inode(msg, msg_len))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cfs_debug("received inode update %016" PRIX64 " from node %d", (uint64_t)te->inode, nodeid);
|
||||
|
||||
|
|
@ -698,8 +718,9 @@ static int dcdb_commit(dfsm_t *dfsm, gpointer data, dfsm_sync_info_t *syncinfo)
|
|||
|
||||
cfs_message("update complete - trying to commit (got %u inode updates)", count);
|
||||
|
||||
if (!bdb_backend_commit_update(memdb, localsi->master, localsi->idx, localsi->updates))
|
||||
if (!bdb_backend_commit_update(memdb, localsi->master, localsi->idx, localsi->updates)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
dcdb_sync_corosync_conf(memdb, FALSE);
|
||||
|
||||
|
|
@ -771,8 +792,9 @@ static int dcdb_deliver(
|
|||
|
||||
int msg_result = -ENOTSUP;
|
||||
|
||||
if (!DCDB_VALID_MESSAGE_TYPE(msg_type))
|
||||
if (!DCDB_VALID_MESSAGE_TYPE(msg_type)) {
|
||||
goto unknown;
|
||||
}
|
||||
|
||||
cfs_debug("process message %u (length = %zd)", msg_type, msg_len);
|
||||
|
||||
|
|
@ -789,8 +811,9 @@ static int dcdb_deliver(
|
|||
if (msg_type == DCDB_MESSAGE_CFS_UNLOCK_REQUEST || msg_type == DCDB_MESSAGE_CFS_UNLOCK) {
|
||||
msg_result = 0; /* ignored anyways */
|
||||
|
||||
if (!dcdb_parse_unlock_request(msg, msg_len, &path, &csum))
|
||||
if (!dcdb_parse_unlock_request(msg, msg_len, &path, &csum)) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
guchar cur_csum[32];
|
||||
memdb_tree_entry_t *te = memdb_getattr(memdb, path);
|
||||
|
|
@ -818,52 +841,61 @@ static int dcdb_deliver(
|
|||
|
||||
} else if (msg_type == DCDB_MESSAGE_CFS_WRITE) {
|
||||
|
||||
if (!dcdb_parse_fuse_message(msg, msg_len, &path, &to, &buf, &size, &offset, &flags))
|
||||
if (!dcdb_parse_fuse_message(msg, msg_len, &path, &to, &buf, &size, &offset, &flags)) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
msg_result = memdb_write(memdb, path, nodeid, msg_time, buf, size, offset, flags);
|
||||
|
||||
if ((msg_result >= 0) && !strcmp(path, "corosync.conf"))
|
||||
if ((msg_result >= 0) && !strcmp(path, "corosync.conf")) {
|
||||
dcdb_sync_corosync_conf(memdb, dfsm_nodeid_is_local(dfsm, nodeid, pid));
|
||||
}
|
||||
|
||||
} else if (msg_type == DCDB_MESSAGE_CFS_CREATE) {
|
||||
|
||||
if (!dcdb_parse_fuse_message(msg, msg_len, &path, &to, &buf, &size, &offset, &flags))
|
||||
if (!dcdb_parse_fuse_message(msg, msg_len, &path, &to, &buf, &size, &offset, &flags)) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
msg_result = memdb_create(memdb, path, nodeid, msg_time);
|
||||
|
||||
if ((msg_result >= 0) && !strcmp(path, "corosync.conf"))
|
||||
if ((msg_result >= 0) && !strcmp(path, "corosync.conf")) {
|
||||
dcdb_sync_corosync_conf(memdb, dfsm_nodeid_is_local(dfsm, nodeid, pid));
|
||||
}
|
||||
|
||||
} else if (msg_type == DCDB_MESSAGE_CFS_MKDIR) {
|
||||
|
||||
if (!dcdb_parse_fuse_message(msg, msg_len, &path, &to, &buf, &size, &offset, &flags))
|
||||
if (!dcdb_parse_fuse_message(msg, msg_len, &path, &to, &buf, &size, &offset, &flags)) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
msg_result = memdb_mkdir(memdb, path, nodeid, msg_time);
|
||||
|
||||
} else if (msg_type == DCDB_MESSAGE_CFS_DELETE) {
|
||||
|
||||
if (!dcdb_parse_fuse_message(msg, msg_len, &path, &to, &buf, &size, &offset, &flags))
|
||||
if (!dcdb_parse_fuse_message(msg, msg_len, &path, &to, &buf, &size, &offset, &flags)) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
msg_result = memdb_delete(memdb, path, nodeid, msg_time);
|
||||
|
||||
} else if (msg_type == DCDB_MESSAGE_CFS_RENAME) {
|
||||
|
||||
if (!dcdb_parse_fuse_message(msg, msg_len, &path, &to, &buf, &size, &offset, &flags))
|
||||
if (!dcdb_parse_fuse_message(msg, msg_len, &path, &to, &buf, &size, &offset, &flags)) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
msg_result = memdb_rename(memdb, path, to, nodeid, msg_time);
|
||||
|
||||
if ((msg_result >= 0) && !strcmp(to, "corosync.conf"))
|
||||
if ((msg_result >= 0) && !strcmp(to, "corosync.conf")) {
|
||||
dcdb_sync_corosync_conf(memdb, dfsm_nodeid_is_local(dfsm, nodeid, pid));
|
||||
}
|
||||
|
||||
} else if (msg_type == DCDB_MESSAGE_CFS_MTIME) {
|
||||
|
||||
if (!dcdb_parse_fuse_message(msg, msg_len, &path, &to, &buf, &size, &offset, &flags))
|
||||
if (!dcdb_parse_fuse_message(msg, msg_len, &path, &to, &buf, &size, &offset, &flags)) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* Note: mtime is sent via offset field */
|
||||
msg_result = memdb_mtime(memdb, path, nodeid, offset);
|
||||
|
|
|
|||
|
|
@ -192,17 +192,21 @@ loop:
|
|||
if (retry && result == CS_ERR_TRY_AGAIN) {
|
||||
nanosleep(&tvreq, NULL);
|
||||
++retries;
|
||||
if ((retries % 10) == 0)
|
||||
if ((retries % 10) == 0) {
|
||||
cfs_dom_message(dfsm->log_domain, "cpg_send_message retry %d", retries);
|
||||
if (retries < 100)
|
||||
}
|
||||
if (retries < 100) {
|
||||
goto loop;
|
||||
}
|
||||
}
|
||||
|
||||
if (retries)
|
||||
if (retries) {
|
||||
cfs_dom_message(dfsm->log_domain, "cpg_send_message retried %d times", retries);
|
||||
}
|
||||
|
||||
if (result != CS_OK && (!retry || result != CS_ERR_TRY_AGAIN))
|
||||
if (result != CS_OK && (!retry || result != CS_ERR_TRY_AGAIN)) {
|
||||
cfs_dom_critical(dfsm->log_domain, "cpg_send_message failed: %d", result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -227,8 +231,9 @@ dfsm_send_state_message_full(dfsm_t *dfsm, uint16_t type, struct iovec *iov, uns
|
|||
real_iov[0].iov_base = (char *)&header;
|
||||
real_iov[0].iov_len = sizeof(header);
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
for (int i = 0; i < len; i++) {
|
||||
real_iov[i + 1] = iov[i];
|
||||
}
|
||||
|
||||
return dfsm_send_message_full(dfsm, real_iov, len + 1, 1);
|
||||
}
|
||||
|
|
@ -273,8 +278,9 @@ cs_error_t dfsm_send_message_sync(
|
|||
real_iov[0].iov_base = (char *)&header;
|
||||
real_iov[0].iov_len = sizeof(header);
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
for (int i = 0; i < len; i++) {
|
||||
real_iov[i + 1] = iov[i];
|
||||
}
|
||||
|
||||
cs_error_t result = dfsm_send_message_full(dfsm, real_iov, len + 1, 1);
|
||||
|
||||
|
|
@ -294,8 +300,9 @@ cs_error_t dfsm_send_message_sync(
|
|||
if (rp) {
|
||||
g_mutex_lock(&dfsm->sync_mutex);
|
||||
|
||||
while (dfsm->msgcount_rcvd < msgcount)
|
||||
while (dfsm->msgcount_rcvd < msgcount) {
|
||||
g_cond_wait(&dfsm->sync_cond, &dfsm->sync_mutex);
|
||||
}
|
||||
|
||||
g_hash_table_remove(dfsm->results, &rp->msgcount);
|
||||
|
||||
|
|
@ -415,8 +422,9 @@ static gboolean dfsm_sync_info_equal(gconstpointer v1, gconstpointer v2) {
|
|||
dfsm_node_info_t *info1 = (dfsm_node_info_t *)v1;
|
||||
dfsm_node_info_t *info2 = (dfsm_node_info_t *)v2;
|
||||
|
||||
if (info1->nodeid == info2->nodeid && info1->pid == info2->pid)
|
||||
if (info1->nodeid == info2->nodeid && info1->pid == info2->pid) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -425,8 +433,9 @@ static int dfsm_sync_info_compare(gconstpointer v1, gconstpointer v2) {
|
|||
dfsm_node_info_t *info1 = (dfsm_node_info_t *)v1;
|
||||
dfsm_node_info_t *info2 = (dfsm_node_info_t *)v2;
|
||||
|
||||
if (info1->nodeid != info2->nodeid)
|
||||
if (info1->nodeid != info2->nodeid) {
|
||||
return info1->nodeid - info2->nodeid;
|
||||
}
|
||||
|
||||
return info1->pid - info2->pid;
|
||||
}
|
||||
|
|
@ -447,8 +456,9 @@ static void dfsm_set_mode(dfsm_t *dfsm, dfsm_mode_t new_mode) {
|
|||
}
|
||||
g_mutex_unlock(&dfsm->mode_mutex);
|
||||
|
||||
if (!changed)
|
||||
if (!changed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (new_mode == DFSM_MODE_START) {
|
||||
cfs_dom_message(dfsm->log_domain, "start cluster connection");
|
||||
|
|
@ -456,8 +466,9 @@ static void dfsm_set_mode(dfsm_t *dfsm, dfsm_mode_t new_mode) {
|
|||
cfs_dom_message(dfsm->log_domain, "starting data syncronisation");
|
||||
} else if (new_mode == DFSM_MODE_SYNCED) {
|
||||
cfs_dom_message(dfsm->log_domain, "all data is up to date");
|
||||
if (dfsm->dfsm_callbacks->dfsm_synced_fn)
|
||||
if (dfsm->dfsm_callbacks->dfsm_synced_fn) {
|
||||
dfsm->dfsm_callbacks->dfsm_synced_fn(dfsm);
|
||||
}
|
||||
} else if (new_mode == DFSM_MODE_UPDATE) {
|
||||
cfs_dom_message(dfsm->log_domain, "waiting for updates from leader");
|
||||
} else if (new_mode == DFSM_MODE_LEAVE) {
|
||||
|
|
@ -516,8 +527,9 @@ static void dfsm_release_sync_resources(
|
|||
|
||||
g_hash_table_remove_all(dfsm->members);
|
||||
|
||||
if (dfsm->sync_info)
|
||||
if (dfsm->sync_info) {
|
||||
g_free(dfsm->sync_info);
|
||||
}
|
||||
|
||||
int size = sizeof(dfsm_sync_info_t) + member_list_entries * sizeof(dfsm_sync_info_t);
|
||||
dfsm_sync_info_t *sync_info = dfsm->sync_info = g_malloc0(size);
|
||||
|
|
@ -535,8 +547,9 @@ static void dfsm_release_sync_resources(
|
|||
for (int i = 0; i < member_list_entries; i++) {
|
||||
dfsm_node_info_t *info = &sync_info->nodes[i];
|
||||
g_hash_table_insert(dfsm->members, info, info);
|
||||
if (info->nodeid == dfsm->nodeid && info->pid == dfsm->pid)
|
||||
if (info->nodeid == dfsm->nodeid && info->pid == dfsm->pid) {
|
||||
sync_info->local = info;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -611,8 +624,9 @@ static void dfsm_cpg_deliver_callback(
|
|||
header->count, base_header->subtype, msg_len
|
||||
);
|
||||
|
||||
if (!dfsm_queue_add_message(dfsm, nodeid, pid, header->count, msg, msg_len))
|
||||
if (!dfsm_queue_add_message(dfsm, nodeid, pid, header->count, msg, msg_len)) {
|
||||
goto leave;
|
||||
}
|
||||
} else {
|
||||
|
||||
int msg_res = -1;
|
||||
|
|
@ -622,11 +636,13 @@ static void dfsm_cpg_deliver_callback(
|
|||
msg_len - sizeof(dfsm_message_normal_header_t)
|
||||
);
|
||||
|
||||
if (nodeid == dfsm->nodeid && pid == dfsm->pid)
|
||||
if (nodeid == dfsm->nodeid && pid == dfsm->pid) {
|
||||
dfsm_record_local_result(dfsm, header->count, msg_res, res);
|
||||
}
|
||||
|
||||
if (res < 0)
|
||||
if (res < 0) {
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
@ -663,11 +679,13 @@ static void dfsm_cpg_deliver_callback(
|
|||
if (mode == DFSM_MODE_SYNCED) {
|
||||
if (base_header->type == DFSM_MESSAGE_UPDATE_COMPLETE) {
|
||||
|
||||
for (int i = 0; i < dfsm->sync_info->node_count; i++)
|
||||
for (int i = 0; i < dfsm->sync_info->node_count; i++) {
|
||||
dfsm->sync_info->nodes[i].synced = 1;
|
||||
}
|
||||
|
||||
if (!dfsm_deliver_queue(dfsm))
|
||||
if (!dfsm_deliver_queue(dfsm)) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
|
|
@ -702,8 +720,9 @@ static void dfsm_cpg_deliver_callback(
|
|||
dfsm->csum_id = csum_id;
|
||||
|
||||
if (nodeid == dfsm->nodeid && pid == dfsm->pid) {
|
||||
if (!dfsm_send_checksum(dfsm))
|
||||
if (!dfsm_send_checksum(dfsm)) {
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -787,11 +806,13 @@ static void dfsm_cpg_deliver_callback(
|
|||
|
||||
result = dfsm_send_state_message_full(dfsm, DFSM_MESSAGE_STATE, iov, 1);
|
||||
|
||||
if (state)
|
||||
if (state) {
|
||||
g_free(state);
|
||||
}
|
||||
|
||||
if (result != CS_OK)
|
||||
if (result != CS_OK) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
|
|
@ -830,21 +851,24 @@ static void dfsm_cpg_deliver_callback(
|
|||
int res = dfsm->dfsm_callbacks->dfsm_process_state_update_fn(
|
||||
dfsm, dfsm->data, dfsm->sync_info
|
||||
);
|
||||
if (res < 0)
|
||||
if (res < 0) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
if (dfsm->sync_info->local->synced) {
|
||||
dfsm_set_mode(dfsm, DFSM_MODE_SYNCED);
|
||||
dfsm_release_sync_resources(dfsm, NULL, 0);
|
||||
|
||||
if (!dfsm_deliver_queue(dfsm))
|
||||
if (!dfsm_deliver_queue(dfsm)) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
} else {
|
||||
dfsm_set_mode(dfsm, DFSM_MODE_UPDATE);
|
||||
|
||||
if (!dfsm_deliver_queue(dfsm))
|
||||
if (!dfsm_deliver_queue(dfsm)) {
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -859,8 +883,9 @@ static void dfsm_cpg_deliver_callback(
|
|||
dfsm, dfsm->data, dfsm->sync_info, nodeid, pid, msg, msg_len
|
||||
);
|
||||
|
||||
if (res < 0)
|
||||
if (res < 0) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
|
|
@ -868,19 +893,23 @@ static void dfsm_cpg_deliver_callback(
|
|||
|
||||
int res = dfsm->dfsm_callbacks->dfsm_commit_fn(dfsm, dfsm->data, dfsm->sync_info);
|
||||
|
||||
if (res < 0)
|
||||
if (res < 0) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
for (int i = 0; i < dfsm->sync_info->node_count; i++)
|
||||
for (int i = 0; i < dfsm->sync_info->node_count; i++) {
|
||||
dfsm->sync_info->nodes[i].synced = 1;
|
||||
}
|
||||
|
||||
dfsm_set_mode(dfsm, DFSM_MODE_SYNCED);
|
||||
|
||||
if (!dfsm_deliver_sync_queue(dfsm))
|
||||
if (!dfsm_deliver_sync_queue(dfsm)) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
if (!dfsm_deliver_queue(dfsm))
|
||||
if (!dfsm_deliver_queue(dfsm)) {
|
||||
goto leave;
|
||||
}
|
||||
|
||||
dfsm_release_sync_resources(dfsm, NULL, 0);
|
||||
|
||||
|
|
@ -948,8 +977,9 @@ static gboolean dfsm_resend_queue(dfsm_t *dfsm) {
|
|||
static gboolean dfsm_deliver_sync_queue(dfsm_t *dfsm) {
|
||||
g_return_val_if_fail(dfsm != NULL, FALSE);
|
||||
|
||||
if (!dfsm->sync_queue)
|
||||
if (!dfsm->sync_queue) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean res = TRUE;
|
||||
|
||||
|
|
@ -984,8 +1014,9 @@ static gboolean dfsm_deliver_queue(dfsm_t *dfsm) {
|
|||
g_return_val_if_fail(dfsm->msg_queue != NULL, FALSE);
|
||||
|
||||
int qlen = g_sequence_get_length(dfsm->msg_queue);
|
||||
if (!qlen)
|
||||
if (!qlen) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GSequenceIter *iter = g_sequence_get_begin_iter(dfsm->msg_queue);
|
||||
GSequenceIter *end = g_sequence_get_end_iter(dfsm->msg_queue);
|
||||
|
|
@ -1084,15 +1115,18 @@ static void dfsm_cpg_confchg_callback(
|
|||
member_ids, i ? ", %d/%d" : "%d/%d", member_list[i].nodeid, member_list[i].pid
|
||||
);
|
||||
|
||||
if (lowest_nodeid == 0 || lowest_nodeid > member_list[i].nodeid)
|
||||
if (lowest_nodeid == 0 || lowest_nodeid > member_list[i].nodeid) {
|
||||
lowest_nodeid = member_list[i].nodeid;
|
||||
}
|
||||
|
||||
if (member_list[i].nodeid == dfsm->nodeid && member_list[i].pid == dfsm->pid)
|
||||
if (member_list[i].nodeid == dfsm->nodeid && member_list[i].pid == dfsm->pid) {
|
||||
dfsm->we_are_member = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((dfsm->we_are_member || mode != DFSM_MODE_START))
|
||||
if ((dfsm->we_are_member || mode != DFSM_MODE_START)) {
|
||||
cfs_dom_message(dfsm->log_domain, "members: %s", member_ids->str);
|
||||
}
|
||||
|
||||
g_string_free(member_ids, TRUE);
|
||||
|
||||
|
|
@ -1138,12 +1172,14 @@ static void dfsm_cpg_confchg_callback(
|
|||
} else {
|
||||
dfsm_set_mode(dfsm, DFSM_MODE_SYNCED);
|
||||
dfsm->sync_info->local->synced = 1;
|
||||
if (!dfsm_deliver_queue(dfsm))
|
||||
if (!dfsm_deliver_queue(dfsm)) {
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
|
||||
if (dfsm->dfsm_callbacks->dfsm_confchg_fn)
|
||||
if (dfsm->dfsm_callbacks->dfsm_confchg_fn) {
|
||||
dfsm->dfsm_callbacks->dfsm_confchg_fn(dfsm, dfsm->data, member_list, member_list_entries);
|
||||
}
|
||||
|
||||
return;
|
||||
leave:
|
||||
|
|
@ -1177,18 +1213,21 @@ dfsm_t *dfsm_new(
|
|||
|
||||
dfsm_t *dfsm;
|
||||
|
||||
if ((dfsm = g_new0(dfsm_t, 1)) == NULL)
|
||||
if ((dfsm = g_new0(dfsm_t, 1)) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_mutex_init(&dfsm->sync_mutex);
|
||||
|
||||
g_cond_init(&dfsm->sync_cond);
|
||||
|
||||
if (!(dfsm->results = g_hash_table_new(g_int64_hash, g_int64_equal)))
|
||||
if (!(dfsm->results = g_hash_table_new(g_int64_hash, g_int64_equal))) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!(dfsm->msg_queue = g_sequence_new(NULL)))
|
||||
if (!(dfsm->msg_queue = g_sequence_new(NULL))) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
g_mutex_init(&dfsm->cpg_mutex);
|
||||
|
||||
|
|
@ -1203,8 +1242,9 @@ dfsm_t *dfsm_new(
|
|||
dfsm->dfsm_callbacks = callbacks;
|
||||
|
||||
dfsm->members = g_hash_table_new(dfsm_sync_info_hash, dfsm_sync_info_equal);
|
||||
if (!dfsm->members)
|
||||
if (!dfsm->members) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
g_mutex_init(&dfsm->mode_mutex);
|
||||
|
||||
|
|
@ -1224,8 +1264,9 @@ gboolean dfsm_is_initialized(dfsm_t *dfsm) {
|
|||
gboolean dfsm_lowest_nodeid(dfsm_t *dfsm) {
|
||||
g_return_val_if_fail(dfsm != NULL, FALSE);
|
||||
|
||||
if (dfsm->lowest_nodeid && (dfsm->lowest_nodeid == dfsm->nodeid))
|
||||
if (dfsm->lowest_nodeid && (dfsm->lowest_nodeid == dfsm->nodeid)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -1234,12 +1275,14 @@ cs_error_t dfsm_verify_request(dfsm_t *dfsm) {
|
|||
g_return_val_if_fail(dfsm != NULL, CS_ERR_INVALID_PARAM);
|
||||
|
||||
/* only do when we have lowest nodeid */
|
||||
if (!dfsm->lowest_nodeid || (dfsm->lowest_nodeid != dfsm->nodeid))
|
||||
if (!dfsm->lowest_nodeid || (dfsm->lowest_nodeid != dfsm->nodeid)) {
|
||||
return CS_OK;
|
||||
}
|
||||
|
||||
dfsm_mode_t mode = dfsm_get_mode(dfsm);
|
||||
if (mode != DFSM_MODE_SYNCED)
|
||||
if (mode != DFSM_MODE_SYNCED) {
|
||||
return CS_OK;
|
||||
}
|
||||
|
||||
int len = 1;
|
||||
struct iovec iov[len];
|
||||
|
|
@ -1258,8 +1301,9 @@ cs_error_t dfsm_verify_request(dfsm_t *dfsm) {
|
|||
cs_error_t result;
|
||||
result = dfsm_send_state_message_full(dfsm, DFSM_MESSAGE_VERIFY_REQUEST, iov, len);
|
||||
|
||||
if (result != CS_OK)
|
||||
if (result != CS_OK) {
|
||||
cfs_dom_critical(dfsm->log_domain, "failed to send VERIFY_REQUEST message");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -1277,8 +1321,9 @@ loop:
|
|||
if (result == CS_ERR_TRY_AGAIN) {
|
||||
nanosleep(&tvreq, NULL);
|
||||
++retries;
|
||||
if ((retries % 10) == 0)
|
||||
if ((retries % 10) == 0) {
|
||||
cfs_dom_message(dfsm->log_domain, "cpg_dispatch retry %d", retries);
|
||||
}
|
||||
goto loop;
|
||||
}
|
||||
|
||||
|
|
@ -1355,8 +1400,9 @@ loop:
|
|||
if (result == CS_ERR_TRY_AGAIN) {
|
||||
nanosleep(&tvreq, NULL);
|
||||
++retries;
|
||||
if ((retries % 10) == 0)
|
||||
if ((retries % 10) == 0) {
|
||||
cfs_dom_message(dfsm->log_domain, "cpg_join retry %d", retries);
|
||||
}
|
||||
goto loop;
|
||||
}
|
||||
|
||||
|
|
@ -1384,8 +1430,9 @@ loop:
|
|||
if (result == CS_ERR_TRY_AGAIN) {
|
||||
nanosleep(&tvreq, NULL);
|
||||
++retries;
|
||||
if ((retries % 10) == 0)
|
||||
if ((retries % 10) == 0) {
|
||||
cfs_dom_message(dfsm->log_domain, "cpg_leave retry %d", retries);
|
||||
}
|
||||
goto loop;
|
||||
}
|
||||
|
||||
|
|
@ -1404,8 +1451,9 @@ gboolean dfsm_finalize(dfsm_t *dfsm) {
|
|||
|
||||
dfsm_send_sync_message_abort(dfsm);
|
||||
|
||||
if (dfsm->joined)
|
||||
if (dfsm->joined) {
|
||||
dfsm_leave(dfsm);
|
||||
}
|
||||
|
||||
if (dfsm->cpg_handle) {
|
||||
cpg_finalize(dfsm->cpg_handle);
|
||||
|
|
@ -1422,8 +1470,9 @@ void dfsm_destroy(dfsm_t *dfsm) {
|
|||
|
||||
dfsm_finalize(dfsm);
|
||||
|
||||
if (dfsm->sync_info && dfsm->sync_info->data && dfsm->dfsm_callbacks->dfsm_cleanup_fn)
|
||||
if (dfsm->sync_info && dfsm->sync_info->data && dfsm->dfsm_callbacks->dfsm_cleanup_fn) {
|
||||
dfsm->dfsm_callbacks->dfsm_cleanup_fn(dfsm, dfsm->data, dfsm->sync_info);
|
||||
}
|
||||
|
||||
dfsm_free_sync_queue(dfsm);
|
||||
|
||||
|
|
@ -1435,22 +1484,26 @@ void dfsm_destroy(dfsm_t *dfsm) {
|
|||
|
||||
g_mutex_clear(&dfsm->cpg_mutex);
|
||||
|
||||
if (dfsm->results)
|
||||
if (dfsm->results) {
|
||||
g_hash_table_destroy(dfsm->results);
|
||||
}
|
||||
|
||||
if (dfsm->msg_queue) {
|
||||
dfsm_free_message_queue(dfsm);
|
||||
g_sequence_free(dfsm->msg_queue);
|
||||
}
|
||||
|
||||
if (dfsm->sync_info)
|
||||
if (dfsm->sync_info) {
|
||||
g_free(dfsm->sync_info);
|
||||
}
|
||||
|
||||
if (dfsm->cpg_handle)
|
||||
if (dfsm->cpg_handle) {
|
||||
cpg_finalize(dfsm->cpg_handle);
|
||||
}
|
||||
|
||||
if (dfsm->members)
|
||||
if (dfsm->members) {
|
||||
g_hash_table_destroy(dfsm->members);
|
||||
}
|
||||
|
||||
g_free(dfsm);
|
||||
}
|
||||
|
|
@ -1481,14 +1534,16 @@ static int service_dfsm_initialize(cfs_service_t *service, gpointer context) {
|
|||
g_return_val_if_fail(dfsm != NULL, -1);
|
||||
|
||||
/* serious internal error - don't try to recover */
|
||||
if (!dfsm_restartable(dfsm))
|
||||
if (!dfsm_restartable(dfsm)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int fd = -1;
|
||||
|
||||
cs_error_t result;
|
||||
if ((result = dfsm_initialize(dfsm, &fd)) != CS_OK)
|
||||
if ((result = dfsm_initialize(dfsm, &fd)) != CS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = dfsm_join(dfsm);
|
||||
if (result != CS_OK) {
|
||||
|
|
@ -1513,22 +1568,27 @@ static gboolean service_dfsm_dispatch(cfs_service_t *service, gpointer context)
|
|||
cs_error_t result;
|
||||
|
||||
result = dfsm_dispatch(dfsm, CS_DISPATCH_ONE);
|
||||
if (result == CS_ERR_LIBRARY || result == CS_ERR_BAD_HANDLE)
|
||||
if (result == CS_ERR_LIBRARY || result == CS_ERR_BAD_HANDLE) {
|
||||
goto finalize;
|
||||
if (result != CS_OK)
|
||||
}
|
||||
if (result != CS_OK) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
dfsm_mode_t mode = dfsm_get_mode(dfsm);
|
||||
if (mode >= DFSM_ERROR_MODE_START) {
|
||||
if (dfsm->joined) {
|
||||
result = dfsm_leave(dfsm);
|
||||
if (result == CS_ERR_LIBRARY || result == CS_ERR_BAD_HANDLE)
|
||||
if (result == CS_ERR_LIBRARY || result == CS_ERR_BAD_HANDLE) {
|
||||
goto finalize;
|
||||
if (result != CS_OK)
|
||||
}
|
||||
if (result != CS_OK) {
|
||||
goto finalize;
|
||||
}
|
||||
} else {
|
||||
if (!dfsm->we_are_member)
|
||||
if (!dfsm->we_are_member) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1566,8 +1626,9 @@ cfs_service_t *service_dfsm_new(dfsm_t *dfsm) {
|
|||
g_return_val_if_fail(dfsm != NULL, NULL);
|
||||
|
||||
service_dfsm_private_t *private = g_new0(service_dfsm_private_t, 1);
|
||||
if (!private)
|
||||
if (!private) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private->dfsm = dfsm;
|
||||
|
||||
|
|
|
|||
|
|
@ -162,19 +162,22 @@ void clog_dump_json(clog_base_t *clog, GString *str, const char *ident, guint ma
|
|||
}
|
||||
cpos = cur->prev;
|
||||
|
||||
if (count >= max_entries)
|
||||
if (count >= max_entries) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ident_digest && ident_digest != cur->ident_digest)
|
||||
if (ident_digest && ident_digest != cur->ident_digest) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char *node = cur->data;
|
||||
char *ident = node + cur->node_len;
|
||||
char *tag = ident + cur->ident_len;
|
||||
char *msg = tag + cur->tag_len;
|
||||
|
||||
if (count)
|
||||
if (count) {
|
||||
g_string_append_printf(str, ",\n");
|
||||
}
|
||||
|
||||
g_string_append_printf(
|
||||
str,
|
||||
|
|
@ -187,8 +190,9 @@ void clog_dump_json(clog_base_t *clog, GString *str, const char *ident, guint ma
|
|||
count++;
|
||||
}
|
||||
|
||||
if (count)
|
||||
if (count) {
|
||||
g_string_append_printf(str, "\n");
|
||||
}
|
||||
|
||||
g_string_append_printf(str, "]\n");
|
||||
g_string_append_printf(str, "}\n");
|
||||
|
|
@ -208,8 +212,9 @@ void clog_copy(clog_base_t *clog, const clog_entry_t *entry) {
|
|||
uint32_t size = clog_entry_size(entry);
|
||||
|
||||
clog_entry_t *new;
|
||||
if ((new = clog_alloc_entry(clog, size)))
|
||||
if ((new = clog_alloc_entry(clog, size))) {
|
||||
memcpy((char *)new + 8, (char *)entry + 8, size - 8);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t clog_pack(
|
||||
|
|
@ -275,8 +280,9 @@ uint32_t clog_pack(
|
|||
clog_base_t *clog_new(uint32_t size) {
|
||||
g_return_val_if_fail(sizeof(clog_base_t) == 8, NULL);
|
||||
|
||||
if (!size)
|
||||
if (!size) {
|
||||
size = CLOG_DEFAULT_SIZE;
|
||||
}
|
||||
|
||||
g_return_val_if_fail(size >= (CLOG_MAX_ENTRY_SIZE * 10), NULL);
|
||||
|
||||
|
|
@ -292,11 +298,13 @@ static gint clog_entry_sort_fn(gconstpointer v1, gconstpointer v2, gpointer user
|
|||
clog_entry_t *entry1 = (clog_entry_t *)v1;
|
||||
clog_entry_t *entry2 = (clog_entry_t *)v2;
|
||||
|
||||
if (entry1->time != entry2->time)
|
||||
if (entry1->time != entry2->time) {
|
||||
return entry1->time - entry2->time;
|
||||
}
|
||||
|
||||
if (entry1->node_digest != entry2->node_digest)
|
||||
if (entry1->node_digest != entry2->node_digest) {
|
||||
return entry1->node_digest - entry2->node_digest;
|
||||
}
|
||||
|
||||
return entry1->uid - entry2->uid;
|
||||
}
|
||||
|
|
@ -315,8 +323,9 @@ clog_base_t *clog_sort(clog_base_t *clog) {
|
|||
g_return_val_if_fail(clog->cpos != 0, NULL);
|
||||
|
||||
clog_base_t *res = clog_new(clog->size);
|
||||
if (!res)
|
||||
if (!res) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GTree *tree = g_tree_new_with_data(clog_entry_sort_fn, NULL);
|
||||
if (!tree) {
|
||||
|
|
@ -356,8 +365,9 @@ static gboolean dedup_lookup(GHashTable *dedup, const clog_entry_t *entry) {
|
|||
|
||||
dedup_entry_t *dd = g_hash_table_lookup(dedup, &entry->node_digest);
|
||||
if (!dd) {
|
||||
if (!(dd = g_new0(dedup_entry_t, 1)))
|
||||
if (!(dd = g_new0(dedup_entry_t, 1))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dd->node_digest = entry->node_digest;
|
||||
dd->time = entry->time;
|
||||
|
|
@ -403,8 +413,9 @@ clog_base_t *clusterlog_merge(clusterlog_t *cl, clog_base_t **clog, int count, i
|
|||
uint32_t maxsize = 0;
|
||||
|
||||
GHashTable *dedup;
|
||||
if (!(dedup = g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, g_free)))
|
||||
if (!(dedup = g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, g_free))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GTree *tree = g_tree_new_with_data(clog_entry_sort_fn, NULL);
|
||||
if (!tree) {
|
||||
|
|
@ -422,8 +433,9 @@ clog_base_t *clusterlog_merge(clusterlog_t *cl, clog_base_t **clog, int count, i
|
|||
g_mutex_lock(&cl->mutex);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (i == local_index)
|
||||
if (i == local_index) {
|
||||
clog[i] = cl->base;
|
||||
}
|
||||
|
||||
if (!clog[i]) {
|
||||
cfs_critical("log pointer is NULL!");
|
||||
|
|
@ -431,8 +443,9 @@ clog_base_t *clusterlog_merge(clusterlog_t *cl, clog_base_t **clog, int count, i
|
|||
continue;
|
||||
}
|
||||
cpos[i] = clog[i]->cpos;
|
||||
if (clog[i]->size > maxsize)
|
||||
if (clog[i]->size > maxsize) {
|
||||
maxsize = clog[i]->size;
|
||||
}
|
||||
}
|
||||
|
||||
size_t logsize = 0;
|
||||
|
|
@ -446,8 +459,9 @@ clog_base_t *clusterlog_merge(clusterlog_t *cl, clog_base_t **clog, int count, i
|
|||
|
||||
/* select entry wit latest time */
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (!cpos[i])
|
||||
if (!cpos[i]) {
|
||||
continue;
|
||||
}
|
||||
clog_entry_t *cur = (clog_entry_t *)((char *)clog[i] + cpos[i]);
|
||||
if (cur->time > last) {
|
||||
last = cur->time;
|
||||
|
|
@ -455,8 +469,9 @@ clog_base_t *clusterlog_merge(clusterlog_t *cl, clog_base_t **clog, int count, i
|
|||
}
|
||||
}
|
||||
|
||||
if (found < 0)
|
||||
if (found < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
clog_entry_t *cur = (clog_entry_t *)((char *)clog[found] + cpos[found]);
|
||||
|
||||
|
|
@ -464,8 +479,9 @@ clog_base_t *clusterlog_merge(clusterlog_t *cl, clog_base_t **clog, int count, i
|
|||
g_tree_insert(tree, cur, cur);
|
||||
dedup_lookup(dedup, cur); /* just to record versions */
|
||||
logsize += cur->next - cpos[found];
|
||||
if (logsize >= maxsize)
|
||||
if (logsize >= maxsize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// no previous entry or wrap-around into already overwritten entry
|
||||
|
|
@ -500,27 +516,32 @@ void clusterlog_destroy(clusterlog_t *cl) {
|
|||
|
||||
g_mutex_clear(&cl->mutex);
|
||||
|
||||
if (cl->base)
|
||||
if (cl->base) {
|
||||
g_free(cl->base);
|
||||
}
|
||||
|
||||
if (cl->dedup)
|
||||
if (cl->dedup) {
|
||||
g_hash_table_destroy(cl->dedup);
|
||||
}
|
||||
|
||||
g_free(cl);
|
||||
}
|
||||
|
||||
clusterlog_t *clusterlog_new(void) {
|
||||
clusterlog_t *cl = g_new0(clusterlog_t, 1);
|
||||
if (!cl)
|
||||
if (!cl) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
g_mutex_init(&cl->mutex);
|
||||
|
||||
if (!(cl->base = clog_new(0)))
|
||||
if (!(cl->base = clog_new(0))) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!(cl->dedup = g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, g_free)))
|
||||
if (!(cl->dedup = g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, g_free))) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return cl;
|
||||
|
||||
|
|
@ -586,8 +607,9 @@ void clusterlog_add(
|
|||
uint32_t size = clog_pack(entry, cfs.nodename, ident, tag, pid, ctime, priority, msg);
|
||||
g_free(msg);
|
||||
|
||||
if (!size)
|
||||
if (!size) {
|
||||
return;
|
||||
}
|
||||
|
||||
clusterlog_insert(cl, entry);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,13 +93,15 @@ cfs_service_new(cfs_service_callbacks_t *callbacks, const char *log_domain, gpoi
|
|||
g_return_val_if_fail(callbacks->cfs_service_dispatch_fn != NULL, NULL);
|
||||
|
||||
cfs_service_t *service = g_new0(cfs_service_t, 1);
|
||||
if (!service)
|
||||
if (!service) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (log_domain)
|
||||
if (log_domain) {
|
||||
service->log_domain = log_domain;
|
||||
else
|
||||
} else {
|
||||
service->log_domain = G_LOG_DOMAIN;
|
||||
}
|
||||
|
||||
service->callbacks = callbacks;
|
||||
|
||||
|
|
@ -131,11 +133,13 @@ cfs_loop_t *cfs_loop_new(struct fuse *fuse) {
|
|||
void cfs_loop_destroy(cfs_loop_t *loop) {
|
||||
g_return_if_fail(loop != NULL);
|
||||
|
||||
if (loop->qbloop)
|
||||
if (loop->qbloop) {
|
||||
qb_loop_destroy(loop->qbloop);
|
||||
}
|
||||
|
||||
if (loop->services)
|
||||
if (loop->services) {
|
||||
g_list_free(loop->services);
|
||||
}
|
||||
|
||||
g_mutex_clear(&loop->server_started_mutex);
|
||||
g_cond_clear(&loop->server_started_cond);
|
||||
|
|
@ -166,8 +170,9 @@ static int32_t poll_dispatch_fn(int32_t fd, int32_t revents, void *data) {
|
|||
service->initialized = FALSE;
|
||||
service->errcount = 0;
|
||||
|
||||
if (!service->restartable)
|
||||
if (!service->restartable) {
|
||||
service->callbacks->cfs_service_finalize_fn(service, service->context);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -198,16 +203,18 @@ static void service_timer_job(void *data) {
|
|||
|
||||
g_mutex_unlock(&loop->server_started_mutex);
|
||||
|
||||
if (terminate)
|
||||
if (terminate) {
|
||||
return;
|
||||
}
|
||||
|
||||
GList *l = loop->services;
|
||||
while (l) {
|
||||
cfs_service_t *service = (cfs_service_t *)l->data;
|
||||
l = g_list_next(l);
|
||||
|
||||
if (!service->initialized)
|
||||
if (!service->initialized) {
|
||||
continue;
|
||||
}
|
||||
|
||||
time_t ctime = time(NULL);
|
||||
if (service->period && service->callbacks->cfs_service_timer_fn &&
|
||||
|
|
@ -232,8 +239,9 @@ static void service_start_job(void *data) {
|
|||
terminate = loop->stop_worker_flag;
|
||||
g_mutex_unlock(&loop->server_started_mutex);
|
||||
|
||||
if (terminate)
|
||||
if (terminate) {
|
||||
return;
|
||||
}
|
||||
|
||||
GList *l = loop->services;
|
||||
time_t ctime = time(NULL);
|
||||
|
|
@ -262,8 +270,9 @@ static void service_start_job(void *data) {
|
|||
service->callbacks->cfs_service_finalize_fn(service, service->context);
|
||||
}
|
||||
} else {
|
||||
if (!service->errcount)
|
||||
if (!service->errcount) {
|
||||
cfs_dom_critical(service->log_domain, "can't initialize service");
|
||||
}
|
||||
service->errcount++;
|
||||
}
|
||||
}
|
||||
|
|
@ -315,8 +324,9 @@ gboolean cfs_loop_start_worker(cfs_loop_t *loop) {
|
|||
loop->worker = g_thread_new("cfs_loop", cfs_loop_worker_thread, loop);
|
||||
|
||||
g_mutex_lock(&loop->server_started_mutex);
|
||||
while (!loop->server_started)
|
||||
while (!loop->server_started) {
|
||||
g_cond_wait(&loop->server_started_cond, &loop->server_started_mutex);
|
||||
}
|
||||
g_mutex_unlock(&loop->server_started_mutex);
|
||||
|
||||
cfs_debug("worker started");
|
||||
|
|
@ -331,8 +341,9 @@ void cfs_loop_stop_worker(cfs_loop_t *loop) {
|
|||
|
||||
g_mutex_lock(&loop->server_started_mutex);
|
||||
loop->stop_worker_flag = TRUE;
|
||||
while (loop->server_started)
|
||||
while (loop->server_started) {
|
||||
g_cond_wait(&loop->server_stopped_cond, &loop->server_started_mutex);
|
||||
}
|
||||
g_mutex_unlock(&loop->server_started_mutex);
|
||||
|
||||
if (loop->worker) {
|
||||
|
|
|
|||
|
|
@ -75,17 +75,20 @@ memdb_tree_entry_t *memdb_tree_entry_copy(memdb_tree_entry_t *te, gboolean with_
|
|||
}
|
||||
|
||||
void memdb_tree_entry_free(memdb_tree_entry_t *te) {
|
||||
if (!te)
|
||||
if (!te) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (te->type == DT_REG) {
|
||||
if (te->data.value)
|
||||
if (te->data.value) {
|
||||
g_free(te->data.value);
|
||||
}
|
||||
}
|
||||
|
||||
if (te->type == DT_DIR) {
|
||||
if (te->data.entries)
|
||||
if (te->data.entries) {
|
||||
g_hash_table_destroy(te->data.entries);
|
||||
}
|
||||
}
|
||||
|
||||
g_free(te);
|
||||
|
|
@ -94,8 +97,9 @@ void memdb_tree_entry_free(memdb_tree_entry_t *te) {
|
|||
void memdb_lock_info_free(memdb_lock_info_t *li) {
|
||||
g_return_if_fail(li != NULL);
|
||||
|
||||
if (li->path)
|
||||
if (li->path) {
|
||||
g_free(li->path);
|
||||
}
|
||||
|
||||
g_free(li);
|
||||
}
|
||||
|
|
@ -104,11 +108,13 @@ static gint memdb_tree_compare(gconstpointer v1, gconstpointer v2) {
|
|||
guint64 a = ((const memdb_tree_entry_t *)v1)->inode;
|
||||
guint64 b = ((const memdb_tree_entry_t *)v2)->inode;
|
||||
|
||||
if (a == b)
|
||||
if (a == b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (a > b)
|
||||
if (a > b) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -116,8 +122,9 @@ static gint memdb_tree_compare(gconstpointer v1, gconstpointer v2) {
|
|||
static void split_path(const char *path, char **dirname, char **basename) {
|
||||
char *dup = g_strdup(path);
|
||||
int len = strlen(dup) - 1;
|
||||
while (len >= 0 && dup[len] == '/')
|
||||
while (len >= 0 && dup[len] == '/') {
|
||||
dup[len--] = 0;
|
||||
}
|
||||
|
||||
char *dn = g_path_get_dirname(dup);
|
||||
char *bn = g_path_get_basename(dup);
|
||||
|
|
@ -152,8 +159,9 @@ memdb_lookup_path(memdb_t *memdb, const char *path, memdb_tree_entry_t **parent)
|
|||
memdb_tree_entry_t *cdir = memdb->root;
|
||||
*parent = NULL;
|
||||
|
||||
if (path[0] == 0 || ((path[0] == '.' || path[0] == '/') && path[1] == 0))
|
||||
if (path[0] == 0 || ((path[0] == '.' || path[0] == '/') && path[1] == 0)) {
|
||||
return cdir;
|
||||
}
|
||||
|
||||
gchar **set = g_strsplit_set(path, "/", 0);
|
||||
|
||||
|
|
@ -162,12 +170,14 @@ memdb_lookup_path(memdb_t *memdb, const char *path, memdb_tree_entry_t **parent)
|
|||
|
||||
while ((name = set[i++])) {
|
||||
|
||||
if (name[0] == 0)
|
||||
if (name[0] == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
*parent = cdir;
|
||||
if ((cdir = memdb_lookup_dir_entry(memdb, name, cdir)) == NULL)
|
||||
if ((cdir = memdb_lookup_dir_entry(memdb, name, cdir)) == NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev(set);
|
||||
|
|
@ -176,8 +186,9 @@ memdb_lookup_path(memdb_t *memdb, const char *path, memdb_tree_entry_t **parent)
|
|||
}
|
||||
|
||||
static gboolean name_is_vm_config(const char *name, guint32 *vmid_ret) {
|
||||
if (!name || name[0] < '1' || name[0] > '9')
|
||||
if (!name || name[0] < '1' || name[0] > '9') {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char *end = NULL;
|
||||
|
||||
|
|
@ -186,11 +197,13 @@ static gboolean name_is_vm_config(const char *name, guint32 *vmid_ret) {
|
|||
unsigned long int vmid = strtoul(name, &end, 10);
|
||||
|
||||
if (!end || end[0] != '.' || end[1] != 'c' || end[2] != 'o' || end[3] != 'n' || end[4] != 'f' ||
|
||||
end[5] != 0 || errno != 0 || vmid > G_MAXUINT32)
|
||||
end[5] != 0 || errno != 0 || vmid > G_MAXUINT32) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (vmid_ret)
|
||||
if (vmid_ret) {
|
||||
*vmid_ret = (guint32)vmid;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -209,8 +222,9 @@ static gboolean valid_nodename(const char *nodename) {
|
|||
for (int i = 0; i < len; i++) {
|
||||
char c = nodename[i];
|
||||
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
|
||||
(i != 0 && i != (len - 1) && c == '-'))
|
||||
(i != 0 && i != (len - 1) && c == '-')) {
|
||||
continue;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -218,11 +232,13 @@ static gboolean valid_nodename(const char *nodename) {
|
|||
}
|
||||
|
||||
static char *dir_contain_vm_config(const char *dirname, int *vmtype_ret) {
|
||||
if (!dirname)
|
||||
if (!dirname) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strncmp(dirname, "nodes/", 6) != 0)
|
||||
if (strncmp(dirname, "nodes/", 6) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dirname += 6;
|
||||
|
||||
|
|
@ -249,8 +265,9 @@ static char *dir_contain_vm_config(const char *dirname, int *vmtype_ret) {
|
|||
}
|
||||
|
||||
static char *path_contain_vm_config(const char *path, int *vmtype_ret, guint32 *vmid_ret) {
|
||||
if (!path)
|
||||
if (!path) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *dirname = NULL;
|
||||
char *base = NULL;
|
||||
|
|
@ -258,8 +275,9 @@ static char *path_contain_vm_config(const char *path, int *vmtype_ret, guint32 *
|
|||
|
||||
split_path(path, &dirname, &base);
|
||||
|
||||
if (name_is_vm_config(base, vmid_ret))
|
||||
if (name_is_vm_config(base, vmid_ret)) {
|
||||
nodename = dir_contain_vm_config(dirname, vmtype_ret);
|
||||
}
|
||||
|
||||
g_free(dirname);
|
||||
g_free(base);
|
||||
|
|
@ -292,15 +310,18 @@ static gboolean vmlist_add_dir(
|
|||
|
||||
memdb_tree_entry_t *node_te = (memdb_tree_entry_t *)value;
|
||||
|
||||
if (node_te->type != DT_REG)
|
||||
if (node_te->type != DT_REG) {
|
||||
continue;
|
||||
}
|
||||
|
||||
guint32 vmid = 0;
|
||||
if (!name_is_vm_config(node_te->name, &vmid))
|
||||
if (!name_is_vm_config(node_te->name, &vmid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!vmlist_hash_insert_vm(vmlist, vmtype, vmid, nodename, FALSE))
|
||||
if (!vmlist_hash_insert_vm(vmlist, vmtype, vmid, nodename, FALSE)) {
|
||||
ret = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -322,8 +343,9 @@ gboolean memdb_lock_expired(memdb_t *memdb, const char *path, const guchar csum[
|
|||
g_critical("wrong lock csum - reset timeout");
|
||||
return FALSE;
|
||||
}
|
||||
if ((ctime > li->ltime) && ((ctime - li->ltime) > CFS_LOCK_TIMEOUT))
|
||||
if ((ctime > li->ltime) && ((ctime - li->ltime) > CFS_LOCK_TIMEOUT)) {
|
||||
return TRUE;
|
||||
}
|
||||
} else {
|
||||
li = g_new0(memdb_lock_info_t, 1);
|
||||
li->path = g_strdup(path);
|
||||
|
|
@ -341,11 +363,13 @@ void memdb_update_locks(memdb_t *memdb) {
|
|||
|
||||
memdb_tree_entry_t *te, *parent;
|
||||
|
||||
if (!(te = memdb_lookup_path(memdb, "priv/lock", &parent)))
|
||||
if (!(te = memdb_lookup_path(memdb, "priv/lock", &parent))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (te->type != DT_DIR)
|
||||
if (te->type != DT_DIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
GHashTable *old = memdb->locks;
|
||||
memdb->locks =
|
||||
|
|
@ -359,8 +383,9 @@ void memdb_update_locks(memdb_t *memdb) {
|
|||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
|
||||
memdb_tree_entry_t *lock_te = (memdb_tree_entry_t *)value;
|
||||
if (lock_te->type != DT_DIR)
|
||||
if (lock_te->type != DT_DIR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
memdb_lock_info_t *li;
|
||||
li = g_new0(memdb_lock_info_t, 1);
|
||||
|
|
@ -382,8 +407,9 @@ void memdb_update_locks(memdb_t *memdb) {
|
|||
}
|
||||
}
|
||||
|
||||
if (old)
|
||||
if (old) {
|
||||
g_hash_table_destroy(old);
|
||||
}
|
||||
}
|
||||
|
||||
gboolean memdb_recreate_vmlist(memdb_t *memdb) {
|
||||
|
|
@ -391,11 +417,13 @@ gboolean memdb_recreate_vmlist(memdb_t *memdb) {
|
|||
|
||||
memdb_tree_entry_t *te, *parent;
|
||||
|
||||
if (!(te = memdb_lookup_path(memdb, "nodes", &parent)))
|
||||
if (!(te = memdb_lookup_path(memdb, "nodes", &parent))) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (te->type != DT_DIR)
|
||||
if (te->type != DT_DIR) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GHashTable *vmlist = vmlist_hash_new();
|
||||
|
||||
|
|
@ -411,24 +439,29 @@ gboolean memdb_recreate_vmlist(memdb_t *memdb) {
|
|||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
|
||||
memdb_tree_entry_t *node_te = (memdb_tree_entry_t *)value;
|
||||
if (node_te->type != DT_DIR)
|
||||
if (node_te->type != DT_DIR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!valid_nodename(node_te->name))
|
||||
if (!valid_nodename(node_te->name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((te = g_hash_table_lookup(node_te->data.entries, "qemu-server"))) {
|
||||
if (!vmlist_add_dir(memdb, vmlist, node_te->name, VMTYPE_QEMU, te))
|
||||
if (!vmlist_add_dir(memdb, vmlist, node_te->name, VMTYPE_QEMU, te)) {
|
||||
ret = FALSE;
|
||||
}
|
||||
}
|
||||
// FIXME: remove openvz stuff for 7.x
|
||||
if ((te = g_hash_table_lookup(node_te->data.entries, "openvz"))) {
|
||||
if (!vmlist_add_dir(memdb, vmlist, node_te->name, VMTYPE_OPENVZ, te))
|
||||
if (!vmlist_add_dir(memdb, vmlist, node_te->name, VMTYPE_OPENVZ, te)) {
|
||||
ret = FALSE;
|
||||
}
|
||||
}
|
||||
if ((te = g_hash_table_lookup(node_te->data.entries, "lxc"))) {
|
||||
if (!vmlist_add_dir(memdb, vmlist, node_te->name, VMTYPE_LXC, te))
|
||||
if (!vmlist_add_dir(memdb, vmlist, node_te->name, VMTYPE_LXC, te)) {
|
||||
ret = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -484,17 +517,21 @@ void memdb_close(memdb_t *memdb) {
|
|||
|
||||
g_mutex_lock(&memdb->mutex);
|
||||
|
||||
if (memdb->bdb)
|
||||
if (memdb->bdb) {
|
||||
bdb_backend_close(memdb->bdb);
|
||||
}
|
||||
|
||||
if (memdb->index)
|
||||
if (memdb->index) {
|
||||
g_hash_table_destroy(memdb->index);
|
||||
}
|
||||
|
||||
if (memdb->locks)
|
||||
if (memdb->locks) {
|
||||
g_hash_table_destroy(memdb->locks);
|
||||
}
|
||||
|
||||
if (memdb->dbfilename)
|
||||
if (memdb->dbfilename) {
|
||||
g_free(memdb->dbfilename);
|
||||
}
|
||||
|
||||
memdb->index = NULL;
|
||||
memdb->bdb = NULL;
|
||||
|
|
@ -746,8 +783,9 @@ static int memdb_pwrite(
|
|||
memcpy(newdata, olddata, newsize);
|
||||
}
|
||||
|
||||
if (count && data)
|
||||
if (count && data) {
|
||||
memcpy((uint8_t *)newdata + offset, data, count);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
|
|
@ -782,8 +820,9 @@ static int memdb_pwrite(
|
|||
goto ret;
|
||||
}
|
||||
|
||||
if (nodename)
|
||||
if (nodename) {
|
||||
vmlist_register_vm(vmtype, vmid, nodename);
|
||||
}
|
||||
|
||||
ret = count;
|
||||
|
||||
|
|
@ -947,11 +986,13 @@ GList *memdb_readdir(memdb_t *memdb, const char *path) {
|
|||
|
||||
g_mutex_lock(&memdb->mutex);
|
||||
|
||||
if (!(te = memdb_lookup_path(memdb, path, &parent)))
|
||||
if (!(te = memdb_lookup_path(memdb, path, &parent))) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
if (te->type != DT_DIR)
|
||||
if (te->type != DT_DIR) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
GHashTable *ht = te->data.entries;
|
||||
|
||||
|
|
@ -979,23 +1020,27 @@ void memdb_dirlist_free(GList *dirlist) {
|
|||
GList *l = dirlist;
|
||||
|
||||
while (l) {
|
||||
if (l->data)
|
||||
if (l->data) {
|
||||
g_free(l->data);
|
||||
}
|
||||
|
||||
l = g_list_next(l);
|
||||
}
|
||||
|
||||
if (dirlist)
|
||||
if (dirlist) {
|
||||
g_list_free(dirlist);
|
||||
}
|
||||
}
|
||||
|
||||
static int unlink_tree_entry(memdb_t *memdb, memdb_tree_entry_t *parent, memdb_tree_entry_t *te) {
|
||||
g_return_val_if_fail(parent != NULL, -EACCES);
|
||||
g_return_val_if_fail(parent->inode == te->parent, -EACCES);
|
||||
|
||||
if (te->type == DT_DIR)
|
||||
if (g_hash_table_size(te->data.entries))
|
||||
if (te->type == DT_DIR) {
|
||||
if (g_hash_table_size(te->data.entries)) {
|
||||
return -ENOTEMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
if (!g_hash_table_steal(parent->data.entries, te->name)) {
|
||||
cfs_critical("internal error - can't delete entry");
|
||||
|
|
@ -1067,8 +1112,9 @@ int memdb_rename(memdb_t *memdb, const char *from, const char *to, guint32 write
|
|||
|
||||
if ((to_te = memdb_lookup_path(memdb, to, &to_parent))) {
|
||||
|
||||
if ((ret = unlink_tree_entry(memdb, to_parent, to_te)) != 0)
|
||||
if ((ret = unlink_tree_entry(memdb, to_parent, to_te)) != 0) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
base = strdup(to_te->name);
|
||||
|
||||
|
|
@ -1099,8 +1145,9 @@ int memdb_rename(memdb_t *memdb, const char *from, const char *to, guint32 write
|
|||
/* NOTE: unlink_tree_entry() make sure that we can only
|
||||
rename emtpy directories */
|
||||
|
||||
if ((ret = unlink_tree_entry(memdb, from_parent, from_te)) != 0)
|
||||
if ((ret = unlink_tree_entry(memdb, from_parent, from_te)) != 0) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
memdb->root->version++;
|
||||
memdb->root->mtime = mtime;
|
||||
|
|
@ -1132,11 +1179,13 @@ int memdb_rename(memdb_t *memdb, const char *from, const char *to, guint32 write
|
|||
|
||||
if (new->type == DT_REG) {
|
||||
|
||||
if (from_node)
|
||||
if (from_node) {
|
||||
vmlist_delete_vm(from_vmid);
|
||||
}
|
||||
|
||||
if (nodename)
|
||||
if (nodename) {
|
||||
vmlist_register_vm(vmtype, vmid, nodename);
|
||||
}
|
||||
|
||||
} else if (new->type == DT_DIR) {
|
||||
/* directories are alwayse empty (see unlink_tree_entry) */
|
||||
|
|
@ -1188,8 +1237,9 @@ int memdb_delete(memdb_t *memdb, const char *path, guint32 writer, guint32 mtime
|
|||
|
||||
record_memdb_change(path);
|
||||
|
||||
if ((ret = unlink_tree_entry(memdb, parent, te)) != 0)
|
||||
if ((ret = unlink_tree_entry(memdb, parent, te)) != 0) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
memdb->root->version++;
|
||||
memdb->root->mtime = mtime;
|
||||
|
|
@ -1351,8 +1401,9 @@ gboolean memdb_tree_entry_csum(memdb_tree_entry_t *te, guchar csum[32]) {
|
|||
g_checksum_update(sha256, (unsigned char *)&te->parent, sizeof(te->parent));
|
||||
g_checksum_update(sha256, (unsigned char *)te->name, strlen(te->name));
|
||||
|
||||
if (te->type == DT_REG && te->size)
|
||||
if (te->type == DT_REG && te->size) {
|
||||
g_checksum_update(sha256, (unsigned char *)te->data.value, te->size);
|
||||
}
|
||||
|
||||
size_t csum_len = 32;
|
||||
g_checksum_get_digest(sha256, csum, &csum_len);
|
||||
|
|
@ -1385,8 +1436,9 @@ memdb_compute_checksum(GHashTable *index, memdb_tree_entry_t *root, guchar *csum
|
|||
g_checksum_update(sha256, (unsigned char *)&te->parent, sizeof(te->parent));
|
||||
g_checksum_update(sha256, (unsigned char *)te->name, strlen(te->name));
|
||||
|
||||
if (te->type == DT_REG && te->size)
|
||||
if (te->type == DT_REG && te->size) {
|
||||
g_checksum_update(sha256, (unsigned char *)te->data.value, te->size);
|
||||
}
|
||||
|
||||
l = g_list_next(l);
|
||||
}
|
||||
|
|
@ -1434,8 +1486,9 @@ memdb_index_t *memdb_encode_index(GHashTable *index, memdb_tree_entry_t *root) {
|
|||
while (l) {
|
||||
memdb_tree_entry_t *te = (memdb_tree_entry_t *)l->data;
|
||||
|
||||
if (te->inode > idx->last_inode)
|
||||
if (te->inode > idx->last_inode) {
|
||||
idx->last_inode = te->inode;
|
||||
}
|
||||
|
||||
idx->entries[ind].inode = te->inode;
|
||||
|
||||
|
|
@ -1449,8 +1502,9 @@ memdb_index_t *memdb_encode_index(GHashTable *index, memdb_tree_entry_t *root) {
|
|||
g_checksum_update(sha256, (unsigned char *)&te->parent, sizeof(te->parent));
|
||||
g_checksum_update(sha256, (unsigned char *)te->name, strlen(te->name));
|
||||
|
||||
if (te->type == DT_REG && te->size)
|
||||
if (te->type == DT_REG && te->size) {
|
||||
g_checksum_update(sha256, (unsigned char *)te->data.value, te->size);
|
||||
}
|
||||
|
||||
gsize len = 32;
|
||||
g_checksum_get_digest(sha256, (guint8 *)idx->entries[ind].digest, &len);
|
||||
|
|
|
|||
|
|
@ -90,8 +90,9 @@ static cfs_plug_t *find_plug(const char *path, char **sub) {
|
|||
g_return_val_if_fail(root_plug != NULL, NULL);
|
||||
g_return_val_if_fail(path != NULL, NULL);
|
||||
|
||||
while (*path == '/')
|
||||
while (*path == '/') {
|
||||
path++;
|
||||
}
|
||||
|
||||
cfs_debug("find_plug start %s", path);
|
||||
|
||||
|
|
@ -102,8 +103,9 @@ static cfs_plug_t *find_plug(const char *path, char **sub) {
|
|||
|
||||
cfs_debug("find_plug end %s = %p (%s)", path, (void *)plug, subpath);
|
||||
|
||||
if (subpath && subpath[0])
|
||||
if (subpath && subpath[0]) {
|
||||
*sub = g_strdup(subpath);
|
||||
}
|
||||
|
||||
g_free(tmppath);
|
||||
|
||||
|
|
@ -138,8 +140,9 @@ static int cfs_fuse_getattr(const char *path, struct stat *stbuf) {
|
|||
|
||||
cfs_debug("leave cfs_fuse_getattr %s (%d)", path, ret);
|
||||
|
||||
if (subpath)
|
||||
if (subpath) {
|
||||
g_free(subpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -157,16 +160,19 @@ static int cfs_fuse_readdir(
|
|||
char *subpath = NULL;
|
||||
cfs_plug_t *plug = find_plug(path, &subpath);
|
||||
|
||||
if (!plug)
|
||||
if (!plug) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
if (plug->ops && plug->ops->readdir)
|
||||
if (plug->ops && plug->ops->readdir) {
|
||||
ret = plug->ops->readdir(plug, subpath ? subpath : "", buf, filler, 0, fi);
|
||||
}
|
||||
ret:
|
||||
cfs_debug("leave cfs_fuse_readdir %s (%d)", path, ret);
|
||||
|
||||
if (subpath)
|
||||
if (subpath) {
|
||||
g_free(subpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -177,13 +183,15 @@ static int cfs_fuse_chmod(const char *path, mode_t mode) {
|
|||
cfs_debug("enter cfs_fuse_chmod %s", path);
|
||||
|
||||
mode_t allowed_mode = (S_IRUSR | S_IWUSR);
|
||||
if (!path_is_private(path))
|
||||
if (!path_is_private(path)) {
|
||||
allowed_mode |= (S_IRGRP);
|
||||
}
|
||||
|
||||
// allow only setting our supported modes (0600 for priv, 0640 for rest)
|
||||
// mode has additional bits set, which we ignore; see stat(2)
|
||||
if ((mode & ALLPERMS) == allowed_mode)
|
||||
if ((mode & ALLPERMS) == allowed_mode) {
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
cfs_debug("leave cfs_fuse_chmod %s (%d) mode: %o", path, ret, (int)mode);
|
||||
|
||||
|
|
@ -196,8 +204,9 @@ static int cfs_fuse_chown(const char *path, uid_t user, gid_t group) {
|
|||
cfs_debug("enter cfs_fuse_chown %s", path);
|
||||
|
||||
// we get -1 if no change should be made
|
||||
if ((user == 0 || user == -1) && (group == cfs.gid || group == -1))
|
||||
if ((user == 0 || user == -1) && (group == cfs.gid || group == -1)) {
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
cfs_debug("leave cfs_fuse_chown %s (%d) (uid: %d; gid: %d)", path, ret, user, group);
|
||||
|
||||
|
|
@ -212,17 +221,20 @@ static int cfs_fuse_mkdir(const char *path, mode_t mode) {
|
|||
char *subpath = NULL;
|
||||
cfs_plug_t *plug = find_plug(path, &subpath);
|
||||
|
||||
if (!plug)
|
||||
if (!plug) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
if (subpath && plug->ops && plug->ops->mkdir)
|
||||
if (subpath && plug->ops && plug->ops->mkdir) {
|
||||
ret = plug->ops->mkdir(plug, subpath, mode);
|
||||
}
|
||||
|
||||
ret:
|
||||
cfs_debug("leave cfs_fuse_mkdir %s (%d)", path, ret);
|
||||
|
||||
if (subpath)
|
||||
if (subpath) {
|
||||
g_free(subpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -235,17 +247,20 @@ static int cfs_fuse_rmdir(const char *path) {
|
|||
char *subpath = NULL;
|
||||
cfs_plug_t *plug = find_plug(path, &subpath);
|
||||
|
||||
if (!plug)
|
||||
if (!plug) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
if (subpath && plug->ops && plug->ops->rmdir)
|
||||
if (subpath && plug->ops && plug->ops->rmdir) {
|
||||
ret = plug->ops->rmdir(plug, subpath);
|
||||
}
|
||||
|
||||
ret:
|
||||
cfs_debug("leave cfs_fuse_rmdir %s (%d)", path, ret);
|
||||
|
||||
if (subpath)
|
||||
if (subpath) {
|
||||
g_free(subpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -261,20 +276,24 @@ static int cfs_fuse_rename(const char *from, const char *to) {
|
|||
char *sub_to = NULL;
|
||||
cfs_plug_t *plug_to = find_plug(to, &sub_to);
|
||||
|
||||
if (!plug_from || !plug_to || plug_from != plug_to)
|
||||
if (!plug_from || !plug_to || plug_from != plug_to) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
if (plug_from->ops && plug_from->ops->rename && sub_from && sub_to)
|
||||
if (plug_from->ops && plug_from->ops->rename && sub_from && sub_to) {
|
||||
ret = plug_from->ops->rename(plug_from, sub_from, sub_to);
|
||||
}
|
||||
|
||||
ret:
|
||||
cfs_debug("leave cfs_fuse_rename from %s to %s (%d)", from, to, ret);
|
||||
|
||||
if (sub_from)
|
||||
if (sub_from) {
|
||||
g_free(sub_from);
|
||||
}
|
||||
|
||||
if (sub_to)
|
||||
if (sub_to) {
|
||||
g_free(sub_to);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -298,8 +317,9 @@ static int cfs_fuse_open(const char *path, struct fuse_file_info *fi) {
|
|||
|
||||
cfs_debug("leave cfs_fuse_open %s (%d)", path, ret);
|
||||
|
||||
if (subpath)
|
||||
if (subpath) {
|
||||
g_free(subpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -316,14 +336,16 @@ cfs_fuse_read(const char *path, char *buf, size_t size, off_t offset, struct fus
|
|||
cfs_plug_t *plug = find_plug(path, &subpath);
|
||||
|
||||
if (plug && plug->ops) {
|
||||
if ((subpath || !plug->ops->readdir) && plug->ops->read)
|
||||
if ((subpath || !plug->ops->readdir) && plug->ops->read) {
|
||||
ret = plug->ops->read(plug, subpath ? subpath : "", buf, size, offset, fi);
|
||||
}
|
||||
}
|
||||
|
||||
cfs_debug("leave cfs_fuse_read %s (%d)", path, ret);
|
||||
|
||||
if (subpath)
|
||||
if (subpath) {
|
||||
g_free(subpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -341,14 +363,16 @@ static int cfs_fuse_write(
|
|||
cfs_plug_t *plug = find_plug(path, &subpath);
|
||||
|
||||
if (plug && plug->ops) {
|
||||
if ((subpath || !plug->ops->readdir) && plug->ops->write)
|
||||
if ((subpath || !plug->ops->readdir) && plug->ops->write) {
|
||||
ret = plug->ops->write(plug, subpath ? subpath : "", buf, size, offset, fi);
|
||||
}
|
||||
}
|
||||
|
||||
cfs_debug("leave cfs_fuse_write %s (%d)", path, ret);
|
||||
|
||||
if (subpath)
|
||||
if (subpath) {
|
||||
g_free(subpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -362,14 +386,16 @@ static int cfs_fuse_truncate(const char *path, off_t size) {
|
|||
cfs_plug_t *plug = find_plug(path, &subpath);
|
||||
|
||||
if (plug && plug->ops) {
|
||||
if ((subpath || !plug->ops->readdir) && plug->ops->truncate)
|
||||
if ((subpath || !plug->ops->readdir) && plug->ops->truncate) {
|
||||
ret = plug->ops->truncate(plug, subpath ? subpath : "", size);
|
||||
}
|
||||
}
|
||||
|
||||
cfs_debug("leave cfs_fuse_truncate %s (%d)", path, ret);
|
||||
|
||||
if (subpath)
|
||||
if (subpath) {
|
||||
g_free(subpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -382,17 +408,20 @@ static int cfs_fuse_create(const char *path, mode_t mode, struct fuse_file_info
|
|||
char *subpath = NULL;
|
||||
cfs_plug_t *plug = find_plug(path, &subpath);
|
||||
|
||||
if (!plug)
|
||||
if (!plug) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
if (subpath && plug->ops && plug->ops->create)
|
||||
if (subpath && plug->ops && plug->ops->create) {
|
||||
ret = plug->ops->create(plug, subpath, mode, fi);
|
||||
}
|
||||
|
||||
ret:
|
||||
cfs_debug("leave cfs_fuse_create %s (%d)", path, ret);
|
||||
|
||||
if (subpath)
|
||||
if (subpath) {
|
||||
g_free(subpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -405,17 +434,20 @@ static int cfs_fuse_unlink(const char *path) {
|
|||
char *subpath = NULL;
|
||||
cfs_plug_t *plug = find_plug(path, &subpath);
|
||||
|
||||
if (!plug)
|
||||
if (!plug) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
if (subpath && plug->ops && plug->ops->unlink)
|
||||
if (subpath && plug->ops && plug->ops->unlink) {
|
||||
ret = plug->ops->unlink(plug, subpath);
|
||||
}
|
||||
|
||||
ret:
|
||||
cfs_debug("leave cfs_fuse_unlink %s (%d)", path, ret);
|
||||
|
||||
if (subpath)
|
||||
if (subpath) {
|
||||
g_free(subpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -428,17 +460,20 @@ static int cfs_fuse_readlink(const char *path, char *buf, size_t max) {
|
|||
char *subpath = NULL;
|
||||
cfs_plug_t *plug = find_plug(path, &subpath);
|
||||
|
||||
if (!plug)
|
||||
if (!plug) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
if (plug->ops && plug->ops->readlink)
|
||||
if (plug->ops && plug->ops->readlink) {
|
||||
ret = plug->ops->readlink(plug, subpath ? subpath : "", buf, max);
|
||||
}
|
||||
|
||||
ret:
|
||||
cfs_debug("leave cfs_fuse_readlink %s (%d)", path, ret);
|
||||
|
||||
if (subpath)
|
||||
if (subpath) {
|
||||
g_free(subpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -451,17 +486,20 @@ static int cfs_fuse_utimens(const char *path, const struct timespec tv[2]) {
|
|||
char *subpath = NULL;
|
||||
cfs_plug_t *plug = find_plug(path, &subpath);
|
||||
|
||||
if (!plug)
|
||||
if (!plug) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
if (plug->ops && plug->ops->utimens)
|
||||
if (plug->ops && plug->ops->utimens) {
|
||||
ret = plug->ops->utimens(plug, subpath ? subpath : "", tv);
|
||||
}
|
||||
|
||||
ret:
|
||||
cfs_debug("leave cfs_fuse_utimens %s (%d)", path, ret);
|
||||
|
||||
if (subpath)
|
||||
if (subpath) {
|
||||
g_free(subpath);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -473,8 +511,9 @@ static int cfs_fuse_statfs(const char *path, struct statvfs *stbuf) {
|
|||
|
||||
int ret = -EACCES;
|
||||
|
||||
if (root_plug && root_plug->ops && root_plug->ops->statfs)
|
||||
if (root_plug && root_plug->ops && root_plug->ops->statfs) {
|
||||
ret = root_plug->ops->statfs(root_plug, "", stbuf);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -598,8 +637,9 @@ static void update_qb_log_settings(void) {
|
|||
static int write_debug_setting_cb(cfs_plug_t *plug, const char *buf, size_t size) {
|
||||
int res = -EIO;
|
||||
|
||||
if (size < 2)
|
||||
if (size < 2) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if (strncmp(buf, "0\n", 2) == 0) {
|
||||
if (cfs.debug) {
|
||||
|
|
@ -670,8 +710,9 @@ static char *lookup_node_ip(const char *nodename) {
|
|||
struct addrinfo ahints = {
|
||||
.ai_flags = AI_V4MAPPED | AI_ALL,
|
||||
};
|
||||
if (getaddrinfo(nodename, NULL, &ahints, &ainfo))
|
||||
if (getaddrinfo(nodename, NULL, &ahints, &ainfo)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *res = NULL;
|
||||
for (struct addrinfo *addr = ainfo; addr != NULL; addr = addr->ai_next) {
|
||||
|
|
@ -778,8 +819,9 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
char *dot = strchr(utsname.nodename, '.');
|
||||
if (dot)
|
||||
if (dot) {
|
||||
*dot = 0;
|
||||
}
|
||||
|
||||
cfs.nodename = g_strdup(utsname.nodename);
|
||||
|
||||
|
|
@ -821,8 +863,9 @@ int main(int argc, char *argv[]) {
|
|||
cfs_critical("unable to acquire pmxcfs lock: %s", strerror(errno));
|
||||
goto err;
|
||||
}
|
||||
if (i == 10)
|
||||
if (i == 10) {
|
||||
cfs_message("unable to acquire pmxcfs lock - trying again");
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
|
@ -861,16 +904,18 @@ int main(int argc, char *argv[]) {
|
|||
cfs_message("forcing local mode (although corosync.conf exists)");
|
||||
cfs_set_quorate(1, TRUE);
|
||||
} else {
|
||||
if (!(dcdb = dcdb_new(memdb)))
|
||||
if (!(dcdb = dcdb_new(memdb))) {
|
||||
goto err;
|
||||
}
|
||||
dcdb_sync_corosync_conf(memdb, 1);
|
||||
}
|
||||
} else {
|
||||
cfs_debug("using local mode (corosync.conf does not exist)");
|
||||
cfs_set_quorate(1, TRUE);
|
||||
}
|
||||
if (conf_data)
|
||||
if (conf_data) {
|
||||
g_free(conf_data);
|
||||
}
|
||||
|
||||
cfs_plug_memdb_t *config = cfs_plug_memdb_new("memdb", memdb, dcdb);
|
||||
|
||||
|
|
@ -943,8 +988,9 @@ int main(int argc, char *argv[]) {
|
|||
dup2(nullfd, 0);
|
||||
dup2(nullfd, 1);
|
||||
dup2(nullfd, 2);
|
||||
if (nullfd > 2)
|
||||
if (nullfd > 2) {
|
||||
close(nullfd);
|
||||
}
|
||||
}
|
||||
|
||||
// do not print to the console after this point
|
||||
|
|
@ -1019,31 +1065,39 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
cfs_debug("worker finished");
|
||||
|
||||
if (service_dcdb)
|
||||
if (service_dcdb) {
|
||||
service_dfsm_destroy(service_dcdb);
|
||||
}
|
||||
|
||||
if (service_confdb)
|
||||
if (service_confdb) {
|
||||
service_confdb_destroy(service_confdb);
|
||||
}
|
||||
|
||||
if (service_quorum)
|
||||
if (service_quorum) {
|
||||
service_quorum_destroy(service_quorum);
|
||||
}
|
||||
|
||||
if (service_status)
|
||||
if (service_status) {
|
||||
service_dfsm_destroy(service_status);
|
||||
}
|
||||
|
||||
ret:
|
||||
|
||||
if (status_fsm)
|
||||
if (status_fsm) {
|
||||
dfsm_destroy(status_fsm);
|
||||
}
|
||||
|
||||
if (dcdb)
|
||||
if (dcdb) {
|
||||
dfsm_destroy(dcdb);
|
||||
}
|
||||
|
||||
if (memdb)
|
||||
if (memdb) {
|
||||
memdb_close(memdb);
|
||||
}
|
||||
|
||||
if (wrote_pidfile)
|
||||
if (wrote_pidfile) {
|
||||
unlink(CFS_PID_FN);
|
||||
}
|
||||
|
||||
cfs_message("exit proxmox configuration filesystem (%d)", ret);
|
||||
|
||||
|
|
|
|||
|
|
@ -165,13 +165,15 @@ loop:
|
|||
if (result == CS_ERR_TRY_AGAIN) {
|
||||
usleep(100000);
|
||||
++retries;
|
||||
if ((retries % 100) == 0)
|
||||
if ((retries % 100) == 0) {
|
||||
cfs_message("quorum_dispatch retry %d", retries);
|
||||
}
|
||||
goto loop;
|
||||
}
|
||||
|
||||
if (result == CS_OK || result == CS_ERR_TRY_AGAIN)
|
||||
if (result == CS_OK || result == CS_ERR_TRY_AGAIN) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
cfs_critical("quorum_dispatch failed: %d", result);
|
||||
|
||||
|
|
@ -191,8 +193,9 @@ cfs_service_t *service_quorum_new(void) {
|
|||
cfs_service_t *service;
|
||||
|
||||
qs_private_t *private = g_new0(qs_private_t, 1);
|
||||
if (!private)
|
||||
if (!private) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
service = cfs_service_new(&cfs_quorum_callbacks, G_LOG_DOMAIN, private);
|
||||
|
||||
|
|
|
|||
|
|
@ -141,8 +141,9 @@ static void s1_connection_destroyed_fn(qb_ipcs_connection_t *c) {
|
|||
cfs_debug("connection about to be freed");
|
||||
|
||||
gpointer ctx;
|
||||
if ((ctx = qb_ipcs_context_get(c)))
|
||||
if ((ctx = qb_ipcs_context_get(c))) {
|
||||
g_free(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t s1_connection_closed_fn(qb_ipcs_connection_t *c) {
|
||||
|
|
@ -519,8 +520,9 @@ static void timer_job(void *data) {
|
|||
if (terminate_server) {
|
||||
cfs_debug("got terminate request");
|
||||
|
||||
if (loop)
|
||||
if (loop) {
|
||||
qb_loop_stop(loop);
|
||||
}
|
||||
|
||||
if (s1) {
|
||||
qb_ipcs_destroy(s1);
|
||||
|
|
@ -538,8 +540,9 @@ static void timer_job(void *data) {
|
|||
|
||||
g_mutex_unlock(&server_started_mutex);
|
||||
|
||||
if (terminate)
|
||||
if (terminate) {
|
||||
return;
|
||||
}
|
||||
|
||||
qb_loop_timer_handle th;
|
||||
qb_loop_timer_add(loop, QB_LOOP_LOW, 1000000000, NULL, timer_job, &th);
|
||||
|
|
@ -589,8 +592,9 @@ gboolean server_start(memdb_t *db) {
|
|||
worker = g_thread_new("server", worker_thread, NULL);
|
||||
|
||||
g_mutex_lock(&server_started_mutex);
|
||||
while (!server_started)
|
||||
while (!server_started) {
|
||||
g_cond_wait(&server_started_cond, &server_started_mutex);
|
||||
}
|
||||
g_mutex_unlock(&server_started_mutex);
|
||||
|
||||
cfs_debug("server started");
|
||||
|
|
@ -603,8 +607,9 @@ void server_stop(void) {
|
|||
|
||||
g_mutex_lock(&server_started_mutex);
|
||||
terminate_server = 1;
|
||||
while (server_started)
|
||||
while (server_started) {
|
||||
g_cond_wait(&server_stopped_cond, &server_started_mutex);
|
||||
}
|
||||
g_mutex_unlock(&server_started_mutex);
|
||||
|
||||
if (worker) {
|
||||
|
|
|
|||
|
|
@ -171,8 +171,9 @@ static gboolean g_int32_equal(gconstpointer v1, gconstpointer v2) {
|
|||
static void vminfo_free(vminfo_t *vminfo) {
|
||||
g_return_if_fail(vminfo != NULL);
|
||||
|
||||
if (vminfo->nodename)
|
||||
if (vminfo->nodename) {
|
||||
g_free(vminfo->nodename);
|
||||
}
|
||||
|
||||
g_free(vminfo);
|
||||
}
|
||||
|
|
@ -202,8 +203,9 @@ int vminfo_to_path(vminfo_t *vminfo, GString *path) {
|
|||
g_return_val_if_fail(vminfo != NULL, -1);
|
||||
g_return_val_if_fail(path != NULL, -1);
|
||||
|
||||
if (!vminfo->nodename)
|
||||
if (!vminfo->nodename) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *type = vminfo_type_to_path_type(vminfo);
|
||||
g_string_printf(path, "/nodes/%s/%s/%u.conf", vminfo->nodename, type, vminfo->vmid);
|
||||
|
|
@ -214,11 +216,13 @@ int vminfo_to_path(vminfo_t *vminfo, GString *path) {
|
|||
void cfs_clnode_destroy(cfs_clnode_t *clnode) {
|
||||
g_return_if_fail(clnode != NULL);
|
||||
|
||||
if (clnode->kvhash)
|
||||
if (clnode->kvhash) {
|
||||
g_hash_table_destroy(clnode->kvhash);
|
||||
}
|
||||
|
||||
if (clnode->name)
|
||||
if (clnode->name) {
|
||||
g_free(clnode->name);
|
||||
}
|
||||
|
||||
g_free(clnode);
|
||||
}
|
||||
|
|
@ -227,8 +231,9 @@ cfs_clnode_t *cfs_clnode_new(const char *name, uint32_t nodeid, uint32_t votes)
|
|||
g_return_val_if_fail(name != NULL, NULL);
|
||||
|
||||
cfs_clnode_t *clnode = g_new0(cfs_clnode_t, 1);
|
||||
if (!clnode)
|
||||
if (!clnode) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
clnode->name = g_strdup(name);
|
||||
clnode->nodeid = nodeid;
|
||||
|
|
@ -240,14 +245,17 @@ cfs_clnode_t *cfs_clnode_new(const char *name, uint32_t nodeid, uint32_t votes)
|
|||
gboolean cfs_clinfo_destroy(cfs_clinfo_t *clinfo) {
|
||||
g_return_val_if_fail(clinfo != NULL, FALSE);
|
||||
|
||||
if (clinfo->cluster_name)
|
||||
if (clinfo->cluster_name) {
|
||||
g_free(clinfo->cluster_name);
|
||||
}
|
||||
|
||||
if (clinfo->nodes_byname)
|
||||
if (clinfo->nodes_byname) {
|
||||
g_hash_table_destroy(clinfo->nodes_byname);
|
||||
}
|
||||
|
||||
if (clinfo->nodes_byid)
|
||||
if (clinfo->nodes_byid) {
|
||||
g_hash_table_destroy(clinfo->nodes_byid);
|
||||
}
|
||||
|
||||
g_free(clinfo);
|
||||
|
||||
|
|
@ -258,19 +266,22 @@ cfs_clinfo_t *cfs_clinfo_new(const char *cluster_name, uint32_t cman_version) {
|
|||
g_return_val_if_fail(cluster_name != NULL, NULL);
|
||||
|
||||
cfs_clinfo_t *clinfo = g_new0(cfs_clinfo_t, 1);
|
||||
if (!clinfo)
|
||||
if (!clinfo) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
clinfo->cluster_name = g_strdup(cluster_name);
|
||||
clinfo->cman_version = cman_version;
|
||||
|
||||
if (!(clinfo->nodes_byid = g_hash_table_new_full(
|
||||
g_int32_hash, g_int32_equal, NULL, (GDestroyNotify)cfs_clnode_destroy
|
||||
)))
|
||||
))) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!(clinfo->nodes_byname = g_hash_table_new(g_str_hash, g_str_equal)))
|
||||
if (!(clinfo->nodes_byname = g_hash_table_new(g_str_hash, g_str_equal))) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return clinfo;
|
||||
|
||||
|
|
@ -301,8 +312,9 @@ int cfs_create_memberlist_msg(GString *str) {
|
|||
|
||||
cfs_clinfo_t *clinfo = cfs_status.clinfo;
|
||||
|
||||
if (clinfo && clinfo->nodes_byid)
|
||||
if (clinfo && clinfo->nodes_byid) {
|
||||
nodecount = g_hash_table_size(clinfo->nodes_byid);
|
||||
}
|
||||
|
||||
if (nodecount) {
|
||||
g_string_append_printf(str, "\"nodename\": \"%s\",\n", cfs.nodename);
|
||||
|
|
@ -328,8 +340,9 @@ int cfs_create_memberlist_msg(GString *str) {
|
|||
int i = 0;
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
cfs_clnode_t *node = (cfs_clnode_t *)value;
|
||||
if (i)
|
||||
if (i) {
|
||||
g_string_append_printf(str, ",\n");
|
||||
}
|
||||
i++;
|
||||
|
||||
g_string_append_printf(
|
||||
|
|
@ -395,8 +408,9 @@ void cfs_cluster_log(clog_entry_t *entry) {
|
|||
iov[0].iov_base = (char *)entry;
|
||||
iov[0].iov_len = clog_entry_size(entry);
|
||||
|
||||
if (dfsm_is_initialized(cfs_status.kvstore))
|
||||
if (dfsm_is_initialized(cfs_status.kvstore)) {
|
||||
dfsm_send_message(cfs_status.kvstore, KVSTORE_MESSAGE_LOG, iov, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -461,8 +475,9 @@ void cfs_status_cleanup(void) {
|
|||
cfs_status.iphash = NULL;
|
||||
}
|
||||
|
||||
if (cfs_status.clusterlog)
|
||||
if (cfs_status.clusterlog) {
|
||||
clusterlog_destroy(cfs_status.clusterlog);
|
||||
}
|
||||
|
||||
g_mutex_unlock(&mutex);
|
||||
}
|
||||
|
|
@ -502,8 +517,9 @@ void cfs_status_set_clinfo(cfs_clinfo_t *clinfo) {
|
|||
}
|
||||
}
|
||||
|
||||
if (old)
|
||||
if (old) {
|
||||
cfs_clinfo_destroy(old);
|
||||
}
|
||||
|
||||
g_mutex_unlock(&mutex);
|
||||
}
|
||||
|
|
@ -524,8 +540,9 @@ static void dump_kvstore_versions(GString *str, GHashTable *kvhash, const char *
|
|||
int i = 0;
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
kventry_t *entry = (kventry_t *)value;
|
||||
if (i)
|
||||
if (i) {
|
||||
g_string_append_printf(str, ",\n");
|
||||
}
|
||||
i++;
|
||||
g_string_append_printf(str, "\"%s\": %u", entry->key, entry->version);
|
||||
}
|
||||
|
|
@ -567,8 +584,9 @@ int cfs_create_version_msg(GString *str) {
|
|||
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
cfs_clnode_t *node = (cfs_clnode_t *)value;
|
||||
if (!node->kvhash)
|
||||
if (!node->kvhash) {
|
||||
continue;
|
||||
}
|
||||
g_string_append_printf(str, ",\n");
|
||||
dump_kvstore_versions(str, node->kvhash, node->name);
|
||||
}
|
||||
|
|
@ -644,8 +662,9 @@ gboolean vmlist_different_vm_exists(int vmtype, guint32 vmid, const char *nodena
|
|||
|
||||
vminfo_t *vminfo;
|
||||
if ((vminfo = (vminfo_t *)g_hash_table_lookup(cfs_status.vmlist, &vmid))) {
|
||||
if (!(vminfo->vmtype == vmtype && strcmp(vminfo->nodename, nodename) == 0))
|
||||
if (!(vminfo->vmtype == vmtype && strcmp(vminfo->nodename, nodename) == 0)) {
|
||||
res = TRUE;
|
||||
}
|
||||
}
|
||||
g_mutex_unlock(&mutex);
|
||||
|
||||
|
|
@ -685,8 +704,9 @@ void cfs_status_set_vmlist(GHashTable *vmlist) {
|
|||
|
||||
cfs_status.vmlist_version++;
|
||||
|
||||
if (cfs_status.vmlist)
|
||||
if (cfs_status.vmlist) {
|
||||
g_hash_table_destroy(cfs_status.vmlist);
|
||||
}
|
||||
|
||||
cfs_status.vmlist = vmlist;
|
||||
|
||||
|
|
@ -722,8 +742,9 @@ int cfs_create_vmlist_msg(GString *str) {
|
|||
vminfo_t *vminfo = (vminfo_t *)value;
|
||||
const char *type = vminfo_type_to_string(vminfo);
|
||||
|
||||
if (!first)
|
||||
if (!first) {
|
||||
g_string_append_printf(str, ",\n");
|
||||
}
|
||||
first = 0;
|
||||
|
||||
g_string_append_printf(
|
||||
|
|
@ -746,22 +767,26 @@ int cfs_create_vmlist_msg(GString *str) {
|
|||
// note: line[line_end] needs to be guaranteed a null byte
|
||||
char *
|
||||
_get_property_value_from_line(char *line, size_t line_len, const char *prop, size_t prop_len) {
|
||||
if (line_len <= prop_len + 1)
|
||||
if (line_len <= prop_len + 1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (line[prop_len] == ':' && memcmp(line, prop, prop_len) == 0) { // found
|
||||
char *v_start = &line[prop_len + 1];
|
||||
char *v_end = &line[line_len - 1];
|
||||
|
||||
// drop initial value whitespaces here already
|
||||
while (v_start < v_end && *v_start && isspace(*v_start))
|
||||
while (v_start < v_end && *v_start && isspace(*v_start)) {
|
||||
v_start++;
|
||||
}
|
||||
|
||||
if (!*v_start)
|
||||
if (!*v_start) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (v_end > v_start && isspace(*v_end))
|
||||
while (v_end > v_start && isspace(*v_end)) {
|
||||
v_end--;
|
||||
}
|
||||
if (v_end < &line[line_len - 1]) {
|
||||
v_end[1] = '\0';
|
||||
}
|
||||
|
|
@ -811,15 +836,18 @@ void _get_property_values(
|
|||
*next_newline = '\0';
|
||||
|
||||
while (line != NULL) {
|
||||
if (!line[0])
|
||||
if (!line[0]) {
|
||||
goto next;
|
||||
}
|
||||
|
||||
// snapshot or pending section start, but nothing found yet -> not found
|
||||
if (line[0] == '[')
|
||||
if (line[0] == '[') {
|
||||
return;
|
||||
}
|
||||
// continue early if line does not begin with the min/max char of the properties
|
||||
if (line[0] < min || line[0] > max)
|
||||
if (line[0] < min || line[0] > max) {
|
||||
goto next;
|
||||
}
|
||||
|
||||
size_t line_len = next_newline - line;
|
||||
for (uint8_t i = 0; i < num_props; i++) {
|
||||
|
|
@ -940,22 +968,26 @@ int cfs_create_guest_conf_properties_msg(
|
|||
|
||||
if (vmid >= 100) {
|
||||
vminfo_t *vminfo = (vminfo_t *)g_hash_table_lookup(cfs_status.vmlist, &vmid);
|
||||
if (vminfo == NULL)
|
||||
if (vminfo == NULL) {
|
||||
goto enoent;
|
||||
}
|
||||
|
||||
if (!vminfo_to_path(vminfo, path))
|
||||
if (!vminfo_to_path(vminfo, path)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// use memdb_read_nolock because lock is handled here
|
||||
int size = memdb_read_nolock(memdb, path->str, &tmp);
|
||||
if (tmp == NULL)
|
||||
if (tmp == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// conf needs to be newline terminated
|
||||
if (((char *)tmp)[size - 1] != '\n') {
|
||||
gpointer new = realloc(tmp, size + 1);
|
||||
if (new == NULL)
|
||||
if (new == NULL) {
|
||||
goto err;
|
||||
}
|
||||
tmp = new;
|
||||
((char *)tmp)[size++] = '\n';
|
||||
}
|
||||
|
|
@ -969,21 +1001,24 @@ int cfs_create_guest_conf_properties_msg(
|
|||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
vminfo_t *vminfo = (vminfo_t *)value;
|
||||
|
||||
if (!vminfo_to_path(vminfo, path))
|
||||
if (!vminfo_to_path(vminfo, path)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
g_free(tmp); // no-op if already null
|
||||
tmp = NULL;
|
||||
// use memdb_read_nolock because lock is handled here
|
||||
int size = memdb_read_nolock(memdb, path->str, &tmp);
|
||||
if (tmp == NULL)
|
||||
if (tmp == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// conf needs to be newline terminated
|
||||
if (((char *)tmp)[size - 1] != '\n') {
|
||||
gpointer new = realloc(tmp, size + 1);
|
||||
if (new == NULL)
|
||||
if (new == NULL) {
|
||||
continue;
|
||||
}
|
||||
tmp = new;
|
||||
((char *)tmp)[size++] = '\n';
|
||||
}
|
||||
|
|
@ -1153,8 +1188,9 @@ static void create_rrd_file(const char *filename, int argcount, const char *rrdd
|
|||
static inline const char *rrd_skip_data(const char *data, int count) {
|
||||
int found = 0;
|
||||
while (*data && found < count) {
|
||||
if (*data++ == ':')
|
||||
if (*data++ == ':') {
|
||||
found++;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
|
@ -1168,8 +1204,9 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
|
|||
static const char *rrdcsock = "unix:/var/run/rrdcached.sock";
|
||||
|
||||
int use_daemon = 1;
|
||||
if (rrdc_connect(rrdcsock) != 0)
|
||||
if (rrdc_connect(rrdcsock) != 0) {
|
||||
use_daemon = 0;
|
||||
}
|
||||
|
||||
char *filename = NULL;
|
||||
|
||||
|
|
@ -1180,11 +1217,13 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
|
|||
|
||||
skip = 2;
|
||||
|
||||
if (strchr(node, '/') != NULL)
|
||||
if (strchr(node, '/') != NULL) {
|
||||
goto keyerror;
|
||||
}
|
||||
|
||||
if (strlen(node) < 1)
|
||||
if (strlen(node) < 1) {
|
||||
goto keyerror;
|
||||
}
|
||||
|
||||
filename = g_strdup_printf(RRDDIR "/%s", key);
|
||||
|
||||
|
|
@ -1206,11 +1245,13 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
|
|||
skip = 4;
|
||||
}
|
||||
|
||||
if (strchr(vmid, '/') != NULL)
|
||||
if (strchr(vmid, '/') != NULL) {
|
||||
goto keyerror;
|
||||
}
|
||||
|
||||
if (strlen(vmid) < 1)
|
||||
if (strlen(vmid) < 1) {
|
||||
goto keyerror;
|
||||
}
|
||||
|
||||
filename = g_strdup_printf(RRDDIR "/%s/%s", "pve2-vm", vmid);
|
||||
|
||||
|
|
@ -1225,19 +1266,23 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
|
|||
const char *node = key + 13;
|
||||
|
||||
const char *storage = node;
|
||||
while (*storage && *storage != '/')
|
||||
while (*storage && *storage != '/') {
|
||||
storage++;
|
||||
}
|
||||
|
||||
if (*storage != '/' || ((storage - node) < 1))
|
||||
if (*storage != '/' || ((storage - node) < 1)) {
|
||||
goto keyerror;
|
||||
}
|
||||
|
||||
storage++;
|
||||
|
||||
if (strchr(storage, '/') != NULL)
|
||||
if (strchr(storage, '/') != NULL) {
|
||||
goto keyerror;
|
||||
}
|
||||
|
||||
if (strlen(storage) < 1)
|
||||
if (strlen(storage) < 1) {
|
||||
goto keyerror;
|
||||
}
|
||||
|
||||
filename = g_strdup_printf(RRDDIR "/%s", key);
|
||||
|
||||
|
|
@ -1280,8 +1325,9 @@ static void update_rrd_data(const char *key, gconstpointer data, size_t len) {
|
|||
}
|
||||
|
||||
ret:
|
||||
if (filename)
|
||||
if (filename) {
|
||||
g_free(filename);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
|
|
@ -1338,8 +1384,9 @@ void cfs_rrd_dump(GString *str) {
|
|||
g_string_append_c(str, 0); // never return undef
|
||||
|
||||
rrd_dump_last = ctime;
|
||||
if (rrd_dump_buf)
|
||||
if (rrd_dump_buf) {
|
||||
g_free(rrd_dump_buf);
|
||||
}
|
||||
rrd_dump_buf = g_strdup(str->str);
|
||||
|
||||
g_mutex_unlock(&mutex);
|
||||
|
|
@ -1396,8 +1443,9 @@ rrdentry_hash_set(GHashTable *rrdhash, const char *key, const char *data, size_t
|
|||
}
|
||||
|
||||
static int kvstore_send_update_message(dfsm_t *dfsm, const char *key, gpointer data, guint32 len) {
|
||||
if (!dfsm_is_initialized(dfsm))
|
||||
if (!dfsm_is_initialized(dfsm)) {
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
struct iovec iov[2];
|
||||
|
||||
|
|
@ -1410,8 +1458,9 @@ static int kvstore_send_update_message(dfsm_t *dfsm, const char *key, gpointer d
|
|||
iov[1].iov_base = (char *)data;
|
||||
iov[1].iov_len = len;
|
||||
|
||||
if (dfsm_send_message(dfsm, KVSTORE_MESSAGE_UPDATE, iov, 2) == CS_OK)
|
||||
if (dfsm_send_message(dfsm, KVSTORE_MESSAGE_UPDATE, iov, 2) == CS_OK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -EACCES;
|
||||
}
|
||||
|
|
@ -1477,12 +1526,15 @@ static gboolean kvstore_parse_update_message(
|
|||
|
||||
/* test if key is null terminated */
|
||||
int i = 0;
|
||||
for (i = 0; i < 256; i++)
|
||||
if (((char *)msg)[i] == 0)
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (((char *)msg)[i] == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 256)
|
||||
if (i == 256) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*len = msg_len - 256;
|
||||
*key = msg;
|
||||
|
|
@ -1505,8 +1557,9 @@ int cfs_create_status_msg(GString *str, const char *nodename, const char *key) {
|
|||
kvhash = cfs_status.kvhash;
|
||||
} else if (cfs_status.clinfo && cfs_status.clinfo->nodes_byname) {
|
||||
cfs_clnode_t *clnode;
|
||||
if ((clnode = g_hash_table_lookup(cfs_status.clinfo->nodes_byname, nodename)))
|
||||
if ((clnode = g_hash_table_lookup(cfs_status.clinfo->nodes_byname, nodename))) {
|
||||
kvhash = clnode->kvhash;
|
||||
}
|
||||
}
|
||||
|
||||
kventry_t *entry;
|
||||
|
|
@ -1525,8 +1578,9 @@ int cfs_status_set(const char *key, gpointer data, size_t len) {
|
|||
g_return_val_if_fail(data != NULL, FALSE);
|
||||
g_return_val_if_fail(cfs_status.kvhash != NULL, FALSE);
|
||||
|
||||
if (len > CFS_MAX_STATUS_SIZE)
|
||||
if (len > CFS_MAX_STATUS_SIZE) {
|
||||
return -EFBIG;
|
||||
}
|
||||
|
||||
g_mutex_lock(&mutex);
|
||||
|
||||
|
|
@ -1541,8 +1595,9 @@ int cfs_status_set(const char *key, gpointer data, size_t len) {
|
|||
}
|
||||
g_mutex_unlock(&mutex);
|
||||
|
||||
if (cfs_status.kvstore)
|
||||
if (cfs_status.kvstore) {
|
||||
kvstore_send_update_message(cfs_status.kvstore, key, data, len);
|
||||
}
|
||||
|
||||
return res ? 0 : -ENOMEM;
|
||||
}
|
||||
|
|
@ -1554,12 +1609,14 @@ gboolean cfs_kvstore_node_set(uint32_t nodeid, const char *key, gconstpointer da
|
|||
|
||||
g_mutex_lock(&mutex);
|
||||
|
||||
if (!cfs_status.clinfo || !cfs_status.clinfo->nodes_byid)
|
||||
if (!cfs_status.clinfo || !cfs_status.clinfo->nodes_byid) {
|
||||
goto ret; /* ignore */
|
||||
}
|
||||
|
||||
cfs_clnode_t *clnode = g_hash_table_lookup(cfs_status.clinfo->nodes_byid, &nodeid);
|
||||
if (!clnode)
|
||||
if (!clnode) {
|
||||
goto ret; /* ignore */
|
||||
}
|
||||
|
||||
cfs_debug("got node %d status update %s", nodeid, key);
|
||||
|
||||
|
|
@ -1622,8 +1679,9 @@ static int dfsm_deliver(
|
|||
g_return_val_if_fail(res_ptr != NULL, -1);
|
||||
|
||||
/* ignore message for ourself */
|
||||
if (dfsm_nodeid_is_local(dfsm, nodeid, pid))
|
||||
if (dfsm_nodeid_is_local(dfsm, nodeid, pid)) {
|
||||
goto ret;
|
||||
}
|
||||
|
||||
if (msg_type == KVSTORE_MESSAGE_UPDATE) {
|
||||
const char *key;
|
||||
|
|
@ -1727,8 +1785,9 @@ static int dfsm_process_state_update(dfsm_t *dfsm, gpointer data, dfsm_sync_info
|
|||
dfsm_node_info_t *ni = &syncinfo->nodes[i];
|
||||
ni->synced = 1;
|
||||
|
||||
if (syncinfo->local == ni)
|
||||
if (syncinfo->local == ni) {
|
||||
local_index = i;
|
||||
}
|
||||
|
||||
clog_base_t *base = (clog_base_t *)ni->state;
|
||||
if (ni->state_len > 8 && ni->state_len == clog_size(base)) {
|
||||
|
|
@ -1759,8 +1818,9 @@ static void dfsm_synced(dfsm_t *dfsm) {
|
|||
g_return_if_fail(dfsm != NULL);
|
||||
|
||||
char *ip = (char *)g_hash_table_lookup(cfs_status.iphash, cfs.nodename);
|
||||
if (!ip)
|
||||
if (!ip) {
|
||||
ip = cfs.ip;
|
||||
}
|
||||
|
||||
cfs_status_set("nodeip", ip, strlen(ip) + 1);
|
||||
}
|
||||
|
|
@ -1804,13 +1864,15 @@ void cfs_set_quorate(uint32_t quorate, gboolean quiet) {
|
|||
cfs_status.quorate = quorate;
|
||||
|
||||
if (!prev_quorate && cfs_status.quorate) {
|
||||
if (!quiet)
|
||||
if (!quiet) {
|
||||
cfs_message("node has quorum");
|
||||
}
|
||||
}
|
||||
|
||||
if (prev_quorate && !cfs_status.quorate) {
|
||||
if (!quiet)
|
||||
if (!quiet) {
|
||||
cfs_message("node lost quorum");
|
||||
}
|
||||
}
|
||||
|
||||
g_mutex_unlock(&mutex);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue