[DRBD-cvs] drbd by lars; get the module count *right* :-/

drbd-user@lists.linbit.com drbd-user@lists.linbit.com
Sun, 16 May 2004 20:40:54 +0200 (CEST)


DRBD CVS committal

Author  : lars
Module  : drbd

Dir     : drbd/drbd


Modified Files:
      Tag: rel-0_7-branch
	drbd_fs.c 


Log Message:
get the module count *right* :-/
===================================================================
RCS file: /var/lib/cvs/drbd/drbd/drbd/drbd_fs.c,v
retrieving revision 1.28.2.89
retrieving revision 1.28.2.90
diff -u -3 -r1.28.2.89 -r1.28.2.90
--- drbd_fs.c	16 May 2004 14:44:08 -0000	1.28.2.89
+++ drbd_fs.c	16 May 2004 18:40:49 -0000	1.28.2.90
@@ -161,7 +161,7 @@
 			struct ioctl_disk_config * arg)
 {
 	NOT_IN_26(int err;) // unused in 26 ?? cannot believe it ...
-	int i, md_gc_valid, minor;
+	int i, md_gc_valid, minor, mput=0;
 	enum ret_codes retcode;
 	struct disk_config new_conf;
 	struct file *filp = 0;
@@ -172,9 +172,6 @@
 
 	minor=(int)(mdev-drbd_conf);
 
-	if (!try_module_get(THIS_MODULE))
-		return -EINVAL;
-
 	/* if you want to reconfigure, please tear down first */
 	smp_rmb();
 	if (!test_bit(DISKLESS,&mdev->flags))
@@ -191,6 +188,12 @@
 	if (copy_from_user(&new_conf, &arg->config,sizeof(struct disk_config)))
 		return -EFAULT;
 
+	if (mdev->cstate == Unconfigured) {
+		// ioctl already has a refcnt
+		__module_get(THIS_MODULE);
+		mput = 1;
+	}
+
 	if ( new_conf.meta_index < -1) {
 		retcode=LDMDInvalid;
 		goto fail_ioctl;
@@ -387,7 +390,7 @@
 	NOT_IN_26(blkdev_put(filp->f_dentry->d_inode->i_bdev,BDEV_FILE);)
 	ONLY_IN_26(bd_release(bdev);)
  fail_ioctl:
-	module_put(THIS_MODULE);
+	if (mput) module_put(THIS_MODULE);
 	if (filp) fput(filp);
 	if (filp2) fput(filp2);
 	if (put_user(retcode, &arg->ret_code)) return -EFAULT;
@@ -432,19 +435,22 @@
 STATIC
 int drbd_ioctl_set_net(struct Drbd_Conf *mdev, struct ioctl_net_config * arg)
 {
-	int i,minor;
+	int i,minor, mput=0;
 	enum ret_codes retcode;
 	struct net_config new_conf;
 
 	minor=(int)(mdev-drbd_conf);
 
-	if (!try_module_get(THIS_MODULE))
-		return -EINVAL;
-
 	// FIXME plausibility check
 	if (copy_from_user(&new_conf, &arg->config,sizeof(struct net_config)))
 		return -EFAULT;
 
+	if (mdev->cstate == Unconfigured) {
+		// ioctl already has a refcnt
+		__module_get(THIS_MODULE);
+		mput = 1;
+	}
+
 #define M_ADDR(A) (((struct sockaddr_in *)&A.my_addr)->sin_addr.s_addr)
 #define M_PORT(A) (((struct sockaddr_in *)&A.my_addr)->sin_port)
 #define O_ADDR(A) (((struct sockaddr_in *)&A.other_addr)->sin_addr.s_addr)
@@ -515,7 +521,7 @@
 	return 0;
 
   fail_ioctl:
-	module_put(THIS_MODULE);
+	if (mput) module_put(THIS_MODULE);
 	if (put_user(retcode, &arg->ret_code)) return -EFAULT;
 	return -EINVAL;
 }
@@ -799,8 +805,8 @@
 		if (test_bit(DISKLESS,&mdev->flags)) {
 			set_cstate(mdev,Unconfigured);
 			drbd_mdev_cleanup(mdev);
+			module_put(THIS_MODULE);
 		} else set_cstate(mdev,StandAlone);
-		module_put(THIS_MODULE);
 
 		break;
 
@@ -845,8 +851,8 @@
 		if (mdev->cstate == StandAlone) {
 			set_cstate(mdev,Unconfigured);
 			drbd_mdev_cleanup(mdev);
+			module_put(THIS_MODULE);
 		}
-		module_put(THIS_MODULE);
 
 		break;