mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
Add a new control CTDB_GET_DB_SEQNUM - fetch a persistent db's sequence number.
Michael (This used to be ctdb commit a7e3b5fac6b3f5d74473f26eb86c067b35647996)
This commit is contained in:
parent
8dedde81cd
commit
46de365e78
@ -626,6 +626,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS = 0,
|
||||
CTDB_CONTROL_GET_LOG = 117,
|
||||
CTDB_CONTROL_CLEAR_LOG = 118,
|
||||
CTDB_CONTROL_TRANS3_COMMIT = 119,
|
||||
CTDB_CONTROL_GET_DB_SEQNUM = 120,
|
||||
};
|
||||
|
||||
/*
|
||||
@ -1537,4 +1538,8 @@ struct ctdb_log_state *ctdb_fork_with_logging(TALLOC_CTX *mem_ctx,
|
||||
int32_t ctdb_control_process_exists(struct ctdb_context *ctdb, pid_t pid);
|
||||
struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb, pid_t pid);
|
||||
|
||||
int32_t ctdb_control_get_db_seqnum(struct ctdb_context *ctdb,
|
||||
TDB_DATA indata,
|
||||
TDB_DATA *outdata);
|
||||
|
||||
#endif
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user