int nlm_send_async_res_nlm4(state_nlm_client_t *host, state_async_func_t func, nfs_res_t *pres) { state_async_queue_t *arg = gsh_malloc(sizeof(*arg)); state_nlm_async_data_t *nlm_arg; state_status_t status; if (arg != NULL) { nlm_arg = &arg->state_async_data.state_nlm_async_data; memset(arg, 0, sizeof(*arg)); arg->state_async_func = func; nlm_arg->nlm_async_host = host; nlm_arg->nlm_async_args.nlm_async_res = *pres; if (!copy_netobj (&nlm_arg->nlm_async_args.nlm_async_res.res_nlm4.cookie, &pres->res_nlm4.cookie)) { LogCrit(COMPONENT_NLM, "Unable to copy async response file handle"); gsh_free(arg); return NFS_REQ_DROP; } } else { LogCrit(COMPONENT_NLM, "Unable to allocate async response"); return NFS_REQ_DROP; } status = state_async_schedule(arg); if (status != STATE_SUCCESS) { gsh_free(arg); return NFS_REQ_DROP; } return NFS_REQ_OK; }
int nlm_send_async_res_nlm4test(state_nlm_client_t * host, state_async_func func, nfs_res_t * pres) { state_async_queue_t * arg = (state_async_queue_t *) Mem_Alloc(sizeof(*arg)); state_nlm_async_data_t * nlm_arg; state_status_t status; if(arg != NULL) { nlm_arg = &arg->state_async_data.state_nlm_async_data; memset(arg, 0, sizeof(*arg)); arg->state_async_func = func; nlm_arg->nlm_async_host = host; nlm_arg->nlm_async_args.nlm_async_res = *pres; if(!copy_netobj(&nlm_arg->nlm_async_args.nlm_async_res.res_nlm4test.cookie, &pres->res_nlm4test.cookie)) { LogFullDebug(COMPONENT_NLM, "Unable to copy async response file handle"); Mem_Free(arg); return NFS_REQ_DROP; } else if(pres->res_nlm4test.test_stat.stat == NLM4_DENIED) { if(!copy_netobj(&nlm_arg->nlm_async_args.nlm_async_res.res_nlm4test.test_stat.nlm4_testrply_u.holder.oh, &pres->res_nlm4test.test_stat.nlm4_testrply_u.holder.oh)) { LogFullDebug(COMPONENT_NLM, "Unable to copy async response oh"); netobj_free(&nlm_arg->nlm_async_args.nlm_async_res.res_nlm4test.cookie); Mem_Free(arg); return NFS_REQ_DROP; } } } else { LogFullDebug(COMPONENT_NLM, "Unable to allocate async response"); return NFS_REQ_DROP; } status = state_async_schedule(arg); if(status != STATE_SUCCESS) { netobj_free(&nlm_arg->nlm_async_args.nlm_async_res.res_nlm4test.cookie); if(pres->res_nlm4test.test_stat.stat == NLM4_DENIED) netobj_free(&nlm_arg->nlm_async_args.nlm_async_res.res_nlm4test.test_stat.nlm4_testrply_u.holder.oh); Mem_Free(arg); return NFS_REQ_DROP; } return NFS_REQ_OK; }
state_status_t nlm_granted_callback(cache_entry_t * pentry, state_lock_entry_t * lock_entry, state_status_t * pstatus) { fsal_op_context_t fsal_context, *pcontext = &fsal_context; state_block_data_t * block_data = lock_entry->sle_block_data; state_nlm_block_data_t * nlm_block_data = &block_data->sbd_block_data.sbd_nlm_block_data; state_cookie_entry_t * cookie_entry = NULL; state_async_queue_t * arg; nlm4_testargs * inarg; state_nlm_owner_t * nlm_grant_owner = &lock_entry->sle_owner->so_owner.so_nlm_owner; state_nlm_client_t * nlm_grant_client = nlm_grant_owner->so_client; granted_cookie_t nlm_grant_cookie; state_status_t dummy_status; if(nlm_block_data_to_fsal_context(block_data, &fsal_context) != TRUE) { *pstatus = STATE_INCONSISTENT_ENTRY; return *pstatus; } arg = gsh_malloc(sizeof(*arg)); if(arg == NULL) { /* If we fail allocation the best is to delete the block entry * so that client can try again and get the lock. May be * by then we are able to allocate objects */ *pstatus = STATE_MALLOC_ERROR; return *pstatus; } memset(arg, 0, sizeof(*arg)); /* Get a cookie to use for this grant */ next_granted_cookie(&nlm_grant_cookie); /* Add a cookie to the blocked lock pending grant. * It will also request lock from FSAL. * Could return STATE_LOCK_BLOCKED because FSAL would have had to block. */ if(state_add_grant_cookie(pentry, pcontext, &nlm_grant_cookie, sizeof(nlm_grant_cookie), lock_entry, &cookie_entry, pstatus) != STATE_SUCCESS) { free_grant_arg(arg); return *pstatus; } /* Fill in the arguments for the NLMPROC4_GRANTED_MSG call */ inc_nlm_client_ref(nlm_grant_client); arg->state_async_func = nlm4_send_grant_msg; arg->state_async_data.state_nlm_async_data.nlm_async_host = nlm_grant_client; arg->state_async_data.state_nlm_async_data.nlm_async_key = cookie_entry; inarg = &arg->state_async_data.state_nlm_async_data.nlm_async_args.nlm_async_grant; if(!copy_netobj(&inarg->alock.fh, &nlm_block_data->sbd_nlm_fh)) goto grant_fail_malloc; if(!fill_netobj(&inarg->alock.oh, lock_entry->sle_owner->so_owner_val, lock_entry->sle_owner->so_owner_len)) goto grant_fail_malloc; if(!fill_netobj(&inarg->cookie, (char *) &nlm_grant_cookie, sizeof(nlm_grant_cookie))) goto grant_fail_malloc; inarg->alock.caller_name = gsh_strdup(nlm_grant_client->slc_nlm_caller_name); if(!inarg->alock.caller_name) goto grant_fail_malloc; inarg->exclusive = lock_entry->sle_lock.lock_type == FSAL_LOCK_W; inarg->alock.svid = nlm_grant_owner->so_nlm_svid; inarg->alock.l_offset = lock_entry->sle_lock.lock_start; inarg->alock.l_len = lock_entry->sle_lock.lock_length; if(isDebug(COMPONENT_NLM)) { char buffer[1024]; netobj_to_string(&inarg->cookie, buffer, sizeof(buffer)); LogDebug(COMPONENT_NLM, "Sending GRANTED for arg=%p svid=%d start=%llx len=%llx cookie=%s", arg, inarg->alock.svid, (unsigned long long) inarg->alock.l_offset, (unsigned long long) inarg->alock.l_len, buffer); } /* Now try to schedule NLMPROC4_GRANTED_MSG call */ *pstatus = state_async_schedule(arg); if(*pstatus != STATE_SUCCESS) goto grant_fail; return *pstatus; grant_fail_malloc: *pstatus = STATE_MALLOC_ERROR; grant_fail: /* Something went wrong after we added a grant cookie, need to clean up */ dec_nlm_client_ref(nlm_grant_client); /* Clean up NLMPROC4_GRANTED_MSG arguments */ free_grant_arg(arg); /* Cancel the pending grant to release the cookie */ if(state_cancel_grant(pcontext, cookie_entry, &dummy_status) != STATE_SUCCESS) { /* Not much we can do other than log that something bad happened. */ LogCrit(COMPONENT_NLM, "Unable to clean up GRANTED lock after error"); } return *pstatus; }