Home | History | Annotate | only in /src/sys/dev/dm
History log of /src/sys/dev/dm
RevisionDateAuthorComments
 1.1 05-Dec-2009  haad branches: 1.1.4;
Install netbsd-dm.h file to include/dev/dm so it can be used by public.
 1.1.4.2 11-Mar-2010  yamt sync with head
 1.1.4.1 05-Dec-2009  yamt file Makefile was added on branch yamt-nfs-mp on 2010-03-11 15:03:26 +0000
 1.6 05-Dec-2009  haad Remove wrong TODO item, it violates abstraction between kernel-libdevmapper
and lvm tools.
 1.5 13-Apr-2009  haad branches: 1.5.2;
Update to reality.
 1.4 02-Jan-2009  haad branches: 1.4.2; 1.4.4; 1.4.6;
Add more tasks and add more details about them.
 1.3 22-Dec-2008  haad Remove done task and add new one.
 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 11-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.3 02-Nov-2008  haad Change TODO file add some new tasks for inspiration.
 1.1.2.2 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.1 11-Jul-2008  haad I have forgot to add these two files.
 1.4.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.4.4.3 28-Apr-2009  skrll Sync with HEAD.
 1.4.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.4.4.1 02-Jan-2009  skrll file TODO 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 02-Jan-2009  mjf file TODO was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.5.2.3 11-Mar-2010  yamt sync with head
 1.5.2.2 04-May-2009  yamt sync with head.
 1.5.2.1 13-Apr-2009  yamt file TODO was added on branch yamt-nfs-mp on 2009-05-04 08:12:36 +0000
 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.
 1.56 21-Aug-2021  andvar fix typos in sys/dev/dm code comments and documentation.
also remove some trailing space in documentation.
 1.55 21-Jan-2020  tkusumi dm: #if0 target's ->upcall() handler

This is part of NetBSD's dm design, but unimplemented
(all handlers return 0) and also unused.
 1.54 05-Jan-2020  tkusumi branches: 1.54.2;
dm: Add dm-delay target

Ported from DragonFlyBSD, but this target had originally existed in
Linux kernel. See below for details.
https://www.kernel.org/doc/Documentation/device-mapper/delay.txt

Due to "tick" in hz(9) not working (which results in dmdlthread spinning
forever in _submit_queue() without dp extracted from delayed list
and queued into submit list), this hasn't been hooked to dm.kmod yet.

taken-from: DragonFlyBSD
 1.53 02-Jan-2020  tkusumi dm: Add dm-flakey target

Ported from DragonFlyBSD, but this target had originally existed in
Linux kernel. See below for details.
https://www.kernel.org/doc/Documentation/device-mapper/dm-flakey.txt

Due to two technical issues, this hasn't been hooked to dm.kmod yet.
1) "tick" in hz(9) not working.
2) Unable to use ->b_private in nestiobuf callback when it's already
used for mbp (see HAS_BUF_PRIV2).

taken-from: DragonFlyBSD
 1.52 23-Dec-2019  tkusumi dm: Make target's ->table() optional

Since ->info() (counter part of ->table() in the original dm design
in Linux kernel in .status where both INFO and TABLE are optional)
is an optional handler, make ->table() optional as well. Some
targets don't have anything to do in ->table() just as in ->info().

taken-from: DragonFlyBSD
 1.51 21-Dec-2019  tkusumi dm: Fix dm-stripe's "status" output format

As mentioned in "dm: Don't try to implement "status" as subset of "table"",
dm-stripe in NetBSD doesn't have correct "status" output format.
Implement ->info() to sync with Linux kernel.

Note that num_error for stripe device isn't implemented yet.

taken-from: DragonFlyBSD
 1.50 21-Dec-2019  tkusumi dm: Remove target's ->deps() by implementing deps in dm core

Retrieving device dependencies doesn't need to be target specific.
The reason it currently needs ->deps() is because dm core doesn't
have data structure that allows table to walk through target's
underlying devices. Add struct dm_mapping to be able to do this,
and remove ->deps()'s from targets which basically do the same thing.

