Skip to content

Commit

Permalink
[LibOS,PAL] Rename PalObjectClose() to PalObjectDestroy()
Browse files Browse the repository at this point in the history
Previous name didn't make it clear that this PAL API not only closes the
associated host resources, but also destroys/frees the PAL handle object
itself. The handle-type-specific callbacks are also renamed from
`close()` to `destroy()`. Also, this function and all its callbacks are
of type `void` now and never return a value (as it's useless anyway).

Signed-off-by: Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
  • Loading branch information
dimakuv committed Sep 28, 2023
1 parent c11f4c6 commit a60dcf7
Show file tree
Hide file tree
Showing 58 changed files with 314 additions and 379 deletions.
2 changes: 1 addition & 1 deletion Documentation/pal/host-abi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Objects
.. doxygenfunction:: PalStreamsWaitEvents
:project: pal

.. doxygenfunction:: PalObjectClose
.. doxygenfunction:: PalObjectDestroy
:project: pal

Miscellaneous
Expand Down
2 changes: 1 addition & 1 deletion libos/include/libos_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static inline bool create_lock(struct libos_lock* l) {
}

static inline void destroy_lock(struct libos_lock* l) {
PalObjectClose(l->lock); // TODO: handle errors
PalObjectDestroy(l->lock);
clear_lock(l);
}

Expand Down
2 changes: 1 addition & 1 deletion libos/src/bookkeep/libos_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void put_handle(struct libos_handle* hdl) {
free(hdl->uri);

if (hdl->pal_handle) {
PalObjectClose(hdl->pal_handle); // TODO: handle errors
PalObjectDestroy(hdl->pal_handle);
hdl->pal_handle = NULL;
}

Expand Down
4 changes: 2 additions & 2 deletions libos/src/bookkeep/libos_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void put_thread(struct libos_thread* thread) {
free(thread->groups_info.groups);

if (thread->pal_handle && thread->pal_handle != g_pal_public_state->first_thread)
PalObjectClose(thread->pal_handle);
PalObjectDestroy(thread->pal_handle);

if (thread->handle_map) {
put_handle_map(thread->handle_map);
Expand All @@ -398,7 +398,7 @@ void put_thread(struct libos_thread* thread) {
/* `signal_altstack` is provided by the user, no need for a clean up. */

if (thread->scheduler_event) {
PalObjectClose(thread->scheduler_event);
PalObjectDestroy(thread->scheduler_event);
}

/* `wake_queue` is only meaningful when `thread` is part of some wake up queue (is just
Expand Down
6 changes: 3 additions & 3 deletions libos/src/fs/chroot/encrypted.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ static int chroot_encrypted_mkdir(struct libos_dentry* dent, mode_t perm) {
ret = pal_to_unix_errno(ret);
goto out;
}
PalObjectClose(palhdl);
PalObjectDestroy(palhdl);

inode->type = S_IFDIR;
inode->perm = perm;
Expand Down Expand Up @@ -297,7 +297,7 @@ static int chroot_encrypted_unlink(struct libos_dentry* dent) {
}

ret = PalStreamDelete(palhdl, PAL_DELETE_ALL);
PalObjectClose(palhdl);
PalObjectDestroy(palhdl);
if (ret < 0) {
ret = pal_to_unix_errno(ret);
goto out;
Expand Down Expand Up @@ -356,7 +356,7 @@ static int chroot_encrypted_chmod(struct libos_dentry* dent, mode_t perm) {
mode_t host_perm = HOST_PERM(perm);
PAL_STREAM_ATTR attr = {.share_flags = host_perm};
ret = PalStreamAttributesSetByHandle(palhdl, &attr);
PalObjectClose(palhdl);
PalObjectDestroy(palhdl);
if (ret < 0) {
ret = pal_to_unix_errno(ret);
goto out;
Expand Down
10 changes: 5 additions & 5 deletions libos/src/fs/chroot/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static int chroot_do_open(struct libos_handle* hdl, struct libos_dentry* dent, m
hdl->pos = 0;
hdl->pal_handle = palhdl;
} else {
PalObjectClose(palhdl);
PalObjectDestroy(palhdl);
}
ret = 0;

Expand Down Expand Up @@ -386,7 +386,7 @@ int chroot_readdir(struct libos_dentry* dent, readdir_callback_t callback, void*

out:
free(buf);
PalObjectClose(palhdl);
PalObjectDestroy(palhdl);
return ret;
}

Expand All @@ -402,7 +402,7 @@ int chroot_unlink(struct libos_dentry* dent) {
return ret;

ret = PalStreamDelete(palhdl, PAL_DELETE_ALL);
PalObjectClose(palhdl);
PalObjectDestroy(palhdl);
if (ret < 0)
return pal_to_unix_errno(ret);

Expand All @@ -426,7 +426,7 @@ static int chroot_rename(struct libos_dentry* old, struct libos_dentry* new) {
goto out;

ret = PalStreamChangeName(palhdl, new_uri);
PalObjectClose(palhdl);
PalObjectDestroy(palhdl);
if (ret < 0) {
ret = pal_to_unix_errno(ret);
goto out;
Expand All @@ -452,7 +452,7 @@ static int chroot_chmod(struct libos_dentry* dent, mode_t perm) {
mode_t host_perm = HOST_PERM(perm);
PAL_STREAM_ATTR attr = {.share_flags = host_perm};
ret = PalStreamAttributesSetByHandle(palhdl, &attr);
PalObjectClose(palhdl);
PalObjectDestroy(palhdl);
if (ret < 0)
return pal_to_unix_errno(ret);

Expand Down
4 changes: 2 additions & 2 deletions libos/src/fs/libos_fs_encrypted.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static int encrypted_file_internal_open(struct libos_encrypted_file* enc, PAL_HA
out:
free(normpath);
if (ret < 0)
PalObjectClose(pal_handle);
PalObjectDestroy(pal_handle);
return ret;
}

Expand Down Expand Up @@ -242,7 +242,7 @@ static void encrypted_file_internal_close(struct libos_encrypted_file* enc) {
}

enc->pf = NULL;
PalObjectClose(enc->pal_handle);
PalObjectDestroy(enc->pal_handle);
enc->pal_handle = NULL;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion libos/src/fs/libos_fs_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ int file_lock_set(struct libos_dentry* dent, struct libos_file_lock* file_lock,
out:
unlock(&g_fs_lock_lock);
if (event)
PalObjectClose(event);
PalObjectDestroy(event);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion libos/src/fs/socket/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static int close(struct libos_handle* handle) {
free(handle->info.sock.peek.buf);
/* No need for atomics - we are releasing the last reference, nothing can access it anymore. */
if (handle->info.sock.pal_handle) {
PalObjectClose(handle->info.sock.pal_handle);
PalObjectDestroy(handle->info.sock.pal_handle);
}
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions libos/src/ipc/libos_ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static void put_ipc_connection(struct libos_ipc_connection* conn) {
refcount_t ref_count = refcount_dec(&conn->ref_count);

if (!ref_count) {
PalObjectClose(conn->handle);
PalObjectDestroy(conn->handle);
destroy_lock(&conn->lock);
free(conn);
}
Expand Down Expand Up @@ -157,7 +157,7 @@ static int ipc_connect(IDTYPE dest, struct libos_ipc_connection** conn_ptr) {
destroy_lock(&conn->lock);
}
if (conn->handle) {
PalObjectClose(conn->handle);
PalObjectDestroy(conn->handle);
}
free(conn);
}
Expand Down Expand Up @@ -311,7 +311,7 @@ int ipc_send_msg_and_get_response(IDTYPE dest, struct libos_ipc_msg* msg, void**
avl_tree_delete(&g_msg_waiters_tree, &waiter.node);
unlock(&g_msg_waiters_tree_lock);
free(waiter.response_data);
PalObjectClose(waiter.event);
PalObjectDestroy(waiter.event);
return ret;
}

Expand Down
6 changes: 3 additions & 3 deletions libos/src/ipc/libos_ipc_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static void del_ipc_connection(struct libos_ipc_connection* conn) {
LISTP_DEL(conn, &g_ipc_connections, list);
g_ipc_connections_cnt--;

PalObjectClose(conn->handle);
PalObjectDestroy(conn->handle);

free(conn);
}
Expand Down Expand Up @@ -320,7 +320,7 @@ static noreturn void ipc_worker_main(void) {
ret = read_exact(new_handle, &new_id, sizeof(new_id));
if (ret < 0) {
log_error(LOG_PREFIX "receiving id failed: %s", unix_strerror(ret));
PalObjectClose(new_handle);
PalObjectDestroy(new_handle);
} else {
ret = add_ipc_connection(new_handle, new_id);
if (ret < 0) {
Expand Down Expand Up @@ -417,6 +417,6 @@ void terminate_ipc_worker(void) {

put_thread(g_worker_thread);
g_worker_thread = NULL;
PalObjectClose(g_self_ipc_handle);
PalObjectDestroy(g_self_ipc_handle);
g_self_ipc_handle = NULL;
}
2 changes: 1 addition & 1 deletion libos/src/libos_checkpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ int create_process_and_send_checkpoint(migrate_func_t migrate_func,
}

if (pal_process)
PalObjectClose(pal_process);
PalObjectDestroy(pal_process);

if (ret < 0) {
log_error("process creation failed");
Expand Down
12 changes: 6 additions & 6 deletions libos/src/libos_pollable_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int create_pollable_event(struct libos_pollable_event* event) {
} while (ret == -PAL_ERROR_INTERRUPTED);
if (ret < 0) {
log_error("PalStreamWaitForClient failed: %s", pal_strerror(ret));
PalObjectClose(write_handle);
PalObjectDestroy(write_handle);
ret = pal_to_unix_errno(ret);
goto out;
}
Expand All @@ -50,10 +50,10 @@ int create_pollable_event(struct libos_pollable_event* event) {

out:;
int tmp_ret = pal_to_unix_errno(PalStreamDelete(srv_handle, PAL_DELETE_ALL));
PalObjectClose(srv_handle);
PalObjectDestroy(srv_handle);
if (!ret && tmp_ret) {
PalObjectClose(read_handle);
PalObjectClose(write_handle);
PalObjectDestroy(read_handle);
PalObjectDestroy(write_handle);
/* Clearing just for sanity. */
event->read_handle = NULL;
event->write_handle = NULL;
Expand All @@ -62,8 +62,8 @@ out:;
}

void destroy_pollable_event(struct libos_pollable_event* event) {
PalObjectClose(event->read_handle);
PalObjectClose(event->write_handle);
PalObjectDestroy(event->read_handle);
PalObjectDestroy(event->write_handle);
}

int set_pollable_event(struct libos_pollable_event* event) {
Expand Down
10 changes: 5 additions & 5 deletions libos/src/libos_rwlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ bool rwlock_create(struct libos_rwlock* l) {
return false;
}
if (PalEventCreate(&l->writer_wait, /*init_signaled=*/false, /*auto_clear=*/true) < 0) {
PalObjectClose(l->readers_wait);
PalObjectDestroy(l->readers_wait);
return false;
}
l->waiting_readers = 0;
if (!create_lock(&l->writers_lock)) {
PalObjectClose(l->readers_wait);
PalObjectClose(l->writer_wait);
PalObjectDestroy(l->readers_wait);
PalObjectDestroy(l->writer_wait);
return false;
}
return true;
Expand All @@ -30,8 +30,8 @@ void rwlock_destroy(struct libos_rwlock* l) {
assert(l->departing_readers == 0);
assert(l->waiting_readers == 0);

PalObjectClose(l->readers_wait);
PalObjectClose(l->writer_wait);
PalObjectDestroy(l->readers_wait);
PalObjectDestroy(l->writer_wait);
destroy_lock(&l->writers_lock);
}

Expand Down
2 changes: 1 addition & 1 deletion libos/src/net/ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static int accept(struct libos_handle* handle, bool is_nonblocking,
handle->info.sock.protocol,
is_nonblocking);
if (!client_handle) {
PalObjectClose(client_pal_handle);
PalObjectDestroy(client_pal_handle);
return -ENOMEM;
}

Expand Down
2 changes: 1 addition & 1 deletion libos/src/net/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static int accept(struct libos_handle* handle, bool is_nonblocking,
handle->info.sock.protocol,
is_nonblocking);
if (!client_handle) {
PalObjectClose(client_pal_handle);
PalObjectDestroy(client_pal_handle);
return -ENOMEM;
}

Expand Down
4 changes: 2 additions & 2 deletions libos/src/sync/libos_sync_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void put_sync_handle(struct sync_handle* handle) {
free(handle->data);
destroy_lock(&handle->use_lock);
destroy_lock(&handle->prop_lock);
PalObjectClose(handle->event);
PalObjectDestroy(handle->event);
free(handle);
}
}
Expand Down Expand Up @@ -199,7 +199,7 @@ static int sync_init(struct sync_handle* handle, uint64_t id) {
if (lock_created(&handle->prop_lock))
destroy_lock(&handle->prop_lock);
if (handle->event)
PalObjectClose(handle->event);
PalObjectDestroy(handle->event);
return ret;
}

Expand Down
8 changes: 4 additions & 4 deletions libos/src/sys/libos_clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ long libos_syscall_clone(unsigned long flags, unsigned long user_stack_addr, int
while (!__atomic_load_n(&new_args.is_thread_initialized, __ATOMIC_ACQUIRE)) {
CPU_RELAX();
}
PalObjectClose(new_args.initialize_event);
PalObjectClose(new_args.create_event);
PalObjectDestroy(new_args.initialize_event);
PalObjectDestroy(new_args.create_event);

put_thread(thread);
return tid;
Expand All @@ -484,9 +484,9 @@ long libos_syscall_clone(unsigned long flags, unsigned long user_stack_addr, int
if (new_args.thread)
put_thread(new_args.thread);
if (new_args.create_event)
PalObjectClose(new_args.create_event);
PalObjectDestroy(new_args.create_event);
if (new_args.initialize_event)
PalObjectClose(new_args.initialize_event);
PalObjectDestroy(new_args.initialize_event);
failed:
put_thread(thread);
return ret;
Expand Down
6 changes: 3 additions & 3 deletions libos/src/sys/libos_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ static int create_pipes(struct libos_handle* srv, struct libos_handle* cli, int

out:;
int tmp_ret = PalStreamDelete(hdl0, PAL_DELETE_ALL);
PalObjectClose(hdl0);
PalObjectDestroy(hdl0);
if (ret || tmp_ret) {
if (hdl1)
PalObjectClose(hdl1);
PalObjectDestroy(hdl1);
if (hdl2)
PalObjectClose(hdl2);
PalObjectDestroy(hdl2);

free(srv->uri);
srv->uri = NULL;
Expand Down
6 changes: 2 additions & 4 deletions pal/include/pal/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ enum {
PAL_HANDLE_TYPE_BOUND,
};

#define PAL_IDX_POISON ((PAL_IDX)-1) /* PAL identifier poison value */

/********** PAL APIs **********/

struct pal_dns_host_conf_addr {
Expand Down Expand Up @@ -826,9 +824,9 @@ int PalStreamsWaitEvents(size_t count, PAL_HANDLE* handle_array, pal_wait_flags_
pal_wait_flags_t* ret_events, uint64_t* timeout_us);

/*!
* \brief Close (deallocate) a PAL handle.
* \brief Close and deallocate a PAL handle.
*/
void PalObjectClose(PAL_HANDLE object_handle);
void PalObjectDestroy(PAL_HANDLE handle);

/*
* MISC
Expand Down

0 comments on commit a60dcf7

Please sign in to comment.