提交 93a18bba 编写于 作者: D Daniel P. Berrange

Treat failure to relabel stdin_path as non-fatal on NFS

NFS does not support file labelling, so ignore this error
for stdin_path when on NFS.

* src/security/security_selinux.c: Ignore failures on labelling
  stdin_path on NFS
* src/util/storage_file.c, src/util/storage_file.h: Refine
  virStorageFileIsSharedFS() to allow it to check for a
  specific FS type.
上级 a51ccaf8
......@@ -689,6 +689,7 @@ virStorageFileFormatTypeToString;
virStorageFileGetMetadata;
virStorageFileGetMetadataFromFD;
virStorageFileIsSharedFS;
virStorageFileIsSharedFSType;
virStorageFileProbeFormat;
virStorageFileProbeFormatFromFD;
......
......@@ -1023,9 +1023,12 @@ SELinuxSetSecurityAllLabel(virSecurityDriverPtr drv,
SELinuxSetFilecon(vm->def->os.initrd, default_content_context) < 0)
return -1;
if (stdin_path &&
SELinuxSetFilecon(stdin_path, default_content_context) < 0)
if (stdin_path) {
if (SELinuxSetFilecon(stdin_path, default_content_context) < 0 &&
virStorageFileIsSharedFSType(stdin_path,
VIR_STORAGE_FILE_SHFS_NFS) != 1)
return -1;
}
return 0;
}
......
......@@ -804,7 +804,8 @@ virStorageFileGetMetadata(const char *path,
# endif
int virStorageFileIsSharedFS(const char *path)
int virStorageFileIsSharedFSType(const char *path,
int fstypes)
{
char *dirpath, *p;
struct statfs sb;
......@@ -853,19 +854,36 @@ int virStorageFileIsSharedFS(const char *path)
VIR_DEBUG("Check if path %s with FS magic %lld is shared",
path, (long long int)sb.f_type);
if (sb.f_type == NFS_SUPER_MAGIC ||
sb.f_type == GFS2_MAGIC ||
sb.f_type == OCFS2_SUPER_MAGIC ||
sb.f_type == AFS_FS_MAGIC) {
if ((fstypes & VIR_STORAGE_FILE_SHFS_NFS) &&
(sb.f_type == NFS_SUPER_MAGIC))
return 1;
if ((fstypes & VIR_STORAGE_FILE_SHFS_GFS2) &&
(sb.f_type == GFS2_MAGIC))
return 1;
if ((fstypes & VIR_STORAGE_FILE_SHFS_OCFS) &&
(sb.f_type == OCFS2_SUPER_MAGIC))
return 1;
if ((fstypes & VIR_STORAGE_FILE_SHFS_AFS) &&
(sb.f_type == AFS_FS_MAGIC))
return 1;
}
return 0;
}
#else
int virStorageFileIsSharedFS(const char *path ATTRIBUTE_UNUSED)
int virStorageFileIsSharedFSType(const char *path ATTRIBUTE_UNUSED,
int fstypes ATTRIBUTE_UNUSED)
{
/* XXX implement me :-) */
return 0;
}
#endif
int virStorageFileIsSharedFS(const char *path)
{
return virStorageFileIsSharedFSType(path,
VIR_STORAGE_FILE_SHFS_NFS |
VIR_STORAGE_FILE_SHFS_GFS2 |
VIR_STORAGE_FILE_SHFS_OCFS |
VIR_STORAGE_FILE_SHFS_AFS);
}
......@@ -68,6 +68,15 @@ int virStorageFileGetMetadataFromFD(const char *path,
int format,
virStorageFileMetadata *meta);
enum {
VIR_STORAGE_FILE_SHFS_NFS = (1 << 0),
VIR_STORAGE_FILE_SHFS_GFS2 = (1 << 1),
VIR_STORAGE_FILE_SHFS_OCFS = (1 << 2),
VIR_STORAGE_FILE_SHFS_AFS = (1 << 3),
};
int virStorageFileIsSharedFS(const char *path);
int virStorageFileIsSharedFSType(const char *path,
int fstypes);
#endif /* __VIR_STORAGE_FILE_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册