Commit a4b9314f authored by Daniel Salzman's avatar Daniel Salzman

knot: make transaction error codes more general

parent d9455d89
......@@ -60,15 +60,15 @@ int conf_io_begin(
assert(conf() != NULL);
if (conf()->io.txn != NULL && !child) {
return KNOT_CONF_ETXN;
return KNOT_TXN_EEXISTS;
} else if (conf()->io.txn == NULL && child) {
return KNOT_CONF_ENOTXN;
return KNOT_TXN_ENOTEXISTS;
}
knot_db_txn_t *parent = conf()->io.txn;
knot_db_txn_t *txn = (parent == NULL) ? conf()->io.txn_stack : parent + 1;
if (txn >= conf()->io.txn_stack + CONF_MAX_TXN_DEPTH) {
return KNOT_CONF_EMANYTXN;
return KNOT_TXN_EEXISTS;
}
// Start the writing transaction.
......@@ -89,7 +89,7 @@ int conf_io_commit(
if (conf()->io.txn == NULL ||
(child && conf()->io.txn == conf()->io.txn_stack)) {
return KNOT_CONF_ENOTXN;
return KNOT_TXN_ENOTEXISTS;
}
knot_db_txn_t *txn = child ? conf()->io.txn : conf()->io.txn_stack;
......@@ -347,7 +347,7 @@ int conf_io_diff(
assert(conf() != NULL);
if (conf()->io.txn == NULL) {
return KNOT_CONF_ENOTXN;
return KNOT_TXN_ENOTEXISTS;
}
// Compare all sections by default.
......@@ -604,7 +604,7 @@ int conf_io_get(
assert(conf() != NULL);
if (conf()->io.txn == NULL && !get_current) {
return KNOT_CONF_ENOTXN;
return KNOT_TXN_ENOTEXISTS;
}
// List all sections by default.
......@@ -759,7 +759,7 @@ int conf_io_set(
assert(conf() != NULL);
if (conf()->io.txn == NULL) {
return KNOT_CONF_ENOTXN;
return KNOT_TXN_ENOTEXISTS;
}
// At least key0 must be specified.
......@@ -926,7 +926,7 @@ int conf_io_unset(
assert(conf() != NULL);
if (conf()->io.txn == NULL) {
return KNOT_CONF_ENOTXN;
return KNOT_TXN_ENOTEXISTS;
}
// Delete all sections by default.
......@@ -1181,7 +1181,7 @@ int conf_io_check(
assert(conf() != NULL);
if (conf()->io.txn == NULL) {
return KNOT_CONF_ENOTXN;
return KNOT_TXN_ENOTEXISTS;
}
int ret;
......
......@@ -516,7 +516,7 @@ int server_reload(server_t *server, const char *cf, bool refresh_hostname)
// Check for no edit mode.
if (conf()->io.txn != NULL) {
log_warning("reload aborted due to active configuration transaction");
return KNOT_CONF_ETXN;
return KNOT_TXN_EEXISTS;
}
conf_t *new_conf = NULL;
......
......@@ -90,8 +90,6 @@ enum knot_error {
/* Control states. */
KNOT_CTL_ESTOP,
KNOT_CTL_EACCEPTED,
KNOT_CTL_EARG_REQ,
/* Network errors. */
KNOT_NET_EADDR,
......@@ -137,9 +135,10 @@ enum knot_error {
KNOT_CONF_ENOTINIT,
KNOT_CONF_EVERSION,
KNOT_CONF_EREDEFINE,
KNOT_CONF_ETXN,
KNOT_CONF_ENOTXN,
KNOT_CONF_EMANYTXN,
/* Transaction errors. */
KNOT_TXN_EEXISTS,
KNOT_TXN_ENOTEXISTS,
/* Processing error. */
KNOT_LAYER_ERROR,
......
......@@ -89,8 +89,6 @@ static const struct error errors[] = {
/* Control states. */
{ KNOT_CTL_ESTOP, "stopping server" },
{ KNOT_CTL_EACCEPTED, "command accepted" },
{ KNOT_CTL_EARG_REQ, "argument required" },
/* Network errors. */
{ KNOT_NET_EADDR, "bad address or host name" },
......@@ -136,9 +134,10 @@ static const struct error errors[] = {
{ KNOT_CONF_ENOTINIT, "config DB not initialized" },
{ KNOT_CONF_EVERSION, "invalid config DB version" },
{ KNOT_CONF_EREDEFINE, "duplicate identifier" },
{ KNOT_CONF_ETXN, "failed to open another config DB transaction" },
{ KNOT_CONF_ENOTXN, "no active config DB transaction" },
{ KNOT_CONF_EMANYTXN, "too many nested config DB transactions" },
/* Transaction errors. */
{ KNOT_TXN_EEXISTS, "too many transactions" },
{ KNOT_TXN_ENOTEXISTS, "no active transaction" },
/* Processing errors. */
{ KNOT_LAYER_ERROR, "processing layer error" },
......
......@@ -177,7 +177,7 @@ static int format_item(conf_io_t *io)
static void test_conf_io_begin()
{
ok(conf_io_begin(true) == KNOT_CONF_ENOTXN, "begin child txn with no parent");
ok(conf_io_begin(true) == KNOT_TXN_ENOTEXISTS, "begin child txn with no parent");
ok(conf()->io.txn == NULL, "check txn depth");
#if defined(__OpenBSD__)
......@@ -186,14 +186,14 @@ static void test_conf_io_begin()
ok(conf_io_begin(false) == KNOT_EOK, "begin parent txn");
ok(conf()->io.txn == &(conf()->io.txn_stack[0]), "check txn depth");
ok(conf_io_begin(false) == KNOT_CONF_ETXN, "begin another parent txn");
ok(conf_io_begin(false) == KNOT_TXN_EEXISTS, "begin another parent txn");
ok(conf()->io.txn == &(conf()->io.txn_stack[0]), "check txn depth");
for (int i = 1; i < CONF_MAX_TXN_DEPTH; i++) {
ok(conf_io_begin(true) == KNOT_EOK, "begin child txn");
ok(conf()->io.txn == &(conf()->io.txn_stack[i]), "check txn depth");
}
ok(conf_io_begin(true) == KNOT_CONF_EMANYTXN, "begin another child txn");
ok(conf_io_begin(true) == KNOT_TXN_EEXISTS, "begin another child txn");
ok(conf()->io.txn == &(conf()->io.txn_stack[CONF_MAX_TXN_DEPTH - 1]),
"check txn depth");
......@@ -259,8 +259,8 @@ static void test_conf_io_abort()
static void test_conf_io_commit()
{
ok(conf_io_commit(false) == KNOT_CONF_ENOTXN, "commit no txt txn");
ok(conf_io_commit(true) == KNOT_CONF_ENOTXN, "commit no txt txn");
ok(conf_io_commit(false) == KNOT_TXN_ENOTEXISTS, "commit no txt txn");
ok(conf_io_commit(true) == KNOT_TXN_ENOTEXISTS, "commit no txt txn");
#if defined(__OpenBSD__)
SKIP_OPENBSD
......@@ -314,7 +314,7 @@ static void test_conf_io_check()
// ERR no txn.
ok(conf_io_check(&io) ==
KNOT_CONF_ENOTXN, "check without active txn");
KNOT_TXN_ENOTEXISTS, "check without active txn");
ok(conf_io_begin(false) == KNOT_EOK, "begin txn");
......@@ -356,7 +356,7 @@ static void test_conf_io_set()
// ERR no txn.
ok(conf_io_set("server", "version", NULL, "text", &io) ==
KNOT_CONF_ENOTXN, "set without active txn");
KNOT_TXN_ENOTEXISTS, "set without active txn");
ok(conf_io_begin(false) == KNOT_EOK, "begin txn");
......@@ -454,7 +454,7 @@ static void test_conf_io_unset()
{
// ERR no txn.
ok(conf_io_unset("server", "version", NULL, "text") ==
KNOT_CONF_ENOTXN, "unset without active txn");
KNOT_TXN_ENOTEXISTS, "unset without active txn");
ok(conf_io_begin(false) == KNOT_EOK, "begin txn");
......@@ -645,7 +645,7 @@ static void test_conf_io_get()
// ERR no txn.
ok(conf_io_get("server", "version", NULL, false, &io) ==
KNOT_CONF_ENOTXN, "get without active txn");
KNOT_TXN_ENOTEXISTS, "get without active txn");
// Get current, no active txn.
*out = '\0';
......@@ -773,7 +773,7 @@ static void test_conf_io_diff()
// ERR no txn.
ok(conf_io_diff("server", "version", NULL, &io) ==
KNOT_CONF_ENOTXN, "diff without active txn");
KNOT_TXN_ENOTEXISTS, "diff without active txn");
ok(conf_io_begin(false) == KNOT_EOK, "begin txn");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment