From patchwork Mon Oct 19 10:59:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 7435081 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 875C4BEEA4 for ; Mon, 19 Oct 2015 11:03:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A500C2070B for ; Mon, 19 Oct 2015 11:03:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E04120700 for ; Mon, 19 Oct 2015 11:03:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751424AbbJSLDN (ORCPT ); Mon, 19 Oct 2015 07:03:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36361 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752259AbbJSLDN (ORCPT ); Mon, 19 Oct 2015 07:03:13 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id ED6D3319AE8; Mon, 19 Oct 2015 11:03:12 +0000 (UTC) Received: from tranklukator.brq.redhat.com (dhcp-1-102.brq.redhat.com [10.34.1.102]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id t9JB3A07011075; Mon, 19 Oct 2015 07:03:11 -0400 Received: by tranklukator.brq.redhat.com (nbSMTP-1.00) for uid 500 oleg@redhat.com; Mon, 19 Oct 2015 12:59:44 +0200 (CEST) Date: Mon, 19 Oct 2015 12:59:42 +0200 From: Oleg Nesterov To: Andre Przywara , Dimitri Ledkov , Ingo Molnar , Pekka Enberg , Will Deacon Cc: kvm@vger.kernel.org Subject: [PATCH 1/3] kvmtool/setup: Introduce extract_file() helper Message-ID: <20151019105942.GA12425@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20151019105930.GA12411@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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 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 --- 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)