locks: Added an xdata-based 'cmd' for inodelk count in a given domain

Following is the semantics of the 'cmd':
1) If @domain is NULL - returns no. of locks blocked/granted in all domains
2) If @domain is non-NULL- returns no. of locks blocked/granted in that
domain
3) If @domain is non-existent - returns '0'; This is important since
locks xlator creates a domain in a lazy manner.

where @domain - a string representing the domain.

Change-Id: I5e609772343acc157ca650300618c1161efbe72d
BUG: 951195
Original-author: Krishnan Parthasarathi <kparthas@redhat.com>
Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com>
Signed-off-by: shishir gowda <sgowda@redhat.com>
Reviewed-on: http://review.gluster.org/4889
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amarts@redhat.com>
This commit is contained in:
shishir gowda 2013-06-05 15:56:27 +05:30 committed by Vijay Bellur
parent ad5ab12160
commit 15e11cfa1d
5 changed files with 70 additions and 22 deletions

View File

@ -110,6 +110,7 @@
#define GLUSTERFS_ENTRYLK_COUNT "glusterfs.entrylk-count"
#define GLUSTERFS_POSIXLK_COUNT "glusterfs.posixlk-count"
#define GLUSTERFS_PARENT_ENTRYLK "glusterfs.parent-entrylk"
#define GLUSTERFS_INODELK_DOM_COUNT "glusterfs.inodelk-dom-count"
#define QUOTA_SIZE_KEY "trusted.glusterfs.quota.size"
#define GFID_TO_PATH_KEY "glusterfs.gfid2path"
#define GF_XATTR_STIME_PATTERN "trusted.glusterfs.*.stime"

View File

@ -78,9 +78,9 @@ grant_blocked_entry_locks (xlator_t *this, pl_inode_t *pl_inode,
void pl_update_refkeeper (xlator_t *this, inode_t *inode);
int32_t
__get_inodelk_count (xlator_t *this, pl_inode_t *pl_inode);
__get_inodelk_count (xlator_t *this, pl_inode_t *pl_inode, char *domname);
int32_t
get_inodelk_count (xlator_t *this, inode_t *inode);
get_inodelk_count (xlator_t *this, inode_t *inode, char *domname);
int32_t
__get_entrylk_count (xlator_t *this, pl_inode_t *pl_inode);

View File

@ -683,29 +683,50 @@ pl_finodelk (call_frame_t *frame, xlator_t *this,
}
static inline int32_t
__get_inodelk_dom_count (pl_dom_list_t *dom)
{
pl_inode_lock_t *lock = NULL;
int32_t count = 0;
list_for_each_entry (lock, &dom->inodelk_list, list) {
count++;
}
list_for_each_entry (lock, &dom->blocked_inodelks, blocked_locks) {
count++;
}
return count;
}
/* Returns the no. of locks (blocked/granted) held on a given domain name
* If @domname is NULL, returns the no. of locks in all the domains present.
* If @domname is non-NULL and non-existent, returns 0 */
int32_t
__get_inodelk_count (xlator_t *this, pl_inode_t *pl_inode)
__get_inodelk_count (xlator_t *this, pl_inode_t *pl_inode, char *domname)
{
int32_t count = 0;
pl_inode_lock_t *lock = NULL;
pl_dom_list_t *dom = NULL;
list_for_each_entry (dom, &pl_inode->dom_list, inode_list) {
list_for_each_entry (lock, &dom->inodelk_list, list) {
count++;
}
list_for_each_entry (lock, &dom->blocked_inodelks, blocked_locks) {
count++;
}
if (domname) {
if (strcmp (domname, dom->domain) == 0) {
count = __get_inodelk_dom_count (dom);
goto out;
}
} else {
/* Counting locks from all domains */
count += __get_inodelk_dom_count (dom);
}
}
out:
return count;
}
int32_t
get_inodelk_count (xlator_t *this, inode_t *inode)
get_inodelk_count (xlator_t *this, inode_t *inode, char *domname)
{
pl_inode_t *pl_inode = NULL;
uint64_t tmp_pl_inode = 0;
@ -721,7 +742,7 @@ get_inodelk_count (xlator_t *this, inode_t *inode)
pthread_mutex_lock (&pl_inode->mutex);
{
count = __get_inodelk_count (this, pl_inode);
count = __get_inodelk_count (this, pl_inode, domname);
}
pthread_mutex_unlock (&pl_inode->mutex);

View File

@ -155,6 +155,7 @@ typedef struct {
typedef struct {
gf_boolean_t entrylk_count_req;
gf_boolean_t inodelk_count_req;
gf_boolean_t inodelk_dom_count_req;
gf_boolean_t posixlk_count_req;
gf_boolean_t parent_entrylk_req;

View File

@ -1946,19 +1946,34 @@ pl_entrylk_xattr_fill (xlator_t *this, inode_t *inode,
}
void
pl_inodelk_xattr_fill (xlator_t *this, inode_t *inode,
dict_t *dict)
pl_inodelk_xattr_fill (xlator_t *this, inode_t *inode, dict_t *dict,
gf_boolean_t per_dom)
{
int32_t count = 0;
int ret = -1;
char *domname = NULL;
count = get_inodelk_count (this, inode);
ret = dict_set_int32 (dict, GLUSTERFS_INODELK_COUNT, count);
if (ret < 0) {
gf_log (this->name, GF_LOG_DEBUG,
" dict_set failed on key %s", GLUSTERFS_INODELK_COUNT);
if (per_dom){
ret = dict_get_str (dict, GLUSTERFS_INODELK_DOM_COUNT,
&domname);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to get "
"value for key %s",GLUSTERFS_INODELK_DOM_COUNT);
goto out;
}
}
count = get_inodelk_count (this, inode, domname);
ret = dict_set_int32 (dict, GLUSTERFS_INODELK_COUNT, count);
if (ret < 0) {
gf_log (this->name, GF_LOG_DEBUG, "Failed to set count for "
"key %s", GLUSTERFS_INODELK_COUNT);
}
out:
return;
}
void
@ -2003,7 +2018,9 @@ pl_lookup_cbk (call_frame_t *frame,
if (local->entrylk_count_req)
pl_entrylk_xattr_fill (this, inode, xdata);
if (local->inodelk_count_req)
pl_inodelk_xattr_fill (this, inode, xdata);
pl_inodelk_xattr_fill (this, inode, xdata, _gf_false);
if (local->inodelk_dom_count_req)
pl_inodelk_xattr_fill (this, inode, xdata, _gf_true);
if (local->posixlk_count_req)
pl_posixlk_xattr_fill (this, inode, xdata);
@ -2050,6 +2067,8 @@ pl_lookup (call_frame_t *frame,
local->entrylk_count_req = 1;
if (dict_get (xdata, GLUSTERFS_INODELK_COUNT))
local->inodelk_count_req = 1;
if (dict_get (xdata, GLUSTERFS_INODELK_DOM_COUNT))
local->inodelk_dom_count_req = 1;
if (dict_get (xdata, GLUSTERFS_POSIXLK_COUNT))
local->posixlk_count_req = 1;
if (dict_get (xdata, GLUSTERFS_PARENT_ENTRYLK))
@ -2088,7 +2107,11 @@ pl_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
if (local->entrylk_count_req)
pl_entrylk_xattr_fill (this, entry->inode, entry->dict);
if (local->inodelk_count_req)
pl_inodelk_xattr_fill (this, entry->inode, entry->dict);
pl_inodelk_xattr_fill (this, entry->inode, entry->dict,
_gf_false);
if (local->inodelk_dom_count_req)
pl_inodelk_xattr_fill (this, entry->inode, entry->dict,
_gf_true);
if (local->posixlk_count_req)
pl_posixlk_xattr_fill (this, entry->inode, entry->dict);
}
@ -2117,6 +2140,8 @@ pl_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
local->entrylk_count_req = 1;
if (dict_get (dict, GLUSTERFS_INODELK_COUNT))
local->inodelk_count_req = 1;
if (dict_get (dict, GLUSTERFS_INODELK_DOM_COUNT))
local->inodelk_dom_count_req = 1;
if (dict_get (dict, GLUSTERFS_POSIXLK_COUNT))
local->posixlk_count_req = 1;
}
@ -2433,7 +2458,7 @@ unlock:
__dump_entrylks (pl_inode);
}
count = __get_inodelk_count (this, pl_inode);
count = __get_inodelk_count (this, pl_inode, NULL);
if (count) {
gf_proc_dump_write("inodelk-count", "%d", count);
__dump_inodelks (pl_inode);