Skip to content

Commit

Permalink
ldb_tdb: Use key value ops for fetch command
Browse files Browse the repository at this point in the history
Signed-off-by: Garming Sam <[email protected]>
Reviewed-by: Andrew Bartlett <[email protected]>
  • Loading branch information
GSam authored and abartlet committed Mar 5, 2018
1 parent 68423e9 commit c9f2ff2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/ldb/ldb_tdb/ldb_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ int ltdb_search_key(struct ldb_module *module, struct ltdb_private *ltdb,
msg->num_elements = 0;
msg->elements = NULL;

ret = tdb_parse_record(ltdb->tdb, tdb_key,
ltdb_parse_data_unpack, &ctx);
ret = ltdb->kv_ops->fetch_and_parse(ltdb, tdb_key,
ltdb_parse_data_unpack, &ctx);

if (ret == -1) {
ret = ltdb->kv_ops->error(ltdb);
if (ret == LDB_SUCCESS) {
Expand Down
9 changes: 9 additions & 0 deletions lib/ldb/ldb_tdb/ldb_tdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,14 @@ static void ltdb_handle_extended(struct ltdb_context *ctx)
ltdb_request_extended_done(ctx, ext, ret);
}

static int ltdb_tdb_parse_record(struct ltdb_private *ltdb, TDB_DATA key,
int (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data),
void *ctx)
{
return tdb_parse_record(ltdb->tdb, key, parser, ctx);
}

static const char * ltdb_tdb_name(struct ltdb_private *ltdb)
{
return tdb_name(ltdb->tdb);
Expand All @@ -1731,6 +1739,7 @@ static bool ltdb_tdb_changed(struct ltdb_private *ltdb)
static const struct kv_db_ops key_value_ops = {
.store = ltdb_tdb_store,
.delete = ltdb_tdb_delete,
.fetch_and_parse = ltdb_tdb_parse_record,
.lock_read = ltdb_lock_read,
.unlock_read = ltdb_unlock_read,
.begin_write = ltdb_tdb_transaction_start,
Expand Down
4 changes: 4 additions & 0 deletions lib/ldb/ldb_tdb/ldb_tdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ struct ltdb_private;
struct kv_db_ops {
int (*store)(struct ltdb_private *ltdb, TDB_DATA key, TDB_DATA data, int flags);
int (*delete)(struct ltdb_private *ltdb, TDB_DATA key);
int (*fetch_and_parse)(struct ltdb_private *ltdb, TDB_DATA key,
int (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data),
void *ctx);
int (*lock_read)(struct ldb_module *);
int (*unlock_read)(struct ldb_module *);
int (*begin_write)(struct ltdb_private *);
Expand Down

0 comments on commit c9f2ff2

Please sign in to comment.