[PATCH] linux-modules: Add module-soft-dependencies.

  • Done
  • quality assurance status badge
Details
2 participants
  • Danny Milosavljevic
  • Ludovic Courtès
Owner
unassigned
Submitted by
Danny Milosavljevic
Severity
normal

Debbugs page

Danny Milosavljevic wrote 6 years ago
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20190125113032.8372-1-dannym@scratchpost.org
* gnu/build/linux-modules.scm (not-softdep-whitespace): New variable.
(module-soft-dependencies): New procedure.
---
gnu/build/linux-modules.scm | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)

Toggle diff (55 lines)
diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm
index 2d8117504..631c5f577 100644
--- a/gnu/build/linux-modules.scm
+++ b/gnu/build/linux-modules.scm
@@ -33,6 +33,7 @@
ensure-dot-ko
module-aliases
module-dependencies
+ module-soft-dependencies
normalize-module-name
file-name->module-name
find-module-file
@@ -100,6 +101,42 @@ contains module names, not actual file names."
(('depends . what)
(string-tokenize what %not-comma)))))
+(define not-softdep-whitespace
+ (char-set-complement (char-set #\space #\tab)))
+
+(define (module-soft-dependencies file)
+ "Return the list of soft dependencies of module FILE."
+ (define (add-to-first-acons value alist)
+ (match alist
+ (((k . v) . b)
+ (cons (cons k (cons value v)) b))))
+
+ ;; TEXT: "pre: baz blubb foo post: bax bar"
+ (define (parse-softdep text)
+ (let loop ((value '())
+ (tokens (string-tokenize text not-softdep-whitespace))
+ (section #f))
+ (match tokens
+ ((token _ ...)
+ (if (string=? (string-take-right token 1) ":") ; section
+ (loop value
+ (cdr tokens)
+ (string-trim-both token))
+ (loop (cons (cons section token) value)
+ (cdr tokens)
+ section)))
+ (()
+ value))))
+
+ ;; Note: Multiple 'softdep sections are allowed.
+ (let ((info (modinfo-section-contents file)))
+ (apply append
+ (filter-map (match-lambda
+ (('softdep . value)
+ (parse-softdep value))
+ (_ #f))
+ (modinfo-section-contents file)))))
+
(define (module-aliases file)
"Return the list of aliases of module FILE."
(let ((info (modinfo-section-contents file)))
Danny Milosavljevic wrote 6 years ago
[PATCH v2] linux-modules: Add modules-soft-dependencies.
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20190125114838.8680-1-dannym@scratchpost.org
* gnu/build/linux-modules.scm (not-softdep-whitespace): New variable.
(module-soft-dependencies): New procedure.
---
gnu/build/linux-modules.scm | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)

Toggle diff (50 lines)
diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm
index 2d8117504..1632f20d5 100644
--- a/gnu/build/linux-modules.scm
+++ b/gnu/build/linux-modules.scm
@@ -33,6 +33,7 @@
ensure-dot-ko
module-aliases
module-dependencies
+ module-soft-dependencies
normalize-module-name
file-name->module-name
find-module-file
@@ -100,6 +101,37 @@ contains module names, not actual file names."
(('depends . what)
(string-tokenize what %not-comma)))))
+(define not-softdep-whitespace
+ (char-set-complement (char-set #\space #\tab)))
+
+(define (module-soft-dependencies file)
+ "Return a list of (cons mode soft-dependency) of module FILE."
+ ;; TEXT: "pre: baz blubb foo post: bax bar"
+ (define (parse-softdep text)
+ (let loop ((value '())
+ (tokens (string-tokenize text not-softdep-whitespace))
+ (section #f))
+ (match tokens
+ ((token _ ...)
+ (if (string=? (string-take-right token 1) ":") ; section
+ (loop value
+ (cdr tokens)
+ (string-trim-both token))
+ (loop (cons (cons section token) value)
+ (cdr tokens)
+ section)))
+ (()
+ value))))
+
+ ;; Note: Multiple 'softdep sections are allowed.
+ (let ((info (modinfo-section-contents file)))
+ (apply append
+ (filter-map (match-lambda
+ (('softdep . value)
+ (parse-softdep value))
+ (_ #f))
+ (modinfo-section-contents file)))))
+
(define (module-aliases file)
"Return the list of aliases of module FILE."
(let ((info (modinfo-section-contents file)))
Ludovic Courtès wrote 6 years ago
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)(address . 34195@debbugs.gnu.org)
87bm44oedg.fsf@gnu.org
Hi Danny,

Danny Milosavljevic <dannym@scratchpost.org> skribis:

Toggle quote (3 lines)
> * gnu/build/linux-modules.scm (not-softdep-whitespace): New variable.
> (module-soft-dependencies): New procedure.

That was fast! :-)


[...]

Toggle quote (14 lines)
> +(define (module-soft-dependencies file)
> + "Return a list of (cons mode soft-dependency) of module FILE."
> + ;; TEXT: "pre: baz blubb foo post: bax bar"
> + (define (parse-softdep text)
> + (let loop ((value '())
> + (tokens (string-tokenize text not-softdep-whitespace))
> + (section #f))
> + (match tokens
> + ((token _ ...)
> + (if (string=? (string-take-right token 1) ":") ; section
> + (loop value
> + (cdr tokens)
> + (string-trim-both token))

You can use the pattern (token rest ...) and then:

(loop value rest (string-trim-both token))

instead of the not-so-nice ‘cdr’. :-)

Toggle quote (8 lines)
> + (let ((info (modinfo-section-contents file)))
> + (apply append
> + (filter-map (match-lambda
> + (('softdep . value)
> + (parse-softdep value))
> + (_ #f))
> + (modinfo-section-contents file)))))

Replace ‘apply append’ with ‘concatenate’.

OK with these changes, thank you!

Ludo’.
Danny Milosavljevic wrote 6 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 34195-done@debbugs.gnu.org)
20190125182537.0535b710@scratchpost.org
Hi Ludo,

Toggle quote (2 lines)
>That was fast! :-)

Yeah, I dislike ticking boot time bombs ;-)

Thanks for the review!

Pushed as 1a5f46621b44aa1458ad7acd4eca5fe1d4574f92
and 519be98c3536b5113cde368f9dc6db2e1ebe073e (tiny fix)
to guix master.

Note that it returns something like

(("pre" . "module-1") ("pre" . "module-2"))

So the user might want to

(1) map cdr (or match ;) ) it
(2) replace dashes by underscores if a filename is desired (normalize-module-name)
(although in practise nobody in the mainline Linux seems to use dashes there
right now, their example in include/linux/module.h has dashes :P)

Example result:

scheme> (module-soft-dependencies "/tmp/vfio.ko")
$2 = (("post" . "vfio_iommu_spapr_tce") ("post" . "vfio_iommu_type1"))
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlxLRpEACgkQ5xo1VCww
uqWNPQf8DXkHQZbnZHYXglmni38TXv/PDFHMli0ggI2fuUxVNnxDOh8Zx58u7Ffm
GTreJx+KEYrXk30lyaoaTGYig6DCCDrJIlSa6UD2e1WZgRIq19yBFxYc4aYJWvnf
FQDYUbg6afvacms4Cr+cq14S6VST3zpvxVySSYiD+HkgEYbu32cFfngZ+a30Fzaz
EJBZtirLkwVZnJUhFw/l4FVzXuX5GBPQxAUTEE4RDzwE+QEYbroH9vzbbRzg1/H1
FvjYulGerBaa5L8snsr+OCj5DpC2frteq+MdPnyG1poo/33Wxp/awk7VhrNigQQp
QfuCizEyKDaqDCli3/m/gSMhsr33Rw==
=HldS
-----END PGP SIGNATURE-----


Closed
Ludovic Courtès wrote 6 years ago
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)(address . 34195-done@debbugs.gnu.org)
87womrjyr0.fsf@gnu.org
Hello,

Danny Milosavljevic <dannym@scratchpost.org> skribis:

Toggle quote (3 lines)
> scheme> (module-soft-dependencies "/tmp/vfio.ko")
> $2 = (("post" . "vfio_iommu_spapr_tce") ("post" . "vfio_iommu_type1"))

That’s probably not the best interface. :-)

Perhaps it should return two values: the list of modules to be loaded
before (“pre”), followed by the list of modules to be loaded after
(“post”).

WDYT?

Ludo’.
Closed
Danny Milosavljevic wrote 6 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 34195-done@debbugs.gnu.org)
20190126160036.17dda684@scratchpost.org
Hi Ludo,

On Sat, 26 Jan 2019 15:10:27 +0100
Ludovic Courtès <ludo@gnu.org> wrote:

Toggle quote (11 lines)
> Danny Milosavljevic <dannym@scratchpost.org> skribis:
>
> > scheme> (module-soft-dependencies "/tmp/vfio.ko")
> > $2 = (("post" . "vfio_iommu_spapr_tce") ("post" . "vfio_iommu_type1"))
>
> That’s probably not the best interface. :-)
>
> Perhaps it should return two values: the list of modules to be loaded
> before (“pre”), followed by the list of modules to be loaded after
> (“post”).

I had thought about it - but for our use case it makes it slower and more
complicated.

I still have the previous version (see below).

Moreover, it did the wrong thing for multiple 'softdep sections.

I guess I can use an external grouper routine (something like a hypothetical
group-by-first - does it exist?) on the result of module-soft-dependencies.

But at that point the caller can call it himself :->

We could hard-code "pre" and "post" as the two only possible sections (and
kmod does), but that would make it break in the future even though we don't
care about the sections, just the module names.

Complicated version:

(define (module-soft-dependencies file)
"Return the list of soft dependencies of module FILE."
(define (add-to-first-acons value alist)
(match alist
(((k . v) . b)
(cons (cons k (cons value v)) b))))

(define (parse-softdep text)
(let loop ((value '())
(tokens (string-tokenize text not-softdep-whitespace))
(section #f))
(write tokens)
(newline)
(match tokens
((token _ ...)
(if (string=? (string-take-right token 1) ":") ; section
(loop (acons (string-drop-right token 1) '() value)
(cdr tokens)
(string-trim-both token))
(loop (add-to-first-acons token value)
(cdr tokens) section)))
(()
value))))

(let ((info (modinfo-section-contents file)))
(filter-map (match-lambda
(('softdep . value)
(parse-softdep value))
(_ #f))
(modinfo-section-contents file))))
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlxMdhQACgkQ5xo1VCww
uqXqOQgAlVZm/4VW+vELWXvdxOt0CEhDFO5oyFuT9lf69wQEQgZOoJHagWauL21+
xJjC6E0dCRDYB/M1uuBAEY5Bxvwqgtoo1zspp2nb6GEWySnMCSv0oCmWmfanDNUL
oSg899KGF7Uc6Ry6pJ1tAGZk6D8szzOZMSmE0LIdUAeX2wEEmj82pNb80svSyFG4
AH7e42IPi95W2cIBBx58oGj25Nsy2H6W1bhCkcF4mmYr6FnTAVrDxbY+0ioD+t+Q
5/PnE5a4MWBWlZwYLVCzL8pSZAD9BdcJrbwSkbpqS/pd9f87fve1T/HL/ahSlXJQ
bb7lMdQf3+QN2u0nyCYIfa2GyrvW0Q==
=sTur
-----END PGP SIGNATURE-----


Closed
Ludovic Courtès wrote 6 years ago
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)(address . 34195-done@debbugs.gnu.org)
87zhrnigzw.fsf@gnu.org
Danny Milosavljevic <dannym@scratchpost.org> skribis:

Toggle quote (17 lines)
> On Sat, 26 Jan 2019 15:10:27 +0100
> Ludovic Courtès <ludo@gnu.org> wrote:
>
>> Danny Milosavljevic <dannym@scratchpost.org> skribis:
>>
>> > scheme> (module-soft-dependencies "/tmp/vfio.ko")
>> > $2 = (("post" . "vfio_iommu_spapr_tce") ("post" . "vfio_iommu_type1"))
>>
>> That’s probably not the best interface. :-)
>>
>> Perhaps it should return two values: the list of modules to be loaded
>> before (“pre”), followed by the list of modules to be loaded after
>> (“post”).
>
> I had thought about it - but for our use case it makes it slower and more
> complicated.

Once you have the result above, you can simply do:

(partition (match-lambda
(("pre" . _) #t)
(("post" . _) #f))
$2)

and then remove the cars. Or you can fold over the elements instead of
constructing the alist in the first place.

Anyway it should be a few more lines at most, I think.

Ludo’.
Closed
Danny Milosavljevic wrote 6 years ago
[PATCH] linux-modules: module-soft-dependencies: Partition the result and return it as two lists.
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20190126161919.31889-1-dannym@scratchpost.org
* gnu/build/linux-modules.scm (module-soft-dependencies): Partition the
result and return it as two lists.
---
gnu/build/linux-modules.scm | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

Toggle diff (49 lines)
diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm
index d69bcbf5a..16c8fad28 100644
--- a/gnu/build/linux-modules.scm
+++ b/gnu/build/linux-modules.scm
@@ -25,6 +25,7 @@
#:use-module (rnrs io ports)
#:use-module (rnrs bytevectors)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-11)
#:use-module (srfi srfi-26)
#:use-module (ice-9 vlist)
#:use-module (ice-9 match)
@@ -105,7 +106,8 @@ contains module names, not actual file names."
(char-set-complement (char-set #\space #\tab)))
(define (module-soft-dependencies file)
- "Return a list of (cons section soft-dependency) of module FILE."
+ "Return the list of modules that can be preloaded, and then the list of
+modules that can be postloaded, of the soft dependencies of module FILE."
;; TEXT: "pre: baz blubb foo post: bax bar"
(define (parse-softdep text)
(let loop ((value '())
@@ -120,13 +122,19 @@ contains module names, not actual file names."
value))))
;; Note: Multiple 'softdep sections are allowed.
- (let ((info (modinfo-section-contents file)))
- (concatenate
- (filter-map (match-lambda
- (('softdep . value)
- (parse-softdep value))
- (_ #f))
- (modinfo-section-contents file)))))
+ (let* ((info (modinfo-section-contents file))
+ (entries (concatenate
+ (filter-map (match-lambda
+ (('softdep . value)
+ (parse-softdep value))
+ (_ #f))
+ (modinfo-section-contents file)))))
+ (let-values (((pres posts)
+ (partition (match-lambda
+ (("pre" . _) #t)
+ (("post" . _) #f))
+ entries)))
+ (values (map cdr pres) (map cdr posts)))))
(define (module-aliases file)
"Return the list of aliases of module FILE."
Closed
Danny Milosavljevic wrote 6 years ago
[PATCH v2] linux-modules: module-soft-dependencies: Partition the result and return it as two lists.
(name . Danny Milosavljevic)(address . dannym@scratchpost.org)
20190126162313.31998-1-dannym@scratchpost.org
* gnu/build/linux-modules.scm (module-soft-dependencies): Partition the
result and return it as two lists.
---
gnu/build/linux-modules.scm | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)

Toggle diff (54 lines)
diff --git a/gnu/build/linux-modules.scm b/gnu/build/linux-modules.scm
index d69bcbf5a..d99d1f01a 100644
--- a/gnu/build/linux-modules.scm
+++ b/gnu/build/linux-modules.scm
@@ -25,6 +25,7 @@
#:use-module (rnrs io ports)
#:use-module (rnrs bytevectors)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-11)
#:use-module (srfi srfi-26)
#:use-module (ice-9 vlist)
#:use-module (ice-9 match)
@@ -105,7 +106,8 @@ contains module names, not actual file names."
(char-set-complement (char-set #\space #\tab)))
(define (module-soft-dependencies file)
- "Return a list of (cons section soft-dependency) of module FILE."
+ "Return the list of modules that can be preloaded, and then the list of
+modules that can be postloaded, of the soft dependencies of module FILE."
;; TEXT: "pre: baz blubb foo post: bax bar"
(define (parse-softdep text)
(let loop ((value '())
@@ -120,13 +122,24 @@ contains module names, not actual file names."
value))))
;; Note: Multiple 'softdep sections are allowed.
- (let ((info (modinfo-section-contents file)))
- (concatenate
- (filter-map (match-lambda
- (('softdep . value)
- (parse-softdep value))
- (_ #f))
- (modinfo-section-contents file)))))
+ (let* ((info (modinfo-section-contents file))
+ (entries (concatenate
+ (filter-map (match-lambda
+ (('softdep . value)
+ (parse-softdep value))
+ (_ #f))
+ (modinfo-section-contents file)))))
+ (let-values (((pres posts)
+ (partition (match-lambda
+ (("pre" . _) #t)
+ (("post" . _) #f))
+ entries)))
+ (values (map (match-lambda
+ ((_ . value) value))
+ pres)
+ (map (match-lambda
+ ((_ . value) value))
+ posts)))))
(define (module-aliases file)
"Return the list of aliases of module FILE."
Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 34195@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 34195
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help