Received: by 10.192.165.148 with SMTP id m20csp2811992imm; Mon, 7 May 2018 01:22:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr2FsL6YkAz36ezUcb/BJ/vQSTdUTaZmbGcn+e2WzBUBqk9Gvlea/a13Ne4vP0ee4KY94lw X-Received: by 2002:a17:902:70c9:: with SMTP id l9-v6mr34813034plt.382.1525681354009; Mon, 07 May 2018 01:22:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525681353; cv=none; d=google.com; s=arc-20160816; b=UqYDPPzpN2uLyOBKtcdHf3ZDwwe4LHdICCUgKpmz9im0XaNDgFUELBOLq6Wodq6rTI CgRIa2xkMU92J2yWeHRoxuLmvyu5Hl8v+vWOWz5tdtuO4cOwEJs9vToSPVPGqz3wBe5N wXvSXWAFG9PoBTJmLofP/TZdyDaYwl8t/rQCaw5UjPrcGwWA+VJsZYDjRnk/u40udgnp 2zdgsVuT5NyfDCkmqV+TCIl7v4YP//ueVZdJcsxByg3Xfj+JxxzhcaWq7kI1GS3Vv7fM oHJOoOACi6+ar6AT2hx405c1lqmOGzfYMxYjI/yVv0ZbUAr1ZWyL3eVU+gU/44KEhzck 1+Bw== 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=XVgWjpdsjRB17Og1OCU0m7DYRAuDIRV8q+Iy9w/kqMg=; b=QyluUQMe9ygMEEFfF2MEOVANjkap127XWKGawthMtMYrRbpZe7ySpm6oawf6vJLHNj f97hOHhcqETXYD59CwonAPvyY3uxPAaERbhccCBVV9z8tU3onj9fHgV64y9sbwa9aia0 hT94l2M59E4yL4bKLT8qKscW6BCj9X/GawRwKNsKcPBl83Ec5EnDYHNO5/PA36qOTB1s AT4tGb/F0I4WRAT/ImtvObgrXOb8iLLF79RqwQdax3KOr6L+vywnbWiwwyv4CMd3zDVS 7YxTuRCBnhP2BbbUAXfyIt0eqlSJZrQJ8pFLo2idu8pkVfZ9pk76xanH7kz0V+QEvd8G mMpw== 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 u2-v6si18907340plm.379.2018.05.07.01.22.19; Mon, 07 May 2018 01:22:33 -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 S1752073AbeEGIVi (ORCPT + 99 others); Mon, 7 May 2018 04:21:38 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:39834 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752023AbeEGIVS (ORCPT ); Mon, 7 May 2018 04:21:18 -0400 Received: by mail-wm0-f67.google.com with SMTP id f8-v6so13738887wmc.4 for ; Mon, 07 May 2018 01:21:17 -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=XVgWjpdsjRB17Og1OCU0m7DYRAuDIRV8q+Iy9w/kqMg=; b=aTUpUBK0a74inBTTUxnaE6hM5D/Fp4J1RHsmXR8N14cXA72i7LfVpQjySveQO3uZ5B jW6oEBFSZH8GU1PyDdFAVEC9X5MxbXejNhzqJwjeDGkFmbi+mCTCHHxHnynpsLKap8oa 6jjTy9FPzN+5Jp8xVNyXP3S8gpAsGCVd6s5cVw0hk956IZWLx9wTtgs+jeDaWVZSe4M9 aCkqQlrW7M/VeEVYpdVdKLwkDWYzdwNqtiYHuQAw9nmkCVl25wI+FvfAGw5rmd2IChak eGAGBXXCPjAjikkb/PafFQe+SEi+m+prDvsvLYV7XkaGH2ZWqWoJwhJpYa9vWIFeZKvN TWvA== X-Gm-Message-State: ALKqPwcNUvtue4erFo3MbnjDBXq/7RQ6SSDUSw7RgrDxEVtKLcLP3dsD skebRq4Nv5xCXZXAlxSZIzT9Dw== X-Received: by 2002:a1c:7e8d:: with SMTP id z135-v6mr146948wmc.6.1525681277117; Mon, 07 May 2018 01:21:17 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (C2B0E321.catv.pool.telekom.hu. [194.176.227.33]) by smtp.gmail.com with ESMTPSA id w6-v6sm26991776wra.16.2018.05.07.01.21.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 May 2018 01:21:16 -0700 (PDT) From: Miklos Szeredi To: Al Viro Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Amir Goldstein Subject: [PATCH 3/3] vfs: dedupe: extract helper for a single dedup Date: Mon, 7 May 2018 10:21:08 +0200 Message-Id: <20180507082108.28186-4-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180507082108.28186-1-mszeredi@redhat.com> References: <20180507082108.28186-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. Signed-off-by: Miklos Szeredi --- fs/read_write.c | 89 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 0cdef381d9d9..023df230e2a0 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1964,6 +1964,44 @@ int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, } EXPORT_SYMBOL(vfs_dedupe_file_range_compare); +static s64 vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, + struct file *dst_file, loff_t dst_pos, + u64 len) +{ + s64 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, + dst_file, dst_pos, len); +out_drop_write: + mnt_drop_write_file(dst_file); + + return ret; +} + int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) { struct file_dedupe_range_info *info; @@ -1972,10 +2010,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; s64 deduped; if (!(file->f_mode & FMODE_READ)) @@ -2010,54 +2045,28 @@ 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, - dst_file, - info->dest_offset, len); - 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, dst_file, + info->dest_offset, len); + 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); -- 2.14.3