summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPete Zaitcev <zaitcev@kotori.zaitcev.us>2017-05-23 17:45:43 -0600
committerThiago da Silva <thiago@redhat.com>2017-06-06 14:53:45 -0400
commit960cdd09dcabe5e125d8ee1c54fcc1f908e8ef11 (patch)
tree51e7d4237bedd2129b38fa3eb2b4733e59252fb0 /src
parentde984f59e7a6cca8c1f3cf1d93b87ff144a2b974 (diff)
downloadliberasurecode-960cdd09dcabe5e125d8ee1c54fcc1f908e8ef11.tar.gz
Stop using ceill() to compute padded data size
The well-known idiom to compute a required number of data blocks of size B to contain data of length d is: (d + (B-1))/B The code we use, with ceill(), computes the same value, but does it in an unorthodox way. This makes a reviewer to doubt himself and even run tests to make sure we're really computing the obvious thing. Apropos the reviewer confusion, the code in Phazr.IO looks weird. It uses (word_size - hamming_distance) to compute the necessary number of blocks... but then returns the amount of memory needed to store blocks of a different size (word_size). We left all of it alone and return exactly the same values that the old computation returned. All these computations were the only thing in the code that used -lm, so drop that too. Coincidentially, this patch solves the crash of distro-built packages of liberasurecode (see Red Hat bug #1454543). But it's a side effect. Expect a proper patch soon. Change-Id: Ib297f6df304abf5ca8c27d3392b1107a525e0be0
Diffstat (limited to 'src')
-rw-r--r--src/backends/phazrio/libphazr.c2
-rw-r--r--src/erasurecode.c8
-rw-r--r--src/erasurecode_helpers.c4
3 files changed, 7 insertions, 7 deletions
diff --git a/src/backends/phazrio/libphazr.c b/src/backends/phazrio/libphazr.c
index 74ad8ad..41ed74e 100644
--- a/src/backends/phazrio/libphazr.c
+++ b/src/backends/phazrio/libphazr.c
@@ -88,7 +88,7 @@ struct libphazr_descriptor {
static int get_padded_blocksize(int w, int hd, int blocksize)
{
int word_size = w / 8;
- return (int) ceill((double) blocksize / (word_size - hd)) * word_size;
+ return ((blocksize + ((word_size - hd) - 1)) / (word_size - hd)) * word_size;
}
static int pio_matrix_encode(void *desc, char **data, char **parity, int blocksize)
diff --git a/src/erasurecode.c b/src/erasurecode.c
index fb6d5de..d4a06c2 100644
--- a/src/erasurecode.c
+++ b/src/erasurecode.c
@@ -1194,8 +1194,8 @@ int liberasurecode_verify_stripe_metadata(int desc,
/**
* This computes the aligned size of a buffer passed into
* the encode function. The encode function must pad fragments
- * to be algined with the word size (w) and the last fragment also
- * needs to be aligned. This computes the sum of the algined fragment
+ * to be aligned with the word size (w) and the last fragment also
+ * needs to be aligned. This computes the sum of the aligned fragment
* sizes for a given buffer to encode.
*/
int liberasurecode_get_aligned_data_size(int desc, uint64_t data_len)
@@ -1218,8 +1218,8 @@ int liberasurecode_get_aligned_data_size(int desc, uint64_t data_len)
alignment_multiple = k * word_size;
- ret = (int) ceill( (double)
- data_len / alignment_multiple) * alignment_multiple;
+ ret = ((data_len + alignment_multiple - 1) / alignment_multiple)
+ * alignment_multiple;
out:
return ret;
diff --git a/src/erasurecode_helpers.c b/src/erasurecode_helpers.c
index 40db93c..fd14298 100644
--- a/src/erasurecode_helpers.c
+++ b/src/erasurecode_helpers.c
@@ -199,8 +199,8 @@ int get_aligned_data_size(ec_backend_t instance, int data_len)
alignment_multiple = k * word_size;
}
- aligned_size = (int)
- ceill((double) data_len / alignment_multiple) * alignment_multiple;
+ aligned_size = ((data_len + alignment_multiple - 1) / alignment_multiple)
+ * alignment_multiple;
return aligned_size;
}