periodic backup
This commit is contained in:
parent
5d539c30b1
commit
ebcfb0a79e
|
@ -69,9 +69,6 @@ struct Cache {
|
||||||
|
|
||||||
/** \brief the FUSE filesystem path to the remote file*/
|
/** \brief the FUSE filesystem path to the remote file*/
|
||||||
char *fs_path;
|
char *fs_path;
|
||||||
|
|
||||||
/** Transfer struct for the streaming cache */
|
|
||||||
TransferStruct *ts;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,8 +41,7 @@ static Link *Link_new(const char *linkname, LinkType type)
|
||||||
/*
|
/*
|
||||||
* remove the '/' from linkname if it exists
|
* remove the '/' from linkname if it exists
|
||||||
*/
|
*/
|
||||||
char *c =
|
char *c = &(link->linkname[strnlen(link->linkname, MAX_FILENAME_LEN) - 1]);
|
||||||
&(link->linkname[strnlen(link->linkname, MAX_FILENAME_LEN) - 1]);
|
|
||||||
if (*c == '/') {
|
if (*c == '/') {
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,8 @@ typedef enum {
|
||||||
link_lock_debug = 1 << 5,
|
link_lock_debug = 1 << 5,
|
||||||
network_lock_debug = 1 << 6,
|
network_lock_debug = 1 << 6,
|
||||||
cache_lock_debug = 1 << 7,
|
cache_lock_debug = 1 << 7,
|
||||||
libcurl_debug = 1 << 8,
|
ramcache_debug = 1 << 8,
|
||||||
|
libcurl_debug = 1 << 9,
|
||||||
} LogType;
|
} LogType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "ramcache.h"
|
#include "ramcache.h"
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -11,6 +12,12 @@ size_t write_memory_callback(void *recv_data, size_t size, size_t nmemb,
|
||||||
size_t recv_size = size * nmemb;
|
size_t recv_size = size * nmemb;
|
||||||
TransferStruct *ts = (TransferStruct *) userp;
|
TransferStruct *ts = (TransferStruct *) userp;
|
||||||
|
|
||||||
|
if (ts->bg_transfer) {
|
||||||
|
lprintf(ramcache_debug, "ramcache: thread %x: locking;\n",
|
||||||
|
pthread_self());
|
||||||
|
}
|
||||||
|
PTHREAD_MUTEX_LOCK(&ts->lock);
|
||||||
|
|
||||||
ts->data = realloc(ts->data, ts->curr_size + recv_size + 1);
|
ts->data = realloc(ts->data, ts->curr_size + recv_size + 1);
|
||||||
if (!ts->data) {
|
if (!ts->data) {
|
||||||
/*
|
/*
|
||||||
|
@ -22,5 +29,49 @@ size_t write_memory_callback(void *recv_data, size_t size, size_t nmemb,
|
||||||
memmove(&ts->data[ts->curr_size], recv_data, recv_size);
|
memmove(&ts->data[ts->curr_size], recv_data, recv_size);
|
||||||
ts->curr_size += recv_size;
|
ts->curr_size += recv_size;
|
||||||
ts->data[ts->curr_size] = '\0';
|
ts->data[ts->curr_size] = '\0';
|
||||||
|
if (ts->bg_transfer) {
|
||||||
|
lprintf(ramcache_debug, "ramcache: thread %x: unlocking;\n",
|
||||||
|
pthread_self());
|
||||||
|
}
|
||||||
|
PTHREAD_MUTEX_UNLOCK(&ts->lock);
|
||||||
return recv_size;
|
return recv_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TransferStruct *TransferStruct_bg_transfer_new()
|
||||||
|
{
|
||||||
|
TransferStruct *ts = CALLOC(1, sizeof(TransferStruct));
|
||||||
|
if (pthread_mutexattr_init(&ts->lock_attr)) {
|
||||||
|
lprintf(fatal, "lock_attr initialisation failed!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pthread_mutexattr_setpshared(&ts->lock_attr,
|
||||||
|
PTHREAD_PROCESS_SHARED)) {
|
||||||
|
lprintf(fatal, "could not set lock_attr!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pthread_mutex_init(&ts->lock, &ts->lock_attr)) {
|
||||||
|
lprintf(fatal, "lock initialisation failed!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
ts->bg_transfer = 1;
|
||||||
|
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TransferStruct_bg_transfer_free(TransferStruct *ts)
|
||||||
|
{
|
||||||
|
if (ts->bg_transfer) {
|
||||||
|
if (pthread_mutex_destroy(&ts->lock)) {
|
||||||
|
lprintf(fatal, "could not destroy lock!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pthread_mutexattr_destroy(&ts->lock_attr)) {
|
||||||
|
lprintf(fatal, "could not destroy lock_attr!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free(NULL) does nothing */
|
||||||
|
free(ts->data);
|
||||||
|
FREE(ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,12 +26,32 @@ struct TransferStruct {
|
||||||
Link *link;
|
Link *link;
|
||||||
/** \brief The minium requested size */
|
/** \brief The minium requested size */
|
||||||
size_t min_req_size;
|
size_t min_req_size;
|
||||||
/** \brief Whether we have sent off the minimally requested data*/
|
/** \brief mutex for background transfer */
|
||||||
int min_data_sent;
|
pthread_mutex_t lock;
|
||||||
|
/** \brief attribute associated with the mutex */
|
||||||
|
pthread_mutexattr_t lock_attr;
|
||||||
|
/** \brief Whether this TransferStruct was used for background transfer */
|
||||||
|
int bg_transfer;
|
||||||
|
/** \brief The cache file used for background transfer */
|
||||||
|
Cache *cf;
|
||||||
|
/** \brief The ID of the segment being downloaded */
|
||||||
|
off_t seg_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \brief callback function for file transfer */
|
/**
|
||||||
|
* \brief Callback function for file transfer
|
||||||
|
*/
|
||||||
size_t write_memory_callback(void *contents, size_t size, size_t nmemb,
|
size_t write_memory_callback(void *contents, size_t size, size_t nmemb,
|
||||||
void *userp);
|
void *userp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Create a TransferStruct for background transfer
|
||||||
|
*/
|
||||||
|
TransferStruct *TransferStruct_bg_transfer_new();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Free a TransferStruct used for background transfer
|
||||||
|
*/
|
||||||
|
void TransferStruct_free(TransferStruct *ts);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -142,7 +142,6 @@ void FREE(void *ptr)
|
||||||
{
|
{
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
free(ptr);
|
free(ptr);
|
||||||
ptr = NULL;
|
|
||||||
} else {
|
} else {
|
||||||
lprintf(fatal, "attempted to double free a pointer!\n");
|
lprintf(fatal, "attempted to double free a pointer!\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue