dm.c (c87866ede44ad7da6b296d732221dc34ce1b154d) dm.c (f1cd6cb24b6b3cd95227e8016d092310a4015e96)
1/*
2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
4 *
5 * This file is released under the GPL.
6 */
7
8#include "dm-core.h"
9#include "dm-rq.h"
10#include "dm-uevent.h"
1/*
2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
4 *
5 * This file is released under the GPL.
6 */
7
8#include "dm-core.h"
9#include "dm-rq.h"
10#include "dm-uevent.h"
11#include "dm-ima.h"
11
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/mutex.h>
15#include <linux/sched/mm.h>
16#include <linux/sched/signal.h>
17#include <linux/blkpg.h>
18#include <linux/bio.h>

--- 237 unchanged lines hidden (view full) ---

256 dm_kcopyd_exit,
257 dm_interface_exit,
258 dm_statistics_exit,
259};
260
261static int __init dm_init(void)
262{
263 const int count = ARRAY_SIZE(_inits);
12
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/mutex.h>
16#include <linux/sched/mm.h>
17#include <linux/sched/signal.h>
18#include <linux/blkpg.h>
19#include <linux/bio.h>

--- 237 unchanged lines hidden (view full) ---

257 dm_kcopyd_exit,
258 dm_interface_exit,
259 dm_statistics_exit,
260};
261
262static int __init dm_init(void)
263{
264 const int count = ARRAY_SIZE(_inits);
264
265 int r, i;
266
265 int r, i;
266
267#if (IS_ENABLED(CONFIG_IMA) && !IS_ENABLED(CONFIG_IMA_DISABLE_HTABLE))
268 DMWARN("CONFIG_IMA_DISABLE_HTABLE is disabled."
269 " Duplicate IMA measurements will not be recorded in the IMA log.");
270#endif
271
267 for (i = 0; i < count; i++) {
268 r = _inits[i]();
269 if (r)
270 goto bad;
271 }
272
273 return 0;
272 for (i = 0; i < count; i++) {
273 r = _inits[i]();
274 if (r)
275 goto bad;
276 }
277
278 return 0;
274
275 bad:
279bad:
276 while (i--)
277 _exits[i]();
278
279 return r;
280}
281
282static void __exit dm_exit(void)
283{

--- 1404 unchanged lines hidden (view full) ---

1688 put_dax(md->dax_dev);
1689 md->dax_dev = NULL;
1690 }
1691
1692 if (md->disk) {
1693 spin_lock(&_minor_lock);
1694 md->disk->private_data = NULL;
1695 spin_unlock(&_minor_lock);
280 while (i--)
281 _exits[i]();
282
283 return r;
284}
285
286static void __exit dm_exit(void)
287{

--- 1404 unchanged lines hidden (view full) ---

1692 put_dax(md->dax_dev);
1693 md->dax_dev = NULL;
1694 }
1695
1696 if (md->disk) {
1697 spin_lock(&_minor_lock);
1698 md->disk->private_data = NULL;
1699 spin_unlock(&_minor_lock);
1696 del_gendisk(md->disk);
1697 }
1698
1699 if (md->queue)
1700 if (dm_get_md_type(md) != DM_TYPE_NONE) {
1701 dm_sysfs_exit(md);
1702 del_gendisk(md->disk);
1703 }
1700 dm_queue_destroy_keyslot_manager(md->queue);
1704 dm_queue_destroy_keyslot_manager(md->queue);
1701
1702 if (md->disk)
1703 blk_cleanup_disk(md->disk);
1705 blk_cleanup_disk(md->disk);
1706 }
1704
1705 cleanup_srcu_struct(&md->io_barrier);
1706
1707 mutex_destroy(&md->suspend_lock);
1708 mutex_destroy(&md->type_lock);
1709 mutex_destroy(&md->table_devices_lock);
1710 mutex_destroy(&md->swap_bios_lock);
1711

--- 75 unchanged lines hidden (view full) ---

1787
1788 if (IS_ENABLED(CONFIG_DAX_DRIVER)) {
1789 md->dax_dev = alloc_dax(md, md->disk->disk_name,
1790 &dm_dax_ops, 0);
1791 if (IS_ERR(md->dax_dev))
1792 goto bad;
1793 }
1794
1707
1708 cleanup_srcu_struct(&md->io_barrier);
1709
1710 mutex_destroy(&md->suspend_lock);
1711 mutex_destroy(&md->type_lock);
1712 mutex_destroy(&md->table_devices_lock);
1713 mutex_destroy(&md->swap_bios_lock);
1714

--- 75 unchanged lines hidden (view full) ---

1790
1791 if (IS_ENABLED(CONFIG_DAX_DRIVER)) {
1792 md->dax_dev = alloc_dax(md, md->disk->disk_name,
1793 &dm_dax_ops, 0);
1794 if (IS_ERR(md->dax_dev))
1795 goto bad;
1796 }
1797
1795 add_disk_no_queue_reg(md->disk);
1796 format_dev_t(md->name, MKDEV(_major, minor));
1797
1798 md->wq = alloc_workqueue("kdmflush", WQ_MEM_RECLAIM, 0);
1799 if (!md->wq)
1800 goto bad;
1801
1802 dm_stats_init(&md->stats);
1803

--- 184 unchanged lines hidden (view full) ---

