[Ocfs2-commits] zab commits r2602 - branches/locking-changes/fs/ocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Thu Sep 22 11:45:28 CDT 2005


Author: zab
Date: 2005-09-22 11:45:24 -0500 (Thu, 22 Sep 2005)
New Revision: 2602

Modified:
   branches/locking-changes/fs/ocfs2/dlmglue.c
   branches/locking-changes/fs/ocfs2/dlmglue.h
   branches/locking-changes/fs/ocfs2/inode.c
   branches/locking-changes/fs/ocfs2/inode.h
   branches/locking-changes/fs/ocfs2/ocfs2_lockid.h
   branches/locking-changes/fs/ocfs2/super.c
Log:
o add the _rw_ lock, nothing uses it yet


Modified: branches/locking-changes/fs/ocfs2/dlmglue.c
===================================================================
--- branches/locking-changes/fs/ocfs2/dlmglue.c	2005-09-20 20:40:53 UTC (rev 2601)
+++ branches/locking-changes/fs/ocfs2/dlmglue.c	2005-09-22 16:45:24 UTC (rev 2602)
@@ -81,6 +81,8 @@
 			      int *requeue);
 static int ocfs2_unblock_data(struct ocfs2_lock_res *lockres,
 			      int *requeue);
+static int ocfs2_unblock_inode_lock(struct ocfs2_lock_res *lockres,
+			      int *requeue);
 static int ocfs2_unblock_osb_lock(struct ocfs2_lock_res *lockres,
 				  int *requeue);
 typedef void (ocfs2_convert_worker_t)(struct ocfs2_lock_res *, int);
@@ -96,6 +98,13 @@
 	int  (*unblock)(struct ocfs2_lock_res *, int *);
 };
 
+static struct ocfs2_lock_res_ops ocfs2_inode_rw_lops = {
+	.ast		= ocfs2_inode_ast_func,
+	.bast		= ocfs2_inode_bast_func,
+	.unlock_ast	= ocfs2_unlock_ast_func,
+	.unblock	= ocfs2_unblock_inode_lock,
+};
+
 static struct ocfs2_lock_res_ops ocfs2_inode_meta_lops = {
 	.ast		= ocfs2_inode_ast_func,
 	.bast		= ocfs2_inode_bast_func,
@@ -130,7 +139,8 @@
 static inline int ocfs2_is_inode_lock(struct ocfs2_lock_res *lockres)
 {
 	return lockres->l_type == OCFS2_LOCK_TYPE_META ||
-		lockres->l_type == OCFS2_LOCK_TYPE_DATA;
+		lockres->l_type == OCFS2_LOCK_TYPE_DATA ||
+		lockres->l_type == OCFS2_LOCK_TYPE_RW;
 }
 
 static inline int ocfs2_is_super_lock(struct ocfs2_lock_res *lockres)
@@ -208,6 +218,22 @@
 						  struct ocfs2_lock_res *lockres,
 						  int new_level);
 
