diff options
| author | Kotresh HR <khiremat@redhat.com> | 2017-06-29 05:45:34 -0400 | 
|---|---|---|
| committer | Jeff Darcy <jeff@pl.atyp.us> | 2017-07-10 14:51:14 +0000 | 
| commit | a62b16b72b03f2b7c25c24ea9ac5968453a92009 (patch) | |
| tree | 7521978a597377f082172a2b5454e83bbab02bbf | |
| parent | 9156a743aa76c955d18c9bfcb7c1a38ba00da890 (diff) | |
storage/posix: New gfid2path infra
With this infra, a new xattr is stored on each entry
creation as below.
trusted.gfid2path.<xxhash> = <pargfid>/<basename>
If there are hardlinks, multiple xattrs would be present.
Fops which are impacted:
create, mknod, link, symlink, rename, unlink
Option to enable:
gluster vol set <VOLNAME> storage.gfid2path on
Updates: #139
Change-Id: I369974cd16703c45ee87f82e6c2ff5a987a6cc6a
Signed-off-by: Kotresh HR <khiremat@redhat.com>
Reviewed-on: https://review.gluster.org/17488
Smoke: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Aravinda VK <avishwan@redhat.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
| -rw-r--r-- | libglusterfs/src/common-utils.h | 1 | ||||
| -rw-r--r-- | libglusterfs/src/glusterfs.h | 1 | ||||
| -rw-r--r-- | tests/gfid2path/gfid2path_fuse.t | 146 | ||||
| -rw-r--r-- | tests/gfid2path/gfid2path_nfs.t | 153 | ||||
| -rw-r--r-- | tests/volume.rc | 2 | ||||
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-set.c | 5 | ||||
| -rw-r--r-- | xlators/storage/posix/src/Makefile.am | 5 | ||||
| -rw-r--r-- | xlators/storage/posix/src/posix-gfid-path.c | 85 | ||||
| -rw-r--r-- | xlators/storage/posix/src/posix-gfid-path.h | 25 | ||||
| -rw-r--r-- | xlators/storage/posix/src/posix.c | 79 | ||||
| -rw-r--r-- | xlators/storage/posix/src/posix.h | 1 | 
11 files changed, 500 insertions, 3 deletions
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 86b7ec6c3d6..41cbb01440c 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -115,6 +115,7 @@ void trap (void);  /* xxhash */  #define GF_XXH64_DIGEST_LENGTH 8 +#define GF_XXHSUM64_DEFAULT_SEED 0  /* Shard */  #define GF_XATTR_SHARD_FILE_SIZE  "trusted.glusterfs.shard.file-size" diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index fa3828365f7..07c1e944232 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -121,6 +121,7 @@  #define GF_XATTR_LINKINFO_KEY   "trusted.distribute.linkinfo"  #define GFID_XATTR_KEY          "trusted.gfid"  #define PGFID_XATTR_KEY_PREFIX  "trusted.pgfid." +#define GFID2PATH_XATTR_KEY_PREFIX  "trusted.gfid2path."  #define VIRTUAL_GFID_XATTR_KEY_STR  "glusterfs.gfid.string"  #define VIRTUAL_GFID_XATTR_KEY      "glusterfs.gfid"  #define UUID_CANONICAL_FORM_LEN 36 diff --git a/tests/gfid2path/gfid2path_fuse.t b/tests/gfid2path/gfid2path_fuse.t new file mode 100644 index 00000000000..38798cf60d0 --- /dev/null +++ b/tests/gfid2path/gfid2path_fuse.t @@ -0,0 +1,146 @@ +#!/bin/bash + +. $(dirname $0)/../include.rc +. $(dirname $0)/../volume.rc + +cleanup; + +XXHSUM_SOURCE="$(dirname $0)/../../contrib/xxhash/xxhsum.c $(dirname $0)/../../contrib/xxhash/xxhash.c" +XXHSUM_EXEC=$(dirname $0)/xxhsum + +## Build xxhsum C source +build_tester $XXHSUM_SOURCE -o $XXHSUM_EXEC -I$(dirname $0)/../../contrib/xxhash +TEST [ -e $XXHSUM_EXEC ] + +TEST glusterd +TEST pidof glusterd + +## Create a single brick volume (B=1) +TEST $CLI volume create $V0 $H0:$B0/${V0}1; +EXPECT "$V0" volinfo_field $V0 'Volume Name'; +EXPECT 'Created' volinfo_field $V0 'Status'; +EXPECT '1' brick_count $V0 + +## Start the volume +TEST $CLI volume start $V0; +EXPECT 'Started' volinfo_field $V0 'Status'; + +## enable gfid2path +TEST $CLI volume set $V0 gfid2path enable + +## Mount the volume +TEST $GFS --volfile-server=$H0 --volfile-id=$V0 $M0; + +pgfid="00000000-0000-0000-0000-000000000001" +xxh64_file=$B0/${V0}1/xxh64_file + +#CREATE +fname=$M0/file1 +touch $fname; +backpath=$B0/${V0}1/file1 + +#Check for the presence of xattr +pgfid_bname=$pgfid/file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath + +#MKNOD +fname=$M0/mknod_file1 +mknod $fname p; +backpath=$B0/${V0}1/mknod_file1 + +#Check for the presence of xattr +pgfid_bname=$pgfid/mknod_file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath + +#LINK +fname1=$M0/file1 +fname2=$M0/hl_file1 +ln $fname1 $fname2 +backpath1=$B0/${V0}1/file1 +backpath2=$B0/${V0}1/hl_file1 + +#Check for the presence of two xattrs +pgfid_bname=$pgfid/file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath1 + +pgfid_bname=$pgfid/hl_file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath2 + +#RENAME +fname1=$M0/file1 +fname2=$M0/rn_file1 +mv $fname1 $fname2 +backpath=$B0/${V0}1/rn_file1 + +#Check for the presence of new xattr +pgfid_bname=$pgfid/file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT_NOT $pgfid_bname get_text_xattr $key $backpath + +pgfid_bname=$pgfid/rn_file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath + +#UNLINK +fname1=$M0/hl_file1 +rm -f $fname1 +fname2=$M0/rn_file1 +backpath=$B0/${V0}1/rn_file1 + +#Check removal of xattr +pgfid_bname=$pgfid/hl_file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT_NOT $pgfid_bname get_text_xattr $key $backpath + +pgfid_bname=$pgfid/rn_file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath + +#SYMLINK +fname=rn_file1 +sym_fname=$M0/sym_file1 +ln -s $fname $sym_fname +backpath=$B0/${V0}1/sym_file1 + +#Check for the presence of xattr +pgfid_bname=$pgfid/sym_file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath + +#FINAL UNLINK +fname=$M0/rn_file1 +sym_fname=$M0/sym_file1 +mknod_fname=$M0/mknod_file1 + +rm -f $fname +rm -f $sym_fname +rm -f $mknod_fname +TEST ! stat $fname +TEST ! stat $sym_fname +TEST ! stat $mknod_fname + +#Cleanups +rm -f $STUB_EXEC +cleanup; diff --git a/tests/gfid2path/gfid2path_nfs.t b/tests/gfid2path/gfid2path_nfs.t new file mode 100644 index 00000000000..4e229dbb99f --- /dev/null +++ b/tests/gfid2path/gfid2path_nfs.t @@ -0,0 +1,153 @@ +#!/bin/bash + +. $(dirname $0)/../include.rc +. $(dirname $0)/../volume.rc +. $(dirname $0)/../nfs.rc + +cleanup; + +XXHSUM_SOURCE="$(dirname $0)/../../contrib/xxhash/xxhsum.c $(dirname $0)/../../contrib/xxhash/xxhash.c" +XXHSUM_EXEC=$(dirname $0)/xxhsum + +## Build xxhsum C source +build_tester $XXHSUM_SOURCE -o $XXHSUM_EXEC -I$(dirname $0)/../../contrib/xxhash +TEST [ -e $XXHSUM_EXEC ] + +TEST glusterd +TEST pidof glusterd + +## Create a single brick volume (B=1) +TEST $CLI volume create $V0 $H0:$B0/${V0}1; +EXPECT "$V0" volinfo_field $V0 'Volume Name'; +EXPECT 'Created' volinfo_field $V0 'Status'; +EXPECT '1' brick_count $V0 + +TEST $CLI volume set $V0 nfs.disable false + +## Start the volume +TEST $CLI volume start $V0; +EXPECT 'Started' volinfo_field $V0 'Status'; + +## enable gfid2path +TEST $CLI volume set $V0 gfid2path enable + +## Wait for volume to register with rpc.mountd +EXPECT_WITHIN $NFS_EXPORT_TIMEOUT "1" is_nfs_export_available + +## Mount the volume +TEST mount_nfs $H0:/$V0 $N0 nolock; + + +pgfid="00000000-0000-0000-0000-000000000001" +xxh64_file=$B0/${V0}1/xxh64_file + +#CREATE +fname=$N0/file1 +touch $fname; +backpath=$B0/${V0}1/file1 + +#Check for the presence of xattr +pgfid_bname=$pgfid/file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath + +#MKNOD +fname=$N0/mknod_file1 +mknod $fname p; +backpath=$B0/${V0}1/mknod_file1 + +#Check for the presence of xattr +pgfid_bname=$pgfid/mknod_file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath + +#LINK +fname1=$N0/file1 +fname2=$N0/hl_file1 +ln $fname1 $fname2 +backpath1=$B0/${V0}1/file1 +backpath2=$B0/${V0}1/hl_file1 + +#Check for the presence of two xattrs +pgfid_bname=$pgfid/file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath1 + +pgfid_bname=$pgfid/hl_file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath2 + +#RENAME +fname1=$N0/file1 +fname2=$N0/rn_file1 +mv $fname1 $fname2 +backpath=$B0/${V0}1/rn_file1 + +#Check for the presence of new xattr +pgfid_bname=$pgfid/file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT_NOT $pgfid_bname get_text_xattr $key $backpath + +pgfid_bname=$pgfid/rn_file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath + +#UNLINK +fname1=$N0/hl_file1 +rm -f $fname1 +fname2=$N0/rn_file1 +backpath=$B0/${V0}1/rn_file1 + +#Check removal of xattr +pgfid_bname=$pgfid/hl_file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT_NOT $pgfid_bname get_text_xattr $key $backpath + +pgfid_bname=$pgfid/rn_file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath + +#SYMLINK +fname=rn_file1 +sym_fname=$N0/sym_file1 +ln -s $fname $sym_fname +backpath=$B0/${V0}1/sym_file1 + +#Check for the presence of xattr +pgfid_bname=$pgfid/sym_file1 +echo -n $pgfid_bname > $xxh64_file +xxh64sum=$($XXHSUM_EXEC $xxh64_file | awk '{print $1}') +key="trusted.gfid2path.$xxh64sum" +EXPECT $pgfid_bname get_text_xattr $key $backpath + +#FINAL UNLINK +fname=$N0/rn_file1 +sym_fname=$N0/sym_file1 +mknod_fname=$N0/mknod_file1 + +rm -f $fname +rm -f $sym_fname +rm -f $mknod_fname +TEST ! stat $fname +TEST ! stat $sym_fname +TEST ! stat $mknod_fname + +#Cleanups +rm -f $STUB_EXEC +cleanup; diff --git a/tests/volume.rc b/tests/volume.rc index 94162cfb5e4..935382b8531 100644 --- a/tests/volume.rc +++ b/tests/volume.rc @@ -356,7 +356,7 @@ function gf_gfid_xattr_to_str {  function get_text_xattr {          local key=$1          local path=$2 -        getfattr -d -m. -e text $path 2>/dev/null | grep -a $key | cut -f2 -d'=' +        getfattr -h -d -m. -e text $path 2>/dev/null | grep -a $key | cut -f2 -d'='  }  function gf_check_file_opened_in_brick { diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index c1aa66cbffb..60a1d9be5fa 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -2782,6 +2782,11 @@ struct volopt_map_entry glusterd_volopt_map[] = {            .voltype     = "storage/posix",            .op_version  = GD_OP_VERSION_3_6_0,          }, +        { .option      = "gfid2path", +          .key         = "storage.gfid2path", +          .voltype     = "storage/posix", +          .op_version  = GD_OP_VERSION_3_12_0, +        },          { .key         = "storage.bd-aio",            .voltype     = "storage/bd",            .op_version  = 3 diff --git a/xlators/storage/posix/src/Makefile.am b/xlators/storage/posix/src/Makefile.am index 2245098c9e4..8ec460578b5 100644 --- a/xlators/storage/posix/src/Makefile.am +++ b/xlators/storage/posix/src/Makefile.am @@ -4,12 +4,13 @@ xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/storage  posix_la_LDFLAGS = -module $(GF_XLATOR_DEFAULT_LDFLAGS) -posix_la_SOURCES = posix.c posix-helpers.c posix-handle.c posix-aio.c +posix_la_SOURCES = posix.c posix-helpers.c posix-handle.c posix-aio.c \ +	posix-gfid-path.c  posix_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la $(LIBAIO) \  	$(ACL_LIBS)  noinst_HEADERS = posix.h posix-mem-types.h posix-handle.h posix-aio.h \ -	posix-messages.h +	posix-messages.h posix-gfid-path.h  AM_CPPFLAGS = $(GF_CPPFLAGS) -I$(top_srcdir)/libglusterfs/src \  	-I$(top_srcdir)/rpc/xdr/src -I$(top_builddir)/rpc/xdr/src \ diff --git a/xlators/storage/posix/src/posix-gfid-path.c b/xlators/storage/posix/src/posix-gfid-path.c new file mode 100644 index 00000000000..500f4d81c24 --- /dev/null +++ b/xlators/storage/posix/src/posix-gfid-path.c @@ -0,0 +1,85 @@ +/* +   Copyright (c) 2017 Red Hat, Inc. <http://www.redhat.com> +   This file is part of GlusterFS. + +   This file is licensed to you under your choice of the GNU Lesser +   General Public License, version 3 or any later version (LGPLv3 or +   later), or the GNU General Public License, version 2 (GPLv2), in all +   cases as published by the Free Software Foundation. +*/ + +#include "common-utils.h" +#include "xlator.h" +#include "syscall.h" +#include "logging.h" +#include "posix-messages.h" + +int32_t +posix_set_gfid2path_xattr (xlator_t *this, const char *path, uuid_t pgfid, +                           const char *bname) +{ +        char        xxh64[GF_XXH64_DIGEST_LENGTH*2+1] = {0,}; +        char        pgfid_bname[1024]                 = {0,}; +        char       *key                               = NULL; +        char       *val                               = NULL; +        size_t      key_size                          = 0; +        size_t      val_size                          = 0; +        int         ret                               = 0; + +        GF_VALIDATE_OR_GOTO ("posix", this, err); + +        snprintf (pgfid_bname, sizeof (pgfid_bname), "%s/%s", uuid_utoa (pgfid), +                  bname); +        gf_xxh64_wrapper ((unsigned char *) pgfid_bname, +                          strlen(pgfid_bname), GF_XXHSUM64_DEFAULT_SEED, xxh64); +        key_size = strlen(GFID2PATH_XATTR_KEY_PREFIX) + GF_XXH64_DIGEST_LENGTH*2+1; +        key = alloca (key_size); +        snprintf (key, key_size, GFID2PATH_XATTR_KEY_PREFIX"%s", xxh64); + +        val_size = UUID_CANONICAL_FORM_LEN + NAME_MAX + 2; +        val = alloca (val_size); +        snprintf (val, val_size, "%s/%s", uuid_utoa (pgfid), bname); + +        ret = sys_lsetxattr (path, key, val, strlen(val), XATTR_CREATE); +        if (ret == -1) { +                gf_msg (this->name, GF_LOG_WARNING, errno, P_MSG_PGFID_OP, +                        "setting gfid2path xattr failed on %s: key = %s ", +                        path, key); +                goto err; +        } +        return 0; + err: +        return -1; +} + +int32_t +posix_remove_gfid2path_xattr (xlator_t *this, const char *path, +                              uuid_t pgfid, const char *bname) +{ +        char        xxh64[GF_XXH64_DIGEST_LENGTH*2+1] = {0,}; +        char        pgfid_bname[1024]                 = {0,}; +        int         ret                               = 0; +        char       *key                               = NULL; +        size_t      key_size                          = 0; + +        GF_VALIDATE_OR_GOTO ("posix", this, err); + +        snprintf (pgfid_bname, sizeof (pgfid_bname), "%s/%s", uuid_utoa (pgfid), +                  bname); +        gf_xxh64_wrapper ((unsigned char *) pgfid_bname, +                          strlen(pgfid_bname), GF_XXHSUM64_DEFAULT_SEED, xxh64); +        key_size = strlen(GFID2PATH_XATTR_KEY_PREFIX) + GF_XXH64_DIGEST_LENGTH*2+1; +        key = alloca (key_size); +        snprintf (key, key_size, GFID2PATH_XATTR_KEY_PREFIX"%s", xxh64); + +        ret = sys_lremovexattr (path, key); +        if (ret == -1) { +                gf_msg (this->name, GF_LOG_WARNING, errno, P_MSG_PGFID_OP, +                        "removing gfid2path xattr failed on %s: key = %s", +                        path, key); +                goto err; +        } +        return 0; + err: +        return -1; +} diff --git a/xlators/storage/posix/src/posix-gfid-path.h b/xlators/storage/posix/src/posix-gfid-path.h new file mode 100644 index 00000000000..dbe0c59540d --- /dev/null +++ b/xlators/storage/posix/src/posix-gfid-path.h @@ -0,0 +1,25 @@ +/* +   Copyright (c) 2017 Red Hat, Inc. <http://www.redhat.com> +   This file is part of GlusterFS. + +   This file is licensed to you under your choice of the GNU Lesser +   General Public License, version 3 or any later version (LGPLv3 or +   later), or the GNU General Public License, version 2 (GPLv2), in all +   cases as published by the Free Software Foundation. +*/ + +#ifndef _POSIX_GFID_PATH_H +#define _POSIX_GFID_PATH_H + +#include "xlator.h" +#include "common-utils.h" + +#define MAX_GFID2PATH_LINK_SUP 500 + +int32_t +posix_set_gfid2path_xattr (xlator_t *, const char *, uuid_t, +                           const char *); +int32_t +posix_remove_gfid2path_xattr (xlator_t *, const char *, uuid_t, +                              const char *); +#endif /* _POSIX_GFID_PATH_H */ diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 45c35203480..87da16694a5 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -57,6 +57,7 @@  #include "glusterfs-acl.h"  #include "posix-messages.h"  #include "events.h" +#include "posix-gfid-path.h"  extern char *marker_xattrs[];  #define ALIGN_SIZE 4096 @@ -1415,6 +1416,11 @@ post_op:                                   XATTR_CREATE, op_ret, this, ignore);          } +        if (priv->gfid2path) { +                posix_set_gfid2path_xattr (this, real_path, loc->pargfid, +                                           loc->name); +        } +  ignore:          op_ret = posix_entry_create_xattr_set (this, real_path, xdata);          if (op_ret) { @@ -2121,6 +2127,17 @@ posix_unlink (call_frame_t *frame, xlator_t *this,                  }          } +        if (priv->gfid2path && (stbuf.ia_nlink > 1)) { +                op_ret = posix_remove_gfid2path_xattr (this, real_path, +                                                       loc->pargfid, +                                                       loc->name); +                if (op_ret < 0) { +                        /* Allow unlink if pgfid xattr is not set. */ +                        if (errno != ENOATTR) +                                goto out; +                } +        } +          unwind_dict = dict_new ();          if (!unwind_dict) {                  op_errno = -ENOMEM; @@ -2382,6 +2399,12 @@ posix_symlink (call_frame_t *frame, xlator_t *this,                  SET_PGFID_XATTR (real_path, pgfid_xattr_key, nlink_samepgfid,                                   XATTR_CREATE, op_ret, this, ignore);          } + +        if (priv->gfid2path) { +                posix_set_gfid2path_xattr (this, real_path, loc->pargfid, +                                           loc->name); +        } +  ignore:          op_ret = posix_entry_create_xattr_set (this, real_path, xdata);          if (op_ret) { @@ -2459,6 +2482,7 @@ posix_rename (call_frame_t *frame, xlator_t *this,          int                   nlink           = 0;          char                 *pgfid_xattr_key = NULL;          int32_t               nlink_samepgfid = 0; +        char                 *gfid_path            = NULL;          dict_t               *unwind_dict     = NULL;          gf_boolean_t          locked          = _gf_false;          gf_boolean_t          get_link_count  = _gf_false; @@ -2645,7 +2669,20 @@ posix_rename (call_frame_t *frame, xlator_t *this,                                                   op_ret,                                                   this, unlock);                  } + +                if (!IA_ISDIR (oldloc->inode->ia_type) && priv->gfid2path) { +                        MAKE_HANDLE_ABSPATH (gfid_path, this, +                                             oldloc->inode->gfid); + +                        posix_remove_gfid2path_xattr (this, gfid_path, +                                                      oldloc->pargfid, +                                                      oldloc->name); +                        posix_set_gfid2path_xattr (this, gfid_path, +                                                   newloc->pargfid, +                                                   newloc->name); +                }          } +  unlock:          if (locked) {                  pthread_mutex_unlock (&ctx_new->pgfid_lock); @@ -2823,6 +2860,23 @@ posix_link (call_frame_t *frame, xlator_t *this,                  }          } +        if (priv->gfid2path) { +                if (stbuf.ia_nlink <= MAX_GFID2PATH_LINK_SUP) { +                        op_ret = posix_set_gfid2path_xattr (this, real_newpath, +                                                            newloc->pargfid, +                                                            newloc->name); +                        if (op_ret) { +                                op_errno = errno; +                                goto out; +                        } +                 } else { +                        gf_msg (this->name, GF_LOG_INFO, 0, +                                P_MSG_XATTR_NOTSUP, "Link count exceeded. " +                                "gfid2path xattr not set (path:%s gfid:%s)", +                                real_newpath, uuid_utoa (newloc->inode->gfid)); +                 } +        } +          op_ret = 0;  out: @@ -3012,6 +3066,11 @@ posix_create (call_frame_t *frame, xlator_t *this,                  SET_PGFID_XATTR (real_path, pgfid_xattr_key, nlink_samepgfid,                                   XATTR_CREATE, op_ret, this, ignore);          } + +        if (priv->gfid2path) { +                posix_set_gfid2path_xattr (this, real_path, loc->pargfid, +                                            loc->name); +        }  ignore:          op_ret = posix_entry_create_xattr_set (this, real_path, xdata);          if (op_ret) { @@ -6918,6 +6977,9 @@ struct posix_private *priv = NULL;          GF_OPTION_RECONF ("update-link-count-parent", priv->update_pgfid_nlinks,                            options, bool, out); +        GF_OPTION_RECONF ("gfid2path", priv->gfid2path, +                          options, bool, out); +          GF_OPTION_RECONF ("node-uuid-pathinfo", priv->node_uuid_pathinfo,                            options, bool, out); @@ -7396,6 +7458,18 @@ init (xlator_t *this)                                        " set.");          } +        tmp_data = dict_get (this->options, "gfid2path"); +        if (tmp_data) { +                if (gf_string2boolean (tmp_data->data, +                                       &_private->gfid2path) == -1) { +                        ret = -1; +                        gf_msg (this->name, GF_LOG_ERROR, 0, +                                P_MSG_INVALID_OPTION, "wrong value provided " +                                "for 'gfid2path'"); +                        goto out; +                } +        } +          ret = dict_get_str (this->options, "glusterd-uuid", &guuid);          if (!ret) {                  if (gf_uuid_parse (guuid, _private->glusterd_uuid)) @@ -7728,6 +7802,11 @@ struct volume_options options[] = {            .default_value = "off",            .description = "Enable placeholders for gfid to path conversion"          }, +        { .key = {"gfid2path"}, +          .type = GF_OPTION_TYPE_BOOL, +          .default_value = "off", +          .description = "Enable logging metadata for gfid to path conversion" +        },  #if GF_DARWIN_HOST_OS          { .key = {"xattr-user-namespace-mode"},            .type = GF_OPTION_TYPE_STR, diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h index febd4326aa1..332c0ab4f49 100644 --- a/xlators/storage/posix/src/posix.h +++ b/xlators/storage/posix/src/posix.h @@ -160,6 +160,7 @@ struct posix_private {  	uint32_t        batch_fsync_delay_usec;          gf_boolean_t    update_pgfid_nlinks; +        gf_boolean_t    gfid2path;          /* seconds to sleep between health checks */          uint32_t        health_check_interval;  | 
