dm.c (abdc568b0540bec6d3e0afebac496adef1189b77) | dm.c (3f77316de0ec0fd208467fbee8d9edc70e2c73b2) |
---|---|
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.h" --- 6 unchanged lines hidden (view full) --- 15#include <linux/blkpg.h> 16#include <linux/bio.h> 17#include <linux/buffer_head.h> 18#include <linux/smp_lock.h> 19#include <linux/mempool.h> 20#include <linux/slab.h> 21#include <linux/idr.h> 22#include <linux/hdreg.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.h" --- 6 unchanged lines hidden (view full) --- 15#include <linux/blkpg.h> 16#include <linux/bio.h> 17#include <linux/buffer_head.h> 18#include <linux/smp_lock.h> 19#include <linux/mempool.h> 20#include <linux/slab.h> 21#include <linux/idr.h> 22#include <linux/hdreg.h> |
23#include <linux/delay.h> |
|
23 24#include <trace/events/block.h> 25 26#define DM_MSG_PREFIX "core" 27 28/* 29 * Cookies are numeric values sent with CHANGE and REMOVE 30 * uevents while resuming, removing or renaming the device. --- 2135 unchanged lines hidden (view full) --- 2166void dm_set_mdptr(struct mapped_device *md, void *ptr) 2167{ 2168 md->interface_ptr = ptr; 2169} 2170 2171void dm_get(struct mapped_device *md) 2172{ 2173 atomic_inc(&md->holders); | 24 25#include <trace/events/block.h> 26 27#define DM_MSG_PREFIX "core" 28 29/* 30 * Cookies are numeric values sent with CHANGE and REMOVE 31 * uevents while resuming, removing or renaming the device. --- 2135 unchanged lines hidden (view full) --- 2167void dm_set_mdptr(struct mapped_device *md, void *ptr) 2168{ 2169 md->interface_ptr = ptr; 2170} 2171 2172void dm_get(struct mapped_device *md) 2173{ 2174 atomic_inc(&md->holders); |
2175 BUG_ON(test_bit(DMF_FREEING, &md->flags)); |
|
2174} 2175 2176const char *dm_device_name(struct mapped_device *md) 2177{ 2178 return md->name; 2179} 2180EXPORT_SYMBOL_GPL(dm_device_name); 2181 | 2176} 2177 2178const char *dm_device_name(struct mapped_device *md) 2179{ 2180 return md->name; 2181} 2182EXPORT_SYMBOL_GPL(dm_device_name); 2183 |
2182void dm_put(struct mapped_device *md) | 2184static void __dm_destroy(struct mapped_device *md, bool wait) |
2183{ 2184 struct dm_table *map; 2185 | 2185{ 2186 struct dm_table *map; 2187 |
2186 BUG_ON(test_bit(DMF_FREEING, &md->flags)); | 2188 might_sleep(); |
2187 | 2189 |
2188 if (atomic_dec_and_lock(&md->holders, &_minor_lock)) { 2189 map = dm_get_live_table(md); 2190 idr_replace(&_minor_idr, MINOR_ALLOCED, 2191 MINOR(disk_devt(dm_disk(md)))); 2192 set_bit(DMF_FREEING, &md->flags); 2193 spin_unlock(&_minor_lock); 2194 if (!dm_suspended_md(md)) { 2195 dm_table_presuspend_targets(map); 2196 dm_table_postsuspend_targets(map); 2197 } 2198 dm_sysfs_exit(md); 2199 dm_table_put(map); 2200 dm_table_destroy(__unbind(md)); 2201 free_dev(md); | 2190 spin_lock(&_minor_lock); 2191 map = dm_get_live_table(md); 2192 idr_replace(&_minor_idr, MINOR_ALLOCED, MINOR(disk_devt(dm_disk(md)))); 2193 set_bit(DMF_FREEING, &md->flags); 2194 spin_unlock(&_minor_lock); 2195 2196 if (!dm_suspended_md(md)) { 2197 dm_table_presuspend_targets(map); 2198 dm_table_postsuspend_targets(map); |
2202 } | 2199 } |
2200 2201 /* 2202 * Rare, but there may be I/O requests still going to complete, 2203 * for example. Wait for all references to disappear. 2204 * No one should increment the reference count of the mapped_device, 2205 * after the mapped_device state becomes DMF_FREEING. 2206 */ 2207 if (wait) 2208 while (atomic_read(&md->holders)) 2209 msleep(1); 2210 else if (atomic_read(&md->holders)) 2211 DMWARN("%s: Forcibly removing mapped_device still in use! (%d users)", 2212 dm_device_name(md), atomic_read(&md->holders)); 2213 2214 dm_sysfs_exit(md); 2215 dm_table_put(map); 2216 dm_table_destroy(__unbind(md)); 2217 free_dev(md); |
|
2203} | 2218} |
2219 2220void dm_destroy(struct mapped_device *md) 2221{ 2222 __dm_destroy(md, true); 2223} 2224 2225void dm_destroy_immediate(struct mapped_device *md) 2226{ 2227 __dm_destroy(md, false); 2228} 2229 2230void dm_put(struct mapped_device *md) 2231{ 2232 atomic_dec(&md->holders); 2233} |
|
2204EXPORT_SYMBOL_GPL(dm_put); 2205 2206static int dm_wait_for_completion(struct mapped_device *md, int interruptible) 2207{ 2208 int r = 0; 2209 DECLARE_WAITQUEUE(wait, current); 2210 2211 dm_unplug_all(md->queue); --- 573 unchanged lines hidden --- | 2234EXPORT_SYMBOL_GPL(dm_put); 2235 2236static int dm_wait_for_completion(struct mapped_device *md, int interruptible) 2237{ 2238 int r = 0; 2239 DECLARE_WAITQUEUE(wait, current); 2240 2241 dm_unplug_all(md->queue); --- 573 unchanged lines hidden --- |