+static char *ocfs2_lock_type_strings[] = {
+	[OCFS2_LOCK_TYPE_META] = "Meta",
+	[OCFS2_LOCK_TYPE_DATA] = "Data",
+	[OCFS2_LOCK_TYPE_SUPER] = "Super",
+	[OCFS2_LOCK_TYPE_RENAME] = "Rename",
+	/* Need to differntiate from [R]ename.. serializing writes is the
+	 * important job it does, anyway. */
+	[OCFS2_LOCK_TYPE_RW] = "Write/Read",
+};
+
+static char *ocfs2_lock_type_string(enum ocfs2_lock_type type)
+{
+	mlog_bug_on_msg(type >= OCFS2_NUM_LOCK_TYPES, "%d\n", type);
+	return ocfs2_lock_type_strings[type];
+}
+
 static inline int ocfs2_lvb_is_trustable(struct ocfs2_lock_res *lockres)
 {
 	struct ocfs2_lvb *lvb = (struct ocfs2_lvb *) lockres->l_lksb.lvb;
@@ -329,14 +355,22 @@
 {
 	struct ocfs2_lock_res_ops *ops;
 
-	BUG_ON(type != OCFS2_LOCK_TYPE_META &&
-	       type != OCFS2_LOCK_TYPE_DATA);
+	switch(type) {
+		case OCFS2_LOCK_TYPE_RW:
+			ops = &ocfs2_inode_rw_lops;
+			break;
+		case OCFS2_LOCK_TYPE_META:
+			ops = &ocfs2_inode_meta_lops;
+			break;
+		case OCFS2_LOCK_TYPE_DATA:
+			ops = &ocfs2_inode_data_lops;
+			break;
+		default:
+			mlog_bug_on_msg(1, "type: %d\n", type);
+			ops = NULL; /* thanks, gcc */
+			break;
+	};
 
-	if (type == OCFS2_LOCK_TYPE_META)
-		ops = &ocfs2_inode_meta_lops;
-	else
-		ops = &ocfs2_inode_data_lops;
-
 	ocfs2_lock_res_init_common(res, type, OCFS2_I(inode)->ip_blkno,
 				   inode->i_generation, ops, inode);
 }
@@ -550,7 +584,7 @@
 
 	mlog(0, "AST fired for inode %"MLFu64", l_action = %u, type = %s\n",
 	     OCFS2_I(inode)->ip_blkno, lockres->l_action,
-	     (lockres->l_type == OCFS2_LOCK_TYPE_META) ? "Meta" : "Data");
+	     ocfs2_lock_type_string(lockres->l_type));
 
 	BUG_ON(!ocfs2_is_inode_lock(lockres));
 
@@ -586,8 +620,8 @@
 		BUG();
 	}
 
-	/* data locking ignores refresh flag for now. */
-	if (lockres->l_type == OCFS2_LOCK_TYPE_DATA)
+	/* data and rw locking ignores refresh flag for now. */
+	if (lockres->l_type != OCFS2_LOCK_TYPE_META)
 		lockres_clear_flags(lockres, OCFS2_LOCK_NEEDS_REFRESH);
 
 	/* set it to something invalid so if we get called again we
@@ -663,7 +697,7 @@
 	mlog(0, "BAST fired for inode %"MLFu64", blocking = %d, level = %d "
 	     "type = %s\n", OCFS2_I(inode)->ip_blkno, level,
 	     lockres->l_level,
-	     (lockres->l_type == OCFS2_LOCK_TYPE_META) ? "Meta" : "Data");
+	     ocfs2_lock_type_string(lockres->l_type));
 
 	ocfs2_generic_bast_func(osb, lockres, level);
 
@@ -1042,6 +1076,19 @@
 	mlog_exit_void();
 }
 
+static int ocfs2_create_new_inode_lock(struct inode *inode,
+				       struct ocfs2_lock_res *lockres)
+{
+	ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+
+	spin_lock(&lockres->l_lock);
+	BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED);
+	lockres_or_flags(lockres, OCFS2_LOCK_LOCAL);
+	spin_unlock(&lockres->l_lock);
+
+	return ocfs2_lock_create(osb, lockres, LKM_EXMODE, LKM_LOCAL);
+}
+
 /* Grants us an EX lock on the data and metadata resources, skipping
  * the normal cluster directory lookup. Use this ONLY on newly created
  * inodes which other nodes can't possibly see, and which haven't been
@@ -1050,9 +1097,7 @@
  * with creating a new lock resource. */
 int ocfs2_create_new_inode_locks(struct inode *inode)
 {
-	int status;
-	ocfs2_super *osb = OCFS2_SB(inode->i_sb);
-	struct ocfs2_lock_res *lockres;
+	int ret;
 
 	BUG_ON(!inode);
 	BUG_ON(!ocfs2_inode_is_new(inode));
@@ -1069,38 +1114,73 @@
 	 * on a resource which has an invalid one -- we'll set it
 	 * valid when we release the EX. */
 
-	lockres = &OCFS2_I(inode)->ip_meta_lockres;
+	ret = ocfs2_create_new_inode_lock(inode,
+					  &OCFS2_I(inode)->ip_rw_lockres);
+	if (ret) {
+		mlog_errno(ret);
+		goto bail;
+	}
 
-	spin_lock(&lockres->l_lock);
-	BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED);
-	lockres_or_flags(lockres, OCFS2_LOCK_LOCAL);
-	spin_unlock(&lockres->l_lock);
+	ret = ocfs2_create_new_inode_lock(inode,
+					  &OCFS2_I(inode)->ip_meta_lockres);
+	if (ret) {
+		mlog_errno(ret);
+		goto bail;
+	}
 
