Skip to contentSkip to conversation

RFC: Fix/Add a fast path (async) IPC for ops

PATCH New Mark Hatle 1 participant 3 messages Nov 11

lore
Share & tools
lore

Mark Hatle

author
#0 lore raw

cover RFC: Fix/Add a fast path (async) IPC for ops

In the distant past a 'FASTOP' was implemented, but never actually worked properly.

It was observed that a true fast op could be implemented using an async calling mechanism, however this is implemented differently from the original work. The new work splits IPC channel into two parts. Then the async calls are handled as they can be, or forced before the next sync call. This ensures that all database operations are kept in sync.

Note, this work is on a separate branch as it needs a lot more review before I would feel safe integrating it. It's also not required to fix any bugs, but simply should help with performance.

See the async-ipc branch of pseudo repository.

Mark Hatle (2):
Send client requests over one shared datagram socket Replace FASTOP with requests that don't wait for a reply

 README.security                |   4 +-
 doc/overview                   |   6 +-
 doc/program_flow               |  11 ++
 doc/pseudo_ipc                 |  73 ++++++++++++--
 enums/msg_type.in              |   2 +-
 enums/op.in                    |  50 +++++-----
 ports/common/guts/_Exit.c      |  16 +++
 ports/common/guts/_exit.c      |  16 +++
 ports/common/guts/execv.c      |   4 +
 ports/common/guts/execve.c     |   4 +
 ports/common/guts/execveat.c   |   4 +
 ports/common/guts/execvp.c     |   4 +
 ports/common/guts/execvpe.c    |   4 +
 ports/common/guts/fexecve.c    |   4 +
 ports/common/pseudo_wrappers.c |  34 +++++++
 ports/common/wrapfuncs.in      |   2 +
 pseudo.1                       |  23 ++++-
 pseudo.c                       |   2 +-
 pseudo.h                       |   1 +
 pseudo_client.c                | 222 +++++++++++++++++++++++++++++++----------
 pseudo_client.h                |   2 +
 pseudo_ipc.c                   |  42 ++++++++
 pseudo_ipc.h                   |   8 ++
 pseudo_server.c                | 186 +++++++++++++++++++++++++++++-----
 pseudo_util.c                  |   1 +
 pseudo_wrappers.c              |  43 ++++++++
 test/test-async-abort.c        |  44 ++++++++
 test/test-async-abort.sh       |  40 ++++++++
 test/test-async-order.c        | 188 ++++++++++++++++++++++++++++++++++
 test/test-async-order.sh       |  23 +++++
 30 files changed, 946 insertions(+), 117 deletions(-)
 create mode 100644 ports/common/guts/_Exit.c
 create mode 100644 ports/common/guts/_exit.c
 create mode 100644 test/test-async-abort.c
 create mode 100755 test/test-async-abort.sh
 create mode 100644 test/test-async-order.c
 create mode 100755 test/test-async-order.sh
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 1/2 Send client requests over one shared datagram socket

From: Mark Hatle <[email protected]>

The server handles each client's stream connection separately, so it has no way to tell the order of requests queued by different clients. That doesn't matter while every client waits for each reply, but it prevents sending requests without waiting: a process could change a file, tell another process, and that process's question could be answered first.

Have clients send all requests, after the initial PING, to a datagram socket shared by all clients, pseudo.request. The kernel queues datagrams in the order they were sent, so the server handles requests in that order even across processes. Replies still go back over each client's stream connection, which also carries PING and SHUTDOWN and tells the server when a client goes away.

Requests carry the client's slot and a per-connection serial number, returned by the PING, so a request still queued from a client that has gone away is applied but never answered on a reused slot. The server reads each request with one recv() instead of FIONREAD plus two reads, and drains the socket before exiting.

AI-Generated: Uses GitHub Copilot

