[PATCH 16/42] state: Drop cache bucket

Sam Ravnborg sam at ravnborg.org
Sat Apr 15 01:53:25 PDT 2017


Hi Sasha.

> diff --git a/common/state/backend_storage.c b/common/state/backend_storage.c
> index 6ec58a0c97..218c67f2d7 100644
> --- a/common/state/backend_storage.c
> +++ b/common/state/backend_storage.c
> @@ -69,22 +69,29 @@ int state_storage_write(struct state_backend_storage *storage,
>  	return -EIO;
>  }
>  
> -/**
> - * state_storage_restore_consistency - Restore consistency on all storage backends
> - * @param storage Storage object
> - * @param buf Buffer with valid data that should be on all buckets after this operation
> - * @param len Length of the buffer
> - * @return 0 on success, -errno otherwise
> - *
> - * This function brings valid data onto all buckets we have to ensure that all
> - * data copies are in sync. In the current implementation we just write the data
> - * to all buckets. Bucket implementations that need to keep the number of writes
> - * low, can read their own copy first and compare it.
> - */
> -int state_storage_restore_consistency(struct state_backend_storage *storage,
> -				      const void * buf, ssize_t len)
> +static int bucket_refresh(struct state_backend_storage *storage,
> +			  struct state_backend_storage_bucket *bucket, void *buf, ssize_t len)
>  {
> -	return state_storage_write(storage, buf, len);
> +	int ret;
> +
> +	if (bucket->needs_refresh)
> +		goto refresh;
> +
> +	if (bucket->len != len)
> +		goto refresh;
> +
> +	if (memcmp(bucket->buf, buf, len))
> +		goto refresh;
> +
> +	return 0;
> +
> +refresh:
> +	ret = bucket->write(bucket, buf, len);

In the code above we check needs_refresh and len.
But needs_refresh is never set back to 0 so it looks like we will refresh it too often.
The same with the len argument.

> +	/*
> +	 * Iterate over all buckets. The first valid one we find is the
> +	 * one we want to use.
> +	 */
>  	list_for_each_entry(bucket, &storage->buckets, bucket_list) {
> -		ret = bucket->read(bucket, buf, len);
> -		if (ret) {
> +		ret = bucket->read(bucket, &bucket->buf, &bucket->len);
> +		if (ret == -EUCLEAN) {
> +			bucket->needs_refresh = 1;
> +		} else if (ret) {
This is where we mark it as need_refresh.

	Sam



More information about the barebox mailing list