-	status = ocfs2_lock_create(osb, lockres, LKM_EXMODE, LKM_LOCAL);
-	if (status < 0) {
-		mlog_errno(status);
+	ret = ocfs2_create_new_inode_lock(inode,
+					  &OCFS2_I(inode)->ip_data_lockres);
+	if (ret) {
+		mlog_errno(ret);
 		goto bail;
 	}
 
-	lockres = &OCFS2_I(inode)->ip_data_lockres;
+bail:
+	mlog_exit(ret);
+	return ret;
+}
 
-	spin_lock(&lockres->l_lock);
-	BUG_ON(lockres->l_flags & OCFS2_LOCK_ATTACHED);
-	lockres_or_flags(lockres, OCFS2_LOCK_LOCAL);
-	spin_unlock(&lockres->l_lock);
+int ocfs2_rw_lock(struct inode *inode, int write)
+{
+	int status, level;
+	struct ocfs2_lock_res *lockres;
 
-	status = ocfs2_lock_create(osb, lockres, LKM_EXMODE, LKM_LOCAL);
-	if (status < 0) {
+	BUG_ON(!inode);
+
+	mlog_entry_void();
+
+	mlog(0, "inode %"MLFu64" take %s RW lock\n",
+	     OCFS2_I(inode)->ip_blkno,
+	     write ? "EXMODE" : "PRMODE");
+
+	lockres = &OCFS2_I(inode)->ip_rw_lockres;
+
+	level = write ? LKM_EXMODE : LKM_PRMODE;
+
+	status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level, 0);
+	if (status < 0)
 		mlog_errno(status);
-		goto bail;
-	}
 
-	status = 0;
-bail:
 	mlog_exit(status);
 	return status;
 }
 
+void ocfs2_rw_unlock(struct inode *inode, int write)
+{
+	int level = write ? LKM_EXMODE : LKM_PRMODE;
+	struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_rw_lockres;
+
+	mlog_entry_void();
+
+	mlog(0, "inode %"MLFu64" drop %s RW lock\n",
+	     OCFS2_I(inode)->ip_blkno,
+	     write ? "EXMODE" : "PRMODE");
+
+	ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
+
+	mlog_exit_void();
+}
+
 int ocfs2_data_lock(struct inode *inode,
 		    int write)
 {
@@ -2024,6 +2104,14 @@
 	if (err < 0 && !status)
 		status = err;
 
+	err = ocfs2_drop_lock(OCFS2_SB(inode->i_sb),
+			      &OCFS2_I(inode)->ip_rw_lockres,
+			      NULL);
+	if (err < 0)
+		mlog_errno(err);
+	if (err < 0 && !status)
+		status = err;
+
 	mlog_exit(status);
 	return status;
 }
@@ -2368,6 +2456,30 @@
 	return status;
 }
 
+static int ocfs2_unblock_inode_lock(struct ocfs2_lock_res *lockres,
+				    int *requeue)
+{
+	int status;
+	struct inode *inode;
+
+	mlog_entry_void();
+
+	mlog(0, "Unblock lockres %s\n", lockres->l_name);
+
+	inode  = ocfs2_lock_res_inode(lockres);
+
+	status = ocfs2_generic_unblock_lock(OCFS2_SB(inode->i_sb),
+					    lockres,
+					    requeue,
+					    NULL);
+	if (status < 0)
+		mlog_errno(status);
+
+	mlog_exit(status);
+	return status;
+}
+
+
 int ocfs2_unblock_meta(struct ocfs2_lock_res *lockres,
 		       int *requeue)
 {

Modified: branches/locking-changes/fs/ocfs2/dlmglue.h
===================================================================
--- branches/locking-changes/fs/ocfs2/dlmglue.h	2005-09-20 20:40:53 UTC (rev 2601)
+++ branches/locking-changes/fs/ocfs2/dlmglue.h	2005-09-22 16:45:24 UTC (rev 2602)
@@ -91,6 +91,8 @@
 		    int write);
 void ocfs2_data_unlock(struct inode *inode,
 		       int write);
+int ocfs2_rw_lock(struct inode *inode, int write);
+void ocfs2_rw_unlock(struct inode *inode, int write);
 /* don't wait on recovery. */
 #define OCFS2_META_LOCK_RECOVERY	(0x01)
 /* Instruct the dlm not to queue ourselves on the other node. */

Modified: branches/locking-changes/fs/ocfs2/inode.c
===================================================================
--- branches/locking-changes/fs/ocfs2/inode.c	2005-09-20 20:40:53 UTC (rev 2601)
+++ branches/locking-changes/fs/ocfs2/inode.c	2005-09-22 16:45:24 UTC (rev 2602)
@@ -317,6 +317,8 @@
 		    break;
 	}
 
+	ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_rw_lockres,
+				  OCFS2_LOCK_TYPE_RW, inode);
 	ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_meta_lockres,
 				  OCFS2_LOCK_TYPE_META, inode);
 	ocfs2_inode_lock_res_init(&OCFS2_I(inode)->ip_data_lockres,
@@ -886,6 +888,7 @@
 	if (status < 0)
 		mlog_errno(status);
 
+	ocfs2_lock_res_free(&oi->ip_rw_lockres);
 	ocfs2_lock_res_free(&oi->ip_meta_lockres);
 	ocfs2_lock_res_free(&oi->ip_data_lockres);
 

Modified: branches/locking-changes/fs/ocfs2/inode.h
===================================================================
--- branches/locking-changes/fs/ocfs2/inode.h	2005-09-20 20:40:53 UTC (rev 2601)
+++ branches/locking-changes/fs/ocfs2/inode.h	2005-09-22 16:45:24 UTC (rev 2602)
@@ -31,6 +31,7 @@
 {
 	u64			ip_blkno;
 
+	struct ocfs2_lock_res	ip_rw_lockres;
 	struct ocfs2_lock_res	ip_meta_lockres;
 	struct ocfs2_lock_res	ip_data_lockres;
 

Modified: branches/locking-changes/fs/ocfs2/ocfs2_lockid.h
===================================================================
--- branches/locking-changes/fs/ocfs2/ocfs2_lockid.h	2005-09-20 20:40:53 UTC (rev 2601)
+++ branches/locking-changes/fs/ocfs2/ocfs2_lockid.h	2005-09-22 16:45:24 UTC (rev 2602)
@@ -40,6 +40,7 @@
 	OCFS2_LOCK_TYPE_DATA,
 	OCFS2_LOCK_TYPE_SUPER,
 	OCFS2_LOCK_TYPE_RENAME,
+	OCFS2_LOCK_TYPE_RW,
 	OCFS2_NUM_LOCK_TYPES
 };
 

Modified: branches/locking-changes/fs/ocfs2/super.c
===================================================================
--- branches/locking-changes/fs/ocfs2/super.c	2005-09-20 20:40:53 UTC (rev 2601)
+++ branches/locking-changes/fs/ocfs2/super.c	2005-09-22 16:45:24 UTC (rev 2602)
@@ -691,6 +691,7 @@
 		oi->ip_blkno = 0ULL;
 		oi->ip_clusters = 0;
 
+		ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
 		ocfs2_lock_res_init_once(&oi->ip_meta_lockres);
 		ocfs2_lock_res_init_once(&oi->ip_data_lockres);
 



More information about the Ocfs2-commits mailing list