Skip to content

Commit

Permalink
ocfs2: remove OCFS2_IOCB_SEM lock type in direct io
Browse files Browse the repository at this point in the history
In ocfs2 direct read/write, OCFS2_IOCB_SEM lock type is used to protect
inode->i_alloc_sem rw semaphore lock in the earlier kernel version.
However, in the latest kernel, inode->i_alloc_sem rw semaphore lock is not
used at all, so OCFS2_IOCB_SEM lock type needs to be removed.

Signed-off-by: Weiwei Wang <[email protected]>
Cc: Mark Fasheh <[email protected]>
Cc: Joel Becker <[email protected]>
Reviewed-by: Junxiao Bi <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
WeiWei Wang authored and torvalds committed Jun 25, 2015
1 parent e272e7f commit fa5a0eb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 37 deletions.
3 changes: 0 additions & 3 deletions fs/ocfs2/aops.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,6 @@ static void ocfs2_dio_end_io(struct kiocb *iocb,
/* this io's submitter should not have unlocked this before we could */
BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));

if (ocfs2_iocb_is_sem_locked(iocb))
ocfs2_iocb_clear_sem_locked(iocb);

if (ocfs2_iocb_is_unaligned_aio(iocb)) {
ocfs2_iocb_clear_unaligned_aio(iocb);

Expand Down
7 changes: 0 additions & 7 deletions fs/ocfs2/aops.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ static inline void ocfs2_iocb_set_rw_locked(struct kiocb *iocb, int level)
enum ocfs2_iocb_lock_bits {
OCFS2_IOCB_RW_LOCK = 0,
OCFS2_IOCB_RW_LOCK_LEVEL,
OCFS2_IOCB_SEM,
OCFS2_IOCB_UNALIGNED_IO,
OCFS2_IOCB_NUM_LOCKS
};
Expand All @@ -88,12 +87,6 @@ enum ocfs2_iocb_lock_bits {
clear_bit(OCFS2_IOCB_RW_LOCK, (unsigned long *)&iocb->private)
#define ocfs2_iocb_rw_locked_level(iocb) \
test_bit(OCFS2_IOCB_RW_LOCK_LEVEL, (unsigned long *)&iocb->private)
#define ocfs2_iocb_set_sem_locked(iocb) \
set_bit(OCFS2_IOCB_SEM, (unsigned long *)&iocb->private)
#define ocfs2_iocb_clear_sem_locked(iocb) \
clear_bit(OCFS2_IOCB_SEM, (unsigned long *)&iocb->private)
#define ocfs2_iocb_is_sem_locked(iocb) \
test_bit(OCFS2_IOCB_SEM, (unsigned long *)&iocb->private)

#define ocfs2_iocb_set_unaligned_aio(iocb) \
set_bit(OCFS2_IOCB_UNALIGNED_IO, (unsigned long *)&iocb->private)
Expand Down
31 changes: 4 additions & 27 deletions fs/ocfs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2250,7 +2250,7 @@ static int ocfs2_prepare_inode_for_write(struct file *file,
static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
struct iov_iter *from)
{
int direct_io, appending, rw_level, have_alloc_sem = 0;
int direct_io, appending, rw_level;
int can_do_direct, has_refcount = 0;
ssize_t written = 0;
ssize_t ret;
Expand Down Expand Up @@ -2279,16 +2279,7 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,

mutex_lock(&inode->i_mutex);

ocfs2_iocb_clear_sem_locked(iocb);

relock:
/* to match setattr's i_mutex -> rw_lock ordering */
if (direct_io) {
have_alloc_sem = 1;
/* communicate with ocfs2_dio_end_io */
ocfs2_iocb_set_sem_locked(iocb);
}

/*
* Concurrent O_DIRECT writes are allowed with
* mount_option "coherency=buffered".
Expand All @@ -2298,7 +2289,7 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
ret = ocfs2_rw_lock(inode, rw_level);
if (ret < 0) {
mlog_errno(ret);
goto out_sems;
goto out_mutex;
}

/*
Expand Down Expand Up @@ -2347,7 +2338,6 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
if (direct_io && !can_do_direct) {
ocfs2_rw_unlock(inode, rw_level);

have_alloc_sem = 0;
rw_level = -1;

direct_io = 0;
Expand Down Expand Up @@ -2416,7 +2406,6 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
*/
if ((ret == -EIOCBQUEUED) || (!ocfs2_iocb_is_rw_locked(iocb))) {
rw_level = -1;
have_alloc_sem = 0;
unaligned_dio = 0;
}

Expand All @@ -2429,10 +2418,7 @@ static ssize_t ocfs2_file_write_iter(struct kiocb *iocb,
if (rw_level != -1)
ocfs2_rw_unlock(inode, rw_level);

out_sems:
if (have_alloc_sem)
ocfs2_iocb_clear_sem_locked(iocb);

out_mutex:
mutex_unlock(&inode->i_mutex);

if (written)
Expand Down Expand Up @@ -2473,7 +2459,7 @@ static ssize_t ocfs2_file_splice_read(struct file *in,
static ssize_t ocfs2_file_read_iter(struct kiocb *iocb,
struct iov_iter *to)
{
int ret = 0, rw_level = -1, have_alloc_sem = 0, lock_level = 0;
int ret = 0, rw_level = -1, lock_level = 0;
struct file *filp = iocb->ki_filp;
struct inode *inode = file_inode(filp);

Expand All @@ -2490,16 +2476,11 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb,
goto bail;
}

ocfs2_iocb_clear_sem_locked(iocb);

/*
* buffered reads protect themselves in ->readpage(). O_DIRECT reads
* need locks to protect pending reads from racing with truncate.
*/
if (iocb->ki_flags & IOCB_DIRECT) {
have_alloc_sem = 1;
ocfs2_iocb_set_sem_locked(iocb);

ret = ocfs2_rw_lock(inode, 0);
if (ret < 0) {
mlog_errno(ret);
Expand Down Expand Up @@ -2535,13 +2516,9 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb,
/* see ocfs2_file_write_iter */
if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) {
rw_level = -1;
have_alloc_sem = 0;
}

bail:
if (have_alloc_sem)
ocfs2_iocb_clear_sem_locked(iocb);

if (rw_level != -1)
ocfs2_rw_unlock(inode, rw_level);

Expand Down

0 comments on commit fa5a0eb

Please sign in to comment.