summaryrefslogtreecommitdiffstats
path: root/xlators/features/index
diff options
context:
space:
mode:
authorEmmanuel Dreyfus <manu@netbsd.org>2013-12-19 14:11:45 +0100
committerVijay Bellur <vbellur@redhat.com>2014-01-02 22:01:48 -0800
commitd1f8b7ebc71df415f6b8ff37e9654ecee0d9064c (patch)
treea7376a9dd9f0475a7b763e16c5cbf86c9ae450d4 /xlators/features/index
parent2ce8918759e9676a54791848fd2ac85f48a05016 (diff)
Use linkat() instead of link() for portability sake
POSIX does not says wether link(2) on symlink should link on symlink itself or on target. Linux use symlink, most other systems use target. Using linkat(2) allows the behavior to be specified, so that the behavior is portable. Also fix configure test for NetBSD linkata(2), which ceased to work. BUG: 764655 Change-Id: Iccd27ac076b7a74e40dcbaa1c4762fd3ad59da5f Signed-off-by: Emmanuel Dreyfus <manu@netbsd.org> Reviewed-on: http://review.gluster.org/6539 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'xlators/features/index')
-rw-r--r--xlators/features/index/src/index.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c
index fde0893ec48..6c634dd9ad1 100644
--- a/xlators/features/index/src/index.c
+++ b/xlators/features/index/src/index.c
@@ -407,7 +407,12 @@ sync_base_indices (void *index_priv)
snprintf (base_index_path, PATH_MAX, "%s/%s",
base_indices_holder, entry->d_name);
+#ifdef HAVE_LINKAT
+ /* see HAVE_LINKAT in xlators/storage/posix/src/posix.c */
+ ret = linkat (AT_FDCWD, xattrop_index_path, AT_FDCWD, base_index_path, 0);
+#else
ret = link (xattrop_index_path, base_index_path);
+#endif
if (ret && errno != EEXIST)
goto out;
@@ -543,7 +548,12 @@ index_add (xlator_t *this, uuid_t gfid, const char *subdir)
index_get_index (priv, index);
make_index_path (priv->index_basepath, subdir,
index, index_path, sizeof (index_path));
+#ifdef HAVE_LINKAT
+ /* see HAVE_LINKAT in xlators/storage/posix/src/posix.c */
+ ret = linkat (AT_FDCWD, index_path, AT_FDCWD, gfid_path, 0);
+#else
ret = link (index_path, gfid_path);
+#endif
if (!ret || (errno == EEXIST)) {
ret = 0;
index_created = 1;
@@ -576,7 +586,12 @@ index_add (xlator_t *this, uuid_t gfid, const char *subdir)
if (fd >= 0)
close (fd);
+#ifdef HAVE_LINKAT
+ /* see HAVE_LINKAT in xlators/storage/posix/src/posix.c */
+ ret = linkat (AT_FDCWD, index_path, AT_FDCWD, gfid_path, 0);
+#else
ret = link (index_path, gfid_path);
+#endif
if (ret && (errno != EEXIST)) {
gf_log (this->name, GF_LOG_ERROR, "%s: Not able to "
"add to index (%s)", uuid_utoa (gfid),
@@ -590,7 +605,12 @@ index_add (xlator_t *this, uuid_t gfid, const char *subdir)
make_index_path (priv->index_basepath,
GF_BASE_INDICES_HOLDER_GFID,
index, base_path, sizeof (base_path));
+#ifdef HAVE_LINKAT
+ /* see HAVE_LINKAT in xlators/storage/posix/src/posix.c */
+ ret = linkat (AT_FDCWD, index_path, AT_FDCWD, base_path, 0);
+#else
ret = link (index_path, base_path);
+#endif
if (ret)
goto out;
}