From patchwork Mon Oct 6 14:34:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 38373 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 26089202E7 for ; Mon, 6 Oct 2014 14:37:48 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id b13sf2844187wgh.0 for ; Mon, 06 Oct 2014 07:37:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=XcAM1c+8CAiTWOoDBNUbZPwlDp5lvUfGu7k1sWpxDgo=; b=D17hxJ0Gvz8E+8r83qeeq0h3kmKLEDKuVz9DmSmjbLIzvCYDqtiz+XyPAQeLww/fNH eJfXy4evtQ7pVWeZ9+MJa1G9bg1t/HJQROOK4OSBzeOIqm5jeUuOkBNK9YbL0hiFGN// JC5rT/zINalgpQG4PnDr7D8n5P9xEkx/B1KkRCs9vM+KvDYopJ67DZMIAWP4odmuS87E HLv0IY3eLsPneUQJ3Funk7JFhgAhxmKVYmt59Dx+5GeHLhsjB7X8lAyj+AMipBmfI19O SiIru+xhQaIAurRE0nVpJvkt1i3xFlKA06R2v7Y6APZfzwFkkspssbwUOO1wETCS0/R3 lIVw== X-Gm-Message-State: ALoCoQlc9r46Mb2e81CFn9MjMHT9H1t70+CAO7AKfi/0wL2M22+IBc5EA5Ydx91rD9vr79pniXVt X-Received: by 10.194.249.134 with SMTP id yu6mr3825282wjc.1.1412606266792; Mon, 06 Oct 2014 07:37:46 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.72 with SMTP id lm8ls577161lac.9.gmail; Mon, 06 Oct 2014 07:37:46 -0700 (PDT) X-Received: by 10.153.7.134 with SMTP id dc6mr25935610lad.9.1412606266585; Mon, 06 Oct 2014 07:37:46 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com [209.85.215.47]) by mx.google.com with ESMTPS id ki4si24299134lbc.45.2014.10.06.07.37.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 06 Oct 2014 07:37:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id pv20so4434970lab.20 for ; Mon, 06 Oct 2014 07:37:46 -0700 (PDT) X-Received: by 10.152.19.195 with SMTP id h3mr4261887lae.71.1412606266403; Mon, 06 Oct 2014 07:37:46 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.130.169 with SMTP id of9csp194018lbb; Mon, 6 Oct 2014 07:37:45 -0700 (PDT) X-Received: by 10.224.165.1 with SMTP id g1mr3901689qay.97.1412606265209; Mon, 06 Oct 2014 07:37:45 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id il7si10721159qab.73.2014.10.06.07.37.44 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 06 Oct 2014 07:37:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:52256 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xb9Q0-0002fE-0b for patch@linaro.org; Mon, 06 Oct 2014 10:37:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xb9Mr-0006dw-AP for qemu-devel@nongnu.org; Mon, 06 Oct 2014 10:34:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xb9Mk-0006MN-VE for qemu-devel@nongnu.org; Mon, 06 Oct 2014 10:34:29 -0400 Received: from afflict.kos.to ([92.243.29.197]:33721) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xb9Mk-0006LK-L9 for qemu-devel@nongnu.org; Mon, 06 Oct 2014 10:34:22 -0400 Received: from afflict.kos.to (afflict [92.243.29.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 720D626511; Mon, 6 Oct 2014 16:34:20 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 6 Oct 2014 17:34:16 +0300 Message-Id: <74a6623b590e5905fe21c65753dcbdb1e8c0b17e.1412604632.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 92.243.29.197 Cc: Alexander Graf Subject: [Qemu-devel] [PULL 2/5] linux-user: Convert blkpg to use a special subop handler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Alexander Graf The blkpg ioctl can take different payloads depending on the opcode in its payload structure. Create a new special ioctl handler that can only deal with partition style ones for now. This patch fixes running parted for me. Signed-off-by: Alexander Graf Signed-off-by: Riku Voipio --- linux-user/ioctls.h | 3 ++- linux-user/syscall.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ linux-user/syscall_types.h | 2 +- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h index 609b27c..e672655 100644 --- a/linux-user/ioctls.h +++ b/linux-user/ioctls.h @@ -78,7 +78,8 @@ IOCTL(BLKRAGET, IOC_R, MK_PTR(TYPE_LONG)) IOCTL(BLKSSZGET, IOC_R, MK_PTR(TYPE_LONG)) IOCTL(BLKBSZGET, IOC_R, MK_PTR(TYPE_INT)) - IOCTL(BLKPG, IOC_W, MK_PTR(MK_STRUCT(STRUCT_blkpg_ioctl_arg))) + IOCTL_SPECIAL(BLKPG, IOC_W, do_ioctl_blkpg, + MK_PTR(MK_STRUCT(STRUCT_blkpg_ioctl_arg))) #ifdef FIBMAP IOCTL(FIBMAP, IOC_W | IOC_R, MK_PTR(TYPE_LONG)) #endif diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8fe9df7..dcb9df9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3696,6 +3696,59 @@ out: return ret; } +static abi_long do_ioctl_blkpg(const IOCTLEntry *ie, uint8_t *buf_temp, int fd, + abi_long cmd, abi_long arg) +{ + void *argptr; + int target_size; + const argtype *arg_type = ie->arg_type; + const argtype part_arg_type[] = { MK_STRUCT(STRUCT_blkpg_partition) }; + abi_long ret; + + struct blkpg_ioctl_arg *host_blkpg = (void*)buf_temp; + struct blkpg_partition host_part; + + /* Read and convert blkpg */ + arg_type++; + target_size = thunk_type_size(arg_type, 0); + argptr = lock_user(VERIFY_READ, arg, target_size, 1); + if (!argptr) { + ret = -TARGET_EFAULT; + goto out; + } + thunk_convert(buf_temp, argptr, arg_type, THUNK_HOST); + unlock_user(argptr, arg, 0); + + switch (host_blkpg->op) { + case BLKPG_ADD_PARTITION: + case BLKPG_DEL_PARTITION: + /* payload is struct blkpg_partition */ + break; + default: + /* Unknown opcode */ + ret = -TARGET_EINVAL; + goto out; + } + + /* Read and convert blkpg->data */ + arg = (abi_long)(uintptr_t)host_blkpg->data; + target_size = thunk_type_size(part_arg_type, 0); + argptr = lock_user(VERIFY_READ, arg, target_size, 1); + if (!argptr) { + ret = -TARGET_EFAULT; + goto out; + } + thunk_convert(&host_part, argptr, part_arg_type, THUNK_HOST); + unlock_user(argptr, arg, 0); + + /* Swizzle the data pointer to our local copy and call! */ + host_blkpg->data = &host_part; + ret = get_errno(ioctl(fd, ie->host_cmd, host_blkpg)); + +out: + return ret; +} + static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp, int fd, abi_long cmd, abi_long arg) { diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h index 9d0c92d..1fd4ee0 100644 --- a/linux-user/syscall_types.h +++ b/linux-user/syscall_types.h @@ -252,4 +252,4 @@ STRUCT(blkpg_ioctl_arg, TYPE_INT, /* op */ TYPE_INT, /* flags */ TYPE_INT, /* datalen */ - MK_PTR(MK_STRUCT(STRUCT_blkpg_partition))) /* data */ + TYPE_PTRVOID) /* data */