From patchwork Thu Apr 12 15:07:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10338893 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 32F32602D8 for ; Thu, 12 Apr 2018 15:26:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26EF31FE82 for ; Thu, 12 Apr 2018 15:26:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BBEC2000A; Thu, 12 Apr 2018 15:26:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EA641FE82 for ; Thu, 12 Apr 2018 15:26:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753768AbeDLP0S (ORCPT ); Thu, 12 Apr 2018 11:26:18 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:52951 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752824AbeDLPIe (ORCPT ); Thu, 12 Apr 2018 11:08:34 -0400 Received: by mail-wm0-f67.google.com with SMTP id g8so12314613wmd.2 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=b7P/B6ro6kjCRSVX6+Guqd0ORVRYyd0DeTCUv3JBKprMAKBAhSZH1235VQBiUIE/KE R4GlrInERvicZwHwW6kl/4hcZgWufhCXY3me/lvH9oVZSM4KyyMskVeUQwo4qtYUFYPL /KYxrFbrv4UMBXNqVPLgi6c63iuoMf8qLQTffmP7Jx7UB6SkZDzYhq/WtmaWPJTpt+qN 4hqLl95Lwr8R0GnKZ/Va3TYCNIAmX+cWbXObLnhI20m/16Hzu3Qhr3PVJO79nsMUVyAW GYKCXLgs+myf+aBzjRJmN7pnDfEgMO8qW9a/pVCgzgeqQlRx9c7Dy51lwg24Vwmm0BV8 b1Ng== X-Gm-Message-State: ALQs6tB8GvQN82Gt0+dRoTd8NdfFkuSrS6WiPViYX4zF0IFAQzof/saP j71LKD9VVsswD8FZWPtVLAJ+ZzYWEuY= X-Google-Smtp-Source: AIpwx49GsFr965hEg4zuWysRTyutDsbK5Jo+vtIssd8vh21ZTEXDYchTpbBbH32g38wv8lOijWkVPQ== 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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);