Skip to content

Commit e2118b3

Browse files
damien-lemoalsnitm
authored andcommitted
dm: rearrange core declarations for extended use from dm-zone.c
Move the definitions of struct dm_target_io, struct dm_io and the bits of the flags field of struct mapped_device from dm.c to dm-core.h to make them usable from dm-zone.c. For the same reason, declare dec_pending() in dm-core.h after renaming it to dm_io_dec_pending(). And for symmetry of the function names, introduce the inline helper dm_io_inc_pending() instead of directly using atomic_inc() calls. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent 9ffbbb4 commit e2118b3

File tree

2 files changed

+59
-52
lines changed

2 files changed

+59
-52
lines changed

drivers/md/dm-core.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ struct mapped_device {
116116
struct srcu_struct io_barrier;
117117
};
118118

119+
/*
120+
* Bits for the flags field of struct mapped_device.
121+
*/
122+
#define DMF_BLOCK_IO_FOR_SUSPEND 0
123+
#define DMF_SUSPENDED 1
124+
#define DMF_FROZEN 2
125+
#define DMF_FREEING 3
126+
#define DMF_DELETING 4
127+
#define DMF_NOFLUSH_SUSPENDING 5
128+
#define DMF_DEFERRED_REMOVE 6
129+
#define DMF_SUSPENDED_INTERNALLY 7
130+
#define DMF_POST_SUSPENDING 8
131+
119132
void disable_discard(struct mapped_device *md);
120133
void disable_write_same(struct mapped_device *md);
121134
void disable_write_zeroes(struct mapped_device *md);
@@ -173,6 +186,45 @@ struct dm_table {
173186
#endif
174187
};
175188

189+
/*
190+
* One of these is allocated per clone bio.
191+
*/
192+
#define DM_TIO_MAGIC 7282014
193+
struct dm_target_io {
194+
unsigned int magic;
195+
struct dm_io *io;
196+
struct dm_target *ti;
197+
unsigned int target_bio_nr;
198+
unsigned int *len_ptr;
199+
bool inside_dm_io;
200+
struct bio clone;
201+
};
202+
203+
/*
204+
* One of these is allocated per original bio.
205+
* It contains the first clone used for that original.
206+
*/
207+
#define DM_IO_MAGIC 5191977
208+
struct dm_io {
209+
unsigned int magic;
210+
struct mapped_device *md;
211+
blk_status_t status;
212+
atomic_t io_count;
213+
struct bio *orig_bio;
214+
unsigned long start_time;
215+
spinlock_t endio_lock;
216+
struct dm_stats_aux stats_aux;
217+
/* last member of dm_target_io is 'struct bio' */
218+
struct dm_target_io tio;
219+
};
220+
221+
static inline void dm_io_inc_pending(struct dm_io *io)
222+
{
223+
atomic_inc(&io->io_count);
224+
}
225+
226+
void dm_io_dec_pending(struct dm_io *io, blk_status_t error);
227+
176228
static inline struct completion *dm_get_completion_from_kobject(struct kobject *kobj)
177229
{
178230
return &container_of(kobj, struct dm_kobject_holder, kobj)->completion;

drivers/md/dm.c

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -74,38 +74,6 @@ struct clone_info {
7474
unsigned sector_count;
7575
};
7676

77-
/*
78-
* One of these is allocated per clone bio.
79-
*/
80-
#define DM_TIO_MAGIC 7282014
81-
struct dm_target_io {
82-
unsigned magic;
83-
struct dm_io *io;
84-
struct dm_target *ti;
85-
unsigned target_bio_nr;
86-
unsigned *len_ptr;
87-
bool inside_dm_io;
88-
struct bio clone;
89-
};
90-
91-
/*
92-
* One of these is allocated per original bio.
93-
* It contains the first clone used for that original.
94-
*/
95-
#define DM_IO_MAGIC 5191977
96-
struct dm_io {
97-
unsigned magic;
98-
struct mapped_device *md;
99-
blk_status_t status;
100-
atomic_t io_count;
101-
struct bio *orig_bio;
102-
unsigned long start_time;
103-
spinlock_t endio_lock;
104-
struct dm_stats_aux stats_aux;
105-
/* last member of dm_target_io is 'struct bio' */
106-
struct dm_target_io tio;
107-
};
108-
10977
#define DM_TARGET_IO_BIO_OFFSET (offsetof(struct dm_target_io, clone))
11078
#define DM_IO_BIO_OFFSET \
11179
(offsetof(struct dm_target_io, clone) + offsetof(struct dm_io, tio))
@@ -137,19 +105,6 @@ EXPORT_SYMBOL_GPL(dm_bio_get_target_bio_nr);
137105

138106
#define MINOR_ALLOCED ((void *)-1)
139107

140-
/*
141-
* Bits for the md->flags field.
142-
*/
143-
#define DMF_BLOCK_IO_FOR_SUSPEND 0
144-
#define DMF_SUSPENDED 1
145-
#define DMF_FROZEN 2
146-
#define DMF_FREEING 3
147-
#define DMF_DELETING 4
148-
#define DMF_NOFLUSH_SUSPENDING 5
149-
#define DMF_DEFERRED_REMOVE 6
150-
#define DMF_SUSPENDED_INTERNALLY 7
151-
#define DMF_POST_SUSPENDING 8
152-
153108
#define DM_NUMA_NODE NUMA_NO_NODE
154109
static int dm_numa_node = DM_NUMA_NODE;
155110

@@ -825,7 +780,7 @@ static int __noflush_suspending(struct mapped_device *md)
825780
* Decrements the number of outstanding ios that a bio has been
826781
* cloned into, completing the original io if necc.
827782
*/
828-
static void dec_pending(struct dm_io *io, blk_status_t error)
783+
void dm_io_dec_pending(struct dm_io *io, blk_status_t error)
829784
{
830785
unsigned long flags;
831786
blk_status_t io_error;
@@ -979,7 +934,7 @@ static void clone_endio(struct bio *bio)
979934
}
980935

981936
free_tio(tio);
982-
dec_pending(io, error);
937+
dm_io_dec_pending(io, error);
983938
}
984939

