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

1.47    ! tkusumi     1: /* $NetBSD: dm_ioctl.c,v 1.46 2019/12/15 14:39:42 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.47    ! tkusumi    32: __KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v 1.46 2019/12/15 14:39:42 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>
1.19      haad       85: #include <sys/device.h>
1.6       haad       86: #include <sys/disk.h>
1.2       haad       87: #include <sys/disklabel.h>
                     88: #include <sys/kmem.h>
                     89: #include <sys/malloc.h>
                     90: 
                     91: #include <machine/int_fmtio.h>
                     92: 
                     93: #include "netbsd-dm.h"
                     94: #include "dm.h"
                     95: 
1.23      haad       96: static uint32_t sc_minor_num;
1.24      haad       97: uint32_t dm_dev_counter;
1.2       haad       98: 
1.19      haad       99: /* Generic cf_data for device-mapper driver */
                    100: static struct cfdata dm_cfdata = {
                    101:        .cf_name = "dm",
                    102:        .cf_atname = "dm",
                    103:        .cf_fstate = FSTATE_STAR,
                    104:        .cf_unit = 0
                    105: };
1.47    ! tkusumi   106: 
1.2       haad      107: #define DM_REMOVE_FLAG(flag, name) do {                                        \
1.47    ! tkusumi   108:        prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag);       \
        !           109:        flag &= ~name;                                                  \
        !           110:        prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag);        \
1.20      haad      111: } while (/*CONSTCOND*/0)
1.2       haad      112: 
                    113: #define DM_ADD_FLAG(flag, name) do {                                   \
1.47    ! tkusumi   114:        prop_dictionary_get_uint32(dm_dict,DM_IOCTL_FLAGS,&flag);       \
        !           115:        flag |= name;                                                   \
        !           116:        prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag);        \
1.20      haad      117: } while (/*CONSTCOND*/0)
1.2       haad      118: 
1.41      tkusumi   119: static int dm_table_init(dm_target_t *, dm_table_entry_t *, char *);
1.2       haad      120: 
                    121: /*
1.47    ! tkusumi   122:  * Print flags sent to the kernel from libdevmapper.
1.2       haad      123:  */
                    124: static int
1.43      tkusumi   125: dm_dbg_print_flags(uint32_t flags)
1.2       haad      126: {
1.46      tkusumi   127: 
1.20      haad      128:        aprint_debug("dbg_print --- %d\n", flags);
                    129: 
1.2       haad      130:        if (flags & DM_READONLY_FLAG)
                    131:                aprint_debug("dbg_flags: DM_READONLY_FLAG set In/Out\n");
                    132: 
                    133:        if (flags & DM_SUSPEND_FLAG)
1.39      tkusumi   134:                aprint_debug("dbg_flags: DM_SUSPEND_FLAG set In/Out\n");
1.2       haad      135: 
                    136:        if (flags & DM_PERSISTENT_DEV_FLAG)
1.39      tkusumi   137:                aprint_debug("dbg_flags: DM_PERSISTENT_DEV_FLAG set In\n");
1.2       haad      138: 
                    139:        if (flags & DM_STATUS_TABLE_FLAG)
                    140:                aprint_debug("dbg_flags: DM_STATUS_TABLE_FLAG set In\n");
                    141: 
                    142:        if (flags & DM_ACTIVE_PRESENT_FLAG)
                    143:                aprint_debug("dbg_flags: DM_ACTIVE_PRESENT_FLAG set Out\n");
                    144: 
                    145:        if (flags & DM_INACTIVE_PRESENT_FLAG)
                    146:                aprint_debug("dbg_flags: DM_INACTIVE_PRESENT_FLAG set Out\n");
                    147: 
                    148:        if (flags & DM_BUFFER_FULL_FLAG)
                    149:                aprint_debug("dbg_flags: DM_BUFFER_FULL_FLAG set Out\n");
                    150: 
                    151:        if (flags & DM_SKIP_BDGET_FLAG)
                    152:                aprint_debug("dbg_flags: DM_SKIP_BDGET_FLAG set In\n");
                    153: 
                    154:        if (flags & DM_SKIP_LOCKFS_FLAG)
                    155:                aprint_debug("dbg_flags: DM_SKIP_LOCKFS_FLAG set In\n");
                    156: 
                    157:        if (flags & DM_NOFLUSH_FLAG)
                    158:                aprint_debug("dbg_flags: DM_NOFLUSH_FLAG set In\n");
1.20      haad      159: 
1.2       haad      160:        return 0;
                    161: }
1.32      christos  162: 
1.2       haad      163: /*
                    164:  * Get list of all available targets from global
                    165:  * target list and sent them back to libdevmapper.
                    166:  */
                    167: int
                    168: dm_list_versions_ioctl(prop_dictionary_t dm_dict)
                    169: {
                    170:        prop_array_t target_list;
                    171:        uint32_t flags;
                    172: 
                    173:        flags = 0;
                    174: 
                    175:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
1.20      haad      176: 
1.2       haad      177:        dm_dbg_print_flags(flags);
                    178:        target_list = dm_target_prop_list();
                    179: 
                    180:        prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, target_list);
1.20      haad      181:        prop_object_release(target_list);
1.2       haad      182: 
                    183:        return 0;
                    184: }
1.32      christos  185: 
1.2       haad      186: /*
                    187:  * Create in-kernel entry for device. Device attributes such as name, uuid are
                    188:  * taken from proplib dictionary.
                    189:  */
                    190: int
                    191: dm_dev_create_ioctl(prop_dictionary_t dm_dict)
                    192: {
                    193:        dm_dev_t *dmv;
                    194:        const char *name, *uuid;
1.29      justin    195:        int r;
                    196:        uint32_t flags;
1.19      haad      197:        device_t devt;
1.20      haad      198: 
1.2       haad      199:        flags = 0;
1.20      haad      200:        name = NULL;
1.2       haad      201:        uuid = NULL;
                    202: 
                    203:        /* Get needed values from dictionary. */
                    204:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    205:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    206:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
1.20      haad      207: 
1.2       haad      208:        dm_dbg_print_flags(flags);
                    209: 
                    210:        /* Lookup name and uuid if device already exist quit. */
                    211:        if ((dmv = dm_dev_lookup(name, uuid, -1)) != NULL) {
1.20      haad      212:                DM_ADD_FLAG(flags, DM_EXISTS_FLAG);     /* Device already exists */
1.2       haad      213:                dm_dev_unbusy(dmv);
                    214:                return EEXIST;
                    215:        }
1.19      haad      216:        if ((devt = config_attach_pseudo(&dm_cfdata)) == NULL) {
                    217:                aprint_error("Unable to attach pseudo device dm/%s\n", name);
                    218:                return (ENOMEM);
                    219:        }
1.2       haad      220:        if ((dmv = dm_dev_alloc()) == NULL)
                    221:                return ENOMEM;
1.19      haad      222: 
1.2       haad      223:        if (uuid)
                    224:                strncpy(dmv->uuid, uuid, DM_UUID_LEN);
1.20      haad      225:        else
1.2       haad      226:                dmv->uuid[0] = '\0';
1.20      haad      227: 
1.2       haad      228:        if (name)
                    229:                strlcpy(dmv->name, name, DM_NAME_LEN);
                    230: 
1.23      haad      231:        dmv->minor = (uint64_t)atomic_inc_32_nv(&sc_minor_num);
1.20      haad      232:        dmv->flags = 0;         /* device flags are set when needed */
1.2       haad      233:        dmv->ref_cnt = 0;
                    234:        dmv->event_nr = 0;
1.19      haad      235:        dmv->devt = devt;
1.20      haad      236: 
1.19      haad      237:        dm_table_head_init(&dmv->table_head);
                    238: 
1.2       haad      239:        mutex_init(&dmv->dev_mtx, MUTEX_DEFAULT, IPL_NONE);
1.18      haad      240:        mutex_init(&dmv->diskp_mtx, MUTEX_DEFAULT, IPL_NONE);
1.2       haad      241:        cv_init(&dmv->dev_cv, "dm_dev");
                    242: 
                    243:        if (flags & DM_READONLY_FLAG)
                    244:                dmv->flags |= DM_READONLY_FLAG;
                    245: 
                    246:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
1.6       haad      247: 
1.10      haad      248:        disk_init(dmv->diskp, dmv->name, &dmdkdriver);
                    249:        disk_attach(dmv->diskp);
1.13      haad      250: 
                    251:        dmv->diskp->dk_info = NULL;
1.20      haad      252: 
                    253:        if ((r = dm_dev_insert(dmv)) != 0)
1.2       haad      254:                dm_dev_free(dmv);
1.20      haad      255: 
1.2       haad      256:        DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
                    257:        DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
1.6       haad      258: 
                    259:        /* Increment device counter After creating device */
1.24      haad      260:        atomic_inc_32(&dm_dev_counter);
1.20      haad      261: 
1.2       haad      262:        return r;
                    263: }
