From patchwork Tue Jan 31 08:34:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9546719 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 45F4D60236 for ; Tue, 31 Jan 2017 08:35:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38D162811E for ; Tue, 31 Jan 2017 08:35:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DB6D28249; Tue, 31 Jan 2017 08:35:42 +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 C14622811E for ; Tue, 31 Jan 2017 08:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751077AbdAaIfi (ORCPT ); Tue, 31 Jan 2017 03:35:38 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33407 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750890AbdAaIf2 (ORCPT ); Tue, 31 Jan 2017 03:35:28 -0500 Received: by mail-wm0-f65.google.com with SMTP id v77so21300906wmv.0; Tue, 31 Jan 2017 00:35:20 -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=XDwShkU551P/iUBm0JWP7Ed0tQhe5Yp1SqQnNbEH15o=; b=hpLgICbkgan1EGOcT/G6g+I6jRl7OxsOUWMkJWH70f46wWvC5f4RYi9RMf3Hg4y3v2 2RYiGVMrTG8dCVnZ2eYZscbOly5FwRfQ2Y4e1K/pyCCPL+hal4ZZfUQsPiZn7VptmVr1 RnDKlUqZ6hEdQckrbVe2O6Kp38h+Sr/ePPMA4XrMQyeurZVJd3GMdsc0NsAit6OFtYMb 9IpT+YI8tcT493UFfxUTNyB0IRZGJhYv0hgOBiL/p2aw7QnKl1I1wHFNTisgUzblFzqx u6fRoclSjMFzanblSALzOfWnN/N1TFtD8K9WgbUnzV01HkyjVALTA1xYuYjqAOWOgopW xmkw== 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=XDwShkU551P/iUBm0JWP7Ed0tQhe5Yp1SqQnNbEH15o=; b=c6kYzeAhV+7MgVmheqzuMXXT2tBjqNUJmYLrAAPLI7GEJJbp4U8fXm2G+9cs1XwuoG 9ViuBpHq9auz88LRcnF9atUFlxx/mGDNpZ0zJDEXpCTemqJxqdJk2uowNpHMS5x7xwKM XnLHyUPMZDzg1KVmHtIMjMWJ7hb56o/AGq2omXJEAZ2t2bxmVIBrrawCj7TE/gCNcqWP yrxmQqw/R6mJp/lp8NhjB6CahUy91douAE0a0Vqw8dBNJwxD13lGmYxZNbG1ws7BpZa9 ShTPJC49RLQeRbXrx8wiFmgjFVfF5bj/b9DHqA4tQ29xigISnYXbqJbZRNmf+4lL0D6M 8YXg== X-Gm-Message-State: AIkVDXJkhTNCoWTXzK6G7B/TFvz3tPi6l9cFSGUoinuwvf3tVara+iEXPmNz8DAI/+HK6g== X-Received: by 10.28.206.136 with SMTP id e130mr17008936wmg.121.1485851719391; Tue, 31 Jan 2017 00:35:19 -0800 (PST) Received: from amir-VirtualBox.ctera.local (bzq-79-176-143-83.red.bezeqint.net. [79.176.143.83]) by smtp.gmail.com with ESMTPSA id i189sm22752140wmg.7.2017.01.31.00.35.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 31 Jan 2017 00:35:17 -0800 (PST) From: Amir Goldstein To: Miklos Szeredi Cc: Jan Kara , Christoph Hellwig , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 3/5] vfs: wrap write f_ops with file_{start,end}_write() Date: Tue, 31 Jan 2017 10:34:57 +0200 Message-Id: <1485851699-25313-4-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485851699-25313-1-git-send-email-amir73il@gmail.com> References: <1485851699-25313-1-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(). Replace {sb,file}_start_write() for {copy,clone}_file_range() and for fallocate(). Beyond correct semantics, this avoids freeze protection to sb when operating on special inodes, such as fallocate() on a blockdev. Reviewed-by: Jan Kara Signed-off-by: Amir Goldstein Reviewed-by: Christoph Hellwig --- fs/open.c | 4 ++-- fs/read_write.c | 4 ++-- include/linux/fs.h | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/fs/open.c b/fs/open.c index f9118f4..949cef2 100644 --- a/fs/open.c +++ b/fs/open.c @@ -314,7 +314,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); /* @@ -327,7 +327,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 511178d..820a3f0 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1543,7 +1543,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 @@ -1579,7 +1579,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; } diff --git a/include/linux/fs.h b/include/linux/fs.h index 4a7f3cc..78c81e6 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 *); @@ -2564,6 +2551,19 @@ static inline void file_end_write(struct file *file) __sb_end_write(file_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.