From: Oleg Nesterov <oleg@redhat.com>
To: Andre Przywara <andre.przywara@arm.com>,
Dimitri Ledkov <dimitri.j.ledkov@intel.com>,
Ingo Molnar <mingo@kernel.org>, Pekka Enberg <penberg@kernel.org>,
Will Deacon <will.deacon@arm.com>
Cc: kvm@vger.kernel.org
Subject: [PATCH 1/3] kvmtool/setup: Introduce extract_file() helper
Date: Mon, 19 Oct 2015 12:59:42 +0200 [thread overview]
Message-ID: <20151019105942.GA12425@redhat.com> (raw)
In-Reply-To: <20151019105930.GA12411@redhat.com>
Turn kvm_setup_guest_init(guestfs_name) into a more generic helper,
extract_file(guestfs_name, filename, data, size) and reimplement
kvm_setup_guest_init() as a trivial wrapper.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
builtin-setup.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/builtin-setup.c b/builtin-setup.c
index 40fef15..bb7c71c 100644
--- a/builtin-setup.c
+++ b/builtin-setup.c
@@ -122,30 +122,34 @@ static const char *guestfs_symlinks[] = {
};
#ifdef CONFIG_GUEST_INIT
-extern char _binary_guest_init_start;
-extern char _binary_guest_init_size;
-
-int kvm_setup_guest_init(const char *guestfs_name)
+static int extract_file(const char *guestfs_name, const char *filename,
+ const void *data, const void *_size)
{
char path[PATH_MAX];
- size_t size;
int fd, ret;
- char *data;
- size = (size_t)&_binary_guest_init_size;
- data = (char *)&_binary_guest_init_start;
- snprintf(path, PATH_MAX, "%s%s/virt/init", kvm__get_dir(), guestfs_name);
+ snprintf(path, PATH_MAX, "%s%s/%s", kvm__get_dir(),
+ guestfs_name, filename);
remove(path);
fd = open(path, O_CREAT | O_WRONLY, 0755);
if (fd < 0)
die("Fail to setup %s", path);
- ret = xwrite(fd, data, size);
+ ret = xwrite(fd, data, (size_t)_size);
if (ret < 0)
die("Fail to setup %s", path);
close(fd);
return 0;
+}
+extern char _binary_guest_init_start;
+extern char _binary_guest_init_size;
+
+int kvm_setup_guest_init(const char *guestfs_name)
+{
+ return extract_file(guestfs_name, "virt/init",
+ &_binary_guest_init_start,
+ &_binary_guest_init_size);
}
#else
int kvm_setup_guest_init(const char *guestfs_name)
--
2.4.3
next prev parent reply other threads:[~2015-10-19 11:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-19 10:59 [PATCH 0/3] kvmtool: tiny init fox x86_64 Oleg Nesterov
2015-10-19 10:59 ` Oleg Nesterov [this message]
2015-10-19 10:59 ` [PATCH 2/3] kvmtool/build: introduce GUEST_PRE_INIT target Oleg Nesterov
2015-10-19 10:59 ` [PATCH 3/3] kvmtool/x86: implement guest_pre_init Oleg Nesterov
2015-10-22 7:59 ` [PATCH 0/3] kvmtool: tiny init fox x86_64 Pekka Enberg
2015-10-22 15:58 ` Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151019105942.GA12425@redhat.com \
--to=oleg@redhat.com \
--cc=andre.przywara@arm.com \
--cc=dimitri.j.ledkov@intel.com \
--cc=kvm@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=penberg@kernel.org \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).