From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Jan Kara <jack@suse.com>, Christoph Hellwig <hch@lst.de>,
Al Viro <viro@zeniv.linux.org.uk>,
linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH v3 4/5] vfs: freeze protect overlay inode on file_start_write()
Date: Tue, 31 Jan 2017 10:34:58 +0200 [thread overview]
Message-ID: <1485851699-25313-5-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1485851699-25313-1-git-send-email-amir73il@gmail.com>
Before writing to overlay file, need to check if either overlay
or upper fs are frozen.
This allows freezing overlayfs mount independently of freezing
underlying fs.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
include/linux/fs.h | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 78c81e6..8a4dbc6 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2534,14 +2534,26 @@ static inline void file_start_write(struct file *file)
{
if (!S_ISREG(file_inode(file)->i_mode))
return;
+ __sb_start_write(locks_inode(file)->i_sb, SB_FREEZE_WRITE, true);
+ if (likely(locks_inode(file) == file_inode(file)))
+ return;
__sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, true);
+
}
static inline bool file_start_write_trylock(struct file *file)
{
+ int ret;
+
if (!S_ISREG(file_inode(file)->i_mode))
return true;
- return __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, false);
+ ret = __sb_start_write(locks_inode(file)->i_sb, SB_FREEZE_WRITE, false);
+ if (!ret || likely(locks_inode(file) == file_inode(file)))
+ return ret;
+ ret = __sb_start_write(file_inode(file)->i_sb, SB_FREEZE_WRITE, false);
+ if (!ret)
+ __sb_end_write(locks_inode(file)->i_sb, SB_FREEZE_WRITE);
+ return ret;
}
static inline void file_end_write(struct file *file)
@@ -2549,6 +2561,9 @@ static inline void file_end_write(struct file *file)
if (!S_ISREG(file_inode(file)->i_mode))
return;
__sb_end_write(file_inode(file)->i_sb, SB_FREEZE_WRITE);
+ if (likely(locks_inode(file) == file_inode(file)))
+ return;
+ __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,
--
2.7.4
next prev parent reply other threads:[~2017-01-31 8:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-31 8:34 [PATCH v3 0/5] overlayfs: support freeze/thaw Amir Goldstein
2017-01-31 8:34 ` [PATCH v3 1/5] vfs: deny fallocate() on directory Amir Goldstein
2017-01-31 10:56 ` Christoph Hellwig
[not found] ` <1485851699-25313-1-git-send-email-amir73il-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-01-31 8:34 ` [PATCH v3 2/5] vfs: deny copy_file_range() for non regular files Amir Goldstein
[not found] ` <1485851699-25313-3-git-send-email-amir73il-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-01-31 10:56 ` Christoph Hellwig
2017-01-31 8:34 ` [PATCH v3 3/5] vfs: wrap write f_ops with file_{start,end}_write() Amir Goldstein
2017-01-31 10:56 ` Christoph Hellwig
2017-01-31 8:34 ` Amir Goldstein [this message]
2017-01-31 8:34 ` [PATCH v3 5/5] ovl: support freeze/thaw super Amir Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1485851699-25313-5-git-send-email-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=hch@lst.de \
--cc=jack@suse.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox