Displaying 20 results from an estimated 22 matches for "random_state".
2018 Dec 28
2
[PATCH v2 nbdkit] common: Improve pseudo-random number generation.
v2:
- Fix seeding.
- Add a test that nbdkit-random-plugin is producing something
which looks at least somewhat random.
Rich.
2018 Dec 28
0
[PATCH v2 nbdkit] common: Improve pseudo-random number generation.
...t http://xoshiro.di.unimi.it/ . Specifically
+ * this is ‘xoshiro256** 1.0’.
+ *
+ * This does _NOT_ generate cryptographically secure random numbers
+ * (CSPRNG) and so should not be used when cryptography or security is
+ * required - use gcrypt if you need those.
+ */
+
+/* You can seed ‘struct random_state’ by setting the s[] elements
+ * directly - but not you must NOT set it all to zero. OR if you have
+ * a 64 bit seed, you can use xsrandom below to initialize the state.
+ */
+struct random_state {
+ uint64_t s[4];
+};
+
+static inline uint64_t
+snext (uint64_t *seed)
+{
+ uint64_t z = (*seed +...
2018 Dec 28
1
[PATCH nbdkit] common: Improve pseudo-random number generation.
...ebastiano Vigna at http://xoshiro.di.unimi.it/ . Specifically
+ * this is ‘xoshiro256** 1.0’.
+ *
+ * This does _NOT_ generate cryptographically secure random numbers
+ * (CSPRNG) and so should not be used when cryptography or security is
+ * required - use gcrypt if you need those.
+ */
+
+struct random_state {
+ uint64_t s[4];
+};
+
+static inline uint64_t
+rotl (const uint64_t x, int k)
+{
+ return (x << k) | (x >> (64 - k));
+}
+
+/* Returns 64 random bits. Updates the state. */
+uint64_t
+xrandom (struct random_state *state)
+{
+ const uint64_t result_starstar = rotl (state->s[1]...
2018 Dec 31
1
Re: [PATCH v2 nbdkit] common: Improve pseudo-random number generation.
...cally
> + * this is ‘xoshiro256** 1.0’.
> + *
> + * This does _NOT_ generate cryptographically secure random numbers
> + * (CSPRNG) and so should not be used when cryptography or security is
> + * required - use gcrypt if you need those.
> + */
> +
> +/* You can seed ‘struct random_state’ by setting the s[] elements
> + * directly - but not you must NOT set it all to zero. OR if you have
s/not you/note you/
> + * a 64 bit seed, you can use xsrandom below to initialize the state.
> + */
> +struct random_state {
> + uint64_t s[4];
> +};
> +
> +static inlin...
2020 Apr 15
0
[PATCH nbdkit 4/9] common/regions: Use new vector type to store the list of regions.
...struct file *files = NULL;
size_t nr_files = 0;
/* Virtual disk layout. */
-struct regions regions;
+regions the_regions;
/* Primary and secondary partition tables and extended boot records.
* Secondary PT is only used for GPT. EBR array of sectors is only
@@ -93,7 +93,7 @@ static struct random_state random_state;
static void
partitioning_load (void)
{
- init_regions (®ions);
+ init_regions (&the_regions);
parse_guid (DEFAULT_TYPE_GUID, type_guid);
xsrandom (time (NULL), &random_state);
}
@@ -110,7 +110,7 @@ partitioning_unload (void)
/* We don't need to free r...
2019 Apr 24
0
[nbdkit PATCH 4/4] filters: Check for mutex failures
.../filters/error/error.c
@@ -283,9 +283,10 @@ random_error (const struct error_settings *error_settings,
* representable in a 64 bit integer, and because we don't need all
* this precision anyway, let's work in 32 bits.
*/
- pthread_mutex_lock (&lock);
- rand = xrandom (&random_state) & UINT32_MAX;
- pthread_mutex_unlock (&lock);
+ {
+ ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&lock);
+ rand = xrandom (&random_state) & UINT32_MAX;
+ }
if (rand >= error_settings->rate * UINT32_MAX)
return false;
diff --git a/filters/log/log.c b/filters/log/log.c...
2019 Mar 19
0
[PATCH nbdkit 1/9] server: Implement extents/can_extents calls for plugins and filters.
...: disk[%zu] != expected type %" PRIu32 "\n",
+ j, type);
+ dump_extents_map (map);
+ exit (EXIT_FAILURE);
+ }
+ }
+
+ return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+ unsigned i;
+ uint64_t offset, length;
+ uint32_t type;
+ size_t j;
+ struct random_state random_state;
+ struct nbdkit_extents_map *map;
+
+ xsrandom (time (NULL), &random_state);
+
+ map = nbdkit_extents_new ();
+ assert (map != NULL);
+
+ for (i = 0; i < 1000; ++i) {
+ type = xrandom (&random_state);
+ type &= 3;
+ offset = xrandom (&random_state);
+...
2019 Feb 22
0
[PATCH nbdkit v3 4/4] Add linuxdisk plugin.
...ory, label, type, size parameters. */
+char *dir;
+const char *label;
+const char *type = "ext2";
+int64_t size;
+bool size_add_estimate; /* if size=+SIZE was used */
+
+/* Virtual disk. */
+static struct virtual_disk disk;
+
+/* Used to create a random GUID for the partition. */
+struct random_state random_state;
+
+static void
+linuxdisk_load (void)
+{
+ init_virtual_disk (&disk);
+ xsrandom (time (NULL), &random_state);
+}
+
+static void
+linuxdisk_unload (void)
+{
+ free_virtual_disk (&disk);
+ free (dir);
+}
+
+static int
+linuxdisk_config (const char *key, const char *valu...
2019 Jan 01
3
[PATCH nbdkit] include: Annotate function parameters with attribute((nonnull)).
Should we use attribute((nonnull)) at all? There's a very interesting
history of this in libvirt -- try looking at commit eefb881 plus the
commits referencing eefb881 -- but it does seem to work for me using
recent GCC and Clang.
I only did a few functions because annotating them gets old quickly...
Rich.
2019 Jan 21
0
[PATCH nbdkit v2 1/4] partitioning plugin: Support MBR logical partitions.
...rds.
+ * Secondary PT is only used for GPT. EBR array of sectors is only
+ * used for MBR with > 4 partitions and has length equal to nr_files-3.
+ */
+unsigned char *primary = NULL, *secondary = NULL, **ebr = NULL;
/* Used to generate random unique partition GUIDs for GPT. */
static struct random_state random_state;
@@ -106,12 +109,17 @@ partitioning_unload (void)
free (files);
/* We don't need to free regions.regions[].u.data because it points
- * to either primary or secondary which we free here.
+ * to primary, secondary or ebr which we free here.
*/
free_regions (&r...
2019 Jan 20
1
[PATCH nbdkit] partitioning: Support MBR logical partitions.
An evolution of the patch I posted yesterday to qemu-devel
(https://www.mail-archive.com/qemu-devel@nongnu.org/msg588920.html)
which (a) works and (b) has a test.
Rich.
2019 Feb 19
0
[PATCH nbdkit 4/4] Add linuxdisk plugin.
...disk.h"
+
+/* Directory, label, size parameters. */
+char **dirs;
+size_t nr_dirs;
+const char *label;
+int64_t size;
+bool size_add_estimate; /* if size=+SIZE was used */
+
+/* Virtual disk. */
+static struct virtual_disk disk;
+
+/* Used to create a random GUID for the partition. */
+struct random_state random_state;
+
+static void
+linuxdisk_load (void)
+{
+ load_filesystem ();
+ init_virtual_disk (&disk);
+ xsrandom (time (NULL), &random_state);
+}
+
+static void
+linuxdisk_unload (void)
+{
+ size_t i;
+
+ free_virtual_disk (&disk);
+
+ for (i = 0; i < nr_dirs; ++i)
+ fre...
2019 Apr 24
7
[nbdkit PATCH 0/4] More mutex sanity checking
I do have a question about whether patch 2 is right, or whether I've
exposed a bigger problem in the truncate (and possibly other) filter,
but the rest seem fairly straightforward.
Eric Blake (4):
server: Check for pthread lock failures
truncate: Factor out reading real_size under mutex
plugins: Check for mutex failures
filters: Check for mutex failures
filters/cache/cache.c
2019 Jan 02
0
[PATCH nbdkit v2 1/2] Annotate internal function parameters with attribute((nonnull)).
...andom.h
index eb08295..098c6d6 100644
--- a/common/include/random.h
+++ b/common/include/random.h
@@ -67,7 +67,7 @@ snext (uint64_t *seed)
}
/* Seed the random state from a 64 bit seed. */
-static inline void
+static inline void __attribute__((__nonnull__ (2)))
xsrandom (uint64_t seed, struct random_state *state)
{
state->s[0] = snext (&seed);
@@ -83,7 +83,7 @@ rotl (const uint64_t x, int k)
}
/* Returns 64 random bits. Updates the state. */
-static inline uint64_t
+static inline uint64_t __attribute__((__nonnull__ (1)))
xrandom (struct random_state *state)
{
const uint64_t resu...
2019 Feb 22
5
[PATCH nbdkit v3 0/4] Add linuxdisk plugin.
For v3 I reimplemented this using mke2fs -d. This obviously makes the
implementation a whole lot simpler, but cannot support multiple
directory merging.
Patches 1-3 are the same as before. I've also reproduced the notes
from v2 below.
v2:
- Fix inconsistent tab/space.
- All 3 plugins now contain a block of text pointing to the
other 2 plugins.
- TMDIR -> TMPDIR
- Unlink the
2019 Jan 02
4
[PATCH nbdkit v2 0/2] Use of attribute(()).
v1 was here:
https://www.redhat.com/archives/libguestfs/2019-January/msg00008.html
In v2 I have provided two patches:
The first patch extends attribute((nonnull)) to most internal
functions, but not to the external API.
The second patch uses a macro so that attribute((format)) is only used
in the public API on GCC or Clang. At least in theory these headers
could be used by a C compiler which
2019 Mar 19
15
[PATCH nbdkit 0/9] [mainly for discussion and early review] Implement extents.
I want to post this but mainly for discussion and early review. It's
not safe for these patches to all go upstream yet (because not all
filters have been checked/adjusted), but if any patches were to go
upstream then probably 1 & 2 only are safe.
File, VDDK, memory and data plugins all work, although I have only
done minimal testing on them.
The current tests, such as they are, all
2019 Feb 19
6
[PATCH nbdkit v2 0/5] Add linuxdisk plugin.
Another interesting thing you can do with this plugin:
https://rwmj.wordpress.com/2019/02/19/nbdkit-linuxdisk-plugin/
v2:
- Fix inconsistent tab/space.
- All 3 plugins now contain a block of text pointing to the
other 2 plugins.
- TMDIR -> TMPDIR
- Unlink the temporary file and other cleanups along error paths.
- fclose -> pclose, and check the return value for errors.
-
2019 Feb 19
7
[PATCH nbdkit 0/4] New plugin: Add linuxdisk plugin.
Turns out Japanese trains are good for coding!
In supermin we have a bunch of code to create the libguestfs
appliance. It creates it directly using libext2fs (part of
e2fsprogs). We can use the same technique to create ext2 virtual
disks in nbdkit, which is what this new plugin does. Why a new plugin
instead of modifying the floppy plugin? See the 4/4 commit message
for an explanation.
The
2019 Jan 21
8
[PATCH nbdkit v2 0/4] Support MBR logical partitions.
This is a revised version of the two series previously posted here:
https://www.redhat.com/archives/libguestfs/2019-January/msg00137.html
https://www.redhat.com/archives/libguestfs/2019-January/msg00139.html
There have been many smaller changes but the highlights are:
- Using SECTOR_SIZE instead of hard-coding 512 everywhere.
- Additional safety checks that the EBR chain doesn't
jump