aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/md/dm-snap-persistent.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index 2a3d626a98d9..5d1a97580cb7 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -106,6 +106,13 @@ struct pstore {
106 void *zero_area; 106 void *zero_area;
107 107
108 /* 108 /*
109 * An area used for header. The header can be written
110 * concurrently with metadata (when invalidating the snapshot),
111 * so it needs a separate buffer.
112 */
113 void *header_area;
114
115 /*
109 * Used to keep track of which metadata area the data in 116 * Used to keep track of which metadata area the data in
110 * 'chunk' refers to. 117 * 'chunk' refers to.
111 */ 118 */
@@ -148,16 +155,27 @@ static int alloc_area(struct pstore *ps)
148 */ 155 */
149 ps->area = vmalloc(len); 156 ps->area = vmalloc(len);
150 if (!ps->area) 157 if (!ps->area)
151 return r; 158 goto err_area;
152 159
153 ps->zero_area = vmalloc(len); 160 ps->zero_area = vmalloc(len);
154 if (!ps->zero_area) { 161 if (!ps->zero_area)
155 vfree(ps->area); 162 goto err_zero_area;
156 return r;
157 }
158 memset(ps->zero_area, 0, len); 163 memset(ps->zero_area, 0, len);
159 164
165 ps->header_area = vmalloc(len);
166 if (!ps->header_area)
167 goto err_header_area;
168
160 return 0; 169 return 0;
170
171err_header_area:
172 vfree(ps->zero_area);
173
174err_zero_area:
175 vfree(ps->area);
176
177err_area:
178 return r;
161} 179}
162 180
163static void free_area(struct pstore *ps) 181static void free_area(struct pstore *ps)
@@ -169,6 +187,10 @@ static void free_area(struct pstore *ps)
169 if (ps->zero_area) 187 if (ps->zero_area)
170 vfree(ps->zero_area); 188 vfree(ps->zero_area);
171 ps->zero_area = NULL; 189 ps->zero_area = NULL;
190
191 if (ps->header_area)
192 vfree(ps->header_area);
193 ps->header_area = NULL;
172} 194}
173 195
174struct mdata_req { 196struct mdata_req {
@@ -285,11 +307,11 @@ static int read_header(struct pstore *ps, int *new_snapshot)
285 if (r) 307 if (r)
286 return r; 308 return r;
287 309
288 r = chunk_io(ps, ps->area, 0, READ, 1); 310 r = chunk_io(ps, ps->header_area, 0, READ, 1);
289 if (r) 311 if (r)
290 goto bad; 312 goto bad;
291 313
292 dh = (struct disk_header *) ps->area; 314 dh = ps->header_area;
293 315
294 if (le32_to_cpu(dh->magic) == 0) { 316 if (le32_to_cpu(dh->magic) == 0) {
295 *new_snapshot = 1; 317 *new_snapshot = 1;
@@ -339,15 +361,15 @@ static int write_header(struct pstore *ps)
339{ 361{
340 struct disk_header *dh; 362 struct disk_header *dh;
341 363
342 memset(ps->area, 0, ps->store->chunk_size << SECTOR_SHIFT); 364 memset(ps->header_area, 0, ps->store->chunk_size << SECTOR_SHIFT);
343 365
344 dh = (struct disk_header *) ps->area; 366 dh = ps->header_area;
345 dh->magic = cpu_to_le32(SNAP_MAGIC); 367 dh->magic = cpu_to_le32(SNAP_MAGIC);
346 dh->valid = cpu_to_le32(ps->valid); 368 dh->valid = cpu_to_le32(ps->valid);
347 dh->version = cpu_to_le32(ps->version); 369 dh->version = cpu_to_le32(ps->version);
348 dh->chunk_size = cpu_to_le32(ps->store->chunk_size); 370 dh->chunk_size = cpu_to_le32(ps->store->chunk_size);
349 371
350 return chunk_io(ps, ps->area, 0, WRITE, 1); 372 return chunk_io(ps, ps->header_area, 0, WRITE, 1);
351} 373}
352 374
353/* 375/*
@@ -667,6 +689,8 @@ static int persistent_ctr(struct dm_exception_store *store,
667 ps->valid = 1; 689 ps->valid = 1;
668 ps->version = SNAPSHOT_DISK_VERSION; 690 ps->version = SNAPSHOT_DISK_VERSION;
669 ps->area = NULL; 691 ps->area = NULL;
692 ps->zero_area = NULL;
693 ps->header_area = NULL;
670 ps->next_free = 2; /* skipping the header and first area */ 694 ps->next_free = 2; /* skipping the header and first area */
671 ps->current_committed = 0; 695 ps->current_committed = 0;
672 696