From: Marco Stornelli <marco.stornelli@gmail.com>
To: Linux FS Devel <linux-fsdevel@vger.kernel.org>
Cc: Benjamin LaHaise <bcrl@kvack.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Jan Harkes <jaharkes@cs.cmu.edu>,
coda@cs.cmu.edu, Matthew Wilcox <matthew@wil.cx>,
linux-kernel@vger.kernel.org, linux-aio@kvack.org,
linux-fsdevel@vger.kernel.org, codalist@coda.cs.cmu.edu,
Jan Kara <jack@suse.cz>
Subject: [PATCH 2/4] fsfreeze: added new file_start_write_killable
Date: Fri, 26 Apr 2013 10:50:52 +0200 [thread overview]
Message-ID: <517A3FEC.7010709@gmail.com> (raw)
Replace file_start_write with file_start_write_killable where
possible.
Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
Reviewed-by: Jan Kara <jack@suse.cz>
---
drivers/block/loop.c | 4 +++-
fs/aio.c | 7 +++++--
fs/coda/file.c | 4 +++-
fs/read_write.c | 28 +++++++++++++++++-----------
fs/splice.c | 4 +++-
include/linux/fs.h | 17 +++++++++++++++++
6 files changed, 48 insertions(+), 16 deletions(-)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index be9a101..2c0d0a3 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -230,7 +230,9 @@ static int __do_lo_send_write(struct file *file,
ssize_t bw;
mm_segment_t old_fs = get_fs();
- file_start_write(file);
+ bw = file_start_write_killable(file);
+ if (bw < 0)
+ return bw;
set_fs(get_ds());
bw = file->f_op->write(file, buf, len, &pos);
set_fs(old_fs);
diff --git a/fs/aio.c b/fs/aio.c
index 5b7ed78..5deddf5 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1103,8 +1103,11 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
if (iocb->ki_pos < 0)
return -EINVAL;
- if (rw == WRITE)
- file_start_write(file);
+ if (rw == WRITE) {
+ ret = file_start_write_killable(file);
+ if (ret < 0)
+ return ret;
+ }
do {
ret = rw_op(iocb, &iocb->ki_iovec[iocb->ki_cur_seg],
iocb->ki_nr_segs - iocb->ki_cur_seg,
diff --git a/fs/coda/file.c b/fs/coda/file.c
index 380b798..c5708d0 100644
--- a/fs/coda/file.c
+++ b/fs/coda/file.c
@@ -79,7 +79,9 @@ coda_file_write(struct file *coda_file, const char __user *buf, size_t count, lo
return -EINVAL;
host_inode = file_inode(host_file);
- file_start_write(host_file);
+ ret = file_start_write_killable(host_file);
+ if (ret < 0)
+ return ret;
mutex_lock(&coda_inode->i_mutex);
ret = host_file->f_op->write(host_file, buf, count, ppos);
diff --git a/fs/read_write.c b/fs/read_write.c
index 7eb7ef3..ed9006f 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -438,17 +438,19 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
ret = rw_verify_area(WRITE, file, pos, count);
if (ret >= 0) {
count = ret;
- file_start_write(file);
- if (file->f_op->write)
- ret = file->f_op->write(file, buf, count, pos);
- else
- ret = do_sync_write(file, buf, count, pos);
+ ret = file_start_write_killable(file);
if (ret > 0) {
- fsnotify_modify(file);
- add_wchar(current, ret);
+ if (file->f_op->write)
+ ret = file->f_op->write(file, buf, count, pos);
+ else
+ ret = do_sync_write(file, buf, count, pos);
+ if (ret > 0) {
+ fsnotify_modify(file);
+ add_wchar(current, ret);
+ }
+ inc_syscw(current);
+ file_end_write(file);
}
- inc_syscw(current);
- file_end_write(file);
}
return ret;
@@ -718,7 +720,9 @@ static ssize_t do_readv_writev(int type, struct file *file,
} else {
fn = (io_fn_t)file->f_op->write;
fnv = file->f_op->aio_write;
- file_start_write(file);
+ ret = file_start_write_killable(file);
+ if (ret < 0)
+ goto out;
}
if (fnv)
@@ -898,7 +902,9 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
} else {
fn = (io_fn_t)file->f_op->write;
fnv = file->f_op->aio_write;
- file_start_write(file);
+ ret = file_start_write_killable(file);
+ if (ret < 0)
+ goto out;
}
if (fnv)
diff --git a/fs/splice.c b/fs/splice.c
index e6b2559..b37c30e 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1115,7 +1115,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
else
splice_write = default_file_splice_write;
- file_start_write(out);
+ ret = file_start_write_killable(out);
+ if (ret < 0)
+ return ret;
ret = splice_write(pipe, out, ppos, len, flags);
file_end_write(out);
return ret;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index c8b7325..998ec2a 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1404,6 +1404,16 @@ static inline void sb_start_write(struct super_block *sb)
__sb_start_write(sb, SB_FREEZE_WRITE, FREEZE_WAIT);
}
+/**
+ * sb_start_write_killable - get write access to a superblock
+ * @sb: the super we write to
+ *
+ */
+static inline int sb_start_write_killable(struct super_block *sb)
+{
+ return __sb_start_write(sb, SB_FREEZE_WRITE, FREEZE_WAIT_KILLABLE);
+}
+
static inline int sb_start_write_trylock(struct super_block *sb)
{
return __sb_start_write(sb, SB_FREEZE_WRITE, FREEZE_NOWAIT);
@@ -2227,6 +2237,13 @@ static inline struct inode *file_inode(struct file *f)
return f->f_inode;
}
+static inline int file_start_write_killable(struct file *file)
+{
+ if (!S_ISREG(file_inode(file)->i_mode))
+ return 1;
+ return sb_start_write_killable(file_inode(file)->i_sb);
+}
+
static inline void file_start_write(struct file *file)
{
if (!S_ISREG(file_inode(file)->i_mode))
--
1.7.3.4
--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to majordomo@kvack.org. For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>
WARNING: multiple messages have this Message-ID (diff)
From: Marco Stornelli <marco.stornelli@gmail.com>
To: Linux FS Devel <linux-fsdevel@vger.kernel.org>
Cc: Benjamin LaHaise <bcrl@kvack.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Jan Harkes <jaharkes@cs.cmu.edu>,
coda@cs.cmu.edu, Matthew Wilcox <matthew@wil.cx>,
linux-kernel@vger.kernel.org, linux-aio@kvack.org,
linux-fsdevel@vger.kernel.org, codalist@TELEMANN.coda.cs.cmu.edu,
Jan Kara <jack@suse.cz>
Subject: [PATCH 2/4] fsfreeze: added new file_start_write_killable
Date: Fri, 26 Apr 2013 10:50:52 +0200 [thread overview]
Message-ID: <517A3FEC.7010709@gmail.com> (raw)
Replace file_start_write with file_start_write_killable where
possible.
Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
Reviewed-by: Jan Kara <jack@suse.cz>
---
drivers/block/loop.c | 4 +++-
fs/aio.c | 7 +++++--
fs/coda/file.c | 4 +++-
fs/read_write.c | 28 +++++++++++++++++-----------
fs/splice.c | 4 +++-
include/linux/fs.h | 17 +++++++++++++++++
6 files changed, 48 insertions(+), 16 deletions(-)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index be9a101..2c0d0a3 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -230,7 +230,9 @@ static int __do_lo_send_write(struct file *file,
ssize_t bw;
mm_segment_t old_fs = get_fs();
- file_start_write(file);
+ bw = file_start_write_killable(file);
+ if (bw < 0)
+ return bw;
set_fs(get_ds());
bw = file->f_op->write(file, buf, len, &pos);
set_fs(old_fs);
diff --git a/fs/aio.c b/fs/aio.c
index 5b7ed78..5deddf5 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1103,8 +1103,11 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
if (iocb->ki_pos < 0)
return -EINVAL;
- if (rw == WRITE)
- file_start_write(file);
+ if (rw == WRITE) {
+ ret = file_start_write_killable(file);
+ if (ret < 0)
+ return ret;
+ }
do {
ret = rw_op(iocb, &iocb->ki_iovec[iocb->ki_cur_seg],
iocb->ki_nr_segs - iocb->ki_cur_seg,
diff --git a/fs/coda/file.c b/fs/coda/file.c
index 380b798..c5708d0 100644
--- a/fs/coda/file.c
+++ b/fs/coda/file.c
@@ -79,7 +79,9 @@ coda_file_write(struct file *coda_file, const char __user *buf, size_t count, lo
return -EINVAL;
host_inode = file_inode(host_file);
- file_start_write(host_file);
+ ret = file_start_write_killable(host_file);
+ if (ret < 0)
+ return ret;
mutex_lock(&coda_inode->i_mutex);
ret = host_file->f_op->write(host_file, buf, count, ppos);
diff --git a/fs/read_write.c b/fs/read_write.c
index 7eb7ef3..ed9006f 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -438,17 +438,19 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
ret = rw_verify_area(WRITE, file, pos, count);
if (ret >= 0) {
count = ret;
- file_start_write(file);
- if (file->f_op->write)
- ret = file->f_op->write(file, buf, count, pos);
- else
- ret = do_sync_write(file, buf, count, pos);
+ ret = file_start_write_killable(file);
if (ret > 0) {
- fsnotify_modify(file);
- add_wchar(current, ret);
+ if (file->f_op->write)
+ ret = file->f_op->write(file, buf, count, pos);
+ else
+ ret = do_sync_write(file, buf, count, pos);
+ if (ret > 0) {
+ fsnotify_modify(file);
+ add_wchar(current, ret);
+ }
+ inc_syscw(current);
+ file_end_write(file);
}
- inc_syscw(current);
- file_end_write(file);
}
return ret;
@@ -718,7 +720,9 @@ static ssize_t do_readv_writev(int type, struct file *file,
} else {
fn = (io_fn_t)file->f_op->write;
fnv = file->f_op->aio_write;
- file_start_write(file);
+ ret = file_start_write_killable(file);
+ if (ret < 0)
+ goto out;
}
if (fnv)
@@ -898,7 +902,9 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
} else {
fn = (io_fn_t)file->f_op->write;
fnv = file->f_op->aio_write;
- file_start_write(file);
+ ret = file_start_write_killable(file);
+ if (ret < 0)
+ goto out;
}
if (fnv)
diff --git a/fs/splice.c b/fs/splice.c
index e6b2559..b37c30e 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1115,7 +1115,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
else
splice_write = default_file_splice_write;
- file_start_write(out);
+ ret = file_start_write_killable(out);
+ if (ret < 0)
+ return ret;
ret = splice_write(pipe, out, ppos, len, flags);
file_end_write(out);
return ret;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index c8b7325..998ec2a 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1404,6 +1404,16 @@ static inline void sb_start_write(struct super_block *sb)
__sb_start_write(sb, SB_FREEZE_WRITE, FREEZE_WAIT);
}
+/**
+ * sb_start_write_killable - get write access to a superblock
+ * @sb: the super we write to
+ *
+ */
+static inline int sb_start_write_killable(struct super_block *sb)
+{
+ return __sb_start_write(sb, SB_FREEZE_WRITE, FREEZE_WAIT_KILLABLE);
+}
+
static inline int sb_start_write_trylock(struct super_block *sb)
{
return __sb_start_write(sb, SB_FREEZE_WRITE, FREEZE_NOWAIT);
@@ -2227,6 +2237,13 @@ static inline struct inode *file_inode(struct file *f)
return f->f_inode;
}
+static inline int file_start_write_killable(struct file *file)
+{
+ if (!S_ISREG(file_inode(file)->i_mode))
+ return 1;
+ return sb_start_write_killable(file_inode(file)->i_sb);
+}
+
static inline void file_start_write(struct file *file)
{
if (!S_ISREG(file_inode(file)->i_mode))
--
1.7.3.4
next reply other threads:[~2013-04-26 8:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-26 8:50 Marco Stornelli [this message]
2013-04-26 8:50 ` [PATCH 2/4] fsfreeze: added new file_start_write_killable Marco Stornelli
2013-04-26 12:06 ` Matthew Wilcox
2013-04-26 12:06 ` Matthew Wilcox
2013-04-26 13:44 ` Marco Stornelli
2013-04-26 13:44 ` Marco Stornelli
-- strict thread matches above, loose matches on Subject: below --
2013-05-04 6:50 Marco Stornelli
2013-05-04 6:50 ` Marco Stornelli
2013-07-04 16:16 Gmail
2013-07-04 16:16 ` Gmail
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=517A3FEC.7010709@gmail.com \
--to=marco.stornelli@gmail.com \
--cc=bcrl@kvack.org \
--cc=coda@cs.cmu.edu \
--cc=codalist@coda.cs.cmu.edu \
--cc=jack@suse.cz \
--cc=jaharkes@cs.cmu.edu \
--cc=linux-aio@kvack.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew@wil.cx \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.