コード例 #1
0
/**
 * nlm4_Unlock_Message: Unlock Message
 *
 *  @param parg        [IN]
 *  @param pexportlist [IN]
 *  @param pcontextp   [IN]
 *  @param pclient     [INOUT]
 *  @param ht          [INOUT]
 *  @param preq        [IN]
 *  @param pres        [OUT]
 *
 */
int nlm4_Unlock_Message(nfs_arg_t * parg /* IN     */ ,
                        exportlist_t * pexport /* IN     */ ,
                        fsal_op_context_t * pcontext /* IN     */ ,
                        cache_inode_client_t * pclient /* INOUT  */ ,
                        hash_table_t * ht /* INOUT  */ ,
                        struct svc_req *preq /* IN     */ ,
                        nfs_res_t * pres /* OUT    */ )
{
  nlm_async_res_t *arg;
  LogFullDebug(COMPONENT_NFSPROTO,
                    "REQUEST PROCESSING: Calling nlm_Unlock_Message");
  nlm4_Unlock(parg, pexport, pcontext, pclient, ht, preq, pres);

  arg = nlm_build_async_res(parg->arg_nlm4_unlock.alock.caller_name, pres);
  nlm_async_callback(nlm4_unlock_message_resp, arg);
  return NFS_REQ_OK;
}
コード例 #2
0
ファイル: nlm_util.c プロジェクト: xushiwei/nfs-ganesha
state_status_t nlm_granted_callback(cache_entry_t        * pentry,
                                    state_lock_entry_t   * lock_entry,
                                    cache_inode_client_t * pclient,
                                    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;
  nlm_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;

  if(nlm_block_data_to_fsal_context(nlm_block_data, &fsal_context) != TRUE)
    {
      *pstatus = STATE_INCONSISTENT_ENTRY;
      return *pstatus;
    }

  arg = (nlm_async_queue_t *) Mem_Alloc(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,
                            pclient,
                            pstatus) != STATE_SUCCESS)
    {
      free_grant_arg(arg);
      return *pstatus;
    }

  /* Fill in the arguments for the NLMPROC4_GRANTED_MSG call */
  arg->nlm_async_func = nlm4_send_grant_msg;
  arg->nlm_async_host = nlm_grant_client;
  arg->nlm_async_key  = cookie_entry;
  inarg = &arg->nlm_async_args.nlm_async_grant;

  if(!copy_netobj(&inarg->alock.fh, &nlm_block_data->sbd_nlm_fh))
    goto grant_fail;

  if(!fill_netobj(&inarg->alock.oh,
                  lock_entry->sle_owner->so_owner_val,
                  lock_entry->sle_owner->so_owner_len))
    goto grant_fail;

  if(!fill_netobj(&inarg->cookie,
                  (char *) &nlm_grant_cookie,
                  sizeof(nlm_grant_cookie)))
    goto grant_fail;

  inarg->alock.caller_name = Str_Dup(nlm_grant_client->slc_nlm_caller_name);
  if(!inarg->alock.caller_name)
    goto grant_fail;

  inarg->exclusive      = lock_entry->sle_lock.sld_type == STATE_LOCK_W;
  inarg->alock.svid     = nlm_grant_owner->so_nlm_svid;
  inarg->alock.l_offset = lock_entry->sle_lock.sld_offset;
  inarg->alock.l_len    = lock_entry->sle_lock.sld_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 */
  if(nlm_async_callback(arg) == -1)
    goto grant_fail;

  *pstatus = STATE_SUCCESS;
  return *pstatus;

 grant_fail:

  /* Something went wrong after we added a grant cookie, need to clean up */

  /* 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,
                        pclient,
                        pstatus) != 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");
    }

  *pstatus = STATE_MALLOC_ERROR;
  return *pstatus;
}