diff options
author | Michael Adam <obnox@samba.org> | 2009-12-11 15:31:02 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2009-12-12 00:45:39 +0100 |
commit | 46de365e78c937ebbb7b219b36773a0aab20e7df (patch) | |
tree | 8193af18bb1a6f86e9ee78e3fdb953d0d2d6317d /ctdb/server | |
parent | 8dedde81cd7b3e8405932d3eb84d55b184275f54 (diff) | |
download | samba-46de365e78c937ebbb7b219b36773a0aab20e7df.tar.gz samba-46de365e78c937ebbb7b219b36773a0aab20e7df.tar.xz samba-46de365e78c937ebbb7b219b36773a0aab20e7df.zip |
Add a new control CTDB_GET_DB_SEQNUM - fetch a persistent db's sequence number.
Michael
(This used to be ctdb commit a7e3b5fac6b3f5d74473f26eb86c067b35647996)
Diffstat (limited to 'ctdb/server')
-rw-r--r-- | ctdb/server/ctdb_control.c | 4 | ||||
-rw-r--r-- | ctdb/server/ctdb_persistent.c | 66 |
2 files changed, 70 insertions, 0 deletions
diff --git a/ctdb/server/ctdb_control.c b/ctdb/server/ctdb_control.c index 9cc5591d3d7..3382fae39aa 100644 --- a/ctdb/server/ctdb_control.c +++ b/ctdb/server/ctdb_control.c @@ -556,6 +556,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, case CTDB_CONTROL_CLEAR_LOG: return ctdb_control_clear_log(ctdb); + case CTDB_CONTROL_GET_DB_SEQNUM: + CHECK_CONTROL_DATA_SIZE(sizeof(uint64_t)); + return ctdb_control_get_db_seqnum(ctdb, indata, outdata); + default: DEBUG(DEBUG_CRIT,(__location__ " Unknown CTDB control opcode %u\n", opcode)); return -1; diff --git a/ctdb/server/ctdb_persistent.c b/ctdb/server/ctdb_persistent.c index c075a5d86a8..59ddadb042f 100644 --- a/ctdb/server/ctdb_persistent.c +++ b/ctdb/server/ctdb_persistent.c @@ -815,4 +815,70 @@ int32_t ctdb_control_persistent_store(struct ctdb_context *ctdb, return ctdb_control_trans2_commit(ctdb, c, ctdb_marshall_finish(m), async_reply); } +static int32_t ctdb_get_db_seqnum(struct ctdb_context *ctdb, + uint32_t db_id, + uint64_t *seqnum) +{ + int32_t ret; + struct ctdb_db_context *ctdb_db; + const char *keyname = CTDB_DB_SEQNUM_KEY; + TDB_DATA key; + TDB_DATA data; + TALLOC_CTX *mem_ctx = talloc_new(ctdb); + + ctdb_db = find_ctdb_db(ctdb, db_id); + if (!ctdb_db) { + DEBUG(DEBUG_ERR,(__location__ " Unknown db 0x%08x\n", db_id)); + ret = -1; + goto done; + } + + key.dptr = (uint8_t *)discard_const(keyname); + key.dsize = strlen(keyname) + 1; + + ret = (int32_t)ctdb_ltdb_fetch(ctdb_db, key, NULL, mem_ctx, &data); + if (ret != 0) { + goto done; + } + + if (data.dsize != sizeof(uint64_t)) { + *seqnum = 0; + goto done; + } + + *seqnum = *(uint64_t *)data.dptr; +done: + talloc_free(mem_ctx); + return ret; +} + +/** + * Get the sequence number of a persistent database. + */ +int32_t ctdb_control_get_db_seqnum(struct ctdb_context *ctdb, + TDB_DATA indata, + TDB_DATA *outdata) +{ + uint32_t db_id; + int32_t ret; + uint64_t seqnum; + + db_id = *(uint32_t *)indata.dptr; + ret = ctdb_get_db_seqnum(ctdb, db_id, &seqnum); + if (ret != 0) { + goto done; + } + + outdata->dsize = sizeof(uint64_t); + outdata->dptr = (uint8_t *)talloc_zero(outdata, uint64_t); + if (outdata->dptr == NULL) { + ret = -1; + goto done; + } + + *(outdata->dptr) = seqnum; + +done: + return ret; +} |