Ejemplo n.º 1
0
static struct dbwrap_lock_order_state *dbwrap_check_lock_order(
	struct db_context *db, TALLOC_CTX *mem_ctx)
{
	int idx;
	static struct db_context *locked_dbs[DBWRAP_LOCK_ORDER_MAX];
	struct dbwrap_lock_order_state *state = NULL;

	if (db->lock_order == 0) {
		/*
		 * lock order 0 is for example for dbwrap_rbt without
		 * real locking. Return state nevertheless to avoid
		 * special cases.
		 */
		return talloc_zero(mem_ctx, struct dbwrap_lock_order_state);
	}

	if (db->lock_order > DBWRAP_LOCK_ORDER_MAX) {
		DEBUG(0,("Invalid lock order %d of %s\n",
			 (int)db->lock_order, db->name));
		smb_panic("invalid lock_order\n");
		return NULL;
	}

	DEBUG(5, ("check lock order %d for %s\n",
		  (int)db->lock_order, db->name));


	for (idx=db->lock_order - 1; idx < DBWRAP_LOCK_ORDER_MAX; idx++) {
		if (locked_dbs[idx] != NULL) {
			DEBUG(0, ("Lock order violation: Trying %s at %d while %s at %d is locked\n",
				  db->name, (int)db->lock_order, locked_dbs[idx]->name, idx + 1));
			debug_lock_order(0, locked_dbs);
			smb_panic("invalid lock_order");
			return NULL;
		}
	}

	state = talloc(mem_ctx, struct dbwrap_lock_order_state);
	if (state == NULL) {
		DEBUG(1, ("talloc failed\n"));
		return NULL;
	}
	state->db = db;
	state->locked_dbs = locked_dbs;
	talloc_set_destructor(state, dbwrap_lock_order_state_destructor);

	locked_dbs[db->lock_order - 1] = db;

	debug_lock_order(10, locked_dbs);

	return state;
}
Ejemplo n.º 2
0
static struct dbwrap_lock_order_state *dbwrap_check_lock_order(
	struct db_context *db, TALLOC_CTX *mem_ctx)
{
	int idx;
	static struct db_context *locked_dbs[DBWRAP_LOCK_ORDER_MAX];
	struct dbwrap_lock_order_state *state = NULL;

	if (!DBWRAP_LOCK_ORDER_VALID(db->lock_order)) {
		DEBUG(0,("Invalid lock order %d of %s\n",
			 (int)db->lock_order, db->name));
		smb_panic("invalid lock_order\n");
		return NULL;
	}

	DEBUG(5, ("check lock order %d for %s\n",
		  (int)db->lock_order, db->name));


	for (idx=db->lock_order - 1; idx < DBWRAP_LOCK_ORDER_MAX; idx++) {
		if (locked_dbs[idx] != NULL) {
			DEBUG(0, ("Lock order violation: Trying %s at %d while %s at %d is locked\n",
				  db->name, (int)db->lock_order, locked_dbs[idx]->name, idx + 1));
			debug_lock_order(0, locked_dbs);
			smb_panic("invalid lock_order");
			return NULL;
		}
	}

	state = talloc(mem_ctx, struct dbwrap_lock_order_state);
	if (state == NULL) {
		DEBUG(1, ("talloc failed\n"));
		return NULL;
	}
	state->db = db;
	state->locked_dbs = locked_dbs;
	talloc_set_destructor(state, dbwrap_lock_order_state_destructor);

	locked_dbs[db->lock_order - 1] = db;

	debug_lock_order(10, locked_dbs);

	return state;
}
Ejemplo n.º 3
0
static int dbwrap_lock_order_state_destructor(
	struct dbwrap_lock_order_state *s)
{
	int idx = s->db->lock_order - 1;

	DEBUG(5, ("release lock order %d for %s\n",
		  (int)s->db->lock_order, s->db->name));

	if (s->locked_dbs[idx] != s->db) {
		DEBUG(0, ("locked db at lock order %d is %s, expected %s\n",
			  idx + 1, s->locked_dbs[idx]->name, s->db->name));
		debug_lock_order(0, s->locked_dbs);
		smb_panic("inconsistent lock_order\n");
	}

	s->locked_dbs[idx] = NULL;

	debug_lock_order(10, s->locked_dbs);

	return 0;
}