1.32      christos  264: 
1.2       haad      265: /*
                    266:  * Get list of created device-mapper devices fromglobal list and
                    267:  * send it to kernel.
                    268:  *
                    269:  * Output dictionary:
                    270:  *
                    271:  * <key>cmd_data</key>
                    272:  *  <array>
                    273:  *   <dict>
                    274:  *    <key>name<key>
                    275:  *    <string>...</string>
                    276:  *
                    277:  *    <key>dev</key>
                    278:  *    <integer>...</integer>
                    279:  *   </dict>
                    280:  *  </array>
                    281:  */
                    282: int
                    283: dm_dev_list_ioctl(prop_dictionary_t dm_dict)
                    284: {
                    285:        prop_array_t dev_list;
                    286:        uint32_t flags;
1.20      haad      287: 
1.2       haad      288:        flags = 0;
1.20      haad      289: 
1.2       haad      290:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
1.20      haad      291: 
1.2       haad      292:        dm_dbg_print_flags(flags);
1.20      haad      293: 
1.2       haad      294:        dev_list = dm_dev_prop_list();
                    295: 
                    296:        prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, dev_list);
                    297:        prop_object_release(dev_list);
1.20      haad      298: 
1.2       haad      299:        return 0;
                    300: }
1.32      christos  301: 
1.2       haad      302: /*
                    303:  * Rename selected devices old name is in struct dm_ioctl.
                    304:  * newname is taken from dictionary
                    305:  *
                    306:  * <key>cmd_data</key>
                    307:  *  <array>
                    308:  *   <string>...</string>
                    309:  *  </array>
                    310:  */
                    311: int
                    312: dm_dev_rename_ioctl(prop_dictionary_t dm_dict)
                    313: {
                    314:        prop_array_t cmd_array;
                    315:        dm_dev_t *dmv;
1.20      haad      316: 
1.2       haad      317:        const char *name, *uuid, *n_name;
                    318:        uint32_t flags, minor;
                    319: 
                    320:        name = NULL;
                    321:        uuid = NULL;
                    322:        minor = 0;
1.20      haad      323: 
1.2       haad      324:        /* Get needed values from dictionary. */
                    325:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    326:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    327:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    328:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
                    329: 
                    330:        dm_dbg_print_flags(flags);
1.20      haad      331: 
1.2       haad      332:        cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
                    333: 
                    334:        prop_array_get_cstring_nocopy(cmd_array, 0, &n_name);
1.20      haad      335: 
1.2       haad      336:        if (strlen(n_name) + 1 > DM_NAME_LEN)
                    337:                return EINVAL;
1.20      haad      338: 
1.2       haad      339:        if ((dmv = dm_dev_rem(name, uuid, minor)) == NULL) {
                    340:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    341:                return ENOENT;
                    342:        }
                    343:        /* change device name */
1.20      haad      344:        /*
                    345:         * XXX How to deal with this change, name only used in
                    346:         * dm_dev_routines, should I add dm_dev_change_name which will run
                    347:         * under the dm_dev_list mutex ?
1.2       haad      348:         */
                    349:        strlcpy(dmv->name, n_name, DM_NAME_LEN);
1.20      haad      350: 
1.2       haad      351:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
                    352:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
                    353:        prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
                    354: 
                    355:        dm_dev_insert(dmv);
1.20      haad      356: 
1.2       haad      357:        return 0;
                    358: }
1.32      christos  359: 
1.2       haad      360: /*
                    361:  * Remove device from global list I have to remove active
                    362:  * and inactive tables first.
                    363:  */
                    364: int
                    365: dm_dev_remove_ioctl(prop_dictionary_t dm_dict)
                    366: {
                    367:        dm_dev_t *dmv;
                    368:        const char *name, *uuid;
                    369:        uint32_t flags, minor;
1.19      haad      370:        device_t devt;
1.20      haad      371: 
1.2       haad      372:        flags = 0;
                    373:        name = NULL;
                    374:        uuid = NULL;
1.20      haad      375: 
1.2       haad      376:        /* Get needed values from dictionary. */
                    377:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    378:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    379:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    380:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
1.20      haad      381: 
1.2       haad      382:        dm_dbg_print_flags(flags);
1.19      haad      383: 
1.20      haad      384:        /*
                    385:         * This seems as hack to me, probably use routine dm_dev_get_devt to
                    386:         * atomicaly get devt from device.
                    387:         */
1.19      haad      388:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      389:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    390:                return ENOENT;
                    391:        }
