pci core: function pci_bus_init() cleanup
[qemu/ar7.git] / block / qcow2-snapshot.c
blob13f88d1b8b6b931d15c6df9be8c430f9c58e408e
1 /*
2 * Block driver for the QCOW version 2 format
4 * Copyright (c) 2004-2006 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
27 #include "block/block_int.h"
28 #include "block/qcow2.h"
29 #include "qemu/error-report.h"
31 void qcow2_free_snapshots(BlockDriverState *bs)
33 BDRVQcow2State *s = bs->opaque;
34 int i;
36 for(i = 0; i < s->nb_snapshots; i++) {
37 g_free(s->snapshots[i].name);
38 g_free(s->snapshots[i].id_str);
40 g_free(s->snapshots);
41 s->snapshots = NULL;
42 s->nb_snapshots = 0;
45 int qcow2_read_snapshots(BlockDriverState *bs)
47 BDRVQcow2State *s = bs->opaque;
48 QCowSnapshotHeader h;
49 QCowSnapshotExtraData extra;
50 QCowSnapshot *sn;
51 int i, id_str_size, name_size;
52 int64_t offset;
53 uint32_t extra_data_size;
54 int ret;
56 if (!s->nb_snapshots) {
57 s->snapshots = NULL;
58 s->snapshots_size = 0;
59 return 0;
62 offset = s->snapshots_offset;
63 s->snapshots = g_new0(QCowSnapshot, s->nb_snapshots);
65 for(i = 0; i < s->nb_snapshots; i++) {
66 /* Read statically sized part of the snapshot header */
67 offset = align_offset(offset, 8);
68 ret = bdrv_pread(bs->file->bs, offset, &h, sizeof(h));
69 if (ret < 0) {
70 goto fail;
73 offset += sizeof(h);
74 sn = s->snapshots + i;
75 sn->l1_table_offset = be64_to_cpu(h.l1_table_offset);
76 sn->l1_size = be32_to_cpu(h.l1_size);
77 sn->vm_state_size = be32_to_cpu(h.vm_state_size);
78 sn->date_sec = be32_to_cpu(h.date_sec);
79 sn->date_nsec = be32_to_cpu(h.date_nsec);
80 sn->vm_clock_nsec = be64_to_cpu(h.vm_clock_nsec);
81 extra_data_size = be32_to_cpu(h.extra_data_size);
83 id_str_size = be16_to_cpu(h.id_str_size);
84 name_size = be16_to_cpu(h.name_size);
86 /* Read extra data */
87 ret = bdrv_pread(bs->file->bs, offset, &extra,
88 MIN(sizeof(extra), extra_data_size));
89 if (ret < 0) {
90 goto fail;
92 offset += extra_data_size;
94 if (extra_data_size >= 8) {
95 sn->vm_state_size = be64_to_cpu(extra.vm_state_size_large);
98 if (extra_data_size >= 16) {
99 sn->disk_size = be64_to_cpu(extra.disk_size);
100 } else {
101 sn->disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;
104 /* Read snapshot ID */
105 sn->id_str = g_malloc(id_str_size + 1);
106 ret = bdrv_pread(bs->file->bs, offset, sn->id_str, id_str_size);
107 if (ret < 0) {
108 goto fail;
110 offset += id_str_size;
111 sn->id_str[id_str_size] = '\0';
113 /* Read snapshot name */
114 sn->name = g_malloc(name_size + 1);
115 ret = bdrv_pread(bs->file->bs, offset, sn->name, name_size);
116 if (ret < 0) {
117 goto fail;
119 offset += name_size;
120 sn->name[name_size] = '\0';
122 if (offset - s->snapshots_offset > QCOW_MAX_SNAPSHOTS_SIZE) {
123 ret = -EFBIG;
124 goto fail;
128 assert(offset - s->snapshots_offset <= INT_MAX);
129 s->snapshots_size = offset - s->snapshots_offset;
130 return 0;
132 fail:
133 qcow2_free_snapshots(bs);
134 return ret;
137 /* add at the end of the file a new list of snapshots */
138 static int qcow2_write_snapshots(BlockDriverState *bs)
140 BDRVQcow2State *s = bs->opaque;
141 QCowSnapshot *sn;
142 QCowSnapshotHeader h;
143 QCowSnapshotExtraData extra;
144 int i, name_size, id_str_size, snapshots_size;
145 struct {
146 uint32_t nb_snapshots;
147 uint64_t snapshots_offset;
148 } QEMU_PACKED header_data;
149 int64_t offset, snapshots_offset = 0;
150 int ret;
152 /* compute the size of the snapshots */
153 offset = 0;
154 for(i = 0; i < s->nb_snapshots; i++) {
155 sn = s->snapshots + i;
156 offset = align_offset(offset, 8);
157 offset += sizeof(h);
158 offset += sizeof(extra);
159 offset += strlen(sn->id_str);
160 offset += strlen(sn->name);
162 if (offset > QCOW_MAX_SNAPSHOTS_SIZE) {
163 ret = -EFBIG;
164 goto fail;
168 assert(offset <= INT_MAX);
169 snapshots_size = offset;
171 /* Allocate space for the new snapshot list */
172 snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size);
173 offset = snapshots_offset;
174 if (offset < 0) {
175 ret = offset;
176 goto fail;
178 ret = bdrv_flush(bs);
179 if (ret < 0) {
180 goto fail;
183 /* The snapshot list position has not yet been updated, so these clusters
184 * must indeed be completely free */
185 ret = qcow2_pre_write_overlap_check(bs, 0, offset, snapshots_size);
186 if (ret < 0) {
187 goto fail;
191 /* Write all snapshots to the new list */
192 for(i = 0; i < s->nb_snapshots; i++) {
193 sn = s->snapshots + i;
194 memset(&h, 0, sizeof(h));
195 h.l1_table_offset = cpu_to_be64(sn->l1_table_offset);
196 h.l1_size = cpu_to_be32(sn->l1_size);
197 /* If it doesn't fit in 32 bit, older implementations should treat it
198 * as a disk-only snapshot rather than truncate the VM state */
199 if (sn->vm_state_size <= 0xffffffff) {
200 h.vm_state_size = cpu_to_be32(sn->vm_state_size);
202 h.date_sec = cpu_to_be32(sn->date_sec);
203 h.date_nsec = cpu_to_be32(sn->date_nsec);
204 h.vm_clock_nsec = cpu_to_be64(sn->vm_clock_nsec);
205 h.extra_data_size = cpu_to_be32(sizeof(extra));
207 memset(&extra, 0, sizeof(extra));
208 extra.vm_state_size_large = cpu_to_be64(sn->vm_state_size);
209 extra.disk_size = cpu_to_be64(sn->disk_size);
211 id_str_size = strlen(sn->id_str);
212 name_size = strlen(sn->name);
213 assert(id_str_size <= UINT16_MAX && name_size <= UINT16_MAX);
214 h.id_str_size = cpu_to_be16(id_str_size);
215 h.name_size = cpu_to_be16(name_size);
216 offset = align_offset(offset, 8);
218 ret = bdrv_pwrite(bs->file->bs, offset, &h, sizeof(h));
219 if (ret < 0) {
220 goto fail;
222 offset += sizeof(h);
224 ret = bdrv_pwrite(bs->file->bs, offset, &extra, sizeof(extra));
225 if (ret < 0) {
226 goto fail;
228 offset += sizeof(extra);
230 ret = bdrv_pwrite(bs->file->bs, offset, sn->id_str, id_str_size);
231 if (ret < 0) {
232 goto fail;
234 offset += id_str_size;
236 ret = bdrv_pwrite(bs->file->bs, offset, sn->name, name_size);
237 if (ret < 0) {
238 goto fail;
240 offset += name_size;
244 * Update the header to point to the new snapshot table. This requires the
245 * new table and its refcounts to be stable on disk.
247 ret = bdrv_flush(bs);
248 if (ret < 0) {
249 goto fail;
252 QEMU_BUILD_BUG_ON(offsetof(QCowHeader, snapshots_offset) !=
253 offsetof(QCowHeader, nb_snapshots) + sizeof(header_data.nb_snapshots));
255 header_data.nb_snapshots = cpu_to_be32(s->nb_snapshots);
256 header_data.snapshots_offset = cpu_to_be64(snapshots_offset);
258 ret = bdrv_pwrite_sync(bs->file->bs, offsetof(QCowHeader, nb_snapshots),
259 &header_data, sizeof(header_data));
260 if (ret < 0) {
261 goto fail;
264 /* free the old snapshot table */
265 qcow2_free_clusters(bs, s->snapshots_offset, s->snapshots_size,
266 QCOW2_DISCARD_SNAPSHOT);
267 s->snapshots_offset = snapshots_offset;
268 s->snapshots_size = snapshots_size;
269 return 0;
271 fail:
272 if (snapshots_offset > 0) {
273 qcow2_free_clusters(bs, snapshots_offset, snapshots_size,
274 QCOW2_DISCARD_ALWAYS);
276 return ret;
279 static void find_new_snapshot_id(BlockDriverState *bs,
280 char *id_str, int id_str_size)
282 BDRVQcow2State *s = bs->opaque;
283 QCowSnapshot *sn;
284 int i;
285 unsigned long id, id_max = 0;
287 for(i = 0; i < s->nb_snapshots; i++) {
288 sn = s->snapshots + i;
289 id = strtoul(sn->id_str, NULL, 10);
290 if (id > id_max)
291 id_max = id;
293 snprintf(id_str, id_str_size, "%lu", id_max + 1);
296 static int find_snapshot_by_id_and_name(BlockDriverState *bs,
297 const char *id,
298 const char *name)
300 BDRVQcow2State *s = bs->opaque;
301 int i;
303 if (id && name) {
304 for (i = 0; i < s->nb_snapshots; i++) {
305 if (!strcmp(s->snapshots[i].id_str, id) &&
306 !strcmp(s->snapshots[i].name, name)) {
307 return i;
310 } else if (id) {
311 for (i = 0; i < s->nb_snapshots; i++) {
312 if (!strcmp(s->snapshots[i].id_str, id)) {
313 return i;
316 } else if (name) {
317 for (i = 0; i < s->nb_snapshots; i++) {
318 if (!strcmp(s->snapshots[i].name, name)) {
319 return i;
324 return -1;
327 static int find_snapshot_by_id_or_name(BlockDriverState *bs,
328 const char *id_or_name)
330 int ret;
332 ret = find_snapshot_by_id_and_name(bs, id_or_name, NULL);
333 if (ret >= 0) {
334 return ret;
336 return find_snapshot_by_id_and_name(bs, NULL, id_or_name);
339 /* if no id is provided, a new one is constructed */
340 int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
342 BDRVQcow2State *s = bs->opaque;
343 QCowSnapshot *new_snapshot_list = NULL;
344 QCowSnapshot *old_snapshot_list = NULL;
345 QCowSnapshot sn1, *sn = &sn1;
346 int i, ret;
347 uint64_t *l1_table = NULL;
348 int64_t l1_table_offset;
350 if (s->nb_snapshots >= QCOW_MAX_SNAPSHOTS) {
351 return -EFBIG;
354 memset(sn, 0, sizeof(*sn));
356 /* Generate an ID */
357 find_new_snapshot_id(bs, sn_info->id_str, sizeof(sn_info->id_str));
359 /* Check that the ID is unique */
360 if (find_snapshot_by_id_and_name(bs, sn_info->id_str, NULL) >= 0) {
361 return -EEXIST;
364 /* Populate sn with passed data */
365 sn->id_str = g_strdup(sn_info->id_str);
366 sn->name = g_strdup(sn_info->name);
368 sn->disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;
369 sn->vm_state_size = sn_info->vm_state_size;
370 sn->date_sec = sn_info->date_sec;
371 sn->date_nsec = sn_info->date_nsec;
372 sn->vm_clock_nsec = sn_info->vm_clock_nsec;
374 /* Allocate the L1 table of the snapshot and copy the current one there. */
375 l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t));
376 if (l1_table_offset < 0) {
377 ret = l1_table_offset;
378 goto fail;
381 sn->l1_table_offset = l1_table_offset;
382 sn->l1_size = s->l1_size;
384 l1_table = g_try_new(uint64_t, s->l1_size);
385 if (s->l1_size && l1_table == NULL) {
386 ret = -ENOMEM;
387 goto fail;
390 for(i = 0; i < s->l1_size; i++) {
391 l1_table[i] = cpu_to_be64(s->l1_table[i]);
394 ret = qcow2_pre_write_overlap_check(bs, 0, sn->l1_table_offset,
395 s->l1_size * sizeof(uint64_t));
396 if (ret < 0) {
397 goto fail;
400 ret = bdrv_pwrite(bs->file->bs, sn->l1_table_offset, l1_table,
401 s->l1_size * sizeof(uint64_t));
402 if (ret < 0) {
403 goto fail;
406 g_free(l1_table);
407 l1_table = NULL;
410 * Increase the refcounts of all clusters and make sure everything is
411 * stable on disk before updating the snapshot table to contain a pointer
412 * to the new L1 table.
414 ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1);
415 if (ret < 0) {
416 goto fail;
419 /* Append the new snapshot to the snapshot list */
420 new_snapshot_list = g_new(QCowSnapshot, s->nb_snapshots + 1);
421 if (s->snapshots) {
422 memcpy(new_snapshot_list, s->snapshots,
423 s->nb_snapshots * sizeof(QCowSnapshot));
424 old_snapshot_list = s->snapshots;
426 s->snapshots = new_snapshot_list;
427 s->snapshots[s->nb_snapshots++] = *sn;
429 ret = qcow2_write_snapshots(bs);
430 if (ret < 0) {
431 g_free(s->snapshots);
432 s->snapshots = old_snapshot_list;
433 s->nb_snapshots--;
434 goto fail;
437 g_free(old_snapshot_list);
439 /* The VM state isn't needed any more in the active L1 table; in fact, it
440 * hurts by causing expensive COW for the next snapshot. */
441 qcow2_discard_clusters(bs, qcow2_vm_state_offset(s),
442 align_offset(sn->vm_state_size, s->cluster_size)
443 >> BDRV_SECTOR_BITS,
444 QCOW2_DISCARD_NEVER, false);
446 #ifdef DEBUG_ALLOC
448 BdrvCheckResult result = {0};
449 qcow2_check_refcounts(bs, &result, 0);
451 #endif
452 return 0;
454 fail:
455 g_free(sn->id_str);
456 g_free(sn->name);
457 g_free(l1_table);
459 return ret;
462 /* copy the snapshot 'snapshot_name' into the current disk image */
463 int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
465 BDRVQcow2State *s = bs->opaque;
466 QCowSnapshot *sn;
467 int i, snapshot_index;
468 int cur_l1_bytes, sn_l1_bytes;
469 int ret;
470 uint64_t *sn_l1_table = NULL;
472 /* Search the snapshot */
473 snapshot_index = find_snapshot_by_id_or_name(bs, snapshot_id);
474 if (snapshot_index < 0) {
475 return -ENOENT;
477 sn = &s->snapshots[snapshot_index];
479 if (sn->disk_size != bs->total_sectors * BDRV_SECTOR_SIZE) {
480 error_report("qcow2: Loading snapshots with different disk "
481 "size is not implemented");
482 ret = -ENOTSUP;
483 goto fail;
487 * Make sure that the current L1 table is big enough to contain the whole
488 * L1 table of the snapshot. If the snapshot L1 table is smaller, the
489 * current one must be padded with zeros.
491 ret = qcow2_grow_l1_table(bs, sn->l1_size, true);
492 if (ret < 0) {
493 goto fail;
496 cur_l1_bytes = s->l1_size * sizeof(uint64_t);
497 sn_l1_bytes = sn->l1_size * sizeof(uint64_t);
500 * Copy the snapshot L1 table to the current L1 table.
502 * Before overwriting the old current L1 table on disk, make sure to
503 * increase all refcounts for the clusters referenced by the new one.
504 * Decrease the refcount referenced by the old one only when the L1
505 * table is overwritten.
507 sn_l1_table = g_try_malloc0(cur_l1_bytes);
508 if (cur_l1_bytes && sn_l1_table == NULL) {
509 ret = -ENOMEM;
510 goto fail;
513 ret = bdrv_pread(bs->file->bs, sn->l1_table_offset,
514 sn_l1_table, sn_l1_bytes);
515 if (ret < 0) {
516 goto fail;
519 ret = qcow2_update_snapshot_refcount(bs, sn->l1_table_offset,
520 sn->l1_size, 1);
521 if (ret < 0) {
522 goto fail;
525 ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_ACTIVE_L1,
526 s->l1_table_offset, cur_l1_bytes);
527 if (ret < 0) {
528 goto fail;
531 ret = bdrv_pwrite_sync(bs->file->bs, s->l1_table_offset, sn_l1_table,
532 cur_l1_bytes);
533 if (ret < 0) {
534 goto fail;
538 * Decrease refcount of clusters of current L1 table.
540 * At this point, the in-memory s->l1_table points to the old L1 table,
541 * whereas on disk we already have the new one.
543 * qcow2_update_snapshot_refcount special cases the current L1 table to use
544 * the in-memory data instead of really using the offset to load a new one,
545 * which is why this works.
547 ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset,
548 s->l1_size, -1);
551 * Now update the in-memory L1 table to be in sync with the on-disk one. We
552 * need to do this even if updating refcounts failed.
554 for(i = 0;i < s->l1_size; i++) {
555 s->l1_table[i] = be64_to_cpu(sn_l1_table[i]);
558 if (ret < 0) {
559 goto fail;
562 g_free(sn_l1_table);
563 sn_l1_table = NULL;
566 * Update QCOW_OFLAG_COPIED in the active L1 table (it may have changed
567 * when we decreased the refcount of the old snapshot.
569 ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0);
570 if (ret < 0) {
571 goto fail;
574 #ifdef DEBUG_ALLOC
576 BdrvCheckResult result = {0};
577 qcow2_check_refcounts(bs, &result, 0);
579 #endif
580 return 0;
582 fail:
583 g_free(sn_l1_table);
584 return ret;
587 int qcow2_snapshot_delete(BlockDriverState *bs,
588 const char *snapshot_id,
589 const char *name,
590 Error **errp)
592 BDRVQcow2State *s = bs->opaque;
593 QCowSnapshot sn;
594 int snapshot_index, ret;
596 /* Search the snapshot */
597 snapshot_index = find_snapshot_by_id_and_name(bs, snapshot_id, name);
598 if (snapshot_index < 0) {
599 error_setg(errp, "Can't find the snapshot");
600 return -ENOENT;
602 sn = s->snapshots[snapshot_index];
604 /* Remove it from the snapshot list */
605 memmove(s->snapshots + snapshot_index,
606 s->snapshots + snapshot_index + 1,
607 (s->nb_snapshots - snapshot_index - 1) * sizeof(sn));
608 s->nb_snapshots--;
609 ret = qcow2_write_snapshots(bs);
610 if (ret < 0) {
611 error_setg_errno(errp, -ret,
612 "Failed to remove snapshot from snapshot list");
613 return ret;
617 * The snapshot is now unused, clean up. If we fail after this point, we
618 * won't recover but just leak clusters.
620 g_free(sn.id_str);
621 g_free(sn.name);
624 * Now decrease the refcounts of clusters referenced by the snapshot and
625 * free the L1 table.
627 ret = qcow2_update_snapshot_refcount(bs, sn.l1_table_offset,
628 sn.l1_size, -1);
629 if (ret < 0) {
630 error_setg_errno(errp, -ret, "Failed to free the cluster and L1 table");
631 return ret;
633 qcow2_free_clusters(bs, sn.l1_table_offset, sn.l1_size * sizeof(uint64_t),
634 QCOW2_DISCARD_SNAPSHOT);
636 /* must update the copied flag on the current cluster offsets */
637 ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 0);
638 if (ret < 0) {
639 error_setg_errno(errp, -ret,
640 "Failed to update snapshot status in disk");
641 return ret;
644 #ifdef DEBUG_ALLOC
646 BdrvCheckResult result = {0};
647 qcow2_check_refcounts(bs, &result, 0);
649 #endif
650 return 0;
653 int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
655 BDRVQcow2State *s = bs->opaque;
656 QEMUSnapshotInfo *sn_tab, *sn_info;
657 QCowSnapshot *sn;
658 int i;
660 if (!s->nb_snapshots) {
661 *psn_tab = NULL;
662 return s->nb_snapshots;
665 sn_tab = g_new0(QEMUSnapshotInfo, s->nb_snapshots);
666 for(i = 0; i < s->nb_snapshots; i++) {
667 sn_info = sn_tab + i;
668 sn = s->snapshots + i;
669 pstrcpy(sn_info->id_str, sizeof(sn_info->id_str),
670 sn->id_str);
671 pstrcpy(sn_info->name, sizeof(sn_info->name),
672 sn->name);
673 sn_info->vm_state_size = sn->vm_state_size;
674 sn_info->date_sec = sn->date_sec;
675 sn_info->date_nsec = sn->date_nsec;
676 sn_info->vm_clock_nsec = sn->vm_clock_nsec;
678 *psn_tab = sn_tab;
679 return s->nb_snapshots;
682 int qcow2_snapshot_load_tmp(BlockDriverState *bs,
683 const char *snapshot_id,
684 const char *name,
685 Error **errp)
687 int i, snapshot_index;
688 BDRVQcow2State *s = bs->opaque;
689 QCowSnapshot *sn;
690 uint64_t *new_l1_table;
691 int new_l1_bytes;
692 int ret;
694 assert(bs->read_only);
696 /* Search the snapshot */
697 snapshot_index = find_snapshot_by_id_and_name(bs, snapshot_id, name);
698 if (snapshot_index < 0) {
699 error_setg(errp,
700 "Can't find snapshot");
701 return -ENOENT;
703 sn = &s->snapshots[snapshot_index];
705 /* Allocate and read in the snapshot's L1 table */
706 if (sn->l1_size > QCOW_MAX_L1_SIZE / sizeof(uint64_t)) {
707 error_setg(errp, "Snapshot L1 table too large");
708 return -EFBIG;
710 new_l1_bytes = sn->l1_size * sizeof(uint64_t);
711 new_l1_table = qemu_try_blockalign(bs->file->bs,
712 align_offset(new_l1_bytes, 512));
713 if (new_l1_table == NULL) {
714 return -ENOMEM;
717 ret = bdrv_pread(bs->file->bs, sn->l1_table_offset,
718 new_l1_table, new_l1_bytes);
719 if (ret < 0) {
720 error_setg(errp, "Failed to read l1 table for snapshot");
721 qemu_vfree(new_l1_table);
722 return ret;
725 /* Switch the L1 table */
726 qemu_vfree(s->l1_table);
728 s->l1_size = sn->l1_size;
729 s->l1_table_offset = sn->l1_table_offset;
730 s->l1_table = new_l1_table;
732 for(i = 0;i < s->l1_size; i++) {
733 be64_to_cpus(&s->l1_table[i]);
736 return 0;