CVS commit: src/sys/dev/dm

2019-11-29 Thread Tomohiro Kusumi
Module Name:src
Committed By:   tkusumi
Date:   Sat Nov 30 05:35:57 UTC 2019

Modified Files:
src/sys/dev/dm: dm_ioctl.c

Log Message:
dm: Always initialize target's status string

Explicitly clear status string to prevent dmsetup(8) from
printing binary junk to stdout. Similar change has been
applied to DragonFlyBSD since 2015.

https://github.com/DragonFlyBSD/DragonFlyBSD/commit/a6cf54187fd7c3e994c573215806ec03572c038e

taken-from: DragonFlyBSD


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/dm/dm_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/dm

2019-11-29 Thread Tomohiro Kusumi
Module Name:src
Committed By:   tkusumi
Date:   Sat Nov 30 05:35:57 UTC 2019

Modified Files:
src/sys/dev/dm: dm_ioctl.c

Log Message:
dm: Always initialize target's status string

Explicitly clear status string to prevent dmsetup(8) from
printing binary junk to stdout. Similar change has been
applied to DragonFlyBSD since 2015.

https://github.com/DragonFlyBSD/DragonFlyBSD/commit/a6cf54187fd7c3e994c573215806ec03572c038e

taken-from: DragonFlyBSD


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/dm/dm_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/dm/dm_ioctl.c
diff -u src/sys/dev/dm/dm_ioctl.c:1.33 src/sys/dev/dm/dm_ioctl.c:1.34
--- src/sys/dev/dm/dm_ioctl.c:1.33	Sun Nov 11 10:21:11 2018
+++ src/sys/dev/dm/dm_ioctl.c	Sat Nov 30 05:35:57 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_ioctl.c,v 1.33 2018/11/11 10:21:11 mlelstv Exp $  */
+/* $NetBSD: dm_ioctl.c,v 1.34 2019/11/30 05:35:57 tkusumi Exp $  */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v 1.33 2018/11/11 10:21:11 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v 1.34 2019/11/30 05:35:57 tkusumi Exp $");
 
 /*
  * Locking is used to synchronise between ioctl calls and between dm_table's
@@ -927,6 +927,12 @@ dm_table_status_ioctl(prop_dictionary_t 
 		prop_dictionary_set_int32(target_dict, DM_TABLE_STAT,
 		dmv->table_head.cur_active_table);
 
+		/*
+		 * Explicitly clear DM_TABLE_PARAMS to prevent dmsetup(8) from
+		 * printing junk when DM_TABLE_PARAMS was never initialized.
+		 */
+		prop_dictionary_set_cstring(target_dict, DM_TABLE_PARAMS, "");
+
 		if (flags & DM_STATUS_TABLE_FLAG) {
 			params = table_en->target->status
 			(table_en->target_config);



Re: CVS commit: src/sys/dev/dm

2014-08-19 Thread Maxime Villard
Le 18/08/2014 19:16, Alistair G. Crooks a écrit :
 
 Module Name:  src
 Committed By: agc
 Date: Mon Aug 18 17:16:42 UTC 2014
 
 Modified Files:
   src/sys/dev/dm: dm_target_stripe.c
 
 Log Message:
 Avoid a memory leak - from maxv
 
 
 To generate a diff of this commit:
 cvs rdiff -u -r1.19 -r1.20 src/sys/dev/dm/dm_target_stripe.c
 
 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.
 
 

I have a doubt for this one.

for (strpi = DM_STRIPE_DEV_OFFSET; strpi  strpc; strpi += 2) {
printf(Stripe target device name %s -- offset %s\n,
   argv[strpi], argv[strpi+1]);

tlc = kmem_alloc(sizeof(*tlc), KM_NOSLEEP);
if ((tlc-pdev = dm_pdev_insert(argv[strpi])) == NULL) {
kmem_free(tsc, sizeof(*tsc));
XXX kmem_free(tlc, sizeof(*tlc));
return ENOENT;
}
tlc-offset = atoi(argv[strpi+1]);

/* Insert striping device to linked list. */
XXX TAILQ_INSERT_TAIL(tsc-stripe_devs, tlc, entries);
}

The tlc's inserted into the list are not freed, are they?



Re: CVS commit: src/sys/dev/dm

2014-08-19 Thread John Nemeth
On Aug 19,  6:50am, Maxime Villard wrote:
} Le 18/08/2014 19:16, Alistair G. Crooks a écrit :
}  
}  Module Name:src
}  Committed By:   agc
}  Date:   Mon Aug 18 17:16:42 UTC 2014
}  
}  Modified Files:
}  src/sys/dev/dm: dm_target_stripe.c
}  
}  Log Message:
}  Avoid a memory leak - from maxv
}  
}  To generate a diff of this commit:
}  cvs rdiff -u -r1.19 -r1.20 src/sys/dev/dm/dm_target_stripe.c
} 
} I have a doubt for this one.
} 
}   for (strpi = DM_STRIPE_DEV_OFFSET; strpi  strpc; strpi += 2) {
}   printf(Stripe target device name %s -- offset %s\n,
}  argv[strpi], argv[strpi+1]);
} 
}   tlc = kmem_alloc(sizeof(*tlc), KM_NOSLEEP);
}   if ((tlc-pdev = dm_pdev_insert(argv[strpi])) == NULL) {
}   kmem_free(tsc, sizeof(*tsc));
} XXX   kmem_free(tlc, sizeof(*tlc));
}   return ENOENT;
}   }
}   tlc-offset = atoi(argv[strpi+1]);
} 
}   /* Insert striping device to linked list. */
} XXX   TAILQ_INSERT_TAIL(tsc-stripe_devs, tlc, entries);
}   }
} 
} The tlc's inserted into the list are not freed, are they?

 Notice the return ENOENT after the two calls to kmem_free().