1.19      haad      392:        devt = dmv->devt;
1.2       haad      393: 
1.19      haad      394:        dm_dev_unbusy(dmv);
1.20      haad      395: 
                    396:        /*
                    397:         * This will call dm_detach routine which will actually removes
                    398:         * device.
                    399:         */
1.19      haad      400:        return config_detach(devt, DETACH_QUIET);
1.2       haad      401: }
1.32      christos  402: 
1.2       haad      403: /*
                    404:  * Return actual state of device to libdevmapper.
                    405:  */
                    406: int
                    407: dm_dev_status_ioctl(prop_dictionary_t dm_dict)
                    408: {
                    409:        dm_dev_t *dmv;
                    410:        const char *name, *uuid;
                    411:        uint32_t flags, j, minor;
1.20      haad      412: 
1.2       haad      413:        name = NULL;
                    414:        uuid = NULL;
                    415:        flags = 0;
1.20      haad      416: 
1.2       haad      417:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    418:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    419:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    420:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
1.20      haad      421: 
1.2       haad      422:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
                    423:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    424:                return ENOENT;
                    425:        }
1.20      haad      426:        dm_dbg_print_flags(dmv->flags);
1.2       haad      427: 
                    428:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
                    429:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
                    430:        prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
                    431: 
                    432:        if (dmv->flags & DM_SUSPEND_FLAG)
                    433:                DM_ADD_FLAG(flags, DM_SUSPEND_FLAG);
                    434: 
1.20      haad      435:        /*
                    436:         * Add status flags for tables I have to check both active and
                    437:         * inactive tables.
                    438:         */
1.37      tkusumi   439:        if ((j = dm_table_get_target_count(&dmv->table_head, DM_TABLE_ACTIVE)))
1.2       haad      440:                DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
1.37      tkusumi   441:        else
1.2       haad      442:                DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
1.20      haad      443: 
1.2       haad      444:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_TARGET_COUNT, j);
1.20      haad      445: 
1.2       haad      446:        if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_INACTIVE))
                    447:                DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
                    448:        else
                    449:                DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
                    450: 
                    451:        dm_dev_unbusy(dmv);
1.20      haad      452: 
1.2       haad      453:        return 0;
                    454: }
1.32      christos  455: 
1.2       haad      456: /*
                    457:  * Set only flag to suggest that device is suspended. This call is
                    458:  * not supported in NetBSD.
                    459:  */
                    460: int
                    461: dm_dev_suspend_ioctl(prop_dictionary_t dm_dict)
                    462: {
                    463:        dm_dev_t *dmv;
                    464:        const char *name, *uuid;
                    465:        uint32_t flags, minor;
1.20      haad      466: 
1.2       haad      467:        name = NULL;
                    468:        uuid = NULL;
                    469:        flags = 0;
1.20      haad      470: 
1.2       haad      471:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    472:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    473:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    474:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
1.20      haad      475: 
                    476:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      477:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    478:                return ENOENT;
                    479:        }
                    480:        atomic_or_32(&dmv->flags, DM_SUSPEND_FLAG);
1.20      haad      481: 
1.2       haad      482:        dm_dbg_print_flags(dmv->flags);
1.20      haad      483: 
1.2       haad      484:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
                    485:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, dmv->flags);
                    486:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
1.20      haad      487: 
1.2       haad      488:        dm_dev_unbusy(dmv);
1.20      haad      489: 
1.2       haad      490:        /* Add flags to dictionary flag after dmv -> dict copy */
1.20      haad      491:        DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
                    492: 
1.2       haad      493:        return 0;
                    494: }
1.32      christos  495: 
1.2       haad      496: /*
                    497:  * Simulate Linux behaviour better and switch tables here and not in
1.20      haad      498:  * dm_table_load_ioctl.
1.2       haad      499:  */
                    500: int
                    501: dm_dev_resume_ioctl(prop_dictionary_t dm_dict)
                    502: {
                    503:        dm_dev_t *dmv;
                    504:        const char *name, *uuid;
                    505:        uint32_t flags, minor;
                    506: 
                    507:        name = NULL;
                    508:        uuid = NULL;
                    509:        flags = 0;
1.20      haad      510: 
                    511:        /*
                    512:         * char *xml; xml = prop_dictionary_externalize(dm_dict);
                    513:         * printf("%s\n",xml);
                    514:         */
                    515: 
1.2       haad      516:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    517:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    518:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    519:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
1.20      haad      520: 
1.2       haad      521:        /* Remove device from global device list */
1.20      haad      522:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      523:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    524:                return ENOENT;
                    525:        }
