1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-10 05:17:59 +03:00

virfile: Make virFileGetXAttr report errors

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>
This commit is contained in:
Michal Privoznik 2019-03-22 15:08:36 +01:00
parent 86e43ded42
commit 0d44d2876a
5 changed files with 46 additions and 12 deletions

View File

@ -1908,6 +1908,7 @@ virFileGetHugepageSize;
virFileGetMountReverseSubtree;
virFileGetMountSubtree;
virFileGetXAttr;
virFileGetXAttrQuiet;
virFileInData;
virFileIsAbsPath;
virFileIsCDROM;

View 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;

View 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;
}

View 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)

View 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;