---
 README.security |   4 +-
 doc/overview    |   3 +-
 doc/pseudo_ipc  |  36 +++++++++++++
 pseudo.h        |   1 +
 pseudo_client.c | 150 +++++++++++++++++++++++++++++++++++++-----------------
 pseudo_ipc.c    |  42 ++++++++++++++++
 pseudo_ipc.h    |   8 +++
 pseudo_server.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 8 files changed, 348 insertions(+), 50 deletions(-)
README.security +2 -2
index 45533f2..5564448 100644
@@ -133,9 +133,9 @@ ignore mismatch errors in pseudo's log.
 
 6. THE SERVER TRUSTS ITS CLIENTS
 
-The pseudo server listens on a Unix socket in its local state directory
+The pseudo server listens on Unix sockets in its local state directory
 and does not authenticate clients beyond the filesystem permissions of
-that socket.  Any process running as the build user can connect and
+those sockets.  Any process running as the build user can connect and
 change the database, and the database files themselves are writable by
 that user.  The resulting metadata can only be trusted as much as every
 process running as the build user.
doc/overview +2 -1
index 96c883d..c9497e5 100644
@@ -19,7 +19,8 @@ to the virtual environment.
 
 Underlying this is access to a server process, which is automatically
 spawned by the library if one is not available.  The server process maintains
