Bug Summary

File:xlators/storage/posix/src/posix-helpers.c
Location:line 1013, column 23
Description:Null pointer passed as an argument to a 'nonnull' parameter

Annotated Source Code

1/*
2 Copyright (c) 2006-2012 Red Hat, Inc. <http://www.redhat.com>
3 This file is part of GlusterFS.
4
5 This file is licensed to you under your choice of the GNU Lesser
6 General Public License, version 3 or any later version (LGPLv3 or
7 later), or the GNU General Public License, version 2 (GPLv2), in all
8 cases as published by the Free Software Foundation.
9*/
10#ifndef _CONFIG_H
11#define _CONFIG_H
12#include "config.h"
13#endif
14
15#define __XOPEN_SOURCE500 500
16
17#include <stdint.h>
18#include <sys/time.h>
19#include <sys/resource.h>
20#include <errno(*__errno_location ()).h>
21#include <libgen.h>
22#include <pthread.h>
23#include <ftw.h>
24#include <sys/stat.h>
25
26#ifndef GF_BSD_HOST_OS
27#include <alloca.h>
28#endif /* GF_BSD_HOST_OS */
29
30#include "glusterfs.h"
31#include "checksum.h"
32#include "dict.h"
33#include "logging.h"
34#include "posix.h"
35#include "xlator.h"
36#include "defaults.h"
37#include "common-utils.h"
38#include "compat-errno.h"
39#include "compat.h"
40#include "byte-order.h"
41#include "syscall.h"
42#include "statedump.h"
43#include "locking.h"
44#include "timer.h"
45#include "glusterfs3-xdr.h"
46#include "hashfn.h"
47#include <fnmatch.h>
48
49char *marker_xattrs[] = {"trusted.glusterfs.quota.*",
50 "trusted.glusterfs.*.xtime",
51 NULL((void*)0)};
52
53static char* posix_ignore_xattrs[] = {
54 "gfid-req",
55 GLUSTERFS_ENTRYLK_COUNT"glusterfs.entrylk-count",
56 GLUSTERFS_INODELK_COUNT"glusterfs.inodelk-count",
57 GLUSTERFS_POSIXLK_COUNT"glusterfs.posixlk-count",
58 NULL((void*)0)
59};
60
61gf_boolean_t
62posix_special_xattr (char **pattern, char *key)
63{
64 int i = 0;
65 gf_boolean_t flag = _gf_false;
66
67 GF_VALIDATE_OR_GOTO ("posix", pattern, out)do { if (!pattern) { (*__errno_location ()) = 22; do { do { if
(0) printf ("invalid argument: " "pattern"); } while (0); _gf_log_callingfn
("posix", "posix-helpers.c", __FUNCTION__, 67, GF_LOG_ERROR,
"invalid argument: " "pattern"); } while (0); goto out; } } while
(0)
;
68 GF_VALIDATE_OR_GOTO ("posix", key, out)do { if (!key) { (*__errno_location ()) = 22; do { do { if (0
) printf ("invalid argument: " "key"); } while (0); _gf_log_callingfn
("posix", "posix-helpers.c", __FUNCTION__, 68, GF_LOG_ERROR,
"invalid argument: " "key"); } while (0); goto out; } } while
(0)
;
69
70 for (i = 0; pattern[i]; i++) {
71 if (!fnmatch (pattern[i], key, 0)) {
72 flag = _gf_true;
73 break;
74 }
75 }
76out:
77 return flag;
78}
79
80static gf_boolean_t
81posix_xattr_ignorable (char *key, posix_xattr_filler_t *filler)
82{
83 int i = 0;
84 gf_boolean_t ignore = _gf_false;
85
86 GF_ASSERT (key)do { if (!(key)) { do { do { if (0) printf ("Assertion failed: "
"key"); } while (0); _gf_log_callingfn ("", "posix-helpers.c"
, __FUNCTION__, 86, GF_LOG_ERROR, "Assertion failed: " "key")
; } while (0); } } while (0)
;
87 if (!key)
88 goto out;
89 for (i = 0; posix_ignore_xattrs[i]; i++) {
90 if (!strcmp (key, posix_ignore_xattrs[i])) {
91 ignore = _gf_true;
92 goto out;
93 }
94 }
95 if ((!strcmp (key, GF_CONTENT_KEY"glusterfs.content"))
96 && (!IA_ISREG (filler->stbuf->ia_type)(filler->stbuf->ia_type == IA_IFREG)))
97 ignore = _gf_true;
98out:
99 return ignore;
100}
101
102static int
103_posix_xattr_get_set (dict_t *xattr_req,
104 char *key,
105 data_t *data,
106 void *xattrargs)
107{
108 posix_xattr_filler_t *filler = xattrargs;
109 char *value = NULL((void*)0);
110 ssize_t xattr_size = -1;
111 int ret = -1;
112 char *databuf = NULL((void*)0);
113 int _fd = -1;
114 loc_t *loc = NULL((void*)0);
115 ssize_t req_size = 0;
116
117
118 if (posix_xattr_ignorable (key, filler))
119 goto out;
120 /* should size be put into the data_t ? */
121 if (!strcmp (key, GF_CONTENT_KEY"glusterfs.content")
122 && IA_ISREG (filler->stbuf->ia_type)(filler->stbuf->ia_type == IA_IFREG)) {
123
124 /* file content request */
125 req_size = data_to_uint64 (data);
126 if (req_size >= filler->stbuf->ia_size) {
127 _fd = open (filler->real_path, O_RDONLY00);
128 if (_fd == -1) {
129 gf_log (filler->this->name, GF_LOG_ERROR,do { do { if (0) printf ("Opening file %s failed: %s", filler
->real_path, strerror ((*__errno_location ()))); } while (
0); _gf_log (filler->this->name, "posix-helpers.c", __FUNCTION__
, 131, GF_LOG_ERROR, "Opening file %s failed: %s", filler->
real_path, strerror ((*__errno_location ()))); } while (0)
130 "Opening file %s failed: %s",do { do { if (0) printf ("Opening file %s failed: %s", filler
->real_path, strerror ((*__errno_location ()))); } while (
0); _gf_log (filler->this->name, "posix-helpers.c", __FUNCTION__
, 131, GF_LOG_ERROR, "Opening file %s failed: %s", filler->
real_path, strerror ((*__errno_location ()))); } while (0)
131 filler->real_path, strerror (errno))do { do { if (0) printf ("Opening file %s failed: %s", filler
->real_path, strerror ((*__errno_location ()))); } while (
0); _gf_log (filler->this->name, "posix-helpers.c", __FUNCTION__
, 131, GF_LOG_ERROR, "Opening file %s failed: %s", filler->
real_path, strerror ((*__errno_location ()))); } while (0)
;
132 goto err;
133 }
134
135 databuf = GF_CALLOC (1, filler->stbuf->ia_size,__gf_calloc (1, filler->stbuf->ia_size, gf_posix_mt_char
)
136 gf_posix_mt_char)__gf_calloc (1, filler->stbuf->ia_size, gf_posix_mt_char
)
;
137 if (!databuf) {
138 goto err;
139 }
140
141 ret = read (_fd, databuf, filler->stbuf->ia_size);
142 if (ret == -1) {
143 gf_log (filler->this->name, GF_LOG_ERROR,do { do { if (0) printf ("Read on file %s failed: %s", filler
->real_path, strerror ((*__errno_location ()))); } while (
0); _gf_log (filler->this->name, "posix-helpers.c", __FUNCTION__
, 145, GF_LOG_ERROR, "Read on file %s failed: %s", filler->
real_path, strerror ((*__errno_location ()))); } while (0)
144 "Read on file %s failed: %s",do { do { if (0) printf ("Read on file %s failed: %s", filler
->real_path, strerror ((*__errno_location ()))); } while (
0); _gf_log (filler->this->name, "posix-helpers.c", __FUNCTION__
, 145, GF_LOG_ERROR, "Read on file %s failed: %s", filler->
real_path, strerror ((*__errno_location ()))); } while (0)
145 filler->real_path, strerror (errno))do { do { if (0) printf ("Read on file %s failed: %s", filler
->real_path, strerror ((*__errno_location ()))); } while (
0); _gf_log (filler->this->name, "posix-helpers.c", __FUNCTION__
, 145, GF_LOG_ERROR, "Read on file %s failed: %s", filler->
real_path, strerror ((*__errno_location ()))); } while (0)
;
146 goto err;
147 }
148
149 ret = close (_fd);
150 _fd = -1;
151 if (ret == -1) {
152 gf_log (filler->this->name, GF_LOG_ERROR,do { do { if (0) printf ("Close on file %s failed: %s", filler
->real_path, strerror ((*__errno_location ()))); } while (
0); _gf_log (filler->this->name, "posix-helpers.c", __FUNCTION__
, 154, GF_LOG_ERROR, "Close on file %s failed: %s", filler->
real_path, strerror ((*__errno_location ()))); } while (0)
153 "Close on file %s failed: %s",do { do { if (0) printf ("Close on file %s failed: %s", filler
->real_path, strerror ((*__errno_location ()))); } while (
0); _gf_log (filler->this->name, "posix-helpers.c", __FUNCTION__
, 154, GF_LOG_ERROR, "Close on file %s failed: %s", filler->
real_path, strerror ((*__errno_location ()))); } while (0)
154 filler->real_path, strerror (errno))do { do { if (0) printf ("Close on file %s failed: %s", filler
->real_path, strerror ((*__errno_location ()))); } while (
0); _gf_log (filler->this->name, "posix-helpers.c", __FUNCTION__
, 154, GF_LOG_ERROR, "Close on file %s failed: %s", filler->
real_path, strerror ((*__errno_location ()))); } while (0)
;
155 goto err;
156 }
157
158 ret = dict_set_bin (filler->xattr, key,
159 databuf, filler->stbuf->ia_size);
160 if (ret < 0) {
161 gf_log (filler->this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to set dict value. key: %s, path: %s"
, key, filler->real_path); } while (0); _gf_log (filler->
this->name, "posix-helpers.c", __FUNCTION__, 163, GF_LOG_ERROR
, "failed to set dict value. key: %s, path: %s", key, filler->
real_path); } while (0)
162 "failed to set dict value. key: %s, path: %s",do { do { if (0) printf ("failed to set dict value. key: %s, path: %s"
, key, filler->real_path); } while (0); _gf_log (filler->
this->name, "posix-helpers.c", __FUNCTION__, 163, GF_LOG_ERROR
, "failed to set dict value. key: %s, path: %s", key, filler->
real_path); } while (0)
163 key, filler->real_path)do { do { if (0) printf ("failed to set dict value. key: %s, path: %s"
, key, filler->real_path); } while (0); _gf_log (filler->
this->name, "posix-helpers.c", __FUNCTION__, 163, GF_LOG_ERROR
, "failed to set dict value. key: %s, path: %s", key, filler->
real_path); } while (0)
;
164 goto err;
165 }
166
167 /* To avoid double free in cleanup below */
168 databuf = NULL((void*)0);
169 err:
170 if (_fd != -1)
171 close (_fd);
172 GF_FREE (databuf)__gf_free (databuf);
173 }
174 } else if (!strcmp (key, GLUSTERFS_OPEN_FD_COUNT"glusterfs.open-fd-count")) {
175 loc = filler->loc;
176 if (loc) {
177 ret = dict_set_uint32 (filler->xattr, key,
178 loc->inode->fd_count);
179 if (ret < 0)
180 gf_log (filler->this->name, GF_LOG_WARNING,do { do { if (0) printf ("Failed to set dictionary value for %s"
, key); } while (0); _gf_log (filler->this->name, "posix-helpers.c"
, __FUNCTION__, 182, GF_LOG_WARNING, "Failed to set dictionary value for %s"
, key); } while (0)
181 "Failed to set dictionary value for %s",do { do { if (0) printf ("Failed to set dictionary value for %s"
, key); } while (0); _gf_log (filler->this->name, "posix-helpers.c"
, __FUNCTION__, 182, GF_LOG_WARNING, "Failed to set dictionary value for %s"
, key); } while (0)
182 key)do { do { if (0) printf ("Failed to set dictionary value for %s"
, key); } while (0); _gf_log (filler->this->name, "posix-helpers.c"
, __FUNCTION__, 182, GF_LOG_WARNING, "Failed to set dictionary value for %s"
, key); } while (0)
;
183 }
184 } else {
185 xattr_size = sys_lgetxattr (filler->real_path, key, NULL((void*)0), 0);
186
187 if (xattr_size > 0) {
188 value = GF_CALLOC (1, xattr_size + 1,__gf_calloc (1, xattr_size + 1, gf_posix_mt_char)
189 gf_posix_mt_char)__gf_calloc (1, xattr_size + 1, gf_posix_mt_char);
190 if (!value)
191 return -1;
192
193 xattr_size = sys_lgetxattr (filler->real_path, key, value,
194 xattr_size);
195 if (xattr_size <= 0) {
196 gf_log (filler->this->name, GF_LOG_WARNING,do { do { if (0) printf ("getxattr failed. path: %s, key: %s"
, filler->real_path, key); } while (0); _gf_log (filler->
this->name, "posix-helpers.c", __FUNCTION__, 198, GF_LOG_WARNING
, "getxattr failed. path: %s, key: %s", filler->real_path,
key); } while (0)
197 "getxattr failed. path: %s, key: %s",do { do { if (0) printf ("getxattr failed. path: %s, key: %s"
, filler->real_path, key); } while (0); _gf_log (filler->
this->name, "posix-helpers.c", __FUNCTION__, 198, GF_LOG_WARNING
, "getxattr failed. path: %s, key: %s", filler->real_path,
key); } while (0)
198 filler->real_path, key)do { do { if (0) printf ("getxattr failed. path: %s, key: %s"
, filler->real_path, key); } while (0); _gf_log (filler->
this->name, "posix-helpers.c", __FUNCTION__, 198, GF_LOG_WARNING
, "getxattr failed. path: %s, key: %s", filler->real_path,
key); } while (0)
;
199 GF_FREE (value)__gf_free (value);
200 return -1;
201 }
202
203 value[xattr_size] = '\0';
204 ret = dict_set_bin (filler->xattr, key,
205 value, xattr_size);
206 if (ret < 0) {
207 gf_log (filler->this->name, GF_LOG_DEBUG,do { do { if (0) printf ("dict set failed. path: %s, key: %s"
, filler->real_path, key); } while (0); _gf_log (filler->
this->name, "posix-helpers.c", __FUNCTION__, 209, GF_LOG_DEBUG
, "dict set failed. path: %s, key: %s", filler->real_path,
key); } while (0)
208 "dict set failed. path: %s, key: %s",do { do { if (0) printf ("dict set failed. path: %s, key: %s"
, filler->real_path, key); } while (0); _gf_log (filler->
this->name, "posix-helpers.c", __FUNCTION__, 209, GF_LOG_DEBUG
, "dict set failed. path: %s, key: %s", filler->real_path,
key); } while (0)
209 filler->real_path, key)do { do { if (0) printf ("dict set failed. path: %s, key: %s"
, filler->real_path, key); } while (0); _gf_log (filler->
this->name, "posix-helpers.c", __FUNCTION__, 209, GF_LOG_DEBUG
, "dict set failed. path: %s, key: %s", filler->real_path,
key); } while (0)
;
210 GF_FREE (value)__gf_free (value);
211 }
212 }
213 }
214out:
215 return 0;
216}
217
218
219int
220posix_fill_gfid_path (xlator_t *this, const char *path, struct iatt *iatt)
221{
222 int ret = 0;
223 ssize_t size = 0;
224
225 if (!iatt)
226 return 0;
227
228 size = sys_lgetxattr (path, GFID_XATTR_KEY"trusted.gfid", iatt->ia_gfid, 16);
229 /* Return value of getxattr */
230 if ((size == 16) || (size == -1))
231 ret = 0;
232 else
233 ret = size;
234
235 return ret;
236}
237
238
239int
240posix_fill_gfid_fd (xlator_t *this, int fd, struct iatt *iatt)
241{
242 int ret = 0;
243 ssize_t size = 0;
244
245 if (!iatt)
246 return 0;
247
248 size = sys_fgetxattr (fd, GFID_XATTR_KEY"trusted.gfid", iatt->ia_gfid, 16);
249 /* Return value of getxattr */
250 if ((size == 16) || (size == -1))
251 ret = 0;
252 else
253 ret = size;
254
255 return ret;
256}
257
258void
259posix_fill_ino_from_gfid (xlator_t *this, struct iatt *buf)
260{
261 uint64_t temp_ino = 0;
262 int j = 0;
263 int i = 0;
264
265 /* consider least significant 8 bytes of value out of gfid */
266 if (uuid_is_null (buf->ia_gfid)) {
267 buf->ia_ino = -1;
268 goto out;
269 }
270 for (i = 15; i > (15 - 8); i--) {
271 temp_ino += (uint64_t)(buf->ia_gfid[i]) << j;
272 j += 8;
273 }
274 buf->ia_ino = temp_ino;
275out:
276 return;
277}
278
279int
280posix_fdstat (xlator_t *this, int fd, struct iatt *stbuf_p)
281{
282 int ret = 0;
283 struct stat fstatbuf = {0, };
284 struct iatt stbuf = {0, };
285
286 ret = fstat (fd, &fstatbuf);
287 if (ret == -1)
288 goto out;
289
290 if (fstatbuf.st_nlink && !S_ISDIR (fstatbuf.st_mode)((((fstatbuf.st_mode)) & 0170000) == (0040000)))
291 fstatbuf.st_nlink--;
292
293 iatt_from_stat (&stbuf, &fstatbuf);
294
295 ret = posix_fill_gfid_fd (this, fd, &stbuf);
296 if (ret)
297 gf_log_callingfn (this->name, GF_LOG_DEBUG, "failed to get gfid")do { do { if (0) printf ("failed to get gfid"); } while (0); _gf_log_callingfn
(this->name, "posix-helpers.c", __FUNCTION__, 297, GF_LOG_DEBUG
, "failed to get gfid"); } while (0)
;
298
299 posix_fill_ino_from_gfid (this, &stbuf);
300
301 if (stbuf_p)
302 *stbuf_p = stbuf;
303
304out:
305 return ret;
306}
307
308
309int
310posix_istat (xlator_t *this, uuid_t gfid, const char *basename__xpg_basename,
311 struct iatt *buf_p)
312{
313 char *real_path = NULL((void*)0);
314 struct stat lstatbuf = {0, };
315 struct iatt stbuf = {0, };
316 int ret = 0;
317 struct posix_private *priv = NULL((void*)0);
318
319
320 priv = this->private;
321
322 MAKE_HANDLE_PATH (real_path, this, gfid, basename)do { int __len; __len = posix_handle_path (this, gfid, __xpg_basename
, ((void*)0), 0); if (__len <= 0) break; real_path = __builtin_alloca
(__len); __len = posix_handle_path (this, gfid, __xpg_basename
, real_path, __len); } while (0)
;
323
324 ret = lstat (real_path, &lstatbuf);
325
326 if (ret != 0) {
327 if (ret == -1) {
328 if (errno(*__errno_location ()) != ENOENT2 && errno(*__errno_location ()) != ELOOP40)
329 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("lstat failed on %s (%s)", real_path
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 331, GF_LOG_WARNING
, "lstat failed on %s (%s)", real_path, strerror ((*__errno_location
()))); } while (0)
330 "lstat failed on %s (%s)",do { do { if (0) printf ("lstat failed on %s (%s)", real_path
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 331, GF_LOG_WARNING
, "lstat failed on %s (%s)", real_path, strerror ((*__errno_location
()))); } while (0)
331 real_path, strerror (errno))do { do { if (0) printf ("lstat failed on %s (%s)", real_path
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 331, GF_LOG_WARNING
, "lstat failed on %s (%s)", real_path, strerror ((*__errno_location
()))); } while (0)
;
332 } else {
333 // may be some backend filesystem issue
334 gf_log (this->name, GF_LOG_ERROR, "lstat failed on "do { do { if (0) printf ("lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, real_path, ret); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 338, GF_LOG_ERROR, "lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, real_path, ret); } while (0)
335 "%s and return value is %d instead of -1. "do { do { if (0) printf ("lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, real_path, ret); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 338, GF_LOG_ERROR, "lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, real_path, ret); } while (0)
336 "Please see dmesg output to check whether the "do { do { if (0) printf ("lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, real_path, ret); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 338, GF_LOG_ERROR, "lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, real_path, ret); } while (0)
337 "failure is due to backend filesystem issue",do { do { if (0) printf ("lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, real_path, ret); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 338, GF_LOG_ERROR, "lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, real_path, ret); } while (0)
338 real_path, ret)do { do { if (0) printf ("lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, real_path, ret); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 338, GF_LOG_ERROR, "lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, real_path, ret); } while (0)
;
339 ret = -1;
340 }
341 goto out;
342 }
343
344 if ((lstatbuf.st_ino == priv->handledir.st_ino) &&
345 (lstatbuf.st_dev == priv->handledir.st_dev)) {
346 errno(*__errno_location ()) = ENOENT2;
347 return -1;
348 }
349
350 if (!S_ISDIR (lstatbuf.st_mode)((((lstatbuf.st_mode)) & 0170000) == (0040000)))
351 lstatbuf.st_nlink --;
352
353 iatt_from_stat (&stbuf, &lstatbuf);
354
355 if (basename__xpg_basename)
356 posix_fill_gfid_path (this, real_path, &stbuf);
357 else
358 uuid_copy (stbuf.ia_gfid, gfid);
359
360 posix_fill_ino_from_gfid (this, &stbuf);
361
362 if (buf_p)
363 *buf_p = stbuf;
364out:
365 return ret;
366}
367
368
369
370int
371posix_pstat (xlator_t *this, uuid_t gfid, const char *path,
372 struct iatt *buf_p)
373{
374 struct stat lstatbuf = {0, };
375 struct iatt stbuf = {0, };
376 int ret = 0;
377 struct posix_private *priv = NULL((void*)0);
378
379
380 priv = this->private;
381
382 ret = lstat (path, &lstatbuf);
383
384 if (ret != 0) {
385 if (ret == -1) {
386 if (errno(*__errno_location ()) != ENOENT2)
387 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("lstat failed on %s (%s)", path, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 389, GF_LOG_WARNING, "lstat failed on %s (%s)"
, path, strerror ((*__errno_location ()))); } while (0)
388 "lstat failed on %s (%s)",do { do { if (0) printf ("lstat failed on %s (%s)", path, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 389, GF_LOG_WARNING, "lstat failed on %s (%s)"
, path, strerror ((*__errno_location ()))); } while (0)
389 path, strerror (errno))do { do { if (0) printf ("lstat failed on %s (%s)", path, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 389, GF_LOG_WARNING, "lstat failed on %s (%s)"
, path, strerror ((*__errno_location ()))); } while (0)
;
390 } else {
391 // may be some backend filesytem issue
392 gf_log (this->name, GF_LOG_ERROR, "lstat failed on "do { do { if (0) printf ("lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, path, ret); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 396, GF_LOG_ERROR, "lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, path, ret); } while (0)
393 "%s and return value is %d instead of -1. "do { do { if (0) printf ("lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, path, ret); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 396, GF_LOG_ERROR, "lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, path, ret); } while (0)
394 "Please see dmesg output to check whether the "do { do { if (0) printf ("lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, path, ret); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 396, GF_LOG_ERROR, "lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, path, ret); } while (0)
395 "failure is due to backend filesystem issue",do { do { if (0) printf ("lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, path, ret); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 396, GF_LOG_ERROR, "lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, path, ret); } while (0)
396 path, ret)do { do { if (0) printf ("lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, path, ret); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 396, GF_LOG_ERROR, "lstat failed on " "%s and return value is %d instead of -1. "
"Please see dmesg output to check whether the " "failure is due to backend filesystem issue"
, path, ret); } while (0)
;
397 ret = -1;
398 }
399 goto out;
400 }
401
402 if ((lstatbuf.st_ino == priv->handledir.st_ino) &&
403 (lstatbuf.st_dev == priv->handledir.st_dev)) {
404 errno(*__errno_location ()) = ENOENT2;
405 return -1;
406 }
407
408 if (!S_ISDIR (lstatbuf.st_mode)((((lstatbuf.st_mode)) & 0170000) == (0040000)))
409 lstatbuf.st_nlink --;
410
411 iatt_from_stat (&stbuf, &lstatbuf);
412
413 if (gfid && !uuid_is_null (gfid))
414 uuid_copy (stbuf.ia_gfid, gfid);
415 else
416 posix_fill_gfid_path (this, path, &stbuf);
417
418 posix_fill_ino_from_gfid (this, &stbuf);
419
420 if (buf_p)
421 *buf_p = stbuf;
422out:
423 return ret;
424}
425
426
427dict_t *
428posix_lookup_xattr_fill (xlator_t *this, const char *real_path, loc_t *loc,
429 dict_t *xattr_req, struct iatt *buf)
430{
431 dict_t *xattr = NULL((void*)0);
432 posix_xattr_filler_t filler = {0, };
433
434 xattr = get_new_dict();
435 if (!xattr) {
436 goto out;
437 }
438
439 filler.this = this;
440 filler.real_path = real_path;
441 filler.xattr = xattr;
442 filler.stbuf = buf;
443 filler.loc = loc;
444
445 dict_foreach (xattr_req, _posix_xattr_get_set, &filler);
446out:
447 return xattr;
448}
449
450
451int
452posix_gfid_set (xlator_t *this, const char *path, loc_t *loc, dict_t *xattr_req)
453{
454 void *uuid_req = NULL((void*)0);
455 uuid_t uuid_curr;
456 int ret = 0;
457 ssize_t size = 0;
458 struct stat stat = {0, };
459
460
461 if (!xattr_req)
462 goto out;
463
464 if (sys_lstat (path, &stat) != 0)
465 goto out;
466
467 size = sys_lgetxattr (path, GFID_XATTR_KEY"trusted.gfid", uuid_curr, 16);
468 if (size == 16) {
469 ret = 0;
470 goto verify_handle;
471 }
472
473 ret = dict_get_ptr (xattr_req, "gfid-req", &uuid_req);
474 if (ret) {
475 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("failed to get the gfid from dict for %s"
, loc->path); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 477, GF_LOG_DEBUG, "failed to get the gfid from dict for %s"
, loc->path); } while (0)
476 "failed to get the gfid from dict for %s",do { do { if (0) printf ("failed to get the gfid from dict for %s"
, loc->path); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 477, GF_LOG_DEBUG, "failed to get the gfid from dict for %s"
, loc->path); } while (0)
477 loc->path)do { do { if (0) printf ("failed to get the gfid from dict for %s"
, loc->path); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 477, GF_LOG_DEBUG, "failed to get the gfid from dict for %s"
, loc->path); } while (0)
;
478 goto out;
479 }
480
481 ret = sys_lsetxattr (path, GFID_XATTR_KEY"trusted.gfid", uuid_req, 16, XATTR_CREATEXATTR_CREATE);
482 if (ret != 0) {
483 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("setting GFID on %s failed (%s)", path
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 485, GF_LOG_WARNING
, "setting GFID on %s failed (%s)", path, strerror ((*__errno_location
()))); } while (0)
484 "setting GFID on %s failed (%s)", path,do { do { if (0) printf ("setting GFID on %s failed (%s)", path
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 485, GF_LOG_WARNING
, "setting GFID on %s failed (%s)", path, strerror ((*__errno_location
()))); } while (0)
485 strerror (errno))do { do { if (0) printf ("setting GFID on %s failed (%s)", path
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 485, GF_LOG_WARNING
, "setting GFID on %s failed (%s)", path, strerror ((*__errno_location
()))); } while (0)
;
486 goto out;
487 }
488 uuid_copy (uuid_curr, uuid_req);
489
490verify_handle:
491 if (!S_ISDIR (stat.st_mode)((((stat.st_mode)) & 0170000) == (0040000)))
492 ret = posix_handle_hard (this, path, uuid_curr, &stat);
493 else
494 ret = posix_handle_soft (this, path, loc, uuid_curr, &stat);
495
496out:
497 return ret;
498}
499
500
501int
502posix_set_file_contents (xlator_t *this, const char *path, char *keyp,
503 data_t *value, int flags)
504{
505 char * key = NULL((void*)0);
506 char real_path[PATH_MAX4096];
507 int32_t file_fd = -1;
508 int op_ret = 0;
509 int ret = -1;
510
511
512 /* XXX: does not handle assigning GFID to created files */
513 return -1;
514
515 key = &(keyp[15]);
516 sprintf (real_path, "%s/%s", path, key);
517
518 if (flags & XATTR_REPLACEXATTR_REPLACE) {
519 /* if file exists, replace it
520 * else, error out */
521 file_fd = open (real_path, O_TRUNC01000|O_WRONLY01);
522
523 if (file_fd == -1) {
524 goto create;
525 }
526
527 if (value->len) {
528 ret = write (file_fd, value->data, value->len);
529 if (ret == -1) {
530 op_ret = -errno(*__errno_location ());
531 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("write failed while doing setxattr "
"for key %s on path %s: %s", key, real_path, strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 534, GF_LOG_ERROR, "write failed while doing setxattr "
"for key %s on path %s: %s", key, real_path, strerror ((*__errno_location
()))); } while (0)
532 "write failed while doing setxattr "do { do { if (0) printf ("write failed while doing setxattr "
"for key %s on path %s: %s", key, real_path, strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 534, GF_LOG_ERROR, "write failed while doing setxattr "
"for key %s on path %s: %s", key, real_path, strerror ((*__errno_location
()))); } while (0)
533 "for key %s on path %s: %s",do { do { if (0) printf ("write failed while doing setxattr "
"for key %s on path %s: %s", key, real_path, strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 534, GF_LOG_ERROR, "write failed while doing setxattr "
"for key %s on path %s: %s", key, real_path, strerror ((*__errno_location
()))); } while (0)
534 key, real_path, strerror (errno))do { do { if (0) printf ("write failed while doing setxattr "
"for key %s on path %s: %s", key, real_path, strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 534, GF_LOG_ERROR, "write failed while doing setxattr "
"for key %s on path %s: %s", key, real_path, strerror ((*__errno_location
()))); } while (0)
;
535 goto out;
536 }
537
538 ret = close (file_fd);
539 if (ret == -1) {
540 op_ret = -errno(*__errno_location ());
541 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("close failed on %s: %s", real_path,
strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 543, GF_LOG_ERROR
, "close failed on %s: %s", real_path, strerror ((*__errno_location
()))); } while (0)
542 "close failed on %s: %s",do { do { if (0) printf ("close failed on %s: %s", real_path,
strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 543, GF_LOG_ERROR
, "close failed on %s: %s", real_path, strerror ((*__errno_location
()))); } while (0)
543 real_path, strerror (errno))do { do { if (0) printf ("close failed on %s: %s", real_path,
strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 543, GF_LOG_ERROR
, "close failed on %s: %s", real_path, strerror ((*__errno_location
()))); } while (0)
;
544 goto out;
545 }
546 }
547
548 create: /* we know file doesn't exist, create it */
549
550 file_fd = open (real_path, O_CREAT0100|O_WRONLY01, 0644);
551
552 if (file_fd == -1) {
553 op_ret = -errno(*__errno_location ());
554 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to open file %s with O_CREAT: %s"
, key, strerror ((*__errno_location ()))); } while (0); _gf_log
(this->name, "posix-helpers.c", __FUNCTION__, 556, GF_LOG_ERROR
, "failed to open file %s with O_CREAT: %s", key, strerror ((
*__errno_location ()))); } while (0)
555 "failed to open file %s with O_CREAT: %s",do { do { if (0) printf ("failed to open file %s with O_CREAT: %s"
, key, strerror ((*__errno_location ()))); } while (0); _gf_log
(this->name, "posix-helpers.c", __FUNCTION__, 556, GF_LOG_ERROR
, "failed to open file %s with O_CREAT: %s", key, strerror ((
*__errno_location ()))); } while (0)
556 key, strerror (errno))do { do { if (0) printf ("failed to open file %s with O_CREAT: %s"
, key, strerror ((*__errno_location ()))); } while (0); _gf_log
(this->name, "posix-helpers.c", __FUNCTION__, 556, GF_LOG_ERROR
, "failed to open file %s with O_CREAT: %s", key, strerror ((
*__errno_location ()))); } while (0)
;
557 goto out;
558 }
559
560 ret = write (file_fd, value->data, value->len);
561 if (ret == -1) {
562 op_ret = -errno(*__errno_location ());
563 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("write failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0); _gf_log (this->name, "posix-helpers.c",
__FUNCTION__, 566, GF_LOG_ERROR, "write failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0)
564 "write failed on %s while setxattr with "do { do { if (0) printf ("write failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0); _gf_log (this->name, "posix-helpers.c",
__FUNCTION__, 566, GF_LOG_ERROR, "write failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0)
565 "key %s: %s",do { do { if (0) printf ("write failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0); _gf_log (this->name, "posix-helpers.c",
__FUNCTION__, 566, GF_LOG_ERROR, "write failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0)
566 real_path, key, strerror (errno))do { do { if (0) printf ("write failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0); _gf_log (this->name, "posix-helpers.c",
__FUNCTION__, 566, GF_LOG_ERROR, "write failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0)
;
567 goto out;
568 }
569
570 ret = close (file_fd);
571 if (ret == -1) {
572 op_ret = -errno(*__errno_location ());
573 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("close failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0); _gf_log (this->name, "posix-helpers.c",
__FUNCTION__, 576, GF_LOG_ERROR, "close failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0)
574 "close failed on %s while setxattr with "do { do { if (0) printf ("close failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0); _gf_log (this->name, "posix-helpers.c",
__FUNCTION__, 576, GF_LOG_ERROR, "close failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0)
575 "key %s: %s",do { do { if (0) printf ("close failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0); _gf_log (this->name, "posix-helpers.c",
__FUNCTION__, 576, GF_LOG_ERROR, "close failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0)
576 real_path, key, strerror (errno))do { do { if (0) printf ("close failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0); _gf_log (this->name, "posix-helpers.c",
__FUNCTION__, 576, GF_LOG_ERROR, "close failed on %s while setxattr with "
"key %s: %s", real_path, key, strerror ((*__errno_location (
)))); } while (0)
;
577 goto out;
578 }
579 }
580
581out:
582 return op_ret;
583}
584
585
586int
587posix_get_file_contents (xlator_t *this, uuid_t pargfid,
588 const char *name, char **contents)
589{
590 char *real_path = NULL((void*)0);
591 int32_t file_fd = -1;
592 struct iatt stbuf = {0,};
593 int op_ret = 0;
594 int ret = -1;
595
596
597 MAKE_HANDLE_PATH (real_path, this, pargfid, name)do { int __len; __len = posix_handle_path (this, pargfid, name
, ((void*)0), 0); if (__len <= 0) break; real_path = __builtin_alloca
(__len); __len = posix_handle_path (this, pargfid, name, real_path
, __len); } while (0)
;
598
599 op_ret = posix_istat (this, pargfid, name, &stbuf);
600 if (op_ret == -1) {
601 op_ret = -errno(*__errno_location ());
602 gf_log (this->name, GF_LOG_ERROR, "lstat failed on %s: %s",do { do { if (0) printf ("lstat failed on %s: %s", real_path,
strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 603, GF_LOG_ERROR
, "lstat failed on %s: %s", real_path, strerror ((*__errno_location
()))); } while (0)
603 real_path, strerror (errno))do { do { if (0) printf ("lstat failed on %s: %s", real_path,
strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 603, GF_LOG_ERROR
, "lstat failed on %s: %s", real_path, strerror ((*__errno_location
()))); } while (0)
;
604 goto out;
605 }
606
607 file_fd = open (real_path, O_RDONLY00);
608
609 if (file_fd == -1) {
610 op_ret = -errno(*__errno_location ());
611 gf_log (this->name, GF_LOG_ERROR, "open failed on %s: %s",do { do { if (0) printf ("open failed on %s: %s", real_path, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 612, GF_LOG_ERROR, "open failed on %s: %s"
, real_path, strerror ((*__errno_location ()))); } while (0)
612 real_path, strerror (errno))do { do { if (0) printf ("open failed on %s: %s", real_path, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 612, GF_LOG_ERROR, "open failed on %s: %s"
, real_path, strerror ((*__errno_location ()))); } while (0)
;
613 goto out;
614 }
615
616 *contents = GF_CALLOC (stbuf.ia_size + 1, sizeof(char),__gf_calloc (stbuf.ia_size + 1, sizeof(char), gf_posix_mt_char
)
617 gf_posix_mt_char)__gf_calloc (stbuf.ia_size + 1, sizeof(char), gf_posix_mt_char
)
;
618 if (! *contents) {
619 op_ret = -errno(*__errno_location ());
620 goto out;
621 }
622
623 ret = read (file_fd, *contents, stbuf.ia_size);
624 if (ret <= 0) {
625 op_ret = -1;
626 gf_log (this->name, GF_LOG_ERROR, "read on %s failed: %s",do { do { if (0) printf ("read on %s failed: %s", real_path, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 627, GF_LOG_ERROR, "read on %s failed: %s"
, real_path, strerror ((*__errno_location ()))); } while (0)
627 real_path, strerror (errno))do { do { if (0) printf ("read on %s failed: %s", real_path, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 627, GF_LOG_ERROR, "read on %s failed: %s"
, real_path, strerror ((*__errno_location ()))); } while (0)
;
628 goto out;
629 }
630
631 *contents[stbuf.ia_size] = '\0';
632
633 op_ret = close (file_fd);
634 file_fd = -1;
635 if (op_ret == -1) {
636 op_ret = -errno(*__errno_location ());
637 gf_log (this->name, GF_LOG_ERROR, "close on %s failed: %s",do { do { if (0) printf ("close on %s failed: %s", real_path,
strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 638, GF_LOG_ERROR
, "close on %s failed: %s", real_path, strerror ((*__errno_location
()))); } while (0)
638 real_path, strerror (errno))do { do { if (0) printf ("close on %s failed: %s", real_path,
strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 638, GF_LOG_ERROR
, "close on %s failed: %s", real_path, strerror ((*__errno_location
()))); } while (0)
;
639 goto out;
640 }
641
642out:
643 if (op_ret < 0) {
644 GF_FREE (*contents)__gf_free (*contents);
645 if (file_fd != -1)
646 close (file_fd);
647 }
648
649 return op_ret;
650}
651
652static int gf_xattr_enotsup_log;
653
654int
655posix_handle_pair (xlator_t *this, const char *real_path,
656 char *key, data_t *value, int flags)
657{
658 int sys_ret = -1;
659 int ret = 0;
660
661 if (ZR_FILE_CONTENT_REQUEST(key)(!strncmp(key, "glusterfs.file.", 15))) {
662 ret = posix_set_file_contents (this, real_path, key, value,
663 flags);
664 } else {
665 sys_ret = sys_lsetxattr (real_path, key, value->data,
666 value->len, flags);
667
668 if (sys_ret < 0) {
669 if (errno(*__errno_location ()) == ENOTSUP95) {
670 GF_LOG_OCCASIONALLY(gf_xattr_enotsup_log,if (!(gf_xattr_enotsup_log++%42)) { do { do { if (0) printf (
"Extended attributes not " "supported (try remounting " "brick with 'user_xattr' "
"flag)"); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 675, GF_LOG_WARNING, "Extended attributes not "
"supported (try remounting " "brick with 'user_xattr' " "flag)"
); } while (0); }
671 this->name,GF_LOG_WARNING,if (!(gf_xattr_enotsup_log++%42)) { do { do { if (0) printf (
"Extended attributes not " "supported (try remounting " "brick with 'user_xattr' "
"flag)"); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 675, GF_LOG_WARNING, "Extended attributes not "
"supported (try remounting " "brick with 'user_xattr' " "flag)"
); } while (0); }
672 "Extended attributes not "if (!(gf_xattr_enotsup_log++%42)) { do { do { if (0) printf (
"Extended attributes not " "supported (try remounting " "brick with 'user_xattr' "
"flag)"); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 675, GF_LOG_WARNING, "Extended attributes not "
"supported (try remounting " "brick with 'user_xattr' " "flag)"
); } while (0); }
673 "supported (try remounting "if (!(gf_xattr_enotsup_log++%42)) { do { do { if (0) printf (
"Extended attributes not " "supported (try remounting " "brick with 'user_xattr' "
"flag)"); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 675, GF_LOG_WARNING, "Extended attributes not "
"supported (try remounting " "brick with 'user_xattr' " "flag)"
); } while (0); }
674 "brick with 'user_xattr' "if (!(gf_xattr_enotsup_log++%42)) { do { do { if (0) printf (
"Extended attributes not " "supported (try remounting " "brick with 'user_xattr' "
"flag)"); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 675, GF_LOG_WARNING, "Extended attributes not "
"supported (try remounting " "brick with 'user_xattr' " "flag)"
); } while (0); }
675 "flag)")if (!(gf_xattr_enotsup_log++%42)) { do { do { if (0) printf (
"Extended attributes not " "supported (try remounting " "brick with 'user_xattr' "
"flag)"); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 675, GF_LOG_WARNING, "Extended attributes not "
"supported (try remounting " "brick with 'user_xattr' " "flag)"
); } while (0); }
;
676 } else if (errno(*__errno_location ()) == ENOENT2) {
677 if (!posix_special_xattr (marker_xattrs,
678 key)) {
679 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("setxattr on %s failed: %s", real_path
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 681, GF_LOG_ERROR
, "setxattr on %s failed: %s", real_path, strerror ((*__errno_location
()))); } while (0)
680 "setxattr on %s failed: %s",do { do { if (0) printf ("setxattr on %s failed: %s", real_path
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 681, GF_LOG_ERROR
, "setxattr on %s failed: %s", real_path, strerror ((*__errno_location
()))); } while (0)
681 real_path, strerror (errno))do { do { if (0) printf ("setxattr on %s failed: %s", real_path
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 681, GF_LOG_ERROR
, "setxattr on %s failed: %s", real_path, strerror ((*__errno_location
()))); } while (0)
;
682 }
683 } else {
684
685#ifdef GF_DARWIN_HOST_OS
686 gf_log (this->name,do { do { if (0) printf ("%s: key:%s error:%s", real_path, key
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 691, (((*__errno_location
()) == 22) ? GF_LOG_DEBUG : GF_LOG_ERROR), "%s: key:%s error:%s"
, real_path, key, strerror ((*__errno_location ()))); } while
(0)
687 ((errno == EINVAL) ?do { do { if (0) printf ("%s: key:%s error:%s", real_path, key
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 691, (((*__errno_location
()) == 22) ? GF_LOG_DEBUG : GF_LOG_ERROR), "%s: key:%s error:%s"
, real_path, key, strerror ((*__errno_location ()))); } while
(0)
688 GF_LOG_DEBUG : GF_LOG_ERROR),do { do { if (0) printf ("%s: key:%s error:%s", real_path, key
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 691, (((*__errno_location
()) == 22) ? GF_LOG_DEBUG : GF_LOG_ERROR), "%s: key:%s error:%s"
, real_path, key, strerror ((*__errno_location ()))); } while
(0)
689 "%s: key:%s error:%s",do { do { if (0) printf ("%s: key:%s error:%s", real_path, key
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 691, (((*__errno_location
()) == 22) ? GF_LOG_DEBUG : GF_LOG_ERROR), "%s: key:%s error:%s"
, real_path, key, strerror ((*__errno_location ()))); } while
(0)
690 real_path, key,do { do { if (0) printf ("%s: key:%s error:%s", real_path, key
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 691, (((*__errno_location
()) == 22) ? GF_LOG_DEBUG : GF_LOG_ERROR), "%s: key:%s error:%s"
, real_path, key, strerror ((*__errno_location ()))); } while
(0)
691 strerror (errno))do { do { if (0) printf ("%s: key:%s error:%s", real_path, key
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 691, (((*__errno_location
()) == 22) ? GF_LOG_DEBUG : GF_LOG_ERROR), "%s: key:%s error:%s"
, real_path, key, strerror ((*__errno_location ()))); } while
(0)
;
692#else /* ! DARWIN */
693 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: key:%s error:%s", real_path, key
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 696, GF_LOG_ERROR
, "%s: key:%s error:%s", real_path, key, strerror ((*__errno_location
()))); } while (0)
694 "%s: key:%s error:%s",do { do { if (0) printf ("%s: key:%s error:%s", real_path, key
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 696, GF_LOG_ERROR
, "%s: key:%s error:%s", real_path, key, strerror ((*__errno_location
()))); } while (0)
695 real_path, key,do { do { if (0) printf ("%s: key:%s error:%s", real_path, key
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 696, GF_LOG_ERROR
, "%s: key:%s error:%s", real_path, key, strerror ((*__errno_location
()))); } while (0)
696 strerror (errno))do { do { if (0) printf ("%s: key:%s error:%s", real_path, key
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 696, GF_LOG_ERROR
, "%s: key:%s error:%s", real_path, key, strerror ((*__errno_location
()))); } while (0)
;
697#endif /* DARWIN */
698 }
699
700 ret = -errno(*__errno_location ());
701 goto out;
702 }
703 }
704out:
705 return ret;
706}
707
708int
709posix_fhandle_pair (xlator_t *this, int fd,
710 char *key, data_t *value, int flags)
711{
712 int sys_ret = -1;
713 int ret = 0;
714
715 sys_ret = sys_fsetxattr (fd, key, value->data,
716 value->len, flags);
717
718 if (sys_ret < 0) {
719 if (errno(*__errno_location ()) == ENOTSUP95) {
720 GF_LOG_OCCASIONALLY(gf_xattr_enotsup_log,if (!(gf_xattr_enotsup_log++%42)) { do { do { if (0) printf (
"Extended attributes not " "supported (try remounting " "brick with 'user_xattr' "
"flag)"); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 725, GF_LOG_WARNING, "Extended attributes not "
"supported (try remounting " "brick with 'user_xattr' " "flag)"
); } while (0); }
721 this->name,GF_LOG_WARNING,if (!(gf_xattr_enotsup_log++%42)) { do { do { if (0) printf (
"Extended attributes not " "supported (try remounting " "brick with 'user_xattr' "
"flag)"); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 725, GF_LOG_WARNING, "Extended attributes not "
"supported (try remounting " "brick with 'user_xattr' " "flag)"
); } while (0); }
722 "Extended attributes not "if (!(gf_xattr_enotsup_log++%42)) { do { do { if (0) printf (
"Extended attributes not " "supported (try remounting " "brick with 'user_xattr' "
"flag)"); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 725, GF_LOG_WARNING, "Extended attributes not "
"supported (try remounting " "brick with 'user_xattr' " "flag)"
); } while (0); }
723 "supported (try remounting "if (!(gf_xattr_enotsup_log++%42)) { do { do { if (0) printf (
"Extended attributes not " "supported (try remounting " "brick with 'user_xattr' "
"flag)"); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 725, GF_LOG_WARNING, "Extended attributes not "
"supported (try remounting " "brick with 'user_xattr' " "flag)"
); } while (0); }
724 "brick with 'user_xattr' "if (!(gf_xattr_enotsup_log++%42)) { do { do { if (0) printf (
"Extended attributes not " "supported (try remounting " "brick with 'user_xattr' "
"flag)"); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 725, GF_LOG_WARNING, "Extended attributes not "
"supported (try remounting " "brick with 'user_xattr' " "flag)"
); } while (0); }
725 "flag)")if (!(gf_xattr_enotsup_log++%42)) { do { do { if (0) printf (
"Extended attributes not " "supported (try remounting " "brick with 'user_xattr' "
"flag)"); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 725, GF_LOG_WARNING, "Extended attributes not "
"supported (try remounting " "brick with 'user_xattr' " "flag)"
); } while (0); }
;
726 } else if (errno(*__errno_location ()) == ENOENT2) {
727 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("fsetxattr on fd=%d failed: %s", fd,
strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 729, GF_LOG_ERROR
, "fsetxattr on fd=%d failed: %s", fd, strerror ((*__errno_location
()))); } while (0)
728 "fsetxattr on fd=%d failed: %s", fd,do { do { if (0) printf ("fsetxattr on fd=%d failed: %s", fd,
strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 729, GF_LOG_ERROR
, "fsetxattr on fd=%d failed: %s", fd, strerror ((*__errno_location
()))); } while (0)
729 strerror (errno))do { do { if (0) printf ("fsetxattr on fd=%d failed: %s", fd,
strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 729, GF_LOG_ERROR
, "fsetxattr on fd=%d failed: %s", fd, strerror ((*__errno_location
()))); } while (0)
;
730 } else {
731
732#ifdef GF_DARWIN_HOST_OS
733 gf_log (this->name,do { do { if (0) printf ("fd=%d: key:%s error:%s", fd, key, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 737, (((*__errno_location (
)) == 22) ? GF_LOG_DEBUG : GF_LOG_ERROR), "fd=%d: key:%s error:%s"
, fd, key, strerror ((*__errno_location ()))); } while (0)
734 ((errno == EINVAL) ?do { do { if (0) printf ("fd=%d: key:%s error:%s", fd, key, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 737, (((*__errno_location (
)) == 22) ? GF_LOG_DEBUG : GF_LOG_ERROR), "fd=%d: key:%s error:%s"
, fd, key, strerror ((*__errno_location ()))); } while (0)
735 GF_LOG_DEBUG : GF_LOG_ERROR),do { do { if (0) printf ("fd=%d: key:%s error:%s", fd, key, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 737, (((*__errno_location (
)) == 22) ? GF_LOG_DEBUG : GF_LOG_ERROR), "fd=%d: key:%s error:%s"
, fd, key, strerror ((*__errno_location ()))); } while (0)
736 "fd=%d: key:%s error:%s",do { do { if (0) printf ("fd=%d: key:%s error:%s", fd, key, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 737, (((*__errno_location (
)) == 22) ? GF_LOG_DEBUG : GF_LOG_ERROR), "fd=%d: key:%s error:%s"
, fd, key, strerror ((*__errno_location ()))); } while (0)
737 fd, key, strerror (errno))do { do { if (0) printf ("fd=%d: key:%s error:%s", fd, key, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 737, (((*__errno_location (
)) == 22) ? GF_LOG_DEBUG : GF_LOG_ERROR), "fd=%d: key:%s error:%s"
, fd, key, strerror ((*__errno_location ()))); } while (0)
;
738#else /* ! DARWIN */
739 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("fd=%d: key:%s error:%s", fd, key, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 741, GF_LOG_ERROR, "fd=%d: key:%s error:%s"
, fd, key, strerror ((*__errno_location ()))); } while (0)
740 "fd=%d: key:%s error:%s",do { do { if (0) printf ("fd=%d: key:%s error:%s", fd, key, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 741, GF_LOG_ERROR, "fd=%d: key:%s error:%s"
, fd, key, strerror ((*__errno_location ()))); } while (0)
741 fd, key, strerror (errno))do { do { if (0) printf ("fd=%d: key:%s error:%s", fd, key, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-helpers.c", __FUNCTION__, 741, GF_LOG_ERROR, "fd=%d: key:%s error:%s"
, fd, key, strerror ((*__errno_location ()))); } while (0)
;
742#endif /* DARWIN */
743 }
744
745 ret = -errno(*__errno_location ());
746 goto out;
747 }
748
749out:
750 return ret;
751}
752
753
754static int
755janitor_walker (const char *fpath, const struct stat *sb,
756 int typeflag, struct FTW *ftwbuf)
757{
758 struct iatt stbuf = {0, };
759 xlator_t *this = NULL((void*)0);
760
761 this = THIS(*__glusterfs_this_location());
762 posix_pstat (this, NULL((void*)0), fpath, &stbuf);
763 switch (sb->st_mode & S_IFMT0170000) {
764 case S_IFREG0100000:
765 case S_IFBLK0060000:
766 case S_IFLNK0120000:
767 case S_IFCHR0020000:
768 case S_IFIFO0010000:
769 case S_IFSOCK0140000:
770 gf_log (THIS->name, GF_LOG_TRACE,do { do { if (0) printf ("unlinking %s", fpath); } while (0);
_gf_log ((*__glusterfs_this_location())->name, "posix-helpers.c"
, __FUNCTION__, 771, GF_LOG_TRACE, "unlinking %s", fpath); } while
(0)
771 "unlinking %s", fpath)do { do { if (0) printf ("unlinking %s", fpath); } while (0);
_gf_log ((*__glusterfs_this_location())->name, "posix-helpers.c"
, __FUNCTION__, 771, GF_LOG_TRACE, "unlinking %s", fpath); } while
(0)
;
772 unlink (fpath);
773 if (stbuf.ia_nlink == 1)
774 posix_handle_unset (this, stbuf.ia_gfid, NULL((void*)0));
775 break;
776
777 case S_IFDIR0040000:
778 if (ftwbuf->level) { /* don't remove top level dir */
779 gf_log (THIS->name, GF_LOG_TRACE,do { do { if (0) printf ("removing directory %s", fpath); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "posix-helpers.c"
, __FUNCTION__, 780, GF_LOG_TRACE, "removing directory %s", fpath
); } while (0)
780 "removing directory %s", fpath)do { do { if (0) printf ("removing directory %s", fpath); } while
(0); _gf_log ((*__glusterfs_this_location())->name, "posix-helpers.c"
, __FUNCTION__, 780, GF_LOG_TRACE, "removing directory %s", fpath
); } while (0)
;
781
782 rmdir (fpath);
783 posix_handle_unset (this, stbuf.ia_gfid, NULL((void*)0));
784 }
785 break;
786 }
787
788 return 0; /* 0 = FTW_CONTINUE */
789}
790
791
792static struct posix_fd *
793janitor_get_next_fd (xlator_t *this)
794{
795 struct posix_private *priv = NULL((void*)0);
796 struct posix_fd *pfd = NULL((void*)0);
797
798 struct timespec timeout;
799
800 priv = this->private;
801
802 pthread_mutex_lock (&priv->janitor_lock);
803 {
804 if (list_empty (&priv->janitor_fds)) {
805 time (&timeout.tv_sec);
806 timeout.tv_sec += priv->janitor_sleep_duration;
807 timeout.tv_nsec = 0;
808
809 pthread_cond_timedwait (&priv->janitor_cond,
810 &priv->janitor_lock,
811 &timeout);
812 goto unlock;
813 }
814
815 pfd = list_entry (priv->janitor_fds.next, struct posix_fd,((struct posix_fd *)((char *)(priv->janitor_fds.next)-(unsigned
long)(&((struct posix_fd *)0)->list)))
816 list)((struct posix_fd *)((char *)(priv->janitor_fds.next)-(unsigned
long)(&((struct posix_fd *)0)->list)))
;
817
818 list_del (priv->janitor_fds.next);
819 }
820unlock:
821 pthread_mutex_unlock (&priv->janitor_lock);
822
823 return pfd;
824}
825
826
827static void *
828posix_janitor_thread_proc (void *data)
829{
830 xlator_t * this = NULL((void*)0);
831 struct posix_private *priv = NULL((void*)0);
832 struct posix_fd *pfd;
833
834 time_t now;
835
836 this = data;
837 priv = this->private;
838
839 THIS(*__glusterfs_this_location()) = this;
840
841 while (1) {
842 time (&now);
843 if ((now - priv->last_landfill_check) > priv->janitor_sleep_duration) {
844 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("janitor cleaning out %s", priv->
trash_path); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 845, GF_LOG_TRACE, "janitor cleaning out %s",
priv->trash_path); } while (0)
845 "janitor cleaning out %s", priv->trash_path)do { do { if (0) printf ("janitor cleaning out %s", priv->
trash_path); } while (0); _gf_log (this->name, "posix-helpers.c"
, __FUNCTION__, 845, GF_LOG_TRACE, "janitor cleaning out %s",
priv->trash_path); } while (0)
;
846
847 nftw (priv->trash_path,
848 janitor_walker,
849 32,
850 FTW_DEPTHFTW_DEPTH | FTW_PHYSFTW_PHYS);
851
852 priv->last_landfill_check = now;
853 }
854
855 pfd = janitor_get_next_fd (this);
856 if (pfd) {
857 if (pfd->dir == NULL((void*)0)) {
858 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("janitor: closing file fd=%d", pfd->
fd); } while (0); _gf_log (this->name, "posix-helpers.c", __FUNCTION__
, 859, GF_LOG_TRACE, "janitor: closing file fd=%d", pfd->fd
); } while (0)
859 "janitor: closing file fd=%d", pfd->fd)do { do { if (0) printf ("janitor: closing file fd=%d", pfd->
fd); } while (0); _gf_log (this->name, "posix-helpers.c", __FUNCTION__
, 859, GF_LOG_TRACE, "janitor: closing file fd=%d", pfd->fd
); } while (0)
;
860 close (pfd->fd);
861 } else {
862 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("janitor: closing dir fd=%p", pfd->
dir); } while (0); _gf_log (this->name, "posix-helpers.c",
__FUNCTION__, 863, GF_LOG_TRACE, "janitor: closing dir fd=%p"
, pfd->dir); } while (0)
863 "janitor: closing dir fd=%p", pfd->dir)do { do { if (0) printf ("janitor: closing dir fd=%p", pfd->
dir); } while (0); _gf_log (this->name, "posix-helpers.c",
__FUNCTION__, 863, GF_LOG_TRACE, "janitor: closing dir fd=%p"
, pfd->dir); } while (0)
;
864 closedir (pfd->dir);
865 }
866
867 GF_FREE (pfd)__gf_free (pfd);
868 }
869 }
870
871 return NULL((void*)0);
872}
873
874
875void
876posix_spawn_janitor_thread (xlator_t *this)
877{
878 struct posix_private *priv = NULL((void*)0);
879 int ret = 0;
880
881 priv = this->private;
882
883 LOCK (&priv->lock)pthread_spin_lock (&priv->lock);
884 {
885 if (!priv->janitor_present) {
886 ret = pthread_create (&priv->janitor, NULL((void*)0),
887 posix_janitor_thread_proc, this);
888
889 if (ret < 0) {
890 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("spawning janitor thread failed: %s"
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 892, GF_LOG_ERROR
, "spawning janitor thread failed: %s", strerror ((*__errno_location
()))); } while (0)
891 "spawning janitor thread failed: %s",do { do { if (0) printf ("spawning janitor thread failed: %s"
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 892, GF_LOG_ERROR
, "spawning janitor thread failed: %s", strerror ((*__errno_location
()))); } while (0)
892 strerror (errno))do { do { if (0) printf ("spawning janitor thread failed: %s"
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-helpers.c", __FUNCTION__, 892, GF_LOG_ERROR
, "spawning janitor thread failed: %s", strerror ((*__errno_location
()))); } while (0)
;
893 goto unlock;
894 }
895
896 priv->janitor_present = _gf_true;
897 }
898 }
899unlock:
900 UNLOCK (&priv->lock)pthread_spin_unlock (&priv->lock);
901}
902
903int
904posix_acl_xattr_set (xlator_t *this, const char *path, dict_t *xattr_req)
905{
906 int ret = 0;
907 data_t *data = NULL((void*)0);
908 struct stat stat = {0, };
909
910 if (!xattr_req)
911 goto out;
912
913 if (sys_lstat (path, &stat) != 0)
914 goto out;
915
916 data = dict_get (xattr_req, "system.posix_acl_access");
917 if (data) {
918 ret = sys_lsetxattr (path, "system.posix_acl_access",
919 data->data, data->len, 0);
920 if (ret != 0)
921 goto out;
922 }
923
924 data = dict_get (xattr_req, "system.posix_acl_default");
925 if (data) {
926 ret = sys_lsetxattr (path, "system.posix_acl_default",
927 data->data, data->len, 0);
928 if (ret != 0)
929 goto out;
930 }
931
932out:
933 return ret;
934}
935
936static int
937_handle_entry_create_keyvalue_pair (dict_t *d, char *k, data_t *v,
938 void *tmp)
939{
940 int ret = -1;
941 posix_xattr_filler_t *filler = NULL((void*)0);
942
943 filler = tmp;
944
945 if (!strcmp (GFID_XATTR_KEY"trusted.gfid", k) ||
946 !strcmp ("gfid-req", k) ||
947 !strcmp ("system.posix_acl_default", k) ||
948 !strcmp ("system.posix_acl_access", k) ||
949 ZR_FILE_CONTENT_REQUEST(k)(!strncmp(k, "glusterfs.file.", 15))) {
950 return 0;
951 }
952
953 ret = posix_handle_pair (filler->this, filler->real_path, k, v,
954 XATTR_CREATEXATTR_CREATE);
955 if (ret < 0) {
956 errno(*__errno_location ()) = -ret;
957 return -1;
958 }
959 return 0;
960}
961
962int
963posix_entry_create_xattr_set (xlator_t *this, const char *path,
964 dict_t *dict)
965{
966 int ret = -1;
967
968 posix_xattr_filler_t filler = {0,};
969
970 if (!dict)
971 goto out;
972
973 filler.this = this;
974 filler.real_path = path;
975
976 ret = dict_foreach (dict, _handle_entry_create_keyvalue_pair, &filler);
977
978out:
979 return ret;
980}
981
982
983static int
984__posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd_p)
985{
986 uint64_t tmp_pfd = 0;
987 struct posix_fd *pfd = NULL((void*)0);
988 int ret = -1;
989 char *real_path = NULL((void*)0);
2
'real_path' initialized to a null pointer value
990 int _fd = -1;
991 DIR *dir = NULL((void*)0);
992
993 ret = __fd_ctx_get (fd, this, &tmp_pfd);
994 if (ret == 0) {
3
Assuming 'ret' is not equal to 0
4
Taking false branch
995 pfd = (void *)(long) tmp_pfd;
996 ret = 0;
997 goto out;
998 }
999
1000 if (!fd_is_anonymous(fd))
5
Taking false branch
1001 /* anonymous fd */
1002 goto out;
1003
1004 MAKE_HANDLE_PATH (real_path, this, fd->inode->gfid, NULL)do { int __len; __len = posix_handle_path (this, fd->inode
->gfid, ((void*)0), ((void*)0), 0); if (__len <= 0) break
; real_path = __builtin_alloca (__len); __len = posix_handle_path
(this, fd->inode->gfid, ((void*)0), real_path, __len);
} while (0)
;
1005
1006 pfd = GF_CALLOC (1, sizeof (*pfd), gf_posix_mt_posix_fd)__gf_calloc (1, sizeof (*pfd), gf_posix_mt_posix_fd);
1007 if (!pfd) {
6
Assuming 'pfd' is non-null
7
Taking false branch
1008 goto out;
1009 }
1010 pfd->fd = -1;
1011
1012 if (fd->inode->ia_type == IA_IFDIR) {
8
Taking true branch
1013 dir = opendir (real_path);
9
Null pointer passed as an argument to a 'nonnull' parameter
1014 if (!dir) {
1015 GF_FREE (pfd)__gf_free (pfd);
1016 pfd = NULL((void*)0);
1017 goto out;
1018 }
1019 _fd = dirfd (dir);
1020 }
1021
1022 if (fd->inode->ia_type == IA_IFREG) {
1023 _fd = open (real_path, O_RDWR02|O_LARGEFILE0100000);
1024 if (_fd == -1) {
1025 GF_FREE (pfd)__gf_free (pfd);
1026 pfd = NULL((void*)0);
1027 goto out;
1028 }
1029 }
1030
1031 pfd->fd = _fd;
1032 pfd->dir = dir;
1033
1034 ret = __fd_ctx_set (fd, this, (uint64_t) (long) pfd);
1035 if (ret != 0) {
1036 if (_fd != -1)
1037 close (_fd);
1038 if (dir)
1039 closedir (dir);
1040 GF_FREE (pfd)__gf_free (pfd);
1041 pfd = NULL((void*)0);
1042 goto out;
1043 }
1044
1045 ret = 0;
1046out:
1047 if (pfd_p)
1048 *pfd_p = pfd;
1049 return ret;
1050}
1051
1052
1053int
1054posix_fd_ctx_get (fd_t *fd, xlator_t *this, struct posix_fd **pfd)
1055{
1056 int ret;
1057
1058 LOCK (&fd->inode->lock)pthread_spin_lock (&fd->inode->lock);
1059 {
1060 ret = __posix_fd_ctx_get (fd, this, pfd);
1
Calling '__posix_fd_ctx_get'
1061 }
1062 UNLOCK (&fd->inode->lock)pthread_spin_unlock (&fd->inode->lock);
1063
1064 return ret;
1065}