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

[PATCH] minixfs cleanups (3/4)

Kill BKL in minix/itree* (similar to ext2 patches)
parent e8de6e05
......@@ -13,6 +13,7 @@
#include "minix.h"
#include <linux/locks.h>
#include <linux/smp_lock.h>
#include <asm/bitops.h>
......@@ -72,9 +73,11 @@ void minix_free_block(struct inode * inode, int block)
return;
}
bh = sbi->s_zmap[zone];
lock_kernel();
if (!minix_test_and_clear_bit(bit,bh->b_data))
printk("free_block (%s:%d): bit already cleared\n",
sb->s_id, block);
unlock_kernel();
mark_buffer_dirty(bh);
return;
}
......@@ -90,6 +93,7 @@ int minix_new_block(struct inode * inode)
printk("trying to get new block from nonexistent device\n");
return 0;
}
lock_kernel();
repeat:
j = 8192;
bh = NULL;
......@@ -98,12 +102,15 @@ int minix_new_block(struct inode * inode)
if ((j = minix_find_first_zero_bit(bh->b_data, 8192)) < 8192)
break;
}
if (!bh || j >= 8192)
if (!bh || j >= 8192) {
unlock_kernel();
return 0;
}
if (minix_test_and_set_bit(j,bh->b_data)) {
printk("new_block: bit already set");
goto repeat;
}
unlock_kernel();
mark_buffer_dirty(bh);
j += i*8192 + sbi->s_firstdatazone-1;
if (j < sbi->s_firstdatazone ||
......
......@@ -534,12 +534,10 @@ int minix_sync_inode(struct inode * inode)
*/
void minix_truncate(struct inode * inode)
{
lock_kernel();
if (INODE_VERSION(inode) == MINIX_V1)
V1_minix_truncate(inode);
else
V2_minix_truncate(inode);
unlock_kernel();
}
static struct super_block *minix_get_sb(struct file_system_type *fs_type,
......
......@@ -6,6 +6,8 @@ typedef struct {
struct buffer_head *bh;
} Indirect;
static rwlock_t pointers_lock = RW_LOCK_UNLOCKED;
static inline void add_chain(Indirect *p, struct buffer_head *bh, block_t *v)
{
p->key = *(p->p = v);
......@@ -43,17 +45,18 @@ static inline Indirect *get_branch(struct inode *inode,
bh = sb_bread(sb, block_to_cpu(p->key));
if (!bh)
goto failure;
/* Reader: pointers */
read_lock(&pointers_lock);
if (!verify_chain(chain, p))
goto changed;
add_chain(++p, bh, (block_t *)bh->b_data + *++offsets);
/* Reader: end */
read_unlock(&pointers_lock);
if (!p->key)
goto no_block;
}
return NULL;
changed:
read_unlock(&pointers_lock);
*err = -EAGAIN;
goto no_block;
failure:
......@@ -108,18 +111,15 @@ static inline int splice_branch(struct inode *inode,
{
int i;
/* Verify that place we are splicing to is still there and vacant */
write_lock(&pointers_lock);
/* Writer: pointers */
/* Verify that place we are splicing to is still there and vacant */
if (!verify_chain(chain, where-1) || *where->p)
/* Writer: end */
goto changed;
/* That's it */
*where->p = where->key;
/* Writer: end */
write_unlock(&pointers_lock);
/* We are done with atomic stuff, now do the rest of housekeeping */
......@@ -133,6 +133,7 @@ static inline int splice_branch(struct inode *inode,
return 0;
changed:
write_unlock(&pointers_lock);
for (i = 1; i < num; i++)
bforget(where[i].bh);
for (i = 0; i < num; i++)
......@@ -153,7 +154,6 @@ static inline int get_block(struct inode * inode, sector_t block,
if (depth == 0)
goto out;
lock_kernel();
reread:
partial = get_branch(inode, depth, offsets, chain, &err);
......@@ -173,7 +173,6 @@ static inline int get_block(struct inode * inode, sector_t block,
brelse(partial->bh);
partial--;
}
unlock_kernel();
out:
return err;
}
......@@ -226,12 +225,14 @@ static Indirect *find_shared(struct inode *inode,
for (k = depth; k > 1 && !offsets[k-1]; k--)
;
partial = get_branch(inode, k, offsets, chain, &err);
/* Writer: pointers */
write_lock(&pointers_lock);
if (!partial)
partial = chain + k-1;
if (!partial->key && *partial->p)
/* Writer: end */
if (!partial->key && *partial->p) {
write_unlock(&pointers_lock);
goto no_top;
}
for (p=partial;p>chain && all_zeroes((block_t*)p->bh->b_data,p->p);p--)
;
if (p == chain + k - 1 && p > chain) {
......@@ -240,7 +241,7 @@ static Indirect *find_shared(struct inode *inode,
*top = *p->p;
*p->p = 0;
}
/* Writer: end */
write_unlock(&pointers_lock);
while(partial > p)
{
......
#include "minix.h"
#include <linux/locks.h>
#include <linux/smp_lock.h>
enum {DEPTH = 3, DIRECT = 7}; /* Only double indirect */
......
#include "minix.h"
#include <linux/locks.h>
#include <linux/smp_lock.h>
enum {DIRECT = 7, DEPTH = 4}; /* Have triple indirect */
......
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