Annotation of src/sys/dev/dm/dm_ioctl.c, revision 1.35

1.35    ! tkusumi     1: /* $NetBSD: dm_ioctl.c,v 1.34 2019/11/30 05:35:57 tkusumi Exp $      */
1.2       haad        2: 
                      3: /*
                      4:  * Copyright (c) 2008 The NetBSD Foundation, Inc.
                      5:  * All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to The NetBSD Foundation
                      8:  * by Adam Hamsik.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     20:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     21:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     22:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     23:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     24:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     25:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     26:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     27:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     28:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     29:  * POSSIBILITY OF SUCH DAMAGE.
                     30:  */
1.32      christos   31: #include <sys/cdefs.h>
1.35    ! tkusumi    32: __KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v 1.34 2019/11/30 05:35:57 tkusumi Exp $");
1.2       haad       33: 
                     34: /*
                     35:  * Locking is used to synchronise between ioctl calls and between dm_table's
                     36:  * users.
                     37:  *
                     38:  * ioctl locking:
                     39:  * Simple reference counting, to count users of device will be used routines
                     40:  * dm_dev_busy/dm_dev_unbusy are used for that.
                     41:  * dm_dev_lookup/dm_dev_rem call dm_dev_busy before return(caller is therefore
                     42:  * holder of reference_counter last).
                     43:  *
                     44:  * ioctl routines which change/remove dm_dev parameters must wait on
                     45:  * dm_dev::dev_cv and when last user will call dm_dev_unbusy they will wake
                     46:  * up them.
                     47:  *
                     48:  * table_head locking:
1.20      haad       49:  * To access table entries dm_table_* routines must be used.
1.2       haad       50:  *
                     51:  * dm_table_get_entry will increment table users reference
1.22      haad       52:  * counter. It will return active or inactive table depends
1.2       haad       53:  * on uint8_t argument.
                     54:  *
                     55:  * dm_table_release must be called for every table_entry from
                     56:  * dm_table_get_entry. Between these to calls tables can'tbe switched
1.20      haad       57:  * or destroyed.
1.2       haad       58:  *
                     59:  * dm_table_head_init initialize talbe_entries SLISTS and io_cv.
                     60:  *
                     61:  * dm_table_head_destroy destroy cv.
                     62:  *
                     63:  * There are two types of users for dm_table_head first type will
                     64:  * only read list and try to do anything with it e.g. dmstrategy,
                     65:  * dm_table_size etc. There is another user for table_head which wants
                     66:  * to change table lists e.g. dm_dev_resume_ioctl, dm_dev_remove_ioctl,
                     67:  * dm_table_clear_ioctl.
1.20      haad       68:  *
1.2       haad       69:  * NOTE: It is not allowed to call dm_table_destroy, dm_table_switch_tables
                     70:  *       with hold table reference counter. Table reference counter is hold
                     71:  *       after calling dm_table_get_entry routine. After calling this
                     72:  *       function user must call dm_table_release before any writer table
                     73:  *       operation.
                     74:  *
                     75:  * Example: dm_table_get_entry
                     76:  *          dm_table_destroy/dm_table_switch_tables
                     77:  * This exaple will lead to deadlock situation because after dm_table_get_entry
                     78:  * table reference counter is != 0 and dm_table_destroy have to wait on cv until
                     79:  * reference counter is 0.
                     80:  *
                     81:  */
                     82: 
                     83: #include <sys/types.h>
                     84: #include <sys/param.h>
                     85: 
1.19      haad       86: #include <sys/device.h>
1.6       haad       87: #include <sys/disk.h>
1.2       haad       88: #include <sys/disklabel.h>
                     89: #include <sys/kmem.h>
                     90: #include <sys/malloc.h>
                     91: #include <sys/vnode.h>
                     92: 
                     93: #include <machine/int_fmtio.h>
                     94: 
                     95: #include "netbsd-dm.h"
                     96: #include "dm.h"
                     97: 
1.23      haad       98: static uint32_t sc_minor_num;
1.10      haad       99: extern const struct dkdriver dmdkdriver;
1.24      haad      100: uint32_t dm_dev_counter;
1.2       haad      101: 
1.19      haad      102: /* Generic cf_data for device-mapper driver */
                    103: static struct cfdata dm_cfdata = {
                    104:        .cf_name = "dm",
                    105:        .cf_atname = "dm",
                    106:        .cf_fstate = FSTATE_STAR,
                    107:        .cf_unit = 0
                    108: };
1.2       haad      109: #define DM_REMOVE_FLAG(flag, name) do {                                        \
                    110:                prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag); \
                    111:                flag &= ~name;                                          \
                    112:                prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
1.20      haad      113: } while (/*CONSTCOND*/0)
1.2       haad      114: 
                    115: #define DM_ADD_FLAG(flag, name) do {                                   \
                    116:                prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag); \
                    117:                flag |= name;                                           \
                    118:                prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
