From patchwork Mon Jan 23 19:43:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9533397 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 C3ADB6046A for ; Mon, 23 Jan 2017 19:43:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B545128395 for ; Mon, 23 Jan 2017 19:43:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A858C2839C; Mon, 23 Jan 2017 19:43:32 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 43E9428395 for ; Mon, 23 Jan 2017 19:43:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750957AbdAWTna (ORCPT ); Mon, 23 Jan 2017 14:43:30 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35701 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750912AbdAWTna (ORCPT ); Mon, 23 Jan 2017 14:43:30 -0500 Received: by mail-wm0-f68.google.com with SMTP id d140so28889297wmd.2; Mon, 23 Jan 2017 11:43:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eJNH7AxiFLa04+MdVu3Sdj6xC0jDu5Otui4lFffPlWQ=; b=Gj47snGmxcFncMYunw/A11quHQxhLOoER1HM3x0eo8hm1ZhG712tyaSZ3B58kaoDMo 354PxUCnjxQOi2x0cCYrrbp5rTS/Thc32Y5nd7MSqfAj9SAiwDkKnkSjdlXvJkKrqDRK J2xsarNsAvxSQ5igcp/JiWDeYzHjElPpTrbS9Fu8NGQbqTfwUUQ3d4Pz1T7wvF4jANTk Sju/DQ2FRLgjdHxqSSx5FvLh9ZOHcLwnAR3b9T4i5HOwlQZae5t3ek4KBQ6F5jFIEAPW /YpUvvOWIUXKt1ejXi1miZH4Ng2t93u5ConX/yeNzPRS398Iyg3kxjfyrN0T+6Cff1+h Q3Xg== 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=eJNH7AxiFLa04+MdVu3Sdj6xC0jDu5Otui4lFffPlWQ=; b=KSaXDzGEZ3JPWOb8DwrXuCs9LZduzRe6cfg/gmYcdWQsL+xRffvjOkkvmT8Iv0hpvW w1ePydNvDaXngIMmOXnLM/uP9o3AruFcYc4uvInnHbzLFmEtHIinZYfO08N5rrhiRUKk mHu4BvLDxdvCkDUsiA8f/pPhyW6sFAhsVISZwdeEj3imbH2cv6IlcIv+hnUsPVFBTYvD ymhAcmJonW4QPWckHcHobtwlrXOuHfRe3YJOaWnAqBfZCUkTceQdoSBa91RZREpCmn9+ aLIxoLvz+tooxbhG7dUL1/tAO5MXCZWCkJhpwkuoHbNSHZ3TCT+ZcsCkgcNok2suI9In eNyA== X-Gm-Message-State: AIkVDXJn9t0pIG/UaJDKHFk/fN4hVepWxYqqTQgnTfoKEUYehLyZ9TkIFZ//Vc07mCt5dA== X-Received: by 10.28.41.135 with SMTP id p129mr16293196wmp.59.1485200608286; Mon, 23 Jan 2017 11:43:28 -0800 (PST) Received: from amir-VirtualBox.Home (bzq-79-176-143-83.red.bezeqint.net. [79.176.143.83]) by smtp.gmail.com with ESMTPSA id d14sm22789748wmd.19.2017.01.23.11.43.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Jan 2017 11:43:27 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Jan Kara , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH v2 4/4] vfs: wrap write f_ops with file_{start, end}_write() Date: Mon, 23 Jan 2017 21:43:16 +0200 Message-Id: <1485200596-14057-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485174742-15866-2-git-send-email-amir73il@gmail.com> References: <1485174742-15866-2-git-send-email-amir73il@gmail.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 Before calling write f_ops, call file_start_write() instead of sb_start_write(). This ensures freeze protection for both overlay and upper fs when file is open from an overlayfs mount. Replace {sb,file}_start_write() for {copy,clone}_file_range() and for fallocate(). For dedup_file_range() there is no need for mnt_want_write_file(). File is already open for write, so we already have mnt_want_write() and we only need file_start_write(). Signed-off-by: Amir Goldstein Reviewed-by: Jan Kara --- fs/open.c | 4 ++-- fs/read_write.c | 12 ++++-------- include/linux/fs.h | 26 +++++++++++++------------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/fs/open.c b/fs/open.c index 9921f70..d3fe1a1 100644 --- a/fs/open.c +++ b/fs/open.c @@ -316,7 +316,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) if (!file->f_op->fallocate) return -EOPNOTSUPP; - sb_start_write(inode->i_sb); + file_start_write(file); ret = file->f_op->fallocate(file, mode, offset, len); /* @@ -329,7 +329,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) if (ret == 0) fsnotify_modify(file); - sb_end_write(inode->i_sb); + file_end_write(file); return ret; } EXPORT_SYMBOL_GPL(vfs_fallocate); diff --git a/fs/read_write.c b/fs/read_write.c index 5816d4c..1e42487 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1538,7 +1538,7 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, if (len == 0) return 0; - sb_start_write(inode_out->i_sb); + file_start_write(file_out); /* * Try cloning first, this is supported by more file systems, and @@ -1574,7 +1574,7 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, inc_syscr(current); inc_syscw(current); - sb_end_write(inode_out->i_sb); + file_end_write(file_out); return ret; } @@ -1976,11 +1976,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) } dst = file_inode(dst_file); - ret = mnt_want_write_file(dst_file); - if (ret) { - info->status = ret; - goto next_loop; - } + file_start_write(dst_file); dst_off = info->dest_offset; ret = clone_verify_area(dst_file, dst_off, len, true); @@ -2013,7 +2009,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) } next_file: - mnt_drop_write_file(dst_file); + file_end_write(dst_file); next_loop: fdput(dst_fd); diff --git a/include/linux/fs.h b/include/linux/fs.h index 71811be..8a4dbc6 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1741,19 +1741,6 @@ extern int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, extern int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same); -static inline int do_clone_file_range(struct file *file_in, loff_t pos_in, - struct file *file_out, loff_t pos_out, - u64 len) -{ - int ret; - - sb_start_write(file_inode(file_out)->i_sb); - ret = vfs_clone_file_range(file_in, pos_in, file_out, pos_out, len); - sb_end_write(file_inode(file_out)->i_sb); - - return ret; -} - struct super_operations { struct inode *(*alloc_inode)(struct super_block *sb); void (*destroy_inode)(struct inode *); @@ -2579,6 +2566,19 @@ static inline void file_end_write(struct file *file) __sb_end_write(locks_inode(file)->i_sb, SB_FREEZE_WRITE); } +static inline int do_clone_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + u64 len) +{ + int ret; + + file_start_write(file_out); + ret = vfs_clone_file_range(file_in, pos_in, file_out, pos_out, len); + file_end_write(file_out); + + return ret; +} + /* * get_write_access() gets write permission for a file. * put_write_access() releases this write permission.