virFileIsExecutable;
virFileIsLink;
virFileIsMountPoint;
+virFileIsSharedFS;
+virFileIsSharedFSType;
virFileLinkPointsTo;
virFileLock;
virFileLoopDeviceAssociate;
virStorageFileGetMetadataFromFD;
virStorageFileGetSCSIKey;
virStorageFileIsClusterFS;
-virStorageFileIsSharedFS;
-virStorageFileIsSharedFSType;
virStorageFileProbeFormat;
virStorageFileProbeFormatFromBuf;
virStorageFileResize;
bool bypass_security = false;
unsigned int vfoflags = 0;
int fd = -1;
- int path_shared = virStorageFileIsSharedFS(path);
+ int path_shared = virFileIsSharedFS(path);
uid_t uid = geteuid();
gid_t gid = getegid();
int rc;
if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_FILE) {
- if ((rc = virStorageFileIsSharedFS(src)) < 0)
+ if ((rc = virFileIsSharedFS(src)) < 0)
return false;
else if (rc == 0)
continue;
* VM's I/O attempts :-)
*/
if (migrated) {
- int rc = virStorageFileIsSharedFS(src);
+ int rc = virFileIsSharedFS(src);
if (rc < 0)
return -1;
if (rc == 1) {
return -1;
} else {
const char *msg;
- if ((virStorageFileIsSharedFSType(path,
- VIR_STORAGE_FILE_SHFS_NFS) == 1) &&
+ if (virFileIsSharedFSType(path, VIR_FILE_SHFS_NFS) == 1 &&
security_get_boolean_active("virt_use_nfs") != 1) {
msg = _("Setting security context '%s' on '%s' not supported. "
"Consider setting virt_use_nfs");
* VM's I/O attempts :-)
*/
if (migrated) {
- int rc = virStorageFileIsSharedFS(src);
+ int rc = virFileIsSharedFS(src);
if (rc < 0)
return -1;
if (rc == 1) {
if (stdin_path) {
if (virSecuritySELinuxSetFilecon(stdin_path, data->content_context) < 0 &&
- virStorageFileIsSharedFSType(stdin_path,
- VIR_STORAGE_FILE_SHFS_NFS) != 1)
+ virFileIsSharedFSType(stdin_path, VIR_FILE_SHFS_NFS) != 1)
return -1;
}
# include <sys/mman.h>
#endif
+#ifdef __linux__
+# if HAVE_LINUX_MAGIC_H
+# include <linux/magic.h>
+# endif
+# include <sys/statfs.h>
+#endif
+
#if defined(__linux__) && HAVE_DECL_LO_FLAGS_AUTOCLEAR
# include <linux/loop.h>
# include <sys/ioctl.h>
/* On Linux we can also verify the FS-type of the
* directory. (this is a NOP on other platforms). */
- if (virStorageFileIsSharedFS(path) <= 0)
+ if (virFileIsSharedFS(path) <= 0)
goto error;
}
return ret;
}
+
+
+#ifdef __linux__
+
+# ifndef NFS_SUPER_MAGIC
+# define NFS_SUPER_MAGIC 0x6969
+# endif
+# ifndef OCFS2_SUPER_MAGIC
+# define OCFS2_SUPER_MAGIC 0x7461636f
+# endif
+# ifndef GFS2_MAGIC
+# define GFS2_MAGIC 0x01161970
+# endif
+# ifndef AFS_FS_MAGIC
+# define AFS_FS_MAGIC 0x6B414653
+# endif
+# ifndef SMB_SUPER_MAGIC
+# define SMB_SUPER_MAGIC 0x517B
+# endif
+# ifndef CIFS_SUPER_MAGIC
+# define CIFS_SUPER_MAGIC 0xFF534D42
+# endif
+
+int
+virFileIsSharedFSType(const char *path,
+ int fstypes)
+{
+ char *dirpath, *p;
+ struct statfs sb;
+ int statfs_ret;
+
+ if (VIR_STRDUP(dirpath, path) < 0)
+ return -1;
+
+ do {
+
+ /* Try less and less of the path until we get to a
+ * directory we can stat. Even if we don't have 'x'
+ * permission on any directory in the path on the NFS
+ * server (assuming it's NFS), we will be able to stat the
+ * mount point, and that will properly tell us if the
+ * fstype is NFS.
+ */
+
+ if ((p = strrchr(dirpath, '/')) == NULL) {
+ virReportSystemError(EINVAL,
+ _("Invalid relative path '%s'"), path);
+ VIR_FREE(dirpath);
+ return -1;
+ }
+
+ if (p == dirpath)
+ *(p+1) = '\0';
+ else
+ *p = '\0';
+
+ statfs_ret = statfs(dirpath, &sb);
+
+ } while ((statfs_ret < 0) && (p != dirpath));
+
+ VIR_FREE(dirpath);
+
+ if (statfs_ret < 0) {
+ virReportSystemError(errno,
+ _("cannot determine filesystem for '%s'"),
+ path);
+ return -1;
+ }
+
+ VIR_DEBUG("Check if path %s with FS magic %lld is shared",
+ path, (long long int)sb.f_type);
+
+ if ((fstypes & VIR_FILE_SHFS_NFS) &&
+ (sb.f_type == NFS_SUPER_MAGIC))
+ return 1;
+
+ if ((fstypes & VIR_FILE_SHFS_GFS2) &&
+ (sb.f_type == GFS2_MAGIC))
+ return 1;
+ if ((fstypes & VIR_FILE_SHFS_OCFS) &&
+ (sb.f_type == OCFS2_SUPER_MAGIC))
+ return 1;
+ if ((fstypes & VIR_FILE_SHFS_AFS) &&
+ (sb.f_type == AFS_FS_MAGIC))
+ return 1;
+ if ((fstypes & VIR_FILE_SHFS_SMB) &&
+ (sb.f_type == SMB_SUPER_MAGIC))
+ return 1;
+ if ((fstypes & VIR_FILE_SHFS_CIFS) &&
+ (sb.f_type == CIFS_SUPER_MAGIC))
+ return 1;
+
+ return 0;
+}
+#else
+int virFileIsSharedFSType(const char *path ATTRIBUTE_UNUSED,
+ int fstypes ATTRIBUTE_UNUSED)
+{
+ /* XXX implement me :-) */
+ return 0;
+}
+#endif
+
+int virFileIsSharedFS(const char *path)
+{
+ return virFileIsSharedFSType(path,
+ VIR_FILE_SHFS_NFS |
+ VIR_FILE_SHFS_GFS2 |
+ VIR_FILE_SHFS_OCFS |
+ VIR_FILE_SHFS_AFS |
+ VIR_FILE_SHFS_SMB |
+ VIR_FILE_SHFS_CIFS);
+}
/*
* virfile.h: safer file handling
*
- * Copyright (C) 2010-2011, 2013 Red Hat, Inc.
+ * Copyright (C) 2010-2014 Red Hat, Inc.
* Copyright (C) 2010 IBM Corporation
* Copyright (C) 2010 Stefan Berger
* Copyright (C) 2010 Eric Blake
bool virFileExists(const char *file) ATTRIBUTE_NONNULL(1);
bool virFileIsExecutable(const char *file) ATTRIBUTE_NONNULL(1);
+enum {
+ VIR_FILE_SHFS_NFS = (1 << 0),
+ VIR_FILE_SHFS_GFS2 = (1 << 1),
+ VIR_FILE_SHFS_OCFS = (1 << 2),
+ VIR_FILE_SHFS_AFS = (1 << 3),
+ VIR_FILE_SHFS_SMB = (1 << 4),
+ VIR_FILE_SHFS_CIFS = (1 << 5),
+};
+
+int virFileIsSharedFSType(const char *path, int fstypes) ATTRIBUTE_NONNULL(1);
+int virFileIsSharedFS(const char *path) ATTRIBUTE_NONNULL(1);
int virFileIsMountPoint(const char *file) ATTRIBUTE_NONNULL(1);
int virFileGetMountSubtree(const char *mtabpath,
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
-#ifdef __linux__
-# if HAVE_LINUX_MAGIC_H
-# include <linux/magic.h>
-# endif
-# include <sys/statfs.h>
-#endif
#include "dirname.h"
#include "viralloc.h"
#include "virerror.h"
return ret;
}
-#ifdef __linux__
-
-# ifndef NFS_SUPER_MAGIC
-# define NFS_SUPER_MAGIC 0x6969
-# endif
-# ifndef OCFS2_SUPER_MAGIC
-# define OCFS2_SUPER_MAGIC 0x7461636f
-# endif
-# ifndef GFS2_MAGIC
-# define GFS2_MAGIC 0x01161970
-# endif
-# ifndef AFS_FS_MAGIC
-# define AFS_FS_MAGIC 0x6B414653
-# endif
-# ifndef SMB_SUPER_MAGIC
-# define SMB_SUPER_MAGIC 0x517B
-# endif
-# ifndef CIFS_SUPER_MAGIC
-# define CIFS_SUPER_MAGIC 0xFF534D42
-# endif
-
-
-int virStorageFileIsSharedFSType(const char *path,
- int fstypes)
-{
- char *dirpath, *p;
- struct statfs sb;
- int statfs_ret;
-
- if (VIR_STRDUP(dirpath, path) < 0)
- return -1;
-
- do {
-
- /* Try less and less of the path until we get to a
- * directory we can stat. Even if we don't have 'x'
- * permission on any directory in the path on the NFS
- * server (assuming it's NFS), we will be able to stat the
- * mount point, and that will properly tell us if the
- * fstype is NFS.
- */
-
- if ((p = strrchr(dirpath, '/')) == NULL) {
- virReportSystemError(EINVAL,
- _("Invalid relative path '%s'"), path);
- VIR_FREE(dirpath);
- return -1;
- }
-
- if (p == dirpath)
- *(p+1) = '\0';
- else
- *p = '\0';
-
- statfs_ret = statfs(dirpath, &sb);
-
- } while ((statfs_ret < 0) && (p != dirpath));
-
- VIR_FREE(dirpath);
-
- if (statfs_ret < 0) {
- virReportSystemError(errno,
- _("cannot determine filesystem for '%s'"),
- path);
- return -1;
- }
-
- VIR_DEBUG("Check if path %s with FS magic %lld is shared",
- path, (long long int)sb.f_type);
-
- 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;
- if ((fstypes & VIR_STORAGE_FILE_SHFS_SMB) &&
- (sb.f_type == SMB_SUPER_MAGIC))
- return 1;
- if ((fstypes & VIR_STORAGE_FILE_SHFS_CIFS) &&
- (sb.f_type == CIFS_SUPER_MAGIC))
- return 1;
-
- return 0;
-}
-#else
-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 |
- VIR_STORAGE_FILE_SHFS_SMB |
- VIR_STORAGE_FILE_SHFS_CIFS);
-}
int virStorageFileIsClusterFS(const char *path)
{
/* These are coherent cluster filesystems known to be safe for
* migration with cache != none
*/
- return virStorageFileIsSharedFSType(path,
- VIR_STORAGE_FILE_SHFS_GFS2 |
- VIR_STORAGE_FILE_SHFS_OCFS);
+ return virFileIsSharedFSType(path,
+ VIR_FILE_SHFS_GFS2 |
+ VIR_FILE_SHFS_OCFS);
}
#ifdef LVS
unsigned long long orig_capacity,
bool pre_allocate);
-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),
- VIR_STORAGE_FILE_SHFS_SMB = (1 << 4),
- VIR_STORAGE_FILE_SHFS_CIFS = (1 << 5),
-};
-
-int virStorageFileIsSharedFS(const char *path);
int virStorageFileIsClusterFS(const char *path);
-int virStorageFileIsSharedFSType(const char *path,
- int fstypes);
int virStorageFileGetLVMKey(const char *path,
char **key);