1.20      haad      119: } while (/*CONSTCOND*/0)
1.2       haad      120: 
                    121: static int dm_dbg_print_flags(int);
                    122: 
                    123: /*
                    124:  * Print flags sent to the kernel from libevmapper.
                    125:  */
                    126: static int
                    127: dm_dbg_print_flags(int flags)
                    128: {
1.20      haad      129:        aprint_debug("dbg_print --- %d\n", flags);
                    130: 
1.2       haad      131:        if (flags & DM_READONLY_FLAG)
                    132:                aprint_debug("dbg_flags: DM_READONLY_FLAG set In/Out\n");
                    133: 
                    134:        if (flags & DM_SUSPEND_FLAG)
                    135:                aprint_debug("dbg_flags: DM_SUSPEND_FLAG set In/Out \n");
                    136: 
                    137:        if (flags & DM_PERSISTENT_DEV_FLAG)
                    138:                aprint_debug("db_flags: DM_PERSISTENT_DEV_FLAG set In\n");
                    139: 
                    140:        if (flags & DM_STATUS_TABLE_FLAG)
                    141:                aprint_debug("dbg_flags: DM_STATUS_TABLE_FLAG set In\n");
                    142: 
                    143:        if (flags & DM_ACTIVE_PRESENT_FLAG)
                    144:                aprint_debug("dbg_flags: DM_ACTIVE_PRESENT_FLAG set Out\n");
                    145: 
                    146:        if (flags & DM_INACTIVE_PRESENT_FLAG)
                    147:                aprint_debug("dbg_flags: DM_INACTIVE_PRESENT_FLAG set Out\n");
                    148: 
                    149:        if (flags & DM_BUFFER_FULL_FLAG)
                    150:                aprint_debug("dbg_flags: DM_BUFFER_FULL_FLAG set Out\n");
                    151: 
                    152:        if (flags & DM_SKIP_BDGET_FLAG)
                    153:                aprint_debug("dbg_flags: DM_SKIP_BDGET_FLAG set In\n");
                    154: 
                    155:        if (flags & DM_SKIP_LOCKFS_FLAG)
                    156:                aprint_debug("dbg_flags: DM_SKIP_LOCKFS_FLAG set In\n");
                    157: 
                    158:        if (flags & DM_NOFLUSH_FLAG)
                    159:                aprint_debug("dbg_flags: DM_NOFLUSH_FLAG set In\n");
1.20      haad      160: 
1.2       haad      161:        return 0;
                    162: }
1.32      christos  163: 
1.2       haad      164: /*
                    165:  * Get version ioctl call I do it as default therefore this
                    166:  * function is unused now.
                    167:  */
                    168: int
                    169: dm_get_version_ioctl(prop_dictionary_t dm_dict)
                    170: {
1.20      haad      171: 
1.2       haad      172:        return 0;
                    173: }
1.32      christos  174: 
1.2       haad      175: /*
                    176:  * Get list of all available targets from global
                    177:  * target list and sent them back to libdevmapper.
                    178:  */
                    179: int
                    180: dm_list_versions_ioctl(prop_dictionary_t dm_dict)
                    181: {
                    182:        prop_array_t target_list;
                    183:        uint32_t flags;
                    184: 
                    185:        flags = 0;
                    186: 
                    187:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
1.20      haad      188: 
1.2       haad      189:        dm_dbg_print_flags(flags);
                    190:        target_list = dm_target_prop_list();
                    191: 
                    192:        prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, target_list);
1.20      haad      193:        prop_object_release(target_list);
1.2       haad      194: 
                    195:        return 0;
                    196: }
