summaryrefslogtreecommitdiffstats
path: root/xlators/features/locks
diff options
context:
space:
mode:
authorPavan Sondur <pavan@gluster.com>2009-10-29 09:31:42 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-10-29 12:02:54 -0700
commitd45e6b9a17a2a40a06d6cffbac97e6568223f143 (patch)
tree01e2b1ebf93ed41d12fee0897bdb4a0f01c26ff6 /xlators/features/locks
parentb9e3c902bf6eed825ebd6323a5905d64a3153269 (diff)
Implement lookup in posix locks to return lock counts in a dict value.
Signed-off-by: Pavan Vilas Sondur <pavan@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 306 (Enhance locks to aid debugging) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=306
Diffstat (limited to 'xlators/features/locks')
-rw-r--r--xlators/features/locks/src/common.h6
-rw-r--r--xlators/features/locks/src/internal.c106
-rw-r--r--xlators/features/locks/src/locks.h5
-rw-r--r--xlators/features/locks/src/posix.c181
4 files changed, 298 insertions, 0 deletions
diff --git a/xlators/features/locks/src/common.h b/xlators/features/locks/src/common.h
index cc53482c4..9f9afc1ca 100644
--- a/xlators/features/locks/src/common.h
+++ b/xlators/features/locks/src/common.h
@@ -75,4 +75,10 @@ void entrylk_trace_block (xlator_t *this, call_frame_t *frame, const char *volum
fd_t *fd, loc_t *loc, const char *basename,
entrylk_cmd cmd, entrylk_type type);
+int32_t
+get_inodelk_count (xlator_t *this, inode_t *inode);
+
+int32_t
+get_entrylk_count (xlator_t *this, inode_t *inode);
+
#endif /* __COMMON_H__ */
diff --git a/xlators/features/locks/src/internal.c b/xlators/features/locks/src/internal.c
index 116902fa8..8959122c3 100644
--- a/xlators/features/locks/src/internal.c
+++ b/xlators/features/locks/src/internal.c
@@ -927,3 +927,109 @@ out:
return 0;
}
+
+static int32_t
+__get_inodelk_count (xlator_t *this, pl_inode_t *pl_inode)
+{
+ int32_t count = 0;
+ posix_lock_t *lock = NULL;
+
+ list_for_each_entry (lock, &pl_inode->int_list, list) {
+
+ gf_log (this->name, GF_LOG_DEBUG,
+ " XATTR DEBUG"
+ "%s (pid=%d) %"PRId64" - %"PRId64" state: %s",
+ lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
+ lock->client_pid,
+ lock->user_flock.l_start,
+ lock->user_flock.l_len,
+ lock->blocked == 1 ? "Blocked" : "Active");
+
+ count++;
+ }
+
+ return count;
+}
+
+int32_t
+get_inodelk_count (xlator_t *this, inode_t *inode)
+{
+ pl_inode_t *pl_inode = NULL;
+ uint64_t tmp_pl_inode = 0;
+ int ret = 0;
+ int32_t count = 0;
+
+ ret = inode_ctx_get (inode, this, &tmp_pl_inode);
+ if (ret != 0) {
+ goto out;
+ }
+
+ pl_inode = (pl_inode_t *)(long) tmp_pl_inode;
+
+ pthread_mutex_lock (&pl_inode->mutex);
+ {
+ count = __get_inodelk_count (this, pl_inode);
+ }
+ pthread_mutex_unlock (&pl_inode->mutex);
+
+out:
+ return count;
+}
+
+static int32_t
+__get_entrylk_count (xlator_t *this, pl_inode_t *pl_inode)
+{
+ int32_t count = 0;
+ pl_entry_lock_t *lock = NULL;
+ pl_entry_lock_t *bl_lock = NULL;
+
+ list_for_each_entry (lock, &pl_inode->dir_list, inode_list) {
+
+ gf_log (this->name, GF_LOG_DEBUG,
+ " XATTR DEBUG"
+ " %s on %s state = Active",
+ lock->type == ENTRYLK_RDLCK ? "ENTRYLK_RDLCK" : "ENTRYLK_WRLCK",
+ lock->basename);
+ count++;
+
+ list_for_each_entry (bl_lock, &lock->blocked_locks, blocked_locks) {
+
+ gf_log (this->name, GF_LOG_DEBUG,
+ " XATTR DEBUG"
+ " %s on %s state = Blocked",
+ bl_lock->type == ENTRYLK_RDLCK ? "ENTRYLK_RDLCK" : "ENTRYLK_WRLCK",
+ bl_lock->basename);
+
+ count++;
+
+ }
+
+ }
+
+ return count;
+}
+
+int32_t
+get_entrylk_count (xlator_t *this, inode_t *inode)
+{
+ pl_inode_t *pl_inode = NULL;
+ uint64_t tmp_pl_inode = 0;
+ int ret = 0;
+ int32_t count = 0;
+
+ ret = inode_ctx_get (inode, this, &tmp_pl_inode);
+ if (ret != 0) {
+ goto out;
+ }
+
+ pl_inode = (pl_inode_t *)(long) tmp_pl_inode;
+
+ pthread_mutex_lock (&pl_inode->mutex);
+ {
+ count = __get_entrylk_count (this, pl_inode);
+ }
+ pthread_mutex_unlock (&pl_inode->mutex);
+
+out:
+ return count;
+}
diff --git a/xlators/features/locks/src/locks.h b/xlators/features/locks/src/locks.h
index f649dd609..98fa1b3aa 100644
--- a/xlators/features/locks/src/locks.h
+++ b/xlators/features/locks/src/locks.h
@@ -111,5 +111,10 @@ typedef struct {
gf_boolean_t trace; /* trace lock requests in and out */
} posix_locks_private_t;
+typedef struct {
+ gf_boolean_t entrylk_count_req;
+ gf_boolean_t inodelk_count_req;
+ gf_boolean_t posixlk_count_req;
+} pl_local_t;
#endif /* __POSIX_LOCKS_H__ */
diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c
index e2ff664ca..52c4c5441 100644
--- a/xlators/features/locks/src/posix.c
+++ b/xlators/features/locks/src/posix.c
@@ -777,6 +777,186 @@ pl_forget (xlator_t *this,
return 0;
}
+static int32_t
+__get_posixlk_count (xlator_t *this, pl_inode_t *pl_inode)
+{
+ posix_lock_t *lock = NULL;
+ int32_t count = 0;
+
+ list_for_each_entry (lock, &pl_inode->ext_list, list) {
+
+ gf_log (this->name, GF_LOG_DEBUG,
+ " XATTR DEBUG"
+ "%s (pid=%d) %"PRId64" - %"PRId64" state: %s",
+ lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
+ lock->client_pid,
+ lock->user_flock.l_start,
+ lock->user_flock.l_len,
+ lock->blocked == 1 ? "Blocked" : "Active");
+
+ count++;
+ }
+
+ return count;
+}
+
+int32_t
+get_posixlk_count (xlator_t *this, inode_t *inode)
+{
+ pl_inode_t *pl_inode = NULL;
+ uint64_t tmp_pl_inode = 0;
+ int ret = 0;
+ int32_t count = 0;
+
+ ret = inode_ctx_get (inode, this, &tmp_pl_inode);
+ if (ret != 0) {
+ goto out;
+ }
+
+ pl_inode = (pl_inode_t *)(long) tmp_pl_inode;
+
+ pthread_mutex_lock (&pl_inode->mutex);
+ {
+ count = __get_posixlk_count (this, pl_inode);
+ }
+ pthread_mutex_unlock (&pl_inode->mutex);
+
+out:
+ return count;
+}
+
+void pl_entrylk_xattr_fill (xlator_t *this, inode_t *inode,
+ dict_t *dict)
+{
+ int32_t count = 0;
+ int ret = -1;
+
+ count = get_entrylk_count (this, inode);
+ ret = dict_set_int32 (dict, GLUSTERFS_ENTRYLK_COUNT, count);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ " dict_set failed on key %s", GLUSTERFS_ENTRYLK_COUNT);
+ }
+
+}
+
+void pl_inodelk_xattr_fill (xlator_t *this, inode_t *inode,
+ dict_t *dict)
+{
+ int32_t count = 0;
+ int ret = -1;
+
+ 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);
+ }
+
+}
+
+void pl_posixlk_xattr_fill (xlator_t *this, inode_t *inode,
+ dict_t *dict)
+{
+ int32_t count = 0;
+ int ret = -1;
+
+ count = get_posixlk_count (this, inode);
+ ret = dict_set_int32 (dict, GLUSTERFS_POSIXLK_COUNT, count);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ " dict_set failed on key %s", GLUSTERFS_POSIXLK_COUNT);
+ }
+
+}
+
+int32_t
+pl_lookup_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ inode_t *inode,
+ struct stat *buf,
+ dict_t *dict)
+{
+ pl_local_t *local = NULL;
+
+ if (!frame->local) {
+ goto out;
+ }
+
+ local = frame->local;
+
+ if (local->entrylk_count_req)
+ pl_entrylk_xattr_fill (this, inode, dict);
+ if (local->inodelk_count_req)
+ pl_inodelk_xattr_fill (this, inode, dict);
+ if (local->posixlk_count_req)
+ pl_posixlk_xattr_fill (this, inode, dict);
+
+
+ frame->local = NULL;
+
+ if (local != NULL)
+ FREE (local);
+
+out:
+ STACK_UNWIND (frame,
+ op_ret,
+ op_errno,
+ inode,
+ buf,
+ dict);
+
+ return 0;
+}
+
+int32_t
+pl_lookup (call_frame_t *frame,
+ xlator_t *this,
+ loc_t *loc,
+ dict_t *xattr_req)
+
+{
+ pl_local_t *local = NULL;
+ int ret = -1;
+
+ VALIDATE_OR_GOTO (frame, out);
+ VALIDATE_OR_GOTO (this, out);
+ VALIDATE_OR_GOTO (loc, out);
+
+ local = CALLOC (1, sizeof (*local));
+ if (!local) {
+ ret = -1;
+ gf_log (this->name, GF_LOG_ERROR,
+ " Out of memory");
+ goto out;
+ }
+
+ if (dict_get (xattr_req, GLUSTERFS_ENTRYLK_COUNT))
+ local->entrylk_count_req = 1;
+ if (dict_get (xattr_req, GLUSTERFS_INODELK_COUNT))
+ local->inodelk_count_req = 1;
+ if (dict_get (xattr_req, GLUSTERFS_POSIXLK_COUNT))
+ local->posixlk_count_req = 1;
+
+ frame->local = local;
+
+ STACK_WIND (frame,
+ pl_lookup_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup,
+ loc,
+ xattr_req);
+
+ ret = 0;
+out:
+ if (ret == -1)
+ STACK_UNWIND (frame, -1, 0, NULL, NULL, NULL, NULL);
+
+ return 0;
+}
int
init (xlator_t *this)
@@ -867,6 +1047,7 @@ pl_fentrylk (call_frame_t *frame, xlator_t *this,
entrylk_cmd cmd, entrylk_type type);
struct xlator_fops fops = {
+ .lookup = pl_lookup,
.create = pl_create,
.truncate = pl_truncate,
.ftruncate = pl_ftruncate,