From: Oleg Nesterov <oleg@redhat.com>
To: Andre Przywara <andre.przywara@arm.com>,
Aneesh Kumar <aneesh.kumar@linux.vnet.ibm.com>,
Sasha Levin <sasha.levin@oracle.com>,
Pekka Enberg <penberg@kernel.org>,
Will Deacon <will.deacon@arm.com>
Cc: kvm@vger.kernel.org
Subject: [PATCH 3/3] kvmtool/run: do not overwrite /virt/init
Date: Thu, 22 Oct 2015 17:59:45 +0200 [thread overview]
Message-ID: <20151022155945.GA15555@redhat.com> (raw)
In-Reply-To: <20151022155921.GA15527@redhat.com>
To me kvm_setup_guest_init() behaviour looks "obviously wrong" and
unfriendly because it always overwrites /virt/init.
kvm_setup_guest_init() is also called when we are going to use this
tree as a rootfs, and without another patch ("kvmtool/run: append
cfg.kernel_cmdline at the end of real_cmdline") the user can't use
"lkvm run -p init=my_init_path". This simply means that you can not
use a customized init unless you patch kvmtool.
Change extract_file() to do nothing if the file already exists. This
should not affect do_setup() which calls kvm_setup_guest_init() only
if make_dir(guestfs_name) creates the new/empty dir.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
builtin-setup.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/builtin-setup.c b/builtin-setup.c
index 1e5b1e4..8be8d62 100644
--- a/builtin-setup.c
+++ b/builtin-setup.c
@@ -130,10 +130,14 @@ static int extract_file(const char *guestfs_name, const char *filename,
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)
+
+ fd = open(path, O_EXCL | O_CREAT | O_WRONLY, 0755);
+ if (fd < 0) {
+ if (errno == EEXIST)
+ return 0;
die("Fail to setup %s", path);
+ }
+
ret = xwrite(fd, data, (size_t)_size);
if (ret < 0)
die("Fail to setup %s", path);
--
2.4.3
next prev parent reply other threads:[~2015-10-22 16:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-22 15:59 [PATCH 0/3] kvmtool: don't overwrite /virt/init Oleg Nesterov
2015-10-22 15:59 ` [PATCH 1/3] kvmtool: add lkvm-static to gitignore Oleg Nesterov
2015-10-22 15:59 ` [PATCH 2/3] kvmtool/run: don't abuse "root=" parameter, don't pass "rw" to v9fs_mount() Oleg Nesterov
2015-10-22 15:59 ` Oleg Nesterov [this message]
2015-10-27 17:06 ` [PATCH 0/3] kvmtool: don't overwrite /virt/init Will Deacon
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=20151022155945.GA15555@redhat.com \
--to=oleg@redhat.com \
--cc=andre.przywara@arm.com \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=penberg@kernel.org \
--cc=sasha.levin@oracle.com \
--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).