From patchwork Tue May 14 16:56:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 64426 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id E82D927BBE9; Tue, 14 May 2024 17:57:31 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id C73ED27BBE2 for ; Tue, 14 May 2024 17:57:30 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6vSd-00015O-Ve; Tue, 14 May 2024 12:57:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s6vSb-000155-8Y for guix-patches@gnu.org; Tue, 14 May 2024 12:57:05 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s6vSa-00047g-Ug; Tue, 14 May 2024 12:57:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s6vSY-0001uj-Jv; Tue, 14 May 2024 12:57:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70947] [PATCH] store: Refactor connect-to-daemon. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 14 May 2024 16:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 70947 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70947@debbugs.gnu.org Cc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by submit@debbugs.gnu.org id=B.17157057807340 (code B ref -1); Tue, 14 May 2024 16:57:02 +0000 Received: (at submit) by debbugs.gnu.org; 14 May 2024 16:56:20 +0000 Received: from localhost ([127.0.0.1]:40344 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s6vRr-0001uK-LC for submit@debbugs.gnu.org; Tue, 14 May 2024 12:56:20 -0400 Received: from lists.gnu.org ([209.51.188.17]:36068) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s6vRn-0001uA-2A for submit@debbugs.gnu.org; Tue, 14 May 2024 12:56:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s6vRl-000108-99 for guix-patches@gnu.org; Tue, 14 May 2024 12:56:13 -0400 Received: from mira.cbaines.net ([212.71.252.8]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6vRi-0003bO-Ve for guix-patches@gnu.org; Tue, 14 May 2024 12:56:12 -0400 Received: from localhost (unknown [45.67.83.168]) by mira.cbaines.net (Postfix) with ESMTPSA id A3B8827BBE2 for ; Tue, 14 May 2024 17:56:07 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 451e25a1 for ; Tue, 14 May 2024 16:56:05 +0000 (UTC) From: Christopher Baines Date: Tue, 14 May 2024 17:56:05 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Received-SPF: pass client-ip=212.71.252.8; envelope-from=mail@cbaines.net; helo=mira.cbaines.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Remove the inner connect procedure, as now that #:non-blocking? needs passing on, this just makes things more difficult. This commit also fixes not passing #:non-blocking? on in the case where open-unix-domain-socket is called as connect. * guix/store.scm (connect-to-daemon): Refactor and fix non-blocking connections to sockets with a filename. Change-Id: I61cd99920df91baba95567d670bec6fa94043875 --- guix/store.scm | 69 +++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 37 deletions(-) base-commit: 6e86089d563ccb67ae04cd941ca7b66c1777831f diff --git a/guix/store.scm b/guix/store.scm index 58ddaa8d15..4070b686cb 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -524,50 +524,45 @@ (define* (open-inet-socket host port #:key non-blocking?) (errno (system-error-errno args))))) (loop rest))))))))) -(define* (connect-to-daemon uri #:key non-blocking?) - "Connect to the daemon at URI, a string that may be an actual URI or a file -name, and return an input/output port. If NON-BLOCKING?, use a non-blocking -socket when using the file, unix or guix URI schemes. +(define* (connect-to-daemon uri-or-filename #:key non-blocking?) + "Connect to the daemon at URI-OR-FILENAME and return an input/output port. +If NON-BLOCKING?, use a non-blocking socket when using the file, unix or guix +URI schemes. This is a low-level procedure that does not perform the initial handshake with the daemon. Use 'open-connection' for that." (define (not-supported) (raise (condition (&store-connection-error - (file uri) + (file uri-or-filename) (errno ENOTSUP))))) - (define connect - (match (string->uri uri) - (#f ;URI is a file name - open-unix-domain-socket) - ((? uri? uri) - (match (uri-scheme uri) - ((or #f 'file 'unix) - (lambda (_) - (open-unix-domain-socket (uri-path uri) - #:non-blocking? non-blocking?))) - ('guix - (lambda (_) - (open-inet-socket (uri-host uri) - (or (uri-port uri) %default-guix-port) - #:non-blocking? non-blocking?))) - ((? symbol? scheme) - ;; Try to dynamically load a module for SCHEME. - ;; XXX: Errors are swallowed. - (match (false-if-exception - (resolve-interface `(guix store ,scheme))) - ((? module? module) - (match (false-if-exception - (module-ref module 'connect-to-daemon)) - ((? procedure? connect) - (lambda (_) - (connect uri))) - (x (not-supported)))) - (#f (not-supported)))) - (x - (not-supported)))))) - - (connect uri)) + (match (string->uri uri-or-filename) + (#f ;URI is a file name + (open-unix-domain-socket uri-or-filename + #:non-blocking? non-blocking?)) + ((? uri? uri) + (match (uri-scheme uri) + ((or #f 'file 'unix) + (open-unix-domain-socket (uri-path uri) + #:non-blocking? non-blocking?)) + ('guix + (open-inet-socket (uri-host uri) + (or (uri-port uri) %default-guix-port) + #:non-blocking? non-blocking?)) + ((? symbol? scheme) + ;; Try to dynamically load a module for SCHEME. + ;; XXX: Errors are swallowed. + (match (false-if-exception + (resolve-interface `(guix store ,scheme))) + ((? module? module) + (match (false-if-exception + (module-ref module 'connect-to-daemon)) + ((? procedure? connect) + (connect uri)) + (x (not-supported)))) + (#f (not-supported)))) + (x + (not-supported)))))) (define* (open-connection #:optional (uri (%daemon-socket-uri)) #:key port (reserve-space? #t) cpu-affinity