1988 return map;
1989}
1990
1991/*
1992 * Constructor for a new device.
1993 */
1994int dm_create(int minor, struct mapped_device **result)
1995{
1798 format_dev_t(md->name, MKDEV(_major, minor));
1799
1800 md->wq = alloc_workqueue("kdmflush", WQ_MEM_RECLAIM, 0);
1801 if (!md->wq)
1802 goto bad;
1803
1804 dm_stats_init(&md->stats);
1805

--- 184 unchanged lines hidden (view full) ---

1990 return map;
1991}
1992
1993/*
1994 * Constructor for a new device.
1995 */
1996int dm_create(int minor, struct mapped_device **result)
1997{
1996 int r;
1997 struct mapped_device *md;
1998
1999 md = alloc_dev(minor);
2000 if (!md)
2001 return -ENXIO;
2002
1998 struct mapped_device *md;
1999
2000 md = alloc_dev(minor);
2001 if (!md)
2002 return -ENXIO;
2003
2003 r = dm_sysfs_init(md);
2004 if (r) {
2005 free_dev(md);
2006 return r;
2007 }
2004 dm_ima_reset_data(md);
2008
2009 *result = md;
2010 return 0;
2011}
2012
2013/*
2014 * Functions to manage md->type.
2015 * All are required to hold md->type_lock.

--- 35 unchanged lines hidden (view full) ---

2051}
2052EXPORT_SYMBOL_GPL(dm_get_queue_limits);
2053
2054/*
2055 * Setup the DM device's queue based on md's type
2056 */
2057int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)
2058{
2005
2006 *result = md;
2007 return 0;
2008}
2009
2010/*
2011 * Functions to manage md->type.
2012 * All are required to hold md->type_lock.

--- 35 unchanged lines hidden (view full) ---

2048}
2049EXPORT_SYMBOL_GPL(dm_get_queue_limits);
2050
2051/*
2052 * Setup the DM device's queue based on md's type
2053 */
2054int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)
2055{
2059 int r;
2056 enum dm_queue_mode type = dm_table_get_type(t);
2060 struct queue_limits limits;
2057 struct queue_limits limits;
2061 enum dm_queue_mode type = dm_get_md_type(md);
2058 int r;
2062
2063 switch (type) {
2064 case DM_TYPE_REQUEST_BASED:
2065 md->disk->fops = &dm_rq_blk_dops;
2066 r = dm_mq_init_request_queue(md, t);
2067 if (r) {
2068 DMERR("Cannot initialize queue for request-based dm mapped device");
2069 return r;

--- 11 unchanged lines hidden (view full) ---

2081 if (r) {
2082 DMERR("Cannot calculate initial queue limits");
2083 return r;
2084 }
2085 r = dm_table_set_restrictions(t, md->queue, &limits);
2086 if (r)
2087 return r;
2088
2059
2060 switch (type) {
2061 case DM_TYPE_REQUEST_BASED:
2062 md->disk->fops = &dm_rq_blk_dops;
2063 r = dm_mq_init_request_queue(md, t);
2064 if (r) {
2065 DMERR("Cannot initialize queue for request-based dm mapped device");
2066 return r;

--- 11 unchanged lines hidden (view full) ---

2078 if (r) {
2079 DMERR("Cannot calculate initial queue limits");
2080 return r;
2081 }
2082 r = dm_table_set_restrictions(t, md->queue, &limits);
2083 if (r)
2084 return r;
2085
2089 blk_register_queue(md->disk);
2086 add_disk(md->disk);
2090
2087
2088 r = dm_sysfs_init(md);
2089 if (r) {
2090 del_gendisk(md->disk);
2091 return r;
2092 }
2093 md->type = type;
2091 return 0;
2092}
2093
2094struct mapped_device *dm_get_md(dev_t dev)
2095{
2096 struct mapped_device *md;
2097 unsigned minor = MINOR(dev);
2098

--- 89 unchanged lines hidden (view full) ---

2188 */
2189 if (wait)
2190 while (atomic_read(&md->holders))
2191 msleep(1);
2192 else if (atomic_read(&md->holders))
2193 DMWARN("%s: Forcibly removing mapped_device still in use! (%d users)",
2194 dm_device_name(md), atomic_read(&md->holders));
2195
2094 return 0;
2095}
2096
2097struct mapped_device *dm_get_md(dev_t dev)
2098{
2099 struct mapped_device *md;
2100 unsigned minor = MINOR(dev);
2101

--- 89 unchanged lines hidden (view full) ---

2191 */
2192 if (wait)
2193 while (atomic_read(&md->holders))
2194 msleep(1);
2195 else if (atomic_read(&md->holders))
2196 DMWARN("%s: Forcibly removing mapped_device still in use! (%d users)",
2197 dm_device_name(md), atomic_read(&md->holders));
2198
2196 dm_sysfs_exit(md);
2197 dm_table_destroy(__unbind(md));
2198 free_dev(md);
2199}
2200
2201void dm_destroy(struct mapped_device *md)
2202{
2203 __dm_destroy(md, true);
2204}

--- 876 unchanged lines hidden ---
2199 dm_table_destroy(__unbind(md));
2200 free_dev(md);
2201}
2202
2203void dm_destroy(struct mapped_device *md)
2204{
2205 __dm_destroy(md, true);
2206}

--- 876 unchanged lines hidden ---