1.33      mlelstv   526: 
                    527:        /* Make inactive table active, if it exists */
                    528:        if (dmv->flags & DM_INACTIVE_PRESENT_FLAG)
                    529:                dm_table_switch_tables(&dmv->table_head);
                    530: 
1.2       haad      531:        atomic_and_32(&dmv->flags, ~(DM_SUSPEND_FLAG | DM_INACTIVE_PRESENT_FLAG));
                    532:        atomic_or_32(&dmv->flags, DM_ACTIVE_PRESENT_FLAG);
1.20      haad      533: 
                    534:        DM_ADD_FLAG(flags, DM_EXISTS_FLAG);
1.2       haad      535: 
1.13      haad      536:        dmgetproperties(dmv->diskp, &dmv->table_head);
1.20      haad      537: 
1.2       haad      538:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_OPEN, dmv->table_head.io_cnt);
1.16      haad      539:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_FLAGS, flags);
1.2       haad      540:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
                    541: 
                    542:        dm_dev_unbusy(dmv);
                    543: 
                    544:        /* Destroy inactive table after resume. */
                    545:        dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
1.20      haad      546: 
1.2       haad      547:        return 0;
                    548: }
1.32      christos  549: 
1.2       haad      550: /*
                    551:  * Table management routines
                    552:  * lvm2tools doens't send name/uuid to kernel with table
                    553:  * for lookup I have to use minor number.
                    554:  */
                    555: 
                    556: /*
                    557:  * Remove inactive table from device. Routines which work's with inactive tables
                    558:  * doesn't need to synchronise with dmstrategy. They can synchronise themselves with mutex?.
                    559:  */
                    560: int
                    561: dm_table_clear_ioctl(prop_dictionary_t dm_dict)
                    562: {
                    563:        dm_dev_t *dmv;
                    564:        const char *name, *uuid;
                    565:        uint32_t flags, minor;
                    566: 
                    567:        name = NULL;
                    568:        uuid = NULL;
                    569:        flags = 0;
                    570:        minor = 0;
1.20      haad      571: 
1.2       haad      572:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    573:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    574:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    575:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
1.20      haad      576: 
1.2       haad      577:        aprint_debug("Clearing inactive table from device: %s--%s\n",
                    578:            name, uuid);
1.20      haad      579: 
                    580:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      581:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    582:                return ENOENT;
                    583:        }
                    584:        /* Select unused table */
                    585:        dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
                    586: 
                    587:        atomic_and_32(&dmv->flags, ~DM_INACTIVE_PRESENT_FLAG);
                    588: 
                    589:        dm_dev_unbusy(dmv);
1.20      haad      590: 
1.2       haad      591:        return 0;
                    592: }
1.32      christos  593: 
1.2       haad      594: /*
                    595:  * Get list of physical devices for active table.
                    596:  * Get dev_t from pdev vnode and insert it into cmd_array.
                    597:  *
                    598:  * XXX. This function is called from lvm2tools to get information
1.20      haad      599:  *      about physical devices, too e.g. during vgcreate.
1.2       haad      600:  */
                    601: int
                    602: dm_table_deps_ioctl(prop_dictionary_t dm_dict)
                    603: {
                    604:        dm_dev_t *dmv;
                    605:        dm_table_t *tbl;
                    606:        dm_table_entry_t *table_en;
                    607: 
                    608:        prop_array_t cmd_array;
                    609:        const char *name, *uuid;
                    610:        uint32_t flags, minor;
1.17      haad      611:        int table_type;
1.2       haad      612: 
                    613:        name = NULL;
                    614:        uuid = NULL;
                    615:        flags = 0;
1.20      haad      616: 
1.2       haad      617:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    618:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    619:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    620:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
                    621: 
                    622:        /* create array for dev_t's */
                    623:        cmd_array = prop_array_create();
                    624: 
1.20      haad      625:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      626:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    627:                return ENOENT;
                    628:        }
                    629:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
                    630:        prop_dictionary_set_cstring(dm_dict, DM_IOCTL_NAME, dmv->name);
                    631:        prop_dictionary_set_cstring(dm_dict, DM_IOCTL_UUID, dmv->uuid);