If the first XXX line is executed then the second XXX line won't be.

}-- End of excerpt from Maxime Villard


Re: CVS commit: src/sys/dev/dm

2014-08-19 Thread Maxime Villard
Le 19/08/2014 10:31, John Nemeth a écrit :
 On Aug 19,  6:50am, Maxime Villard wrote:
 } Le 18/08/2014 19:16, Alistair G. Crooks a écrit :
 }  
 }  Module Name:  src
 }  Committed By: agc
 }  Date: Mon Aug 18 17:16:42 UTC 2014
 }  
 }  Modified Files:
 }src/sys/dev/dm: dm_target_stripe.c
 }  
 }  Log Message:
 }  Avoid a memory leak - from maxv
 }  
 }  To generate a diff of this commit:
 }  cvs rdiff -u -r1.19 -r1.20 src/sys/dev/dm/dm_target_stripe.c
 } 
 } I have a doubt for this one.
 } 
 } for (strpi = DM_STRIPE_DEV_OFFSET; strpi  strpc; strpi += 2) {
 } printf(Stripe target device name %s -- offset %s\n,
 }argv[strpi], argv[strpi+1]);
 } 
 } tlc = kmem_alloc(sizeof(*tlc), KM_NOSLEEP);
 } if ((tlc-pdev = dm_pdev_insert(argv[strpi])) == NULL) {
 } kmem_free(tsc, sizeof(*tsc));
 } XXX kmem_free(tlc, sizeof(*tlc));
 } return ENOENT;
 } }
 } tlc-offset = atoi(argv[strpi+1]);
 } 
 } /* Insert striping device to linked list. */
 } XXX TAILQ_INSERT_TAIL(tsc-stripe_devs, tlc, entries);
 } }
 } 
 } The tlc's inserted into the list are not freed, are they?
 
  Notice the return ENOENT after the two calls to kmem_free().
 If the first XXX line is executed then the second XXX line won't be.

Yes, but that's a loop. The second XXX line may be reached several times,
before the first one returns ENOENT. And on that case the tlc's previously
allocated are not freed.

Unless I'm not reading clearly?




Re: CVS commit: src/sys/dev/dm

2010-05-18 Thread Matthias Scheler
On Tue, May 18, 2010 at 03:10:41PM +, Adam Hamsik wrote:
 Log Message:
 Add support for DIOCCACHESYNC ioctl for dm devices. Add new sync function
 pointer to dm_target_t because that is the only part of dm which know real
 block device. disk_ioctl_switch parses whole device table and for every
 entry it calls particular sync routine which propagates DIOCCACHESYNC
 to real disk.

What happens if a logical volume consists of two slice of one physical
device? Will the physical device get flushed twice?

Kind regards

-- 
Matthias Scheler  http://zhadum.org.uk/


Re: CVS commit: src/sys/dev/dm

2010-05-18 Thread Adam Hamsik

On May,Tuesday 18 2010, at 5:42 PM, Matthias Scheler wrote:

 On Tue, May 18, 2010 at 03:10:41PM +, Adam Hamsik wrote:
 Log Message:
 Add support for DIOCCACHESYNC ioctl for dm devices. Add new sync function
 pointer to dm_target_t because that is the only part of dm which know real
 block device. disk_ioctl_switch parses whole device table and for every
 entry it calls particular sync routine which propagates DIOCCACHESYNC
 to real disk.
 
 What happens if a logical volume consists of two slice of one physical
 device? Will the physical device get flushed twice?

Yes and there is no easy way how to not do that.

Regards

Adam.



Re: CVS commit: src/sys/dev/dm

2010-03-24 Thread Adam Hamsik

On Mar,Tuesday 23 2010, at 4:09 PM, Jonathan A. Kollasch wrote:

 Module Name:  src
 Committed By: jakllsch
 Date: Tue Mar 23 15:09:45 UTC 2010
 
 Modified Files:
   src/sys/dev/dm: device-mapper.c
 
 Log Message:
 Rework module/builtin code so it works in both cases.
 (Tested recently in the module case, slightly less recently as builtin.)
 
 haad [if it works] go for it
 

now when we have built in case working, would you like to add pseudo-device dm 
to AMD64, i386 non-modular kernels ? I think that 

ALL
MONOLITHIC
*XEN*

should be enough. What do you think about this ?(Sorry I have zero free time 
now, otherwise I would do it myself:()

Regards

Adam.



CVS commit: src/sys/dev/dm

2010-02-26 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Feb 26 23:52:43 UTC 2010

Modified Files:
src/sys/dev/dm: device-mapper.c

Log Message:
Use correct prototype for dmattach().


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/dm/device-mapper.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/dm/device-mapper.c
diff -u src/sys/dev/dm/device-mapper.c:1.17 src/sys/dev/dm/device-mapper.c:1.18
--- src/sys/dev/dm/device-mapper.c:1.17	Thu Feb 25 23:37:39 2010
+++ src/sys/dev/dm/device-mapper.c	Fri Feb 26 23:52:43 2010
@@ -1,4 +1,4 @@
-/*$NetBSD: device-mapper.c,v 1.17 2010/02/25 23:37:39 haad Exp $ */
+/*$NetBSD: device-mapper.c,v 1.18 2010/02/26 23:52:43 jakllsch Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -46,7 +46,6 @@
 #include sys/ioccom.h
 #include sys/kmem.h
 #include sys/module.h
-#include sys/once.h
 
 #include netbsd-dm.h
 #include dm.h
@@ -60,9 +59,10 @@
 static dev_type_size(dmsize);
 
 /* attach and detach routines */
-int dmattach(void);
+void dmattach(int);
 int dmdestroy(void);
 
+static int doinit(void);
 static int dm_cmd_to_fun(prop_dictionary_t);
 static int disk_ioctl_switch(dev_t, u_long, void *);
 static int dm_ioctl_switch(u_long);
@@ -161,11 +161,9 @@
 		if (error)
 			break;
 
-		error = dmattach();
+		error = doinit();
 		if (error) {
 			config_cfdriver_detach(dm_cd);
-			aprint_error(%s: unable to register cfattach\n,
-			dm_cd.cd_name);
 			break;
 		}
 
@@ -278,7 +276,8 @@
 	
 	error = config_cfattach_attach(dm_cd.cd_name, dm_ca);
 	if (error) {
-		aprint_error(Unable to register cfattach for dm driver\n);
+		aprint_error(%s: unable to register cfattach\n,
+		dm_cd.cd_name);
 		return error;
 	}
 	
@@ -290,12 +289,10 @@
 }
 
 /* attach routine */