-a UNIX domain socket while it is active, and maintains a database (using
+UNIX domain sockets while it is active (see doc/pseudo_ipc), and maintains a
+database (using
 sqlite) of files known to the system.  Files are recorded in the database
 only if they are created within the virtualized environment or have been
 altered by it; files merely read are not added.
doc/pseudo_ipc +36 -0
index 0d9d6cd..e4ec750 100644
@@ -1,5 +1,28 @@
 MESSAGE PASSING
 
+The server has two UNIX domain sockets in its local state directory:
+
+pseudo.socket
+	A stream socket.  Each client connects to it, sends a PING to
+	register, and gets every reply on this connection.  pseudo -S
+	also sends its SHUTDOWN request here, and the server notices a
+	client going away when the connection closes.
+
+pseudo.request
+	A datagram socket shared by all clients.  Every request after the
+	initial PING is sent here.
+
+The kernel queues datagrams from all senders on the one socket in the
+order they were sent, so the server handles requests in that order even
+across processes.  Once a client's send has returned, its request is
+queued ahead of anything another client sends afterwards.  If a process
+changes a file and then tells another process about it (through a pipe,
+by exiting, or any other way), the server has already queued the change
+by the time the second process can ask about the file.
+
+It also means the server reads each request with a single recv(),
+rather than a header and then a path.
+
 typedef struct {
 	pseudo_msg_type_t type;
 	pseudo_op_t op;
@@ -16,6 +39,8 @@ typedef struct {
 	unsigned int pathlen;
 	int nlink;
 	int deleting;
+	int client_id;
+	unsigned int client_serial;
 	char path[];
 } pseudo_msg_t;
 
@@ -44,6 +69,11 @@ only sends PING, OP, or FASTOP.  FASTOP is used for operations whose result
 the client doesn't need, but the server still replies with ACK (or NAK on
 failure) and the client still waits for that reply.
 
+A PING on the stream socket registers the client: the reply gives it the
+client_id and client_serial to put in its requests.  A PING on the
+request socket is answered once every request the client sent before it
+has been handled.
+
 When run with '-S', the pseudo program
 runs as a client, sending a SHUTDOWN message to a server -- but only if
 it can find one, it does not start a new one.  In this case, the server
@@ -84,6 +114,12 @@ deleting carries the database's "deleting" mark (see doc/database) when
 the server looks up file entries.  The server uses it internally; the
 client doesn't set or use it.
 
+client_id and client_serial identify the client's stream connection in
+requests on the shared socket, so the server knows where to reply.  The
+server numbers every connection, so a request still queued from a client
+that has gone away is never answered on a connection that has since
+reused its client_id; the server applies it without replying.
+
 32/64 bit:  This structure should have the same offsets for every element,
 including path, on both 64-bit and 32-bit machines.  (Check with 'offsets.c'.)
 It is *not* an error if sizeof(pseudo_msg_t) is different; the padding
pseudo.h +1 -0
index 6a7339b..253a21d 100644
@@ -131,6 +131,7 @@ extern char *pseudo_version;
 #define PSEUDO_PATHLOCK "pseudo.pathlock"
 #define PSEUDO_PIDFILE "pseudo.pid"
 #define PSEUDO_SOCKET "pseudo.socket"
+#define PSEUDO_REQUEST_SOCKET "pseudo.request"
 
 #define PSEUDO_SEVERITY_DEFAULT "info,warn,error"
 
pseudo_client.c +104 -46

248 lines not on this page · raw message

pseudo_ipc.c +42 -0

48 lines not on this page · raw message

pseudo_ipc.h +8 -0
index d945257..1fc20a9 100644
@@ -26,6 +26,8 @@ typedef struct {
 	unsigned int pathlen;
 	int nlink;
 	int deleting;
+	int client_id;
+	unsigned int client_serial;
 	char path[];
 } pseudo_msg_t;
 
@@ -47,7 +49,13 @@ extern int pseudo_access_fopen(const char *);
 
 #define PSEUDO_HEADER_SIZE (offsetof(pseudo_msg_t, path))
 
+/* largest request sent over the datagram socket: two paths for rename,
+ * or a path plus an xattr name and value (at most 64KB)
+ */
+#define PSEUDO_MAX_REQUEST (256 * 1024)
+
 extern pseudo_msg_t *pseudo_msg_receive(int fd);
+extern pseudo_msg_t *pseudo_msg_receive_request(int fd);
 extern pseudo_msg_t *pseudo_msg_dup(pseudo_msg_t *);
 extern pseudo_msg_t *pseudo_msg_dupheader(pseudo_msg_t *);
 extern pseudo_msg_t *pseudo_msg_new(size_t, const char *);
pseudo_server.c +153 -1

214 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH 2/2 Replace FASTOP with requests that don't wait for a reply

In reply to Mark Hatle

From: Mark Hatle <[email protected]>

Most requests only tell the server about a change, such as chown, chmod, creat, rename or unlink, and the client ignores the reply, but it still waited for every one.

FASTOP was meant to avoid that, but it sent requests over each client's own connection, so another process could overtake a change it had been told about, and it dropped errors. "Half-undo FASTOP" (449c234) fixed the errors by having the client wait for every reply again, leaving FASTOP identical to OP; the server's early-ACK path never ran because the message type had already been changed to ACK or NAK. Remove it, its op "wait" column and the dead server code.

Since requests are now handled in the order they were sent, even across processes, send these as a new PSEUDO_MSG_ASYNC type without waiting. The ops are marked in a new "async" column in enums/op.in.

The server only replies to an async request if the client must abort, for instance after a path mismatch. The client reads that reply ahead of the reply to its next synchronous request and aborts then. So that an abort isn't lost, a client with requests outstanding waits for them with a PING on the request socket before exec() and at exit; the exit check doesn't wait for the pseudo lock, which another thread may hold indefinitely. _exit() and _Exit() skip destructors, and are used by forked workers such as Python's multiprocessing, so wrap them to wait as well. PSEUDO_SYNC=1 makes every request wait, so the client aborts in the call that caused the problem.

On a tar/chown/find/ls/rm workload of 40,000 files this takes the run from 21.8s to 14.3s.

Add tests that changes made without waiting are seen by other processes told about them through a pipe or by reaping the process, and that an abort is still delivered, at the next synchronous request, _exit() or execvpe(), with and without PSEUDO_SYNC.

AI-Generated: Uses GitHub Copilot

---
 doc/overview                   |   3 +-
 doc/program_flow               |  11 +++
 doc/pseudo_ipc                 |  43 +++++++---
 enums/msg_type.in              |   2 +-
 enums/op.in                    |  50 +++++------
 ports/common/guts/_Exit.c      |  16 ++++
 ports/common/guts/_exit.c      |  16 ++++
 ports/common/guts/execv.c      |   4 +
 ports/common/guts/execve.c     |   4 +
 ports/common/guts/execveat.c   |   4 +
 ports/common/guts/execvp.c     |   4 +
 ports/common/guts/execvpe.c    |   4 +
 ports/common/guts/fexecve.c    |   4 +
 ports/common/pseudo_wrappers.c |  34 ++++++++
 ports/common/wrapfuncs.in      |   2 +
 pseudo.1                       |  23 ++++-
 pseudo.c                       |   2 +-
 pseudo_client.c                |  72 +++++++++++++++-
 pseudo_client.h                |   2 +
 pseudo_server.c                |  42 ++++-----
 pseudo_util.c                  |   1 +
 pseudo_wrappers.c              |  43 ++++++++++
 test/test-async-abort.c        |  44 ++++++++++
 test/test-async-abort.sh       |  40 +++++++++
 test/test-async-order.c        | 188 +++++++++++++++++++++++++++++++++++++++++
 test/test-async-order.sh       |  23 +++++
 26 files changed, 606 insertions(+), 75 deletions(-)
 create mode 100644 ports/common/guts/_Exit.c
 create mode 100644 ports/common/guts/_exit.c
 create mode 100644 test/test-async-abort.c
 create mode 100755 test/test-async-abort.sh
 create mode 100644 test/test-async-order.c
 create mode 100755 test/test-async-order.sh
doc/overview +2 -1
index c9497e5..7b7ab1e 100644
@@ -47,7 +47,8 @@ client can restart it.)
 4.  The server code.  This code is fairly simple; all it does is maintain
 the database of file information.  Operations consist either of a request
 for information (e.g., a stat(2) call) or notification of a change.  The
