Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: vfsmgr - more cleanups
  • Loading branch information
perexg committed Dec 3, 2015
1 parent bd86875 commit 77f6608
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/dvr/dvr_vfsmgr.c
@@ -1,6 +1,7 @@
/*
* Digital Video Recorder - file system management
* Copyright (C) 2015 Jaroslav Kysela
* Copyright (C) 2015 Glenn Christiaensen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -82,12 +83,12 @@ dvr_disk_space_cleanup(dvr_config_t *cfg)

if (diskdata.f_bsize * (int64_t)diskdata.f_blocks < requiredBytes) {
tvhlog(LOG_WARNING, "dvr","disk space cleanup for config \"%s\", required free space \"%ld MB\" is smaller than the total disk size!",
configName, requiredBytes/(int64_t)1024/(int64_t)1024);
configName, requiredBytes/(int64_t)1024/(int64_t)1024);
return -1;
}

tvhlog(LOG_INFO, "dvr","disk space cleanup for config \"%s\", required free space \"%ld MB\", current free space \"%ld MB\"",
configName, requiredBytes/(int64_t)1024/(int64_t)1024, availBytes/(int64_t)1024/(int64_t)1024);
configName, requiredBytes/(int64_t)1024/(int64_t)1024, availBytes/(int64_t)1024/(int64_t)1024);

while (availBytes < requiredBytes) {
oldest = NULL;
Expand Down Expand Up @@ -128,29 +129,28 @@ dvr_disk_space_cleanup(dvr_config_t *cfg)
if (strftime(tbuf, sizeof(tbuf), "%F %T", &tm) <= 0)
*tbuf = 0;
tvhlog(LOG_INFO, "dvr","Delete \"until space needed\" recording \"%s\" with stop time \"%s\" and file size \"%ld MB\"",
lang_str_get(oldest->de_title, NULL), tbuf, fileSize/(int64_t)1024/(int64_t)1024);
lang_str_get(oldest->de_title, NULL), tbuf, fileSize/(int64_t)1024/(int64_t)1024);

dvr_disk_space_config_lastdelete = dispatch_clock;
dvr_entry_delete(oldest, 1); // delete actual file
if (dvr_entry_get_retention_days(oldest) == DVR_RET_ONREMOVE)
dvr_entry_destroy(oldest, 1); // also delete database entry
}
else {
tvhlog(LOG_WARNING, "dvr","%s \"until space needed\" recordings found for config \"%s\", you are running out of disk space very soon!",
loops > 0 ? "Not enough" : "No", configName);
} else {
tvhlog(LOG_WARNING, "dvr", "%s \"until space needed\" recordings found for config \"%s\", you are running out of disk space very soon!",
loops > 0 ? "Not enough" : "No", configName);
goto finish;
}

loops++;
if (loops >= 10) {
tvhlog(LOG_WARNING, "dvr","Not able to clear the required disk space after deleting %i \"until space needed\" recordings...", loops);
tvhlog(LOG_WARNING, "dvr", "Not able to clear the required disk space after deleting %i \"until space needed\" recordings...", loops);
goto finish;
}
}

finish:
tvhlog(LOG_INFO, "dvr","disk space cleanup for config \"%s\", cleared \"%ld MB\" of disk space, new free disk space \"%ld MB\"",
configName, clearedBytes/(int64_t)1024/(int64_t)1024, availBytes/(int64_t)1024/(int64_t)1024);
configName, clearedBytes/(int64_t)1024/(int64_t)1024, availBytes/(int64_t)1024/(int64_t)1024);

return clearedBytes;
}
Expand All @@ -174,8 +174,7 @@ dvr_disk_space_check()
if (dvr_disk_space_config_idx > dvr_disk_space_config_size)
dvr_disk_space_config_idx = 1;

LIST_FOREACH(cfg, &dvrconfigs, config_link)
{
LIST_FOREACH(cfg, &dvrconfigs, config_link) {
idx++;

if (cfg->dvr_enabled &&
Expand All @@ -200,7 +199,7 @@ dvr_disk_space_check()
/* only cleanup one directory at the time as the system needs time to delete the actual files */
dvr_disk_space_cleanup(de->de_config);
cleanupDone = 1;
dvr_disk_space_config_idx = idx;
dvr_disk_space_config_idx = idx + 1;
break;
}
}
Expand Down Expand Up @@ -249,13 +248,12 @@ dvr_get_disk_space_tcb(void *opaque, int dearmed)
dvr_get_disk_space_update((char *)opaque);
htsmsg_add_s64(m, "freediskspace", dvr_bfree);
htsmsg_add_s64(m, "totaldiskspace", dvr_btotal);
notify_by_msg("diskspaceUpdate", m, 0);

/* check free disk space for each dvr config and start cleanup if needed */
pthread_mutex_unlock(&tasklet_lock);
dvr_disk_space_check();
pthread_mutex_lock(&tasklet_lock);

notify_by_msg("diskspaceUpdate", m, 0);
}

free(opaque);
Expand Down

0 comments on commit 77f6608

Please sign in to comment.