Skip to content

Commit e371b3f

Browse files
committedNov 21, 2023
Bump efivarfs_get_variable throughput to 50 variables/second from 33⅓
Read the whole variable at once, then copy out the attributes (for a description of efivarfs rate limiting, see rhboot#258) Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
1 parent f6baefa commit e371b3f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed
 

‎src/efivarfs.c

+9-8
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ efivarfs_get_variable(efi_guid_t guid, const char *name, uint8_t **data,
241241
__typeof__(errno) errno_value;
242242
int ret = -1;
243243
size_t size = 0;
244-
uint32_t ret_attributes = 0;
245244
uint8_t *ret_data;
246245
int fd = -1;
247246
char *path = NULL;
@@ -259,21 +258,23 @@ efivarfs_get_variable(efi_guid_t guid, const char *name, uint8_t **data,
259258
goto err;
260259
}
261260

262-
rc = read(fd, &ret_attributes, sizeof (ret_attributes));
261+
rc = read_file(fd, &ret_data, &size);
263262
if (rc < 0) {
264-
efi_error("read failed");
263+
efi_error("read_file failed");
265264
goto err;
266265
}
266+
--size; // read_file pads out 1 extra byte to NUL
267267

268-
rc = read_file(fd, &ret_data, &size);
269-
if (rc < 0) {
270-
efi_error("read_file failed");
268+
if (size < sizeof (*attributes)) {
269+
efi_error("no attributes");
271270
goto err;
272271
}
273272

274-
*attributes = ret_attributes;
273+
memcpy(attributes, ret_data, sizeof (*attributes));
274+
memmove(ret_data, ret_data + sizeof (*attributes), size - sizeof (*attributes));
275+
275276
*data = ret_data;
276-
*data_size = size - 1; // read_file pads out 1 extra byte to NUL it */
277+
*data_size = size - sizeof (*attributes);
277278

278279
ret = 0;
279280
err:

0 commit comments

Comments
 (0)
Please sign in to comment.