# mdconfig and device numbers



## tobe (Jun 11, 2009)

Hi,

I'm using mdconfig to mount UFS snapshots.
The following code is used to create a device for a given snapshot:

```
device=$(mdconfig -a -t vnode -o readonly -f "${1}")
```
and the following code is used to delete the device:

```
mdconfig -d -u "${device}"
```

It works fine, but the device number (md0, md1, md...) is always increasing, i mean, if /dev/md0 doesn't exists, it is not reused, instead, a new device is created with the highest number available, until i destroy and recreate all devices.

_Note: i know the -u flag can be used to pass in a device number, but i don't want to use it because of possible race conditions (i hope mdconfig take care of this when allocating a device number)_

Questions:
- It is a bug or a feature of mdconfig? 
- Is there a limit on the device numbers?

Thanks,
TobÃ©


----------



## pbd (Jun 12, 2009)

tobe said:
			
		

> - Is there a limit on the device numbers?



I'm sorry, that I cannot answer your question responsibly, but yesterday run an infinite loop that creates md devices. Now, the last is md2551863 and increasing.


----------



## mk (Jun 12, 2009)

use -u in *if* statement to check is the specified number already in use. if so - increase device number for example with two to escape possiblity to hit another device in use. you can go further and specify ranges witch to be used for given device - memory device for multiple tmp dirs 100-200,mount iso (ala windows daemontools) 201-300 and so forth.


----------



## tobe (Jun 12, 2009)

pbd said:
			
		

> I'm sorry, that I cannot answer your question responsibly, but yesterday run an infinite loop that creates md devices. Now, the last is md2551863 and increasing.


Then the increasing numbering is probably not a problem


----------



## fronclynne (Jun 12, 2009)

*Carl Sagan stole my lunch money*



			
				tobe said:
			
		

> Then the increasing numbering is probably not a problem


From a quick glance at /usr/src/sbin/mdconfig/mdconfig.c:

```
mdio.md_unit == (unsigned)ULONG_MAX
```
But, not being fluent in C, I'm not clear if that's 1.84x10^19 or 4.29x10^9 or what.  Probably an absurdly large number in human terms.


----------



## trev (Jun 12, 2009)

fronclynne said:
			
		

> From a quick glance at /usr/src/sbin/mdconfig/mdconfig.c:
> 
> ```
> mdio.md_unit == (unsigned)ULONG_MAX
> ...



32 bit OS/compiler = 4,294,967,295 	
64 bit OS/compiler = 18,446,744,073,709,551,615


----------



## tobe (Jun 12, 2009)

It should probably be enough 

Thanks guys, it was my last open question for my snapsnot manager, now 'm going to submit it to the ports tree.


----------

