Bug Summary

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

Annotated Source Code

1/*
2 Copyright (c) 2011-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#include <errno(*__errno_location ()).h>
16#include <sys/types.h>
17#include <sys/stat.h>
18#include <unistd.h>
19#include <libgen.h>
20#ifdef GF_LINUX_HOST_OS1
21#include <alloca.h>
22#endif
23
24#include "posix-handle.h"
25#include "posix.h"
26#include "xlator.h"
27#include "syscall.h"
28
29
30#define HANDLE_PFX".glusterfs" ".glusterfs"
31#define TRASH_DIR"landfill" "landfill"
32
33#define UUID0_STR"00000000-0000-0000-0000-000000000000" "00000000-0000-0000-0000-000000000000"
34#define SLEN(str)(sizeof(str) - 1) (sizeof(str) - 1)
35
36
37int
38posix_handle_relpath (xlator_t *this, uuid_t gfid, const char *basename__xpg_basename,
39 char *buf, size_t buflen)
40{
41 char *uuid_str = NULL((void*)0);
42 int len = 0;
43
44 len = SLEN("../")(sizeof("../") - 1)
45 + SLEN("../")(sizeof("../") - 1)
46 + SLEN("00/")(sizeof("00/") - 1)
47 + SLEN("00/")(sizeof("00/") - 1)
48 + SLEN(UUID0_STR)(sizeof("00000000-0000-0000-0000-000000000000") - 1)
49 + 1 /* '\0' */
50 ;
51
52 if (basename__xpg_basename) {
53 len += (strlen (basename__xpg_basename) + 1);
54 }
55
56 if (buflen < len || !buf)
57 return len;
58
59 uuid_str = uuid_utoa (gfid);
60
61 if (basename__xpg_basename) {
62 len = snprintf (buf, buflen, "../../%02x/%02x/%s/%s",
63 gfid[0], gfid[1], uuid_str, basename__xpg_basename);
64 } else {
65 len = snprintf (buf, buflen, "../../%02x/%02x/%s",
66 gfid[0], gfid[1], uuid_str);
67 }
68
69 return len;
70}
71
72
73/*
74 TODO: explain how this pump fixes ELOOP
75*/
76int
77posix_handle_pump (xlator_t *this, char *buf, int len, int maxlen,
78 char *base_str, int base_len, int pfx_len)
79{
80 char linkname[512] = {0,}; /* "../../<gfid>/<NAME_MAX>" */
81 int ret = 0;
82 int blen = 0;
83 int link_len = 0;
84
85 /* is a directory's symlink-handle */
86 ret = readlink (base_str, linkname, 512);
87 if (ret == -1) {
88 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("internal readlink failed on %s (%s)"
, base_str, strerror ((*__errno_location ()))); } while (0); _gf_log
(this->name, "posix-handle.c", __FUNCTION__, 90, GF_LOG_ERROR
, "internal readlink failed on %s (%s)", base_str, strerror (
(*__errno_location ()))); } while (0)
89 "internal readlink failed on %s (%s)",do { do { if (0) printf ("internal readlink failed on %s (%s)"
, base_str, strerror ((*__errno_location ()))); } while (0); _gf_log
(this->name, "posix-handle.c", __FUNCTION__, 90, GF_LOG_ERROR
, "internal readlink failed on %s (%s)", base_str, strerror (
(*__errno_location ()))); } while (0)
90 base_str, strerror (errno))do { do { if (0) printf ("internal readlink failed on %s (%s)"
, base_str, strerror ((*__errno_location ()))); } while (0); _gf_log
(this->name, "posix-handle.c", __FUNCTION__, 90, GF_LOG_ERROR
, "internal readlink failed on %s (%s)", base_str, strerror (
(*__errno_location ()))); } while (0)
;
91 goto err;
92 }
93
94 if (ret < 512)
95 linkname[ret] = 0;
96
97 link_len = ret;
98
99 if ((ret == 8) && memcmp (linkname, "../../..", 8) == 0) {
100 if (strcmp (base_str, buf) == 0) {
101 strcpy (buf + pfx_len, "..");
102 }
103 goto out;
104 }
105
106 if (ret < 50 || ret >= 512) {
107 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("malformed internal link %s for %s",
linkname, base_str); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 109, GF_LOG_ERROR, "malformed internal link %s for %s"
, linkname, base_str); } while (0)
108 "malformed internal link %s for %s",do { do { if (0) printf ("malformed internal link %s for %s",
linkname, base_str); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 109, GF_LOG_ERROR, "malformed internal link %s for %s"
, linkname, base_str); } while (0)
109 linkname, base_str)do { do { if (0) printf ("malformed internal link %s for %s",
linkname, base_str); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 109, GF_LOG_ERROR, "malformed internal link %s for %s"
, linkname, base_str); } while (0)
;
110 goto err;
111 }
112
113 if (memcmp (linkname, "../../", 6) != 0) {
114 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("malformed internal link %s for %s",
linkname, base_str); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 116, GF_LOG_ERROR, "malformed internal link %s for %s"
, linkname, base_str); } while (0)
115 "malformed internal link %s for %s",do { do { if (0) printf ("malformed internal link %s for %s",
linkname, base_str); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 116, GF_LOG_ERROR, "malformed internal link %s for %s"
, linkname, base_str); } while (0)
116 linkname, base_str)do { do { if (0) printf ("malformed internal link %s for %s",
linkname, base_str); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 116, GF_LOG_ERROR, "malformed internal link %s for %s"
, linkname, base_str); } while (0)
;
117 goto err;
118 }
119
120 if ((linkname[2] != '/') ||
121 (linkname[5] != '/') ||
122 (linkname[8] != '/') ||
123 (linkname[11] != '/') ||
124 (linkname[48] != '/')) {
125 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("malformed internal link %s for %s",
linkname, base_str); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 127, GF_LOG_ERROR, "malformed internal link %s for %s"
, linkname, base_str); } while (0)
126 "malformed internal link %s for %s",do { do { if (0) printf ("malformed internal link %s for %s",
linkname, base_str); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 127, GF_LOG_ERROR, "malformed internal link %s for %s"
, linkname, base_str); } while (0)
127 linkname, base_str)do { do { if (0) printf ("malformed internal link %s for %s",
linkname, base_str); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 127, GF_LOG_ERROR, "malformed internal link %s for %s"
, linkname, base_str); } while (0)
;
128 goto err;
129 }
130
131 if ((linkname[20] != '-') ||
132 (linkname[25] != '-') ||
133 (linkname[30] != '-') ||
134 (linkname[35] != '-')) {
135 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("malformed internal link %s for %s",
linkname, base_str); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 137, GF_LOG_ERROR, "malformed internal link %s for %s"
, linkname, base_str); } while (0)
136 "malformed internal link %s for %s",do { do { if (0) printf ("malformed internal link %s for %s",
linkname, base_str); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 137, GF_LOG_ERROR, "malformed internal link %s for %s"
, linkname, base_str); } while (0)
137 linkname, base_str)do { do { if (0) printf ("malformed internal link %s for %s",
linkname, base_str); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 137, GF_LOG_ERROR, "malformed internal link %s for %s"
, linkname, base_str); } while (0)
;
138 goto err;
139 }
140
141 blen = link_len - 48;
142 memmove (buf + base_len + blen, buf + base_len,
143 (strlen (buf) - base_len) + 1);
144
145 strncpy (base_str + pfx_len, linkname + 6, 42);
146
147 if (len + blen < maxlen)
148 strncpy (buf + pfx_len, linkname + 6, link_len - 6);
149out:
150 return len + blen;
151err:
152 return -1;
153}
154
155
156/*
157 posix_handle_path differs from posix_handle_gfid_path in the way that the
158 path filled in @buf by posix_handle_path will return type IA_IFDIR when
159 an lstat() is performed on it, whereas posix_handle_gfid_path returns path
160 to the handle symlink (typically used for the purpose of unlinking it).
161
162 posix_handle_path also guarantees immunity to ELOOP on the path returned by it
163*/
164
165int
166posix_handle_path (xlator_t *this, uuid_t gfid, const char *basename__xpg_basename,
167 char *ubuf, size_t size)
168{
169 struct posix_private *priv = NULL((void*)0);
170 char *uuid_str = NULL((void*)0);
171 int len = 0;
172 int ret = -1;
173 struct stat stat;
174 char *base_str = NULL((void*)0);
175 int base_len = 0;
176 int pfx_len;
177 int maxlen;
178 char *buf;
179
180 priv = this->private;
181
182 uuid_str = uuid_utoa (gfid);
183
184 if (ubuf) {
185 buf = ubuf;
186 maxlen = size;
187 } else {
188 maxlen = PATH_MAX4096;
189 buf = alloca (maxlen)__builtin_alloca (maxlen);
190 }
191
192 base_len = (priv->base_path_length + SLEN(HANDLE_PFX)(sizeof(".glusterfs") - 1) + 45);
193 base_str = alloca (base_len + 1)__builtin_alloca (base_len + 1);
194 base_len = snprintf (base_str, base_len + 1, "%s/%s/%02x/%02x/%s",
195 priv->base_path, HANDLE_PFX".glusterfs", gfid[0], gfid[1],
196 uuid_str);
197
198 pfx_len = priv->base_path_length + 1 + SLEN(HANDLE_PFX)(sizeof(".glusterfs") - 1) + 1;
199
200 if (basename__xpg_basename) {
201 len = snprintf (buf, maxlen, "%s/%s", base_str, basename__xpg_basename);
202 } else {
203 len = snprintf (buf, maxlen, "%s", base_str);
204 }
205
206 ret = lstat (base_str, &stat);
207
208 if (!(ret == 0 && S_ISLNK(stat.st_mode)((((stat.st_mode)) & 0170000) == (0120000)) && stat.st_nlink == 1))
209 goto out;
210
211 do {
212 errno(*__errno_location ()) = 0;
213 ret = posix_handle_pump (this, buf, len, maxlen,
214 base_str, base_len, pfx_len);
215 if (ret == -1)
216 break;
217
218 len = ret;
219
220 ret = lstat (buf, &stat);
221 } while ((ret == -1) && errno(*__errno_location ()) == ELOOP40);
222
223out:
224 return len + 1;
225}
226
227
228int
229posix_handle_gfid_path (xlator_t *this, uuid_t gfid, const char *basename__xpg_basename,
230 char *buf, size_t buflen)
231{
232 struct posix_private *priv = NULL((void*)0);
233 char *uuid_str = NULL((void*)0);
234 int len = 0;
235
236 priv = this->private;
237
238 len = priv->base_path_length /* option directory "/export" */
239 + SLEN("/")(sizeof("/") - 1)
240 + SLEN(HANDLE_PFX)(sizeof(".glusterfs") - 1)
241 + SLEN("/")(sizeof("/") - 1)
242 + SLEN("00/")(sizeof("00/") - 1)
243 + SLEN("00/")(sizeof("00/") - 1)
244 + SLEN(UUID0_STR)(sizeof("00000000-0000-0000-0000-000000000000") - 1)
245 + 1 /* '\0' */
246 ;
247
248 if (basename__xpg_basename) {
249 len += (strlen (basename__xpg_basename) + 1);
250 } else {
251 len += 256; /* worst-case for directory's symlink-handle expansion */
252 }
253
254 if ((buflen < len) || !buf)
255 return len;
256
257 uuid_str = uuid_utoa (gfid);
258
259 if (__is_root_gfid (gfid)) {
260 if (basename__xpg_basename) {
261 len = snprintf (buf, buflen, "%s/%s", priv->base_path,
262 basename__xpg_basename);
263 } else {
264 strncpy (buf, priv->base_path, buflen);
265 }
266 goto out;
267 }
268
269 if (basename__xpg_basename) {
270 len = snprintf (buf, buflen, "%s/%s/%02x/%02x/%s/%s", priv->base_path,
271 HANDLE_PFX".glusterfs", gfid[0], gfid[1], uuid_str, basename__xpg_basename);
272 } else {
273 len = snprintf (buf, buflen, "%s/%s/%02x/%02x/%s", priv->base_path,
274 HANDLE_PFX".glusterfs", gfid[0], gfid[1], uuid_str);
275 }
276out:
277 return len;
278}
279
280
281int
282posix_handle_init (xlator_t *this)
283{
284 struct posix_private *priv = NULL((void*)0);
285 char *handle_pfx = NULL((void*)0);
286 int ret = 0;
287 int len = 0;
288 struct stat stbuf;
289 struct stat rootbuf;
290 struct stat exportbuf;
291 char *rootstr = NULL((void*)0);
292 uuid_t gfid = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
293
294 priv = this->private;
295
296 ret = stat (priv->base_path, &exportbuf);
297 if (ret || !S_ISDIR (exportbuf.st_mode)((((exportbuf.st_mode)) & 0170000) == (0040000))) {
298 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Not a directory: %s", priv->base_path
); } while (0); _gf_log (this->name, "posix-handle.c", __FUNCTION__
, 299, GF_LOG_ERROR, "Not a directory: %s", priv->base_path
); } while (0)
299 "Not a directory: %s", priv->base_path)do { do { if (0) printf ("Not a directory: %s", priv->base_path
); } while (0); _gf_log (this->name, "posix-handle.c", __FUNCTION__
, 299, GF_LOG_ERROR, "Not a directory: %s", priv->base_path
); } while (0)
;
300 return -1;
301 }
302
303 handle_pfx = alloca (priv->base_path_length + 1 + strlen (HANDLE_PFX)__builtin_alloca (priv->base_path_length + 1 + strlen (".glusterfs"
) + 1)
304 + 1)__builtin_alloca (priv->base_path_length + 1 + strlen (".glusterfs"
) + 1)
;
305
306 sprintf (handle_pfx, "%s/%s", priv->base_path, HANDLE_PFX".glusterfs");
307
308 ret = stat (handle_pfx, &stbuf);
309 switch (ret) {
310 case -1:
311 if (errno(*__errno_location ()) == ENOENT2) {
312 ret = mkdir (handle_pfx, 0600);
313 if (ret != 0) {
314 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Creating directory %s failed: %s", handle_pfx
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 316, GF_LOG_ERROR,
"Creating directory %s failed: %s", handle_pfx, strerror ((*
__errno_location ()))); } while (0)
315 "Creating directory %s failed: %s",do { do { if (0) printf ("Creating directory %s failed: %s", handle_pfx
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 316, GF_LOG_ERROR,
"Creating directory %s failed: %s", handle_pfx, strerror ((*
__errno_location ()))); } while (0)
316 handle_pfx, strerror (errno))do { do { if (0) printf ("Creating directory %s failed: %s", handle_pfx
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 316, GF_LOG_ERROR,
"Creating directory %s failed: %s", handle_pfx, strerror ((*
__errno_location ()))); } while (0)
;
317 return -1;
318 }
319 } else {
320 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Checking for %s failed: %s", handle_pfx
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 322, GF_LOG_ERROR,
"Checking for %s failed: %s", handle_pfx, strerror ((*__errno_location
()))); } while (0)
321 "Checking for %s failed: %s",do { do { if (0) printf ("Checking for %s failed: %s", handle_pfx
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 322, GF_LOG_ERROR,
"Checking for %s failed: %s", handle_pfx, strerror ((*__errno_location
()))); } while (0)
322 handle_pfx, strerror (errno))do { do { if (0) printf ("Checking for %s failed: %s", handle_pfx
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 322, GF_LOG_ERROR,
"Checking for %s failed: %s", handle_pfx, strerror ((*__errno_location
()))); } while (0)
;
323 return -1;
324 }
325 break;
326 case 0:
327 if (!S_ISDIR (stbuf.st_mode)((((stbuf.st_mode)) & 0170000) == (0040000))) {
328 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Not a directory: %s", handle_pfx); }
while (0); _gf_log (this->name, "posix-handle.c", __FUNCTION__
, 330, GF_LOG_ERROR, "Not a directory: %s", handle_pfx); } while
(0)
329 "Not a directory: %s",do { do { if (0) printf ("Not a directory: %s", handle_pfx); }
while (0); _gf_log (this->name, "posix-handle.c", __FUNCTION__
, 330, GF_LOG_ERROR, "Not a directory: %s", handle_pfx); } while
(0)
330 handle_pfx)do { do { if (0) printf ("Not a directory: %s", handle_pfx); }
while (0); _gf_log (this->name, "posix-handle.c", __FUNCTION__
, 330, GF_LOG_ERROR, "Not a directory: %s", handle_pfx); } while
(0)
;
331 return -1;
332 }
333 break;
334 default:
335 break;
336 }
337
338 stat (handle_pfx, &priv->handledir);
339
340 len = posix_handle_path (this, gfid, NULL((void*)0), NULL((void*)0), 0);
341 rootstr = alloca (len)__builtin_alloca (len);
342 posix_handle_path (this, gfid, NULL((void*)0), rootstr, len);
343
344 ret = stat (rootstr, &rootbuf);
345 switch (ret) {
346 case -1:
347 if (errno(*__errno_location ()) != ENOENT2) {
348 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("%s: %s", priv->base_path, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 350, GF_LOG_ERROR, "%s: %s"
, priv->base_path, strerror ((*__errno_location ()))); } while
(0)
349 "%s: %s", priv->base_path,do { do { if (0) printf ("%s: %s", priv->base_path, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 350, GF_LOG_ERROR, "%s: %s"
, priv->base_path, strerror ((*__errno_location ()))); } while
(0)
350 strerror (errno))do { do { if (0) printf ("%s: %s", priv->base_path, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 350, GF_LOG_ERROR, "%s: %s"
, priv->base_path, strerror ((*__errno_location ()))); } while
(0)
;
351 return -1;
352 }
353
354 ret = posix_handle_mkdir_hashes (this, rootstr);
355 if (ret) {
356 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("mkdir %s failed (%s)", rootstr, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 358, GF_LOG_WARNING, "mkdir %s failed (%s)"
, rootstr, strerror ((*__errno_location ()))); } while (0)
357 "mkdir %s failed (%s)",do { do { if (0) printf ("mkdir %s failed (%s)", rootstr, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 358, GF_LOG_WARNING, "mkdir %s failed (%s)"
, rootstr, strerror ((*__errno_location ()))); } while (0)
358 rootstr, strerror (errno))do { do { if (0) printf ("mkdir %s failed (%s)", rootstr, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 358, GF_LOG_WARNING, "mkdir %s failed (%s)"
, rootstr, strerror ((*__errno_location ()))); } while (0)
;
359 return -1;
360 }
361
362 ret = symlink ("../../..", rootstr);
363 if (ret) {
364 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("symlink %s creation failed (%s)", rootstr
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 366, GF_LOG_ERROR,
"symlink %s creation failed (%s)", rootstr, strerror ((*__errno_location
()))); } while (0)
365 "symlink %s creation failed (%s)",do { do { if (0) printf ("symlink %s creation failed (%s)", rootstr
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 366, GF_LOG_ERROR,
"symlink %s creation failed (%s)", rootstr, strerror ((*__errno_location
()))); } while (0)
366 rootstr, strerror (errno))do { do { if (0) printf ("symlink %s creation failed (%s)", rootstr
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 366, GF_LOG_ERROR,
"symlink %s creation failed (%s)", rootstr, strerror ((*__errno_location
()))); } while (0)
;
367 return -1;
368 }
369 break;
370 case 0:
371 if ((exportbuf.st_ino == rootbuf.st_ino) &&
372 (exportbuf.st_dev == rootbuf.st_dev))
373 return 0;
374
375 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Different dirs %s (%lld/%lld) != %s (%lld/%lld)"
, priv->base_path, (long long) exportbuf.st_ino, (long long
) exportbuf.st_dev, rootstr, (long long) rootbuf.st_ino, (long
long) rootbuf.st_dev); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 379, GF_LOG_ERROR, "Different dirs %s (%lld/%lld) != %s (%lld/%lld)"
, priv->base_path, (long long) exportbuf.st_ino, (long long
) exportbuf.st_dev, rootstr, (long long) rootbuf.st_ino, (long
long) rootbuf.st_dev); } while (0)
376 "Different dirs %s (%lld/%lld) != %s (%lld/%lld)",do { do { if (0) printf ("Different dirs %s (%lld/%lld) != %s (%lld/%lld)"
, priv->base_path, (long long) exportbuf.st_ino, (long long
) exportbuf.st_dev, rootstr, (long long) rootbuf.st_ino, (long
long) rootbuf.st_dev); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 379, GF_LOG_ERROR, "Different dirs %s (%lld/%lld) != %s (%lld/%lld)"
, priv->base_path, (long long) exportbuf.st_ino, (long long
) exportbuf.st_dev, rootstr, (long long) rootbuf.st_ino, (long
long) rootbuf.st_dev); } while (0)
377 priv->base_path, (long long) exportbuf.st_ino,do { do { if (0) printf ("Different dirs %s (%lld/%lld) != %s (%lld/%lld)"
, priv->base_path, (long long) exportbuf.st_ino, (long long
) exportbuf.st_dev, rootstr, (long long) rootbuf.st_ino, (long
long) rootbuf.st_dev); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 379, GF_LOG_ERROR, "Different dirs %s (%lld/%lld) != %s (%lld/%lld)"
, priv->base_path, (long long) exportbuf.st_ino, (long long
) exportbuf.st_dev, rootstr, (long long) rootbuf.st_ino, (long
long) rootbuf.st_dev); } while (0)
378 (long long) exportbuf.st_dev, rootstr,do { do { if (0) printf ("Different dirs %s (%lld/%lld) != %s (%lld/%lld)"
, priv->base_path, (long long) exportbuf.st_ino, (long long
) exportbuf.st_dev, rootstr, (long long) rootbuf.st_ino, (long
long) rootbuf.st_dev); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 379, GF_LOG_ERROR, "Different dirs %s (%lld/%lld) != %s (%lld/%lld)"
, priv->base_path, (long long) exportbuf.st_ino, (long long
) exportbuf.st_dev, rootstr, (long long) rootbuf.st_ino, (long
long) rootbuf.st_dev); } while (0)
379 (long long) rootbuf.st_ino, (long long) rootbuf.st_dev)do { do { if (0) printf ("Different dirs %s (%lld/%lld) != %s (%lld/%lld)"
, priv->base_path, (long long) exportbuf.st_ino, (long long
) exportbuf.st_dev, rootstr, (long long) rootbuf.st_ino, (long
long) rootbuf.st_dev); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 379, GF_LOG_ERROR, "Different dirs %s (%lld/%lld) != %s (%lld/%lld)"
, priv->base_path, (long long) exportbuf.st_ino, (long long
) exportbuf.st_dev, rootstr, (long long) rootbuf.st_ino, (long
long) rootbuf.st_dev); } while (0)
;
380 return -1;
381
382 break;
383 }
384
385 return 0;
386}
387
388gf_boolean_t
389posix_does_old_trash_exists (char *old_trash)
390{
391 uuid_t gfid = {0};
392 gf_boolean_t exists = _gf_false;
393 struct stat stbuf = {0};
394 int ret = 0;
395
396 ret = lstat (old_trash, &stbuf);
397 if ((ret == 0) && S_ISDIR (stbuf.st_mode)((((stbuf.st_mode)) & 0170000) == (0040000))) {
398 ret = sys_lgetxattr (old_trash, "trusted.gfid", gfid, 16);
399 if ((ret < 0) && (errno(*__errno_location ()) == ENODATA61))
400 exists = _gf_true;
401 }
402 return exists;
403}
404
405int
406posix_handle_new_trash_init (xlator_t *this, char *trash)
407{
408 int ret = 0;
409 struct stat stbuf = {0};
410
411 ret = lstat (trash, &stbuf);
412 switch (ret) {
413 case -1:
414 if (errno(*__errno_location ()) == ENOENT2) {
415 ret = mkdir (trash, 0755);
416 if (ret != 0) {
417 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Creating directory %s failed: %s", trash
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 419, GF_LOG_ERROR,
"Creating directory %s failed: %s", trash, strerror ((*__errno_location
()))); } while (0)
418 "Creating directory %s failed: %s",do { do { if (0) printf ("Creating directory %s failed: %s", trash
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 419, GF_LOG_ERROR,
"Creating directory %s failed: %s", trash, strerror ((*__errno_location
()))); } while (0)
419 trash, strerror (errno))do { do { if (0) printf ("Creating directory %s failed: %s", trash
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 419, GF_LOG_ERROR,
"Creating directory %s failed: %s", trash, strerror ((*__errno_location
()))); } while (0)
;
420 }
421 } else {
422 gf_log (this->name, GF_LOG_ERROR, "Checking for %s "do { do { if (0) printf ("Checking for %s " "failed: %s", trash
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 423, GF_LOG_ERROR,
"Checking for %s " "failed: %s", trash, strerror ((*__errno_location
()))); } while (0)
423 "failed: %s", trash, strerror (errno))do { do { if (0) printf ("Checking for %s " "failed: %s", trash
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 423, GF_LOG_ERROR,
"Checking for %s " "failed: %s", trash, strerror ((*__errno_location
()))); } while (0)
;
424 }
425 break;
426 case 0:
427 if (!S_ISDIR (stbuf.st_mode)((((stbuf.st_mode)) & 0170000) == (0040000))) {
428 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Not a directory: %s", trash); } while
(0); _gf_log (this->name, "posix-handle.c", __FUNCTION__,
429, GF_LOG_ERROR, "Not a directory: %s", trash); } while (0
)
429 "Not a directory: %s", trash)do { do { if (0) printf ("Not a directory: %s", trash); } while
(0); _gf_log (this->name, "posix-handle.c", __FUNCTION__,
429, GF_LOG_ERROR, "Not a directory: %s", trash); } while (0
)
;
430 ret = -1;
431 }
432 break;
433 default:
434 break;
435 }
436 return ret;
437}
438
439int
440posix_mv_old_trash_into_new_trash (xlator_t *this, char *old, char *new)
441{
442 char dest_old[PATH_MAX4096] = {0};
443 int ret = 0;
444 uuid_t dest_name = {0};
445
446 if (!posix_does_old_trash_exists (old))
447 goto out;
448 uuid_generate (dest_name);
449 snprintf (dest_old, sizeof (dest_old), "%s/%s", new,
450 uuid_utoa (dest_name));
451 ret = rename (old, dest_old);
452 if (ret < 0) {
453 gf_log (this->name, GF_LOG_ERROR, "Not able to move "do { do { if (0) printf ("Not able to move " "%s -> %s (%s)"
, old, dest_old, strerror ((*__errno_location ()))); } while (
0); _gf_log (this->name, "posix-handle.c", __FUNCTION__, 454
, GF_LOG_ERROR, "Not able to move " "%s -> %s (%s)", old, dest_old
, strerror ((*__errno_location ()))); } while (0)
454 "%s -> %s (%s)", old, dest_old, strerror (errno))do { do { if (0) printf ("Not able to move " "%s -> %s (%s)"
, old, dest_old, strerror ((*__errno_location ()))); } while (
0); _gf_log (this->name, "posix-handle.c", __FUNCTION__, 454
, GF_LOG_ERROR, "Not able to move " "%s -> %s (%s)", old, dest_old
, strerror ((*__errno_location ()))); } while (0)
;
455 }
456out:
457 return ret;
458}
459
460int
461posix_handle_trash_init (xlator_t *this)
462{
463 int ret = -1;
464 struct posix_private *priv = NULL((void*)0);
465 char old_trash[PATH_MAX4096] = {0};
466
467 priv = this->private;
468
469 priv->trash_path = GF_CALLOC (1, priv->base_path_length + strlen ("/")__gf_calloc (1, priv->base_path_length + strlen ("/") + strlen
(".glusterfs") + strlen ("/") + strlen ("landfill") + 1, gf_posix_mt_trash_path
)
470 + strlen (HANDLE_PFX) + strlen ("/")__gf_calloc (1, priv->base_path_length + strlen ("/") + strlen
(".glusterfs") + strlen ("/") + strlen ("landfill") + 1, gf_posix_mt_trash_path
)
471 + strlen (TRASH_DIR) + 1,__gf_calloc (1, priv->base_path_length + strlen ("/") + strlen
(".glusterfs") + strlen ("/") + strlen ("landfill") + 1, gf_posix_mt_trash_path
)
472 gf_posix_mt_trash_path)__gf_calloc (1, priv->base_path_length + strlen ("/") + strlen
(".glusterfs") + strlen ("/") + strlen ("landfill") + 1, gf_posix_mt_trash_path
)
;
473
474 if (!priv->trash_path)
475 goto out;
476
477 strncpy (priv->trash_path, priv->base_path, priv->base_path_length);
478 strcat (priv->trash_path, "/" HANDLE_PFX".glusterfs" "/" TRASH_DIR"landfill");
479 ret = posix_handle_new_trash_init (this, priv->trash_path);
480 if (ret)
481 goto out;
482 snprintf (old_trash, sizeof (old_trash), "%s/.landfill",
483 priv->base_path);
484 ret = posix_mv_old_trash_into_new_trash (this, old_trash,
485 priv->trash_path);
486out:
487 return ret;
488}
489
490int
491posix_handle_mkdir_hashes (xlator_t *this, const char *newpath)
492{
493 char *duppath = NULL((void*)0);
494 char *parpath = NULL((void*)0);
495 int ret = 0;
496
497 duppath = strdupa (newpath)(__extension__ ({ const char *__old = (newpath); size_t __len
= strlen (__old) + 1; char *__new = (char *) __builtin_alloca
(__len); (char *) memcpy (__new, __old, __len); }))
;
498 parpath = dirname (duppath);
499 parpath = dirname (duppath);
500
501 ret = mkdir (parpath, 0700);
502 if (ret == -1 && errno(*__errno_location ()) != EEXIST17) {
503 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("error mkdir hash-1 %s (%s)", parpath
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 505, GF_LOG_ERROR,
"error mkdir hash-1 %s (%s)", parpath, strerror ((*__errno_location
()))); } while (0)
504 "error mkdir hash-1 %s (%s)",do { do { if (0) printf ("error mkdir hash-1 %s (%s)", parpath
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 505, GF_LOG_ERROR,
"error mkdir hash-1 %s (%s)", parpath, strerror ((*__errno_location
()))); } while (0)
505 parpath, strerror (errno))do { do { if (0) printf ("error mkdir hash-1 %s (%s)", parpath
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 505, GF_LOG_ERROR,
"error mkdir hash-1 %s (%s)", parpath, strerror ((*__errno_location
()))); } while (0)
;
506 return -1;
507 }
508
509 strcpy (duppath, newpath);
510 parpath = dirname (duppath);
511
512 ret = mkdir (parpath, 0700);
513 if (ret == -1 && errno(*__errno_location ()) != EEXIST17) {
514 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("error mkdir hash-2 %s (%s)", parpath
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 516, GF_LOG_ERROR,
"error mkdir hash-2 %s (%s)", parpath, strerror ((*__errno_location
()))); } while (0)
515 "error mkdir hash-2 %s (%s)",do { do { if (0) printf ("error mkdir hash-2 %s (%s)", parpath
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 516, GF_LOG_ERROR,
"error mkdir hash-2 %s (%s)", parpath, strerror ((*__errno_location
()))); } while (0)
516 parpath, strerror (errno))do { do { if (0) printf ("error mkdir hash-2 %s (%s)", parpath
, strerror ((*__errno_location ()))); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 516, GF_LOG_ERROR,
"error mkdir hash-2 %s (%s)", parpath, strerror ((*__errno_location
()))); } while (0)
;
517 return -1;
518 }
519
520 return 0;
521}
522
523
524int
525posix_handle_hard (xlator_t *this, const char *oldpath, uuid_t gfid, struct stat *oldbuf)
526{
527 char *newpath = NULL((void*)0);
1
'newpath' initialized to a null pointer value
528 struct stat newbuf;
529 int ret = -1;
530
531
532 MAKE_HANDLE_PATH (newpath, this, gfid, NULL)do { int __len; __len = posix_handle_path (this, gfid, ((void
*)0), ((void*)0), 0); if (__len <= 0) break; newpath = __builtin_alloca
(__len); __len = posix_handle_path (this, gfid, ((void*)0), newpath
, __len); } while (0)
;
533
534 ret = lstat (newpath, &newbuf);
2
Null pointer passed as an argument to a 'nonnull' parameter
535 if (ret == -1 && errno(*__errno_location ()) != ENOENT2) {
536 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("%s: %s", newpath, strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 537, GF_LOG_WARNING, "%s: %s", newpath, strerror
((*__errno_location ()))); } while (0)
537 "%s: %s", newpath, strerror (errno))do { do { if (0) printf ("%s: %s", newpath, strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 537, GF_LOG_WARNING, "%s: %s", newpath, strerror
((*__errno_location ()))); } while (0)
;
538 return -1;
539 }
540
541 if (ret == -1 && errno(*__errno_location ()) == ENOENT2) {
542 ret = posix_handle_mkdir_hashes (this, newpath);
543 if (ret) {
544 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("mkdir %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 546, GF_LOG_WARNING, "mkdir %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
545 "mkdir %s failed (%s)",do { do { if (0) printf ("mkdir %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 546, GF_LOG_WARNING, "mkdir %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
546 newpath, strerror (errno))do { do { if (0) printf ("mkdir %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 546, GF_LOG_WARNING, "mkdir %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
;
547 return -1;
548 }
549
550#ifdef HAVE_LINKAT1
551 /*
552 * Use linkat if the target may be a symlink to a directory
553 * or without an existing target. See comment about linkat()
554 * usage in posix_link() in posix.c for details
555 */
556 ret = linkat (AT_FDCWD-100, oldpath, AT_FDCWD-100, newpath, 0);
557#else
558 ret = link (oldpath, newpath);
559#endif
560 if (ret) {
561 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("link %s -> %s failed (%s)", oldpath
, newpath, strerror ((*__errno_location ()))); } while (0); _gf_log
(this->name, "posix-handle.c", __FUNCTION__, 563, GF_LOG_WARNING
, "link %s -> %s failed (%s)", oldpath, newpath, strerror (
(*__errno_location ()))); } while (0)
562 "link %s -> %s failed (%s)",do { do { if (0) printf ("link %s -> %s failed (%s)", oldpath
, newpath, strerror ((*__errno_location ()))); } while (0); _gf_log
(this->name, "posix-handle.c", __FUNCTION__, 563, GF_LOG_WARNING
, "link %s -> %s failed (%s)", oldpath, newpath, strerror (
(*__errno_location ()))); } while (0)
563 oldpath, newpath, strerror (errno))do { do { if (0) printf ("link %s -> %s failed (%s)", oldpath
, newpath, strerror ((*__errno_location ()))); } while (0); _gf_log
(this->name, "posix-handle.c", __FUNCTION__, 563, GF_LOG_WARNING
, "link %s -> %s failed (%s)", oldpath, newpath, strerror (
(*__errno_location ()))); } while (0)
;
564 return -1;
565 }
566
567 ret = lstat (newpath, &newbuf);
568 if (ret) {
569 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("lstat on %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 571, GF_LOG_WARNING, "lstat on %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
570 "lstat on %s failed (%s)",do { do { if (0) printf ("lstat on %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 571, GF_LOG_WARNING, "lstat on %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
571 newpath, strerror (errno))do { do { if (0) printf ("lstat on %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 571, GF_LOG_WARNING, "lstat on %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
;
572 return -1;
573 }
574 }
575
576 if (newbuf.st_ino != oldbuf->st_ino ||
577 newbuf.st_dev != oldbuf->st_dev) {
578 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("mismatching ino/dev between file %s (%lld/%lld) "
"and handle %s (%lld/%lld)", oldpath, (long long) oldbuf->
st_ino, (long long) oldbuf->st_dev, newpath, (long long) newbuf
.st_ino, (long long) newbuf.st_dev); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 582, GF_LOG_WARNING
, "mismatching ino/dev between file %s (%lld/%lld) " "and handle %s (%lld/%lld)"
, oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->
st_dev, newpath, (long long) newbuf.st_ino, (long long) newbuf
.st_dev); } while (0)
579 "mismatching ino/dev between file %s (%lld/%lld) "do { do { if (0) printf ("mismatching ino/dev between file %s (%lld/%lld) "
"and handle %s (%lld/%lld)", oldpath, (long long) oldbuf->
st_ino, (long long) oldbuf->st_dev, newpath, (long long) newbuf
.st_ino, (long long) newbuf.st_dev); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 582, GF_LOG_WARNING
, "mismatching ino/dev between file %s (%lld/%lld) " "and handle %s (%lld/%lld)"
, oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->
st_dev, newpath, (long long) newbuf.st_ino, (long long) newbuf
.st_dev); } while (0)
580 "and handle %s (%lld/%lld)",do { do { if (0) printf ("mismatching ino/dev between file %s (%lld/%lld) "
"and handle %s (%lld/%lld)", oldpath, (long long) oldbuf->
st_ino, (long long) oldbuf->st_dev, newpath, (long long) newbuf
.st_ino, (long long) newbuf.st_dev); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 582, GF_LOG_WARNING
, "mismatching ino/dev between file %s (%lld/%lld) " "and handle %s (%lld/%lld)"
, oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->
st_dev, newpath, (long long) newbuf.st_ino, (long long) newbuf
.st_dev); } while (0)
581 oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->st_dev,do { do { if (0) printf ("mismatching ino/dev between file %s (%lld/%lld) "
"and handle %s (%lld/%lld)", oldpath, (long long) oldbuf->
st_ino, (long long) oldbuf->st_dev, newpath, (long long) newbuf
.st_ino, (long long) newbuf.st_dev); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 582, GF_LOG_WARNING
, "mismatching ino/dev between file %s (%lld/%lld) " "and handle %s (%lld/%lld)"
, oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->
st_dev, newpath, (long long) newbuf.st_ino, (long long) newbuf
.st_dev); } while (0)
582 newpath, (long long) newbuf.st_ino, (long long) newbuf.st_dev)do { do { if (0) printf ("mismatching ino/dev between file %s (%lld/%lld) "
"and handle %s (%lld/%lld)", oldpath, (long long) oldbuf->
st_ino, (long long) oldbuf->st_dev, newpath, (long long) newbuf
.st_ino, (long long) newbuf.st_dev); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 582, GF_LOG_WARNING
, "mismatching ino/dev between file %s (%lld/%lld) " "and handle %s (%lld/%lld)"
, oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->
st_dev, newpath, (long long) newbuf.st_ino, (long long) newbuf
.st_dev); } while (0)
;
583 ret = -1;
584 }
585
586 return ret;
587}
588
589
590int
591posix_handle_soft (xlator_t *this, const char *real_path, loc_t *loc,
592 uuid_t gfid, struct stat *oldbuf)
593{
594 char *oldpath = NULL((void*)0);
595 char *newpath = NULL((void*)0);
596 struct stat newbuf;
597 int ret = -1;
598
599
600 MAKE_HANDLE_PATH (newpath, this, gfid, NULL)do { int __len; __len = posix_handle_path (this, gfid, ((void
*)0), ((void*)0), 0); if (__len <= 0) break; newpath = __builtin_alloca
(__len); __len = posix_handle_path (this, gfid, ((void*)0), newpath
, __len); } while (0)
;
601 MAKE_HANDLE_RELPATH (oldpath, this, loc->pargfid, loc->name)do { int __len; __len = posix_handle_relpath (this, loc->pargfid
, loc->name, ((void*)0), 0); if (__len <= 0) break; oldpath
= __builtin_alloca (__len); __len = posix_handle_relpath (this
, loc->pargfid, loc->name, oldpath, __len); } while (0)
;
602
603
604 ret = lstat (newpath, &newbuf);
605 if (ret == -1 && errno(*__errno_location ()) != ENOENT2) {
606 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("%s: %s", newpath, strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 607, GF_LOG_WARNING, "%s: %s", newpath, strerror
((*__errno_location ()))); } while (0)
607 "%s: %s", newpath, strerror (errno))do { do { if (0) printf ("%s: %s", newpath, strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 607, GF_LOG_WARNING, "%s: %s", newpath, strerror
((*__errno_location ()))); } while (0)
;
608 return -1;
609 }
610
611 if (ret == -1 && errno(*__errno_location ()) == ENOENT2) {
612 ret = posix_handle_mkdir_hashes (this, newpath);
613 if (ret) {
614 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("mkdir %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 616, GF_LOG_WARNING, "mkdir %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
615 "mkdir %s failed (%s)",do { do { if (0) printf ("mkdir %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 616, GF_LOG_WARNING, "mkdir %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
616 newpath, strerror (errno))do { do { if (0) printf ("mkdir %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 616, GF_LOG_WARNING, "mkdir %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
;
617 return -1;
618 }
619
620 ret = symlink (oldpath, newpath);
621 if (ret) {
622 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("symlink %s -> %s failed (%s)", oldpath
, newpath, strerror ((*__errno_location ()))); } while (0); _gf_log
(this->name, "posix-handle.c", __FUNCTION__, 624, GF_LOG_WARNING
, "symlink %s -> %s failed (%s)", oldpath, newpath, strerror
((*__errno_location ()))); } while (0)
623 "symlink %s -> %s failed (%s)",do { do { if (0) printf ("symlink %s -> %s failed (%s)", oldpath
, newpath, strerror ((*__errno_location ()))); } while (0); _gf_log
(this->name, "posix-handle.c", __FUNCTION__, 624, GF_LOG_WARNING
, "symlink %s -> %s failed (%s)", oldpath, newpath, strerror
((*__errno_location ()))); } while (0)
624 oldpath, newpath, strerror (errno))do { do { if (0) printf ("symlink %s -> %s failed (%s)", oldpath
, newpath, strerror ((*__errno_location ()))); } while (0); _gf_log
(this->name, "posix-handle.c", __FUNCTION__, 624, GF_LOG_WARNING
, "symlink %s -> %s failed (%s)", oldpath, newpath, strerror
((*__errno_location ()))); } while (0)
;
625 return -1;
626 }
627
628 ret = lstat (newpath, &newbuf);
629 if (ret) {
630 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("stat on %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 632, GF_LOG_WARNING, "stat on %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
631 "stat on %s failed (%s)",do { do { if (0) printf ("stat on %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 632, GF_LOG_WARNING, "stat on %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
632 newpath, strerror (errno))do { do { if (0) printf ("stat on %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 632, GF_LOG_WARNING, "stat on %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
;
633 return -1;
634 }
635 }
636
637 ret = stat (real_path, &newbuf);
638 if (ret) {
639 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("stat on %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 640, GF_LOG_WARNING, "stat on %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
640 "stat on %s failed (%s)", newpath, strerror (errno))do { do { if (0) printf ("stat on %s failed (%s)", newpath, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 640, GF_LOG_WARNING, "stat on %s failed (%s)"
, newpath, strerror ((*__errno_location ()))); } while (0)
;
641 return -1;
642 }
643
644 if (!oldbuf)
645 return ret;
646
647 if (newbuf.st_ino != oldbuf->st_ino ||
648 newbuf.st_dev != oldbuf->st_dev) {
649 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("mismatching ino/dev between file %s (%lld/%lld) "
"and handle %s (%lld/%lld)", oldpath, (long long) oldbuf->
st_ino, (long long) oldbuf->st_dev, newpath, (long long) newbuf
.st_ino, (long long) newbuf.st_dev); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 653, GF_LOG_WARNING
, "mismatching ino/dev between file %s (%lld/%lld) " "and handle %s (%lld/%lld)"
, oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->
st_dev, newpath, (long long) newbuf.st_ino, (long long) newbuf
.st_dev); } while (0)
650 "mismatching ino/dev between file %s (%lld/%lld) "do { do { if (0) printf ("mismatching ino/dev between file %s (%lld/%lld) "
"and handle %s (%lld/%lld)", oldpath, (long long) oldbuf->
st_ino, (long long) oldbuf->st_dev, newpath, (long long) newbuf
.st_ino, (long long) newbuf.st_dev); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 653, GF_LOG_WARNING
, "mismatching ino/dev between file %s (%lld/%lld) " "and handle %s (%lld/%lld)"
, oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->
st_dev, newpath, (long long) newbuf.st_ino, (long long) newbuf
.st_dev); } while (0)
651 "and handle %s (%lld/%lld)",do { do { if (0) printf ("mismatching ino/dev between file %s (%lld/%lld) "
"and handle %s (%lld/%lld)", oldpath, (long long) oldbuf->
st_ino, (long long) oldbuf->st_dev, newpath, (long long) newbuf
.st_ino, (long long) newbuf.st_dev); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 653, GF_LOG_WARNING
, "mismatching ino/dev between file %s (%lld/%lld) " "and handle %s (%lld/%lld)"
, oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->
st_dev, newpath, (long long) newbuf.st_ino, (long long) newbuf
.st_dev); } while (0)
652 oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->st_dev,do { do { if (0) printf ("mismatching ino/dev between file %s (%lld/%lld) "
"and handle %s (%lld/%lld)", oldpath, (long long) oldbuf->
st_ino, (long long) oldbuf->st_dev, newpath, (long long) newbuf
.st_ino, (long long) newbuf.st_dev); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 653, GF_LOG_WARNING
, "mismatching ino/dev between file %s (%lld/%lld) " "and handle %s (%lld/%lld)"
, oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->
st_dev, newpath, (long long) newbuf.st_ino, (long long) newbuf
.st_dev); } while (0)
653 newpath, (long long) newbuf.st_ino, (long long) newbuf.st_dev)do { do { if (0) printf ("mismatching ino/dev between file %s (%lld/%lld) "
"and handle %s (%lld/%lld)", oldpath, (long long) oldbuf->
st_ino, (long long) oldbuf->st_dev, newpath, (long long) newbuf
.st_ino, (long long) newbuf.st_dev); } while (0); _gf_log (this
->name, "posix-handle.c", __FUNCTION__, 653, GF_LOG_WARNING
, "mismatching ino/dev between file %s (%lld/%lld) " "and handle %s (%lld/%lld)"
, oldpath, (long long) oldbuf->st_ino, (long long) oldbuf->
st_dev, newpath, (long long) newbuf.st_ino, (long long) newbuf
.st_dev); } while (0)
;
654 ret = -1;
655 }
656
657 return ret;
658}
659
660
661static int
662posix_handle_unset_gfid (xlator_t *this, uuid_t gfid)
663{
664 char *path = NULL((void*)0);
665 int ret = 0;
666 struct stat stat;
667
668 MAKE_HANDLE_GFID_PATH (path, this, gfid, NULL)do { int __len = 0; __len = posix_handle_gfid_path (this, gfid
, ((void*)0), ((void*)0), 0); if (__len <= 0) break; path =
__builtin_alloca (__len); __len = posix_handle_gfid_path (this
, gfid, ((void*)0), path, __len); } while (0)
;
669
670 ret = lstat (path, &stat);
671
672 if (ret == -1) {
673 if (errno(*__errno_location ()) != ENOENT2) {
674 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("%s: %s", path, strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 675, GF_LOG_WARNING, "%s: %s", path, strerror
((*__errno_location ()))); } while (0)
675 "%s: %s", path, strerror (errno))do { do { if (0) printf ("%s: %s", path, strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 675, GF_LOG_WARNING, "%s: %s", path, strerror
((*__errno_location ()))); } while (0)
;
676 }
677 goto out;
678 }
679
680 ret = unlink (path);
681 if (ret == -1) {
682 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("unlink %s failed (%s)", path, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 683, GF_LOG_WARNING, "unlink %s failed (%s)"
, path, strerror ((*__errno_location ()))); } while (0)
683 "unlink %s failed (%s)", path, strerror (errno))do { do { if (0) printf ("unlink %s failed (%s)", path, strerror
((*__errno_location ()))); } while (0); _gf_log (this->name
, "posix-handle.c", __FUNCTION__, 683, GF_LOG_WARNING, "unlink %s failed (%s)"
, path, strerror ((*__errno_location ()))); } while (0)
;
684 }
685
686out:
687 return ret;
688}
689
690
691int
692posix_handle_unset (xlator_t *this, uuid_t gfid, const char *basename__xpg_basename)
693{
694 int ret;
695 struct iatt stat;
696 char *path = NULL((void*)0);
697
698
699 if (!basename__xpg_basename) {
700 ret = posix_handle_unset_gfid (this, gfid);
701 return ret;
702 }
703
704 MAKE_HANDLE_PATH (path, this, gfid, basename)do { int __len; __len = posix_handle_path (this, gfid, __xpg_basename
, ((void*)0), 0); if (__len <= 0) break; path = __builtin_alloca
(__len); __len = posix_handle_path (this, gfid, __xpg_basename
, path, __len); } while (0)
;
705
706 ret = posix_istat (this, gfid, basename__xpg_basename, &stat);
707
708 if (ret == -1) {
709 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("%s: %s", path, strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 710, GF_LOG_WARNING, "%s: %s", path, strerror
((*__errno_location ()))); } while (0)
710 "%s: %s", path, strerror (errno))do { do { if (0) printf ("%s: %s", path, strerror ((*__errno_location
()))); } while (0); _gf_log (this->name, "posix-handle.c"
, __FUNCTION__, 710, GF_LOG_WARNING, "%s: %s", path, strerror
((*__errno_location ()))); } while (0)
;
711 return -1;
712 }
713
714 ret = posix_handle_unset_gfid (this, stat.ia_gfid);
715
716 return ret;
717}
718
719
720int
721posix_create_link_if_gfid_exists (xlator_t *this, uuid_t gfid,
722 char *real_path)
723{
724 int ret = -1;
725 struct stat stbuf = {0,};
726 char *newpath = NULL((void*)0);
727
728 MAKE_HANDLE_PATH (newpath, this, gfid, NULL)do { int __len; __len = posix_handle_path (this, gfid, ((void
*)0), ((void*)0), 0); if (__len <= 0) break; newpath = __builtin_alloca
(__len); __len = posix_handle_path (this, gfid, ((void*)0), newpath
, __len); } while (0)
;
729 ret = lstat (newpath, &stbuf);
730 if (!ret) {
731#ifdef HAVE_LINKAT1
732 /*
733 * Use linkat if the target may be a symlink to a directory
734 * or without an existing target. See comment about linkat()
735 * usage in posix_link() in posix.c for details
736 */
737 ret = linkat (AT_FDCWD-100, newpath, AT_FDCWD-100, real_path, 0);
738#else
739 ret = link (newpath, real_path);
740#endif
741 }
742
743 return ret;
744}