storage: Modify storageBackendWipeLocal to allow zero from end of device
Add bool 'zero_end' and logic that would allow a caller to wipe specific portions of a target device either from the beginning (the default) or from the end when zero_end is true. This will allow for this code to wipe out partition table information from a device.
This commit is contained in:
parent
1acce5c853
commit
859a2d162a
@ -2516,26 +2516,38 @@ static int
|
|||||||
storageBackendWipeLocal(const char *path,
|
storageBackendWipeLocal(const char *path,
|
||||||
int fd,
|
int fd,
|
||||||
unsigned long long wipe_len,
|
unsigned long long wipe_len,
|
||||||
size_t writebuf_length)
|
size_t writebuf_length,
|
||||||
|
bool zero_end)
|
||||||
{
|
{
|
||||||
int ret = -1, written = 0;
|
int ret = -1, written = 0;
|
||||||
unsigned long long remaining = 0;
|
unsigned long long remaining = 0;
|
||||||
|
off_t size;
|
||||||
size_t write_size = 0;
|
size_t write_size = 0;
|
||||||
char *writebuf = NULL;
|
char *writebuf = NULL;
|
||||||
|
|
||||||
VIR_DEBUG("wiping start: 0 len: %llu", wipe_len);
|
|
||||||
|
|
||||||
if (VIR_ALLOC_N(writebuf, writebuf_length) < 0)
|
if (VIR_ALLOC_N(writebuf, writebuf_length) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (lseek(fd, 0, SEEK_SET) < 0) {
|
if (!zero_end) {
|
||||||
virReportSystemError(errno,
|
if ((size = lseek(fd, 0, SEEK_SET)) < 0) {
|
||||||
_("Failed to seek to the start in volume "
|
virReportSystemError(errno,
|
||||||
"with path '%s'"),
|
_("Failed to seek to the start in volume "
|
||||||
path);
|
"with path '%s'"),
|
||||||
goto cleanup;
|
path);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((size = lseek(fd, -wipe_len, SEEK_END)) < 0) {
|
||||||
|
virReportSystemError(errno,
|
||||||
|
_("Failed to seek to %llu bytes to the end "
|
||||||
|
"in volume with path '%s'"),
|
||||||
|
wipe_len, path);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VIR_DEBUG("wiping start: %zd len: %llu", (ssize_t) size, wipe_len);
|
||||||
|
|
||||||
remaining = wipe_len;
|
remaining = wipe_len;
|
||||||
while (remaining > 0) {
|
while (remaining > 0) {
|
||||||
|
|
||||||
@ -2573,7 +2585,8 @@ storageBackendWipeLocal(const char *path,
|
|||||||
static int
|
static int
|
||||||
storageBackendVolWipeLocalFile(const char *path,
|
storageBackendVolWipeLocalFile(const char *path,
|
||||||
unsigned int algorithm,
|
unsigned int algorithm,
|
||||||
unsigned long long allocation)
|
unsigned long long allocation,
|
||||||
|
bool zero_end)
|
||||||
{
|
{
|
||||||
int ret = -1, fd = -1;
|
int ret = -1, fd = -1;
|
||||||
const char *alg_char = NULL;
|
const char *alg_char = NULL;
|
||||||
@ -2648,7 +2661,8 @@ storageBackendVolWipeLocalFile(const char *path,
|
|||||||
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 = storageBackendVolZeroSparseFileLocal(path, st.st_size, fd);
|
ret = storageBackendVolZeroSparseFileLocal(path, st.st_size, fd);
|
||||||
} else {
|
} else {
|
||||||
ret = storageBackendWipeLocal(path, fd, allocation, st.st_blksize);
|
ret = storageBackendWipeLocal(path, fd, allocation, st.st_blksize,
|
||||||
|
zero_end);
|
||||||
}
|
}
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -2686,7 +2700,7 @@ storageBackendVolWipePloop(virStorageVolDefPtr vol,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (storageBackendVolWipeLocalFile(target_path, algorithm,
|
if (storageBackendVolWipeLocalFile(target_path, algorithm,
|
||||||
vol->target.allocation) < 0)
|
vol->target.allocation, false) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virFileRemove(disk_desc, 0, 0) < 0) {
|
if (virFileRemove(disk_desc, 0, 0) < 0) {
|
||||||
@ -2735,7 +2749,7 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
ret = storageBackendVolWipePloop(vol, algorithm);
|
ret = storageBackendVolWipePloop(vol, algorithm);
|
||||||
} else {
|
} else {
|
||||||
ret = storageBackendVolWipeLocalFile(vol->target.path, algorithm,
|
ret = storageBackendVolWipeLocalFile(vol->target.path, algorithm,
|
||||||
vol->target.allocation);
|
vol->target.allocation, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user