Received: by 10.192.165.156 with SMTP id m28csp2094909imm; Thu, 12 Apr 2018 08:31:37 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/V1DdHnqUXVhuRQsgwtriN1vVhvvEno5BDaE9Fy5LstQBzCPeOx7TMVHusXsqUy9I6p01H X-Received: by 2002:a17:902:728f:: with SMTP id d15-v6mr1581890pll.119.1523547097438; Thu, 12 Apr 2018 08:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523547097; cv=none; d=google.com; s=arc-20160816; b=mKZoPXWCRwTl3yrqJuMGRcEEKcukTu42FR4AAQb20zUpFwkDP3RIn5jV1ldSRO1I12 MP7vWInAQR+izIKw5UPCBGmNz+PAKgy2cqJX1ImvIAQo7Mx/dDQJ1PExe/8UypQA1Z6o OD86JxVGfDjiCSDicMEnRyMpLdN9QVrvS9RKHq1S8Fa9NWRWdHETTZCJHNeoIv97/zlA YaSEMyakGakKNM5GSP3HQyH1qAeMaZFhM5CQNPPdoGeR9seLlfQqdHnC9FL9Iy26g9dh +GIMWKYxbbFpwgcDwM7Stlw25Wfsjf7B8Uz6ufDtZGVFb4sWxyPKkOVqRB532ZJ4Qr/0 8gWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=C6Cth3TueQftiEAcu7wKPojAwNrHlzscT8t0UTbEbZw=; b=RdKXWCcP8qGZ5ThOmrJT+0f8oSCDqU9bUCMIn1+cQmcy/IcoOdBSeEmPgIEvtls1WI C7ydERlRfCDfnwt1m1b90AXLJtuu+h1uvhvFvV/iKmmcDmLyvC6JNI4xwD9A3H8z9Xox bvtguTHNPLIOsToJ0giF+EofYYhsb5/5sDRCtCpHUdEge5zvNRjL01P9Dt0dX9uxb9pM HZoG3FnGqAkQ3JNY51TCtb6NA0ON3d3LSv5YXYRtfFeHm/ifcuvwrARUYmpo5nQptxqH qK3bMcwBxv2oO++6Q30FkwM3nY0q+8lYrg3mypwPsGuIRGdvC9z+5pGvSmxDvA9N22P1 i2fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64si2451510pgj.169.2018.04.12.08.31.00; Thu, 12 Apr 2018 08:31:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753320AbeDLP0X (ORCPT + 99 others); Thu, 12 Apr 2018 11:26:23 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:34525 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752820AbeDLPIe (ORCPT ); Thu, 12 Apr 2018 11:08:34 -0400 Received: by mail-wm0-f65.google.com with SMTP id w2so3550817wmw.1 for ; Thu, 12 Apr 2018 08:08:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=C6Cth3TueQftiEAcu7wKPojAwNrHlzscT8t0UTbEbZw=; b=bsQLxrYR6trVKHL29qaXwC4NQ9qGlNCXTBYD3IsD1nUIl6dNOKbrRYSkbTKHNPLkK+ dJsKe3ygqgaLmbH9onjIPVKAMZoWvosWmXW6ZNQBNBSgk0Q8g3zIkmvaqEbzUSuA67x2 E/ah0uDlRjTuhvbU5JZIapRYtjrZ2xObAeUFyCr59Bg0bEQVEsIsdGg8g28VAq+CJ52Z 6Rg85ny/muLBwRNBmBLGazgMJ8nXIi6isiC1wclb3H9n224rDqyVL1N9CXy7FuUhupYs MgWFFY1RYd82IAcD7pQqcAHovXFkdO9gAMb7gk1MN33Wrdlp/Qf0oObaaj6HCnHVaY0e 5PMw== X-Gm-Message-State: ALQs6tAGDS/hRWqUG+9oJE0MaDVNaMOLhLQnhrW7rBV3eZGyrrsSAE2r AwKnE2CAul4CuxZ6B8hvJvNM4g== X-Received: by 10.28.54.154 with SMTP id y26mr1005076wmh.102.1523545712953; Thu, 12 Apr 2018 08:08:32 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (catv-176-63-54-97.catv.broadband.hu. [176.63.54.97]) by smtp.gmail.com with ESMTPSA id p197sm2621783wme.43.2018.04.12.08.08.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Apr 2018 08:08:32 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 01/35] vfs: clean up dedup Date: Thu, 12 Apr 2018 17:07:52 +0200 Message-Id: <20180412150826.20988-2-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180412150826.20988-1-mszeredi@redhat.com> References: <20180412150826.20988-1-mszeredi@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Extract vfs_dedupe_file_range_one() helper to deal with a single dedup request. Export this helper to modules, so it can be used by overlayfs to stack the dedupe method. Signed-off-by: Miklos Szeredi --- fs/read_write.c | 90 ++++++++++++++++++++++++++++++------------------------ include/linux/fs.h | 3 ++ 2 files changed, 53 insertions(+), 40 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index f8547b82dfb3..82aa0d32d0cd 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1937,6 +1937,44 @@ int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, } EXPORT_SYMBOL(vfs_dedupe_file_range_compare); +ssize_t vfs_dedupe_file_range_one(struct file *src_file, u64 src_pos, u64 len, + struct file *dst_file, u64 dst_pos) +{ + ssize_t ret; + + ret = mnt_want_write_file(dst_file); + if (ret) + return ret; + + ret = clone_verify_area(dst_file, dst_pos, len, true); + if (ret < 0) + goto out_drop_write; + + ret = -EINVAL; + if (!(capable(CAP_SYS_ADMIN) || (dst_file->f_mode & FMODE_WRITE))) + goto out_drop_write; + + ret = -EXDEV; + if (src_file->f_path.mnt != dst_file->f_path.mnt) + goto out_drop_write; + + ret = -EISDIR; + if (S_ISDIR(file_inode(dst_file)->i_mode)) + goto out_drop_write; + + ret = -EINVAL; + if (!dst_file->f_op->dedupe_file_range) + goto out_drop_write; + + ret = dst_file->f_op->dedupe_file_range(src_file, src_pos, len, + dst_file, dst_pos); +out_drop_write: + mnt_drop_write_file(dst_file); + + return ret; +} +EXPORT_SYMBOL(vfs_dedupe_file_range_one); + int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) { struct file_dedupe_range_info *info; @@ -1945,10 +1983,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) u64 len; int i; int ret; - bool is_admin = capable(CAP_SYS_ADMIN); u16 count = same->dest_count; - struct file *dst_file; - loff_t dst_off; ssize_t deduped; if (!(file->f_mode & FMODE_READ)) @@ -1983,54 +2018,29 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) } for (i = 0, info = same->info; i < count; i++, info++) { - struct inode *dst; struct fd dst_fd = fdget(info->dest_fd); + struct file *dst_file = dst_fd.file; - dst_file = dst_fd.file; if (!dst_file) { info->status = -EBADF; goto next_loop; } - dst = file_inode(dst_file); - - ret = mnt_want_write_file(dst_file); - if (ret) { - info->status = ret; - goto next_loop; - } - - dst_off = info->dest_offset; - ret = clone_verify_area(dst_file, dst_off, len, true); - if (ret < 0) { - info->status = ret; - goto next_file; - } - ret = 0; if (info->reserved) { info->status = -EINVAL; - } else if (!(is_admin || (dst_file->f_mode & FMODE_WRITE))) { - info->status = -EINVAL; - } else if (file->f_path.mnt != dst_file->f_path.mnt) { - info->status = -EXDEV; - } else if (S_ISDIR(dst->i_mode)) { - info->status = -EISDIR; - } else if (dst_file->f_op->dedupe_file_range == NULL) { - info->status = -EINVAL; - } else { - deduped = dst_file->f_op->dedupe_file_range(file, off, - len, dst_file, - info->dest_offset); - if (deduped == -EBADE) - info->status = FILE_DEDUPE_RANGE_DIFFERS; - else if (deduped < 0) - info->status = deduped; - else - info->bytes_deduped += deduped; + goto next_loop; } -next_file: - mnt_drop_write_file(dst_file); + deduped = vfs_dedupe_file_range_one(file, off, len, + dst_file, + info->dest_offset); + if (deduped == -EBADE) + info->status = FILE_DEDUPE_RANGE_DIFFERS; + else if (deduped < 0) + info->status = deduped; + else + info->bytes_deduped += deduped; + next_loop: fdput(dst_fd); diff --git a/include/linux/fs.h b/include/linux/fs.h index c6baf767619e..f0f87f2beb79 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1809,6 +1809,9 @@ extern int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, loff_t len, bool *is_same); extern int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same); +extern ssize_t vfs_dedupe_file_range_one(struct file *src_file, u64 src_pos, + u64 len, struct file *dst_file, + u64 dst_pos); struct super_operations { struct inode *(*alloc_inode)(struct super_block *sb); -- 2.14.3