/* * Handles close notifications. Commits the session by calling * the close_cache_mp_write_session. */ static int on_mp_write_session_close_notification(struct query_state *qstate) { TRACE_IN(on_mp_write_session_close_notification); configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); close_cache_mp_write_session((cache_mp_write_session)qstate->mdata); configuration_unlock_entry(qstate->config_entry, CELT_MULTIPART); qstate->mdata = INVALID_CACHE_MP_WRITE_SESSION; qstate->kevent_watermark = 0; qstate->process_func = NULL; TRACE_OUT(on_mp_write_session_close_notification); return (0); }
static int on_mp_read_session_request_process(struct query_state *qstate) { struct cache_mp_read_session_request *c_mp_rs_request; struct cache_mp_read_session_response *c_mp_rs_response; cache_mp_read_session rs; cache_entry c_entry; char *dec_cache_entry_name; char *buffer; size_t buffer_size; cache_mp_write_session ws; struct agent *lookup_agent; struct multipart_agent *mp_agent; void *mdata; int res; TRACE_IN(on_mp_read_session_request_process); init_comm_element(&qstate->response, CET_MP_READ_SESSION_RESPONSE); c_mp_rs_response = get_cache_mp_read_session_response( &qstate->response); c_mp_rs_request = get_cache_mp_read_session_request(&qstate->request); qstate->config_entry = configuration_find_entry( s_configuration, c_mp_rs_request->entry); if (qstate->config_entry == NULL) { c_mp_rs_response->error_code = ENOENT; LOG_ERR_2("read_session_request", "can't find configuration entry '%s'." " aborting request", c_mp_rs_request->entry); goto fin; } if (qstate->config_entry->enabled == 0) { c_mp_rs_response->error_code = EACCES; LOG_ERR_2("read_session_request", "configuration entry '%s' is disabled", c_mp_rs_request->entry); goto fin; } if (qstate->config_entry->perform_actual_lookups != 0) dec_cache_entry_name = strdup( qstate->config_entry->mp_cache_params.cep.entry_name); else { #ifdef NS_NSCD_EID_CHECKING if (check_query_eids(qstate) != 0) { c_mp_rs_response->error_code = EPERM; goto fin; } #endif asprintf(&dec_cache_entry_name, "%s%s", qstate->eid_str, qstate->config_entry->mp_cache_params.cep.entry_name); } assert(dec_cache_entry_name != NULL); configuration_lock_rdlock(s_configuration); c_entry = find_cache_entry(s_cache, dec_cache_entry_name); configuration_unlock(s_configuration); if ((c_entry == INVALID_CACHE) && (qstate->config_entry->perform_actual_lookups != 0)) c_entry = register_new_mp_cache_entry(qstate, dec_cache_entry_name); free(dec_cache_entry_name); if (c_entry != INVALID_CACHE_ENTRY) { configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); rs = open_cache_mp_read_session(c_entry); configuration_unlock_entry(qstate->config_entry, CELT_MULTIPART); if ((rs == INVALID_CACHE_MP_READ_SESSION) && (qstate->config_entry->perform_actual_lookups != 0)) { lookup_agent = find_agent(s_agent_table, c_mp_rs_request->entry, MULTIPART_AGENT); if ((lookup_agent != NULL) && (lookup_agent->type == MULTIPART_AGENT)) { mp_agent = (struct multipart_agent *) lookup_agent; mdata = mp_agent->mp_init_func(); /* * Multipart agents read the whole snapshot * of the data at one time. */ configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); ws = open_cache_mp_write_session(c_entry); configuration_unlock_entry(qstate->config_entry, CELT_MULTIPART); if (ws != NULL) { do { buffer = NULL; res = mp_agent->mp_lookup_func(&buffer, &buffer_size, mdata); if ((res & NS_TERMINATE) && (buffer != NULL)) { configuration_lock_entry( qstate->config_entry, CELT_MULTIPART); if (cache_mp_write(ws, buffer, buffer_size) != 0) { abandon_cache_mp_write_session(ws); ws = NULL; } configuration_unlock_entry( qstate->config_entry, CELT_MULTIPART); free(buffer); buffer = NULL; } else { configuration_lock_entry( qstate->config_entry, CELT_MULTIPART); close_cache_mp_write_session(ws); configuration_unlock_entry( qstate->config_entry, CELT_MULTIPART); free(buffer); buffer = NULL; } } while ((res & NS_TERMINATE) && (ws != NULL)); } configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); rs = open_cache_mp_read_session(c_entry); configuration_unlock_entry(qstate->config_entry, CELT_MULTIPART); } } if (rs == INVALID_CACHE_MP_READ_SESSION) c_mp_rs_response->error_code = -1; else { qstate->mdata = rs; qstate->destroy_func = on_mp_read_session_destroy; configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); if ((qstate->config_entry->mp_query_timeout.tv_sec != 0) || (qstate->config_entry->mp_query_timeout.tv_usec != 0)) memcpy(&qstate->timeout, &qstate->config_entry->mp_query_timeout, sizeof(struct timeval)); configuration_unlock_entry(qstate->config_entry, CELT_MULTIPART); } } else c_mp_rs_response->error_code = -1; fin: qstate->process_func = on_mp_read_session_response_write1; qstate->kevent_watermark = sizeof(int); qstate->kevent_filter = EVFILT_WRITE; TRACE_OUT(on_mp_read_session_request_process); return (0); }