Received: by 10.192.165.156 with SMTP id m28csp2087715imm; Thu, 12 Apr 2018 08:24:35 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+JgFUh1lEfmvrmK9k4ceoZFP6Ak7SbH1/jgRDZ7EVIxpyzGzJfBGX6cHG1wYaXINs/y6Xy X-Received: by 2002:a17:902:b212:: with SMTP id t18-v6mr1506396plr.137.1523546674982; Thu, 12 Apr 2018 08:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523546674; cv=none; d=google.com; s=arc-20160816; b=NK2Qgg/BQlEFclgHFMpIp4kHJcvxpddzSw+0oDhoUzibET6jT8aiFu5BZeo7bnOEzi g9BziA+WZORhfyj/MXGVpIiimK4GAgQDHRHEyMlIhOpwWGV3PVrvc70vPMjjgLjrZIhP rnnI+vN+Vhf7b6oFHk+KRjdS/xZjHg/zW+cXkRnVwmRBIbPuEeCZ8GtVsIRDfu+F1Bg0 NLq+Ol2F1sn8qtc8SDqkR6kk+tzVw7ulMX/Rep7bxVBDBoNuRNz8lYMlXrY+nGAM6VeL q0ClMMTpQwKx1Q8emBfKy2w041ceMoIeDx3LIjIOvOpA8N1LWRLlr1dkQ+uLmAC3Zoqg XEyQ== 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=m1sMqC8KpJhRoV1evQnQLvvU43+aTQ8DjQhA+g/8s/8=; b=Ar3qoG9nvCEAynJS14Kx7XHqerti1t2zDpZTqo+XIQ+/3KDQpNQouwnQSXc9+omXh+ 6X4A28oY5H3rQBp61cPb+cbI9uE+6undwqgQgSBilVfEW9v0An2XwxvdzNDlFpcbbDoD M7tWjqMib7c/7/cWrooKujMKxe/YwdX6MIitHlajilehXoodM5coarNsE8QAh2Qh9tc9 fp3yCFxKWbmBGjEUbtunT81/kO9V9MnZ6lQOOPAhPxCoc7MK8UVsPKzxeZyVnCWy5mPQ uO7Zs49+xzfcjVpYQx5/eaBmG1ivyolA0U/KkEkvcvo5h2nyNQ94v80peUGS3H/XXL8X /QqA== 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 x6si55560pfh.428.2018.04.12.08.23.57; Thu, 12 Apr 2018 08:24:34 -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 S1754155AbeDLPTh (ORCPT + 99 others); Thu, 12 Apr 2018 11:19:37 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:34343 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753450AbeDLPIz (ORCPT ); Thu, 12 Apr 2018 11:08:55 -0400 Received: by mail-wr0-f196.google.com with SMTP id d19so5474343wre.1 for ; Thu, 12 Apr 2018 08:08:54 -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=m1sMqC8KpJhRoV1evQnQLvvU43+aTQ8DjQhA+g/8s/8=; b=L27dewFmN3a/soB5BxrStQMuAmsxWe3QtHtNyIEPq2h2CY2O5FaCIspxnpcXNnXm5v jo0H26/qQ94byu4JST+FRJhWEo64OncJ+rTN7oR+AiW0Ay/hwqRy57i2xz8TkzcOsoFh 4McDTK9w9OwQ0jUx39aKlz5w04GEQAjXQqEZfmGtzVXw5bmy/Xo552qn1MhjE56QlLNY GY89hOucDqLiIy52/87qtwX6Sykw966OfP7FNnDE2Q0X6siuDSH0pXDbUUvcSf9jZPuM MyTxfHACZ08slyay0E+Rb4+OqjiyBh0sTLN1/WDe1to1Z5wgHzO42ItKBONfZXAz9/Rq r08g== X-Gm-Message-State: ALQs6tAUgvOlD8OSKPt7xtvihtcuki4sMebEXGRRxP0IoU7kAWHiZvqR AftdsVBuZndYyFE94mpUv/5cgQ== X-Received: by 10.223.139.4 with SMTP id n4mr1087913wra.112.1523545733624; Thu, 12 Apr 2018 08:08:53 -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.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Apr 2018 08:08:53 -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 19/35] ovl: readd reflink/copyfile/dedup support Date: Thu, 12 Apr 2018 17:08:10 +0200 Message-Id: <20180412150826.20988-20-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 Since set of arguments are so similar, handle in a common helper. Signed-off-by: Miklos Szeredi --- fs/overlayfs/file.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 9670e160967e..39b1b73334ad 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -352,6 +352,81 @@ long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return ret; } +enum ovl_copyop { + OVL_COPY, + OVL_CLONE, + OVL_DEDUPE, +}; + +static ssize_t ovl_copyfile(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 len, unsigned int flags, enum ovl_copyop op) +{ + struct inode *inode_out = file_inode(file_out); + struct fd real_in, real_out; + const struct cred *old_cred; + int ret; + + ret = ovl_real_file(file_out, &real_out); + if (ret) + return ret; + + ret = ovl_real_file(file_in, &real_in); + if (ret) { + fdput(real_out); + return ret; + } + + old_cred = ovl_override_creds(file_inode(file_out)->i_sb); + switch (op) { + case OVL_COPY: + ret = vfs_copy_file_range(real_in.file, pos_in, + real_out.file, pos_out, len, flags); + break; + + case OVL_CLONE: + ret = vfs_clone_file_range(real_in.file, pos_in, + real_out.file, pos_out, len); + break; + + case OVL_DEDUPE: + ret = vfs_dedupe_file_range_one(real_in.file, pos_in, len, + real_out.file, pos_out); + break; + } + revert_creds(old_cred); + + /* Update size */ + ovl_copyattr(ovl_inode_real(inode_out), inode_out); + + fdput(real_in); + fdput(real_out); + + return ret; +} + +static ssize_t ovl_copy_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t len, unsigned int flags) +{ + return ovl_copyfile(file_in, pos_in, file_out, pos_out, len, flags, + OVL_COPY); +} + +static int ovl_clone_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, u64 len) +{ + return ovl_copyfile(file_in, pos_in, file_out, pos_out, len, 0, + OVL_CLONE); +} + +static ssize_t ovl_dedupe_file_range(struct file *file_in, u64 pos_in, u64 len, + struct file *file_out, u64 pos_out) +{ + return ovl_copyfile(file_in, pos_in, file_out, pos_out, len, 0, + OVL_DEDUPE); +} + const struct file_operations ovl_file_operations = { .open = ovl_open, .release = ovl_release, @@ -362,4 +437,8 @@ const struct file_operations ovl_file_operations = { .mmap = ovl_mmap, .fallocate = ovl_fallocate, .unlocked_ioctl = ovl_ioctl, + + .copy_file_range = ovl_copy_file_range, + .clone_file_range = ovl_clone_file_range, + .dedupe_file_range = ovl_dedupe_file_range, }; -- 2.14.3