提交 86f71e0a 编写于 作者: E Eric Blake

conf: expose probe for non-local storage

Deciding if a user string represents a local file instead of a
network path is an operation worth exposing directly, particularly
since the next patch will be removing a redundant variable that
was caching the information.

* src/util/virstoragefile.h (virStorageIsFile): New declaration.
* src/util/virstoragefile.c (virBackingStoreIsFile): Rename...
(virStorageIsFile): ...export, and allow NULL input.
(virStorageFileGetMetadataInternal)
(virStorageFileGetMetadataRecurse, virStorageFileGetMetadata):
Update callers.
* src/conf/domain_conf.c (virDomainDiskDefForeachPath): Use it.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Likewise.
* src/libvirt_private.syms (virstoragefile.h): Export function.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 7010768c
...@@ -18565,7 +18565,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk, ...@@ -18565,7 +18565,7 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
goto cleanup; goto cleanup;
tmp = disk->backingChain; tmp = disk->backingChain;
while (tmp && tmp->backingStoreIsFile) { while (tmp && virStorageIsFile(tmp->backingStore)) {
if (!ignoreOpenFailure && !tmp->backingMeta) { if (!ignoreOpenFailure && !tmp->backingMeta) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unable to visit backing chain file %s"), _("unable to visit backing chain file %s"),
......
...@@ -1833,6 +1833,7 @@ virStorageFileIsClusterFS; ...@@ -1833,6 +1833,7 @@ virStorageFileIsClusterFS;
virStorageFileProbeFormat; virStorageFileProbeFormat;
virStorageFileProbeFormatFromBuf; virStorageFileProbeFormatFromBuf;
virStorageFileResize; virStorageFileResize;
virStorageIsFile;
virStorageNetHostDefClear; virStorageNetHostDefClear;
virStorageNetHostDefCopy; virStorageNetHostDefCopy;
virStorageNetHostDefFree; virStorageNetHostDefFree;
......
...@@ -118,7 +118,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target, ...@@ -118,7 +118,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
*backingStore = meta->backingStore; *backingStore = meta->backingStore;
meta->backingStore = NULL; meta->backingStore = NULL;
if (meta->backingStoreFormat == VIR_STORAGE_FILE_AUTO && if (meta->backingStoreFormat == VIR_STORAGE_FILE_AUTO &&
meta->backingStoreIsFile) { virStorageIsFile(*backingStore)) {
if ((ret = virStorageFileProbeFormat(*backingStore, -1, -1)) < 0) { if ((ret = virStorageFileProbeFormat(*backingStore, -1, -1)) < 0) {
/* If the backing file is currently unavailable, only log an error, /* If the backing file is currently unavailable, only log an error,
* but continue. Returning -1 here would disable the whole storage * but continue. Returning -1 here would disable the whole storage
......
...@@ -688,11 +688,17 @@ virStorageFileMatchesVersion(int format, ...@@ -688,11 +688,17 @@ virStorageFileMatchesVersion(int format,
return false; return false;
} }
static bool bool
virBackingStoreIsFile(const char *backing) virStorageIsFile(const char *backing)
{ {
char *colon = strchr(backing, ':'); char *colon;
char *slash = strchr(backing, '/'); char *slash;
if (!backing)
return false;
colon = strchr(backing, ':');
slash = strchr(backing, '/');
/* Reject anything that looks like a protocol (such as nbd: or /* Reject anything that looks like a protocol (such as nbd: or
* rbd:); if someone really does want a relative file name that * rbd:); if someone really does want a relative file name that
...@@ -866,7 +872,7 @@ virStorageFileGetMetadataInternal(const char *path, ...@@ -866,7 +872,7 @@ virStorageFileGetMetadataInternal(const char *path,
VIR_FREE(backing); VIR_FREE(backing);
goto cleanup; goto cleanup;
} }
if (virBackingStoreIsFile(backing)) { if (virStorageIsFile(backing)) {
meta->backingStoreIsFile = true; meta->backingStoreIsFile = true;
meta->backingStoreRaw = meta->backingStore; meta->backingStoreRaw = meta->backingStore;
meta->backingStore = NULL; meta->backingStore = NULL;
...@@ -1146,7 +1152,7 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath, ...@@ -1146,7 +1152,7 @@ virStorageFileGetMetadataRecurse(const char *path, const char *canonPath,
if (virHashAddEntry(cycle, canonPath, (void *)1) < 0) if (virHashAddEntry(cycle, canonPath, (void *)1) < 0)
return -1; return -1;
if (virBackingStoreIsFile(path)) { if (virStorageIsFile(path)) {
if ((fd = virFileOpenAs(canonPath, O_RDONLY, 0, uid, gid, 0)) < 0) { if ((fd = virFileOpenAs(canonPath, O_RDONLY, 0, uid, gid, 0)) < 0) {
virReportSystemError(-fd, _("Failed to open file '%s'"), path); virReportSystemError(-fd, _("Failed to open file '%s'"), path);
return -1; return -1;
...@@ -1235,7 +1241,7 @@ virStorageFileGetMetadata(const char *path, int format, ...@@ -1235,7 +1241,7 @@ virStorageFileGetMetadata(const char *path, int format,
if (!cycle) if (!cycle)
return NULL; return NULL;
if (virBackingStoreIsFile(path)) { if (virStorageIsFile(path)) {
if (!(canonPath = canonicalize_file_name(path))) { if (!(canonPath = canonicalize_file_name(path))) {
virReportSystemError(errno, _("unable to resolve '%s'"), path); virReportSystemError(errno, _("unable to resolve '%s'"), path);
goto cleanup; goto cleanup;
......
...@@ -315,6 +315,7 @@ int virStorageFileResize(const char *path, ...@@ -315,6 +315,7 @@ int virStorageFileResize(const char *path,
bool pre_allocate); bool pre_allocate);
int virStorageFileIsClusterFS(const char *path); int virStorageFileIsClusterFS(const char *path);
bool virStorageIsFile(const char *path);
int virStorageFileGetLVMKey(const char *path, int virStorageFileGetLVMKey(const char *path,
char **key); char **key);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册