Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
idnode: change config save mechanism (do I/O outside global_lock)
  • Loading branch information
perexg committed Feb 10, 2016
1 parent e481234 commit bd55aeb
Show file tree
Hide file tree
Showing 66 changed files with 556 additions and 644 deletions.
60 changes: 21 additions & 39 deletions src/access.c
Expand Up @@ -1143,19 +1143,6 @@ access_destroy_by_channel_tag(channel_tag_t *ct, int delconf)
idnode_list_destroy(&ct->ct_accesses, delconf ? ct : NULL);
}

/**
*
*/
void
access_entry_save(access_entry_t *ae)
{
htsmsg_t *c = htsmsg_create_map();
char ubuf[UUID_HEX_SIZE];
idnode_save(&ae->ae_id, c);
hts_settings_save(c, "accesscontrol/%s", idnode_uuid_as_str(&ae->ae_id, ubuf));
htsmsg_destroy(c);
}

/**
*
*/
Expand All @@ -1168,7 +1155,7 @@ access_entry_reindex(void)
TAILQ_FOREACH(ae, &access_entries, ae_link) {
if (ae->ae_index != i) {
ae->ae_index = i;
access_entry_save(ae);
idnode_changed(&ae->ae_id);
}
i++;
}
Expand All @@ -1178,11 +1165,16 @@ access_entry_reindex(void)
* Class definition
* **************************************************************************/

static void
access_entry_class_save(idnode_t *self)
static htsmsg_t *
access_entry_class_save(idnode_t *self, char *filename, size_t fsize)
{
access_entry_t *ae = (access_entry_t *)self;
char ubuf[UUID_HEX_SIZE];
htsmsg_t *c = htsmsg_create_map();
access_entry_update_rights((access_entry_t *)self);
access_entry_save((access_entry_t *)self);
idnode_save(&ae->ae_id, c);
snprintf(filename, fsize, "accesscontrol/%s", idnode_uuid_as_str(&ae->ae_id, ubuf));
return c;
}

static void
Expand Down Expand Up @@ -1778,20 +1770,15 @@ passwd_entry_destroy(passwd_entry_t *pw, int delconf)
free(pw);
}

void
passwd_entry_save(passwd_entry_t *pw)
static htsmsg_t *
passwd_entry_class_save(idnode_t *self, char *filename, size_t fsize)
{
htsmsg_t *c = htsmsg_create_map();
passwd_entry_t *pw = (passwd_entry_t *)self;
char ubuf[UUID_HEX_SIZE];
htsmsg_t *c = htsmsg_create_map();
idnode_save(&pw->pw_id, c);
hts_settings_save(c, "passwd/%s", idnode_uuid_as_str(&pw->pw_id, ubuf));
htsmsg_destroy(c);
}

static void
passwd_entry_class_save(idnode_t *self)
{
passwd_entry_save((passwd_entry_t *)self);
snprintf(filename, fsize, "passwd/%s", idnode_uuid_as_str(&pw->pw_id, ubuf));
return c;
}

static void
Expand Down Expand Up @@ -1954,20 +1941,15 @@ ipblock_entry_destroy(ipblock_entry_t *ib)
free(ib);
}

void
ipblock_entry_save(ipblock_entry_t *ib)
static htsmsg_t *
ipblock_entry_class_save(idnode_t *self, char *filename, size_t fsize)
{
ipblock_entry_t *ib = (ipblock_entry_t *)self;
htsmsg_t *c = htsmsg_create_map();
char ubuf[UUID_HEX_SIZE];
idnode_save(&ib->ib_id, c);
hts_settings_save(c, "ipblock/%s", idnode_uuid_as_str(&ib->ib_id, ubuf));
htsmsg_destroy(c);
}

static void
ipblock_entry_class_save(idnode_t *self)
{
ipblock_entry_save((ipblock_entry_t *)self);
snprintf(filename, fsize, "ipblock/%s", idnode_uuid_as_str(&ib->ib_id, ubuf));
return c;
}

static const char *
Expand Down Expand Up @@ -2109,7 +2091,7 @@ access_init(int createdefault, int noacl)
ae->ae_admin = 1;
access_entry_update_rights(ae);

access_entry_save(ae);
idnode_changed(&ae->ae_id);

tvhlog(LOG_WARNING, "access",
"Created default wide open access controle entry");
Expand Down
10 changes: 0 additions & 10 deletions src/access.h
Expand Up @@ -275,12 +275,6 @@ access_entry_create(const char *uuid, htsmsg_t *conf);
void
access_entry_destroy(access_entry_t *ae, int delconf);

/**
*
*/
void
access_entry_save(access_entry_t *ae);

