From 704961a39ffd019487e36ac6dbd425399cb85cf2 Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Fri, 4 Oct 2019 11:17:44 +0300 Subject: Multiple files: make root gfid a static variable In many places we use it, compare to it, etc. It could be a static variable, as it really doesn't change. I think it's better than initializing to 0 and then doing gfid[15] = 1 or other tricks. I think there are additional oppportunuties to make more variables static. This is an attempt at an easy one. Change-Id: I7f23a30a94056d8f043645371ab841cbd0f90d19 updates: bz#1193929 Signed-off-by: Yaniv Kaul --- xlators/cluster/dht/src/dht-common.c | 5 +--- xlators/cluster/dht/src/dht-helper.c | 7 +----- xlators/cluster/dht/src/dht-rebalance.c | 5 +--- xlators/cluster/ec/src/ec-helpers.c | 2 +- xlators/features/bit-rot/src/stub/bit-rot-stub.c | 11 ++------- xlators/features/gfid-access/src/gfid-access.c | 6 ++--- xlators/mount/fuse/src/fuse-bridge.c | 4 +--- xlators/nfs/server/src/mount3.c | 10 ++------ xlators/nfs/server/src/nfs-common.c | 5 +--- xlators/nfs/server/src/nfs-fops.c | 2 +- xlators/nfs/server/src/nfs3-fh.c | 6 ++--- xlators/protocol/server/src/server-common.c | 30 +++++------------------- xlators/storage/posix/src/posix-common.c | 2 +- xlators/storage/posix/src/posix-handle.c | 2 +- 14 files changed, 24 insertions(+), 73 deletions(-) diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c index 232685bd56d..b295ce8bd03 100644 --- a/xlators/cluster/dht/src/dht-common.c +++ b/xlators/cluster/dht/src/dht-common.c @@ -6395,9 +6395,7 @@ dht_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) int i = -1; inode_t *inode = NULL; inode_table_t *itable = NULL; - uuid_t root_gfid = { - 0, - }; + static uuid_t root_gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; loc_t newloc = { 0, }; @@ -6423,7 +6421,6 @@ dht_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) } loc = &local->loc2; - root_gfid[15] = 1; inode = inode_find(itable, root_gfid); if (!inode) { diff --git a/xlators/cluster/dht/src/dht-helper.c b/xlators/cluster/dht/src/dht-helper.c index 980a562deb2..9d3e3a3a0b2 100644 --- a/xlators/cluster/dht/src/dht-helper.c +++ b/xlators/cluster/dht/src/dht-helper.c @@ -1917,9 +1917,7 @@ dht_heal_path(xlator_t *this, char *path, inode_table_t *itable) }; char *bname = NULL; char *save_ptr = NULL; - uuid_t gfid = { - 0, - }; + static uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; char *tmp_path = NULL; tmp_path = gf_strdup(path); @@ -1927,9 +1925,6 @@ dht_heal_path(xlator_t *this, char *path, inode_table_t *itable) goto out; } - memset(gfid, 0, 16); - gfid[15] = 1; - gf_uuid_copy(loc.pargfid, gfid); loc.parent = inode_ref(itable->root); diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c index 0bf499abbf3..d4e639db704 100644 --- a/xlators/cluster/dht/src/dht-rebalance.c +++ b/xlators/cluster/dht/src/dht-rebalance.c @@ -2447,15 +2447,12 @@ void dht_build_root_inode(xlator_t *this, inode_t **inode) { inode_table_t *itable = NULL; - uuid_t root_gfid = { - 0, - }; + static uuid_t root_gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; itable = inode_table_new(0, this); if (!itable) return; - root_gfid[15] = 1; *inode = inode_find(itable, root_gfid); } diff --git a/xlators/cluster/ec/src/ec-helpers.c b/xlators/cluster/ec/src/ec-helpers.c index baac001d169..48f54475e01 100644 --- a/xlators/cluster/ec/src/ec-helpers.c +++ b/xlators/cluster/ec/src/ec-helpers.c @@ -476,7 +476,7 @@ out: int32_t ec_loc_setup_path(xlator_t *xl, loc_t *loc) { - uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; char *name; int32_t ret = -EINVAL; diff --git a/xlators/features/bit-rot/src/stub/bit-rot-stub.c b/xlators/features/bit-rot/src/stub/bit-rot-stub.c index de2184d6193..d9ac009d316 100644 --- a/xlators/features/bit-rot/src/stub/bit-rot-stub.c +++ b/xlators/features/bit-rot/src/stub/bit-rot-stub.c @@ -1817,9 +1817,7 @@ br_stub_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name, dict_t *xdata) { void *cookie = NULL; - uuid_t rootgfid = { - 0, - }; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; fop_getxattr_cbk_t cbk = br_stub_getxattr_cbk; int32_t op_ret = -1; int32_t op_errno = EINVAL; @@ -1831,8 +1829,6 @@ br_stub_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, GF_VALIDATE_OR_GOTO(this->name, this->private, unwind); GF_VALIDATE_OR_GOTO(this->name, loc->inode, unwind); - rootgfid[15] = 1; - if (!name) { cbk = br_stub_listxattr_cbk; goto wind; @@ -1902,16 +1898,13 @@ br_stub_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd, const char *name, dict_t *xdata) { void *cookie = NULL; - uuid_t rootgfid = { - 0, - }; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; fop_fgetxattr_cbk_t cbk = br_stub_getxattr_cbk; int32_t op_ret = -1; int32_t op_errno = EINVAL; br_stub_local_t *local = NULL; br_stub_private_t *priv = NULL; - rootgfid[15] = 1; priv = this->private; if (!name) { diff --git a/xlators/features/gfid-access/src/gfid-access.c b/xlators/features/gfid-access/src/gfid-access.c index ad7776741d9..3fea5672a21 100644 --- a/xlators/features/gfid-access/src/gfid-access.c +++ b/xlators/features/gfid-access/src/gfid-access.c @@ -327,10 +327,8 @@ out: static gf_boolean_t __is_gfid_access_dir(uuid_t gfid) { - uuid_t aux_gfid; - - memset(aux_gfid, 0, 16); - aux_gfid[15] = GF_AUX_GFID; + static uuid_t aux_gfid = {0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, GF_AUX_GFID}; if (gf_uuid_compare(gfid, aux_gfid) == 0) return _gf_true; diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c index e1bd095b177..2ed8bbdcc44 100644 --- a/xlators/mount/fuse/src/fuse-bridge.c +++ b/xlators/mount/fuse/src/fuse-bridge.c @@ -5220,7 +5220,7 @@ fuse_first_lookup(xlator_t *this) }; xlator_t *xl = NULL; dict_t *dict = NULL; - uuid_t gfid; + static uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; int ret = -1; struct iatt iatt = { 0, @@ -5238,8 +5238,6 @@ fuse_first_lookup(xlator_t *this) xl = priv->active_subvol; - memset(gfid, 0, 16); - gfid[15] = 1; ret = dict_set_gfuuid(dict, "gfid-req", gfid, true); if (ret) { gf_log(xl->name, GF_LOG_ERROR, "failed to set 'gfid-req'"); diff --git a/xlators/nfs/server/src/mount3.c b/xlators/nfs/server/src/mount3.c index 177046ecf8c..3b16bb82c74 100644 --- a/xlators/nfs/server/src/mount3.c +++ b/xlators/nfs/server/src/mount3.c @@ -920,14 +920,11 @@ mnt3svc_volume_mount(rpcsvc_request_t *req, struct mount3_state *ms, { inode_t *exportinode = NULL; int ret = -EFAULT; - uuid_t rootgfid = { - 0, - }; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; if ((!req) || (!exp) || (!ms)) return ret; - rootgfid[15] = 1; exportinode = inode_find(exp->vol->itable, rootgfid); if (!exportinode) { gf_msg(GF_MNT, GF_LOG_ERROR, ENOENT, NFS_MSG_GET_ROOT_INODE_FAIL, @@ -1372,9 +1369,7 @@ __mnt3_resolve_subdir(mnt3_resolve_t *mres) nfs_user_t nfu = { 0, }; - uuid_t rootgfid = { - 0, - }; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; if (!mres) return ret; @@ -1385,7 +1380,6 @@ __mnt3_resolve_subdir(mnt3_resolve_t *mres) if (!firstcomp) goto err; - rootgfid[15] = 1; ret = nfs_entry_loc_fill(mres->mstate->nfsx, mres->exp->vol->itable, rootgfid, firstcomp, &mres->resolveloc, NFS_RESOLVE_CREATE, NULL); diff --git a/xlators/nfs/server/src/nfs-common.c b/xlators/nfs/server/src/nfs-common.c index 5b3ee976e37..b8f6b6f318e 100644 --- a/xlators/nfs/server/src/nfs-common.c +++ b/xlators/nfs/server/src/nfs-common.c @@ -272,11 +272,8 @@ err: int nfs_root_loc_fill(inode_table_t *itable, loc_t *loc) { - uuid_t rootgfid = { - 0, - }; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; - rootgfid[15] = 1; return nfs_gfid_loc_fill(itable, rootgfid, loc, NFS_RESOLVE_EXIST); } diff --git a/xlators/nfs/server/src/nfs-fops.c b/xlators/nfs/server/src/nfs-fops.c index 896c67c9305..4d8540c2c3e 100644 --- a/xlators/nfs/server/src/nfs-fops.c +++ b/xlators/nfs/server/src/nfs-fops.c @@ -327,7 +327,7 @@ nfs_gfid_dict(inode_t *inode) unsigned char *dyngfid = NULL; dict_t *dictgfid = NULL; int ret = -1; - uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; dyngfid = GF_MALLOC(sizeof(uuid_t), gf_common_mt_char); if (dyngfid == NULL) diff --git a/xlators/nfs/server/src/nfs3-fh.c b/xlators/nfs/server/src/nfs3-fh.c index d0c0a2f55b2..caa3cfa6995 100644 --- a/xlators/nfs/server/src/nfs3-fh.c +++ b/xlators/nfs/server/src/nfs3-fh.c @@ -64,7 +64,7 @@ nfs3_fh_build_indexed_root_fh(xlator_list_t *cl, xlator_t *xl) struct iatt buf = { 0, }; - uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; if ((!cl) || (!xl)) return fh; @@ -85,7 +85,7 @@ nfs3_fh_build_uuid_root_fh(uuid_t volumeid, uuid_t mountid) struct iatt buf = { 0, }; - uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static uuid_t root = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; gf_uuid_copy(buf.ia_gfid, root); nfs3_fh_init(&fh, &buf); @@ -98,7 +98,7 @@ nfs3_fh_build_uuid_root_fh(uuid_t volumeid, uuid_t mountid) int nfs3_fh_is_root_fh(struct nfs3_fh *fh) { - uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; if (!fh) return 0; diff --git a/xlators/protocol/server/src/server-common.c b/xlators/protocol/server/src/server-common.c index ce7f264dd80..4bb84042a9e 100644 --- a/xlators/protocol/server/src/server-common.c +++ b/xlators/protocol/server/src/server-common.c @@ -21,11 +21,8 @@ server_post_stat(server_state_t *state, gfs3_stat_rsp *rsp, struct iatt *stbuf) we use inode table which is shared by everyone, but make sure we send fops only from subdir and below, we have to alter inode gfid and send it to client */ - uuid_t gfid = { - 0, - }; + static uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; - gfid[15] = 1; stbuf->ia_ino = 1; gf_uuid_copy(stbuf->ia_gfid, gfid); } @@ -182,11 +179,8 @@ server_post_fstat(server_state_t *state, gfs3_fstat_rsp *rsp, we use inode table which is shared by everyone, but make sure we send fops only from subdir and below, we have to alter inode gfid and send it to client */ - uuid_t gfid = { - 0, - }; + static uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; - gfid[15] = 1; stbuf->ia_ino = 1; gf_uuid_copy(stbuf->ia_gfid, gfid); } @@ -454,9 +448,7 @@ server_post_lookup(gfs3_lookup_rsp *rsp, call_frame_t *frame, { inode_t *root_inode = NULL; inode_t *link_inode = NULL; - uuid_t rootgfid = { - 0, - }; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; root_inode = frame->root->client->bound_xl->itable->root; @@ -480,7 +472,6 @@ server_post_lookup(gfs3_lookup_rsp *rsp, call_frame_t *frame, make sure we send fops only from subdir and below, we have to alter inode gfid and send it to client */ stbuf->ia_ino = 1; - rootgfid[15] = 1; gf_uuid_copy(stbuf->ia_gfid, rootgfid); if (inode->ia_type == 0) inode->ia_type = stbuf->ia_type; @@ -521,11 +512,8 @@ server4_post_common_3iatt(server_state_t *state, gfx_common_3iatt_rsp *rsp, we use inode table which is shared by everyone, but make sure we send fops only from subdir and below, we have to alter inode gfid and send it to client */ - uuid_t gfid = { - 0, - }; + static uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; - gfid[15] = 1; preparent->ia_ino = 1; postparent->ia_ino = 1; gf_uuid_copy(preparent->ia_gfid, gfid); @@ -591,11 +579,8 @@ server4_post_common_iatt(server_state_t *state, gfx_common_iatt_rsp *rsp, we use inode table which is shared by everyone, but make sure we send fops only from subdir and below, we have to alter inode gfid and send it to client */ - uuid_t gfid = { - 0, - }; + static uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; - gfid[15] = 1; stbuf->ia_ino = 1; gf_uuid_copy(stbuf->ia_gfid, gfid); } @@ -802,9 +787,7 @@ server4_post_lookup(gfx_common_2iatt_rsp *rsp, call_frame_t *frame, { inode_t *root_inode = NULL; inode_t *link_inode = NULL; - uuid_t rootgfid = { - 0, - }; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; root_inode = frame->root->client->bound_xl->itable->root; @@ -828,7 +811,6 @@ server4_post_lookup(gfx_common_2iatt_rsp *rsp, call_frame_t *frame, make sure we send fops only from subdir and below, we have to alter inode gfid and send it to client */ stbuf->ia_ino = 1; - rootgfid[15] = 1; gf_uuid_copy(stbuf->ia_gfid, rootgfid); if (inode->ia_type == 0) inode->ia_type = stbuf->ia_type; diff --git a/xlators/storage/posix/src/posix-common.c b/xlators/storage/posix/src/posix-common.c index abe086da105..13b70da4d64 100644 --- a/xlators/storage/posix/src/posix-common.c +++ b/xlators/storage/posix/src/posix-common.c @@ -576,7 +576,7 @@ posix_init(xlator_t *this) uuid_t gfid = { 0, }; - uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static uuid_t rootgfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; char *guuid = NULL; int32_t uid = -1; int32_t gid = -1; diff --git a/xlators/storage/posix/src/posix-handle.c b/xlators/storage/posix/src/posix-handle.c index 4764c47cbae..f4686a96ed9 100644 --- a/xlators/storage/posix/src/posix-handle.c +++ b/xlators/storage/posix/src/posix-handle.c @@ -504,7 +504,7 @@ posix_handle_init(xlator_t *this) struct stat rootbuf; struct stat exportbuf; char *rootstr = NULL; - uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + static uuid_t gfid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; priv = this->private; -- cgit