Skip to content

Commit a2f83e8

Browse files
Mikulas Patockasnitm
authored andcommitted
dm snapshot: introduce account_start_copy() and account_end_copy()
This simple refactoring moves code for modifying the semaphore cow_count into separate functions to prepare for changes that will extend these methods to provide for a more sophisticated mechanism for COW throttling. Signed-off-by: Mikulas Patocka <[email protected]> Reviewed-by: Nikos Tsironis <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 0a00585 commit a2f83e8

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

drivers/md/dm-snap.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,16 @@ static void snapshot_dtr(struct dm_target *ti)
15121512
kfree(s);
15131513
}
15141514

1515+
static void account_start_copy(struct dm_snapshot *s)
1516+
{
1517+
down(&s->cow_count);
1518+
}
1519+
1520+
static void account_end_copy(struct dm_snapshot *s)
1521+
{
1522+
up(&s->cow_count);
1523+
}
1524+
15151525
/*
15161526
* Flush a list of buffers.
15171527
*/
@@ -1732,7 +1742,7 @@ static void copy_callback(int read_err, unsigned long write_err, void *context)
17321742
rb_link_node(&pe->out_of_order_node, parent, p);
17331743
rb_insert_color(&pe->out_of_order_node, &s->out_of_order_tree);
17341744
}
1735-
up(&s->cow_count);
1745+
account_end_copy(s);
17361746
}
17371747

17381748
/*
@@ -1756,7 +1766,7 @@ static void start_copy(struct dm_snap_pending_exception *pe)
17561766
dest.count = src.count;
17571767

17581768
/* Hand over to kcopyd */
1759-
down(&s->cow_count);
1769+
account_start_copy(s);
17601770
dm_kcopyd_copy(s->kcopyd_client, &src, 1, &dest, 0, copy_callback, pe);
17611771
}
17621772

@@ -1776,7 +1786,7 @@ static void start_full_bio(struct dm_snap_pending_exception *pe,
17761786
pe->full_bio = bio;
17771787
pe->full_bio_end_io = bio->bi_end_io;
17781788

1779-
down(&s->cow_count);
1789+
account_start_copy(s);
17801790
callback_data = dm_kcopyd_prepare_callback(s->kcopyd_client,
17811791
copy_callback, pe);
17821792

@@ -1866,7 +1876,7 @@ static void zero_callback(int read_err, unsigned long write_err, void *context)
18661876
struct bio *bio = context;
18671877
struct dm_snapshot *s = bio->bi_private;
18681878

1869-
up(&s->cow_count);
1879+
account_end_copy(s);
18701880
bio->bi_status = write_err ? BLK_STS_IOERR : 0;
18711881
bio_endio(bio);
18721882
}
@@ -1880,7 +1890,7 @@ static void zero_exception(struct dm_snapshot *s, struct dm_exception *e,
18801890
dest.sector = bio->bi_iter.bi_sector;
18811891
dest.count = s->store->chunk_size;
18821892

1883-
down(&s->cow_count);
1893+
account_start_copy(s);
18841894
WARN_ON_ONCE(bio->bi_private);
18851895
bio->bi_private = s;
18861896
dm_kcopyd_zero(s->kcopyd_client, 1, &dest, 0, zero_callback, bio);

0 commit comments

Comments
 (0)