Subject: [bug#41143] [PATCH v2 1/2] mapped-devices: Allow target to be list of strings.

From: Ludovic Courtès <[email-masked]>
Date: Thu, 05 Nov 2020 10:48:39 +0100

Hi Mikhail,

Did you have a chance to look into the proposed changes?

  https://issues.guix.gnu.org/41143

Would be nice to have LVM support integrated!

TIA,
Ludo’.

Ludovic Courtès <[email-masked]> skribis:

> Hi Mikhail,
>
> Mikhail Tsykalov <[email-masked]> skribis:
>
>> * gnu/system/mapped-devices.scm (<mapped-device>): Rename constructor to
>> %mapped-device.
>> [target]: Remove field.
>> [targets]: New field. Adjust users.
>> (mapped-device-compatibility-helper, mapped-device): New macros.
>> (mapped-device-target): New deprecated procedure.
>
> Thanks for following up.  I think we’re almost done, some comments
> below:
>
>> --- a/gnu/system/linux-initrd.scm
>> +++ b/gnu/system/linux-initrd.scm
>> @@ -196,7 +196,7 @@ upon error."
>>      ;; List of gexps to open the mapped devices.
>>      (map (lambda (md)
>>             (let* ((source (mapped-device-source md))
>> -                  (target (mapped-device-target md))
>> +                  (target (mapped-device-targets md))
>
> I think we should write ‘targets’ (plural) everywhere.  That can help
> avoid confusion IMO.
>
>> -                        #$target)))))
>> +                        #$(car target))))))
>>  
>>  (define (close-luks-device source target)
>>    "Return a gexp that closes TARGET, a LUKS device."
>>    #~(zero? (system* #$(file-append cryptsetup-static "/sbin/cryptsetup")
>> -                    "close" #$target)))
>> +                    "close" #$(car target))))
>
> As per our coding convention (info "(guix) Data Types and Pattern
> Matching"), I’d recommend using ‘match’
>
>   (define (close-luks-device source targets)
>     (match targets
>       ((target)
>        #~(zero? (system* … #$target)))))
>
> That has the added benefit that it errors out if TARGETS is not exactly
> a one-element list.
>
>>  (define (close-raid-device sources target)
>>    "Return a gexp that stops the RAID device TARGET."
>>    #~(zero? (system* #$(file-append mdadm-static "/sbin/mdadm")
>> -                    "--stop" #$target)))
>> +                    "--stop" #$(car target))))
>
> Same here.
>
> Could you also update “Mapped Devices” in doc/guix.texi to mention the
> new ‘targets’ field?
>
> Thanks,
> Ludo’.