1.32      christos  197: 
1.2       haad      198: /*
                    199:  * Create in-kernel entry for device. Device attributes such as name, uuid are
                    200:  * taken from proplib dictionary.
                    201:  *
                    202:  */
                    203: int
                    204: dm_dev_create_ioctl(prop_dictionary_t dm_dict)
                    205: {
                    206:        dm_dev_t *dmv;
                    207:        const char *name, *uuid;
1.29      justin    208:        int r;
                    209:        uint32_t flags;
1.19      haad      210:        device_t devt;
1.20      haad      211: 
1.2       haad      212:        r = 0;
                    213:        flags = 0;
1.20      haad      214:        name = NULL;
1.2       haad      215:        uuid = NULL;
                    216: 
                    217:        /* Get needed values from dictionary. */
                    218:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    219:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    220:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
1.20      haad      221: 
1.2       haad      222:        dm_dbg_print_flags(flags);
                    223: 
                    224:        /* Lookup name and uuid if device already exist quit. */
                    225:        if ((dmv = dm_dev_lookup(name, uuid, -1)) != NULL) {
1.20      haad      226:                DM_ADD_FLAG(flags, DM_EXISTS_FLAG);     /* Device already exists */
1.2       haad      227:                dm_dev_unbusy(dmv);
                    228:                return EEXIST;
                    229:        }
1.19      haad      230:        if ((devt = config_attach_pseudo(&dm_cfdata)) == NULL) {
                    231:                aprint_error("Unable to attach pseudo device dm/%s\n", name);
                    232:                return (ENOMEM);
                    233:        }
1.2       haad      234:        if ((dmv = dm_dev_alloc()) == NULL)
                    235:                return ENOMEM;
1.19      haad      236: 
1.2       haad      237:        if (uuid)
                    238:                strncpy(dmv->uuid, uuid, DM_UUID_LEN);
1.20      haad      239:        else
1.2       haad      240:                dmv->uuid[0] = '\0';
1.20      haad      241: 
1.2       haad      242:        if (name)
                    243:                strlcpy(dmv->name, name, DM_NAME_LEN);
                    244: 
1.23      haad      245:        dmv->minor = (uint64_t)atomic_inc_32_nv(&sc_minor_num);
1.20      haad      246:        dmv->flags = 0;         /* device flags are set when needed */
1.2       haad      247:        dmv->ref_cnt = 0;
                    248:        dmv->event_nr = 0;
1.19      haad      249:        dmv->devt = devt;
1.20      haad      250: 
1.19      haad      251:        dm_table_head_init(&dmv->table_head);
                    252: 
1.2       haad      253:        mutex_init(&dmv->dev_mtx, MUTEX_DEFAULT, IPL_NONE);
1.18      haad      254:        mutex_init(&dmv->diskp_mtx, MUTEX_DEFAULT, IPL_NONE);
1.2       haad      255:        cv_init(&dmv->dev_cv, "dm_dev");
                    256: 
                    257:        if (flags & DM_READONLY_FLAG)
                    258:                dmv->flags |= DM_READONLY_FLAG;
                    259: 
                    260:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
1.6       haad      261: 
1.10      haad      262:        disk_init(dmv->diskp, dmv->name, &dmdkdriver);
                    263:        disk_attach(dmv->diskp);
1.13      haad      264: 
                    265:        dmv->diskp->dk_info = NULL;
1.20      haad      266: 
                    267:        if ((r = dm_dev_insert(dmv)) != 0)
1.2       haad      268:                dm_dev_free(dmv);
1.20      haad      269: 
1.2       haad      270:        DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
                    271:        DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
1.6       haad      272: 
                    273:        /* Increment device counter After creating device */
1.24      haad      274:        atomic_inc_32(&dm_dev_counter);
1.20      haad      275: 
1.2       haad      276:        return r;
                    277: }
1.32      christos  278: 
1.2       haad      279: /*
                    280:  * Get list of created device-mapper devices fromglobal list and
                    281:  * send it to kernel.
                    282:  *
                    283:  * Output dictionary:
                    284:  *
                    285:  * <key>cmd_data</key>
                    286:  *  <array>
                    287:  *   <dict>
                    288:  *    <key>name<key>
                    289:  *    <string>...</string>
                    290:  *
                    291:  *    <key>dev</key>
                    292:  *    <integer>...</integer>
                    293:  *   </dict>
                    294:  *  </array>
1.20      haad      295:  *
1.2       haad      296:  */
                    297: int
                    298: dm_dev_list_ioctl(prop_dictionary_t dm_dict)
                    299: {
                    300:        prop_array_t dev_list;
                    301: 
                    302:        uint32_t flags;
1.20      haad      303: 
1.2       haad      304:        flags = 0;
1.20      haad      305: 
1.2       haad      306:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
1.20      haad      307: 
1.2       haad      308:        dm_dbg_print_flags(flags);
1.20      haad      309: 
1.2       haad      310:        dev_list = dm_dev_prop_list();
                    311: 
                    312:        prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, dev_list);
                    313:        prop_object_release(dev_list);
1.20      haad      314: 
1.2       haad      315:        return 0;
                    316: }
1.32      christos  317: 
1.2       haad      318: /*
                    319:  * Rename selected devices old name is in struct dm_ioctl.
                    320:  * newname is taken from dictionary
                    321:  *
                    322:  * <key>cmd_data</key>
                    323:  *  <array>
                    324:  *   <string>...</string>
                    325:  *  </array>
                    326:  */
                    327: int
                    328: dm_dev_rename_ioctl(prop_dictionary_t dm_dict)
                    329: {
                    330:        prop_array_t cmd_array;
                    331:        dm_dev_t *dmv;
1.20      haad      332: 
1.2       haad      333:        const char *name, *uuid, *n_name;
                    334:        uint32_t flags, minor;
                    335: 
                    336:        name = NULL;
                    337:        uuid = NULL;
                    338:        minor = 0;
1.20      haad      339: 
1.2       haad      340:        /* Get needed values from dictionary. */
                    341:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    342:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    343:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    344:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
                    345: 
                    346:        dm_dbg_print_flags(flags);
1.20      haad      347: 
1.2       haad      348:        cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
                    349: 
                    350:        prop_array_get_cstring_nocopy(cmd_array, 0, &n_name);
1.20      haad      351: 
1.2       haad      352:        if (strlen(n_name) + 1 > DM_NAME_LEN)
                    353:                return EINVAL;
1.20      haad      354: 
1.2       haad      355:        if ((dmv = dm_dev_rem(name, uuid, minor)) == NULL) {
                    356:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    357:                return ENOENT;
                    358:        }
                    359:        /* change device name */
1.20      haad      360:        /*
                    361:         * XXX How to deal with this change, name only used in
                    362:         * dm_dev_routines, should I add dm_dev_change_name which will run
                    363:         * under the dm_dev_list mutex ?
1.2       haad      364:         */
                    365:        strlcpy(dmv->name, n_name, DM_NAME_LEN);
1.20      haad      366: 
1.2       haad      367:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
                    368:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
                    369:        prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
                    370: 
                    371:        dm_dev_insert(dmv);
1.20      haad      372: 
1.2       haad      373:        return 0;
                    374: }