1.20      haad      632: 
1.2       haad      633:        aprint_debug("Getting table deps for device: %s\n", dmv->name);
                    634: 
1.20      haad      635:        /*
                    636:         * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query
                    637:         * INACTIVE TABLE
                    638:         */
1.17      haad      639:        if (flags & DM_QUERY_INACTIVE_TABLE_FLAG)
                    640:                table_type = DM_TABLE_INACTIVE;
                    641:        else
                    642:                table_type = DM_TABLE_ACTIVE;
1.20      haad      643: 
1.17      haad      644:        tbl = dm_table_get_entry(&dmv->table_head, table_type);
1.2       haad      645: 
                    646:        SLIST_FOREACH(table_en, tbl, next)
1.37      tkusumi   647:                table_en->target->deps(table_en, cmd_array);
1.2       haad      648: 
1.17      haad      649:        dm_table_release(&dmv->table_head, table_type);
1.2       haad      650:        dm_dev_unbusy(dmv);
1.20      haad      651: 
1.2       haad      652:        prop_dictionary_set(dm_dict, DM_IOCTL_CMD_DATA, cmd_array);
                    653:        prop_object_release(cmd_array);
1.20      haad      654: 
1.2       haad      655:        return 0;
                    656: }
1.32      christos  657: 
1.2       haad      658: /*
                    659:  * Load new table/tables to device.
                    660:  * Call apropriate target init routine open all physical pdev's and
                    661:  * link them to device. For other targets mirror, strip, snapshot
                    662:  * etc. also add dependency devices to upcalls list.
                    663:  *
                    664:  * Load table to inactive slot table are switched in dm_device_resume_ioctl.
                    665:  * This simulates Linux behaviour better there should not be any difference.
                    666:  */
                    667: int
                    668: dm_table_load_ioctl(prop_dictionary_t dm_dict)
                    669: {
                    670:        dm_dev_t *dmv;
                    671:        dm_table_entry_t *table_en, *last_table;
1.20      haad      672:        dm_table_t *tbl;
1.2       haad      673:        dm_target_t *target;
                    674: 
                    675:        prop_object_iterator_t iter;
                    676:        prop_array_t cmd_array;
1.15      haad      677:        prop_dictionary_t target_dict;
1.20      haad      678: 
1.2       haad      679:        const char *name, *uuid, *type;
1.46      tkusumi   680:        uint32_t flags, minor;
1.15      haad      681: 
1.2       haad      682:        flags = 0;
                    683:        name = NULL;
                    684:        uuid = NULL;
                    685:        last_table = NULL;
                    686: 
1.20      haad      687:        /*
                    688:         * char *xml; xml = prop_dictionary_externalize(dm_dict);
                    689:         * printf("%s\n",xml);
                    690:         */
                    691: 
1.2       haad      692:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    693:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    694:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    695:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
1.20      haad      696: 
1.2       haad      697:        cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
                    698:        iter = prop_array_iterator(cmd_array);
1.20      haad      699:        dm_dbg_print_flags(flags);
                    700: 
                    701:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      702:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
1.28      mlelstv   703:                prop_object_iterator_release(iter);
1.2       haad      704:                return ENOENT;
                    705:        }
1.7       haad      706:        aprint_debug("Loading table to device: %s--%d\n", name,
                    707:            dmv->table_head.cur_active_table);
1.20      haad      708: 
1.2       haad      709:        /*
                    710:         * I have to check if this table slot is not used by another table list.
                    711:         * if it is used I should free them.
                    712:         */
                    713:        if (dmv->flags & DM_INACTIVE_PRESENT_FLAG)
                    714:                dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
                    715: 
                    716:        dm_dbg_print_flags(dmv->flags);
                    717:        tbl = dm_table_get_entry(&dmv->table_head, DM_TABLE_INACTIVE);
1.20      haad      718: 
1.2       haad      719:        aprint_debug("dmv->name = %s\n", dmv->name);
1.20      haad      720: 
1.2       haad      721:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
                    722: 
