dm.c (91de76e661a266731fc2889a398ad1694df9d523) dm.c (b0b4d7c6752a45c545bcdce647ccfa8fb27f0a06)
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"

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

19#include <linux/dax.h>
20#include <linux/slab.h>
21#include <linux/idr.h>
22#include <linux/uio.h>
23#include <linux/hdreg.h>
24#include <linux/delay.h>
25#include <linux/wait.h>
26#include <linux/pr.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"

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

19#include <linux/dax.h>
20#include <linux/slab.h>
21#include <linux/idr.h>
22#include <linux/uio.h>
23#include <linux/hdreg.h>
24#include <linux/delay.h>
25#include <linux/wait.h>
26#include <linux/pr.h>
27#include <linux/refcount.h>
27
28#define DM_MSG_PREFIX "core"
29
30/*
31 * Cookies are numeric values sent with CHANGE and REMOVE
32 * uevents while resuming, removing or renaming the device.
33 */
34#define DM_COOKIE_ENV_VAR_NAME "DM_COOKIE"

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

93 */
94struct dm_md_mempools {
95 mempool_t *io_pool;
96 struct bio_set *bs;
97};
98
99struct table_device {
100 struct list_head list;
28
29#define DM_MSG_PREFIX "core"
30
31/*
32 * Cookies are numeric values sent with CHANGE and REMOVE
33 * uevents while resuming, removing or renaming the device.
34 */
35#define DM_COOKIE_ENV_VAR_NAME "DM_COOKIE"

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

94 */
95struct dm_md_mempools {
96 mempool_t *io_pool;
97 struct bio_set *bs;
98};
99
100struct table_device {
101 struct list_head list;
101 atomic_t count;
102 refcount_t count;
102 struct dm_dev dm_dev;
103};
104
105static struct kmem_cache *_io_cache;
106static struct kmem_cache *_rq_tio_cache;
107static struct kmem_cache *_rq_cache;
108
109/*

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

680 if ((r = open_table_device(td, dev, md))) {
681 mutex_unlock(&md->table_devices_lock);
682 kfree(td);
683 return r;
684 }
685
686 format_dev_t(td->dm_dev.name, dev);
687
103 struct dm_dev dm_dev;
104};
105
106static struct kmem_cache *_io_cache;
107static struct kmem_cache *_rq_tio_cache;
108static struct kmem_cache *_rq_cache;
109
110/*

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

681 if ((r = open_table_device(td, dev, md))) {
682 mutex_unlock(&md->table_devices_lock);
683 kfree(td);
684 return r;
685 }
686
687 format_dev_t(td->dm_dev.name, dev);
688
688 atomic_set(&td->count, 0);
689 refcount_set(&td->count, 1);
689 list_add(&td->list, &md->table_devices);
690 list_add(&td->list, &md->table_devices);
691 } else {
692 refcount_inc(&td->count);
690 }
693 }
691 atomic_inc(&td->count);
692 mutex_unlock(&md->table_devices_lock);
693
694 *result = &td->dm_dev;
695 return 0;
696}
697EXPORT_SYMBOL_GPL(dm_get_table_device);
698
699void dm_put_table_device(struct mapped_device *md, struct dm_dev *d)
700{
701 struct table_device *td = container_of(d, struct table_device, dm_dev);
702
703 mutex_lock(&md->table_devices_lock);
694 mutex_unlock(&md->table_devices_lock);
695
696 *result = &td->dm_dev;
697 return 0;
698}
699EXPORT_SYMBOL_GPL(dm_get_table_device);
700
701void dm_put_table_device(struct mapped_device *md, struct dm_dev *d)
702{
703 struct table_device *td = container_of(d, struct table_device, dm_dev);
704
705 mutex_lock(&md->table_devices_lock);
704 if (atomic_dec_and_test(&td->count)) {
706 if (refcount_dec_and_test(&td->count)) {
705 close_table_device(td, md);
706 list_del(&td->list);
707 kfree(td);
708 }
709 mutex_unlock(&md->table_devices_lock);
710}
711EXPORT_SYMBOL(dm_put_table_device);
712
713static void free_table_devices(struct list_head *devices)
714{
715 struct list_head *tmp, *next;
716
717 list_for_each_safe(tmp, next, devices) {
718 struct table_device *td = list_entry(tmp, struct table_device, list);
719
720 DMWARN("dm_destroy: %s still exists with %d references",
707 close_table_device(td, md);
708 list_del(&td->list);
709 kfree(td);
710 }
711 mutex_unlock(&md->table_devices_lock);
712}
713EXPORT_SYMBOL(dm_put_table_device);
714
715static void free_table_devices(struct list_head *devices)
716{
717 struct list_head *tmp, *next;
718
719 list_for_each_safe(tmp, next, devices) {
720 struct table_device *td = list_entry(tmp, struct table_device, list);
721
722 DMWARN("dm_destroy: %s still exists with %d references",
721 td->dm_dev.name, atomic_read(&td->count));
723 td->dm_dev.name, refcount_read(&td->count));
722 kfree(td);
723 }
724}
725
726/*
727 * Get the geometry associated with a dm device
728 */
729int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo)

--- 2273 unchanged lines hidden ---
724 kfree(td);
725 }
726}
727
728/*
729 * Get the geometry associated with a dm device
730 */
731int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo)

--- 2273 unchanged lines hidden ---