Displaying 11 results from an estimated 11 matches for "new_bm_size_u64".
2018 Dec 01
2
[PATCH nbdkit] common: Move shared bitmap code to a common library.
I have some patches I'm working on to fix the cache filter.
However this is a prelude. It should be simply pure refactoring.
All tests pass still.
Rich.
2018 Jan 26
2
[PATCH nbdkit] filters: cache, cow: Handle bitmap overflow on 32 bit architectures.
...ap in bytes. */
-static uint64_t bm_size;
+static size_t bm_size;
enum bm_entry {
BLOCK_NOT_CACHED = 0,
@@ -167,7 +167,14 @@ blk_set_size (uint64_t new_size)
{
uint8_t *new_bm;
const size_t old_bm_size = bm_size;
- size_t new_bm_size = DIV_ROUND_UP (new_size, BLKSIZE*8/2);
+ uint64_t new_bm_size_u64 = DIV_ROUND_UP (new_size, BLKSIZE*8/2);
+ size_t new_bm_size;
+
+ if (new_bm_size_u64 > SIZE_MAX) {
+ nbdkit_error ("bitmap too large for this architecture");
+ return -1;
+ }
+ new_bm_size = (size_t) new_bm_size_u64;
new_bm = realloc (bitmap, new_bm_size);
if (new_bm...
2018 Dec 01
0
[PATCH nbdkit] common: Move shared bitmap code to a common library.
...+#include <string.h>
+#include <stdint.h>
+
+#include <nbdkit-plugin.h>
+
+#include "bitmap.h"
+#include "rounding.h"
+
+int
+bitmap_resize (struct bitmap *bm, uint64_t new_size)
+{
+ uint8_t *new_bitmap;
+ const size_t old_bm_size = bm->size;
+ uint64_t new_bm_size_u64;
+ size_t new_bm_size;
+
+ new_bm_size_u64 = DIV_ROUND_UP (new_size, bm->blksize * 8 / bm->bpb);
+ if (new_bm_size_u64 > SIZE_MAX) {
+ nbdkit_error ("bitmap too large for this architecture");
+ return -1;
+ }
+ new_bm_size = (size_t) new_bm_size_u64;
+
+ new_bitmap =...
2018 Dec 02
2
[PATCH nbdkit v2] common: Move shared bitmap code to a common library.
This is exactly the same as v1:
https://www.redhat.com/archives/libguestfs/2018-December/msg00004.html
except that it now frees the bitmap on unload (which the old code did
not - there was always a memory leak).
Rich.
2018 Dec 02
0
[PATCH nbdkit v2] common: Move shared bitmap code to a common library.
...+#include <string.h>
+#include <stdint.h>
+
+#include <nbdkit-plugin.h>
+
+#include "bitmap.h"
+#include "rounding.h"
+
+int
+bitmap_resize (struct bitmap *bm, uint64_t new_size)
+{
+ uint8_t *new_bitmap;
+ const size_t old_bm_size = bm->size;
+ uint64_t new_bm_size_u64;
+ size_t new_bm_size;
+
+ new_bm_size_u64 = DIV_ROUND_UP (new_size, bm->blksize * 8 / bm->bpb);
+ if (new_bm_size_u64 > SIZE_MAX) {
+ nbdkit_error ("bitmap too large for this architecture");
+ return -1;
+ }
+ new_bm_size = (size_t) new_bm_size_u64;
+
+ new_bitmap =...
2018 Dec 03
0
[PATCH nbdkit v3] common: Move shared bitmap code to a common library.
...+#include <string.h>
+#include <stdint.h>
+
+#include <nbdkit-plugin.h>
+
+#include "bitmap.h"
+#include "rounding.h"
+
+int
+bitmap_resize (struct bitmap *bm, uint64_t new_size)
+{
+ uint8_t *new_bitmap;
+ const size_t old_bm_size = bm->size;
+ uint64_t new_bm_size_u64;
+ size_t new_bm_size;
+
+ new_bm_size_u64 = DIV_ROUND_UP (new_size,
+ bm->blksize * UINT64_C(8) / bm->bpb);
+ if (new_bm_size_u64 > SIZE_MAX) {
+ nbdkit_error ("bitmap too large for this architecture");
+ return -1;
+ }
+ new_bm_size =...
2018 Dec 03
3
[PATCH nbdkit v3] common: Move shared bitmap code to a common library.
v2:
https://www.redhat.com/archives/libguestfs/2018-December/msg00039.html
v2 -> v3:
- Fix all the issues raised in Eric's review.
- Precompute some numbers to make the calculations easier.
- Calculations now use bitshifts and masks in preference to division
and modulo.
- Clear existing bits before setting (which fixes a bug in the cache
filter).
Rich.
2019 Sep 13
1
[PATCH nbdkit] common/bitmap: Don't fail on realloc (ptr, 0)
...2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/bitmap/bitmap.c b/common/bitmap/bitmap.c
index caac916..6bf04dc 100644
--- a/common/bitmap/bitmap.c
+++ b/common/bitmap/bitmap.c
@@ -60,7 +60,7 @@ bitmap_resize (struct bitmap *bm, uint64_t new_size)
new_bm_size = (size_t) new_bm_size_u64;
new_bitmap = realloc (bm->bitmap, new_bm_size);
- if (new_bitmap == NULL) {
+ if (new_bm_size && new_bitmap == NULL) {
nbdkit_error ("realloc: %m");
return -1;
}
--
2.23.0
2018 Dec 03
1
Re: [PATCH nbdkit v2] common: Move shared bitmap code to a common library.
...implemented). 'git config diff.orderFile /path/to/file'; see
qemu's scripts/git.orderfile for an example.
> +
> +int
> +bitmap_resize (struct bitmap *bm, uint64_t new_size)
> +{
> + uint8_t *new_bitmap;
> + const size_t old_bm_size = bm->size;
> + uint64_t new_bm_size_u64;
> + size_t new_bm_size;
> +
> + new_bm_size_u64 = DIV_ROUND_UP (new_size, bm->blksize * 8 / bm->bpb);
Can the computation of bm->blksize * 8 overflow? (blksize is 32-bit
unsigned; did initialization clamp block size to less than 512M?). But
appears to be unchanged in the ref...
2019 Sep 15
0
[PATCH nbdkit v2] common/bitmap: Don't fail on realloc (ptr, 0)
...les changed, 54 insertions(+), 4 deletions(-)
diff --git a/common/bitmap/bitmap.c b/common/bitmap/bitmap.c
index caac916..2cc625c 100644
--- a/common/bitmap/bitmap.c
+++ b/common/bitmap/bitmap.c
@@ -59,10 +59,16 @@ bitmap_resize (struct bitmap *bm, uint64_t new_size)
}
new_bm_size = (size_t) new_bm_size_u64;
- new_bitmap = realloc (bm->bitmap, new_bm_size);
- if (new_bitmap == NULL) {
- nbdkit_error ("realloc: %m");
- return -1;
+ if (new_bm_size > 0) {
+ new_bitmap = realloc (bm->bitmap, new_bm_size);
+ if (new_bitmap == NULL) {
+ nbdkit_error ("realloc:...
2019 Sep 15
2
[PATCH nbdkit v2] common/bitmap: Don't fail on realloc (ptr, 0)
v1 was here:
https://www.redhat.com/archives/libguestfs/2019-September/msg00100.html
In v2 I've changed the patch so it avoids calling realloc at all in
this case.
The patch is a bit longer this way. But I don't see any other
alternative if we are to avoid having a "realloc wrapper" of some kind
that we use everywhere, which I guess we should avoid because it makes
plugins