-server sends back failure or success notices.
+server sends back failure or success notices for requests for information;
+notifications of a change are sent without waiting for a reply.
 
 As a fairly typical example, the progress of a stat(2) call is:
 
doc/program_flow +11 -0
index 5fbdb5d..174f443 100644
@@ -14,6 +14,8 @@ libpseudo execution flow:
 			setup pseudo_functions
 			setup log files (PSEUDO_DEBUG_FILE, PSEUDO_EVLOG_FILE)
 		pseudo_client.c: pseudo_init_client()
+			wait for this process's asynchronous requests
+			setup PSEUDO_SYNC
 			setup PSEUDO_DISABLED
 			setup pseudo_localstate_dir_fd
 			setup PSEUDO_NOSYMLINKEXP
@@ -30,6 +32,7 @@ libpseudo execution flow:
 			pseudo_setupenv()
 			if PSEUDO_UNLOAD
 				pseudo_dropenv()
+			pseudo_client_flush()
 			real_exec*()
 
 	fork()
@@ -77,6 +80,14 @@ libpseudo execution flow:
 		unmask signals (if they were blocked above)
 		return rc
 
+	# on exit #
+
+	pseudo_wrappers.c: (destructor) _libpseudo_fini(), or _exit()/_Exit()
+		pseudo_exit_flush()
+			if this process has asynchronous requests pending,
+			and the lock is free (or already ours)
+				pseudo_client_flush()
+
 pseudo execution flow:
 	pseudo.c: main()
 		pseudo_util.c: pseudo_init_util()
doc/pseudo_ipc +30 -13

71 lines not on this page · raw message

enums/msg_type.in +1 -1
index 578d571..8435599 100644
@@ -4,4 +4,4 @@ shutdown
 op
 ack
 nak
-fastop
+async
enums/op.in +25 -25

55 lines not on this page · raw message

