From 4fb5a2af7b9fe926782ea6139349eeb63be86920 Mon Sep 17 00:00:00 2001 From: vmallika Date: Sat, 2 Apr 2016 08:57:00 +0530 Subject: marker: optimize mq_update_dirty_inode_task This is a backport of http://review.gluster.org/#/c/13892/ In function mq_update_dirty_inode_task we do readdirp on a dirty directory and for entry we again do lookup to fecth the contribution xattr. We can fetch this contribution as part of readdirp > Change-Id: I766593c0dba793f1ab3b43625acce1c7d9af8d7f > BUG: 1320818 > Signed-off-by: vmallika Change-Id: Id826a09a72529f7435372ea7f04068dd10da5fcb BUG: 1324040 Signed-off-by: vmallika Reviewed-on: http://review.gluster.org/13908 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System --- xlators/features/marker/src/marker-quota.c | 94 ++++++++++++++---------------- 1 file changed, 44 insertions(+), 50 deletions(-) (limited to 'xlators/features/marker') diff --git a/xlators/features/marker/src/marker-quota.c b/xlators/features/marker/src/marker-quota.c index d6545dae5a0..4e91c640295 100644 --- a/xlators/features/marker/src/marker-quota.c +++ b/xlators/features/marker/src/marker-quota.c @@ -377,17 +377,6 @@ mq_sub_meta (quota_meta_t *dst, const quota_meta_t *src) } } -gf_boolean_t -quota_meta_is_null (const quota_meta_t *meta) -{ - if (meta->size == 0 && - meta->file_count == 0 && - meta->dir_count == 0) - return _gf_true; - - return _gf_false; -} - int32_t mq_are_xattrs_set (xlator_t *this, loc_t *loc, gf_boolean_t *contri_set, gf_boolean_t *size_set) @@ -1754,24 +1743,24 @@ out: int mq_update_dirty_inode_task (void *opaque) { - int32_t ret = -1; - fd_t *fd = NULL; - off_t offset = 0; - loc_t child_loc = {0, }; + int32_t ret = -1; + fd_t *fd = NULL; + off_t offset = 0; gf_dirent_t entries; - gf_dirent_t *entry = NULL; - gf_boolean_t locked = _gf_false; - gf_boolean_t free_entries = _gf_false; - gf_boolean_t updated = _gf_false; - int32_t dirty = 0; - quota_meta_t contri = {0, }; - quota_meta_t size = {0, }; - quota_meta_t contri_sum = {0, }; - quota_meta_t delta = {0, }; - quota_synctask_t *args = NULL; - xlator_t *this = NULL; - loc_t *loc = NULL; - quota_inode_ctx_t *ctx = NULL; + gf_dirent_t *entry = NULL; + gf_boolean_t locked = _gf_false; + gf_boolean_t updated = _gf_false; + int32_t dirty = 0; + quota_meta_t contri = {0, }; + quota_meta_t size = {0, }; + quota_meta_t contri_sum = {0, }; + quota_meta_t delta = {0, }; + quota_synctask_t *args = NULL; + xlator_t *this = NULL; + loc_t *loc = NULL; + quota_inode_ctx_t *ctx = NULL; + dict_t *xdata = NULL; + char contri_key[QUOTA_KEY_MAX] = {0, }; GF_ASSERT (opaque); @@ -1779,11 +1768,29 @@ mq_update_dirty_inode_task (void *opaque) loc = &args->loc; this = args->this; THIS = this; + INIT_LIST_HEAD (&entries.list); ret = mq_inode_ctx_get (loc->inode, this, &ctx); if (ret < 0) goto out; + GET_CONTRI_KEY (this, contri_key, loc->gfid, ret); + if (ret < 0) + goto out; + + xdata = dict_new (); + if (xdata == NULL) { + gf_log (this->name, GF_LOG_ERROR, "dict_new failed"); + ret = -1; + goto out; + } + + ret = dict_set_int64 (xdata, contri_key, 0); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "dict_set failed"); + goto out; + } + ret = mq_lock (this, loc, F_WRLCK); if (ret < 0) goto out; @@ -1811,9 +1818,8 @@ mq_update_dirty_inode_task (void *opaque) } fd_bind (fd); - INIT_LIST_HEAD (&entries.list); while ((ret = syncop_readdirp (this, fd, 131072, offset, &entries, - NULL, NULL)) != 0) { + xdata, NULL)) != 0) { if (ret < 0) { gf_log (this->name, (-ret == ENOENT || -ret == ESTALE) ? GF_LOG_DEBUG:GF_LOG_ERROR, "readdirp failed " @@ -1824,7 +1830,6 @@ mq_update_dirty_inode_task (void *opaque) if (list_empty (&entries.list)) break; - free_entries = _gf_true; list_for_each_entry (entry, &entries.list, list) { offset = entry->d_off; @@ -1832,26 +1837,15 @@ mq_update_dirty_inode_task (void *opaque) !strcmp (entry->d_name, "..")) continue; - ret = loc_build_child (&child_loc, loc, entry->d_name); - if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "Couldn't build loc for %s/%s " - "returning from updation of dirty " - "inode", loc->path, entry->d_name); - goto out; - } - - ret = mq_get_contri (this, &child_loc, &contri, - loc->gfid); - if (ret < 0) - goto out; + memset (&contri, 0, sizeof (contri)); + quota_dict_get_meta (entry->dict, contri_key, &contri); + if (quota_meta_is_null (&contri)) + continue; mq_add_meta (&contri_sum, &contri); - loc_wipe (&child_loc); } gf_dirent_free (&entries); - free_entries = _gf_false; } /* Inculde for self */ contri_sum.dir_count++; @@ -1888,12 +1882,14 @@ mq_update_dirty_inode_task (void *opaque) updated = _gf_true; out: - if (free_entries) - gf_dirent_free (&entries); + gf_dirent_free (&entries); if (fd) fd_unref (fd); + if (xdata) + dict_unref (xdata); + if (ret < 0) { /* On failure clear dirty status flag. * In the next lookup inspect_directory_xattr @@ -1909,8 +1905,6 @@ out: if (locked) mq_lock (this, loc, F_UNLCK); - loc_wipe(&child_loc); - if (updated) mq_initiate_quota_blocking_txn (this, loc, NULL); -- cgit