Skip to content

Commit

Permalink
modules/kvs: drop cache_entry_set_treeobj()
Browse files Browse the repository at this point in the history
This function no longer has any users except in tests.
Replicate it as a convenience function in the tests.
  • Loading branch information
garlick committed Nov 7, 2017
1 parent d206767 commit 8764b66
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 32 deletions.
22 changes: 0 additions & 22 deletions src/modules/kvs/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,28 +199,6 @@ const json_t *cache_entry_get_treeobj (struct cache_entry *hp)
return hp->o;
}

int cache_entry_set_treeobj (struct cache_entry *hp, const json_t *o)
{
char *s = NULL;
int saved_errno;
int rc = -1;

if (!hp || !o || treeobj_validate (o) < 0) {
errno = EINVAL;
goto done;
}
if (!(s = treeobj_encode (o)))
goto done;
if (cache_entry_set_raw (hp, s, strlen (s)) < 0)
goto done;
rc = 0;
done:
saved_errno = errno;
free (s);
errno = saved_errno;
return rc;
}

void cache_entry_destroy (void *arg)
{
struct cache_entry *hp = arg;
Expand Down
13 changes: 3 additions & 10 deletions src/modules/kvs/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct cache;
/* Create/destroy cache entry.
*
* cache_entry_create() creates an empty cache entry. Data can be set
* in an entry via cache_entry_set_raw() or cache_entry_set_treeobj().
* in an entry via cache_entry_set_raw().
*/
struct cache_entry *cache_entry_create (void);
void cache_entry_destroy (void *arg);
Expand Down Expand Up @@ -55,12 +55,6 @@ int cache_entry_force_clear_dirty (struct cache_entry *hp);
* if it is non-NULL. If 'data' is non-NULL, 'len' must be > 0. If
* 'data' is NULL, 'len' must be zero.
*
* treeobj set accessor is a convenience function that will take a treeobj
* object and extract the raw data string from it and store that in
* the cache entry. The treeobj object 'o' is also cached internally for
* later retrieval. The create transfers ownership of 'o' to the
* cache entry. 'o' must be non-NULL.
*
* treeobj get accessor is a convenience function that will return the
* treeobj object equivalent of the raw data stored internally. If the
* internal raw data is not a valid treeobj object (i.e. improperly
Expand All @@ -72,15 +66,14 @@ int cache_entry_force_clear_dirty (struct cache_entry *hp);
* Generally speaking, a cache entry can only be set once. An attempt
* to set new data in a cache entry will silently succeed.
*
* cache_entry_set_raw() & cache_entry_set_treeobj() &
* cache_entry_clear_data() returns -1 on error, 0 on success
* cache_entry_set_raw() & cache_entry_clear_data()
* return -1 on error, 0 on success
*/
int cache_entry_get_raw (struct cache_entry *hp, const void **data,
int *len);
int cache_entry_set_raw (struct cache_entry *hp, const void *data, int len);

const json_t *cache_entry_get_treeobj (struct cache_entry *hp);
int cache_entry_set_treeobj (struct cache_entry *hp, const json_t *o);

/* Arrange for message handler represented by 'wait' to be restarted
* once cache entry becomes valid or not dirty at completion of a
Expand Down
22 changes: 22 additions & 0 deletions src/modules/kvs/test/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@
#include "src/modules/kvs/waitqueue.h"
#include "src/modules/kvs/cache.h"

static int cache_entry_set_treeobj (struct cache_entry *hp, const json_t *o)
{
char *s = NULL;
int saved_errno;
int rc = -1;

if (!hp || !o || treeobj_validate (o) < 0) {
errno = EINVAL;
goto done;
}
if (!(s = treeobj_encode (o)))
goto done;
if (cache_entry_set_raw (hp, s, strlen (s)) < 0)
goto done;
rc = 0;
done:
saved_errno = errno;
free (s);
errno = saved_errno;
return rc;
}

void wait_cb (void *arg)
{
int *count = arg;
Expand Down
22 changes: 22 additions & 0 deletions src/modules/kvs/test/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@

static int test_global = 5;

static int cache_entry_set_treeobj (struct cache_entry *hp, const json_t *o)
{
char *s = NULL;
int saved_errno;
int rc = -1;

if (!hp || !o || treeobj_validate (o) < 0) {
errno = EINVAL;
goto done;
}
if (!(s = treeobj_encode (o)))
goto done;
if (cache_entry_set_raw (hp, s, strlen (s)) < 0)
goto done;
rc = 0;
done:
saved_errno = errno;
free (s);
errno = saved_errno;
return rc;
}

/* convenience function */
static struct cache_entry *create_cache_entry_raw (void *data, int len)
{
Expand Down
22 changes: 22 additions & 0 deletions src/modules/kvs/test/lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ struct lookup_ref_data
int count;
};

static int cache_entry_set_treeobj (struct cache_entry *hp, const json_t *o)
{
char *s = NULL;
int saved_errno;
int rc = -1;

if (!hp || !o || treeobj_validate (o) < 0) {
errno = EINVAL;
goto done;
}
if (!(s = treeobj_encode (o)))
goto done;
if (cache_entry_set_raw (hp, s, strlen (s)) < 0)
goto done;
rc = 0;
done:
saved_errno = errno;
free (s);
errno = saved_errno;
return rc;
}

/* convenience function */
static struct cache_entry *create_cache_entry_raw (void *data, int len)
{
Expand Down

0 comments on commit 8764b66

Please sign in to comment.