Skip to contentSkip to conversation

ocfs2: add nowait aio support

PATCH Superseded Gang He 3 participants 10 messages Nov 29, 2017 – Nov 30, 2017 OCFS2

v2 of 4 Superseded 1 of 3 applied Latest is v4 →

lore
Share & tools
lore

Gang He

author
#0 lore raw

v2 cover ocfs2: add nowait aio support

As you know, VFS layer has introduced non-block aio flag IOCB_NOWAIT, which informs kernel to bail out if an AIO request will block for reasons such as file allocations, or a writeback triggered, or would block while allocating requests while performing direct I/O. Subsequent, pwritev2/preadv2 also can leverage this part kernel code.
So far, ext4/xfs/btrfs have supported this feature, I'd like to add the related code for ocfs2 file system.

Compare with v1, some changes are as below,
use osb pointer in ocfs2_try_rw_lock() function, modify ocfs2_overwrite_io() function to make all error value can be returned to the upper code,
move invoking ocfs2_overwrite_io() function from ocfs2_file_write_iter() to ocfs2_prepare_inode_for_write(), this change can combine acquiring the related locks.

Gang He (3):
ocfs2: add ocfs2_try_rw_lock and ocfs2_try_inode_lock
ocfs2: add ocfs2_overwrite_io function
ocfs2: nowait aio support

 fs/ocfs2/dir.c         |  2 +-
 fs/ocfs2/dlmglue.c     | 41 +++++++++++++++++++---
 fs/ocfs2/dlmglue.h     |  6 +++-
 fs/ocfs2/extent_map.c  | 41 ++++++++++++++++++++++
 fs/ocfs2/extent_map.h  |  3 ++
 fs/ocfs2/file.c        | 95 +++++++++++++++++++++++++++++++++++++++-----------
 fs/ocfs2/mmap.c        |  2 +-
 fs/ocfs2/ocfs2_trace.h | 10 +++---
 8 files changed, 168 insertions(+), 32 deletions(-)
Signature · 1 line
1.8.5.6
author
#1 lore raw

PATCH v2 1/3 ocfs2: add ocfs2_try_rw_lock and ocfs2_try_inode_lock

Add ocfs2_try_rw_lock and ocfs2_try_inode_lock functions, which will be used in non-block IO scenarios.

---
 fs/ocfs2/dlmglue.c | 21 +++++++++++++++++++++
 fs/ocfs2/dlmglue.h |  4 ++++
 2 files changed, 25 insertions(+)
fs/ocfs2/dlmglue.c +21 -0
index 4689940..a68efa3 100644
@@ -1742,6 +1742,27 @@ int ocfs2_rw_lock(struct inode *inode, int write)
 	return status;
 }
 
