|
|
803fb7 |
From b4bfb025f7ab0878e8e7e980dbad5b0a5bed1555 Mon Sep 17 00:00:00 2001
|
|
|
803fb7 |
From: Lennart Poettering <lennart@poettering.net>
|
|
|
803fb7 |
Date: Thu, 10 Dec 2015 12:40:04 +0100
|
|
|
803fb7 |
Subject: [PATCH] importd: drop dkr support
|
|
|
803fb7 |
|
|
|
803fb7 |
The current code is not compatible with current dkr protocols anyway,
|
|
|
803fb7 |
and dkr has a different focus ("microservices") than nspawn anyway
|
|
|
803fb7 |
("whole machine containers"), hence drop support for it, we cannot
|
|
|
803fb7 |
reasonably keep this up to date, and it creates the impression we'd
|
|
|
803fb7 |
actually care for the microservices usecase.
|
|
|
803fb7 |
|
|
|
803fb7 |
Cherry-picked from: b43d75c
|
|
|
803fb7 |
Related: #1284974
|
|
|
803fb7 |
---
|
|
|
803fb7 |
Makefile.am | 2 -
|
|
|
803fb7 |
TODO | 4 -
|
|
|
803fb7 |
configure.ac | 9 -
|
|
|
de8967 |
man/machinectl.xml | 58 --
|
|
|
de8967 |
src/import/import-dkr.c | 891 ------------------------
|
|
|
de8967 |
src/import/import-dkr.h | 36 -
|
|
|
de8967 |
src/import/importd.c | 111 +--
|
|
|
803fb7 |
src/import/org.freedesktop.import1.conf | 4 -
|
|
|
de8967 |
src/import/pull.c | 119 +---
|
|
|
de8967 |
src/machine/machinectl.c | 90 +--
|
|
|
de8967 |
src/shared/import-util.c | 31 -
|
|
|
803fb7 |
src/shared/import-util.h | 4 -
|
|
|
803fb7 |
12 files changed, 5 insertions(+), 1354 deletions(-)
|
|
|
803fb7 |
delete mode 100644 src/import/import-dkr.c
|
|
|
803fb7 |
delete mode 100644 src/import/import-dkr.h
|
|
|
803fb7 |
|
|
|
803fb7 |
diff --git a/Makefile.am b/Makefile.am
|
|
|
803fb7 |
index 3a09e0a62..b0a34b212 100644
|
|
|
803fb7 |
--- a/Makefile.am
|
|
|
803fb7 |
+++ b/Makefile.am
|
|
|
803fb7 |
@@ -5369,8 +5369,6 @@ systemd_pull_SOURCES = \
|
|
|
803fb7 |
src/import/import-raw.h \
|
|
|
803fb7 |
src/import/import-tar.c \
|
|
|
803fb7 |
src/import/import-tar.h \
|
|
|
803fb7 |
- src/import/import-dkr.c \
|
|
|
803fb7 |
- src/import/import-dkr.h \
|
|
|
803fb7 |
src/import/import-job.c \
|
|
|
803fb7 |
src/import/import-job.h \
|
|
|
803fb7 |
src/import/import-common.c \
|
|
|
803fb7 |
diff --git a/TODO b/TODO
|
|
|
803fb7 |
index 90b2c4b30..d96d2bf0e 100644
|
|
|
803fb7 |
--- a/TODO
|
|
|
803fb7 |
+++ b/TODO
|
|
|
803fb7 |
@@ -126,10 +126,6 @@ Features:
|
|
|
803fb7 |
|
|
|
803fb7 |
* rework journald sigbus stuff to use mutex
|
|
|
803fb7 |
|
|
|
803fb7 |
-* import-dkr: support tarsum checksum verification, if it becomes reality one day...
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-* import-dkr: convert json bits to nspawn configuration
|
|
|
803fb7 |
-
|
|
|
803fb7 |
* import: support import from local files, and export to local files
|
|
|
803fb7 |
|
|
|
803fb7 |
* core/cgroup: support net_cls modules, and support automatically allocating class ids, then add support for making firewall changes depending on it, to implement a per-service firewall
|
|
|
803fb7 |
diff --git a/configure.ac b/configure.ac
|
|
|
803fb7 |
index 9103f9b92..2734368dc 100644
|
|
|
803fb7 |
--- a/configure.ac
|
|
|
803fb7 |
+++ b/configure.ac
|
|
|
803fb7 |
@@ -1389,14 +1389,6 @@ AC_ARG_ENABLE([split-usr],
|
|
|
803fb7 |
enable_split_usr=no
|
|
|
803fb7 |
])])
|
|
|
803fb7 |
|
|
|
803fb7 |
-AC_ARG_WITH([dkr-index-url],
|
|
|
803fb7 |
- [AS_HELP_STRING([--dkr-index-url=URL], [Specify the default index URL to use for image downloads])],
|
|
|
803fb7 |
- [DEFAULT_DKR_INDEX_URL="\"$withval\""],
|
|
|
803fb7 |
- [DEFAULT_DKR_INDEX_URL="NULL"])
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-AC_DEFINE_UNQUOTED(DEFAULT_DKR_INDEX_URL, [$DEFAULT_DKR_INDEX_URL], [Default index URL to use for image downloads])
|
|
|
803fb7 |
-AC_SUBST(DEFAULT_DKR_INDEX_URL)
|
|
|
803fb7 |
-
|
|
|
803fb7 |
AS_IF([test "x${enable_split_usr}" = "xyes"], [
|
|
|
803fb7 |
AC_DEFINE(HAVE_SPLIT_USR, 1, [Define if /bin, /sbin aren't symlinks into /usr])
|
|
|
803fb7 |
])
|
|
|
803fb7 |
@@ -1564,7 +1556,6 @@ AC_MSG_RESULT([
|
|
|
803fb7 |
Maximum System UID: ${SYSTEM_UID_MAX}
|
|
|
803fb7 |
Maximum System GID: ${SYSTEM_GID_MAX}
|
|
|
803fb7 |
Certificate root: ${CERTIFICATEROOT}
|
|
|
803fb7 |
- Default dkr Index ${DEFAULT_DKR_INDEX_URL}
|
|
|
803fb7 |
|
|
|
803fb7 |
CFLAGS: ${OUR_CFLAGS} ${CFLAGS}
|
|
|
803fb7 |
CPPFLAGS: ${OUR_CPPFLAGS} ${CPPFLAGS}
|
|
|
803fb7 |
diff --git a/man/machinectl.xml b/man/machinectl.xml
|
|
|
803fb7 |
index 640cb8b7d..b0a7f2ae4 100644
|
|
|
803fb7 |
--- a/man/machinectl.xml
|
|
|
803fb7 |
+++ b/man/machinectl.xml
|
|
|
803fb7 |
@@ -204,16 +204,6 @@
|
|
|
803fb7 |
image.</para></listitem>
|
|
|
803fb7 |
</varlistentry>
|
|
|
803fb7 |
|
|
|
803fb7 |
- <varlistentry>
|
|
|
803fb7 |
- <term><option>--dkr-index-url</option></term>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- <listitem><para>Specifies the index server to use for
|
|
|
803fb7 |
- downloading <literal>dkr</literal> images with the
|
|
|
803fb7 |
- <command>pull-dkr</command>. Takes a
|
|
|
803fb7 |
- <literal>http://</literal>, <literal>https://</literal>
|
|
|
803fb7 |
- URL.</para></listitem>
|
|
|
803fb7 |
- </varlistentry>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
<xi:include href="user-system-options.xml" xpointer="host" />
|
|
|
803fb7 |
<xi:include href="user-system-options.xml" xpointer="machine" />
|
|
|
803fb7 |
|
|
|
803fb7 |
@@ -602,42 +592,6 @@
|
|
|
803fb7 |
below.</para></listitem>
|
|
|
803fb7 |
</varlistentry>
|
|
|
803fb7 |
|
|
|
803fb7 |
- <varlistentry>
|
|
|
803fb7 |
- <term><command>pull-dkr</command> <replaceable>REMOTE</replaceable> [<replaceable>NAME</replaceable>]</term>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- <listitem><para>Downloads a <literal>dkr</literal> container
|
|
|
803fb7 |
- image and makes it available locally. The remote name refers
|
|
|
803fb7 |
- to a <literal>dkr</literal> container name. If omitted, the
|
|
|
803fb7 |
- local machine name is derived from the <literal>dkr</literal>
|
|
|
803fb7 |
- container name.</para>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- <para>Image verification is not available for
|
|
|
803fb7 |
- <literal>dkr</literal> containers, and thus
|
|
|
803fb7 |
- <option>--verify=no</option> must always be specified with
|
|
|
803fb7 |
- this command.</para>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- <para>This command downloads all (missing) layers for the
|
|
|
803fb7 |
- specified container and places them in read-only subvolumes in
|
|
|
803fb7 |
- <filename>/var/lib/machines/</filename>. A writable snapshot
|
|
|
803fb7 |
- of the newest layer is then created under the specified local
|
|
|
803fb7 |
- machine name. To omit creation of this writable snapshot, pass
|
|
|
803fb7 |
- <literal>-</literal> as local machine name.</para>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- <para>The read-only layer subvolumes are prefixed with
|
|
|
803fb7 |
- <filename>.dkr-</filename>, and thus now shown by
|
|
|
803fb7 |
- <command>list-images</command>, unless <option>--all</option>
|
|
|
803fb7 |
- is passed.</para>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- <para>To specify the <literal>dkr</literal> index server to
|
|
|
803fb7 |
- use for looking up the specified container, use
|
|
|
803fb7 |
- <option>--dkr-index-url=</option>.</para>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- <para>Note that pressing C-c during execution of this command
|
|
|
803fb7 |
- will not abort the download. Use
|
|
|
803fb7 |
- <command>cancel-transfer</command>, described
|
|
|
803fb7 |
- below.</para></listitem>
|
|
|
803fb7 |
- </varlistentry>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
<varlistentry>
|
|
|
803fb7 |
<term><command>list-transfers</command></term>
|
|
|
803fb7 |
|
|
|
803fb7 |
@@ -728,18 +682,6 @@
|
|
|
803fb7 |
the machine started as system service. With the last command a
|
|
|
803fb7 |
login prompt into the container is requested.</para>
|
|
|
803fb7 |
</example>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- <example>
|
|
|
803fb7 |
- <title>Download a Fedora <literal>dkr</literal> image</title>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- <programlisting># machinectl pull-dkr --verify=no mattdm/fedora
|
|
|
803fb7 |
-# systemd-nspawn -M fedora</programlisting>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- <para>Downloads a <literal>dkr</literal> image and opens a shell
|
|
|
803fb7 |
- in it. Note that the specified download command might require an
|
|
|
803fb7 |
- index server to be specified with the
|
|
|
803fb7 |
- <literal>--dkr-index-url=</literal>.</para>
|
|
|
803fb7 |
- </example>
|
|
|
803fb7 |
</refsect1>
|
|
|
803fb7 |
|
|
|
803fb7 |
<refsect1>
|
|
|
803fb7 |
diff --git a/src/import/import-dkr.c b/src/import/import-dkr.c
|
|
|
803fb7 |
deleted file mode 100644
|
|
|
803fb7 |
index fb72f6cee..000000000
|
|
|
803fb7 |
--- a/src/import/import-dkr.c
|
|
|
803fb7 |
+++ /dev/null
|
|
|
803fb7 |
@@ -1,891 +0,0 @@
|
|
|
803fb7 |
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-/***
|
|
|
803fb7 |
- This file is part of systemd.
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- Copyright 2014 Lennart Poettering
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- systemd is free software; you can redistribute it and/or modify it
|
|
|
803fb7 |
- under the terms of the GNU Lesser General Public License as published by
|
|
|
803fb7 |
- the Free Software Foundation; either version 2.1 of the License, or
|
|
|
803fb7 |
- (at your option) any later version.
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- systemd is distributed in the hope that it will be useful, but
|
|
|
803fb7 |
- WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
803fb7 |
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
803fb7 |
- Lesser General Public License for more details.
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- You should have received a copy of the GNU Lesser General Public License
|
|
|
803fb7 |
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
803fb7 |
-***/
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-#include <curl/curl.h>
|
|
|
803fb7 |
-#include <sys/prctl.h>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-#include "sd-daemon.h"
|
|
|
803fb7 |
-#include "json.h"
|
|
|
803fb7 |
-#include "strv.h"
|
|
|
803fb7 |
-#include "btrfs-util.h"
|
|
|
803fb7 |
-#include "utf8.h"
|
|
|
803fb7 |
-#include "mkdir.h"
|
|
|
803fb7 |
-#include "import-util.h"
|
|
|
803fb7 |
-#include "curl-util.h"
|
|
|
803fb7 |
-#include "aufs-util.h"
|
|
|
803fb7 |
-#include "import-job.h"
|
|
|
803fb7 |
-#include "import-common.h"
|
|
|
803fb7 |
-#include "import-dkr.h"
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-typedef enum DkrProgress {
|
|
|
803fb7 |
- DKR_SEARCHING,
|
|
|
803fb7 |
- DKR_RESOLVING,
|
|
|
803fb7 |
- DKR_METADATA,
|
|
|
803fb7 |
- DKR_DOWNLOADING,
|
|
|
803fb7 |
- DKR_COPYING,
|
|
|
803fb7 |
-} DkrProgress;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-struct DkrImport {
|
|
|
803fb7 |
- sd_event *event;
|
|
|
803fb7 |
- CurlGlue *glue;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- char *index_url;
|
|
|
803fb7 |
- char *image_root;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- ImportJob *images_job;
|
|
|
803fb7 |
- ImportJob *tags_job;
|
|
|
803fb7 |
- ImportJob *ancestry_job;
|
|
|
803fb7 |
- ImportJob *json_job;
|
|
|
803fb7 |
- ImportJob *layer_job;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- char *name;
|
|
|
803fb7 |
- char *tag;
|
|
|
803fb7 |
- char *id;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- char *response_token;
|
|
|
803fb7 |
- char **response_registries;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- char **ancestry;
|
|
|
803fb7 |
- unsigned n_ancestry;
|
|
|
803fb7 |
- unsigned current_ancestry;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- DkrImportFinished on_finished;
|
|
|
803fb7 |
- void *userdata;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- char *local;
|
|
|
803fb7 |
- bool force_local;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- char *temp_path;
|
|
|
803fb7 |
- char *final_path;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- pid_t tar_pid;
|
|
|
803fb7 |
-};
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-#define PROTOCOL_PREFIX "https://"
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-#define HEADER_TOKEN "X-Do" /* the HTTP header for the auth token */ "cker-Token:"
|
|
|
803fb7 |
-#define HEADER_REGISTRY "X-Do" /*the HTTP header for the registry */ "cker-Endpoints:"
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-#define LAYERS_MAX 2048
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static void dkr_import_job_on_finished(ImportJob *j);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-DkrImport* dkr_import_unref(DkrImport *i) {
|
|
|
803fb7 |
- if (!i)
|
|
|
803fb7 |
- return NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (i->tar_pid > 1) {
|
|
|
803fb7 |
- (void) kill_and_sigcont(i->tar_pid, SIGKILL);
|
|
|
803fb7 |
- (void) wait_for_terminate(i->tar_pid, NULL);
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- import_job_unref(i->images_job);
|
|
|
803fb7 |
- import_job_unref(i->tags_job);
|
|
|
803fb7 |
- import_job_unref(i->ancestry_job);
|
|
|
803fb7 |
- import_job_unref(i->json_job);
|
|
|
803fb7 |
- import_job_unref(i->layer_job);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- curl_glue_unref(i->glue);
|
|
|
803fb7 |
- sd_event_unref(i->event);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (i->temp_path) {
|
|
|
803fb7 |
- (void) btrfs_subvol_remove(i->temp_path);
|
|
|
803fb7 |
- (void) rm_rf_dangerous(i->temp_path, false, true, false);
|
|
|
803fb7 |
- free(i->temp_path);
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- free(i->name);
|
|
|
803fb7 |
- free(i->tag);
|
|
|
803fb7 |
- free(i->id);
|
|
|
803fb7 |
- free(i->response_token);
|
|
|
803fb7 |
- free(i->response_registries);
|
|
|
803fb7 |
- strv_free(i->ancestry);
|
|
|
803fb7 |
- free(i->final_path);
|
|
|
803fb7 |
- free(i->index_url);
|
|
|
803fb7 |
- free(i->image_root);
|
|
|
803fb7 |
- free(i->local);
|
|
|
803fb7 |
- free(i);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return NULL;
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-int dkr_import_new(
|
|
|
803fb7 |
- DkrImport **ret,
|
|
|
803fb7 |
- sd_event *event,
|
|
|
803fb7 |
- const char *index_url,
|
|
|
803fb7 |
- const char *image_root,
|
|
|
803fb7 |
- DkrImportFinished on_finished,
|
|
|
803fb7 |
- void *userdata) {
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- _cleanup_(dkr_import_unrefp) DkrImport *i = NULL;
|
|
|
803fb7 |
- char *e;
|
|
|
803fb7 |
- int r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(ret);
|
|
|
803fb7 |
- assert(index_url);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!http_url_is_valid(index_url))
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i = new0(DkrImport, 1);
|
|
|
803fb7 |
- if (!i)
|
|
|
803fb7 |
- return -ENOMEM;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->on_finished = on_finished;
|
|
|
803fb7 |
- i->userdata = userdata;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->image_root = strdup(image_root ?: "/var/lib/machines");
|
|
|
803fb7 |
- if (!i->image_root)
|
|
|
803fb7 |
- return -ENOMEM;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->index_url = strdup(index_url);
|
|
|
803fb7 |
- if (!i->index_url)
|
|
|
803fb7 |
- return -ENOMEM;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- e = endswith(i->index_url, "/");
|
|
|
803fb7 |
- if (e)
|
|
|
803fb7 |
- *e = 0;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (event)
|
|
|
803fb7 |
- i->event = sd_event_ref(event);
|
|
|
803fb7 |
- else {
|
|
|
803fb7 |
- r = sd_event_default(&i->event);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return r;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = curl_glue_new(&i->glue, i->event);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->glue->on_finished = import_job_curl_on_finished;
|
|
|
803fb7 |
- i->glue->userdata = i;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- *ret = i;
|
|
|
803fb7 |
- i = NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return 0;
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static void dkr_import_report_progress(DkrImport *i, DkrProgress p) {
|
|
|
803fb7 |
- unsigned percent;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(i);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- switch (p) {
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- case DKR_SEARCHING:
|
|
|
803fb7 |
- percent = 0;
|
|
|
803fb7 |
- if (i->images_job)
|
|
|
803fb7 |
- percent += i->images_job->progress_percent * 5 / 100;
|
|
|
803fb7 |
- break;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- case DKR_RESOLVING:
|
|
|
803fb7 |
- percent = 5;
|
|
|
803fb7 |
- if (i->tags_job)
|
|
|
803fb7 |
- percent += i->tags_job->progress_percent * 5 / 100;
|
|
|
803fb7 |
- break;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- case DKR_METADATA:
|
|
|
803fb7 |
- percent = 10;
|
|
|
803fb7 |
- if (i->ancestry_job)
|
|
|
803fb7 |
- percent += i->ancestry_job->progress_percent * 5 / 100;
|
|
|
803fb7 |
- if (i->json_job)
|
|
|
803fb7 |
- percent += i->json_job->progress_percent * 5 / 100;
|
|
|
803fb7 |
- break;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- case DKR_DOWNLOADING:
|
|
|
803fb7 |
- percent = 20;
|
|
|
803fb7 |
- percent += 75 * i->current_ancestry / MAX(1U, i->n_ancestry);
|
|
|
803fb7 |
- if (i->layer_job)
|
|
|
803fb7 |
- percent += i->layer_job->progress_percent * 75 / MAX(1U, i->n_ancestry) / 100;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- break;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- case DKR_COPYING:
|
|
|
803fb7 |
- percent = 95;
|
|
|
803fb7 |
- break;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- default:
|
|
|
803fb7 |
- assert_not_reached("Unknown progress state");
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- sd_notifyf(false, "X_IMPORT_PROGRESS=%u", percent);
|
|
|
803fb7 |
- log_debug("Combined progress %u%%", percent);
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static int parse_id(const void *payload, size_t size, char **ret) {
|
|
|
803fb7 |
- _cleanup_free_ char *buf = NULL, *id = NULL, *other = NULL;
|
|
|
803fb7 |
- union json_value v = {};
|
|
|
803fb7 |
- void *json_state = NULL;
|
|
|
803fb7 |
- const char *p;
|
|
|
803fb7 |
- int t;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(payload);
|
|
|
803fb7 |
- assert(ret);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (size <= 0)
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (memchr(payload, 0, size))
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- buf = strndup(payload, size);
|
|
|
803fb7 |
- if (!buf)
|
|
|
803fb7 |
- return -ENOMEM;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- p = buf;
|
|
|
803fb7 |
- t = json_tokenize(&p, &id, &v, &json_state, NULL);
|
|
|
803fb7 |
- if (t < 0)
|
|
|
803fb7 |
- return t;
|
|
|
803fb7 |
- if (t != JSON_STRING)
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- t = json_tokenize(&p, &other, &v, &json_state, NULL);
|
|
|
803fb7 |
- if (t < 0)
|
|
|
803fb7 |
- return t;
|
|
|
803fb7 |
- if (t != JSON_END)
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!dkr_id_is_valid(id))
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- *ret = id;
|
|
|
803fb7 |
- id = NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return 0;
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static int parse_ancestry(const void *payload, size_t size, char ***ret) {
|
|
|
803fb7 |
- _cleanup_free_ char *buf = NULL;
|
|
|
803fb7 |
- void *json_state = NULL;
|
|
|
803fb7 |
- const char *p;
|
|
|
803fb7 |
- enum {
|
|
|
803fb7 |
- STATE_BEGIN,
|
|
|
803fb7 |
- STATE_ITEM,
|
|
|
803fb7 |
- STATE_COMMA,
|
|
|
803fb7 |
- STATE_END,
|
|
|
803fb7 |
- } state = STATE_BEGIN;
|
|
|
803fb7 |
- _cleanup_strv_free_ char **l = NULL;
|
|
|
803fb7 |
- size_t n = 0, allocated = 0;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (size <= 0)
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (memchr(payload, 0, size))
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- buf = strndup(payload, size);
|
|
|
803fb7 |
- if (!buf)
|
|
|
803fb7 |
- return -ENOMEM;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- p = buf;
|
|
|
803fb7 |
- for (;;) {
|
|
|
803fb7 |
- _cleanup_free_ char *str;
|
|
|
803fb7 |
- union json_value v = {};
|
|
|
803fb7 |
- int t;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- t = json_tokenize(&p, &str, &v, &json_state, NULL);
|
|
|
803fb7 |
- if (t < 0)
|
|
|
803fb7 |
- return t;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- switch (state) {
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- case STATE_BEGIN:
|
|
|
803fb7 |
- if (t == JSON_ARRAY_OPEN)
|
|
|
803fb7 |
- state = STATE_ITEM;
|
|
|
803fb7 |
- else
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- break;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- case STATE_ITEM:
|
|
|
803fb7 |
- if (t == JSON_STRING) {
|
|
|
803fb7 |
- if (!dkr_id_is_valid(str))
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (n+1 > LAYERS_MAX)
|
|
|
803fb7 |
- return -EFBIG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!GREEDY_REALLOC(l, allocated, n + 2))
|
|
|
803fb7 |
- return -ENOMEM;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- l[n++] = str;
|
|
|
803fb7 |
- str = NULL;
|
|
|
803fb7 |
- l[n] = NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- state = STATE_COMMA;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- } else if (t == JSON_ARRAY_CLOSE)
|
|
|
803fb7 |
- state = STATE_END;
|
|
|
803fb7 |
- else
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- break;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- case STATE_COMMA:
|
|
|
803fb7 |
- if (t == JSON_COMMA)
|
|
|
803fb7 |
- state = STATE_ITEM;
|
|
|
803fb7 |
- else if (t == JSON_ARRAY_CLOSE)
|
|
|
803fb7 |
- state = STATE_END;
|
|
|
803fb7 |
- else
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
- break;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- case STATE_END:
|
|
|
803fb7 |
- if (t == JSON_END) {
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (strv_isempty(l))
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!strv_is_uniq(l))
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- l = strv_reverse(l);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- *ret = l;
|
|
|
803fb7 |
- l = NULL;
|
|
|
803fb7 |
- return 0;
|
|
|
803fb7 |
- } else
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static const char *dkr_import_current_layer(DkrImport *i) {
|
|
|
803fb7 |
- assert(i);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (strv_isempty(i->ancestry))
|
|
|
803fb7 |
- return NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return i->ancestry[i->current_ancestry];
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static const char *dkr_import_current_base_layer(DkrImport *i) {
|
|
|
803fb7 |
- assert(i);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (strv_isempty(i->ancestry))
|
|
|
803fb7 |
- return NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (i->current_ancestry <= 0)
|
|
|
803fb7 |
- return NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return i->ancestry[i->current_ancestry-1];
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static int dkr_import_add_token(DkrImport *i, ImportJob *j) {
|
|
|
803fb7 |
- const char *t;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(i);
|
|
|
803fb7 |
- assert(j);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (i->response_token)
|
|
|
803fb7 |
- t = strjoina("Authorization: Token ", i->response_token);
|
|
|
803fb7 |
- else
|
|
|
803fb7 |
- t = HEADER_TOKEN " true";
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- j->request_header = curl_slist_new("Accept: application/json", t, NULL);
|
|
|
803fb7 |
- if (!j->request_header)
|
|
|
803fb7 |
- return -ENOMEM;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return 0;
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static bool dkr_import_is_done(DkrImport *i) {
|
|
|
803fb7 |
- assert(i);
|
|
|
803fb7 |
- assert(i->images_job);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (i->images_job->state != IMPORT_JOB_DONE)
|
|
|
803fb7 |
- return false;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!i->tags_job || i->tags_job->state != IMPORT_JOB_DONE)
|
|
|
803fb7 |
- return false;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!i->ancestry_job || i->ancestry_job->state != IMPORT_JOB_DONE)
|
|
|
803fb7 |
- return false;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!i->json_job || i->json_job->state != IMPORT_JOB_DONE)
|
|
|
803fb7 |
- return false;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (i->layer_job && i->layer_job->state != IMPORT_JOB_DONE)
|
|
|
803fb7 |
- return false;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (dkr_import_current_layer(i))
|
|
|
803fb7 |
- return false;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return true;
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static int dkr_import_make_local_copy(DkrImport *i) {
|
|
|
803fb7 |
- int r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(i);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!i->local)
|
|
|
803fb7 |
- return 0;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!i->final_path) {
|
|
|
803fb7 |
- i->final_path = strjoin(i->image_root, "/.dkr-", i->id, NULL);
|
|
|
803fb7 |
- if (!i->final_path)
|
|
|
803fb7 |
- return log_oom();
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = import_make_local_copy(i->final_path, i->image_root, i->local, i->force_local);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return 0;
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static int dkr_import_job_on_open_disk(ImportJob *j) {
|
|
|
803fb7 |
- const char *base;
|
|
|
803fb7 |
- DkrImport *i;
|
|
|
803fb7 |
- int r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(j);
|
|
|
803fb7 |
- assert(j->userdata);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i = j->userdata;
|
|
|
803fb7 |
- assert(i->layer_job == j);
|
|
|
803fb7 |
- assert(i->final_path);
|
|
|
803fb7 |
- assert(!i->temp_path);
|
|
|
803fb7 |
- assert(i->tar_pid <= 0);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = tempfn_random(i->final_path, &i->temp_path);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return log_oom();
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- mkdir_parents_label(i->temp_path, 0700);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- base = dkr_import_current_base_layer(i);
|
|
|
803fb7 |
- if (base) {
|
|
|
803fb7 |
- const char *base_path;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- base_path = strjoina(i->image_root, "/.dkr-", base);
|
|
|
803fb7 |
- r = btrfs_subvol_snapshot(base_path, i->temp_path, false, true);
|
|
|
803fb7 |
- } else
|
|
|
803fb7 |
- r = btrfs_subvol_make(i->temp_path);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return log_error_errno(r, "Failed to make btrfs subvolume %s: %m", i->temp_path);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- j->disk_fd = import_fork_tar(i->temp_path, &i->tar_pid);
|
|
|
803fb7 |
- if (j->disk_fd < 0)
|
|
|
803fb7 |
- return j->disk_fd;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return 0;
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static void dkr_import_job_on_progress(ImportJob *j) {
|
|
|
803fb7 |
- DkrImport *i;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(j);
|
|
|
803fb7 |
- assert(j->userdata);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i = j->userdata;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- dkr_import_report_progress(
|
|
|
803fb7 |
- i,
|
|
|
803fb7 |
- j == i->images_job ? DKR_SEARCHING :
|
|
|
803fb7 |
- j == i->tags_job ? DKR_RESOLVING :
|
|
|
803fb7 |
- j == i->ancestry_job || j == i->json_job ? DKR_METADATA :
|
|
|
803fb7 |
- DKR_DOWNLOADING);
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static int dkr_import_pull_layer(DkrImport *i) {
|
|
|
803fb7 |
- _cleanup_free_ char *path = NULL;
|
|
|
803fb7 |
- const char *url, *layer = NULL;
|
|
|
803fb7 |
- int r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(i);
|
|
|
803fb7 |
- assert(!i->layer_job);
|
|
|
803fb7 |
- assert(!i->temp_path);
|
|
|
803fb7 |
- assert(!i->final_path);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- for (;;) {
|
|
|
803fb7 |
- layer = dkr_import_current_layer(i);
|
|
|
803fb7 |
- if (!layer)
|
|
|
803fb7 |
- return 0; /* no more layers */
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- path = strjoin(i->image_root, "/.dkr-", layer, NULL);
|
|
|
803fb7 |
- if (!path)
|
|
|
803fb7 |
- return log_oom();
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (laccess(path, F_OK) < 0) {
|
|
|
803fb7 |
- if (errno == ENOENT)
|
|
|
803fb7 |
- break;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return log_error_errno(errno, "Failed to check for container: %m");
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- log_info("Layer %s already exists, skipping.", layer);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->current_ancestry++;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- free(path);
|
|
|
803fb7 |
- path = NULL;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- log_info("Pulling layer %s...", layer);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->final_path = path;
|
|
|
803fb7 |
- path = NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- url = strjoina(PROTOCOL_PREFIX, i->response_registries[0], "/v1/images/", layer, "/layer");
|
|
|
803fb7 |
- r = import_job_new(&i->layer_job, url, i->glue, i);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return log_error_errno(r, "Failed to allocate layer job: %m");
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = dkr_import_add_token(i, i->layer_job);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return log_oom();
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->layer_job->on_finished = dkr_import_job_on_finished;
|
|
|
803fb7 |
- i->layer_job->on_open_disk = dkr_import_job_on_open_disk;
|
|
|
803fb7 |
- i->layer_job->on_progress = dkr_import_job_on_progress;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = import_job_begin(i->layer_job);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return log_error_errno(r, "Failed to start layer job: %m");
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return 0;
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static void dkr_import_job_on_finished(ImportJob *j) {
|
|
|
803fb7 |
- DkrImport *i;
|
|
|
803fb7 |
- int r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(j);
|
|
|
803fb7 |
- assert(j->userdata);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i = j->userdata;
|
|
|
803fb7 |
- if (j->error != 0) {
|
|
|
803fb7 |
- if (j == i->images_job)
|
|
|
803fb7 |
- log_error_errno(j->error, "Failed to retrieve images list. (Wrong index URL?)");
|
|
|
803fb7 |
- else if (j == i->tags_job)
|
|
|
803fb7 |
- log_error_errno(j->error, "Failed to retrieve tags list.");
|
|
|
803fb7 |
- else if (j == i->ancestry_job)
|
|
|
803fb7 |
- log_error_errno(j->error, "Failed to retrieve ancestry list.");
|
|
|
803fb7 |
- else if (j == i->json_job)
|
|
|
803fb7 |
- log_error_errno(j->error, "Failed to retrieve json data.");
|
|
|
803fb7 |
- else
|
|
|
803fb7 |
- log_error_errno(j->error, "Failed to retrieve layer data.");
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = j->error;
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (i->images_job == j) {
|
|
|
803fb7 |
- const char *url;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(!i->tags_job);
|
|
|
803fb7 |
- assert(!i->ancestry_job);
|
|
|
803fb7 |
- assert(!i->json_job);
|
|
|
803fb7 |
- assert(!i->layer_job);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (strv_isempty(i->response_registries)) {
|
|
|
803fb7 |
- r = -EBADMSG;
|
|
|
803fb7 |
- log_error("Didn't get registry information.");
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- log_info("Index lookup succeeded, directed to registry %s.", i->response_registries[0]);
|
|
|
803fb7 |
- dkr_import_report_progress(i, DKR_RESOLVING);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- url = strjoina(PROTOCOL_PREFIX, i->response_registries[0], "/v1/repositories/", i->name, "/tags/", i->tag);
|
|
|
803fb7 |
- r = import_job_new(&i->tags_job, url, i->glue, i);
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_error_errno(r, "Failed to allocate tags job: %m");
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = dkr_import_add_token(i, i->tags_job);
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_oom();
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->tags_job->on_finished = dkr_import_job_on_finished;
|
|
|
803fb7 |
- i->tags_job->on_progress = dkr_import_job_on_progress;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = import_job_begin(i->tags_job);
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_error_errno(r, "Failed to start tags job: %m");
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- } else if (i->tags_job == j) {
|
|
|
803fb7 |
- const char *url;
|
|
|
803fb7 |
- char *id = NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(!i->ancestry_job);
|
|
|
803fb7 |
- assert(!i->json_job);
|
|
|
803fb7 |
- assert(!i->layer_job);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = parse_id(j->payload, j->payload_size, &id;;
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_error_errno(r, "Failed to parse JSON id.");
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- free(i->id);
|
|
|
803fb7 |
- i->id = id;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- log_info("Tag lookup succeeded, resolved to layer %s.", i->id);
|
|
|
803fb7 |
- dkr_import_report_progress(i, DKR_METADATA);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- url = strjoina(PROTOCOL_PREFIX, i->response_registries[0], "/v1/images/", i->id, "/ancestry");
|
|
|
803fb7 |
- r = import_job_new(&i->ancestry_job, url, i->glue, i);
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_error_errno(r, "Failed to allocate ancestry job: %m");
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = dkr_import_add_token(i, i->ancestry_job);
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_oom();
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->ancestry_job->on_finished = dkr_import_job_on_finished;
|
|
|
803fb7 |
- i->ancestry_job->on_progress = dkr_import_job_on_progress;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- url = strjoina(PROTOCOL_PREFIX, i->response_registries[0], "/v1/images/", i->id, "/json");
|
|
|
803fb7 |
- r = import_job_new(&i->json_job, url, i->glue, i);
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_error_errno(r, "Failed to allocate json job: %m");
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = dkr_import_add_token(i, i->json_job);
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_oom();
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->json_job->on_finished = dkr_import_job_on_finished;
|
|
|
803fb7 |
- i->json_job->on_progress = dkr_import_job_on_progress;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = import_job_begin(i->ancestry_job);
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_error_errno(r, "Failed to start ancestry job: %m");
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = import_job_begin(i->json_job);
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_error_errno(r, "Failed to start json job: %m");
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- } else if (i->ancestry_job == j) {
|
|
|
803fb7 |
- char **ancestry = NULL, **k;
|
|
|
803fb7 |
- unsigned n;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(!i->layer_job);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = parse_ancestry(j->payload, j->payload_size, &ancestry);
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_error_errno(r, "Failed to parse JSON id.");
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- n = strv_length(ancestry);
|
|
|
803fb7 |
- if (n <= 0 || !streq(ancestry[n-1], i->id)) {
|
|
|
803fb7 |
- log_error("Ancestry doesn't end in main layer.");
|
|
|
803fb7 |
- strv_free(ancestry);
|
|
|
803fb7 |
- r = -EBADMSG;
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- log_info("Ancestor lookup succeeded, requires layers:\n");
|
|
|
803fb7 |
- STRV_FOREACH(k, ancestry)
|
|
|
803fb7 |
- log_info("\t%s", *k);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- strv_free(i->ancestry);
|
|
|
803fb7 |
- i->ancestry = ancestry;
|
|
|
803fb7 |
- i->n_ancestry = n;
|
|
|
803fb7 |
- i->current_ancestry = 0;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- dkr_import_report_progress(i, DKR_DOWNLOADING);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = dkr_import_pull_layer(i);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- } else if (i->layer_job == j) {
|
|
|
803fb7 |
- assert(i->temp_path);
|
|
|
803fb7 |
- assert(i->final_path);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- j->disk_fd = safe_close(j->disk_fd);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (i->tar_pid > 0) {
|
|
|
803fb7 |
- r = wait_for_terminate_and_warn("tar", i->tar_pid, true);
|
|
|
803fb7 |
- i->tar_pid = 0;
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = aufs_resolve(i->temp_path);
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_error_errno(r, "Failed to resolve aufs whiteouts: %m");
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = btrfs_subvol_set_read_only(i->temp_path, true);
|
|
|
803fb7 |
- if (r < 0) {
|
|
|
803fb7 |
- log_error_errno(r, "Failed to mark snapshot read-only: %m");
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (rename(i->temp_path, i->final_path) < 0) {
|
|
|
803fb7 |
- log_error_errno(errno, "Failed to rename snaphsot: %m");
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- log_info("Completed writing to layer %s.", i->final_path);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->layer_job = import_job_unref(i->layer_job);
|
|
|
803fb7 |
- free(i->temp_path);
|
|
|
803fb7 |
- i->temp_path = NULL;
|
|
|
803fb7 |
- free(i->final_path);
|
|
|
803fb7 |
- i->final_path = NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->current_ancestry ++;
|
|
|
803fb7 |
- r = dkr_import_pull_layer(i);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- } else if (i->json_job != j)
|
|
|
803fb7 |
- assert_not_reached("Got finished event for unknown curl object");
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!dkr_import_is_done(i))
|
|
|
803fb7 |
- return;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- dkr_import_report_progress(i, DKR_COPYING);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = dkr_import_make_local_copy(i);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- goto finish;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = 0;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-finish:
|
|
|
803fb7 |
- if (i->on_finished)
|
|
|
803fb7 |
- i->on_finished(i, r, i->userdata);
|
|
|
803fb7 |
- else
|
|
|
803fb7 |
- sd_event_exit(i->event, r);
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static int dkr_import_job_on_header(ImportJob *j, const char *header, size_t sz) {
|
|
|
803fb7 |
- _cleanup_free_ char *registry = NULL;
|
|
|
803fb7 |
- char *token;
|
|
|
803fb7 |
- DkrImport *i;
|
|
|
803fb7 |
- int r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(j);
|
|
|
803fb7 |
- assert(j->userdata);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i = j->userdata;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = curl_header_strdup(header, sz, HEADER_TOKEN, &token);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return log_oom();
|
|
|
803fb7 |
- if (r > 0) {
|
|
|
803fb7 |
- free(i->response_token);
|
|
|
803fb7 |
- i->response_token = token;
|
|
|
803fb7 |
- return 0;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = curl_header_strdup(header, sz, HEADER_REGISTRY, ®istry);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return log_oom();
|
|
|
803fb7 |
- if (r > 0) {
|
|
|
803fb7 |
- char **l, **k;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- l = strv_split(registry, ",");
|
|
|
803fb7 |
- if (!l)
|
|
|
803fb7 |
- return log_oom();
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- STRV_FOREACH(k, l) {
|
|
|
803fb7 |
- if (!hostname_is_valid(*k)) {
|
|
|
803fb7 |
- log_error("Registry hostname is not valid.");
|
|
|
803fb7 |
- strv_free(l);
|
|
|
803fb7 |
- return -EBADMSG;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- strv_free(i->response_registries);
|
|
|
803fb7 |
- i->response_registries = l;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return 0;
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-int dkr_import_pull(DkrImport *i, const char *name, const char *tag, const char *local, bool force_local) {
|
|
|
803fb7 |
- const char *url;
|
|
|
803fb7 |
- int r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(i);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!dkr_name_is_valid(name))
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (tag && !dkr_tag_is_valid(tag))
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (local && !machine_name_is_valid(local))
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (i->images_job)
|
|
|
803fb7 |
- return -EBUSY;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!tag)
|
|
|
803fb7 |
- tag = "latest";
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = free_and_strdup(&i->local, local);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return r;
|
|
|
803fb7 |
- i->force_local = force_local;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = free_and_strdup(&i->name, name);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return r;
|
|
|
803fb7 |
- r = free_and_strdup(&i->tag, tag);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- url = strjoina(i->index_url, "/v1/repositories/", name, "/images");
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = import_job_new(&i->images_job, url, i->glue, i);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = dkr_import_add_token(i, i->images_job);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- i->images_job->on_finished = dkr_import_job_on_finished;
|
|
|
803fb7 |
- i->images_job->on_header = dkr_import_job_on_header;
|
|
|
803fb7 |
- i->images_job->on_progress = dkr_import_job_on_progress;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return import_job_begin(i->images_job);
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
diff --git a/src/import/import-dkr.h b/src/import/import-dkr.h
|
|
|
803fb7 |
deleted file mode 100644
|
|
|
803fb7 |
index 633c76796..000000000
|
|
|
803fb7 |
--- a/src/import/import-dkr.h
|
|
|
803fb7 |
+++ /dev/null
|
|
|
803fb7 |
@@ -1,36 +0,0 @@
|
|
|
803fb7 |
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-/***
|
|
|
803fb7 |
- This file is part of systemd.
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- Copyright 2014 Lennart Poettering
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- systemd is free software; you can redistribute it and/or modify it
|
|
|
803fb7 |
- under the terms of the GNU Lesser General Public License as published by
|
|
|
803fb7 |
- the Free Software Foundation; either version 2.1 of the License, or
|
|
|
803fb7 |
- (at your option) any later version.
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- systemd is distributed in the hope that it will be useful, but
|
|
|
803fb7 |
- WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
803fb7 |
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
803fb7 |
- Lesser General Public License for more details.
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- You should have received a copy of the GNU Lesser General Public License
|
|
|
803fb7 |
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
803fb7 |
-***/
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-#pragma once
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-#include "sd-event.h"
|
|
|
803fb7 |
-#include "util.h"
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-typedef struct DkrImport DkrImport;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-typedef void (*DkrImportFinished)(DkrImport *import, int error, void *userdata);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-int dkr_import_new(DkrImport **import, sd_event *event, const char *index_url, const char *image_root, DkrImportFinished on_finished, void *userdata);
|
|
|
803fb7 |
-DkrImport* dkr_import_unref(DkrImport *import);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-DEFINE_TRIVIAL_CLEANUP_FUNC(DkrImport*, dkr_import_unref);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-int dkr_import_pull(DkrImport *import, const char *name, const char *tag, const char *local, bool force_local);
|
|
|
803fb7 |
diff --git a/src/import/importd.c b/src/import/importd.c
|
|
|
803fb7 |
index 1222bf3cd..9aaf991f8 100644
|
|
|
803fb7 |
--- a/src/import/importd.c
|
|
|
803fb7 |
+++ b/src/import/importd.c
|
|
|
803fb7 |
@@ -38,7 +38,6 @@ typedef struct Manager Manager;
|
|
|
803fb7 |
typedef enum TransferType {
|
|
|
803fb7 |
TRANSFER_TAR,
|
|
|
803fb7 |
TRANSFER_RAW,
|
|
|
803fb7 |
- TRANSFER_DKR,
|
|
|
803fb7 |
_TRANSFER_TYPE_MAX,
|
|
|
803fb7 |
_TRANSFER_TYPE_INVALID = -1,
|
|
|
803fb7 |
} TransferType;
|
|
|
803fb7 |
@@ -56,8 +55,6 @@ struct Transfer {
|
|
|
803fb7 |
char *local;
|
|
|
803fb7 |
bool force_local;
|
|
|
803fb7 |
|
|
|
803fb7 |
- char *dkr_index_url;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
pid_t pid;
|
|
|
803fb7 |
|
|
|
803fb7 |
int log_fd;
|
|
|
803fb7 |
@@ -91,7 +88,6 @@ struct Manager {
|
|
|
803fb7 |
static const char* const transfer_type_table[_TRANSFER_TYPE_MAX] = {
|
|
|
803fb7 |
[TRANSFER_TAR] = "tar",
|
|
|
803fb7 |
[TRANSFER_RAW] = "raw",
|
|
|
803fb7 |
- [TRANSFER_DKR] = "dkr",
|
|
|
803fb7 |
};
|
|
|
803fb7 |
|
|
|
803fb7 |
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(transfer_type, TransferType);
|
|
|
803fb7 |
@@ -108,7 +104,6 @@ static Transfer *transfer_unref(Transfer *t) {
|
|
|
803fb7 |
|
|
|
803fb7 |
free(t->remote);
|
|
|
803fb7 |
free(t->local);
|
|
|
803fb7 |
- free(t->dkr_index_url);
|
|
|
803fb7 |
free(t->object_path);
|
|
|
803fb7 |
|
|
|
803fb7 |
if (t->pid > 0) {
|
|
|
803fb7 |
@@ -355,7 +350,6 @@ static int transfer_start(Transfer *t) {
|
|
|
803fb7 |
"--verify",
|
|
|
803fb7 |
NULL, /* verify argument */
|
|
|
803fb7 |
NULL, /* maybe --force */
|
|
|
803fb7 |
- NULL, /* maybe --dkr-index-url */
|
|
|
803fb7 |
NULL, /* the actual URL */
|
|
|
803fb7 |
NULL, /* remote */
|
|
|
803fb7 |
NULL, /* local */
|
|
|
803fb7 |
@@ -410,11 +404,6 @@ static int transfer_start(Transfer *t) {
|
|
|
803fb7 |
if (t->force_local)
|
|
|
803fb7 |
cmd[k++] = "--force";
|
|
|
803fb7 |
|
|
|
803fb7 |
- if (t->dkr_index_url) {
|
|
|
803fb7 |
- cmd[k++] = "--dkr-index-url";
|
|
|
803fb7 |
- cmd[k++] = t->dkr_index_url;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
cmd[k++] = t->remote;
|
|
|
803fb7 |
if (t->local)
|
|
|
803fb7 |
cmd[k++] = t->local;
|
|
|
803fb7 |
@@ -624,7 +613,7 @@ static int manager_new(Manager **ret) {
|
|
|
803fb7 |
return 0;
|
|
|
803fb7 |
}
|
|
|
803fb7 |
|
|
|
803fb7 |
-static Transfer *manager_find(Manager *m, TransferType type, const char *dkr_index_url, const char *remote) {
|
|
|
803fb7 |
+static Transfer *manager_find(Manager *m, TransferType type, const char *remote) {
|
|
|
803fb7 |
Transfer *t;
|
|
|
803fb7 |
Iterator i;
|
|
|
803fb7 |
|
|
|
803fb7 |
@@ -635,8 +624,7 @@ static Transfer *manager_find(Manager *m, TransferType type, const char *dkr_ind
|
|
|
803fb7 |
HASHMAP_FOREACH(t, m->transfers, i) {
|
|
|
803fb7 |
|
|
|
803fb7 |
if (t->type == type &&
|
|
|
803fb7 |
- streq_ptr(t->remote, remote) &&
|
|
|
803fb7 |
- streq_ptr(t->dkr_index_url, dkr_index_url))
|
|
|
803fb7 |
+ streq_ptr(t->remote, remote))
|
|
|
803fb7 |
return t;
|
|
|
803fb7 |
}
|
|
|
803fb7 |
|
|
|
803fb7 |
@@ -689,7 +677,7 @@ static int method_pull_tar_or_raw(sd_bus *bus, sd_bus_message *msg, void *userda
|
|
|
803fb7 |
|
|
|
803fb7 |
type = streq_ptr(sd_bus_message_get_member(msg), "PullTar") ? TRANSFER_TAR : TRANSFER_RAW;
|
|
|
803fb7 |
|
|
|
803fb7 |
- if (manager_find(m, type, NULL, remote))
|
|
|
803fb7 |
+ if (manager_find(m, type, remote))
|
|
|
803fb7 |
return sd_bus_error_setf(error, BUS_ERROR_TRANSFER_IN_PROGRESS, "Transfer for %s already in progress.", remote);
|
|
|
803fb7 |
|
|
|
803fb7 |
r = transfer_new(m, &t);
|
|
|
803fb7 |
@@ -719,98 +707,6 @@ static int method_pull_tar_or_raw(sd_bus *bus, sd_bus_message *msg, void *userda
|
|
|
803fb7 |
return sd_bus_reply_method_return(msg, "uo", id, object);
|
|
|
803fb7 |
}
|
|
|
803fb7 |
|
|
|
803fb7 |
-static int method_pull_dkr(sd_bus *bus, sd_bus_message *msg, void *userdata, sd_bus_error *error) {
|
|
|
803fb7 |
- _cleanup_(transfer_unrefp) Transfer *t = NULL;
|
|
|
803fb7 |
- const char *index_url, *remote, *tag, *local, *verify, *object;
|
|
|
803fb7 |
- Manager *m = userdata;
|
|
|
803fb7 |
- ImportVerify v;
|
|
|
803fb7 |
- int force, r;
|
|
|
803fb7 |
- uint32_t id;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert(bus);
|
|
|
803fb7 |
- assert(msg);
|
|
|
803fb7 |
- assert(m);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = bus_verify_polkit_async(
|
|
|
803fb7 |
- msg,
|
|
|
803fb7 |
- CAP_SYS_ADMIN,
|
|
|
803fb7 |
- "org.freedesktop.import1.pull",
|
|
|
803fb7 |
- false,
|
|
|
803fb7 |
- &m->polkit_registry,
|
|
|
803fb7 |
- error);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return r;
|
|
|
803fb7 |
- if (r == 0)
|
|
|
803fb7 |
- return 1; /* Will call us back */
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = sd_bus_message_read(msg, "sssssb", &index_url, &remote, &tag, &local, &verify, &force);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (isempty(index_url))
|
|
|
803fb7 |
- index_url = DEFAULT_DKR_INDEX_URL;
|
|
|
803fb7 |
- if (!index_url)
|
|
|
803fb7 |
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Index URL must be specified.");
|
|
|
803fb7 |
- if (!http_url_is_valid(index_url))
|
|
|
803fb7 |
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Index URL %s is invalid", index_url);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!dkr_name_is_valid(remote))
|
|
|
803fb7 |
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Remote name %s is not valid", remote);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (isempty(tag))
|
|
|
803fb7 |
- tag = "latest";
|
|
|
803fb7 |
- else if (!dkr_tag_is_valid(tag))
|
|
|
803fb7 |
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Tag %s is not valid", tag);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (isempty(local))
|
|
|
803fb7 |
- local = NULL;
|
|
|
803fb7 |
- else if (!machine_name_is_valid(local))
|
|
|
803fb7 |
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Local name %s is invalid", local);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (isempty(verify))
|
|
|
803fb7 |
- v = IMPORT_VERIFY_SIGNATURE;
|
|
|
803fb7 |
- else
|
|
|
803fb7 |
- v = import_verify_from_string(verify);
|
|
|
803fb7 |
- if (v < 0)
|
|
|
803fb7 |
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown verification mode %s", verify);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (v != IMPORT_VERIFY_NO)
|
|
|
803fb7 |
- return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "DKR does not support verification.");
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (manager_find(m, TRANSFER_DKR, index_url, remote))
|
|
|
803fb7 |
- return sd_bus_error_setf(error, BUS_ERROR_TRANSFER_IN_PROGRESS, "Transfer for %s already in progress.", remote);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = transfer_new(m, &t);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- t->type = TRANSFER_DKR;
|
|
|
803fb7 |
- t->verify = v;
|
|
|
803fb7 |
- t->force_local = force;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- t->dkr_index_url = strdup(index_url);
|
|
|
803fb7 |
- if (!t->dkr_index_url)
|
|
|
803fb7 |
- return -ENOMEM;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- t->remote = strjoin(remote, ":", tag, NULL);
|
|
|
803fb7 |
- if (!t->remote)
|
|
|
803fb7 |
- return -ENOMEM;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- t->local = strdup(local);
|
|
|
803fb7 |
- if (!t->local)
|
|
|
803fb7 |
- return -ENOMEM;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = transfer_start(t);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- object = t->object_path;
|
|
|
803fb7 |
- id = t->id;
|
|
|
803fb7 |
- t = NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return sd_bus_reply_method_return(msg, "uo", id, object);
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
static int method_list_transfers(sd_bus *bus, sd_bus_message *msg, void *userdata, sd_bus_error *error) {
|
|
|
803fb7 |
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
|
|
|
803fb7 |
Manager *m = userdata;
|
|
|
803fb7 |
@@ -956,7 +852,6 @@ static const sd_bus_vtable manager_vtable[] = {
|
|
|
803fb7 |
SD_BUS_VTABLE_START(0),
|
|
|
803fb7 |
SD_BUS_METHOD("PullTar", "sssb", "uo", method_pull_tar_or_raw, SD_BUS_VTABLE_UNPRIVILEGED),
|
|
|
803fb7 |
SD_BUS_METHOD("PullRaw", "sssb", "uo", method_pull_tar_or_raw, SD_BUS_VTABLE_UNPRIVILEGED),
|
|
|
803fb7 |
- SD_BUS_METHOD("PullDkr", "sssssb", "uo", method_pull_dkr, SD_BUS_VTABLE_UNPRIVILEGED),
|
|
|
803fb7 |
SD_BUS_METHOD("ListTransfers", NULL, "a(usssdo)", method_list_transfers, SD_BUS_VTABLE_UNPRIVILEGED),
|
|
|
803fb7 |
SD_BUS_METHOD("CancelTransfer", "u", NULL, method_cancel_transfer, SD_BUS_VTABLE_UNPRIVILEGED),
|
|
|
803fb7 |
SD_BUS_SIGNAL("TransferNew", "uo", 0),
|
|
|
803fb7 |
diff --git a/src/import/org.freedesktop.import1.conf b/src/import/org.freedesktop.import1.conf
|
|
|
803fb7 |
index ae36af422..ed2539a03 100644
|
|
|
803fb7 |
--- a/src/import/org.freedesktop.import1.conf
|
|
|
803fb7 |
+++ b/src/import/org.freedesktop.import1.conf
|
|
|
803fb7 |
@@ -52,10 +52,6 @@
|
|
|
803fb7 |
send_interface="org.freedesktop.import1.Manager"
|
|
|
803fb7 |
send_member="PullRaw"/>
|
|
|
803fb7 |
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- send_interface="org.freedesktop.import1.Manager"
|
|
|
803fb7 |
- send_member="PullDkr"/>
|
|
|
803fb7 |
-
|
|
|
803fb7 |
|
|
|
803fb7 |
send_interface="org.freedesktop.import1.Transfer"
|
|
|
803fb7 |
send_member="Cancel"/>
|
|
|
803fb7 |
diff --git a/src/import/pull.c b/src/import/pull.c
|
|
|
803fb7 |
index ee3ff6803..9cb10880f 100644
|
|
|
803fb7 |
--- a/src/import/pull.c
|
|
|
803fb7 |
+++ b/src/import/pull.c
|
|
|
803fb7 |
@@ -28,13 +28,11 @@
|
|
|
803fb7 |
#include "machine-image.h"
|
|
|
803fb7 |
#include "import-tar.h"
|
|
|
803fb7 |
#include "import-raw.h"
|
|
|
803fb7 |
-#include "import-dkr.h"
|
|
|
803fb7 |
#include "import-util.h"
|
|
|
803fb7 |
|
|
|
803fb7 |
static bool arg_force = false;
|
|
|
803fb7 |
static const char *arg_image_root = "/var/lib/machines";
|
|
|
803fb7 |
static ImportVerify arg_verify = IMPORT_VERIFY_SIGNATURE;
|
|
|
803fb7 |
-static const char* arg_dkr_index_url = DEFAULT_DKR_INDEX_URL;
|
|
|
803fb7 |
|
|
|
803fb7 |
static int interrupt_signal_handler(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
|
|
|
803fb7 |
log_notice("Transfer aborted.");
|
|
|
803fb7 |
@@ -214,107 +212,6 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
|
|
|
803fb7 |
return -r;
|
|
|
803fb7 |
}
|
|
|
803fb7 |
|
|
|
803fb7 |
-static void on_dkr_finished(DkrImport *import, int error, void *userdata) {
|
|
|
803fb7 |
- sd_event *event = userdata;
|
|
|
803fb7 |
- assert(import);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (error == 0)
|
|
|
803fb7 |
- log_info("Operation completed successfully.");
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- sd_event_exit(event, abs(error));
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-static int pull_dkr(int argc, char *argv[], void *userdata) {
|
|
|
803fb7 |
- _cleanup_(dkr_import_unrefp) DkrImport *import = NULL;
|
|
|
803fb7 |
- _cleanup_event_unref_ sd_event *event = NULL;
|
|
|
803fb7 |
- const char *name, *tag, *local;
|
|
|
803fb7 |
- int r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!arg_dkr_index_url) {
|
|
|
803fb7 |
- log_error("Please specify an index URL with --dkr-index-url=");
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (arg_verify != IMPORT_VERIFY_NO) {
|
|
|
803fb7 |
- log_error("Imports from dkr do not support image verification, please pass --verify=no.");
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- tag = strchr(argv[1], ':');
|
|
|
803fb7 |
- if (tag) {
|
|
|
803fb7 |
- name = strndupa(argv[1], tag - argv[1]);
|
|
|
803fb7 |
- tag++;
|
|
|
803fb7 |
- } else {
|
|
|
803fb7 |
- name = argv[1];
|
|
|
803fb7 |
- tag = "latest";
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!dkr_name_is_valid(name)) {
|
|
|
803fb7 |
- log_error("Remote name '%s' is not valid.", name);
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!dkr_tag_is_valid(tag)) {
|
|
|
803fb7 |
- log_error("Tag name '%s' is not valid.", tag);
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (argc >= 3)
|
|
|
803fb7 |
- local = argv[2];
|
|
|
803fb7 |
- else {
|
|
|
803fb7 |
- local = strchr(name, '/');
|
|
|
803fb7 |
- if (local)
|
|
|
803fb7 |
- local++;
|
|
|
803fb7 |
- else
|
|
|
803fb7 |
- local = name;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (isempty(local) || streq(local, "-"))
|
|
|
803fb7 |
- local = NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (local) {
|
|
|
803fb7 |
- if (!machine_name_is_valid(local)) {
|
|
|
803fb7 |
- log_error("Local image name '%s' is not valid.", local);
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!arg_force) {
|
|
|
803fb7 |
- r = image_find(local, NULL);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
|
|
|
803fb7 |
- else if (r > 0) {
|
|
|
803fb7 |
- log_error_errno(EEXIST, "Image '%s' already exists.", local);
|
|
|
803fb7 |
- return -EEXIST;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- log_info("Pulling '%s' with tag '%s', saving as '%s'.", name, tag, local);
|
|
|
803fb7 |
- } else
|
|
|
803fb7 |
- log_info("Pulling '%s' with tag '%s'.", name, tag);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = sd_event_default(&event);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return log_error_errno(r, "Failed to allocate event loop: %m");
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- assert_se(sigprocmask_many(SIG_BLOCK, SIGTERM, SIGINT, -1) == 0);
|
|
|
803fb7 |
- sd_event_add_signal(event, NULL, SIGTERM, interrupt_signal_handler, NULL);
|
|
|
803fb7 |
- sd_event_add_signal(event, NULL, SIGINT, interrupt_signal_handler, NULL);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = dkr_import_new(&import, event, arg_dkr_index_url, arg_image_root, on_dkr_finished, event);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return log_error_errno(r, "Failed to allocate importer: %m");
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = dkr_import_pull(import, name, tag, local, arg_force);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return log_error_errno(r, "Failed to pull image: %m");
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = sd_event_loop(event);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return log_error_errno(r, "Failed to run event loop: %m");
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- log_info("Exiting.");
|
|
|
803fb7 |
- return -r;
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
|
|
|
803fb7 |
static int help(int argc, char *argv[], void *userdata) {
|
|
|
803fb7 |
|
|
|
803fb7 |
@@ -326,11 +223,9 @@ static int help(int argc, char *argv[], void *userdata) {
|
|
|
803fb7 |
" --verify= Verify downloaded image, one of: 'no',\n"
|
|
|
803fb7 |
" 'checksum', 'signature'.\n"
|
|
|
803fb7 |
" --image-root= Image root directory\n"
|
|
|
803fb7 |
- " --dkr-index-url=URL Specify index URL to use for downloads\n\n"
|
|
|
803fb7 |
"Commands:\n"
|
|
|
803fb7 |
" tar URL [NAME] Download a TAR image\n"
|
|
|
803fb7 |
- " raw URL [NAME] Download a RAW image\n"
|
|
|
803fb7 |
- " dkr REMOTE [NAME] Download a DKR image\n",
|
|
|
803fb7 |
+ " raw URL [NAME] Download a RAW image\n",
|
|
|
803fb7 |
program_invocation_short_name);
|
|
|
803fb7 |
|
|
|
803fb7 |
return 0;
|
|
|
803fb7 |
@@ -341,7 +236,6 @@ static int parse_argv(int argc, char *argv[]) {
|
|
|
803fb7 |
enum {
|
|
|
803fb7 |
ARG_VERSION = 0x100,
|
|
|
803fb7 |
ARG_FORCE,
|
|
|
803fb7 |
- ARG_DKR_INDEX_URL,
|
|
|
803fb7 |
ARG_IMAGE_ROOT,
|
|
|
803fb7 |
ARG_VERIFY,
|
|
|
803fb7 |
};
|
|
|
803fb7 |
@@ -350,7 +244,6 @@ static int parse_argv(int argc, char *argv[]) {
|
|
|
803fb7 |
{ "help", no_argument, NULL, 'h' },
|
|
|
803fb7 |
{ "version", no_argument, NULL, ARG_VERSION },
|
|
|
803fb7 |
{ "force", no_argument, NULL, ARG_FORCE },
|
|
|
803fb7 |
- { "dkr-index-url", required_argument, NULL, ARG_DKR_INDEX_URL },
|
|
|
803fb7 |
{ "image-root", required_argument, NULL, ARG_IMAGE_ROOT },
|
|
|
803fb7 |
{ "verify", required_argument, NULL, ARG_VERIFY },
|
|
|
803fb7 |
{}
|
|
|
803fb7 |
@@ -377,15 +270,6 @@ static int parse_argv(int argc, char *argv[]) {
|
|
|
803fb7 |
arg_force = true;
|
|
|
803fb7 |
break;
|
|
|
803fb7 |
|
|
|
803fb7 |
- case ARG_DKR_INDEX_URL:
|
|
|
803fb7 |
- if (!http_url_is_valid(optarg)) {
|
|
|
803fb7 |
- log_error("Index URL is not valid: %s", optarg);
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- arg_dkr_index_url = optarg;
|
|
|
803fb7 |
- break;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
case ARG_IMAGE_ROOT:
|
|
|
803fb7 |
arg_image_root = optarg;
|
|
|
803fb7 |
break;
|
|
|
803fb7 |
@@ -415,7 +299,6 @@ static int import_main(int argc, char *argv[]) {
|
|
|
803fb7 |
{ "help", VERB_ANY, VERB_ANY, 0, help },
|
|
|
803fb7 |
{ "tar", 2, 3, 0, pull_tar },
|
|
|
803fb7 |
{ "raw", 2, 3, 0, pull_raw },
|
|
|
803fb7 |
- { "dkr", 2, 3, 0, pull_dkr },
|
|
|
803fb7 |
{}
|
|
|
803fb7 |
};
|
|
|
803fb7 |
|
|
|
803fb7 |
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
|
|
|
803fb7 |
index ef1214a66..cfd3162fb 100644
|
|
|
803fb7 |
--- a/src/machine/machinectl.c
|
|
|
803fb7 |
+++ b/src/machine/machinectl.c
|
|
|
803fb7 |
@@ -77,7 +77,6 @@ static unsigned arg_lines = 10;
|
|
|
803fb7 |
static OutputMode arg_output = OUTPUT_SHORT;
|
|
|
803fb7 |
static bool arg_force = false;
|
|
|
803fb7 |
static ImportVerify arg_verify = IMPORT_VERIFY_SIGNATURE;
|
|
|
803fb7 |
-static const char* arg_dkr_index_url = NULL;
|
|
|
803fb7 |
|
|
|
803fb7 |
static void pager_open_if_enabled(void) {
|
|
|
803fb7 |
|
|
|
803fb7 |
@@ -1998,78 +1997,6 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
|
|
|
803fb7 |
return pull_image_common(bus, m);
|
|
|
803fb7 |
}
|
|
|
803fb7 |
|
|
|
803fb7 |
-static int pull_dkr(int argc, char *argv[], void *userdata) {
|
|
|
803fb7 |
- _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
|
|
|
803fb7 |
- const char *local, *remote, *tag;
|
|
|
803fb7 |
- sd_bus *bus = userdata;
|
|
|
803fb7 |
- int r;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (arg_verify != IMPORT_VERIFY_NO) {
|
|
|
803fb7 |
- log_error("Imports from DKR do not support image verification, please pass --verify=no.");
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- remote = argv[1];
|
|
|
803fb7 |
- tag = strchr(remote, ':');
|
|
|
803fb7 |
- if (tag) {
|
|
|
803fb7 |
- remote = strndupa(remote, tag - remote);
|
|
|
803fb7 |
- tag++;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!dkr_name_is_valid(remote)) {
|
|
|
803fb7 |
- log_error("DKR name '%s' is invalid.", remote);
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
- if (tag && !dkr_tag_is_valid(tag)) {
|
|
|
803fb7 |
- log_error("DKR tag '%s' is invalid.", remote);
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (argc >= 3)
|
|
|
803fb7 |
- local = argv[2];
|
|
|
803fb7 |
- else {
|
|
|
803fb7 |
- local = strchr(remote, '/');
|
|
|
803fb7 |
- if (local)
|
|
|
803fb7 |
- local++;
|
|
|
803fb7 |
- else
|
|
|
803fb7 |
- local = remote;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (isempty(local) || streq(local, "-"))
|
|
|
803fb7 |
- local = NULL;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (local) {
|
|
|
803fb7 |
- if (!machine_name_is_valid(local)) {
|
|
|
803fb7 |
- log_error("Local name %s is not a suitable machine name.", local);
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = sd_bus_message_new_method_call(
|
|
|
803fb7 |
- bus,
|
|
|
803fb7 |
- &m,
|
|
|
803fb7 |
- "org.freedesktop.import1",
|
|
|
803fb7 |
- "/org/freedesktop/import1",
|
|
|
803fb7 |
- "org.freedesktop.import1.Manager",
|
|
|
803fb7 |
- "PullDkr");
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return bus_log_create_error(r);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- r = sd_bus_message_append(
|
|
|
803fb7 |
- m,
|
|
|
803fb7 |
- "sssssb",
|
|
|
803fb7 |
- arg_dkr_index_url,
|
|
|
803fb7 |
- remote,
|
|
|
803fb7 |
- tag,
|
|
|
803fb7 |
- local,
|
|
|
803fb7 |
- import_verify_to_string(arg_verify),
|
|
|
803fb7 |
- arg_force);
|
|
|
803fb7 |
- if (r < 0)
|
|
|
803fb7 |
- return bus_log_create_error(r);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return pull_image_common(bus, m);
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
typedef struct TransferInfo {
|
|
|
803fb7 |
uint32_t id;
|
|
|
803fb7 |
const char *type;
|
|
|
803fb7 |
@@ -2237,8 +2164,6 @@ static int help(int argc, char *argv[], void *userdata) {
|
|
|
803fb7 |
" --verify=MODE Verification mode for downloaded images (no,\n"
|
|
|
803fb7 |
" checksum, signature)\n"
|
|
|
803fb7 |
" --force Download image even if already exists\n"
|
|
|
803fb7 |
- " --dkr-index-url=URL Specify the index URL to use for DKR image\n"
|
|
|
803fb7 |
- " downloads\n\n"
|
|
|
803fb7 |
"Machine Commands:\n"
|
|
|
803fb7 |
" list List running VMs and containers\n"
|
|
|
803fb7 |
" status NAME... Show VM/container details\n"
|
|
|
803fb7 |
@@ -2265,7 +2190,6 @@ static int help(int argc, char *argv[], void *userdata) {
|
|
|
803fb7 |
"Image Transfer Commands:\n"
|
|
|
803fb7 |
" pull-tar URL [NAME] Download a TAR container image\n"
|
|
|
803fb7 |
" pull-raw URL [NAME] Download a RAW container or VM image\n"
|
|
|
803fb7 |
- " pull-dkr REMOTE [NAME] Download a DKR container image\n"
|
|
|
803fb7 |
" list-transfers Show list of downloads in progress\n"
|
|
|
803fb7 |
" cancel-transfer Cancel a download\n"
|
|
|
803fb7 |
, program_invocation_short_name);
|
|
|
803fb7 |
@@ -2284,8 +2208,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|
|
803fb7 |
ARG_MKDIR,
|
|
|
803fb7 |
ARG_NO_ASK_PASSWORD,
|
|
|
803fb7 |
ARG_VERIFY,
|
|
|
803fb7 |
- ARG_FORCE,
|
|
|
803fb7 |
- ARG_DKR_INDEX_URL,
|
|
|
803fb7 |
+ ARG_FORCE
|
|
|
803fb7 |
};
|
|
|
803fb7 |
|
|
|
803fb7 |
static const struct option options[] = {
|
|
|
803fb7 |
@@ -2308,7 +2231,6 @@ static int parse_argv(int argc, char *argv[]) {
|
|
|
803fb7 |
{ "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
|
|
|
803fb7 |
{ "verify", required_argument, NULL, ARG_VERIFY },
|
|
|
803fb7 |
{ "force", no_argument, NULL, ARG_FORCE },
|
|
|
803fb7 |
- { "dkr-index-url", required_argument, NULL, ARG_DKR_INDEX_URL },
|
|
|
803fb7 |
{}
|
|
|
803fb7 |
};
|
|
|
803fb7 |
|
|
|
803fb7 |
@@ -2421,15 +2343,6 @@ static int parse_argv(int argc, char *argv[]) {
|
|
|
803fb7 |
arg_force = true;
|
|
|
803fb7 |
break;
|
|
|
803fb7 |
|
|
|
803fb7 |
- case ARG_DKR_INDEX_URL:
|
|
|
803fb7 |
- if (!http_url_is_valid(optarg)) {
|
|
|
803fb7 |
- log_error("Index URL is invalid: %s", optarg);
|
|
|
803fb7 |
- return -EINVAL;
|
|
|
803fb7 |
- }
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- arg_dkr_index_url = optarg;
|
|
|
803fb7 |
- break;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
case '?':
|
|
|
803fb7 |
return -EINVAL;
|
|
|
803fb7 |
|
|
|
803fb7 |
@@ -2467,7 +2380,6 @@ static int machinectl_main(int argc, char *argv[], sd_bus *bus) {
|
|
|
803fb7 |
{ "disable", 2, VERB_ANY, 0, enable_machine },
|
|
|
803fb7 |
{ "pull-tar", 2, 3, 0, pull_tar },
|
|
|
803fb7 |
{ "pull-raw", 2, 3, 0, pull_raw },
|
|
|
803fb7 |
- { "pull-dkr", 2, 3, 0, pull_dkr },
|
|
|
803fb7 |
{ "list-transfers", VERB_ANY, 1, 0, list_transfers },
|
|
|
803fb7 |
{ "cancel-transfer", 2, VERB_ANY, 0, cancel_transfer },
|
|
|
803fb7 |
{}
|
|
|
803fb7 |
diff --git a/src/shared/import-util.c b/src/shared/import-util.c
|
|
|
803fb7 |
index 660d92ac5..c0aba30a9 100644
|
|
|
803fb7 |
--- a/src/shared/import-util.c
|
|
|
803fb7 |
+++ b/src/shared/import-util.c
|
|
|
803fb7 |
@@ -149,34 +149,3 @@ int raw_strip_suffixes(const char *p, char **ret) {
|
|
|
803fb7 |
|
|
|
803fb7 |
return 0;
|
|
|
803fb7 |
}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-bool dkr_name_is_valid(const char *name) {
|
|
|
803fb7 |
- const char *slash, *p;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (isempty(name))
|
|
|
803fb7 |
- return false;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- slash = strchr(name, '/');
|
|
|
803fb7 |
- if (!slash)
|
|
|
803fb7 |
- return false;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!filename_is_valid(slash + 1))
|
|
|
803fb7 |
- return false;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- p = strndupa(name, slash - name);
|
|
|
803fb7 |
- if (!filename_is_valid(p))
|
|
|
803fb7 |
- return false;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return true;
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-bool dkr_id_is_valid(const char *id) {
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!filename_is_valid(id))
|
|
|
803fb7 |
- return false;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- if (!in_charset(id, "0123456789abcdef"))
|
|
|
803fb7 |
- return false;
|
|
|
803fb7 |
-
|
|
|
803fb7 |
- return true;
|
|
|
803fb7 |
-}
|
|
|
803fb7 |
diff --git a/src/shared/import-util.h b/src/shared/import-util.h
|
|
|
803fb7 |
index ff155b0ff..22773c58e 100644
|
|
|
803fb7 |
--- a/src/shared/import-util.h
|
|
|
803fb7 |
+++ b/src/shared/import-util.h
|
|
|
803fb7 |
@@ -41,7 +41,3 @@ ImportVerify import_verify_from_string(const char *s) _pure_;
|
|
|
803fb7 |
|
|
|
803fb7 |
int tar_strip_suffixes(const char *name, char **ret);
|
|
|
803fb7 |
int raw_strip_suffixes(const char *name, char **ret);
|
|
|
803fb7 |
-
|
|
|
803fb7 |
-bool dkr_name_is_valid(const char *name);
|
|
|
803fb7 |
-bool dkr_id_is_valid(const char *id);
|
|
|
803fb7 |
-#define dkr_tag_is_valid(tag) filename_is_valid(tag)
|