-int
-dmattach(void)
+void
+dmattach(int n)
 {
-	static ONCE_DECL(control);
-
-	return RUN_ONCE(control, doinit);
+	doinit();
 }
 
 /* Destroy routine */



CVS commit: src/sys/dev/dm

2010-02-26 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Feb 26 23:52:43 UTC 2010

Modified Files:
src/sys/dev/dm: device-mapper.c

Log Message:
Use correct prototype for dmattach().


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/dm/device-mapper.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/dm

2010-02-26 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sat Feb 27 00:31:57 UTC 2010

Modified Files:
src/sys/dev/dm: device-mapper.c

Log Message:
Use RUN_ONCE(9) again.  (Everyone happy now?)


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/dm/device-mapper.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/dm

2010-02-26 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Sat Feb 27 00:31:57 UTC 2010

Modified Files:
src/sys/dev/dm: device-mapper.c

Log Message:
Use RUN_ONCE(9) again.  (Everyone happy now?)


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/dm/device-mapper.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/dm/device-mapper.c
diff -u src/sys/dev/dm/device-mapper.c:1.18 src/sys/dev/dm/device-mapper.c:1.19
--- src/sys/dev/dm/device-mapper.c:1.18	Fri Feb 26 23:52:43 2010
+++ src/sys/dev/dm/device-mapper.c	Sat Feb 27 00:31:57 2010
@@ -1,4 +1,4 @@
-/*$NetBSD: device-mapper.c,v 1.18 2010/02/26 23:52:43 jakllsch Exp $ */
+/*$NetBSD: device-mapper.c,v 1.19 2010/02/27 00:31:57 jakllsch Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -46,6 +46,7 @@
 #include sys/ioccom.h
 #include sys/kmem.h
 #include sys/module.h
+#include sys/once.h
 
 #include netbsd-dm.h
 #include dm.h
@@ -62,7 +63,9 @@
 void dmattach(int);
 int dmdestroy(void);
 
+static ONCE_DECL(doinit_control);
 static int doinit(void);
+
 static int dm_cmd_to_fun(prop_dictionary_t);
 static int disk_ioctl_switch(dev_t, u_long, void *);
 static int dm_ioctl_switch(u_long);
@@ -161,7 +164,7 @@
 		if (error)
 			break;
 
-		error = doinit();
+		error = RUN_ONCE(doinit_control, doinit);
 		if (error) {
 			config_cfdriver_detach(dm_cd);
 			break;
@@ -292,7 +295,7 @@
 void
 dmattach(int n)
 {
-	doinit();
+	RUN_ONCE(doinit_control, doinit);
 }
 
 /* Destroy routine */



CVS commit: src/sys/dev/dm

2010-02-25 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Feb 25 20:48:59 UTC 2010

Modified Files:
src/sys/dev/dm: device-mapper.c dm_ioctl.c

Log Message:
Be sure to config_cfattach_attach() in dmattach().
Loosely based on patch from Brian Brombacher,
with other inspriation from vnd(4).

This should fix PR kern/42799.

While here, a few prototype, style and namespace pollution-related changes.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/dm/device-mapper.c
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/dm/dm_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/dm

2010-02-25 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Feb 25 20:48:59 UTC 2010

Modified Files:
src/sys/dev/dm: device-mapper.c dm_ioctl.c

Log Message:
Be sure to config_cfattach_attach() in dmattach().
Loosely based on patch from Brian Brombacher,
with other inspriation from vnd(4).

This should fix PR kern/42799.

While here, a few prototype, style and namespace pollution-related changes.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/dm/device-mapper.c
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/dm/dm_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/dm/device-mapper.c
diff -u src/sys/dev/dm/device-mapper.c:1.15 src/sys/dev/dm/device-mapper.c:1.16
--- src/sys/dev/dm/device-mapper.c:1.15	Fri Jan  8 00:27:48 2010
+++ src/sys/dev/dm/device-mapper.c	Thu Feb 25 20:48:58 2010
@@ -1,4 +1,4 @@
-/*$NetBSD: device-mapper.c,v 1.15 2010/01/08 00:27:48 pooka Exp $ */
+/*$NetBSD: device-mapper.c,v 1.16 2010/02/25 20:48:58 jakllsch Exp $ */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,9 +59,10 @@
 static dev_type_size(dmsize);
 
 /* attach and detach routines */
