From patchwork Thu Jan 30 00:27:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Heift X-Patchwork-Id: 3555441 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 77B6A9F2E9 for ; Thu, 30 Jan 2014 00:28:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A9E88201B9 for ; Thu, 30 Jan 2014 00:28:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D03C52018E for ; Thu, 30 Jan 2014 00:28:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751487AbaA3A2R (ORCPT ); Wed, 29 Jan 2014 19:28:17 -0500 Received: from mail-ee0-f47.google.com ([74.125.83.47]:61984 "EHLO mail-ee0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752258AbaA3A1w (ORCPT ); Wed, 29 Jan 2014 19:27:52 -0500 Received: by mail-ee0-f47.google.com with SMTP id d49so1253631eek.34 for ; Wed, 29 Jan 2014 16:27:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=jQNe4vCNOvQCiweB7qbVrwUrZGWf/B14xdM2EmgpogA=; b=dK8tFEzh5pO4ZetgQnx6mQSvX21ObdnFX3mgZrCbkII7KUeLRSE4Xk/E7IDIoRLwG4 4H2YPw0/207oqyQGI6TM4pTCGLaupmhWMIutQQV+VsfjlKQ/Imx2pZRWCjULrzjrzkLh lnf63O1uEij9Q+2uljg40IrXzu6an51cEk0Czae6CJxL/pue9hpGHp8zB07IWTVcNOIH qymlIM3kC9VW8OM+44vxXwG26P4a88rXM+9x0E7hDrt9yQOM1hHvmVGeyVwo4AwjFWvb V4eSlhHoeDtaJUVj6paV4wLhxe86vIeSaB8TP83CQY9YZjogHCr3G/UKwpRUmXcfKicI 1LGg== X-Gm-Message-State: ALoCoQnCKn4t48+j+blKhJhPS84L+qJzmUCrUxomxRNn/2z5ivz9K5nnZt78Yi7Ic0ugGDlMyMyL X-Received: by 10.14.32.132 with SMTP id o4mr13254343eea.14.1391041671847; Wed, 29 Jan 2014 16:27:51 -0800 (PST) Received: from localhost (host-115-115.kawo1.rwth-aachen.de. [134.130.115.115]) by mx.google.com with ESMTPSA id n7sm15309674eef.5.2014.01.29.16.27.50 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 29 Jan 2014 16:27:51 -0800 (PST) From: Gerhard Heift To: linux-btrfs@vger.kernel.org Subject: [PATCH RFCv3 4/6] btrfs: new function read_extent_buffer_to_user Date: Thu, 30 Jan 2014 01:27:29 +0100 Message-Id: <1391041651-15689-5-git-send-email-Gerhard@Heift.Name> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1391041651-15689-1-git-send-email-Gerhard@Heift.Name> References: <1391041651-15689-1-git-send-email-Gerhard@Heift.Name> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 This new function reads the content of an extent directly to user memory. Signed-off-by: Gerhard Heift --- fs/btrfs/extent_io.c | 37 +++++++++++++++++++++++++++++++++++++ fs/btrfs/extent_io.h | 3 +++ 2 files changed, 40 insertions(+) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index fbe501d..d1e9dd8 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -4956,6 +4956,43 @@ void read_extent_buffer(struct extent_buffer *eb, void *dstv, } } +int read_extent_buffer_to_user(struct extent_buffer *eb, void __user *dstv, + unsigned long start, + unsigned long len) +{ + size_t cur; + size_t offset; + struct page *page; + char *kaddr; + char __user *dst = (char __user *)dstv; + size_t start_offset = eb->start & ((u64)PAGE_CACHE_SIZE - 1); + unsigned long i = (start_offset + start) >> PAGE_CACHE_SHIFT; + int ret = 0; + + WARN_ON(start > eb->len); + WARN_ON(start + len > eb->start + eb->len); + + offset = (start_offset + start) & (PAGE_CACHE_SIZE - 1); + + while (len > 0) { + page = extent_buffer_page(eb, i); + + cur = min(len, (PAGE_CACHE_SIZE - offset)); + kaddr = page_address(page); + if (copy_to_user(dst, kaddr + offset, cur)) { + ret = -EFAULT; + break; + } + + dst += cur; + len -= cur; + offset = 0; + i++; + } + + return ret; +} + int map_private_extent_buffer(struct extent_buffer *eb, unsigned long start, unsigned long min_len, char **map, unsigned long *map_start, diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 58b27e5..d0b1541 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -304,6 +304,9 @@ int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv, void read_extent_buffer(struct extent_buffer *eb, void *dst, unsigned long start, unsigned long len); +int read_extent_buffer_to_user(struct extent_buffer *eb, void __user *dst, + unsigned long start, + unsigned long len); void write_extent_buffer(struct extent_buffer *eb, const void *src, unsigned long start, unsigned long len); void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,