]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/md/dm-snap.c
Merge branch 'for-4.8/core' of git://git.kernel.dk/linux-block
[karo-tx-linux.git] / drivers / md / dm-snap.c
index 3766386080a48fbfb06226ae80646b5e2f0e653a..69ab1ff5f5c996ce542d0025943231ed54e6fe59 100644 (file)
@@ -1105,6 +1105,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
        int i;
        int r = -EINVAL;
        char *origin_path, *cow_path;
+       dev_t origin_dev, cow_dev;
        unsigned args_used, num_flush_bios = 1;
        fmode_t origin_mode = FMODE_READ;
 
@@ -1135,11 +1136,19 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
                ti->error = "Cannot get origin device";
                goto bad_origin;
        }
+       origin_dev = s->origin->bdev->bd_dev;
 
        cow_path = argv[0];
        argv++;
        argc--;
 
+       cow_dev = dm_get_dev_t(cow_path);
+       if (cow_dev && cow_dev == origin_dev) {
+               ti->error = "COW device cannot be the same as origin device";
+               r = -EINVAL;
+               goto bad_cow;
+       }
+
        r = dm_get_device(ti, cow_path, dm_table_get_mode(ti->table), &s->cow);
        if (r) {
                ti->error = "Cannot get COW device";
@@ -1201,7 +1210,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 
        ti->private = s;
        ti->num_flush_bios = num_flush_bios;
-       ti->per_bio_data_size = sizeof(struct dm_snap_tracked_chunk);
+       ti->per_io_data_size = sizeof(struct dm_snap_tracked_chunk);
 
        /* Add snapshot to the list of snapshots for this origin */
        /* Exceptions aren't triggered till snapshot_resume() is called */
@@ -1671,7 +1680,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
 
        init_tracked_chunk(bio);
 
-       if (bio->bi_rw & REQ_FLUSH) {
+       if (bio->bi_rw & REQ_PREFLUSH) {
                bio->bi_bdev = s->cow->bdev;
                return DM_MAPIO_REMAPPED;
        }
@@ -1790,7 +1799,7 @@ static int snapshot_merge_map(struct dm_target *ti, struct bio *bio)
 
        init_tracked_chunk(bio);
 
-       if (bio->bi_rw & REQ_FLUSH) {
+       if (bio->bi_rw & REQ_PREFLUSH) {
                if (!dm_bio_get_target_bio_nr(bio))
                        bio->bi_bdev = s->origin->bdev;
                else
@@ -2276,7 +2285,7 @@ static int origin_map(struct dm_target *ti, struct bio *bio)
 
        bio->bi_bdev = o->dev->bdev;
 
-       if (unlikely(bio->bi_rw & REQ_FLUSH))
+       if (unlikely(bio->bi_rw & REQ_PREFLUSH))
                return DM_MAPIO_REMAPPED;
 
        if (bio_rw(bio) != WRITE)