1.20      haad      723:        while ((target_dict = prop_object_iterator_next(iter)) != NULL) {
1.46      tkusumi   724:                int ret;
                    725:                char *str = NULL;
                    726: 
1.2       haad      727:                prop_dictionary_get_cstring_nocopy(target_dict,
                    728:                    DM_TABLE_TYPE, &type);
                    729:                /*
                    730:                 * If we want to deny table with 2 or more different
                    731:                 * target we should do it here
                    732:                 */
1.7       haad      733:                if (((target = dm_target_lookup(type)) == NULL) &&
                    734:                    ((target = dm_target_autoload(type)) == NULL)) {
1.8       haad      735:                        dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
1.7       haad      736:                        dm_dev_unbusy(dmv);
1.28      mlelstv   737:                        prop_object_iterator_release(iter);
1.2       haad      738:                        return ENOENT;
1.7       haad      739:                }
1.31      chs       740:                table_en = kmem_alloc(sizeof(dm_table_entry_t), KM_SLEEP);
1.2       haad      741:                prop_dictionary_get_uint64(target_dict, DM_TABLE_START,
                    742:                    &table_en->start);
                    743:                prop_dictionary_get_uint64(target_dict, DM_TABLE_LENGTH,
                    744:                    &table_en->length);
                    745: 
                    746:                table_en->target = target;
                    747:                table_en->dm_dev = dmv;
                    748:                table_en->target_config = NULL;
1.20      haad      749: 
1.2       haad      750:                /*
                    751:                 * There is a parameter string after dm_target_spec
                    752:                 * structure which  points to /dev/wd0a 284 part of
                    753:                 * table. String str points to this text. This can be
                    754:                 * null and therefore it should be checked before we try to
                    755:                 * use it.
                    756:                 */
1.15      haad      757:                prop_dictionary_get_cstring(target_dict,
1.20      haad      758:                    DM_TABLE_PARAMS, (char **) &str);
                    759: 
1.30      christos  760:                if (SLIST_EMPTY(tbl) || last_table == NULL)
1.2       haad      761:                        /* insert this table to head */
                    762:                        SLIST_INSERT_HEAD(tbl, table_en, next);
                    763:                else
                    764:                        SLIST_INSERT_AFTER(last_table, table_en, next);
1.20      haad      765: 
1.41      tkusumi   766:                if ((ret = dm_table_init(target, table_en, str)) != 0) {
1.4       haad      767:                        dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
1.2       haad      768:                        dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
1.15      haad      769:                        free(str, M_TEMP);
                    770: 
1.4       haad      771:                        dm_dev_unbusy(dmv);
1.28      mlelstv   772:                        prop_object_iterator_release(iter);
1.2       haad      773:                        return ret;
                    774:                }
                    775:                last_table = table_en;
1.15      haad      776:                free(str, M_TEMP);
1.2       haad      777:        }
                    778:        prop_object_iterator_release(iter);
1.20      haad      779: 
1.2       haad      780:        DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
                    781:        atomic_or_32(&dmv->flags, DM_INACTIVE_PRESENT_FLAG);
1.20      haad      782: 
1.2       haad      783:        dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
                    784:        dm_dev_unbusy(dmv);
                    785:        return 0;
                    786: }
1.32      christos  787: 
1.41      tkusumi   788: static int
                    789: dm_table_init(dm_target_t *target, dm_table_entry_t *table_en, char *params)
                    790: {
                    791:        int i, n, ret, argc;
                    792:        char **ap, **argv;
                    793: 
                    794:        if (params == NULL)
                    795:                return EINVAL;
                    796: 
                    797:        n = target->max_argc;
                    798:        if (n)
                    799:                aprint_debug("Max argc %d for %s target\n", n, target->name);
                    800:        else
                    801:                n = 32; /* large enough for most targets */
                    802: 
                    803:        argv = kmem_alloc(sizeof(*argv) * n, KM_SLEEP);
                    804: 
                    805:        for (ap = argv;
                    806:             ap < &argv[n] && (*ap = strsep(&params, " \t")) != NULL;) {
                    807:                if (**ap != '\0')
                    808:                        ap++;
                    809:        }
                    810:        argc = ap - argv;
                    811: 
                    812:        for (i = 0; i < argc; i++)
                    813:                aprint_debug("DM: argv[%d] = \"%s\"\n", i, argv[i]);
                    814: 
                    815:        KASSERT(target->init);
                    816:        ret = target->init(table_en, argc, argv);
                    817: 
                    818:        kmem_free(argv, sizeof(*argv) * n);
                    819: 
                    820:        return ret;
                    821: }
                    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: int
                    847: dm_table_status_ioctl(prop_dictionary_t dm_dict)
                    848: {
                    849:        dm_dev_t *dmv;
                    850:        dm_table_t *tbl;
                    851:        dm_table_entry_t *table_en;
                    852: 
                    853:        prop_array_t cmd_array;
                    854:        prop_dictionary_t target_dict;
1.20      haad      855: 
1.29      justin    856:        uint32_t minor, flags;
1.2       haad      857:        const char *name, *uuid;
1.17      haad      858:        int table_type;
1.20      haad      859: 
1.2       haad      860:        uuid = NULL;
                    861:        name = NULL;
                    862:        flags = 0;
                    863: 
                    864:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
                    865:        prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
                    866:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
                    867:        prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);
                    868: 
                    869:        cmd_array = prop_array_create();