ports/common/guts/_Exit.c new file +16 -0
new file mode 100644
index 0000000..5c93d2d
@@ -0,0 +1,16 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * void _Exit(int status)
+ */
+
+	/* NOTE THAT THIS IS NEVER USED!
+	 * The hand-written _Exit() in ../pseudo_wrappers.c flushes
+	 * asynchronous requests and exits directly.
+	 */
+
+	real__Exit(status);
+
+/*	return;
+ * }
+ */
ports/common/guts/_exit.c new file +16 -0
new file mode 100644
index 0000000..06f2520
@@ -0,0 +1,16 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * void _exit(int status)
+ */
+
+	/* NOTE THAT THIS IS NEVER USED!
+	 * The hand-written _exit() in ../pseudo_wrappers.c flushes
+	 * asynchronous requests and exits directly.
+	 */
+
+	real__exit(status);
+
+/*	return;
+ * }
+ */
ports/common/guts/execv.c +4 -0
index d4031b3..dc3540b 100644
@@ -33,6 +33,10 @@
 	/* if exec() fails, we may end up taking signals unexpectedly...
 	 * not much we can do about that.
 	 */
+	/* exec() skips destructors, so collect errors for requests
+	 * sent without waiting now
+	 */
+	pseudo_client_flush();
 	sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL);
 	rc = real_execv(file, argv);
 
ports/common/guts/execve.c +4 -0
index de2f1d4..29cb637 100644
@@ -27,6 +27,10 @@
 	/* if exec() fails, we may end up taking signals unexpectedly...
 	 * not much we can do about that.
 	 */
+	/* exec() skips destructors, so collect errors for requests
+	 * sent without waiting now
+	 */
+	pseudo_client_flush();
 	sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL);
 	rc = real_execve(file, argv, new_environ);
 
ports/common/guts/execveat.c +4 -0
index 10e0d52..b591dc4 100644
@@ -19,6 +19,10 @@
 	if (pseudo_has_unload(new_environ))
 		new_environ = pseudo_dropenvp(new_environ);
 
+	/* exec() skips destructors, so collect errors for requests
+	 * sent without waiting now
+	 */
+	pseudo_client_flush();
 	sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL);
 	rc = real_execveat(dirfd, path, argv, new_environ, flags);
 
ports/common/guts/execvp.c +4 -0
index ffc94be..2d0c8f2 100644
@@ -33,6 +33,10 @@
 	/* if exec() fails, we may end up taking signals unexpectedly...
 	 * not much we can do about that.
 	 */
+	/* exec() skips destructors, so collect errors for requests
+	 * sent without waiting now
+	 */
+	pseudo_client_flush();
 	sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL);
 	rc = real_execvp(file, argv);
 
ports/common/guts/execvpe.c +4 -0
index 37e4927..5fc544b 100644
@@ -19,6 +19,10 @@
 	if (pseudo_has_unload(new_environ))
 		new_environ = pseudo_dropenvp(new_environ);
 
+	/* exec() skips destructors, so collect errors for requests
+	 * sent without waiting now
+	 */
+	pseudo_client_flush();
 	sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL);
 	rc = real_execvpe(file, argv, new_environ);
 
ports/common/guts/fexecve.c +4 -0
index a0162d3..8e64ae0 100644
@@ -11,6 +11,10 @@
 	if (pseudo_has_unload(new_environ))
 		new_environ = pseudo_dropenvp(new_environ);
 
+	/* exec() skips destructors, so collect errors for requests
+	 * sent without waiting now
+	 */
+	pseudo_client_flush();
 	sigprocmask(SIG_SETMASK, &pseudo_saved_sigmask, NULL);
 	rc = real_fexecve(fd, argv, new_environ);
 
ports/common/pseudo_wrappers.c +34 -0
index 2ad0814..a391b48 100644
@@ -445,6 +445,29 @@ execveat(int dirfd, const char *path, char *const *argv, char *const *envp, int
 	return rc;
 }
 