1.32      christos  375: 
1.2       haad      376: /*
                    377:  * Remove device from global list I have to remove active
                    378:  * and inactive tables first.
                    379:  */
                    380: int
                    381: dm_dev_remove_ioctl(prop_dictionary_t dm_dict)
                    382: {
                    383:        dm_dev_t *dmv;
                    384:        const char *name, *uuid;
                    385:        uint32_t flags, minor;
1.19      haad      386:        device_t devt;
1.20      haad      387: 
1.2       haad      388:        flags = 0;
                    389:        name = NULL;
                    390:        uuid = NULL;
1.20      haad      391: 
1.2       haad      392:        /* Get needed values from dictionary. */
                    393:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    394:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    395:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    396:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
1.20      haad      397: 
1.2       haad      398:        dm_dbg_print_flags(flags);
1.19      haad      399: 
1.20      haad      400:        /*
                    401:         * This seems as hack to me, probably use routine dm_dev_get_devt to
                    402:         * atomicaly get devt from device.
                    403:         */
1.19      haad      404:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      405:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    406:                return ENOENT;
                    407:        }
1.19      haad      408:        devt = dmv->devt;
1.2       haad      409: 
1.19      haad      410:        dm_dev_unbusy(dmv);
1.20      haad      411: 
                    412:        /*
                    413:         * This will call dm_detach routine which will actually removes
                    414:         * device.
                    415:         */
1.19      haad      416:        return config_detach(devt, DETACH_QUIET);
1.2       haad      417: }
1.32      christos  418: 
1.2       haad      419: /*
                    420:  * Return actual state of device to libdevmapper.
                    421:  */
                    422: int
                    423: dm_dev_status_ioctl(prop_dictionary_t dm_dict)
                    424: {
                    425:        dm_dev_t *dmv;
                    426:        const char *name, *uuid;
                    427:        uint32_t flags, j, minor;
1.20      haad      428: 
1.2       haad      429:        name = NULL;
                    430:        uuid = NULL;
                    431:        flags = 0;
                    432:        j = 0;
1.20      haad      433: 
1.2       haad      434:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    435:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    436:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    437:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
1.20      haad      438: 
1.2       haad      439:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
                    440:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    441:                return ENOENT;
                    442:        }
1.20      haad      443:        dm_dbg_print_flags(dmv->flags);
1.2       haad      444: 
                    445:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
                    446:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
                    447:        prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
                    448: 
                    449:        if (dmv->flags & DM_SUSPEND_FLAG)
                    450:                DM_ADD_FLAG(flags, DM_SUSPEND_FLAG);
                    451: 
1.20      haad      452:        /*
                    453:         * Add status flags for tables I have to check both active and
                    454:         * inactive tables.
                    455:         */
1.2       haad      456:        if ((j = dm_table_get_target_count(&dmv->table_head, DM_TABLE_ACTIVE))) {
                    457:                DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
                    458:        } else
                    459:                DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
1.20      haad      460: 
1.2       haad      461:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_TARGET_COUNT, j);
1.20      haad      462: 
1.2       haad      463:        if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_INACTIVE))
                    464:                DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
                    465:        else
                    466:                DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
                    467: 
                    468:        dm_dev_unbusy(dmv);
1.20      haad      469: 
1.2       haad      470:        return 0;
                    471: }
1.32      christos  472: 
1.2       haad      473: /*
                    474:  * Set only flag to suggest that device is suspended. This call is
                    475:  * not supported in NetBSD.
                    476:  *
                    477:  */
                    478: int
                    479: dm_dev_suspend_ioctl(prop_dictionary_t dm_dict)
                    480: {
                    481:        dm_dev_t *dmv;
                    482:        const char *name, *uuid;
                    483:        uint32_t flags, minor;
1.20      haad      484: 
1.2       haad      485:        name = NULL;
                    486:        uuid = NULL;
                    487:        flags = 0;
1.20      haad      488: 
1.2       haad      489:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    490:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    491:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    492:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
1.20      haad      493: 
                    494:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      495:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    496:                return ENOENT;
                    497:        }
                    498:        atomic_or_32(&dmv->flags, DM_SUSPEND_FLAG);
1.20      haad      499: 
1.2       haad      500:        dm_dbg_print_flags(dmv->flags);
1.20      haad      501: 
1.2       haad      502:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
                    503:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, dmv->flags);
                    504:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
