Skip to content

Commit

Permalink
util-lib: split out image dissecting code and loopback code from nspawn
Browse files Browse the repository at this point in the history
This adds two new APIs to systemd:

- loop-util.h is a simple internal API for allocating, setting up and releasing
  loopback block devices.

- dissect-image.h is an internal API for taking apart disk images and figuring
  out what the purpose of each partition is.

Both APIs are basically refactored versions of similar code in nspawn.  This
rework should permit us to reuse this in other places than just nspawn in the
future. Specifically: to implement RootImage= in the service image, similar to
RootDirectory=, but operating on a disk image; to unify the gpt-auto-discovery
generator code with the discovery logic in nspawn; to add new API to machined
for determining the OS version of a disk image (i.e. not just running
containers). This PR does not make any such changes however, it just provides
the new reworked API.

The reworked code is also slightly more powerful than the nspawn original one.
When pointing it to an image or block device with a naked file system (i.e. no
partition table) it will simply make it the root device.
  • Loading branch information
poettering committed Dec 7, 2016
1 parent 9e70a49 commit 8c1be37
Show file tree
Hide file tree
Showing 7 changed files with 902 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
/test-dhcp-option
/test-dhcp-server
/test-dhcp6-client
/test-dissect-image
/test-dns-domain
/test-dns-packet
/test-dnssec
Expand Down
30 changes: 25 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,8 @@ libshared_la_SOURCES = \
src/shared/machine-image.h \
src/shared/machine-pool.c \
src/shared/machine-pool.h \
src/shared/loop-util.c \
src/shared/loop-util.h \
src/shared/resolve-util.c \
src/shared/resolve-util.h \
src/shared/bus-unit-util.c \
Expand All @@ -1053,7 +1055,9 @@ libshared_la_SOURCES = \
src/shared/fdset.c \
src/shared/fdset.h \
src/shared/nsflags.h \
src/shared/nsflags.c
src/shared/nsflags.c \
src/shared/dissect-image.c \
src/shared/dissect-image.h

if HAVE_UTMP
libshared_la_SOURCES += \
Expand All @@ -1076,7 +1080,8 @@ libshared_la_CFLAGS = \
$(AM_CFLAGS) \
$(ACL_CFLAGS) \
$(LIBIDN_CFLAGS) \
$(SECCOMP_CFLAGS)
$(SECCOMP_CFLAGS) \
$(BLKID_CFLAGS)

libshared_la_LIBADD = \
libsystemd-internal.la \
Expand All @@ -1085,7 +1090,8 @@ libshared_la_LIBADD = \
libudev-internal.la \
$(ACL_LIBS) \
$(LIBIDN_LIBS) \
$(SECCOMP_LIBS)
$(SECCOMP_LIBS) \
$(BLKID_LIBS)

rootlibexec_LTLIBRARIES += \
libsystemd-shared.la
Expand All @@ -1107,6 +1113,7 @@ libsystemd_shared_la_CFLAGS = \
$(ACL_CFLAGS) \
$(LIBIDN_CFLAGS) \
$(SECCOMP_CFLAGS) \
$(BLKID_CFLAGS) \
-fvisibility=default

# We can't use libshared_la_LIBADD here because it would
Expand All @@ -1118,7 +1125,8 @@ libsystemd_shared_la_LIBADD = \
$(libudev_internal_la_LIBADD) \
$(ACL_LIBS) \
$(LIBIDN_LIBS) \
$(SECCOMP_LIBS)
$(SECCOMP_LIBS) \
$(BLKID_LIBS)

libsystemd_shared_la_LDFLAGS = \
$(AM_LDFLAGS) \
Expand Down Expand Up @@ -1456,7 +1464,8 @@ manual_tests += \
test-btrfs \
test-acd \
test-ipv4ll-manual \
test-ask-password-api
test-ask-password-api \
test-dissect-image

unsafe_tests = \
test-hostname \
Expand Down Expand Up @@ -2067,6 +2076,17 @@ test_ask_password_api_SOURCES = \
test_ask_password_api_LDADD = \
libsystemd-shared.la

test_dissect_image_SOURCES = \
src/test/test-dissect-image.c

test_dissect_image_CFLAGS = \
$(AM_CFLAGS) \
$(BLKID_CFLAGS)

test_dissect_image_LDADD = \
libsystemd-shared.la \
$(BLKID_LIBS)

test_signal_util_SOURCES = \
src/test/test-signal-util.c

Expand Down
Loading

0 comments on commit 8c1be37

Please sign in to comment.