Bug Summary

File:xlators/nfs/server/src/nfs3.c
Location:line 1406, column 38
Description:Access to field 'req' results in a dereference of a null pointer (loaded from variable 'cs')

Annotated Source Code

1/*
2 Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com>
3 This file is part of GlusterFS.
4
5 GlusterFS is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3 of the License,
8 or (at your option) any later version.
9
10 GlusterFS is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see
17 <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef _CONFIG_H
21#define _CONFIG_H
22#include "config.h"
23#endif
24
25#include "rpcsvc.h"
26#include "dict.h"
27#include "xlator.h"
28#include "mount3.h"
29#include "xdr-nfs3.h"
30#include "msg-nfs3.h"
31#include "iobuf.h"
32#include "nfs3.h"
33#include "mem-pool.h"
34#include "logging.h"
35#include "nfs-common.h"
36#include "nfs-fops.h"
37#include "nfs-inodes.h"
38#include "nfs-generics.h"
39#include "nfs3-helpers.h"
40#include "nfs-mem-types.h"
41#include "nfs.h"
42#include "xdr-rpc.h"
43#include "xdr-generic.h"
44
45#include <sys/socket.h>
46#include <sys/uio.h>
47#include <sys/statvfs.h>
48#include <time.h>
49
50#define nfs3_validate_strlen_or_goto(str, len, label, status, retval)do { if ((str)) { if (strlen ((str)) > (len)) { do { do { if
(0) printf ("strlen " "too long"); } while (0); _gf_log ("nfs"
"-nfsv3", "nfs3.c", __FUNCTION__, 50, GF_LOG_ERROR, "strlen "
"too long"); } while (0); status = NFS3ERR_NAMETOOLONG; retval
= -36; goto label; } } } while (0);
\
51 do { \
52 if ((str)) { \
53 if (strlen ((str)) > (len)) { \
54 gf_log (GF_NFS3, GF_LOG_ERROR, "strlen "\do { do { if (0) printf ("strlen " "too long"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 55, GF_LOG_ERROR, "strlen "
"too long"); } while (0)
55 "too long")do { do { if (0) printf ("strlen " "too long"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 55, GF_LOG_ERROR, "strlen "
"too long"); } while (0)
; \
56 status = NFS3ERR_NAMETOOLONG; \
57 retval = -ENAMETOOLONG36; \
58 goto label; \
59 } \
60 } \
61 } while (0); \
62
63#define nfs3_validate_nfs3_state(request, state, status, label, retval)do { state = (((rpcsvc_program_t *)((request)->prog))->
private); if (!state) { do { do { if (0) printf ("NFSv3 state "
"missing from RPC request"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 63, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); status = NFS3ERR_SERVERFAULT; ret = -14; goto
label; } } while (0);
\
64 do { \
65 state = rpcsvc_request_program_private (request)(((rpcsvc_program_t *)((request)->prog))->private); \
66 if (!state) { \
67 gf_log (GF_NFS3, GF_LOG_ERROR, "NFSv3 state " \do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 68, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0)
68 "missing from RPC request")do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 68, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0)
; \
69 status = NFS3ERR_SERVERFAULT; \
70 ret = -EFAULT14; \
71 goto label; \
72 } \
73 } while (0); \
74
75
76struct nfs3_export *
77__nfs3_get_export_by_index (struct nfs3_state *nfs3, uuid_t exportid)
78{
79 struct nfs3_export *exp = NULL((void*)0);
80 int index = 0;
81 int searchindex = 0;
82
83 searchindex = nfs3_fh_exportid_to_index (exportid)((uint16_t)exportid[15]);
84 list_for_each_entry (exp, &nfs3->exports, explist)for (exp = ((typeof(*exp) *)((char *)((&nfs3->exports)
->next)-(unsigned long)(&((typeof(*exp) *)0)->explist
))); &exp->explist != (&nfs3->exports); exp = (
(typeof(*exp) *)((char *)(exp->explist.next)-(unsigned long
)(&((typeof(*exp) *)0)->explist))))
{
85 if (searchindex == index)
86 goto found;
87
88 ++index;
89 }
90
91 exp = NULL((void*)0);
92 gf_log (GF_NFS, GF_LOG_ERROR, "searchindex=%d not found", searchindex)do { do { if (0) printf ("searchindex=%d not found", searchindex
); } while (0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 92, GF_LOG_ERROR
, "searchindex=%d not found", searchindex); } while (0)
;
93found:
94 return exp;
95}
96
97
98struct nfs3_export *
99__nfs3_get_export_by_volumeid (struct nfs3_state *nfs3, uuid_t exportid)
100{
101 struct nfs3_export *exp = NULL((void*)0);
102
103 list_for_each_entry (exp, &nfs3->exports, explist)for (exp = ((typeof(*exp) *)((char *)((&nfs3->exports)
->next)-(unsigned long)(&((typeof(*exp) *)0)->explist
))); &exp->explist != (&nfs3->exports); exp = (
(typeof(*exp) *)((char *)(exp->explist.next)-(unsigned long
)(&((typeof(*exp) *)0)->explist))))
{
104 if (!uuid_compare (exportid, exp->volumeid))
105 goto found;
106 }
107
108 exp = NULL((void*)0);
109found:
110 return exp;
111}
112
113
114struct nfs3_export *
115__nfs3_get_export_by_exportid (struct nfs3_state *nfs3, uuid_t exportid)
116{
117 struct nfs3_export *exp = NULL((void*)0);
118
119 if (!nfs3)
120 return exp;
121
122 if (gf_nfs_dvm_off (nfs_state(nfs3->nfsx))(((struct nfs_state *)(nfs3->nfsx)->private)->dynamicvolumes
== 2)
)
123 exp = __nfs3_get_export_by_index (nfs3, exportid);
124 else
125 exp = __nfs3_get_export_by_volumeid (nfs3, exportid);
126
127 return exp;
128}
129
130
131int
132nfs3_export_access (struct nfs3_state *nfs3, uuid_t exportid)
133{
134 int ret = GF_NFS3_VOLACCESS_RO2;
135 struct nfs3_export *exp = NULL((void*)0);
136
137 GF_VALIDATE_OR_GOTO (GF_NFS3, nfs3, err)do { if (!nfs3) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "nfs3"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 137, GF_LOG_ERROR, "invalid argument: "
"nfs3"); } while (0); goto err; } } while (0)
;
138
139 exp = __nfs3_get_export_by_exportid (nfs3, exportid);
140
141 if (!exp) {
142 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to get export by ID")do { do { if (0) printf ("Failed to get export by ID"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 142, GF_LOG_ERROR
, "Failed to get export by ID"); } while (0)
;
143 goto err;
144 }
145
146 ret = exp->access;
147
148err:
149 return ret;
150}
151
152#define nfs3_check_rw_volaccess(nfs3state, exid, status, label)do { if (nfs3_export_access (nfs3state,exid)!=1){ do { do { if
(0) printf ("No read-write access"); } while (0); _gf_log ("nfs"
"-nfsv3", "nfs3.c", __FUNCTION__, 152, GF_LOG_ERROR, "No read-write access"
); } while (0); status = NFS3ERR_ROFS; goto label; } } while (
0)
\
153 do { \
154 if (nfs3_export_access (nfs3state,exid)!=GF_NFS3_VOLACCESS_RW1){\
155 gf_log (GF_NFS3, GF_LOG_ERROR, "No read-write access")do { do { if (0) printf ("No read-write access"); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 155, GF_LOG_ERROR
, "No read-write access"); } while (0)
;\
156 status = NFS3ERR_ROFS; \
157 goto label; \
158 } \
159 } while (0) \
160
161
162
163xlator_t *
164nfs3_fh_to_xlator (struct nfs3_state *nfs3, struct nfs3_fh *fh)
165{
166 xlator_t *vol = NULL((void*)0);
167 struct nfs3_export *exp = NULL((void*)0);
168
169 GF_VALIDATE_OR_GOTO (GF_NFS3, nfs3, out)do { if (!nfs3) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "nfs3"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 169, GF_LOG_ERROR, "invalid argument: "
"nfs3"); } while (0); goto out; } } while (0)
;
170 GF_VALIDATE_OR_GOTO (GF_NFS3, fh, out)do { if (!fh) { (*__errno_location ()) = 22; do { do { if (0)
printf ("invalid argument: " "fh"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 170, GF_LOG_ERROR, "invalid argument: "
"fh"); } while (0); goto out; } } while (0)
;
171
172 exp = __nfs3_get_export_by_exportid (nfs3, fh->exportid);
173 if (!exp)
174 goto out;
175
176 vol = exp->subvol;
177out:
178 return vol;
179}
180
181
182int
183nfs3_is_root_looked_up (struct nfs3_state *nfs3, struct nfs3_fh *rootfh)
184{
185 struct nfs3_export *exp = NULL((void*)0);
186 int ret = 0;
187
188 GF_VALIDATE_OR_GOTO (GF_NFS3, nfs3, out)do { if (!nfs3) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "nfs3"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 188, GF_LOG_ERROR, "invalid argument: "
"nfs3"); } while (0); goto out; } } while (0)
;
189 GF_VALIDATE_OR_GOTO (GF_NFS3, rootfh, out)do { if (!rootfh) { (*__errno_location ()) = 22; do { do { if
(0) printf ("invalid argument: " "rootfh"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 189, GF_LOG_ERROR, "invalid argument: "
"rootfh"); } while (0); goto out; } } while (0)
;
190
191 exp = __nfs3_get_export_by_exportid (nfs3, rootfh->exportid);
192 if (!exp)
193 goto out;
194
195 ret = exp->rootlookedup;
196out:
197 return ret;
198}
199
200
201int
202nfs3_set_root_looked_up (struct nfs3_state *nfs3, struct nfs3_fh *rootfh)
203{
204 struct nfs3_export *exp = NULL((void*)0);
205 int ret = 0;
206
207 GF_VALIDATE_OR_GOTO (GF_NFS3, nfs3, out)do { if (!nfs3) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "nfs3"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 207, GF_LOG_ERROR, "invalid argument: "
"nfs3"); } while (0); goto out; } } while (0)
;
208 GF_VALIDATE_OR_GOTO (GF_NFS3, rootfh, out)do { if (!rootfh) { (*__errno_location ()) = 22; do { do { if
(0) printf ("invalid argument: " "rootfh"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 208, GF_LOG_ERROR, "invalid argument: "
"rootfh"); } while (0); goto out; } } while (0)
;
209
210 exp = __nfs3_get_export_by_exportid (nfs3, rootfh->exportid);
211 if (!exp)
212 goto out;
213
214 exp->rootlookedup = 1;
215out:
216 return ret;
217}
218
219
220#define nfs3_map_fh_to_volume(nfs3state, handle, req, volume, status, label)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); volume = nfs3_fh_to_xlator ((nfs3state), handle); if
(!volume) { uuid_unparse (handle->exportid, exportid); uuid_unparse
(handle->gfid, gfid); trans = ((req)->trans); do { do {
if (0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 220, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 220, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); status = NFS3ERR_STALE; goto
label; } else { do { do { if (0) printf ("FH to Volume: %s" ,
volume->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 220, GF_LOG_TRACE, "FH to Volume: %s" ,volume
->name); } while (0); (req)->private = (void *)(volume)
; } } while (0);
\
221 do { \
222 char exportid[256], gfid[256]; \
223 rpc_transport_t *trans = NULL((void*)0); \
224 volume = nfs3_fh_to_xlator ((nfs3state), handle); \
225 if (!volume) { \
226 uuid_unparse (handle->exportid, exportid); \
227 uuid_unparse (handle->gfid, gfid); \
228 trans = rpcsvc_request_transport (req)((req)->trans); \
229 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to map " \do { do { if (0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 232, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
230 "FH to vol: client=%s, exportid=%s, gfid=%s",\do { do { if (0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 232, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
231 trans->peerinfo.identifier, exportid, \do { do { if (0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 232, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
232 gfid)do { do { if (0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 232, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; \
233 gf_log (GF_NFS3, GF_LOG_ERROR, \do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 236, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0)
234 "Stale nfs client %s must be trying to "\do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 236, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0)
235 "connect to a deleted volume, please " \do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 236, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0)
236 "unmount it.", trans->peerinfo.identifier)do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 236, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0)
;\
237 status = NFS3ERR_STALE; \
238 goto label; \
239 } else { \
240 gf_log (GF_NFS3, GF_LOG_TRACE, "FH to Volume: %s"\do { do { if (0) printf ("FH to Volume: %s" ,volume->name)
; } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 241, GF_LOG_TRACE, "FH to Volume: %s" ,volume->name); } while
(0)
241 ,volume->name)do { do { if (0) printf ("FH to Volume: %s" ,volume->name)
; } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 241, GF_LOG_TRACE, "FH to Volume: %s" ,volume->name); } while
(0)
; \
242 rpcsvc_request_set_private (req, volume)(req)->private = (void *)(volume); \
243 } \
244 } while (0); \
245
246
247#define nfs3_validate_gluster_fh(handle, status, errlabel)do { if ((handle)) { if (!nfs3_fh_validate (handle)) { do { do
{ if (0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 247, GF_LOG_ERROR, "Bad Handle"); }
while (0); status = NFS3ERR_BADHANDLE; goto errlabel; } } } while
(0)
\
248 do { \
249 if ((handle)) { \
250 if (!nfs3_fh_validate (handle)) { \
251 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad Handle")do { do { if (0) printf ("Bad Handle"); } while (0); _gf_log (
"nfs""-nfsv3", "nfs3.c", __FUNCTION__, 251, GF_LOG_ERROR, "Bad Handle"
); } while (0)
;\
252 status = NFS3ERR_BADHANDLE; \
253 goto errlabel; \
254 } \
255 } \
256 } while (0) \
257
258#define nfs3_check_fh_resolve_status(cst, nfstat, erlabl)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cst)->resolve_ret
< 0) { trans = ((cst->req)->trans); xlatorp = nfs3_fh_to_xlator
(cst->nfs3state, &cst->resolvefh); uuid_unparse (cst
->resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans
->peerinfo.identifier, xlatorp ? xlatorp->name : "ERR",
gfid); do { do { if (0) printf ("Unable to resolve FH" ": %s"
, buf); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 258, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); nfstat = nfs3_errno_to_nfsstat3 (cst->resolve_errno)
; goto erlabl; } } while (0)
\
259 do { \
260 xlator_t *xlatorp = NULL((void*)0); \
261 char buf[256], gfid[256]; \
262 rpc_transport_t *trans = NULL((void*)0); \
263 if ((cst)->resolve_ret < 0) { \
264 trans = rpcsvc_request_transport (cst->req)((cst->req)->trans); \
265 xlatorp = nfs3_fh_to_xlator (cst->nfs3state, \
266 &cst->resolvefh); \
267 uuid_unparse (cst->resolvefh.gfid, gfid); \
268 sprintf (buf, "(%s) %s : %s", trans->peerinfo.identifier,\
269 xlatorp ? xlatorp->name : "ERR", gfid); \
270 gf_log (GF_NFS3, GF_LOG_ERROR, "Unable to resolve FH"\do { do { if (0) printf ("Unable to resolve FH" ": %s", buf);
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
271, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0)
271 ": %s", buf)do { do { if (0) printf ("Unable to resolve FH" ": %s", buf);
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
271, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0)
; \
272 nfstat = nfs3_errno_to_nfsstat3 (cst->resolve_errno);\
273 goto erlabl; \
274 } \
275 } while (0) \
276
277#define nfs3_check_new_fh_resolve_status(cst, nfstat, erlabl)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if (((cst)->resolve_ret
< 0) && ((cst)->resolve_errno != 2)) { trans =
((cst->req)->trans); xlatorp = nfs3_fh_to_xlator (cst->
nfs3state, &cst->resolvefh); uuid_unparse (cst->resolvefh
.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->peerinfo
.identifier, xlatorp ? xlatorp->name : "ERR", gfid); do { do
{ if (0) printf ("Unable to resolve FH" ": %s", buf); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 277, GF_LOG_ERROR
, "Unable to resolve FH" ": %s", buf); } while (0); nfstat = nfs3_errno_to_nfsstat3
(cs->resolve_errno); goto erlabl; } } while (0)
\
278 do { \
279 xlator_t *xlatorp = NULL((void*)0); \
280 char buf[256], gfid[256]; \
281 rpc_transport_t *trans = NULL((void*)0); \
282 if (((cst)->resolve_ret < 0) && \
283 ((cst)->resolve_errno != ENOENT2)) { \
284 trans = rpcsvc_request_transport (cst->req)((cst->req)->trans); \
285 xlatorp = nfs3_fh_to_xlator (cst->nfs3state, \
286 &cst->resolvefh); \
287 uuid_unparse (cst->resolvefh.gfid, gfid); \
288 sprintf (buf, "(%s) %s : %s", trans->peerinfo.identifier,\
289 xlatorp ? xlatorp->name : "ERR", gfid); \
290 gf_log (GF_NFS3, GF_LOG_ERROR, "Unable to resolve FH"\do { do { if (0) printf ("Unable to resolve FH" ": %s", buf);
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
291, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0)
291 ": %s", buf)do { do { if (0) printf ("Unable to resolve FH" ": %s", buf);
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
291, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0)
; \
292 nfstat = nfs3_errno_to_nfsstat3 (cs->resolve_errno);\
293 goto erlabl; \
294 } \
295 } while (0) \
296
297
298int
299__nfs3_get_volume_id (struct nfs3_state *nfs3, xlator_t *xl,
300 uuid_t volumeid)
301{
302 int ret = -1;
303 struct nfs3_export *exp = NULL((void*)0);
304
305 GF_VALIDATE_OR_GOTO (GF_NFS3, nfs3, out)do { if (!nfs3) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "nfs3"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 305, GF_LOG_ERROR, "invalid argument: "
"nfs3"); } while (0); goto out; } } while (0)
;
306 GF_VALIDATE_OR_GOTO (GF_NFS3, xl, out)do { if (!xl) { (*__errno_location ()) = 22; do { do { if (0)
printf ("invalid argument: " "xl"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 306, GF_LOG_ERROR, "invalid argument: "
"xl"); } while (0); goto out; } } while (0)
;
307
308 list_for_each_entry (exp, &nfs3->exports, explist)for (exp = ((typeof(*exp) *)((char *)((&nfs3->exports)
->next)-(unsigned long)(&((typeof(*exp) *)0)->explist
))); &exp->explist != (&nfs3->exports); exp = (
(typeof(*exp) *)((char *)(exp->explist.next)-(unsigned long
)(&((typeof(*exp) *)0)->explist))))
{
309 if (exp->subvol == xl) {
310 uuid_copy (volumeid, exp->volumeid);
311 ret = 0;
312 goto out;
313 }
314 }
315
316out:
317 return ret;
318}
319
320
321#define nfs3_funge_solaris_zerolen_fh(nfs3st, fhd, enam, nfsst, erl)do { xlator_t *fungexl = ((void*)0); uuid_t zero = {0, }; fungexl
=nfs_mntpath_to_xlator ((nfs3st)->exportslist,enam); if (
!fungexl) { (nfsst) = NFS3ERR_NOENT; goto erl; } uuid_copy ((
fhd)->gfid, zero); (fhd)->gfid[15] = 1; (enam) = ((void
*)0); if (((((struct nfs_state *)(nfs3st->nfsx)->private
)->dynamicvolumes == 2))) (fhd)->exportid[15] = nfs_xlator_to_xlid
((nfs3st)->exportslist, fungexl); else { if(__nfs3_get_volume_id
((nfs3st), fungexl, (fhd)->exportid) < 0) { (nfsst) = NFS3ERR_STALE
; goto erl; } } } while (0)
\
322 do { \
323 xlator_t *fungexl = NULL((void*)0); \
324 uuid_t zero = {0, }; \
325 fungexl =nfs_mntpath_to_xlator ((nfs3st)->exportslist,enam);\
326 if (!fungexl) { \
327 (nfsst) = NFS3ERR_NOENT; \
328 goto erl; \
329 } \
330 \
331 uuid_copy ((fhd)->gfid, zero); \
332 (fhd)->gfid[15] = 1; \
333 (enam) = NULL((void*)0); \
334 if ((gf_nfs_dvm_off (nfs_state (nfs3st->nfsx))(((struct nfs_state *)(nfs3st->nfsx)->private)->dynamicvolumes
== 2)
)) \
335 (fhd)->exportid[15] = nfs_xlator_to_xlid ((nfs3st)->exportslist, fungexl); \
336 else { \
337 if(__nfs3_get_volume_id ((nfs3st), fungexl, (fhd)->exportid) < 0) { \
338 (nfsst) = NFS3ERR_STALE; \
339 goto erl; \
340 } \
341 } \
342 } while (0) \
343
344
345#define nfs3_volume_started_check(nf3stt, vlm, rtval, erlbl)do { if ((!nfs_subvolume_started ((nf3stt->nfsx)->private
, vlm))){ do { do { if (0) printf ("Volume is disabled: %s", vlm
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 345, GF_LOG_ERROR, "Volume is disabled: %s", vlm->name);
} while (0); rtval = (-2); goto erlbl; } } while (0)
\
346 do { \
347 if ((!nfs_subvolume_started (nfs_state (nf3stt->nfsx)(nf3stt->nfsx)->private, vlm))){\
348 gf_log (GF_NFS3, GF_LOG_ERROR, "Volume is disabled: %s",\do { do { if (0) printf ("Volume is disabled: %s", vlm->name
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 349, GF_LOG_ERROR, "Volume is disabled: %s", vlm->name);
} while (0)
349 vlm->name)do { do { if (0) printf ("Volume is disabled: %s", vlm->name
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 349, GF_LOG_ERROR, "Volume is disabled: %s", vlm->name);
} while (0)
; \
350 rtval = RPCSVC_ACTOR_IGNORE(-2); \
351 goto erlbl; \
352 } \
353 } while (0) \
354
355
356int
357nfs3_export_sync_trusted (struct nfs3_state *nfs3, uuid_t exportid)
358{
359 struct nfs3_export *exp = NULL((void*)0);
360 int ret = 0;
361
362 GF_VALIDATE_OR_GOTO (GF_NFS3, nfs3, err)do { if (!nfs3) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "nfs3"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 362, GF_LOG_ERROR, "invalid argument: "
"nfs3"); } while (0); goto err; } } while (0)
;
363
364 exp = __nfs3_get_export_by_exportid (nfs3, exportid);
365 if (!exp)
366 goto err;
367
368 ret = exp->trusted_sync;
369err:
370 return ret;
371}
372
373
374int
375nfs3_export_write_trusted (struct nfs3_state *nfs3, uuid_t exportid)
376{
377 struct nfs3_export *exp = NULL((void*)0);
378 int ret = 0;
379
380 GF_VALIDATE_OR_GOTO (GF_NFS3, nfs3, err)do { if (!nfs3) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "nfs3"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 380, GF_LOG_ERROR, "invalid argument: "
"nfs3"); } while (0); goto err; } } while (0)
;
381
382 exp = __nfs3_get_export_by_exportid (nfs3, exportid);
383 if (!exp)
384 goto err;
385
386 ret = exp->trusted_write;
387err:
388 return ret;
389}
390
391int
392nfs3_solaris_zerolen_fh (struct nfs3_fh *fh, int fhlen)
393{
394 if (!fh)
395 return 0;
396
397 if (nfs3_fh_validate (fh))
398 return 0;
399
400 if (fhlen == 0)
401 return 1;
402
403 return 0;
404}
405
406
407/* Function pointer that represents the generic prototypes of functions used
408 * to serialize NFS3 message structures into the XDR format.
409 * For usage, see the nfs3svc_XXX_cbk functions.
410 */
411typedef ssize_t (*nfs3_serializer) (struct iovec outmsg, void *args);
412
413nfs3_call_state_t *
414nfs3_call_state_init (struct nfs3_state *s, rpcsvc_request_t *req, xlator_t *v)
415{
416 nfs3_call_state_t *cs = NULL((void*)0);
417
418 GF_VALIDATE_OR_GOTO (GF_NFS3, s, err)do { if (!s) { (*__errno_location ()) = 22; do { do { if (0) printf
("invalid argument: " "s"); } while (0); _gf_log_callingfn (
"nfs""-nfsv3", "nfs3.c", __FUNCTION__, 418, GF_LOG_ERROR, "invalid argument: "
"s"); } while (0); goto err; } } while (0)
;
419 GF_VALIDATE_OR_GOTO (GF_NFS3, req, err)do { if (!req) { (*__errno_location ()) = 22; do { do { if (0
) printf ("invalid argument: " "req"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 419, GF_LOG_ERROR, "invalid argument: "
"req"); } while (0); goto err; } } while (0)
;
420 GF_VALIDATE_OR_GOTO (GF_NFS3, v, err)do { if (!v) { (*__errno_location ()) = 22; do { do { if (0) printf
("invalid argument: " "v"); } while (0); _gf_log_callingfn (
"nfs""-nfsv3", "nfs3.c", __FUNCTION__, 420, GF_LOG_ERROR, "invalid argument: "
"v"); } while (0); goto err; } } while (0)
;
421
422 cs = (nfs3_call_state_t *) mem_get (s->localpool);
423 if (!cs) {
424 gf_log (GF_NFS3, GF_LOG_ERROR, "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 424, GF_LOG_ERROR, "out of memory"
); } while (0)
;
425 return NULL((void*)0);
426 }
427
428 memset (cs, 0, sizeof (*cs));
429 INIT_LIST_HEAD (&cs->entries.list)do { (&cs->entries.list)->next = (&cs->entries
.list)->prev = &cs->entries.list; } while (0)
;
430 INIT_LIST_HEAD (&cs->openwait_q)do { (&cs->openwait_q)->next = (&cs->openwait_q
)->prev = &cs->openwait_q; } while (0)
;
431 cs->operrno = EINVAL22;
432 cs->req = req;
433 cs->vol = v;
434 cs->nfsx = s->nfsx;
435 cs->nfs3state = s;
436err:
437 return cs;
438}
439
440void
441nfs3_call_state_wipe (nfs3_call_state_t *cs)
442{
443 if (!cs)
444 return;
445
446 if (cs->fd) {
447 gf_log (GF_NFS3, GF_LOG_TRACE, "fd 0x%lx ref: %d",do { do { if (0) printf ("fd 0x%lx ref: %d", (long)cs->fd,
cs->fd->refcount); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 448, GF_LOG_TRACE, "fd 0x%lx ref: %d"
, (long)cs->fd, cs->fd->refcount); } while (0)
448 (long)cs->fd, cs->fd->refcount)do { do { if (0) printf ("fd 0x%lx ref: %d", (long)cs->fd,
cs->fd->refcount); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 448, GF_LOG_TRACE, "fd 0x%lx ref: %d"
, (long)cs->fd, cs->fd->refcount); } while (0)
;
449 fd_unref (cs->fd);
450 }
451
452 GF_FREE (cs->resolventry)__gf_free (cs->resolventry);
453
454 GF_FREE (cs->pathname)__gf_free (cs->pathname);
455
456 if (!list_empty (&cs->entries.list))
457 gf_dirent_free (&cs->entries);
458
459 nfs_loc_wipe (&cs->oploc);
460 nfs_loc_wipe (&cs->resolvedloc);
461 if (cs->iob)
462 iobuf_unref (cs->iob);
463 if (cs->iobref)
464 iobref_unref (cs->iobref);
465 if (cs->trans)
466 rpc_transport_unref (cs->trans);
467 memset (cs, 0, sizeof (*cs));
468 mem_put (cs);
469 /* Already refd by fd_lookup, so no need to ref again. */
470}
471
472
473#define nfs3_handle_call_state_init(nfs3state, calls, rq, vl ,opstat, errlabel)do { calls = nfs3_call_state_init ((nfs3state), (rq), (vl)); if
(!calls) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 473, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); opstat = NFS3ERR_SERVERFAULT; goto errlabel; } } while (
0)
\
474 do { \
475 calls = nfs3_call_state_init ((nfs3state), (rq), (vl)); \
476 if (!calls) { \
477 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to " \do { do { if (0) printf ("Failed to " "init call state"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 478, GF_LOG_ERROR
, "Failed to " "init call state"); } while (0)
478 "init call state")do { do { if (0) printf ("Failed to " "init call state"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 478, GF_LOG_ERROR
, "Failed to " "init call state"); } while (0)
; \
479 opstat = NFS3ERR_SERVERFAULT; \
480 goto errlabel; \
481 } \
482 } while (0) \
483
484
485
486struct iobuf *
487nfs3_serialize_reply (rpcsvc_request_t *req, void *arg, nfs3_serializer sfunc,
488 struct iovec *outmsg)
489{
490 struct nfs3_state *nfs3 = NULL((void*)0);
491 struct iobuf *iob = NULL((void*)0);
492 ssize_t retlen = -1;
493
494 nfs3 = (struct nfs3_state *)rpcsvc_request_program_private (req)(((rpcsvc_program_t *)((req)->prog))->private);
495 if (!nfs3) {
496 gf_log (GF_NFS3, GF_LOG_ERROR, "NFSv3 state not found in RPC"do { do { if (0) printf ("NFSv3 state not found in RPC" " request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 497, GF_LOG_ERROR, "NFSv3 state not found in RPC" " request"
); } while (0)
497 " request")do { do { if (0) printf ("NFSv3 state not found in RPC" " request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 497, GF_LOG_ERROR, "NFSv3 state not found in RPC" " request"
); } while (0)
;
498 goto ret;
499 }
500
501 /* First, get the io buffer into which the reply in arg will
502 * be serialized.
503 */
504 /* TODO: get rid of 'sfunc' and use 'xdrproc_t' so we
505 can have 'xdr_sizeof' */
506 iob = iobuf_get (nfs3->iobpool);
507 if (!iob) {
508 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to get iobuf")do { do { if (0) printf ("Failed to get iobuf"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 508, GF_LOG_ERROR
, "Failed to get iobuf"); } while (0)
;
509 goto ret;
510 }
511
512 iobuf_to_iovec (iob, outmsg);
513 /* Use the given serializer to translate the give C structure in arg
514 * to XDR format which will be written into the buffer in outmsg.
515 */
516 /* retlen is used to received the error since size_t is unsigned and we
517 * need -1 for error notification during encoding.
518 */
519 retlen = sfunc (*outmsg, arg);
520 if (retlen == -1) {
521 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to encode message")do { do { if (0) printf ("Failed to encode message"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 521, GF_LOG_ERROR
, "Failed to encode message"); } while (0)
;
522 goto ret;
523 }
524
525 outmsg->iov_len = retlen;
526ret:
527 if (retlen == -1) {
528 iobuf_unref (iob);
529 iob = NULL((void*)0);
530 }
531
532 return iob;
533}
534
535
536
537/* Generic reply function for NFSv3 specific replies. */
538int
539nfs3svc_submit_reply (rpcsvc_request_t *req, void *arg, nfs3_serializer sfunc)
540{
541 struct iovec outmsg = {0, };
542 struct iobuf *iob = NULL((void*)0);
543 int ret = -1;
544 struct iobref *iobref = NULL((void*)0);
545
546 if (!req)
547 return -1;
548
549 iob = nfs3_serialize_reply (req, arg, sfunc, &outmsg);
550 if (!iob) {
551 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to serialize reply")do { do { if (0) printf ("Failed to serialize reply"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 551, GF_LOG_ERROR
, "Failed to serialize reply"); } while (0)
;
552 goto ret;
553 }
554
555 iobref = iobref_new ();
556 if (!iobref) {
557 iobuf_unref (iob);
558 gf_log (GF_NFS3, GF_LOG_ERROR, "failed on iobref_new()")do { do { if (0) printf ("failed on iobref_new()"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 558, GF_LOG_ERROR
, "failed on iobref_new()"); } while (0)
;
559 goto ret;
560 }
561
562 iobref_add (iobref, iob);
563
564 /* Then, submit the message for transmission. */
565 ret = rpcsvc_submit_message (req, &outmsg, 1, NULL((void*)0), 0, iobref);
566
567 /* Now that we've done our job of handing the message to the RPC layer
568 * we can safely unref the iob in the hope that RPC layer must have
569 * ref'ed the iob on receiving into the txlist.
570 */
571 iobuf_unref (iob);
572 iobref_unref (iobref);
573
574 if (ret == -1) {
575 gf_log (GF_NFS3, GF_LOG_ERROR, "Reply submission failed")do { do { if (0) printf ("Reply submission failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 575, GF_LOG_ERROR
, "Reply submission failed"); } while (0)
;
576 goto ret;
577 }
578
579 ret = 0;
580ret:
581 return ret;
582}
583
584
585int
586nfs3svc_submit_vector_reply (rpcsvc_request_t *req, void *arg,
587 nfs3_serializer sfunc, struct iovec *payload,
588 int vcount, struct iobref *iobref)
589{
590 struct iovec outmsg = {0, };
591 struct iobuf *iob = NULL((void*)0);
592 int ret = -1;
593 int new_iobref = 0;
594
595 if (!req)
596 return -1;
597
598 iob = nfs3_serialize_reply (req, arg, sfunc, &outmsg);
599 if (!iob) {
600 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to serialize reply")do { do { if (0) printf ("Failed to serialize reply"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 600, GF_LOG_ERROR
, "Failed to serialize reply"); } while (0)
;
601 goto ret;
602 }
603 if (iobref == NULL((void*)0)) {
604 iobref = iobref_new ();
605 if (!iobref) {
606 gf_log (GF_NFS3, GF_LOG_ERROR, "failed on iobref_new")do { do { if (0) printf ("failed on iobref_new"); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 606, GF_LOG_ERROR
, "failed on iobref_new"); } while (0)
;
607 goto ret;
608 }
609 new_iobref = 1;
610 }
611
612 iobref_add (iobref, iob);
613
614 /* Then, submit the message for transmission. */
615 ret = rpcsvc_submit_message (req, &outmsg, 1, payload, vcount, iobref);
616
617 /* Now that we've done our job of handing the message to the RPC layer
618 * we can safely unref the iob in the hope that RPC layer must have
619 * ref'ed the iob on receiving into the txlist.
620 */
621 iobuf_unref (iob);
622 if (new_iobref)
623 iobref_unref (iobref);
624
625 if (ret == -1) {
626 gf_log (GF_NFS3, GF_LOG_ERROR, "Reply submission failed")do { do { if (0) printf ("Reply submission failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 626, GF_LOG_ERROR
, "Reply submission failed"); } while (0)
;
627 goto ret;
628 }
629
630 ret = 0;
631ret:
632 return ret;
633}
634
635uint64_t
636nfs3_request_xlator_deviceid (rpcsvc_request_t *rq)
637{
638 struct nfs3_state *nfs3 = NULL((void*)0);
639 xlator_t *xl = NULL((void*)0);
640 uint64_t devid = 0;
641 uuid_t volumeid = {0, };
642
643 if (!rq)
644 return 0;
645
646 xl = rpcsvc_request_private (rq)((rq)->private);
647 nfs3 = rpcsvc_request_program_private (rq)(((rpcsvc_program_t *)((rq)->prog))->private);
648 if (gf_nfs_dvm_off (nfs_state (nfs3->nfsx))(((struct nfs_state *)(nfs3->nfsx)->private)->dynamicvolumes
== 2)
)
649 devid = (uint64_t)nfs_xlator_to_xlid (nfs3->exportslist, xl);
650 else {
651 __nfs3_get_volume_id (nfs3, xl, volumeid);
652 memcpy (&devid, &volumeid[8], sizeof (devid));
653 }
654
655 return devid;
656}
657
658
659int
660nfs3svc_null (rpcsvc_request_t *req)
661{
662 struct iovec dummyvec = {0, };
663 if (!req)
664 return RPCSVC_ACTOR_ERROR(-1);
665 rpcsvc_submit_generic (req, &dummyvec, 1, NULL((void*)0), 0, NULL((void*)0));
666 return RPCSVC_ACTOR_SUCCESS0;
667}
668
669
670int
671nfs3_getattr_reply (rpcsvc_request_t *req, nfsstat3 status, struct iatt *buf)
672{
673 getattr3res res;
674 uint64_t deviceid = 0;
675
676 deviceid = nfs3_request_xlator_deviceid (req);
677 nfs3_fill_getattr3res (&res, status, buf, deviceid);
678 nfs3svc_submit_reply (req, &res,
679 (nfs3_serializer)xdr_serialize_getattr3res);
680
681 return 0;
682}
683
684
685int32_t
686nfs3svc_getattr_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
687 int32_t op_ret, int32_t op_errno, inode_t *inode,
688 struct iatt *buf, dict_t *xattr,
689 struct iatt *postparent)
690{
691 nfsstat3 status = NFS3_OK;
692 nfs3_call_state_t *cs = NULL((void*)0);
693
694 cs = frame->local;
695
696 /*
697 * Somewhat counter-intuitively, we don't need to look for sh-failed
698 * here. Failing this getattr will generate a new lookup from the
699 * client, and nfs_fop_lookup_cbk will detect any self-heal failures.
700 */
701
702 if (op_ret == -1) {
703 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 705, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
704 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 705, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
705 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 705, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
706 status = nfs3_errno_to_nfsstat3 (op_errno);
707 }
708 else {
709 nfs_fix_generation(this,inode);
710 }
711
712 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_GETATTR1,
713 status, op_errno);
714
715 nfs3_getattr_reply (cs->req, status, buf);
716 nfs3_call_state_wipe (cs);
717
718 return 0;
719}
720
721
722int32_t
723nfs3svc_getattr_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
724 int32_t op_ret, int32_t op_errno, struct iatt *buf,
725 dict_t *xdata)
726{
727 nfsstat3 status = NFS3_OK;
728 nfs3_call_state_t *cs = NULL((void*)0);
729
730 cs = frame->local;
731
732 if (op_ret == -1) {
733 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 735, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
734 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 735, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
735 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 735, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
736 status = nfs3_errno_to_nfsstat3 (op_errno);
737 }
738
739 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_GETATTR1,
740 status, op_errno);
741
742 nfs3_getattr_reply (cs->req, status, buf);
743 nfs3_call_state_wipe (cs);
744
745 return 0;
746}
747
748
749int
750nfs3_getattr_resume (void *carg)
751{
752 nfsstat3 stat = NFS3ERR_SERVERFAULT;
753 int ret = -EFAULT14;
754 nfs_user_t nfu = {0, };
755 nfs3_call_state_t *cs = NULL((void*)0);
756 uint64_t raw_ctx = 0;
757 struct nfs_inode_ctx *ictx = NULL((void*)0);
758 struct nfs_state *priv = NULL((void*)0);
759
760 if (!carg)
761 return ret;
762
763 cs = (nfs3_call_state_t *)carg;
764 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 764, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
765 nfs_request_user_init (&nfu, cs->req);
766 /* If inode which is to be getattr'd is the root, we need to do a
767 * lookup instead because after a server reboot, it is not necessary
768 * for the root to have been looked up when the getattr on the root is
769 * sent. AND, this causes a problem for stat-prefetch in that it
770 * expects even the root inode to have been looked up.
771
772 if (__is_root_gfid (cs->resolvedloc.inode->gfid))
773 ret = nfs_lookup (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
774 nfs3svc_getattr_lookup_cbk, cs);
775 else
776 ret = nfs_stat (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
777 */
778
779 if (cs->hardresolved) {
780 ret = -EFAULT14;
781 stat = NFS3_OK;
782 goto nfs3err;
783 }
784
785 /*
786 * If brick state changed, we need to force a proper lookup cycle (as
787 * would happen in native protocol) to do self-heal checks. We detect
788 * this by comparing the generation number for the last successful
789 * creation/lookup on the inode to the current number, so inodes that
790 * haven't been validated since the state change are affected.
791 */
792 if (inode_ctx_get(cs->resolvedloc.inode,cs->nfsx,&raw_ctx)inode_ctx_get2(cs->resolvedloc.inode,cs->nfsx,&raw_ctx
,0)
== 0) {
793 ictx = (struct nfs_inode_ctx *)raw_ctx;
794 priv = cs->nfsx->private;
795 if (ictx->generation != priv->generation) {
796 ret = nfs_lookup (cs->nfsx, cs->vol, &nfu,
797 &cs->resolvedloc,
798 nfs3svc_getattr_lookup_cbk, cs);
799 goto check_err;
800 }
801 }
802
803 ret = nfs_stat (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
804 nfs3svc_getattr_stat_cbk, cs);
805
806check_err:
807 if (ret < 0) {
808 gf_log (GF_NFS3, GF_LOG_ERROR, "Stat fop failed: %s: %s",do { do { if (0) printf ("Stat fop failed: %s: %s", cs->oploc
.path, strerror (-ret)); } while (0); _gf_log ("nfs""-nfsv3",
"nfs3.c", __FUNCTION__, 809, GF_LOG_ERROR, "Stat fop failed: %s: %s"
, cs->oploc.path, strerror (-ret)); } while (0)
809 cs->oploc.path, strerror (-ret))do { do { if (0) printf ("Stat fop failed: %s: %s", cs->oploc
.path, strerror (-ret)); } while (0); _gf_log ("nfs""-nfsv3",
"nfs3.c", __FUNCTION__, 809, GF_LOG_ERROR, "Stat fop failed: %s: %s"
, cs->oploc.path, strerror (-ret)); } while (0)
;
810 stat = nfs3_errno_to_nfsstat3 (-ret);
811 }
812
813nfs3err:
814 if (ret < 0) {
815 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
816 NFS3_GETATTR1, stat, -ret);
817 nfs3_getattr_reply (cs->req, stat, &cs->stbuf);
818 nfs3_call_state_wipe (cs);
819 ret = 0;
820 }
821
822 return ret;
823}
824
825
826int
827nfs3_getattr (rpcsvc_request_t *req, struct nfs3_fh *fh)
828{
829 xlator_t *vol = NULL((void*)0);
830 nfsstat3 stat = NFS3ERR_SERVERFAULT;
831 int ret = -EFAULT14;
832 struct nfs3_state *nfs3 = NULL((void*)0);
833 nfs3_call_state_t *cstate = NULL((void*)0);
834
835 GF_VALIDATE_OR_GOTO (GF_NFS3, req, out)do { if (!req) { (*__errno_location ()) = 22; do { do { if (0
) printf ("invalid argument: " "req"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 835, GF_LOG_ERROR, "invalid argument: "
"req"); } while (0); goto out; } } while (0)
;
836 GF_VALIDATE_OR_GOTO (GF_NFS3, fh, out)do { if (!fh) { (*__errno_location ()) = 22; do { do { if (0)
printf ("invalid argument: " "fh"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 836, GF_LOG_ERROR, "invalid argument: "
"fh"); } while (0); goto out; } } while (0)
;
837
838 nfs3_log_common_call (rpcsvc_request_xid (req)((req)->xid), "GETATTR", fh);
839 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 839, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
840 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 840, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
841 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 841, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 841, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 841, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
842 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 842, GF_LOG_ERROR, "Volume is disabled: %s", vol->name);
} while (0); ret = (-2); goto out; } } while (0)
;
843 nfs3_handle_call_state_init (nfs3, cstate, req, vol, stat, nfs3err)do { cstate = nfs3_call_state_init ((nfs3), (req), (vol)); if
(!cstate) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 843, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
844
845 ret = nfs3_fh_resolve_and_resume (cstate, fh, NULL((void*)0),nfs3_getattr_resume);
846 if (ret < 0)
847 stat = nfs3_errno_to_nfsstat3 (-ret);
848
849nfs3err:
850 if (ret < 0) {
851 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_GETATTR1,
852 stat, -ret);
853 nfs3_getattr_reply (req, stat, NULL((void*)0));
854 ret = 0;
855 nfs3_call_state_wipe (cstate);
856 }
857out:
858 return ret;
859}
860
861
862int
863nfs3svc_getattr (rpcsvc_request_t *req)
864{
865 struct nfs3_fh fh = {{0}, };
866 getattr3args args;
867 int ret = RPCSVC_ACTOR_ERROR(-1);
868
869 if (!req)
870 return ret;
871
872 nfs3_prep_getattr3args (&args, &fh);
873 if (xdr_to_getattr3args (req->msg[0], &args) <= 0) {
874 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 874, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
875 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
876 goto rpcerr;
877 }
878
879 ret = nfs3_getattr (req, &fh);
880 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
881 gf_log (GF_NFS3, GF_LOG_ERROR, "GETATTR procedure failed")do { do { if (0) printf ("GETATTR procedure failed"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 881, GF_LOG_ERROR
, "GETATTR procedure failed"); } while (0)
;
882 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
883 ret = RPCSVC_ACTOR_ERROR(-1);
884 }
885
886rpcerr:
887 return ret;
888}
889
890
891int
892nfs3_setattr_reply (rpcsvc_request_t *req, nfsstat3 stat, struct iatt *preop,
893 struct iatt *postop)
894{
895 setattr3res res = {0, };
896 uint64_t deviceid = 0;
897
898 deviceid = nfs3_request_xlator_deviceid (req);
899 nfs3_fill_setattr3res (&res, stat, preop, postop, deviceid);
900 nfs3svc_submit_reply (req, (void *)&res,
901 (nfs3_serializer) xdr_serialize_setattr3res);
902 return 0;
903}
904
905
906int32_t
907nfs3svc_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
908 int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
909 struct iatt *postbuf, dict_t *xdata)
910{
911 nfsstat3 stat = NFS3ERR_SERVERFAULT;
912 struct iatt *prestat = NULL((void*)0);
913 nfs3_call_state_t *cs = NULL((void*)0);
914
915 cs = frame->local;
916 if (op_ret == -1) {
917 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 919, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
918 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 919, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
919 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 919, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
920 stat = nfs3_errno_to_nfsstat3 (op_errno);
921 goto nfs3err;
922 }
923
924 /* If the first stat was got from the guarded setattr callback, or
925 * from an earlier setattr call then we'll need to use that stat
926 * instead of the preop returned here.
927 */
928 if (cs->preparent.ia_ino != 0)
929 prestat = &cs->preparent;
930 else
931 prestat = prebuf;
932
933 stat = NFS3_OK;
934nfs3err:
935 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_SETATTR2, stat,
936 op_errno);
937 nfs3_setattr_reply (cs->req, stat, prestat, postbuf);
938 nfs3_call_state_wipe (cs);
939
940 return 0;
941}
942
943
944int32_t
945nfs3svc_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
946 int32_t op_ret, int32_t op_errno, struct iatt *preop,
947 struct iatt *postop, dict_t *xdata)
948{
949 nfsstat3 stat = NFS3ERR_SERVERFAULT;
950 int ret = -1;
951 struct iatt *prebuf = NULL((void*)0);
952 nfs_user_t nfu = {0, };
953 nfs3_call_state_t *cs = NULL((void*)0);
954
955 cs = frame->local;
956 if (op_ret == -1) {
957 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 959, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
958 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 959, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
959 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 959, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
960 stat = nfs3_errno_to_nfsstat3 (op_errno);
961 goto nfs3err;
962 }
963
964 prebuf = preop;
965 /* Store the current preop in case we need to send a truncate,
966 * in which case the preop to be returned will be this one.
967 */
968 cs->preparent = *preop;
969
970 /* Only truncate if the size is not already same as the requested
971 * truncation and also only if this is not a directory.
972 */
973 if ((gf_attr_size_set (cs->setattr_valid)((cs->setattr_valid) & 0x8)) &&
974 (!IA_ISDIR (postop->ia_type)(postop->ia_type == IA_IFDIR))) {
975 nfs_request_user_init (&nfu, cs->req);
976 ret = nfs_truncate (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
977 cs->stbuf.ia_size, nfs3svc_truncate_cbk,cs);
978
979 if (ret < 0)
980 stat = nfs3_errno_to_nfsstat3 (-ret);
981 } else {
982 ret = -1; /* Force a reply in the branch below. */
983 stat = NFS3_OK;
984 }
985
986nfs3err:
987 if (ret < 0) {
988 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
989 NFS3_SETATTR2, stat, op_errno);
990 nfs3_setattr_reply (cs->req, stat, prebuf, postop);
991 nfs3_call_state_wipe (cs);
992 }
993
994 return 0;
995}
996
997
998
999int32_t
1000nfs3svc_setattr_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1001 int32_t op_ret, int32_t op_errno, struct iatt *buf,
1002 dict_t *xdata)
1003{
1004
1005 int ret = -EFAULT14;
1006 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1007 nfs_user_t nfu = {0, };
1008 nfs3_call_state_t *cs = NULL((void*)0);
1009
1010 cs = frame->local;
1011 if (op_ret == -1) {
1012 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1014, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
1013 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1014, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
1014 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1014, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
1015 stat = nfs3_errno_to_nfsstat3 (op_errno);
1016 goto nfs3err;
1017 }
1018
1019 if (buf->ia_ctime != cs->timestamp.seconds) {
1020 gf_log (GF_NFS3, GF_LOG_ERROR, "Timestamps not in sync")do { do { if (0) printf ("Timestamps not in sync"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1020, GF_LOG_ERROR
, "Timestamps not in sync"); } while (0)
;
1021 stat = NFS3ERR_NOT_SYNC;
1022 goto nfs3err;
1023 }
1024
1025 /* Not a clean way but no motivation to add a new member to local. */
1026 cs->preparent = *buf;
1027 nfs_request_user_init (&nfu, cs->req);
1028 ret = nfs_setattr (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,&cs->stbuf,
1029 cs->setattr_valid, nfs3svc_setattr_cbk, cs);
1030 if (ret < 0)
1031 stat = nfs3_errno_to_nfsstat3 (-ret);
1032
1033nfs3err:
1034 if (ret < 0) {
1035 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
1036 NFS3_SETATTR2, stat, op_errno);
1037 nfs3_setattr_reply (cs->req, stat, NULL((void*)0), NULL((void*)0));
1038 nfs3_call_state_wipe (cs);
1039 }
1040
1041 return 0;
1042}
1043
1044
1045int
1046nfs3_setattr_resume (void *carg)
1047{
1048 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1049 int ret = -EFAULT14;
1050 nfs_user_t nfu = {0, };
1051 nfs3_call_state_t *cs = NULL((void*)0);
1052
1053 if (!carg)
1054 return ret;
1055
1056 cs = (nfs3_call_state_t *)carg;
1057 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1057, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
1058 nfs_request_user_init (&nfu, cs->req);
1059 ret = nfs_setattr (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
1060 &cs->stbuf, cs->setattr_valid,
1061 nfs3svc_setattr_cbk, cs);
1062
1063 if (ret < 0)
1064 stat = nfs3_errno_to_nfsstat3 (-ret);
1065
1066nfs3err:
1067 if (ret < 0) {
1068 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
1069 NFS3_SETATTR2, stat, -ret);
1070 nfs3_setattr_reply (cs->req, stat, NULL((void*)0), NULL((void*)0));
1071 nfs3_call_state_wipe (cs);
1072 }
1073
1074 return ret;
1075}
1076
1077
1078int
1079nfs3_setattr (rpcsvc_request_t *req, struct nfs3_fh *fh, sattr3 *sattr,
1080 sattrguard3 *guard)
1081{
1082 xlator_t *vol = NULL((void*)0);
1083 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1084 int ret = -EFAULT14;
1085 struct nfs3_state *nfs3 = NULL((void*)0);
1086 nfs3_call_state_t *cs = NULL((void*)0);
1087
1088 GF_VALIDATE_OR_GOTO (GF_NFS3, req, out)do { if (!req) { (*__errno_location ()) = 22; do { do { if (0
) printf ("invalid argument: " "req"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1088, GF_LOG_ERROR, "invalid argument: "
"req"); } while (0); goto out; } } while (0)
;
1089 GF_VALIDATE_OR_GOTO (GF_NFS3, fh, out)do { if (!fh) { (*__errno_location ()) = 22; do { do { if (0)
printf ("invalid argument: " "fh"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1089, GF_LOG_ERROR, "invalid argument: "
"fh"); } while (0); goto out; } } while (0)
;
1090 GF_VALIDATE_OR_GOTO (GF_NFS3, sattr, out)do { if (!sattr) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "sattr"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1090, GF_LOG_ERROR, "invalid argument: "
"sattr"); } while (0); goto out; } } while (0)
;
1091 GF_VALIDATE_OR_GOTO (GF_NFS3, guard, out)do { if (!guard) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "guard"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1091, GF_LOG_ERROR, "invalid argument: "
"guard"); } while (0); goto out; } } while (0)
;
1092
1093 nfs3_log_common_call (rpcsvc_request_xid (req)((req)->xid), "SETATTR", fh);
1094 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 1094, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
1095 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1095, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
1096 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 1096, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1096, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 1096, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
1097 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1097, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
1098 nfs3_check_rw_volaccess (nfs3, fh->exportid, stat, nfs3err)do { if (nfs3_export_access (nfs3,fh->exportid)!=1){ do { do
{ if (0) printf ("No read-write access"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1098, GF_LOG_ERROR, "No read-write access"
); } while (0); stat = NFS3ERR_ROFS; goto nfs3err; } } while (
0)
;
1099 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
1099, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
1100
1101 cs->setattr_valid = nfs3_sattr3_to_setattr_valid (sattr, &cs->stbuf,
1102 NULL((void*)0));
1103 if (guard->check) {
1104 gf_log (GF_NFS3, GF_LOG_TRACE, "Guard check required")do { do { if (0) printf ("Guard check required"); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1104, GF_LOG_TRACE
, "Guard check required"); } while (0)
;
1105 cs->timestamp = guard->sattrguard3_u.obj_ctime;
1106 cs->sattrguardcheck = 1;
1107 } else {
1108 gf_log (GF_NFS3, GF_LOG_TRACE, "Guard check not required")do { do { if (0) printf ("Guard check not required"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1108, GF_LOG_TRACE
, "Guard check not required"); } while (0)
;
1109 cs->sattrguardcheck = 0;
1110 }
1111
1112 if (!cs->setattr_valid) {
1113 ret = -EINVAL22; /* Force a reply */
1114 stat = NFS3_OK;
1115 gf_log (GF_NFS3, GF_LOG_ERROR, "cs->setattr_valid is invalid")do { do { if (0) printf ("cs->setattr_valid is invalid"); }
while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1115
, GF_LOG_ERROR, "cs->setattr_valid is invalid"); } while (
0)
;
1116 goto nfs3err;
1117 }
1118
1119 ret = nfs3_fh_resolve_and_resume (cs, fh, NULL((void*)0), nfs3_setattr_resume);
1120 if (ret < 0)
1121 stat = nfs3_errno_to_nfsstat3 (-ret);
1122
1123nfs3err:
1124 if (ret < 0) {
1125 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_SETATTR2,
1126 stat, -ret);
1127 nfs3_setattr_reply (req, stat, NULL((void*)0), NULL((void*)0));
1128 nfs3_call_state_wipe (cs);
1129 /* Ret must be 0 after this so that the caller does not
1130 * also send an RPC reply.
1131 */
1132 ret = 0;
1133 }
1134out:
1135 return ret;
1136}
1137
1138
1139
1140int
1141nfs3svc_setattr (rpcsvc_request_t *req)
1142{
1143 struct nfs3_fh fh = {{0}, };
1144 setattr3args args;
1145 int ret = RPCSVC_ACTOR_ERROR(-1);
1146
1147 GF_VALIDATE_OR_GOTO (GF_NFS3, req, rpcerr)do { if (!req) { (*__errno_location ()) = 22; do { do { if (0
) printf ("invalid argument: " "req"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1147, GF_LOG_ERROR, "invalid argument: "
"req"); } while (0); goto rpcerr; } } while (0)
;
1148
1149 nfs3_prep_setattr3args (&args, &fh);
1150 if (xdr_to_setattr3args (req->msg[0], &args) <= 0) {
1151 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1151, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
1152 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
1153 goto rpcerr;
1154 }
1155
1156 ret = nfs3_setattr (req, &fh, &args.new_attributes, &args.guard);
1157 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
1158 gf_log (GF_NFS3, GF_LOG_ERROR, "SETATTR procedure failed")do { do { if (0) printf ("SETATTR procedure failed"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1158, GF_LOG_ERROR
, "SETATTR procedure failed"); } while (0)
;
1159 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
1160 ret = RPCSVC_ACTOR_ERROR(-1);
1161 }
1162
1163rpcerr:
1164 return ret;
1165
1166}
1167
1168
1169int
1170nfs3_lookup_reply (rpcsvc_request_t *req, nfsstat3 stat, struct nfs3_fh *newfh,
1171 struct iatt *stbuf, struct iatt *postparent)
1172{
1173 lookup3res res = {0, };
1174 uint64_t deviceid = 0;
1175
1176 deviceid = nfs3_request_xlator_deviceid (req);
1177 nfs3_fill_lookup3res (&res, stat, newfh, stbuf, postparent, deviceid);
1178 return nfs3svc_submit_reply (req, &res,
1179 (nfs3_serializer)xdr_serialize_lookup3res);
1180}
1181
1182int
1183nfs3_lookup_resume (void *carg);
1184
1185
1186int
1187nfs3_fresh_lookup (nfs3_call_state_t *cs)
1188{
1189 int ret = -EFAULT14;
1190 char *oldresolventry = NULL((void*)0);
1191
1192 GF_VALIDATE_OR_GOTO (GF_NFS3, cs, err)do { if (!cs) { (*__errno_location ()) = 22; do { do { if (0)
printf ("invalid argument: " "cs"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1192, GF_LOG_ERROR, "invalid argument: "
"cs"); } while (0); goto err; } } while (0)
;
1193 gf_log (GF_NFS3, GF_LOG_DEBUG, "inode needs fresh lookup")do { do { if (0) printf ("inode needs fresh lookup"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1193, GF_LOG_DEBUG
, "inode needs fresh lookup"); } while (0)
;
1194 inode_unlink (cs->resolvedloc.inode, cs->resolvedloc.parent,
1195 cs->resolventry);
1196 nfs_loc_wipe (&cs->resolvedloc);
1197
1198 /* Store pointer to currently allocated resolventry because it gets over
1199 * written in fh_resolve_and_resume.
1200 */
1201 oldresolventry = cs->resolventry;
1202 cs->lookuptype = GF_NFS3_FRESH;
1203 ret = nfs3_fh_resolve_and_resume (cs, &cs->resolvefh, cs->resolventry,
1204 nfs3_lookup_resume);
1205 /* Allocated in the previous call to fh_resolve_and_resume using the
1206 * same call_state.
1207 */
1208 GF_FREE (oldresolventry)__gf_free (oldresolventry);
1209err:
1210 return ret;
1211}
1212
1213int
1214nfs3svc_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1215 int32_t op_ret, int32_t op_errno, inode_t *inode,
1216 struct iatt *buf, dict_t *xattr, struct iatt *postparent)
1217{
1218 struct nfs3_fh newfh = {{0}, };
1219 nfsstat3 status = NFS3_OK;
1220 nfs3_call_state_t *cs = NULL((void*)0);
1221 inode_t *oldinode = NULL((void*)0);
1222
1223 cs = frame->local;
1224 if (op_ret == -1) {
1225 gf_log (GF_NFS,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1228, (op_errno
== 2 ? GF_LOG_TRACE : GF_LOG_WARNING), "%x: %s => -1 (%s)"
, ((cs->req)->xid), cs->resolvedloc.path, strerror (
op_errno)); } while (0)
1226 (op_errno == ENOENT ? GF_LOG_TRACE : GF_LOG_WARNING),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1228, (op_errno
== 2 ? GF_LOG_TRACE : GF_LOG_WARNING), "%x: %s => -1 (%s)"
, ((cs->req)->xid), cs->resolvedloc.path, strerror (
op_errno)); } while (0)
1227 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1228, (op_errno
== 2 ? GF_LOG_TRACE : GF_LOG_WARNING), "%x: %s => -1 (%s)"
, ((cs->req)->xid), cs->resolvedloc.path, strerror (
op_errno)); } while (0)
1228 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1228, (op_errno
== 2 ? GF_LOG_TRACE : GF_LOG_WARNING), "%x: %s => -1 (%s)"
, ((cs->req)->xid), cs->resolvedloc.path, strerror (
op_errno)); } while (0)
;
1229 status = nfs3_errno_to_nfsstat3 (op_errno);
1230 goto xmit_res;
1231 }
1232
1233 nfs3_fh_build_child_fh (&cs->parent, buf, &newfh);
1234 oldinode = inode_link (inode, cs->resolvedloc.parent,
1235 cs->resolvedloc.name, buf);
1236xmit_res:
1237 /* Only send fresh lookup if it was a revalidate that failed. */
1238 if ((op_ret == -1) && (nfs3_is_revalidate_lookup (cs)((cs)->lookuptype == GF_NFS3_REVALIDATE))) {
1239 op_ret = nfs3_fresh_lookup (cs);
1240 goto out;
1241 }
1242
1243 nfs3_log_newfh_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_LOOKUP3, status,
1244 op_errno, &newfh);
1245 nfs3_lookup_reply (cs->req, status, &newfh, buf, postparent);
1246 nfs3_call_state_wipe (cs);
1247out:
1248 if (oldinode) {
1249 inode_lookup (oldinode);
1250 inode_unref (oldinode);
1251 }
1252 return 0;
1253}
1254
1255
1256int
1257nfs3svc_lookup_parentdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1258 int32_t op_ret, int32_t op_errno, inode_t *inode,
1259 struct iatt *buf, dict_t *xattr,
1260 struct iatt *postparent)
1261{
1262 struct nfs3_fh newfh = {{0}, };
1263 nfsstat3 status = NFS3_OK;
1264 nfs3_call_state_t *cs = NULL((void*)0);
1265 uuid_t volumeid = {0, };
1266 struct nfs3_state *nfs3 = NULL((void*)0);
1267
1268 cs = frame->local;
1269 if (op_ret == -1) {
1270 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1272, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
1271 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1272, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
1272 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1272, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
1273 status = nfs3_errno_to_nfsstat3 (op_errno);
1274 goto xmit_res;
1275 }
1276
1277 nfs3 = cs->nfs3state;
1278 /* If the buf inode shows that this is a root dir's buf, then the file
1279 * handle needs to be specially crafted, in all other cases, we'll just
1280 * create the handle normally using the buffer of the parent dir.
1281 */
1282 if (buf->ia_ino != 1) {
1283 nfs3_fh_build_parent_fh (&cs->fh, buf, &newfh);
1284 goto xmit_res;
1285 }
1286
1287 if (gf_nfs_dvm_off (nfs_state (nfs3->nfsx))(((struct nfs_state *)(nfs3->nfsx)->private)->dynamicvolumes
== 2)
)
1288 newfh = nfs3_fh_build_indexed_root_fh (nfs3->exportslist,
1289 cs->vol);
1290 else {
1291 __nfs3_get_volume_id (nfs3, cs->vol, volumeid);
1292 newfh = nfs3_fh_build_uuid_root_fh (volumeid);
1293 }
1294
1295xmit_res:
1296 nfs3_log_newfh_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_LOOKUP3, status,
1297 op_errno, &newfh);
1298 nfs3_lookup_reply (cs->req, status, &newfh, buf, postparent);
1299 nfs3_call_state_wipe (cs);
1300
1301 return 0;
1302}
1303
1304
1305
1306int
1307nfs3_lookup_parentdir_resume (void *carg)
1308{
1309 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1310 int ret = -EFAULT14;
1311 nfs_user_t nfu = {0, };
1312 nfs3_call_state_t *cs = NULL((void*)0);
1313 inode_t *parent = NULL((void*)0);
1314
1315 GF_VALIDATE_OR_GOTO (GF_NFS3, carg, nfs3err)do { if (!carg) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "carg"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1315, GF_LOG_ERROR, "invalid argument: "
"carg"); } while (0); goto nfs3err; } } while (0)
;
1316
1317 cs = (nfs3_call_state_t *)carg;
1318 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1318, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
1319
1320 /* At this point now, the loc in cs is for the directory file handle
1321 * sent by the client. This loc needs to be transformed into a loc that
1322 * represents the parent dir of cs->resolvedloc.inode.
1323 *
1324 * EXCEPT in the case where the .. is a parent of the root directory.
1325 * In this case we'll be returning the file handle and attributes of the
1326 * root itself.
1327 */
1328 nfs_request_user_init (&nfu, cs->req);
1329
1330 /* Save the file handle from the LOOKUP request. We'll use this to
1331 * build the file handle of the parent directory in case the parent is
1332 * not root dir.
1333 */
1334 cs->fh = cs->resolvefh;
1335
1336 /* If fh is that of the root, the resolvedloc will already contain
1337 * the loc for root. After that, we'll send lookup for the root dir
1338 * itself since we cannot send the lookup on the parent of root.
1339 *
1340 * For all other cases, we'll send the lookup on the parent of the
1341 * given directory file handle.
1342 */
1343 if (!nfs3_fh_is_root_fh (&cs->fh)) {
1344 parent = inode_ref (cs->resolvedloc.parent);
1345 nfs_loc_wipe (&cs->resolvedloc);
1346 ret = nfs_inode_loc_fill (parent, &cs->resolvedloc,
1347 NFS_RESOLVE_CREATE2);
1348
1349 if (ret < 0) {
1350 gf_log (GF_NFS3, GF_LOG_ERROR, "nfs_inode_loc_fill"do { do { if (0) printf ("nfs_inode_loc_fill" " error"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1351, GF_LOG_ERROR
, "nfs_inode_loc_fill" " error"); } while (0)
1351 " error")do { do { if (0) printf ("nfs_inode_loc_fill" " error"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1351, GF_LOG_ERROR
, "nfs_inode_loc_fill" " error"); } while (0)
;
1352 goto errtostat;
1353 }
1354 }
1355
1356 ret = nfs_lookup (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
1357 nfs3svc_lookup_parentdir_cbk, cs);
1358errtostat:
1359 if (ret < 0)
1360 stat = nfs3_errno_to_nfsstat3 (-ret);
1361
1362nfs3err:
1363 if (ret < 0) {
1364 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_LOOKUP3,
1365 stat, -ret);
1366 nfs3_lookup_reply (cs->req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0));
1367 nfs3_call_state_wipe (cs);
1368 }
1369
1370 if (parent)
1371 inode_unref (parent);
1372
1373 return ret;
1374}
1375
1376
1377int
1378nfs3_lookup_resume (void *carg)
1379{
1380 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1381 int ret = -EFAULT14;
1382 nfs_user_t nfu = {0, };
1383 nfs3_call_state_t *cs = NULL((void*)0);
1
'cs' initialized to a null pointer value
1384 struct nfs3_fh newfh = {{0},};
1385
1386 GF_VALIDATE_OR_GOTO (GF_NFS3, carg, nfs3err)do { if (!carg) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "carg"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1386, GF_LOG_ERROR, "invalid argument: "
"carg"); } while (0); goto nfs3err; } } while (0)
;
1387
1388 cs = (nfs3_call_state_t *)carg;
1389 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1389, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
1390 cs->parent = cs->resolvefh;
1391
1392 if (cs->hardresolved) {
1393 stat = NFS3_OK;
1394 nfs3_fh_build_child_fh (&cs->parent, &cs->stbuf, &newfh);
1395 goto nfs3err;
1396 }
1397
1398 nfs_request_user_init (&nfu, cs->req);
1399 ret = nfs_lookup (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
1400 nfs3svc_lookup_cbk, cs);
1401 if (ret < 0)
1402 stat = nfs3_errno_to_nfsstat3 (-ret);
1403
1404nfs3err:
1405 if (ret < 0) {
2
Taking true branch
1406 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_LOOKUP3,
3
Within the expansion of the macro 'rpcsvc_request_xid':
a
Access to field 'req' results in a dereference of a null pointer (loaded from variable 'cs')
1407 stat, -ret);
1408 nfs3_lookup_reply (cs->req, stat, &newfh, &cs->stbuf,
1409 &cs->postparent);
1410 nfs3_call_state_wipe (cs);
1411 }
1412
1413 return ret;
1414}
1415
1416
1417int
1418nfs3_lookup (rpcsvc_request_t *req, struct nfs3_fh *fh, int fhlen, char *name)
1419{
1420 xlator_t *vol = NULL((void*)0);
1421 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1422 int ret = -EFAULT14;
1423 struct nfs3_state *nfs3 = NULL((void*)0);
1424 nfs3_call_state_t *cs = NULL((void*)0);
1425
1426 GF_VALIDATE_OR_GOTO (GF_NFS3, req, out)do { if (!req) { (*__errno_location ()) = 22; do { do { if (0
) printf ("invalid argument: " "req"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1426, GF_LOG_ERROR, "invalid argument: "
"req"); } while (0); goto out; } } while (0)
;
1427 GF_VALIDATE_OR_GOTO (GF_NFS3, fh, out)do { if (!fh) { (*__errno_location ()) = 22; do { do { if (0)
printf ("invalid argument: " "fh"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1427, GF_LOG_ERROR, "invalid argument: "
"fh"); } while (0); goto out; } } while (0)
;
1428 GF_VALIDATE_OR_GOTO (GF_NFS3, name, out)do { if (!name) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "name"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1428, GF_LOG_ERROR, "invalid argument: "
"name"); } while (0); goto out; } } while (0)
;
1429
1430 nfs3_log_fh_entry_call (rpcsvc_request_xid (req)((req)->xid), "LOOKUP", fh,
1431 name);
1432 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1432, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
1433 if (nfs3_solaris_zerolen_fh (fh, fhlen))
1434 nfs3_funge_solaris_zerolen_fh (nfs3, fh, name, stat, nfs3err)do { xlator_t *fungexl = ((void*)0); uuid_t zero = {0, }; fungexl
=nfs_mntpath_to_xlator ((nfs3)->exportslist,name); if (!fungexl
) { (stat) = NFS3ERR_NOENT; goto nfs3err; } uuid_copy ((fh)->
gfid, zero); (fh)->gfid[15] = 1; (name) = ((void*)0); if (
((((struct nfs_state *)(nfs3->nfsx)->private)->dynamicvolumes
== 2))) (fh)->exportid[15] = nfs_xlator_to_xlid ((nfs3)->
exportslist, fungexl); else { if(__nfs3_get_volume_id ((nfs3)
, fungexl, (fh)->exportid) < 0) { (stat) = NFS3ERR_STALE
; goto nfs3err; } } } while (0)
;
1435 else
1436 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 1436, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
1437 nfs3_validate_strlen_or_goto (name, NFS_NAME_MAX, nfs3err, stat, ret)do { if ((name)) { if (strlen ((name)) > (255)) { do { do {
if (0) printf ("strlen " "too long"); } while (0); _gf_log (
"nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1437, GF_LOG_ERROR, "strlen "
"too long"); } while (0); stat = NFS3ERR_NAMETOOLONG; ret = -
36; goto nfs3err; } } } while (0);
;
1438 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 1438, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1438, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 1438, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
1439 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1439, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
1440 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
1440, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
1441
1442 cs->lookuptype = GF_NFS3_REVALIDATE;
1443 ret = nfs3_fh_resolve_and_resume (cs, fh, name,
1444 nfs3_lookup_resume);
1445
1446 if (ret < 0) {
1447 gf_log (GF_NFS, GF_LOG_ERROR, "failed to start hard reslove")do { do { if (0) printf ("failed to start hard reslove"); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1447, GF_LOG_ERROR
, "failed to start hard reslove"); } while (0)
;
1448 stat = nfs3_errno_to_nfsstat3 (-ret);
1449 }
1450
1451nfs3err:
1452 if (ret < 0) {
1453 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_LOOKUP3,
1454 stat,
1455 -ret);
1456 nfs3_lookup_reply (req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0));
1457 nfs3_call_state_wipe (cs);
1458 /* Ret must be 0 after this so that the caller does not
1459 * also send an RPC reply.
1460 */
1461 ret = 0;
1462 }
1463out:
1464 return ret;
1465}
1466
1467
1468int
1469nfs3svc_lookup (rpcsvc_request_t *req)
1470{
1471 char name[NFS_PATH_MAX4096];
1472 struct nfs3_fh fh = {{0}, };
1473 lookup3args args;
1474 int ret = RPCSVC_ACTOR_ERROR(-1);
1475
1476 GF_VALIDATE_OR_GOTO (GF_NFS, req, rpcerr)do { if (!req) { (*__errno_location ()) = 22; do { do { if (0
) printf ("invalid argument: " "req"); } while (0); _gf_log_callingfn
("nfs", "nfs3.c", __FUNCTION__, 1476, GF_LOG_ERROR, "invalid argument: "
"req"); } while (0); goto rpcerr; } } while (0)
;
1477
1478 nfs3_prep_lookup3args (&args, &fh, name);
1479 if (xdr_to_lookup3args (req->msg[0], &args) <= 0) {
1480 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1480, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
1481 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
1482 goto rpcerr;
1483 }
1484
1485 ret = nfs3_lookup (req, &fh, args.what.dir.data.data_len, name);
1486 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
1487 gf_log (GF_NFS3, GF_LOG_ERROR, "LOOKUP procedure failed")do { do { if (0) printf ("LOOKUP procedure failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1487, GF_LOG_ERROR
, "LOOKUP procedure failed"); } while (0)
;
1488 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
1489 ret = RPCSVC_ACTOR_ERROR(-1);
1490 }
1491
1492rpcerr:
1493 return ret;
1494}
1495
1496
1497int
1498nfs3_access_reply (rpcsvc_request_t *req, nfsstat3 status, int32_t accbits,
1499 int32_t reqaccbits)
1500{
1501 access3res res;
1502
1503 nfs3_fill_access3res (&res, status, accbits, reqaccbits);
1504 nfs3svc_submit_reply (req, &res,
1505 (nfs3_serializer)xdr_serialize_access3res);
1506 return 0;
1507}
1508
1509
1510int32_t
1511nfs3svc_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1512 int32_t op_ret, int32_t op_errno, dict_t *xdata)
1513{
1514 nfsstat3 status = NFS3_OK;
1515 nfs3_call_state_t *cs = NULL((void*)0);
1516
1517 cs = frame->local;
1518
1519 if (op_ret == -1) {
1520 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1522, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
1521 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1522, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
1522 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1522, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
1523 status = nfs3_errno_to_nfsstat3 (op_errno);
1524 }
1525 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_ACCESS4, status,
1526 op_errno);
1527 nfs3_access_reply (cs->req, status, op_errno, cs->accessbits);
1528 nfs3_call_state_wipe (cs);
1529
1530 return 0;
1531}
1532
1533int
1534nfs3_access_resume (void *carg)
1535{
1536 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1537 int ret = -EFAULT14;
1538 nfs_user_t nfu = {0, };
1539 nfs3_call_state_t *cs = NULL((void*)0);
1540
1541 GF_VALIDATE_OR_GOTO (GF_NFS3, carg, nfs3err)do { if (!carg) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "carg"); } while (0); _gf_log_callingfn
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1541, GF_LOG_ERROR, "invalid argument: "
"carg"); } while (0); goto nfs3err; } } while (0)
;
1542
1543 cs = (nfs3_call_state_t *)carg;
1544 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1544, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
1545 cs->fh = cs->resolvefh;
1546 nfs_request_user_init (&nfu, cs->req);
1547 ret = nfs_access (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
1548 cs->accessbits, nfs3svc_access_cbk, cs);
1549 if (ret < 0)
1550 stat = nfs3_errno_to_nfsstat3 (-ret);
1551
1552nfs3err:
1553 if (ret < 0) {
1554 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_ACCESS4,
1555 stat, -ret);
1556 nfs3_access_reply (cs->req, stat, 0, 0);
1557 nfs3_call_state_wipe (cs);
1558 ret = 0;
1559 }
1560
1561 return ret;
1562}
1563
1564
1565int
1566nfs3_access (rpcsvc_request_t *req, struct nfs3_fh *fh, uint32_t accbits)
1567{
1568 xlator_t *vol = NULL((void*)0);
1569 struct nfs3_state *nfs3 = NULL((void*)0);
1570 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1571 int ret = -EFAULT14;
1572 nfs3_call_state_t *cs = NULL((void*)0);
1573
1574 GF_VALIDATE_OR_GOTO (GF_NFS, req, out)do { if (!req) { (*__errno_location ()) = 22; do { do { if (0
) printf ("invalid argument: " "req"); } while (0); _gf_log_callingfn
("nfs", "nfs3.c", __FUNCTION__, 1574, GF_LOG_ERROR, "invalid argument: "
"req"); } while (0); goto out; } } while (0)
;
1575 GF_VALIDATE_OR_GOTO (GF_NFS, fh, out)do { if (!fh) { (*__errno_location ()) = 22; do { do { if (0)
printf ("invalid argument: " "fh"); } while (0); _gf_log_callingfn
("nfs", "nfs3.c", __FUNCTION__, 1575, GF_LOG_ERROR, "invalid argument: "
"fh"); } while (0); goto out; } } while (0)
;
1576 nfs3_log_common_call (rpcsvc_request_xid (req)((req)->xid), "ACCESS", fh);
1577 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 1577, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
1578 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1578, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
1579 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 1579, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1579, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 1579, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
1580 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1580, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
1581 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
1581, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
1582 cs->accessbits = accbits;
1583
1584 ret = nfs3_fh_resolve_and_resume (cs, fh, NULL((void*)0), nfs3_access_resume);
1585 if (ret < 0)
1586 stat = nfs3_errno_to_nfsstat3 (-ret);
1587
1588nfs3err:
1589 if (ret < 0) {
1590 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_ACCESS4,
1591 stat, -ret);
1592 nfs3_access_reply (req, stat, 0, 0);
1593 nfs3_call_state_wipe (cs);
1594 ret = 0;
1595 }
1596out:
1597 return ret;
1598}
1599
1600
1601int
1602nfs3svc_access (rpcsvc_request_t *req)
1603{
1604 struct nfs3_fh fh = {{0}, };
1605 access3args args;
1606 int ret = RPCSVC_ACTOR_ERROR(-1);
1607
1608 if (!req)
1609 return ret;
1610
1611 nfs3_prep_access3args (&args, &fh);
1612 if (xdr_to_access3args (req->msg[0], &args) <= 0) {
1613 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1613, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
1614 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
1615 goto rpcerr;
1616 }
1617
1618 ret = nfs3_access (req, &fh, args.access);
1619 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
1620 gf_log (GF_NFS3, GF_LOG_ERROR, "ACCESS procedure failed")do { do { if (0) printf ("ACCESS procedure failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1620, GF_LOG_ERROR
, "ACCESS procedure failed"); } while (0)
;
1621 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
1622 ret = RPCSVC_ACTOR_ERROR(-1);
1623 }
1624
1625rpcerr:
1626 return ret;
1627}
1628
1629
1630int
1631nfs3_readlink_reply (rpcsvc_request_t *req, nfsstat3 stat, char *path,
1632 struct iatt *buf)
1633{
1634 readlink3res res = {0, };
1635 uint64_t deviceid = 0;
1636
1637 deviceid = nfs3_request_xlator_deviceid (req);
1638 nfs3_fill_readlink3res (&res, stat, path, buf, deviceid);
1639 nfs3svc_submit_reply (req, (void *)&res,
1640 (nfs3_serializer)xdr_serialize_readlink3res);
1641
1642 return 0;
1643}
1644
1645
1646int32_t
1647nfs3svc_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1648 int32_t op_ret, int32_t op_errno, const char *path,
1649 struct iatt *buf, dict_t *xdata)
1650{
1651 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1652 nfs3_call_state_t *cs = NULL((void*)0);
1653
1654 cs = frame->local;
1655 if (op_ret == -1) {
1656 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1658, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
1657 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1658, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
1658 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1658, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
1659 stat = nfs3_errno_to_nfsstat3 (op_errno);
1660 goto nfs3err;
1661 }
1662
1663 stat = NFS3_OK;
1664
1665nfs3err:
1666 nfs3_log_readlink_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), stat, op_errno,
1667 (char *)path);
1668 nfs3_readlink_reply (cs->req, stat, (char *)path, buf);
1669 nfs3_call_state_wipe (cs);
1670
1671 return 0;
1672}
1673
1674
1675int
1676nfs3_readlink_resume (void *carg)
1677{
1678 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1679 int ret = -EFAULT14;
1680 nfs3_call_state_t *cs = NULL((void*)0);
1681 nfs_user_t nfu = {0, };
1682
1683 if (!carg)
1684 return ret;
1685
1686 cs = (nfs3_call_state_t *)carg;
1687 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1687, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
1688 nfs_request_user_init (&nfu, cs->req);
1689 ret = nfs_readlink (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
1690 nfs3svc_readlink_cbk, cs);
1691 if (ret < 0)
1692 stat = nfs3_errno_to_nfsstat3 (-ret);
1693
1694nfs3err:
1695 if (ret < 0) {
1696 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
1697 NFS3_READLINK5, stat, -ret);
1698 nfs3_readlink_reply (cs->req, stat, NULL((void*)0), NULL((void*)0));
1699 nfs3_call_state_wipe (cs);
1700 }
1701
1702 return ret;
1703}
1704
1705
1706int
1707nfs3_readlink (rpcsvc_request_t *req, struct nfs3_fh *fh)
1708{
1709 xlator_t *vol = NULL((void*)0);
1710 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1711 int ret = -EFAULT14;
1712 struct nfs3_state *nfs3 = NULL((void*)0);
1713 nfs3_call_state_t *cs = NULL((void*)0);
1714
1715 if ((!req) || (!fh)) {
1716 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1716, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
1717 return -1;
1718 }
1719
1720 nfs3_log_common_call (rpcsvc_request_xid (req)((req)->xid), "READLINK", fh);
1721 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 1721, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
1722 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1722, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
1723 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 1723, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1723, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 1723, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
1724 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1724, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
1725 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
1725, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
1726
1727 ret = nfs3_fh_resolve_and_resume (cs, fh, NULL((void*)0), nfs3_readlink_resume);
1728 if (ret < 0)
1729 stat = nfs3_errno_to_nfsstat3 (-ret);
1730
1731nfs3err:
1732 if (ret < 0) {
1733 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_READLINK5,
1734 stat, -ret);
1735 nfs3_readlink_reply (req, stat, NULL((void*)0), NULL((void*)0));
1736 nfs3_call_state_wipe (cs);
1737 /* Ret must be 0 after this so that the caller does not
1738 * also send an RPC reply.
1739 */
1740 ret = 0;
1741 }
1742out:
1743 return ret;
1744}
1745
1746
1747int
1748nfs3svc_readlink (rpcsvc_request_t *req)
1749{
1750 struct nfs3_fh fh = {{0}, };
1751 readlink3args args;
1752 int ret = RPCSVC_ACTOR_ERROR(-1);
1753
1754 if (!req)
1755 return ret;
1756
1757 nfs3_prep_readlink3args (&args, &fh);
1758 if (xdr_to_readlink3args (req->msg[0], &args) <= 0) {
1759 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1759, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
1760 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
1761 goto rpcerr;
1762 }
1763
1764 ret = nfs3_readlink (req, &fh);
1765 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
1766 gf_log (GF_NFS3, GF_LOG_ERROR, "READLINK procedure failed")do { do { if (0) printf ("READLINK procedure failed"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1766, GF_LOG_ERROR
, "READLINK procedure failed"); } while (0)
;
1767 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
1768 ret = RPCSVC_ACTOR_ERROR(-1);
1769 }
1770
1771rpcerr:
1772 return ret;
1773}
1774
1775
1776int
1777nfs3_read_reply (rpcsvc_request_t *req, nfsstat3 stat, count3 count,
1778 struct iovec *vec, int vcount, struct iobref *iobref,
1779 struct iatt *poststat, int is_eof)
1780{
1781 read3res res = {0, };
1782 uint64_t deviceid = 0;
1783
1784 deviceid = nfs3_request_xlator_deviceid (req);
1785 nfs3_fill_read3res (&res, stat, count, poststat, is_eof, deviceid);
1786 if (stat == NFS3_OK) {
1787 xdr_vector_round_up (vec, vcount, count);
1788 /* iob can be zero if the file size was zero. If so, op_ret
1789 * would be 0 and count = 0.
1790 */
1791
1792 if (count != 0) {
1793 nfs3svc_submit_vector_reply (req, (void *)&res,
1794 (nfs3_serializer)
1795 xdr_serialize_read3res_nocopy,
1796 vec, vcount, iobref);
1797 } else
1798
1799 nfs3svc_submit_reply (req, (void *)&res,
1800 (nfs3_serializer)
1801 xdr_serialize_read3res_nocopy);
1802 } else
1803 nfs3svc_submit_reply (req, (void *)&res,
1804 (nfs3_serializer)
1805 xdr_serialize_read3res_nocopy);
1806
1807 return 0;
1808}
1809
1810
1811int32_t
1812nfs3svc_read_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1813 int32_t op_ret, int32_t op_errno, struct iovec *vector,
1814 int32_t count, struct iatt *stbuf, struct iobref *iobref,
1815 dict_t *xdata)
1816{
1817 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1818 int is_eof = 0;
1819 nfs3_call_state_t *cs = NULL((void*)0);
1820
1821 cs = frame->local;
1822 if (op_ret == -1) {
1823 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1825, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
1824 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1825, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
1825 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 1825, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
1826 stat = nfs3_errno_to_nfsstat3 (op_errno);
1827 goto err;
1828 } else
1829 stat = NFS3_OK;
1830
1831 if (op_errno == ENOENT2)
1832 is_eof = 1;
1833
1834err:
1835 nfs3_log_read_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), stat, op_errno,
1836 op_ret, is_eof, vector, count);
1837 nfs3_read_reply (cs->req, stat, op_ret, vector, count, iobref, stbuf,
1838 is_eof);
1839 nfs3_call_state_wipe (cs);
1840
1841 return 0;
1842}
1843
1844
1845int
1846nfs3_read_fd_resume (void *carg)
1847{
1848 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1849 int ret = -EFAULT14;
1850 nfs_user_t nfu = {0, };
1851 nfs3_call_state_t *cs = NULL((void*)0);
1852
1853 if (!carg)
1854 return ret;
1855
1856 cs = (nfs3_call_state_t *)carg;
1857 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1857, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
1858 nfs_request_user_init (&nfu, cs->req);
1859 ret = nfs_read (cs->nfsx, cs->vol, &nfu, cs->fd, cs->datacount,
1860 cs->dataoffset, nfs3svc_read_cbk, cs);
1861 if (ret < 0)
1862 stat = nfs3_errno_to_nfsstat3 (-ret);
1863nfs3err:
1864 if (ret < 0) {
1865 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_READ6,
1866 stat, -ret);
1867 nfs3_read_reply (cs->req, stat, 0, NULL((void*)0), 0, NULL((void*)0), NULL((void*)0), 0);
1868 nfs3_call_state_wipe (cs);
1869 }
1870
1871 return ret;
1872}
1873
1874
1875int
1876nfs3_read_resume (void *carg)
1877{
1878 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1879 int ret = -EFAULT14;
1880 nfs3_call_state_t *cs = NULL((void*)0);
1881 fd_t *fd = NULL((void*)0);
1882
1883 if (!carg)
1884 return ret;
1885
1886 cs = (nfs3_call_state_t *)carg;
1887 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1887, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
1888 fd = fd_anonymous (cs->resolvedloc.inode);
1889 if (!fd) {
1890 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to create anonymous fd")do { do { if (0) printf ("Failed to create anonymous fd"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1890, GF_LOG_ERROR
, "Failed to create anonymous fd"); } while (0)
;
1891 goto nfs3err;
1892 }
1893
1894 cs->fd = fd;
1895 nfs3_read_fd_resume (cs);
1896 ret = 0;
1897nfs3err:
1898 if (ret < 0) {
1899 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_READ6,
1900 stat, -ret);
1901 nfs3_read_reply (cs->req, stat, 0, NULL((void*)0),0, NULL((void*)0), NULL((void*)0), 0);
1902 nfs3_call_state_wipe (cs);
1903 }
1904
1905 return ret;
1906}
1907
1908int
1909nfs3_read (rpcsvc_request_t *req, struct nfs3_fh *fh, offset3 offset,
1910 count3 count)
1911{
1912 xlator_t *vol = NULL((void*)0);
1913 nfsstat3 stat = NFS3ERR_SERVERFAULT;
1914 int ret = -EFAULT14;
1915 struct nfs3_state *nfs3 = NULL((void*)0);
1916 nfs3_call_state_t *cs = NULL((void*)0);
1917
1918 if ((!req) || (!fh)) {
1919 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1919, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
1920 return -1;
1921 }
1922
1923 nfs3_log_rw_call (rpcsvc_request_xid (req)((req)->xid), "READ", fh, offset,
1924 count, -1);
1925 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 1925, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
1926 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1926, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
1927 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 1927, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1927, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 1927, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
1928 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 1928, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
1929 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
1929, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
1930
1931 cs->datacount = count;
1932 cs->dataoffset = offset;
1933 ret = nfs3_fh_resolve_and_resume (cs, fh, NULL((void*)0), nfs3_read_resume);
1934 if (ret < 0)
1935 stat = nfs3_errno_to_nfsstat3 (-ret);
1936
1937nfs3err:
1938 if (ret < 0) {
1939 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_READ6, stat,
1940 -ret);
1941 nfs3_read_reply (req, stat, 0, NULL((void*)0),0, NULL((void*)0), NULL((void*)0), 0);
1942 nfs3_call_state_wipe (cs);
1943 ret = 0;
1944 }
1945out:
1946 return ret;
1947}
1948
1949
1950int
1951nfs3svc_read (rpcsvc_request_t *req)
1952{
1953 struct nfs3_fh fh = {{0}, };
1954 read3args args;
1955 int ret = RPCSVC_ACTOR_ERROR(-1);
1956
1957 if (!req)
1958 return ret;
1959
1960 nfs3_prep_read3args (&args, &fh);
1961 if (xdr_to_read3args (req->msg[0], &args) <= 0) {
1962 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1962, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
1963 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
1964 goto rpcerr;
1965 }
1966
1967 ret = nfs3_read (req, &fh, args.offset, args.count);
1968 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
1969 gf_log (GF_NFS3, GF_LOG_ERROR, "READ procedure failed")do { do { if (0) printf ("READ procedure failed"); } while (0
); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 1969, GF_LOG_ERROR
, "READ procedure failed"); } while (0)
;
1970 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
1971 ret = RPCSVC_ACTOR_ERROR(-1);
1972 }
1973
1974rpcerr:
1975 return ret;
1976}
1977
1978
1979int
1980nfs3_write_reply (rpcsvc_request_t *req, nfsstat3 stat, count3 count,
1981 stable_how stable, uint64_t wverf, struct iatt *prestat,
1982 struct iatt *poststat)
1983{
1984 write3res res = {0, };
1985 uint64_t deviceid = 0;
1986
1987 deviceid = nfs3_request_xlator_deviceid (req);
1988 nfs3_fill_write3res (&res, stat, count, stable, wverf, prestat,
1989 poststat, deviceid);
1990 nfs3svc_submit_reply (req, (void *)&res,
1991 (nfs3_serializer)xdr_serialize_write3res);
1992
1993 return 0;
1994}
1995
1996int32_t
1997nfs3svc_write_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1998 int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
1999 struct iatt *postbuf, dict_t *xdata)
2000{
2001 struct nfs3_state *nfs3 = NULL((void*)0);
2002 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2003 nfs3_call_state_t *cs = NULL((void*)0);
2004
2005 cs = frame->local;
2006 nfs3 = rpcsvc_request_program_private (cs->req)(((rpcsvc_program_t *)((cs->req)->prog))->private);
2007
2008 if (op_ret == -1) {
2009 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2011, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2010 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2011, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2011 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2011, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
2012 stat = nfs3_errno_to_nfsstat3 (op_errno);
2013 } else
2014 stat = NFS3_OK;
2015
2016 nfs3_log_write_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), stat, op_errno,
2017 cs->maxcount, cs->writetype, nfs3->serverstart);
2018 nfs3_write_reply (cs->req, stat, cs->maxcount, cs->writetype,
2019 nfs3->serverstart, &cs->stbuf, postbuf);
2020 nfs3_call_state_wipe (cs);
2021 return 0;
2022}
2023
2024
2025
2026/*
2027 * Before going into the write reply logic, here is a matrix that shows the
2028 * requirements for a write reply as given by RFC1813.
2029 *
2030 * Requested Write Type || Possible Returns
2031 * ==============================================
2032 * FILE_SYNC || FILE_SYNC
2033 * DATA_SYNC || DATA_SYNC or FILE_SYNC
2034 * UNSTABLE || DATA_SYNC or FILE_SYNC or UNSTABLE
2035 *
2036 * Write types other than UNSTABLE are together called STABLE.
2037 * RS - Return Stable
2038 * RU - Return Unstable
2039 * WS - Write Stable
2040 * WU - Write Unstable
2041 *
2042 *+============================================+
2043 *| Vol Opts -> || trusted-write| trusted-sync |
2044 *| Write Type || | |
2045 *|-------------||--------------|--------------|
2046 *| STABLE || WS | WU |
2047 *| || RS | RS |
2048 *|-------------||--------------|--------------|
2049 *| UNSTABLE || WU | WU |
2050 *| || RS | RS |
2051 *|-------------||--------------|--------------|
2052 *| COMMIT || fsync | getattr |
2053 *+============================================+
2054 *
2055 *
2056 */
2057int32_t
2058nfs3svc_write_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
2059 int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
2060 struct iatt *postbuf, dict_t *xdata)
2061{
2062 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2063 nfs3_call_state_t *cs = NULL((void*)0);
2064 struct nfs3_state *nfs3 = NULL((void*)0);
2065
2066 cs = frame->local;
2067 nfs3 = rpcsvc_request_program_private (cs->req)(((rpcsvc_program_t *)((cs->req)->prog))->private);
2068 if (op_ret == -1) {
2069 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2071, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2070 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2071, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2071 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2071, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
2072 stat = nfs3_errno_to_nfsstat3 (op_errno);
2073 goto err;
2074 }
2075
2076 stat = NFS3_OK;
2077 cs->maxcount = op_ret;
2078
2079err:
2080 nfs3_log_write_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), stat,
2081 op_errno, cs->maxcount, cs->writetype,
2082 nfs3->serverstart);
2083 nfs3_write_reply (cs->req, stat, cs->maxcount,
2084 cs->writetype, nfs3->serverstart, prebuf,
2085 postbuf);
2086 nfs3_call_state_wipe (cs);
2087
2088 return 0;
2089}
2090
2091
2092int
2093__nfs3_write_resume (nfs3_call_state_t *cs)
2094{
2095 int ret = -EFAULT14;
2096 nfs_user_t nfu = {0, };
2097
2098 if (!cs)
2099 return ret;
2100
2101 nfs_request_user_init (&nfu, cs->req);
2102 /* It is possible that the RPC record contains more bytes than
2103 * than the size of write requested in this request. This means,
2104 * that in the RPC message buffer, there could be more bytes
2105 * beyind the @count bytes. Since @payload is referring to the write
2106 * data directly inside the RPC request buffer(..since we performed a
2107 * no-copy deXDRing..), we might end up writing more data than
2108 * requested, because till now payload.iov_len accounts for all the
2109 * bytes not just the write request bytes. These extra bytes are present
2110 * as a requirement of the XDR encoding to round up the all string and
2111 * opaque data buffers to multiples of 4 bytes.
2112 */
2113 cs->datavec.iov_len = cs->datacount;
2114 ret = nfs_write (cs->nfsx, cs->vol, &nfu, cs->fd, cs->iobref,
2115 &cs->datavec, 1, cs->dataoffset, nfs3svc_write_cbk,
2116 cs);
2117
2118 return ret;
2119}
2120
2121
2122int
2123nfs3_write_resume (void *carg)
2124{
2125 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2126 int ret = -EFAULT14;
2127 nfs3_call_state_t *cs = NULL((void*)0);
2128 fd_t *fd = NULL((void*)0);
2129
2130 if (!carg)
2131 return ret;
2132
2133 cs = (nfs3_call_state_t *)carg;
2134 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 2134, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
2135 fd = fd_anonymous (cs->resolvedloc.inode);
2136 if (!fd) {
2137 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to create anonymous fd")do { do { if (0) printf ("Failed to create anonymous fd"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2137, GF_LOG_ERROR
, "Failed to create anonymous fd"); } while (0)
;
2138 goto nfs3err;
2139 }
2140
2141 cs->fd = fd; /* Gets unrefd when the call state is wiped. */
2142
2143/*
2144 enum stable_how {
2145 UNSTABLE = 0,
2146 DATA_SYNC = 1,
2147 FILE_SYNC = 2,
2148 };
2149*/
2150 switch (cs->writetype) {
2151 case UNSTABLE:
2152 break;
2153 case DATA_SYNC:
2154 fd->flags |= O_DSYNC010000;
2155 break;
2156 case FILE_SYNC:
2157 fd->flags |= O_SYNC04010000;
2158 break;
2159 }
2160
2161 ret = __nfs3_write_resume (cs);
2162 if (ret < 0)
2163 stat = nfs3_errno_to_nfsstat3 (-ret);
2164nfs3err:
2165 if (ret < 0) {
2166 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_WRITE7,
2167 stat, -ret);
2168 nfs3_write_reply (cs->req, stat, 0, cs->writetype, 0, NULL((void*)0),
2169 NULL((void*)0));
2170 nfs3_call_state_wipe (cs);
2171 }
2172 return ret;
2173}
2174
2175
2176int
2177nfs3_write (rpcsvc_request_t *req, struct nfs3_fh *fh, offset3 offset,
2178 count3 count, stable_how stable, struct iovec payload,
2179 struct iobref *iobref)
2180{
2181 xlator_t *vol = NULL((void*)0);
2182 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2183 int ret = -EFAULT14;
2184 struct nfs3_state *nfs3 = NULL((void*)0);
2185 nfs3_call_state_t *cs = NULL((void*)0);
2186
2187 if ((!req) || (!fh) || (!payload.iov_base)) {
2188 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2188, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
2189 return -1;
2190 }
2191
2192 nfs3_log_rw_call (rpcsvc_request_xid (req)((req)->xid), "WRITE", fh, offset,
2193 count, stable);
2194 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 2194, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
2195 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 2195, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
2196 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 2196, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2196, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 2196, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
2197 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 2197, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
2198 nfs3_check_rw_volaccess (nfs3, fh->exportid, stat, nfs3err)do { if (nfs3_export_access (nfs3,fh->exportid)!=1){ do { do
{ if (0) printf ("No read-write access"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2198, GF_LOG_ERROR, "No read-write access"
); } while (0); stat = NFS3ERR_ROFS; goto nfs3err; } } while (
0)
;
2199 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
2199, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
2200 cs->datacount = count;
2201 cs->dataoffset = offset;
2202 cs->writetype = stable;
2203 cs->iobref = iobref;
2204 cs->datavec = payload;
2205
2206
2207 ret = nfs3_fh_resolve_and_resume (cs, fh, NULL((void*)0), nfs3_write_resume);
2208 if (ret < 0)
2209 stat = nfs3_errno_to_nfsstat3 (-ret);
2210
2211nfs3err:
2212 if (ret < 0) {
2213 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_WRITE7,
2214 stat, -ret);
2215 nfs3_write_reply (req, stat, 0, stable, 0, NULL((void*)0), NULL((void*)0));
2216 nfs3_call_state_wipe (cs);
2217 ret = 0;
2218 }
2219out:
2220 return ret;
2221}
2222
2223#define NFS3_VECWRITE_READFHLEN1 1
2224#define NFS3_VECWRITE_READFH2 2
2225#define NFS3_VECWRITE_READREST3 3
2226
2227#define NFS3_WRITE_POSTFH_SIZE20 20
2228
2229
2230int
2231nfs3svc_write_vecsizer (int state, ssize_t *readsize, char *base_addr,
2232 char *curr_addr)
2233{
2234 int ret = 0;
2235 uint32_t fhlen = 0;
2236 uint32_t fhlen_n = 0;
2237
2238 if (state == 0) {
2239 ret = NFS3_VECWRITE_READFHLEN1;
2240 *readsize = 4;
2241 } else if (state == NFS3_VECWRITE_READFHLEN1) {
2242 fhlen_n = *(uint32_t *)(curr_addr - 4);
2243 fhlen = ntohl (fhlen_n);
2244 *readsize = xdr_length_round_up (fhlen, NFS3_FHSIZE64);
2245 ret = NFS3_VECWRITE_READFH2;
2246 } else if (state == NFS3_VECWRITE_READFH2) {
2247 *readsize = NFS3_WRITE_POSTFH_SIZE20;
2248 ret = NFS3_VECWRITE_READREST3;
2249 } else if (state == NFS3_VECWRITE_READREST3) {
2250 ret = 0;
2251 *readsize = 0;
2252 } else
2253 gf_log ("nfs", GF_LOG_ERROR, "state wrong")do { do { if (0) printf ("state wrong"); } while (0); _gf_log
("nfs", "nfs3.c", __FUNCTION__, 2253, GF_LOG_ERROR, "state wrong"
); } while (0)
;
2254
2255 return ret;
2256}
2257
2258
2259int
2260nfs3svc_write (rpcsvc_request_t *req)
2261{
2262 struct nfs3_fh fh = {{0}, };
2263 write3args args;
2264 int ret = RPCSVC_ACTOR_ERROR(-1);
2265
2266 if (!req)
2267 return ret;
2268 nfs3_prep_write3args (&args, &fh);
2269 if (xdr_to_write3args (req->msg[0], &args) <= 0) {
2270 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2270, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
2271 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
2272 goto rpcerr;
2273 }
2274
2275 /* To ensure that the iobuf for the current record does not
2276 * get returned to the iobpool, we need to keep a reference for
2277 * ourselves because the RPC call handler who called us will unref its
2278 * own ref of the record's iobuf when it is done handling the request.
2279 */
2280
2281 ret = nfs3_write (req, &fh, args.offset, args.count, args.stable,
2282 req->msg[1], rpcsvc_request_iobref_ref (req)(iobref_ref ((req)->iobref)));
2283 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
2284 gf_log (GF_NFS3, GF_LOG_ERROR, "WRITE procedure failed")do { do { if (0) printf ("WRITE procedure failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2284, GF_LOG_ERROR
, "WRITE procedure failed"); } while (0)
;
2285 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
2286 ret = RPCSVC_ACTOR_ERROR(-1);
2287 }
2288
2289rpcerr:
2290 return ret;
2291}
2292
2293
2294int
2295nfs3_create_reply (rpcsvc_request_t *req, nfsstat3 stat, struct nfs3_fh *newfh,
2296 struct iatt *newbuf, struct iatt *preparent,
2297 struct iatt *postparent)
2298{
2299 create3res res = {0, };
2300 uint64_t deviceid = 0;
2301
2302 deviceid = nfs3_request_xlator_deviceid (req);
2303 nfs3_fill_create3res (&res, stat, newfh, newbuf, preparent, postparent,
2304 deviceid);
2305 nfs3svc_submit_reply (req, (void *)&res,
2306 (nfs3_serializer)xdr_serialize_create3res);
2307 return 0;
2308}
2309
2310
2311int32_t
2312nfs3svc_create_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
2313 int32_t op_ret, int32_t op_errno,
2314 struct iatt *preop, struct iatt *postop, dict_t *xdata)
2315{
2316 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2317 nfs3_call_state_t *cs = NULL((void*)0);
2318
2319 cs = frame->local;
2320 if (op_ret == -1) {
2321 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2323, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2322 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2323, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2323 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2323, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
2324 stat = nfs3_errno_to_nfsstat3 (op_errno);
2325 goto nfs3err;
2326 }
2327
2328 stat = NFS3_OK;
2329nfs3err:
2330 nfs3_log_newfh_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_CREATE8, stat,
2331 op_errno, &cs->fh);
2332 nfs3_create_reply (cs->req, stat, &cs->fh, postop, &cs->preparent,
2333 &cs->postparent);
2334 nfs3_call_state_wipe (cs);
2335
2336 return 0;
2337}
2338
2339
2340int32_t
2341nfs3svc_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
2342 int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode,
2343 struct iatt *buf, struct iatt *preparent,
2344 struct iatt *postparent, dict_t *xdata)
2345{
2346 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2347 int ret = -EFAULT14;
2348 nfs_user_t nfu = {0, };
2349 nfs3_call_state_t *cs = NULL((void*)0);
2350 inode_t *oldinode = NULL((void*)0);
2351
2352 cs = frame->local;
2353 if (op_ret == -1) {
2354 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2356, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2355 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2356, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2356 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2356, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
2357 stat = nfs3_errno_to_nfsstat3 (op_errno);
2358 goto nfs3err;
2359 }
2360
2361 nfs3_fh_build_child_fh (&cs->parent, buf, &cs->fh);
2362 oldinode = inode_link (inode, cs->resolvedloc.parent,
2363 cs->resolvedloc.name, buf);
2364
2365 /* Means no attributes were required to be set. */
2366 if (!cs->setattr_valid) {
2367 stat = NFS3_OK;
2368 ret = -1;
2369 goto nfs3err;
2370 }
2371
2372 cs->preparent = *preparent;
2373 cs->postparent = *postparent;
2374 nfs_request_user_init (&nfu, cs->req);
2375 uuid_copy (cs->resolvedloc.gfid, inode->gfid);
2376 ret = nfs_setattr (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,&cs->stbuf,
2377 cs->setattr_valid, nfs3svc_create_setattr_cbk, cs);
2378 if (ret < 0)
2379 stat = nfs3_errno_to_nfsstat3 (-ret);
2380
2381nfs3err:
2382 if (oldinode) {
2383 inode_lookup (oldinode);
2384 inode_unref (oldinode);
2385 }
2386
2387 if (ret < 0) {
2388 nfs3_log_newfh_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_CREATE8,
2389 stat, op_errno, &cs->fh);
2390 nfs3_create_reply (cs->req, stat, &cs->fh, buf, preparent,
2391 postparent);
2392 nfs3_call_state_wipe (cs);
2393 }
2394
2395 return 0;
2396}
2397
2398int
2399nfs3_create_common (nfs3_call_state_t *cs)
2400{
2401 int ret = -EFAULT14;
2402 int flags = 0;
2403 nfs_user_t nfu = {0, };
2404 uid_t uid = 0;
2405 gid_t gid = 0;
2406
2407 if (!cs)
2408 return ret;
2409
2410 if (cs->createmode == GUARDED)
2411 flags = (O_RDWR02 | O_EXCL0200);
2412 else
2413 flags = O_RDWR02;
2414
2415 if (gf_attr_uid_set (cs->setattr_valid)((cs->setattr_valid) & 0x2)) {
2416 uid = cs->stbuf.ia_uid;
2417 cs->setattr_valid &= ~GF_SET_ATTR_UID0x2;
2418 } else
2419 uid = rpcsvc_request_uid (cs->req)((cs->req)->uid);
2420
2421 if (gf_attr_gid_set (cs->setattr_valid)((cs->setattr_valid) & 0x4)) {
2422 gid = cs->stbuf.ia_gid;
2423 cs->setattr_valid &= ~GF_SET_ATTR_GID0x4;
2424 } else
2425 gid = rpcsvc_request_gid (cs->req)((cs->req)->gid);
2426
2427 nfs_request_primary_user_init (&nfu, cs->req, uid, gid);
2428 /* We can avoid sending the setattr call later if only the mode is
2429 * required to be set. This is possible because the create fop allows
2430 * us to specify a mode arg.
2431 */
2432 if (cs->setattr_valid & GF_SET_ATTR_MODE0x1) {
2433 cs->setattr_valid &= ~GF_SET_ATTR_MODE0x1;
2434 ret = nfs_create (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
2435 flags, cs->mode, nfs3svc_create_cbk, cs);
2436 } else
2437 ret = nfs_create (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
2438 flags, NFS_DEFAULT_CREATE_MODE0600,
2439 nfs3svc_create_cbk, cs);
2440
2441 return ret;
2442}
2443
2444
2445int32_t
2446nfs3svc_create_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
2447 int32_t op_ret, int32_t op_errno, struct iatt *buf,
2448 dict_t *xdata)
2449{
2450 int ret = -EFAULT14;
2451 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2452 nfs_user_t nfu = {0, };
2453 nfs3_call_state_t *cs = NULL((void*)0);
2454
2455 cs = frame->local;
2456 nfs_request_user_init (&nfu, cs->req);
2457 if (op_ret == -1) {
2458 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2460, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2459 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2460, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2460 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2460, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
2461 ret = -op_errno;
2462 stat = nfs3_errno_to_nfsstat3 (op_errno);
2463 goto nfs3err;
2464 }
2465
2466 if ((cs->stbuf.ia_mtime == buf->ia_mtime) &&
2467 (cs->stbuf.ia_atime == buf->ia_atime)) {
2468 gf_log (GF_NFS3, GF_LOG_DEBUG,do { do { if (0) printf ("Create req retransmitted verf %x %x"
, cs->stbuf.ia_mtime, cs->stbuf.ia_atime); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2470, GF_LOG_DEBUG
, "Create req retransmitted verf %x %x", cs->stbuf.ia_mtime
, cs->stbuf.ia_atime); } while (0)
2469 "Create req retransmitted verf %x %x",do { do { if (0) printf ("Create req retransmitted verf %x %x"
, cs->stbuf.ia_mtime, cs->stbuf.ia_atime); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2470, GF_LOG_DEBUG
, "Create req retransmitted verf %x %x", cs->stbuf.ia_mtime
, cs->stbuf.ia_atime); } while (0)
2470 cs->stbuf.ia_mtime, cs->stbuf.ia_atime)do { do { if (0) printf ("Create req retransmitted verf %x %x"
, cs->stbuf.ia_mtime, cs->stbuf.ia_atime); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2470, GF_LOG_DEBUG
, "Create req retransmitted verf %x %x", cs->stbuf.ia_mtime
, cs->stbuf.ia_atime); } while (0)
;
2471 stat = NFS3_OK;
2472 nfs3_fh_build_child_fh (&cs->parent, buf, &cs->fh);
2473 } else {
2474 gf_log (GF_NFS3, GF_LOG_DEBUG,do { do { if (0) printf ("File already exist new_verf %x %x" "old_verf %x %x"
, cs->stbuf.ia_mtime, cs->stbuf.ia_atime, buf->ia_mtime
, buf->ia_atime); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 2478, GF_LOG_DEBUG, "File already exist new_verf %x %x"
"old_verf %x %x", cs->stbuf.ia_mtime, cs->stbuf.ia_atime
, buf->ia_mtime, buf->ia_atime); } while (0)
2475 "File already exist new_verf %x %x"do { do { if (0) printf ("File already exist new_verf %x %x" "old_verf %x %x"
, cs->stbuf.ia_mtime, cs->stbuf.ia_atime, buf->ia_mtime
, buf->ia_atime); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 2478, GF_LOG_DEBUG, "File already exist new_verf %x %x"
"old_verf %x %x", cs->stbuf.ia_mtime, cs->stbuf.ia_atime
, buf->ia_mtime, buf->ia_atime); } while (0)
2476 "old_verf %x %x", cs->stbuf.ia_mtime,do { do { if (0) printf ("File already exist new_verf %x %x" "old_verf %x %x"
, cs->stbuf.ia_mtime, cs->stbuf.ia_atime, buf->ia_mtime
, buf->ia_atime); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 2478, GF_LOG_DEBUG, "File already exist new_verf %x %x"
"old_verf %x %x", cs->stbuf.ia_mtime, cs->stbuf.ia_atime
, buf->ia_mtime, buf->ia_atime); } while (0)
2477 cs->stbuf.ia_atime,do { do { if (0) printf ("File already exist new_verf %x %x" "old_verf %x %x"
, cs->stbuf.ia_mtime, cs->stbuf.ia_atime, buf->ia_mtime
, buf->ia_atime); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 2478, GF_LOG_DEBUG, "File already exist new_verf %x %x"
"old_verf %x %x", cs->stbuf.ia_mtime, cs->stbuf.ia_atime
, buf->ia_mtime, buf->ia_atime); } while (0)
2478 buf->ia_mtime, buf->ia_atime)do { do { if (0) printf ("File already exist new_verf %x %x" "old_verf %x %x"
, cs->stbuf.ia_mtime, cs->stbuf.ia_atime, buf->ia_mtime
, buf->ia_atime); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 2478, GF_LOG_DEBUG, "File already exist new_verf %x %x"
"old_verf %x %x", cs->stbuf.ia_mtime, cs->stbuf.ia_atime
, buf->ia_mtime, buf->ia_atime); } while (0)
;
2479 stat = NFS3ERR_EXIST;
2480 }
2481
2482nfs3err:
2483 if (ret < 0) {
2484 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_CREATE8,
2485 stat, op_errno);
2486 nfs3_create_reply (cs->req, stat, &cs->fh, buf, NULL((void*)0), NULL((void*)0));
2487 nfs3_call_state_wipe (cs);
2488 }
2489
2490 return 0;
2491}
2492
2493
2494int
2495nfs3_create_exclusive (nfs3_call_state_t *cs)
2496{
2497 int ret = -EFAULT14;
2498 nfs_user_t nfu = {0, };
2499
2500 if (!cs)
2501 return ret;
2502
2503 /* Storing verifier as a mtime and atime attribute, to store it
2504 * in stable storage */
2505 memcpy (&cs->stbuf.ia_atime, &cs->cookieverf,
2506 sizeof (cs->stbuf.ia_atime));
2507 memcpy (&cs->stbuf.ia_mtime,
2508 ((char *) &cs->cookieverf) + sizeof (cs->stbuf.ia_atime),
2509 sizeof (cs->stbuf.ia_mtime));
2510 cs->setattr_valid |= GF_SET_ATTR_ATIME0x10;
2511 cs->setattr_valid |= GF_SET_ATTR_MTIME0x20;
2512 nfs_request_user_init (&nfu, cs->req);
2513
2514 /* If the file already existed we need to get that attributes so we can
2515 * compare and check whether a previous create operation was
2516 * interrupted due to server failure or dropped packets.
2517 */
2518 if ((cs->resolve_ret == 0) ||
2519 ((cs->resolve_ret == -1) && (cs->resolve_errno != ENOENT2))) {
2520 ret = nfs_stat (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
2521 nfs3svc_create_stat_cbk, cs);
2522 goto nfs3err;
2523 }
2524
2525 ret = nfs3_create_common (cs);
2526nfs3err:
2527 return ret;
2528}
2529
2530
2531int
2532nfs3_create_resume (void *carg)
2533{
2534 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2535 int ret = -EFAULT14;
2536 nfs3_call_state_t *cs = NULL((void*)0);
2537
2538 if (!carg)
2539 return ret;
2540
2541 cs = (nfs3_call_state_t *)carg;
2542 nfs3_check_new_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if (((cs)->resolve_ret
< 0) && ((cs)->resolve_errno != 2)) { trans = (
(cs->req)->trans); xlatorp = nfs3_fh_to_xlator (cs->
nfs3state, &cs->resolvefh); uuid_unparse (cs->resolvefh
.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->peerinfo
.identifier, xlatorp ? xlatorp->name : "ERR", gfid); do { do
{ if (0) printf ("Unable to resolve FH" ": %s", buf); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2542, GF_LOG_ERROR
, "Unable to resolve FH" ": %s", buf); } while (0); stat = nfs3_errno_to_nfsstat3
(cs->resolve_errno); goto nfs3err; } } while (0)
;
2543 if (cs->createmode == EXCLUSIVE)
2544 ret = nfs3_create_exclusive (cs);
2545 else
2546 ret = nfs3_create_common (cs);
2547
2548 /* Handle a failure return from either of the create functions above. */
2549 if (ret < 0)
2550 stat = nfs3_errno_to_nfsstat3 (-ret);
2551
2552nfs3err:
2553 if (ret < 0) {
2554 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_CREATE8,
2555 stat, -ret);
2556 nfs3_create_reply (cs->req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
2557 nfs3_call_state_wipe (cs);
2558 }
2559
2560 return ret;
2561}
2562
2563int
2564nfs3_create (rpcsvc_request_t *req, struct nfs3_fh *dirfh, char *name,
2565 createmode3 mode, sattr3 *sattr, uint64_t cverf)
2566{
2567 xlator_t *vol = NULL((void*)0);
2568 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2569 int ret = -EFAULT14;
2570 struct nfs3_state *nfs3 = NULL((void*)0);
2571 nfs3_call_state_t *cs = NULL((void*)0);
2572
2573 if ((!req) || (!dirfh) || (!name) || (!sattr))
2574 return -1;
2575
2576 nfs3_log_create_call (rpcsvc_request_xid (req)((req)->xid), dirfh, name, mode);
2577 nfs3_validate_gluster_fh (dirfh, stat, nfs3err)do { if ((dirfh)) { if (!nfs3_fh_validate (dirfh)) { do { do {
if (0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 2577, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
2578 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 2578, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
2579 nfs3_validate_strlen_or_goto (name, NFS_NAME_MAX, nfs3err, stat, ret)do { if ((name)) { if (strlen ((name)) > (255)) { do { do {
if (0) printf ("strlen " "too long"); } while (0); _gf_log (
"nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2579, GF_LOG_ERROR, "strlen "
"too long"); } while (0); stat = NFS3ERR_NAMETOOLONG; ret = -
36; goto nfs3err; } } } while (0);
;
2580 nfs3_map_fh_to_volume (nfs3, dirfh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), dirfh); if (!vol)
{ uuid_unparse (dirfh->exportid, exportid); uuid_unparse (
dirfh->gfid, gfid); trans = ((req)->trans); do { do { if
(0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2580, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 2580, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 2580, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
2581 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 2581, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
2582 nfs3_check_rw_volaccess (nfs3, dirfh->exportid, stat, nfs3err)do { if (nfs3_export_access (nfs3,dirfh->exportid)!=1){ do
{ do { if (0) printf ("No read-write access"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2582, GF_LOG_ERROR, "No read-write access"
); } while (0); stat = NFS3ERR_ROFS; goto nfs3err; } } while (
0)
;
2583 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
2583, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
2584
2585 cs->cookieverf = cverf;
2586 /*In Exclusive create client is supposed to send cverf instead of
2587 * sattr*/
2588 if (mode != EXCLUSIVE)
2589 cs->setattr_valid = nfs3_sattr3_to_setattr_valid (sattr,
2590 &cs->stbuf,
2591 &cs->mode);
2592 cs->createmode = mode;
2593 cs->parent = *dirfh;
2594
2595 ret = nfs3_fh_resolve_and_resume (cs, dirfh, name, nfs3_create_resume);
2596 if (ret < 0)
2597 stat = nfs3_errno_to_nfsstat3 (-ret);
2598
2599nfs3err:
2600 if (ret < 0) {
2601 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_CREATE8,
2602 stat, -ret);
2603 nfs3_create_reply (req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
2604 nfs3_call_state_wipe (cs);
2605 ret = 0;
2606 }
2607out:
2608 return ret;
2609}
2610
2611
2612int
2613nfs3svc_create (rpcsvc_request_t *req)
2614{
2615 char name[NFS_PATH_MAX4096];
2616 struct nfs3_fh dirfh = {{0}, };
2617 create3args args;
2618 int ret = RPCSVC_ACTOR_ERROR(-1);
2619 uint64_t cverf = 0;
2620 uint64_t *cval;
2621
2622 if (!req)
2623 return ret;
2624
2625 nfs3_prep_create3args (&args, &dirfh, name);
2626 if (xdr_to_create3args (req->msg[0], &args) <= 0) {
2627 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2627, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
2628 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
2629 goto rpcerr;
2630 }
2631
2632 cval = (uint64_t *)args.how.createhow3_u.verf;
2633 if (cval)
2634 cverf = *cval;
2635 else {
2636 gf_log(GF_NFS3, GF_LOG_ERROR,do { do { if (0) printf ("Error getting createverf3 from args"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 2637, GF_LOG_ERROR, "Error getting createverf3 from args");
} while (0)
2637 "Error getting createverf3 from args")do { do { if (0) printf ("Error getting createverf3 from args"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 2637, GF_LOG_ERROR, "Error getting createverf3 from args");
} while (0)
;
2638 goto rpcerr;
2639 }
2640
2641 ret = nfs3_create (req, &dirfh, name, args.how.mode,
2642 &args.how.createhow3_u.obj_attributes, cverf);
2643 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
2644 gf_log (GF_NFS3, GF_LOG_ERROR, "CREATE procedure failed")do { do { if (0) printf ("CREATE procedure failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2644, GF_LOG_ERROR
, "CREATE procedure failed"); } while (0)
;
2645 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
2646 ret = RPCSVC_ACTOR_ERROR(-1);
2647 }
2648
2649rpcerr:
2650 return ret;
2651}
2652
2653
2654int
2655nfs3_mkdir_reply (rpcsvc_request_t *req, nfsstat3 stat, struct nfs3_fh *fh,
2656 struct iatt *buf, struct iatt *preparent,
2657 struct iatt *postparent)
2658{
2659 mkdir3res res = {0, };
2660 uint64_t deviceid = 0;
2661
2662 deviceid = nfs3_request_xlator_deviceid (req);
2663 nfs3_fill_mkdir3res (&res, stat, fh, buf, preparent, postparent,
2664 deviceid);
2665 nfs3svc_submit_reply (req, &res,
2666 (nfs3_serializer)xdr_serialize_mkdir3res);
2667 return 0;
2668}
2669
2670int32_t
2671nfs3svc_mkdir_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
2672 int32_t op_ret, int32_t op_errno,
2673 struct iatt *preop, struct iatt *postop, dict_t *xdata)
2674{
2675 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2676 nfs3_call_state_t *cs = NULL((void*)0);
2677
2678 cs = frame->local;
2679 if (op_ret == -1) {
2680 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2682, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2681 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2682, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2682 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2682, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
2683 stat = nfs3_errno_to_nfsstat3 (op_errno);
2684 goto nfs3err;
2685 }
2686
2687 stat = NFS3_OK;
2688nfs3err:
2689 nfs3_log_newfh_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_MKDIR9, stat,
2690 op_errno, &cs->fh);
2691 nfs3_mkdir_reply (cs->req, stat, &cs->fh, postop, &cs->preparent,
2692 &cs->postparent);
2693 nfs3_call_state_wipe (cs);
2694
2695 return 0;
2696}
2697
2698
2699int32_t
2700nfs3svc_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
2701 int32_t op_ret, int32_t op_errno, inode_t *inode,
2702 struct iatt *buf, struct iatt *preparent,
2703 struct iatt *postparent, dict_t *xdata)
2704{
2705 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2706 int ret = -EFAULT14;
2707 nfs_user_t nfu = {0, };
2708 nfs3_call_state_t *cs = NULL((void*)0);
2709
2710 cs = frame->local;
2711 if (op_ret == -1) {
2712 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2714, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2713 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2714, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2714 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2714, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
2715 stat = nfs3_errno_to_nfsstat3 (op_errno);
2716 goto nfs3err;
2717 }
2718
2719 nfs3_fh_build_child_fh (&cs->parent, buf, &cs->fh);
2720
2721 /* Means no attributes were required to be set. */
2722 if (!cs->setattr_valid) {
2723 stat = NFS3_OK;
2724 goto nfs3err;
2725 }
2726
2727 cs->preparent = *preparent;
2728 cs->postparent = *postparent;
2729 nfs_request_user_init (&nfu, cs->req);
2730 ret = nfs_setattr (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,&cs->stbuf,
2731 cs->setattr_valid, nfs3svc_mkdir_setattr_cbk, cs);
2732 if (ret < 0)
2733 stat = nfs3_errno_to_nfsstat3 (-ret);
2734
2735nfs3err:
2736 if (ret < 0) {
2737 nfs3_log_newfh_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_MKDIR9,
2738 stat, op_errno, &cs->fh);
2739 nfs3_mkdir_reply (cs->req, stat, &cs->fh, buf, preparent,
2740 postparent);
2741 nfs3_call_state_wipe (cs);
2742 }
2743
2744 return 0;
2745}
2746
2747
2748int
2749nfs3_mkdir_resume (void *carg)
2750{
2751 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2752 int ret = -EFAULT14;
2753 nfs_user_t nfu = {0, };
2754 nfs3_call_state_t *cs = NULL((void*)0);
2755
2756 if (!carg)
2757 return ret;
2758
2759 cs = (nfs3_call_state_t *)carg;
2760 nfs3_check_new_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if (((cs)->resolve_ret
< 0) && ((cs)->resolve_errno != 2)) { trans = (
(cs->req)->trans); xlatorp = nfs3_fh_to_xlator (cs->
nfs3state, &cs->resolvefh); uuid_unparse (cs->resolvefh
.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->peerinfo
.identifier, xlatorp ? xlatorp->name : "ERR", gfid); do { do
{ if (0) printf ("Unable to resolve FH" ": %s", buf); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2760, GF_LOG_ERROR
, "Unable to resolve FH" ": %s", buf); } while (0); stat = nfs3_errno_to_nfsstat3
(cs->resolve_errno); goto nfs3err; } } while (0)
;
2761 nfs_request_user_init (&nfu, cs->req);
2762
2763 if (gf_attr_mode_set (cs->setattr_valid)((cs->setattr_valid) & 0x1)) {
2764 cs->setattr_valid &= ~GF_SET_ATTR_MODE0x1;
2765 ret = nfs_mkdir (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
2766 cs->mode, nfs3svc_mkdir_cbk, cs);
2767 } else
2768 ret = nfs_mkdir (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
2769 cs->mode, nfs3svc_mkdir_cbk, cs);
2770
2771 if (ret < 0)
2772 stat = nfs3_errno_to_nfsstat3 (-ret);
2773
2774nfs3err:
2775 if (ret < 0) {
2776 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_MKDIR9,
2777 stat, -ret);
2778 nfs3_mkdir_reply (cs->req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
2779 nfs3_call_state_wipe (cs);
2780 }
2781
2782 return 0;
2783}
2784
2785
2786
2787int
2788nfs3_mkdir (rpcsvc_request_t *req, struct nfs3_fh *dirfh, char *name,
2789 sattr3 *sattr)
2790{
2791 xlator_t *vol = NULL((void*)0);
2792 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2793 int ret = -EFAULT14;
2794 struct nfs3_state *nfs3 = NULL((void*)0);
2795 nfs3_call_state_t *cs = NULL((void*)0);
2796
2797 if ((!req) || (!dirfh) || (!name) || (!sattr)) {
2798 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2798, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
2799 return -1;
2800 }
2801
2802 nfs3_log_fh_entry_call (rpcsvc_request_xid (req)((req)->xid), "MKDIR", dirfh,
2803 name);
2804 nfs3_validate_gluster_fh (dirfh, stat, nfs3err)do { if ((dirfh)) { if (!nfs3_fh_validate (dirfh)) { do { do {
if (0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 2804, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
2805 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 2805, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
2806 nfs3_validate_strlen_or_goto (name, NFS_NAME_MAX, nfs3err, stat, ret)do { if ((name)) { if (strlen ((name)) > (255)) { do { do {
if (0) printf ("strlen " "too long"); } while (0); _gf_log (
"nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2806, GF_LOG_ERROR, "strlen "
"too long"); } while (0); stat = NFS3ERR_NAMETOOLONG; ret = -
36; goto nfs3err; } } } while (0);
;
2807 nfs3_map_fh_to_volume (nfs3, dirfh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), dirfh); if (!vol)
{ uuid_unparse (dirfh->exportid, exportid); uuid_unparse (
dirfh->gfid, gfid); trans = ((req)->trans); do { do { if
(0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2807, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 2807, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 2807, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
2808 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 2808, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
2809 nfs3_check_rw_volaccess (nfs3, dirfh->exportid, stat, nfs3err)do { if (nfs3_export_access (nfs3,dirfh->exportid)!=1){ do
{ do { if (0) printf ("No read-write access"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2809, GF_LOG_ERROR, "No read-write access"
); } while (0); stat = NFS3ERR_ROFS; goto nfs3err; } } while (
0)
;
2810 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
2810, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
2811
2812 cs->parent = *dirfh;
2813 cs->setattr_valid = nfs3_sattr3_to_setattr_valid (sattr, &cs->stbuf,
2814 &cs->mode);
2815 ret = nfs3_fh_resolve_and_resume (cs, dirfh, name, nfs3_mkdir_resume);
2816 if (ret < 0)
2817 stat = nfs3_errno_to_nfsstat3 (-ret);
2818
2819nfs3err:
2820 if (ret < 0) {
2821 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_MKDIR9,
2822 stat, -ret);
2823 nfs3_mkdir_reply (req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
2824 nfs3_call_state_wipe (cs);
2825 ret = 0;
2826 }
2827out:
2828 return ret;
2829}
2830
2831
2832int
2833nfs3svc_mkdir (rpcsvc_request_t *req)
2834{
2835 char name[NFS_PATH_MAX4096];
2836 struct nfs3_fh dirfh = {{0}, };
2837 mkdir3args args;
2838 int ret = RPCSVC_ACTOR_ERROR(-1);
2839
2840 if (!req)
2841 return ret;
2842 nfs3_prep_mkdir3args (&args, &dirfh, name);
2843 if (xdr_to_mkdir3args (req->msg[0], &args) <= 0) {
2844 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2844, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
2845 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
2846 goto rpcerr;
2847 }
2848
2849 ret = nfs3_mkdir (req, &dirfh, name, &args.attributes);
2850 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
2851 gf_log (GF_NFS3, GF_LOG_ERROR, "MKDIR procedure failed")do { do { if (0) printf ("MKDIR procedure failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2851, GF_LOG_ERROR
, "MKDIR procedure failed"); } while (0)
;
2852 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
2853 ret = RPCSVC_ACTOR_ERROR(-1);
2854 }
2855
2856rpcerr:
2857 return ret;
2858}
2859
2860
2861int
2862nfs3_symlink_reply (rpcsvc_request_t *req, nfsstat3 stat, struct nfs3_fh *fh,
2863 struct iatt *buf, struct iatt *preparent,
2864 struct iatt *postparent)
2865{
2866 symlink3res res = {0, };
2867 uint64_t deviceid = 0;
2868
2869 deviceid = nfs3_request_xlator_deviceid (req);
2870 nfs3_fill_symlink3res (&res, stat, fh, buf, preparent, postparent,
2871 deviceid);
2872 nfs3svc_submit_reply (req, (void *)&res,
2873 (nfs3_serializer)xdr_serialize_symlink3res);
2874
2875 return 0;
2876}
2877
2878
2879int32_t
2880nfs3svc_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
2881 int32_t op_ret, int32_t op_errno, inode_t *inode,
2882 struct iatt *buf, struct iatt *preparent,
2883 struct iatt *postparent, dict_t *xdata)
2884{
2885 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2886 nfs3_call_state_t *cs = NULL((void*)0);
2887
2888 cs = frame->local;
2889 if (op_ret == -1) {
2890 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2892, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2891 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2892, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
2892 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 2892, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
2893 stat = nfs3_errno_to_nfsstat3 (op_errno);
2894 goto nfs3err;
2895 }
2896
2897 nfs3_fh_build_child_fh (&cs->parent, buf, &cs->fh);
2898 stat = NFS3_OK;
2899
2900nfs3err:
2901 nfs3_log_newfh_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_SYMLINK10, stat,
2902 op_errno, &cs->fh);
2903 nfs3_symlink_reply (cs->req, stat, &cs->fh, buf, preparent,
2904 postparent);
2905 nfs3_call_state_wipe (cs);
2906 return 0;
2907}
2908
2909
2910int
2911nfs3_symlink_resume (void *carg)
2912{
2913 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2914 int ret = -EFAULT14;
2915 nfs3_call_state_t *cs = NULL((void*)0);
2916 nfs_user_t nfu = {0, };
2917
2918 if (!carg)
2919 return ret;
2920
2921 cs = (nfs3_call_state_t *)carg;
2922 nfs3_check_new_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if (((cs)->resolve_ret
< 0) && ((cs)->resolve_errno != 2)) { trans = (
(cs->req)->trans); xlatorp = nfs3_fh_to_xlator (cs->
nfs3state, &cs->resolvefh); uuid_unparse (cs->resolvefh
.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->peerinfo
.identifier, xlatorp ? xlatorp->name : "ERR", gfid); do { do
{ if (0) printf ("Unable to resolve FH" ": %s", buf); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2922, GF_LOG_ERROR
, "Unable to resolve FH" ": %s", buf); } while (0); stat = nfs3_errno_to_nfsstat3
(cs->resolve_errno); goto nfs3err; } } while (0)
;
2923 nfs_request_user_init (&nfu, cs->req);
2924 ret = nfs_symlink (cs->nfsx, cs->vol, &nfu, cs->pathname,
2925 &cs->resolvedloc, nfs3svc_symlink_cbk, cs);
2926 if (ret < 0)
2927 stat = nfs3_errno_to_nfsstat3 (-ret);
2928
2929nfs3err:
2930 if (ret < 0) {
2931 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
2932 NFS3_SYMLINK10, stat, -ret);
2933 nfs3_symlink_reply (cs->req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
2934 nfs3_call_state_wipe (cs);
2935 }
2936
2937 return ret;
2938}
2939
2940
2941int
2942nfs3_symlink (rpcsvc_request_t *req, struct nfs3_fh *dirfh, char *name,
2943 char *target, sattr3 *sattr)
2944{
2945 xlator_t *vol = NULL((void*)0);
2946 nfsstat3 stat = NFS3ERR_SERVERFAULT;
2947 int ret = -EFAULT14;
2948 struct nfs3_state *nfs3 = NULL((void*)0);
2949 nfs3_call_state_t *cs = NULL((void*)0);
2950
2951 if ((!req) || (!dirfh) || (!name) || (!target) || (!sattr)) {
2952 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2952, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
2953 return -1;
2954 }
2955
2956 nfs3_log_symlink_call (rpcsvc_request_xid (req)((req)->xid), dirfh, name,
2957 target);
2958 nfs3_validate_gluster_fh (dirfh, stat, nfs3err)do { if ((dirfh)) { if (!nfs3_fh_validate (dirfh)) { do { do {
if (0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 2958, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
2959 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 2959, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
2960 nfs3_validate_strlen_or_goto (name, NFS_NAME_MAX, nfs3err, stat, ret)do { if ((name)) { if (strlen ((name)) > (255)) { do { do {
if (0) printf ("strlen " "too long"); } while (0); _gf_log (
"nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2960, GF_LOG_ERROR, "strlen "
"too long"); } while (0); stat = NFS3ERR_NAMETOOLONG; ret = -
36; goto nfs3err; } } } while (0);
;
2961 nfs3_map_fh_to_volume (nfs3, dirfh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), dirfh); if (!vol)
{ uuid_unparse (dirfh->exportid, exportid); uuid_unparse (
dirfh->gfid, gfid); trans = ((req)->trans); do { do { if
(0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2961, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 2961, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 2961, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
2962 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 2962, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
2963 nfs3_check_rw_volaccess (nfs3, dirfh->exportid, stat, nfs3err)do { if (nfs3_export_access (nfs3,dirfh->exportid)!=1){ do
{ do { if (0) printf ("No read-write access"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 2963, GF_LOG_ERROR, "No read-write access"
); } while (0); stat = NFS3ERR_ROFS; goto nfs3err; } } while (
0)
;
2964 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
2964, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
2965
2966 cs->parent = *dirfh;
2967 cs->pathname = gf_strdup (target);
2968 if (!cs->pathname) {
2969 ret = -1;
2970 stat = NFS3ERR_SERVERFAULT;
2971 goto nfs3err;
2972 }
2973
2974 ret = nfs3_fh_resolve_and_resume (cs, dirfh, name, nfs3_symlink_resume);
2975 if (ret < 0)
2976 stat = nfs3_errno_to_nfsstat3 (-ret);
2977
2978nfs3err:
2979 if (ret < 0) {
2980 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_SYMLINK10,
2981 stat, -ret);
2982 nfs3_symlink_reply (req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
2983 nfs3_call_state_wipe (cs);
2984 /* Ret must be 0 after this so that the caller does not
2985 * also send an RPC reply.
2986 */
2987 ret = 0;
2988 }
2989out:
2990 return ret;
2991}
2992
2993
2994int
2995nfs3svc_symlink (rpcsvc_request_t *req)
2996{
2997 char name[NFS_PATH_MAX4096];
2998 struct nfs3_fh dirfh = {{0}, };
2999 char target[NFS_PATH_MAX4096];
3000 symlink3args args;
3001 int ret = RPCSVC_ACTOR_ERROR(-1);
3002
3003 if (!req)
3004 return ret;
3005 nfs3_prep_symlink3args (&args, &dirfh, name, target);
3006 if (xdr_to_symlink3args (req->msg[0], &args) <= 0) {
3007 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3007, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
3008 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
3009 goto rpcerr;
3010 }
3011
3012 ret = nfs3_symlink (req, &dirfh, name, target,
3013 &args.symlink.symlink_attributes);
3014 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
3015 gf_log (GF_NFS3, GF_LOG_ERROR, "SYMLINK procedure failed")do { do { if (0) printf ("SYMLINK procedure failed"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3015, GF_LOG_ERROR
, "SYMLINK procedure failed"); } while (0)
;
3016 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
3017 ret = RPCSVC_ACTOR_ERROR(-1);
3018 }
3019
3020rpcerr:
3021 return ret;
3022}
3023
3024
3025int
3026nfs3_mknod_reply (rpcsvc_request_t *req, nfsstat3 stat, struct nfs3_fh *fh,
3027 struct iatt *buf, struct iatt *preparent,
3028 struct iatt *postparent)
3029{
3030 mknod3res res = {0, };
3031 uint64_t deviceid = 0;
3032
3033 deviceid = nfs3_request_xlator_deviceid (req);
3034 nfs3_fill_mknod3res (&res, stat, fh, buf, preparent, postparent,
3035 deviceid);
3036 nfs3svc_submit_reply (req, (void *)&res,
3037 (nfs3_serializer)xdr_serialize_mknod3res);
3038
3039 return 0;
3040}
3041
3042int32_t
3043nfs3svc_mknod_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
3044 int32_t op_ret, int32_t op_errno,
3045 struct iatt *preop, struct iatt *postop, dict_t *xdata)
3046{
3047 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3048 nfs3_call_state_t *cs = NULL((void*)0);
3049
3050 cs = frame->local;
3051 if (op_ret == -1) {
3052 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 3054, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3053 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 3054, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3054 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 3054, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
3055 stat = nfs3_errno_to_nfsstat3 (op_errno);
3056 goto nfs3err;
3057 }
3058
3059 stat = NFS3_OK;
3060nfs3err:
3061 nfs3_log_newfh_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_MKNOD11, stat,
3062 op_errno, &cs->fh);
3063 nfs3_mknod_reply (cs->req, stat, &cs->fh, postop, &cs->preparent,
3064 &cs->postparent);
3065 nfs3_call_state_wipe (cs);
3066 return 0;
3067}
3068
3069
3070
3071int32_t
3072nfs3svc_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
3073 int32_t op_ret, int32_t op_errno, inode_t *inode,
3074 struct iatt *buf, struct iatt *preparent,
3075 struct iatt *postparent, dict_t *xdata)
3076{
3077 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3078 int ret = -1;
3079 nfs_user_t nfu = {0, };
3080 nfs3_call_state_t *cs = NULL((void*)0);
3081
3082 cs = frame->local;
3083 if (op_ret == -1) {
3084 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 3086, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3085 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 3086, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3086 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 3086, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
3087 stat = nfs3_errno_to_nfsstat3 (op_errno);
3088 goto nfs3err;
3089 }
3090
3091 nfs3_fh_build_child_fh (&cs->parent, buf, &cs->fh);
3092
3093 /* Means no attributes were required to be set. */
3094 if (!cs->setattr_valid) {
3095 stat = NFS3_OK;
3096 ret = -1;
3097 goto nfs3err;
3098 }
3099
3100 cs->preparent = *preparent;
3101 cs->postparent = *postparent;
3102 nfs_request_user_init (&nfu, cs->req);
3103 ret = nfs_setattr (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,&cs->stbuf,
3104 cs->setattr_valid, nfs3svc_mknod_setattr_cbk, cs);
3105 if (ret < 0)
3106 stat = nfs3_errno_to_nfsstat3 (-ret);
3107nfs3err:
3108 if (ret < 0) {
3109 nfs3_log_newfh_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_MKNOD11,
3110 stat,
3111 op_errno, &cs->fh);
3112 nfs3_mknod_reply (cs->req, stat, &cs->fh, buf, preparent,
3113 postparent);
3114 nfs3_call_state_wipe (cs);
3115 }
3116
3117 return 0;
3118}
3119
3120
3121int
3122nfs3_mknod_device (nfs3_call_state_t *cs)
3123{
3124 int ret = -EFAULT14;
3125 dev_t devnum = 0;
3126 mode_t mode = 0;
3127 nfs_user_t nfu = {0, };
3128
3129 if (!cs)
3130 return ret;
3131
3132 devnum = makedev (cs->devnums.specdata1, cs->devnums.specdata2)gnu_dev_makedev (cs->devnums.specdata1, cs->devnums.specdata2
)
;
3133 if (cs->mknodtype == NF3CHR)
3134 mode = S_IFCHR0020000;
3135 else
3136 mode = S_IFBLK0060000;
3137
3138 nfs_request_user_init (&nfu, cs->req);
3139 if (gf_attr_mode_set (cs->setattr_valid)((cs->setattr_valid) & 0x1)) {
3140 cs->setattr_valid &= ~GF_SET_ATTR_MODE0x1;
3141 mode |= cs->mode;
3142 ret = nfs_mknod (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
3143 mode, devnum, nfs3svc_mknod_cbk, cs);
3144 } else
3145 ret = nfs_mknod (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
3146 mode, devnum, nfs3svc_mknod_cbk, cs);
3147
3148 return ret;
3149}
3150
3151
3152int
3153nfs3_mknod_fifo (nfs3_call_state_t *cs)
3154{
3155 int ret = -EFAULT14;
3156 nfs_user_t nfu = {0, };
3157 mode_t mode = S_IFIFO0010000;
3158
3159 if (!cs)
3160 return ret;
3161
3162 nfs_request_user_init (&nfu, cs->req);
3163 if (gf_attr_mode_set (cs->setattr_valid)((cs->setattr_valid) & 0x1)) {
3164 cs->setattr_valid &= ~GF_SET_ATTR_MODE0x1;
3165 mode |= cs->mode;
3166 ret = nfs_mknod (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
3167 mode, 0, nfs3svc_mknod_cbk, cs);
3168 } else
3169 ret = nfs_mknod (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
3170 mode, 0, nfs3svc_mknod_cbk, cs);
3171
3172 return ret;
3173}
3174
3175
3176int
3177nfs3_mknod_resume (void *carg)
3178{
3179 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3180 int ret = -EFAULT14;
3181 nfs3_call_state_t *cs = NULL((void*)0);
3182
3183 if (!carg)
3184 return ret;
3185
3186 cs = (nfs3_call_state_t *)carg;
3187 nfs3_check_new_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if (((cs)->resolve_ret
< 0) && ((cs)->resolve_errno != 2)) { trans = (
(cs->req)->trans); xlatorp = nfs3_fh_to_xlator (cs->
nfs3state, &cs->resolvefh); uuid_unparse (cs->resolvefh
.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->peerinfo
.identifier, xlatorp ? xlatorp->name : "ERR", gfid); do { do
{ if (0) printf ("Unable to resolve FH" ": %s", buf); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3187, GF_LOG_ERROR
, "Unable to resolve FH" ": %s", buf); } while (0); stat = nfs3_errno_to_nfsstat3
(cs->resolve_errno); goto nfs3err; } } while (0)
;
3188 switch (cs->mknodtype) {
3189
3190 case NF3CHR:
3191 case NF3BLK:
3192 ret = nfs3_mknod_device (cs);
3193 break;
3194 case NF3SOCK:
3195 case NF3FIFO:
3196 ret = nfs3_mknod_fifo (cs);
3197 break;
3198 default:
3199 ret = -EBADF9;
3200 break;
3201 }
3202
3203 if (ret < 0)
3204 stat = nfs3_errno_to_nfsstat3 (-ret);
3205
3206nfs3err:
3207 if (ret < 0) {
3208 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_MKNOD11,
3209 stat, -ret);
3210 nfs3_mknod_reply (cs->req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
3211 nfs3_call_state_wipe (cs);
3212 }
3213
3214 return ret;
3215}
3216
3217
3218
3219int
3220nfs3_mknod (rpcsvc_request_t *req, struct nfs3_fh *fh, char *name,
3221 mknoddata3 *nodedata)
3222{
3223 xlator_t *vol = NULL((void*)0);
3224 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3225 int ret = -EFAULT14;
3226 struct nfs3_state *nfs3 = NULL((void*)0);
3227 nfs3_call_state_t *cs = NULL((void*)0);
3228 sattr3 *sattr = NULL((void*)0);
3229
3230 if ((!req) || (!fh) || (!name) || (!nodedata)) {
3231 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3231, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
3232 return -1;
3233 }
3234
3235 nfs3_log_mknod_call (rpcsvc_request_xid (req)((req)->xid), fh, name,
3236 nodedata->type);
3237 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 3237, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
3238 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3238, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
3239 nfs3_validate_strlen_or_goto (name, NFS_NAME_MAX, nfs3err, stat, ret)do { if ((name)) { if (strlen ((name)) > (255)) { do { do {
if (0) printf ("strlen " "too long"); } while (0); _gf_log (
"nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3239, GF_LOG_ERROR, "strlen "
"too long"); } while (0); stat = NFS3ERR_NAMETOOLONG; ret = -
36; goto nfs3err; } } } while (0);
;
3240 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 3240, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3240, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 3240, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
3241 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3241, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
3242 nfs3_check_rw_volaccess (nfs3, fh->exportid, stat, nfs3err)do { if (nfs3_export_access (nfs3,fh->exportid)!=1){ do { do
{ if (0) printf ("No read-write access"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3242, GF_LOG_ERROR, "No read-write access"
); } while (0); stat = NFS3ERR_ROFS; goto nfs3err; } } while (
0)
;
3243 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
3243, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
3244
3245 cs->mknodtype = nodedata->type;
3246 switch (nodedata->type) {
3247 case NF3CHR:
3248 case NF3BLK:
3249 cs->devnums = nodedata->mknoddata3_u.device.spec;
3250 sattr = &nodedata->mknoddata3_u.device.dev_attributes;
3251 cs->setattr_valid = nfs3_sattr3_to_setattr_valid (sattr,
3252 &cs->stbuf,
3253 &cs->mode);
3254 break;
3255 case NF3SOCK:
3256 case NF3FIFO:
3257 sattr = &nodedata->mknoddata3_u.pipe_attributes;
3258 cs->setattr_valid = nfs3_sattr3_to_setattr_valid (sattr,
3259 &cs->stbuf,
3260 &cs->mode);
3261 break;
3262 default:
3263 ret = -EBADF9;
3264 break;
3265 }
3266
3267 cs->parent = *fh;
3268 ret = nfs3_fh_resolve_and_resume (cs, fh, name, nfs3_mknod_resume);
3269 if (ret < 0)
3270 stat = nfs3_errno_to_nfsstat3 (-ret);
3271
3272nfs3err:
3273 if (ret < 0) {
3274 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_MKNOD11,
3275 stat, -ret);
3276 nfs3_mknod_reply (req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
3277 /* Ret must be 0 after this so that the caller does not
3278 * also send an RPC reply.
3279 */
3280 nfs3_call_state_wipe (cs);
3281 ret = 0;
3282 }
3283out:
3284 return ret;
3285}
3286
3287
3288int
3289nfs3svc_mknod (rpcsvc_request_t *req)
3290{
3291 char name[NFS_PATH_MAX4096];
3292 struct nfs3_fh fh = {{0}, };
3293 mknod3args args;
3294 int ret = RPCSVC_ACTOR_ERROR(-1);
3295
3296 if (!req)
3297 return ret;
3298 nfs3_prep_mknod3args (&args, &fh, name);
3299 if (xdr_to_mknod3args (req->msg[0], &args) <= 0) {
3300 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3300, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
3301 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
3302 goto rpcerr;
3303 }
3304
3305 ret = nfs3_mknod (req, &fh, name, &args.what);
3306 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
3307 gf_log (GF_NFS3, GF_LOG_ERROR, "MKNOD procedure failed")do { do { if (0) printf ("MKNOD procedure failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3307, GF_LOG_ERROR
, "MKNOD procedure failed"); } while (0)
;
3308 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
3309 ret = RPCSVC_ACTOR_ERROR(-1);
3310 }
3311
3312rpcerr:
3313 return ret;
3314}
3315
3316int
3317nfs3_remove_reply (rpcsvc_request_t *req, nfsstat3 stat, struct iatt *preparent
3318 , struct iatt *postparent)
3319{
3320 remove3res res = {0, };
3321 uint64_t deviceid = 0;
3322
3323 deviceid = nfs3_request_xlator_deviceid (req);
3324 nfs3_fill_remove3res (&res, stat, preparent, postparent, deviceid);
3325 nfs3svc_submit_reply (req, (void *)&res,
3326 (nfs3_serializer)xdr_serialize_remove3res);
3327 return 0;
3328}
3329
3330
3331
3332int32_t
3333nfs3svc_remove_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
3334 int32_t op_ret, int32_t op_errno, struct iatt *preparent,
3335 struct iatt *postparent, dict_t *xdata)
3336{
3337 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3338 nfs3_call_state_t *cs = NULL((void*)0);
3339
3340 cs = frame->local;
3341 if (op_ret == -1) {
3342 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 3344, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3343 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 3344, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3344 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 3344, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
3345 stat = nfs3_errno_to_nfsstat3 (op_errno);
3346 }
3347
3348 if (op_ret == 0)
3349 stat = NFS3_OK;
3350
3351 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_REMOVE12, stat,
3352 op_errno);
3353 nfs3_remove_reply (cs->req, stat, preparent, postparent);
3354 nfs3_call_state_wipe (cs);
3355
3356 return 0;
3357}
3358
3359
3360int
3361__nfs3_remove (nfs3_call_state_t *cs)
3362{
3363 int ret = -EFAULT14;
3364 nfs_user_t nfu = {0, };
3365 ia_type_t type = 0;
3366
3367 if (!cs)
3368 return ret;
3369 type = cs->resolvedloc.inode->ia_type;
3370 nfs_request_user_init (&nfu, cs->req);
3371 if (IA_ISDIR (type)(type == IA_IFDIR))
3372 ret = nfs_rmdir (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
3373 nfs3svc_remove_cbk, cs);
3374 else
3375 ret = nfs_unlink (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
3376 nfs3svc_remove_cbk, cs);
3377
3378 return ret;
3379}
3380
3381
3382int
3383nfs3_remove_resume (void *carg)
3384{
3385 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3386 int ret = -EFAULT14;
3387 nfs3_call_state_t *cs = NULL((void*)0);
3388
3389 if (!carg)
3390 return ret;
3391
3392 cs = (nfs3_call_state_t *)carg;
3393 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3393, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
3394 ret = __nfs3_remove (cs);
3395 if (ret < 0)
3396 stat = nfs3_errno_to_nfsstat3 (-ret);
3397
3398nfs3err:
3399 if (ret < 0) {
3400 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_REMOVE12,
3401 stat, -ret);
3402 nfs3_remove_reply (cs->req, stat, NULL((void*)0), NULL((void*)0));
3403 nfs3_call_state_wipe (cs);
3404 }
3405
3406 return ret;
3407}
3408
3409
3410int
3411nfs3_remove (rpcsvc_request_t *req, struct nfs3_fh *fh, char *name)
3412{
3413 xlator_t *vol = NULL((void*)0);
3414 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3415 int ret = -EFAULT14;
3416 struct nfs3_state *nfs3 = NULL((void*)0);
3417 nfs3_call_state_t *cs = NULL((void*)0);
3418
3419 if ((!req) || (!fh) || (!name)) {
3420 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3420, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
3421 return -1;
3422 }
3423
3424 nfs3_log_fh_entry_call (rpcsvc_request_xid (req)((req)->xid), "REMOVE", fh,
3425 name);
3426 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 3426, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
3427 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3427, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
3428 nfs3_validate_strlen_or_goto (name, NFS_NAME_MAX, nfs3err, stat, ret)do { if ((name)) { if (strlen ((name)) > (255)) { do { do {
if (0) printf ("strlen " "too long"); } while (0); _gf_log (
"nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3428, GF_LOG_ERROR, "strlen "
"too long"); } while (0); stat = NFS3ERR_NAMETOOLONG; ret = -
36; goto nfs3err; } } } while (0);
;
3429 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 3429, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3429, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 3429, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
3430 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3430, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
3431 nfs3_check_rw_volaccess (nfs3, fh->exportid, stat, nfs3err)do { if (nfs3_export_access (nfs3,fh->exportid)!=1){ do { do
{ if (0) printf ("No read-write access"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3431, GF_LOG_ERROR, "No read-write access"
); } while (0); stat = NFS3ERR_ROFS; goto nfs3err; } } while (
0)
;
3432 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
3432, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
3433
3434 ret = nfs3_fh_resolve_and_resume (cs, fh, name, nfs3_remove_resume);
3435 if (ret < 0)
3436 stat = nfs3_errno_to_nfsstat3 (-ret);
3437
3438nfs3err:
3439 if (ret < 0) {
3440 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_REMOVE12,
3441 stat, -ret);
3442 nfs3_remove_reply (req, stat, NULL((void*)0), NULL((void*)0));
3443 nfs3_call_state_wipe (cs);
3444 /* Ret must be 0 after this so that the caller does not
3445 * also send an RPC reply.
3446 */
3447 ret = 0;
3448 }
3449out:
3450 return ret;
3451}
3452
3453
3454int
3455nfs3svc_remove (rpcsvc_request_t *req)
3456{
3457 char name[NFS_PATH_MAX4096];
3458 struct nfs3_fh fh = {{0}, };
3459 remove3args args;
3460 int ret = RPCSVC_ACTOR_ERROR(-1);
3461
3462 if (!req)
3463 return ret;
3464 nfs3_prep_remove3args (&args, &fh, name);
3465 if (xdr_to_remove3args (req->msg[0], &args) <= 0) {
3466 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3466, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
3467 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
3468 goto rpcerr;
3469 }
3470
3471 ret = nfs3_remove (req, &fh, name);
3472 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
3473 gf_log (GF_NFS3, GF_LOG_ERROR, "REMOVE procedure failed")do { do { if (0) printf ("REMOVE procedure failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3473, GF_LOG_ERROR
, "REMOVE procedure failed"); } while (0)
;
3474 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
3475 ret = RPCSVC_ACTOR_ERROR(-1);
3476 }
3477
3478rpcerr:
3479 return ret;
3480}
3481
3482
3483int
3484nfs3_rmdir_reply (rpcsvc_request_t *req, nfsstat3 stat, struct iatt *preparent,
3485 struct iatt *postparent)
3486{
3487 rmdir3res res = {0, };
3488 uint64_t deviceid = 0;
3489
3490 deviceid = nfs3_request_xlator_deviceid (req);
3491 nfs3_fill_rmdir3res (&res, stat, preparent, postparent, deviceid);
3492 nfs3svc_submit_reply (req, (void *)&res,
3493 (nfs3_serializer)xdr_serialize_rmdir3res);
3494 return 0;
3495}
3496
3497
3498int32_t
3499nfs3svc_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
3500 int32_t op_ret, int32_t op_errno, struct iatt *preparent,
3501 struct iatt *postparent, dict_t *xdata)
3502{
3503 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3504 nfs3_call_state_t *cs = NULL((void*)0);
3505
3506 cs = frame->local;
3507 if (op_ret == -1) {
3508 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 3510, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3509 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 3510, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3510 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 3510, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
3511 stat = nfs3_errno_to_nfsstat3 (op_errno);
3512 } else {
3513 stat = NFS3_OK;
3514 }
3515
3516 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_RMDIR13, stat,
3517 op_errno);
3518 nfs3_rmdir_reply (cs->req, stat, preparent, postparent);
3519 nfs3_call_state_wipe (cs);
3520
3521 return 0;
3522}
3523
3524int
3525nfs3_rmdir_resume (void *carg)
3526{
3527 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3528 int ret = -EFAULT14;
3529 nfs3_call_state_t *cs = NULL((void*)0);
3530 nfs_user_t nfu = {0, };
3531
3532 if (!carg)
3533 return ret;
3534
3535 cs = (nfs3_call_state_t *)carg;
3536 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3536, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
3537 nfs_request_user_init (&nfu, cs->req);
3538 ret = nfs_rmdir (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
3539 nfs3svc_rmdir_cbk, cs);
3540 if (ret < 0)
3541 stat = nfs3_errno_to_nfsstat3 (-ret);
3542
3543nfs3err:
3544 if (ret < 0) {
3545 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_RMDIR13,
3546 stat, -ret);
3547 nfs3_rmdir_reply (cs->req, stat, NULL((void*)0), NULL((void*)0));
3548 nfs3_call_state_wipe (cs);
3549 }
3550
3551 return ret;
3552}
3553
3554
3555
3556int
3557nfs3_rmdir (rpcsvc_request_t *req, struct nfs3_fh *fh, char *name)
3558{
3559 xlator_t *vol = NULL((void*)0);
3560 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3561 int ret = -EFAULT14;
3562 struct nfs3_state *nfs3 = NULL((void*)0);
3563 nfs3_call_state_t *cs = NULL((void*)0);
3564
3565 if ((!req) || (!fh) || (!name)) {
3566 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3566, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
3567 return -1;
3568 }
3569
3570 nfs3_log_fh_entry_call (rpcsvc_request_xid (req)((req)->xid), "RMDIR", fh,
3571 name);
3572 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 3572, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
3573 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3573, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
3574 nfs3_validate_strlen_or_goto (name, NFS_NAME_MAX, nfs3err, stat, ret)do { if ((name)) { if (strlen ((name)) > (255)) { do { do {
if (0) printf ("strlen " "too long"); } while (0); _gf_log (
"nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3574, GF_LOG_ERROR, "strlen "
"too long"); } while (0); stat = NFS3ERR_NAMETOOLONG; ret = -
36; goto nfs3err; } } } while (0);
;
3575 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 3575, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3575, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 3575, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
3576 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3576, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
3577 nfs3_check_rw_volaccess (nfs3, fh->exportid, stat, nfs3err)do { if (nfs3_export_access (nfs3,fh->exportid)!=1){ do { do
{ if (0) printf ("No read-write access"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3577, GF_LOG_ERROR, "No read-write access"
); } while (0); stat = NFS3ERR_ROFS; goto nfs3err; } } while (
0)
;
3578 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
3578, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
3579
3580 ret = nfs3_fh_resolve_and_resume (cs, fh, name, nfs3_rmdir_resume);
3581 if (ret < 0)
3582 stat = nfs3_errno_to_nfsstat3 (-ret);
3583
3584nfs3err:
3585 if (ret < 0) {
3586 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_RMDIR13,
3587 stat, -ret);
3588 nfs3_rmdir_reply (req, stat, NULL((void*)0), NULL((void*)0));
3589 nfs3_call_state_wipe (cs);
3590 /* Ret must be 0 after this so that the caller does not
3591 * also send an RPC reply.
3592 */
3593 ret = 0;
3594 }
3595out:
3596 return ret;
3597}
3598
3599
3600int
3601nfs3svc_rmdir (rpcsvc_request_t *req)
3602{
3603 char name[NFS_PATH_MAX4096];
3604 struct nfs3_fh fh = {{0}, };
3605 rmdir3args args;
3606 int ret = RPCSVC_ACTOR_ERROR(-1);
3607
3608 if (!req)
3609 return ret;
3610 nfs3_prep_rmdir3args (&args, &fh, name);
3611 if (xdr_to_rmdir3args (req->msg[0], &args) <= 0) {
3612 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3612, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
3613 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
3614 goto rpcerr;
3615 }
3616
3617 ret = nfs3_rmdir (req, &fh, name);
3618 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
3619 gf_log (GF_NFS3, GF_LOG_ERROR, "RMDIR procedure failed")do { do { if (0) printf ("RMDIR procedure failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3619, GF_LOG_ERROR
, "RMDIR procedure failed"); } while (0)
;
3620 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
3621 ret = RPCSVC_ACTOR_ERROR(-1);
3622 }
3623
3624rpcerr:
3625 return ret;
3626}
3627
3628
3629int
3630nfs3_rename_reply (rpcsvc_request_t *req, nfsstat3 stat, struct iatt *buf,
3631 struct iatt *preoldparent, struct iatt *postoldparent,
3632 struct iatt *prenewparent, struct iatt *postnewparent)
3633{
3634 rename3res res = {0, };
3635 uint64_t deviceid = 0;
3636
3637 deviceid = nfs3_request_xlator_deviceid (req);
3638 nfs3_fill_rename3res (&res, stat, buf, preoldparent, postoldparent,
3639 prenewparent, postnewparent, deviceid);
3640
3641 nfs3svc_submit_reply (req, (void *)&res,
3642 (nfs3_serializer) xdr_serialize_rename3res);
3643
3644 return 0;
3645}
3646
3647
3648
3649int32_t
3650nfs3svc_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
3651 int32_t op_ret, int32_t op_errno, struct iatt *buf,
3652 struct iatt *preoldparent, struct iatt *postoldparent,
3653 struct iatt *prenewparent, struct iatt *postnewparent,
3654 dict_t *xdata)
3655{
3656 int ret = -EFAULT14;
3657 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3658 nfs3_call_state_t *cs = NULL((void*)0);
3659
3660 cs = frame->local;
3661 if (op_ret == -1) {
3662 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: rename %s -> %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0); _gf_log ("nfs", "nfs3.c"
, __FUNCTION__, 3665, GF_LOG_WARNING, "%x: rename %s -> %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3663 "%x: rename %s -> %s => -1 (%s)",do { do { if (0) printf ("%x: rename %s -> %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0); _gf_log ("nfs", "nfs3.c"
, __FUNCTION__, 3665, GF_LOG_WARNING, "%x: rename %s -> %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3664 rpcsvc_request_xid (cs->req), cs->oploc.path,do { do { if (0) printf ("%x: rename %s -> %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0); _gf_log ("nfs", "nfs3.c"
, __FUNCTION__, 3665, GF_LOG_WARNING, "%x: rename %s -> %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3665 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: rename %s -> %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0); _gf_log ("nfs", "nfs3.c"
, __FUNCTION__, 3665, GF_LOG_WARNING, "%x: rename %s -> %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
3666 stat = nfs3_errno_to_nfsstat3 (op_errno);
3667 goto nfs3err;
3668 }
3669
3670 stat = NFS3_OK;
3671nfs3err:
3672 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_RENAME14, stat,
3673 -ret);
3674 nfs3_rename_reply (cs->req, stat, buf, preoldparent, postoldparent,
3675 prenewparent, postnewparent);
3676 nfs3_call_state_wipe (cs);
3677 return 0;
3678}
3679
3680
3681int
3682nfs3_rename_resume_dst (void *carg)
3683{
3684 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3685 int ret = -EFAULT14;
3686 nfs3_call_state_t *cs = NULL((void*)0);
3687 nfs_user_t nfu = {0, };
3688
3689 if (!carg)
3690 return ret;
3691
3692 cs = (nfs3_call_state_t *)carg;
3693 nfs3_check_new_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if (((cs)->resolve_ret
< 0) && ((cs)->resolve_errno != 2)) { trans = (
(cs->req)->trans); xlatorp = nfs3_fh_to_xlator (cs->
nfs3state, &cs->resolvefh); uuid_unparse (cs->resolvefh
.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->peerinfo
.identifier, xlatorp ? xlatorp->name : "ERR", gfid); do { do
{ if (0) printf ("Unable to resolve FH" ": %s", buf); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3693, GF_LOG_ERROR
, "Unable to resolve FH" ": %s", buf); } while (0); stat = nfs3_errno_to_nfsstat3
(cs->resolve_errno); goto nfs3err; } } while (0)
;
3694 cs->parent = cs->resolvefh;
3695 nfs_request_user_init (&nfu, cs->req);
3696 ret = nfs_rename (cs->nfsx, cs->vol, &nfu, &cs->oploc, &cs->resolvedloc,
3697 nfs3svc_rename_cbk, cs);
3698 if (ret < 0)
3699 stat = nfs3_errno_to_nfsstat3 (-ret);
3700
3701nfs3err:
3702 if (ret < 0) {
3703 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_RENAME14,
3704 stat, -ret);
3705 nfs3_rename_reply (cs->req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
3706 nfs3_call_state_wipe (cs);
3707 }
3708
3709 return ret;
3710}
3711
3712
3713
3714int
3715nfs3_rename_resume_src (void *carg)
3716{
3717 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3718 int ret = -EFAULT14;
3719 nfs3_call_state_t *cs = NULL((void*)0);
3720
3721 if (!carg)
3722 return ret;
3723
3724 cs = (nfs3_call_state_t *)carg;
3725 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3725, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
3726 /* Copy the resolved loc for the source file into another loc
3727 * for safekeeping till we resolve the dest loc.
3728 */
3729 nfs_loc_copy (&cs->oploc, &cs->resolvedloc);
3730 nfs_loc_wipe (&cs->resolvedloc);
3731 GF_FREE (cs->resolventry)__gf_free (cs->resolventry);
3732
3733 ret = nfs3_fh_resolve_and_resume (cs, &cs->fh, cs->pathname,
3734 nfs3_rename_resume_dst);
3735 if (ret < 0)
3736 stat = nfs3_errno_to_nfsstat3 (-ret);
3737
3738nfs3err:
3739 if (ret < 0) {
3740 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_RENAME14,
3741 stat, -ret);
3742 nfs3_rename_reply (cs->req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
3743 nfs3_call_state_wipe (cs);
3744 }
3745
3746 return ret;
3747}
3748
3749
3750int
3751nfs3_rename (rpcsvc_request_t *req, struct nfs3_fh *olddirfh, char *oldname,
3752 struct nfs3_fh *newdirfh, char *newname)
3753{
3754 xlator_t *vol = NULL((void*)0);
3755 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3756 int ret = -EFAULT14;
3757 struct nfs3_state *nfs3 = NULL((void*)0);
3758 nfs3_call_state_t *cs = NULL((void*)0);
3759
3760 if ((!req) || (!olddirfh) || (!oldname) || (!newdirfh) || (!newname)) {
3761 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3761, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
3762 return -1;
3763 }
3764
3765 nfs3_log_rename_call (rpcsvc_request_xid (req)((req)->xid), olddirfh, oldname,
3766 newdirfh, newname);
3767 nfs3_validate_gluster_fh (olddirfh, stat, nfs3err)do { if ((olddirfh)) { if (!nfs3_fh_validate (olddirfh)) { do
{ do { if (0) printf ("Bad Handle"); } while (0); _gf_log ("nfs"
"-nfsv3", "nfs3.c", __FUNCTION__, 3767, GF_LOG_ERROR, "Bad Handle"
); } while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } }
while (0)
;
3768 nfs3_validate_gluster_fh (newdirfh, stat, nfs3err)do { if ((newdirfh)) { if (!nfs3_fh_validate (newdirfh)) { do
{ do { if (0) printf ("Bad Handle"); } while (0); _gf_log ("nfs"
"-nfsv3", "nfs3.c", __FUNCTION__, 3768, GF_LOG_ERROR, "Bad Handle"
); } while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } }
while (0)
;
3769 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3769, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
3770 nfs3_validate_strlen_or_goto(oldname, NFS_NAME_MAX, nfs3err, stat, ret)do { if ((oldname)) { if (strlen ((oldname)) > (255)) { do
{ do { if (0) printf ("strlen " "too long"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3770, GF_LOG_ERROR, "strlen "
"too long"); } while (0); stat = NFS3ERR_NAMETOOLONG; ret = -
36; goto nfs3err; } } } while (0);
;
3771 nfs3_validate_strlen_or_goto(newname, NFS_NAME_MAX, nfs3err, stat, ret)do { if ((newname)) { if (strlen ((newname)) > (255)) { do
{ do { if (0) printf ("strlen " "too long"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3771, GF_LOG_ERROR, "strlen "
"too long"); } while (0); stat = NFS3ERR_NAMETOOLONG; ret = -
36; goto nfs3err; } } } while (0);
;
3772 nfs3_map_fh_to_volume (nfs3, olddirfh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), olddirfh); if (!vol
) { uuid_unparse (olddirfh->exportid, exportid); uuid_unparse
(olddirfh->gfid, gfid); trans = ((req)->trans); do { do
{ if (0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3772, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 3772, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 3772, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
3773 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3773, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
3774 nfs3_check_rw_volaccess (nfs3, olddirfh->exportid, stat, nfs3err)do { if (nfs3_export_access (nfs3,olddirfh->exportid)!=1){
do { do { if (0) printf ("No read-write access"); } while (0
); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3774, GF_LOG_ERROR
, "No read-write access"); } while (0); stat = NFS3ERR_ROFS; goto
nfs3err; } } while (0)
;
3775 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
3775, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
3776
3777 /* While we resolve the source (fh, name) pair, we need to keep a copy
3778 * of the dest (fh,name) pair.
3779 */
3780 cs->fh = *newdirfh;
3781 cs->pathname = gf_strdup (newname);
3782 if (!cs->pathname) {
3783 stat = NFS3ERR_SERVERFAULT;
3784 ret = -1;
3785 goto nfs3err;
3786 }
3787
3788 ret = nfs3_fh_resolve_and_resume (cs, olddirfh, oldname,
3789 nfs3_rename_resume_src);
3790 if (ret < 0)
3791 stat = nfs3_errno_to_nfsstat3 (-ret);
3792
3793nfs3err:
3794 if (ret < 0) {
3795 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_RENAME14,
3796 stat, -ret);
3797 nfs3_rename_reply (req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0), NULL((void*)0));
3798 nfs3_call_state_wipe (cs);
3799 /* Ret must be 0 after this so that the caller does not
3800 * also send an RPC reply.
3801 */
3802 ret = 0;
3803 }
3804out:
3805 return ret;
3806}
3807
3808
3809int
3810nfs3svc_rename (rpcsvc_request_t *req)
3811{
3812 char newname[NFS_PATH_MAX4096];
3813 char oldname[NFS_PATH_MAX4096];
3814 struct nfs3_fh olddirfh = {{0}, };
3815 struct nfs3_fh newdirfh = {{0}, };
3816 rename3args args;
3817 int ret = RPCSVC_ACTOR_ERROR(-1);
3818
3819 if (!req)
3820 return ret;
3821 nfs3_prep_rename3args (&args, &olddirfh, oldname, &newdirfh, newname);
3822 if (xdr_to_rename3args (req->msg[0], &args) <= 0) {
3823 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3823, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
3824 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
3825 goto rpcerr;
3826 }
3827
3828 ret = nfs3_rename (req, &olddirfh, oldname, &newdirfh, newname);
3829 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
3830 gf_log (GF_NFS3, GF_LOG_ERROR, "RENAME procedure failed")do { do { if (0) printf ("RENAME procedure failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3830, GF_LOG_ERROR
, "RENAME procedure failed"); } while (0)
;
3831 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
3832 ret = RPCSVC_ACTOR_ERROR(-1);
3833 }
3834
3835rpcerr:
3836 return ret;
3837}
3838
3839
3840int
3841nfs3_link_reply (rpcsvc_request_t *req, nfsstat3 stat, struct iatt *buf,
3842 struct iatt *preparent, struct iatt *postparent)
3843{
3844 link3res res = {0, };
3845 uint64_t deviceid = 0;
3846
3847 deviceid = nfs3_request_xlator_deviceid (req);
3848 nfs3_fill_link3res (&res, stat, buf, preparent, postparent, deviceid);
3849 nfs3svc_submit_reply (req, (void *)&res,
3850 (nfs3_serializer)xdr_serialize_link3res);
3851
3852 return 0;
3853}
3854
3855
3856int32_t
3857nfs3svc_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
3858 int32_t op_ret, int32_t op_errno, inode_t *inode,
3859 struct iatt *buf, struct iatt *preparent,
3860 struct iatt *postparent, dict_t *xdata)
3861{
3862 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3863 nfs3_call_state_t *cs = NULL((void*)0);
3864
3865 cs = frame->local;
3866 if (op_ret == -1) {
3867 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: link %s <- %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0); _gf_log ("nfs", "nfs3.c"
, __FUNCTION__, 3870, GF_LOG_WARNING, "%x: link %s <- %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3868 "%x: link %s <- %s => -1 (%s)",do { do { if (0) printf ("%x: link %s <- %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0); _gf_log ("nfs", "nfs3.c"
, __FUNCTION__, 3870, GF_LOG_WARNING, "%x: link %s <- %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3869 rpcsvc_request_xid (cs->req), cs->oploc.path,do { do { if (0) printf ("%x: link %s <- %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0); _gf_log ("nfs", "nfs3.c"
, __FUNCTION__, 3870, GF_LOG_WARNING, "%x: link %s <- %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0)
3870 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: link %s <- %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0); _gf_log ("nfs", "nfs3.c"
, __FUNCTION__, 3870, GF_LOG_WARNING, "%x: link %s <- %s => -1 (%s)"
, ((cs->req)->xid), cs->oploc.path, cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
3871 stat = nfs3_errno_to_nfsstat3 (op_errno);
3872 } else
3873 stat = NFS3_OK;
3874
3875 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_LINK15, stat,
3876 op_errno);
3877 nfs3_link_reply (cs->req, stat, buf, preparent, postparent);
3878 nfs3_call_state_wipe (cs);
3879
3880 return 0;
3881}
3882
3883
3884int
3885nfs3_link_resume_lnk (void *carg)
3886{
3887 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3888 int ret = -EFAULT14;
3889 nfs3_call_state_t *cs = NULL((void*)0);
3890 nfs_user_t nfu = {0, };
3891
3892 if (!carg)
3893 return ret;
3894
3895 cs = (nfs3_call_state_t *)carg;
3896 nfs3_check_new_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if (((cs)->resolve_ret
< 0) && ((cs)->resolve_errno != 2)) { trans = (
(cs->req)->trans); xlatorp = nfs3_fh_to_xlator (cs->
nfs3state, &cs->resolvefh); uuid_unparse (cs->resolvefh
.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->peerinfo
.identifier, xlatorp ? xlatorp->name : "ERR", gfid); do { do
{ if (0) printf ("Unable to resolve FH" ": %s", buf); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3896, GF_LOG_ERROR
, "Unable to resolve FH" ": %s", buf); } while (0); stat = nfs3_errno_to_nfsstat3
(cs->resolve_errno); goto nfs3err; } } while (0)
;
3897
3898 nfs_request_user_init (&nfu, cs->req);
3899 ret = nfs_link (cs->nfsx, cs->vol, &nfu, &cs->oploc, &cs->resolvedloc,
3900 nfs3svc_link_cbk, cs);
3901 if (ret < 0)
3902 stat = nfs3_errno_to_nfsstat3 (-ret);
3903
3904nfs3err:
3905 if (ret < 0) {
3906 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_LINK15,
3907 stat, -ret);
3908 nfs3_link_reply (cs->req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0));
3909 nfs3_call_state_wipe (cs);
3910 }
3911 return ret;
3912}
3913
3914
3915int
3916nfs3_link_resume_tgt (void *carg)
3917{
3918 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3919 int ret = -EFAULT14;
3920 nfs3_call_state_t *cs = NULL((void*)0);
3921
3922 if (!carg)
3923 return ret;
3924
3925 cs = (nfs3_call_state_t *)carg;
3926 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3926, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
3927 nfs_loc_copy (&cs->oploc, &cs->resolvedloc);
3928 nfs_loc_wipe (&cs->resolvedloc);
3929
3930 ret = nfs3_fh_resolve_and_resume (cs, &cs->fh, cs->pathname,
3931 nfs3_link_resume_lnk);
3932 if (ret < 0)
3933 stat = nfs3_errno_to_nfsstat3 (-ret);
3934
3935nfs3err:
3936 if (ret < 0) {
3937 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_LINK15,
3938 stat, -ret);
3939 nfs3_link_reply (cs->req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0));
3940 nfs3_call_state_wipe (cs);
3941 }
3942
3943 return ret;
3944}
3945
3946
3947int
3948nfs3_link (rpcsvc_request_t *req, struct nfs3_fh *targetfh,
3949 struct nfs3_fh *dirfh, char *newname)
3950{
3951 xlator_t *vol = NULL((void*)0);
3952 nfsstat3 stat = NFS3ERR_SERVERFAULT;
3953 int ret = -EFAULT14;
3954 struct nfs3_state *nfs3 = NULL((void*)0);
3955 nfs3_call_state_t *cs = NULL((void*)0);
3956
3957 if ((!req) || (!targetfh) || (!dirfh) || (!newname)) {
3958 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3958, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
3959 return -1;
3960 }
3961
3962 nfs3_validate_gluster_fh (dirfh, stat, nfs3err)do { if ((dirfh)) { if (!nfs3_fh_validate (dirfh)) { do { do {
if (0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 3962, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
3963 nfs3_validate_gluster_fh (targetfh, stat, nfs3err)do { if ((targetfh)) { if (!nfs3_fh_validate (targetfh)) { do
{ do { if (0) printf ("Bad Handle"); } while (0); _gf_log ("nfs"
"-nfsv3", "nfs3.c", __FUNCTION__, 3963, GF_LOG_ERROR, "Bad Handle"
); } while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } }
while (0)
;
3964 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3964, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
3965 nfs3_validate_strlen_or_goto(newname, NFS_NAME_MAX, nfs3err, stat, ret)do { if ((newname)) { if (strlen ((newname)) > (255)) { do
{ do { if (0) printf ("strlen " "too long"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3965, GF_LOG_ERROR, "strlen "
"too long"); } while (0); stat = NFS3ERR_NAMETOOLONG; ret = -
36; goto nfs3err; } } } while (0);
;
3966 nfs3_map_fh_to_volume (nfs3, dirfh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), dirfh); if (!vol)
{ uuid_unparse (dirfh->exportid, exportid); uuid_unparse (
dirfh->gfid, gfid); trans = ((req)->trans); do { do { if
(0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3966, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 3966, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 3966, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
3967 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 3967, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
3968 nfs3_check_rw_volaccess (nfs3, dirfh->exportid, stat, nfs3err)do { if (nfs3_export_access (nfs3,dirfh->exportid)!=1){ do
{ do { if (0) printf ("No read-write access"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 3968, GF_LOG_ERROR, "No read-write access"
); } while (0); stat = NFS3ERR_ROFS; goto nfs3err; } } while (
0)
;
3969 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
3969, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
3970
3971 cs->fh = *dirfh;
3972 cs->pathname = gf_strdup (newname);
3973 if (!cs->pathname) {
3974 stat = NFS3ERR_SERVERFAULT;
3975 ret = -1;
3976 goto nfs3err;
3977 }
3978
3979 ret = nfs3_fh_resolve_and_resume (cs, targetfh, NULL((void*)0),
3980 nfs3_link_resume_tgt);
3981 if (ret < 0)
3982 stat = nfs3_errno_to_nfsstat3 (-ret);
3983
3984nfs3err:
3985 if (ret < 0) {
3986 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_LINK15, stat,
3987 -ret);
3988 nfs3_link_reply (req, stat, NULL((void*)0), NULL((void*)0), NULL((void*)0));
3989 nfs3_call_state_wipe (cs);
3990 /* Ret must be 0 after this so that the caller does not
3991 * also send an RPC reply.
3992 */
3993 ret = 0;
3994 }
3995out:
3996 return ret;
3997}
3998
3999int
4000nfs3svc_link (rpcsvc_request_t *req)
4001{
4002 char newpath[NFS_PATH_MAX4096];
4003 struct nfs3_fh dirfh = {{0}, };
4004 struct nfs3_fh targetfh = {{0}, };
4005 link3args args;
4006 int ret = RPCSVC_ACTOR_ERROR(-1);
4007
4008 if (!req)
4009 return ret;
4010 nfs3_prep_link3args (&args, &targetfh, &dirfh, newpath);
4011 if (xdr_to_link3args (req->msg[0], &args) <= 0) {
4012 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4012, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
4013 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
4014 goto rpcerr;
4015 }
4016
4017 ret = nfs3_link (req, &targetfh, &dirfh, newpath);
4018 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
4019 gf_log (GF_NFS3, GF_LOG_ERROR, "LINK procedure failed")do { do { if (0) printf ("LINK procedure failed"); } while (0
); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4019, GF_LOG_ERROR
, "LINK procedure failed"); } while (0)
;
4020 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
4021 ret = RPCSVC_ACTOR_ERROR(-1);
4022 }
4023
4024rpcerr:
4025 return ret;
4026}
4027
4028
4029int
4030nfs3_readdirp_reply (rpcsvc_request_t *req, nfsstat3 stat,struct nfs3_fh *dirfh,
4031 uint64_t cverf, struct iatt *dirstat, gf_dirent_t *entries,
4032 count3 dircount, count3 maxcount, int is_eof)
4033{
4034 readdirp3res res = {0, };
4035 uint64_t deviceid = 0;
4036
4037 deviceid = nfs3_request_xlator_deviceid (req);
4038 nfs3_fill_readdirp3res (&res, stat, dirfh, cverf, dirstat, entries,
4039 dircount, maxcount, is_eof, deviceid);
4040 nfs3svc_submit_reply (req, (void *)&res,
4041 (nfs3_serializer) xdr_serialize_readdirp3res);
4042 nfs3_free_readdirp3res (&res);
4043
4044 return 0;
4045}
4046
4047
4048int
4049nfs3_readdir_reply (rpcsvc_request_t *req, nfsstat3 stat, struct nfs3_fh *dirfh,
4050 uint64_t cverf, struct iatt *dirstat, gf_dirent_t *entries,
4051 count3 count, int is_eof)
4052{
4053 readdir3res res = {0, };
4054 uint64_t deviceid = 0;
4055
4056 deviceid = nfs3_request_xlator_deviceid (req);
4057 nfs3_fill_readdir3res (&res, stat, dirfh, cverf, dirstat, entries, count
4058 , is_eof, deviceid);
4059 nfs3svc_submit_reply (req, (void *)&res,
4060 (nfs3_serializer) xdr_serialize_readdir3res);
4061 nfs3_free_readdir3res (&res);
4062
4063 return 0;
4064}
4065
4066
4067int32_t
4068nfs3svc_readdir_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
4069 int32_t op_ret, int32_t op_errno, struct iatt *buf,
4070 dict_t *xdata)
4071{
4072 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4073 int is_eof = 0;
4074 nfs3_call_state_t *cs = NULL((void*)0);
4075
4076 cs = frame->local;
4077 if (op_ret == -1) {
4078 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4080, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4079 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4080, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4080 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4080, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
4081 stat = nfs3_errno_to_nfsstat3 (op_errno);
4082 goto nfs3err;
4083 }
4084
4085 /* Check whether we encountered a end of directory stream while
4086 * readdir'ing.
4087 */
4088 if (cs->operrno == ENOENT2) {
4089 gf_log (GF_NFS3, GF_LOG_TRACE, "Reached end-of-directory")do { do { if (0) printf ("Reached end-of-directory"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4089, GF_LOG_TRACE
, "Reached end-of-directory"); } while (0)
;
4090 is_eof = 1;
4091 }
4092
4093 stat = NFS3_OK;
4094nfs3err:
4095 if (cs->maxcount == 0) {
4096 nfs3_log_readdir_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), stat,
4097 op_errno, (uintptr_t)cs->fd,
4098 cs->dircount, is_eof);
4099 nfs3_readdir_reply (cs->req, stat, &cs->parent,
4100 (uintptr_t)cs->fd, buf, &cs->entries,
4101 cs->dircount, is_eof);
4102 } else {
4103 nfs3_log_readdirp_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), stat,
4104 op_errno, (uintptr_t)cs->fd,
4105 cs->dircount, cs->maxcount, is_eof);
4106 nfs3_readdirp_reply (cs->req, stat, &cs->parent,
4107 (uintptr_t)cs->fd, buf,
4108 &cs->entries, cs->dircount,
4109 cs->maxcount, is_eof);
4110 }
4111
4112 if (is_eof) {
4113 /* do nothing */
4114 }
4115
4116 nfs3_call_state_wipe (cs);
4117 return 0;
4118}
4119
4120
4121int32_t
4122nfs3svc_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
4123 int32_t op_ret, int32_t op_errno, gf_dirent_t *entries,
4124 dict_t *xdata)
4125{
4126 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4127 int ret = -EFAULT14;
4128 nfs_user_t nfu = {0, };
4129 nfs3_call_state_t *cs = NULL((void*)0);
4130
4131 cs = frame->local;
4132 if (op_ret == -1) {
4133 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4135, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4134 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4135, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4135 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4135, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
4136 stat = nfs3_errno_to_nfsstat3 (op_errno);
4137 goto err;
4138 }
4139
4140 cs->operrno = op_errno;
4141 list_splice_init (&entries->list, &cs->entries.list);
4142 nfs_request_user_init (&nfu, cs->req);
4143 ret = nfs_fstat (cs->nfsx, cs->vol, &nfu, cs->fd,
4144 nfs3svc_readdir_fstat_cbk, cs);
4145 if (ret < 0) {
4146 op_ret = -1;
4147 stat = nfs3_errno_to_nfsstat3 (-ret);
4148 op_errno = -ret;
4149 }
4150
4151err:
4152 if (op_ret >= 0)
4153 goto ret;
4154
4155 if (cs->maxcount == 0) {
4156 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
4157 NFS3_READDIR16, stat, op_errno);
4158 nfs3_readdir_reply (cs->req, stat, NULL((void*)0), 0, NULL((void*)0), NULL((void*)0), 0, 0);
4159 } else {
4160 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
4161 NFS3_READDIRP17, stat, op_errno);
4162 nfs3_readdirp_reply (cs->req, stat, NULL((void*)0), 0, NULL((void*)0), NULL((void*)0),
4163 0, 0, 0);
4164 }
4165
4166 /* For directories, we force a purge from the fd cache on close
4167 * so that next time the dir is read, we'll get any changed directory
4168 * entries.
4169 */
4170 nfs3_call_state_wipe (cs);
4171ret:
4172 return 0;
4173}
4174
4175int
4176nfs3_readdir_process (nfs3_call_state_t *cs)
4177{
4178 int ret = -EFAULT14;
4179 nfs_user_t nfu = {0, };
4180
4181 if (!cs)
4182 return ret;
4183
4184 nfs_request_user_init (&nfu, cs->req);
4185 ret = nfs_readdirp (cs->nfsx, cs->vol, &nfu, cs->fd, cs->dircount,
4186 cs->cookie, nfs3svc_readdir_cbk, cs);
4187 return ret;
4188}
4189
4190
4191int
4192nfs3_readdir_read_resume (void *carg)
4193{
4194 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4195 int ret = -EFAULT14;
4196 nfs3_call_state_t *cs = NULL((void*)0);
4197 struct nfs3_state *nfs3 = NULL((void*)0);
4198
4199 if (!carg)
4200 return ret;
4201
4202 cs = (nfs3_call_state_t *)carg;
4203 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4203, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
4204 nfs3 = rpcsvc_request_program_private (cs->req)(((rpcsvc_program_t *)((cs->req)->prog))->private);
4205 ret = nfs3_verify_dircookie (nfs3, cs->fd, cs->cookie, cs->cookieverf,
4206 &stat);
4207 if (ret < 0) /* Stat already set by verifier function above. */
4208 goto nfs3err;
4209
4210 ret = nfs3_readdir_process (cs);
4211 if (ret < 0)
4212 stat = nfs3_errno_to_nfsstat3 (-ret);
4213nfs3err:
4214 if (ret < 0) {
4215 if (cs->maxcount == 0) {
4216 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
4217 NFS3_READDIR16, stat, -ret);
4218 nfs3_readdir_reply (cs->req, stat, NULL((void*)0), 0, NULL((void*)0), NULL((void*)0),
4219 0, 0);
4220 } else {
4221 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
4222 NFS3_READDIRP17, stat, -ret);
4223 nfs3_readdirp_reply (cs->req, stat, NULL((void*)0), 0, NULL((void*)0), NULL((void*)0),
4224 0, 0, 0);
4225 }
4226 nfs3_call_state_wipe (cs);
4227 }
4228
4229 return 0;
4230}
4231
4232
4233int32_t
4234nfs3svc_readdir_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
4235 int32_t op_ret, int32_t op_errno, fd_t *fd,
4236 dict_t *xdata)
4237{
4238 /*
4239 * We don't really need this, it's just an artifact of forcing the
4240 * opendir to happen.
4241 */
4242 if (fd) {
4243 fd_unref(fd);
4244 }
4245
4246 return 0;
4247}
4248
4249
4250int
4251nfs3_readdir_open_resume (void *carg)
4252{
4253 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4254 int ret = -EFAULT14;
4255 nfs3_call_state_t *cs = NULL((void*)0);
4256 nfs_user_t nfu = {0, };
4257
4258 if (!carg)
4259 return ret;
4260
4261 cs = (nfs3_call_state_t *)carg;
4262 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4262, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
4263 cs->fd = fd_anonymous (cs->resolvedloc.inode);
4264 if (!cs->fd) {
4265 gf_log (GF_NFS3, GF_LOG_ERROR, "Faile to create anonymous fd")do { do { if (0) printf ("Faile to create anonymous fd"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4265, GF_LOG_ERROR
, "Faile to create anonymous fd"); } while (0)
;
4266 goto nfs3err;
4267 }
4268
4269 /*
4270 * NFS client will usually send us a readdirp without an opendir,
4271 * which would cause us to skip our usual self-heal checks which occur
4272 * in opendir for native protocol. To make sure those checks do happen,
4273 * our most reliable option is to do our own opendir for any readdirp
4274 * at the beginning of the directory.
4275 */
4276 if (cs->cookie == 0) {
4277 nfs_request_user_init (&nfu, cs->req);
4278 ret = nfs_opendir (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
4279 nfs3svc_readdir_opendir_cbk, cs);
4280 if (ret < 0) {
4281 gf_log (GF_NFS3, GF_LOG_ERROR, "auto-opendir failed")do { do { if (0) printf ("auto-opendir failed"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4281, GF_LOG_ERROR
, "auto-opendir failed"); } while (0)
;
4282 }
4283 }
4284
4285 ret = nfs3_readdir_read_resume (cs);
4286 if (ret < 0)
4287 stat = nfs3_errno_to_nfsstat3 (-ret);
4288
4289nfs3err:
4290 if (ret < 0) {
4291 if (cs->maxcount == 0) {
4292 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
4293 NFS3_READDIR16, stat, -ret);
4294 nfs3_readdir_reply (cs->req, stat, NULL((void*)0), 0, NULL((void*)0), NULL((void*)0),
4295 0, 0);
4296 } else {
4297 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
4298 NFS3_READDIRP17, stat, -ret);
4299 nfs3_readdirp_reply (cs->req, stat, NULL((void*)0), 0, NULL((void*)0), NULL((void*)0),
4300 0, 0, 0);
4301 }
4302 nfs3_call_state_wipe (cs);
4303 }
4304
4305 return ret;
4306}
4307
4308
4309
4310int
4311nfs3_readdir (rpcsvc_request_t *req, struct nfs3_fh *fh, cookie3 cookie,
4312 uint64_t cverf, count3 dircount, count3 maxcount)
4313{
4314 xlator_t *vol = NULL((void*)0);
4315 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4316 int ret = -EFAULT14;
4317 struct nfs3_state *nfs3 = NULL((void*)0);
4318 nfs3_call_state_t *cs = NULL((void*)0);
4319
4320 if ((!req) || (!fh)) {
4321 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4321, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
4322 return -1;
4323 }
4324
4325 nfs3_log_readdir_call (rpcsvc_request_xid (req)((req)->xid), fh, dircount,
4326 maxcount);
4327 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 4327, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
4328 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4328, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
4329 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 4329, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4329, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 4329, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
4330 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4330, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
4331 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
4331, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
4332
4333 cs->cookieverf = cverf;
4334 cs->dircount = dircount;
4335 cs->maxcount = maxcount;
4336 cs->cookie = cookie;
4337 cs->parent = *fh;
4338 ret = nfs3_fh_resolve_and_resume (cs, fh, NULL((void*)0),
4339 nfs3_readdir_open_resume);
4340 if (ret < 0)
4341 stat = nfs3_errno_to_nfsstat3 (-ret);
4342
4343nfs3err:
4344 if (ret < 0) {
4345 if (maxcount == 0) {
4346 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid),
4347 NFS3_READDIR16, stat, -ret);
4348 nfs3_readdir_reply (req, stat, NULL((void*)0), 0, NULL((void*)0), NULL((void*)0), 0,
4349 0);
4350 } else {
4351 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid),
4352 NFS3_READDIRP17, stat, -ret);
4353 nfs3_readdirp_reply (req, stat, NULL((void*)0), 0, NULL((void*)0), NULL((void*)0), 0,
4354 0, 0);
4355 }
4356 /* Ret must be NULL after this so that the caller does not
4357 * also send an RPC reply.
4358 */
4359 ret = 0;
4360 nfs3_call_state_wipe (cs);
4361 }
4362out:
4363 return ret;
4364}
4365
4366
4367int
4368nfs3svc_readdir (rpcsvc_request_t *req)
4369{
4370 readdir3args ra;
4371 struct nfs3_fh fh = {{0},};
4372 int ret = RPCSVC_ACTOR_ERROR(-1);
4373 uint64_t verf = 0;
4374 uint64_t *cval;
4375
4376 if (!req)
4377 return ret;
4378 nfs3_prep_readdir3args (&ra, &fh);
4379 if (xdr_to_readdir3args (req->msg[0], &ra) <= 0) {
4380 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4380, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
4381 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
4382 goto rpcerr;
4383 }
4384
4385 cval = (uint64_t *) ra.cookieverf;
4386
4387 if (cval)
4388 verf = *cval;
4389 else {
4390 gf_log(GF_NFS3, GF_LOG_ERROR,do { do { if (0) printf ("Error getting cookieverf from readdir args"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4391, GF_LOG_ERROR, "Error getting cookieverf from readdir args"
); } while (0)
4391 "Error getting cookieverf from readdir args")do { do { if (0) printf ("Error getting cookieverf from readdir args"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4391, GF_LOG_ERROR, "Error getting cookieverf from readdir args"
); } while (0)
;
4392 goto rpcerr;
4393 }
4394
4395 ret = nfs3_readdir (req, &fh, ra.cookie, verf, ra.count, 0);
4396 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
4397 gf_log (GF_NFS3, GF_LOG_ERROR, "READDIR procedure failed")do { do { if (0) printf ("READDIR procedure failed"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4397, GF_LOG_ERROR
, "READDIR procedure failed"); } while (0)
;
4398 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
4399 ret = RPCSVC_ACTOR_ERROR(-1);
4400 }
4401
4402rpcerr:
4403 return ret;
4404}
4405
4406
4407int
4408nfs3svc_readdirp (rpcsvc_request_t *req)
4409{
4410 readdirp3args ra;
4411 struct nfs3_fh fh = {{0},};
4412 int ret = RPCSVC_ACTOR_ERROR(-1);
4413 uint64_t cverf = 0;
4414 uint64_t *cval;
4415
4416 if (!req)
4417 return ret;
4418 nfs3_prep_readdirp3args (&ra, &fh);
4419 if (xdr_to_readdirp3args (req->msg[0], &ra) <= 0) {
4420 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4420, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
4421 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
4422 goto rpcerr;
4423 }
4424
4425 cval = (uint64_t *) ra.cookieverf;
4426
4427 if (cval)
4428 cverf = *cval;
4429 else {
4430 gf_log (GF_NFS3, GF_LOG_ERROR,do { do { if (0) printf ("Error getting cookieverf from readdirp args"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4431, GF_LOG_ERROR, "Error getting cookieverf from readdirp args"
); } while (0)
4431 "Error getting cookieverf from readdirp args")do { do { if (0) printf ("Error getting cookieverf from readdirp args"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4431, GF_LOG_ERROR, "Error getting cookieverf from readdirp args"
); } while (0)
;
4432 goto rpcerr;
4433 }
4434
4435 ret = nfs3_readdir (req, &fh, ra.cookie, cverf, ra.dircount,
4436 ra.maxcount);
4437 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
4438 gf_log (GF_NFS3, GF_LOG_ERROR, "READDIRP procedure failed")do { do { if (0) printf ("READDIRP procedure failed"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4438, GF_LOG_ERROR
, "READDIRP procedure failed"); } while (0)
;
4439 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
4440 ret = RPCSVC_ACTOR_ERROR(-1);
4441 }
4442
4443rpcerr:
4444 return ret;
4445}
4446
4447
4448int
4449nfs3_fsstat_reply (rpcsvc_request_t *req, nfsstat3 stat, struct statvfs *fsbuf,
4450 struct iatt *postbuf)
4451{
4452 fsstat3res res = {0, };
4453 uint64_t deviceid = 0;
4454
4455 deviceid = nfs3_request_xlator_deviceid (req);
4456 nfs3_fill_fsstat3res (&res, stat, fsbuf, postbuf, deviceid);
4457 return nfs3svc_submit_reply (req, &res,
4458 (nfs3_serializer)xdr_serialize_fsstat3res);
4459
4460}
4461
4462
4463int32_t
4464nfs3_fsstat_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
4465 int32_t op_ret, int32_t op_errno, struct iatt *buf,
4466 dict_t *xdata)
4467{
4468 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4469 nfs3_call_state_t *cs = NULL((void*)0);
4470
4471 cs = frame->local;
4472 if (op_ret == -1) {
4473 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4475, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4474 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4475, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4475 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4475, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
4476 stat = nfs3_errno_to_nfsstat3 (op_errno);
4477 } else
4478 stat = NFS3_OK;
4479
4480 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_FSSTAT18, stat,
4481 op_errno);
4482 nfs3_fsstat_reply (cs->req, stat, &cs->fsstat, buf);
4483 nfs3_call_state_wipe (cs);
4484 return 0;
4485}
4486
4487
4488int32_t
4489nfs3_fsstat_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
4490 int32_t op_ret, int32_t op_errno, struct statvfs *buf,
4491 dict_t *xdata)
4492{
4493 nfs_user_t nfu = {0, };
4494 int ret = -EFAULT14;
4495 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4496 nfs3_call_state_t *cs = NULL((void*)0);
4497
4498 cs = frame->local;
4499 if (op_ret == -1) {
4500 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4502, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4501 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4502, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4502 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4502, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
4503 ret = -op_errno;
4504 stat = nfs3_errno_to_nfsstat3 (op_errno);
4505 goto err;
4506 }
4507
4508 /* Then get the stat for the fs root in order to fill in the
4509 * post_op_attr.
4510 */
4511 cs->fsstat = *buf;
4512 nfs_request_user_init (&nfu, cs->req);
4513 ret = nfs_stat (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
4514 nfs3_fsstat_stat_cbk, cs);
4515 if (ret < 0)
4516 stat = nfs3_errno_to_nfsstat3 (-ret);
4517
4518err:
4519 if (ret < 0) {
4520 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_FSSTAT18,
4521 stat, -ret);
4522 nfs3_fsstat_reply (cs->req, stat, NULL((void*)0), NULL((void*)0));
4523 nfs3_call_state_wipe (cs);
4524 }
4525
4526 return 0;
4527}
4528
4529
4530int
4531nfs3_fsstat_resume (void *carg)
4532{
4533 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4534 int ret = -EFAULT14;
4535 nfs3_call_state_t *cs = NULL((void*)0);
4536 nfs_user_t nfu = {0, };
4537
4538 if (!carg)
4539 return ret;
4540
4541 cs = (nfs3_call_state_t *)carg;
4542 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4542, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
4543 nfs_request_user_init (&nfu, cs->req);
4544 /* First, we need to get the statvfs for the subvol */
4545 ret = nfs_statfs (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
4546 nfs3_fsstat_statfs_cbk, cs);
4547 if (ret < 0)
4548 stat = nfs3_errno_to_nfsstat3 (-ret);
4549
4550nfs3err:
4551 if (ret < 0) {
4552 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_FSSTAT18,
4553 stat, -ret);
4554 nfs3_fsstat_reply (cs->req, stat, NULL((void*)0), NULL((void*)0));
4555 nfs3_call_state_wipe (cs);
4556 }
4557
4558 return ret;
4559}
4560
4561
4562
4563int
4564nfs3_fsstat (rpcsvc_request_t *req, struct nfs3_fh *fh)
4565{
4566 xlator_t *vol = NULL((void*)0);
4567 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4568 int ret = -EFAULT14;
4569 struct nfs3_state *nfs3 = NULL((void*)0);
4570 nfs3_call_state_t *cs = NULL((void*)0);
4571
4572 if ((!req) || (!fh)) {
4573 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4573, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
4574 return -1;
4575 }
4576
4577 nfs3_log_common_call (rpcsvc_request_xid (req)((req)->xid), "FSSTAT", fh);
4578 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 4578, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
4579 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4579, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
4580 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 4580, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4580, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 4580, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
4581 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4581, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
4582 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
4582, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
4583
4584 ret = nfs3_fh_resolve_and_resume (cs, fh, NULL((void*)0), nfs3_fsstat_resume);
4585 if (ret < 0)
4586 stat = nfs3_errno_to_nfsstat3 (-ret);
4587
4588nfs3err:
4589 if (ret < 0) {
4590 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_FSSTAT18,
4591 stat, -ret);
4592 nfs3_fsstat_reply (req, stat, NULL((void*)0), NULL((void*)0));
4593 nfs3_call_state_wipe (cs);
4594 /* Ret must be 0 after this so that the caller does not
4595 * also send an RPC reply.
4596 */
4597 ret = 0;
4598 }
4599out:
4600 return ret;
4601}
4602
4603
4604int
4605nfs3svc_fsstat (rpcsvc_request_t *req)
4606{
4607 struct nfs3_fh fh = {{0}, };
4608 fsstat3args args;
4609 int ret = RPCSVC_ACTOR_ERROR(-1);
4610
4611 if (!req)
4612 return ret;
4613 nfs3_prep_fsstat3args (&args, &fh);
4614 if (xdr_to_fsstat3args (req->msg[0], &args) <= 0) {
4615 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4615, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
4616 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
4617 goto rpcerr;
4618 }
4619
4620 ret = nfs3_fsstat (req, &fh);
4621 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
4622 gf_log (GF_NFS3, GF_LOG_ERROR, "FSTAT procedure failed")do { do { if (0) printf ("FSTAT procedure failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4622, GF_LOG_ERROR
, "FSTAT procedure failed"); } while (0)
;
4623 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
4624 ret = RPCSVC_ACTOR_ERROR(-1);
4625 }
4626
4627rpcerr:
4628 return ret;
4629}
4630
4631
4632int
4633nfs3_fsinfo_reply (rpcsvc_request_t *req, nfsstat3 status, struct iatt *fsroot)
4634{
4635 fsinfo3res res;
4636 struct nfs3_state *nfs3 = NULL((void*)0);
4637 uint64_t deviceid = 0;
4638
4639 deviceid = nfs3_request_xlator_deviceid (req);
4640 nfs3 = rpcsvc_request_program_private (req)(((rpcsvc_program_t *)((req)->prog))->private);
4641 nfs3_fill_fsinfo3res (nfs3, &res, status, fsroot, deviceid);
4642
4643 nfs3svc_submit_reply (req, &res,
4644 (nfs3_serializer)xdr_serialize_fsinfo3res);
4645 return 0;
4646}
4647
4648
4649int32_t
4650nfs3svc_fsinfo_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
4651 int32_t op_ret, int32_t op_errno, struct iatt *buf,
4652 dict_t *xdata)
4653{
4654 nfsstat3 status = NFS3ERR_SERVERFAULT;
4655 nfs3_call_state_t *cs = NULL((void*)0);
4656
4657 cs = frame->local;
4658
4659 if (op_ret == -1) {
4660 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4662, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4661 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4662, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4662 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4662, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
4663 status = nfs3_errno_to_nfsstat3 (op_errno);
4664 }else
4665 status = NFS3_OK;
4666
4667 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_FSINFO19, status,
4668 op_errno);
4669
4670 nfs3_fsinfo_reply (cs->req, status, buf);
4671 nfs3_call_state_wipe (cs);
4672
4673 return 0;
4674}
4675
4676
4677int
4678nfs3_fsinfo_resume (void *carg)
4679{
4680 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4681 int ret = -EFAULT14;
4682 nfs_user_t nfu = {0, };
4683 nfs3_call_state_t *cs = NULL((void*)0);
4684
4685
4686 if (!carg)
4687 return ret;
4688
4689 cs = (nfs3_call_state_t *)carg;
4690 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4690, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
4691 nfs_request_user_init (&nfu, cs->req);
4692
4693 ret = nfs_stat (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
4694 nfs3svc_fsinfo_cbk, cs);
4695 if (ret < 0)
4696 stat = nfs3_errno_to_nfsstat3 (-ret);
4697
4698nfs3err:
4699 if (ret < 0) {
4700 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_FSINFO19,
4701 stat, -ret);
4702 nfs3_fsinfo_reply (cs->req, stat, NULL((void*)0));
4703 nfs3_call_state_wipe (cs);
4704 }
4705
4706 return ret;
4707}
4708
4709
4710int
4711nfs3_fsinfo (rpcsvc_request_t *req, struct nfs3_fh *fh)
4712{
4713 xlator_t *vol = NULL((void*)0);
4714 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4715 int ret = -EFAULT14;
4716 struct nfs3_state *nfs3 = NULL((void*)0);
4717 nfs3_call_state_t *cs = NULL((void*)0);
4718
4719 if ((!req) || (!fh)) {
4720 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4720, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
4721 return -1;
4722 }
4723
4724 nfs3_log_common_call (rpcsvc_request_xid (req)((req)->xid), "FSINFO", fh);
4725 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 4725, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
4726 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4726, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
4727 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 4727, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4727, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 4727, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
4728 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4728, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
4729 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
4729, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
4730
4731 ret = nfs3_fh_resolve_and_resume (cs, fh, NULL((void*)0), nfs3_fsinfo_resume);
4732 if (ret < 0)
4733 stat = nfs3_errno_to_nfsstat3 (-ret);
4734
4735nfs3err:
4736 if (ret < 0) {
4737 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_FSINFO19,
4738 stat, -ret);
4739 nfs3_fsinfo_reply (req, stat, NULL((void*)0));
4740 nfs3_call_state_wipe (cs);
4741 ret = 0;
4742 }
4743out:
4744 return ret;
4745}
4746
4747
4748int
4749nfs3svc_fsinfo (rpcsvc_request_t *req)
4750{
4751 int ret = RPCSVC_ACTOR_ERROR(-1);
4752 fsinfo3args args;
4753 struct nfs3_fh root = {{0}, };
4754
4755 if (!req)
4756 return ret;
4757
4758 nfs3_prep_fsinfo3args (&args, &root);
4759 if (xdr_to_fsinfo3args (req->msg[0], &args) <= 0) {
4760 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding arguments")do { do { if (0) printf ("Error decoding arguments"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4760, GF_LOG_ERROR
, "Error decoding arguments"); } while (0)
;
4761 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
4762 goto rpcerr;
4763 }
4764
4765 ret = nfs3_fsinfo (req, &root);
4766 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
4767 gf_log (GF_NFS3, GF_LOG_ERROR, "FSINFO procedure failed")do { do { if (0) printf ("FSINFO procedure failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4767, GF_LOG_ERROR
, "FSINFO procedure failed"); } while (0)
;
4768 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
4769 ret = RPCSVC_ACTOR_ERROR(-1);
4770 }
4771
4772rpcerr:
4773 return ret;
4774}
4775
4776
4777int
4778nfs3_pathconf_reply (rpcsvc_request_t *req, nfsstat3 stat, struct iatt *buf)
4779{
4780 pathconf3res res = {0, };
4781 uint64_t deviceid = 0;
4782
4783 deviceid = nfs3_request_xlator_deviceid (req);
4784 nfs3_fill_pathconf3res (&res, stat, buf, deviceid);
4785 nfs3svc_submit_reply (req, (void *)&res,
4786 (nfs3_serializer)xdr_serialize_pathconf3res);
4787 return 0;
4788}
4789
4790
4791int32_t
4792nfs3svc_pathconf_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
4793 int32_t op_ret, int32_t op_errno, struct iatt *buf,
4794 dict_t *xdata)
4795{
4796 struct iatt *sbuf = NULL((void*)0);
4797 nfs3_call_state_t *cs = NULL((void*)0);
4798 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4799
4800 cs = frame->local;
4801 if (op_ret == -1) {
4802 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4804, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4803 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4804, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4804 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4804, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
4805 stat = nfs3_errno_to_nfsstat3 (op_errno);
4806 } else {
4807 /* If stat fop failed, we can still send the other components
4808 * in a pathconf reply.
4809 */
4810 sbuf = buf;
4811 stat = NFS3_OK;
4812 }
4813
4814 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_PATHCONF20, stat,
4815 op_errno);
4816 nfs3_pathconf_reply (cs->req, stat, sbuf);
4817 nfs3_call_state_wipe (cs);
4818
4819 return 0;
4820}
4821
4822
4823int
4824nfs3_pathconf_resume (void *carg)
4825{
4826 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4827 int ret = -EFAULT14;
4828 nfs_user_t nfu = {0, };
4829 nfs3_call_state_t *cs = NULL((void*)0);
4830
4831 if (!carg)
4832 return ret;
4833
4834 cs = (nfs3_call_state_t *)carg;
4835 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4835, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
4836 nfs_request_user_init (&nfu, cs->req);
4837 ret = nfs_stat (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
4838 nfs3svc_pathconf_cbk, cs);
4839 if (ret < 0)
4840 stat = nfs3_errno_to_nfsstat3 (-ret);
4841nfs3err:
4842 if (ret < 0) {
4843 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid),
4844 NFS3_PATHCONF20, stat, -ret);
4845 nfs3_pathconf_reply (cs->req, stat, NULL((void*)0));
4846 nfs3_call_state_wipe (cs);
4847 }
4848
4849 return ret;
4850}
4851
4852int
4853nfs3_pathconf (rpcsvc_request_t *req, struct nfs3_fh *fh)
4854{
4855 xlator_t *vol = NULL((void*)0);
4856 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4857 int ret = -EFAULT14;
4858 struct nfs3_state *nfs3 = NULL((void*)0);
4859 nfs3_call_state_t *cs = NULL((void*)0);
4860
4861 if ((!req) || (!fh)) {
4862 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4862, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
4863 return -1;
4864 }
4865
4866 nfs3_log_common_call (rpcsvc_request_xid (req)((req)->xid), "PATHCONF", fh);
4867 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 4867, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
4868 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4868, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
4869 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 4869, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4869, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 4869, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
4870 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4870, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
4871 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
4871, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
4872
4873 ret = nfs3_fh_resolve_and_resume (cs, fh, NULL((void*)0), nfs3_pathconf_resume);
4874 if (ret < 0)
4875 stat = nfs3_errno_to_nfsstat3 (-ret);
4876
4877nfs3err:
4878 if (ret < 0) {
4879 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_PATHCONF20,
4880 stat, -ret);
4881 nfs3_pathconf_reply (req, stat, NULL((void*)0));
4882 nfs3_call_state_wipe (cs);
4883 /* Ret must be 0 after this so that the caller does not
4884 * also send an RPC reply.
4885 */
4886 ret = 0;
4887 }
4888out:
4889 return ret;
4890}
4891
4892
4893int
4894nfs3svc_pathconf (rpcsvc_request_t *req)
4895{
4896 struct nfs3_fh fh = {{0}, };
4897 pathconf3args args;
4898 int ret = RPCSVC_ACTOR_ERROR(-1);
4899
4900 if (!req)
4901 return ret;
4902 nfs3_prep_pathconf3args (&args, &fh);
4903 if (xdr_to_pathconf3args (req->msg[0], &args) <= 0) {
4904 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4904, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
4905 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
4906 goto rpcerr;
4907 }
4908
4909 ret = nfs3_pathconf (req, &fh);
4910 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
4911 gf_log (GF_NFS3, GF_LOG_ERROR, "PATHCONF procedure failed")do { do { if (0) printf ("PATHCONF procedure failed"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 4911, GF_LOG_ERROR
, "PATHCONF procedure failed"); } while (0)
;
4912 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
4913 ret = RPCSVC_ACTOR_ERROR(-1);
4914 }
4915
4916rpcerr:
4917 return ret;
4918}
4919
4920int
4921nfs3_commit_reply (rpcsvc_request_t *req, nfsstat3 stat, uint64_t wverf,
4922 struct iatt *prestat, struct iatt *poststat)
4923{
4924 commit3res res = {0, };
4925 uint64_t deviceid = 0;
4926
4927 deviceid = nfs3_request_xlator_deviceid (req);
4928 nfs3_fill_commit3res (&res, stat, wverf, prestat, poststat, deviceid);
4929 nfs3svc_submit_reply (req, (void *)&res,
4930 (nfs3_serializer)xdr_serialize_commit3res);
4931
4932 return 0;
4933}
4934
4935
4936int32_t
4937nfs3svc_commit_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
4938 int32_t op_ret, int32_t op_errno, dict_t *xdata)
4939{
4940 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4941 nfs3_call_state_t *cs = NULL((void*)0);
4942 struct nfs3_state *nfs3 = NULL((void*)0);
4943
4944 cs = frame->local;
4945 if (op_ret == -1) {
4946 gf_log (GF_NFS, GF_LOG_WARNING,do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4948, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4947 "%x: %s => -1 (%s)", rpcsvc_request_xid (cs->req),do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4948, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
4948 cs->resolvedloc.path, strerror (op_errno))do { do { if (0) printf ("%x: %s => -1 (%s)", ((cs->req
)->xid), cs->resolvedloc.path, strerror (op_errno)); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 4948, GF_LOG_WARNING
, "%x: %s => -1 (%s)", ((cs->req)->xid), cs->resolvedloc
.path, strerror (op_errno)); } while (0)
;
4949 stat = nfs3_errno_to_nfsstat3 (op_errno);
4950 } else
4951 stat = NFS3_OK;
4952
4953 nfs3 = rpcsvc_request_program_private (cs->req)(((rpcsvc_program_t *)((cs->req)->prog))->private);
4954 nfs3_log_commit_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), stat, op_errno,
4955 nfs3->serverstart);
4956 nfs3_commit_reply (cs->req, stat, nfs3->serverstart, NULL((void*)0), NULL((void*)0));
4957 nfs3_call_state_wipe (cs);
4958
4959 return 0;
4960}
4961
4962int
4963nfs3_commit_resume (void *carg)
4964{
4965 nfsstat3 stat = NFS3ERR_SERVERFAULT;
4966 int ret = -EFAULT14;
4967 nfs_user_t nfu = {0, };
4968 nfs3_call_state_t *cs = NULL((void*)0);
4969
4970 if (!carg)
4971 return ret;
4972
4973 cs = (nfs3_call_state_t *)carg;
4974 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 4974, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
4975
4976 if (nfs3_export_sync_trusted (cs->nfs3state, cs->resolvefh.exportid)) {
4977 ret = -1;
4978 stat = NFS3_OK;
4979 goto nfs3err;
4980 }
4981
4982 nfs_request_user_init (&nfu, cs->req);
4983 ret = nfs_flush (cs->nfsx, cs->vol, &nfu, cs->fd,
4984 nfs3svc_commit_cbk, cs);
4985 if (ret < 0)
4986 stat = nfs3_errno_to_nfsstat3 (-ret);
4987
4988nfs3err:
4989 if (ret < 0) {
4990 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_COMMIT21,
4991 stat, -ret);
4992 nfs3_commit_reply (cs->req, stat, cs->nfs3state->serverstart,
4993 NULL((void*)0), NULL((void*)0));
4994 nfs3_call_state_wipe (cs);
4995 ret = 0;
4996 }
4997
4998 return 0;
4999}
5000
5001
5002int
5003nfs3_commit_open_resume (void *carg)
5004{
5005 nfsstat3 stat = NFS3ERR_SERVERFAULT;
5006 int ret = -EFAULT14;
5007 nfs3_call_state_t *cs = NULL((void*)0);
5008
5009 if (!carg)
5010 return ret;
5011
5012 cs = (nfs3_call_state_t *)carg;
5013 nfs3_check_fh_resolve_status (cs, stat, nfs3err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5013, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nfs3_errno_to_nfsstat3 (cs->resolve_errno); goto
nfs3err; } } while (0)
;
5014 cs->fd = fd_anonymous (cs->resolvedloc.inode);
5015 if (!cs->fd) {
5016 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to create anonymous fd.")do { do { if (0) printf ("Failed to create anonymous fd."); }
while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5016
, GF_LOG_ERROR, "Failed to create anonymous fd."); } while (0
)
;
5017 goto nfs3err;
5018 }
5019
5020 ret = nfs3_commit_resume (cs);
5021 if (ret < 0)
5022 stat = nfs3_errno_to_nfsstat3 (-ret);
5023nfs3err:
5024 if (ret < 0) {
5025 nfs3_log_common_res (rpcsvc_request_xid (cs->req)((cs->req)->xid), NFS3_COMMIT21,
5026 stat, -ret);
5027 nfs3_commit_reply (cs->req, stat, 0, NULL((void*)0), NULL((void*)0));
5028 nfs3_call_state_wipe (cs);
5029 }
5030
5031 return ret;
5032}
5033
5034
5035
5036int
5037nfs3_commit (rpcsvc_request_t *req, struct nfs3_fh *fh, offset3 offset,
5038 count3 count)
5039{
5040 xlator_t *vol = NULL((void*)0);
5041 nfsstat3 stat = NFS3ERR_SERVERFAULT;
5042 int ret = -EFAULT14;
5043 struct nfs3_state *nfs3 = NULL((void*)0);
5044 nfs3_call_state_t *cs = NULL((void*)0);
5045
5046 if ((!req) || (!fh)) {
5047 gf_log (GF_NFS3, GF_LOG_ERROR, "Bad arguments")do { do { if (0) printf ("Bad arguments"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5047, GF_LOG_ERROR, "Bad arguments"
); } while (0)
;
5048 return -1;
5049 }
5050
5051 nfs3_log_rw_call (rpcsvc_request_xid (req)((req)->xid), "COMMIT", fh, offset,
5052 count, -1);
5053 nfs3_validate_gluster_fh (fh, stat, nfs3err)do { if ((fh)) { if (!nfs3_fh_validate (fh)) { do { do { if (
0) printf ("Bad Handle"); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 5053, GF_LOG_ERROR, "Bad Handle"); }
while (0); stat = NFS3ERR_BADHANDLE; goto nfs3err; } } } while
(0)
;
5054 nfs3_validate_nfs3_state (req, nfs3, stat, nfs3err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5054, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); stat = NFS3ERR_SERVERFAULT; ret = -14; goto nfs3err
; } } while (0);
;
5055 nfs3_map_fh_to_volume (nfs3, fh, req, vol, stat, nfs3err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((nfs3), fh); if (!vol) { uuid_unparse
(fh->exportid, exportid); uuid_unparse (fh->gfid, gfid
); trans = ((req)->trans); do { do { if (0) printf ("Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); _gf_log ("nfs""-nfsv3"
, "nfs3.c", __FUNCTION__, 5055, GF_LOG_ERROR, "Failed to map "
"FH to vol: client=%s, exportid=%s, gfid=%s", trans->peerinfo
.identifier, exportid, gfid); } while (0); do { do { if (0) printf
("Stale nfs client %s must be trying to " "connect to a deleted volume, please "
"unmount it.", trans->peerinfo.identifier); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5055, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = NFS3ERR_STALE; goto
nfs3err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 5055, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
5056 nfs3_volume_started_check (nfs3, vol, ret, out)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5056, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto out; } } while (0)
;
5057 nfs3_check_rw_volaccess (nfs3, fh->exportid, stat, nfs3err)do { if (nfs3_export_access (nfs3,fh->exportid)!=1){ do { do
{ if (0) printf ("No read-write access"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5057, GF_LOG_ERROR, "No read-write access"
); } while (0); stat = NFS3ERR_ROFS; goto nfs3err; } } while (
0)
;
5058 nfs3_handle_call_state_init (nfs3, cs, req, vol, stat, nfs3err)do { cs = nfs3_call_state_init ((nfs3), (req), (vol)); if (!cs
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__,
5058, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = NFS3ERR_SERVERFAULT; goto nfs3err; } } while (0)
;
5059
5060 cs->datacount = count;
5061 cs->dataoffset = offset;
5062 ret = nfs3_fh_resolve_and_resume (cs, fh, NULL((void*)0),
5063 nfs3_commit_open_resume);
5064 if (ret < 0)
5065 stat = nfs3_errno_to_nfsstat3 (-ret);
5066
5067nfs3err:
5068 if (ret < 0) {
5069 nfs3_log_common_res (rpcsvc_request_xid (req)((req)->xid), NFS3_COMMIT21,
5070 stat, -ret);
5071 nfs3_commit_reply (req, stat, 0, NULL((void*)0), NULL((void*)0));
5072 nfs3_call_state_wipe (cs);
5073 ret = 0;
5074 }
5075out:
5076 return ret;
5077}
5078
5079
5080
5081int
5082nfs3svc_commit (rpcsvc_request_t *req)
5083{
5084 struct nfs3_fh fh = {{0}, };
5085 commit3args args;
5086 int ret = RPCSVC_ACTOR_ERROR(-1);
5087
5088 if (!req)
5089 return ret;
5090 nfs3_prep_commit3args (&args, &fh);
5091 if (xdr_to_commit3args (req->msg[0], &args) <= 0) {
5092 gf_log (GF_NFS3, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5092, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
5093 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
5094 goto rpcerr;
5095 }
5096
5097 ret = nfs3_commit (req, &fh, args.offset, args.count);
5098 if ((ret < 0) && (ret != RPCSVC_ACTOR_IGNORE(-2))) {
5099 gf_log (GF_NFS3, GF_LOG_ERROR, "COMMIT procedure failed")do { do { if (0) printf ("COMMIT procedure failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5099, GF_LOG_ERROR
, "COMMIT procedure failed"); } while (0)
;
5100 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR;
5101 ret = RPCSVC_ACTOR_ERROR(-1);
5102 }
5103
5104rpcerr:
5105 return ret;
5106}
5107
5108
5109rpcsvc_actor_t nfs3svc_actors[NFS3_PROC_COUNT22] = {
5110 {"NULL", NFS3_NULL0, nfs3svc_null, NULL((void*)0), 0},
5111 {"GETATTR", NFS3_GETATTR1, nfs3svc_getattr,NULL((void*)0), 0},
5112 {"SETATTR", NFS3_SETATTR2, nfs3svc_setattr,NULL((void*)0), 0},
5113 {"LOOKUP", NFS3_LOOKUP3, nfs3svc_lookup, NULL((void*)0), 0},
5114 {"ACCESS", NFS3_ACCESS4, nfs3svc_access, NULL((void*)0), 0},
5115 {"READLINK", NFS3_READLINK5, nfs3svc_readlink,NULL((void*)0), 0},
5116 {"READ", NFS3_READ6, nfs3svc_read, NULL((void*)0), 0},
5117 {"WRITE", NFS3_WRITE7, nfs3svc_write, nfs3svc_write_vecsizer, 0},
5118 {"CREATE", NFS3_CREATE8, nfs3svc_create, NULL((void*)0), 0},
5119 {"MKDIR", NFS3_MKDIR9, nfs3svc_mkdir, NULL((void*)0), 0},
5120 {"SYMLINK", NFS3_SYMLINK10, nfs3svc_symlink,NULL((void*)0), 0},
5121 {"MKNOD", NFS3_MKNOD11, nfs3svc_mknod, NULL((void*)0), 0},
5122 {"REMOVE", NFS3_REMOVE12, nfs3svc_remove, NULL((void*)0), 0},
5123 {"RMDIR", NFS3_RMDIR13, nfs3svc_rmdir, NULL((void*)0), 0},
5124 {"RENAME", NFS3_RENAME14, nfs3svc_rename, NULL((void*)0), 0},
5125 {"LINK", NFS3_LINK15, nfs3svc_link, NULL((void*)0), 0},
5126 {"READDIR", NFS3_READDIR16, nfs3svc_readdir,NULL((void*)0), 0},
5127 {"READDIRPLUS", NFS3_READDIRP17, nfs3svc_readdirp,NULL((void*)0), 0},
5128 {"FSSTAT", NFS3_FSSTAT18, nfs3svc_fsstat, NULL((void*)0), 0},
5129 {"FSINFO", NFS3_FSINFO19, nfs3svc_fsinfo, NULL((void*)0), 0},
5130 {"PATHCONF", NFS3_PATHCONF20, nfs3svc_pathconf,NULL((void*)0), 0},
5131 {"COMMIT", NFS3_COMMIT21, nfs3svc_commit, NULL((void*)0), 0}
5132};
5133
5134
5135rpcsvc_program_t nfs3prog = {
5136 .progname = "NFS3",
5137 .prognum = NFS_PROGRAM100003,
5138 .progver = NFS_V33,
5139 .progport = GF_NFS3_PORT2049,
5140 .actors = nfs3svc_actors,
5141 .numactors = NFS3_PROC_COUNT22,
5142
5143 /* Requests like FSINFO are sent before an auth scheme
5144 * is inited by client. See RFC 2623, Section 2.3.2. */
5145 .min_auth = AUTH_NULL0,
5146};
5147
5148
5149int
5150nfs3_init_options (struct nfs3_state *nfs3, xlator_t *nfsx)
5151{
5152 int ret = -1;
5153 char *optstr = NULL((void*)0);
5154 uint64_t size64 = 0;
5155
5156 if ((!nfs3) || (!nfsx))
5157 return -1;
5158
5159 /* nfs3.read-size */
5160 nfs3->readsize = GF_NFS3_RTPREF(64 * 1024ULL);
5161 if (dict_get (nfsx->options, "nfs3.read-size")) {
5162 ret = dict_get_str (nfsx->options, "nfs3.read-size", &optstr);
5163 if (ret < 0) {
5164 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to read "do { do { if (0) printf ("Failed to read " " option: nfs3.read-size"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5165, GF_LOG_ERROR, "Failed to read " " option: nfs3.read-size"
); } while (0)
5165 " option: nfs3.read-size")do { do { if (0) printf ("Failed to read " " option: nfs3.read-size"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5165, GF_LOG_ERROR, "Failed to read " " option: nfs3.read-size"
); } while (0)
;
5166 ret = -1;
5167 goto err;
5168 }
5169
5170 ret = gf_string2bytesize (optstr, &size64);
5171 nfs3->readsize = size64;
5172 if (ret == -1) {
5173 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to format"do { do { if (0) printf ("Failed to format" " option: nfs3.read-size"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5174, GF_LOG_ERROR, "Failed to format" " option: nfs3.read-size"
); } while (0)
5174 " option: nfs3.read-size")do { do { if (0) printf ("Failed to format" " option: nfs3.read-size"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5174, GF_LOG_ERROR, "Failed to format" " option: nfs3.read-size"
); } while (0)
;
5175 ret = -1;
5176 goto err;
5177 }
5178 }
5179
5180 /* nfs3.write-size */
5181 nfs3->writesize = GF_NFS3_WTPREF(64 * 1024ULL);
5182 if (dict_get (nfsx->options, "nfs3.write-size")) {
5183 ret = dict_get_str (nfsx->options, "nfs3.write-size", &optstr);
5184 if (ret < 0) {
5185 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to read "do { do { if (0) printf ("Failed to read " " option: nfs3.write-size"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5186, GF_LOG_ERROR, "Failed to read " " option: nfs3.write-size"
); } while (0)
5186 " option: nfs3.write-size")do { do { if (0) printf ("Failed to read " " option: nfs3.write-size"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5186, GF_LOG_ERROR, "Failed to read " " option: nfs3.write-size"
); } while (0)
;
5187 ret = -1;
5188 goto err;
5189 }
5190
5191 ret = gf_string2bytesize (optstr, &size64);
5192 nfs3->writesize = size64;
5193 if (ret == -1) {
5194 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to format"do { do { if (0) printf ("Failed to format" " option: nfs3.write-size"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5195, GF_LOG_ERROR, "Failed to format" " option: nfs3.write-size"
); } while (0)
5195 " option: nfs3.write-size")do { do { if (0) printf ("Failed to format" " option: nfs3.write-size"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5195, GF_LOG_ERROR, "Failed to format" " option: nfs3.write-size"
); } while (0)
;
5196 ret = -1;
5197 goto err;
5198 }
5199 }
5200
5201 /* nfs3.readdir.size */
5202 nfs3->readdirsize = GF_NFS3_DTPREF(64 * 1024ULL);
5203 if (dict_get (nfsx->options, "nfs3.readdir-size")) {
5204 ret = dict_get_str (nfsx->options,"nfs3.readdir-size", &optstr);
5205 if (ret < 0) {
5206 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to read"do { do { if (0) printf ("Failed to read" " option: nfs3.readdir-size"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5207, GF_LOG_ERROR, "Failed to read" " option: nfs3.readdir-size"
); } while (0)
5207 " option: nfs3.readdir-size")do { do { if (0) printf ("Failed to read" " option: nfs3.readdir-size"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5207, GF_LOG_ERROR, "Failed to read" " option: nfs3.readdir-size"
); } while (0)
;
5208 ret = -1;
5209 goto err;
5210 }
5211
5212 ret = gf_string2bytesize (optstr, &size64);
5213 nfs3->readdirsize = size64;
5214 if (ret == -1) {
5215 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to format"do { do { if (0) printf ("Failed to format" " option: nfs3.readdir-size"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5216, GF_LOG_ERROR, "Failed to format" " option: nfs3.readdir-size"
); } while (0)
5216 " option: nfs3.readdir-size")do { do { if (0) printf ("Failed to format" " option: nfs3.readdir-size"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5216, GF_LOG_ERROR, "Failed to format" " option: nfs3.readdir-size"
); } while (0)
;
5217 ret = -1;
5218 goto err;
5219 }
5220 }
5221
5222
5223 /* We want to use the size of the biggest param for the io buffer size.
5224 */
5225 nfs3->iobsize = nfs3->readsize;
5226 if (nfs3->iobsize < nfs3->writesize)
5227 nfs3->iobsize = nfs3->writesize;
5228 if (nfs3->iobsize < nfs3->readdirsize)
5229 nfs3->iobsize = nfs3->readdirsize;
5230
5231 /* But this is the true size of each iobuf. We need this size to
5232 * accommodate the NFS headers also in the same buffer. */
5233 nfs3->iobsize = nfs3->iobsize * 2;
5234
5235 /* mem-factor */
5236 nfs3->memfactor = GF_NFS3_DEFAULT_MEMFACTOR15;
5237 ret = 0;
5238err:
5239 return ret;
5240}
5241
5242
5243int
5244nfs3_init_subvolume_options (struct nfs3_state *nfs3, struct nfs3_export *exp)
5245{
5246 int ret = -1;
5247 char *optstr = NULL((void*)0);
5248 char searchkey[1024];
5249 char *name = NULL((void*)0);
5250 gf_boolean_t boolt = _gf_false;
5251 uuid_t volumeid = {0, };
5252 dict_t *options = NULL((void*)0);
5253
5254 if ((!exp) || (!nfs3))
5255 return -1;
5256
5257 options = nfs3->nfsx->options;
5258 uuid_clear (volumeid);
5259 if (gf_nfs_dvm_off (nfs_state (nfs3->nfsx))(((struct nfs_state *)(nfs3->nfsx)->private)->dynamicvolumes
== 2)
)
5260 goto no_dvm;
5261
5262 ret = snprintf (searchkey, 1024, "nfs3.%s.volume-id",exp->subvol->name);
5263 if (ret < 0) {
5264 gf_log (GF_MNT, GF_LOG_ERROR, "snprintf failed")do { do { if (0) printf ("snprintf failed"); } while (0); _gf_log
("nfs""-mount", "nfs3.c", __FUNCTION__, 5264, GF_LOG_ERROR, "snprintf failed"
); } while (0)
;
5265 ret = -1;
5266 goto err;
5267 }
5268
5269 if (dict_get (options, searchkey)) {
5270 ret = dict_get_str (options, searchkey, &optstr);
5271 if (ret < 0) {
5272 gf_log (GF_MNT, GF_LOG_ERROR, "Failed to read option"do { do { if (0) printf ("Failed to read option" ": %s", searchkey
); } while (0); _gf_log ("nfs""-mount", "nfs3.c", __FUNCTION__
, 5273, GF_LOG_ERROR, "Failed to read option" ": %s", searchkey
); } while (0)
5273 ": %s", searchkey)do { do { if (0) printf ("Failed to read option" ": %s", searchkey
); } while (0); _gf_log ("nfs""-mount", "nfs3.c", __FUNCTION__
, 5273, GF_LOG_ERROR, "Failed to read option" ": %s", searchkey
); } while (0)
;
5274 ret = -1;
5275 goto err;
5276 }
5277 } else {
5278 gf_log (GF_MNT, GF_LOG_ERROR, "DVM is on but volume-id not "do { do { if (0) printf ("DVM is on but volume-id not " "given for volume: %s"
, exp->subvol->name); } while (0); _gf_log ("nfs""-mount"
, "nfs3.c", __FUNCTION__, 5279, GF_LOG_ERROR, "DVM is on but volume-id not "
"given for volume: %s", exp->subvol->name); } while (0
)
5279 "given for volume: %s", exp->subvol->name)do { do { if (0) printf ("DVM is on but volume-id not " "given for volume: %s"
, exp->subvol->name); } while (0); _gf_log ("nfs""-mount"
, "nfs3.c", __FUNCTION__, 5279, GF_LOG_ERROR, "DVM is on but volume-id not "
"given for volume: %s", exp->subvol->name); } while (0
)
;
5280 ret = -1;
5281 goto err;
5282 }
5283
5284 if (optstr) {
5285 ret = uuid_parse (optstr, volumeid);
5286 if (ret < 0) {
5287 gf_log (GF_MNT, GF_LOG_ERROR, "Failed to parse volume "do { do { if (0) printf ("Failed to parse volume " "UUID"); }
while (0); _gf_log ("nfs""-mount", "nfs3.c", __FUNCTION__, 5288
, GF_LOG_ERROR, "Failed to parse volume " "UUID"); } while (0
)
5288 "UUID")do { do { if (0) printf ("Failed to parse volume " "UUID"); }
while (0); _gf_log ("nfs""-mount", "nfs3.c", __FUNCTION__, 5288
, GF_LOG_ERROR, "Failed to parse volume " "UUID"); } while (0
)
;
5289 ret = -1;
5290 goto err;
5291 }
5292 uuid_copy (exp->volumeid, volumeid);
5293 }
5294
5295no_dvm:
5296 /* Volume Access */
5297 name = exp->subvol->name;
5298 ret = snprintf (searchkey, 1024, "nfs3.%s.volume-access", name);
5299 if (ret < 0) {
5300 gf_log (GF_NFS3, GF_LOG_ERROR, "snprintf failed")do { do { if (0) printf ("snprintf failed"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5300, GF_LOG_ERROR, "snprintf failed"
); } while (0)
;
5301 ret = -1;
5302 goto err;
5303 }
5304
5305 exp->access = GF_NFS3_DEFAULT_VOLACCESS(1);
5306 if (dict_get (options, searchkey)) {
5307 ret = dict_get_str (options, searchkey, &optstr);
5308 if (ret < 0) {
5309 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to read "do { do { if (0) printf ("Failed to read " " option: %s", searchkey
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5310, GF_LOG_ERROR, "Failed to read " " option: %s", searchkey
); } while (0)
5310 " option: %s", searchkey)do { do { if (0) printf ("Failed to read " " option: %s", searchkey
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5310, GF_LOG_ERROR, "Failed to read " " option: %s", searchkey
); } while (0)
;
5311 ret = -1;
5312 goto err;
5313 }
5314
5315 if (strcmp (optstr, "read-only") == 0)
5316 exp->access = GF_NFS3_VOLACCESS_RO2;
5317 }
5318
5319 ret = snprintf (searchkey, 1024, "rpc-auth.%s.unix", name);
5320 if (ret < 0) {
5321 gf_log (GF_NFS3, GF_LOG_ERROR, "snprintf failed")do { do { if (0) printf ("snprintf failed"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5321, GF_LOG_ERROR, "snprintf failed"
); } while (0)
;
5322 ret = -1;
5323 goto err;
5324 }
5325
5326 if (dict_get (options, searchkey)) {
5327 ret = dict_get_str (options, searchkey, &optstr);
5328 if (ret < 0) {
5329 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to read "do { do { if (0) printf ("Failed to read " " option: %s", searchkey
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5330, GF_LOG_ERROR, "Failed to read " " option: %s", searchkey
); } while (0)
5330 " option: %s", searchkey)do { do { if (0) printf ("Failed to read " " option: %s", searchkey
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5330, GF_LOG_ERROR, "Failed to read " " option: %s", searchkey
); } while (0)
;
5331 ret = -1;
5332 goto err;
5333 }
5334 }
5335
5336 exp->trusted_sync = 0;
5337 ret = snprintf (searchkey, 1024, "nfs3.%s.trusted-sync", name);
5338 if (ret < 0) {
5339 gf_log (GF_NFS3, GF_LOG_ERROR, "snprintf failed")do { do { if (0) printf ("snprintf failed"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5339, GF_LOG_ERROR, "snprintf failed"
); } while (0)
;
5340 ret = -1;
5341 goto err;
5342 }
5343
5344 if (dict_get (options, searchkey)) {
5345 ret = dict_get_str (options, searchkey, &optstr);
5346 if (ret < 0) {
5347 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to read "do { do { if (0) printf ("Failed to read " " option: %s", searchkey
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5348, GF_LOG_ERROR, "Failed to read " " option: %s", searchkey
); } while (0)
5348 " option: %s", searchkey)do { do { if (0) printf ("Failed to read " " option: %s", searchkey
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5348, GF_LOG_ERROR, "Failed to read " " option: %s", searchkey
); } while (0)
;
5349 ret = -1;
5350 goto err;
5351 }
5352
5353 ret = gf_string2boolean (optstr, &boolt);
5354 if (ret < 0) {
5355 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to convert str "do { do { if (0) printf ("Failed to convert str " "to gf_boolean_t"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5356, GF_LOG_ERROR, "Failed to convert str " "to gf_boolean_t"
); } while (0)
5356 "to gf_boolean_t")do { do { if (0) printf ("Failed to convert str " "to gf_boolean_t"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5356, GF_LOG_ERROR, "Failed to convert str " "to gf_boolean_t"
); } while (0)
;
5357 ret = -1;
5358 goto err;
5359 }
5360
5361 if (boolt == _gf_true)
5362 exp->trusted_sync = 1;
5363 }
5364
5365 exp->trusted_write = 0;
5366 ret = snprintf (searchkey, 1024, "nfs3.%s.trusted-write", name);
5367 if (ret < 0) {
5368 gf_log (GF_NFS3, GF_LOG_ERROR, "snprintf failed")do { do { if (0) printf ("snprintf failed"); } while (0); _gf_log
("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5368, GF_LOG_ERROR, "snprintf failed"
); } while (0)
;
5369 ret = -1;
5370 goto err;
5371 }
5372
5373 if (dict_get (options, searchkey)) {
5374 ret = dict_get_str (options, searchkey, &optstr);
5375 if (ret < 0) {
5376 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to read "do { do { if (0) printf ("Failed to read " " option: %s", searchkey
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5377, GF_LOG_ERROR, "Failed to read " " option: %s", searchkey
); } while (0)
5377 " option: %s", searchkey)do { do { if (0) printf ("Failed to read " " option: %s", searchkey
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5377, GF_LOG_ERROR, "Failed to read " " option: %s", searchkey
); } while (0)
;
5378 ret = -1;
5379 goto err;
5380 }
5381
5382 ret = gf_string2boolean (optstr, &boolt);
5383 if (ret < 0) {
5384 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to convert str "do { do { if (0) printf ("Failed to convert str " "to gf_boolean_t"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5385, GF_LOG_ERROR, "Failed to convert str " "to gf_boolean_t"
); } while (0)
5385 "to gf_boolean_t")do { do { if (0) printf ("Failed to convert str " "to gf_boolean_t"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5385, GF_LOG_ERROR, "Failed to convert str " "to gf_boolean_t"
); } while (0)
;
5386 ret = -1;
5387 goto err;
5388 }
5389
5390 if (boolt == _gf_true)
5391 exp->trusted_write = 1;
5392 }
5393
5394 /* If trusted-sync is on, then we also switch on trusted-write because
5395 * tw is included in ts. In write logic, we're then only checking for
5396 * tw.
5397 */
5398 if (exp->trusted_sync)
5399 exp->trusted_write = 1;
5400
5401 gf_log (GF_NFS3, GF_LOG_TRACE, "%s: %s, %s, %s", exp->subvol->name,do { do { if (0) printf ("%s: %s, %s, %s", exp->subvol->
name, (exp->access == 2)?"read-only":"read-write", (exp->
trusted_sync == 0)?"no trusted_sync":"trusted_sync", (exp->
trusted_write == 0)?"no trusted_write":"trusted_write"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5404, GF_LOG_TRACE
, "%s: %s, %s, %s", exp->subvol->name, (exp->access ==
2)?"read-only":"read-write", (exp->trusted_sync == 0)?"no trusted_sync"
:"trusted_sync", (exp->trusted_write == 0)?"no trusted_write"
:"trusted_write"); } while (0)
5402 (exp->access == GF_NFS3_VOLACCESS_RO)?"read-only":"read-write",do { do { if (0) printf ("%s: %s, %s, %s", exp->subvol->
name, (exp->access == 2)?"read-only":"read-write", (exp->
trusted_sync == 0)?"no trusted_sync":"trusted_sync", (exp->
trusted_write == 0)?"no trusted_write":"trusted_write"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5404, GF_LOG_TRACE
, "%s: %s, %s, %s", exp->subvol->name, (exp->access ==
2)?"read-only":"read-write", (exp->trusted_sync == 0)?"no trusted_sync"
:"trusted_sync", (exp->trusted_write == 0)?"no trusted_write"
:"trusted_write"); } while (0)
5403 (exp->trusted_sync == 0)?"no trusted_sync":"trusted_sync",do { do { if (0) printf ("%s: %s, %s, %s", exp->subvol->
name, (exp->access == 2)?"read-only":"read-write", (exp->
trusted_sync == 0)?"no trusted_sync":"trusted_sync", (exp->
trusted_write == 0)?"no trusted_write":"trusted_write"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5404, GF_LOG_TRACE
, "%s: %s, %s, %s", exp->subvol->name, (exp->access ==
2)?"read-only":"read-write", (exp->trusted_sync == 0)?"no trusted_sync"
:"trusted_sync", (exp->trusted_write == 0)?"no trusted_write"
:"trusted_write"); } while (0)
5404 (exp->trusted_write == 0)?"no trusted_write":"trusted_write")do { do { if (0) printf ("%s: %s, %s, %s", exp->subvol->
name, (exp->access == 2)?"read-only":"read-write", (exp->
trusted_sync == 0)?"no trusted_sync":"trusted_sync", (exp->
trusted_write == 0)?"no trusted_write":"trusted_write"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5404, GF_LOG_TRACE
, "%s: %s, %s, %s", exp->subvol->name, (exp->access ==
2)?"read-only":"read-write", (exp->trusted_sync == 0)?"no trusted_sync"
:"trusted_sync", (exp->trusted_write == 0)?"no trusted_write"
:"trusted_write"); } while (0)
;
5405 ret = 0;
5406err:
5407 return ret;
5408}
5409
5410
5411struct nfs3_export *
5412nfs3_init_subvolume (struct nfs3_state *nfs3, xlator_t *subvol)
5413{
5414 int ret = -1;
5415 struct nfs3_export *exp = NULL((void*)0);
5416
5417 if ((!nfs3) || (!subvol))
5418 return NULL((void*)0);
5419
5420 exp = GF_CALLOC (1, sizeof (*exp), gf_nfs_mt_nfs3_export)__gf_calloc (1, sizeof (*exp), gf_nfs_mt_nfs3_export);
5421 exp->subvol = subvol;
5422 INIT_LIST_HEAD (&exp->explist)do { (&exp->explist)->next = (&exp->explist)
->prev = &exp->explist; } while (0)
;
5423 gf_log (GF_NFS3, GF_LOG_TRACE, "Initing state: %s", exp->subvol->name)do { do { if (0) printf ("Initing state: %s", exp->subvol->
name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5423, GF_LOG_TRACE, "Initing state: %s", exp->subvol->
name); } while (0)
;
5424
5425 ret = nfs3_init_subvolume_options (nfs3, exp);
5426 if (ret == -1) {
5427 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to init subvol")do { do { if (0) printf ("Failed to init subvol"); } while (0
); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5427, GF_LOG_ERROR
, "Failed to init subvol"); } while (0)
;
5428 goto exp_free;
5429 }
5430
5431 ret = 0;
5432exp_free:
5433 if (ret < 0) {
5434 GF_FREE (exp)__gf_free (exp);
5435 exp = NULL((void*)0);
5436 }
5437
5438 return exp;
5439}
5440
5441
5442int
5443nfs3_init_subvolumes (struct nfs3_state *nfs3)
5444{
5445 int ret = -1;
5446 struct xlator_list *xl_list = NULL((void*)0);
5447 struct nfs3_export *exp = NULL((void*)0);
5448
5449 if (!nfs3)
5450 return -1;
5451
5452 xl_list = nfs3->nfsx->children;
5453
5454 while (xl_list) {
5455 exp = nfs3_init_subvolume (nfs3, xl_list->xlator);
5456 if (!exp) {
5457 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to init subvol: "do { do { if (0) printf ("Failed to init subvol: " "%s", xl_list
->xlator->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 5458, GF_LOG_ERROR, "Failed to init subvol: "
"%s", xl_list->xlator->name); } while (0)
5458 "%s", xl_list->xlator->name)do { do { if (0) printf ("Failed to init subvol: " "%s", xl_list
->xlator->name); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c"
, __FUNCTION__, 5458, GF_LOG_ERROR, "Failed to init subvol: "
"%s", xl_list->xlator->name); } while (0)
;
5459 goto err;
5460 }
5461 list_add_tail (&exp->explist, &nfs3->exports);
5462 xl_list = xl_list->next;
5463 }
5464
5465 ret = 0;
5466err:
5467 return ret;
5468}
5469
5470
5471struct nfs3_state *
5472nfs3_init_state (xlator_t *nfsx)
5473{
5474 struct nfs3_state *nfs3 = NULL((void*)0);
5475 int ret = -1;
5476 unsigned int localpool = 0;
5477 struct nfs_state *nfs = NULL((void*)0);
5478
5479 if (!nfsx)
5480 return NULL((void*)0);
5481
5482 nfs3 = (struct nfs3_state *)GF_CALLOC (1, sizeof (*nfs3),__gf_calloc (1, sizeof (*nfs3), gf_nfs_mt_nfs3_state)
5483 gf_nfs_mt_nfs3_state)__gf_calloc (1, sizeof (*nfs3), gf_nfs_mt_nfs3_state);
5484 if (!nfs3) {
5485 gf_log (GF_NFS3, GF_LOG_ERROR, "Memory allocation failed")do { do { if (0) printf ("Memory allocation failed"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5485, GF_LOG_ERROR
, "Memory allocation failed"); } while (0)
;
5486 return NULL((void*)0);
5487 }
5488
5489 nfs = nfsx->private;
5490 ret = nfs3_init_options (nfs3, nfsx);
5491 if (ret == -1) {
5492 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to init options")do { do { if (0) printf ("Failed to init options"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5492, GF_LOG_ERROR
, "Failed to init options"); } while (0)
;
5493 goto ret;
5494 }
5495
5496 nfs3->iobpool = nfsx->ctx->iobuf_pool;
5497
5498 localpool = nfs3->memfactor * GF_NFS_CONCURRENT_OPS_MULT15;
5499 gf_log (GF_NFS3, GF_LOG_TRACE, "local pool: %d", localpool)do { do { if (0) printf ("local pool: %d", localpool); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5499, GF_LOG_TRACE
, "local pool: %d", localpool); } while (0)
;
5500 nfs3->localpool = mem_pool_new (nfs3_call_state_t, localpool)mem_pool_new_fn (sizeof(nfs3_call_state_t), localpool, "nfs3_call_state_t"
)
;
5501 if (!nfs3->localpool) {
5502 gf_log (GF_NFS3, GF_LOG_ERROR, "local mempool creation failed")do { do { if (0) printf ("local mempool creation failed"); } while
(0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5502, GF_LOG_ERROR
, "local mempool creation failed"); } while (0)
;
5503 ret = -1;
5504 goto ret;
5505 }
5506
5507 nfs3->nfsx = nfsx;
5508 nfs3->exportslist = nfsx->children;
5509 INIT_LIST_HEAD (&nfs3->exports)do { (&nfs3->exports)->next = (&nfs3->exports
)->prev = &nfs3->exports; } while (0)
;
5510 ret = nfs3_init_subvolumes (nfs3);
5511 if (ret == -1) {
5512 gf_log (GF_NFS3, GF_LOG_ERROR, "Failed to init per-subvolume "do { do { if (0) printf ("Failed to init per-subvolume " "state"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5513, GF_LOG_ERROR, "Failed to init per-subvolume " "state"
); } while (0)
5513 "state")do { do { if (0) printf ("Failed to init per-subvolume " "state"
); } while (0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__
, 5513, GF_LOG_ERROR, "Failed to init per-subvolume " "state"
); } while (0)
;
5514 goto free_localpool;
5515 }
5516
5517 nfs3->serverstart = (uint64_t)time (NULL((void*)0));
5518 INIT_LIST_HEAD (&nfs3->fdlru)do { (&nfs3->fdlru)->next = (&nfs3->fdlru)->
prev = &nfs3->fdlru; } while (0)
;
5519 LOCK_INIT (&nfs3->fdlrulock)pthread_spin_init (&nfs3->fdlrulock, 0);
5520 nfs3->fdcount = 0;
5521
5522 rpcsvc_create_listeners (nfs->rpcsvc, nfsx->options, nfsx->name);
5523 if (ret == -1) {
5524 gf_log (GF_NFS, GF_LOG_ERROR, "Unable to create listeners")do { do { if (0) printf ("Unable to create listeners"); } while
(0); _gf_log ("nfs", "nfs3.c", __FUNCTION__, 5524, GF_LOG_ERROR
, "Unable to create listeners"); } while (0)
;
5525 goto free_localpool;
5526 }
5527
5528 nfs->nfs3state = nfs3;
5529 ret = 0;
5530
5531free_localpool:
5532 if (ret == -1)
5533 mem_pool_destroy (nfs3->localpool);
5534
5535ret:
5536 if (ret == -1) {
5537 GF_FREE (nfs3)__gf_free (nfs3);
5538 nfs3 = NULL((void*)0);
5539 }
5540
5541 return nfs3;
5542}
5543
5544
5545rpcsvc_program_t *
5546nfs3svc_init (xlator_t *nfsx)
5547{
5548 struct nfs3_state *nfs3 = NULL((void*)0);
5549
5550 if (!nfsx)
5551 return NULL((void*)0);
5552
5553 nfs3 = nfs3_init_state (nfsx);
5554 if (!nfs3) {
5555 gf_log (GF_NFS3, GF_LOG_ERROR, "NFSv3 state init failed")do { do { if (0) printf ("NFSv3 state init failed"); } while (
0); _gf_log ("nfs""-nfsv3", "nfs3.c", __FUNCTION__, 5555, GF_LOG_ERROR
, "NFSv3 state init failed"); } while (0)
;
5556 return NULL((void*)0);
5557 }
5558
5559 nfs3prog.private = nfs3;
5560
5561 return &nfs3prog;
5562}
5563
5564