Skip to contentSkip to conversation

Ocfs2: Teach 'coherency=full' O_DIRECT writes to correctly up_read i_alloc_sem.

PATCH New Tristan Ye 2 participants 3 messages Nov 29, 2010 OCFS2

lore
Share & tools
lore

Tristan Ye

author
#0 lore raw

PATCH 1/1 Ocfs2: Teach 'coherency=full' O_DIRECT writes to correctly up_read i_alloc_sem.

Due to newly-introduced 'coherency=full' O_DIRECT writes also takes the EX rw_lock like buffered writes did(rw_level == 1), it turns out messing the usage of 'level' in ocfs2_dio_end_io() up, which caused i_alloc_sem being failed to get up_read'd correctly.

This patch tries to teach ocfs2_dio_end_io to understand well on all locking stuffs by explicitly introducing a new bit for i_alloc_sem in iocb's private data, just like what we did for rw_lock.

---
 fs/ocfs2/aops.c |    6 ++++--
 fs/ocfs2/aops.h |    6 ++++++
 fs/ocfs2/file.c |    5 ++++-
 3 files changed, 14 insertions(+), 3 deletions(-)
fs/ocfs2/aops.c +4 -2
index f1e962c..857e013 100644
@@ -568,7 +568,7 @@ static void ocfs2_dio_end_io(struct kiocb *iocb,
 			     bool is_async)
 {
 	struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
-	int level;
+	int level, sem_locked;
 
 	/* this io's submitter should not have unlocked this before we could */
 	BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
@@ -576,7 +576,9 @@ static void ocfs2_dio_end_io(struct kiocb *iocb,
 	ocfs2_iocb_clear_rw_locked(iocb);
 
 	level = ocfs2_iocb_rw_locked_level(iocb);
-	if (!level)
+	sem_locked = ocfs2_iocb_is_sem_locked(iocb);
+	ocfs2_iocb_clear_sem_locked(iocb);
+	if (sem_locked)
 		up_read(&inode->i_alloc_sem);
 	ocfs2_rw_unlock(inode, level);
 
fs/ocfs2/aops.h +6 -0
index 76bfdfd..c7a3e5f 100644
@@ -72,4 +72,10 @@ static inline void ocfs2_iocb_set_rw_locked(struct kiocb *iocb, int level)
 	clear_bit(0, (unsigned long *)&iocb->private)
 #define ocfs2_iocb_rw_locked_level(iocb) \
 	test_bit(1, (unsigned long *)&iocb->private)
+#define ocfs2_iocb_set_sem_locked(iocb) \
+	set_bit(2, (unsigned long *)&iocb->private)
+#define ocfs2_iocb_clear_sem_locked(iocb) \
+	clear_bit(2, (unsigned long *)&iocb->private)
+#define ocfs2_iocb_is_sem_locked(iocb) \
+	test_bit(2, (unsigned long *)&iocb->private)
 #endif /* OCFS2_FILE_H */
fs/ocfs2/file.c +4 -1
index 77b4c04..4e66990 100644
@@ -2246,7 +2246,10 @@ relock:
 	if (direct_io) {
 		down_read(&inode->i_alloc_sem);
 		have_alloc_sem = 1;
-	}
+		/* communicate with ocfs2_dio_end_io */
+		ocfs2_iocb_set_sem_locked(iocb);
+	} else
+		ocfs2_iocb_clear_sem_locked(iocb);
 
 	/*
 	 * Concurrent O_DIRECT writes are allowed with
Signature · 1 line
1.5.5
#1 lore raw

PATCH 1/1 Ocfs2: Teach 'coherency=full' O_DIRECT writes to correctly up_read i_alloc_sem.

Hi Tristan,
Your patch forgets to set the new flag properly in direct read.

Regards,
Tao

Quoted 72 lines · Tristan Ye

Due to newly-introduced 'coherency=full' O_DIRECT writes also takes the EX rw_lock like buffered writes did(rw_level == 1), it turns out messing the usage of 'level' in ocfs2_dio_end_io() up, which caused i_alloc_sem being failed to get up_read'd correctly.

This patch tries to teach ocfs2_dio_end_io to understand well on all locking stuffs by explicitly introducing a new bit for i_alloc_sem in iocb's private data, just like what we did for rw_lock.

---
  fs/ocfs2/aops.c |    6 ++++--
  fs/ocfs2/aops.h |    6 ++++++
  fs/ocfs2/file.c |    5 ++++-
  3 files changed, 14 insertions(+), 3 deletions(-)
fs/ocfs2/aops.c +4 -2
index f1e962c..857e013 100644
@@ -568,7 +568,7 @@ static void ocfs2_dio_end_io(struct kiocb *iocb,
  			     bool is_async)
  {
  	struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
-	int level;
+	int level, sem_locked;
 
  	/* this io's submitter should not have unlocked this before we could */
  	BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
@@ -576,7 +576,9 @@ static void ocfs2_dio_end_io(struct kiocb *iocb,
  	ocfs2_iocb_clear_rw_locked(iocb);
 
  	level = ocfs2_iocb_rw_locked_level(iocb);
-	if (!level)
+	sem_locked = ocfs2_iocb_is_sem_locked(iocb);
+	ocfs2_iocb_clear_sem_locked(iocb);
+	if (sem_locked)
  		up_read(&inode->i_alloc_sem);
  	ocfs2_rw_unlock(inode, level);
 
fs/ocfs2/aops.h +6 -0
index 76bfdfd..c7a3e5f 100644
@@ -72,4 +72,10 @@ static inline void ocfs2_iocb_set_rw_locked(struct kiocb *iocb, int level)
  	clear_bit(0, (unsigned long *)&iocb->private)
  #define ocfs2_iocb_rw_locked_level(iocb) \
  	test_bit(1, (unsigned long *)&iocb->private)
+#define ocfs2_iocb_set_sem_locked(iocb) \
+	set_bit(2, (unsigned long *)&iocb->private)
+#define ocfs2_iocb_clear_sem_locked(iocb) \
+	clear_bit(2, (unsigned long *)&iocb->private)
+#define ocfs2_iocb_is_sem_locked(iocb) \
+	test_bit(2, (unsigned long *)&iocb->private)
  #endif /* OCFS2_FILE_H */
fs/ocfs2/file.c +4 -1
index 77b4c04..4e66990 100644
@@ -2246,7 +2246,10 @@ relock:
  	if (direct_io) {
  		down_read(&inode->i_alloc_sem);
  		have_alloc_sem = 1;
-	}
+		/* communicate with ocfs2_dio_end_io */
+		ocfs2_iocb_set_sem_locked(iocb);
+	} else
+		ocfs2_iocb_clear_sem_locked(iocb);
 
  	/*
  	 * Concurrent O_DIRECT writes are allowed with
author
#2 lore raw

PATCH 1/1 Ocfs2: Teach 'coherency=full' O_DIRECT writes to correctly up_read i_alloc_sem.

Quoted 2 lines · Tao Ma

Hi Tristan,
Your patch forgets to set the new flag properly in direct read.

Tao,

Thanks, good catch!

Using a new 'sem_locked' flag in ocfs2_dio_end_io() also will be affecting direct read definitely.

Quoted 83 lines

Regards,
Tao

Quoted 79 lines · Tristan Ye

Due to newly-introduced 'coherency=full' O_DIRECT writes also takes the EX
rw_lock like buffered writes did(rw_level == 1), it turns out messing the
usage of 'level' in ocfs2_dio_end_io() up, which caused i_alloc_sem being
failed to get up_read'd correctly.

This patch tries to teach ocfs2_dio_end_io to understand well on all locking
stuffs by explicitly introducing a new bit for i_alloc_sem in iocb's private
data, just like what we did for rw_lock.

---
  fs/ocfs2/aops.c |    6 ++++--
  fs/ocfs2/aops.h |    6 ++++++
  fs/ocfs2/file.c |    5 ++++-
  3 files changed, 14 insertions(+), 3 deletions(-)
fs/ocfs2/aops.c +1 -1
index f1e962c..857e013 100644
@@ -568,7 +568,7 @@ static void ocfs2_dio_end_io(struct kiocb *iocb,
                   bool is_async)
  {
      struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
-    int level;
+    int level, sem_locked;
 
      /* this io's submitter should not have unlocked this before we 

could */

      BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
fs/ocfs2/aops.c +3 -1
@@ -576,7 +576,9 @@ static void ocfs2_dio_end_io(struct kiocb *iocb,
      ocfs2_iocb_clear_rw_locked(iocb);
 
      level = ocfs2_iocb_rw_locked_level(iocb);
-    if (!level)
+    sem_locked = ocfs2_iocb_is_sem_locked(iocb);
+    ocfs2_iocb_clear_sem_locked(iocb);
+    if (sem_locked)
          up_read(&inode->i_alloc_sem);
      ocfs2_rw_unlock(inode, level);
 
fs/ocfs2/aops.h +6 -0
index 76bfdfd..c7a3e5f 100644
@@ -72,4 +72,10 @@ static inline void ocfs2_iocb_set_rw_locked(struct 
 kiocb *iocb, int level)
      clear_bit(0, (unsigned long *)&iocb->private)
  #define ocfs2_iocb_rw_locked_level(iocb) \
      test_bit(1, (unsigned long *)&iocb->private)
+#define ocfs2_iocb_set_sem_locked(iocb) \
+    set_bit(2, (unsigned long *)&iocb->private)
+#define ocfs2_iocb_clear_sem_locked(iocb) \
+    clear_bit(2, (unsigned long *)&iocb->private)
+#define ocfs2_iocb_is_sem_locked(iocb) \
+    test_bit(2, (unsigned long *)&iocb->private)
  #endif /* OCFS2_FILE_H */
fs/ocfs2/file.c +4 -1
index 77b4c04..4e66990 100644
@@ -2246,7 +2246,10 @@ relock:
      if (direct_io) {
          down_read(&inode->i_alloc_sem);
          have_alloc_sem = 1;
-    }
+        /* communicate with ocfs2_dio_end_io */
+        ocfs2_iocb_set_sem_locked(iocb);
+    } else
+        ocfs2_iocb_clear_sem_locked(iocb);
 
      /*
       * Concurrent O_DIRECT writes are allowed with