Sat Aug 27 17:07:50 2011 UTC ()
- add a function to get the inactive table's size
- some whitespace fix from emacs...


(ahoka)
diff -r1.22 -r1.23 src/sys/dev/dm/dm.h
diff -r1.25 -r1.26 src/sys/dev/dm/dm_ioctl.c

cvs diff -r1.22 -r1.23 src/sys/dev/dm/dm.h (expand / switch to unified diff)

--- src/sys/dev/dm/dm.h 2010/12/23 20:07:13 1.22
+++ src/sys/dev/dm/dm.h 2011/08/27 17:07:49 1.23
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dm.h,v 1.22 2010/12/23 20:07:13 christos Exp $ */ 1/* $NetBSD: dm.h,v 1.23 2011/08/27 17:07:49 ahoka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Hamsik. 8 * by Adam Hamsik.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -78,27 +78,27 @@ typedef struct dm_table_entry { @@ -78,27 +78,27 @@ typedef struct dm_table_entry {
78 uint64_t length; 78 uint64_t length;
79 79
80 struct dm_target *target; /* Link to table target. */ 80 struct dm_target *target; /* Link to table target. */
81 void *target_config; /* Target specific data. */ 81 void *target_config; /* Target specific data. */
82 SLIST_ENTRY(dm_table_entry) next; 82 SLIST_ENTRY(dm_table_entry) next;
83} dm_table_entry_t; 83} dm_table_entry_t;
84 84
85SLIST_HEAD(dm_table, dm_table_entry); 85SLIST_HEAD(dm_table, dm_table_entry);
86 86
87typedef struct dm_table dm_table_t; 87typedef struct dm_table dm_table_t;
88 88
89typedef struct dm_table_head { 89typedef struct dm_table_head {
90 /* Current active table is selected with this. */ 90 /* Current active table is selected with this. */
91 int cur_active_table;  91 int cur_active_table;
92 struct dm_table tables[2]; 92 struct dm_table tables[2];
93 93
94 kmutex_t table_mtx; 94 kmutex_t table_mtx;
95 kcondvar_t table_cv; /*IO waiting cv */ 95 kcondvar_t table_cv; /*IO waiting cv */
96 96
97 uint32_t io_cnt; 97 uint32_t io_cnt;
98} dm_table_head_t; 98} dm_table_head_t;
99 99
100#define MAX_DEV_NAME 32 100#define MAX_DEV_NAME 32
101 101
102/* 102/*
103 * This structure is used to store opened vnodes for disk with name. 103 * This structure is used to store opened vnodes for disk with name.
104 * I need this because devices can be opened only once, but I can 104 * I need this because devices can be opened only once, but I can
@@ -111,74 +111,74 @@ typedef struct dm_pdev { @@ -111,74 +111,74 @@ typedef struct dm_pdev {
111 struct vnode *pdev_vnode; 111 struct vnode *pdev_vnode;
112 uint64_t pdev_numsec; 112 uint64_t pdev_numsec;
113 unsigned pdev_secsize; 113 unsigned pdev_secsize;
114 int ref_cnt; /* reference counter for users ofthis pdev */ 114 int ref_cnt; /* reference counter for users ofthis pdev */
115 115
116 SLIST_ENTRY(dm_pdev) next_pdev; 116 SLIST_ENTRY(dm_pdev) next_pdev;
117} dm_pdev_t; 117} dm_pdev_t;
118 118
119/* 119/*
120 * This structure is called for every device-mapper device. 120 * This structure is called for every device-mapper device.
121 * It points to SLIST of device tables and mirrored, snapshoted etc. devices. 121 * It points to SLIST of device tables and mirrored, snapshoted etc. devices.
122 */ 122 */
123TAILQ_HEAD(dm_dev_head, dm_dev) dm_devs; 123TAILQ_HEAD(dm_dev_head, dm_dev) dm_devs;
124  124
125typedef struct dm_dev { 125typedef struct dm_dev {
126 char name[DM_NAME_LEN]; 126 char name[DM_NAME_LEN];
127 char uuid[DM_UUID_LEN]; 127 char uuid[DM_UUID_LEN];
128 128
129 device_t devt; /* pointer to autoconf device_t structure */ 129 device_t devt; /* pointer to autoconf device_t structure */
130 uint64_t minor; /* Device minor number */ 130 uint64_t minor; /* Device minor number */
131 uint32_t flags; /* store communication protocol flags */ 131 uint32_t flags; /* store communication protocol flags */
132 132
133 kmutex_t dev_mtx; /* mutex for generall device lock */ 133 kmutex_t dev_mtx; /* mutex for generall device lock */
134 kcondvar_t dev_cv; /* cv for between ioctl synchronisation */ 134 kcondvar_t dev_cv; /* cv for between ioctl synchronisation */
135  135
136 uint32_t event_nr; 136 uint32_t event_nr;
137 uint32_t ref_cnt; 137 uint32_t ref_cnt;
138 138
139 uint32_t dev_type; 139 uint32_t dev_type;
140 140
141 dm_table_head_t table_head; 141 dm_table_head_t table_head;
142 142
143 struct dm_dev_head upcalls; 143 struct dm_dev_head upcalls;
144  144
145 struct disk *diskp; 145 struct disk *diskp;
146 kmutex_t diskp_mtx; 146 kmutex_t diskp_mtx;
147  147
148 TAILQ_ENTRY(dm_dev) next_upcall; /* LIST of mirrored, snapshoted devices. */ 148 TAILQ_ENTRY(dm_dev) next_upcall; /* LIST of mirrored, snapshoted devices. */
149 149
150 TAILQ_ENTRY(dm_dev) next_devlist; /* Major device list. */ 150 TAILQ_ENTRY(dm_dev) next_devlist; /* Major device list. */
151} dm_dev_t; 151} dm_dev_t;
152 152
153/* Device types used for upcalls */ 153/* Device types used for upcalls */
154#define DM_ZERO_DEV (1 << 0) 154#define DM_ZERO_DEV (1 << 0)
155#define DM_ERROR_DEV (1 << 1)  155#define DM_ERROR_DEV (1 << 1)
156#define DM_LINEAR_DEV (1 << 2) 156#define DM_LINEAR_DEV (1 << 2)
157#define DM_MIRROR_DEV (1 << 3) 157#define DM_MIRROR_DEV (1 << 3)
158#define DM_STRIPE_DEV (1 << 4) 158#define DM_STRIPE_DEV (1 << 4)
159#define DM_SNAPSHOT_DEV (1 << 5) 159#define DM_SNAPSHOT_DEV (1 << 5)
160#define DM_SNAPSHOT_ORIG_DEV (1 << 6) 160#define DM_SNAPSHOT_ORIG_DEV (1 << 6)
161#define DM_SPARE_DEV (1 << 7) 161#define DM_SPARE_DEV (1 << 7)
162/* Set this device type only during dev remove ioctl. */ 162/* Set this device type only during dev remove ioctl. */
163#define DM_DELETING_DEV (1 << 8)  163#define DM_DELETING_DEV (1 << 8)
164 164
165 165
166/* for zero, error : dm_target->target_config == NULL */ 166/* for zero, error : dm_target->target_config == NULL */
167  167
168/* 168/*
169 * Target config is initiated with target_init function. 169 * Target config is initiated with target_init function.
170 */ 170 */
171  171
172/* for linear : */ 172/* for linear : */
173typedef struct target_linear_config { 173typedef struct target_linear_config {
174 dm_pdev_t *pdev; 174 dm_pdev_t *pdev;
175 uint64_t offset; 175 uint64_t offset;
176 TAILQ_ENTRY(target_linear_config) entries; 176 TAILQ_ENTRY(target_linear_config) entries;
177} dm_target_linear_config_t; 177} dm_target_linear_config_t;
178 178
179/* 179/*
180 * Striping devices are stored in a linked list, this might be inefficient 180 * Striping devices are stored in a linked list, this might be inefficient
181 * for more than 8 striping devices and can be changed to something more 181 * for more than 8 striping devices and can be changed to something more
182 * scalable. 182 * scalable.
183 * TODO: look for other options than linked list. 183 * TODO: look for other options than linked list.
184 */ 184 */
@@ -204,61 +204,61 @@ typedef struct target_mirror_config { @@ -204,61 +204,61 @@ typedef struct target_mirror_config {
204 /* copied blocks bitmaps administration etc*/ 204 /* copied blocks bitmaps administration etc*/
205 dm_pdev_t *log_pdev; /* for administration */ 205 dm_pdev_t *log_pdev; /* for administration */
206 uint64_t log_regionsize; /* blocksize of mirror */ 206 uint64_t log_regionsize; /* blocksize of mirror */
207 207
208 /* list of parts that still need copied etc.; run length encoded? */ 208 /* list of parts that still need copied etc.; run length encoded? */
209} dm_target_mirror_config_t; 209} dm_target_mirror_config_t;
210 210
211 211
212/* for snapshot : */ 212/* for snapshot : */
213typedef struct target_snapshot_config { 213typedef struct target_snapshot_config {
214 dm_pdev_t *tsc_snap_dev; 214 dm_pdev_t *tsc_snap_dev;
215 /* cow dev is set only for persistent snapshot devices */ 215 /* cow dev is set only for persistent snapshot devices */
216 dm_pdev_t *tsc_cow_dev; 216 dm_pdev_t *tsc_cow_dev;
217  217
218 uint64_t tsc_chunk_size; 218 uint64_t tsc_chunk_size;
219 uint32_t tsc_persistent_dev; 219 uint32_t tsc_persistent_dev;
220} dm_target_snapshot_config_t; 220} dm_target_snapshot_config_t;
221 221
222/* for snapshot-origin devices */ 222/* for snapshot-origin devices */
223typedef struct target_snapshot_origin_config { 223typedef struct target_snapshot_origin_config {
224 dm_pdev_t *tsoc_real_dev; 224 dm_pdev_t *tsoc_real_dev;
225 /* list of snapshots ? */ 225 /* list of snapshots ? */
226} dm_target_snapshot_origin_config_t; 226} dm_target_snapshot_origin_config_t;
227 227
228/* constant dm_target structures for error, zero, linear, stripes etc. */ 228/* constant dm_target structures for error, zero, linear, stripes etc. */
229typedef struct dm_target { 229typedef struct dm_target {
230 char name[DM_MAX_TYPE_NAME]; 230 char name[DM_MAX_TYPE_NAME];
231 /* Initialize target_config area */ 231 /* Initialize target_config area */
232 int (*init)(dm_dev_t *, void **, char *); 232 int (*init)(dm_dev_t *, void **, char *);
233 233
234 /* Destroy target_config area */ 234 /* Destroy target_config area */
235 int (*destroy)(dm_table_entry_t *); 235 int (*destroy)(dm_table_entry_t *);
236  236
237 int (*deps) (dm_table_entry_t *, prop_array_t); 237 int (*deps) (dm_table_entry_t *, prop_array_t);
238 /* 238 /*
239 * Status routine is called to get params string, which is target 239 * Status routine is called to get params string, which is target
240 * specific. When dm_table_status_ioctl is called with flag 240 * specific. When dm_table_status_ioctl is called with flag
241 * DM_STATUS_TABLE_FLAG I have to sent params string back. 241 * DM_STATUS_TABLE_FLAG I have to sent params string back.
242 */ 242 */
243 char * (*status)(void *); 243 char * (*status)(void *);
244 int (*strategy)(dm_table_entry_t *, struct buf *); 244 int (*strategy)(dm_table_entry_t *, struct buf *);
245 int (*sync)(dm_table_entry_t *); 245 int (*sync)(dm_table_entry_t *);
246 int (*upcall)(dm_table_entry_t *, struct buf *); 246 int (*upcall)(dm_table_entry_t *, struct buf *);
247 int (*secsize)(dm_table_entry_t *, unsigned *); 247 int (*secsize)(dm_table_entry_t *, unsigned *);
248  248
249 uint32_t version[3]; 249 uint32_t version[3];
250 int ref_cnt; 250 int ref_cnt;
251  251
252 TAILQ_ENTRY(dm_target) dm_target_next; 252 TAILQ_ENTRY(dm_target) dm_target_next;
253} dm_target_t; 253} dm_target_t;
254 254
255/* Interface structures */ 255/* Interface structures */
256 256
257/* 257/*
258 * This structure is used to translate command sent to kernel driver in 258 * This structure is used to translate command sent to kernel driver in
259 * <key>command</key> 259 * <key>command</key>
260 * <value></value> 260 * <value></value>
261 * to function which I can call, and if the command is allowed for 261 * to function which I can call, and if the command is allowed for
262 * non-superusers. 262 * non-superusers.
263 */ 263 */
264struct cmd_function { 264struct cmd_function {
@@ -305,44 +305,45 @@ int dm_target_init(void); @@ -305,44 +305,45 @@ int dm_target_init(void);
305#define DM_MAX_PARAMS_SIZE 1024 305#define DM_MAX_PARAMS_SIZE 1024
306 306
307/* dm_target_linear.c */ 307/* dm_target_linear.c */
308int dm_target_linear_init(dm_dev_t *, void**, char *); 308int dm_target_linear_init(dm_dev_t *, void**, char *);
309char * dm_target_linear_status(void *); 309char * dm_target_linear_status(void *);
310int dm_target_linear_strategy(dm_table_entry_t *, struct buf *); 310int dm_target_linear_strategy(dm_table_entry_t *, struct buf *);
311int dm_target_linear_sync(dm_table_entry_t *); 311int dm_target_linear_sync(dm_table_entry_t *);
312int dm_target_linear_deps(dm_table_entry_t *, prop_array_t); 312int dm_target_linear_deps(dm_table_entry_t *, prop_array_t);
313int dm_target_linear_destroy(dm_table_entry_t *); 313int dm_target_linear_destroy(dm_table_entry_t *);
314int dm_target_linear_upcall(dm_table_entry_t *, struct buf *); 314int dm_target_linear_upcall(dm_table_entry_t *, struct buf *);
315int dm_target_linear_secsize(dm_table_entry_t *, unsigned *); 315int dm_target_linear_secsize(dm_table_entry_t *, unsigned *);
316 316
317/* Generic function used to convert char to string */ 317/* Generic function used to convert char to string */
318uint64_t atoi(const char *);  318uint64_t atoi(const char *);
319 319
320/* dm_target_stripe.c */ 320/* dm_target_stripe.c */
321int dm_target_stripe_init(dm_dev_t *, void**, char *); 321int dm_target_stripe_init(dm_dev_t *, void**, char *);
322char * dm_target_stripe_status(void *); 322char * dm_target_stripe_status(void *);
323int dm_target_stripe_strategy(dm_table_entry_t *, struct buf *); 323int dm_target_stripe_strategy(dm_table_entry_t *, struct buf *);
324int dm_target_stripe_sync(dm_table_entry_t *); 324int dm_target_stripe_sync(dm_table_entry_t *);
325int dm_target_stripe_deps(dm_table_entry_t *, prop_array_t); 325int dm_target_stripe_deps(dm_table_entry_t *, prop_array_t);
326int dm_target_stripe_destroy(dm_table_entry_t *); 326int dm_target_stripe_destroy(dm_table_entry_t *);
327int dm_target_stripe_upcall(dm_table_entry_t *, struct buf *); 327int dm_target_stripe_upcall(dm_table_entry_t *, struct buf *);
328int dm_target_stripe_secsize(dm_table_entry_t *, unsigned *); 328int dm_target_stripe_secsize(dm_table_entry_t *, unsigned *);
329 329
330/* dm_table.c */ 330/* dm_table.c */
331#define DM_TABLE_ACTIVE 0 331#define DM_TABLE_ACTIVE 0
332#define DM_TABLE_INACTIVE 1 332#define DM_TABLE_INACTIVE 1
333 333
334int dm_table_destroy(dm_table_head_t *, uint8_t); 334int dm_table_destroy(dm_table_head_t *, uint8_t);
335uint64_t dm_table_size(dm_table_head_t *); 335uint64_t dm_table_size(dm_table_head_t *);
 336uint64_t dm_inactive_table_size(dm_table_head_t *);
336void dm_table_disksize(dm_table_head_t *, uint64_t *, unsigned *); 337void dm_table_disksize(dm_table_head_t *, uint64_t *, unsigned *);
337dm_table_t * dm_table_get_entry(dm_table_head_t *, uint8_t); 338dm_table_t * dm_table_get_entry(dm_table_head_t *, uint8_t);
338int dm_table_get_target_count(dm_table_head_t *, uint8_t); 339int dm_table_get_target_count(dm_table_head_t *, uint8_t);
339void dm_table_release(dm_table_head_t *, uint8_t s); 340void dm_table_release(dm_table_head_t *, uint8_t s);
340void dm_table_switch_tables(dm_table_head_t *); 341void dm_table_switch_tables(dm_table_head_t *);
341void dm_table_head_init(dm_table_head_t *); 342void dm_table_head_init(dm_table_head_t *);
342void dm_table_head_destroy(dm_table_head_t *); 343void dm_table_head_destroy(dm_table_head_t *);
343 344
344/* dm_dev.c */ 345/* dm_dev.c */
345dm_dev_t* dm_dev_alloc(void); 346dm_dev_t* dm_dev_alloc(void);
346void dm_dev_busy(dm_dev_t *); 347void dm_dev_busy(dm_dev_t *);
347int dm_dev_destroy(void); 348int dm_dev_destroy(void);
348dm_dev_t* dm_dev_detach(device_t); 349dm_dev_t* dm_dev_detach(device_t);

cvs diff -r1.25 -r1.26 src/sys/dev/dm/dm_ioctl.c (expand / switch to unified diff)

--- src/sys/dev/dm/dm_ioctl.c 2011/05/24 15:23:41 1.25
+++ src/sys/dev/dm/dm_ioctl.c 2011/08/27 17:07:49 1.26
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dm_ioctl.c,v 1.25 2011/05/24 15:23:41 joerg Exp $ */ 1/* $NetBSD: dm_ioctl.c,v 1.26 2011/08/27 17:07:49 ahoka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Hamsik. 8 * by Adam Hamsik.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -783,26 +783,27 @@ dm_table_load_ioctl(prop_dictionary_t dm @@ -783,26 +783,27 @@ dm_table_load_ioctl(prop_dictionary_t dm
783 * Params string is different for every target, 783 * Params string is different for every target,
784 * therfore I have to pass it to target init 784 * therfore I have to pass it to target init
785 * routine and parse parameters there. 785 * routine and parse parameters there.
786 */ 786 */
787 787
788 if ((ret = target->init(dmv, &table_en->target_config, 788 if ((ret = target->init(dmv, &table_en->target_config,
789 str)) != 0) { 789 str)) != 0) {
790 790
791 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE); 791 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
792 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE); 792 dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
793 free(str, M_TEMP); 793 free(str, M_TEMP);
794 794
795 dm_dev_unbusy(dmv); 795 dm_dev_unbusy(dmv);
 796 dm_target_unbusy(target);
796 return ret; 797 return ret;
797 } 798 }
798 last_table = table_en; 799 last_table = table_en;
799 free(str, M_TEMP); 800 free(str, M_TEMP);
800 } 801 }
801 prop_object_iterator_release(iter); 802 prop_object_iterator_release(iter);
802 803
803 DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG); 804 DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
804 atomic_or_32(&dmv->flags, DM_INACTIVE_PRESENT_FLAG); 805 atomic_or_32(&dmv->flags, DM_INACTIVE_PRESENT_FLAG);
805 806
806 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE); 807 dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
807 dm_dev_unbusy(dmv); 808 dm_dev_unbusy(dmv);
808 return 0; 809 return 0;