1.20      haad      505: 
1.2       haad      506:        dm_dev_unbusy(dmv);
1.20      haad      507: 
1.2       haad      508:        /* Add flags to dictionary flag after dmv -> dict copy */
1.20      haad      509:        DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
                    510: 
1.2       haad      511:        return 0;
                    512: }
1.32      christos  513: 
1.2       haad      514: /*
                    515:  * Simulate Linux behaviour better and switch tables here and not in
1.20      haad      516:  * dm_table_load_ioctl.
1.2       haad      517:  */
                    518: int
                    519: dm_dev_resume_ioctl(prop_dictionary_t dm_dict)
                    520: {
                    521:        dm_dev_t *dmv;
                    522:        const char *name, *uuid;
                    523:        uint32_t flags, minor;
                    524: 
                    525:        name = NULL;
                    526:        uuid = NULL;
                    527:        flags = 0;
1.20      haad      528: 
                    529:        /*
                    530:         * char *xml; xml = prop_dictionary_externalize(dm_dict);
                    531:         * printf("%s\n",xml);
                    532:         */
                    533: 
1.2       haad      534:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    535:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    536:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    537:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
1.20      haad      538: 
1.2       haad      539:        /* Remove device from global device list */
1.20      haad      540:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      541:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    542:                return ENOENT;
                    543:        }
1.33      mlelstv   544: 
                    545:        /* Make inactive table active, if it exists */
                    546:        if (dmv->flags & DM_INACTIVE_PRESENT_FLAG)
                    547:                dm_table_switch_tables(&dmv->table_head);
                    548: 
1.2       haad      549:        atomic_and_32(&dmv->flags, ~(DM_SUSPEND_FLAG | DM_INACTIVE_PRESENT_FLAG));
                    550:        atomic_or_32(&dmv->flags, DM_ACTIVE_PRESENT_FLAG);
1.20      haad      551: 
                    552:        DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
1.2       haad      553: 
1.13      haad      554:        dmgetproperties(dmv->diskp, &dmv->table_head);
1.20      haad      555: 
1.2       haad      556:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
1.16      haad      557:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags);
1.2       haad      558:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
                    559: 
                    560:        dm_dev_unbusy(dmv);
                    561: 
                    562:        /* Destroy inactive table after resume. */
                    563:        dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
1.20      haad      564: 
1.2       haad      565:        return 0;
                    566: }
1.32      christos  567: 
1.2       haad      568: /*
                    569:  * Table management routines
                    570:  * lvm2tools doens't send name/uuid to kernel with table
                    571:  * for lookup I have to use minor number.
                    572:  */
                    573: 
                    574: /*
                    575:  * Remove inactive table from device. Routines which work's with inactive tables
                    576:  * doesn't need to synchronise with dmstrategy. They can synchronise themselves with mutex?.
                    577:  *
                    578:  */
                    579: int
                    580: dm_table_clear_ioctl(prop_dictionary_t dm_dict)
                    581: {
                    582:        dm_dev_t *dmv;
                    583:        const char *name, *uuid;
                    584:        uint32_t flags, minor;
                    585: 
1.20      haad      586:        dmv = NULL;
1.2       haad      587:        name = NULL;
                    588:        uuid = NULL;
                    589:        flags = 0;
                    590:        minor = 0;
1.20      haad      591: 
1.2       haad      592:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    593:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    594:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    595:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
1.20      haad      596: 
1.2       haad      597:        aprint_debug("Clearing inactive table from device: %s--%s\n",
                    598:            name, uuid);
1.20      haad      599: 
                    600:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      601:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    602:                return ENOENT;
                    603:        }
                    604:        /* Select unused table */
                    605:        dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
                    606: 
                    607:        atomic_and_32(&dmv->flags, ~DM_INACTIVE_PRESENT_FLAG);
                    608: 
                    609:        dm_dev_unbusy(dmv);
1.20      haad      610: 
1.2       haad      611:        return 0;
                    612: }
1.32      christos  613: 
1.2       haad      614: /*
                    615:  * Get list of physical devices for active table.
                    616:  * Get dev_t from pdev vnode and insert it into cmd_array.
                    617:  *
                    618:  * XXX. This function is called from lvm2tools to get information
1.20      haad      619:  *      about physical devices, too e.g. during vgcreate.
1.2       haad      620:  */
                    621: int
                    622: dm_table_deps_ioctl(prop_dictionary_t dm_dict)
                    623: {
                    624:        dm_dev_t *dmv;
                    625:        dm_table_t *tbl;
                    626:        dm_table_entry_t *table_en;
                    627: 
                    628:        prop_array_t cmd_array;
                    629:        const char *name, *uuid;
                    630:        uint32_t flags, minor;
1.17      haad      631: 
                    632:        int table_type;
1.2       haad      633: 
                    634:        name = NULL;
                    635:        uuid = NULL;
1.20      haad      636:        dmv = NULL;
1.2       haad      637:        flags = 0;
1.20      haad      638: 
1.2       haad      639:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    640:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    641:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    642:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
                    643: 
                    644:        /* create array for dev_t's */
                    645:        cmd_array = prop_array_create();
                    646: 
1.20      haad      647:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      648:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    649:                return ENOENT;
                    650:        }
                    651:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
                    652:        prop_dictionary_set_cstring(dm_dict, DM_IOCTL_NAME, dmv->name);
                    653:        prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