+/* _exit() skips destructors, so collect errors for requests sent
+ * without waiting here instead.
+ */
+void
+_exit(int status) {
+	pseudo_exit_flush();
+	if (real__exit)
+		real__exit(status);
+	syscall(SYS_exit_group, status);
+	for (;;)
+		;
+}
+
+void
+_Exit(int status) {
+	pseudo_exit_flush();
+	if (real__Exit)
+		real__Exit(status);
+	syscall(SYS_exit_group, status);
+	for (;;)
+		;
+}
+
 /* no profiling in fork because it wouldn't work anyway
  * half the time
  */
@@ -543,6 +566,17 @@ wrap_execveat(int dirfd, const char *path, char *const *argv, char *const *envp,
 	return rc;
 }
 
+/* not used, the hand-written wrappers flush and exit directly */
+static void
+wrap__exit(int status) {
+	(void) status;
+}
+
+static void
+wrap__Exit(int status) {
+	(void) status;
+}
+
 static int
 wrap_fork(void) {
 	int rc = -1;
ports/common/wrapfuncs.in +2 -0
index 9b01bf2..10a5fae 100644
@@ -10,3 +10,5 @@ int posix_spawnp(pid_t *pid, const char *file, const posix_spawn_file_actions_t
 int execvpe(const char *file, char *const *argv, char *const *envp); /* hand_wrapped=1 */
 int fexecve(int fd, char *const *argv, char *const *envp); /* hand_wrapped=1 */
 int execveat(int dirfd, const char *path, char *const *argv, char *const *envp, int flags); /* hand_wrapped=1 */
+void _exit(int status); /* hand_wrapped=1 */
+void _Exit(int status); /* hand_wrapped=1 */
pseudo.1 +20 -3
index 2ccf6bd..2475631 100644
@@ -798,6 +798,21 @@ suppresses informational messages or warnings; errors are always shown.
 The default is
 .IR info,warn,error .
 .TP 8
+.B PSEUDO_SYNC
+By default, requests whose result the client doesn't use, such as
+.IR chown(2)
+or
+.IR chmod(2) ,
+are sent to the server without waiting for it to handle them.  The
+server still handles every request in the order clients sent it, so
+other processes always see the change.  If the server asks the client
+to abort, for instance after a path mismatch, the client aborts at its
+next request that does wait for a reply, or before
+.IR exec(3)
+or exiting.  If this variable is set to a value other than 0, the
+client waits for every request, so it aborts in the call that caused
+the problem.  This is slower, but can help when debugging.
+.TP 8
 .BR PSEUDO_UIDS ,\  PSEUDO_GIDS
 These variables are used internally to pass information about the current
 emulated user and group identity from one process to another.
@@ -855,9 +870,11 @@ or debugged in that context.
 Filesystem performance is noticably worse under
 .I pseudo
 than it is otherwise.  This is probably because nearly every operation
-(other than reads and writes) involves at least one round-trip network
-communication with the server, and probably some kind of database
-activity.
+(other than reads and writes) involves a message to the server, and
+probably some kind of database activity.  Operations that ask about a
+file wait for the server's reply; ones that only report a change do not
+(see
+.BR PSEUDO_SYNC ).
 
 .SH SECURITY
 .I pseudo
pseudo.c +1 -1
index 26c7a36..70f439d 100644
@@ -1087,7 +1087,7 @@ pseudo_server_response(pseudo_msg_t *msg, const char *program, const char *tag,
 		return 0;
 		break;
 	case PSEUDO_MSG_OP:
-	case PSEUDO_MSG_FASTOP:
+	case PSEUDO_MSG_ASYNC:
 		return pseudo_op(msg, program, tag, response_path, response_len);
 		break;
 	case PSEUDO_MSG_ACK:		/* FALLTHROUGH */
pseudo_client.c +68 -4

128 lines not on this page · raw message

pseudo_client.h +2 -0
index ef959e6..b9a8405 100644
@@ -19,6 +19,8 @@ extern void pseudo_magic(void);
 extern void pseudo_client_touchuid(void);
 extern void pseudo_client_touchgid(void);
 extern int pseudo_client_shutdown(int);
+extern void pseudo_client_flush(void);
+extern int pseudo_client_flush_needed(void);
 extern int pseudo_fd(int fd, int how);
 extern int pseudo_client_path_lock(int shared);
 extern void pseudo_client_path_unlock(int fd);
pseudo_server.c +15 -27

89 lines not on this page · raw message

pseudo_util.c +1 -0
index d9312d0..4253eaa 100644
@@ -58,6 +58,7 @@ static struct pseudo_variables pseudo_env[] = {
 	{ "PSEUDO_DISABLED", 15, NULL },
 	{ "PSEUDO_UNLOAD", 13, NULL },
 	{ "PSEUDO_ALLOW_FSYNC", 18, NULL },
+	{ "PSEUDO_SYNC", 11, NULL },
 #ifdef PSEUDO_PROFILING
 	{ "PSEUDO_PROFILE_PATH", 19, NULL },
 #endif
pseudo_wrappers.c +43 -0

69 lines not on this page · raw message

test/test-async-abort.c new file +44 -0

44 lines not on this page · raw message

test/test-async-abort.sh new file +40 -0
new file mode 100755
index 0000000..53cef39
@@ -0,0 +1,40 @@
+#!/bin/bash
+#
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+# A chown() whose database entry has another name makes the server tell
+# the client to abort.  chown() is sent without waiting, so the client
+# must still abort: at its next request that waits for a reply, or when
+# it leaves with _exit() or execs another program.  With PSEUDO_SYNC set,
+# it must abort inside chown() itself.
+#
+# The temporary tree has to live below $PWD so that pseudo tracks it.
+
+tmpdir="$(mktemp -d -p "$PWD" async_abort_XXXXXX)"
+trap "rm -rf '$tmpdir'" EXIT TERM INT
+
+rc=0
+check() {
+    local sync="$1" how="$2" expect="$3" out status
+    : > "$tmpdir/a"
+    # rename it behind pseudo's back, so the database still says "a"
+    PSEUDO_DISABLED=1 mv "$tmpdir/a" "$tmpdir/b"
+    out=$(PSEUDO_SYNC=$sync ./test/test-async-abort "$tmpdir/b" "$how" 2>/dev/null)
+    status=$?
+    # put the name back so the database entry can be removed cleanly
+    PSEUDO_DISABLED=1 mv "$tmpdir/b" "$tmpdir/a"
+    rm -f "$tmpdir/a"
+    if [ $status -ne 134 ]; then
+        echo "FAILED: $how: expected abort (PSEUDO_SYNC=${sync:-unset}), got status $status"
+        rc=1
+    elif [ "$out" != "$expect" ]; then
+        echo "FAILED: $how: PSEUDO_SYNC=${sync:-unset}: expected output '$expect', got '$out'"
+        rc=1
+    fi
+}
+
+for how in stat _exit execvpe; do
+    check "" $how "returned"
+done
+check 1 stat ""
+exit $rc
test/test-async-order.c new file +188 -0

188 lines not on this page · raw message

test/test-async-order.sh new file +23 -0
new file mode 100755
index 0000000..5dee635
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+# Ownership and mode changes are sent to the server without waiting for a
+# reply.  Another process that learns of a change, through a pipe or by
+# reaping the process that made it, must see the new values.  Run it
+# both with and without PSEUDO_SYNC, which makes every request wait.
+#
+# The temporary tree has to live below $PWD so that pseudo tracks it.
+
+tmpdir="$(mktemp -d -p "$PWD" async_order_XXXXXX)"
+trap "rm -rf '$tmpdir'" EXIT TERM INT
+
+rc=0
+for sync in "" 1; do
+    rm -f "$tmpdir"/f*
+    if ! PSEUDO_SYNC=$sync ./test/test-async-order "$tmpdir" 500; then
+        echo "FAILED: ordering broken (PSEUDO_SYNC=${sync:-unset})"
+        rc=1
+    fi
+done
+exit $rc
Signature · 1 line
1.8.3.1