diff options
author | Zhou Zhengping <johnzzpcrystal@gmail.com> | 2016-07-16 21:43:58 -0400 |
---|---|---|
committer | Jeff Darcy <jdarcy@redhat.com> | 2016-07-18 04:59:05 -0700 |
commit | 73b9ede7e115fab245b0f59d18e4d6cc4d297cec (patch) | |
tree | 88b9b003486c7b98241d93069e7fa773508b1284 | |
parent | 939184c6709db1391d38c892e098c20519d746cc (diff) |
core: add a basis function to reduce verbose code
Change-Id: Icebe1b865edb317685e93f3ef11d98fd9b2c2e9a
BUG: 1357226
Signed-off-by: Zhou Zhengping <johnzzpcrystal@gmail.com>
Reviewed-on: http://review.gluster.org/14936
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Smoke: Gluster Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
-rw-r--r-- | libglusterfs/src/common-utils.c | 14 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 6 | ||||
-rw-r--r-- | xlators/cluster/ec/src/ec-combine.c | 15 | ||||
-rw-r--r-- | xlators/features/gfid-access/src/gfid-access.c | 9 | ||||
-rw-r--r-- | xlators/features/snapview-server/src/snapview-server-helpers.c | 10 | ||||
-rw-r--r-- | xlators/meta/src/meta-helpers.c | 15 | ||||
-rw-r--r-- | xlators/performance/md-cache/src/md-cache.c | 16 | ||||
-rw-r--r-- | xlators/storage/posix/src/posix-helpers.c | 10 |
8 files changed, 24 insertions, 71 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index b9062c159c7..b2d5a279dc8 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -4538,3 +4538,17 @@ is_virtual_xattr (const char *k) return ret; } + +ino_t +gfid_to_ino (uuid_t gfid) +{ + ino_t ino = 0; + int32_t i; + + for (i = 8; i < 16; i++) { + ino <<= 8; + ino += (uint8_t)gfid[i]; + } + + return ino; +} diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index e2b3f3ea032..d7277e6e834 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -652,6 +652,12 @@ gf_time_fmt (char *dst, size_t sz_dst, time_t utime, unsigned int fmt) return dst; } +/* This function helps us use gfid (unique identity) to generate inode's unique + * number in glusterfs. + */ +ino_t +gfid_to_ino (uuid_t gfid); + int mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks); /* diff --git a/xlators/cluster/ec/src/ec-combine.c b/xlators/cluster/ec/src/ec-combine.c index 2566cc0d0cf..379d703bf35 100644 --- a/xlators/cluster/ec/src/ec-combine.c +++ b/xlators/cluster/ec/src/ec-combine.c @@ -108,21 +108,6 @@ void ec_iatt_time_merge(uint32_t * dst_sec, uint32_t * dst_nsec, } static -uint64_t -gfid_to_ino(uuid_t gfid) -{ - uint64_t ino = 0; - int32_t i; - - for (i = 8; i < 16; i++) { - ino <<= 8; - ino += (uint8_t)gfid[i]; - } - - return ino; -} - -static gf_boolean_t ec_iatt_is_trusted(ec_fop_data_t *fop, struct iatt *iatt) { diff --git a/xlators/features/gfid-access/src/gfid-access.c b/xlators/features/gfid-access/src/gfid-access.c index a2b1a2c6793..7d75b09bae0 100644 --- a/xlators/features/gfid-access/src/gfid-access.c +++ b/xlators/features/gfid-access/src/gfid-access.c @@ -655,10 +655,7 @@ ga_virtual_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, inode_t *inode, struct iatt *buf, dict_t *xdata, struct iatt *postparent) { - int j = 0; - int i = 0; int ret = 0; - uint64_t temp_ino = 0; inode_t *cbk_inode = NULL; inode_t *true_inode = NULL; uuid_t random_gfid = {0,}; @@ -727,11 +724,7 @@ ga_virtual_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, gf_uuid_copy (buf->ia_gfid, random_gfid); - for (i = 15; i > (15 - 8); i--) { - temp_ino += (uint64_t)(buf->ia_gfid[i]) << j; - j += 8; - } - buf->ia_ino = temp_ino; + buf->ia_ino = gfid_to_ino (buf->ia_gfid); unwind: /* Lookup on non-existing gfid returns ESTALE. diff --git a/xlators/features/snapview-server/src/snapview-server-helpers.c b/xlators/features/snapview-server/src/snapview-server-helpers.c index dd2e891a849..5bf41c2317b 100644 --- a/xlators/features/snapview-server/src/snapview-server-helpers.c +++ b/xlators/features/snapview-server/src/snapview-server-helpers.c @@ -347,9 +347,6 @@ svs_uuid_generate (uuid_t gfid, char *snapname, uuid_t origin_gfid) void svs_fill_ino_from_gfid (struct iatt *buf) { - uint64_t temp_ino = 0; - int j = 0; - int i = 0; xlator_t *this = NULL; this = THIS; @@ -362,11 +359,8 @@ svs_fill_ino_from_gfid (struct iatt *buf) buf->ia_ino = -1; goto out; } - for (i = 15; i > (15 - 8); i--) { - temp_ino += (uint64_t)(buf->ia_gfid[i]) << j; - j += 8; - } - buf->ia_ino = temp_ino; + + buf->ia_ino = gfid_to_ino (buf->ia_gfid); out: return; } diff --git a/xlators/meta/src/meta-helpers.c b/xlators/meta/src/meta-helpers.c index d01fcb3c679..e681af59bf7 100644 --- a/xlators/meta/src/meta-helpers.c +++ b/xlators/meta/src/meta-helpers.c @@ -185,21 +185,6 @@ meta_direct_io_mode (dict_t *xdata, call_frame_t *frame) } -static uint64_t -gfid_to_ino (uuid_t gfid) -{ - uint64_t ino = 0; - int i = 0, j = 0; - - for (i = 15; i > (15 - 8); i--) { - ino += (uint64_t)(gfid[i]) << j; - j += 8; - } - - return ino; -} - - static void meta_uuid_copy (uuid_t dst, uuid_t src) { diff --git a/xlators/performance/md-cache/src/md-cache.c b/xlators/performance/md-cache/src/md-cache.c index 1ad9e8ebda1..0a4d3c78ead 100644 --- a/xlators/performance/md-cache/src/md-cache.c +++ b/xlators/performance/md-cache/src/md-cache.c @@ -99,22 +99,6 @@ static struct mdc_key { } }; - -static uint64_t -gfid_to_ino (uuid_t gfid) -{ - uint64_t ino = 0; - int i = 0, j = 0; - - for (i = 15; i > (15 - 8); i--) { - ino += (uint64_t)(gfid[i]) << j; - j += 8; - } - - return ino; -} - - struct mdc_local; typedef struct mdc_local mdc_local_t; diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c index d6209521206..8ad674e063f 100644 --- a/xlators/storage/posix/src/posix-helpers.c +++ b/xlators/storage/posix/src/posix-helpers.c @@ -527,20 +527,12 @@ posix_fill_gfid_fd (xlator_t *this, int fd, struct iatt *iatt) void posix_fill_ino_from_gfid (xlator_t *this, struct iatt *buf) { - uint64_t temp_ino = 0; - int j = 0; - int i = 0; - /* consider least significant 8 bytes of value out of gfid */ if (gf_uuid_is_null (buf->ia_gfid)) { buf->ia_ino = -1; goto out; } - for (i = 15; i > (15 - 8); i--) { - temp_ino += (uint64_t)(buf->ia_gfid[i]) << j; - j += 8; - } - buf->ia_ino = temp_ino; + buf->ia_ino = gfid_to_ino (buf->ia_gfid); out: return; } |