Commit fde48def authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] hpfs: clean up lock ordering

	hpfs_{lock,unlock}_{2,3}inodes() killed; all places that take more than
one lock have ->i_sem held by VFS on all inodes involved and all hpfs per-inode
locks are of the same type.  IOW, we can replace these guys with multiple
hpfs_lock_inode() - order doesn't matter here.
parent c4357dfe
...@@ -60,74 +60,6 @@ void hpfs_unlock_inode(struct inode *i) ...@@ -60,74 +60,6 @@ void hpfs_unlock_inode(struct inode *i)
} }
} }
void hpfs_lock_2inodes(struct inode *i1, struct inode *i2)
{
if (!i2 || i1 == i2) {
hpfs_lock_inode(i1);
} else if (!i1) {
hpfs_lock_inode(i2);
} else {
struct hpfs_inode_info *hpfs_i1 = hpfs_i(i1);
struct hpfs_inode_info *hpfs_i2 = hpfs_i(i2);
if (i1->i_ino < i2->i_ino) {
down(&hpfs_i1->i_sem);
down(&hpfs_i2->i_sem);
} else {
down(&hpfs_i2->i_sem);
down(&hpfs_i1->i_sem);
}
}
}
void hpfs_unlock_2inodes(struct inode *i1, struct inode *i2)
{
/* order of up() doesn't matter here */
hpfs_unlock_inode(i1);
hpfs_unlock_inode(i2);
}
void hpfs_lock_3inodes(struct inode *i1, struct inode *i2, struct inode *i3)
{
if (!i1) { hpfs_lock_2inodes(i2, i3); return; }
if (!i2) { hpfs_lock_2inodes(i1, i3); return; }
if (!i3) { hpfs_lock_2inodes(i1, i2); return; }
if (i1->i_ino < i2->i_ino && i1->i_ino < i3->i_ino) {
struct hpfs_inode_info *hpfs_i1 = hpfs_i(i1);
down(&hpfs_i1->i_sem);
hpfs_lock_2inodes(i2, i3);
} else if (i2->i_ino < i1->i_ino && i2->i_ino < i3->i_ino) {
struct hpfs_inode_info *hpfs_i2 = hpfs_i(i2);
down(&hpfs_i2->i_sem);
hpfs_lock_2inodes(i1, i3);
} else if (i3->i_ino < i1->i_ino && i3->i_ino < i2->i_ino) {
struct hpfs_inode_info *hpfs_i3 = hpfs_i(i3);
down(&hpfs_i3->i_sem);
hpfs_lock_2inodes(i1, i2);
} else if (i1->i_ino != i2->i_ino) hpfs_lock_2inodes(i1, i2);
else hpfs_lock_2inodes(i1, i3);
}
void hpfs_unlock_3inodes(struct inode *i1, struct inode *i2, struct inode *i3)
{
if (!i1) { hpfs_unlock_2inodes(i2, i3); return; }
if (!i2) { hpfs_unlock_2inodes(i1, i3); return; }
if (!i3) { hpfs_unlock_2inodes(i1, i2); return; }
if (i1->i_ino < i2->i_ino && i1->i_ino < i3->i_ino) {
struct hpfs_inode_info *hpfs_i1 = hpfs_i(i1);
hpfs_unlock_2inodes(i2, i3);
up(&hpfs_i1->i_sem);
} else if (i2->i_ino < i1->i_ino && i2->i_ino < i3->i_ino) {
struct hpfs_inode_info *hpfs_i2 = hpfs_i(i2);
hpfs_unlock_2inodes(i1, i3);
up(&hpfs_i2->i_sem);
} else if (i3->i_ino < i1->i_ino && i3->i_ino < i2->i_ino) {
struct hpfs_inode_info *hpfs_i3 = hpfs_i(i3);
hpfs_unlock_2inodes(i1, i2);
up(&hpfs_i3->i_sem);
} else if (i1->i_ino != i2->i_ino) hpfs_unlock_2inodes(i1, i2);
else hpfs_unlock_2inodes(i1, i3);
}
/* Map a sector into a buffer and return pointers to it and to the buffer. */ /* Map a sector into a buffer and return pointers to it and to the buffer. */
void *hpfs_map_sector(struct super_block *s, unsigned secno, struct buffer_head **bhp, void *hpfs_map_sector(struct super_block *s, unsigned secno, struct buffer_head **bhp,
......
...@@ -196,10 +196,6 @@ void hpfs_lock_iget(struct super_block *, int); ...@@ -196,10 +196,6 @@ void hpfs_lock_iget(struct super_block *, int);
void hpfs_unlock_iget(struct super_block *); void hpfs_unlock_iget(struct super_block *);
void hpfs_lock_inode(struct inode *); void hpfs_lock_inode(struct inode *);
void hpfs_unlock_inode(struct inode *); void hpfs_unlock_inode(struct inode *);
void hpfs_lock_2inodes(struct inode *, struct inode *);
void hpfs_unlock_2inodes(struct inode *, struct inode *);
void hpfs_lock_3inodes(struct inode *, struct inode *, struct inode *);
void hpfs_unlock_3inodes(struct inode *, struct inode *, struct inode *);
void *hpfs_map_sector(struct super_block *, unsigned, struct buffer_head **, int); void *hpfs_map_sector(struct super_block *, unsigned, struct buffer_head **, int);
void *hpfs_get_sector(struct super_block *, unsigned, struct buffer_head **); void *hpfs_get_sector(struct super_block *, unsigned, struct buffer_head **);
void *hpfs_map_4sectors(struct super_block *, unsigned, struct quad_buffer_head *, int); void *hpfs_map_4sectors(struct super_block *, unsigned, struct quad_buffer_head *, int);
......
...@@ -349,7 +349,8 @@ int hpfs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -349,7 +349,8 @@ int hpfs_unlink(struct inode *dir, struct dentry *dentry)
lock_kernel(); lock_kernel();
hpfs_adjust_length((char *)name, &len); hpfs_adjust_length((char *)name, &len);
again: again:
hpfs_lock_2inodes(dir, inode); hpfs_lock_inode(dir);
hpfs_lock_inode(inode);
err = -ENOENT; err = -ENOENT;
de = map_dirent(dir, hpfs_i(dir)->i_dno, (char *)name, len, &dno, &qbh); de = map_dirent(dir, hpfs_i(dir)->i_dno, (char *)name, len, &dno, &qbh);
if (!de) if (!de)
...@@ -376,7 +377,8 @@ int hpfs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -376,7 +377,8 @@ int hpfs_unlink(struct inode *dir, struct dentry *dentry)
if (rep++) if (rep++)
break; break;
hpfs_unlock_2inodes(dir, inode); hpfs_unlock_inode(inode);
hpfs_unlock_inode(dir);
d_drop(dentry); d_drop(dentry);
spin_lock(&dentry->d_lock); spin_lock(&dentry->d_lock);
if (atomic_read(&dentry->d_count) > 1 || if (atomic_read(&dentry->d_count) > 1 ||
...@@ -407,7 +409,8 @@ int hpfs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -407,7 +409,8 @@ int hpfs_unlink(struct inode *dir, struct dentry *dentry)
out1: out1:
hpfs_brelse4(&qbh); hpfs_brelse4(&qbh);
out: out:
hpfs_unlock_2inodes(dir, inode); hpfs_unlock_inode(inode);
hpfs_unlock_inode(dir);
unlock_kernel(); unlock_kernel();
return err; return err;
} }
...@@ -427,7 +430,8 @@ int hpfs_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -427,7 +430,8 @@ int hpfs_rmdir(struct inode *dir, struct dentry *dentry)
hpfs_adjust_length((char *)name, &len); hpfs_adjust_length((char *)name, &len);
lock_kernel(); lock_kernel();
hpfs_lock_2inodes(dir, inode); hpfs_lock_inode(dir);
hpfs_lock_inode(inode);
err = -ENOENT; err = -ENOENT;
de = map_dirent(dir, hpfs_i(dir)->i_dno, (char *)name, len, &dno, &qbh); de = map_dirent(dir, hpfs_i(dir)->i_dno, (char *)name, len, &dno, &qbh);
if (!de) if (!de)
...@@ -465,7 +469,8 @@ int hpfs_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -465,7 +469,8 @@ int hpfs_rmdir(struct inode *dir, struct dentry *dentry)
out1: out1:
hpfs_brelse4(&qbh); hpfs_brelse4(&qbh);
out: out:
hpfs_unlock_2inodes(dir, inode); hpfs_unlock_inode(inode);
hpfs_unlock_inode(dir);
unlock_kernel(); unlock_kernel();
return err; return err;
} }
...@@ -522,7 +527,10 @@ int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -522,7 +527,10 @@ int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry,
hpfs_adjust_length((char *)old_name, &old_len); hpfs_adjust_length((char *)old_name, &old_len);
lock_kernel(); lock_kernel();
hpfs_lock_3inodes(old_dir, new_dir, i); hpfs_lock_inode(old_dir);
if (new_dir != old_dir)
hpfs_lock_inode(new_dir);
hpfs_lock_inode(i);
/* Erm? Moving over the empty non-busy directory is perfectly legal */ /* Erm? Moving over the empty non-busy directory is perfectly legal */
if (new_inode && S_ISDIR(new_inode->i_mode)) { if (new_inode && S_ISDIR(new_inode->i_mode)) {
...@@ -601,7 +609,10 @@ int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -601,7 +609,10 @@ int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry,
hpfs_i(i)->i_conv = hpfs_sb(i->i_sb)->sb_conv; hpfs_i(i)->i_conv = hpfs_sb(i->i_sb)->sb_conv;
hpfs_decide_conv(i, (char *)new_name, new_len); hpfs_decide_conv(i, (char *)new_name, new_len);
end1: end1:
hpfs_unlock_3inodes(old_dir, new_dir, i); hpfs_unlock_inode(i);
if (old_dir != new_dir)
hpfs_unlock_inode(new_dir);
hpfs_unlock_inode(old_dir);
unlock_kernel(); unlock_kernel();
return err; return err;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment