1    	/*
2    	 * vim:noexpandtab:shiftwidth=8:tabstop=8:
3    	 *
4    	 * Copyright CEA/DAM/DIF  (2008)
5    	 * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
6    	 *                Thomas LEIBOVICI  thomas.leibovici@cea.fr
7    	 *
8    	 *
9    	 * This program is free software; you can redistribute it and/or
10   	 * modify it under the terms of the GNU Lesser General Public License
11   	 * as published by the Free Software Foundation; either version 3 of
12   	 * the License, or (at your option) any later version.
13   	 *
14   	 * This program is distributed in the hope that it will be useful, but
15   	 * WITHOUT ANY WARRANTY; without even the implied warranty of
16   	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   	 * Lesser General Public License for more details.
18   	 *
19   	 * You should have received a copy of the GNU Lesser General Public
20   	 * License along with this library; if not, write to the Free Software
21   	 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22   	 * 02110-1301 USA
23   	 *
24   	 * ---------------------------------------
25   	 */
26   	
27   	/**
28   	 * @file    nfs4_op_reclaim_complete.c
29   	 * @brief   Routines used for managing the NFS4 COMPOUND functions.
30   	 *
31   	 * Routines used for managing the NFS4 COMPOUND functions.
32   	 *
33   	 *
34   	 */
35   	#include "config.h"
36   	#include <stdio.h>
37   	#include <string.h>
38   	#include <pthread.h>
39   	#include <fcntl.h>
40   	#include <sys/file.h>
41   	#include "hashtable.h"
42   	#include "log.h"
43   	#include "gsh_rpc.h"
44   	#include "nfs23.h"
45   	#include "nfs4.h"
46   	#include "mount.h"
47   	#include "nfs_core.h"
48   	#include "nfs_exports.h"
49   	#include "nfs_proto_functions.h"
50   	#include "nfs_file_handle.h"
51   	#include "sal_data.h"
52   	#include "sal_functions.h"
53   	
54   	/**
55   	 *
56   	 * @brief The NFS4_OP_RECLAIM_COMPLETE4 operation.
57   	 *
58   	 * This function implements the NFS4_OP_RECLAIM_COMPLETE4 operation.
59   	 *
60   	 * @param[in]     op    Arguments for the nfs4_op
61   	 * @param[in,out] data  Compound request's data
62   	 * @param[out]    resp  Retuls for the nfs4_op
63   	 *
64   	 * @return per RFC5661 p. 372
65   	 *
66   	 * @see nfs4_Compound
67   	 *
68   	 */
69   	
70   	enum nfs_req_result nfs4_op_reclaim_complete(struct nfs_argop4 *op,
71   						     compound_data_t *data,
72   						     struct nfs_resop4 *resp)
73   	{
74   		RECLAIM_COMPLETE4args * const arg_RECLAIM_COMPLETE4
75   		    __attribute__ ((unused))
76   		    = &op->nfs_argop4_u.opreclaim_complete;
77   		RECLAIM_COMPLETE4res * const res_RECLAIM_COMPLETE4 =
78   		    &resp->nfs_resop4_u.opreclaim_complete;
(1) Event deref_ptr: Directly dereferencing pointer "data->session".
Also see events: [check_after_deref]
79   		nfs_client_id_t	*clientid = data->session->clientid_record;
80   	
81   		resp->resop = NFS4_OP_RECLAIM_COMPLETE;
82   	
83   		res_RECLAIM_COMPLETE4->rcr_status = NFS4_OK;
84   	
85   		if (data->minorversion == 0) {
86   			res_RECLAIM_COMPLETE4->rcr_status = NFS4ERR_INVAL;
87   			return NFS_REQ_ERROR;
88   		}
89   	
(2) Event check_after_deref: Null-checking "data->session" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
Also see events: [deref_ptr]
90   		if (data->session == NULL) {
91   			res_RECLAIM_COMPLETE4->rcr_status = NFS4ERR_OP_NOT_IN_SESSION;
92   			return NFS_REQ_ERROR;
93   		}
94   	
95   		/* For now, we don't handle rca_one_fs, so we won't complain about
96   		 * complete already for it.
97   		 */
98   		if (clientid->cid_cb.v41.cid_reclaim_complete &&
99   		    !arg_RECLAIM_COMPLETE4->rca_one_fs) {
100  			res_RECLAIM_COMPLETE4->rcr_status = NFS4ERR_COMPLETE_ALREADY;
101  			return NFS_REQ_ERROR;
102  		}
103  	
104  		if (!arg_RECLAIM_COMPLETE4->rca_one_fs) {
105  			clientid->cid_cb.v41.cid_reclaim_complete = true;
106  			if (clientid->cid_allow_reclaim)
107  				atomic_inc_int32_t(&reclaim_completes);
108  		}
109  	
110  		return NFS_REQ_OK;
111  	}				/* nfs41_op_reclaim_complete */
112  	
113  	/**
114  	 * @brief Free memory allocated for RECLAIM_COMPLETE result
115  	 *
116  	 * This function frees anty memory allocated for the result of the
117  	 * NFS4_OP_RECLAIM_COMPLETE operation.
118  	 */
119  	void nfs4_op_reclaim_complete_Free(nfs_resop4 *resp)
120  	{
121  		/* Nothing to be done */
122  	}
123