From patchwork Tue Apr 23 20:47:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Sent X-Patchwork-Id: 63325 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 31A9227BBE2; Tue, 23 Apr 2024 21:50:34 +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.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham 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 1830D27BBE9 for ; Tue, 23 Apr 2024 21:50:30 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rzN5i-0003Wb-Up; Tue, 23 Apr 2024 16:50:16 -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 1rzN5Z-0003SO-1I for guix-patches@gnu.org; Tue, 23 Apr 2024 16:50: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 1rzN5Y-0003hp-4c for guix-patches@gnu.org; Tue, 23 Apr 2024 16:50:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rzN5o-0003kl-JS for guix-patches@gnu.org; Tue, 23 Apr 2024 16:50:20 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70542] [PATCH 3/4] file-systems: Add support for mounting CIFS file systems Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 23 Apr 2024 20:50:20 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70542 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70542@debbugs.gnu.org Cc: Richard Sent Received: via spool by 70542-submit@debbugs.gnu.org id=B70542.171390535313685 (code B ref 70542); Tue, 23 Apr 2024 20:50:20 +0000 Received: (at 70542) by debbugs.gnu.org; 23 Apr 2024 20:49:13 +0000 Received: from localhost ([127.0.0.1]:54265 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rzN4b-0003XQ-Qk for submit@debbugs.gnu.org; Tue, 23 Apr 2024 16:49:11 -0400 Received: from mail-108-mta217.mxroute.com ([136.175.108.217]:38211) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rzN3h-0003N5-VT for 70542@debbugs.gnu.org; Tue, 23 Apr 2024 16:48:17 -0400 Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta217.mxroute.com (ZoneMTA) with ESMTPSA id 18f0cb701b30003bea.001 for <70542@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 23 Apr 2024 20:47:51 +0000 X-Zone-Loop: 20718e557b230361005c5e9978407a7cec17626c1460 X-Originating-IP: [136.175.111.2] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=hF0faV2T67I+4RAauNmiSl9RRGb3R2Gw5DORSuQpHLg=; b=iKHYhzqAu+M0UDae3lX/b0oxU6 xU7k54SXSiGWt0zaAh5sh7IV87wEpsx8k0o9Z4Ty3jDjmWq5Au8ODHpLTg5hl3boco8dLYQauNmLZ KhfhDA8wDAhAXFI2yc0bTg8qHlBi2IQkqbkZvv2WhOL6D8IXaj+xSPNuHEKv9WPUs2LwuDmy+JQMm CrFRD4tkTCScAyimVdOGAD6Iub0I6f/OFCZWIulBYk1hwqeMeUe+m3t7Cgz5Q42OwPgaFXEp7Wgga L3bCAHzGDOtOCMr2jdOgcgrxnVOncgXHQYpII2UUVb7YKx9xlNyT+6tssFzhkdYfYlESVAM26VFEI /7yn1DZQ==; From: Richard Sent Date: Tue, 23 Apr 2024 16:47:21 -0400 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Authenticated-Id: richard@freakingpenguin.com 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 * gnu/build/file-systems (canonicalize-device-name): Do not attempt to resolve CIFS formatted device specifications. * gnu/build/file-systems (mount-file-system): Add (mount-cifs) and (host-to-ip). Logic for ip/host to ip resolution was duplicated with mount-nfs, so isolate into a dedicated function. Change-Id: I522d70a10651ca79533a4fc60b96b884243a3526 --- gnu/build/file-systems.scm | 60 +++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index 78d779f398..ae29b36c4e 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -8,6 +8,7 @@ ;;; Copyright © 2020 Maxim Cournoyer ;;; Copyright © 2022 Oleg Pykhalov ;;; Copyright © 2024 Nicolas Graves +;;; Copyright © 2024 Richard Sent ;;; ;;; This file is part of GNU Guix. ;;; @@ -37,6 +38,7 @@ (define-module (gnu build file-systems) #:use-module (rnrs bytevectors) #:use-module (ice-9 match) #:use-module (ice-9 rdelim) + #:use-module (ice-9 regex) #:use-module (system foreign) #:autoload (system repl repl) (start-repl) #:use-module (srfi srfi-1) @@ -1047,8 +1049,11 @@ (define (canonicalize-device-spec spec) (match spec ((? string?) - (if (or (string-contains spec ":/") (string=? spec "none")) - spec ; do not resolve NFS / tmpfs devices + (if (or (string-contains spec ":/") ;nfs + (and (>= (string-length spec) 2) + (equal? (string-take spec 2) "//")) ;cifs + (string=? spec "none")) + spec ; do not resolve NFS / CIFS / tmpfs devices ;; Nothing to do, but wait until SPEC shows up. (resolve identity spec identity))) ((? file-system-label?) @@ -1156,6 +1161,14 @@ (define* (mount-file-system fs #:key (root "/root") (repair (file-system-repair fs))) "Mount the file system described by FS, a object, under ROOT." + (define* (host-to-ip host #:optional service) + "Return the IP address for host, which may be an IP address or a hostname." + (let* ((aa (match (getaddrinfo host service) ((x . _) x))) + (sa (addrinfo:addr aa)) + (inet-addr (inet-ntop (sockaddr:fam sa) + (sockaddr:addr sa)))) + inet-addr)) + (define (mount-nfs source mount-point type flags options) (let* ((idx (string-rindex source #\:)) (host-part (string-take source idx)) @@ -1163,11 +1176,7 @@ (define* (mount-file-system fs #:key (root "/root") (host (match (string-split host-part (string->char-set "[]")) (("" h "") h) ((h) h))) - (aa (match (getaddrinfo host "nfs") ((x . _) x))) - (sa (addrinfo:addr aa)) - (inet-addr (inet-ntop (sockaddr:fam sa) - (sockaddr:addr sa)))) - + (inet-addr (host-to-ip host "nfs"))) ;; Mounting an NFS file system requires passing the address ;; of the server in the addr= option (mount source mount-point type flags @@ -1176,6 +1185,41 @@ (define* (mount-file-system fs #:key (root "/root") (if options (string-append "," options) ""))))) + + (define (mount-cifs source mount-point type flags options) + ;; Source is of form "///" + (let* ((regex-match (string-match "//([^/]+)/(.+)" source)) + (server (match:substring regex-match 1)) + (share (match:substring regex-match 2)) + ;; Match ",guest,", ",guest$", "^guest,", or "^guest$," not + ;; e.g. user=foo,pass=notaguest + (guest? (string-match "(^|,)(guest)($|,)" options)) + ;; Perform DNS resolution now instead of attempting kernel dns + ;; resolver upcalling. /sbin/request-key does not exist and the + ;; kernel hardcodes the path. + ;; + ;; (getaddrinfo) doesn't support cifs service, so omit it. + (inet-addr (host-to-ip server))) + (mount source mount-point type flags + (string-append "ip=" + inet-addr + ;; As of Linux af1a3d2ba9 (v5.11) unc is ignored + ;; and source is parsed by the kernel + ;; directly. Pass it for compatibility. + ",unc=" + ;; Match format of mount.cifs's mount syscall. + "\\\\" server "\\" share + (if guest? + ",user=,pass=" + "") + (if options + ;; No need to delete "guest" from options. + ;; linux/fs/smb/client/fs_context.c explicitly + ;; ignores it. Also, avoiding excess commas + ;; when deleting is a pain. + (string-append "," options) + ""))))) + (let* ((type (file-system-type fs)) (source (canonicalize-device-spec (file-system-device fs))) (target (string-append root "/" @@ -1210,6 +1254,8 @@ (define* (mount-file-system fs #:key (root "/root") (cond ((string-prefix? "nfs" type) (mount-nfs source target type flags options)) + ((string-prefix? "cifs" type) + (mount-cifs source target type flags options)) ((memq 'shared (file-system-flags fs)) (mount source target type flags options) (mount "none" target #f MS_SHARED))