Home | History | Annotate | Download | only in dm
History log of /src/sys/dev/dm/device-mapper.c
RevisionDateAuthorComments
 1.65  29-Sep-2025  mlelstv Use xdevice_name for DIOCGWEDGEINFO answer to align with the registered
disk name. getdisksize() relies on it to find the disk structure.

Fixes PR 59674.
Pullup -11.
 1.64  31-Mar-2022  pgoyette For device modules that provide both auto-config and /dev/xxx
interfaces, make sure that initialization and destruction
follow the proper sequence. This is triggered by the recent
changes to the devsw stuff; per riastradh@ the required call
sequence is:

devsw_attach()
config_init_component() or config_cf*_attach()
...
config_fini_component() or config_cf*_detach()
devsw_detach()

While here, add a few missing calls to some of the detach
routines.

Testing of these changes has been limited to:
1. compile without build break
2. no related test failures from atf
3. modload/modunload work as well as
before.

No functional device testing done, since I don't have any
of these devices. Let me know of any damage I might cause
here!

XXX Some of the modules affected by this commit are already
XXX broken; see kern/56772. This commit does not break
any additional modules (as far as I know).
 1.63  28-Mar-2022  mlelstv Media size is in bytes (off_t), not sectors.
 1.62  07-May-2021  hannken Track the number of cdev and bdev opens and fail dm_detach()
on open devices unless detach is forced.

PR kern/54969 (Disk cache is no longer flushed on shutdown)
 1.61  08-Jul-2020  thorpej branches: 1.61.6;
Adapt to proplib API chanages.
 1.60  16-Jan-2020  maya dm(8) doesn't cause problems on suspend, don't block it.

Tested by Matthias Petermann, thanks!
 1.59  22-Dec-2019  tkusumi branches: 1.59.2;
dm: Make numsec/secsize arguments in dm_table_disksize() optional
 1.58  22-Dec-2019  tkusumi dm: Add missing "ioctl called" debug prints
 1.57  19-Dec-2019  tkusumi dm: Refactor dmioctl()

More readable without dm_ioctl_switch() as a separate function.
 1.56  19-Dec-2019  tkusumi dm: u_{int,long} -> unsigned {int,long}
 1.55  15-Dec-2019  tkusumi dm: Rename dm specific atoi() to atoi64()

This is uint64_t version, not sys/lib/libsa/atoi.c.
 1.54  15-Dec-2019  tkusumi dm: Style cleanups (no functional changes)
 1.53  15-Dec-2019  tkusumi dm: Make targets' ->sync() optional

Apparently some targets have nothing to sync, so make it optional.
 1.52  15-Dec-2019  tkusumi dm: "unsigned" -> "unsigned int" for consistency

Use either one, but not both.
 1.51  14-Dec-2019  tkusumi dm: Move extern declaration of global variables to dm.h
 1.50  14-Dec-2019  tkusumi dm: Remove void casts of function calls

Use of void casts in dm is not consistent, just get rid of them.
 1.49  11-Dec-2019  tkusumi dm: Revert "Fix error handling in dmioctl()" for now

This change seems to break "deps" in dm ioctl(2) for linear target.
Revert the change, will revisit later.
https://mail-index.netbsd.org/current-users/2019/12/11/msg037179.html
 1.48  09-Dec-2019  tkusumi dm: Fix error handling in dmioctl()

Looks like cleanup_exit label is in a wrong place.
Should skip prop_dictionary_copyout_ioctl() on error.
 1.47  07-Dec-2019  tkusumi dm: Fix indentation
 1.46  06-Dec-2019  tkusumi dm: Fix typos in comments/messages

taken-from: DragonFlyBSD
 1.45  05-Dec-2019  tkusumi dm: Remove unneeded dm_get_version_ioctl()

"version" is implemented and handled in userspace,
hence dm ioctl doesn't need to support it.

taken-from: DragonFlyBSD
 1.44  04-Dec-2019  tkusumi dm: Minor fixes/cleanups
 1.43  04-Dec-2019  tkusumi dm: style + whitespace + indentation fixes

No functional changes.
 1.42  03-Dec-2019  tkusumi dm: Doesn't need to expose struct cmd_function in a header
 1.41  02-Dec-2019  tkusumi dm: Add a comment on race window on unload

There is a minor race window on unload vs device creation
that can cause panic.
https://github.com/DragonFlyBSD/DragonFlyBSD/commit/53a07f3ae7313aa58948a60f46428bfc2254dc3c

taken-from: DragonFlyBSD
 1.40  06-Oct-2018  mlelstv branches: 1.40.4;
Add ioctls to query geometry.
 1.39  28-Oct-2017  riastradh branches: 1.39.2; 1.39.4;
Kill some more extern struct cfdriver declarations.

Down with externs in .c!
 1.38  11-Jul-2016  msaitoh branches: 1.38.2; 1.38.8; 1.38.10;
KNF. No functional change.
 1.37  20-Aug-2015  christos include "ioconf.h" to get the 'void <driver>attach(int count);' prototype.
 1.36  31-Dec-2014  mlelstv disk_blocksize and disk_set_info relay the same information
to the disk subsystem.

Make disk_set_info also set blocksize shift values.
Remove every call to disk_blocksize.

Keep disk_blocksize for ABI compatibility, make it also set dg_secsize.
 1.35  02-Oct-2014  justin branches: 1.35.2;
devmajor_t not int
 1.34  25-Jul-2014  dholland Add d_discard to all struct cdevsw instances I could find.

All have been set to "nodiscard"; some should get a real implementation.
 1.33  25-Jul-2014  dholland Add d_discard to all struct bdevsw instances I could find.

I've set them all to nodiscard. Some of them (wd, dk, vnd, ld,
raidframe, maybe cgd) should be implemented for real.
 1.32  28-Dec-2013  pgoyette branches: 1.32.2;
Make dksubr.c into a module, and make the cgd and dm modules depend on
it.

Now that cgd is completely modularized, descend into modules/cgd to
actually create the module.
 1.31  18-Oct-2013  christos remove unused variables
 1.30  29-May-2013  christos branches: 1.30.2;
phase 1 of disk geometry cleanup:
- centralize the geometry -> plist code so that we don't have
n useless copies of it.
 1.29  13-Mar-2012  elad branches: 1.29.2;
Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.
 1.28  23-Dec-2010  christos branches: 1.28.8; 1.28.12;
Now that we have allowed operator to access the control node, make sure
that he cannot cause damage, by only allowing the superuser to do ioctls
that can cause damage.
 1.27  23-Dec-2010  mlelstv make dm aware of physical sector sizes.

For aggregates of multiple disks we use the largest sector size from
all disks. For standard power-of-2 sizes this is the same as the least
common multiple. We still require proper alignment of the targets in
the mapping table.

ok by haad@
 1.26  06-Dec-2010  haad I have forgot to fix dm_dev_counter here, too.
 1.25  23-Oct-2010  haad Add old file describing locking schema used in dm driver.
 1.24  09-Oct-2010  haad In rome do as romans do. If I will get EEXIST from devsw_attach don't exit and
continue. This unbreaks usage of libdm in RUMP.
 1.23  18-May-2010  haad 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.

While I was here implement some KNF fixes and remove unneeded symbols from
dm.h.

Problem reported on port-xen@ by Hugo Silva.
 1.22  26-Mar-2010  jakllsch Fix build of i386 ALL kernel with patch from Greg A. Woods in PR/43056.
 1.21  23-Mar-2010  jakllsch 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
 1.20  12-Mar-2010  haad branches: 1.20.2;
Disable disk_ioctl_switch fo device-mapper control device.
 1.19  27-Feb-2010  jakllsch Use RUN_ONCE(9) again. (Everyone happy now?)
 1.18  26-Feb-2010  jakllsch Use correct prototype for dmattach().
 1.17  25-Feb-2010  haad 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.
 1.16  25-Feb-2010  jakllsch 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.
 1.15  08-Jan-2010  pooka branches: 1.15.2;
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.
 1.14  03-Jan-2010  haad Refactor dmioctl to by cleaner and to copyout dictionary in case when something
went wrong.
 1.13  03-Jan-2010  haad 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.
 1.12  03-Jan-2010  haad Hook device-mapper to autoconf framework. Add dm_attach, dm_match and dm_detach
routines used by autoconf users. Change dm_dev_remove_ioctl to call dm_detach.

This should be primary used by kernel to disable devices during shutdown of
system with nested disk devices.

Requested by dyoung@.
 1.11  29-Dec-2009  haad Add private lock to dm_dev_t used for mutual exclusion for diks(9) api
routines. This change fixes PR kern/42532.
 1.10  06-Dec-2009  haad Add support for DM_QUERY_INACTIVE_TABLE_FLAG to dm_table_status and dm_table_deps
this flag was introduced to dm->lvm protocol in 4.16.0 version of it. Restore
vrsion check functionality and sent back actual kernel driver version.
 1.9  16-Oct-2009  joerg Don't spam the console with debug messages.
 1.8  27-Jun-2009  jakllsch Some fixes for dm(4).

- Limit accesses to the size of the volume.
This fixes a KASSERT in physio_biodone().
- Change dm_table_size() to return the size of the volume in
DEV_BSIZE units. It was reporting it in DEV_BSIZE^2 units.
- Remove a bit of trailing whitespace.

ok haad
 1.7  05-Jun-2009  haad Add support for DIOCGDISKINFO to disk like device drivers. Change
partutil.c::getdiskinfo to use it to get disk geometry info.
Use DIOCGWEDGEINFO ioctl to get information about partition size, if disk
driver doesn't support it use old DIOCGDINFO. This patch adds support for
wedge like devices(lvm logical volumes, ZFS zvol partitions) to newfs and
other tools.

No objections on tech-userlevel@.
 1.6  06-Apr-2009  haad branches: 1.6.2;
Use functions from disk(9) framework. Initialize disk/disklabel during
dm_device_create_ioctl, before calling dmgetdisklabel.
Use disk_busy/disk_unbusy in dmstrategy to display LVM LV's in iostat
output.
 1.5  22-Jan-2009  agc branches: 1.5.2;
Move back to printing the minor device as a 32-bit entity
 1.4  16-Jan-2009  haad branches: 1.4.2; 1.4.4;
Disable unloading of dm driver when there are any devices defined. This means
that we have to run lvm vgchange -a n before modunload in NetBSD.

We really need to disable module unloading only for mounted devices, I have
to look at vfs_hooks for mount/umount calls and find way how to mark devices
as mounted in dm driver.
 1.3  11-Jan-2009  haad Fix aprint_debug after christos-time_t merge.
 1.2  19-Dec-2008  haad Merge the haad-dm branch to -current. This branch adds LVM functionality to
the base NetBSD system. It uses Linux LVM2 tools and our BSD licensed
device-mapper driver.