=====(A) before this commit
table
| [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

=====(B) this commit
table---->mapping-->mapping-->mapping-->...
| | | |
| v v v [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

taken-from: DragonFlyBSD
 1.49 20-Dec-2019  tkusumi dm: Fix "table" output format of dm-linear and dm-stripe

The existing "table" output showing device file path of pdev is
not compatible with dm in Linux kernel (and also DragonFlyBSD).
It should be showing "major:minor" instead.

taken-from: DragonFlyBSD
 1.48 16-Dec-2019  tkusumi dm: Cleanup dm.h (remove unneeded comments, etc)
 1.47 16-Dec-2019  tkusumi dm: Enable dm-error and dm-zero target

Add these two targets to dm.kmod.
These are generally available in Linux and DragonFlyBSD,
so enable them in NetBSD as well.
 1.46 15-Dec-2019  tkusumi dm: Rename dm specific atoi() to atoi64()

This is uint64_t version, not sys/lib/libsa/atoi.c.
 1.45 15-Dec-2019  tkusumi dm: Make targets' ->sync() optional

Apparently some targets have nothing to sync, so make it optional.
 1.44 15-Dec-2019  tkusumi dm: Make targets' ->secsize() optional

and make a caller assume secsize 0 if ->secsize not present.
This allows a dummy function to be removed which was added in
"dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)".
 1.43 15-Dec-2019  tkusumi dm: "unsigned" -> "unsigned int" for consistency

Use either one, but not both.
 1.42 15-Dec-2019  tkusumi dm: Rename targets' ->status() to ->table() given ->info() exists

Since now that dm targets in NetBSD have ->info() for "status",
->status() should be renamed to ->table() for "table",
given how dm target status was originally designed in Linux kernel.

taken-from: DragonFlyBSD
 1.41 14-Dec-2019  tkusumi dm: Don't try to implement "status" as subset of "table"

The way dm_table_status_ioctl() implements "status" and "table" is
not compatible with Linux kernel. Some targets have different outputs
that "status" can't be implemented as subset of "table".

Add ->info() handler to sync with "status" behavior in Linux kernel.
Some targets which currently exist in NetBSD (I think striped)
as well as some minor targets that I plan to port to NetBSD
can/should implement ->info(), but will do that in a different commit.

taken-from: DragonFlyBSD
 1.40 14-Dec-2019  tkusumi dm: Move extern declaration of global variables to dm.h
 1.39 12-Dec-2019  tkusumi dm: Make target's ->init() take parsed argc and argv

This gets rid of the same parser code in each target using strsep(3).
taken-from: DragonFlyBSD
 1.38 08-Dec-2019  tkusumi dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)

dm_target_insert() has assertions to ensure targets implement all handlers.
Adding dummy ones at least prevents panic on modload(8).
 1.37 08-Dec-2019  tkusumi dm: Move targets specific structs to .c files

These don't need to be defined and exposed in dm.h.
 1.36 08-Dec-2019  tkusumi dm: Unbreak compilation of kernel modules

The dm kernel modules (MK_DM_TARGETS enabled in sys/modules/dm/Makefile)
have been broken. Unbreak the build.
 1.35 08-Dec-2019  tkusumi dm: Refactor target's ->init() i/f

Take dm_table_entry_t* instead of void**.
Remove dm_dev_t* unneeded by target code.
No functional change, but for future changes.

taken-from: DragonFlyBSD
 1.34 07-Dec-2019  tkusumi dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD
 1.33 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.32 04-Dec-2019  tkusumi dm: Comment out unused dm_dev fields documented in sys/dev/dm/doc
 1.31 03-Dec-2019  tkusumi dm: Remove unused macro MAX_TARGET_STRING_LEN

that was added but never used in both NetBSD and DragonFlyBSD.
taken-from: DragonFlyBSD
 1.30 03-Dec-2019  tkusumi dm: Include <sys/vnode.h> in dm.h

dm.h already depends on vnode, so have dm.h include <sys/vnode.h>
instead of other .c files.

taken-from: DragonFlyBSD
 1.29 03-Dec-2019  tkusumi dm: Doesn't need to expose struct cmd_function in a header
 1.28 01-Dec-2019  tkusumi dm: Remove unused dm_dev::dev_type

Given OOP-like architecture of dm target device structure,
dm_dev doesn't need to have self contained target type field,
and in fact this is unused.
 1.27 02-Oct-2014  justin branches: 1.27.20;
dm_target_t reference count is modified with atomic_{inc,dec}_32 so should
be uint_32_t not int
 1.26 14-Jun-2014  hannken Change dk_lookup() to return an anonymous vnode not associated with
any file system. Change all consumers of dk_lookup() to get the
device from "v_rdev" instead of VOP_GETATTR() as specfs does not
support VOP_GETATTR(). Devices obtained with dk_lookup() will no
longer disappear on forced unmounts.

Fix for PR kern/48849 (root mirror raid fails on shutdown)

Welcome to 6.99.44
 1.25 09-Dec-2013  wiz branches: 1.25.2;
Fix typo ("then" instead of "than")
 1.24 28-Jul-2012  matt branches: 1.24.2; 1.24.4;
Fix -fno-common found by building i386/conf/ALL
 1.23 27-Aug-2011  ahoka branches: 1.23.2;
- add a function to get the inactive table's size
- some whitespace fix from emacs...
 1.22 23-Dec-2010  christos 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.21 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.20 06-Dec-2010  haad Add comment about dm_dev minor, and change it to 32bit value we realy not
going to use so much device minor numbers.
 1.19 23-Oct-2010  haad Add old file describing locking schema used in dm driver.
 1.18 18-May-2010  haad Add multi device strip support written by Guillermo Amaral and reviewed by me.
 1.17 29-Dec-2009  haad branches: 1.17.2; 1.17.4;
Add private lock to dm_dev_t used for mutual exclusion for diks(9) api
routines. This change fixes PR kern/42532.
 1.16 06-Dec-2009  haad Make our driver version equal to linux driver.
 1.15 01-Dec-2009  haad Revert my commit which have added knowledge about dm targets to libdevmapper,
this breaks abstraction. Because only lvmtools/lvmlib and device-mapper can
have knowledge about target mapping and libdevmapper only passes requests
from lvmtools to kernel and back. Bump major library and driver version.

Requested by: yamt@
 1.14 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.13 05-Jun-2009  haad Parse dm param string in libdevmapper and not in a dm target init function.
Create proplib param dictionary entry in libdevmapper and pass it to dm in
dm_ioctl dict.
Param target is then passed to target init function, where is parse. I like
this aproach much better than passing char **argv and trusting to user input.

I have bumped minor lib/driver version.

XXX. Add more sanity checks in kernel.
 1.12 25-Mar-2009  dyoung branches: 1.12.2;
It is only by chance that this gets the prop_array_t definition that it
needs, so explicitly #include <prop/proplib.h>.
 1.11 06-Mar-2009  haad Fix lvm lvrename command. There was bug in dm_dev_lookup where
dm_dev_lookup_name was called with device uuid. Remove dm_dev_t:dk_label is
it not used anymore.
 1.10 01-Mar-2009  haad Add initial support for striping target, hardcode maximal number of stripes
to 2 for now. strategy routine must be written, for now only parsing and
support routines are available. This is work in progress code and should be
taken very carefully.
 1.9 19-Feb-2009  haad Add support for autoloading of device-mapper targets modules. Add
dm_target_autoload function which tries to load target module. Fix two
deadlocks in dm_table_load_ioctl error path(I forgot to call dm_dev_unbusy).
 1.8 16-Jan-2009  haad branches: 1.8.2; 1.8.4; 1.8.6;
Add struct disk to dm_dev so our LV will beshowed in iostat output.
 1.7 11-Jan-2009  haad Use 64bit long minor nuber in dm_dev structure.
 1.6 02-Jan-2009  haad Add stubs for mirror target, too. This target does nothing for now, but lvm
tools support mirror target and trying to create LV with mirrorred backend
caused panic in dm_table_load_ioctl.
 1.5 02-Jan-2009  haad Add stripe target functions stubs. Stripe target must be present in dm driver
because without it lvm2tools will not create LVsi and eventualy panic system.

Problem reported by agc@.
 1.4 21-Dec-2008  haad Add support for loading dm targets as separate modules. All targets except
linear can be loaded as module. Module is not loaded when there is target
with similar name already. Zero and error targets aresimple examples how
can be all future targets written to support dynamic loading. Target can't
be unloaded until there is at least one user.
 1.3 19-Dec-2008  haad Add infrastructure needed to load device-mapper targets as modules.
Targets wasn't converted yet and at least snapshot target will be converted
in a near future.
 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.20 05-Nov-2008  haad Fix copyright in TNF licenses.
 1.1.2.19 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.18 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.17 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.16 11-Sep-2008  haad Add new dm_target_*_deps function which will get all dependiences from
selected target. It is used to get device dependencies during
dm_table_deps_ioctl. Remove dm_dev::pdevs list which was really hard to
manage and wasn't use for anything usefull.
 1.1.2.15 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.14 08-Sep-2008  haad Add new version of snapshot code for nowonlyinitial configuration of
snapshots (parsing parameters strings and opening devices was added).

Fixonebug in dm_pdev where was one SLIST_ENTRY used to for global
pdev list and for per device pdev list. This bug was hidden for a
long time because I haven't used devices with more than one pdev.
 1.1.2.13 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.12 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.11 28-Aug-2008  haad Add dm_pdev_lookup_name_list which is used to lookup pdev in device pdev list.

Add new reference counter to struct pdev which is used from device pdev list.
When pdev is inserted from target_init routine increment device pdev list ref_cnt
and remove pdev from list only when this ref. counter is 0.

Avoid problem when to tables with same device can remove pdev from this list.
 1.1.2.10 20-Aug-2008  haad Add initial portion of snapshot code. Divide snapshot code into 2 parts

snapshot-origin and snapshot

First target is used to inform all snapshots about writes to master device.
Snapshot targets implements exception store for changed blocks.

This is how linux does snapshots on lvm2 devices if we want to use lvm2tools,
for snapshots I have to keep this as much compatible as possible to linux.

Change atoi from static to public function now it can be used with other
targets, too.
 1.1.2.9 19-Aug-2008  haad Add dm_*_destroy functions and change type of argument in dm_pdev_decr.
 1.1.2.8 19-Aug-2008  haad Add $NetBSD$ tag to all dm driver sources.
 1.1.2.7 02-Aug-2008  haad Add status functions for zero, error targets these routines are not needed
here, but I want to be consistent (I already define dm_target_*_init).
 1.1.2.6 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.5 28-Jul-2008  haad Add status function to targets. This function is called from dm_table_status_ioctl,
when DM_STATUS_TABLE_FLAG is specified and it's purpose is construct params string.
Which can be sent back to libdevmapper.

Add adding removing of the DM_SUSPENDED_FLAG flag in dm_dev_suspend/resume ioctls.
 1.1.2.4 22-Jul-2008  haad Change parsing of parameter string. Remove knowledge about pramaer string
from dm_table_load_ioctl and move it to target_init routines. Parameter
string is targets specific and therefore only target routine know how to
parse it correctly. Remove unneeded parameter from dm_target_*_init(argc)
and change dm target routines accordingly.

Simplify dm_table_load_ioctl and move pdev inserting code to target init
funstions.
 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.8.6.2 23-Jul-2009  jym Sync with HEAD.
 1.8.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.8.4.4 28-Apr-2009  skrll Sync with HEAD.
 1.8.4.3 03-Mar-2009  skrll Sync with HEAD.
 1.8.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.8.4.1 16-Jan-2009  skrll file dm.h was added on branch nick-hppapmap on 2009-01-19 13:17:52 +0000
 1.8.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.8.2.1 16-Jan-2009  mjf file dm.h was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.12.2.5 11-Aug-2010  yamt sync with head.
 1.12.2.4 11-Mar-2010  yamt sync with head
 1.12.2.3 20-Jun-2009  yamt sync with head
 1.12.2.2 04-May-2009  yamt sync with head.
 1.12.2.1 25-Mar-2009  yamt file dm.h was added on branch yamt-nfs-mp on 2009-05-04 08:12:36 +0000
 1.17.4.2 05-Mar-2011  rmind sync with head
 1.17.4.1 30-May-2010  rmind sync with head
 1.17.2.2 06-Nov-2010  uebayasi Sync with HEAD.
 1.17.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.23.2.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.23.2.1 30-Oct-2012  yamt sync with head
 1.24.4.1 18-May-2014  rmind sync with head
 1.24.2.2 03-Dec-2017  jdolecek update from HEAD
 1.24.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.25.2.1 10-Aug-2014  tls Rebase.
 1.27.20.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.54.2.1 25-Jan-2020  ad Sync with head.
 1.19 21-Aug-2021  andvar fix typos in sys/dev/dm code comments and documentation.
also remove some trailing space in documentation.
 1.18 08-Jul-2020  thorpej Adapt to proplib API chanages.
 1.17 31-Dec-2019  tkusumi dm: Remove unnecessary inlining

These two don't really need to be inlined.
 1.16 15-Dec-2019  tkusumi dm: Style cleanups (no functional changes)
 1.15 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.14 07-Dec-2019  tkusumi dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD
 1.13 04-Dec-2019  tkusumi dm: style + whitespace + indentation fixes

No functional changes.
 1.12 03-Dec-2019  tkusumi dm: Make global dm locks static

These are all per-file locks which protect dev/pdev/target structure.
taken-from: DragonFlyBSD
 1.11 05-Jan-2018  christos branches: 1.11.4;
use some size_t, add whitespace between functions, rcsids.
 1.10 01-Jun-2017  chs remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
 1.9 18-Oct-2014  snj branches: 1.9.2;
src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.8 04-Jan-2010  haad branches: 1.8.22;
Indent files remove unnecessary blank lines, white spaces and KNFize code.
 1.7 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.6 09-Sep-2009  haad Fix bug in kmem_alloc/kmem_free of params string. Params string was
allocated with length DM_MAX_PARAMS_SIZE and released with strlen + 1 size.

Disable KM_NOSLEEP allocation because we do not need them here there is
nothing critical in ioctl part of dm driver.

Bug reported by jak@.
 1.5 13-Apr-2009  haad branches: 1.5.2;
Destroy locks in dm_dev_free, do not allocate struct disk twice.
 1.4 18-Mar-2009  cegger Ansify function definitions w/o arguments. Generated with sed.
 1.3 06-Mar-2009  haad Fix lvm lvrename command. There was bug in dm_dev_lookup where
dm_dev_lookup_name was called with device uuid. Remove dm_dev_t:dk_label is
it not used anymore.
 1.2 19-Dec-2008  haad branches: 1.2.2; 1.2.4; 1.2.6;
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.15 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.14 05-Nov-2008  haad Fix copyright in TNF licenses.
 1.1.2.13 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.12 16-Oct-2008  haad Be consistent when calling struct dm_dev. Use name dmv when possible.
Change DISABLE_DEV macro to inline function.
 1.1.2.11 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.10 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.9 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.8 08-Sep-2008  haad Small code style fixes suggested by rmind@.
 1.1.2.7 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.6 28-Aug-2008  haad Remove dm_dev_free from dm_dev_remove. When removing device from system
I have to write lock device rw_lock(disable all IO on device) remove
device from global list of devices and only after destroing lock I can
free device structure.

Fix lockdebug panic.
 1.1.2.5 19-Aug-2008  haad Add dm_target_destroy and dm_dev_destroy functions these functions
are used to free all devices and targets. So I will not leak any memory
after kmod unload.
 1.1.2.4 19-Aug-2008  haad Add $NetBSD$ tag to all dm driver sources.
 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.2.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.2.4.3 28-Apr-2009  skrll Sync with HEAD.
 1.2.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.2.4.1 19-Dec-2008  skrll file dm_dev.c was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.2.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.2.1 19-Dec-2008  mjf file dm_dev.c was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.5.2.4 11-Mar-2010  yamt sync with head
 1.5.2.3 16-Sep-2009  yamt sync with head
 1.5.2.2 04-May-2009  yamt sync with head.
 1.5.2.1 13-Apr-2009  yamt file dm_dev.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:36 +0000
 1.8.22.1 03-Dec-2017  jdolecek update from HEAD
 1.9.2.1 28-Aug-2017  skrll Sync with HEAD
 1.11.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.57 14-Jan-2024  mlelstv Avoid leaving a configured device without resources.
 1.56 13-Oct-2022  andvar s/exaple/example/
 1.55 21-Aug-2021  andvar fix typos in sys/dev/dm code comments and documentation.
also remove some trailing space in documentation.
 1.54 20-Aug-2021  andvar fix various typos in comments and log messages.
 1.53 24-Jul-2021  andvar Fix all remaining typos, mainly in comments but also in few definitions and log messages, reported by me in PR kern/54889.
Also fixed some additional typos in comments, found on review of same files or typos.
 1.52 21-Jun-2021  christos fix proplib deprecation
 1.51 07-May-2021  hannken Make sure the unit number of device-mapper devices matches their minor number.
 1.50 08-Jul-2020  thorpej branches: 1.50.6;
Adapt to proplib API chanages.
 1.49 23-Dec-2019  tkusumi dm: Make target's ->table() optional

Since ->info() (counter part of ->table() in the original dm design
in Linux kernel in .status where both INFO and TABLE are optional)
is an optional handler, make ->table() optional as well. Some
targets don't have anything to do in ->table() just as in ->info().

taken-from: DragonFlyBSD
 1.48 21-Dec-2019  tkusumi dm: Remove target's ->deps() by implementing deps in dm core

Retrieving device dependencies doesn't need to be target specific.
The reason it currently needs ->deps() is because dm core doesn't
have data structure that allows table to walk through target's
underlying devices. Add struct dm_mapping to be able to do this,
and remove ->deps()'s from targets which basically do the same thing.

=====(A) before this commit
table
| [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

=====(B) this commit
table---->mapping-->mapping-->mapping-->...
| | | |
| v v v [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

taken-from: DragonFlyBSD
 1.47 19-Dec-2019  tkusumi dm: Minor dm_ioctl.c fixes (indentation/typo/type/etc)
 1.46 15-Dec-2019  tkusumi dm: Style cleanups (no functional changes)
 1.45 15-Dec-2019  tkusumi dm: Rename targets' ->status() to ->table() given ->info() exists

Since now that dm targets in NetBSD have ->info() for "status",
->status() should be renamed to ->table() for "table",
given how dm target status was originally designed in Linux kernel.

taken-from: DragonFlyBSD
 1.44 14-Dec-2019  tkusumi dm: Don't try to implement "status" as subset of "table"

The way dm_table_status_ioctl() implements "status" and "table" is
not compatible with Linux kernel. Some targets have different outputs
that "status" can't be implemented as subset of "table".

Add ->info() handler to sync with "status" behavior in Linux kernel.
Some targets which currently exist in NetBSD (I think striped)
as well as some minor targets that I plan to port to NetBSD
can/should implement ->info(), but will do that in a different commit.

taken-from: DragonFlyBSD
 1.43 14-Dec-2019  tkusumi dm: Make dm_dbg_print_flags() take uint32_t flag

which comes from prop_dictionary_get_uint32() result.
taken-from: DragonFlyBSD
 1.42 14-Dec-2019  tkusumi dm: Move extern declaration of global variables to dm.h
 1.41 12-Dec-2019  tkusumi dm: Make target's ->init() take parsed argc and argv

This gets rid of the same parser code in each target using strsep(3).
taken-from: DragonFlyBSD
 1.40 08-Dec-2019  tkusumi dm: Refactor target's ->init() i/f

Take dm_table_entry_t* instead of void**.
Remove dm_dev_t* unneeded by target code.
No functional change, but for future changes.

taken-from: DragonFlyBSD
 1.39 06-Dec-2019  tkusumi dm: Fix typos in comments/messages

taken-from: DragonFlyBSD
 1.38 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.37 04-Dec-2019  tkusumi dm: style + whitespace + indentation fixes

No functional changes.
 1.36 03-Dec-2019  tkusumi dm: Include <sys/vnode.h> in dm.h

dm.h already depends on vnode, so have dm.h include <sys/vnode.h>
instead of other .c files.

taken-from: DragonFlyBSD
 1.35 01-Dec-2019  tkusumi dm: Remove unused dm_dev::dev_type

Given OOP-like architecture of dm target device structure,
dm_dev doesn't need to have self contained target type field,
and in fact this is unused.
 1.34 30-Nov-2019  tkusumi 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
 1.33 11-Nov-2018  mlelstv Only _if_ an inactive table has been loaded, make it active when resuming.
Fixes lvrename operation.
 1.32 05-Jan-2018  christos branches: 1.32.2; 1.32.4;
PR/52900: Tomohiro Kusumi: Fix kernel panic when target's ->init() failed
Reliably unbusy the target in the *all* the destroy routines, so ioctl
does not need to do it.
 1.31 01-Jun-2017  chs remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
 1.30 10-May-2015  christos branches: 1.30.8;
CID 976256: Help coverity understand that when the list is empty the head
is NULL.
 1.29 02-Oct-2014  justin branches: 1.29.2;
Call prop_dictionary_get_uint32 with uint32_t
 1.28 24-Dec-2013  mlelstv release proplib iterator in failure paths.
 1.27 18-Oct-2013  christos remove unused variables
 1.26 27-Aug-2011  ahoka branches: 1.26.2; 1.26.12; 1.26.16;
- add a function to get the inactive table's size
- some whitespace fix from emacs...
 1.25 24-May-2011  joerg Fix logic error
 1.24 06-Dec-2010  haad branches: 1.24.2;
We don't need 64 bit variable for dm_device coutner, too.
 1.23 06-Dec-2010  haad Add comment about dm_dev minor, and change it to 32bit value we realy not
going to use so much device minor numbers.
 1.22 18-May-2010  haad Fix typo in comment.
 1.21 25-Feb-2010  jakllsch branches: 1.21.2;
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.20 04-Jan-2010  haad branches: 1.20.2;
Indent files remove unnecessary blank lines, white spaces and KNFize code.
 1.19 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.18 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.17 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.16 05-Dec-2009  haad Fix bug in dm_table_resume_ioctl where dmv->flags was sent back to libdevmapper
except flags variable. This fixes weird behaviour, when worng links to
devices in /dev/mapper were created after lvrename/lvresize.
 1.15 01-Dec-2009  haad Revert my commit which have added knowledge about dm targets to libdevmapper,
this breaks abstraction. Because only lvmtools/lvmlib and device-mapper can
have knowledge about target mapping and libdevmapper only passes requests
from lvmtools to kernel and back. Bump major library and driver version.

Requested by: yamt@
 1.14 09-Sep-2009  haad Fix bug in kmem_alloc/kmem_free of params string. Params string was
allocated with length DM_MAX_PARAMS_SIZE and released with strlen + 1 size.

Disable KM_NOSLEEP allocation because we do not need them here there is
nothing critical in ioctl part of dm driver.

Bug reported by jak@.
 1.13 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.12 05-Jun-2009  haad Parse dm param string in libdevmapper and not in a dm target init function.
Create proplib param dictionary entry in libdevmapper and pass it to dm in
dm_ioctl dict.
Param target is then passed to target init function, where is parse. I like
this aproach much better than passing char **argv and trusting to user input.

I have bumped minor lib/driver version.

XXX. Add more sanity checks in kernel.
 1.11 13-Apr-2009  haad branches: 1.11.2;
Destroy locks in dm_dev_free, do not allocate struct disk twice.
 1.10 06-Apr-2009  haad 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.9 08-Mar-2009  agc Fix tyop in previous.
 1.8 20-Feb-2009  haad Release tables before we drop reference on device, now creating device with
nonexistent target fails and not ends with deadlock.
 1.7 19-Feb-2009  haad Add support for autoloading of device-mapper targets modules. Add
dm_target_autoload function which tries to load target module. Fix two
deadlocks in dm_table_load_ioctl error path(I forgot to call dm_dev_unbusy).
 1.6 16-Jan-2009  haad branches: 1.6.2; 1.6.4; 1.6.6;
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.5 11-Jan-2009  haad Use 64bit long minor nuber in dm_dev structure.
 1.4 21-Dec-2008  haad Fix error path in target_init call. When initializing target fails i have
to release table before I try to destroy it and I haveto unbusy device, too.
 1.3 19-Dec-2008  haad Add infrastructure needed to load device-mapper targets as modules.
Targets wasn't converted yet and at least snapshot target will be converted
in a near future.
 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.23 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.22 05-Nov-2008  haad Fix copyright in TNF licenses.
 1.1.2.21 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.20 29-Oct-2008  haad Fix locking in dm_table_load_ioctl. With new locking architecture is not
allowed to call write table operation (dm_table_destroy,
dm_table_switch_tables) after dm_table_get_entry call. Because after
after table_get_entry call we are holding table reference counter and
writer table functions will sleep while reference counter is 0.
 1.1.2.19 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.18 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.17 22-Sep-2008  haad Fix bug where I tried to prop_object_release null object which caused weird
atuvm panic. Change init functions to failed when they receive params string
== NULL when they need some data.
 1.1.2.16 11-Sep-2008  haad Add new dm_target_*_deps function which will get all dependiences from
selected target. It is used to get device dependencies during
dm_table_deps_ioctl. Remove dm_dev::pdevs list which was really hard to
manage and wasn't use for anything usefull.
 1.1.2.15 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.14 08-Sep-2008  haad Add new version of snapshot code for nowonlyinitial configuration of
snapshots (parsing parameters strings and opening devices was added).

Fixonebug in dm_pdev where was one SLIST_ENTRY used to for global
pdev list and for per device pdev list. This bug was hidden for a
long time because I haven't used devices with more than one pdev.
 1.1.2.13 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.12 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.11 28-Aug-2008  haad Add new parameters to netbsd proplib protocol. Fix flags manipulation
in our driver it should behaves like linux now. Fix other minor protocol
differences.
 1.1.2.10 20-Aug-2008  haad Fix bug reported by blymn@, after failed dm_target_*_init I haven't cleaned
tables properly and therefore after next try I get panic.

Fix dm_dev_remove_ioctl to properly remove pdevs from a device list.
 1.1.2.9 19-Aug-2008  haad Remove unnecessary call of dm_pdev_rem in dm_table_load. Change dm_dev_remove
to call dm_pdev_decr for all devices in pdev list.

Because target config contains pdevs I have to decrement them in
dm_target_*_destroy.
 1.1.2.8 19-Aug-2008  haad Add $NetBSD$ tag to all dm driver sources.
 1.1.2.7 02-Aug-2008  haad Fix dm_table_status_ioctl error path. When there is no active table ioctl
routine have to return.
 1.1.2.6 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.5 28-Jul-2008  haad Add status function to targets. This function is called from dm_table_status_ioctl,
when DM_STATUS_TABLE_FLAG is specified and it's purpose is construct params string.
Which can be sent back to libdevmapper.

Add adding removing of the DM_SUSPENDED_FLAG flag in dm_dev_suspend/resume ioctls.
 1.1.2.4 22-Jul-2008  haad Change parsing of parameter string. Remove knowledge about pramaer string
from dm_table_load_ioctl and move it to target_init routines. Parameter
string is targets specific and therefore only target routine know how to
parse it correctly. Remove unneeded parameter from dm_target_*_init(argc)
and change dm target routines accordingly.

Simplify dm_table_load_ioctl and move pdev inserting code to target init
funstions.
 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.6.6.2 23-Jul-2009  jym Sync with HEAD.
 1.6.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.6.4.4 28-Apr-2009  skrll Sync with HEAD.
 1.6.4.3 03-Mar-2009  skrll Sync with HEAD.
 1.6.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.6.4.1 16-Jan-2009  skrll file dm_ioctl.c was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.6.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.6.2.1 16-Jan-2009  mjf file dm_ioctl.c was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.11.2.6 11-Aug-2010  yamt sync with head.
 1.11.2.5 11-Mar-2010  yamt sync with head
 1.11.2.4 16-Sep-2009  yamt sync with head
 1.11.2.3 20-Jun-2009  yamt sync with head
 1.11.2.2 04-May-2009  yamt sync with head.
 1.11.2.1 13-Apr-2009  yamt file dm_ioctl.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:36 +0000
 1.20.2.2 17-Aug-2010  uebayasi Sync with HEAD.
 1.20.2.1 30-Apr-2010  uebayasi Sync with HEAD.
 1.21.2.3 31-May-2011  rmind sync with head
 1.21.2.2 05-Mar-2011  rmind sync with head
 1.21.2.1 30-May-2010  rmind sync with head
 1.24.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.26.16.1 18-May-2014  rmind sync with head
 1.26.12.2 03-Dec-2017  jdolecek update from HEAD
 1.26.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.26.2.1 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.29.2.2 28-Aug-2017  skrll Sync with HEAD
 1.29.2.1 06-Jun-2015  skrll Sync with HEAD
 1.30.8.1 17-May-2017  pgoyette At suggestion of chuq@, modify config_attach_pseudo() to return with a
reference held on the device.

Adapt callers to expect the reference to exist, and to ensure that the
reference is released.
 1.32.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.32.4.1 10-Jun-2019  christos Sync with HEAD
 1.32.2.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.50.6.2 01-Aug-2021  thorpej Sync with HEAD.
 1.50.6.1 13-May-2021  thorpej Sync with HEAD.
 1.23 21-Aug-2021  andvar fix typos in sys/dev/dm code comments and documentation.
also remove some trailing space in documentation.
 1.22 20-Dec-2019  tkusumi dm: Fix "table" output format of dm-linear and dm-stripe

The existing "table" output showing device file path of pdev is
not compatible with dm in Linux kernel (and also DragonFlyBSD).
It should be showing "major:minor" instead.

taken-from: DragonFlyBSD
 1.21 15-Dec-2019  tkusumi dm: Style cleanups (no functional changes)
 1.20 13-Dec-2019  tkusumi dm: Fix memory leak in dm_pdev_rem()

Need to free dmp regardless of dm_pdev_rem() return value.
taken-from: DragonFlyBSD
 1.19 08-Dec-2019  mlelstv Switch to vn_bdev_open* functions.
 1.18 07-Dec-2019  tkusumi dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD
 1.17 07-Dec-2019  tkusumi dm: Simplify list eviction code

taken-from: DragonFlyBSD
 1.16 06-Dec-2019  tkusumi dm: Remove trailing whitespace
 1.15 04-Dec-2019  tkusumi dm: Minor fixes/cleanups
 1.14 04-Dec-2019  tkusumi dm: style + whitespace + indentation fixes

No functional changes.
 1.13 03-Dec-2019  tkusumi dm: Make global dm locks static

These are all per-file locks which protect dev/pdev/target structure.
taken-from: DragonFlyBSD
 1.12 03-Dec-2019  tkusumi dm: Include <sys/vnode.h> in dm.h

dm.h already depends on vnode, so have dm.h include <sys/vnode.h>
instead of other .c files.

taken-from: DragonFlyBSD
 1.11 01-Dec-2019  tkusumi dm: Fix race on pdev create

List lookup and insert need to be atomic.
https://github.com/DragonFlyBSD/DragonFlyBSD/commit/ac816675c8321309b49d6a335f95c5388036803f

take-from: DragonFlyBSD
 1.10 05-Jan-2018  christos branches: 1.10.4;
use some size_t, add whitespace between functions, rcsids.
 1.9 01-Jun-2017  chs remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
 1.8 23-Dec-2010  mlelstv branches: 1.8.18; 1.8.36;
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.7 19-Nov-2010  dholland Introduce struct pathbuf. This is an abstraction to hold a pathname
and the metadata required to interpret it. Callers of namei must now
create a pathbuf and pass it to NDINIT (instead of a string and a
uio_seg), then destroy the pathbuf after the namei session is
complete.

Update all namei call sites accordingly. Add a pathbuf(9) man page and
update namei(9).

The pathbuf interface also now appears in a couple of related
additional places that were passing string/uio_seg pairs that were
later fed into NDINIT. Update other call sites accordingly.
 1.6 04-Jan-2010  haad branches: 1.6.4;
Indent files remove unnecessary blank lines, white spaces and KNFize code.
 1.5 03-Jan-2010  haad Replace aprint_Verbose with aprint_debug to shutup unnecessary logs.
 1.4 09-Sep-2009  haad Fix bug in kmem_alloc/kmem_free of params string. Params string was
allocated with length DM_MAX_PARAMS_SIZE and released with strlen + 1 size.

Disable KM_NOSLEEP allocation because we do not need them here there is
nothing critical in ioctl part of dm driver.

Bug reported by jak@.
 1.3 18-Mar-2009  cegger branches: 1.3.2;
Ansify function definitions w/o arguments. Generated with sed.
 1.2 19-Dec-2008  haad branches: 1.2.2; 1.2.4; 1.2.6;
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.13 05-Nov-2008  haad Fix copyright in TNF licenses.
 1.1.2.12 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.11 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.10 11-Sep-2008  haad Add new dm_target_*_deps function which will get all dependiences from
selected target. It is used to get device dependencies during
dm_table_deps_ioctl. Remove dm_dev::pdevs list which was really hard to
manage and wasn't use for anything usefull.
 1.1.2.9 08-Sep-2008  haad Add new version of snapshot code for nowonlyinitial configuration of
snapshots (parsing parameters strings and opening devices was added).

Fixonebug in dm_pdev where was one SLIST_ENTRY used to for global
pdev list and for per device pdev list. This bug was hidden for a
long time because I haven't used devices with more than one pdev.
 1.1.2.8 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.7 28-Aug-2008  haad Add dm_pdev_lookup_name_list which is used to lookup pdev in device pdev list.

Add new reference counter to struct pdev which is used from device pdev list.
When pdev is inserted from target_init routine increment device pdev list ref_cnt
and remove pdev from list only when this ref. counter is 0.

Avoid problem when to tables with same device can remove pdev from this list.
 1.1.2.6 20-Aug-2008  haad Fix memory leak and use vn_close to close pdev vnode in dm_pdev_rem.

With this change dmsetup remove works again.
 1.1.2.5 19-Aug-2008  haad Add dm_pdev_destroy routine. Change behaviour of dm_pdev_decr to decrement
only reference counter for one dm_pdev and not for all pdevs in a list.

Change dm_pdev_rem to static because it is only used in dm.pdev.c. Add note
to comment that dm_pdev_rem must be called with held pdev mutex.
 1.1.2.4 19-Aug-2008  haad Add $NetBSD$ tag to all dm driver sources.
 1.1.2.3 29-Jul-2008  haad Fix locking issues find by @blymn. dm_pdev_insert dmp->ref_cnt was
incremented without held mutex. Hold mutex during dm_pdev_decr run.
 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.2.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.2.4.3 28-Apr-2009  skrll Sync with HEAD.
 1.2.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.2.4.1 19-Dec-2008  skrll file dm_pdev.c was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.2.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.2.1 19-Dec-2008  mjf file dm_pdev.c was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.3.2.4 11-Mar-2010  yamt sync with head
 1.3.2.3 16-Sep-2009  yamt sync with head
 1.3.2.2 04-May-2009  yamt sync with head.
 1.3.2.1 18-Mar-2009  yamt file dm_pdev.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:36 +0000
 1.6.4.1 05-Mar-2011  rmind sync with head
 1.8.36.1 28-Aug-2017  skrll Sync with HEAD
 1.8.18.1 03-Dec-2017  jdolecek update from HEAD
 1.10.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.21 21-Aug-2021  andvar fix typos in sys/dev/dm code comments and documentation.
also remove some trailing space in documentation.
 1.20 20-Aug-2021  andvar fix various typos in comments and log messages.
 1.19 31-Dec-2019  tkusumi dm: Remove unnecessary inlining

These two don't really need to be inlined.
 1.18 22-Dec-2019  tkusumi dm: Make numsec/secsize arguments in dm_table_disksize() optional
 1.17 21-Dec-2019  tkusumi dm: Remove target's ->deps() by implementing deps in dm core

Retrieving device dependencies doesn't need to be target specific.
The reason it currently needs ->deps() is because dm core doesn't
have data structure that allows table to walk through target's
underlying devices. Add struct dm_mapping to be able to do this,
and remove ->deps()'s from targets which basically do the same thing.

=====(A) before this commit
table
| [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

=====(B) this commit
table---->mapping-->mapping-->mapping-->...
| | | |
| v v v [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

taken-from: DragonFlyBSD
 1.16 15-Dec-2019  tkusumi dm: Style cleanups (no functional changes)
 1.15 15-Dec-2019  tkusumi dm: Make targets' ->secsize() optional

and make a caller assume secsize 0 if ->secsize not present.
This allows a dummy function to be removed which was added in
"dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)".
 1.14 15-Dec-2019  tkusumi dm: "unsigned" -> "unsigned int" for consistency

Use either one, but not both.
 1.13 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.12 07-Dec-2019  tkusumi dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD
 1.11 07-Dec-2019  tkusumi dm: Simplify list eviction code

taken-from: DragonFlyBSD
 1.10 05-Dec-2019  tkusumi dm: Make dm core set config to NULL after destroy

Just let dm core do this instead of having a comment expecting each
target to do the right thing.

taken-from: DragonFlyBSD
 1.9 04-Dec-2019  tkusumi dm: style + whitespace + indentation fixes

No functional changes.
 1.8 05-Jan-2018  christos branches: 1.8.4;
use some size_t, add whitespace between functions, rcsids.
 1.7 27-Aug-2011  ahoka add function to get the inactive table size (for during target init)
 1.6 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.5 04-Jan-2010  haad branches: 1.5.4;
Indent files remove unnecessary blank lines, white spaces and KNFize code.
 1.4 23-Oct-2009  joerg Reduce a noise from a debug printf to debug level
 1.3 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.2 19-Dec-2008  haad branches: 1.2.2; 1.2.4; 1.2.6; 1.2.8;
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.12 05-Nov-2008  haad Fix copyright in TNF licenses.
 1.1.2.11 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.10 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.9 08-Sep-2008  haad Fix comment in dm_table and change target alloc function suggested by rmind@.
 1.1.2.8 04-Sep-2008  haad Remove unneeded includes.
 1.1.2.7 19-Aug-2008  haad Add $NetBSD$ tag to all dm driver sources.
 1.1.2.6 02-Aug-2008  haad Fix dm_table_destroy, use example code from queue.h. This should fix
dmsetup remove for zero/error target device.
 1.1.2.5 29-Jul-2008  haad Change comment in dm_table_destroy and dm-target_linear_init.
These functions should be called with per device mutex held.
 1.1.2.4 28-Jul-2008  haad Add status function to targets. This function is called from dm_table_status_ioctl,
when DM_STATUS_TABLE_FLAG is specified and it's purpose is construct params string.
Which can be sent back to libdevmapper.

Add adding removing of the DM_SUSPENDED_FLAG flag in dm_dev_suspend/resume ioctls.
 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.2.8.4 11-Mar-2010  yamt sync with head
 1.2.8.3 18-Jul-2009  yamt sync with head.
 1.2.8.2 04-May-2009  yamt sync with head.
 1.2.8.1 19-Dec-2008  yamt file dm_table.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:36 +0000
 1.2.6.1 23-Jul-2009  jym Sync with HEAD.
 1.2.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.2.4.1 19-Dec-2008  skrll file dm_table.c was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.2.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.2.1 19-Dec-2008  mjf file dm_table.c was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.5.4.1 05-Mar-2011  rmind sync with head
 1.8.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.42 21-Aug-2021  andvar fix typos in sys/dev/dm code comments and documentation.
also remove some trailing space in documentation.
 1.41 08-Jul-2020  thorpej Adapt to proplib API chanages.
 1.40 21-Jan-2020  tkusumi dm: #if0 target's ->upcall() handler

This is part of NetBSD's dm design, but unimplemented
(all handlers return 0) and also unused.
 1.39 05-Jan-2020  tkusumi branches: 1.39.2;
dm: Add dm-delay target

Ported from DragonFlyBSD, but this target had originally existed in
Linux kernel. See below for details.
https://www.kernel.org/doc/Documentation/device-mapper/delay.txt

Due to "tick" in hz(9) not working (which results in dmdlthread spinning
forever in _submit_queue() without dp extracted from delayed list
and queued into submit list), this hasn't been hooked to dm.kmod yet.

taken-from: DragonFlyBSD
 1.38 02-Jan-2020  tkusumi dm: Add dm-flakey target

Ported from DragonFlyBSD, but this target had originally existed in
Linux kernel. See below for details.
https://www.kernel.org/doc/Documentation/device-mapper/dm-flakey.txt

Due to two technical issues, this hasn't been hooked to dm.kmod yet.
1) "tick" in hz(9) not working.
2) Unable to use ->b_private in nestiobuf callback when it's already
used for mbp (see HAS_BUF_PRIV2).

taken-from: DragonFlyBSD
 1.37 23-Dec-2019  tkusumi dm: Make target's ->table() optional

Since ->info() (counter part of ->table() in the original dm design
in Linux kernel in .status where both INFO and TABLE are optional)
is an optional handler, make ->table() optional as well. Some
targets don't have anything to do in ->table() just as in ->info().

taken-from: DragonFlyBSD
 1.36 21-Dec-2019  tkusumi dm: Fix dm-stripe's "status" output format

As mentioned in "dm: Don't try to implement "status" as subset of "table"",
dm-stripe in NetBSD doesn't have correct "status" output format.
Implement ->info() to sync with Linux kernel.

Note that num_error for stripe device isn't implemented yet.

taken-from: DragonFlyBSD
 1.35 21-Dec-2019  tkusumi dm: Remove target's ->deps() by implementing deps in dm core

Retrieving device dependencies doesn't need to be target specific.
The reason it currently needs ->deps() is because dm core doesn't
have data structure that allows table to walk through target's
underlying devices. Add struct dm_mapping to be able to do this,
and remove ->deps()'s from targets which basically do the same thing.

=====(A) before this commit
table
| [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

=====(B) this commit
table---->mapping-->mapping-->mapping-->...
| | | |
| v v v [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

taken-from: DragonFlyBSD
 1.34 19-Dec-2019  tkusumi dm: u_{int,long} -> unsigned {int,long}
 1.33 16-Dec-2019  tkusumi dm: Enable dm-error and dm-zero target

Add these two targets to dm.kmod.
These are generally available in Linux and DragonFlyBSD,
so enable them in NetBSD as well.
 1.32 15-Dec-2019  tkusumi dm: Style cleanups (no functional changes)
 1.31 15-Dec-2019  tkusumi dm: Make targets' ->sync() optional

Apparently some targets have nothing to sync, so make it optional.
 1.30 15-Dec-2019  tkusumi dm: Make targets' ->secsize() optional

and make a caller assume secsize 0 if ->secsize not present.
This allows a dummy function to be removed which was added in
"dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)".
 1.29 15-Dec-2019  tkusumi dm: Rename targets' ->status() to ->table() given ->info() exists

Since now that dm targets in NetBSD have ->info() for "status",
->status() should be renamed to ->table() for "table",
given how dm target status was originally designed in Linux kernel.

taken-from: DragonFlyBSD
 1.28 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.27 13-Dec-2019  tkusumi dm: Don't KASSERT() target handlers

Having assertions here causes panic if target is missing anything
as shown in "dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)".
Instead just return EINVAL if a handler(s) isn't implemented.

taken-from: DragonFlyBSD
 1.26 08-Dec-2019  tkusumi dm: Unbreak compilation of kernel modules

The dm kernel modules (MK_DM_TARGETS enabled in sys/modules/dm/Makefile)
have been broken. Unbreak the build.
 1.25 07-Dec-2019  tkusumi dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD
 1.24 07-Dec-2019  tkusumi dm: Simplify list eviction code

taken-from: DragonFlyBSD
 1.23 06-Dec-2019  tkusumi dm: Don't ignore dm_target_alloc() argument

dm_target_alloc() is supposed to be copying the name argument to its ->name.
taken-from: DragonFlyBSD
 1.22 04-Dec-2019  tkusumi dm: style + whitespace + indentation fixes

No functional changes.
 1.21 03-Dec-2019  tkusumi dm: Make global dm locks static

These are all per-file locks which protect dev/pdev/target structure.
taken-from: DragonFlyBSD
 1.20 05-Jan-2018  christos branches: 1.20.4;
use some size_t, add whitespace between functions, rcsids.
 1.19 18-Oct-2014  snj src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
 1.18 28-Aug-2011  ahoka branches: 1.18.12;
readd assertions noew with the correct struct
im wondering why the module cflags didnt warn about this obvious typo
 1.17 27-Aug-2011  joerg Revert last, assertions on undefined variables don't make sense.
 1.16 27-Aug-2011  ahoka Add a sanity check for missing functions in dmt
 1.15 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.14 21-Aug-2010  pgoyette Update the rest of the kernel to conform to the module subsystem's new
locking protocol.
 1.13 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.12 04-Jan-2010  haad branches: 1.12.2; 1.12.4;
Indent files remove unnecessary blank lines, white spaces and KNFize code.
 1.11 09-Sep-2009  haad Fix bug in kmem_alloc/kmem_free of params string. Params string was
allocated with length DM_MAX_PARAMS_SIZE and released with strlen + 1 size.

Disable KM_NOSLEEP allocation because we do not need them here there is
nothing critical in ioctl part of dm driver.

Bug reported by jak@.
 1.10 16-Aug-2009  yamt fix a comment typo.
 1.9 20-Feb-2009  haad branches: 1.9.2;
Call dm_target_busy only on properly autoloaded module.
 1.8 19-Feb-2009  haad In NetBSD our target modules are called with prefix dm_target_. Add this
prefix to target module name when loading module, lvm2tools uses linux
target names e.g. zero not dm_target_zero.
 1.7 19-Feb-2009  haad Add support for autoloading of device-mapper targets modules. Add
dm_target_autoload function which tries to load target module. Fix two
deadlocks in dm_table_load_ioctl error path(I forgot to call dm_dev_unbusy).
 1.6 02-Jan-2009  haad branches: 1.6.2; 1.6.4; 1.6.6;
Add stubs for mirror target, too. This target does nothing for now, but lvm
tools support mirror target and trying to create LV with mirrorred backend
caused panic in dm_table_load_ioctl.
 1.5 02-Jan-2009  haad Add stripe target functions stubs. Stripe target must be present in dm driver
because without it lvm2tools will not create LVsi and eventualy panic system.

Problem reported by agc@.
 1.4 21-Dec-2008  haad Add support for loading dm targets as separate modules. All targets except
linear can be loaded as module. Module is not loaded when there is target
with similar name already. Zero and error targets aresimple examples how
can be all future targets written to support dynamic loading. Target can't
be unloaded until there is at least one user.
 1.3 19-Dec-2008  haad Add infrastructure needed to load device-mapper targets as modules.
Targets wasn't converted yet and at least snapshot target will be converted
in a near future.
 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 11-Sep-2008  haad Add new dm_target_*_deps function which will get all dependiences from
selected target. It is used to get device dependencies during
dm_table_deps_ioctl. Remove dm_dev::pdevs list which was really hard to
manage and wasn't use for anything usefull.
 1.1.2.12 08-Sep-2008  haad Fix comment in dm_table and change target alloc function suggested by rmind@.
 1.1.2.11 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.10 20-Aug-2008  haad Add initial portion of snapshot code. Divide snapshot code into 2 parts

snapshot-origin and snapshot

First target is used to inform all snapshots about writes to master device.
Snapshot targets implements exception store for changed blocks.

This is how linux does snapshots on lvm2 devices if we want to use lvm2tools,
for snapshots I have to keep this as much compatible as possible to linux.

Change atoi from static to public function now it can be used with other
targets, too.
 1.1.2.9 19-Aug-2008  haad Add dm_target_destroy and dm_dev_destroy functions these functions
are used to free all devices and targets. So I will not leak any memory
after kmod unload.
 1.1.2.8 19-Aug-2008  haad Add $NetBSD$ tag to all dm driver sources.
 1.1.2.7 02-Aug-2008  haad Add status routines and fix small overflow dmt was allocated as "zero" and
was user for a "error".
 1.1.2.6 29-Jul-2008  haad Fix dm_target_rem. Remove unneeded goto and use return directly.
 1.1.2.5 28-Jul-2008  haad Add status function to targets. This function is called from dm_table_status_ioctl,
when DM_STATUS_TABLE_FLAG is specified and it's purpose is construct params string.
Which can be sent back to libdevmapper.

Add adding removing of the DM_SUSPENDED_FLAG flag in dm_dev_suspend/resume ioctls.
 1.1.2.4 19-Jul-2008  haad Fix previous commit. device-mapper driver should build fine now.
 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.6.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.6.4.3 03-Mar-2009  skrll Sync with HEAD.
 1.6.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.6.4.1 02-Jan-2009  skrll file dm_target.c was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.6.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.6.2.1 02-Jan-2009  mjf file dm_target.c was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.9.2.7 09-Oct-2010  yamt sync with head
 1.9.2.6 11-Aug-2010  yamt sync with head.
 1.9.2.5 11-Mar-2010  yamt sync with head
 1.9.2.4 16-Sep-2009  yamt sync with head
 1.9.2.3 19-Aug-2009  yamt sync with head.
 1.9.2.2 04-May-2009  yamt sync with head.
 1.9.2.1 20-Feb-2009  yamt file dm_target.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:36 +0000
 1.12.4.2 05-Mar-2011  rmind sync with head
 1.12.4.1 30-May-2010  rmind sync with head
 1.12.2.2 22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.12.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.18.12.1 03-Dec-2017  jdolecek update from HEAD
 1.20.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.39.2.1 25-Jan-2020  ad Sync with head.
 1.2 21-Jan-2020  tkusumi branches: 1.2.4;
dm: #if0 target's ->upcall() handler

This is part of NetBSD's dm design, but unimplemented
(all handlers return 0) and also unused.
 1.1 05-Jan-2020  tkusumi branches: 1.1.2;
dm: Add dm-delay target

Ported from DragonFlyBSD, but this target had originally existed in
Linux kernel. See below for details.
https://www.kernel.org/doc/Documentation/device-mapper/delay.txt

Due to "tick" in hz(9) not working (which results in dmdlthread spinning
forever in _submit_queue() without dp extracted from delayed list
and queued into submit list), this hasn't been hooked to dm.kmod yet.

taken-from: DragonFlyBSD
 1.1.2.1 25-Jan-2020  ad Sync with head.
 1.2.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.2.4.1 21-Jan-2020  martin file dm_target_delay.c was added on branch phil-wifi on 2020-04-08 14:08:03 +0000
 1.29 21-Jan-2020  tkusumi dm: #if0 target's ->upcall() handler

This is part of NetBSD's dm design, but unimplemented
(all handlers return 0) and also unused.
 1.28 23-Dec-2019  tkusumi branches: 1.28.2;
dm: Make target's ->table() optional

Since ->info() (counter part of ->table() in the original dm design
in Linux kernel in .status where both INFO and TABLE are optional)
is an optional handler, make ->table() optional as well. Some
targets don't have anything to do in ->table() just as in ->info().

taken-from: DragonFlyBSD
 1.27 21-Dec-2019  tkusumi dm: Remove target's ->deps() by implementing deps in dm core

Retrieving device dependencies doesn't need to be target specific.
The reason it currently needs ->deps() is because dm core doesn't
have data structure that allows table to walk through target's
underlying devices. Add struct dm_mapping to be able to do this,
and remove ->deps()'s from targets which basically do the same thing.

=====(A) before this commit
table
| [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

=====(B) this commit
table---->mapping-->mapping-->mapping-->...
| | | |
| v v v [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

taken-from: DragonFlyBSD
 1.26 18-Dec-2019  tkusumi dm: Test # of args in target's ->init()

The # of args is part of target's spec.
Both Linux kernel and DragonFlyBSD test argc on ctr/init.
 1.25 16-Dec-2019  tkusumi dm: Enable dm-error and dm-zero target

Add these two targets to dm.kmod.
These are generally available in Linux and DragonFlyBSD,
so enable them in NetBSD as well.
 1.24 15-Dec-2019  tkusumi dm: Style cleanups (no functional changes)
 1.23 15-Dec-2019  tkusumi dm: Make targets' ->sync() optional

Apparently some targets have nothing to sync, so make it optional.
 1.22 15-Dec-2019  tkusumi dm: Make targets' ->secsize() optional

and make a caller assume secsize 0 if ->secsize not present.
This allows a dummy function to be removed which was added in
"dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)".
 1.21 15-Dec-2019  tkusumi dm: Rename targets' ->status() to ->table() given ->info() exists

Since now that dm targets in NetBSD have ->info() for "status",
->status() should be renamed to ->table() for "table",
given how dm target status was originally designed in Linux kernel.

taken-from: DragonFlyBSD
 1.20 14-Dec-2019  tkusumi dm: Remove unconditional debug prints in targets' ->strategy()

Having debug prints in ->strategy() by default just to tell ->strategy()
is called is overkill.
taken-from: DragonFlyBSD
 1.19 12-Dec-2019  tkusumi dm: Make target's ->init() take parsed argc and argv

This gets rid of the same parser code in each target using strsep(3).
taken-from: DragonFlyBSD
 1.18 08-Dec-2019  tkusumi dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)

dm_target_insert() has assertions to ensure targets implement all handlers.
Adding dummy ones at least prevents panic on modload(8).
 1.17 08-Dec-2019  tkusumi dm: Refactor target's ->init() i/f

Take dm_table_entry_t* instead of void**.
Remove dm_dev_t* unneeded by target code.
No functional change, but for future changes.

taken-from: DragonFlyBSD
 1.16 07-Dec-2019  tkusumi dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD
 1.15 06-Dec-2019  tkusumi dm: Don't ignore dm_target_alloc() argument

dm_target_alloc() is supposed to be copying the name argument to its ->name.
taken-from: DragonFlyBSD
 1.14 05-Dec-2019  tkusumi dm: Make dm core set config to NULL after destroy

Just let dm core do this instead of having a comment expecting each
target to do the right thing.

taken-from: DragonFlyBSD
 1.13 01-Dec-2019  tkusumi dm: Remove unused dm_dev::dev_type

Given OOP-like architecture of dm target device structure,
dm_dev doesn't need to have self contained target type field,
and in fact this is unused.
 1.12 05-Jan-2018  christos branches: 1.12.4;
use some size_t, add whitespace between functions, rcsids.
 1.11 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.10 04-Jan-2010  haad branches: 1.10.2; 1.10.4;
Indent files remove unnecessary blank lines, white spaces and KNFize code.
 1.9 01-Dec-2009  haad Revert my commit which have added knowledge about dm targets to libdevmapper,
this breaks abstraction. Because only lvmtools/lvmlib and device-mapper can
have knowledge about target mapping and libdevmapper only passes requests
from lvmtools to kernel and back. Bump major library and driver version.

Requested by: yamt@
 1.8 05-Jun-2009  haad Parse dm param string in libdevmapper and not in a dm target init function.
Create proplib param dictionary entry in libdevmapper and pass it to dm in
dm_ioctl dict.
Param target is then passed to target init function, where is parse. I like
this aproach much better than passing char **argv and trusting to user input.

I have bumped minor lib/driver version.

XXX. Add more sanity checks in kernel.
 1.7 19-Feb-2009  haad branches: 1.7.2;
Add support for autoloading of device-mapper targets modules. Add
dm_target_autoload function which tries to load target module. Fix two
deadlocks in dm_table_load_ioctl error path(I forgot to call dm_dev_unbusy).
 1.6 14-Jan-2009  haad branches: 1.6.2; 1.6.4; 1.6.6;
Add dm module as dependency and remove module_hold/module_rele calls.
 1.5 02-Jan-2009  haad Properly register dm_target_* modules with module framework.
 1.4 21-Dec-2008  haad Add support for loading dm targets as separate modules. All targets except
linear can be loaded as module. Module is not loaded when there is target
with similar name already. Zero and error targets aresimple examples how
can be all future targets written to support dynamic loading. Target can't
be unloaded until there is at least one user.
 1.3 19-Dec-2008  haad Add infrastructure needed to load device-mapper targets as modules.
Targets wasn't converted yet and at least snapshot target will be converted
in a near future.
 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.9 05-Nov-2008  haad Fix copyright in TNF licenses.
 1.1.2.8 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.7 11-Sep-2008  haad Add new dm_target_*_deps function which will get all dependiences from
selected target. It is used to get device dependencies during
dm_table_deps_ioctl. Remove dm_dev::pdevs list which was really hard to
manage and wasn't use for anything usefull.
 1.1.2.6 03-Sep-2008  haad Remove unneeded includes.
 1.1.2.5 19-Aug-2008  haad Add $NetBSD$ tag to all dm driver sources.
 1.1.2.4 02-Aug-2008  haad Add status functions for zero, error targets these routines are not needed
here, but I want to be consistent (I already define dm_target_*_init).
 1.1.2.3 22-Jul-2008  haad Change parsing of parameter string. Remove knowledge about pramaer string
from dm_table_load_ioctl and move it to target_init routines. Parameter
string is targets specific and therefore only target routine know how to
parse it correctly. Remove unneeded parameter from dm_target_*_init(argc)
and change dm target routines accordingly.

Simplify dm_table_load_ioctl and move pdev inserting code to target init
funstions.
 1.1.2.2 19-Jul-2008  haad *** empty log message ***
 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.6.6.2 23-Jul-2009  jym Sync with HEAD.
 1.6.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.6.4.3 03-Mar-2009  skrll Sync with HEAD.
 1.6.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.6.4.1 14-Jan-2009  skrll file dm_target_error.c was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.6.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.6.2.1 14-Jan-2009  mjf file dm_target_error.c was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.7.2.5 11-Aug-2010  yamt sync with head.
 1.7.2.4 11-Mar-2010  yamt sync with head
 1.7.2.3 20-Jun-2009  yamt sync with head
 1.7.2.2 04-May-2009  yamt sync with head.
 1.7.2.1 19-Feb-2009  yamt file dm_target_error.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:36 +0000
 1.10.4.1 30-May-2010  rmind sync with head
 1.10.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.12.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.28.2.1 25-Jan-2020  ad Sync with head.
 1.4 24-Jul-2021  andvar Fix all remaining typos, mainly in comments but also in few definitions and log messages, reported by me in PR kern/54889.
Also fixed some additional typos in comments, found on review of same files or typos.
 1.3 21-Jan-2020  tkusumi branches: 1.3.4; 1.3.12;
dm: #if0 target's ->upcall() handler

This is part of NetBSD's dm design, but unimplemented
(all handlers return 0) and also unused.
 1.2 05-Jan-2020  tkusumi branches: 1.2.2;
dm: Add "Copyright (c) 2015 The DragonFly Project." to dm-flakey

which I missed in my initial dm-flakey commit.
 1.1 02-Jan-2020  tkusumi dm: Add dm-flakey target

Ported from DragonFlyBSD, but this target had originally existed in
Linux kernel. See below for details.
https://www.kernel.org/doc/Documentation/device-mapper/dm-flakey.txt

Due to two technical issues, this hasn't been hooked to dm.kmod yet.
1) "tick" in hz(9) not working.
2) Unable to use ->b_private in nestiobuf callback when it's already
used for mbp (see HAS_BUF_PRIV2).

taken-from: DragonFlyBSD
 1.2.2.1 25-Jan-2020  ad Sync with head.
 1.3.12.1 01-Aug-2021  thorpej Sync with HEAD.
 1.3.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.3.4.1 21-Jan-2020  martin file dm_target_flakey.c was added on branch phil-wifi on 2020-04-08 14:08:03 +0000
 1.37 21-Jan-2020  tkusumi dm: #if0 target's ->upcall() handler

This is part of NetBSD's dm design, but unimplemented
(all handlers return 0) and also unused.
 1.36 28-Dec-2019  tkusumi branches: 1.36.2;
dm: Fix typo in comment dklinear -> linear
 1.35 21-Dec-2019  tkusumi dm: Remove target's ->deps() by implementing deps in dm core

Retrieving device dependencies doesn't need to be target specific.
The reason it currently needs ->deps() is because dm core doesn't
have data structure that allows table to walk through target's
underlying devices. Add struct dm_mapping to be able to do this,
and remove ->deps()'s from targets which basically do the same thing.

=====(A) before this commit
table
| [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

=====(B) this commit
table---->mapping-->mapping-->mapping-->...
| | | |
| v v v [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

taken-from: DragonFlyBSD
 1.34 20-Dec-2019  tkusumi dm: Fix "table" output format of dm-linear and dm-stripe

The existing "table" output showing device file path of pdev is
not compatible with dm in Linux kernel (and also DragonFlyBSD).
It should be showing "major:minor" instead.

taken-from: DragonFlyBSD
 1.33 18-Dec-2019  tkusumi dm: Test # of args in target's ->init()

The # of args is part of target's spec.
Both Linux kernel and DragonFlyBSD test argc on ctr/init.
 1.32 15-Dec-2019  tkusumi dm: Rename dm specific atoi() to atoi64()

This is uint64_t version, not sys/lib/libsa/atoi.c.
 1.31 15-Dec-2019  tkusumi dm: Style cleanups (no functional changes)
 1.30 15-Dec-2019  tkusumi dm: "unsigned" -> "unsigned int" for consistency

Use either one, but not both.
 1.29 15-Dec-2019  tkusumi dm: Rename targets' ->status() to ->table() given ->info() exists

Since now that dm targets in NetBSD have ->info() for "status",
->status() should be renamed to ->table() for "table",
given how dm target status was originally designed in Linux kernel.

taken-from: DragonFlyBSD
 1.28 14-Dec-2019  tkusumi dm: Remove unconditional debug prints in targets' ->strategy()

Having debug prints in ->strategy() by default just to tell ->strategy()
is called is overkill.
taken-from: DragonFlyBSD
 1.27 12-Dec-2019  tkusumi dm: Make target's ->init() take parsed argc and argv

This gets rid of the same parser code in each target using strsep(3).
taken-from: DragonFlyBSD
 1.26 09-Dec-2019  tkusumi dm: Silence aprint_normal() in dm_target_linear_status()

dm_target_linear_status() shouldn't print this debug message by default
on dmsetup "table" ioctl/command.
 1.25 08-Dec-2019  tkusumi dm: Refactor target's ->init() i/f

Take dm_table_entry_t* instead of void**.
Remove dm_dev_t* unneeded by target code.
No functional change, but for future changes.

taken-from: DragonFlyBSD
 1.24 07-Dec-2019  tkusumi dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD
 1.23 06-Dec-2019  tkusumi dm: Remove trailing whitespace
 1.22 05-Dec-2019  tkusumi dm: Make dm core set config to NULL after destroy

Just let dm core do this instead of having a comment expecting each
target to do the right thing.

taken-from: DragonFlyBSD
 1.21 03-Dec-2019  tkusumi dm: Include <sys/vnode.h> in dm.h

dm.h already depends on vnode, so have dm.h include <sys/vnode.h>
instead of other .c files.

taken-from: DragonFlyBSD
 1.20 02-Dec-2019  tkusumi dm: Remove misleading comment on linear target arg

The offset arg is mandatory.
Remove code and comment that makes it sounds like it's optional.

taken-from: DragonFlyBSD
 1.19 01-Dec-2019  tkusumi dm: Remove unused dm_dev::dev_type

Given OOP-like architecture of dm target device structure,
dm_dev doesn't need to have self contained target type field,
and in fact this is unused.
 1.18 15-Oct-2019  chs convert more KM_NOSLEEP to KM_SLEEP and remove code to handle failures.
 1.17 05-Jan-2018  christos branches: 1.17.4;
PR/52900: Tomohiro Kusumi: Fix kernel panic when target's ->init() failed
Reliably unbusy the target in the *all* the destroy routines, so ioctl
does not need to do it.
 1.16 04-Jun-2017  mbalmer more dependiences -> dependencies
 1.15 01-Jun-2017  chs remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
 1.14 14-Jun-2014  hannken branches: 1.14.4;
Change dk_lookup() to return an anonymous vnode not associated with
any file system. Change all consumers of dk_lookup() to get the
device from "v_rdev" instead of VOP_GETATTR() as specfs does not
support VOP_GETATTR(). Devices obtained with dk_lookup() will no
longer disappear on forced unmounts.

Fix for PR kern/48849 (root mirror raid fails on shutdown)

Welcome to 6.99.44
 1.13 14-Oct-2011  hannken branches: 1.13.12; 1.13.26;
Change the vnode locking protocol of VOP_GETATTR() to request at least
a shared lock. Make all calls outside of file systems respect it.

The calls from file systems need review.

No objections from tech-kern.
 1.12 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.11 15-Nov-2010  uebayasi curlwp needs sys/lwp.h.
 1.10 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.9 04-Jan-2010  haad branches: 1.9.2; 1.9.4;
Indent files remove unnecessary blank lines, white spaces and KNFize code.
 1.8 01-Dec-2009  haad Revert my commit which have added knowledge about dm targets to libdevmapper,
this breaks abstraction. Because only lvmtools/lvmlib and device-mapper can
have knowledge about target mapping and libdevmapper only passes requests
from lvmtools to kernel and back. Bump major library and driver version.

Requested by: yamt@
 1.7 09-Sep-2009  haad Fix bug in kmem_alloc/kmem_free of params string. Params string was
allocated with length DM_MAX_PARAMS_SIZE and released with strlen + 1 size.

Disable KM_NOSLEEP allocation because we do not need them here there is
nothing critical in ioctl part of dm driver.

Bug reported by jak@.
 1.6 16-Aug-2009  yamt fix a comment typo.
 1.5 05-Jun-2009  haad Parse dm param string in libdevmapper and not in a dm target init function.
Create proplib param dictionary entry in libdevmapper and pass it to dm in
dm_ioctl dict.
Param target is then passed to target init function, where is parse. I like
this aproach much better than passing char **argv and trusting to user input.

I have bumped minor lib/driver version.

XXX. Add more sanity checks in kernel.
 1.4 01-Mar-2009  haad branches: 1.4.2;
Linear target has only 2 arguments in a params string not 9.
 1.3 19-Dec-2008  haad branches: 1.3.2; 1.3.4; 1.3.6;
Add infrastructure needed to load device-mapper targets as modules.
Targets wasn't converted yet and at least snapshot target will be converted
in a near future.
 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.20 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.19 05-Nov-2008  haad Fix copyright in TNF licenses.
 1.1.2.18 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.17 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.16 22-Sep-2008  haad Fix bug where I tried to prop_object_release null object which caused weird
atuvm panic. Change init functions to failed when they receive params string
== NULL when they need some data.
 1.1.2.15 11-Sep-2008  haad Add new dm_target_*_deps function which will get all dependiences from
selected target. It is used to get device dependencies during
dm_table_deps_ioctl. Remove dm_dev::pdevs list which was really hard to
manage and wasn't use for anything usefull.
 1.1.2.14 08-Sep-2008  haad Add new version of snapshot code for nowonlyinitial configuration of
snapshots (parsing parameters strings and opening devices was added).

Fixonebug in dm_pdev where was one SLIST_ENTRY used to for global
pdev list and for per device pdev list. This bug was hidden for a
long time because I haven't used devices with more than one pdev.
 1.1.2.13 03-Sep-2008  haad Remove unneeded includes.
 1.1.2.12 28-Aug-2008  haad Fix pdev manipulation in init, destroy routines. In destroy routine remove
pdev from device list only if it is not referenced from other tables too.
 1.1.2.11 20-Aug-2008  haad For pdevs located in target_config areas, decrement reference counts during
dm_target_*_destroy call. Remove these pdevs from device list.
 1.1.2.10 20-Aug-2008  haad Add initial portion of snapshot code. Divide snapshot code into 2 parts

snapshot-origin and snapshot

First target is used to inform all snapshots about writes to master device.
Snapshot targets implements exception store for changed blocks.

This is how linux does snapshots on lvm2 devices if we want to use lvm2tools,
for snapshots I have to keep this as much compatible as possible to linux.

Change atoi from static to public function now it can be used with other
targets, too.
 1.1.2.9 19-Aug-2008  haad Remove unnecessary call of dm_pdev_rem in dm_table_load. Change dm_dev_remove
to call dm_pdev_decr for all devices in pdev list.

Because target config contains pdevs I have to decrement them in
dm_target_*_destroy.
 1.1.2.8 19-Aug-2008  haad Add $NetBSD$ tag to all dm driver sources.
 1.1.2.7 02-Aug-2008  haad After dm_target_*_destroy set table_en->target_config to NULL.
 1.1.2.6 29-Jul-2008  haad Change comment in dm_table_destroy and dm-target_linear_init.
These functions should be called with per device mutex held.
 1.1.2.5 28-Jul-2008  haad Add status function to targets. This function is called from dm_table_status_ioctl,
when DM_STATUS_TABLE_FLAG is specified and it's purpose is construct params string.
Which can be sent back to libdevmapper.

Add adding removing of the DM_SUSPENDED_FLAG flag in dm_dev_suspend/resume ioctls.
 1.1.2.4 22-Jul-2008  haad Change parsing of parameter string. Remove knowledge about pramaer string
from dm_table_load_ioctl and move it to target_init routines. Parameter
string is targets specific and therefore only target routine know how to
parse it correctly. Remove unneeded parameter from dm_target_*_init(argc)
and change dm target routines accordingly.

Simplify dm_table_load_ioctl and move pdev inserting code to target init
funstions.
 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.3.6.2 23-Jul-2009  jym Sync with HEAD.
 1.3.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.3.4.4 28-Apr-2009  skrll Sync with HEAD.
 1.3.4.3 03-Mar-2009  skrll Sync with HEAD.
 1.3.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.3.4.1 19-Dec-2008  skrll file dm_target_linear.c was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.3.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.3.2.1 19-Dec-2008  mjf file dm_target_linear.c was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.4.2.7 11-Aug-2010  yamt sync with head.
 1.4.2.6 11-Mar-2010  yamt sync with head
 1.4.2.5 16-Sep-2009  yamt sync with head
 1.4.2.4 19-Aug-2009  yamt sync with head.
 1.4.2.3 20-Jun-2009  yamt sync with head
 1.4.2.2 04-May-2009  yamt sync with head.
 1.4.2.1 01-Mar-2009  yamt file dm_target_linear.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:36 +0000
 1.9.4.2 05-Mar-2011  rmind sync with head
 1.9.4.1 30-May-2010  rmind sync with head
 1.9.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.13.26.1 10-Aug-2014  tls Rebase.
 1.13.12.2 03-Dec-2017  jdolecek update from HEAD
 1.13.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.14.4.1 28-Aug-2017  skrll Sync with HEAD
 1.17.4.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.36.2.1 25-Jan-2020  ad Sync with head.
 1.24 21-Jan-2020  tkusumi dm: #if0 target's ->upcall() handler

This is part of NetBSD's dm design, but unimplemented
(all handlers return 0) and also unused.
 1.23 21-Dec-2019  tkusumi branches: 1.23.2;
dm: Remove target's ->deps() by implementing deps in dm core

Retrieving device dependencies doesn't need to be target specific.
The reason it currently needs ->deps() is because dm core doesn't
have data structure that allows table to walk through target's
underlying devices. Add struct dm_mapping to be able to do this,
and remove ->deps()'s from targets which basically do the same thing.

=====(A) before this commit
table
| [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

=====(B) this commit
table---->mapping-->mapping-->mapping-->...
| | | |
| v v v [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

taken-from: DragonFlyBSD
 1.22 15-Dec-2019  tkusumi dm: Style cleanups (no functional changes)
 1.21 15-Dec-2019  tkusumi dm: Make targets' ->secsize() optional

and make a caller assume secsize 0 if ->secsize not present.
This allows a dummy function to be removed which was added in
"dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)".
 1.20 15-Dec-2019  tkusumi dm: Rename targets' ->status() to ->table() given ->info() exists

Since now that dm targets in NetBSD have ->info() for "status",
->status() should be renamed to ->table() for "table",
given how dm target status was originally designed in Linux kernel.

taken-from: DragonFlyBSD
 1.19 14-Dec-2019  tkusumi dm: Remove unconditional debug prints in targets' ->strategy()

Having debug prints in ->strategy() by default just to tell ->strategy()
is called is overkill.
taken-from: DragonFlyBSD
 1.18 12-Dec-2019  tkusumi dm: Make target's ->init() take parsed argc and argv

This gets rid of the same parser code in each target using strsep(3).
taken-from: DragonFlyBSD
 1.17 08-Dec-2019  tkusumi dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)

dm_target_insert() has assertions to ensure targets implement all handlers.
Adding dummy ones at least prevents panic on modload(8).
 1.16 08-Dec-2019  tkusumi dm: Move targets specific structs to .c files

These don't need to be defined and exposed in dm.h.
 1.15 08-Dec-2019  tkusumi dm: Refactor target's ->init() i/f

Take dm_table_entry_t* instead of void**.
Remove dm_dev_t* unneeded by target code.
No functional change, but for future changes.

taken-from: DragonFlyBSD
 1.14 07-Dec-2019  tkusumi dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD
 1.13 06-Dec-2019  tkusumi dm: Don't ignore dm_target_alloc() argument

dm_target_alloc() is supposed to be copying the name argument to its ->name.
taken-from: DragonFlyBSD
 1.12 05-Dec-2019  tkusumi dm: Make dm core set config to NULL after destroy

Just let dm core do this instead of having a comment expecting each
target to do the right thing.

taken-from: DragonFlyBSD
 1.11 01-Dec-2019  tkusumi dm: Remove unused dm_dev::dev_type

Given OOP-like architecture of dm target device structure,
dm_dev doesn't need to have self contained target type field,
and in fact this is unused.
 1.10 05-Jan-2018  christos branches: 1.10.4;
use some size_t, add whitespace between functions, rcsids.
 1.9 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.8 04-Jan-2010  haad branches: 1.8.2; 1.8.4;
Indent files remove unnecessary blank lines, white spaces and KNFize code.
 1.7 01-Dec-2009  haad Revert my commit which have added knowledge about dm targets to libdevmapper,
this breaks abstraction. Because only lvmtools/lvmlib and device-mapper can
have knowledge about target mapping and libdevmapper only passes requests
from lvmtools to kernel and back. Bump major library and driver version.

Requested by: yamt@
 1.6 05-Jun-2009  haad Parse dm param string in libdevmapper and not in a dm target init function.
Create proplib param dictionary entry in libdevmapper and pass it to dm in
dm_ioctl dict.
Param target is then passed to target init function, where is parse. I like
this aproach much better than passing char **argv and trusting to user input.

I have bumped minor lib/driver version.

XXX. Add more sanity checks in kernel.
 1.5 01-Mar-2009  haad branches: 1.5.2;
Change comment and add description of line used to configure mirror device.
 1.4 19-Feb-2009  haad Add support for autoloading of device-mapper targets modules. Add
dm_target_autoload function which tries to load target module. Fix two
deadlocks in dm_table_load_ioctl error path(I forgot to call dm_dev_unbusy).
 1.3 14-Jan-2009  haad branches: 1.3.2; 1.3.4; 1.3.6;
Add dm module as dependency and remove module_hold/module_rele calls.
 1.2 02-Jan-2009  haad Return ENOSYS during from dm_target_init routine these tow targets aren't
implemented yet.
 1.1 02-Jan-2009  haad Add stubs for mirror target, too. This target does nothing for now, but lvm
tools support mirror target and trying to create LV with mirrorred backend
caused panic in dm_table_load_ioctl.
 1.3.6.2 23-Jul-2009  jym Sync with HEAD.
 1.3.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.3.4.3 03-Mar-2009  skrll Sync with HEAD.
 1.3.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.3.4.1 14-Jan-2009  skrll file dm_target_mirror.c was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.3.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.3.2.1 14-Jan-2009  mjf file dm_target_mirror.c was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.5.2.5 11-Aug-2010  yamt sync with head.
 1.5.2.4 11-Mar-2010  yamt sync with head
 1.5.2.3 20-Jun-2009  yamt sync with head
 1.5.2.2 04-May-2009  yamt sync with head.
 1.5.2.1 01-Mar-2009  yamt file dm_target_mirror.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:36 +0000
 1.8.4.1 30-May-2010  rmind sync with head
 1.8.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.10.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.23.2.1 25-Jan-2020  ad Sync with head.
 1.38 21-Jan-2020  tkusumi dm: #if0 target's ->upcall() handler

This is part of NetBSD's dm design, but unimplemented
(all handlers return 0) and also unused.
 1.37 21-Dec-2019  tkusumi branches: 1.37.2;
dm: Remove target's ->deps() by implementing deps in dm core

Retrieving device dependencies doesn't need to be target specific.
The reason it currently needs ->deps() is because dm core doesn't
have data structure that allows table to walk through target's
underlying devices. Add struct dm_mapping to be able to do this,
and remove ->deps()'s from targets which basically do the same thing.

=====(A) before this commit
table
| [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

=====(B) this commit
table---->mapping-->mapping-->mapping-->...
| | | |
| v v v [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

taken-from: DragonFlyBSD
 1.36 15-Dec-2019  tkusumi dm: Rename dm specific atoi() to atoi64()

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

Apparently some targets have nothing to sync, so make it optional.
 1.33 15-Dec-2019  tkusumi dm: Make targets' ->secsize() optional

and make a caller assume secsize 0 if ->secsize not present.
This allows a dummy function to be removed which was added in
"dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)".
 1.32 15-Dec-2019  tkusumi dm: Rename targets' ->status() to ->table() given ->info() exists

Since now that dm targets in NetBSD have ->info() for "status",
->status() should be renamed to ->table() for "table",
given how dm target status was originally designed in Linux kernel.

taken-from: DragonFlyBSD
 1.31 14-Dec-2019  tkusumi dm: Remove unconditional debug prints in targets' ->strategy()

Having debug prints in ->strategy() by default just to tell ->strategy()
is called is overkill.
taken-from: DragonFlyBSD
 1.30 12-Dec-2019  tkusumi dm: Make target's ->init() take parsed argc and argv

This gets rid of the same parser code in each target using strsep(3).
taken-from: DragonFlyBSD
 1.29 08-Dec-2019  tkusumi dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)

dm_target_insert() has assertions to ensure targets implement all handlers.
Adding dummy ones at least prevents panic on modload(8).
 1.28 08-Dec-2019  tkusumi dm: Move targets specific structs to .c files

These don't need to be defined and exposed in dm.h.
 1.27 08-Dec-2019  tkusumi dm: Unbreak compilation of kernel modules

The dm kernel modules (MK_DM_TARGETS enabled in sys/modules/dm/Makefile)
have been broken. Unbreak the build.
 1.26 08-Dec-2019  tkusumi dm: Refactor target's ->init() i/f

Take dm_table_entry_t* instead of void**.
Remove dm_dev_t* unneeded by target code.
No functional change, but for future changes.

taken-from: DragonFlyBSD
 1.25 07-Dec-2019  tkusumi dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD
 1.24 06-Dec-2019  tkusumi dm: Don't ignore dm_target_alloc() argument

dm_target_alloc() is supposed to be copying the name argument to its ->name.
taken-from: DragonFlyBSD
 1.23 05-Dec-2019  tkusumi dm: Make dm core set config to NULL after destroy

Just let dm core do this instead of having a comment expecting each
target to do the right thing.

taken-from: DragonFlyBSD
 1.22 03-Dec-2019  tkusumi dm: Include <sys/vnode.h> in dm.h

dm.h already depends on vnode, so have dm.h include <sys/vnode.h>
instead of other .c files.

taken-from: DragonFlyBSD
 1.21 01-Dec-2019  tkusumi dm: Remove unused dm_dev::dev_type

Given OOP-like architecture of dm target device structure,
dm_dev doesn't need to have self contained target type field,
and in fact this is unused.
 1.20 15-Oct-2019  chs convert more KM_NOSLEEP to KM_SLEEP and remove code to handle failures.
 1.19 05-Jan-2018  christos branches: 1.19.4;
PR/52900: Tomohiro Kusumi: Fix kernel panic when target's ->init() failed
Reliably unbusy the target in the *all* the destroy routines, so ioctl
does not need to do it.
 1.18 04-Jun-2017  mbalmer more dependiences -> dependencies
 1.17 18-Aug-2014  agc branches: 1.17.2;
Avoid a memory leak - from maxv
 1.16 14-Jun-2014  hannken branches: 1.16.2;
Change dk_lookup() to return an anonymous vnode not associated with
any file system. Change all consumers of dk_lookup() to get the
device from "v_rdev" instead of VOP_GETATTR() as specfs does not
support VOP_GETATTR(). Devices obtained with dk_lookup() will no
longer disappear on forced unmounts.

Fix for PR kern/48849 (root mirror raid fails on shutdown)

Welcome to 6.99.44
 1.15 14-Oct-2011  hannken branches: 1.15.12; 1.15.26;
Change the vnode locking protocol of VOP_GETATTR() to request at least
a shared lock. Make all calls outside of file systems respect it.

The calls from file systems need review.

No objections from tech-kern.
 1.14 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.13 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.12 04-Jan-2010  haad branches: 1.12.2; 1.12.4;
Indent files remove unnecessary blank lines, white spaces and KNFize code.
 1.11 01-Dec-2009  haad Revert my commit which have added knowledge about dm targets to libdevmapper,
this breaks abstraction. Because only lvmtools/lvmlib and device-mapper can
have knowledge about target mapping and libdevmapper only passes requests
from lvmtools to kernel and back. Bump major library and driver version.

Requested by: yamt@
 1.10 20-Jun-2009  cegger buidfix: change dm_target_snapshot_orig_init() to match prototype.
 1.9 05-Jun-2009  haad Parse dm param string in libdevmapper and not in a dm target init function.
Create proplib param dictionary entry in libdevmapper and pass it to dm in
dm_ioctl dict.
Param target is then passed to target init function, where is parse. I like
this aproach much better than passing char **argv and trusting to user input.

I have bumped minor lib/driver version.

XXX. Add more sanity checks in kernel.
 1.8 19-Feb-2009  haad branches: 1.8.2;
Add support for autoloading of device-mapper targets modules. Add
dm_target_autoload function which tries to load target module. Fix two
deadlocks in dm_table_load_ioctl error path(I forgot to call dm_dev_unbusy).
 1.7 14-Jan-2009  haad branches: 1.7.2; 1.7.4; 1.7.6;
Add dm module as dependency and remove module_hold/module_rele calls.
 1.6 02-Jan-2009  haad Properly register dm_target_* modules with module framework.
 1.5 02-Jan-2009  haad Add stripe target functions stubs. Stripe target must be present in dm driver
because without it lvm2tools will not create LVsi and eventualy panic system.

Problem reported by agc@.
 1.4 21-Dec-2008  haad Add support for loading dm targets as separate modules. All targets except
linear can be loaded as module. Module is not loaded when there is target
with similar name already. Zero and error targets aresimple examples how
can be all future targets written to support dynamic loading. Target can't
be unloaded until there is at least one user.
 1.3 19-Dec-2008  haad Add infrastructure needed to load device-mapper targets as modules.
Targets wasn't converted yet and at least snapshot target will be converted
in a near future.
 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 19-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.13 05-Nov-2008  haad Fix copyright in TNF licenses.
 1.1.2.12 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.11 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.10 22-Sep-2008  haad Fix bug where I tried to prop_object_release null object which caused weird
atuvm panic. Change init functions to failed when they receive params string
== NULL when they need some data.
 1.1.2.9 11-Sep-2008  haad Add new dm_target_*_deps function which will get all dependiences from
selected target. It is used to get device dependencies during
dm_table_deps_ioctl. Remove dm_dev::pdevs list which was really hard to
manage and wasn't use for anything usefull.
 1.1.2.8 08-Sep-2008  haad Add new version of snapshot code for nowonlyinitial configuration of
snapshots (parsing parameters strings and opening devices was added).

Fixonebug in dm_pdev where was one SLIST_ENTRY used to for global
pdev list and for per device pdev list. This bug was hidden for a
long time because I haven't used devices with more than one pdev.
 1.1.2.7 03-Sep-2008  haad Remove unneeded includes.
 1.1.2.6 20-Aug-2008  haad Add initial portion of snapshot code. Divide snapshot code into 2 parts

snapshot-origin and snapshot

First target is used to inform all snapshots about writes to master device.
Snapshot targets implements exception store for changed blocks.

This is how linux does snapshots on lvm2 devices if we want to use lvm2tools,
for snapshots I have to keep this as much compatible as possible to linux.

Change atoi from static to public function now it can be used with other
targets, too.
 1.1.2.5 19-Aug-2008  haad Add $NetBSD$ tag to all dm driver sources.
 1.1.2.4 02-Aug-2008  haad After dm_target_*_destroy set table_en->target_config to NULL.
 1.1.2.3 28-Jul-2008  haad Add status function to targets. This function is called from dm_table_status_ioctl,
when DM_STATUS_TABLE_FLAG is specified and it's purpose is construct params string.
Which can be sent back to libdevmapper.

Add adding removing of the DM_SUSPENDED_FLAG flag in dm_dev_suspend/resume ioctls.
 1.1.2.2 22-Jul-2008  haad Change parsing of parameter string. Remove knowledge about pramaer string
from dm_table_load_ioctl and move it to target_init routines. Parameter
string is targets specific and therefore only target routine know how to
parse it correctly. Remove unneeded parameter from dm_target_*_init(argc)
and change dm target routines accordingly.

Simplify dm_table_load_ioctl and move pdev inserting code to target init
funstions.
 1.1.2.1 19-Jul-2008  haad *** empty log message ***
 1.7.6.2 23-Jul-2009  jym Sync with HEAD.
 1.7.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.7.4.3 03-Mar-2009  skrll Sync with HEAD.
 1.7.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.7.4.1 14-Jan-2009  skrll file dm_target_snapshot.c was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.7.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.7.2.1 14-Jan-2009  mjf file dm_target_snapshot.c was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.8.2.6 11-Aug-2010  yamt sync with head.
 1.8.2.5 11-Mar-2010  yamt sync with head
 1.8.2.4 18-Jul-2009  yamt sync with head.
 1.8.2.3 20-Jun-2009  yamt sync with head
 1.8.2.2 04-May-2009  yamt sync with head.
 1.8.2.1 19-Feb-2009  yamt file dm_target_snapshot.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:36 +0000
 1.12.4.2 05-Mar-2011  rmind sync with head
 1.12.4.1 30-May-2010  rmind sync with head
 1.12.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.15.26.1 10-Aug-2014  tls Rebase.
 1.15.12.2 03-Dec-2017  jdolecek update from HEAD
 1.15.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.16.2.1 20-Oct-2014  martin Pullup the following revisions, requested by maxv in ticket #148:

sys/compat/svr4/svr4_stat.c 1.70
sys/dev/dm/dm_target_snapshot.c 1.17
sys/dev/if_ndis/if_ndis_pci.c 1.20
sys/fs/smbfs/smbfs_smb.c 1.45
sys/ufs/ext2fs/ext2fs_readwrite.c 1.65

Various fixes: two memory leaks, a typo, a dead compiler condition and
unused macros, respectively in if_ndis and dm, smbfs, svr4 and ext2fs.
 1.17.2.1 28-Aug-2017  skrll Sync with HEAD
 1.19.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.19.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.37.2.1 25-Jan-2020  ad Sync with head.
 1.45 08-Sep-2024  rillig fix a/an grammar in obvious cases
 1.44 21-Jan-2020  tkusumi branches: 1.44.30;
dm: #if0 target's ->upcall() handler

This is part of NetBSD's dm design, but unimplemented
(all handlers return 0) and also unused.
 1.43 21-Dec-2019  tkusumi branches: 1.43.2;
dm: Fix dm-stripe's "status" output format

As mentioned in "dm: Don't try to implement "status" as subset of "table"",
dm-stripe in NetBSD doesn't have correct "status" output format.
Implement ->info() to sync with Linux kernel.

Note that num_error for stripe device isn't implemented yet.

taken-from: DragonFlyBSD
 1.42 21-Dec-2019  tkusumi dm: Remove target's ->deps() by implementing deps in dm core

Retrieving device dependencies doesn't need to be target specific.
The reason it currently needs ->deps() is because dm core doesn't
have data structure that allows table to walk through target's
underlying devices. Add struct dm_mapping to be able to do this,
and remove ->deps()'s from targets which basically do the same thing.

=====(A) before this commit
table
| [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

=====(B) this commit
table---->mapping-->mapping-->mapping-->...
| | | |
| v v v [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

taken-from: DragonFlyBSD
 1.41 20-Dec-2019  tkusumi dm: Fix "table" output format of dm-linear and dm-stripe

The existing "table" output showing device file path of pdev is
not compatible with dm in Linux kernel (and also DragonFlyBSD).
It should be showing "major:minor" instead.

taken-from: DragonFlyBSD
 1.40 18-Dec-2019  tkusumi dm: Test # of args in target's ->init()

The # of args is part of target's spec.
Both Linux kernel and DragonFlyBSD test argc on ctr/init.
 1.39 15-Dec-2019  tkusumi dm: Rename dm specific atoi() to atoi64()

This is uint64_t version, not sys/lib/libsa/atoi.c.
 1.38 15-Dec-2019  tkusumi dm: Style cleanups (no functional changes)
 1.37 15-Dec-2019  tkusumi dm: "unsigned" -> "unsigned int" for consistency

Use either one, but not both.
 1.36 15-Dec-2019  tkusumi dm: Rename targets' ->status() to ->table() given ->info() exists

Since now that dm targets in NetBSD have ->info() for "status",
->status() should be renamed to ->table() for "table",
given how dm target status was originally designed in Linux kernel.

taken-from: DragonFlyBSD
 1.35 14-Dec-2019  tkusumi dm: Remove unconditional debug prints in targets' ->strategy()

Having debug prints in ->strategy() by default just to tell ->strategy()
is called is overkill.
taken-from: DragonFlyBSD
 1.34 12-Dec-2019  tkusumi dm: Make target's ->init() take parsed argc and argv

This gets rid of the same parser code in each target using strsep(3).
taken-from: DragonFlyBSD
 1.33 09-Dec-2019  tkusumi dm: Correct target name "stripe" -> "striped"

Sync with Linux kernel.
The file name is "stripe", but the target name is "striped".
DragonFlyBSD also follows this.
 1.32 08-Dec-2019  tkusumi dm: Move targets specific structs to .c files

These don't need to be defined and exposed in dm.h.
 1.31 08-Dec-2019  tkusumi dm: Refactor target's ->init() i/f

Take dm_table_entry_t* instead of void**.
Remove dm_dev_t* unneeded by target code.
No functional change, but for future changes.

taken-from: DragonFlyBSD
 1.30 07-Dec-2019  tkusumi dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD
 1.29 06-Dec-2019  tkusumi dm: Fix typos in comments/messages

taken-from: DragonFlyBSD
 1.28 06-Dec-2019  tkusumi dm: Don't ignore dm_target_alloc() argument

dm_target_alloc() is supposed to be copying the name argument to its ->name.
taken-from: DragonFlyBSD
 1.27 05-Dec-2019  tkusumi dm: Make dm core set config to NULL after destroy

Just let dm core do this instead of having a comment expecting each
target to do the right thing.

taken-from: DragonFlyBSD
 1.26 03-Dec-2019  tkusumi dm: Include <sys/vnode.h> in dm.h

dm.h already depends on vnode, so have dm.h include <sys/vnode.h>
instead of other .c files.

taken-from: DragonFlyBSD
 1.25 01-Dec-2019  tkusumi dm: Remove unused dm_dev::dev_type

Given OOP-like architecture of dm target device structure,
dm_dev doesn't need to have self contained target type field,
and in fact this is unused.
 1.24 15-Oct-2019  chs convert more KM_NOSLEEP to KM_SLEEP and remove code to handle failures.
 1.23 05-Jan-2018  christos branches: 1.23.4;
use some size_t, add whitespace between functions, rcsids.
 1.22 01-Jun-2017  chs remove checks for failure after memory allocation calls that cannot fail:

kmem_alloc() with KM_SLEEP
kmem_zalloc() with KM_SLEEP
percpu_alloc()
pserialize_create()
psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
 1.21 19-Aug-2014  christos branches: 1.21.2;
cleanup properly on error.
 1.20 18-Aug-2014  agc Avoid a memory leak - from maxv
 1.19 14-Jun-2014  hannken branches: 1.19.2;
Change dk_lookup() to return an anonymous vnode not associated with
any file system. Change all consumers of dk_lookup() to get the
device from "v_rdev" instead of VOP_GETATTR() as specfs does not
support VOP_GETATTR(). Devices obtained with dk_lookup() will no
longer disappear on forced unmounts.

Fix for PR kern/48849 (root mirror raid fails on shutdown)

Welcome to 6.99.44
 1.18 07-Aug-2012  haad branches: 1.18.2; 1.18.12;
Fix problem reported by jym on current-user@ patch was provided by mhitch@.
 1.17 04-Jan-2012  haad branches: 1.17.2;
Fix wrong KASSERT, reported by mhitch@.
 1.16 14-Oct-2011  hannken branches: 1.16.2; 1.16.6;
Change the vnode locking protocol of VOP_GETATTR() to request at least
a shared lock. Make all calls outside of file systems respect it.

The calls from file systems need review.

No objections from tech-kern.
 1.15 27-Aug-2011  ahoka be consistent and define secsize here as well (though this seems unused?)
some white' from emacs
 1.14 02-Jun-2011  haad Fix simple typo which made stripe target not working very at all. Issue
found by mhitch@.
 1.13 23-Dec-2010  mlelstv branches: 1.13.2; 1.13.6;
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.12 15-Nov-2010  uebayasi curlwp needs sys/lwp.h.
 1.11 23-Oct-2010  haad Add old file describing locking schema used in dm driver.
 1.10 18-May-2010  haad Add multi device strip support written by Guillermo Amaral and reviewed by me.
 1.9 04-Jan-2010  haad branches: 1.9.2; 1.9.4;
Indent files remove unnecessary blank lines, white spaces and KNFize code.
 1.8 01-Dec-2009  haad Revert my commit which have added knowledge about dm targets to libdevmapper,
this breaks abstraction. Because only lvmtools/lvmlib and device-mapper can
have knowledge about target mapping and libdevmapper only passes requests
from lvmtools to kernel and back. Bump major library and driver version.

Requested by: yamt@
 1.7 09-Sep-2009  haad Fix bug in kmem_alloc/kmem_free of params string. Params string was
allocated with length DM_MAX_PARAMS_SIZE and released with strlen + 1 size.

Disable KM_NOSLEEP allocation because we do not need them here there is
nothing critical in ioctl part of dm driver.

Bug reported by jak@.
 1.6 05-Jun-2009  haad Parse dm param string in libdevmapper and not in a dm target init function.
Create proplib param dictionary entry in libdevmapper and pass it to dm in
dm_ioctl dict.
Param target is then passed to target init function, where is parse. I like
this aproach much better than passing char **argv and trusting to user input.

I have bumped minor lib/driver version.

XXX. Add more sanity checks in kernel.
 1.5 06-Apr-2009  haad branches: 1.5.2;
Fix build on amd64. Patch sent by dieter roelants.
 1.4 07-Mar-2009  reinoud Actually lmplement striping as LVM target. OK'd by Adam.
 1.3 01-Mar-2009  haad Add initial support for striping target, hardcode maximal number of stripes
to 2 for now. strategy routine must be written, for now only parsing and
support routines are available. This is work in progress code and should be
taken very carefully.
 1.2 02-Jan-2009  haad branches: 1.2.2; 1.2.4; 1.2.6;
Return ENOSYS during from dm_target_init routine these tow targets aren't
implemented yet.
 1.1 02-Jan-2009  haad Add stripe target functions stubs. Stripe target must be present in dm driver
because without it lvm2tools will not create LVsi and eventualy panic system.

Problem reported by agc@.
 1.2.6.2 23-Jul-2009  jym Sync with HEAD.
 1.2.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.2.4.4 28-Apr-2009  skrll Sync with HEAD.
 1.2.4.3 03-Mar-2009  skrll Sync with HEAD.
 1.2.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.2.4.1 02-Jan-2009  skrll file dm_target_stripe.c was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.2.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.2.1 02-Jan-2009  mjf file dm_target_stripe.c was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.5.2.6 11-Aug-2010  yamt sync with head.
 1.5.2.5 11-Mar-2010  yamt sync with head
 1.5.2.4 16-Sep-2009  yamt sync with head
 1.5.2.3 20-Jun-2009  yamt sync with head
 1.5.2.2 04-May-2009  yamt sync with head.
 1.5.2.1 06-Apr-2009  yamt file dm_target_stripe.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:37 +0000
 1.9.4.3 12-Jun-2011  rmind sync with head
 1.9.4.2 05-Mar-2011  rmind sync with head
 1.9.4.1 30-May-2010  rmind sync with head
 1.9.2.2 06-Nov-2010  uebayasi Sync with HEAD.
 1.9.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.13.6.1 23-Jun-2011  cherry Catchup with rmind-uvmplock merge.
 1.13.2.1 06-Jun-2011  jruoho Sync with HEAD.
 1.16.6.1 18-Feb-2012  mrg merge to -current.
 1.16.2.2 30-Oct-2012  yamt sync with head
 1.16.2.1 17-Apr-2012  yamt sync with head
 1.17.2.1 09-Aug-2012  martin Pull up following revision(s) (requested by haad in ticket #467):
sys/dev/dm/dm_target_stripe.c: revision 1.18
Fix problem reported by jym on current-user@ patch was provided by mhitch@.
 1.18.12.1 10-Aug-2014  tls Rebase.
 1.18.2.2 03-Dec-2017  jdolecek update from HEAD
 1.18.2.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.19.2.1 29-Aug-2014  martin Pull up following revision(s) (requested by christos in ticket #55):
sys/dev/dm/dm_target_stripe.c: revision 1.20-1.21
Avoid a memory leak - from maxv.
Cleanup properly on error.
 1.21.2.1 28-Aug-2017  skrll Sync with HEAD
 1.23.4.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.23.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.43.2.1 25-Jan-2020  ad Sync with head.
 1.44.30.1 02-Aug-2025  perseant Sync with HEAD
 1.32 21-Jan-2020  tkusumi dm: #if0 target's ->upcall() handler

This is part of NetBSD's dm design, but unimplemented
(all handlers return 0) and also unused.
 1.31 27-Dec-2019  msaitoh branches: 1.31.2;
s/suport/support/
 1.30 23-Dec-2019  tkusumi dm: Make target's ->table() optional

Since ->info() (counter part of ->table() in the original dm design
in Linux kernel in .status where both INFO and TABLE are optional)
is an optional handler, make ->table() optional as well. Some
targets don't have anything to do in ->table() just as in ->info().

taken-from: DragonFlyBSD
 1.29 21-Dec-2019  tkusumi dm: Remove target's ->deps() by implementing deps in dm core

Retrieving device dependencies doesn't need to be target specific.
The reason it currently needs ->deps() is because dm core doesn't
have data structure that allows table to walk through target's
underlying devices. Add struct dm_mapping to be able to do this,
and remove ->deps()'s from targets which basically do the same thing.

=====(A) before this commit
table
| [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

=====(B) this commit
table---->mapping-->mapping-->mapping-->...
| | | |
| v v v [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)

taken-from: DragonFlyBSD
 1.28 18-Dec-2019  tkusumi dm: Test # of args in target's ->init()

The # of args is part of target's spec.
Both Linux kernel and DragonFlyBSD test argc on ctr/init.
 1.27 16-Dec-2019  tkusumi dm: Enable dm-error and dm-zero target

Add these two targets to dm.kmod.
These are generally available in Linux and DragonFlyBSD,
so enable them in NetBSD as well.
 1.26 15-Dec-2019  tkusumi dm: Style cleanups (no functional changes)
 1.25 15-Dec-2019  tkusumi dm: Make targets' ->sync() optional

Apparently some targets have nothing to sync, so make it optional.
 1.24 15-Dec-2019  tkusumi dm: Make targets' ->secsize() optional

and make a caller assume secsize 0 if ->secsize not present.
This allows a dummy function to be removed which was added in
"dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)".
 1.23 15-Dec-2019  tkusumi dm: Rename targets' ->status() to ->table() given ->info() exists

Since now that dm targets in NetBSD have ->info() for "status",
->status() should be renamed to ->table() for "table",
given how dm target status was originally designed in Linux kernel.

taken-from: DragonFlyBSD
 1.22 14-Dec-2019  tkusumi dm: Remove unconditional debug prints in targets' ->strategy()

Having debug prints in ->strategy() by default just to tell ->strategy()
is called is overkill.
taken-from: DragonFlyBSD
 1.21 12-Dec-2019  tkusumi dm: Make target's ->init() take parsed argc and argv

This gets rid of the same parser code in each target using strsep(3).
taken-from: DragonFlyBSD
 1.20 08-Dec-2019  tkusumi dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)

dm_target_insert() has assertions to ensure targets implement all handlers.
Adding dummy ones at least prevents panic on modload(8).
 1.19 08-Dec-2019  tkusumi dm: Refactor target's ->init() i/f

Take dm_table_entry_t* instead of void**.
Remove dm_dev_t* unneeded by target code.
No functional change, but for future changes.

taken-from: DragonFlyBSD
 1.18 07-Dec-2019  tkusumi dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD
 1.17 06-Dec-2019  tkusumi dm: Remove trailing whitespace
 1.16 06-Dec-2019  tkusumi dm: Don't ignore dm_target_alloc() argument

dm_target_alloc() is supposed to be copying the name argument to its ->name.
taken-from: DragonFlyBSD
 1.15 05-Dec-2019  tkusumi dm: Make dm core set config to NULL after destroy

Just let dm core do this instead of having a comment expecting each
target to do the right thing.

taken-from: DragonFlyBSD
 1.14 01-Dec-2019  tkusumi dm: Remove unused dm_dev::dev_type

Given OOP-like architecture of dm target device structure,
dm_dev doesn't need to have self contained target type field,
and in fact this is unused.
 1.13 05-Jan-2018  christos branches: 1.13.4;
use some size_t, add whitespace between functions, rcsids.
 1.12 11-Dec-2011  agc fixup comments - no functional change
 1.11 18-May-2010  haad branches: 1.11.8; 1.11.12;
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.10 04-Jan-2010  haad branches: 1.10.2; 1.10.4;
Indent files remove unnecessary blank lines, white spaces and KNFize code.
 1.9 01-Dec-2009  haad Revert my commit which have added knowledge about dm targets to libdevmapper,
this breaks abstraction. Because only lvmtools/lvmlib and device-mapper can
have knowledge about target mapping and libdevmapper only passes requests
from lvmtools to kernel and back. Bump major library and driver version.

Requested by: yamt@
 1.8 05-Jun-2009  haad Parse dm param string in libdevmapper and not in a dm target init function.
Create proplib param dictionary entry in libdevmapper and pass it to dm in
dm_ioctl dict.
Param target is then passed to target init function, where is parse. I like
this aproach much better than passing char **argv and trusting to user input.

I have bumped minor lib/driver version.

XXX. Add more sanity checks in kernel.
 1.7 19-Feb-2009  haad branches: 1.7.2;
Add support for autoloading of device-mapper targets modules. Add
dm_target_autoload function which tries to load target module. Fix two
deadlocks in dm_table_load_ioctl error path(I forgot to call dm_dev_unbusy).
 1.6 14-Jan-2009  haad branches: 1.6.2; 1.6.4; 1.6.6;
Add dm module as dependency and remove module_hold/module_rele calls.
 1.5 02-Jan-2009  haad Properly register dm_target_* modules with module framework.
 1.4 21-Dec-2008  haad Add support for loading dm targets as separate modules. All targets except
linear can be loaded as module. Module is not loaded when there is target
with similar name already. Zero and error targets aresimple examples how
can be all future targets written to support dynamic loading. Target can't
be unloaded until there is at least one user.
 1.3 19-Dec-2008  haad Add infrastructure needed to load device-mapper targets as modules.
Targets wasn't converted yet and at least snapshot target will be converted
in a near future.
 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.11 05-Nov-2008  haad Fix copyright in TNF licenses.
 1.1.2.10 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.9 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.8 11-Sep-2008  haad Add new dm_target_*_deps function which will get all dependiences from
selected target. It is used to get device dependencies during
dm_table_deps_ioctl. Remove dm_dev::pdevs list which was really hard to
manage and wasn't use for anything usefull.
 1.1.2.7 03-Sep-2008  haad Remove unneeded includes.
 1.1.2.6 19-Aug-2008  haad Add $NetBSD$ tag to all dm driver sources.
 1.1.2.5 02-Aug-2008  haad Add status functions for zero, error targets these routines are not needed
here, but I want to be consistent (I already define dm_target_*_init).
 1.1.2.4 22-Jul-2008  haad Change parsing of parameter string. Remove knowledge about pramaer string
from dm_table_load_ioctl and move it to target_init routines. Parameter
string is targets specific and therefore only target routine know how to
parse it correctly. Remove unneeded parameter from dm_target_*_init(argc)
and change dm target routines accordingly.

Simplify dm_table_load_ioctl and move pdev inserting code to target init
funstions.
 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.6.6.2 23-Jul-2009  jym Sync with HEAD.
 1.6.6.1 13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.6.4.3 03-Mar-2009  skrll Sync with HEAD.
 1.6.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.6.4.1 14-Jan-2009  skrll file dm_target_zero.c was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.6.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.6.2.1 14-Jan-2009  mjf file dm_target_zero.c was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.7.2.5 11-Aug-2010  yamt sync with head.
 1.7.2.4 11-Mar-2010  yamt sync with head
 1.7.2.3 20-Jun-2009  yamt sync with head
 1.7.2.2 04-May-2009  yamt sync with head.
 1.7.2.1 19-Feb-2009  yamt file dm_target_zero.c was added on branch yamt-nfs-mp on 2009-05-04 08:12:37 +0000
 1.10.4.1 30-May-2010  rmind sync with head
 1.10.2.1 17-Aug-2010  uebayasi Sync with HEAD.
 1.11.12.1 18-Feb-2012  mrg merge to -current.
 1.11.8.1 17-Apr-2012  yamt sync with head
 1.13.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.31.2.1 25-Jan-2020  ad Sync with head.
 1.7 17-Dec-2019  mlelstv Add error and zero targets to build.
 1.6 03-Jan-2010  haad branches: 1.6.64;
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.5 28-Jun-2009  haad Remove unneeded targets from build. Should fix brekage of ALL kernel build
found by cegger@.
 1.4 02-Jan-2009  haad branches: 1.4.2; 1.4.4; 1.4.6; 1.4.8;
Add stubs for mirror target, too. This target does nothing for now, but lvm
tools support mirror target and trying to create LV with mirrorred backend
caused panic in dm_table_load_ioctl.
 1.3 02-Jan-2009  haad Add stripe target functions stubs. Stripe target must be present in dm driver
because without it lvm2tools will not create LVsi and eventualy panic system.

Problem reported by agc@.
 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 11-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.2 19-Jul-2008  haad *** empty log message ***
 1.1.2.1 11-Jul-2008  haad I have forgot to add these two files.
 1.4.8.4 11-Mar-2010  yamt sync with head
 1.4.8.3 18-Jul-2009  yamt sync with head.
 1.4.8.2 04-May-2009  yamt sync with head.
 1.4.8.1 02-Jan-2009  yamt file files.dm was added on branch yamt-nfs-mp on 2009-05-04 08:12:37 +0000
 1.4.6.1 23-Jul-2009  jym Sync with HEAD.
 1.4.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.4.4.1 02-Jan-2009  skrll file files.dm was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.4.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.4.2.1 02-Jan-2009  mjf file files.dm was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.6.64.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.10 06-Dec-2019  tkusumi dm: Remove trailing whitespace
 1.9 03-Dec-2019  tkusumi dm: Remove unused macro DM_CMD_LEN

that was added but never used in both NetBSD and DragonFlyBSD.
taken-from: DragonFlyBSD
 1.8 04-Jun-2017  mbalmer branches: 1.8.6;
fix typo in comment
 1.7 06-Sep-2015  dholland More on PR 41200: headers that declare ioctls should include sys/ioccom.h.
This covers (I think) all the MI headers outside of external/ (and dist/).
 1.6 05-Dec-2009  haad branches: 1.6.22; 1.6.40;
Include only user-kernel communication protocol related information in this header.
 1.5 01-Dec-2009  haad Revert my commit which have added knowledge about dm targets to libdevmapper,
this breaks abstraction. Because only lvmtools/lvmlib and device-mapper can
have knowledge about target mapping and libdevmapper only passes requests
from lvmtools to kernel and back. Bump major library and driver version.

Requested by: yamt@
 1.4 05-Jun-2009  haad Parse dm param string in libdevmapper and not in a dm target init function.
Create proplib param dictionary entry in libdevmapper and pass it to dm in
dm_ioctl dict.
Param target is then passed to target init function, where is parse. I like
this aproach much better than passing char **argv and trusting to user input.

I have bumped minor lib/driver version.

XXX. Add more sanity checks in kernel.
 1.3 22-Dec-2008  haad branches: 1.3.2; 1.3.4; 1.3.6; 1.3.8;
Remove DM_TABLE_DEPS it is not used in kernel driver and it breaks build
of libdevmapper because it clashes with DM_TABLE_DEPS from dm-ioctl.h.
 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.6 05-Nov-2008  haad Fix copyright in TNF licenses.
 1.1.2.5 28-Aug-2008  haad Add new parameters to netbsd proplib protocol. Fix flags manipulation
in our driver it should behaves like linux now. Fix other minor protocol
differences.
 1.1.2.4 19-Aug-2008  haad Add $NetBSD$ tag to all dm driver sources.
 1.1.2.3 28-Jul-2008  haad Add status function to targets. This function is called from dm_table_status_ioctl,
when DM_STATUS_TABLE_FLAG is specified and it's purpose is construct params string.
Which can be sent back to libdevmapper.

Add adding removing of the DM_SUSPENDED_FLAG flag in dm_dev_suspend/resume ioctls.
 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.3.8.4 11-Mar-2010  yamt sync with head
 1.3.8.3 20-Jun-2009  yamt sync with head
 1.3.8.2 04-May-2009  yamt sync with head.
 1.3.8.1 22-Dec-2008  yamt file netbsd-dm.h was added on branch yamt-nfs-mp on 2009-05-04 08:12:37 +0000
 1.3.6.1 23-Jul-2009  jym Sync with HEAD.
 1.3.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.3.4.1 22-Dec-2008  skrll file netbsd-dm.h was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.3.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.3.2.1 22-Dec-2008  mjf file netbsd-dm.h was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.6.40.2 28-Aug-2017  skrll Sync with HEAD
 1.6.40.1 22-Sep-2015  skrll Sync with HEAD
 1.6.22.1 03-Dec-2017  jdolecek update from HEAD
 1.8.6.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.6 07-Nov-2021  andvar fix various typos, mainly s/prefered/preferred/
 1.5 21-Aug-2021  andvar fix typos in sys/dev/dm code comments and documentation.
also remove some trailing space in documentation.
 1.4 04-Jun-2017  mbalmer more dependiences -> dependencies
 1.3 09-Dec-2013  wiz branches: 1.3.6;
Fix typo ("then" instead of "than")
 1.2 19-Dec-2008  haad branches: 1.2.2; 1.2.4; 1.2.8; 1.2.20; 1.2.30; 1.2.34;
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.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.2.34.1 18-May-2014  rmind sync with head
 1.2.30.2 03-Dec-2017  jdolecek update from HEAD
 1.2.30.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.20.1 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.2.8.2 04-May-2009  yamt sync with head.
 1.2.8.1 19-Dec-2008  yamt file design.txt was added on branch yamt-nfs-mp on 2009-05-04 08:12:37 +0000
 1.2.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.2.4.1 19-Dec-2008  skrll file design.txt was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.2.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.2.1 19-Dec-2008  mjf file design.txt was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000
 1.3.6.1 28-Aug-2017  skrll Sync with HEAD
 1.5 14-Oct-2023  andvar fix various typos in comments and documentation, mainly in word "between".
 1.4 21-Aug-2021  andvar fix typos in sys/dev/dm code comments and documentation.
also remove some trailing space in documentation.
 1.3 07-Dec-2019  tkusumi dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD
 1.2 01-Dec-2019  tkusumi dm: Remove unused dm_dev::dev_type

Given OOP-like architecture of dm target device structure,
dm_dev doesn't need to have self contained target type field,
and in fact this is unused.
 1.1 23-Oct-2010  haad branches: 1.1.2; 1.1.8; 1.1.64;
Add old file describing locking schema used in dm driver.
 1.1.64.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.8.2 05-Mar-2011  rmind sync with head
 1.1.8.1 23-Oct-2010  rmind file locking.txt was added on branch rmind-uvmplock on 2011-03-05 20:53:08 +0000
 1.1.2.2 06-Nov-2010  uebayasi Sync with HEAD.
 1.1.2.1 23-Oct-2010  uebayasi file locking.txt was added on branch uebayasi-xip on 2010-11-06 08:08:29 +0000
 1.2 19-Dec-2008  haad branches: 1.2.2; 1.2.4; 1.2.8;
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.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.2.8.2 04-May-2009  yamt sync with head.
 1.2.8.1 19-Dec-2008  yamt file proposal-dm.txt was added on branch yamt-nfs-mp on 2009-05-04 08:12:37 +0000
 1.2.4.2 19-Jan-2009  skrll Sync with HEAD.
 1.2.4.1 19-Dec-2008  skrll file proposal-dm.txt was added on branch nick-hppapmap on 2009-01-19 13:17:53 +0000
 1.2.2.2 17-Jan-2009  mjf Sync with HEAD.
 1.2.2.1 19-Dec-2008  mjf file proposal-dm.txt was added on branch mjf-devfs2 on 2009-01-17 13:28:53 +0000

RSS XML Feed