timeshift: include support for total buffer size.

This commit is contained in:
Adam Sutton 2013-01-14 22:37:57 +00:00
parent c463b7d7ba
commit aff8b05c28
5 changed files with 26 additions and 8 deletions

View file

@ -29,7 +29,6 @@
<dd>If checked, this allows the timeshift buffer to grow unbounded until
your storage media runs out of space (WARNING: this could be dangerous!).
<!--
<dt>Max. Size (MegaBytes)
<dd>Specifies the maximum combined size of all timeshift buffers. If you
specify an unlimited period its highly recommended you specifying a value
@ -39,7 +38,6 @@
<dd>If checked, this allows the combined size of all timeshift buffers to
potentially grow unbounded until your storage media runs out of space
(WARNING: this could be dangerous!).
-->
</dl>
Changes to any of these settings must be confirmed by pressing the

View file

@ -27,6 +27,9 @@ extern uint32_t timeshift_max_period;
extern int timeshift_unlimited_size;
extern size_t timeshift_max_size;
extern size_t timeshift_total_size;
extern pthread_mutex_t timeshift_size_lock;
void timeshift_init ( void );
void timeshift_term ( void );
void timeshift_save ( void );

View file

@ -38,6 +38,9 @@ static pthread_t timeshift_reaper_thread;
static pthread_mutex_t timeshift_reaper_lock;
static pthread_cond_t timeshift_reaper_cond;
pthread_mutex_t timeshift_size_lock;
size_t timeshift_total_size;
/* **************************************************************************
* File reaper thread
* *************************************************************************/
@ -72,6 +75,10 @@ static void* timeshift_reaper_callback ( void *p )
if (errno != ENOTEMPTY)
tvhlog(LOG_ERR, "timeshift", "failed to remove %s [e=%s]",
dpath, strerror(errno));
pthread_mutex_lock(&timeshift_size_lock);
assert(tsf->size >= timeshift_total_size);
timeshift_total_size -= tsf->size;
pthread_mutex_unlock(&timeshift_size_lock);
/* Free memory */
while ((ti = TAILQ_FIRST(&tsf->iframes))) {
@ -218,8 +225,13 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create )
}
/* Check size */
// TODO: need to implement this
pthread_mutex_lock(&timeshift_size_lock);
if (!timeshift_unlimited_size && timeshift_total_size >= timeshift_max_size) {
tvhlog(LOG_DEBUG, "timshift", "ts %d buffer full", ts->id);
ts->full = 1;
}
pthread_mutex_unlock(&timeshift_size_lock);
/* Create new file */
tsf_tmp = NULL;
if (!ts->full) {
@ -304,6 +316,10 @@ void timeshift_filemgr_init ( void )
timeshift_filemgr_get_root(path, sizeof(path));
rmtree(path);
/* Size processing */
timeshift_total_size = 0;
pthread_mutex_init(&timeshift_size_lock, NULL);
/* Start the reaper thread */
timeshift_reaper_run = 1;
pthread_mutex_init(&timeshift_reaper_lock, NULL);

View file

@ -224,6 +224,9 @@ static inline ssize_t _process_msg0
if (err > 0) {
tsf->last = sm->sm_time;
tsf->size += err;
pthread_mutex_lock(&timeshift_size_lock);
timeshift_total_size += err;
pthread_mutex_unlock(&timeshift_size_lock);
}
return err;
}

View file

@ -56,15 +56,13 @@ tvheadend.timeshift = function() {
fieldLabel: 'Max. Size (MB)',
name: 'timeshift_max_size',
allowBlank: false,
width: 300,
hidden : true
width: 300
});
var timeshiftUnlSize = new Ext.form.Checkbox({
fieldLabel: '&nbsp;&nbsp;&nbsp;(unlimited)',
name: 'timeshift_unlimited_size',
Width: 300,
hidden : true
Width: 300
});
/* ****************************************************************