Skip to content
Snippets Groups Projects
Commit c73d4825 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

ctl: add zone-purge operation

parent 2dceb631
No related branches found
No related tags found
No related merge requests found
...@@ -134,6 +134,9 @@ requires a ttl value specified. ...@@ -134,6 +134,9 @@ requires a ttl value specified.
\fBzone\-unset\fP \fIzone\fP \fIowner\fP [\fItype\fP [\fIrdata\fP]] \fBzone\-unset\fP \fIzone\fP \fIowner\fP [\fItype\fP [\fIrdata\fP]]
Remove zone data within the transaction. Remove zone data within the transaction.
.TP .TP
\fBzone\-purge\fP \fIzone\fP\&...
Purge zone data, zone file, and zone journal.
.TP
\fBconf\-init\fP \fBconf\-init\fP
Initialize the configuration database. (*) Initialize the configuration database. (*)
.TP .TP
......
...@@ -111,6 +111,9 @@ Actions ...@@ -111,6 +111,9 @@ Actions
**zone-unset** *zone* *owner* [*type* [*rdata*]] **zone-unset** *zone* *owner* [*type* [*rdata*]]
Remove zone data within the transaction. Remove zone data within the transaction.
**zone-purge** *zone*...
Purge zone data, zone file, and zone journal.
**conf-init** **conf-init**
Initialize the configuration database. (*) Initialize the configuration database. (*)
......
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
*/ */
#include <string.h> #include <string.h>
#include <unistd.h>
#include <urcu.h> #include <urcu.h>
#include "knot/common/log.h" #include "knot/common/log.h"
#include "knot/conf/confio.h" #include "knot/conf/confio.h"
#include "knot/ctl/commands.h" #include "knot/ctl/commands.h"
#include "knot/events/handlers.h"
#include "knot/updates/zone-update.h" #include "knot/updates/zone-update.h"
#include "libknot/libknot.h" #include "libknot/libknot.h"
#include "libknot/yparser/yptrafo.h" #include "libknot/yparser/yptrafo.h"
...@@ -903,6 +905,31 @@ static int zone_txn_unset(zone_t *zone, ctl_args_t *args) ...@@ -903,6 +905,31 @@ static int zone_txn_unset(zone_t *zone, ctl_args_t *args)
} }
static int zone_purge(zone_t *zone, ctl_args_t *args)
{
UNUSED(args);
// Abort possible editing transaction.
(void)zone_txn_abort(zone, args);
// Expire the zone.
event_expire(conf(), zone);
// Purge the zone file.
char *zonefile = conf_zonefile(conf(), zone->name);
(void)unlink(zonefile);
free(zonefile);
// Purge the zone journal.
char *journalfile = conf_journalfile(conf(), zone->name);
(void)unlink(journalfile);
free(journalfile);
// TODO: Purge the zone timers (after zone events refactoring).
return KNOT_EOK;
}
static int ctl_zone(ctl_args_t *args, ctl_cmd_t cmd) static int ctl_zone(ctl_args_t *args, ctl_cmd_t cmd)
{ {
switch (cmd) { switch (cmd) {
...@@ -934,6 +961,8 @@ static int ctl_zone(ctl_args_t *args, ctl_cmd_t cmd) ...@@ -934,6 +961,8 @@ static int ctl_zone(ctl_args_t *args, ctl_cmd_t cmd)
return zones_apply(args, zone_txn_set); return zones_apply(args, zone_txn_set);
case CTL_ZONE_UNSET: case CTL_ZONE_UNSET:
return zones_apply(args, zone_txn_unset); return zones_apply(args, zone_txn_unset);
case CTL_ZONE_PURGE:
return zones_apply(args, zone_purge);
default: default:
assert(0); assert(0);
return KNOT_EINVAL; return KNOT_EINVAL;
...@@ -1249,6 +1278,7 @@ static const desc_t cmd_table[] = { ...@@ -1249,6 +1278,7 @@ static const desc_t cmd_table[] = {
[CTL_ZONE_GET] = { "zone-get", ctl_zone }, [CTL_ZONE_GET] = { "zone-get", ctl_zone },
[CTL_ZONE_SET] = { "zone-set", ctl_zone }, [CTL_ZONE_SET] = { "zone-set", ctl_zone },
[CTL_ZONE_UNSET] = { "zone-unset", ctl_zone }, [CTL_ZONE_UNSET] = { "zone-unset", ctl_zone },
[CTL_ZONE_PURGE] = { "zone-purge", ctl_zone },
[CTL_CONF_LIST] = { "conf-list", ctl_conf_read }, [CTL_CONF_LIST] = { "conf-list", ctl_conf_read },
[CTL_CONF_READ] = { "conf-read", ctl_conf_read }, [CTL_CONF_READ] = { "conf-read", ctl_conf_read },
......
...@@ -54,6 +54,7 @@ typedef enum { ...@@ -54,6 +54,7 @@ typedef enum {
CTL_ZONE_GET, CTL_ZONE_GET,
CTL_ZONE_SET, CTL_ZONE_SET,
CTL_ZONE_UNSET, CTL_ZONE_UNSET,
CTL_ZONE_PURGE,
CTL_CONF_LIST, CTL_CONF_LIST,
CTL_CONF_READ, CTL_CONF_READ,
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#define CMD_ZONE_GET "zone-get" #define CMD_ZONE_GET "zone-get"
#define CMD_ZONE_SET "zone-set" #define CMD_ZONE_SET "zone-set"
#define CMD_ZONE_UNSET "zone-unset" #define CMD_ZONE_UNSET "zone-unset"
#define CMD_ZONE_PURGE "zone-purge"
#define CMD_CONF_INIT "conf-init" #define CMD_CONF_INIT "conf-init"
#define CMD_CONF_CHECK "conf-check" #define CMD_CONF_CHECK "conf-check"
...@@ -219,6 +220,7 @@ static void format_data(ctl_cmd_t cmd, knot_ctl_type_t data_type, ...@@ -219,6 +220,7 @@ static void format_data(ctl_cmd_t cmd, knot_ctl_type_t data_type,
case CTL_ZONE_BEGIN: case CTL_ZONE_BEGIN:
case CTL_ZONE_COMMIT: case CTL_ZONE_COMMIT:
case CTL_ZONE_ABORT: case CTL_ZONE_ABORT:
case CTL_ZONE_PURGE:
if (data_type == KNOT_CTL_TYPE_DATA) { if (data_type == KNOT_CTL_TYPE_DATA) {
printf("%s%s%s%s%s%s%s%s", printf("%s%s%s%s%s%s%s%s",
(!(*empty) ? "\n" : ""), (!(*empty) ? "\n" : ""),
...@@ -321,6 +323,7 @@ static void format_block(ctl_cmd_t cmd, bool failed, bool empty) ...@@ -321,6 +323,7 @@ static void format_block(ctl_cmd_t cmd, bool failed, bool empty)
case CTL_ZONE_ABORT: case CTL_ZONE_ABORT:
case CTL_ZONE_SET: case CTL_ZONE_SET:
case CTL_ZONE_UNSET: case CTL_ZONE_UNSET:
case CTL_ZONE_PURGE:
printf("%s\n", failed ? "" : "OK"); printf("%s\n", failed ? "" : "OK");
break; break;
case CTL_ZONE_STATUS: case CTL_ZONE_STATUS:
...@@ -559,6 +562,11 @@ static int cmd_zone_ctl(cmd_args_t *args) ...@@ -559,6 +562,11 @@ static int cmd_zone_ctl(cmd_args_t *args)
return ret; return ret;
} }
if (args->desc->cmd == CTL_ZONE_PURGE && !args->force) {
log_error("force option required!");
return KNOT_EDENIED;
}
// Ignore all zones argument. // Ignore all zones argument.
if (args->argc == 1 && strcmp(args->argv[0], "--") == 0) { if (args->argc == 1 && strcmp(args->argv[0], "--") == 0) {
args->argc = 0; args->argc = 0;
...@@ -884,6 +892,7 @@ const cmd_desc_t cmd_table[] = { ...@@ -884,6 +892,7 @@ const cmd_desc_t cmd_table[] = {
{ CMD_ZONE_GET, cmd_zone_node_ctl, CTL_ZONE_GET, CMD_FREQ_ZONE }, { CMD_ZONE_GET, cmd_zone_node_ctl, CTL_ZONE_GET, CMD_FREQ_ZONE },
{ CMD_ZONE_SET, cmd_zone_node_ctl, CTL_ZONE_SET, CMD_FREQ_ZONE }, { CMD_ZONE_SET, cmd_zone_node_ctl, CTL_ZONE_SET, CMD_FREQ_ZONE },
{ CMD_ZONE_UNSET, cmd_zone_node_ctl, CTL_ZONE_UNSET, CMD_FREQ_ZONE }, { CMD_ZONE_UNSET, cmd_zone_node_ctl, CTL_ZONE_UNSET, CMD_FREQ_ZONE },
{ CMD_ZONE_PURGE, cmd_zone_ctl, CTL_ZONE_PURGE, CMD_FREQ_ZONE },
{ CMD_CONF_INIT, cmd_conf_init, CTL_NONE, CMD_FWRITE }, { CMD_CONF_INIT, cmd_conf_init, CTL_NONE, CMD_FWRITE },
{ CMD_CONF_CHECK, cmd_conf_check, CTL_NONE, CMD_FREAD }, { CMD_CONF_CHECK, cmd_conf_check, CTL_NONE, CMD_FREAD },
...@@ -925,6 +934,7 @@ static const cmd_help_t cmd_help_table[] = { ...@@ -925,6 +934,7 @@ static const cmd_help_t cmd_help_table[] = {
{ CMD_ZONE_GET, "<zone> [<owner> [<type>]]", "Get zone data within the transaction." }, { CMD_ZONE_GET, "<zone> [<owner> [<type>]]", "Get zone data within the transaction." },
{ CMD_ZONE_SET, "<zone> <owner> [<ttl>] <type> <rdata>", "Add zone record within the transaction." }, { CMD_ZONE_SET, "<zone> <owner> [<ttl>] <type> <rdata>", "Add zone record within the transaction." },
{ CMD_ZONE_UNSET, "<zone> <owner> [<type> [<rdata>]]", "Remove zone data within the transaction." }, { CMD_ZONE_UNSET, "<zone> <owner> [<type> [<rdata>]]", "Remove zone data within the transaction." },
{ CMD_ZONE_PURGE, "<zone>...", "Purge zone data, zone file, and zone journal." },
{ "", "", "" }, { "", "", "" },
{ CMD_CONF_INIT, "", "Initialize the confdb. (*)" }, { CMD_CONF_INIT, "", "Initialize the confdb. (*)" },
{ CMD_CONF_CHECK, "", "Check the server configuration. (*)" }, { CMD_CONF_CHECK, "", "Check the server configuration. (*)" },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment