mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 09:47:20 +03:00
storage: move buffer allocation inside virStorageBackendWipeExtentLocal
We do not need to pass a zero-filled buffer as an argument, the function can allocate its own.
This commit is contained in:
parent
09cbfc0481
commit
4bccdf0ceb
@ -1991,17 +1991,20 @@ virStorageBackendWipeExtentLocal(virStorageVolDefPtr vol,
|
|||||||
int fd,
|
int fd,
|
||||||
off_t extent_start,
|
off_t extent_start,
|
||||||
off_t extent_length,
|
off_t extent_length,
|
||||||
char *writebuf,
|
|
||||||
size_t writebuf_length,
|
size_t writebuf_length,
|
||||||
size_t *bytes_wiped)
|
size_t *bytes_wiped)
|
||||||
{
|
{
|
||||||
int ret = -1, written = 0;
|
int ret = -1, written = 0;
|
||||||
off_t remaining = 0;
|
off_t remaining = 0;
|
||||||
size_t write_size = 0;
|
size_t write_size = 0;
|
||||||
|
char *writebuf = NULL;
|
||||||
|
|
||||||
VIR_DEBUG("extent logical start: %ju len: %ju",
|
VIR_DEBUG("extent logical start: %ju len: %ju",
|
||||||
(uintmax_t)extent_start, (uintmax_t)extent_length);
|
(uintmax_t)extent_start, (uintmax_t)extent_length);
|
||||||
|
|
||||||
|
if (VIR_ALLOC_N(writebuf, writebuf_length) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (lseek(fd, extent_start, SEEK_SET) < 0) {
|
if (lseek(fd, extent_start, SEEK_SET) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to seek to position %ju in volume "
|
_("Failed to seek to position %ju in volume "
|
||||||
@ -2041,6 +2044,7 @@ virStorageBackendWipeExtentLocal(virStorageVolDefPtr vol,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
VIR_FREE(writebuf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2054,7 +2058,6 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
{
|
{
|
||||||
int ret = -1, fd = -1;
|
int ret = -1, fd = -1;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *writebuf = NULL;
|
|
||||||
size_t bytes_wiped = 0;
|
size_t bytes_wiped = 0;
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
|
|
||||||
@ -2123,15 +2126,10 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
if (S_ISREG(st.st_mode) && st.st_blocks < (st.st_size / DEV_BSIZE)) {
|
if (S_ISREG(st.st_mode) && st.st_blocks < (st.st_size / DEV_BSIZE)) {
|
||||||
ret = virStorageBackendVolZeroSparseFileLocal(vol, st.st_size, fd);
|
ret = virStorageBackendVolZeroSparseFileLocal(vol, st.st_size, fd);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (VIR_ALLOC_N(writebuf, st.st_blksize) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
ret = virStorageBackendWipeExtentLocal(vol,
|
ret = virStorageBackendWipeExtentLocal(vol,
|
||||||
fd,
|
fd,
|
||||||
0,
|
0,
|
||||||
vol->target.allocation,
|
vol->target.allocation,
|
||||||
writebuf,
|
|
||||||
st.st_blksize,
|
st.st_blksize,
|
||||||
&bytes_wiped);
|
&bytes_wiped);
|
||||||
}
|
}
|
||||||
@ -2139,7 +2137,6 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
VIR_FREE(writebuf);
|
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user