xref: /netbsd-src/lib/libdm/dm.3 (revision 6c259f3957f89c11609ed3fdf8d0040e66d0ae42)
1*6c259f39Srillig.\"     $NetBSD: dm.3,v 1.7 2022/09/10 12:14:17 rillig Exp $
283425a0fShaad.\"
383425a0fShaad.\" Copyright (c) 2004,2009 The NetBSD Foundation, Inc.
483425a0fShaad.\" All rights reserved.
583425a0fShaad.\"
683425a0fShaad.\" This code is derived from software contributed to The NetBSD Foundation
783425a0fShaad.\" by Adam Hamsik.
883425a0fShaad.\"
983425a0fShaad.\" Redistribution and use in source and binary forms, with or without
1083425a0fShaad.\" modification, are permitted provided that the following conditions
1183425a0fShaad.\" are met:
1283425a0fShaad.\" 1. Redistributions of source code must retain the above copyright
1383425a0fShaad.\"    notice, this list of conditions and the following disclaimer.
1483425a0fShaad.\" 2. Redistributions in binary form must reproduce the above copyright
1583425a0fShaad.\"    notice, this list of conditions and the following disclaimer in the
1683425a0fShaad.\"    documentation and/or other materials provided with the distribution.
1783425a0fShaad.\"
1883425a0fShaad.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1983425a0fShaad.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2083425a0fShaad.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2183425a0fShaad.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2283425a0fShaad.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2383425a0fShaad.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2483425a0fShaad.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2583425a0fShaad.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2683425a0fShaad.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2783425a0fShaad.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2883425a0fShaad.\" POSSIBILITY OF SUCH DAMAGE.
2989567fa5Sdholland.Dd January 22, 2016
3083425a0fShaad.Dt DM 3
3183425a0fShaad.Os
3283425a0fShaad.Sh NAME
336024239eShaad.Nm dm
3483425a0fShaad.Nd device-mapper access manipulation library
3583425a0fShaad.Sh LIBRARY
3683425a0fShaad.Lb libdm
3783425a0fShaad.Sh SYNOPSIS
3889567fa5Sdholland.In dm.h
3983425a0fShaad.Ft void
4083425a0fShaad.Fn libdm_iter_destroy "libdm_iter_t libdm_iter"
4183425a0fShaad.Ft int
4283425a0fShaad.Fn libdm_task_run "libdm_task_t *libdm_task"
4383425a0fShaad.Ft libdm_task_t
4483425a0fShaad.Fn libdm_task_create "const char *command"
4583425a0fShaad.Ft void
4683425a0fShaad.Fn libdm_task_destroy "libdm_task_t libdm_task"
4783425a0fShaad.Ft int
4883425a0fShaad.Fn libdm_task_set_name "const char *name" "libdm_task_t libdm_task"
4983425a0fShaad.Ft char *
5083425a0fShaad.Fn libdm_task_get_name "libdm_task_t libdm_task"
5183425a0fShaad.Ft int
5283425a0fShaad.Fn libdm_task_set_uuid "const char *uuid" "libdm_task_t libdm_task"
5383425a0fShaad.Ft char *
5483425a0fShaad.Fn libdm_task_get_uuid "libdm_task_t libdm_task"
5583425a0fShaad.Ft char *
5683425a0fShaad.Fn libdm_task_get_command "libdm_task_t libdm_task"
5783425a0fShaad.Ft int32_t
5883425a0fShaad.Fn libdm_task_get_cmd_version "libdm_task_t libdm_task" "uint32_t *ver" "size_t size"
5983425a0fShaad.Ft int
6083425a0fShaad.Fn libdm_task_set_minor "uint32_t minor" "libdm_task_t libdm_task"
6183425a0fShaad.Ft uint32_t
6283425a0fShaad.Fn libdm_task_get_minor "libdm_task_t libdm_task"
6383425a0fShaad.Ft int
6483425a0fShaad.Fn libdm_task_set_flags "uint32_t flags" "libdm_task_t libdm_task"
6583425a0fShaad.Ft uint32_t
6683425a0fShaad.Fn libdm_task_get_flags "libdm_task_t libdm_task"
6783425a0fShaad.Ft uint32_t
6883425a0fShaad.Fn libdm_task_get_target_num "libdm_task_t libdm_task"
6983425a0fShaad.Ft int32_t
7083425a0fShaad.Fn libdm_task_get_open_num "libdm_task_t libdm_task"
7183425a0fShaad.Ft uint32_t
7283425a0fShaad.Fn libdm_task_get_event_num "libdm_task_t libdm_task"
7383425a0fShaad.Ft int
7483425a0fShaad.Fn libdm_task_set_cmd "libdm_cmd_t libdm_cmd" "libdm_task_t libdm_task"
7583425a0fShaad.Ft libdm_cmd_t
7683425a0fShaad.Fn libdm_task_get_cmd "libdm_task_t libdm_task"
7783425a0fShaad.Ft libdm_cmd_t
7883425a0fShaad.Fn libdm_cmd_create "void"
7983425a0fShaad.Ft void
8083425a0fShaad.Fn libdm_cmd_destroy "libdm_cmd_t libdm_cmd"
8183425a0fShaad.Ft libdm_iter_t
8283425a0fShaad.Fn libdm_cmd_iter_create "libdm_cmd_t libdm_cmd"
8383425a0fShaad.Ft int
8483425a0fShaad.Fn libdm_cmd_set_table "libdm_table_t libdm_table" "libdm_cmd_t libdm_cmd"
8583425a0fShaad.Ft libdm_table_t
8683425a0fShaad.Fn libdm_cmd_get_table "libdm_iter_t iter"
8783425a0fShaad.Ft libdm_target_t
8883425a0fShaad.Fn libdm_cmd_get_target "libdm_iter_t iter"
8983425a0fShaad.Ft libdm_dev_t
9083425a0fShaad.Fn libdm_cmd_get_dev "libdm_iter_t iter"
9183425a0fShaad.Ft uint64_t
9283425a0fShaad.Fn libdm_cmd_get_deps "libdm_iter_t libdm_iter"
9383425a0fShaad.Ft libdm_table_t
9483425a0fShaad.Fn libdm_table_create "void"
9583425a0fShaad.Ft void
9683425a0fShaad.Fn libdm_table_destroy "libdm_table_t libdm_table"
9783425a0fShaad.Ft int
9883425a0fShaad.Fn libdm_table_set_start "uint64_t start" "libdm_table_t libdm_table"
9983425a0fShaad.Ft uint64_t
10083425a0fShaad.Fn libdm_table_get_start "libdm_table_t libdm_table"
10183425a0fShaad.Ft int
10283425a0fShaad.Fn libdm_table_set_length "uint64_t length" "libdm_table_t libdm_table"
10383425a0fShaad.Ft uint64_t
10483425a0fShaad.Fn libdm_table_get_length "libdm_table_t libdm_table"
10583425a0fShaad.Ft int
10683425a0fShaad.Fn libdm_table_set_target "const char *name" "libdm_table_t libdm_table"
10783425a0fShaad.Ft char *
10883425a0fShaad.Fn libdm_table_get_target "libdm_table_t libdm_table"
10983425a0fShaad.Ft int
11083425a0fShaad.Fn libdm_table_set_params "const char *params" "libdm_table_t libdm_table"
11183425a0fShaad.Ft char *
11283425a0fShaad.Fn libdm_table_get_params "libdm_table_t libdm_table"
11383425a0fShaad.Ft int32_t
11483425a0fShaad.Fn libdm_table_get_status "libdm_table_t libdm_table"
11583425a0fShaad.Ft void
11683425a0fShaad.Fn libdm_target_destroy "libdm_target_t libdm_target"
11783425a0fShaad.Ft char *
11883425a0fShaad.Fn libdm_target_get_name "libdm_target_t libdm_target"
11983425a0fShaad.Ft int32_t
12083425a0fShaad.Fn libdm_target_get_version "libdm_target_t libdm_target" "uint32_t *ver" "size_t size"
12183425a0fShaad.Ft void
12283425a0fShaad.Fn libdm_dev_destroy "libdm_dev_t libdm_dev"
12383425a0fShaad.Ft char *
12483425a0fShaad.Fn libdm_dev_get_name "libdm_dev_t libdm_dev"
12583425a0fShaad.Ft uint32_t
12683425a0fShaad.Fn libdm_dev_get_minor "libdm_dev_t libdm_dev"
12783425a0fShaad.Ft int
12883425a0fShaad.Fn libdm_dev_set_newname "const char *newname" "libdm_cmd_t libdm_cmd"
12983425a0fShaad.Sh DESCRIPTION
13049efa429SwizEvery object in libdm has its own create and destroy routine.
13183425a0fShaad.Bl -bullet -offset indent -compact
13283425a0fShaad.It
13383425a0fShaadlibdm_task_t
13483425a0fShaad.It
13583425a0fShaadlibdm_cmd_t
13683425a0fShaad.It
13783425a0fShaadlibdm_table_t
13883425a0fShaad.El
13983425a0fShaad.Pp
14083425a0fShaadExcept
14183425a0fShaad.Vt libdm_dev_t
14283425a0fShaadwhich is received from kernel as list of physical devices on which
14349efa429Swizthe logical device depends.
14483425a0fShaad.Vt libdm_target_t
14549efa429Swizwhich is received from kernel as list of available targets to use.
14683425a0fShaad.Vt libdm_iter_t
14749efa429Swizwhich is used as iteration counter for array entries in the task structure.
14883425a0fShaad.Pp
14949efa429SwizEvery object attribute in libdm can be set and gotten by appropriate routines,
15049efa429Swiztherefore there always are set and get routines.
15183425a0fShaad.Ss LIBDM TASK
15283425a0fShaadThe
15383425a0fShaad.Fn libdm_task_create
15483425a0fShaadfunction creates a libdm task dictionary with command string set to
15583425a0fShaad.Fa command .
15683425a0fShaadIf
15783425a0fShaad.Fa command
15883425a0fShaadis
15983425a0fShaad.Dv NULL ,
16049efa429Swizlibdm_task_t is not created and the function returns
16183425a0fShaad.Dv NULL .
16283425a0fShaad.Pp
16383425a0fShaad.Fn libdm_task_destroy
16483425a0fShaadfree all memory allocated to
16583425a0fShaad.Fa libdm_task
16683425a0fShaadby
16783425a0fShaad.Fn libdm_task_create .
16883425a0fShaad.Pp
16983425a0fShaad.Fn libdm_task_run
17083425a0fShaadSends created
17183425a0fShaad.Fa libdm_task
17249efa429Swizto kernel and receives new one as reply.
17383425a0fShaad.Pp
174*6c259f39SrilligList of attributes available in
17583425a0fShaad.Vt libdm_task_t :
17683425a0fShaad.Bl -column -offset indent "DM_IOCTL_TARGET_COUNT" "Number of table entries" "XXX"
17783425a0fShaad.It Sy Attribute Ta Sy Description Ta Sy Mode
17883425a0fShaad.It Li DM_IOCTL_OPEN Ta Device open-count Ta Read-Only
17983425a0fShaad.It Li DM_IOCTL_MINOR Ta Device minor number Ta Read-Write
18083425a0fShaad.It Li DM_IOCTL_NAME Ta Device name Ta Read-Write
18183425a0fShaad.It Li DM_IOCTL_UUID Ta Device uuid Ta Read-Write
18283425a0fShaad.It Li DM_IOCTL_TARGET_COUNT Ta Number of table entries Ta Read-Only
18383425a0fShaad.\".It Li DM_IOCTL_EVENT Ta Not implemented Ta not imp
18483425a0fShaad.It Li DM_IOCTL_FLAGS Ta Device status flags Ta Read-Write
18583425a0fShaad.El
18683425a0fShaad.Pp
18783425a0fShaad.Fn libdm_task_set_name
18883425a0fShaadand
18983425a0fShaad.Fn libdm_task_get_name
19049efa429SwizSet name of the device for commands which need to have a dm device
19149efa429Swizidentifier.
19249efa429SwizThe device-mapper later uses the device name to look up the device
19349efa429Swizfrom the list of all devices.
19449efa429SwizThe get routine will fetch the device name from the task dictionary.
19583425a0fShaad.Pp
19683425a0fShaad.Fn libdm_task_set_uuid
19783425a0fShaadand
19883425a0fShaad.Fn libdm_task_get_uuid
19949efa429SwizSet uuid of device for commands which need to have a dm device
20049efa429Swizidentifier.
20149efa429SwizThe device-mapper later uses the device uuid to look up the device
20249efa429Swizfrom the list of all devices.
20349efa429SwizThe get routine will fetch the device uuid from the task dictionary.
20483425a0fShaad.Pp
20583425a0fShaad.Fn libdm_task_set_minor
20683425a0fShaadand
20783425a0fShaad.Fn libdm_task_get_minor
20849efa429SwizSet minor device number of device for commands which need to have
20949efa429Swiza dm device identifier.
21049efa429SwizThe device-mapper later uses the device minor number to look up
21149efa429Swizthe device from the list of all devices.
21249efa429SwizThe get routine will fetch the device minor number from the task
21349efa429Swizdictionary.
21483425a0fShaad.Pp
21583425a0fShaad.Fn libdm_task_set_flags
21683425a0fShaadand
21783425a0fShaad.Fn libdm_task_get_flags
21849efa429SwizSet/fetch device status flags from the task dictionary.
21983425a0fShaad.Pp
22083425a0fShaad.Fn libdm_task_get_open_num
2216024239eShaadFetch number of opened devices from the kernel and return them as count.
22283425a0fShaad.Pp
22383425a0fShaad.Fn libdm_task_get_target_num
2246024239eShaadFetch number of opened devices from the kernel and return them as count.
22583425a0fShaad.Pp
22683425a0fShaad.Fn libdm_task_get_cmd_version
22749efa429SwizGet the version of the dm driver in the kernel as array
22883425a0fShaad.Fa uint32_t *ver
22949efa429Swizof size
23049efa429Swiz.Fa size .
23183425a0fShaad.Fn libdm_task_set_cmd
23283425a0fShaadand
23383425a0fShaad.Fn libdm_task_get_cmd
23449efa429SwizAdd and fetch cmd structure from
23583425a0fShaad.Vt libdm_task_t .
23683425a0fShaad.Vt libdm_cmd_t
23749efa429Swizis the container used to carry information specific for the particular
23849efa429Swizcommand.
23949efa429Swizcmd is usually set before libdm_task_run is used and is taken from
24049efa429Swizthe task structure after the task run was called.
24183425a0fShaad.Ss LIBDM TASK CMD
24283425a0fShaadThe
24383425a0fShaad.Fn libdm_cmd_create
24449efa429Swizfunction will allocate a cmd structure which can later be put in
24549efa429Swizto the task.
24683425a0fShaad.Pp
24783425a0fShaad.Fn libdm_cmd_destroy
24849efa429Swizwill deallocate a previously allocated cmd structure.
24983425a0fShaad.Pp
25083425a0fShaad.Fn libdm_cmd_set_table
25149efa429SwizWill load and fetch the device mapping table from the dm device.
25249efa429SwizThe table is usually loaded to the device during initial device
25349efa429Swizcreation or device resizing.
25483425a0fShaad.Pp
25549efa429SwizBecause libdm_cmd is an array of structures, all _get routines need an
25649efa429Swiziterator to work.
25749efa429SwizFor every entry we can have more than one.
25883425a0fShaad.Fn libdm_cmd_get_table
25949efa429SwizWhen the user creates a task with the "status" command, the kernel
26049efa429Swizsends cmd with a table in it.
26183425a0fShaad.Pp
26283425a0fShaad.Fn libdm_cmd_get_target
26349efa429SwizGet mapping target description from cmd.
26449efa429SwizTarget contains target_name and target_version.
26583425a0fShaad.Pp
26683425a0fShaad.Fn libdm_cmd_get_dev
26749efa429SwizWhen user creates a task with the "info" command, the kernel sends
26849efa429Swizcmd with information about dm device to user.
26983425a0fShaad.Pp
27083425a0fShaad.Fn libdm_cmd_get_deps
27149efa429SwizWhen user creates a task with the "deps" command, the kernel sends
27249efa429Swizcmd with an array of physical devices attached to the dm device.
27383425a0fShaad.Pp
27449efa429SwizUsually the device has more than one table entry in the device command.
27549efa429SwizTherefore cmd iterators are needed for
27649efa429Swiz.Vt libdm_cmd_t ;
27749efa429Swizthey can be created by the
27883425a0fShaad.Fn libdm_cmd_iter_create
27949efa429Swizfunction.
280252a7f0fSnjoly.Ss LIBDM CMD TABLE
28149efa429SwizA device table describes the logical mapping between the dm device and
28249efa429Swizphysical devices.
28349efa429SwizEvery table has the logical block start, the table length (in disk
28449efa429Swizblocks), the target used by table, the physical device, and the
28549efa429Swizoffset on it.
28649efa429SwizThe physical device and the offset on it are parameters which are
28749efa429Swiztarget specific and are passed down to the target as param string.
28883425a0fShaad.Pp
28983425a0fShaadExample device table entry
29083425a0fShaad.Dl 0 1024 linear /dev/wd1a 384
29183425a0fShaad.Bl -column -offset indent "DM_TABLE_LENGTH" "Number of table entries"
29283425a0fShaad.It Sy Attribute Ta Sy Description
29383425a0fShaad.It Li DM_TABLE_TYPE Ta Used device mapper target
29483425a0fShaad.It Li DM_TABLE_START Ta Device Logical start block
29583425a0fShaad.It Li DM_TABLE_STAT Ta Is 1 if this is current active table
29683425a0fShaad.It Li DM_TABLE_LENGTH Ta Logical length described by table
29783425a0fShaad.It Li DM_TABLE_PARAMS Ta Params passed down to target
29883425a0fShaad.El
29983425a0fShaad.Pp
30083425a0fShaad.Fn libdm_table_set_start
30183425a0fShaadand
30283425a0fShaad.Fn libdm_table_get_start
30349efa429SwizSet start table from
30483425a0fShaad.Fa start
30583425a0fShaadvalue to
30683425a0fShaad.Fa libdm_table
30749efa429Swizargument.
30849efa429SwizGet routine will get the table start from kernel as
30983425a0fShaad.Vt libdm_table .
31083425a0fShaad.Pp
31183425a0fShaad.Fn libdm_table_set_length
31283425a0fShaadand
31383425a0fShaad.Fn libdm_table_get_length
31449efa429SwizSet table length from
31583425a0fShaad.Fa length
31683425a0fShaadvalue to
31783425a0fShaad.Fa libdm_table
31849efa429Swizargument.
31949efa429SwizGet routine will get the table length from kernel as
32083425a0fShaad.Vt libdm_table .
32183425a0fShaad.Pp
32283425a0fShaad.Fn libdm_table_set_target
32383425a0fShaadand
32483425a0fShaad.Fn libdm_table_get_target
32549efa429SwizSet target name from
32683425a0fShaad.Fa target
32783425a0fShaadvalue to
32883425a0fShaad.Fa libdm_table
32949efa429Swizargument.
33049efa429SwizThe target must be actually present in the kernel, otherwise
33149efa429Swiz.Fn libdm_task_run
33249efa429Swizwill fail.
33349efa429SwizGet routine will get the table entry target from kernel as
33483425a0fShaad.Vt libdm_table .
33583425a0fShaad.Pp
33683425a0fShaad.Fn libdm_table_set_params
33783425a0fShaadand
33883425a0fShaad.Fn libdm_table_get_params
33983425a0fShaadSet table target parameter string from
34083425a0fShaad.Fa params
34149efa429Swizargument to
34283425a0fShaad.Fa libdm_table .
34349efa429SwizThis is later in the kernel passed to the target init routine.
34449efa429SwizGet routine will get the table parameter string from kernel as
34583425a0fShaad.Vt libdm_table .
34683425a0fShaad.Pp
34783425a0fShaad.Fn libdm_table_get_status
34849efa429SwizGet table status which can be Active/Inactive.
34949efa429SwizThis tells if this table is actually used or not.
35083425a0fShaad.Ss LIBDM_TARGET
35183425a0fShaad.Fn libdm_target_destroy
35283425a0fShaadDestroy target received from
35383425a0fShaad.Vt libdm_cmd
35483425a0fShaadwith libdm_cmd_iter iterator.
35583425a0fShaad.Pp
35683425a0fShaad.Fn libdm_target_get_name
35749efa429Swizreturns pointer to a string with available target name.
35883425a0fShaad.Pp
359*6c259f39Srillig.Fn libdm_target_get_version
36083425a0fShaadSets argument
36183425a0fShaad.Fa ver[3]
36249efa429Swizto a in-kernel loaded target version.
36383425a0fShaad.Ss LIBDM_DEV
36483425a0fShaad.Fn libdm_dev_destroy
36583425a0fShaadDestroy device received from
36683425a0fShaad.Vt libdm_cmd
36783425a0fShaadwith libdm_cmd_iter iterator.
36883425a0fShaad.Pp
36983425a0fShaad.Fn libdm_dev_get_name
37083425a0fShaadReturn pointer to a string with underlying device name from
37183425a0fShaad.Vt libdm_dev_t
37283425a0fShaad.Pp
37383425a0fShaad.Fn libdm_dev_get_minor
37483425a0fShaadReturn underlying device minor number.
37583425a0fShaad.Ss MISC
37683425a0fShaad.Fn libdm_dev_set_newname
37783425a0fShaadThis routine will set new dm device name attribute to
37883425a0fShaad.Fa newname .
37983425a0fShaadUser must then called libdm_task_run on this task to
38049efa429Swizchange the device name.
38183425a0fShaad.Sh RETURN VALUES
38249efa429SwizUpon success, all described functions return zero or
38349efa429Swiz.Pf non- Dv NULL
38449efa429Swizpointer.
38583425a0fShaadOtherwise, an error number will be returned to indicate the error.
38683425a0fShaad.Sh SEE ALSO
38783425a0fShaad.Xr dm 4
38883425a0fShaad.Sh HISTORY
38983425a0fShaadThe
39083425a0fShaad.Nm
39183425a0fShaadwas written and contributed to
39283425a0fShaad.Nx
39349efa429Swizby
39449efa429Swiz.An Adam Hamsik
39549efa429Swizand first appeared in
39683425a0fShaad.Nx 6.0 .
397