1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2013 Lennart Poettering
19 #include "alloc-util.h"
20 #include "btrfs-util.h"
21 #include "chattr-util.h"
23 #include "dirent-util.h"
24 #include "dissect-image.h"
30 #include "hostname-util.h"
31 #include "id128-util.h"
32 #include "lockfile-util.h"
34 #include "loop-util.h"
35 #include "machine-image.h"
38 #include "path-util.h"
40 #include "string-table.h"
41 #include "string-util.h"
43 #include "time-util.h"
46 #include "xattr-util.h"
48 static const char image_search_path
[] =
50 "/var/lib/container\0" /* legacy */
51 "/usr/local/lib/machines\0"
52 "/usr/lib/machines\0";
54 Image
*image_unref(Image
*i
) {
62 strv_free(i
->machine_info
);
63 strv_free(i
->os_release
);
68 static char **image_settings_path(Image
*image
) {
69 _cleanup_strv_free_
char **l
= NULL
;
79 fn
= strjoina(image
->name
, ".nspawn");
81 FOREACH_STRING(s
, "/etc/systemd/nspawn/", "/run/systemd/nspawn/") {
82 l
[i
] = strappend(s
, fn
);
89 l
[i
] = file_in_same_dir(image
->path
, fn
);
96 static char *image_roothash_path(Image
*image
) {
101 fn
= strjoina(image
->name
, ".roothash");
103 return file_in_same_dir(image
->path
, fn
);
106 static int image_new(
110 const char *filename
,
116 _cleanup_(image_unrefp
) Image
*i
= NULL
;
119 assert(t
< _IMAGE_TYPE_MAX
);
129 i
->read_only
= read_only
;
132 i
->usage
= i
->usage_exclusive
= (uint64_t) -1;
133 i
->limit
= i
->limit_exclusive
= (uint64_t) -1;
135 i
->name
= strdup(pretty
);
140 i
->path
= strjoin(path
, "/", filename
);
142 i
->path
= strdup(filename
);
147 path_kill_slashes(i
->path
);
154 static int image_make(
158 const char *filename
,
167 /* We explicitly *do* follow symlinks here, since we want to allow symlinking trees, raw files and block
168 * devices into /var/lib/machines/, and treat them normally. */
170 if (fstatat(dfd
, filename
, &st
, 0) < 0)
174 (path
&& path_startswith(path
, "/usr")) ||
175 (faccessat(dfd
, filename
, W_OK
, AT_EACCESS
) < 0 && errno
== EROFS
);
177 if (S_ISDIR(st
.st_mode
)) {
178 _cleanup_close_
int fd
= -1;
179 unsigned file_attr
= 0;
187 fd
= openat(dfd
, filename
, O_CLOEXEC
|O_NOCTTY
|O_DIRECTORY
);
191 /* btrfs subvolumes have inode 256 */
192 if (st
.st_ino
== 256) {
194 r
= btrfs_is_filesystem(fd
);
198 BtrfsSubvolInfo info
;
200 /* It's a btrfs subvolume */
202 r
= btrfs_subvol_get_info_fd(fd
, 0, &info
);
206 r
= image_new(IMAGE_SUBVOLUME
,
210 info
.read_only
|| read_only
,
217 if (btrfs_quota_scan_ongoing(fd
) == 0) {
218 BtrfsQuotaInfo quota
;
220 r
= btrfs_subvol_get_subtree_quota_fd(fd
, 0, "a
);
222 (*ret
)->usage
= quota
.referenced
;
223 (*ret
)->usage_exclusive
= quota
.exclusive
;
225 (*ret
)->limit
= quota
.referenced_max
;
226 (*ret
)->limit_exclusive
= quota
.exclusive_max
;
234 /* If the IMMUTABLE bit is set, we consider the
235 * directory read-only. Since the ioctl is not
236 * supported everywhere we ignore failures. */
237 (void) read_attr_fd(fd
, &file_attr
);
239 /* It's just a normal directory. */
240 r
= image_new(IMAGE_DIRECTORY
,
244 read_only
|| (file_attr
& FS_IMMUTABLE_FL
),
253 } else if (S_ISREG(st
.st_mode
) && endswith(filename
, ".raw")) {
256 /* It's a RAW disk image */
261 fd_getcrtime_at(dfd
, filename
, &crtime
, 0);
264 pretty
= strndupa(filename
, strlen(filename
) - 4);
266 r
= image_new(IMAGE_RAW
,
270 !(st
.st_mode
& 0222) || read_only
,
272 timespec_load(&st
.st_mtim
),
277 (*ret
)->usage
= (*ret
)->usage_exclusive
= st
.st_blocks
* 512;
278 (*ret
)->limit
= (*ret
)->limit_exclusive
= st
.st_size
;
282 } else if (S_ISBLK(st
.st_mode
)) {
283 _cleanup_close_
int block_fd
= -1;
284 uint64_t size
= UINT64_MAX
;
294 block_fd
= openat(dfd
, filename
, O_RDONLY
|O_NONBLOCK
|O_CLOEXEC
|O_NOCTTY
);
296 log_debug_errno(errno
, "Failed to open block device %s/%s, ignoring: %m", path
, filename
);
298 if (fstat(block_fd
, &st
) < 0)
300 if (!S_ISBLK(st
.st_mode
)) /* Verify that what we opened is actually what we think it is */
306 if (ioctl(block_fd
, BLKROGET
, &state
) < 0)
307 log_debug_errno(errno
, "Failed to issue BLKROGET on device %s/%s, ignoring: %m", path
, filename
);
312 if (ioctl(block_fd
, BLKGETSIZE64
, &size
) < 0)
313 log_debug_errno(errno
, "Failed to issue BLKFLSBUF on device %s/%s, ignoring: %m", path
, filename
);
315 block_fd
= safe_close(block_fd
);
318 r
= image_new(IMAGE_BLOCK
,
322 !(st
.st_mode
& 0222) || read_only
,
329 if (size
!= 0 && size
!= UINT64_MAX
)
330 (*ret
)->usage
= (*ret
)->usage_exclusive
= (*ret
)->limit
= (*ret
)->limit_exclusive
= size
;
338 int image_find(const char *name
, Image
**ret
) {
344 /* There are no images with invalid names */
345 if (!image_name_is_valid(name
))
348 NULSTR_FOREACH(path
, image_search_path
) {
349 _cleanup_closedir_
DIR *d
= NULL
;
359 r
= image_make(NULL
, dirfd(d
), path
, name
, ret
);
360 if (IN_SET(r
, 0, -ENOENT
)) {
361 _cleanup_free_
char *raw
= NULL
;
363 raw
= strappend(name
, ".raw");
367 r
= image_make(NULL
, dirfd(d
), path
, raw
, ret
);
368 if (IN_SET(r
, 0, -ENOENT
))
377 if (streq(name
, ".host"))
378 return image_make(".host", AT_FDCWD
, NULL
, "/", ret
);
383 int image_discover(Hashmap
*h
) {
389 NULSTR_FOREACH(path
, image_search_path
) {
390 _cleanup_closedir_
DIR *d
= NULL
;
401 FOREACH_DIRENT_ALL(de
, d
, return -errno
) {
402 _cleanup_(image_unrefp
) Image
*image
= NULL
;
404 if (!image_name_is_valid(de
->d_name
))
407 if (hashmap_contains(h
, de
->d_name
))
410 r
= image_make(NULL
, dirfd(d
), path
, de
->d_name
, &image
);
411 if (IN_SET(r
, 0, -ENOENT
))
416 r
= hashmap_put(h
, image
->name
, image
);
424 if (!hashmap_contains(h
, ".host")) {
425 _cleanup_(image_unrefp
) Image
*image
= NULL
;
427 r
= image_make(".host", AT_FDCWD
, NULL
, "/", &image
);
431 r
= hashmap_put(h
, image
->name
, image
);
442 int image_remove(Image
*i
) {
443 _cleanup_(release_lock_file
) LockFile global_lock
= LOCK_FILE_INIT
, local_lock
= LOCK_FILE_INIT
;
444 _cleanup_strv_free_
char **settings
= NULL
;
445 _cleanup_free_
char *roothash
= NULL
;
451 if (IMAGE_IS_VENDOR(i
) || IMAGE_IS_HOST(i
))
454 settings
= image_settings_path(i
);
458 roothash
= image_roothash_path(i
);
462 /* Make sure we don't interfere with a running nspawn */
463 r
= image_path_lock(i
->path
, LOCK_EX
|LOCK_NB
, &global_lock
, &local_lock
);
469 case IMAGE_SUBVOLUME
:
471 /* Let's unlink first, maybe it is a symlink? If that works we are happy. Otherwise, let's get out the
473 if (unlink(i
->path
) < 0) {
474 r
= btrfs_subvol_remove(i
->path
, BTRFS_REMOVE_RECURSIVE
|BTRFS_REMOVE_QUOTA
);
481 case IMAGE_DIRECTORY
:
482 /* Allow deletion of read-only directories */
483 (void) chattr_path(i
->path
, 0, FS_IMMUTABLE_FL
);
484 r
= rm_rf(i
->path
, REMOVE_ROOT
|REMOVE_PHYSICAL
|REMOVE_SUBVOLUME
);
492 /* If this is inside of /dev, then it's a real block device, hence let's not touch the device node
493 * itself (but let's remove the stuff stored alongside it). If it's anywhere else, let's try to unlink
494 * the thing (it's most likely a symlink after all). */
496 if (path_startswith(i
->path
, "/dev"))
501 if (unlink(i
->path
) < 0)
509 STRV_FOREACH(j
, settings
) {
510 if (unlink(*j
) < 0 && errno
!= ENOENT
)
511 log_debug_errno(errno
, "Failed to unlink %s, ignoring: %m", *j
);
514 if (unlink(roothash
) < 0 && errno
!= ENOENT
)
515 log_debug_errno(errno
, "Failed to unlink %s, ignoring: %m", roothash
);
520 static int rename_auxiliary_file(const char *path
, const char *new_name
, const char *suffix
) {
521 _cleanup_free_
char *rs
= NULL
;
524 fn
= strjoina(new_name
, suffix
);
526 rs
= file_in_same_dir(path
, fn
);
530 return rename_noreplace(AT_FDCWD
, path
, AT_FDCWD
, rs
);
533 int image_rename(Image
*i
, const char *new_name
) {
534 _cleanup_(release_lock_file
) LockFile global_lock
= LOCK_FILE_INIT
, local_lock
= LOCK_FILE_INIT
, name_lock
= LOCK_FILE_INIT
;
535 _cleanup_free_
char *new_path
= NULL
, *nn
= NULL
, *roothash
= NULL
;
536 _cleanup_strv_free_
char **settings
= NULL
;
537 unsigned file_attr
= 0;
543 if (!image_name_is_valid(new_name
))
546 if (IMAGE_IS_VENDOR(i
) || IMAGE_IS_HOST(i
))
549 settings
= image_settings_path(i
);
553 roothash
= image_roothash_path(i
);
557 /* Make sure we don't interfere with a running nspawn */
558 r
= image_path_lock(i
->path
, LOCK_EX
|LOCK_NB
, &global_lock
, &local_lock
);
562 /* Make sure nobody takes the new name, between the time we
563 * checked it is currently unused in all search paths, and the
564 * time we take possession of it */
565 r
= image_name_lock(new_name
, LOCK_EX
|LOCK_NB
, &name_lock
);
569 r
= image_find(new_name
, NULL
);
577 case IMAGE_DIRECTORY
:
578 /* Turn of the immutable bit while we rename the image, so that we can rename it */
579 (void) read_attr_path(i
->path
, &file_attr
);
581 if (file_attr
& FS_IMMUTABLE_FL
)
582 (void) chattr_path(i
->path
, 0, FS_IMMUTABLE_FL
);
585 case IMAGE_SUBVOLUME
:
586 new_path
= file_in_same_dir(i
->path
, new_name
);
591 /* Refuse renaming raw block devices in /dev, the names are picked by udev after all. */
592 if (path_startswith(i
->path
, "/dev"))
595 new_path
= file_in_same_dir(i
->path
, new_name
);
601 fn
= strjoina(new_name
, ".raw");
602 new_path
= file_in_same_dir(i
->path
, fn
);
613 nn
= strdup(new_name
);
617 r
= rename_noreplace(AT_FDCWD
, i
->path
, AT_FDCWD
, new_path
);
621 /* Restore the immutable bit, if it was set before */
622 if (file_attr
& FS_IMMUTABLE_FL
)
623 (void) chattr_path(new_path
, FS_IMMUTABLE_FL
, FS_IMMUTABLE_FL
);
625 free_and_replace(i
->path
, new_path
);
626 free_and_replace(i
->name
, nn
);
628 STRV_FOREACH(j
, settings
) {
629 r
= rename_auxiliary_file(*j
, new_name
, ".nspawn");
630 if (r
< 0 && r
!= -ENOENT
)
631 log_debug_errno(r
, "Failed to rename settings file %s, ignoring: %m", *j
);
634 r
= rename_auxiliary_file(roothash
, new_name
, ".roothash");
635 if (r
< 0 && r
!= -ENOENT
)
636 log_debug_errno(r
, "Failed to rename roothash file %s, ignoring: %m", roothash
);
641 static int clone_auxiliary_file(const char *path
, const char *new_name
, const char *suffix
) {
642 _cleanup_free_
char *rs
= NULL
;
645 fn
= strjoina(new_name
, suffix
);
647 rs
= file_in_same_dir(path
, fn
);
651 return copy_file_atomic(path
, rs
, 0664, 0, COPY_REFLINK
);
654 int image_clone(Image
*i
, const char *new_name
, bool read_only
) {
655 _cleanup_(release_lock_file
) LockFile name_lock
= LOCK_FILE_INIT
;
656 _cleanup_strv_free_
char **settings
= NULL
;
657 _cleanup_free_
char *roothash
= NULL
;
658 const char *new_path
;
664 if (!image_name_is_valid(new_name
))
667 settings
= image_settings_path(i
);
671 roothash
= image_roothash_path(i
);
675 /* Make sure nobody takes the new name, between the time we
676 * checked it is currently unused in all search paths, and the
677 * time we take possession of it */
678 r
= image_name_lock(new_name
, LOCK_EX
|LOCK_NB
, &name_lock
);
682 r
= image_find(new_name
, NULL
);
690 case IMAGE_SUBVOLUME
:
691 case IMAGE_DIRECTORY
:
692 /* If we can we'll always try to create a new btrfs subvolume here, even if the source is a plain
695 new_path
= strjoina("/var/lib/machines/", new_name
);
697 r
= btrfs_subvol_snapshot(i
->path
, new_path
,
698 (read_only
? BTRFS_SNAPSHOT_READ_ONLY
: 0) |
699 BTRFS_SNAPSHOT_FALLBACK_COPY
|
700 BTRFS_SNAPSHOT_FALLBACK_DIRECTORY
|
701 BTRFS_SNAPSHOT_FALLBACK_IMMUTABLE
|
702 BTRFS_SNAPSHOT_RECURSIVE
|
703 BTRFS_SNAPSHOT_QUOTA
);
705 /* Enable "subtree" quotas for the copy, if we didn't copy any quota from the source. */
706 (void) btrfs_subvol_auto_qgroup(new_path
, 0, true);
711 new_path
= strjoina("/var/lib/machines/", new_name
, ".raw");
713 r
= copy_file_atomic(i
->path
, new_path
, read_only
? 0444 : 0644, FS_NOCOW_FL
, COPY_REFLINK
);
724 STRV_FOREACH(j
, settings
) {
725 r
= clone_auxiliary_file(*j
, new_name
, ".nspawn");
726 if (r
< 0 && r
!= -ENOENT
)
727 log_debug_errno(r
, "Failed to clone settings %s, ignoring: %m", *j
);
730 r
= clone_auxiliary_file(roothash
, new_name
, ".roothash");
731 if (r
< 0 && r
!= -ENOENT
)
732 log_debug_errno(r
, "Failed to clone root hash file %s, ignoring: %m", roothash
);
737 int image_read_only(Image
*i
, bool b
) {
738 _cleanup_(release_lock_file
) LockFile global_lock
= LOCK_FILE_INIT
, local_lock
= LOCK_FILE_INIT
;
743 if (IMAGE_IS_VENDOR(i
) || IMAGE_IS_HOST(i
))
746 /* Make sure we don't interfere with a running nspawn */
747 r
= image_path_lock(i
->path
, LOCK_EX
|LOCK_NB
, &global_lock
, &local_lock
);
753 case IMAGE_SUBVOLUME
:
755 /* Note that we set the flag only on the top-level
756 * subvolume of the image. */
758 r
= btrfs_subvol_set_read_only(i
->path
, b
);
764 case IMAGE_DIRECTORY
:
765 /* For simple directory trees we cannot use the access
766 mode of the top-level directory, since it has an
767 effect on the container itself. However, we can
768 use the "immutable" flag, to at least make the
769 top-level directory read-only. It's not as good as
770 a read-only subvolume, but at least something, and
771 we can read the value back. */
773 r
= chattr_path(i
->path
, b
? FS_IMMUTABLE_FL
: 0, FS_IMMUTABLE_FL
);
782 if (stat(i
->path
, &st
) < 0)
785 if (chmod(i
->path
, (st
.st_mode
& 0444) | (b
? 0000 : 0200)) < 0)
788 /* If the images is now read-only, it's a good time to
789 * defrag it, given that no write patterns will
790 * fragment it again. */
792 (void) btrfs_defrag(i
->path
);
797 _cleanup_close_
int fd
= -1;
801 fd
= open(i
->path
, O_CLOEXEC
|O_RDONLY
|O_NONBLOCK
|O_NOCTTY
);
805 if (fstat(fd
, &st
) < 0)
807 if (!S_ISBLK(st
.st_mode
))
810 if (ioctl(fd
, BLKROSET
, &state
) < 0)
823 int image_path_lock(const char *path
, int operation
, LockFile
*global
, LockFile
*local
) {
824 _cleanup_free_
char *p
= NULL
;
825 LockFile t
= LOCK_FILE_INIT
;
833 /* Locks an image path. This actually creates two locks: one
834 * "local" one, next to the image path itself, which might be
835 * shared via NFS. And another "global" one, in /run, that
836 * uses the device/inode number. This has the benefit that we
837 * can even lock a tree that is a mount point, correctly. */
839 if (!path_is_absolute(path
))
842 if (getenv_bool("SYSTEMD_NSPAWN_LOCK") == 0) {
843 *local
= *global
= (LockFile
) LOCK_FILE_INIT
;
847 if (path_equal(path
, "/"))
850 if (stat(path
, &st
) >= 0) {
851 if (S_ISBLK(st
.st_mode
))
852 r
= asprintf(&p
, "/run/systemd/nspawn/locks/block-%u:%u", major(st
.st_rdev
), minor(st
.st_rdev
));
853 else if (S_ISDIR(st
.st_mode
) || S_ISREG(st
.st_mode
))
854 r
= asprintf(&p
, "/run/systemd/nspawn/locks/inode-%lu:%lu", (unsigned long) st
.st_dev
, (unsigned long) st
.st_ino
);
862 /* For block devices we don't need the "local" lock, as the major/minor lock above should be sufficient, since
863 * block devices are device local anyway. */
864 if (!path_startswith(path
, "/dev")) {
865 r
= make_lock_file_for(path
, operation
, &t
);
867 if ((operation
& LOCK_SH
) && r
== -EROFS
)
868 log_debug_errno(r
, "Failed to create shared lock for '%s', ignoring: %m", path
);
875 mkdir_p("/run/systemd/nspawn/locks", 0700);
877 r
= make_lock_file(p
, operation
, global
);
879 release_lock_file(&t
);
883 *global
= (LockFile
) LOCK_FILE_INIT
;
889 int image_set_limit(Image
*i
, uint64_t referenced_max
) {
892 if (IMAGE_IS_VENDOR(i
) || IMAGE_IS_HOST(i
))
895 if (i
->type
!= IMAGE_SUBVOLUME
)
898 /* We set the quota both for the subvolume as well as for the
899 * subtree. The latter is mostly for historical reasons, since
900 * we didn't use to have a concept of subtree quota, and hence
901 * only modified the subvolume quota. */
903 (void) btrfs_qgroup_set_limit(i
->path
, 0, referenced_max
);
904 (void) btrfs_subvol_auto_qgroup(i
->path
, 0, true);
905 return btrfs_subvol_set_subtree_quota_limit(i
->path
, 0, referenced_max
);
908 int image_read_metadata(Image
*i
) {
909 _cleanup_(release_lock_file
) LockFile global_lock
= LOCK_FILE_INIT
, local_lock
= LOCK_FILE_INIT
;
914 r
= image_path_lock(i
->path
, LOCK_SH
|LOCK_NB
, &global_lock
, &local_lock
);
920 case IMAGE_SUBVOLUME
:
921 case IMAGE_DIRECTORY
: {
922 _cleanup_strv_free_
char **machine_info
= NULL
, **os_release
= NULL
;
923 sd_id128_t machine_id
= SD_ID128_NULL
;
924 _cleanup_free_
char *hostname
= NULL
;
925 _cleanup_free_
char *path
= NULL
;
927 r
= chase_symlinks("/etc/hostname", i
->path
, CHASE_PREFIX_ROOT
|CHASE_TRAIL_SLASH
, &path
);
928 if (r
< 0 && r
!= -ENOENT
)
929 log_debug_errno(r
, "Failed to chase /etc/hostname in image %s: %m", i
->name
);
931 r
= read_etc_hostname(path
, &hostname
);
933 log_debug_errno(errno
, "Failed to read /etc/hostname of image %s: %m", i
->name
);
938 r
= chase_symlinks("/etc/machine-id", i
->path
, CHASE_PREFIX_ROOT
|CHASE_TRAIL_SLASH
, &path
);
939 if (r
< 0 && r
!= -ENOENT
)
940 log_debug_errno(r
, "Failed to chase /etc/machine-id in image %s: %m", i
->name
);
942 _cleanup_close_
int fd
= -1;
944 fd
= open(path
, O_RDONLY
|O_CLOEXEC
|O_NOCTTY
);
946 log_debug_errno(errno
, "Failed to open %s: %m", path
);
948 r
= id128_read_fd(fd
, ID128_PLAIN
, &machine_id
);
950 log_debug_errno(r
, "Image %s contains invalid machine ID.", i
->name
);
956 r
= chase_symlinks("/etc/machine-info", i
->path
, CHASE_PREFIX_ROOT
|CHASE_TRAIL_SLASH
, &path
);
957 if (r
< 0 && r
!= -ENOENT
)
958 log_debug_errno(r
, "Failed to chase /etc/machine-info in image %s: %m", i
->name
);
960 r
= load_env_file_pairs(NULL
, path
, NULL
, &machine_info
);
962 log_debug_errno(r
, "Failed to parse machine-info data of %s: %m", i
->name
);
967 r
= chase_symlinks("/etc/os-release", i
->path
, CHASE_PREFIX_ROOT
|CHASE_TRAIL_SLASH
, &path
);
969 r
= chase_symlinks("/usr/lib/os-release", i
->path
, CHASE_PREFIX_ROOT
|CHASE_TRAIL_SLASH
, &path
);
970 if (r
< 0 && r
!= -ENOENT
)
971 log_debug_errno(r
, "Failed to chase os-release in image: %m");
973 r
= load_env_file_pairs(NULL
, path
, NULL
, &os_release
);
975 log_debug_errno(r
, "Failed to parse os-release data of %s: %m", i
->name
);
978 free_and_replace(i
->hostname
, hostname
);
979 i
->machine_id
= machine_id
;
980 strv_free_and_replace(i
->machine_info
, machine_info
);
981 strv_free_and_replace(i
->os_release
, os_release
);
988 _cleanup_(loop_device_unrefp
) LoopDevice
*d
= NULL
;
989 _cleanup_(dissected_image_unrefp
) DissectedImage
*m
= NULL
;
991 r
= loop_device_make_by_path(i
->path
, O_RDONLY
, &d
);
995 r
= dissect_image(d
->fd
, NULL
, 0, DISSECT_IMAGE_REQUIRE_ROOT
, &m
);
999 r
= dissected_image_acquire_metadata(m
);
1003 free_and_replace(i
->hostname
, m
->hostname
);
1004 i
->machine_id
= m
->machine_id
;
1005 strv_free_and_replace(i
->machine_info
, m
->machine_info
);
1006 strv_free_and_replace(i
->os_release
, m
->os_release
);
1015 i
->metadata_valid
= true;
1020 int image_name_lock(const char *name
, int operation
, LockFile
*ret
) {
1026 /* Locks an image name, regardless of the precise path used. */
1028 if (!image_name_is_valid(name
))
1031 if (getenv_bool("SYSTEMD_NSPAWN_LOCK") == 0) {
1032 *ret
= (LockFile
) LOCK_FILE_INIT
;
1036 if (streq(name
, ".host"))
1039 mkdir_p("/run/systemd/nspawn/locks", 0700);
1040 p
= strjoina("/run/systemd/nspawn/locks/name-", name
);
1042 return make_lock_file(p
, operation
, ret
);
1045 bool image_name_is_valid(const char *s
) {
1046 if (!filename_is_valid(s
))
1049 if (string_has_cc(s
, NULL
))
1052 if (!utf8_is_valid(s
))
1055 /* Temporary files for atomically creating new files */
1056 if (startswith(s
, ".#"))
1062 static const char* const image_type_table
[_IMAGE_TYPE_MAX
] = {
1063 [IMAGE_DIRECTORY
] = "directory",
1064 [IMAGE_SUBVOLUME
] = "subvolume",
1065 [IMAGE_RAW
] = "raw",
1066 [IMAGE_BLOCK
] = "block",
1069 DEFINE_STRING_TABLE_LOOKUP(image_type
, ImageType
);