All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit e09de3c1 authored by Ian Campbell's avatar Ian Campbell

libxl: Make all hidden/static functions take a gc not a ctx

Also ensure that static and hidden functions use the libxl__ prefix
not just libxl_ (in the case of static functions only when they use a
libxl prefix to start with).

This follows the policy described in libxl.h "libxl memory
management".

Based on a manual audit of:
grep ^static tools/libxl/libxl*.[ch]| grep libxl_ctx
grep libxl__ tools/libxl/*.h| grep libxl_ctx
Signed-off-by: default avatarIan Campbell <ian.campbell@citrix.com>
Committed-by: default avatarIan Jackson <ian.jackson@eu.citrix.com>
parent 8a073d01
This diff is collapsed.
......@@ -271,7 +271,7 @@ out_err:
return NULL;
}
static void parse_bootloader_result(libxl_ctx *ctx,
static void parse_bootloader_result(libxl__gc *gc,
libxl_domain_build_info *info,
const char *o)
{
......@@ -414,7 +414,7 @@ int libxl_run_bootloader(libxl_ctx *ctx,
goto out_close;
}
parse_bootloader_result(ctx, info, blout);
parse_bootloader_result(&gc, info, blout);
rc = 0;
out_close:
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -91,12 +91,13 @@ void libxl_report_child_exitstatus(libxl_ctx *ctx,
}
}
int libxl__spawn_spawn(libxl_ctx *ctx,
int libxl__spawn_spawn(libxl__gc *gc,
libxl__device_model_starting *starting,
const char *what,
void (*intermediate_hook)(void *for_spawn,
pid_t innerchild))
{
libxl_ctx *ctx = libxl__gc_owner(gc);
pid_t child, got;
int status;
pid_t intermediate;
......@@ -138,11 +139,12 @@ int libxl__spawn_spawn(libxl_ctx *ctx,
? WTERMSIG(status)+128 : -1);
}
static void report_spawn_intermediate_status(libxl_ctx *ctx,
libxl__spawn_starting *for_spawn,
int status)
static void report_spawn_intermediate_status(libxl__gc *gc,
libxl__spawn_starting *for_spawn,
int status)
{
if (!WIFEXITED(status)) {
libxl_ctx *ctx = libxl__gc_owner(gc);
char *intermediate_what;
/* intermediate process did the logging itself if it exited */
if ( asprintf(&intermediate_what,
......@@ -154,9 +156,10 @@ static void report_spawn_intermediate_status(libxl_ctx *ctx,
}
}
int libxl__spawn_detach(libxl_ctx *ctx,
int libxl__spawn_detach(libxl__gc *gc,
libxl__spawn_starting *for_spawn)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
int r, status;
pid_t got;
int rc = 0;
......@@ -175,7 +178,7 @@ int libxl__spawn_detach(libxl_ctx *ctx,
got = call_waitpid(ctx->waitpid_instead, for_spawn->intermediate, &status, 0);
assert(got == for_spawn->intermediate);
if (!(WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL)) {
report_spawn_intermediate_status(ctx, for_spawn, status);
report_spawn_intermediate_status(gc, for_spawn, status);
rc = ERROR_FAIL;
}
for_spawn->intermediate = 0;
......@@ -187,8 +190,9 @@ int libxl__spawn_detach(libxl_ctx *ctx,
return rc;
}
int libxl__spawn_check(libxl_ctx *ctx, void *for_spawn_void)
int libxl__spawn_check(libxl__gc *gc, void *for_spawn_void)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
libxl__spawn_starting *for_spawn = for_spawn_void;
pid_t got;
int status;
......@@ -200,7 +204,7 @@ int libxl__spawn_check(libxl_ctx *ctx, void *for_spawn_void)
if (!got) return 0;
assert(got == for_spawn->intermediate);
report_spawn_intermediate_status(ctx, for_spawn, status);
report_spawn_intermediate_status(gc, for_spawn, status);
for_spawn->intermediate = 0;
return ERROR_FAIL;
......
......@@ -29,7 +29,7 @@
#include "libxl_internal.h"
#include "libxl_utils.h"
int libxl__error_set(libxl_ctx *ctx, int code)
int libxl__error_set(libxl__gc *gc, int code)
{
return 0;
}
......@@ -82,7 +82,7 @@ void *libxl__zalloc(libxl__gc *gc, int bytes)
{
void *ptr = calloc(bytes, 1);
if (!ptr) {
libxl__error_set(libxl__gc_owner(gc), ENOMEM);
libxl__error_set(gc, ENOMEM);
return NULL;
}
......@@ -94,7 +94,7 @@ void *libxl__calloc(libxl__gc *gc, size_t nmemb, size_t size)
{
void *ptr = calloc(nmemb, size);
if (!ptr) {
libxl__error_set(libxl__gc_owner(gc), ENOMEM);
libxl__error_set(gc, ENOMEM);
return NULL;
}
......
......@@ -157,25 +157,25 @@ _hidden char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t,
/* On error: returns NULL, sets errno (no logging) */
/* from xl_dom */
_hidden int libxl__domain_is_hvm(libxl_ctx *ctx, uint32_t domid);
_hidden int libxl__domain_shutdown_reason(libxl_ctx *ctx, uint32_t domid);
_hidden int libxl__domain_is_hvm(libxl__gc *gc, uint32_t domid);
_hidden int libxl__domain_shutdown_reason(libxl__gc *gc, uint32_t domid);
_hidden int libxl__build_pre(libxl_ctx *ctx, uint32_t domid,
_hidden int libxl__build_pre(libxl__gc *gc, uint32_t domid,
libxl_domain_build_info *info, libxl_domain_build_state *state);
_hidden int libxl__build_post(libxl_ctx *ctx, uint32_t domid,
_hidden int libxl__build_post(libxl__gc *gc, uint32_t domid,
libxl_domain_build_info *info, libxl_domain_build_state *state,
char **vms_ents, char **local_ents);
_hidden int libxl__build_pv(libxl_ctx *ctx, uint32_t domid,
_hidden int libxl__build_pv(libxl__gc *gc, uint32_t domid,
libxl_domain_build_info *info, libxl_domain_build_state *state);
_hidden int libxl__build_hvm(libxl_ctx *ctx, uint32_t domid,
_hidden int libxl__build_hvm(libxl__gc *gc, uint32_t domid,
libxl_domain_build_info *info, libxl_domain_build_state *state);
_hidden int libxl__domain_restore_common(libxl_ctx *ctx, uint32_t domid,
_hidden int libxl__domain_restore_common(libxl__gc *gc, uint32_t domid,
libxl_domain_build_info *info, libxl_domain_build_state *state, int fd);
_hidden int libxl__domain_suspend_common(libxl_ctx *ctx, uint32_t domid, int fd, int hvm, int live, int debug);
_hidden int libxl__domain_save_device_model(libxl_ctx *ctx, uint32_t domid, int fd);
_hidden void libxl__userdata_destroyall(libxl_ctx *ctx, uint32_t domid);
_hidden int libxl__domain_suspend_common(libxl__gc *gc, uint32_t domid, int fd, int hvm, int live, int debug);
_hidden int libxl__domain_save_device_model(libxl__gc *gc, uint32_t domid, int fd);
_hidden void libxl__userdata_destroyall(libxl__gc *gc, uint32_t domid);
/* from xl_device */
_hidden char *libxl__device_disk_string_of_backend(libxl_disk_backend backend);
......@@ -184,25 +184,18 @@ _hidden char *libxl__device_disk_string_of_format(libxl_disk_format format);
_hidden int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor);
_hidden int libxl__device_disk_dev_number(char *virtpath);
_hidden int libxl__device_generic_add(libxl_ctx *ctx, libxl__device *device,
_hidden int libxl__device_generic_add(libxl__gc *gc, libxl__device *device,
char **bents, char **fents);
_hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device);
_hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device);
_hidden int libxl__device_del(libxl_ctx *ctx, libxl__device *dev, int wait);
_hidden int libxl__device_destroy(libxl_ctx *ctx, char *be_path, int force);
_hidden int libxl__devices_destroy(libxl_ctx *ctx, uint32_t domid, int force);
_hidden int libxl__wait_for_device_model(libxl_ctx *ctx,
uint32_t domid, char *state,
int (*check_callback)(libxl_ctx *ctx,
uint32_t domid,
const char *state,
void *userdata),
void *check_callback_userdata);
_hidden int libxl__wait_for_backend(libxl_ctx *ctx, char *be_path, char *state);
_hidden int libxl__device_del(libxl__gc *gc, libxl__device *dev, int wait);
_hidden int libxl__device_destroy(libxl__gc *gc, char *be_path, int force);
_hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force);
_hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state);
/* from libxl_pci */
_hidden int libxl__device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev, int starting);
_hidden int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int starting);
/* xl_exec */
......@@ -222,33 +215,40 @@ typedef struct {
} libxl__device_model_starting;
/* from xl_create */
_hidden int libxl__domain_make(libxl_ctx *ctx, libxl_domain_create_info *info, uint32_t *domid);
_hidden int libxl__domain_build(libxl_ctx *ctx, libxl_domain_build_info *info, uint32_t domid, /* out */ libxl_domain_build_state *state);
_hidden int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, uint32_t *domid);
_hidden int libxl__domain_build(libxl__gc *gc, libxl_domain_build_info *info, uint32_t domid, /* out */ libxl_domain_build_state *state);
/* for device model creation */
_hidden int libxl__create_device_model(libxl_ctx *ctx,
_hidden int libxl__create_device_model(libxl__gc *gc,
libxl_device_model_info *info,
libxl_device_disk *disk, int num_disks,
libxl_device_nic *vifs, int num_vifs,
libxl__device_model_starting **starting_r);
_hidden int libxl__create_xenpv_qemu(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb,
_hidden int libxl__create_xenpv_qemu(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb,
libxl__device_model_starting **starting_r);
_hidden int libxl__need_xenpv_qemu(libxl_ctx *ctx,
_hidden int libxl__need_xenpv_qemu(libxl__gc *gc,
int nr_consoles, libxl_device_console *consoles,
int nr_vfbs, libxl_device_vfb *vfbs,
int nr_disks, libxl_device_disk *disks);
/* Caller must either: pass starting_r==0, or on successful
* return pass *starting_r (which will be non-0) to
* libxl_confirm_device_model or libxl_detach_device_model. */
_hidden int libxl__confirm_device_model_startup(libxl_ctx *ctx,
_hidden int libxl__confirm_device_model_startup(libxl__gc *gc,
libxl__device_model_starting *starting);
_hidden int libxl__detach_device_model(libxl__gc *gc, libxl__device_model_starting *starting);
_hidden int libxl__wait_for_device_model(libxl__gc *gc,
uint32_t domid, char *state,
int (*check_callback)(libxl__gc *gc,
uint32_t domid,
const char *state,
void *userdata),
void *check_callback_userdata);
_hidden int libxl__spawn_spawn(libxl_ctx *ctx,
_hidden int libxl__spawn_spawn(libxl__gc *gc,
libxl__device_model_starting *starting,
const char *what,
void (*intermediate_hook)(void *for_spawn, pid_t innerchild));
_hidden int libxl__destroy_device_model(libxl_ctx *ctx, uint32_t domid);
_hidden int libxl__destroy_device_model(libxl__gc *gc, uint32_t domid);
/* Logs errors. A copy of "what" is taken. Return values:
* < 0 error, for_spawn need not be detached
......@@ -256,11 +256,11 @@ _hidden int libxl__destroy_device_model(libxl_ctx *ctx, uint32_t domid);
* 0 caller is now the inner child, should probably call libxl__exec
* Caller, may pass 0 for for_spawn, in which case no need to detach.
*/
_hidden int libxl__spawn_detach(libxl_ctx *ctx,
_hidden int libxl__spawn_detach(libxl__gc *gc,
libxl__spawn_starting *for_spawn);
/* Logs errors. Idempotent, but only permitted after successful
* call to libxl__spawn_spawn, and no point calling it again if it fails. */
_hidden int libxl__spawn_check(libxl_ctx *ctx,
_hidden int libxl__spawn_check(libxl__gc *gc,
void *for_spawn);
/* Logs errors but also returns them.
* for_spawn must actually be a libxl__spawn_starting* but
......@@ -325,7 +325,7 @@ struct libxl__xen_console_reader {
unsigned int index;
};
_hidden int libxl__error_set(libxl_ctx *ctx, int code);
_hidden int libxl__error_set(libxl__gc *gc, int code);
_hidden int libxl__file_reference_map(libxl_file_reference *f);
_hidden int libxl__file_reference_unmap(libxl_file_reference *f);
......
This diff is collapsed.
......@@ -223,7 +223,9 @@ out:
return ret;
}
static int logrename(libxl_ctx *ctx, const char *old, const char *new) {
static int logrename(libxl__gc *gc, const char *old, const char *new)
{
libxl_ctx *ctx = libxl__gc_owner(gc);
int r;
r = rename(old, new);
......@@ -252,14 +254,14 @@ int libxl_create_logfile(libxl_ctx *ctx, char *name, char **full_name)
for (i = 9; i > 0; i--) {
logfile = libxl__sprintf(&gc, "/var/log/xen/%s.log.%d", name, i);
logfile_new = libxl__sprintf(&gc, "/var/log/xen/%s.log.%d", name, i + 1);
rc = logrename(ctx, logfile, logfile_new);
rc = logrename(&gc, logfile, logfile_new);
if (rc)
goto out;
}
logfile = libxl__sprintf(&gc, "/var/log/xen/%s.log", name);
logfile_new = libxl__sprintf(&gc, "/var/log/xen/%s.log.1", name);
rc = logrename(ctx, logfile, logfile_new);
rc = logrename(&gc, logfile, logfile_new);
if (rc)
goto out;
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment