Skip to content

Commit f4477e3

Browse files
committed
Convert PalStreamOpen to return pal_error_t
Signed-off-by: Mariusz Zaborski <[email protected]>
1 parent d7a0b9c commit f4477e3

40 files changed

+346
-301
lines changed

Documentation/Doxyfile-pal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@INCLUDE = Doxyfile
22
PROJECT_NAME = "PAL"
33
OUTPUT_DIRECTORY = _build/doxygen-pal
4-
INPUT = ../pal/include/arch/x86_64 ../pal/include/pal ../pal/include ../common/include/iovec.h
4+
INPUT = ../pal/include/arch/x86_64 ../pal/include/pal ../pal/include ../common/include/pal_error.h ../common/include/iovec.h
55
MACRO_EXPANSION = YES
66
EXPAND_ONLY_PREDEF = YES
7-
PREDEFINED = noreturn= __x86_64__=1
7+
PREDEFINED = noreturn= __x86_64__=1 NODISCARD=

Documentation/pal/host-abi.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ Data types and variables
4242
Data types
4343
^^^^^^^^^^
4444

45+
Return type
46+
"""""""""""
47+
48+
All new PAL functions should return an error of :type:`pal_error_t`.
49+
50+
.. doxygentypedef:: pal_error_t
51+
:project: pal
52+
53+
.. doxygenenum:: _pal_error_t
54+
:project: pal
55+
4556
PAL handles
4657
"""""""""""
4758

libos/src/fs/chroot/encrypted.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,11 @@ static int chroot_encrypted_mkdir(struct libos_dentry* dent, mode_t perm) {
272272

273273
/* This opens a "dir:..." URI */
274274
PAL_HANDLE palhdl;
275-
ret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, HOST_PERM(perm), PAL_CREATE_ALWAYS,
276-
PAL_OPTION_PASSTHROUGH, &palhdl);
277-
if (ret < 0) {
278-
ret = pal_to_unix_errno(ret);
275+
pal_error_t pret;
276+
pret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, HOST_PERM(perm), PAL_CREATE_ALWAYS,
277+
PAL_OPTION_PASSTHROUGH, &palhdl);
278+
if (pret != PAL_ERROR_SUCCESS) {
279+
ret = -pal_to_unix_errno(pret);
279280
goto out;
280281
}
281282
PalObjectDestroy(palhdl);
@@ -304,10 +305,11 @@ static int chroot_encrypted_unlink(struct libos_dentry* dent) {
304305
return ret;
305306

306307
PAL_HANDLE palhdl;
307-
ret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER,
308-
PAL_OPTION_PASSTHROUGH, &palhdl);
309-
if (ret < 0) {
310-
ret = pal_to_unix_errno(ret);
308+
pal_error_t pret;
309+
pret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER,
310+
PAL_OPTION_PASSTHROUGH, &palhdl);
311+
if (pret != PAL_ERROR_SUCCESS) {
312+
ret = -pal_to_unix_errno(pret);
311313
goto out;
312314
}
313315

@@ -369,10 +371,11 @@ static int chroot_encrypted_chmod(struct libos_dentry* dent, mode_t perm) {
369371
goto out;
370372

371373
PAL_HANDLE palhdl;
372-
ret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER,
373-
PAL_OPTION_PASSTHROUGH, &palhdl);
374-
if (ret < 0) {
375-
ret = pal_to_unix_errno(ret);
374+
pal_error_t pret;
375+
pret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER,
376+
PAL_OPTION_PASSTHROUGH, &palhdl);
377+
if (pret != PAL_ERROR_SUCCESS) {
378+
ret = -pal_to_unix_errno(pret);
376379
goto out;
377380
}
378381
mode_t host_perm = HOST_PERM(perm);

libos/src/fs/chroot/fs.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,16 @@ static int chroot_lookup(struct libos_dentry* dent) {
114114
/* Open a temporary read-only PAL handle for a file (used by `unlink` etc.) */
115115
static int chroot_temp_open(struct libos_dentry* dent, PAL_HANDLE* out_palhdl) {
116116
char* uri;
117+
pal_error_t pret;
118+
117119
int ret = dentry_uri(dent, dent->inode->type, &uri);
118120
if (ret < 0)
119121
return ret;
120122

121-
ret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER,
122-
/*options=*/0, out_palhdl);
123+
pret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_NEVER,
124+
/*options=*/0, out_palhdl);
123125
free(uri);
124-
return pal_to_unix_errno(ret);
126+
return -pal_to_unix_errno(pret);
125127
}
126128

127129
/* Open a PAL handle, and associate it with a LibOS handle (if provided). */
@@ -130,8 +132,9 @@ static int chroot_do_open(struct libos_handle* hdl, struct libos_dentry* dent, m
130132
assert(locked(&g_dcache_lock));
131133

132134
int ret;
133-
135+
pal_error_t pret;
134136
char* uri;
137+
135138
ret = dentry_uri(dent, type, &uri);
136139
if (ret < 0)
137140
return ret;
@@ -141,9 +144,10 @@ static int chroot_do_open(struct libos_handle* hdl, struct libos_dentry* dent, m
141144
enum pal_create_mode create = LINUX_OPEN_FLAGS_TO_PAL_CREATE(flags);
142145
pal_stream_options_t options = LINUX_OPEN_FLAGS_TO_PAL_OPTIONS(flags);
143146
mode_t host_perm = HOST_PERM(perm);
144-
ret = PalStreamOpen(uri, access, host_perm, create, options, &palhdl);
145-
if (ret < 0) {
146-
ret = pal_to_unix_errno(ret);
147+
148+
pret = PalStreamOpen(uri, access, host_perm, create, options, &palhdl);
149+
if (pret != PAL_ERROR_SUCCESS) {
150+
ret = -pal_to_unix_errno(pret);
147151
goto out;
148152
}
149153

libos/src/fs/dev/fs.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ static int dev_tty_open(struct libos_handle* hdl, struct libos_dentry* dent, int
6464
return -ENOMEM;
6565

6666
PAL_HANDLE palhdl;
67-
int ret = PalStreamOpen(uri, LINUX_OPEN_FLAGS_TO_PAL_ACCESS(flags), PSEUDO_PERM_FILE_RW,
68-
PAL_CREATE_NEVER, /*options=*/0, &palhdl);
69-
if (ret < 0) {
67+
pal_error_t pret = PalStreamOpen(uri, LINUX_OPEN_FLAGS_TO_PAL_ACCESS(flags),
68+
PSEUDO_PERM_FILE_RW, PAL_CREATE_NEVER, /*options=*/0,
69+
&palhdl);
70+
if (pret != PAL_ERROR_SUCCESS) {
7071
free(uri);
71-
return pal_to_unix_errno(ret);
72+
return -pal_to_unix_errno(pret);
7273
}
7374

7475
assert(hdl);

libos/src/fs/libos_fs_encrypted.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ static int encrypted_file_internal_open(struct libos_encrypted_file* enc, PAL_HA
168168

169169
if (!pal_handle) {
170170
enum pal_create_mode create_mode = create ? PAL_CREATE_ALWAYS : PAL_CREATE_NEVER;
171-
ret = PalStreamOpen(enc->uri, PAL_ACCESS_RDWR, share_flags, create_mode,
172-
PAL_OPTION_PASSTHROUGH, &pal_handle);
173-
if (ret < 0) {
174-
log_warning("PalStreamOpen failed: %s", pal_strerror(ret));
175-
return pal_to_unix_errno(ret);
171+
pal_error_t pret = PalStreamOpen(enc->uri, PAL_ACCESS_RDWR, share_flags, create_mode,
172+
PAL_OPTION_PASSTHROUGH, &pal_handle);
173+
if (pret != PAL_ERROR_SUCCESS) {
174+
log_warning("PalStreamOpen failed: %s", pal_strerror(pret));
175+
return -pal_to_unix_errno(pret);
176176
}
177177
}
178178

libos/src/fs/shm/fs.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static int shm_do_open(struct libos_handle* hdl, struct libos_dentry* dent, mode
5757
assert(locked(&g_dcache_lock));
5858

5959
char* uri;
60+
pal_error_t pret;
6061
int ret = dentry_uri(dent, type, &uri);
6162
if (ret < 0)
6263
return ret;
@@ -66,9 +67,9 @@ static int shm_do_open(struct libos_handle* hdl, struct libos_dentry* dent, mode
6667
enum pal_create_mode create = LINUX_OPEN_FLAGS_TO_PAL_CREATE(flags);
6768
pal_stream_options_t options = LINUX_OPEN_FLAGS_TO_PAL_OPTIONS(flags);
6869
mode_t host_perm = HOST_PERM(perm);
69-
ret = PalStreamOpen(uri, access, host_perm, create, options, &palhdl);
70-
if (ret < 0) {
71-
ret = pal_to_unix_errno(ret);
70+
pret = PalStreamOpen(uri, access, host_perm, create, options, &palhdl);
71+
if (pret != PAL_ERROR_SUCCESS) {
72+
ret = -pal_to_unix_errno(pret);
7273
goto out;
7374
}
7475

libos/src/ipc/libos_ipc.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ static int vmid_to_uri(IDTYPE vmid, char* uri, size_t uri_size) {
108108
static int ipc_connect(IDTYPE dest, struct libos_ipc_connection** conn_ptr) {
109109
struct libos_ipc_connection dummy = { .vmid = dest };
110110
int ret = 0;
111+
pal_error_t pret;
111112

112113
lock(&g_ipc_connections_lock);
113114
struct libos_ipc_connection* conn = node2conn(avl_tree_find(&g_ipc_connections, &dummy.node));
@@ -128,11 +129,11 @@ static int ipc_connect(IDTYPE dest, struct libos_ipc_connection** conn_ptr) {
128129
BUG();
129130
}
130131
do {
131-
ret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_IGNORED,
132-
/*options=*/0, &conn->handle);
133-
} while (ret == -PAL_ERROR_INTERRUPTED);
134-
if (ret < 0) {
135-
ret = pal_to_unix_errno(ret);
132+
pret = PalStreamOpen(uri, PAL_ACCESS_RDONLY, /*share_flags=*/0, PAL_CREATE_IGNORED,
133+
/*options=*/0, &conn->handle);
134+
} while (pret == PAL_ERROR_INTERRUPTED);
135+
if (pret != PAL_ERROR_SUCCESS) {
136+
ret = -pal_to_unix_errno(pret);
136137
goto out;
137138
}
138139
ret = write_exact(conn->handle, &g_process_ipc_ids.self_vmid,

libos/src/libos_init.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ int create_pipe(char* name, char* uri, size_t size, PAL_HANDLE* hdl, bool use_vm
540540
int ret;
541541
size_t len;
542542
char pipename[PIPE_URI_SIZE];
543+
pal_error_t pret;
543544
PAL_HANDLE pipe = NULL;
544545

545546
assert(hdl);
@@ -566,14 +567,14 @@ int create_pipe(char* name, char* uri, size_t size, PAL_HANDLE* hdl, bool use_vm
566567
if (len >= size)
567568
return -ERANGE;
568569

569-
ret = PalStreamOpen(uri, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED,
570-
/*options=*/0, &pipe);
571-
if (ret < 0) {
572-
if (!use_vmid_for_name && ret == -PAL_ERROR_STREAMEXIST) {
570+
pret = PalStreamOpen(uri, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED,
571+
/*options=*/0, &pipe);
572+
if (pret != PAL_ERROR_SUCCESS) {
573+
if (!use_vmid_for_name && pret == PAL_ERROR_STREAMEXIST) {
573574
/* tried to create a pipe with random name but it already exists */
574575
continue;
575576
}
576-
return pal_to_unix_errno(ret);
577+
return -pal_to_unix_errno(pret);
577578
}
578579

579580
break; /* succeeded in creating the pipe with random/vmid name */

libos/src/libos_pollable_event.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
int create_pollable_event(struct libos_pollable_event* event) {
1414
char uri[PIPE_URI_SIZE];
1515
PAL_HANDLE srv_handle;
16+
pal_error_t pret;
1617
int ret = create_pipe(/*name=*/NULL, uri, sizeof(uri), &srv_handle,
1718
/*use_vmid_for_name=*/false);
1819
if (ret < 0) {
@@ -22,12 +23,12 @@ int create_pollable_event(struct libos_pollable_event* event) {
2223

2324
PAL_HANDLE write_handle;
2425
do {
25-
ret = PalStreamOpen(uri, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED,
26-
PAL_OPTION_NONBLOCK, &write_handle);
27-
} while (ret == -PAL_ERROR_INTERRUPTED);
28-
if (ret < 0) {
29-
log_error("PalStreamOpen failed: %s", pal_strerror(ret));
30-
ret = pal_to_unix_errno(ret);
26+
pret = PalStreamOpen(uri, PAL_ACCESS_RDWR, /*share_flags=*/0, PAL_CREATE_IGNORED,
27+
PAL_OPTION_NONBLOCK, &write_handle);
28+
} while (pret == PAL_ERROR_INTERRUPTED);
29+
if (pret != PAL_ERROR_SUCCESS) {
30+
log_error("PalStreamOpen failed: %s", pal_strerror(pret));
31+
ret = -pal_to_unix_errno(pret);
3132
goto out;
3233
}
3334

0 commit comments

Comments
 (0)