/**
*
*/
Expand All @@ -298,16 +292,12 @@ passwd_entry_t *
passwd_entry_create(const char *uuid, htsmsg_t *conf);
void
passwd_entry_destroy(passwd_entry_t *ae, int delconf);
void
passwd_entry_save(passwd_entry_t *pw);

/**
*
*/
ipblock_entry_t *
ipblock_entry_create(const char *uuid, htsmsg_t *conf);
void
ipblock_entry_save(ipblock_entry_t *pw);

/**
*
Expand Down
6 changes: 3 additions & 3 deletions src/api/api_access.c
Expand Up @@ -47,7 +47,7 @@ api_passwd_entry_create

pthread_mutex_lock(&global_lock);
if ((pw = passwd_entry_create(NULL, conf)) != NULL)
passwd_entry_save(pw);
idnode_changed(&pw->pw_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down Expand Up @@ -79,7 +79,7 @@ api_ipblock_entry_create

pthread_mutex_lock(&global_lock);
if ((ib = ipblock_entry_create(NULL, conf)) != NULL)
ipblock_entry_save(ib);
idnode_changed(&ib->ib_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down Expand Up @@ -155,7 +155,7 @@ api_access_entry_create

pthread_mutex_lock(&global_lock);
if ((ae = access_entry_create(NULL, conf)) != NULL)
access_entry_save(ae);
idnode_changed(&ae->ae_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/api/api_bouquet.c
Expand Up @@ -75,7 +75,7 @@ api_bouquet_create
pthread_mutex_lock(&global_lock);
bq = bouquet_create(NULL, conf, NULL, NULL);
if (bq)
bouquet_save(bq, 0);
idnode_changed(&bq->bq_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/api/api_channel.c
Expand Up @@ -94,7 +94,7 @@ api_channel_create
pthread_mutex_lock(&global_lock);
ch = channel_create(NULL, conf, NULL);
if (ch)
channel_save(ch);
idnode_changed(&ch->ch_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down Expand Up @@ -151,7 +151,7 @@ api_channel_tag_create
pthread_mutex_lock(&global_lock);
ct = channel_tag_create(NULL, conf);
if (ct)
channel_tag_save(ct);
idnode_changed(&ct->ct_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down
24 changes: 9 additions & 15 deletions src/api/api_dvr.c
Expand Up @@ -57,7 +57,7 @@ api_dvr_config_create

pthread_mutex_lock(&global_lock);
if ((cfg = dvr_config_create(NULL, NULL, conf)))
dvr_config_save(cfg);
idnode_changed(&cfg->dvr_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down Expand Up @@ -172,7 +172,7 @@ api_dvr_entry_create
htsmsg_add_msg(conf, "subtitle", m);
}
if ((de = dvr_entry_create(NULL, conf, 0)))
dvr_entry_save(de);
idnode_changed(&de->de_id);

res = 0;
free(lang);
Expand Down Expand Up @@ -244,7 +244,7 @@ api_dvr_entry_create_by_event
NULL, DVR_PRIO_NORMAL, DVR_RET_DVRCONFIG,
DVR_RET_DVRCONFIG, comment);
if (de)
dvr_entry_save(de);
idnode_changed(&de->de_id);
}
}
pthread_mutex_unlock(&global_lock);
Expand Down Expand Up @@ -382,10 +382,8 @@ api_dvr_autorec_create
if (cfg) {
htsmsg_set_str(conf, "config_name", idnode_uuid_as_str(&cfg->dvr_id, ubuf));
dae = dvr_autorec_create(NULL, conf);
if (dae) {
dvr_autorec_save(dae);
dvr_autorec_changed(dae, 1);
}
if (dae)
idnode_changed(&dae->dae_id);
}
pthread_mutex_unlock(&global_lock);

Expand Down Expand Up @@ -427,10 +425,8 @@ api_dvr_autorec_create_by_series
perm->aa_username,
perm->aa_representative,
"Created from EPG query");
if (dae) {
dvr_autorec_save(dae);
dvr_autorec_changed(dae, 1);
}
if (dae)
idnode_changed(&dae->dae_id);
}
}
pthread_mutex_unlock(&global_lock);
Expand Down Expand Up @@ -467,10 +463,8 @@ api_dvr_timerec_create

pthread_mutex_lock(&global_lock);
dte = dvr_timerec_create(NULL, conf);
if (dte) {
dvr_timerec_save(dte);
dvr_timerec_check(dte);
}
if (dte)
idnode_changed(&dte->dte_id);
pthread_mutex_unlock(&global_lock);

return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/api/api_mpegts.c
Expand Up @@ -128,7 +128,7 @@ api_mpegts_network_create
if (mn) {
err = 0;
*resp = htsmsg_create_map();
mn->mn_config_save(mn);
idnode_changed(&mn->mn_id);
} else {
err = EINVAL;
}
Expand Down Expand Up @@ -225,7 +225,7 @@ api_mpegts_network_muxcreate
if (!(mm = mn->mn_mux_create2(mn, conf)))
goto exit;

mm->mm_config_save(mm);
idnode_changed(&mm->mm_id);
err = 0;

exit:
Expand Down Expand Up @@ -319,7 +319,7 @@ api_mpegts_mux_sched_create
if (mms) {
err = 0;
*resp = htsmsg_create_map();
mpegts_mux_sched_save(mms);
idnode_changed(&mms->mms_id);
} else {
err = EINVAL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/api_wizard.c
Expand Up @@ -32,7 +32,7 @@ wizard_page ( const char *page )
if (strcmp(page, config.wizard ?: "")) {
free(config.wizard);
config.wizard = page[0] ? strdup(page) : NULL;
config_save();
idnode_changed(&config.idnode);
}
pthread_mutex_unlock(&global_lock);
return 0;
Expand Down
50 changes: 20 additions & 30 deletions src/bouquet.c
Expand Up @@ -206,7 +206,7 @@ bouquet_find_by_source(const char *name, const char *src, int create)
tvhwarn("bouquet", "bouquet name '%s' changed to '%s'", bq->bq_name ?: "", name);
free(bq->bq_name);
bq->bq_name = strdup(name);
bouquet_save(bq, 1);
idnode_changed(&bq->bq_id);
}
return bq;
}
Expand Down Expand Up @@ -239,7 +239,7 @@ bouquet_tag(bouquet_t *bq, int create)
ct = channel_tag_find_by_name(buf, create);
if (ct) {
bq->bq_chtag_ptr = ct;
bouquet_save(bq, 0);
idnode_changed(&bq->bq_id);
}
return ct;
}
Expand Down Expand Up @@ -294,10 +294,8 @@ bouquet_map_channel(bouquet_t *bq, service_t *t)
else
ch = (channel_t *)ilm->ilm_in2;
if (ch && bq->bq_chtag)
if (channel_tag_map(bouquet_tag(bq, 1), ch, ch)) {
idnode_notify_changed(&ch->ch_id);
channel_save(ch);
}
if (channel_tag_map(bouquet_tag(bq, 1), ch, ch))
idnode_changed(&ch->ch_id);
}

/*
Expand Down Expand Up @@ -462,8 +460,10 @@ bouquet_completed(bouquet_t *bq, uint32_t seen)
bq->bq_active_services = idnode_set_create(1);

save:
if (bq->bq_saveflag)
bouquet_save(bq, 1);
if (bq->bq_saveflag) {
bq->bq_saveflag = 0;
idnode_changed(&bq->bq_id);
}
}

/*
Expand Down Expand Up @@ -568,28 +568,10 @@ bouquet_delete(bouquet_t *bq)
} else {
idnode_set_free(bq->bq_services);
bq->bq_services = idnode_set_create(1);
bouquet_save(bq, 1);
idnode_changed(&bq->bq_id);
}
}

/**
*
*/
void
bouquet_save(bouquet_t *bq, int notify)
{
htsmsg_t *c = htsmsg_create_map();
char ubuf[UUID_HEX_SIZE];
idnode_save(&bq->bq_id, c);
hts_settings_save(c, "bouquet/%s", idnode_uuid_as_str(&bq->bq_id, ubuf));
if (bq->bq_shield)
htsmsg_add_bool(c, "shield", 1);
htsmsg_destroy(c);
bq->bq_saveflag = 0;
if (notify)
idnode_notify_changed(&bq->bq_id);
}

/**
*
*/
Expand All @@ -607,10 +589,18 @@ bouquet_change_comment ( bouquet_t *bq, const char *comment, int replace )
* Class definition
* **************************************************************************/

static void
bouquet_class_save(idnode_t *self)
static htsmsg_t *
bouquet_class_save(idnode_t *self, char *filename, size_t fsize)
{
bouquet_save((bouquet_t *)self, 0);
bouquet_t *bq = (bouquet_t *)self;
htsmsg_t *c = htsmsg_create_map();
char ubuf[UUID_HEX_SIZE];
idnode_save(&bq->bq_id, c);
snprintf(filename, fsize, "bouquet/%s", idnode_uuid_as_str(&bq->bq_id, ubuf));
if (bq->bq_shield)
htsmsg_add_bool(c, "shield", 1);
bq->bq_saveflag = 0;
return c;
}

static void
Expand Down

0 comments on commit bd55aeb

Please sign in to comment.