Richard W.M. Jones
2016-Feb-04 18:27 UTC
[Libguestfs] [PATCH] aarch64: Use a common table of AAVMF paths.
Previously the code had two places where an identical set of AAVMF paths were stored. Put this information into one place. This is just refactoring. --- src/appliance.c | 26 +++++--------------------- src/guestfs-internal-frontend.h | 1 + src/utils.c | 12 ++++++++++++ v2v/utils-c.c | 27 +++++++++++++++++++++++++++ v2v/utils.ml | 7 +++---- 5 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/appliance.c b/src/appliance.c index 1dbf9c7..dbde35e 100644 --- a/src/appliance.c +++ b/src/appliance.c @@ -443,32 +443,15 @@ dir_contains_files (const char *dir, ...) * * XXX See also v2v/utils.ml:find_uefi_firmware */ -#ifdef __aarch64__ - -static const char *uefi_firmware[] = { - "/usr/share/AAVMF/AAVMF_CODE.fd", - "/usr/share/AAVMF/AAVMF_VARS.fd", - - "/usr/share/edk2.git/aarch64/QEMU_EFI-pflash.raw", - "/usr/share/edk2.git/aarch64/vars-template-pflash.raw", - - NULL -}; - -#else - -static const char *uefi_firmware[] = { NULL }; - -#endif - int guestfs_int_get_uefi (guestfs_h *g, char **code, char **vars) { +#ifdef __aarch64__ size_t i; - for (i = 0; uefi_firmware[i] != NULL; i += 2) { - const char *codefile = uefi_firmware[i]; - const char *varsfile = uefi_firmware[i+1]; + for (i = 0; guestfs_int_aavmf_firmware[i] != NULL; i += 2) { + const char *codefile = guestfs_int_aavmf_firmware[i]; + const char *varsfile = guestfs_int_aavmf_firmware[i+1]; if (access (codefile, R_OK) == 0 && access (varsfile, R_OK) == 0) { CLEANUP_CMD_CLOSE struct command *copycmd = guestfs_int_new_command (g); @@ -495,6 +478,7 @@ guestfs_int_get_uefi (guestfs_h *g, char **code, char **vars) return 0; } } +#endif /* Not found. */ *code = *vars = NULL; diff --git a/src/guestfs-internal-frontend.h b/src/guestfs-internal-frontend.h index 2fbf875..6f54a73 100644 --- a/src/guestfs-internal-frontend.h +++ b/src/guestfs-internal-frontend.h @@ -107,6 +107,7 @@ extern int guestfs_int_random_string (char *ret, size_t len); extern char *guestfs_int_drive_name (size_t index, char *ret); extern ssize_t guestfs_int_drive_index (const char *); extern int guestfs_int_is_true (const char *str); +extern const char *guestfs_int_aavmf_firmware[]; /* These functions are used internally by the CLEANUP_* macros. * Don't call them directly. diff --git a/src/utils.c b/src/utils.c index 36fd458..9244d16 100644 --- a/src/utils.c +++ b/src/utils.c @@ -314,3 +314,15 @@ guestfs_int_is_true (const char *str) return -1; } + +/* See src/appliance.c:guestfs_int_get_uefi. */ +const char * +guestfs_int_aavmf_firmware[] = { + "/usr/share/AAVMF/AAVMF_CODE.fd", + "/usr/share/AAVMF/AAVMF_VARS.fd", + + "/usr/share/edk2.git/aarch64/QEMU_EFI-pflash.raw", + "/usr/share/edk2.git/aarch64/vars-template-pflash.raw", + + NULL +}; diff --git a/v2v/utils-c.c b/v2v/utils-c.c index 66291b2..4ec4063 100644 --- a/v2v/utils-c.c +++ b/v2v/utils-c.c @@ -57,3 +57,30 @@ v2v_utils_drive_index (value strv) CAMLreturn (Val_int (r)); } + +value +v2v_utils_aavmf_firmware (value unitv) +{ + CAMLparam1 (unitv); + CAMLlocal5 (rv, v, v1, v2, cons); + /* Initialize the list backwards. */ + size_t i = guestfs_int_count_strings ((char **) guestfs_int_aavmf_firmware); + + rv = Val_int (0); + + while (i > 0) { + v1 = caml_copy_string (guestfs_int_aavmf_firmware[i-2]); + v2 = caml_copy_string (guestfs_int_aavmf_firmware[i-1]); + v = caml_alloc (2, 0); + Store_field (v, 0, v1); + Store_field (v, 1, v2); + cons = caml_alloc (2, 0); + Store_field (cons, 1, rv); + rv = cons; + Store_field (cons, 0, v); + + i -= 2; + } + + CAMLreturn (rv); +} diff --git a/v2v/utils.ml b/v2v/utils.ml index 82f4377..636f3c2 100644 --- a/v2v/utils.ml +++ b/v2v/utils.ml @@ -81,6 +81,8 @@ let qemu_supports_sound_card = function | Types.USBAudio -> true +external aavmf_firmware : unit -> (string * string) list = "v2v_utils_aavmf_firmware" + (* Find the UEFI firmware. *) let find_uefi_firmware guest_arch let files @@ -96,10 +98,7 @@ let find_uefi_firmware guest_arch "/usr/share/qemu/ovmf-x86_64-code.bin", "/usr/share/qemu/ovmf-x86_64-vars.bin" ] | "aarch64" -> - [ "/usr/share/AAVMF/AAVMF_CODE.fd", - "/usr/share/AAVMF/AAVMF_VARS.fd"; - "/usr/share/edk2.git/aarch64/QEMU_EFI-pflash.raw", - "/usr/share/edk2.git/aarch64/vars-template-pflash.raw" ] + aavmf_firmware () (* actually defined in src/utils.c *) | arch -> error (f_"don't know how to convert UEFI guests for architecture %s") guest_arch in -- 2.5.0
Seemingly Similar Threads
- [PATCH] aarch64: appliance: Use AAVMF (UEFI) if available for running the appliance.
- [PATCH 0/2] uefi: Add new locations for UEFI files on Fedora.
- [PATCH v2 0/2] v2v: Use OVMF secure boot file (RHBZ#1367615).
- [PATCH] v2v: Use OVMF secure boot file (RHBZ#1367615).
- [PATCH 1/2] utils, builder: Add wrappers for posix_fadvise.