dm.c (f1615bbe9be4def59c3b3eaddb60722efeed16c2) dm.c (acfe0ad74d2e1bfc81d1d7bf5e15b043985d3650)
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"

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

49static DEFINE_IDR(_minor_idr);
50
51static DEFINE_SPINLOCK(_minor_lock);
52
53static void do_deferred_remove(struct work_struct *w);
54
55static DECLARE_WORK(deferred_remove_work, do_deferred_remove);
56
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"

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

49static DEFINE_IDR(_minor_idr);
50
51static DEFINE_SPINLOCK(_minor_lock);
52
53static void do_deferred_remove(struct work_struct *w);
54
55static DECLARE_WORK(deferred_remove_work, do_deferred_remove);
56
57static struct workqueue_struct *deferred_remove_workqueue;
58
57/*
58 * For bio-based dm.
59 * One of these is allocated per bio.
60 */
61struct dm_io {
62 struct mapped_device *md;
63 int error;
64 atomic_t io_count;

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

271 _rq_tio_cache = KMEM_CACHE(dm_rq_target_io, 0);
272 if (!_rq_tio_cache)
273 goto out_free_io_cache;
274
275 r = dm_uevent_init();
276 if (r)
277 goto out_free_rq_tio_cache;
278
59/*
60 * For bio-based dm.
61 * One of these is allocated per bio.
62 */
63struct dm_io {
64 struct mapped_device *md;
65 int error;
66 atomic_t io_count;

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

273 _rq_tio_cache = KMEM_CACHE(dm_rq_target_io, 0);
274 if (!_rq_tio_cache)
275 goto out_free_io_cache;
276
277 r = dm_uevent_init();
278 if (r)
279 goto out_free_rq_tio_cache;
280
281 deferred_remove_workqueue = alloc_workqueue("kdmremove", WQ_UNBOUND, 1);
282 if (!deferred_remove_workqueue) {
283 r = -ENOMEM;
284 goto out_uevent_exit;
285 }
286
279 _major = major;
280 r = register_blkdev(_major, _name);
281 if (r < 0)
287 _major = major;
288 r = register_blkdev(_major, _name);
289 if (r < 0)
282 goto out_uevent_exit;
290 goto out_free_workqueue;
283
284 if (!_major)
285 _major = r;
286
287 return 0;
288
291
292 if (!_major)
293 _major = r;
294
295 return 0;
296
297out_free_workqueue:
298 destroy_workqueue(deferred_remove_workqueue);
289out_uevent_exit:
290 dm_uevent_exit();
291out_free_rq_tio_cache:
292 kmem_cache_destroy(_rq_tio_cache);
293out_free_io_cache:
294 kmem_cache_destroy(_io_cache);
295
296 return r;
297}
298
299static void local_exit(void)
300{
301 flush_scheduled_work();
299out_uevent_exit:
300 dm_uevent_exit();
301out_free_rq_tio_cache:
302 kmem_cache_destroy(_rq_tio_cache);
303out_free_io_cache:
304 kmem_cache_destroy(_io_cache);
305
306 return r;
307}
308
309static void local_exit(void)
310{
311 flush_scheduled_work();
312 destroy_workqueue(deferred_remove_workqueue);
302
303 kmem_cache_destroy(_rq_tio_cache);
304 kmem_cache_destroy(_io_cache);
305 unregister_blkdev(_major, _name);
306 dm_uevent_exit();
307
308 _major = 0;
309

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

402static void dm_blk_close(struct gendisk *disk, fmode_t mode)
403{
404 struct mapped_device *md = disk->private_data;
405
406 spin_lock(&_minor_lock);
407
408 if (atomic_dec_and_test(&md->open_count) &&
409 (test_bit(DMF_DEFERRED_REMOVE, &md->flags)))
313
314 kmem_cache_destroy(_rq_tio_cache);
315 kmem_cache_destroy(_io_cache);
316 unregister_blkdev(_major, _name);
317 dm_uevent_exit();
318
319 _major = 0;
320

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

413static void dm_blk_close(struct gendisk *disk, fmode_t mode)
414{
415 struct mapped_device *md = disk->private_data;
416
417 spin_lock(&_minor_lock);
418
419 if (atomic_dec_and_test(&md->open_count) &&
420 (test_bit(DMF_DEFERRED_REMOVE, &md->flags)))
410 schedule_work(&deferred_remove_work);
421 queue_work(deferred_remove_workqueue, &deferred_remove_work);
411
412 dm_put(md);
413
414 spin_unlock(&_minor_lock);
415}
416
417int dm_open_count(struct mapped_device *md)
418{

--- 2528 unchanged lines hidden ---
422
423 dm_put(md);
424
425 spin_unlock(&_minor_lock);
426}
427
428int dm_open_count(struct mapped_device *md)
429{

--- 2528 unchanged lines hidden ---