[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH parted 5/6] libparted: make pop/push update mode propagate sanity
From: |
Hans de Goede |
Subject: |
[PATCH parted 5/6] libparted: make pop/push update mode propagate sanity check errors |
Date: |
Thu, 10 Dec 2009 12:43:17 +0100 |
Sanity check errors indicate something is really really wrong, still
sometimes they happen, when they happen it helps a lot in debugging
them when the libparted caller immediately errors out at the first
moment, rather then slugging along until things crash somewere.
* libparted/disk.c(_disk_push_update_mode,_disk_pop_update_mode):
Change return value from void to int, and return 0 when the sanity
check calls fail.
* libparted/disk.c(*): Update all _disk_push_update_mode /
_disk_pop_update_mode callers to propagate the return value.
---
libparted/disk.c | 87 ++++++++++++++++++++++++++++++++++++------------------
1 files changed, 58 insertions(+), 29 deletions(-)
diff --git a/libparted/disk.c b/libparted/disk.c
index d14fe41..476ece8 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -54,8 +54,8 @@
#ifdef DEBUG
static int _disk_check_sanity (PedDisk* disk);
#endif
-static void _disk_push_update_mode (PedDisk* disk);
-static void _disk_pop_update_mode (PedDisk* disk);
+static int _disk_push_update_mode (PedDisk* disk);
+static int _disk_pop_update_mode (PedDisk* disk);
static int _disk_raw_insert_before (PedDisk* disk, PedPartition* loc,
PedPartition* part);
static int _disk_raw_insert_after (PedDisk* disk, PedPartition* loc,
@@ -222,9 +222,11 @@ _add_duplicate_part (PedDisk* disk, PedPartition* old_part)
goto error;
new_part->disk = disk;
- _disk_push_update_mode (disk);
+ if (!_disk_push_update_mode (disk))
+ goto error_destroy_new_part;
ret = _disk_raw_add (disk, new_part);
- _disk_pop_update_mode (disk);
+ if (!_disk_pop_update_mode (disk))
+ goto error_destroy_new_part;
if (!ret)
goto error_destroy_new_part;
#ifdef DEBUG
@@ -260,7 +262,8 @@ ped_disk_duplicate (const PedDisk* old_disk)
if (!new_disk)
goto error;
- _disk_push_update_mode (new_disk);
+ if (!_disk_push_update_mode (new_disk))
+ goto error_destroy_new_disk;
for (old_part = ped_disk_next_partition (old_disk, NULL); old_part;
old_part = ped_disk_next_partition (old_disk, old_part)) {
if (ped_partition_is_active (old_part)) {
@@ -270,7 +273,8 @@ ped_disk_duplicate (const PedDisk* old_disk)
}
}
}
- _disk_pop_update_mode (new_disk);
+ if (!_disk_pop_update_mode (new_disk))
+ goto error_destroy_new_disk;
return new_disk;
error_destroy_new_disk:
@@ -373,12 +377,15 @@ ped_disk_new_fresh (PedDevice* dev, const PedDiskType*
type)
disk = type->ops->alloc (dev);
if (!disk)
goto error;
- _disk_pop_update_mode (disk);
+ if (!_disk_pop_update_mode (disk))
+ goto error_destroy_disk;
PED_ASSERT (disk->update_mode == 0, ignored);
disk->needs_clobber = 1;
return disk;
+error_destroy_disk:
+ ped_disk_destroy (disk);
error:
return NULL;
}
@@ -1106,12 +1113,13 @@ _disk_alloc_freespace (PedDisk* disk)
* partitions are removed, making it much easier for various manipulation
* routines...
*/
-static void
+static int
_disk_push_update_mode (PedDisk* disk)
{
if (!disk->update_mode) {
#ifdef DEBUG
- _disk_check_sanity (disk);
+ if (!_disk_check_sanity (disk))
+ return 0;
#endif
_disk_remove_freespace (disk);
@@ -1119,24 +1127,27 @@ _disk_push_update_mode (PedDisk* disk)
_disk_remove_metadata (disk);
#ifdef DEBUG
- _disk_check_sanity (disk);
+ if (!_disk_check_sanity (disk))
+ return 0;
#endif
} else {
disk->update_mode++;
}
+ return 1;
}
-static void
+static int
_disk_pop_update_mode (PedDisk* disk)
{
- PED_ASSERT (disk->update_mode, return);
+ PED_ASSERT (disk->update_mode, return 0);
if (disk->update_mode == 1) {
/* re-allocate metadata BEFORE leaving update mode, to prevent infinite
* recursion (metadata allocation requires update mode)
*/
#ifdef DEBUG
- _disk_check_sanity (disk);
+ if (!_disk_check_sanity (disk))
+ return 0;
#endif
_disk_alloc_metadata (disk);
@@ -1144,11 +1155,13 @@ _disk_pop_update_mode (PedDisk* disk)
_disk_alloc_freespace (disk);
#ifdef DEBUG
- _disk_check_sanity (disk);
+ if (!_disk_check_sanity (disk))
+ return 0;
#endif
} else {
disk->update_mode--;
}
+ return 1;
}
/** @} */
@@ -1978,7 +1991,8 @@ ped_disk_add_partition (PedDisk* disk, PedPartition* part,
if (!_partition_check_basic_sanity (disk, part))
return 0;
- _disk_push_update_mode (disk);
+ if (!_disk_push_update_mode (disk))
+ return 0;
if (ped_partition_is_active (part)) {
overlap_constraint
@@ -2012,7 +2026,8 @@ ped_disk_add_partition (PedDisk* disk, PedPartition* part,
ped_constraint_destroy (overlap_constraint);
ped_constraint_destroy (constraints);
- _disk_pop_update_mode (disk);
+ if (!_disk_pop_update_mode (disk))
+ return 0;
#ifdef DEBUG
if (!_disk_check_sanity (disk))
return 0;
@@ -2041,10 +2056,12 @@ ped_disk_remove_partition (PedDisk* disk, PedPartition*
part)
PED_ASSERT (disk != NULL, return 0);
PED_ASSERT (part != NULL, return 0);
- _disk_push_update_mode (disk);
+ if (!_disk_push_update_mode (disk))
+ return 0;
PED_ASSERT (part->part_list == NULL, ignored);
_disk_raw_remove (disk, part);
- _disk_pop_update_mode (disk);
+ if (!_disk_pop_update_mode (disk))
+ return 0;
ped_disk_enumerate_partitions (disk);
return 1;
}
@@ -2063,12 +2080,14 @@ ped_disk_delete_partition (PedDisk* disk, PedPartition*
part)
PED_ASSERT (disk != NULL, return 0);
PED_ASSERT (part != NULL, return 0);
- _disk_push_update_mode (disk);
+ if (!_disk_push_update_mode (disk))
+ return 0;
if (part->type == PED_PARTITION_EXTENDED)
ped_disk_delete_all_logical (disk);
ped_disk_remove_partition (disk, part);
ped_partition_destroy (part);
- _disk_pop_update_mode (disk);
+ if (!_disk_pop_update_mode (disk))
+ return 0;
return 1;
}
@@ -2106,7 +2125,8 @@ ped_disk_delete_all (PedDisk* disk)
PED_ASSERT (disk != NULL, return 0);
- _disk_push_update_mode (disk);
+ if (!_disk_push_update_mode (disk))
+ return 0;
for (walk = disk->part_list; walk; walk = next) {
next = walk->next;
@@ -2115,7 +2135,8 @@ ped_disk_delete_all (PedDisk* disk)
return 0;
}
- _disk_pop_update_mode (disk);
+ if (!_disk_pop_update_mode (disk))
+ return 0;
return 1;
}
@@ -2149,7 +2170,8 @@ ped_disk_set_partition_geom (PedDisk* disk, PedPartition*
part,
old_geom = part->geom;
ped_geometry_init (&new_geom, part->geom.dev, start, end - start + 1);
- _disk_push_update_mode (disk);
+ if (!_disk_push_update_mode (disk))
+ return 0;
overlap_constraint
= _partition_get_overlap_constraint (part, &new_geom);
@@ -2172,7 +2194,8 @@ ped_disk_set_partition_geom (PedDisk* disk, PedPartition*
part,
_disk_raw_remove (disk, part);
_disk_raw_add (disk, part);
- _disk_pop_update_mode (disk);
+ if (!_disk_pop_update_mode (disk))
+ goto error;
ped_constraint_destroy (overlap_constraint);
ped_constraint_destroy (constraints);
@@ -2180,6 +2203,7 @@ ped_disk_set_partition_geom (PedDisk* disk, PedPartition*
part,
error_pop_update_mode:
_disk_pop_update_mode (disk);
+error:
ped_constraint_destroy (overlap_constraint);
ped_constraint_destroy (constraints);
part->geom = old_geom;
@@ -2218,7 +2242,8 @@ ped_disk_maximize_partition (PedDisk* disk, PedPartition*
part,
old_geom = part->geom;
- _disk_push_update_mode (disk);
+ if (!_disk_push_update_mode (disk))
+ return 0;
if (part->prev)
new_start = part->prev->geom.end + 1;
@@ -2234,7 +2259,8 @@ ped_disk_maximize_partition (PedDisk* disk, PedPartition*
part,
new_end))
goto error;
- _disk_pop_update_mode (disk);
+ if (!_disk_pop_update_mode (disk))
+ return 0;
return 1;
error:
@@ -2306,11 +2332,13 @@ ped_disk_minimize_extended_partition (PedDisk* disk)
if (!ext_part)
return 1;
- _disk_push_update_mode (disk);
+ if (!_disk_push_update_mode (disk))
+ return 0;
first_logical = ext_part->part_list;
if (!first_logical) {
- _disk_pop_update_mode (disk);
+ if (!_disk_pop_update_mode (disk))
+ return 0;
return ped_disk_delete_partition (disk, ext_part);
}
@@ -2323,7 +2351,8 @@ ped_disk_minimize_extended_partition (PedDisk* disk)
last_logical->geom.end);
ped_constraint_destroy (constraint);
- _disk_pop_update_mode (disk);
+ if (!_disk_pop_update_mode (disk))
+ return 0;
return status;
}
--
1.6.5.2
Re: [PATCH parted 1/6] parted.texi: Document --align option, Jim Meyering, 2009/12/10