-int dmattach(void);
-int dmdestroy(void);
+void dmattach(int);
+void dmdestroy(void);
 
+static void dm_init(void);
 static int dm_cmd_to_fun(prop_dictionary_t);
 static int disk_ioctl_switch(dev_t, u_long, void *);
 static int dm_ioctl_switch(u_long);
@@ -112,7 +113,7 @@
 
 extern struct cfdriver dm_cd;
 
-extern uint64_t dev_counter;
+extern uint64_t dm_dev_counter;
 
 /*
  * This array is used to translate cmd to function pointer.
@@ -149,15 +150,15 @@
 dm_modcmd(modcmd_t cmd, void *arg)
 {
 #ifdef _MODULE
-	int bmajor = -1, cmajor = -1;
 	int error;
+	int bmajor, cmajor;
 
 	error = 0;
+	bmajor = -1;
+	cmajor = -1;
 
 	switch (cmd) {
 	case MODULE_CMD_INIT:
-		dmattach();
-
 		error = config_cfdriver_attach(dm_cd);
 		if (error)
 			break;
@@ -165,13 +166,21 @@
 		error = config_cfattach_attach(dm_cd.cd_name, dm_ca);
 		if (error) {
 			config_cfdriver_detach(dm_cd);
-			aprint_error(Unable to register cfattach for dm driver\n);
-
+			aprint_error(%s: unable to register cfattach\n,
+			dm_cd.cd_name);
 			break;
 		}
 
-		error =  devsw_attach(dm, dm_bdevsw, bmajor,
+		error = devsw_attach(dm_cd.cd_name, dm_bdevsw, bmajor,
 		dm_cdevsw, cmajor);
+		if (error) {
+			config_cfattach_detach(dm_cd.cd_name, dm_ca);
+			config_cfdriver_detach(dm_cd);
+			break;
+		}
+
+		dm_init();
+
 		break;
 
 	case MODULE_CMD_FINI:
@@ -181,7 +190,7 @@
 		 * to disable auto-unload only if there is mounted dm device
 		 * present.
 		 */ 
-		if (dev_counter  0)
+		if (dm_dev_counter  0)
 			return EBUSY;
 		dmdestroy();
 
@@ -270,25 +279,29 @@
 	(void)dm_dev_free(dmv);
 
 	/* Decrement device counter After removing device */
-	atomic_dec_64(dev_counter);
+	atomic_dec_64(dm_dev_counter);
 
 	return 0;
 }
 
 /* attach routine */
-int
-dmattach(void)
+void
+dmattach(int num)
 {
+	int error;
 
-	dm_target_init();
-	dm_dev_init();
-	dm_pdev_init();
+	error = config_cfattach_attach(dm_cd.cd_name, dm_ca);
+	if (error) {
+		aprint_error(%s: unable to register cfattach\n,
+		dm_cd.cd_name);
+		return;
+	}
 
-	return 0;
+	dm_init();
 }
 
 /* Destroy routine */
-int
+void
 dmdestroy(void)
 {
 
@@ -296,7 +309,6 @@
 	dm_pdev_destroy();
 	dm_target_destroy();
 
-	return 0;
 }
 
 static int
@@ -354,6 +366,14 @@
 	return r;
 }
 
+static void
+dm_init(void)
+{
+	dm_target_init();
+	dm_dev_init();
+	dm_pdev_init();
+}
+
 /*
  * Translate command sent from libdevmapper to func.
  */

Index: src/sys/dev/dm/dm_ioctl.c
diff -u src/sys/dev/dm/dm_ioctl.c:1.20 src/sys/dev/dm/dm_ioctl.c:1.21
--- src/sys/dev/dm/dm_ioctl.c:1.20	Mon Jan  4 00:19:08 2010
+++ src/sys/dev/dm/dm_ioctl.c	Thu Feb 25 20:48:58 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_ioctl.c,v 1.20 2010/01/04 00:19:08 haad Exp $  */
+/* $NetBSD: dm_ioctl.c,v 1.21 2010/02/25 20:48:58 jakllsch Exp $  */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -95,7 +95,7 @@
 
 static uint64_t sc_minor_num;
 extern const struct dkdriver dmdkdriver;