1.20      haad      654: 
1.2       haad      655:        aprint_debug("Getting table deps for device: %s\n", dmv->name);
                    656: 
1.20      haad      657:        /*
                    658:         * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query
                    659:         * INACTIVE TABLE
                    660:         */
1.17      haad      661:        if (flags & DM_QUERY_INACTIVE_TABLE_FLAG)
                    662:                table_type = DM_TABLE_INACTIVE;
                    663:        else
                    664:                table_type = DM_TABLE_ACTIVE;
1.20      haad      665: 
1.17      haad      666:        tbl = dm_table_get_entry(&dmv->table_head, table_type);
1.2       haad      667: 
                    668:        SLIST_FOREACH(table_en, tbl, next)
1.20      haad      669:            table_en->target->deps(table_en, cmd_array);
1.2       haad      670: 
1.17      haad      671:        dm_table_release(&dmv->table_head, table_type);
1.2       haad      672:        dm_dev_unbusy(dmv);
1.20      haad      673: 
1.2       haad      674:        prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array);
                    675:        prop_object_release(cmd_array);
1.20      haad      676: 
1.2       haad      677:        return 0;
                    678: }
1.32      christos  679: 
1.2       haad      680: /*
                    681:  * Load new table/tables to device.
                    682:  * Call apropriate target init routine open all physical pdev's and
                    683:  * link them to device. For other targets mirror, strip, snapshot
                    684:  * etc. also add dependency devices to upcalls list.
                    685:  *
                    686:  * Load table to inactive slot table are switched in dm_device_resume_ioctl.
                    687:  * This simulates Linux behaviour better there should not be any difference.
                    688:  *
                    689:  */
                    690: int
                    691: dm_table_load_ioctl(prop_dictionary_t dm_dict)
                    692: {
                    693:        dm_dev_t *dmv;
                    694:        dm_table_entry_t *table_en, *last_table;
1.20      haad      695:        dm_table_t *tbl;
1.2       haad      696:        dm_target_t *target;
                    697: 
                    698:        prop_object_iterator_t iter;
                    699:        prop_array_t cmd_array;
1.15      haad      700:        prop_dictionary_t target_dict;
1.20      haad      701: 
1.2       haad      702:        const char *name, *uuid, *type;
                    703: 
                    704:        uint32_t flags, ret, minor;
                    705: 
1.15      haad      706:        char *str;
                    707: 
1.2       haad      708:        ret = 0;
                    709:        flags = 0;
                    710:        name = NULL;
                    711:        uuid = NULL;
                    712:        dmv = NULL;
                    713:        last_table = NULL;
1.15      haad      714:        str = NULL;
1.2       haad      715: 
1.20      haad      716:        /*
                    717:         * char *xml; xml = prop_dictionary_externalize(dm_dict);
                    718:         * printf("%s\n",xml);
                    719:         */
                    720: 
1.2       haad      721:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    722:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    723:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    724:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
1.20      haad      725: 
1.2       haad      726:        cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
                    727:        iter = prop_array_iterator(cmd_array);
1.20      haad      728:        dm_dbg_print_flags(flags);
                    729: 
                    730:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      731:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
1.28      mlelstv   732:                prop_object_iterator_release(iter);
1.2       haad      733:                return ENOENT;
                    734:        }
1.7       haad      735:        aprint_debug("Loading table to device: %s--%d\n", name,
                    736:            dmv->table_head.cur_active_table);
1.20      haad      737: 
1.2       haad      738:        /*
                    739:         * I have to check if this table slot is not used by another table list.
                    740:         * if it is used I should free them.
                    741:         */
                    742:        if (dmv->flags & DM_INACTIVE_PRESENT_FLAG)
                    743:                dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
                    744: 
                    745:        dm_dbg_print_flags(dmv->flags);
                    746:        tbl = dm_table_get_entry(&dmv->table_head, DM_TABLE_INACTIVE);
1.20      haad      747: 
1.2       haad      748:        aprint_debug("dmv->name = %s\n", dmv->name);
1.20      haad      749: 
1.2       haad      750:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
                    751: 
