提交 912911a4 编写于 作者: P Peter Krempa

storage: gluster: Optimize header reader functions

The gluster code had two functions for reading volume headers, remove
one and reuse the second one.
上级 25924dec
......@@ -651,9 +651,6 @@ virStorageFileBackendGlusterReadHeader(virStorageSourcePtr src,
{
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
glfs_fd_t *fd = NULL;
size_t alloc = 0;
size_t size = 0;
int save_errno;
ssize_t ret = -1;
*buf = NULL;
......@@ -661,47 +658,11 @@ virStorageFileBackendGlusterReadHeader(virStorageSourcePtr src,
if (!(fd = glfs_open(priv->vol, src->path, O_RDONLY))) {
virReportSystemError(errno, _("Failed to open file '%s'"),
src->path);
goto cleanup;
}
/* code below is shamelessly stolen from saferead_lim */
for (;;) {
int count;
int requested;
if (size + BUFSIZ + 1 > alloc) {
alloc += alloc / 2;
if (alloc < size + BUFSIZ + 1)
alloc = size + BUFSIZ + 1;
if (VIR_REALLOC_N(*buf, alloc) < 0) {
save_errno = errno;
break;
}
}
/* Ensure that (size + requested <= max_len); */
requested = MIN(size < max_len ? max_len - size : 0,
alloc - size - 1);
count = glfs_read(fd, *buf + size, requested, 0);
size += count;
if (count != requested || requested == 0) {
save_errno = errno;
if (count < 0) {
virReportSystemError(errno,
_("cannot read header '%s'"), src->path);
break;
}
ret = size;
goto cleanup;
}
return -1;
}
VIR_FREE(*buf);
errno = save_errno;
ret = virStorageBackendGlusterReadHeader(fd, src->path, max_len, buf);
cleanup:
if (fd)
glfs_close(fd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册