-uint64_t dev_counter;
+uint64_t dm_dev_counter;
 
 /* Generic cf_data for device-mapper driver */
 static struct cfdata dm_cfdata = {
@@ -266,7 +266,7 @@
 	DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
 
 	/* Increment device counter After creating device */
-	atomic_inc_64(dev_counter);
+	atomic_inc_64(dm_dev_counter);
 
 	return r;
 }



CVS commit: src/sys/dev/dm

2010-02-25 Thread Adam Hamsik
Module Name:src
Committed By:   haad
Date:   Thu Feb 25 23:37:39 UTC 2010

Modified Files:
src/sys/dev/dm: device-mapper.c

Log Message:
Fix device-mapper to work in builtin case. This commit fixes

PR: 42799

REwork fix commited by jak@ to be more readable and remove unneeded ifdef 
_MODULE.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/dm/device-mapper.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/dm/device-mapper.c
diff -u src/sys/dev/dm/device-mapper.c:1.16 src/sys/dev/dm/device-mapper.c:1.17
--- src/sys/dev/dm/device-mapper.c:1.16	Thu Feb 25 20:48:58 2010
+++ src/sys/dev/dm/device-mapper.c	Thu Feb 25 23:37:39 2010
@@ -1,7 +1,7 @@
-/*$NetBSD: device-mapper.c,v 1.16 2010/02/25 20:48:58 jakllsch Exp $ */
+/*$NetBSD: device-mapper.c,v 1.17 2010/02/25 23:37:39 haad Exp $ */
 
 /*
- * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -46,6 +46,7 @@
 #include sys/ioccom.h
 #include sys/kmem.h
 #include sys/module.h
+#include sys/once.h
 
 #include netbsd-dm.h
 #include dm.h
@@ -59,10 +60,9 @@
 static dev_type_size(dmsize);
 
 /* attach and detach routines */
-void dmattach(int);
-void dmdestroy(void);
+int dmattach(void);
+int dmdestroy(void);
 
-static void dm_init(void);
 static int dm_cmd_to_fun(prop_dictionary_t);
 static int disk_ioctl_switch(dev_t, u_long, void *);
 static int dm_ioctl_switch(u_long);
@@ -149,9 +149,7 @@
 static int
 dm_modcmd(modcmd_t cmd, void *arg)
 {
-#ifdef _MODULE
-	int error;
-	int bmajor, cmajor;
+	int error, bmajor, cmajor;
 
 	error = 0;
 	bmajor = -1;
@@ -163,7 +161,7 @@
 		if (error)
 			break;
 
-		error = config_cfattach_attach(dm_cd.cd_name, dm_ca);
+		error = dmattach();
 		if (error) {
 			config_cfdriver_detach(dm_cd);
 			aprint_error(%s: unable to register cfattach\n,
@@ -178,9 +176,6 @@
 			config_cfdriver_detach(dm_cd);
 			break;
 		}
-
-		dm_init();
-
 		break;
 
 	case MODULE_CMD_FINI:
@@ -192,9 +187,8 @@
 		 */ 
 		if (dm_dev_counter  0)
 			return EBUSY;
-		dmdestroy();
 
-		error = config_cfattach_detach(dm_cd.cd_name, dm_ca);
+		error = dmdestroy();
 		if (error)
 			break;
 
@@ -210,13 +204,6 @@
 	}
 
 	return error;
-#else
-
-	if (cmd == MODULE_CMD_INIT)
-		return 0;
-	return ENOTTY;
-
-#endif /* _MODULE */
 }
 
 
@@ -284,31 +271,48 @@
 	return 0;
 }
 
