Keeps track of the last sync time of each block.

This commit is contained in:
Andrea Mazzoleni 2013-06-23 22:54:54 +02:00
parent ef53cd4086
commit e0164b29d1
3 changed files with 39 additions and 10 deletions

33
elem.h
View file

@ -680,12 +680,39 @@ struct snapraid_map* map_alloc(const char* name, unsigned position, const char*
void map_free(struct snapraid_map* map);
/**
* Make an info.
* Makes an info.
*/
static inline snapraid_info info_make(time_t last_access)
{
/* clear the low bit to keep some free bits */
return last_access & ~0xFF;
/* clear the lowest bit as reserved for the hash type */
return last_access & ~0x1;
}
/**
* Sets the info at the specified position.
* The position is allocated if not yet done.
*/
static inline void info_set(tommy_arrayof* array, unsigned pos, snapraid_info info)
{
tommy_arrayof_grow(array, pos + 1);
memcpy(tommy_arrayof_ref(array, pos), &info, sizeof(snapraid_info));
}
/**
* Gets the info at the specified position.
* For not allocated position, 0 is returned.
*/
static inline snapraid_info info_get(tommy_arrayof* array, unsigned pos)
{
snapraid_info info;
if (pos >= tommy_arrayof_size(array))
return 0;
memcpy(&info, tommy_arrayof_ref(array, pos), sizeof(snapraid_info));
return info;
}
#endif

View file

@ -1040,8 +1040,7 @@ void state_read(struct snapraid_state* state)
info = info_make(t);
/* insert the block in the block array */
tommy_arrayof_grow(&state->infoarr, v_pos + 1);
memcpy(tommy_arrayof_ref(&state->infoarr, v_pos), &info, sizeof(snapraid_info));
info_set(&state->infoarr, v_pos, info);
} else if (strcmp(tag, "off") == 0) {
/* "off" command */
block_off_t v_pos;
@ -1963,15 +1962,11 @@ void state_write(struct snapraid_state* state)
/* note that here infomax contains the maximum block for which we wrote something */
/* tha could be smaller than of blocks we have in memory, in case of deleted blocks */
/* don't try to write more info than stored */
if (infomax > tommy_arrayof_size(&state->infoarr))
infomax = tommy_arrayof_size(&state->infoarr);
/* for each block */
for(b=0;b<infomax;++b) {
snapraid_info info;
memcpy(&info, tommy_arrayof_ref(&state->infoarr, b), sizeof(snapraid_info));
info = info_get(&state->infoarr, b);
/* save only stuff different than 0 */
if (info != 0) {

7
sync.c
View file

@ -45,6 +45,10 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
block_off_t autosavemissing;
int ret;
unsigned unrecoverable_error;
time_t now;
/* get the present time */
now = time(0);
/* maps the disks to handles */
handle = handle_map(state, &diskmax);
@ -309,6 +313,9 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
/* now all the blocks have the hash and the parity computed */
block_state_set(block, BLOCK_STATE_BLK);
}
/* update the time info of the block */
info_set(&state->infoarr, i, info_make(now));
}
/* mark the state as needing write */