1.20      haad      870: 
                    871:        if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
1.2       haad      872:                DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
                    873:                return ENOENT;
                    874:        }
1.20      haad      875:        /*
                    876:         * if DM_QUERY_INACTIVE_TABLE_FLAG is passed we need to query
                    877:         * INACTIVE TABLE
                    878:         */
1.17      haad      879:        if (flags & DM_QUERY_INACTIVE_TABLE_FLAG)
                    880:                table_type = DM_TABLE_INACTIVE;
                    881:        else
                    882:                table_type = DM_TABLE_ACTIVE;
1.20      haad      883: 
1.37      tkusumi   884:        if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_ACTIVE)) {
1.2       haad      885:                DM_ADD_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
1.37      tkusumi   886:        } else {
1.2       haad      887:                DM_REMOVE_FLAG(flags, DM_ACTIVE_PRESENT_FLAG);
1.20      haad      888: 
1.2       haad      889:                if (dm_table_get_target_count(&dmv->table_head, DM_TABLE_INACTIVE))
                    890:                        DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
1.37      tkusumi   891:                else
1.2       haad      892:                        DM_REMOVE_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
                    893:        }
1.20      haad      894: 
1.2       haad      895:        if (dmv->flags & DM_SUSPEND_FLAG)
                    896:                DM_ADD_FLAG(flags, DM_SUSPEND_FLAG);
1.20      haad      897: 
1.2       haad      898:        prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);
1.20      haad      899: 
1.2       haad      900:        aprint_debug("Status of device tables: %s--%d\n",
                    901:            name, dmv->table_head.cur_active_table);
1.20      haad      902: 
1.17      haad      903:        tbl = dm_table_get_entry(&dmv->table_head, table_type);
1.20      haad      904: 
                    905:        SLIST_FOREACH(table_en, tbl, next) {
1.46      tkusumi   906:                char *params;
                    907: 
1.2       haad      908:                target_dict = prop_dictionary_create();
                    909:                aprint_debug("%016" PRIu64 ", length %016" PRIu64
                    910:                    ", target %s\n", table_en->start, table_en->length,
                    911:                    table_en->target->name);
                    912: 
                    913:                prop_dictionary_set_uint64(target_dict, DM_TABLE_START,
                    914:                    table_en->start);
                    915:                prop_dictionary_set_uint64(target_dict, DM_TABLE_LENGTH,
                    916:                    table_en->length);
                    917: 
                    918:                prop_dictionary_set_cstring(target_dict, DM_TABLE_TYPE,
                    919:                    table_en->target->name);
                    920: 
                    921:                /* dm_table_get_cur_actv.table ?? */
                    922:                prop_dictionary_set_int32(target_dict, DM_TABLE_STAT,
                    923:                    dmv->table_head.cur_active_table);
                    924: 
1.34      tkusumi   925:                /*
                    926:                 * Explicitly clear DM_TABLE_PARAMS to prevent dmsetup(8) from
                    927:                 * printing junk when DM_TABLE_PARAMS was never initialized.
                    928:                 */
                    929:                prop_dictionary_set_cstring(target_dict, DM_TABLE_PARAMS, "");
                    930: 
1.44      tkusumi   931:                if (flags & DM_STATUS_TABLE_FLAG)
1.45      tkusumi   932:                        params = table_en->target->table(
1.44      tkusumi   933:                            table_en->target_config);
                    934:                else if (table_en->target->info)
                    935:                        params = table_en->target->info(
                    936:                            table_en->target_config);
                    937:                else
                    938:                        params = NULL;
1.20      haad      939: 
1.44      tkusumi   940:                if (params != NULL) {
                    941:                        prop_dictionary_set_cstring(target_dict,
                    942:                            DM_TABLE_PARAMS, params);
                    943:                        kmem_free(params, DM_MAX_PARAMS_SIZE);
1.2       haad      944:                }
1.44      tkusumi   945: 
1.2       haad      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: {
1.47    ! tkusumi   969:        int 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>