Skip to contentSkip to conversation

Disallow cluster_stack changes if fs are mounted

PATCH New Goldwyn Rodrigues 2 participants 2 messages Sep 6, 2013 – Sep 9, 2013 OCFS2

lore
Share & tools
lore
#0 lore raw

PATCH 6/6 Disallow cluster_stack changes if fs are mounted

---
 fs/ocfs2/stackglue.c | 18 ++++++++++++++++++
 fs/ocfs2/stackglue.h |  3 +++
 fs/ocfs2/super.c     |  2 ++
 3 files changed, 23 insertions(+)
fs/ocfs2/stackglue.c +18 -0
index 4dd732b..e352a2e 100644
@@ -41,6 +41,7 @@ static DEFINE_SPINLOCK(ocfs2_stack_lock);
 static LIST_HEAD(ocfs2_stack_list);
 static char cluster_stack_name[OCFS2_STACK_LABEL_LEN + 1];
 static char ocfs2_hb_ctl_path[OCFS2_MAX_HB_CTL_PATH] = "/sbin/ocfs2_hb_ctl";
+static atomic_t mount_count = ATOMIC_INIT(0);
 
 /*
  * The stack currently in use.  If not null, active_stack->sp_count > 0,
@@ -417,6 +418,18 @@ int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn,
 }
 EXPORT_SYMBOL_GPL(ocfs2_cluster_disconnect);
 
+void ocfs2_inc_mount_count()
+{
+	atomic_inc(&mount_count);
+}
+EXPORT_SYMBOL_GPL(ocfs2_inc_mount_count);
+
+void ocfs2_dec_mount_count()
+{
+	atomic_dec(&mount_count);
+}
+EXPORT_SYMBOL_GPL(ocfs2_dec_mount_count);
+
 /*
  * Leave the group for this filesystem.  This is executed by a userspace
  * program (stored in ocfs2_hb_ctl_path).
@@ -569,6 +582,11 @@ static ssize_t ocfs2_cluster_stack_store(struct kobject *kobj,
 	size_t len = count;
 	ssize_t ret;
 
+	if (atomic_read(&mount_count) > 0) {
+		printk(KERN_NOTICE "ocfs2_stackglue: Cannot set cluster_stack when filesystems are mounted.\n");
+		return -EINVAL;
+	}
+
 	if (len == 0)
 		return len;
 
fs/ocfs2/stackglue.h +3 -0
index c953290..9eeeff03 100644
@@ -291,6 +291,9 @@ int ocfs2_plock(struct ocfs2_cluster_connection *conn, u64 ino,
 
 void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_proto);
 
+void ocfs2_inc_mount_count(void);
+void ocfs2_dec_mount_count(void);
+
 
 /* Used by stack plugins */
 int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin);
fs/ocfs2/super.c +2 -0
index 60f3d8e..c91087c 100644
@@ -1214,6 +1214,7 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
 
 	/* Start this when the mount is almost sure of being successful */
 	ocfs2_orphan_scan_start(osb);
+	ocfs2_inc_mount_count();
 
 	return status;
 
@@ -1253,6 +1254,7 @@ static void ocfs2_kill_sb(struct super_block *sb)
 	spin_unlock(&dentry_list_lock);
 	/* Wait for work to finish and/or remove it */
 	cancel_work_sync(&osb->dentry_lock_work);
+	ocfs2_dec_mount_count();
 out:
 	kill_block_super(sb);
 }
Signature · 5 lines
1.8.1.4


-- 
Goldwyn
#1 lore raw

PATCH 6/6 Disallow cluster_stack changes if fs are mounted

Quoted 27 lines · Goldwyn Rodrigues
fs/ocfs2/stackglue.h +3 -0
index c953290..9eeeff03 100644
@@ -291,6 +291,9 @@ int ocfs2_plock(struct ocfs2_cluster_connection *conn, u64 ino,
 
 void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_proto);
 
+void ocfs2_inc_mount_count(void);
+void ocfs2_dec_mount_count(void);
+
 
 /* Used by stack plugins */
 int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin);
fs/ocfs2/super.c +1 -0
index 60f3d8e..c91087c 100644
@@ -1214,6 +1214,7 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
 
 	/* Start this when the mount is almost sure of being successful */
 	ocfs2_orphan_scan_start(osb);
+	ocfs2_inc_mount_count();
 
 	return status;
 

fs/ocfs2/super.c static void ocfs2_kill_sb(struct super_block *sb) · line 1260

Quoted 7 lines
fs/ocfs2/super.c +1 -0
@@ -1253,6 +1254,7 @@ static void ocfs2_kill_sb(struct super_block *sb)
 	spin_unlock(&dentry_list_lock);
 	/* Wait for work to finish and/or remove it */
 	cancel_work_sync(&osb->dentry_lock_work);
+	ocfs2_dec_mount_count();
 out:
 	kill_block_super(sb);
 }

Why not put these calls in ocfs2_dlm_init() and ocfs2_dlm_shutdown() ?

	--Mark

--
Mark Fasheh