Re: [libvirt] Re: Reopening the old discussion about virDomainBlockPeek

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jun 06, 2008 at 05:01:20PM +0200, Jim Meyering wrote:
> "Richard W.M. Jones" <rjones@xxxxxxxxxx> wrote:
> > Attached is an updated patch.  The changes are:
> >  - updated to latest CVS
> >  - run make check / syntax-check
> >  - remove virsh subcommand (as per Dan's suggestion - see below)
> >  - some more things that Dan pointed out - see below
> ...
> > Index: src/xend_internal.c
> > ===================================================================
> ...
> > +    data.path = path;
> > +    data.ok = 0;
> > +
> > +    if (xend_parse_sexp_blockdevs (domain->conn, root,
> > +                                   priv->xendConfigVersion,
> > +                                   check_path, &data) == -1)
> > +        return -1;
> > +
> > +    if (!data.ok) {
> > +        virXendError (domain->conn, VIR_ERR_INVALID_ARG,
> > +                      _("invalid path"));
> > +        return -1;
> > +    }
> > +
> > +    /* The path is correct, now try to open it and get its size. */
> > +    fd = open (path, O_RDONLY);
> > +    if (fd == -1 || fstat (fd, &statbuf) == -1) {
> > +        virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
> > +        goto done;
> > +    }
> > +
> > +    /* Seek and read. */
> > +    /* NB. Because we configure with AC_SYS_LARGEFILE, off_t should
> > +     * be 64 bits on all platforms.
> > +     */
> > +    if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
> > +        saferead (fd, buffer, size) == (ssize_t) -1) {
> > +        virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
> > +        goto done;
> > +    }
> 
> Hi Rich,
> 
> Sorry it took so long.
> 
> This all looks fine.
> The only suggestion I can make is to include the "path"
> in the three diagnostics above.  I imagine it might otherwise
> be hard to understand what the diagnostic is talking about otherwise.

Suggested patch attached.

It seems a little bit perverse to have to put gettext around
"%s: %s" but that's what make syntax-check wants.

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
? scripts/Makefile
? scripts/Makefile.in
Index: src/xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.197
diff -u -p -r1.197 xend_internal.c
--- src/xend_internal.c	6 Jun 2008 11:09:57 -0000	1.197
+++ src/xend_internal.c	9 Jun 2008 09:47:12 -0000
@@ -160,25 +160,37 @@ struct xend {
 };
 
 
+static void virXendError(virConnectPtr conn, virErrorNumber error,
+                         const char *fmt, ...)
+    ATTRIBUTE_FORMAT(printf,3,4);
+
+#define MAX_ERROR_MESSAGE_LEN 1024
+
 /**
  * virXendError:
  * @conn: the connection if available
  * @error: the error number
- * @info: extra information string
+ * @fmt: format string followed by variable args
  *
  * Handle an error at the xend daemon interface
  */
 static void
-virXendError(virConnectPtr conn, virErrorNumber error, const char *info)
+virXendError(virConnectPtr conn, virErrorNumber error,
+             const char *fmt, ...)
 {
-    const char *errmsg;
+    va_list args;
+    char msg[MAX_ERROR_MESSAGE_LEN];
+    const char *msg2;
 
-    if (error == VIR_ERR_OK)
-        return;
+    if (fmt) {
+        va_start (args, fmt);
+        vsnprintf (msg, sizeof (msg), fmt, args);
+        va_end (args);
+    }
 
-    errmsg = __virErrorMsg(error, info);
+    msg2 = __virErrorMsg (error, fmt ? msg : NULL);
     __virRaiseError(conn, NULL, NULL, VIR_FROM_XEND, error, VIR_ERR_ERROR,
-                    errmsg, info, NULL, 0, 0, errmsg, info);
+                    msg2, msg, NULL, 0, 0, msg2, msg);
 }
 
 /**
@@ -490,7 +502,7 @@ xend_get(virConnectPtr xend, const char 
 
     if (((ret < 0) || (ret >= 300)) &&
         ((ret != 404) || (!STRPREFIX(path, "/xend/domain/")))) {
-        virXendError(xend, VIR_ERR_GET_FAILED, content);
+        virXendError(xend, VIR_ERR_GET_FAILED, "%s", content);
     }
 
     return ret;
@@ -539,16 +551,16 @@ xend_post(virConnectPtr xend, const char
     close(s);
 
     if ((ret < 0) || (ret >= 300)) {
-        virXendError(xend, VIR_ERR_POST_FAILED, content);
+        virXendError(xend, VIR_ERR_POST_FAILED, "%s", content);
     } else if ((ret == 202) && (strstr(content, "failed") != NULL)) {
-        virXendError(xend, VIR_ERR_POST_FAILED, content);
+        virXendError(xend, VIR_ERR_POST_FAILED, "%s", content);
         ret = -1;
     } else if (((ret >= 200) && (ret <= 202)) && (strstr(content, "xend.err") != NULL)) {
         /* This is to catch case of things like 'virsh dump Domain-0 foo'
          * which returns a success code, but the word 'xend.err'
          * in body to indicate error :-(
          */
-        virXendError(xend, VIR_ERR_POST_FAILED, content);
+        virXendError(xend, VIR_ERR_POST_FAILED, "%s", content);
         ret = -1;
     }
 
@@ -1026,7 +1038,7 @@ xenDaemonOpen_tcp(virConnectPtr conn, co
     pent = gethostbyname(host);
     if (pent == NULL) {
         if (inet_aton(host, &ip) == 0) {
-            virXendError(NULL, VIR_ERR_UNKNOWN_HOST, host);
+            virXendError(NULL, VIR_ERR_UNKNOWN_HOST, "%s", host);
             errno = ESRCH;
             return (-1);
         }
@@ -3925,12 +3937,14 @@ xenDaemonDomainMigratePrepare (virConnec
     if (uri_in == NULL) {
         r = gethostname (hostname, HOST_NAME_MAX+1);
         if (r == -1) {
-            virXendError (dconn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
+            virXendError (dconn, VIR_ERR_SYSTEM_ERROR,
+                          "%s", strerror (errno));
             return -1;
         }
         *uri_out = strdup (hostname);
         if (*uri_out == NULL) {
-            virXendError (dconn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
+            virXendError (dconn, VIR_ERR_SYSTEM_ERROR,
+                          "%s", strerror (errno));
             return -1;
         }
     }
@@ -4575,14 +4589,15 @@ xenDaemonDomainBlockPeek (virDomainPtr d
 
     if (!data.ok) {
         virXendError (domain->conn, VIR_ERR_INVALID_ARG,
-                      _("invalid path"));
+                      _("%s: invalid path"), path);
         return -1;
     }
 
     /* The path is correct, now try to open it and get its size. */
     fd = open (path, O_RDONLY);
     if (fd == -1) {
-        virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
+        virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR,
+                      _("%s: %s"), path, strerror (errno));
         goto done;
     }
 
@@ -4592,7 +4607,8 @@ xenDaemonDomainBlockPeek (virDomainPtr d
      */
     if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
         saferead (fd, buffer, size) == (ssize_t) -1) {
-        virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
+        virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR,
+                      _("%s: %s"), path, strerror (errno));
         goto done;
     }
 
--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]