conf: use disk source accessors in security/

Part of a series of cleanups to use new accessor methods.

* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Use accessors.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Eric Blake 2014-03-18 13:55:04 -06:00
parent cd01d2ad51
commit 2aad0ebe2d
2 changed files with 19 additions and 16 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2010-2013 Red Hat, Inc. * Copyright (C) 2010-2014 Red Hat, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -355,7 +355,7 @@ virSecurityDACSetSecurityImageLabel(virSecurityManagerPtr mgr,
if (!priv->dynamicOwnership) if (!priv->dynamicOwnership)
return 0; return 0;
if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_NETWORK)
return 0; return 0;
params[0] = mgr; params[0] = mgr;
@ -374,11 +374,12 @@ virSecurityDACRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr,
int migrated) int migrated)
{ {
virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr); virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
const char *src = virDomainDiskGetSource(disk);
if (!priv->dynamicOwnership) if (!priv->dynamicOwnership)
return 0; return 0;
if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_NETWORK)
return 0; return 0;
/* Don't restore labels on readoly/shared disks, because /* Don't restore labels on readoly/shared disks, because
@ -392,7 +393,7 @@ virSecurityDACRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr,
if (disk->readonly || disk->shared) if (disk->readonly || disk->shared)
return 0; return 0;
if (!disk->src) if (!src)
return 0; return 0;
/* If we have a shared FS & doing migrated, we must not /* If we have a shared FS & doing migrated, we must not
@ -401,17 +402,17 @@ virSecurityDACRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr,
* VM's I/O attempts :-) * VM's I/O attempts :-)
*/ */
if (migrated) { if (migrated) {
int rc = virStorageFileIsSharedFS(disk->src); int rc = virStorageFileIsSharedFS(src);
if (rc < 0) if (rc < 0)
return -1; return -1;
if (rc == 1) { if (rc == 1) {
VIR_DEBUG("Skipping image label restore on %s because FS is shared", VIR_DEBUG("Skipping image label restore on %s because FS is shared",
disk->src); src);
return 0; return 0;
} }
} }
return virSecurityDACRestoreSecurityFileLabel(disk->src); return virSecurityDACRestoreSecurityFileLabel(src);
} }
@ -904,7 +905,7 @@ virSecurityDACSetSecurityAllLabel(virSecurityManagerPtr mgr,
for (i = 0; i < def->ndisks; i++) { for (i = 0; i < def->ndisks; i++) {
/* XXX fixme - we need to recursively label the entire tree :-( */ /* XXX fixme - we need to recursively label the entire tree :-( */
if (def->disks[i]->type == VIR_DOMAIN_DISK_TYPE_DIR) if (virDomainDiskGetType(def->disks[i]) == VIR_DOMAIN_DISK_TYPE_DIR)
continue; continue;
if (virSecurityDACSetSecurityImageLabel(mgr, if (virSecurityDACSetSecurityImageLabel(mgr,
def, def,

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008-2013 Red Hat, Inc. * Copyright (C) 2008-2014 Red Hat, Inc.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -1133,6 +1133,7 @@ virSecuritySELinuxRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr,
{ {
virSecurityLabelDefPtr seclabel; virSecurityLabelDefPtr seclabel;
virSecurityDeviceLabelDefPtr disk_seclabel; virSecurityDeviceLabelDefPtr disk_seclabel;
const char *src = virDomainDiskGetSource(disk);
seclabel = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME); seclabel = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
if (seclabel == NULL) if (seclabel == NULL)
@ -1162,7 +1163,7 @@ virSecuritySELinuxRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr,
if (disk->readonly || disk->shared) if (disk->readonly || disk->shared)
return 0; return 0;
if (!disk->src || disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) if (!src || virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_NETWORK)
return 0; return 0;
/* If we have a shared FS & doing migrated, we must not /* If we have a shared FS & doing migrated, we must not
@ -1171,17 +1172,17 @@ virSecuritySELinuxRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr,
* VM's I/O attempts :-) * VM's I/O attempts :-)
*/ */
if (migrated) { if (migrated) {
int rc = virStorageFileIsSharedFS(disk->src); int rc = virStorageFileIsSharedFS(src);
if (rc < 0) if (rc < 0)
return -1; return -1;
if (rc == 1) { if (rc == 1) {
VIR_DEBUG("Skipping image label restore on %s because FS is shared", VIR_DEBUG("Skipping image label restore on %s because FS is shared",
disk->src); src);
return 0; return 0;
} }
} }
return virSecuritySELinuxRestoreSecurityFileLabel(mgr, disk->src); return virSecuritySELinuxRestoreSecurityFileLabel(mgr, src);
} }
@ -1262,7 +1263,7 @@ virSecuritySELinuxSetSecurityImageLabel(virSecurityManagerPtr mgr,
if (cbdata.secdef->norelabel) if (cbdata.secdef->norelabel)
return 0; return 0;
if (disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK) if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_NETWORK)
return 0; return 0;
return virDomainDiskDefForeachPath(disk, return virDomainDiskDefForeachPath(disk,
@ -2271,9 +2272,10 @@ virSecuritySELinuxSetSecurityAllLabel(virSecurityManagerPtr mgr,
for (i = 0; i < def->ndisks; i++) { for (i = 0; i < def->ndisks; i++) {
/* XXX fixme - we need to recursively label the entire tree :-( */ /* XXX fixme - we need to recursively label the entire tree :-( */
if (def->disks[i]->type == VIR_DOMAIN_DISK_TYPE_DIR) { if (virDomainDiskGetType(def->disks[i]) == VIR_DOMAIN_DISK_TYPE_DIR) {
VIR_WARN("Unable to relabel directory tree %s for disk %s", VIR_WARN("Unable to relabel directory tree %s for disk %s",
def->disks[i]->src, def->disks[i]->dst); virDomainDiskGetSource(def->disks[i]),
def->disks[i]->dst);
continue; continue;
} }
if (virSecuritySELinuxSetSecurityImageLabel(mgr, if (virSecuritySELinuxSetSecurityImageLabel(mgr,