1.20      haad      752:        while ((target_dict = prop_object_iterator_next(iter)) != NULL) {
1.2       haad      753: 
                    754:                prop_dictionary_get_cstring_nocopy(target_dict,
                    755:                    DM_TABLE_TYPE, &type);
                    756:                /*
                    757:                 * If we want to deny table with 2 or more different
                    758:                 * target we should do it here
                    759:                 */
1.7       haad      760:                if (((target = dm_target_lookup(type)) == NULL) &&
                    761:                    ((target = dm_target_autoload(type)) == NULL)) {
1.8       haad      762:                        dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
1.7       haad      763:                        dm_dev_unbusy(dmv);
1.28      mlelstv   764:                        prop_object_iterator_release(iter);
1.2       haad      765:                        return ENOENT;
1.7       haad      766:                }
1.31      chs       767:                table_en = kmem_alloc(sizeof(dm_table_entry_t), KM_SLEEP);
1.2       haad      768:                prop_dictionary_get_uint64(target_dict, DM_TABLE_START,
                    769:                    &table_en->start);
                    770:                prop_dictionary_get_uint64(target_dict, DM_TABLE_LENGTH,
                    771:                    &table_en->length);
                    772: 
                    773:                table_en->target = target;
                    774:                table_en->dm_dev = dmv;
                    775:                table_en->target_config = NULL;
1.20      haad      776: 
1.2       haad      777:                /*
                    778:                 * There is a parameter string after dm_target_spec
                    779:                 * structure which  points to /dev/wd0a 284 part of
                    780:                 * table. String str points to this text. This can be
                    781:                 * null and therefore it should be checked before we try to
                    782:                 * use it.
                    783:                 */
1.15      haad      784:                prop_dictionary_get_cstring(target_dict,
1.20      haad      785:                    DM_TABLE_PARAMS, (char **) &str);
                    786: 
1.30      christos  787:                if (SLIST_EMPTY(tbl) || last_table == NULL)
1.2       haad      788:                        /* insert this table to head */
                    789:                        SLIST_INSERT_HEAD(tbl, table_en, next);
                    790:                else
                    791:                        SLIST_INSERT_AFTER(last_table, table_en, next);
1.20      haad      792: 
1.2       haad      793:                /*
                    794:                 * Params string is different for every target,
                    795:                 * therfore I have to pass it to target init
                    796:                 * routine and parse parameters there.
                    797:                 */
1.20      haad      798: 
1.2       haad      799:                if ((ret = target->init(dmv, &table_en->target_config,
1.15      haad      800:                            str)) != 0) {
1.2       haad      801: 
1.4       haad      802:                        dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
1.2       haad      803:                        dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
1.15      haad      804:                        free(str, M_TEMP);
                    805: 
1.4       haad      806:                        dm_dev_unbusy(dmv);
1.28      mlelstv   807:                        prop_object_iterator_release(iter);
1.2       haad      808:                        return ret;
                    809:                }
                    810:                last_table = table_en;
1.15      haad      811:                free(str, M_TEMP);
1.2       haad      812:        }
                    813:        prop_object_iterator_release(iter);
1.20      haad      814: 
1.2       haad      815:        DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
                    816:        atomic_or_32(&dmv->flags, DM_INACTIVE_PRESENT_FLAG);
1.20      haad      817: 
1.2       haad      818:        dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
                    819:        dm_dev_unbusy(dmv);
                    820:        return 0;
                    821: }
1.32      christos  822: 
1.2       haad      823: /*
                    824:  * Get description of all tables loaded to device from kernel
                    825:  * and send it to libdevmapper.
                    826:  *
                    827:  * Output dictionary for every table:
                    828:  *
                    829:  * <key>cmd_data</key>
                    830:  * <array>
                    831:  *   <dict>
                    832:  *    <key>type<key>
                    833:  *    <string>...</string>
                    834:  *
                    835:  *    <key>start</key>
                    836:  *    <integer>...</integer>
                    837:  *
                    838:  *    <key>length</key>
                    839:  *    <integer>...</integer>
                    840:  *
                    841:  *    <key>params</key>
                    842:  *    <string>...</string>
                    843:  *   </dict>
                    844:  * </array>
                    845:  *
                    846:  */
                    847: int
                    848: dm_table_status_ioctl(prop_dictionary_t dm_dict)
                    849: {
                    850:        dm_dev_t *dmv;
                    851:        dm_table_t *tbl;
                    852:        dm_table_entry_t *table_en;
                    853: 
                    854:        prop_array_t cmd_array;
                    855:        prop_dictionary_t target_dict;
1.20      haad      856: 
1.29      justin    857:        uint32_t minor, flags;
1.20      haad      858: 
1.2       haad      859:        const char *name, *uuid;
                    860:        char *params;
1.17      haad      861:        int table_type;
1.20      haad      862: 
1.2       haad      863:        dmv = NULL;
                    864:        uuid = NULL;
                    865:        name = NULL;
                    866:        params = NULL;
                    867:        flags = 0;
                    868: 
                    869:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    870:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    871:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    872:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
                    873: 
                    874:        cmd_array = prop_array_create();
1.20      haad      875: 
                    876:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      877:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    878:                return ENOENT;
                    879:        }
1.20      haad      880:        /*
                    881:         * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query
                    882:         * INACTIVE TABLE
                    883:         */
1.17      haad      884:        if (flags & DM_QUERY_INACTIVE_TABLE_FLAG)
                    885:                table_type = DM_TABLE_INACTIVE;
                    886:        else
                    887:                table_type = DM_TABLE_ACTIVE;
1.20      haad      888: 
1.2       haad      889:        if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_ACTIVE))
                    890:                DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
                    891:        else {
                    892:                DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
1.20      haad      893: 
1.2       haad      894:                if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_INACTIVE))
                    895:                        DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
                    896:                else {
                    897:                        DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
                    898:                }
                    899:        }
1.20      haad      900: 
1.2       haad      901:        if (dmv->flags & DM_SUSPEND_FLAG)
                    902:                DM_ADD_FLAG(flags, DM_SUSPEND_FLAG);
1.20      haad      903: 
1.2       haad      904:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
1.20      haad      905: 
1.2       haad      906:        aprint_debug("Status of device tables: %s--%d\n",
                    907:            name, dmv->table_head.cur_active_table);
1.20      haad      908: 
1.17      haad      909:        tbl = dm_table_get_entry(&dmv->table_head, table_type);
1.20      haad      910: 
                    911:        SLIST_FOREACH(table_en, tbl, next) {
1.2       haad      912:                target_dict = prop_dictionary_create();
                    913:                aprint_debug("%016" PRIu64 ", length %016" PRIu64
                    914:                    ", target %s\n", table_en->start, table_en->length,
                    915:                    table_en->target->name);
                    916: 
                    917:                prop_dictionary_set_uint64(target_dict, DM_TABLE_START,
                    918:                    table_en->start);
                    919:                prop_dictionary_set_uint64(target_dict, DM_TABLE_LENGTH,
                    920:                    table_en->length);
                    921: 
                    922:                prop_dictionary_set_cstring(target_dict, DM_TABLE_TYPE,
                    923:                    table_en->target->name);
                    924: 
                    925:                /* dm_table_get_cur_actv.table ?? */
                    926:                prop_dictionary_set_int32(target_dict, DM_TABLE_STAT,
                    927:                    dmv->table_head.cur_active_table);
                    928: 
1.34      tkusumi   929:                /*
                    930:                 * Explicitly clear DM_TABLE_PARAMS to prevent dmsetup(8) from
                    931:                 * printing junk when DM_TABLE_PARAMS was never initialized.
                    932:                 */
                    933:                prop_dictionary_set_cstring(target_dict, DM_TABLE_PARAMS, "");
                    934: 
1.25      joerg     935:                if (flags & DM_STATUS_TABLE_FLAG) {
1.2       haad      936:                        params = table_en->target->status
                    937:                            (table_en->target_config);
                    938: 
1.20      haad      939:                        if (params != NULL) {
1.2       haad      940:                                prop_dictionary_set_cstring(target_dict,
                    941:                                    DM_TABLE_PARAMS, params);
1.20      haad      942: 
1.14      haad      943:                                kmem_free(params, DM_MAX_PARAMS_SIZE);
1.2       haad      944:                        }
                    945:                }
                    946:                prop_array_add(cmd_array, target_dict);
                    947:                prop_object_release(target_dict);
                    948:        }
                    949: 
1.17      haad      950:        dm_table_release(&dmv->table_head, table_type);
1.2       haad      951:        dm_dev_unbusy(dmv);
1.17      haad      952: 
                    953:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags);
1.2       haad      954:        prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array);
                    955:        prop_object_release(cmd_array);
1.20      haad      956: 
1.2       haad      957:        return 0;
                    958: }
                    959: 
                    960: /*
                    961:  * For every call I have to set kernel driver version.
                    962:  * Because I can have commands supported only in other
1.20      haad      963:  * newer/later version. This routine is called for every
1.2       haad      964:  * ioctl command.
                    965:  */
                    966: int
                    967: dm_check_version(prop_dictionary_t dm_dict)
                    968: {
                    969:        size_t i;
1.29      justin    970:        uint32_t dm_version[3];
1.2       haad      971:        prop_array_t ver;
1.20      haad      972: 
1.2       haad      973:        ver = prop_dictionary_get(dm_dict, DM_IOCTL_VERSION);
1.20      haad      974: 
                    975:        for (i = 0; i < 3; i++)
1.2       haad      976:                prop_array_get_uint32(ver, i, &dm_version[i]);
                    977: 
1.20      haad      978:        if (DM_VERSION_MAJOR != dm_version[0] || DM_VERSION_MINOR < dm_version[1]) {
1.2       haad      979:                aprint_debug("libdevmapper/kernel version mismatch "
                    980:                    "kernel: %d.%d.%d libdevmapper: %d.%d.%d\n",
                    981:                    DM_VERSION_MAJOR, DM_VERSION_MINOR, DM_VERSION_PATCHLEVEL,
                    982:                    dm_version[0], dm_version[1], dm_version[2]);
1.20      haad      983: 
1.2       haad      984:                return EIO;
                    985:        }
                    986:        prop_array_set_uint32(ver, 0, DM_VERSION_MAJOR);
                    987:        prop_array_set_uint32(ver, 1, DM_VERSION_MINOR);
                    988:        prop_array_set_uint32(ver, 2, DM_VERSION_PATCHLEVEL);
                    989: 
1.17      haad      990:        prop_dictionary_set(dm_dict, DM_IOCTL_VERSION, ver);
1.20      haad      991: 
1.2       haad      992:        return 0;
                    993: }

CVSweb <webmaster@jp.NetBSD.org>