-/* attach routine */
-void
-dmattach(int num)
+static int
+doinit(void)
 {
 	int error;
-
+	
 	error = config_cfattach_attach(dm_cd.cd_name, dm_ca);
 	if (error) {
-		aprint_error(%s: unable to register cfattach\n,
-		dm_cd.cd_name);
-		return;
+		aprint_error(Unable to register cfattach for dm driver\n);
+		return error;
 	}
+	
+	dm_target_init();
+	dm_dev_init();
+	dm_pdev_init();
 
-	dm_init();
+	return 0;
+}
+
+/* attach routine */
+int
+dmattach(void)
+{
+	static ONCE_DECL(control);
+
+	return RUN_ONCE(control, doinit);
 }
 
 /* Destroy routine */
-void
+int
 dmdestroy(void)
 {
+	int error;
 
+	error = config_cfattach_detach(dm_cd.cd_name, dm_ca);
+	if (error)
+		return error;
+	
 	dm_dev_destroy();
 	dm_pdev_destroy();
 	dm_target_destroy();
 
+	return 0;
 }
 
 static int
@@ -366,14 +370,6 @@
 	return r;
 }
 
-static void
-dm_init(void)
-{
-	dm_target_init();
-	dm_dev_init();
-	dm_pdev_init();
-}
-
 /*
  * Translate command sent from libdevmapper to func.
  */



CVS commit: src/sys/dev/dm

2010-02-25 Thread Adam Hamsik
Module Name:src
Committed By:   haad
Date:   Thu Feb 25 23:37:39 UTC 2010

Modified Files:
src/sys/dev/dm: device-mapper.c

Log Message:
Fix device-mapper to work in builtin case. This commit fixes

PR: 42799

REwork fix commited by jak@ to be more readable and remove unneeded ifdef 
_MODULE.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/dm/device-mapper.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/dm

2010-01-07 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Jan  8 00:27:48 UTC 2010

Modified Files:
src/sys/dev/dm: device-mapper.c

Log Message:
Fix this for non-module (which, i guess, is only i386/ALL).

XXX: autoconfusion vs. modules is an intolerable mess of stepping
on each others' toes.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/dm/device-mapper.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/dm

2010-01-03 Thread Adam Hamsik
Module Name:src
Committed By:   haad
Date:   Sun Jan  3 12:53:00 UTC 2010

Modified Files:
src/sys/dev/dm: dm_pdev.c

Log Message:
Replace aprint_Verbose with aprint_debug to shutup unnecessary logs.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/dm/dm_pdev.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/dm

2010-01-03 Thread Adam Hamsik
Module Name:src
Committed By:   haad
Date:   Sun Jan  3 22:44:10 UTC 2010

Modified Files:
src/sys/dev/dm: device-mapper.c

Log Message:
KNF police, remove unnecessary whitespaces and tabulators. Refactor dmioctl
to not use prop_dictionary_copy* functions if NetBSD_DM_IOCTL command was
not called on device. If disk_ioctl returms anything else then ENOTTY exit
from dmioctl.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/dm/device-mapper.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/dm

2010-01-03 Thread Adam Hamsik
Module Name:src
Committed By:   haad
Date:   Sun Jan  3 22:55:26 UTC 2010

Modified Files:
src/sys/dev/dm: device-mapper.c

Log Message:
Refactor dmioctl to by cleaner and to copyout dictionary in case when something
went wrong.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/dm/device-mapper.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/dm

2010-01-03 Thread Adam Hamsik
Module Name:src
Committed By:   haad
Date:   Mon Jan  4 00:14:41 UTC 2010

Modified Files:
src/sys/dev/dm: dm_target.c dm_target_linear.c dm_target_stripe.c

Log Message:
Indent files remove unnecessary blank lines, white spaces and KNFize code.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/dm/dm_target.c
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/dm/dm_target_linear.c \
src/sys/dev/dm/dm_target_stripe.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/dm

2010-01-03 Thread Adam Hamsik
Module Name:src
Committed By:   haad
Date:   Mon Jan  4 00:19:08 UTC 2010

Modified Files:
src/sys/dev/dm: dm_dev.c dm_ioctl.c dm_pdev.c dm_table.c

Log Message:
Indent files remove unnecessary blank lines, white spaces and KNFize code.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/dm/dm_dev.c
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/dm/dm_ioctl.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/dm/dm_pdev.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/dm/dm_table.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.