]> xenbits.xensource.com Git - libvirt.git/commitdiff
virfile: Make virFileGetXAttr report errors
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 22 Mar 2019 14:08:36 +0000 (15:08 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 3 Jul 2019 06:36:03 +0000 (08:36 +0200)
The way that security drivers use XATTR is kind of verbose. If
error reporting was left for caller then the caller would end up
even more verbose.

There are two places where we do not want to report error if
virFileGetXAttr fails. Therefore virFileGetXAttrQuiet is
introduced as an alternative that doesn't report errors.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/libvirt_private.syms
src/security/security_util.c
src/util/virfile.c
src/util/virfile.h
tests/qemusecuritymock.c

index 34937adc5df05a2ca0ef94efafabe76b9daa18ef..cf993f0c9c318d36021f1e12c9891bb171112d3a 100644 (file)
@@ -1908,6 +1908,7 @@ virFileGetHugepageSize;
 virFileGetMountReverseSubtree;
 virFileGetMountSubtree;
 virFileGetXAttr;
+virFileGetXAttrQuiet;
 virFileInData;
 virFileIsAbsPath;
 virFileIsCDROM;
index bfa78c6cca98829533ac16cdf010227982618b29..f09a18a6231152cc484e2ace0f5ecc83fabf34a5 100644 (file)
@@ -123,7 +123,7 @@ virSecurityGetRememberedLabel(const char *name,
     if (!(ref_name = virSecurityGetRefCountAttrName(name)))
         goto cleanup;
 
-    if (virFileGetXAttr(path, ref_name, &value) < 0) {
+    if (virFileGetXAttrQuiet(path, ref_name, &value) < 0) {
         if (errno == ENOSYS || errno == ENODATA || errno == ENOTSUP) {
             ret = 0;
         } else {
@@ -208,7 +208,7 @@ virSecuritySetRememberedLabel(const char *name,
     if (!(ref_name = virSecurityGetRefCountAttrName(name)))
         goto cleanup;
 
-    if (virFileGetXAttr(path, ref_name, &value) < 0) {
+    if (virFileGetXAttrQuiet(path, ref_name, &value) < 0) {
         if (errno == ENOSYS || errno == ENOTSUP) {
             ret = 0;
             goto cleanup;
index f7415cf63309ca85c2ac6b107d7e8b35cd323b15..00f69dce69bfa5b1ce9a37f3a69814b23a2cd68a 100644 (file)
@@ -4364,7 +4364,7 @@ virFileWaitForExists(const char *path,
 
 #if HAVE_LIBATTR
 /**
- * virFileGetXAttr;
+ * virFileGetXAttrQuiet;
  * @path: a filename
  * @name: name of xattr
  * @value: read value
@@ -4376,9 +4376,9 @@ virFileWaitForExists(const char *path,
  *         -1 otherwise (with errno set).
  */
 int
-virFileGetXAttr(const char *path,
-                const char *name,
-                char **value)
+virFileGetXAttrQuiet(const char *path,
+                     const char *name,
+                     char **value)
 {
     char *buf = NULL;
     int ret = -1;
@@ -4451,9 +4451,9 @@ virFileRemoveXAttr(const char *path,
 #else /* !HAVE_LIBATTR */
 
 int
-virFileGetXAttr(const char *path ATTRIBUTE_UNUSED,
-                const char *name ATTRIBUTE_UNUSED,
-                char **value ATTRIBUTE_UNUSED)
+virFileGetXAttrQuiet(const char *path ATTRIBUTE_UNUSED,
+                     const char *name ATTRIBUTE_UNUSED,
+                     char **value ATTRIBUTE_UNUSED)
 {
     errno = ENOSYS;
     return -1;
@@ -4477,3 +4477,31 @@ virFileRemoveXAttr(const char *path ATTRIBUTE_UNUSED,
 }
 
 #endif /* HAVE_LIBATTR */
+
+/**
+ * virFileGetXAttr;
+ * @path: a filename
+ * @name: name of xattr
+ * @value: read value
+ *
+ * Reads xattr with @name for given @path and stores it into
+ * @value. Caller is responsible for freeing @value.
+ *
+ * Returns: 0 on success,
+ *         -1 otherwise (with errno set AND error reported).
+ */
+int
+virFileGetXAttr(const char *path,
+                const char *name,
+                char **value)
+{
+    int ret;
+
+    if ((ret = virFileGetXAttrQuiet(path, name, value)) < 0) {
+        virReportSystemError(errno,
+                             _("Unable to get XATTR %s on %s"),
+                             name, path);
+    }
+
+    return ret;
+}
index 094c92e2b9e27c04ee900962251296fe827b7ff8..c2d1b36c85c58a552a6ce871368f0c2f7c150d05 100644 (file)
@@ -383,6 +383,11 @@ int virFileGetXAttr(const char *path,
                     char **value)
     ATTRIBUTE_NOINLINE;
 
+int virFileGetXAttrQuiet(const char *path,
+                         const char *name,
+                         char **value)
+    ATTRIBUTE_NOINLINE;
+
 int virFileSetXAttr(const char *path,
                     const char *name,
                     const char *value)
index 815bd44d7652c504a71d9d2fb7d567472324f908..e219a9f023fe967efd5f81b661ea84c733ea3642 100644 (file)
@@ -126,9 +126,9 @@ get_key(const char *path,
 
 
 int
-virFileGetXAttr(const char *path,
-                const char *name,
-                char **value)
+virFileGetXAttrQuiet(const char *path,
+                     const char *name,
+                     char **value)
 {
     int ret = -1;
     char *key;