diff options
| author | Mathieu Othacehe <othacehe@gnu.org> | 2020-07-31 13:43:20 +0200 |
|---|---|---|
| committer | Mathieu Othacehe <othacehe@gnu.org> | 2020-07-31 13:43:20 +0200 |
| commit | 7c27bd115b14afd142da7684cc349369965f9eab (patch) | |
| tree | bd8ee8a4e6ec582481f926820fc4bfe0b8740f23 /gnu/build | |
| parent | 6bb07e91e1ab9367f636a3a5e9d52a9e0772aa89 (diff) | |
file-system: Add mount-may-fail? option.
* gnu/system/file-systems.scm (<file-system>): Add a mount-may-fail? field.
(file-system->spec): adapt accordingly,
(spec->file-system): ditto.
* gnu/build/file-systems.scm (mount-file-system): If 'system-error is raised
and mount-may-fail? is true, ignore it. Otherwise, re-raise the exception.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
Diffstat (limited to 'gnu/build')
| -rw-r--r-- | gnu/build/file-systems.scm | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index 478c71a4e1c..4ba1503b9f6 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm | |||
| @@ -814,26 +814,33 @@ corresponds to the symbols listed in FLAGS." | |||
| 814 | (when (file-system-check? fs) | 814 | (when (file-system-check? fs) |
| 815 | (check-file-system source type)) | 815 | (check-file-system source type)) |
| 816 | 816 | ||
| 817 | ;; Create the mount point. Most of the time this is a directory, but | 817 | (catch 'system-error |
| 818 | ;; in the case of a bind mount, a regular file or socket may be needed. | 818 | (lambda () |
| 819 | (if (and (= MS_BIND (logand flags MS_BIND)) | 819 | ;; Create the mount point. Most of the time this is a directory, but |
| 820 | (not (file-is-directory? source))) | 820 | ;; in the case of a bind mount, a regular file or socket may be |
| 821 | (unless (file-exists? mount-point) | 821 | ;; needed. |
| 822 | (mkdir-p (dirname mount-point)) | 822 | (if (and (= MS_BIND (logand flags MS_BIND)) |
| 823 | (call-with-output-file mount-point (const #t))) | 823 | (not (file-is-directory? source))) |
| 824 | (mkdir-p mount-point)) | 824 | (unless (file-exists? mount-point) |
| 825 | 825 | (mkdir-p (dirname mount-point)) | |
| 826 | (cond | 826 | (call-with-output-file mount-point (const #t))) |
| 827 | ((string-prefix? "nfs" type) | 827 | (mkdir-p mount-point)) |
| 828 | (mount-nfs source mount-point type flags options)) | 828 | |
| 829 | (else | 829 | (cond |
| 830 | (mount source mount-point type flags options))) | 830 | ((string-prefix? "nfs" type) |
| 831 | 831 | (mount-nfs source mount-point type flags options)) | |
| 832 | ;; For read-only bind mounts, an extra remount is needed, as per | 832 | (else |
| 833 | ;; <http://lwn.net/Articles/281157/>, which still applies to Linux 4.0. | 833 | (mount source mount-point type flags options))) |
| 834 | (when (and (= MS_BIND (logand flags MS_BIND)) | 834 | |
| 835 | (= MS_RDONLY (logand flags MS_RDONLY))) | 835 | ;; For read-only bind mounts, an extra remount is needed, as per |
| 836 | (let ((flags (logior MS_BIND MS_REMOUNT MS_RDONLY))) | 836 | ;; <http://lwn.net/Articles/281157/>, which still applies to Linux |
| 837 | (mount source mount-point type flags #f))))) | 837 | ;; 4.0. |
| 838 | (when (and (= MS_BIND (logand flags MS_BIND)) | ||
| 839 | (= MS_RDONLY (logand flags MS_RDONLY))) | ||
| 840 | (let ((flags (logior MS_BIND MS_REMOUNT MS_RDONLY))) | ||
| 841 | (mount source mount-point type flags #f)))) | ||
| 842 | (lambda args | ||
| 843 | (or (file-system-mount-may-fail? fs) | ||
| 844 | (apply throw args)))))) | ||
| 838 | 845 | ||
| 839 | ;;; file-systems.scm ends here | 846 | ;;; file-systems.scm ends here |