The device-mapper driver can be used to create virtual block devices which
maps virtual blocks to real with target mapping called target. Currently
these targets are available a linear, zero, error and a snapshot (this is
work in progress and doesn't work yet).

The lvm2tools adds lvm and dmsetup binary to based system, where the lvm
tool is used to manage and administer whole LVM and the dmestup is used to
communicate iwith device-mapper kernel driver. With these tools also
a libdevmapper library is instaled to the base system.

Building of tools and driver is currently disable and can be enabled with
MKLVM=yes in mk.conf. I will add sets lists and rc.d script soon.

Oked by agc@ and cube@.
 1.1  07-Jul-2008  haad branches: 1.1.2;
Add dmgetdefaultdisklabel to get virtual disklabel for Logical Volume device. Add snapshot targets (snapshot, snapshot-origin), add dm_type to dm_dev structure to identify type of device. e.g. we can have mirrored disk device with snapshot on them and spare disk on them. When driver want to work with snapshot devices, it looks to upcalls list and finds all DM_SNAPSHOT devices.
 1.1.2.17  03-Dec-2008  haad Fix several memory leaks in proplib library handling. Rework dm_cmd_to_fun
function to use prop_string_t.
 1.1.2.16  05-Nov-2008  haad Fix copyright in TNF licenses.
 1.1.2.15  02-Nov-2008  haad Use typedef in all structures in dm driver and use them in source code.
No functional change expected.
 1.1.2.14  16-Oct-2008  haad Rewrite locking in dm driver for last time. Replace rwlock with mutex/cv.
Move table lists to separate structure called table_head and access them
through dm_table interface. Thx go@, rmind@ and Dusan Bernat for help and
suggestions.
 1.1.2.13  26-Sep-2008  haad Rework disklabel stuff once again, do not allocate nw disklabel struct
every time DIOCGPART is called. Recreate disklabel after resume so it
contains correct table. Do not leak device when I want to create device
with name which already exists.

XXX: dm_dev_resume_ioctl and dmgetdisklabel is broken I need to completly
rework locking here soon.
 1.1.2.12  10-Sep-2008  haad Introduce new dm_dev_lookup and use it to lookup for device name, uuid and
minor number in device global list.
 1.1.2.11  05-Sep-2008  haad Rework handling of disklabel stuff. Remove disklabel from dstruct dm_dev
and generate it dynamicaly for every call. Withthese changes using -F and
-s options when creating file-system with newfs is not needed anymore.
 1.1.2.10  03-Sep-2008  haad Simplify locking remove mutexes from pdev, target part of dm and only allow
one ioctl command to be in driver at time. Ioctl interface of dm device is
not performance critical so I don't need to paralelize dm driver so much.

Add new dev_type --> DM_DELETING_DEV which is set to device during
dm_device_remove_ioctl. To disable any incoming IO which will come in time
window between geting a rw_lock and removing device from global dev list.

XXX. I can't remove mutex from dm_dev.c also because dm_lookup_minor is
called from device-mapper and not from dm_ioctl.c
 1.1.2.9  19-Aug-2008  haad Use dm_*_destroy routines in dmdestroy, I will not leak any memory after
kmod unload anymore.
 1.1.2.8  19-Aug-2008  haad Fix device-mapper driver loading ask kmod. Register driver with devsw_attach
and deregister with devsw_detach.
 1.1.2.7  19-Aug-2008  haad Add $NetBSD$ tag to all dm driver sources.
 1.1.2.6  03-Aug-2008  haad Add support for new kernel modules. Remove old LKM code. Device-mapper driver
can be now built as kmod.
 1.1.2.5  29-Jul-2008  haad Fix pasto.
 1.1.2.4  28-Jul-2008  haad Add basic synchronization between dmstrategy routine and ioctl functions.
Dmstrategy locks, per dev rwlock for reading and all struct dm_dev changing
routines in dm_ioctl(such as dm_table_resume_ioctl, dm_dev_remove_ioctl),
have to lock it for writing.
Modify comments and ad description to each function about locking which
I think should be used there. I want to use mutex for synchronization of
different ioctl calls on same device. e.g. we can't remove table from
inactive slot when there is dm_table_status_ioctl runnning.
 1.1.2.3  19-Jul-2008  haad *** empty log message ***
 1.1.2.2  11-Jul-2008  haad KNFize my sources add space after comma in function parameters.
Wrap to 80 chars per line.
 1.1.2.1  07-Jul-2008  haad Import of device-mapper driver. This driver is BSD rewrite of linux dm driver.
For now only error, linear and zero targets are supported. This driver uses NetBSD
specific ioctl protocola based on proplib.

I was able to create logical volume (with lvm2tools lvcreate utility) with this
version of driver, newfs it and mount it.
 1.4.4.4  28-Apr-2009  skrll Sync with HEAD.
 1.4.4.3  03-Mar-2009  skrll Sync with HEAD.
 1.4.4.2  19-Jan-2009  skrll Sync with HEAD.
 1.4.4.1  16-Jan-2009  skrll file device-mapper.c was added on branch nick-hppapmap on 2009-01-19 13:17:52 +0000
 1.4.2.2  17-Jan-2009  mjf Sync with HEAD.
 1.4.2.1  16-Jan-2009  mjf file device-mapper.c was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.5.2.2  23-Jul-2009  jym Sync with HEAD.
 1.5.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.6.2.6  11-Aug-2010  yamt sync with head.
 1.6.2.5  11-Mar-2010  yamt sync with head
 1.6.2.4  18-Jul-2009  yamt sync with head.
 1.6.2.3  20-Jun-2009  yamt sync with head
 1.6.2.2  04-May-2009  yamt sync with head.
 1.6.2.1  06-Apr-2009  yamt file device-mapper.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:36 +0000
 1.15.2.4  06-Nov-2010  uebayasi Sync with HEAD.
 1.15.2.3  22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.15.2.2  17-Aug-2010  uebayasi Sync with HEAD.
 1.15.2.1  30-Apr-2010  uebayasi Sync with HEAD.
 1.20.2.2  05-Mar-2011  rmind sync with head
 1.20.2.1  30-May-2010  rmind sync with head
 1.28.12.1  05-Apr-2012  mrg sync to latest -current.
 1.28.8.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.28.8.1  17-Apr-2012  yamt sync with head
 1.29.2.3  03-Dec-2017  jdolecek update from HEAD
 1.29.2.2  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.29.2.1  23-Jun-2013  tls resync from head
 1.30.2.1  18-May-2014  rmind sync with head
 1.32.2.1  10-Aug-2014  tls Rebase.
 1.35.2.3  05-Oct-2016  skrll Sync with HEAD
 1.35.2.2  22-Sep-2015  skrll Sync with HEAD
 1.35.2.1  06-Apr-2015  skrll Sync with HEAD
 1.38.10.1  13-Oct-2018  martin Pull up following revision(s) (requested by mlelstv in ticket #1055):

sys/dev/dm/device-mapper.c: revision 1.40

Add ioctls to query geometry.
 1.38.8.2  29-Apr-2017  pgoyette Remove more unnecessary #include for sys/localcount.h
 1.38.8.1  27-Apr-2017  pgoyette Restore all work from the former pgoyette-localcount branch (which is
now abandoned doe to cvs merge botch).

The branch now builds, and installs via anita. There are still some
problems (cgd is non-functional and all atf tests time-out) but they
will get resolved soon.
 1.38.2.3  26-Jul-2016  pgoyette Rename LOCALCOUNT_INITIALIZER to DEVSW_MODULE_INIT. This better describes
what we're doing, and why.
 1.38.2.2  19-Jul-2016  pgoyette Instead of repeatedly typing the conditional initialization of the
.d_localcount members in the various {b,c}devsw, define an initializer
macro and use it. This also removes the need for defining new symbols
for each 'struct localcount'.

As suggested by riastradh@
 1.38.2.1  18-Jul-2016  pgoyette Rump drivers are always installed via devsw_attach() so we need to
always allocate a 'struct localcount' for these drivers whenever they
are built as modules.
 1.39.4.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.39.4.1  10-Jun-2019  christos Sync with HEAD
 1.39.2.1  20-Oct-2018  pgoyette Sync with head
 1.40.4.1  21-Jan-2020  martin Pull up following revision(s) (requested by maya in ticket #641):

sys/dev/dm/device-mapper.c: revision 1.60

dm(8) doesn't cause problems on suspend, don't block it.
Tested by Matthias Petermann, thanks!
 1.59.2.1  17-Jan-2020  ad Sync with head.
 1.61.6.1  13-May-2021  thorpej Sync with HEAD.

RSS XML Feed