From a12cadc1377ef51ad52defd1da91bf8f599e5786 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Tue, 18 Dec 2018 14:38:22 +0530 Subject: cluster/afr: Refactor internal locking code to allow multiple inodelks For implementing copy_file_range fop, AFR needs to perform two inodelks in the same transaction. This patch brings in the necessary structure to make it easier to do so. Entry-locks in AFR were already taking multiple entry-locks on different inodes with the respective basenames. This patch extends the logic in inodelks to use the same lockee_t structure. This lead to removal of quite a lot of duplicate code present in afr-lk-common.c as both the locks are doing same things except 'winding' part. updates: #536 Change-Id: Ibfce7e3f260bb27b18645152ec680c33866fe0ae Signed-off-by: Pranith Kumar K --- xlators/cluster/afr/src/afr-dir-write.c | 143 -------------------------------- 1 file changed, 143 deletions(-) (limited to 'xlators/cluster/afr/src/afr-dir-write.c') diff --git a/xlators/cluster/afr/src/afr-dir-write.c b/xlators/cluster/afr/src/afr-dir-write.c index 486b06b162f..f2c8ef450e1 100644 --- a/xlators/cluster/afr/src/afr-dir-write.c +++ b/xlators/cluster/afr/src/afr-dir-write.c @@ -425,15 +425,11 @@ int afr_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata) { - afr_private_t *priv = NULL; afr_local_t *local = NULL; - afr_internal_lock_t *int_lock = NULL; call_frame_t *transaction_frame = NULL; int ret = -1; int op_errno = ENOMEM; - priv = this->private; - transaction_frame = copy_frame(frame); if (!transaction_frame) goto out; @@ -475,16 +471,6 @@ afr_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, local->transaction.main_frame = frame; local->transaction.basename = AFR_BASENAME(loc->path); - int_lock = &local->internal_lock; - - int_lock->lockee_count = 0; - ret = afr_init_entry_lockee(&int_lock->lockee[0], local, - &local->transaction.parent_loc, - local->transaction.basename, priv->child_count); - if (ret) - goto out; - - int_lock->lockee_count++; ret = afr_transaction(transaction_frame, this, AFR_ENTRY_TRANSACTION); if (ret < 0) { op_errno = -ret; @@ -555,15 +541,11 @@ int afr_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, dev_t dev, mode_t umask, dict_t *xdata) { - afr_private_t *priv = NULL; afr_local_t *local = NULL; - afr_internal_lock_t *int_lock = NULL; call_frame_t *transaction_frame = NULL; int ret = -1; int op_errno = ENOMEM; - priv = this->private; - transaction_frame = copy_frame(frame); if (!transaction_frame) goto out; @@ -598,16 +580,6 @@ afr_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, local->transaction.main_frame = frame; local->transaction.basename = AFR_BASENAME(loc->path); - int_lock = &local->internal_lock; - - int_lock->lockee_count = 0; - ret = afr_init_entry_lockee(&int_lock->lockee[0], local, - &local->transaction.parent_loc, - local->transaction.basename, priv->child_count); - if (ret) - goto out; - - int_lock->lockee_count++; ret = afr_transaction(transaction_frame, this, AFR_ENTRY_TRANSACTION); if (ret < 0) { op_errno = -ret; @@ -676,15 +648,11 @@ int afr_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, mode_t umask, dict_t *xdata) { - afr_private_t *priv = NULL; afr_local_t *local = NULL; - afr_internal_lock_t *int_lock = NULL; call_frame_t *transaction_frame = NULL; int ret = -1; int op_errno = ENOMEM; - priv = this->private; - transaction_frame = copy_frame(frame); if (!transaction_frame) goto out; @@ -726,16 +694,6 @@ afr_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, local->transaction.main_frame = frame; local->transaction.basename = AFR_BASENAME(loc->path); - int_lock = &local->internal_lock; - - int_lock->lockee_count = 0; - ret = afr_init_entry_lockee(&int_lock->lockee[0], local, - &local->transaction.parent_loc, - local->transaction.basename, priv->child_count); - if (ret) - goto out; - - int_lock->lockee_count++; ret = afr_transaction(transaction_frame, this, AFR_ENTRY_TRANSACTION); if (ret < 0) { op_errno = -ret; @@ -804,15 +762,11 @@ int afr_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, dict_t *xdata) { - afr_private_t *priv = NULL; afr_local_t *local = NULL; - afr_internal_lock_t *int_lock = NULL; call_frame_t *transaction_frame = NULL; int ret = -1; int op_errno = ENOMEM; - priv = this->private; - transaction_frame = copy_frame(frame); if (!transaction_frame) goto out; @@ -847,16 +801,6 @@ afr_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, local->transaction.main_frame = frame; local->transaction.basename = AFR_BASENAME(newloc->path); - int_lock = &local->internal_lock; - - int_lock->lockee_count = 0; - ret = afr_init_entry_lockee(&int_lock->lockee[0], local, - &local->transaction.parent_loc, - local->transaction.basename, priv->child_count); - if (ret) - goto out; - - int_lock->lockee_count++; ret = afr_transaction(transaction_frame, this, AFR_ENTRY_TRANSACTION); if (ret < 0) { op_errno = -ret; @@ -926,15 +870,11 @@ int afr_symlink(call_frame_t *frame, xlator_t *this, const char *linkpath, loc_t *loc, mode_t umask, dict_t *xdata) { - afr_private_t *priv = NULL; afr_local_t *local = NULL; - afr_internal_lock_t *int_lock = NULL; call_frame_t *transaction_frame = NULL; int ret = -1; int op_errno = ENOMEM; - priv = this->private; - transaction_frame = copy_frame(frame); if (!transaction_frame) goto out; @@ -968,16 +908,6 @@ afr_symlink(call_frame_t *frame, xlator_t *this, const char *linkpath, local->transaction.main_frame = frame; local->transaction.basename = AFR_BASENAME(loc->path); - int_lock = &local->internal_lock; - - int_lock->lockee_count = 0; - ret = afr_init_entry_lockee(&int_lock->lockee[0], local, - &local->transaction.parent_loc, - local->transaction.basename, priv->child_count); - if (ret) - goto out; - - int_lock->lockee_count++; ret = afr_transaction(transaction_frame, this, AFR_ENTRY_TRANSACTION); if (ret < 0) { op_errno = -ret; @@ -1050,15 +980,10 @@ int afr_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, dict_t *xdata) { - afr_private_t *priv = NULL; afr_local_t *local = NULL; - afr_internal_lock_t *int_lock = NULL; call_frame_t *transaction_frame = NULL; int ret = -1; int op_errno = ENOMEM; - int nlockee = 0; - - priv = this->private; transaction_frame = copy_frame(frame); if (!transaction_frame) { @@ -1101,35 +1026,6 @@ afr_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc, local->transaction.main_frame = frame; local->transaction.basename = AFR_BASENAME(oldloc->path); local->transaction.new_basename = AFR_BASENAME(newloc->path); - int_lock = &local->internal_lock; - - int_lock->lockee_count = nlockee = 0; - ret = afr_init_entry_lockee( - &int_lock->lockee[nlockee], local, &local->transaction.new_parent_loc, - local->transaction.new_basename, priv->child_count); - if (ret) - goto out; - - nlockee++; - ret = afr_init_entry_lockee(&int_lock->lockee[nlockee], local, - &local->transaction.parent_loc, - local->transaction.basename, priv->child_count); - if (ret) - goto out; - - nlockee++; - if (local->newloc.inode && IA_ISDIR(local->newloc.inode->ia_type)) { - ret = afr_init_entry_lockee(&int_lock->lockee[nlockee], local, - &local->newloc, NULL, priv->child_count); - if (ret) - goto out; - - nlockee++; - } - qsort(int_lock->lockee, nlockee, sizeof(*int_lock->lockee), - afr_entry_lockee_cmp); - int_lock->lockee_count = nlockee; - ret = afr_transaction(transaction_frame, this, AFR_ENTRY_RENAME_TRANSACTION); if (ret < 0) { @@ -1198,15 +1094,11 @@ int afr_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, dict_t *xdata) { - afr_private_t *priv = NULL; afr_local_t *local = NULL; - afr_internal_lock_t *int_lock = NULL; call_frame_t *transaction_frame = NULL; int ret = -1; int op_errno = ENOMEM; - priv = this->private; - transaction_frame = copy_frame(frame); if (!transaction_frame) goto out; @@ -1239,16 +1131,6 @@ afr_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag, local->transaction.main_frame = frame; local->transaction.basename = AFR_BASENAME(loc->path); - int_lock = &local->internal_lock; - - int_lock->lockee_count = 0; - ret = afr_init_entry_lockee(&int_lock->lockee[0], local, - &local->transaction.parent_loc, - local->transaction.basename, priv->child_count); - if (ret) - goto out; - - int_lock->lockee_count++; ret = afr_transaction(transaction_frame, this, AFR_ENTRY_TRANSACTION); if (ret < 0) { op_errno = -ret; @@ -1315,15 +1197,10 @@ int afr_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, dict_t *xdata) { - afr_private_t *priv = NULL; afr_local_t *local = NULL; - afr_internal_lock_t *int_lock = NULL; call_frame_t *transaction_frame = NULL; int ret = -1; int op_errno = ENOMEM; - int nlockee = 0; - - priv = this->private; transaction_frame = copy_frame(frame); if (!transaction_frame) @@ -1357,26 +1234,6 @@ afr_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, local->transaction.main_frame = frame; local->transaction.basename = AFR_BASENAME(loc->path); - int_lock = &local->internal_lock; - - int_lock->lockee_count = nlockee = 0; - ret = afr_init_entry_lockee(&int_lock->lockee[nlockee], local, - &local->transaction.parent_loc, - local->transaction.basename, priv->child_count); - if (ret) - goto out; - - nlockee++; - ret = afr_init_entry_lockee(&int_lock->lockee[nlockee], local, &local->loc, - NULL, priv->child_count); - if (ret) - goto out; - - nlockee++; - qsort(int_lock->lockee, nlockee, sizeof(*int_lock->lockee), - afr_entry_lockee_cmp); - int_lock->lockee_count = nlockee; - ret = afr_transaction(transaction_frame, this, AFR_ENTRY_TRANSACTION); if (ret < 0) { op_errno = -ret; -- cgit