+int
+guestfs__set_network (guestfs_h *g, int v)
+{
+ g->enable_network = !!v;
+ return 0;
+}
+
+int
+guestfs__get_network (guestfs_h *g)
+{
+ return g->enable_network;
+}
+
+int
+guestfs__set_attach_method (guestfs_h *g, const char *method)
+{
+ if (STREQ (method, "appliance")) {
+ g->attach_method = ATTACH_METHOD_APPLIANCE;
+ free (g->attach_method_arg);
+ g->attach_method_arg = NULL;
+ }
+ else if (STRPREFIX (method, "unix:") && strlen (method) > 5) {
+ g->attach_method = ATTACH_METHOD_UNIX;
+ free (g->attach_method_arg);
+ g->attach_method_arg = safe_strdup (g, method + 5);
+ /* Note that we don't check the path exists until launch is called. */
+ }
+ else {
+ error (g, "invalid attach method: %s", method);
+ return -1;
+ }
+
+ return 0;
+}
+
+char *
+guestfs__get_attach_method (guestfs_h *g)
+{
+ char *ret;
+
+ switch (g->attach_method) {
+ case ATTACH_METHOD_APPLIANCE:
+ ret = safe_strdup (g, "appliance");
+ break;
+
+ case ATTACH_METHOD_UNIX:
+ ret = safe_malloc (g, strlen (g->attach_method_arg) + 5 + 1);
+ strcpy (ret, "unix:");
+ strcat (ret, g->attach_method_arg);
+ break;
+
+ default: /* keep GCC happy - this is not reached */
+ abort ();
+ }
+
+ return ret;
+}
+
+int
+guestfs__set_pgroup (guestfs_h *g, int v)
+{
+ g->pgroup = !!v;
+ return 0;
+}
+
+int
+guestfs__get_pgroup (guestfs_h *g)
+{
+ return g->pgroup;
+}
+
+int
+guestfs__set_smp (guestfs_h *g, int v)
+{
+ if (v >= 1) {
+ g->smp = v;
+ return 0;
+ } else {
+ error (g, "invalid smp parameter: %d", v);
+ return -1;
+ }
+}
+
+int
+guestfs__get_smp (guestfs_h *g)
+{
+ return g->smp;
+}
+
+/* Note the private data area is allocated lazily, since the vast
+ * majority of callers will never use it. This means g->pda is
+ * likely to be NULL.
+ */
+struct pda_entry {
+ char *key; /* key */
+ void *data; /* opaque user data pointer */
+};
+
+static size_t
+hasher (void const *x, size_t table_size)
+{
+ struct pda_entry const *p = x;
+ return hash_pjw (p->key, table_size);
+}
+
+static bool
+comparator (void const *x, void const *y)
+{
+ struct pda_entry const *a = x;
+ struct pda_entry const *b = y;
+ return STREQ (a->key, b->key);
+}
+
+static void
+freer (void *x)
+{
+ if (x) {
+ struct pda_entry *p = x;
+ free (p->key);
+ free (p);
+ }
+}
+
+void
+guestfs_set_private (guestfs_h *g, const char *key, void *data)
+{
+ if (g->pda == NULL) {
+ g->pda = hash_initialize (16, NULL, hasher, comparator, freer);
+ if (g->pda == NULL)
+ g->abort_cb ();
+ }
+
+ struct pda_entry *new_entry = safe_malloc (g, sizeof *new_entry);
+ new_entry->key = safe_strdup (g, key);
+ new_entry->data = data;
+
+ struct pda_entry *old_entry = hash_delete (g->pda, new_entry);
+ freer (old_entry);
+
+ struct pda_entry *entry = hash_insert (g->pda, new_entry);
+ if (entry == NULL)
+ g->abort_cb ();
+ assert (entry == new_entry);
+}
+
+static inline char *
+bad_cast (char const *s)
+{
+ return (char *) s;
+}
+
+void *
+guestfs_get_private (guestfs_h *g, const char *key)
+{
+ if (g->pda == NULL)
+ return NULL; /* no keys have been set */
+
+ const struct pda_entry k = { .key = bad_cast (key) };
+ struct pda_entry *entry = hash_lookup (g->pda, &k);
+ if (entry)
+ return entry->data;
+ else
+ return NULL;
+}
+
+/* Iterator. */
+void *
+guestfs_first_private (guestfs_h *g, const char **key_rtn)
+{
+ if (g->pda == NULL)
+ return NULL;
+
+ g->pda_next = hash_get_first (g->pda);
+
+ /* Ignore any keys with NULL data pointers. */
+ while (g->pda_next && g->pda_next->data == NULL)
+ g->pda_next = hash_get_next (g->pda, g->pda_next);
+
+ if (g->pda_next == NULL)
+ return NULL;
+
+ *key_rtn = g->pda_next->key;
+ return g->pda_next->data;
+}
+
+void *
+guestfs_next_private (guestfs_h *g, const char **key_rtn)
+{
+ if (g->pda == NULL)
+ return NULL;
+
+ if (g->pda_next == NULL)
+ return NULL;
+
+ /* Walk to the next key with a non-NULL data pointer. */
+ do {
+ g->pda_next = hash_get_next (g->pda, g->pda_next);
+ } while (g->pda_next && g->pda_next->data == NULL);
+
+ if (g->pda_next == NULL)
+ return NULL;
+
+ *key_rtn = g->pda_next->key;
+ return g->pda_next->data;
+}
+
+/* When tracing, be careful how we print BufferIn parameters which
+ * usually contain large amounts of binary data (RHBZ#646822).
+ */