Skip to contentSkip to conversation

(no subject)

Ocfs2-devel New tao.ma at oracle.com 1 participant 3 messages Apr 30, 2008 1 message not in the archive OCFS2

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

.com>
Subject: [patch 1/2] ocfs2-1.2: Remove inode_alloc from handle when inode allocation fails.
Content-Disposition: inline; filename=journal.patch
Status: O
Content-Length: 3170
Lines: 88

When we fail to alloc an inode from the inode_alloc:000X, we need to remove that allocation inode from current transaction. Otherwise we may encounter dead lock when other nodes want to steal inode from us.

fs/ocfs2/journal.c +47 -0
Index: ocfs2-1.2/fs/ocfs2/journal.c
===================================================================
@@ -228,6 +228,53 @@ void ocfs2_handle_add_inode(struct ocfs2
 	list_add_tail(&(OCFS2_I(inode)->ip_handle_list), &(handle->inode_list));
 }
 
+/*
+ * This method is a bit tricky and break up the policy of normal inode
+ * operation in a journal transaction. It will remove the alloc inode
+ * and free its lock from the transaction.
+ * So it should only be used in inode stealing.
+ *
+ * The 1st part is copied from ocfs2_handle_unlock_inodes.
+ * The 2nd part is copied from ocfs2_handle_cleanup_locks.
+ */
+void  ocfs2_handle_remove_alloc_inode(struct ocfs2_journal_handle *handle,
+				      struct inode *inode)
+{
+	struct list_head *p, *n;
+	struct ocfs2_journal_lock *lock;
+
+	BUG_ON(!handle);
+	BUG_ON(!inode);
+	BUG_ON(!OCFS2_I(inode)->ip_handle);
+	BUG_ON(list_empty(&OCFS2_I(inode)->ip_handle_list));
+
+	OCFS2_I(inode)->ip_handle = NULL;
+	list_del_init(&OCFS2_I(inode)->ip_handle_list);
+
+	mutex_unlock(&inode->i_mutex);
+	iput(inode);
+
+	list_for_each_safe(p, n, &(handle->locks)) {
+		lock = list_entry(p, struct ocfs2_journal_lock,
+				  jl_lock_list);
+
+		if (inode == lock->jl_inode) {
+			list_del(&lock->jl_lock_list);
+			handle->num_locks--;
+
+			ocfs2_meta_unlock(inode, 1);
+			if (atomic_read(&inode->i_count) == 1)
+				mlog(ML_ERROR,
+				     "Inode %"MLFu64", "
+				     "I'm doing a last iput for!",
+				     OCFS2_I(inode)->ip_blkno);
+			iput(inode);
+			kmem_cache_free(ocfs2_lock_cache, lock);
+			break;
+		}
+	}
+}
+
 static void ocfs2_handle_unlock_inodes(struct ocfs2_journal_handle *handle)
 {
 	struct list_head *p, *n;
fs/ocfs2/journal.h +5 -0
Index: ocfs2-1.2/fs/ocfs2/journal.h
===================================================================
@@ -256,6 +256,9 @@ static inline void ocfs2_checkpoint_inod
  *                          to be released at the end of that handle. Locks
  *                          will be released in the order that they are added.
  *  ocfs2_handle_add_inode - Add a locked inode to a transaction.
+ *
+ *  ocfs2_handle_remove_alloc_inode - Remove a locked alloc inode from a
+ *                        transaction. It should only be used in inode stealing.
  */
 
 /* You must always start_trans with a number of buffs > 0, but it's
@@ -318,6 +321,8 @@ int                  ocfs2_handle_add_lo
 void                 ocfs2_handle_add_inode(struct ocfs2_journal_handle *handle,
 					    struct inode *inode);
 
+void ocfs2_handle_remove_alloc_inode(struct ocfs2_journal_handle *handle,
+				     struct inode *inode);
 /*
  *  Credit Macros:
  *  Convenience macros to calculate number of credits needed.
#2 lore raw

PATCH 1/2 ocfs2-1.2: Remove inode_alloc from handle when inode allocation fails.

In reply to a message not in the archive

When we fail to alloc an inode from the inode_alloc:000X, we need to remove that allocation inode from current transaction. Otherwise we may encounter dead lock when other nodes want to steal inode from us.

fs/ocfs2/journal.c +47 -0
Index: ocfs2-1.2/fs/ocfs2/journal.c
===================================================================
@@ -228,6 +228,53 @@ void ocfs2_handle_add_inode(struct ocfs2
 	list_add_tail(&(OCFS2_I(inode)->ip_handle_list), &(handle->inode_list));
 }
 
+/*
+ * This method is a bit tricky and break up the policy of normal inode
+ * operation in a journal transaction. It will remove the alloc inode
+ * and free its lock from the transaction.
+ * So it should only be used in inode stealing.
+ *
+ * The 1st part is copied from ocfs2_handle_unlock_inodes.
+ * The 2nd part is copied from ocfs2_handle_cleanup_locks.
+ */
+void  ocfs2_handle_remove_alloc_inode(struct ocfs2_journal_handle *handle,
+				      struct inode *inode)
+{
+	struct list_head *p, *n;
+	struct ocfs2_journal_lock *lock;
+
+	BUG_ON(!handle);
+	BUG_ON(!inode);
+	BUG_ON(!OCFS2_I(inode)->ip_handle);
+	BUG_ON(list_empty(&OCFS2_I(inode)->ip_handle_list));
+
+	OCFS2_I(inode)->ip_handle = NULL;
+	list_del_init(&OCFS2_I(inode)->ip_handle_list);
+
+	mutex_unlock(&inode->i_mutex);
+	iput(inode);
+
+	list_for_each_safe(p, n, &(handle->locks)) {
+		lock = list_entry(p, struct ocfs2_journal_lock,
+				  jl_lock_list);
+
+		if (inode == lock->jl_inode) {
+			list_del(&lock->jl_lock_list);
+			handle->num_locks--;
+
+			ocfs2_meta_unlock(inode, 1);
+			if (atomic_read(&inode->i_count) == 1)
+				mlog(ML_ERROR,
+				     "Inode %"MLFu64", "
+				     "I'm doing a last iput for!",
+				     OCFS2_I(inode)->ip_blkno);
+			iput(inode);
+			kmem_cache_free(ocfs2_lock_cache, lock);
+			break;
+		}
+	}
+}
+
 static void ocfs2_handle_unlock_inodes(struct ocfs2_journal_handle *handle)
 {
 	struct list_head *p, *n;
fs/ocfs2/journal.h +5 -0
Index: ocfs2-1.2/fs/ocfs2/journal.h
===================================================================
@@ -256,6 +256,9 @@ static inline void ocfs2_checkpoint_inod
  *                          to be released at the end of that handle. Locks
  *                          will be released in the order that they are added.
  *  ocfs2_handle_add_inode - Add a locked inode to a transaction.
+ *
+ *  ocfs2_handle_remove_alloc_inode - Remove a locked alloc inode from a
+ *                        transaction. It should only be used in inode stealing.
  */
 
 /* You must always start_trans with a number of buffs > 0, but it's
@@ -318,6 +321,8 @@ int                  ocfs2_handle_add_lo
 void                 ocfs2_handle_add_inode(struct ocfs2_journal_handle *handle,
 					    struct inode *inode);
 
+void ocfs2_handle_remove_alloc_inode(struct ocfs2_journal_handle *handle,
+				     struct inode *inode);
 /*
  *  Credit Macros:
  *  Convenience macros to calculate number of credits needed.
#3 lore raw

PATCH 2/2 ocfs2-1.2: Add inode stealing for ocfs2_reserve_new_inode

In reply to a message not in the archive

Inode allocation is modified to look in other nodes allocators during extreme out of space situations. We retry our own slot when space is freed back to the global bitmap, or whenever we've allocated more than 1024 inode from another slot.

fs/ocfs2/alloc.c +2 -0
Index: ocfs2-1.2/fs/ocfs2/alloc.c
===================================================================
@@ -1213,6 +1213,8 @@ static void ocfs2_truncate_log_worker(vo
 	status = ocfs2_flush_truncate_log(osb);
 	if (status < 0)
 		mlog_errno(status);
+	else
+		ocfs2_init_inode_steal_slot(osb);
 
 	mlog_exit(status);
 }
fs/ocfs2/localalloc.c +3 -0
Index: ocfs2-1.2/fs/ocfs2/localalloc.c
===================================================================
@@ -440,6 +440,9 @@ bail:
 	if (main_bm_inode)
 		iput(main_bm_inode);
 
+	if (!status)
+		ocfs2_init_inode_steal_slot(osb);
+
 	mlog_exit(status);
 	return status;
 }
fs/ocfs2/namei.c +1 -1
Index: ocfs2-1.2/fs/ocfs2/namei.c
===================================================================
@@ -527,7 +527,7 @@ static int ocfs2_mknod_locked(struct ocf
 	fe->i_fs_generation = cpu_to_le32(osb->fs_generation);
 	fe->i_blkno = cpu_to_le64(fe_blkno);
 	fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
-	fe->i_suballoc_slot = cpu_to_le16(osb->slot_num);
+	fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
 	fe->i_uid = cpu_to_le32(current->fsuid);
 	if (dir->i_mode & S_ISGID) {
 		fe->i_gid = cpu_to_le32(dir->i_gid);
fs/ocfs2/ocfs2.h +32 -2
Index: ocfs2-1.2/fs/ocfs2/ocfs2.h
===================================================================
@@ -224,11 +224,14 @@ struct ocfs2_super
 	u32 s_feature_incompat;
 	u32 s_feature_ro_compat;
 
-	/* Protects s_next_generaion, osb_flags. Could protect more on
-	 * osb as it's very short lived. */
+	/* Protects s_next_generation, osb_flags and s_inode_steal_slot.
+	 * Could protect more on osb as it's very short lived.
+	 */
 	spinlock_t osb_lock;
 	u32 s_next_generation;
 	unsigned long osb_flags;
+	s16 s_inode_steal_slot;
+	atomic_t s_num_inodes_stolen;
 
 	unsigned long s_mount_opt;
 
@@ -456,6 +459,33 @@ static inline unsigned long ocfs2_align_
 	return (unsigned long)((bytes + 511) >> 9);
 }
 
+static inline void ocfs2_init_inode_steal_slot(struct ocfs2_super *osb)
+{
+	spin_lock(&osb->osb_lock);
+	osb->s_inode_steal_slot = OCFS2_INVALID_SLOT;
+	spin_unlock(&osb->osb_lock);
+	atomic_set(&osb->s_num_inodes_stolen, 0);
+}
+
+static inline void ocfs2_set_inode_steal_slot(struct ocfs2_super *osb,
+					      s16 slot)
+{
+	spin_lock(&osb->osb_lock);
+	osb->s_inode_steal_slot = slot;
+	spin_unlock(&osb->osb_lock);
+}
+
+static inline s16 ocfs2_get_inode_steal_slot(struct ocfs2_super *osb)
+{
+	s16 slot;
+
+	spin_lock(&osb->osb_lock);
+	slot = osb->s_inode_steal_slot;
+	spin_unlock(&osb->osb_lock);
+
+	return slot;
+}
+
 #define ocfs2_set_bit ext2_set_bit
 #define ocfs2_clear_bit ext2_clear_bit
 #define ocfs2_test_bit ext2_test_bit
fs/ocfs2/suballoc.c +134 -13

223 lines not on this page · raw message

fs/ocfs2/suballoc.h +1 -0
Index: ocfs2-1.2/fs/ocfs2/suballoc.h
===================================================================
@@ -36,6 +36,7 @@ typedef int (group_search_t)(struct inod
 struct ocfs2_alloc_context {
 	struct inode *ac_inode;    /* which bitmap are we allocating from? */
 	struct buffer_head *ac_bh; /* file entry bh */
+	u32    ac_alloc_slot;   /* which slot are we allocating from? */
 	u32    ac_bits_wanted;
 	u32    ac_bits_given;
 #define OCFS2_AC_USE_LOCAL 1
fs/ocfs2/super.c +1 -0
Index: ocfs2-1.2/fs/ocfs2/super.c
===================================================================
@@ -1371,6 +1371,7 @@ static int ocfs2_initialize_super(struct
 	osb->blocked_lock_count = 0;
 	INIT_LIST_HEAD(&osb->vote_list);
 	spin_lock_init(&osb->osb_lock);
+	ocfs2_init_inode_steal_slot(osb);
 
 	osb->osb_okp_teardown_next = NULL;
 	atomic_set(&osb->osb_okp_pending, 0);