Skip to content

Commit c241104

Browse files
Mikulas Patockakergon
authored andcommitted
dm snapshot: test chunk size against both origin and snapshot
Validate chunk size against both origin and snapshot sector size Don't allow chunk size smaller than either origin or snapshot logical sector size. Reading or writing data not aligned to sector size is not allowed and causes immediate errors. This requires us to open the origin before initialising the exception store and to export dm_snap_origin. Cc: stable@kernel.org Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Reviewed-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
1 parent 1e5554c commit c241104

3 files changed

Lines changed: 26 additions & 17 deletions

File tree

‎drivers/md/dm-exception-store.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ int dm_exception_store_set_chunk_size(struct dm_exception_store *store,
173173

174174
/* Validate the chunk size against the device block size */
175175
if (chunk_size %
176-
(bdev_logical_block_size(dm_snap_cow(store->snap)->bdev) >> 9)) {
176+
(bdev_logical_block_size(dm_snap_cow(store->snap)->bdev) >> 9) ||
177+
chunk_size %
178+
(bdev_logical_block_size(dm_snap_origin(store->snap)->bdev) >> 9)) {
177179
*error = "Chunk size is not a multiple of device blocksize";
178180
return -EINVAL;
179181
}

‎drivers/md/dm-exception-store.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ struct dm_exception_store {
126126
};
127127

128128
/*
129-
* Obtain the cow device used by a given snapshot.
129+
* Obtain the origin or cow device used by a given snapshot.
130130
*/
131+
struct dm_dev *dm_snap_origin(struct dm_snapshot *snap);
131132
struct dm_dev *dm_snap_cow(struct dm_snapshot *snap);
132133

133134
/*

‎drivers/md/dm-snap.c‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ struct dm_snapshot {
148148
#define RUNNING_MERGE 0
149149
#define SHUTDOWN_MERGE 1
150150

151+
struct dm_dev *dm_snap_origin(struct dm_snapshot *s)
152+
{
153+
return s->origin;
154+
}
155+
EXPORT_SYMBOL(dm_snap_origin);
156+
151157
struct dm_dev *dm_snap_cow(struct dm_snapshot *s)
152158
{
153159
return s->cow;
@@ -1065,10 +1071,6 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
10651071
origin_mode = FMODE_WRITE;
10661072
}
10671073

1068-
origin_path = argv[0];
1069-
argv++;
1070-
argc--;
1071-
10721074
s = kmalloc(sizeof(*s), GFP_KERNEL);
10731075
if (!s) {
10741076
ti->error = "Cannot allocate snapshot context private "
@@ -1077,6 +1079,16 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
10771079
goto bad;
10781080
}
10791081

1082+
origin_path = argv[0];
1083+
argv++;
1084+
argc--;
1085+
1086+
r = dm_get_device(ti, origin_path, origin_mode, &s->origin);
1087+
if (r) {
1088+
ti->error = "Cannot get origin device";
1089+
goto bad_origin;
1090+
}
1091+
10801092
cow_path = argv[0];
10811093
argv++;
10821094
argc--;
@@ -1097,12 +1109,6 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
10971109
argv += args_used;
10981110
argc -= args_used;
10991111

1100-
r = dm_get_device(ti, origin_path, origin_mode, &s->origin);
1101-
if (r) {
1102-
ti->error = "Cannot get origin device";
1103-
goto bad_origin;
1104-
}
1105-
11061112
s->ti = ti;
11071113
s->valid = 1;
11081114
s->active = 0;
@@ -1212,15 +1218,15 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
12121218
dm_exception_table_exit(&s->complete, exception_cache);
12131219

12141220
bad_hash_tables:
1215-
dm_put_device(ti, s->origin);
1216-
1217-
bad_origin:
12181221
dm_exception_store_destroy(s->store);
12191222

12201223
bad_store:
12211224
dm_put_device(ti, s->cow);
12221225

12231226
bad_cow:
1227+
dm_put_device(ti, s->origin);
1228+
1229+
bad_origin:
12241230
kfree(s);
12251231

12261232
bad:
@@ -1314,12 +1320,12 @@ static void snapshot_dtr(struct dm_target *ti)
13141320

13151321
mempool_destroy(s->pending_pool);
13161322

1317-
dm_put_device(ti, s->origin);
1318-
13191323
dm_exception_store_destroy(s->store);
13201324

13211325
dm_put_device(ti, s->cow);
13221326

1327+
dm_put_device(ti, s->origin);
1328+
13231329
kfree(s);
13241330
}
13251331

0 commit comments

Comments
 (0)