+int ocfs2_try_rw_lock(struct inode *inode, int write)
+{
+	int status, level;
+	struct ocfs2_lock_res *lockres;
+	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+
+	mlog(0, "inode %llu try to take %s RW lock\n",
+	     (unsigned long long)OCFS2_I(inode)->ip_blkno,
+	     write ? "EXMODE" : "PRMODE");
+
+	if (ocfs2_mount_local(osb))
+		return 0;
+
+	lockres = &OCFS2_I(inode)->ip_rw_lockres;
+
+	level = write ? DLM_LOCK_EX : DLM_LOCK_PR;
+
+	status = ocfs2_cluster_lock(osb, lockres, level, DLM_LKF_NOQUEUE, 0);
+	return status;
+}
+
 void ocfs2_rw_unlock(struct inode *inode, int write)
 {
 	int level = write ? DLM_LOCK_EX : DLM_LOCK_PR;
fs/ocfs2/dlmglue.h +4 -0
index a7fc18b..05910fc 100644
@@ -116,6 +116,7 @@ void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res *lockres,
 int ocfs2_create_new_inode_locks(struct inode *inode);
 int ocfs2_drop_inode_locks(struct inode *inode);
 int ocfs2_rw_lock(struct inode *inode, int write);
+int ocfs2_try_rw_lock(struct inode *inode, int write);
 void ocfs2_rw_unlock(struct inode *inode, int write);
 int ocfs2_open_lock(struct inode *inode);
 int ocfs2_try_open_lock(struct inode *inode, int write);
@@ -140,6 +141,9 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 /* 99% of the time we don't want to supply any additional flags --
  * those are for very specific cases only. */
 #define ocfs2_inode_lock(i, b, e) ocfs2_inode_lock_full_nested(i, b, e, 0, OI_LS_NORMAL)
+#define ocfs2_try_inode_lock(i, b, e)\
+		ocfs2_inode_lock_full_nested(i, b, e, OCFS2_META_LOCK_NOQUEUE,\
+		OI_LS_NORMAL)
 void ocfs2_inode_unlock(struct inode *inode,
 		       int ex);
 int ocfs2_super_lock(struct ocfs2_super *osb,
Signature · 1 line
1.8.5.6
Reviewed-by on v2 1/3
#2 lore raw

Re: [Ocfs2-devel] [PATCH v2 1/3] ocfs2: add ocfs2_try_rw_lock and ocfs2_try_inode_lock

Quoted 4 lines · Gang He

Add ocfs2_try_rw_lock and ocfs2_try_inode_lock functions, which will be used in non-block IO scenarios.

Quoted 60 lines
---
 fs/ocfs2/dlmglue.c | 21 +++++++++++++++++++++
 fs/ocfs2/dlmglue.h |  4 ++++
 2 files changed, 25 insertions(+)
fs/ocfs2/dlmglue.c +21 -0
index 4689940..a68efa3 100644
@@ -1742,6 +1742,27 @@ int ocfs2_rw_lock(struct inode *inode, int write)
 	return status;
 }
 
+int ocfs2_try_rw_lock(struct inode *inode, int write)
+{
+	int status, level;
+	struct ocfs2_lock_res *lockres;
+	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+
+	mlog(0, "inode %llu try to take %s RW lock\n",
+	     (unsigned long long)OCFS2_I(inode)->ip_blkno,
+	     write ? "EXMODE" : "PRMODE");
+
+	if (ocfs2_mount_local(osb))
+		return 0;
+
+	lockres = &OCFS2_I(inode)->ip_rw_lockres;
+
+	level = write ? DLM_LOCK_EX : DLM_LOCK_PR;
+
+	status = ocfs2_cluster_lock(osb, lockres, level, DLM_LKF_NOQUEUE, 0);
+	return status;
+}
+
 void ocfs2_rw_unlock(struct inode *inode, int write)
 {
 	int level = write ? DLM_LOCK_EX : DLM_LOCK_PR;
fs/ocfs2/dlmglue.h +4 -0
index a7fc18b..05910fc 100644
@@ -116,6 +116,7 @@ void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res *lockres,
 int ocfs2_create_new_inode_locks(struct inode *inode);
 int ocfs2_drop_inode_locks(struct inode *inode);
 int ocfs2_rw_lock(struct inode *inode, int write);
+int ocfs2_try_rw_lock(struct inode *inode, int write);
 void ocfs2_rw_unlock(struct inode *inode, int write);
 int ocfs2_open_lock(struct inode *inode);
 int ocfs2_try_open_lock(struct inode *inode, int write);
@@ -140,6 +141,9 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 /* 99% of the time we don't want to supply any additional flags --
  * those are for very specific cases only. */
 #define ocfs2_inode_lock(i, b, e) ocfs2_inode_lock_full_nested(i, b, e, 0, OI_LS_NORMAL)
+#define ocfs2_try_inode_lock(i, b, e)\
+		ocfs2_inode_lock_full_nested(i, b, e, OCFS2_META_LOCK_NOQUEUE,\
+		OI_LS_NORMAL)
 void ocfs2_inode_unlock(struct inode *inode,
 		       int ex);
 int ocfs2_super_lock(struct ocfs2_super *osb,
#3 lore raw

Re: [Ocfs2-devel] [PATCH v2 1/3] ocfs2: add ocfs2_try_rw_lock and ocfs2_try_inode_lock

In reply to Gang He
Quoted 25 lines · Gang He

Add ocfs2_try_rw_lock and ocfs2_try_inode_lock functions, which will be used in non-block IO scenarios.

---
  fs/ocfs2/dlmglue.c | 21 +++++++++++++++++++++
  fs/ocfs2/dlmglue.h |  4 ++++
  2 files changed, 25 insertions(+)
fs/ocfs2/dlmglue.c +8 -0
index 4689940..a68efa3 100644
@@ -1742,6 +1742,27 @@ int ocfs2_rw_lock(struct inode *inode, int write)
  	return status;
  }
 
+int ocfs2_try_rw_lock(struct inode *inode, int write)
+{
+	int status, level;
+	struct ocfs2_lock_res *lockres;
+	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+
+	mlog(0, "inode %llu try to take %s RW lock\n",
+	     (unsigned long long)OCFS2_I(inode)->ip_blkno,

fs/ocfs2/dlmglue.c int ocfs2_rw_lock(struct inode *inode, int write) · line 1762

Quoted 10 lines
fs/ocfs2/dlmglue.c +10 -0
+	     write ? "EXMODE" : "PRMODE");
+
+	if (ocfs2_mount_local(osb))
+		return 0;
+
+	lockres = &OCFS2_I(inode)->ip_rw_lockres;
+
+	level = write ? DLM_LOCK_EX : DLM_LOCK_PR;
+
+	status = ocfs2_cluster_lock(osb, lockres, level, DLM_LKF_NOQUEUE, 0);

Hi Gang,
Should we consider about passing a flag - OCFS2_LOCK_NONBLOCK to ocfs2_cluster_lock. Otherwise a cluster locking progress may be waiting for accomplishment of DC, which I think violates _NO_WAIT_ semantics.

Thanks,
Changwei.

Quoted 29 lines
fs/ocfs2/dlmglue.c +3 -0
+	return status;
+}
+
  void ocfs2_rw_unlock(struct inode *inode, int write)
  {
  	int level = write ? DLM_LOCK_EX : DLM_LOCK_PR;
fs/ocfs2/dlmglue.h +4 -0
index a7fc18b..05910fc 100644
@@ -116,6 +116,7 @@ void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res *lockres,
  int ocfs2_create_new_inode_locks(struct inode *inode);
  int ocfs2_drop_inode_locks(struct inode *inode);
  int ocfs2_rw_lock(struct inode *inode, int write);
+int ocfs2_try_rw_lock(struct inode *inode, int write);
  void ocfs2_rw_unlock(struct inode *inode, int write);
  int ocfs2_open_lock(struct inode *inode);
  int ocfs2_try_open_lock(struct inode *inode, int write);
@@ -140,6 +141,9 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
  /* 99% of the time we don't want to supply any additional flags --
   * those are for very specific cases only. */
  #define ocfs2_inode_lock(i, b, e) ocfs2_inode_lock_full_nested(i, b, e, 0, OI_LS_NORMAL)
+#define ocfs2_try_inode_lock(i, b, e)\
+		ocfs2_inode_lock_full_nested(i, b, e, OCFS2_META_LOCK_NOQUEUE,\
+		OI_LS_NORMAL)
  void ocfs2_inode_unlock(struct inode *inode,
  		       int ex);
  int ocfs2_super_lock(struct ocfs2_super *osb,
author
#4 lore raw

Re: [Ocfs2-devel] [PATCH v2 1/3] ocfs2: add ocfs2_try_rw_lock and ocfs2_try_inode_lock

Hello Changwei,

Quoted 34 lines
Quoted 1 line
Quoted 1 line
Quoted 32 lines · Gang He

Add ocfs2_try_rw_lock and ocfs2_try_inode_lock functions, which will be used in non-block IO scenarios.

---
  fs/ocfs2/dlmglue.c | 21 +++++++++++++++++++++
  fs/ocfs2/dlmglue.h |  4 ++++
  2 files changed, 25 insertions(+)
fs/ocfs2/dlmglue.c +15 -0
index 4689940..a68efa3 100644
@@ -1742,6 +1742,27 @@ int ocfs2_rw_lock(struct inode *inode, int write)
  	return status;
  }
 
+int ocfs2_try_rw_lock(struct inode *inode, int write)
+{
+	int status, level;
+	struct ocfs2_lock_res *lockres;
+	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+
+	mlog(0, "inode %llu try to take %s RW lock\n",
+	     (unsigned long long)OCFS2_I(inode)->ip_blkno,
+	     write ? "EXMODE" : "PRMODE");
+
+	if (ocfs2_mount_local(osb))
+		return 0;
+
+	lockres = &OCFS2_I(inode)->ip_rw_lockres;
+
Quoted 8 lines

fs/ocfs2/dlmglue.c int ocfs2_rw_lock(struct inode *inode, int write) · line 1762

Quoted 3 lines
fs/ocfs2/dlmglue.c +3 -0
+	level = write ? DLM_LOCK_EX : DLM_LOCK_PR;
+
+	status = ocfs2_cluster_lock(osb, lockres, level, DLM_LKF_NOQUEUE, 0);

Hi Gang,
Should we consider about passing a flag - OCFS2_LOCK_NONBLOCK to ocfs2_cluster_lock. Otherwise a cluster locking progress may be waiting for accomplishment of DC, which I think violates _NO_WAIT_ semantics.

If ocfs2 is a local file system, we should not wait for any condition, but for a cluster file system,
we cannot avoid this totally according to the current DLM lock design, we need to wait for a little to get lock for the first time. Why do we not use OCFS2_LOCK_NONBLOCK flag to get a lock?
since this flag is not stable to get a lock no matter this lock is occupied by other nodes, or not.
If you use OCFS2_LOCK_NONBLOCK flag to get a fresh lock, you possibly fail or success, depends on when the lock acquisition callback happens. So, I think DLM_LKF_NOQUEUE flag should be more matched to _NO_WAIT_ semantics.
we always get a fresh lock successfully, always failed if the lock is/was occupied by other nodes.
This flag can give us a consistent locking behavior.

Thanks
Gang

Quoted 35 lines

Thanks,
Changwei.

fs/ocfs2/dlmglue.h void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res

Quoted 11 lines
fs/ocfs2/dlmglue.c +3 -0
+	return status;
+}
+
  void ocfs2_rw_unlock(struct inode *inode, int write)
  {
  	int level = write ? DLM_LOCK_EX : DLM_LOCK_PR;
fs/ocfs2/dlmglue.h +0 -0
index a7fc18b..05910fc 100644
@@ -116,6 +116,7 @@ void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res 

*lockres,

fs/ocfs2/dlmglue.h int ocfs2_inode_lock_with_page(struct inode *inode, · line 143

Quoted 11 lines
fs/ocfs2/dlmglue.h +1 -0
  int ocfs2_create_new_inode_locks(struct inode *inode);
  int ocfs2_drop_inode_locks(struct inode *inode);
  int ocfs2_rw_lock(struct inode *inode, int write);
+int ocfs2_try_rw_lock(struct inode *inode, int write);
  void ocfs2_rw_unlock(struct inode *inode, int write);
  int ocfs2_open_lock(struct inode *inode);
  int ocfs2_try_open_lock(struct inode *inode, int write);
@@ -140,6 +141,9 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
  /* 99% of the time we don't want to supply any additional flags --
   * those are for very specific cases only. */
  #define ocfs2_inode_lock(i, b, e) ocfs2_inode_lock_full_nested(i, b, e, 0, 

OI_LS_NORMAL)

Quoted 7 lines
fs/ocfs2/dlmglue.h +3 -0
+#define ocfs2_try_inode_lock(i, b, e)\
+		ocfs2_inode_lock_full_nested(i, b, e, OCFS2_META_LOCK_NOQUEUE,\
+		OI_LS_NORMAL)
  void ocfs2_inode_unlock(struct inode *inode,
  		       int ex);
  int ocfs2_super_lock(struct ocfs2_super *osb,
#5 lore raw

Re: [Ocfs2-devel] [PATCH v2 1/3] ocfs2: add ocfs2_try_rw_lock and ocfs2_try_inode_lock

Hi Gang,

Quoted 46 lines · Gang He

Hello Changwei,

Quoted 34 lines
Quoted 1 line
Quoted 1 line
Quoted 32 lines · Gang He

Add ocfs2_try_rw_lock and ocfs2_try_inode_lock functions, which will be used in non-block IO scenarios.

---
   fs/ocfs2/dlmglue.c | 21 +++++++++++++++++++++
   fs/ocfs2/dlmglue.h |  4 ++++
   2 files changed, 25 insertions(+)
fs/ocfs2/dlmglue.c +15 -0
index 4689940..a68efa3 100644
@@ -1742,6 +1742,27 @@ int ocfs2_rw_lock(struct inode *inode, int write)
   	return status;
   }
 
+int ocfs2_try_rw_lock(struct inode *inode, int write)
+{
+	int status, level;
+	struct ocfs2_lock_res *lockres;
+	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+
+	mlog(0, "inode %llu try to take %s RW lock\n",
+	     (unsigned long long)OCFS2_I(inode)->ip_blkno,
+	     write ? "EXMODE" : "PRMODE");
+
+	if (ocfs2_mount_local(osb))
+		return 0;
+
+	lockres = &OCFS2_I(inode)->ip_rw_lockres;
+
Quoted 8 lines

fs/ocfs2/dlmglue.c int ocfs2_rw_lock(struct inode *inode, int write) · line 1762

Quoted 3 lines
fs/ocfs2/dlmglue.c +3 -0
+	level = write ? DLM_LOCK_EX : DLM_LOCK_PR;
+
+	status = ocfs2_cluster_lock(osb, lockres, level, DLM_LKF_NOQUEUE, 0);

Hi Gang,
Should we consider about passing a flag - OCFS2_LOCK_NONBLOCK to ocfs2_cluster_lock. Otherwise a cluster locking progress may be waiting for accomplishment of DC, which I think violates _NO_WAIT_ semantics.

Quoted 4 lines

If ocfs2 is a local file system, we should not wait for any condition, but for a cluster file system,
we cannot avoid this totally according to the current DLM lock design, we need to wait for a little to get lock for the first time. Why do we not use OCFS2_LOCK_NONBLOCK flag to get a lock?
since this flag is not stable to get a lock no matter this lock is occupied by other nodes, or not.

I suppose local node must be granted under the condition that it is marked with *OCFS2_LOCK_BLOCKED*. And the control flag _OCFS2_LOCK_NONBLOCK_ will make lock progress directly return -EAGAIN without any waiting.

Quoted 2 lines

If you use OCFS2_LOCK_NONBLOCK flag to get a fresh lock, you possibly fail or success, depends on when the lock acquisition callback happens. So, I think DLM_LKF_NOQUEUE flag should be more matched to _NO_WAIT_ semantics.

I thinks OCFS2_LOCK_NONBLOCK doesn't conflict DLM_LKF_NOQUEUE, they are the forth and fifth argument respectively.

Quoted 1 line

we always get a fresh lock successfully, always failed if the lock is/was occupied by other nodes.

What do you mean by a fresh lock? A lock that is never granted or acquired? If a lock is marked with OCFS2_LOCK_BLOCKED, local node must has acquired it.

Thanks,
Changwei

Quoted 44 lines

This flag can give us a consistent locking behavior.

Thanks
Gang

Quoted 35 lines

Thanks,
Changwei.

fs/ocfs2/dlmglue.h void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res

Quoted 11 lines
fs/ocfs2/dlmglue.c +3 -0
+	return status;
+}
+
   void ocfs2_rw_unlock(struct inode *inode, int write)
   {
   	int level = write ? DLM_LOCK_EX : DLM_LOCK_PR;
fs/ocfs2/dlmglue.h +0 -0
index a7fc18b..05910fc 100644
@@ -116,6 +116,7 @@ void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res

*lockres,

fs/ocfs2/dlmglue.h int ocfs2_inode_lock_with_page(struct inode *inode, · line 143

Quoted 11 lines
fs/ocfs2/dlmglue.h +1 -0
   int ocfs2_create_new_inode_locks(struct inode *inode);
   int ocfs2_drop_inode_locks(struct inode *inode);
   int ocfs2_rw_lock(struct inode *inode, int write);
+int ocfs2_try_rw_lock(struct inode *inode, int write);
   void ocfs2_rw_unlock(struct inode *inode, int write);
   int ocfs2_open_lock(struct inode *inode);
   int ocfs2_try_open_lock(struct inode *inode, int write);
@@ -140,6 +141,9 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
   /* 99% of the time we don't want to supply any additional flags --
    * those are for very specific cases only. */
   #define ocfs2_inode_lock(i, b, e) ocfs2_inode_lock_full_nested(i, b, e, 0,

OI_LS_NORMAL)

Quoted 7 lines
fs/ocfs2/dlmglue.h +3 -0
+#define ocfs2_try_inode_lock(i, b, e)\
+		ocfs2_inode_lock_full_nested(i, b, e, OCFS2_META_LOCK_NOQUEUE,\
+		OI_LS_NORMAL)
   void ocfs2_inode_unlock(struct inode *inode,
   		       int ex);
   int ocfs2_super_lock(struct ocfs2_super *osb,
author
#6 lore raw

Re: [Ocfs2-devel] [PATCH v2 1/3] ocfs2: add ocfs2_try_rw_lock and ocfs2_try_inode_lock

Hi Changwei,

Quoted 62 lines
Quoted 1 line
Quoted 1 line

Hi Gang,

Quoted 46 lines · Gang He

Hello Changwei,

Quoted 34 lines
Quoted 1 line
Quoted 1 line
Quoted 32 lines · Gang He

Add ocfs2_try_rw_lock and ocfs2_try_inode_lock functions, which will be used in non-block IO scenarios.

---
   fs/ocfs2/dlmglue.c | 21 +++++++++++++++++++++
   fs/ocfs2/dlmglue.h |  4 ++++
   2 files changed, 25 insertions(+)
fs/ocfs2/dlmglue.c +15 -0
index 4689940..a68efa3 100644
@@ -1742,6 +1742,27 @@ int ocfs2_rw_lock(struct inode *inode, int write)
   	return status;
   }
 
+int ocfs2_try_rw_lock(struct inode *inode, int write)
+{
+	int status, level;
+	struct ocfs2_lock_res *lockres;
+	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+
+	mlog(0, "inode %llu try to take %s RW lock\n",
+	     (unsigned long long)OCFS2_I(inode)->ip_blkno,
+	     write ? "EXMODE" : "PRMODE");
+
+	if (ocfs2_mount_local(osb))
+		return 0;
+
+	lockres = &OCFS2_I(inode)->ip_rw_lockres;
+
Quoted 8 lines

fs/ocfs2/dlmglue.c int ocfs2_rw_lock(struct inode *inode, int write) · line 1762

Quoted 3 lines
fs/ocfs2/dlmglue.c +3 -0
+	level = write ? DLM_LOCK_EX : DLM_LOCK_PR;
+
+	status = ocfs2_cluster_lock(osb, lockres, level, DLM_LKF_NOQUEUE, 0);

Hi Gang,
Should we consider about passing a flag - OCFS2_LOCK_NONBLOCK to ocfs2_cluster_lock. Otherwise a cluster locking progress may be waiting for accomplishment of DC, which I think violates _NO_WAIT_ semantics.

Quoted 1 line

If ocfs2 is a local file system, we should not wait for any condition, but

for a cluster file system,

Quoted 1 line

we cannot avoid this totally according to the current DLM lock design, we

need to wait for a little to get lock for the first time.

Quoted 2 lines

Why do we not use OCFS2_LOCK_NONBLOCK flag to get a lock?
since this flag is not stable to get a lock no matter this lock is occupied

by other nodes, or not.
I suppose local node must be granted under the condition that it is marked with *OCFS2_LOCK_BLOCKED*. And the control flag _OCFS2_LOCK_NONBLOCK_ will make lock progress directly return -EAGAIN without any waiting.

Quoted 7 lines
Quoted 1 line

If you use OCFS2_LOCK_NONBLOCK flag to get a fresh lock, you possibly fail

or success, depends on when the lock acquisition callback happens.

Quoted 1 line

So, I think DLM_LKF_NOQUEUE flag should be more matched to _NO_WAIT_

semantics.

I thinks OCFS2_LOCK_NONBLOCK doesn't conflict DLM_LKF_NOQUEUE, they are the forth and fifth argument respectively.

Two arguments doesn't conflict,
but the _OCFS2_LOCK_NONBLOCK_ flag will bring the uncertainty of lock acquisition, since depends on when the lock acquisition callback happens. In the other words, you possibly do not get a lock for one time if passing the _OCFS2_LOCK_NONBLOCK_ flag.
I think that this flag is suitable to ocfs2_inode_lock_with_page case, since when we can not get the lock immediately, we can try it again and again. In actually, introducing this flag is to avoid a dead-lock case, a very tricky case.

Thanks
Gang

Quoted 56 lines
Quoted 2 lines

we always get a fresh lock successfully, always failed if the lock is/was

occupied by other nodes.

What do you mean by a fresh lock? A lock that is never granted or acquired? If a lock is marked with OCFS2_LOCK_BLOCKED, local node must has acquired it.

Thanks,
Changwei

Quoted 23 lines

This flag can give us a consistent locking behavior.

Thanks
Gang

Quoted 16 lines

Thanks,
Changwei.

fs/ocfs2/dlmglue.h void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res

Quoted 11 lines
fs/ocfs2/dlmglue.c +3 -0
+	return status;
+}
+
   void ocfs2_rw_unlock(struct inode *inode, int write)
   {
   	int level = write ? DLM_LOCK_EX : DLM_LOCK_PR;
fs/ocfs2/dlmglue.h +0 -0
index a7fc18b..05910fc 100644
@@ -116,6 +116,7 @@ void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res

*lockres,

Quoted 11 lines
Quoted 11 lines

fs/ocfs2/dlmglue.h int ocfs2_inode_lock_with_page(struct inode *inode, · line 143

Quoted 11 lines
fs/ocfs2/dlmglue.h +1 -0
   int ocfs2_create_new_inode_locks(struct inode *inode);
   int ocfs2_drop_inode_locks(struct inode *inode);
   int ocfs2_rw_lock(struct inode *inode, int write);
+int ocfs2_try_rw_lock(struct inode *inode, int write);
   void ocfs2_rw_unlock(struct inode *inode, int write);
   int ocfs2_open_lock(struct inode *inode);
   int ocfs2_try_open_lock(struct inode *inode, int write);
@@ -140,6 +141,9 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
   /* 99% of the time we don't want to supply any additional flags --
    * those are for very specific cases only. */
   #define ocfs2_inode_lock(i, b, e) ocfs2_inode_lock_full_nested(i, b, e, 

0,

Quoted 10 lines
Quoted 8 lines

OI_LS_NORMAL)

Quoted 7 lines
fs/ocfs2/dlmglue.h +3 -0
+#define ocfs2_try_inode_lock(i, b, e)\
+		ocfs2_inode_lock_full_nested(i, b, e, OCFS2_META_LOCK_NOQUEUE,\
+		OI_LS_NORMAL)
   void ocfs2_inode_unlock(struct inode *inode,
   		       int ex);
   int ocfs2_super_lock(struct ocfs2_super *osb,
author
#7 lore raw

PATCH v2 2/3 ocfs2: add ocfs2_overwrite_io function

In reply to Gang He

Add ocfs2_overwrite_io function, which is used to judge if overwrite allocated blocks, otherwise, the write will bring extra block allocation overhead.

---
 fs/ocfs2/extent_map.c | 41 +++++++++++++++++++++++++++++++++++++++++
 fs/ocfs2/extent_map.h |  3 +++
 2 files changed, 44 insertions(+)
fs/ocfs2/extent_map.c +41 -0
index e4719e0..4da33e9 100644
@@ -832,6 +832,47 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 	return ret;
 }
 
+/* Is IO overwriting allocated blocks? */
+int ocfs2_overwrite_io(struct inode *inode, struct buffer_head *di_bh,
+		       u64 map_start, u64 map_len)
+{
+	int ret = 0, is_last;
+	u32 mapping_end, cpos;
+	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+	struct ocfs2_extent_rec rec;
+
+	if ((OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) &&
+	   ((map_start + map_len) <= i_size_read(inode)))
+		goto out;
+
+	cpos = map_start >> osb->s_clustersize_bits;
+	mapping_end = ocfs2_clusters_for_bytes(inode->i_sb,
+					       map_start + map_len);
+	is_last = 0;
+	while (cpos < mapping_end && !is_last) {
+		ret = ocfs2_get_clusters_nocache(inode, di_bh, cpos,
+						 NULL, &rec, &is_last);
+		if (ret) {
+			mlog_errno(ret);
+			goto out;
+		}
+
+		if (rec.e_blkno == 0ULL)
+			break;
+
+		if (rec.e_flags & OCFS2_EXT_REFCOUNTED)
+			break;
+
+		cpos = le32_to_cpu(rec.e_cpos) +
+			le16_to_cpu(rec.e_leaf_clusters);
+	}
+
+	if (cpos < mapping_end)
+		ret = -EAGAIN;
+out:
+	return ret;
+}
+
 int ocfs2_seek_data_hole_offset(struct file *file, loff_t *offset, int whence)
 {
 	struct inode *inode = file->f_mapping->host;
fs/ocfs2/extent_map.h +3 -0
index 67ea57d..1057586 100644
@@ -53,6 +53,9 @@ int ocfs2_extent_map_get_blocks(struct inode *inode, u64 v_blkno, u64 *p_blkno,
 int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 		 u64 map_start, u64 map_len);
 
+int ocfs2_overwrite_io(struct inode *inode, struct buffer_head *di_bh,
+		       u64 map_start, u64 map_len);
+
 int ocfs2_seek_data_hole_offset(struct file *file, loff_t *offset, int origin);
 
 int ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster,
Signature · 1 line
1.8.5.6
Reviewed-by on v2 2/3
#8 lore raw

Re: [Ocfs2-devel] [PATCH v2 2/3] ocfs2: add ocfs2_overwrite_io function

It looks fine to me.

Quoted 5 lines · Gang He

Add ocfs2_overwrite_io function, which is used to judge if overwrite allocated blocks, otherwise, the write will bring extra block allocation overhead.

Quoted 72 lines
---
  fs/ocfs2/extent_map.c | 41 +++++++++++++++++++++++++++++++++++++++++
  fs/ocfs2/extent_map.h |  3 +++
  2 files changed, 44 insertions(+)
fs/ocfs2/extent_map.c +41 -0
index e4719e0..4da33e9 100644
@@ -832,6 +832,47 @@ int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  	return ret;
  }
 
+/* Is IO overwriting allocated blocks? */
+int ocfs2_overwrite_io(struct inode *inode, struct buffer_head *di_bh,
+		       u64 map_start, u64 map_len)
+{
+	int ret = 0, is_last;
+	u32 mapping_end, cpos;
+	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+	struct ocfs2_extent_rec rec;
+
+	if ((OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) &&
+	   ((map_start + map_len) <= i_size_read(inode)))
+		goto out;
+
+	cpos = map_start >> osb->s_clustersize_bits;
+	mapping_end = ocfs2_clusters_for_bytes(inode->i_sb,
+					       map_start + map_len);
+	is_last = 0;
+	while (cpos < mapping_end && !is_last) {
+		ret = ocfs2_get_clusters_nocache(inode, di_bh, cpos,
+						 NULL, &rec, &is_last);
+		if (ret) {
+			mlog_errno(ret);
+			goto out;
+		}
+
+		if (rec.e_blkno == 0ULL)
+			break;
+
+		if (rec.e_flags & OCFS2_EXT_REFCOUNTED)
+			break;
+
+		cpos = le32_to_cpu(rec.e_cpos) +
+			le16_to_cpu(rec.e_leaf_clusters);
+	}
+
+	if (cpos < mapping_end)
+		ret = -EAGAIN;
+out:
+	return ret;
+}
+
  int ocfs2_seek_data_hole_offset(struct file *file, loff_t *offset, int whence)
  {
  	struct inode *inode = file->f_mapping->host;
fs/ocfs2/extent_map.h +3 -0
index 67ea57d..1057586 100644
@@ -53,6 +53,9 @@ int ocfs2_extent_map_get_blocks(struct inode *inode, u64 v_blkno, u64 *p_blkno,
  int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  		 u64 map_start, u64 map_len);
 
+int ocfs2_overwrite_io(struct inode *inode, struct buffer_head *di_bh,
+		       u64 map_start, u64 map_len);
+
  int ocfs2_seek_data_hole_offset(struct file *file, loff_t *offset, int origin);
 
  int ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster,
author
#9 lore raw

PATCH v2 3/3 ocfs2: nowait aio support

In reply to Gang He

Return -EAGAIN if any of the following checks fail for direct I/O with nowait flag:
Can not get the related locks immediately,
Blocks are not allocated at the write location, it will trigger block allocation, this will block IO operations.

---
 fs/ocfs2/dir.c         |  2 +-
 fs/ocfs2/dlmglue.c     | 20 ++++++++---
 fs/ocfs2/dlmglue.h     |  2 +-
 fs/ocfs2/file.c        | 95 +++++++++++++++++++++++++++++++++++++++-----------
 fs/ocfs2/mmap.c        |  2 +-
 fs/ocfs2/ocfs2_trace.h | 10 +++---
 6 files changed, 99 insertions(+), 32 deletions(-)
fs/ocfs2/dir.c +1 -1
index febe631..ea50901 100644
@@ -1957,7 +1957,7 @@ int ocfs2_readdir(struct file *file, struct dir_context *ctx)
 
 	trace_ocfs2_readdir((unsigned long long)OCFS2_I(inode)->ip_blkno);
 
-	error = ocfs2_inode_lock_atime(inode, file->f_path.mnt, &lock_level);
+	error = ocfs2_inode_lock_atime(inode, file->f_path.mnt, &lock_level, 1);
 	if (lock_level && error >= 0) {
 		/* We release EX lock which used to update atime
 		 * and get PR lock again to reduce contention
fs/ocfs2/dlmglue.c +15 -5
index a68efa3..07e169f 100644
@@ -2515,13 +2515,18 @@ int ocfs2_inode_lock_with_page(struct inode *inode,
 
 int ocfs2_inode_lock_atime(struct inode *inode,
 			  struct vfsmount *vfsmnt,
-			  int *level)
+			  int *level, int wait)
 {
 	int ret;
 
-	ret = ocfs2_inode_lock(inode, NULL, 0);
+	if (wait)
+		ret = ocfs2_inode_lock(inode, NULL, 0);
+	else
+		ret = ocfs2_try_inode_lock(inode, NULL, 0);
+
 	if (ret < 0) {
-		mlog_errno(ret);
+		if (ret != -EAGAIN)
+			mlog_errno(ret);
 		return ret;
 	}
 
@@ -2533,9 +2538,14 @@ int ocfs2_inode_lock_atime(struct inode *inode,
 		struct buffer_head *bh = NULL;
 
 		ocfs2_inode_unlock(inode, 0);
-		ret = ocfs2_inode_lock(inode, &bh, 1);
+		if (wait)
+			ret = ocfs2_inode_lock(inode, &bh, 1);
+		else
+			ret = ocfs2_try_inode_lock(inode, &bh, 1);
+
 		if (ret < 0) {
-			mlog_errno(ret);
+			if (ret != -EAGAIN)
+				mlog_errno(ret);
 			return ret;
 		}
 		*level = 1;
fs/ocfs2/dlmglue.h +1 -1
index 05910fc..c83dbb5 100644
@@ -123,7 +123,7 @@ void ocfs2_refcount_lock_res_init(struct ocfs2_lock_res *lockres,
 void ocfs2_open_unlock(struct inode *inode);
 int ocfs2_inode_lock_atime(struct inode *inode,
 			  struct vfsmount *vfsmnt,
-			  int *level);
+			  int *level, int wait);
 int ocfs2_inode_lock_full_nested(struct inode *inode,
 			 struct buffer_head **ret_bh,
 			 int ex,
fs/ocfs2/file.c +75 -20

189 lines not on this page · raw message

fs/ocfs2/mmap.c +1 -1
index 098f5c7..fb9a20e 100644
@@ -184,7 +184,7 @@ int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
 	int ret = 0, lock_level = 0;
 
 	ret = ocfs2_inode_lock_atime(file_inode(file),
-				    file->f_path.mnt, &lock_level);
+				    file->f_path.mnt, &lock_level, 1);
 	if (ret < 0) {
 		mlog_errno(ret);
 		goto out;
fs/ocfs2/ocfs2_trace.h +6 -4
index a0b5d00..e2a11aa 100644
@@ -1449,20 +1449,22 @@
 
 TRACE_EVENT(ocfs2_prepare_inode_for_write,
 	TP_PROTO(unsigned long long ino, unsigned long long saved_pos,
-		 unsigned long count),
-	TP_ARGS(ino, saved_pos, count),
+		 unsigned long count, int wait),
+	TP_ARGS(ino, saved_pos, count, wait),
 	TP_STRUCT__entry(
 		__field(unsigned long long, ino)
 		__field(unsigned long long, saved_pos)
 		__field(unsigned long, count)
+		__field(int, wait)
 	),
 	TP_fast_assign(
 		__entry->ino = ino;
 		__entry->saved_pos = saved_pos;
 		__entry->count = count;
+		__entry->wait = wait;
 	),
-	TP_printk("%llu %llu %lu", __entry->ino,
-		  __entry->saved_pos, __entry->count)
+	TP_printk("%llu %llu %lu %d", __entry->ino,
+		  __entry->saved_pos, __entry->count, __entry->wait)
 );
 
 DEFINE_OCFS2_INT_EVENT(generic_file_aio_read_ret);
Signature · 1 line
1.8.5.6