From c86c6429538086609114b3a680d59b94dc339bfc Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Mon, 22 Jul 2013 16:00:47 -0400 Subject: Notice when read locks fail When we fail to obtain a read lock on the data, attempt to fail the operation, so that it can be retried later. --- src/back-sch.c | 74 +++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/src/back-sch.c b/src/back-sch.c index 9d63c6b..f3ac7d9 100644 --- a/src/back-sch.c +++ b/src/back-sch.c @@ -1268,16 +1268,23 @@ backend_search_cb(Slapi_PBlock *pb) if (!slapi_be_exist(cbdata.target_dn)) { slapi_log_error(SLAPI_LOG_PLUGIN, cbdata.state->plugin_desc->spd_id, - "slapi_be_exists(\"%s\") = 0, ignoring search\n", - cbdata.target); + "slapi_be_exists(\"%s\") = 0, " + "ignoring search\n", cbdata.target); slapi_sdn_free(&cbdata.target_dn); return 0; } /* Walk the list of groups. */ wrap_inc_call_level(); - map_rdlock(); - map_data_foreach_domain(cbdata.state, backend_search_group_cb, &cbdata); - map_unlock(); + if (map_rdlock() == 0) { + map_data_foreach_domain(cbdata.state, backend_search_group_cb, + &cbdata); + map_unlock(); + } else { + slapi_log_error(SLAPI_LOG_PLUGIN, + cbdata.state->plugin_desc->spd_id, + "unable to acquire read lock, " + "ignoring search\n"); + } wrap_dec_call_level(); #ifdef USE_NSSWITCH /* If during search of some sets we staged additional lookups, perform them. */ @@ -1499,7 +1506,7 @@ backend_check_scope_pb(Slapi_PBlock *pb) } static int -backend_write_cb(Slapi_PBlock *pb) +backend_write_cb(Slapi_PBlock *pb, struct plugin_state *state) { int ret; @@ -1508,15 +1515,20 @@ backend_write_cb(Slapi_PBlock *pb) } wrap_inc_call_level(); - map_rdlock(); - if (backend_check_scope_pb(pb)) { - slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, - NULL, NULL, 0, NULL); - ret = -1; + if (map_rdlock() == 0) { + if (backend_check_scope_pb(pb)) { + slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, + NULL, NULL, 0, NULL); + ret = -1; + } else { + ret = 0; + } + map_unlock(); } else { - ret = 0; + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "unable to acquire read lock\n"); + ret = -1; } - map_unlock(); wrap_dec_call_level(); return ret; @@ -1527,15 +1539,16 @@ backend_pre_write_cb(Slapi_PBlock *pb) { struct plugin_state *state; slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); - return state->use_be_txns ? 0: backend_write_cb(pb); + return state->use_be_txns ? 0: backend_write_cb(pb, state); } static int backend_betxn_pre_write_cb(Slapi_PBlock *pb) { struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); - return state->use_be_txns ? backend_write_cb(pb) : 0; + return state->use_be_txns ? backend_write_cb(pb, state) : 0; } #ifdef USE_PAM @@ -1623,7 +1636,12 @@ backend_bind_cb(Slapi_PBlock *pb) * 3. If bind target DN is not found in the map cache, bind request is rejected. * */ wrap_inc_call_level(); - map_rdlock(); + if (map_rdlock() != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "unable to acquire read lock\n"); + ret = 0; + goto done_with_lock; + } backend_locate(pb, &data, &entry_group, &entry_set); if (data != NULL) { is_nsswitch_origin = slapi_entry_attr_get_charptr(data->e, "schema-compat-origin"); @@ -1669,6 +1687,7 @@ backend_bind_cb(Slapi_PBlock *pb) slapi_ch_free_string(&username); slapi_ch_free_string(&is_nsswitch_origin); } else { +done_with_lock: map_unlock(); wrap_dec_call_level(); if (backend_check_scope_pb(pb)) { @@ -1685,20 +1704,27 @@ backend_bind_cb(Slapi_PBlock *pb) static int backend_compare_cb(Slapi_PBlock *pb) { - int ret; + struct plugin_state *state; + int ret = -1; + if (wrap_get_call_level() > 0) { return 0; } wrap_inc_call_level(); - map_rdlock(); - if (backend_check_scope_pb(pb)) { - slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, - NULL, NULL, 0, NULL); - ret = -1; + if (map_rdlock() == 0) { + if (backend_check_scope_pb(pb)) { + slapi_send_ldap_result(pb, LDAP_UNWILLING_TO_PERFORM, + NULL, NULL, 0, NULL); + ret = -1; + } else { + ret = 0; + } + map_unlock(); } else { - ret = 0; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "unable to acquire read lock\n"); } - map_unlock(); wrap_dec_call_level(); return ret; } -- cgit