summaryrefslogtreecommitdiffstats
path: root/xlators/features/locks/src/posix.c
diff options
context:
space:
mode:
authorSusant Palai <spalai@redhat.com>2016-04-17 10:17:42 +0530
committerNiels de Vos <ndevos@redhat.com>2016-05-01 18:04:36 -0700
commit90a8d15ea9778b5089521767137b14cb52b9a2b3 (patch)
tree3f9d562aefbc67ac3973c15ca60279bd3c055803 /xlators/features/locks/src/posix.c
parent2cca000fcc2adbffbb3f5258c57ae564b9e2d51f (diff)
posix/lock: add getactivelk () fop
Change-Id: I99e41a80854d6f90572df755e14757099ae1236f BUG: 1326085 Signed-off-by: Susant Palai <spalai@redhat.com> Reviewed-on: http://review.gluster.org/13995 Reviewed-by: Niels de Vos <ndevos@redhat.com> Smoke: Gluster Build System <jenkins@build.gluster.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'xlators/features/locks/src/posix.c')
-rw-r--r--xlators/features/locks/src/posix.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c
index 1bebdc568a8..2f3ad957540 100644
--- a/xlators/features/locks/src/posix.c
+++ b/xlators/features/locks/src/posix.c
@@ -2278,6 +2278,102 @@ pl_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
return 0;
}
+lock_migration_info_t *
+gf_mig_info_for_lock (posix_lock_t *lock)
+{
+ lock_migration_info_t *new = NULL;
+
+ new = GF_CALLOC (1, sizeof (lock_migration_info_t),
+ gf_common_mt_lock_mig);
+ if (new == NULL) {
+ goto out;
+ }
+
+ INIT_LIST_HEAD (&new->list);
+
+ posix_lock_to_flock (lock, &new->flock);
+
+ new->client_uid = gf_strdup (lock->client_uid);
+
+out:
+ return new;
+}
+
+int
+pl_fill_active_locks (pl_inode_t *pl_inode, lock_migration_info_t *lmi)
+{
+ posix_lock_t *temp = NULL;
+ lock_migration_info_t *newlock = NULL;
+ int count = 0;
+
+ pthread_mutex_lock (&pl_inode->mutex);
+ {
+ if (list_empty (&pl_inode->ext_list)) {
+ count = 0;
+ goto out;
+ }
+
+ list_for_each_entry (temp, &pl_inode->ext_list, list) {
+
+ if (temp->blocked)
+ continue;
+
+ newlock = gf_mig_info_for_lock (temp);
+ if (!newlock) {
+ gf_msg (THIS->name, GF_LOG_ERROR, 0, 0,
+ "lock_dup failed");
+ count = -1;
+ goto out;
+ }
+
+ list_add_tail (&newlock->list, &lmi->list);
+ count++;
+ }
+
+ /*TODO: Need to implement meta lock/unlock. meta-unlock should
+ * set this flag. Tracking BZ: 1331720*/
+ pl_inode->migrated = _gf_true;
+ }
+
+out:
+ pthread_mutex_unlock (&pl_inode->mutex);
+ return count;
+}
+
+/* This function reads only active locks */
+static int
+pl_getactivelk (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
+{
+ pl_inode_t *pl_inode = NULL;
+ lock_migration_info_t locks;
+ int op_ret = 0;
+ int op_errno = 0;
+ int count = 0;
+
+ INIT_LIST_HEAD (&locks.list);
+
+ pl_inode = pl_inode_get (this, loc->inode);
+ if (!pl_inode) {
+ gf_msg (this->name, GF_LOG_ERROR, 0, 0,
+ "pl_inode_get failed");
+
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto out;
+ }
+
+ count = pl_fill_active_locks (pl_inode, &locks);
+
+ op_ret = count;
+
+out:
+ STACK_UNWIND_STRICT (getactivelk, frame, op_ret, op_errno, &locks,
+ NULL);
+
+ gf_free_mig_locks (&locks);
+
+ return 0;
+}
void
pl_dump_lock (char *str, int size, struct gf_flock *flock,
@@ -2869,6 +2965,7 @@ struct xlator_fops fops = {
.fgetxattr = pl_fgetxattr,
.fsetxattr = pl_fsetxattr,
.rename = pl_rename,
+ .getactivelk = pl_getactivelk,
};
struct xlator_dumpops dumpops = {