summaryrefslogtreecommitdiffstats
path: root/xlators/features/locks
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/features/locks')
-rw-r--r--xlators/features/locks/src/common.c372
-rw-r--r--xlators/features/locks/src/common.h4
-rw-r--r--xlators/features/locks/src/entrylk.c30
-rw-r--r--xlators/features/locks/src/inodelk.c100
-rw-r--r--xlators/features/locks/src/locks.h94
-rw-r--r--xlators/features/locks/src/posix.c996
6 files changed, 798 insertions, 798 deletions
diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c
index b9037688a3f..a2401d4e94d 100644
--- a/xlators/features/locks/src/common.c
+++ b/xlators/features/locks/src/common.c
@@ -371,34 +371,34 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small)
memcpy (v.locks[1], small, sizeof (posix_lock_t));
}
- else {
- gf_log ("posix-locks", GF_LOG_ERROR,
- "Unexpected case in subtract_locks. Please send "
+ else {
+ gf_log ("posix-locks", GF_LOG_ERROR,
+ "Unexpected case in subtract_locks. Please send "
"a bug report to gluster-devel@nongnu.org");
- }
+ }
- return v;
+ return v;
}
/*
- Start searching from {begin}, and return the first lock that
- conflicts, NULL if no conflict
- If {begin} is NULL, then start from the beginning of the list
+ Start searching from {begin}, and return the first lock that
+ conflicts, NULL if no conflict
+ If {begin} is NULL, then start from the beginning of the list
*/
static posix_lock_t *
first_overlap (pl_inode_t *pl_inode, posix_lock_t *lock)
{
- posix_lock_t *l = NULL;
+ posix_lock_t *l = NULL;
- list_for_each_entry (l, &pl_inode->ext_list, list) {
- if (l->blocked)
- continue;
+ list_for_each_entry (l, &pl_inode->ext_list, list) {
+ if (l->blocked)
+ continue;
- if (locks_overlap (l, lock))
- return l;
- }
+ if (locks_overlap (l, lock))
+ return l;
+ }
- return NULL;
+ return NULL;
}
@@ -407,21 +407,21 @@ first_overlap (pl_inode_t *pl_inode, posix_lock_t *lock)
static int
__is_lock_grantable (pl_inode_t *pl_inode, posix_lock_t *lock)
{
- posix_lock_t *l = NULL;
- int ret = 1;
-
- list_for_each_entry (l, &pl_inode->ext_list, list) {
- if (!l->blocked && locks_overlap (lock, l)) {
- if (((l->fl_type == F_WRLCK)
- || (lock->fl_type == F_WRLCK))
- && (lock->fl_type != F_UNLCK)
- && !same_owner (l, lock)) {
- ret = 0;
- break;
- }
- }
- }
- return ret;
+ posix_lock_t *l = NULL;
+ int ret = 1;
+
+ list_for_each_entry (l, &pl_inode->ext_list, list) {
+ if (!l->blocked && locks_overlap (lock, l)) {
+ if (((l->fl_type == F_WRLCK)
+ || (lock->fl_type == F_WRLCK))
+ && (lock->fl_type != F_UNLCK)
+ && !same_owner (l, lock)) {
+ ret = 0;
+ break;
+ }
+ }
+ }
+ return ret;
}
@@ -431,224 +431,224 @@ extern void do_blocked_rw (pl_inode_t *);
static void
__insert_and_merge (pl_inode_t *pl_inode, posix_lock_t *lock)
{
- posix_lock_t *conf = NULL;
- posix_lock_t *t = NULL;
- posix_lock_t *sum = NULL;
- int i = 0;
- struct _values v = { .locks = {0, 0, 0} };
+ posix_lock_t *conf = NULL;
+ posix_lock_t *t = NULL;
+ posix_lock_t *sum = NULL;
+ int i = 0;
+ struct _values v = { .locks = {0, 0, 0} };
- list_for_each_entry_safe (conf, t, &pl_inode->ext_list, list) {
- if (!locks_overlap (conf, lock))
- continue;
+ list_for_each_entry_safe (conf, t, &pl_inode->ext_list, list) {
+ if (!locks_overlap (conf, lock))
+ continue;
- if (same_owner (conf, lock)) {
- if (conf->fl_type == lock->fl_type) {
- sum = add_locks (lock, conf);
+ if (same_owner (conf, lock)) {
+ if (conf->fl_type == lock->fl_type) {
+ sum = add_locks (lock, conf);
- sum->fl_type = lock->fl_type;
- sum->transport = lock->transport;
- sum->client_pid = lock->client_pid;
+ sum->fl_type = lock->fl_type;
+ sum->transport = lock->transport;
+ sum->client_pid = lock->client_pid;
- __delete_lock (pl_inode, conf);
- __destroy_lock (conf);
+ __delete_lock (pl_inode, conf);
+ __destroy_lock (conf);
- __destroy_lock (lock);
- __insert_and_merge (pl_inode, sum);
+ __destroy_lock (lock);
+ __insert_and_merge (pl_inode, sum);
- return;
- } else {
- sum = add_locks (lock, conf);
+ return;
+ } else {
+ sum = add_locks (lock, conf);
- sum->fl_type = conf->fl_type;
- sum->transport = conf->transport;
- sum->client_pid = conf->client_pid;
+ sum->fl_type = conf->fl_type;
+ sum->transport = conf->transport;
+ sum->client_pid = conf->client_pid;
- v = subtract_locks (sum, lock);
+ v = subtract_locks (sum, lock);
- __delete_lock (pl_inode, conf);
- __destroy_lock (conf);
+ __delete_lock (pl_inode, conf);
+ __destroy_lock (conf);
- __delete_lock (pl_inode, lock);
- __destroy_lock (lock);
+ __delete_lock (pl_inode, lock);
+ __destroy_lock (lock);
- __destroy_lock (sum);
+ __destroy_lock (sum);
- for (i = 0; i < 3; i++) {
- if (!v.locks[i])
- continue;
+ for (i = 0; i < 3; i++) {
+ if (!v.locks[i])
+ continue;
INIT_LIST_HEAD (&v.locks[i]->list);
- __insert_and_merge (pl_inode,
- v.locks[i]);
- }
+ __insert_and_merge (pl_inode,
+ v.locks[i]);
+ }
- __delete_unlck_locks (pl_inode);
- return;
- }
- }
+ __delete_unlck_locks (pl_inode);
+ return;
+ }
+ }
- if (lock->fl_type == F_UNLCK) {
- continue;
- }
+ if (lock->fl_type == F_UNLCK) {
+ continue;
+ }
- if ((conf->fl_type == F_RDLCK) && (lock->fl_type == F_RDLCK)) {
- __insert_lock (pl_inode, lock);
- return;
- }
- }
+ if ((conf->fl_type == F_RDLCK) && (lock->fl_type == F_RDLCK)) {
+ __insert_lock (pl_inode, lock);
+ return;
+ }
+ }
- /* no conflicts, so just insert */
- if (lock->fl_type != F_UNLCK) {
- __insert_lock (pl_inode, lock);
- } else {
- __destroy_lock (lock);
- }
+ /* no conflicts, so just insert */
+ if (lock->fl_type != F_UNLCK) {
+ __insert_lock (pl_inode, lock);
+ } else {
+ __destroy_lock (lock);
+ }
}
void
__grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode, struct list_head *granted)
{
- struct list_head tmp_list;
- posix_lock_t *l = NULL;
- posix_lock_t *tmp = NULL;
- posix_lock_t *conf = NULL;
+ struct list_head tmp_list;
+ posix_lock_t *l = NULL;
+ posix_lock_t *tmp = NULL;
+ posix_lock_t *conf = NULL;
- INIT_LIST_HEAD (&tmp_list);
+ INIT_LIST_HEAD (&tmp_list);
- list_for_each_entry_safe (l, tmp, &pl_inode->ext_list, list) {
- if (l->blocked) {
- conf = first_overlap (pl_inode, l);
- if (conf)
- continue;
+ list_for_each_entry_safe (l, tmp, &pl_inode->ext_list, list) {
+ if (l->blocked) {
+ conf = first_overlap (pl_inode, l);
+ if (conf)
+ continue;
- l->blocked = 0;
- list_move_tail (&l->list, &tmp_list);
- }
- }
+ l->blocked = 0;
+ list_move_tail (&l->list, &tmp_list);
+ }
+ }
- list_for_each_entry_safe (l, tmp, &tmp_list, list) {
- list_del_init (&l->list);
+ list_for_each_entry_safe (l, tmp, &tmp_list, list) {
+ list_del_init (&l->list);
- if (__is_lock_grantable (pl_inode, l)) {
- conf = CALLOC (1, sizeof (*conf));
+ if (__is_lock_grantable (pl_inode, l)) {
+ conf = CALLOC (1, sizeof (*conf));
- if (!conf) {
- l->blocked = 1;
- __insert_lock (pl_inode, l);
- continue;
- }
+ if (!conf) {
+ l->blocked = 1;
+ __insert_lock (pl_inode, l);
+ continue;
+ }
- conf->frame = l->frame;
- l->frame = NULL;
+ conf->frame = l->frame;
+ l->frame = NULL;
- posix_lock_to_flock (l, &conf->user_flock);
+ posix_lock_to_flock (l, &conf->user_flock);
- gf_log (this->name, GF_LOG_TRACE,
- "%s (pid=%d) %"PRId64" - %"PRId64" => Granted",
- l->fl_type == F_UNLCK ? "Unlock" : "Lock",
- l->client_pid,
- l->user_flock.l_start,
- l->user_flock.l_len);
+ gf_log (this->name, GF_LOG_TRACE,
+ "%s (pid=%d) %"PRId64" - %"PRId64" => Granted",
+ l->fl_type == F_UNLCK ? "Unlock" : "Lock",
+ l->client_pid,
+ l->user_flock.l_start,
+ l->user_flock.l_len);
- __insert_and_merge (pl_inode, l);
+ __insert_and_merge (pl_inode, l);
- list_add (&conf->list, granted);
- } else {
- l->blocked = 1;
- __insert_lock (pl_inode, l);
- }
- }
+ list_add (&conf->list, granted);
+ } else {
+ l->blocked = 1;
+ __insert_lock (pl_inode, l);
+ }
+ }
}
void
grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode)
{
- struct list_head granted_list;
- posix_lock_t *tmp = NULL;
- posix_lock_t *lock = NULL;
+ struct list_head granted_list;
+ posix_lock_t *tmp = NULL;
+ posix_lock_t *lock = NULL;
- INIT_LIST_HEAD (&granted_list);
+ INIT_LIST_HEAD (&granted_list);
- pthread_mutex_lock (&pl_inode->mutex);
- {
- __grant_blocked_locks (this, pl_inode, &granted_list);
- }
- pthread_mutex_unlock (&pl_inode->mutex);
+ pthread_mutex_lock (&pl_inode->mutex);
+ {
+ __grant_blocked_locks (this, pl_inode, &granted_list);
+ }
+ pthread_mutex_unlock (&pl_inode->mutex);
- list_for_each_entry_safe (lock, tmp, &granted_list, list) {
- list_del_init (&lock->list);
+ list_for_each_entry_safe (lock, tmp, &granted_list, list) {
+ list_del_init (&lock->list);
- STACK_UNWIND (lock->frame, 0, 0, &lock->user_flock);
+ STACK_UNWIND (lock->frame, 0, 0, &lock->user_flock);
- FREE (lock);
- }
+ FREE (lock);
+ }
- return;
+ return;
}
int
pl_setlk (xlator_t *this, pl_inode_t *pl_inode, posix_lock_t *lock,
- int can_block)
+ int can_block)
{
- int ret = 0;
-
- errno = 0;
-
- pthread_mutex_lock (&pl_inode->mutex);
- {
- if (__is_lock_grantable (pl_inode, lock)) {
- gf_log (this->name, GF_LOG_TRACE,
- "%s (pid=%d) %"PRId64" - %"PRId64" => OK",
- lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
- lock->client_pid,
- lock->user_flock.l_start,
- lock->user_flock.l_len);
- __insert_and_merge (pl_inode, lock);
- } else if (can_block) {
- gf_log (this->name, GF_LOG_TRACE,
- "%s (pid=%d) %"PRId64" - %"PRId64" => Blocked",
- lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
- lock->client_pid,
- lock->user_flock.l_start,
- lock->user_flock.l_len);
- lock->blocked = 1;
- __insert_lock (pl_inode, lock);
- ret = -1;
- } else {
- gf_log (this->name, GF_LOG_TRACE,
- "%s (pid=%d) %"PRId64" - %"PRId64" => NOK",
- lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
- lock->client_pid,
- lock->user_flock.l_start,
- lock->user_flock.l_len);
- errno = EAGAIN;
- ret = -1;
- }
- }
- pthread_mutex_unlock (&pl_inode->mutex);
+ int ret = 0;
+
+ errno = 0;
+
+ pthread_mutex_lock (&pl_inode->mutex);
+ {
+ if (__is_lock_grantable (pl_inode, lock)) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "%s (pid=%d) %"PRId64" - %"PRId64" => OK",
+ lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
+ lock->client_pid,
+ lock->user_flock.l_start,
+ lock->user_flock.l_len);
+ __insert_and_merge (pl_inode, lock);
+ } else if (can_block) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "%s (pid=%d) %"PRId64" - %"PRId64" => Blocked",
+ lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
+ lock->client_pid,
+ lock->user_flock.l_start,
+ lock->user_flock.l_len);
+ lock->blocked = 1;
+ __insert_lock (pl_inode, lock);
+ ret = -1;
+ } else {
+ gf_log (this->name, GF_LOG_TRACE,
+ "%s (pid=%d) %"PRId64" - %"PRId64" => NOK",
+ lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
+ lock->client_pid,
+ lock->user_flock.l_start,
+ lock->user_flock.l_len);
+ errno = EAGAIN;
+ ret = -1;
+ }
+ }
+ pthread_mutex_unlock (&pl_inode->mutex);
- grant_blocked_locks (this, pl_inode);
+ grant_blocked_locks (this, pl_inode);
- do_blocked_rw (pl_inode);
+ do_blocked_rw (pl_inode);
- return ret;
+ return ret;
}
posix_lock_t *
pl_getlk (pl_inode_t *pl_inode, posix_lock_t *lock)
{
- posix_lock_t *conf = NULL;
+ posix_lock_t *conf = NULL;
- conf = first_overlap (pl_inode, lock);
+ conf = first_overlap (pl_inode, lock);
- if (conf == NULL) {
- lock->fl_type = F_UNLCK;
- return lock;
- }
+ if (conf == NULL) {
+ lock->fl_type = F_UNLCK;
+ return lock;
+ }
- return conf;
+ return conf;
}
diff --git a/xlators/features/locks/src/common.h b/xlators/features/locks/src/common.h
index 59201c9070a..36a74168649 100644
--- a/xlators/features/locks/src/common.h
+++ b/xlators/features/locks/src/common.h
@@ -31,7 +31,7 @@ pl_getlk (pl_inode_t *inode, posix_lock_t *lock);
int
pl_setlk (xlator_t *this, pl_inode_t *inode, posix_lock_t *lock,
- int can_block);
+ int can_block);
void
grant_blocked_locks (xlator_t *this, pl_inode_t *inode);
@@ -63,7 +63,7 @@ __destroy_inode_lock (pl_inode_lock_t *lock);
void
grant_blocked_entry_locks (xlator_t *this, pl_inode_t *pl_inode,
- pl_entry_lock_t *unlocked, pl_dom_list_t *dom);
+ pl_entry_lock_t *unlocked, pl_dom_list_t *dom);
void pl_update_refkeeper (xlator_t *this, inode_t *inode);
diff --git a/xlators/features/locks/src/entrylk.c b/xlators/features/locks/src/entrylk.c
index e22a8305d27..4e038809cac 100644
--- a/xlators/features/locks/src/entrylk.c
+++ b/xlators/features/locks/src/entrylk.c
@@ -253,10 +253,10 @@ __lock_name (pl_inode_t *pinode, const char *basename, entrylk_type type,
default:
- gf_log (this->name, GF_LOG_DEBUG,
- "Invalid type for entrylk specified: %d", type);
- ret = -EINVAL;
- goto out;
+ gf_log (this->name, GF_LOG_DEBUG,
+ "Invalid type for entrylk specified: %d", type);
+ ret = -EINVAL;
+ goto out;
}
ret = 0;
@@ -430,8 +430,8 @@ unlock:
/* Common entrylk code called by pl_entrylk and pl_fentrylk */
int
pl_common_entrylk (call_frame_t *frame, xlator_t *this,
- const char *volume, inode_t *inode, const char *basename,
- entrylk_cmd cmd, entrylk_type type)
+ const char *volume, inode_t *inode, const char *basename,
+ entrylk_cmd cmd, entrylk_type type)
{
int32_t op_ret = -1;
int32_t op_errno = 0;
@@ -467,8 +467,8 @@ pl_common_entrylk (call_frame_t *frame, xlator_t *this,
if (pid == 0) {
/*
- this is a special case that means release
- all locks from this transport
+ this is a special case that means release
+ all locks from this transport
*/
gf_log (this->name, GF_LOG_TRACE,
@@ -516,7 +516,7 @@ pl_common_entrylk (call_frame_t *frame, xlator_t *this,
case ENTRYLK_UNLOCK:
pthread_mutex_lock (&pinode->mutex);
{
- unlocked = __unlock_name (dom, basename, type);
+ unlocked = __unlock_name (dom, basename, type);
}
pthread_mutex_unlock (&pinode->mutex);
@@ -554,9 +554,9 @@ pl_entrylk (call_frame_t *frame, xlator_t *this,
entrylk_cmd cmd, entrylk_type type)
{
- pl_common_entrylk (frame, this, volume, loc->inode, basename, cmd, type);
+ pl_common_entrylk (frame, this, volume, loc->inode, basename, cmd, type);
- return 0;
+ return 0;
}
@@ -568,11 +568,11 @@ pl_entrylk (call_frame_t *frame, xlator_t *this,
int
pl_fentrylk (call_frame_t *frame, xlator_t *this,
- const char *volume, fd_t *fd, const char *basename,
- entrylk_cmd cmd, entrylk_type type)
+ const char *volume, fd_t *fd, const char *basename,
+ entrylk_cmd cmd, entrylk_type type)
{
- pl_common_entrylk (frame, this, volume, fd->inode, basename, cmd, type);
+ pl_common_entrylk (frame, this, volume, fd->inode, basename, cmd, type);
- return 0;
+ return 0;
}
diff --git a/xlators/features/locks/src/inodelk.c b/xlators/features/locks/src/inodelk.c
index 1cb2c952200..dd6c54bddfc 100644
--- a/xlators/features/locks/src/inodelk.c
+++ b/xlators/features/locks/src/inodelk.c
@@ -34,13 +34,13 @@
#include "common.h"
void
- __delete_inode_lock (pl_inode_lock_t *lock)
+__delete_inode_lock (pl_inode_lock_t *lock)
{
list_del (&lock->list);
}
void
- __destroy_inode_lock (pl_inode_lock_t *lock)
+__destroy_inode_lock (pl_inode_lock_t *lock)
{
FREE (lock);
}
@@ -117,7 +117,7 @@ __blocked_lock_conflict (pl_dom_list_t *dom, pl_inode_lock_t *lock)
}
}
- out:
+out:
return ret;
}
@@ -158,12 +158,12 @@ __lock_inodelk (xlator_t *this, pl_inode_t *pl_inode, pl_inode_lock_t *lock,
list_add_tail (&lock->blocked_locks, &dom->blocked_inodelks);
- gf_log (this->name, GF_LOG_TRACE,
- "%s (pid=%d) %"PRId64" - %"PRId64" => Blocked",
- lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
- lock->client_pid,
- lock->user_flock.l_start,
- lock->user_flock.l_len);
+ gf_log (this->name, GF_LOG_TRACE,
+ "%s (pid=%d) %"PRId64" - %"PRId64" => Blocked",
+ lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
+ lock->client_pid,
+ lock->user_flock.l_start,
+ lock->user_flock.l_len);
goto out;
@@ -179,11 +179,11 @@ __lock_inodelk (xlator_t *this, pl_inode_t *pl_inode, pl_inode_lock_t *lock,
gf_log (this->name, GF_LOG_TRACE,
"Lock is grantable, but blocking to prevent starvation");
gf_log (this->name, GF_LOG_TRACE,
- "%s (pid=%d) %"PRId64" - %"PRId64" => Blocked",
- lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
- lock->client_pid,
- lock->user_flock.l_start,
- lock->user_flock.l_len);
+ "%s (pid=%d) %"PRId64" - %"PRId64" => Blocked",
+ lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
+ lock->client_pid,
+ lock->user_flock.l_start,
+ lock->user_flock.l_len);
goto out;
@@ -230,13 +230,13 @@ __inode_unlock_lock (xlator_t *this, pl_inode_lock_t *lock, pl_dom_list_t *dom)
conf = find_matching_inodelk (lock, dom);
if (!conf) {
- gf_log (this->name, GF_LOG_DEBUG,
- " Matching lock not found for unlock");
+ gf_log (this->name, GF_LOG_DEBUG,
+ " Matching lock not found for unlock");
goto out;
}
__delete_inode_lock (conf);
- gf_log (this->name, GF_LOG_DEBUG,
- " Matching lock found for unlock");
+ gf_log (this->name, GF_LOG_DEBUG,
+ " Matching lock found for unlock");
__destroy_inode_lock (lock);
@@ -361,11 +361,11 @@ pl_inode_setlk (xlator_t *this, pl_inode_t *pl_inode, pl_inode_lock_t *lock,
ret = __lock_inodelk (this, pl_inode, lock, can_block, dom);
if (ret == 0)
gf_log (this->name, GF_LOG_TRACE,
- "%s (pid=%d) %"PRId64" - %"PRId64" => OK",
- lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
- lock->client_pid,
- lock->fl_start,
- lock->fl_end);
+ "%s (pid=%d) %"PRId64" - %"PRId64" => OK",
+ lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
+ lock->client_pid,
+ lock->fl_start,
+ lock->fl_end);
if (ret == -EAGAIN)
gf_log (this->name, GF_LOG_TRACE,
@@ -387,19 +387,19 @@ pl_inode_setlk (xlator_t *this, pl_inode_t *pl_inode, pl_inode_lock_t *lock,
goto out;
}
- gf_log (this->name, GF_LOG_TRACE,
- "%s (pid=%d) %"PRId64" - %"PRId64" => OK",
- lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
- lock->client_pid,
- lock->user_flock.l_start,
- lock->user_flock.l_len);
- ret = 0;
-
- grant_blocked_inode_locks (this, pl_inode, retlock, dom);
+ gf_log (this->name, GF_LOG_TRACE,
+ "%s (pid=%d) %"PRId64" - %"PRId64" => OK",
+ lock->fl_type == F_UNLCK ? "Unlock" : "Lock",
+ lock->client_pid,
+ lock->user_flock.l_start,
+ lock->user_flock.l_len);
+ ret = 0;
+
+ grant_blocked_inode_locks (this, pl_inode, retlock, dom);
}
out:
pthread_mutex_unlock (&pl_inode->mutex);
- return ret;
+ return ret;
}
/* Create a new inode_lock_t */
@@ -434,7 +434,7 @@ new_inode_lock (struct flock *flock, transport_t *transport, pid_t client_pid, c
/* Common inodelk code called form pl_inodelk and pl_finodelk */
int
pl_common_inodelk (call_frame_t *frame, xlator_t *this,
- const char *volume, inode_t *inode, int32_t cmd, struct flock *flock)
+ const char *volume, inode_t *inode, int32_t cmd, struct flock *flock)
{
int32_t op_ret = -1;
int32_t op_errno = 0;
@@ -470,8 +470,8 @@ pl_common_inodelk (call_frame_t *frame, xlator_t *this,
if (client_pid == 0) {
/*
- special case: this means release all locks
- from this transport
+ special case: this means release all locks
+ from this transport
*/
gf_log (this->name, GF_LOG_TRACE,
"Releasing all locks from transport %p", transport);
@@ -500,7 +500,7 @@ pl_common_inodelk (call_frame_t *frame, xlator_t *this,
case F_SETLK:
memcpy (&reqlock->user_flock, flock, sizeof (struct flock));
ret = pl_inode_setlk (this, pinode, reqlock,
- can_block, dom);
+ can_block, dom);
if (ret < 0) {
if (can_block)
@@ -516,38 +516,38 @@ pl_common_inodelk (call_frame_t *frame, xlator_t *this,
default:
op_errno = ENOTSUP;
gf_log (this->name, GF_LOG_DEBUG,
- "Lock command F_GETLK not supported for [f]inodelk "
+ "Lock command F_GETLK not supported for [f]inodelk "
"(cmd=%d)",
- cmd);
- goto unwind;
- }
+ cmd);
+ goto unwind;
+ }
- op_ret = 0;
+ op_ret = 0;
unwind:
pl_update_refkeeper (this, inode);
- STACK_UNWIND_STRICT (inodelk, frame, op_ret, op_errno);
+ STACK_UNWIND_STRICT (inodelk, frame, op_ret, op_errno);
out:
- return 0;
+ return 0;
}
int
pl_inodelk (call_frame_t *frame, xlator_t *this,
- const char *volume, loc_t *loc, int32_t cmd, struct flock *flock)
+ const char *volume, loc_t *loc, int32_t cmd, struct flock *flock)
{
- pl_common_inodelk (frame, this, volume, loc->inode, cmd, flock);
+ pl_common_inodelk (frame, this, volume, loc->inode, cmd, flock);
- return 0;
+ return 0;
}
int
pl_finodelk (call_frame_t *frame, xlator_t *this,
- const char *volume, fd_t *fd, int32_t cmd, struct flock *flock)
+ const char *volume, fd_t *fd, int32_t cmd, struct flock *flock)
{
- pl_common_inodelk (frame, this, volume, fd->inode, cmd, flock);
+ pl_common_inodelk (frame, this, volume, fd->inode, cmd, flock);
- return 0;
+ return 0;
}
diff --git a/xlators/features/locks/src/locks.h b/xlators/features/locks/src/locks.h
index 9d030f15e13..cf6d595147a 100644
--- a/xlators/features/locks/src/locks.h
+++ b/xlators/features/locks/src/locks.h
@@ -1,20 +1,20 @@
/*
- Copyright (c) 2006, 2007, 2008 Gluster, Inc. <http://www.gluster.com>
- This file is part of GlusterFS.
-
- GlusterFS is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3 of the License,
- or (at your option) any later version.
-
- GlusterFS is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see
- <http://www.gnu.org/licenses/>.
+ Copyright (c) 2006, 2007, 2008 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
*/
#ifndef __POSIX_LOCKS_H__
@@ -33,24 +33,24 @@
struct __pl_fd;
struct __posix_lock {
- struct list_head list;
+ struct list_head list;
- short fl_type;
- off_t fl_start;
- off_t fl_end;
+ short fl_type;
+ off_t fl_start;
+ off_t fl_end;
- short blocked; /* waiting to acquire */
- struct flock user_flock; /* the flock supplied by the user */
- xlator_t *this; /* required for blocked locks */
- fd_t *fd;
+ short blocked; /* waiting to acquire */
+ struct flock user_flock; /* the flock supplied by the user */
+ xlator_t *this; /* required for blocked locks */
+ fd_t *fd;
- call_frame_t *frame;
+ call_frame_t *frame;
- /* These two together serve to uniquely identify each process
- across nodes */
+ /* These two together serve to uniquely identify each process
+ across nodes */
- transport_t *transport; /* to identify client node */
- pid_t client_pid; /* pid of client process */
+ transport_t *transport; /* to identify client node */
+ pid_t client_pid; /* pid of client process */
};
typedef struct __posix_lock posix_lock_t;
@@ -79,9 +79,9 @@ struct __pl_inode_lock {
typedef struct __pl_inode_lock pl_inode_lock_t;
struct __pl_rw_req_t {
- struct list_head list;
- call_stub_t *stub;
- posix_lock_t region;
+ struct list_head list;
+ call_stub_t *stub;
+ posix_lock_t region;
};
typedef struct __pl_rw_req_t pl_rw_req_t;
@@ -96,19 +96,19 @@ struct __pl_dom_list_t {
typedef struct __pl_dom_list_t pl_dom_list_t;
struct __entry_lock {
- struct list_head domain_list; /* list_head back to pl_dom_list_t */
- struct list_head blocked_locks; /* list_head back to blocked_entrylks */
+ struct list_head domain_list; /* list_head back to pl_dom_list_t */
+ struct list_head blocked_locks; /* list_head back to blocked_entrylks */
- call_frame_t *frame;
- xlator_t *this;
+ call_frame_t *frame;
+ xlator_t *this;
const char *volume;
- const char *basename;
- entrylk_type type;
+ const char *basename;
+ entrylk_type type;
- transport_t *trans;
- pid_t client_pid; /* pid of client process */
+ transport_t *trans;
+ pid_t client_pid; /* pid of client process */
};
typedef struct __entry_lock pl_entry_lock_t;
@@ -117,12 +117,12 @@ typedef struct __entry_lock pl_entry_lock_t;
with this file */
struct __pl_inode {
- pthread_mutex_t mutex;
+ pthread_mutex_t mutex;
- struct list_head dom_list; /* list of domains */
- struct list_head ext_list; /* list of fcntl locks */
- struct list_head rw_list; /* list of waiting r/w requests */
- int mandatory; /* if mandatory locking is enabled */
+ struct list_head dom_list; /* list of domains */
+ struct list_head ext_list; /* list of fcntl locks */
+ struct list_head rw_list; /* list of waiting r/w requests */
+ int mandatory; /* if mandatory locking is enabled */
inode_t *refkeeper; /* hold refs on an inode while locks are
held to prevent pruning */
@@ -131,13 +131,13 @@ typedef struct __pl_inode pl_inode_t;
struct __pl_fd {
- gf_boolean_t nonblocking; /* whether O_NONBLOCK has been set */
+ gf_boolean_t nonblocking; /* whether O_NONBLOCK has been set */
};
typedef struct __pl_fd pl_fd_t;
typedef struct {
- gf_boolean_t mandatory; /* if mandatory locking is enabled */
+ gf_boolean_t mandatory; /* if mandatory locking is enabled */
} posix_locks_private_t;
diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c
index 50958a2ed93..c7ae1baedbd 100644
--- a/xlators/features/locks/src/posix.c
+++ b/xlators/features/locks/src/posix.c
@@ -49,262 +49,262 @@ void do_blocked_rw (pl_inode_t *);
static int __rw_allowable (pl_inode_t *, posix_lock_t *, glusterfs_fop_t);
struct _truncate_ops {
- loc_t loc;
- fd_t *fd;
- off_t offset;
- enum {TRUNCATE, FTRUNCATE} op;
+ loc_t loc;
+ fd_t *fd;
+ off_t offset;
+ enum {TRUNCATE, FTRUNCATE} op;
};
int
pl_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct stat *prebuf,
+ int32_t op_ret, int32_t op_errno, struct stat *prebuf,
struct stat *postbuf)
{
- struct _truncate_ops *local = NULL;
+ struct _truncate_ops *local = NULL;
- local = frame->local;
+ local = frame->local;
- if (local->op == TRUNCATE)
- loc_wipe (&local->loc);
+ if (local->op == TRUNCATE)
+ loc_wipe (&local->loc);
- STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno,
+ STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno,
prebuf, postbuf);
- return 0;
+ return 0;
}
static int
truncate_allowed (pl_inode_t *pl_inode,
- transport_t *transport, pid_t client_pid,
- off_t offset)
+ transport_t *transport, pid_t client_pid,
+ off_t offset)
{
- posix_lock_t *l = NULL;
- posix_lock_t region = {.list = {0, }, };
- int ret = 1;
-
- region.fl_start = offset;
- region.fl_end = LLONG_MAX;
- region.transport = transport;
- region.client_pid = client_pid;
-
- pthread_mutex_lock (&pl_inode->mutex);
- {
- list_for_each_entry (l, &pl_inode->ext_list, list) {
- if (!l->blocked
- && locks_overlap (&region, l)
- && !same_owner (&region, l)) {
- ret = 0;
- break;
- }
- }
- }
- pthread_mutex_unlock (&pl_inode->mutex);
-
- return ret;
+ posix_lock_t *l = NULL;
+ posix_lock_t region = {.list = {0, }, };
+ int ret = 1;
+
+ region.fl_start = offset;
+ region.fl_end = LLONG_MAX;
+ region.transport = transport;
+ region.client_pid = client_pid;
+
+ pthread_mutex_lock (&pl_inode->mutex);
+ {
+ list_for_each_entry (l, &pl_inode->ext_list, list) {
+ if (!l->blocked
+ && locks_overlap (&region, l)
+ && !same_owner (&region, l)) {
+ ret = 0;
+ break;
+ }
+ }
+ }
+ pthread_mutex_unlock (&pl_inode->mutex);
+
+ return ret;
}
static int
truncate_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct stat *buf)
+ int32_t op_ret, int32_t op_errno, struct stat *buf)
{
- posix_locks_private_t *priv = NULL;
- struct _truncate_ops *local = NULL;
- inode_t *inode = NULL;
- pl_inode_t *pl_inode = NULL;
-
-
- priv = this->private;
- local = frame->local;
-
- if (op_ret != 0) {
- gf_log (this->name, GF_LOG_ERROR,
- "got error (errno=%d, stderror=%s) from child",
- op_errno, strerror (op_errno));
- goto unwind;
- }
-
- if (local->op == TRUNCATE)
- inode = local->loc.inode;
- else
- inode = local->fd->inode;
-
- pl_inode = pl_inode_get (this, inode);
- if (!pl_inode) {
- gf_log (this->name, GF_LOG_ERROR,
- "Out of memory.");
+ posix_locks_private_t *priv = NULL;
+ struct _truncate_ops *local = NULL;
+ inode_t *inode = NULL;
+ pl_inode_t *pl_inode = NULL;
+
+
+ priv = this->private;
+ local = frame->local;
+
+ if (op_ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "got error (errno=%d, stderror=%s) from child",
+ op_errno, strerror (op_errno));
+ goto unwind;
+ }
+
+ if (local->op == TRUNCATE)
+ inode = local->loc.inode;
+ else
+ inode = local->fd->inode;
+
+ pl_inode = pl_inode_get (this, inode);
+ if (!pl_inode) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Out of memory.");
op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
-
- if (priv->mandatory
- && pl_inode->mandatory
- && !truncate_allowed (pl_inode, frame->root->trans,
- frame->root->pid, local->offset)) {
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+
+ if (priv->mandatory
+ && pl_inode->mandatory
+ && !truncate_allowed (pl_inode, frame->root->trans,
+ frame->root->pid, local->offset)) {
op_ret = -1;
- op_errno = EAGAIN;
- goto unwind;
- }
-
- switch (local->op) {
- case TRUNCATE:
- STACK_WIND (frame, pl_truncate_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->truncate,
- &local->loc, local->offset);
- break;
- case FTRUNCATE:
- STACK_WIND (frame, pl_truncate_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->ftruncate,
- local->fd, local->offset);
- break;
- }
-
- return 0;
+ op_errno = EAGAIN;
+ goto unwind;
+ }
+
+ switch (local->op) {
+ case TRUNCATE:
+ STACK_WIND (frame, pl_truncate_cbk, FIRST_CHILD (this),
+ FIRST_CHILD (this)->fops->truncate,
+ &local->loc, local->offset);
+ break;
+ case FTRUNCATE:
+ STACK_WIND (frame, pl_truncate_cbk, FIRST_CHILD (this),
+ FIRST_CHILD (this)->fops->ftruncate,
+ local->fd, local->offset);
+ break;
+ }
+
+ return 0;
unwind:
- if (local->op == TRUNCATE)
- loc_wipe (&local->loc);
+ if (local->op == TRUNCATE)
+ loc_wipe (&local->loc);
- STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, buf, NULL);
- return 0;
+ STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, buf, NULL);
+ return 0;
}
int
pl_truncate (call_frame_t *frame, xlator_t *this,
- loc_t *loc, off_t offset)
+ loc_t *loc, off_t offset)
{
- struct _truncate_ops *local = NULL;
+ struct _truncate_ops *local = NULL;
- local = CALLOC (1, sizeof (struct _truncate_ops));
- if (!local) {
- gf_log (this->name, GF_LOG_ERROR,
- "Out of memory.");
- goto unwind;
- }
+ local = CALLOC (1, sizeof (struct _truncate_ops));
+ if (!local) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Out of memory.");
+ goto unwind;
+ }
- local->op = TRUNCATE;
- local->offset = offset;
- loc_copy (&local->loc, loc);
+ local->op = TRUNCATE;
+ local->offset = offset;
+ loc_copy (&local->loc, loc);
- frame->local = local;
+ frame->local = local;
- STACK_WIND (frame, truncate_stat_cbk, FIRST_CHILD (this),
- FIRST_CHILD (this)->fops->stat, loc);
+ STACK_WIND (frame, truncate_stat_cbk, FIRST_CHILD (this),
+ FIRST_CHILD (this)->fops->stat, loc);
- return 0;
+ return 0;
unwind:
- STACK_UNWIND_STRICT (truncate, frame, -1, ENOMEM, NULL, NULL);
+ STACK_UNWIND_STRICT (truncate, frame, -1, ENOMEM, NULL, NULL);
- return 0;
+ return 0;
}
int
pl_ftruncate (call_frame_t *frame, xlator_t *this,
- fd_t *fd, off_t offset)
+ fd_t *fd, off_t offset)
{
- struct _truncate_ops *local = NULL;
+ struct _truncate_ops *local = NULL;
- local = CALLOC (1, sizeof (struct _truncate_ops));
- if (!local) {
- gf_log (this->name, GF_LOG_ERROR,
- "Out of memory.");
- goto unwind;
- }
+ local = CALLOC (1, sizeof (struct _truncate_ops));
+ if (!local) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Out of memory.");
+ goto unwind;
+ }
- local->op = FTRUNCATE;
- local->offset = offset;
- local->fd = fd;
+ local->op = FTRUNCATE;
+ local->offset = offset;
+ local->fd = fd;
- frame->local = local;
+ frame->local = local;
- STACK_WIND (frame, truncate_stat_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->fstat, fd);
- return 0;
+ STACK_WIND (frame, truncate_stat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fstat, fd);
+ return 0;
unwind:
- STACK_UNWIND_STRICT (ftruncate, frame, -1, ENOMEM, NULL, NULL);
+ STACK_UNWIND_STRICT (ftruncate, frame, -1, ENOMEM, NULL, NULL);
- return 0;
+ return 0;
}
static void
__delete_locks_of_owner (pl_inode_t *pl_inode,
- transport_t *transport, pid_t pid)
+ transport_t *transport, pid_t pid)
{
- posix_lock_t *tmp = NULL;
- posix_lock_t *l = NULL;
+ posix_lock_t *tmp = NULL;
+ posix_lock_t *l = NULL;
- /* TODO: what if it is a blocked lock with pending l->frame */
+ /* TODO: what if it is a blocked lock with pending l->frame */
- list_for_each_entry_safe (l, tmp, &pl_inode->ext_list, list) {
- if ((l->transport == transport)
- && (l->client_pid == pid)) {
- __delete_lock (pl_inode, l);
- __destroy_lock (l);
- }
- }
+ list_for_each_entry_safe (l, tmp, &pl_inode->ext_list, list) {
+ if ((l->transport == transport)
+ && (l->client_pid == pid)) {
+ __delete_lock (pl_inode, l);
+ __destroy_lock (l);
+ }
+ }
- return;
+ return;
}
int
pl_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno)
+ int32_t op_ret, int32_t op_errno)
{
- STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno);
+ STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno);
- return 0;
+ return 0;
}
int
pl_flush (call_frame_t *frame, xlator_t *this,
- fd_t *fd)
+ fd_t *fd)
{
- posix_locks_private_t *priv = NULL;
- pl_inode_t *pl_inode = NULL;
+ posix_locks_private_t *priv = NULL;
+ pl_inode_t *pl_inode = NULL;
- priv = this->private;
+ priv = this->private;
- pl_inode = pl_inode_get (this, fd->inode);
+ pl_inode = pl_inode_get (this, fd->inode);
- if (!pl_inode) {
- gf_log (this->name, GF_LOG_DEBUG, "Could not get inode.");
- STACK_UNWIND_STRICT (flush, frame, -1, EBADFD);
- return 0;
- }
+ if (!pl_inode) {
+ gf_log (this->name, GF_LOG_DEBUG, "Could not get inode.");
+ STACK_UNWIND_STRICT (flush, frame, -1, EBADFD);
+ return 0;
+ }
- pthread_mutex_lock (&pl_inode->mutex);
- {
- __delete_locks_of_owner (pl_inode, frame->root->trans,
- frame->root->pid);
- }
- pthread_mutex_unlock (&pl_inode->mutex);
+ pthread_mutex_lock (&pl_inode->mutex);
+ {
+ __delete_locks_of_owner (pl_inode, frame->root->trans,
+ frame->root->pid);
+ }
+ pthread_mutex_unlock (&pl_inode->mutex);
- grant_blocked_locks (this, pl_inode);
+ grant_blocked_locks (this, pl_inode);
- do_blocked_rw (pl_inode);
+ do_blocked_rw (pl_inode);
- STACK_WIND (frame, pl_flush_cbk, FIRST_CHILD(this),
- FIRST_CHILD(this)->fops->flush, fd);
- return 0;
+ STACK_WIND (frame, pl_flush_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->flush, fd);
+ return 0;
}
int
pl_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, fd_t *fd)
+ int32_t op_ret, int32_t op_errno, fd_t *fd)
{
- STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd);
+ STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd);
- return 0;
+ return 0;
}
@@ -312,190 +312,190 @@ int
pl_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
fd_t *fd, int32_t wbflags)
{
- /* why isn't O_TRUNC being handled ? */
- STACK_WIND (frame, pl_open_cbk,
- FIRST_CHILD(this), FIRST_CHILD(this)->fops->open,
- loc, flags & ~O_TRUNC, fd, wbflags);
+ /* why isn't O_TRUNC being handled ? */
+ STACK_WIND (frame, pl_open_cbk,
+ FIRST_CHILD(this), FIRST_CHILD(this)->fops->open,
+ loc, flags & ~O_TRUNC, fd, wbflags);
- return 0;
+ return 0;
}
int
pl_create_cbk (call_frame_t *frame, void *cookie,
- xlator_t *this, int32_t op_ret, int32_t op_errno,
- fd_t *fd, inode_t *inode, struct stat *buf,
+ xlator_t *this, int32_t op_ret, int32_t op_errno,
+ fd_t *fd, inode_t *inode, struct stat *buf,
struct stat *preparent, struct stat *postparent)
{
- STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, inode, buf,
+ STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, inode, buf,
preparent, postparent);
- return 0;
+ return 0;
}
int
pl_create (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int32_t flags, mode_t mode, fd_t *fd)
+ loc_t *loc, int32_t flags, mode_t mode, fd_t *fd)
{
- STACK_WIND (frame, pl_create_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->create,
- loc, flags, mode, fd);
- return 0;
+ STACK_WIND (frame, pl_create_cbk,
+ FIRST_CHILD (this), FIRST_CHILD (this)->fops->create,
+ loc, flags, mode, fd);
+ return 0;
}
int
pl_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno,
- struct iovec *vector, int32_t count, struct stat *stbuf,
+ int32_t op_ret, int32_t op_errno,
+ struct iovec *vector, int32_t count, struct stat *stbuf,
struct iobref *iobref)
{
- STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno,
+ STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno,
vector, count, stbuf, iobref);
- return 0;
+ return 0;
}
int
pl_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, struct stat *prebuf,
+ int32_t op_ret, int32_t op_errno, struct stat *prebuf,
struct stat *postbuf)
{
- STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf);
+ STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf);
- return 0;
+ return 0;
}
void
do_blocked_rw (pl_inode_t *pl_inode)
{
- struct list_head wind_list;
- pl_rw_req_t *rw = NULL;
- pl_rw_req_t *tmp = NULL;
-
- INIT_LIST_HEAD (&wind_list);
-
- pthread_mutex_lock (&pl_inode->mutex);
- {
- list_for_each_entry_safe (rw, tmp, &pl_inode->rw_list, list) {
- if (__rw_allowable (pl_inode, &rw->region,
- rw->stub->fop)) {
- list_del_init (&rw->list);
- list_add_tail (&rw->list, &wind_list);
- }
- }
- }
- pthread_mutex_unlock (&pl_inode->mutex);
-
- list_for_each_entry_safe (rw, tmp, &wind_list, list) {
- list_del_init (&rw->list);
- call_resume (rw->stub);
- free (rw);
- }
-
- return;
+ struct list_head wind_list;
+ pl_rw_req_t *rw = NULL;
+ pl_rw_req_t *tmp = NULL;
+
+ INIT_LIST_HEAD (&wind_list);
+
+ pthread_mutex_lock (&pl_inode->mutex);
+ {
+ list_for_each_entry_safe (rw, tmp, &pl_inode->rw_list, list) {
+ if (__rw_allowable (pl_inode, &rw->region,
+ rw->stub->fop)) {
+ list_del_init (&rw->list);
+ list_add_tail (&rw->list, &wind_list);
+ }
+ }
+ }
+ pthread_mutex_unlock (&pl_inode->mutex);
+
+ list_for_each_entry_safe (rw, tmp, &wind_list, list) {
+ list_del_init (&rw->list);
+ call_resume (rw->stub);
+ free (rw);
+ }
+
+ return;
}
static int
__rw_allowable (pl_inode_t *pl_inode, posix_lock_t *region,
- glusterfs_fop_t op)
+ glusterfs_fop_t op)
{
- posix_lock_t *l = NULL;
- int ret = 1;
-
- list_for_each_entry (l, &pl_inode->ext_list, list) {
- if (locks_overlap (l, region) && !same_owner (l, region)) {
- if ((op == GF_FOP_READ) && (l->fl_type != F_WRLCK))
- continue;
- ret = 0;
- break;
- }
- }
-
- return ret;
+ posix_lock_t *l = NULL;
+ int ret = 1;
+
+ list_for_each_entry (l, &pl_inode->ext_list, list) {
+ if (locks_overlap (l, region) && !same_owner (l, region)) {
+ if ((op == GF_FOP_READ) && (l->fl_type != F_WRLCK))
+ continue;
+ ret = 0;
+ break;
+ }
+ }
+
+ return ret;
}
int
pl_readv_cont (call_frame_t *frame, xlator_t *this,
- fd_t *fd, size_t size, off_t offset)
+ fd_t *fd, size_t size, off_t offset)
{
- STACK_WIND (frame, pl_readv_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->readv,
- fd, size, offset);
+ STACK_WIND (frame, pl_readv_cbk,
+ FIRST_CHILD (this), FIRST_CHILD (this)->fops->readv,
+ fd, size, offset);
- return 0;
+ return 0;
}
int
pl_readv (call_frame_t *frame, xlator_t *this,
- fd_t *fd, size_t size, off_t offset)
+ fd_t *fd, size_t size, off_t offset)
{
- posix_locks_private_t *priv = NULL;
- pl_inode_t *pl_inode = NULL;
- pl_rw_req_t *rw = NULL;
- posix_lock_t region = {.list = {0, }, };
- int op_ret = 0;
- int op_errno = 0;
- char wind_needed = 1;
-
-
- priv = this->private;
- pl_inode = pl_inode_get (this, fd->inode);
-
- if (priv->mandatory && pl_inode->mandatory) {
- region.fl_start = offset;
- region.fl_end = offset + size - 1;
- region.transport = frame->root->trans;
- region.client_pid = frame->root->pid;
+ posix_locks_private_t *priv = NULL;
+ pl_inode_t *pl_inode = NULL;
+ pl_rw_req_t *rw = NULL;
+ posix_lock_t region = {.list = {0, }, };
+ int op_ret = 0;
+ int op_errno = 0;
+ char wind_needed = 1;
+
+
+ priv = this->private;
+ pl_inode = pl_inode_get (this, fd->inode);
+
+ if (priv->mandatory && pl_inode->mandatory) {
+ region.fl_start = offset;
+ region.fl_end = offset + size - 1;
+ region.transport = frame->root->trans;
+ region.client_pid = frame->root->pid;
- pthread_mutex_lock (&pl_inode->mutex);
- {
- wind_needed = __rw_allowable (pl_inode, &region,
+ pthread_mutex_lock (&pl_inode->mutex);
+ {
+ wind_needed = __rw_allowable (pl_inode, &region,
GF_FOP_READ);
- if (wind_needed) {
- goto unlock;
+ if (wind_needed) {
+ goto unlock;
+ }
+
+ if (fd->flags & O_NONBLOCK) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "returning EAGAIN as fd is O_NONBLOCK");
+ op_errno = EAGAIN;
+ op_ret = -1;
+ goto unlock;
+ }
+
+ rw = CALLOC (1, sizeof (*rw));
+ if (!rw) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Out of memory.");
+ op_errno = ENOMEM;
+ op_ret = -1;
+ goto unlock;
}
- if (fd->flags & O_NONBLOCK) {
- gf_log (this->name, GF_LOG_TRACE,
- "returning EAGAIN as fd is O_NONBLOCK");
- op_errno = EAGAIN;
- op_ret = -1;
- goto unlock;
- }
-
- rw = CALLOC (1, sizeof (*rw));
- if (!rw) {
- gf_log (this->name, GF_LOG_ERROR,
- "Out of memory.");
- op_errno = ENOMEM;
- op_ret = -1;
- goto unlock;
- }
-
- rw->stub = fop_readv_stub (frame, pl_readv_cont,
- fd, size, offset);
- if (!rw->stub) {
- gf_log (this->name, GF_LOG_ERROR,
- "Out of memory.");
- op_errno = ENOMEM;
- op_ret = -1;
- free (rw);
- goto unlock;
- }
-
- rw->region = region;
-
- list_add_tail (&rw->list, &pl_inode->rw_list);
- }
- unlock:
- pthread_mutex_unlock (&pl_inode->mutex);
- }
+ rw->stub = fop_readv_stub (frame, pl_readv_cont,
+ fd, size, offset);
+ if (!rw->stub) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Out of memory.");
+ op_errno = ENOMEM;
+ op_ret = -1;
+ free (rw);
+ goto unlock;
+ }
+
+ rw->region = region;
+
+ list_add_tail (&rw->list, &pl_inode->rw_list);
+ }
+ unlock:
+ pthread_mutex_unlock (&pl_inode->mutex);
+ }
if (wind_needed) {
@@ -504,94 +504,94 @@ pl_readv (call_frame_t *frame, xlator_t *this,
fd, size, offset);
}
- if (op_ret == -1)
- STACK_UNWIND_STRICT (readv, frame, -1, op_errno,
+ if (op_ret == -1)
+ STACK_UNWIND_STRICT (readv, frame, -1, op_errno,
NULL, 0, NULL, NULL);
- return 0;
+ return 0;
}
int
pl_writev_cont (call_frame_t *frame, xlator_t *this, fd_t *fd,
- struct iovec *vector, int count, off_t offset,
+ struct iovec *vector, int count, off_t offset,
struct iobref *iobref)
{
- STACK_WIND (frame, pl_writev_cbk,
- FIRST_CHILD (this), FIRST_CHILD (this)->fops->writev,
- fd, vector, count, offset, iobref);
+ STACK_WIND (frame, pl_writev_cbk,
+ FIRST_CHILD (this), FIRST_CHILD (this)->fops->writev,
+ fd, vector, count, offset, iobref);
- return 0;
+ return 0;
}
int
pl_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
- struct iovec *vector, int32_t count, off_t offset,
+ struct iovec *vector, int32_t count, off_t offset,
struct iobref *iobref)
{
- posix_locks_private_t *priv = NULL;
- pl_inode_t *pl_inode = NULL;
- pl_rw_req_t *rw = NULL;
- posix_lock_t region = {.list = {0, }, };
- int op_ret = 0;
- int op_errno = 0;
- char wind_needed = 1;
-
-
- priv = this->private;
- pl_inode = pl_inode_get (this, fd->inode);
-
- if (priv->mandatory && pl_inode->mandatory) {
- region.fl_start = offset;
- region.fl_end = offset + iov_length (vector, count) - 1;
- region.transport = frame->root->trans;
- region.client_pid = frame->root->pid;
+ posix_locks_private_t *priv = NULL;
+ pl_inode_t *pl_inode = NULL;
+ pl_rw_req_t *rw = NULL;
+ posix_lock_t region = {.list = {0, }, };
+ int op_ret = 0;
+ int op_errno = 0;
+ char wind_needed = 1;
+
+
+ priv = this->private;
+ pl_inode = pl_inode_get (this, fd->inode);
+
+ if (priv->mandatory && pl_inode->mandatory) {
+ region.fl_start = offset;
+ region.fl_end = offset + iov_length (vector, count) - 1;
+ region.transport = frame->root->trans;
+ region.client_pid = frame->root->pid;
- pthread_mutex_lock (&pl_inode->mutex);
- {
- wind_needed = __rw_allowable (pl_inode, &region,
+ pthread_mutex_lock (&pl_inode->mutex);
+ {
+ wind_needed = __rw_allowable (pl_inode, &region,
GF_FOP_WRITE);
- if (wind_needed)
- goto unlock;
+ if (wind_needed)
+ goto unlock;
- if (fd->flags & O_NONBLOCK) {
- gf_log (this->name, GF_LOG_TRACE,
- "returning EAGAIN because fd is "
+ if (fd->flags & O_NONBLOCK) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "returning EAGAIN because fd is "
"O_NONBLOCK");
- op_errno = EAGAIN;
- op_ret = -1;
- goto unlock;
- }
-
- rw = CALLOC (1, sizeof (*rw));
- if (!rw) {
- gf_log (this->name, GF_LOG_ERROR,
- "Out of memory.");
- op_errno = ENOMEM;
- op_ret = -1;
- goto unlock;
- }
-
- rw->stub = fop_writev_stub (frame, pl_writev_cont,
- fd, vector, count, offset,
+ op_errno = EAGAIN;
+ op_ret = -1;
+ goto unlock;
+ }
+
+ rw = CALLOC (1, sizeof (*rw));
+ if (!rw) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Out of memory.");
+ op_errno = ENOMEM;
+ op_ret = -1;
+ goto unlock;
+ }
+
+ rw->stub = fop_writev_stub (frame, pl_writev_cont,
+ fd, vector, count, offset,
iobref);
- if (!rw->stub) {
- gf_log (this->name, GF_LOG_ERROR,
- "Out of memory.");
- op_errno = ENOMEM;
- op_ret = -1;
- free (rw);
- goto unlock;
- }
+ if (!rw->stub) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Out of memory.");
+ op_errno = ENOMEM;
+ op_ret = -1;
+ free (rw);
+ goto unlock;
+ }
- rw->region = region;
+ rw->region = region;
- list_add_tail (&rw->list, &pl_inode->rw_list);
- }
- unlock:
- pthread_mutex_unlock (&pl_inode->mutex);
- }
+ list_add_tail (&rw->list, &pl_inode->rw_list);
+ }
+ unlock:
+ pthread_mutex_unlock (&pl_inode->mutex);
+ }
if (wind_needed)
@@ -599,10 +599,10 @@ pl_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
FIRST_CHILD (this), FIRST_CHILD (this)->fops->writev,
fd, vector, count, offset, iobref);
- if (op_ret == -1)
- STACK_UNWIND_STRICT (writev, frame, -1, op_errno, NULL, NULL);
+ if (op_ret == -1)
+ STACK_UNWIND_STRICT (writev, frame, -1, op_errno, NULL, NULL);
- return 0;
+ return 0;
}
@@ -610,95 +610,95 @@ int
pl_lk (call_frame_t *frame, xlator_t *this,
fd_t *fd, int32_t cmd, struct flock *flock)
{
- transport_t *transport = NULL;
- pid_t client_pid = 0;
- posix_locks_private_t *priv = NULL;
- pl_inode_t *pl_inode = NULL;
- int op_ret = 0;
- int op_errno = 0;
- int can_block = 0;
- posix_lock_t *reqlock = NULL;
- posix_lock_t *conf = NULL;
- int ret = 0;
-
- transport = frame->root->trans;
- client_pid = frame->root->pid;
- priv = this->private;
-
- pl_inode = pl_inode_get (this, fd->inode);
- if (!pl_inode) {
- gf_log (this->name, GF_LOG_ERROR,
- "Out of memory.");
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
-
- reqlock = new_posix_lock (flock, transport, client_pid);
- if (!reqlock) {
- gf_log (this->name, GF_LOG_ERROR,
- "Out of memory.");
- op_ret = -1;
- op_errno = ENOMEM;
- goto unwind;
- }
-
- switch (cmd) {
+ transport_t *transport = NULL;
+ pid_t client_pid = 0;
+ posix_locks_private_t *priv = NULL;
+ pl_inode_t *pl_inode = NULL;
+ int op_ret = 0;
+ int op_errno = 0;
+ int can_block = 0;
+ posix_lock_t *reqlock = NULL;
+ posix_lock_t *conf = NULL;
+ int ret = 0;
+
+ transport = frame->root->trans;
+ client_pid = frame->root->pid;
+ priv = this->private;
+
+ pl_inode = pl_inode_get (this, fd->inode);
+ if (!pl_inode) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Out of memory.");
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+
+ reqlock = new_posix_lock (flock, transport, client_pid);
+ if (!reqlock) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Out of memory.");
+ op_ret = -1;
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+
+ switch (cmd) {
#if F_GETLK != F_GETLK64
- case F_GETLK64:
+ case F_GETLK64:
#endif
- case F_GETLK:
- conf = pl_getlk (pl_inode, reqlock);
- posix_lock_to_flock (conf, flock);
- __destroy_lock (reqlock);
+ case F_GETLK:
+ conf = pl_getlk (pl_inode, reqlock);
+ posix_lock_to_flock (conf, flock);
+ __destroy_lock (reqlock);
- break;
+ break;
#if F_SETLKW != F_SETLKW64
- case F_SETLKW64:
+ case F_SETLKW64:
#endif
- case F_SETLKW:
- can_block = 1;
- reqlock->frame = frame;
- reqlock->this = this;
- reqlock->fd = fd;
+ case F_SETLKW:
+ can_block = 1;
+ reqlock->frame = frame;
+ reqlock->this = this;
+ reqlock->fd = fd;
- /* fall through */
+ /* fall through */
#if F_SETLK != F_SETLK64
- case F_SETLK64:
+ case F_SETLK64:
#endif
- case F_SETLK:
- memcpy (&reqlock->user_flock, flock, sizeof (struct flock));
- ret = pl_setlk (this, pl_inode, reqlock,
- can_block);
-
- if (ret == -1) {
- if (can_block)
- goto out;
-
- gf_log (this->name, GF_LOG_DEBUG, "returning EAGAIN");
- op_ret = -1;
- op_errno = EAGAIN;
- __destroy_lock (reqlock);
- }
- }
+ case F_SETLK:
+ memcpy (&reqlock->user_flock, flock, sizeof (struct flock));
+ ret = pl_setlk (this, pl_inode, reqlock,
+ can_block);
+
+ if (ret == -1) {
+ if (can_block)
+ goto out;
+
+ gf_log (this->name, GF_LOG_DEBUG, "returning EAGAIN");
+ op_ret = -1;
+ op_errno = EAGAIN;
+ __destroy_lock (reqlock);
+ }
+ }
unwind:
pl_update_refkeeper (this, fd->inode);
- STACK_UNWIND_STRICT (lk, frame, op_ret, op_errno, flock);
+ STACK_UNWIND_STRICT (lk, frame, op_ret, op_errno, flock);
out:
- return 0;
+ return 0;
}
/* TODO: this function just logs, no action required?? */
int
pl_forget (xlator_t *this,
- inode_t *inode)
+ inode_t *inode)
{
- pl_inode_t *pl_inode = NULL;
+ pl_inode_t *pl_inode = NULL;
posix_lock_t *ext_tmp = NULL;
posix_lock_t *ext_l = NULL;
@@ -715,11 +715,11 @@ pl_forget (xlator_t *this,
pl_dom_list_t *dom = NULL;
pl_dom_list_t *dom_tmp = NULL;
- pl_inode = pl_inode_get (this, inode);
+ pl_inode = pl_inode_get (this, inode);
- if (!list_empty (&pl_inode->rw_list)) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Pending R/W requests found, releasing.");
+ if (!list_empty (&pl_inode->rw_list)) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "Pending R/W requests found, releasing.");
list_for_each_entry_safe (rw_req, rw_tmp, &pl_inode->rw_list,
list) {
@@ -727,11 +727,11 @@ pl_forget (xlator_t *this,
list_del (&rw_req->list);
FREE (rw_req);
}
- }
+ }
- if (!list_empty (&pl_inode->ext_list)) {
- gf_log (this->name, GF_LOG_DEBUG,
- "Pending fcntl locks found, releasing.");
+ if (!list_empty (&pl_inode->ext_list)) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "Pending fcntl locks found, releasing.");
list_for_each_entry_safe (ext_l, ext_tmp, &pl_inode->ext_list,
list) {
@@ -739,7 +739,7 @@ pl_forget (xlator_t *this,
__delete_lock (pl_inode, ext_l);
__destroy_lock (ext_l);
}
- }
+ }
list_for_each_entry_safe (dom, dom_tmp, &pl_inode->dom_list, inode_list) {
@@ -778,7 +778,7 @@ pl_forget (xlator_t *this,
FREE (pl_inode);
- return 0;
+ return 0;
}
@@ -794,9 +794,9 @@ pl_dump_inode_priv (xlator_t *this, inode_t *inode)
if (!inode)
return -1;
- ret = inode_ctx_get (inode, this, &tmp_pl_inode);
+ ret = inode_ctx_get (inode, this, &tmp_pl_inode);
- if (ret != 0)
+ if (ret != 0)
return ret;
pl_inode = (pl_inode_t *)(long)tmp_pl_inode;
@@ -829,7 +829,7 @@ pl_dump_inode (xlator_t *this)
"xlator.features.locks.inode_table");
}
- return 0;
+ return 0;
}
@@ -837,93 +837,93 @@ pl_dump_inode (xlator_t *this)
int
init (xlator_t *this)
{
- posix_locks_private_t *priv = NULL;
- xlator_list_t *trav = NULL;
- data_t *mandatory = NULL;
-
- if (!this->children || this->children->next) {
- gf_log (this->name, GF_LOG_CRITICAL,
- "FATAL: posix-locks should have exactly one child");
- return -1;
- }
-
- if (!this->parents) {
- gf_log (this->name, GF_LOG_WARNING,
- "Volume is dangling. Please check the volume file.");
- }
-
- trav = this->children;
- while (trav->xlator->children)
- trav = trav->xlator->children;
-
- if (strncmp ("storage/", trav->xlator->type, 8)) {
- gf_log (this->name, GF_LOG_CRITICAL,
- "'locks' translator is not loaded over a storage "
+ posix_locks_private_t *priv = NULL;
+ xlator_list_t *trav = NULL;
+ data_t *mandatory = NULL;
+
+ if (!this->children || this->children->next) {
+ gf_log (this->name, GF_LOG_CRITICAL,
+ "FATAL: posix-locks should have exactly one child");
+ return -1;
+ }
+
+ if (!this->parents) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "Volume is dangling. Please check the volume file.");
+ }
+
+ trav = this->children;
+ while (trav->xlator->children)
+ trav = trav->xlator->children;
+
+ if (strncmp ("storage/", trav->xlator->type, 8)) {
+ gf_log (this->name, GF_LOG_CRITICAL,
+ "'locks' translator is not loaded over a storage "
"translator");
- return -1;
- }
+ return -1;
+ }
- priv = CALLOC (1, sizeof (*priv));
+ priv = CALLOC (1, sizeof (*priv));
- mandatory = dict_get (this->options, "mandatory-locks");
- if (mandatory) {
- if (gf_string2boolean (mandatory->data,
- &priv->mandatory) == -1) {
- gf_log (this->name, GF_LOG_ERROR,
- "'mandatory-locks' takes on only boolean "
+ mandatory = dict_get (this->options, "mandatory-locks");
+ if (mandatory) {
+ if (gf_string2boolean (mandatory->data,
+ &priv->mandatory) == -1) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "'mandatory-locks' takes on only boolean "
"values.");
- return -1;
- }
- }
+ return -1;
+ }
+ }
- this->private = priv;
- return 0;
+ this->private = priv;
+ return 0;
}
int
fini (xlator_t *this)
{
- posix_locks_private_t *priv = NULL;
+ posix_locks_private_t *priv = NULL;
- priv = this->private;
- free (priv);
+ priv = this->private;
+ free (priv);
- return 0;
+ return 0;
}
int
pl_inodelk (call_frame_t *frame, xlator_t *this,
- const char *volume, loc_t *loc, int32_t cmd, struct flock *flock);
+ const char *volume, loc_t *loc, int32_t cmd, struct flock *flock);
int
pl_finodelk (call_frame_t *frame, xlator_t *this,
- const char *volume, fd_t *fd, int32_t cmd, struct flock *flock);
+ const char *volume, fd_t *fd, int32_t cmd, struct flock *flock);
int
pl_entrylk (call_frame_t *frame, xlator_t *this,
- const char *volume, loc_t *loc, const char *basename,
- entrylk_cmd cmd, entrylk_type type);
+ const char *volume, loc_t *loc, const char *basename,
+ entrylk_cmd cmd, entrylk_type type);
int
pl_fentrylk (call_frame_t *frame, xlator_t *this,
- const char *volume, fd_t *fd, const char *basename,
- entrylk_cmd cmd, entrylk_type type);
+ const char *volume, fd_t *fd, const char *basename,
+ entrylk_cmd cmd, entrylk_type type);
struct xlator_fops fops = {
- .create = pl_create,
- .truncate = pl_truncate,
- .ftruncate = pl_ftruncate,
- .open = pl_open,
- .readv = pl_readv,
- .writev = pl_writev,
- .lk = pl_lk,
- .inodelk = pl_inodelk,
- .finodelk = pl_finodelk,
- .entrylk = pl_entrylk,
- .fentrylk = pl_fentrylk,
- .flush = pl_flush,
+ .create = pl_create,
+ .truncate = pl_truncate,
+ .ftruncate = pl_ftruncate,
+ .open = pl_open,
+ .readv = pl_readv,
+ .writev = pl_writev,
+ .lk = pl_lk,
+ .inodelk = pl_inodelk,
+ .finodelk = pl_finodelk,
+ .entrylk = pl_entrylk,
+ .fentrylk = pl_fentrylk,
+ .flush = pl_flush,
};
@@ -935,13 +935,13 @@ struct xlator_dumpops dumpops = {
};
struct xlator_cbks cbks = {
- .forget = pl_forget,
+ .forget = pl_forget,
};
struct volume_options options[] = {
- { .key = { "mandatory-locks", "mandatory" },
- .type = GF_OPTION_TYPE_BOOL
- },
- { .key = {NULL} },
+ { .key = { "mandatory-locks", "mandatory" },
+ .type = GF_OPTION_TYPE_BOOL
+ },
+ { .key = {NULL} },
};