aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/namei.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ocfs2/namei.c')
-rw-r--r--fs/ocfs2/namei.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index b931e04e3388..914c121ec890 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -94,6 +94,14 @@ static int ocfs2_create_symlink_data(struct ocfs2_super *osb,
94 struct inode *inode, 94 struct inode *inode,
95 const char *symname); 95 const char *symname);
96 96
97static int ocfs2_double_lock(struct ocfs2_super *osb,
98 struct buffer_head **bh1,
99 struct inode *inode1,
100 struct buffer_head **bh2,
101 struct inode *inode2,
102 int rename);
103
104static void ocfs2_double_unlock(struct inode *inode1, struct inode *inode2);
97/* An orphan dir name is an 8 byte value, printed as a hex string */ 105/* An orphan dir name is an 8 byte value, printed as a hex string */
98#define OCFS2_ORPHAN_NAMELEN ((int)(2 * sizeof(u64))) 106#define OCFS2_ORPHAN_NAMELEN ((int)(2 * sizeof(u64)))
99 107
@@ -678,8 +686,10 @@ static int ocfs2_link(struct dentry *old_dentry,
678{ 686{
679 handle_t *handle; 687 handle_t *handle;
680 struct inode *inode = old_dentry->d_inode; 688 struct inode *inode = old_dentry->d_inode;
689 struct inode *old_dir = old_dentry->d_parent->d_inode;
681 int err; 690 int err;
682 struct buffer_head *fe_bh = NULL; 691 struct buffer_head *fe_bh = NULL;
692 struct buffer_head *old_dir_bh = NULL;
683 struct buffer_head *parent_fe_bh = NULL; 693 struct buffer_head *parent_fe_bh = NULL;
684 struct ocfs2_dinode *fe = NULL; 694 struct ocfs2_dinode *fe = NULL;
685 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb); 695 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
@@ -696,19 +706,33 @@ static int ocfs2_link(struct dentry *old_dentry,
696 706
697 dquot_initialize(dir); 707 dquot_initialize(dir);
698 708
699 err = ocfs2_inode_lock_nested(dir, &parent_fe_bh, 1, OI_LS_PARENT); 709 err = ocfs2_double_lock(osb, &old_dir_bh, old_dir,
710 &parent_fe_bh, dir, 0);
700 if (err < 0) { 711 if (err < 0) {
701 if (err != -ENOENT) 712 if (err != -ENOENT)
702 mlog_errno(err); 713 mlog_errno(err);
703 return err; 714 return err;
704 } 715 }
705 716
717 /* make sure both dirs have bhs
718 * get an extra ref on old_dir_bh if old==new */
719 if (!parent_fe_bh) {
720 if (old_dir_bh) {
721 parent_fe_bh = old_dir_bh;
722 get_bh(parent_fe_bh);
723 } else {
724 mlog(ML_ERROR, "%s: no old_dir_bh!\n", osb->uuid_str);
725 err = -EIO;
726 goto out;
727 }
728 }
729
706 if (!dir->i_nlink) { 730 if (!dir->i_nlink) {
707 err = -ENOENT; 731 err = -ENOENT;
708 goto out; 732 goto out;
709 } 733 }
710 734
711 err = ocfs2_lookup_ino_from_name(dir, old_dentry->d_name.name, 735 err = ocfs2_lookup_ino_from_name(old_dir, old_dentry->d_name.name,
712 old_dentry->d_name.len, &old_de_ino); 736 old_dentry->d_name.len, &old_de_ino);
713 if (err) { 737 if (err) {
714 err = -ENOENT; 738 err = -ENOENT;
@@ -801,10 +825,11 @@ out_unlock_inode:
801 ocfs2_inode_unlock(inode, 1); 825 ocfs2_inode_unlock(inode, 1);
802 826
803out: 827out:
804 ocfs2_inode_unlock(dir, 1); 828 ocfs2_double_unlock(old_dir, dir);
805 829
806 brelse(fe_bh); 830 brelse(fe_bh);
807 brelse(parent_fe_bh); 831 brelse(parent_fe_bh);
832 brelse(old_dir_bh);
808 833
809 ocfs2_free_dir_lookup_result(&lookup); 834 ocfs2_free_dir_lookup_result(&lookup);
810 835
@@ -1072,14 +1097,15 @@ static int ocfs2_check_if_ancestor(struct ocfs2_super *osb,
1072} 1097}
1073 1098
1074/* 1099/*
1075 * The only place this should be used is rename! 1100 * The only place this should be used is rename and link!
1076 * if they have the same id, then the 1st one is the only one locked. 1101 * if they have the same id, then the 1st one is the only one locked.
1077 */ 1102 */
1078static int ocfs2_double_lock(struct ocfs2_super *osb, 1103static int ocfs2_double_lock(struct ocfs2_super *osb,
1079 struct buffer_head **bh1, 1104 struct buffer_head **bh1,
1080 struct inode *inode1, 1105 struct inode *inode1,
1081 struct buffer_head **bh2, 1106 struct buffer_head **bh2,
1082 struct inode *inode2) 1107 struct inode *inode2,
1108 int rename)
1083{ 1109{
1084 int status; 1110 int status;
1085 int inode1_is_ancestor, inode2_is_ancestor; 1111 int inode1_is_ancestor, inode2_is_ancestor;
@@ -1127,7 +1153,7 @@ static int ocfs2_double_lock(struct ocfs2_super *osb,
1127 } 1153 }
1128 /* lock id2 */ 1154 /* lock id2 */
1129 status = ocfs2_inode_lock_nested(inode2, bh2, 1, 1155 status = ocfs2_inode_lock_nested(inode2, bh2, 1,
1130 OI_LS_RENAME1); 1156 rename == 1 ? OI_LS_RENAME1 : OI_LS_PARENT);
1131 if (status < 0) { 1157 if (status < 0) {
1132 if (status != -ENOENT) 1158 if (status != -ENOENT)
1133 mlog_errno(status); 1159 mlog_errno(status);
@@ -1136,7 +1162,8 @@ static int ocfs2_double_lock(struct ocfs2_super *osb,
1136 } 1162 }
1137 1163
1138 /* lock id1 */ 1164 /* lock id1 */
1139 status = ocfs2_inode_lock_nested(inode1, bh1, 1, OI_LS_RENAME2); 1165 status = ocfs2_inode_lock_nested(inode1, bh1, 1,
1166 rename == 1 ? OI_LS_RENAME2 : OI_LS_PARENT);
1140 if (status < 0) { 1167 if (status < 0) {
1141 /* 1168 /*
1142 * An error return must mean that no cluster locks 1169 * An error return must mean that no cluster locks
@@ -1252,7 +1279,7 @@ static int ocfs2_rename(struct inode *old_dir,
1252 1279
1253 /* if old and new are the same, this'll just do one lock. */ 1280 /* if old and new are the same, this'll just do one lock. */
1254 status = ocfs2_double_lock(osb, &old_dir_bh, old_dir, 1281 status = ocfs2_double_lock(osb, &old_dir_bh, old_dir,
1255 &new_dir_bh, new_dir); 1282 &new_dir_bh, new_dir, 1);
1256 if (status < 0) { 1283 if (status < 0) {
1257 mlog_errno(status); 1284 mlog_errno(status);
1258 goto bail; 1285 goto bail;