static int ldbm_instance_config_readonly_set(void *arg, void *value, char *errorbuf, int phase, int apply) { ldbm_instance *inst = (ldbm_instance *)arg; uintptr_t pval = (uintptr_t)value; if (!apply) { return LDAP_SUCCESS; } if (CONFIG_PHASE_RUNNING == phase) { /* if the instance is busy, we'll save the user's readonly settings * but won't change them until the instance is un-busy again. */ if (! (inst->inst_flags & INST_FLAG_BUSY)) { slapi_mtn_be_set_readonly(inst->inst_be, (int)pval); } if ((int)pval) { inst->inst_flags |= INST_FLAG_READONLY; } else { inst->inst_flags &= ~INST_FLAG_READONLY; } } else { slapi_be_set_readonly(inst->inst_be, (int)pval); } return LDAP_SUCCESS; }
int instance_set_busy_and_readonly(ldbm_instance *inst) { PR_Lock(inst->inst_config_mutex); if (inst->inst_flags & INST_FLAG_BUSY) { PR_Unlock(inst->inst_config_mutex); return -1; } inst->inst_flags |= INST_FLAG_BUSY; /* save old readonly state */ if (slapi_be_get_readonly(inst->inst_be)) { inst->inst_flags |= INST_FLAG_READONLY; } else { inst->inst_flags &= ~INST_FLAG_READONLY; } /* * Normally, acquire rlock on be_lock, then lock inst_config_mutex. * instance_set_busy_and_readonly should release inst_config_mutex * before acquiring wlock on be_lock in slapi_mtn_be_set_readonly. */ PR_Unlock(inst->inst_config_mutex); slapi_mtn_be_set_readonly(inst->inst_be, 1); return 0; }
/* mark a backend instance to be not "busy" anymore */ void instance_set_not_busy(ldbm_instance *inst) { int readonly; PR_Lock(inst->inst_config_mutex); inst->inst_flags &= ~INST_FLAG_BUSY; /* set backend readonly flag to match instance flags again * (sometimes the instance changes the readonly status when it's busy) */ readonly = (inst->inst_flags & INST_FLAG_READONLY ? 1 : 0); slapi_mtn_be_set_readonly(inst->inst_be, readonly); PR_Unlock(inst->inst_config_mutex); }