From patchwork Thu Jan 30 15:24:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Heift X-Patchwork-Id: 3557821 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BED15C02DC for ; Thu, 30 Jan 2014 15:24:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 288D32016C for ; Thu, 30 Jan 2014 15:24:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0DB8A201C0 for ; Thu, 30 Jan 2014 15:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753540AbaA3PYX (ORCPT ); Thu, 30 Jan 2014 10:24:23 -0500 Received: from mail-ea0-f170.google.com ([209.85.215.170]:52399 "EHLO mail-ea0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753430AbaA3PYU (ORCPT ); Thu, 30 Jan 2014 10:24:20 -0500 Received: by mail-ea0-f170.google.com with SMTP id k10so1721380eaj.15 for ; Thu, 30 Jan 2014 07:24:19 -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=hkIJzW7P0SFKpuiBDNQd51/IowImaXZbooAPg8wUKUo9xHyIdHb8K6pYtq1okDvyS9 rLViU5xdt+Yh2c3KlifhE+qkntD+9P04gncfKPyLKSQ7CgrZQjVRQou53Gs+JGFRbM3V UyJDhss6U0zgPB/66GqIn/8bKatmeuTO6ihztjT20gbu14RCaEDc6sknv6KLw1cRexS6 Ev3mKCHwqEinlN9LNakgDmfNB/QzBmN7xW+mHvQTlkiJhugTnVUiN4FcZUde9FcWZPtc zIw+wLi85r8gTmTBHTAPF0ml6FrSfDPArhumnlMQlceAFLW3Y3KKynPiqyKZOgDXrQyK S1uw== X-Gm-Message-State: ALoCoQmwSswKGZ/UQVAPWlOv+ZG6VdpNOzThEBaZvLZXPBXzNNklrx0Cy4KjAeyd52QxqDmMrZjq X-Received: by 10.14.207.194 with SMTP id n42mr3093185eeo.76.1391095459680; Thu, 30 Jan 2014 07:24:19 -0800 (PST) Received: from localhost (host-115-115.kawo1.rwth-aachen.de. [134.130.115.115]) by mx.google.com with ESMTPSA id u7sm23679987eep.11.2014.01.30.07.24.18 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 30 Jan 2014 07:24:19 -0800 (PST) From: Gerhard Heift To: linux-btrfs@vger.kernel.org Subject: [PATCH RFCv4 5/7] btrfs: new function read_extent_buffer_to_user Date: Thu, 30 Jan 2014 16:24:01 +0100 Message-Id: <1391095443-20287-6-git-send-email-Gerhard@Heift.Name> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1391095443-20287-1-git-send-email-Gerhard@Heift.Name> References: <1391095443-20287-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.3 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,