virstoragefile: move virStorageFileResize into virfile

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Pavel Hrdina 2020-12-07 12:04:04 +01:00
parent e1894cf490
commit ec594462c1
6 changed files with 53 additions and 53 deletions

View File

@ -2121,6 +2121,7 @@ virFileRelLinkPointsTo;
virFileRemove;
virFileRemoveLastComponent;
virFileRemoveXAttr;
virFileResize;
virFileResolveAllLinks;
virFileResolveLink;
virFileRewrite;
@ -3150,7 +3151,6 @@ virStorageFileParseChainIndex;
virStorageFileProbeFormat;
virStorageFileRead;
virStorageFileReportBrokenChain;
virStorageFileResize;
virStorageFileStat;
virStorageFileSupportsAccess;
virStorageFileSupportsBackingChainTraversal;

View File

@ -2394,7 +2394,7 @@ virStorageBackendVolResizeLocal(virStoragePoolObjPtr pool,
VIR_STORAGE_VOL_RESIZE_SHRINK, -1);
if (vol->target.format == VIR_STORAGE_FILE_RAW && !vol->target.encryption) {
return virStorageFileResize(vol->target.path, capacity, pre_allocate);
return virFileResize(vol->target.path, capacity, pre_allocate);
} else if (vol->target.format == VIR_STORAGE_FILE_RAW && vol->target.encryption) {
if (pre_allocate) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",

View File

@ -557,6 +557,53 @@ virFileRewriteStr(const char *path,
}
/**
* virFileResize:
*
* Change the capacity of the raw storage file at 'path'.
*/
int
virFileResize(const char *path,
unsigned long long capacity,
bool pre_allocate)
{
int rc;
VIR_AUTOCLOSE fd = -1;
if ((fd = open(path, O_RDWR)) < 0) {
virReportSystemError(errno, _("Unable to open '%s'"), path);
return -1;
}
if (pre_allocate) {
if ((rc = virFileAllocate(fd, 0, capacity)) != 0) {
if (rc == -2) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("preallocate is not supported on this platform"));
} else {
virReportSystemError(errno,
_("Failed to pre-allocate space for "
"file '%s'"), path);
}
return -1;
}
}
if (ftruncate(fd, capacity) < 0) {
virReportSystemError(errno,
_("Failed to truncate file '%s'"), path);
return -1;
}
if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno, _("Unable to save '%s'"), path);
return -1;
}
return 0;
}
int virFileTouch(const char *path, mode_t mode)
{
int fd = -1;

View File

@ -133,6 +133,10 @@ int virFileRewriteStr(const char *path,
mode_t mode,
const char *str);
int virFileResize(const char *path,
unsigned long long capacity,
bool pre_allocate);
int virFileTouch(const char *path, mode_t mode);
int virFileUpdatePerm(const char *path,

View File

@ -1193,53 +1193,6 @@ virStorageFileGetMetadataFromFD(const char *path,
}
/**
* virStorageFileResize:
*
* Change the capacity of the raw storage file at 'path'.
*/
int
virStorageFileResize(const char *path,
unsigned long long capacity,
bool pre_allocate)
{
int rc;
VIR_AUTOCLOSE fd = -1;
if ((fd = open(path, O_RDWR)) < 0) {
virReportSystemError(errno, _("Unable to open '%s'"), path);
return -1;
}
if (pre_allocate) {
if ((rc = virFileAllocate(fd, 0, capacity)) != 0) {
if (rc == -2) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("preallocate is not supported on this platform"));
} else {
virReportSystemError(errno,
_("Failed to pre-allocate space for "
"file '%s'"), path);
}
return -1;
}
}
if (ftruncate(fd, capacity) < 0) {
virReportSystemError(errno,
_("Failed to truncate file '%s'"), path);
return -1;
}
if (VIR_CLOSE(fd) < 0) {
virReportSystemError(errno, _("Unable to save '%s'"), path);
return -1;
}
return 0;
}
int virStorageFileIsClusterFS(const char *path)
{
/* These are coherent cluster filesystems known to be safe for

View File

@ -420,10 +420,6 @@ virStorageSourcePtr virStorageFileChainLookup(virStorageSourcePtr chain,
virStorageSourcePtr *parent)
ATTRIBUTE_NONNULL(1);
int virStorageFileResize(const char *path,
unsigned long long capacity,
bool pre_allocate);
int virStorageFileIsClusterFS(const char *path);
bool virStorageIsFile(const char *path);
bool virStorageIsRelative(const char *backing);