From patchwork Mon Oct 6 19:11:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 38379 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F00CB20350 for ; Mon, 6 Oct 2014 19:12:36 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id ge10sf3190220lab.1 for ; Mon, 06 Oct 2014 12:12:35 -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=TygSRfxzhcyEqFIdpYY7gIfPi7e1EATCfgACWb2bbkAbf8tZSdrWQefu9607tP/RPl UG/y1i+mvg1/sqYzT2oGXZPQlnBYL8uUSyO+Q4sNtKRIlLbrv0CK/pMjnp6FHIrZFElZ 4ZwalwOSV3KWANCj8b1XkoH56P8UlotvH1NufFSpZKZlzEpQuU9FR5W81cbZWCNeRSQI GMaYqo/YrXGYu4WVOAywhgc0O+E4TGCSLqb+xiPztjCn6ataxVmyZm06szwTdZ3CMrV4 ZBblW55iJ2OD8bW3Va+7clWi9LFfQClN5I5lllr8x2/D8Tm2qch2Ddio+9WMA6pdzaHe t/Rg== X-Gm-Message-State: ALoCoQkELka4dBI07TOKGttYQJqtsENuWkMjFkd7HWgf1mxkWLYY88D2cO83dsgjWlC8MXrkyKHo X-Received: by 10.112.60.225 with SMTP id k1mr1073700lbr.0.1412622755440; Mon, 06 Oct 2014 12:12:35 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.132 with SMTP id y4ls160233laj.73.gmail; Mon, 06 Oct 2014 12:12:35 -0700 (PDT) X-Received: by 10.112.26.103 with SMTP id k7mr5366696lbg.86.1412622755300; Mon, 06 Oct 2014 12:12:35 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com [209.85.215.44]) by mx.google.com with ESMTPS id z3si922632lad.17.2014.10.06.12.12.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 06 Oct 2014 12:12:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id gb8so5020129lab.31 for ; Mon, 06 Oct 2014 12:12:34 -0700 (PDT) X-Received: by 10.112.50.10 with SMTP id y10mr24903238lbn.0.1412622754512; Mon, 06 Oct 2014 12:12:34 -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 of9csp239696lbb; Mon, 6 Oct 2014 12:12:33 -0700 (PDT) X-Received: by 10.140.82.230 with SMTP id h93mr30461206qgd.44.1412622753165; Mon, 06 Oct 2014 12:12:33 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k9si25800477qch.25.2014.10.06.12.12.32 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 06 Oct 2014 12:12:33 -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]:53842 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbDhw-0002p2-2z for patch@linaro.org; Mon, 06 Oct 2014 15:12:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57406) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbDgv-00024i-RN for qemu-devel@nongnu.org; Mon, 06 Oct 2014 15:11:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XbDgr-0007c7-DE for qemu-devel@nongnu.org; Mon, 06 Oct 2014 15:11:29 -0400 Received: from afflict.kos.to ([92.243.29.197]:33861) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbDgr-0007bC-34 for qemu-devel@nongnu.org; Mon, 06 Oct 2014 15:11:25 -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 23A5B26511; Mon, 6 Oct 2014 21:11:24 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 6 Oct 2014 22:11:20 +0300 Message-Id: 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 v2 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.44 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 */