Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 2920
b: refs/heads/master
c: 35a82d1
h: refs/heads/master
v: v3
  • Loading branch information
Nick Piggin authored and Linus Torvalds committed Jun 23, 2005
1 parent a15c1a7 commit 834bef2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 45 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ab4af03a4054bd78bcabfb2214c9597201beae35
refs/heads/master: 35a82d1a53e1a9ad54efafcc940f9335beaed5c3
81 changes: 38 additions & 43 deletions trunk/drivers/block/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,17 +472,11 @@ static int do_bio_filebacked(struct loop_device *lo, struct bio *bio)
*/
static void loop_add_bio(struct loop_device *lo, struct bio *bio)
{
unsigned long flags;

spin_lock_irqsave(&lo->lo_lock, flags);
if (lo->lo_biotail) {
lo->lo_biotail->bi_next = bio;
lo->lo_biotail = bio;
} else
lo->lo_bio = lo->lo_biotail = bio;
spin_unlock_irqrestore(&lo->lo_lock, flags);

up(&lo->lo_bh_mutex);
}

/*
Expand All @@ -492,14 +486,12 @@ static struct bio *loop_get_bio(struct loop_device *lo)
{
struct bio *bio;

spin_lock_irq(&lo->lo_lock);
if ((bio = lo->lo_bio)) {
if (bio == lo->lo_biotail)
lo->lo_biotail = NULL;
lo->lo_bio = bio->bi_next;
bio->bi_next = NULL;
}
spin_unlock_irq(&lo->lo_lock);

return bio;
}
Expand All @@ -509,35 +501,28 @@ static int loop_make_request(request_queue_t *q, struct bio *old_bio)
struct loop_device *lo = q->queuedata;
int rw = bio_rw(old_bio);

if (!lo)
goto out;
if (rw == READA)
rw = READ;

BUG_ON(!lo || (rw != READ && rw != WRITE));

spin_lock_irq(&lo->lo_lock);
if (lo->lo_state != Lo_bound)
goto inactive;
atomic_inc(&lo->lo_pending);
spin_unlock_irq(&lo->lo_lock);

if (rw == WRITE) {
if (lo->lo_flags & LO_FLAGS_READ_ONLY)
goto err;
} else if (rw == READA) {
rw = READ;
} else if (rw != READ) {
printk(KERN_ERR "loop: unknown command (%x)\n", rw);
goto err;
}
goto out;
if (unlikely(rw == WRITE && (lo->lo_flags & LO_FLAGS_READ_ONLY)))
goto out;
lo->lo_pending++;
loop_add_bio(lo, old_bio);
spin_unlock_irq(&lo->lo_lock);
up(&lo->lo_bh_mutex);
return 0;
err:
if (atomic_dec_and_test(&lo->lo_pending))
up(&lo->lo_bh_mutex);

out:
if (lo->lo_pending == 0)
up(&lo->lo_bh_mutex);
spin_unlock_irq(&lo->lo_lock);
bio_io_error(old_bio, old_bio->bi_size);
return 0;
inactive:
spin_unlock_irq(&lo->lo_lock);
goto out;
}

/*
Expand All @@ -560,13 +545,11 @@ static void do_loop_switch(struct loop_device *, struct switch_request *);

static inline void loop_handle_bio(struct loop_device *lo, struct bio *bio)
{
int ret;

if (unlikely(!bio->bi_bdev)) {
do_loop_switch(lo, bio->bi_private);
bio_put(bio);
} else {
ret = do_bio_filebacked(lo, bio);
int ret = do_bio_filebacked(lo, bio);
bio_endio(bio, bio->bi_size, ret);
}
}
Expand Down Expand Up @@ -594,34 +577,45 @@ static int loop_thread(void *data)
set_user_nice(current, -20);

lo->lo_state = Lo_bound;
atomic_inc(&lo->lo_pending);
lo->lo_pending = 1;

/*
* up sem, we are running
*/
up(&lo->lo_sem);

for (;;) {
down_interruptible(&lo->lo_bh_mutex);
int pending;

/*
* could be upped because of tear-down, not because of
* pending work
* interruptible just to not contribute to load avg
*/
if (!atomic_read(&lo->lo_pending))
if (down_interruptible(&lo->lo_bh_mutex))
continue;

spin_lock_irq(&lo->lo_lock);

/*
* could be upped because of tear-down, not pending work
*/
if (unlikely(!lo->lo_pending)) {
spin_unlock_irq(&lo->lo_lock);
break;
}

bio = loop_get_bio(lo);
if (!bio) {
printk("loop: missing bio\n");
continue;
}
lo->lo_pending--;
pending = lo->lo_pending;
spin_unlock_irq(&lo->lo_lock);

BUG_ON(!bio);
loop_handle_bio(lo, bio);

/*
* upped both for pending work and tear-down, lo_pending
* will hit zero then
*/
if (atomic_dec_and_test(&lo->lo_pending))
if (unlikely(!pending))
break;
}

Expand Down Expand Up @@ -900,7 +894,8 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev)

spin_lock_irq(&lo->lo_lock);
lo->lo_state = Lo_rundown;
if (atomic_dec_and_test(&lo->lo_pending))
lo->lo_pending--;
if (!lo->lo_pending)
up(&lo->lo_bh_mutex);
spin_unlock_irq(&lo->lo_lock);

Expand Down
2 changes: 1 addition & 1 deletion trunk/include/linux/loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct loop_device {
struct semaphore lo_sem;
struct semaphore lo_ctl_mutex;
struct semaphore lo_bh_mutex;
atomic_t lo_pending;
int lo_pending;

request_queue_t *lo_queue;
};
Expand Down

0 comments on commit 834bef2

Please sign in to comment.