Index: delta_diff_generator.cc |
diff --git a/delta_diff_generator.cc b/delta_diff_generator.cc |
index d0841388ec06b23b11a5f786294ff00d73a513d2..1477b35a1320289dd85df8b2fdf6644cf766d1e2 100644 |
--- a/delta_diff_generator.cc |
+++ b/delta_diff_generator.cc |
@@ -57,6 +57,7 @@ const size_t kBlockSize = 4096; // bytes |
const size_t kRootFSPartitionSize = 1 * 1024 * 1024 * 1024; // bytes |
petkov
2010/12/02 05:04:06
This is an obsolete dupe now? Remove.
adlr
2010/12/02 19:21:41
Oops missed this. I decided to use this and not ma
|
const uint64_t kVersionNumber = 1; |
const uint64_t kFullUpdateChunkSize = 1024 * 1024; // bytes |
+const uint64_t kRootfsPartitionSize = 1024 * 1024 * 1024; // bytes |
petkov
2010/12/02 05:04:06
Add a TODO to increase this to 2GiB when we stop c
adlr
2010/12/02 19:21:41
Done.
|
static const char* kInstallOperationTypes[] = { |
"REPLACE", |
@@ -1027,7 +1028,7 @@ bool AssignBlockForAdjoiningCuts( |
if (ranges.blocks() + scratch_blocks_found > blocks_needed) { |
// trim down ranges |
vector<Extent> new_ranges = ranges.GetExtentsForBlockCount( |
- blocks_needed - scratch_blocks_found); |
+ blocks_needed - scratch_blocks_found); |
ranges = ExtentRanges(); |
ranges.AddExtents(new_ranges); |
} |
@@ -1256,7 +1257,8 @@ bool DeltaDiffGenerator::ConvertGraphToDag(Graph* graph, |
const string& new_root, |
int fd, |
off_t* data_file_size, |
- vector<Vertex::Index>* final_order) { |
+ vector<Vertex::Index>* final_order, |
+ Vertex::Index scratch_vertex) { |
CycleBreaker cycle_breaker; |
LOG(INFO) << "Finding cycles..."; |
set<Edge> cut_edges; |
@@ -1297,12 +1299,32 @@ bool DeltaDiffGenerator::ConvertGraphToDag(Graph* graph, |
cuts)); |
LOG(INFO) << "Making sure all temp blocks have been allocated"; |
+ // Remove the scratch node, if any |
+ if (scratch_vertex != Vertex::kInvalidIndex) { |
+ final_order->erase(final_order->begin() + |
+ inverse_final_order[scratch_vertex]); |
+ (*graph)[scratch_vertex].valid = false; |
+ GenerateReverseTopoOrderMap(*final_order, &inverse_final_order); |
+ } |
+ |
graph_utils::DumpGraph(*graph); |
CHECK(NoTempBlocksRemain(*graph)); |
LOG(INFO) << "done making sure all temp blocks are allocated"; |
return true; |
} |
+void DeltaDiffGenerator::CreateScratchNode(uint64_t start_block, |
+ uint64_t num_blocks, |
+ Vertex* vertex) { |
+ vertex->file_name = "<scratch>"; |
+ vertex->op.set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ); |
+ vertex->op.set_data_offset(0); |
+ vertex->op.set_data_length(0); |
+ Extent* extent = vertex->op.add_dst_extents(); |
+ extent->set_start_block(start_block); |
+ extent->set_num_blocks(num_blocks); |
+} |
+ |
bool DeltaDiffGenerator::GenerateDeltaUpdateFile( |
const string& old_root, |
const string& old_image, |
@@ -1347,6 +1369,7 @@ bool DeltaDiffGenerator::GenerateDeltaUpdateFile( |
vector<DeltaArchiveManifest_InstallOperation> kernel_ops; |
vector<Vertex::Index> final_order; |
+ Vertex::Index scratch_vertex = Vertex::kInvalidIndex; |
{ |
int fd; |
TEST_AND_RETURN_FALSE( |
@@ -1372,6 +1395,15 @@ bool DeltaDiffGenerator::GenerateDeltaUpdateFile( |
new_image, |
&graph.back())); |
+ // Final scratch block (if there's space) |
+ if (blocks.size() < (kRootfsPartitionSize / kBlockSize)) { |
+ scratch_vertex = graph.size(); |
+ graph.resize(graph.size() + 1); |
+ CreateScratchNode(blocks.size(), |
+ (kRootfsPartitionSize / kBlockSize) - blocks.size(), |
+ &graph.back()); |
+ } |
+ |
// Read kernel partition |
TEST_AND_RETURN_FALSE(DeltaCompressKernelPartition(old_kernel_part, |
new_kernel_part, |
@@ -1391,7 +1423,8 @@ bool DeltaDiffGenerator::GenerateDeltaUpdateFile( |
new_root, |
fd, |
&data_file_size, |
- &final_order)); |
+ &final_order, |
+ scratch_vertex)); |
} else { |
// Full update |
off_t new_image_size = |