From patchwork Thu Oct 22 15:59:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 7465721 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1FA43BF90C for ; Thu, 22 Oct 2015 16:03:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5B18620649 for ; Thu, 22 Oct 2015 16:03:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C1B120658 for ; Thu, 22 Oct 2015 16:03:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965267AbbJVQDU (ORCPT ); Thu, 22 Oct 2015 12:03:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36822 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752250AbbJVQDT (ORCPT ); Thu, 22 Oct 2015 12:03:19 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 5C2DE228; Thu, 22 Oct 2015 16:03:19 +0000 (UTC) Received: from tranklukator.brq.redhat.com (dhcp-1-102.brq.redhat.com [10.34.1.102]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id t9MG3Hni001317; Thu, 22 Oct 2015 12:03:17 -0400 Received: by tranklukator.brq.redhat.com (nbSMTP-1.00) for uid 500 oleg@redhat.com; Thu, 22 Oct 2015 17:59:47 +0200 (CEST) Date: Thu, 22 Oct 2015 17:59:45 +0200 From: Oleg Nesterov To: Andre Przywara , Aneesh Kumar , Sasha Levin , Pekka Enberg , Will Deacon Cc: kvm@vger.kernel.org Subject: [PATCH 3/3] kvmtool/run: do not overwrite /virt/init Message-ID: <20151022155945.GA15555@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20151022155921.GA15527@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);