From 90d71ec93676223538b5a19d3413771f88a8f084 Mon Sep 17 00:00:00 2001 From: Jan Hák Date: Tue, 26 Nov 2024 12:56:51 +0100 Subject: backup: fix usage of new atomic in code (variable backup_ctx) --- src/knot/ctl/commands.c | 8 ++++---- src/knot/events/handlers/backup.c | 4 ++-- src/knot/zone/backup.c | 2 +- src/knot/zone/zone.c | 4 ++++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/knot/ctl/commands.c b/src/knot/ctl/commands.c index 2bc271c7f..8879faa77 100644 --- a/src/knot/ctl/commands.c +++ b/src/knot/ctl/commands.c @@ -662,7 +662,7 @@ static int zone_backup_cmd(zone_t *zone, ctl_args_t *args) int ret = KNOT_EOK; pthread_mutex_lock(&zone->cu_lock); - if (zone->backup_ctx != NULL) { + if (ATOMIC_GET(zone->backup_ctx) != NULL) { log_zone_warning(zone->name, "backup or restore already in progress, skipping zone"); ctx->failed = true; ret = KNOT_EPROGRESS; @@ -675,7 +675,7 @@ static int zone_backup_cmd(zone_t *zone, ctl_args_t *args) } if (ret == KNOT_EOK) { - zone->backup_ctx = ctx; + ATOMIC_SET(zone->backup_ctx, ctx); } pthread_mutex_unlock(&zone->cu_lock); @@ -699,7 +699,7 @@ static int zone_backup_cmd(zone_t *zone, ctl_args_t *args) } if (ret != KNOT_EOK || finish) { - zone->backup_ctx = NULL; + ATOMIC_SET(zone->backup_ctx, NULL); return ret; } @@ -874,7 +874,7 @@ static int zone_txn_begin_l(zone_t *zone, _unused_ ctl_args_t *args) return KNOT_TXN_EEXISTS; } - struct zone_backup_ctx *backup_ctx = zone->backup_ctx; + struct zone_backup_ctx *backup_ctx = ATOMIC_GET(zone->backup_ctx); if (backup_ctx != NULL && backup_ctx->restore_mode) { log_zone_warning(zone->name, "zone restore pending, try opening control transaction later"); return KNOT_EAGAIN; diff --git a/src/knot/events/handlers/backup.c b/src/knot/events/handlers/backup.c index bbafe7e16..f267ea49a 100644 --- a/src/knot/events/handlers/backup.c +++ b/src/knot/events/handlers/backup.c @@ -26,7 +26,7 @@ int event_backup(conf_t *conf, zone_t *zone) { assert(zone); - zone_backup_ctx_t *ctx = zone->backup_ctx; + zone_backup_ctx_t *ctx = ATOMIC_GET(zone->backup_ctx); if (ctx == NULL) { return KNOT_EINVAL; } @@ -66,6 +66,6 @@ int event_backup(conf_t *conf, zone_t *zone) done: ret_deinit = zone_backup_deinit(ctx); - zone->backup_ctx = NULL; + ATOMIC_SET(zone->backup_ctx, NULL); return (ret != KNOT_EOK) ? ret : ret_deinit; } diff --git a/src/knot/zone/backup.c b/src/knot/zone/backup.c index 5c3038a50..5bf9b5903 100644 --- a/src/knot/zone/backup.c +++ b/src/knot/zone/backup.c @@ -444,7 +444,7 @@ static int backup_kaspdb(zone_backup_ctx_t *ctx, conf_t *conf, zone_t *zone, int zone_backup(conf_t *conf, zone_t *zone) { - zone_backup_ctx_t *ctx = zone->backup_ctx; + zone_backup_ctx_t *ctx = ATOMIC_GET(zone->backup_ctx); if (ctx == NULL) { return KNOT_EINVAL; } diff --git a/src/knot/zone/zone.c b/src/knot/zone/zone.c index 1302dc9a5..16f645968 100644 --- a/src/knot/zone/zone.c +++ b/src/knot/zone/zone.c @@ -194,6 +194,8 @@ zone_t* zone_new(const knot_dname_t *name) init_list(&zone->internal_notify); + ATOMIC_INIT(zone->backup_ctx, NULL); + return zone; } @@ -243,6 +245,8 @@ void zone_free(zone_t **zone_ptr) ptrlist_free(&zone->internal_notify, NULL); + ATOMIC_DEINIT(zone->backup_ctx); + free(zone); *zone_ptr = NULL; } -- cgit v1.2.3