From: Richard W.M. Jones Date: Wed, 26 Oct 2011 16:47:34 +0000 (+0100) Subject: libvirt: Detect if a disk has the flag. X-Git-Tag: 1.13.26~4 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=163f7df8452f5d7eb47039a98cd97d498528e4d5;p=libguestfs.git libvirt: Detect if a disk has the flag. This changes the private function guestfs___for_each_disk so that the flag on libvirt disks is detected and passed through to the callback function. --- diff --git a/df/domains.c b/df/domains.c index 5bc7c42..7a4e33c 100644 --- a/df/domains.c +++ b/df/domains.c @@ -93,7 +93,7 @@ free_domain (struct domain *domain) static void add_domains_by_id (virConnectPtr conn, int *ids, size_t n); static void add_domains_by_name (virConnectPtr conn, char **names, size_t n); static void add_domain (virDomainPtr dom); -static int add_disk (guestfs_h *g, const char *filename, const char *format, void *domain_vp); +static int add_disk (guestfs_h *g, const char *filename, const char *format, int readonly, void *domain_vp); static void multi_df (struct domain *, size_t n); void @@ -287,7 +287,8 @@ add_domain (virDomainPtr dom) } static int -add_disk (guestfs_h *g, const char *filename, const char *format, +add_disk (guestfs_h *g, + const char *filename, const char *format, int readonly, void *domain_vp) { struct domain *domain = domain_vp; diff --git a/generator/generator_c.ml b/generator/generator_c.ml index bfdea33..e6023b8 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -630,7 +630,7 @@ extern void *guestfs_safe_malloc (guestfs_h *g, size_t nbytes); extern void *guestfs_safe_calloc (guestfs_h *g, size_t n, size_t s); extern const char *guestfs_tmpdir (void); #ifdef GUESTFS_PRIVATE_FOR_EACH_DISK -extern int guestfs___for_each_disk (guestfs_h *g, virDomainPtr dom, int (*)(guestfs_h *g, const char *filename, const char *format, void *data), void *data); +extern int guestfs___for_each_disk (guestfs_h *g, virDomainPtr dom, int (*)(guestfs_h *g, const char *filename, const char *format, int readonly, void *data), void *data); #endif /* End of private functions. */ diff --git a/src/virt.c b/src/virt.c index cc11c68..e4bafa2 100644 --- a/src/virt.c +++ b/src/virt.c @@ -167,6 +167,7 @@ guestfs___for_each_disk (guestfs_h *g, virDomainPtr dom, int (*f) (guestfs_h *g, const char *filename, const char *format, + int readonly, void *data), void *data) { @@ -284,9 +285,20 @@ guestfs___for_each_disk (guestfs_h *g, format = (char *) xmlNodeListGetString (doc, attr->children, 1); } + /* Get the flag. */ + xmlXPathObjectPtr xpreadonly; + + xpathCtx->node = nodes->nodeTab[i]; + xpreadonly = xmlXPathEvalExpression (BAD_CAST "./readonly", xpathCtx); + int readonly = 0; + if (xpreadonly != NULL && + xpreadonly->nodesetval && + xpreadonly->nodesetval->nodeNr > 0) + readonly = 1; + int t; if (f) - t = f (g, filename, format, data); + t = f (g, filename, format, readonly, data); else t = 0; @@ -294,6 +306,7 @@ guestfs___for_each_disk (guestfs_h *g, xmlFree (format); xmlXPathFreeObject (xpfilename); xmlXPathFreeObject (xpformat); + xmlXPathFreeObject (xpreadonly); if (t == -1) goto cleanup; @@ -320,7 +333,7 @@ guestfs___for_each_disk (guestfs_h *g, /* This was proposed as an external API, but it's not quite baked yet. */ -static int add_disk (guestfs_h *g, const char *filename, const char *format, void *optargs_vp); +static int add_disk (guestfs_h *g, const char *filename, const char *format, int readonly, void *optargs_vp); static int connect_live (guestfs_h *g, virDomainPtr dom); static int @@ -401,7 +414,8 @@ guestfs___add_libvirt_dom (guestfs_h *g, virDomainPtr dom, } static int -add_disk (guestfs_h *g, const char *filename, const char *format, +add_disk (guestfs_h *g, + const char *filename, const char *format, int readonly, void *optargs_vp) { struct guestfs_add_drive_opts_argv *optargs = optargs_vp;