985940
/*
@@ -1247,7 +1202,7 @@ static blk_qc_t __map_bio(struct dm_target_io *tio)
12471202
* anything, the target has assumed ownership of
12481203
* this io.
12491204
*/
1250-
atomic_inc(&io->io_count);
1205+
dm_io_inc_pending(io);
12511206
sector = clone->bi_iter.bi_sector;
12521207

12531208
if (unlikely(swap_bios_limit(ti, clone))) {
@@ -1273,15 +1228,15 @@ static blk_qc_t __map_bio(struct dm_target_io *tio)
12731228
up(&md->swap_bios_semaphore);
12741229
}
12751230
free_tio(tio);
1276-
dec_pending(io, BLK_STS_IOERR);
1231+
dm_io_dec_pending(io, BLK_STS_IOERR);
12771232
break;
12781233
case DM_MAPIO_REQUEUE:
12791234
if (unlikely(swap_bios_limit(ti, clone))) {
12801235
struct mapped_device *md = io->md;
12811236
up(&md->swap_bios_semaphore);
12821237
}
12831238
free_tio(tio);
1284-
dec_pending(io, BLK_STS_DM_REQUEUE);
1239+
dm_io_dec_pending(io, BLK_STS_DM_REQUEUE);
12851240
break;
12861241
default:
12871242
DMWARN("unimplemented target map return value: %d", r);
@@ -1570,7 +1525,7 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md,
15701525

15711526
if (bio->bi_opf & REQ_PREFLUSH) {
15721527
error = __send_empty_flush(&ci);
1573-
/* dec_pending submits any data associated with flush */
1528+
/* dm_io_dec_pending submits any data associated with flush */
15741529
} else if (op_is_zone_mgmt(bio_op(bio))) {
15751530
ci.bio = bio;
15761531
ci.sector_count = 0;
@@ -1611,7 +1566,7 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md,
16111566
}
16121567

16131568
/* drop the extra reference count */
1614-
dec_pending(ci.io, errno_to_blk_status(error));
1569+
dm_io_dec_pending(ci.io, errno_to_blk_status(error));
16151570
return ret;
16161571
}
16171572

0 commit comments

Comments
 (0)