]> git.ipfire.org Git - thirdparty/mdadm.git/blob - mdadm.h
mdadm: remove symlink option
[thirdparty/mdadm.git] / mdadm.h
1 /*
2 * mdadm - manage Linux "md" devices aka RAID arrays.
3 *
4 * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Author: Neil Brown
22 * Email: <neilb@suse.de>
23 */
24
25 #define _GNU_SOURCE
26 #define _FILE_OFFSET_BITS 64
27 #include <unistd.h>
28 #ifdef __GLIBC__
29 extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
30 #elif !defined(lseek64)
31 # if defined(__NO_STAT64) || __WORDSIZE != 32
32 # define lseek64 lseek
33 # endif
34 #endif
35
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 #include <stdint.h>
39 #include <stdlib.h>
40 #include <time.h>
41 #include <sys/time.h>
42 #include <getopt.h>
43 #include <fcntl.h>
44 #include <stdio.h>
45 #include <errno.h>
46 #include <string.h>
47 #include <syslog.h>
48 #include <stdbool.h>
49 #include <signal.h>
50 /* Newer glibc requires sys/sysmacros.h directly for makedev() */
51 #include <sys/sysmacros.h>
52 #ifdef __dietlibc__
53 #include <strings.h>
54 /* dietlibc has deprecated random and srandom!! */
55 #define random rand
56 #define srandom srand
57 #endif
58
59 #ifdef NO_COROSYNC
60 #define CS_OK 1
61 typedef uint64_t cmap_handle_t;
62 #else
63 #include <corosync/cmap.h>
64 #endif
65
66 #ifndef NO_DLM
67 #include <libdlm.h>
68 #include <errno.h>
69 #else
70 #define LKF_NOQUEUE 0x00000001
71 #define LKM_PWMODE 4
72 #define EUNLOCK 0x10002
73
74 typedef void *dlm_lshandle_t;
75
76 struct dlm_lksb {
77 int sb_status;
78 uint32_t sb_lkid;
79 char sb_flags;
80 char *sb_lvbptr;
81 };
82 #endif
83
84 #include <linux/kdev_t.h>
85 /*#include <linux/fs.h> */
86 #include <sys/mount.h>
87 #include <asm/types.h>
88 #include <sys/ioctl.h>
89 #define MD_MAJOR 9
90 #define MdpMinorShift 6
91
92 #ifndef BLKGETSIZE64
93 #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
94 #endif
95
96 #define DEFAULT_CHUNK 512
97 #define DEFAULT_BITMAP_CHUNK 4096
98 #define DEFAULT_BITMAP_DELAY 5
99 #define DEFAULT_MAX_WRITE_BEHIND 256
100
101 /* MAP_DIR should be somewhere that persists across the pivotroot
102 * from early boot to late boot.
103 * /run seems to have emerged as the best standard.
104 */
105 #ifndef MAP_DIR
106 #define MAP_DIR "/run/mdadm"
107 #endif /* MAP_DIR */
108 /* MAP_FILE is what we name the map file we put in MAP_DIR, in case you
109 * want something other than the default of "map"
110 */
111 #ifndef MAP_FILE
112 #define MAP_FILE "map"
113 #endif /* MAP_FILE */
114 /* MDMON_DIR is where pid and socket files used for communicating
115 * with mdmon normally live. Best is /var/run/mdadm as
116 * mdmon is needed at early boot then it needs to write there prior
117 * to /var/run being mounted read/write, and it also then needs to
118 * persist beyond when /var/run is mounter read-only. So, to be
119 * safe, the default is somewhere that is read/write early in the
120 * boot process and stays up as long as possible during shutdown.
121 */
122 #ifndef MDMON_DIR
123 #define MDMON_DIR "/run/mdadm"
124 #endif /* MDMON_DIR */
125
126 /* FAILED_SLOTS is where to save files storing recent removal of array
127 * member in order to allow future reuse of disk inserted in the same
128 * slot for array recovery
129 */
130 #ifndef FAILED_SLOTS_DIR
131 #define FAILED_SLOTS_DIR "/run/mdadm/failed-slots"
132 #endif /* FAILED_SLOTS */
133
134 #ifndef MDMON_SERVICE
135 #define MDMON_SERVICE "mdmon"
136 #endif /* MDMON_SERVICE */
137
138 #ifndef GROW_SERVICE
139 #define GROW_SERVICE "mdadm-grow-continue"
140 #endif /* GROW_SERVICE */
141
142 #include "md_u.h"
143 #include "md_p.h"
144 #include "bitmap.h"
145 #include "msg.h"
146
147 #include <endian.h>
148 /* Redhat don't like to #include <asm/byteorder.h>, and
149 * some time include <linux/byteorder/xxx_endian.h> isn't enough,
150 * and there is no standard conversion function so... */
151 /* And dietlibc doesn't think byteswap is ok, so.. */
152 /* #include <byteswap.h> */
153 #define __mdadm_bswap_16(x) (((x) & 0x00ffU) << 8 | \
154 ((x) & 0xff00U) >> 8)
155 #define __mdadm_bswap_32(x) (((x) & 0x000000ffU) << 24 | \
156 ((x) & 0xff000000U) >> 24 | \
157 ((x) & 0x0000ff00U) << 8 | \
158 ((x) & 0x00ff0000U) >> 8)
159 #define __mdadm_bswap_64(x) (((x) & 0x00000000000000ffULL) << 56 | \
160 ((x) & 0xff00000000000000ULL) >> 56 | \
161 ((x) & 0x000000000000ff00ULL) << 40 | \
162 ((x) & 0x00ff000000000000ULL) >> 40 | \
163 ((x) & 0x0000000000ff0000ULL) << 24 | \
164 ((x) & 0x0000ff0000000000ULL) >> 24 | \
165 ((x) & 0x00000000ff000000ULL) << 8 | \
166 ((x) & 0x000000ff00000000ULL) >> 8)
167
168 #if !defined(__KLIBC__)
169 #if BYTE_ORDER == LITTLE_ENDIAN
170 #define __cpu_to_le16(_x) (unsigned int)(_x)
171 #define __cpu_to_le32(_x) (unsigned int)(_x)
172 #define __cpu_to_le64(_x) (unsigned long long)(_x)
173 #define __le16_to_cpu(_x) (unsigned int)(_x)
174 #define __le32_to_cpu(_x) (unsigned int)(_x)
175 #define __le64_to_cpu(_x) (unsigned long long)(_x)
176
177 #define __cpu_to_be16(_x) __mdadm_bswap_16(_x)
178 #define __cpu_to_be32(_x) __mdadm_bswap_32(_x)
179 #define __cpu_to_be64(_x) __mdadm_bswap_64(_x)
180 #define __be16_to_cpu(_x) __mdadm_bswap_16(_x)
181 #define __be32_to_cpu(_x) __mdadm_bswap_32(_x)
182 #define __be64_to_cpu(_x) __mdadm_bswap_64(_x)
183 #elif BYTE_ORDER == BIG_ENDIAN
184 #define __cpu_to_le16(_x) __mdadm_bswap_16(_x)
185 #define __cpu_to_le32(_x) __mdadm_bswap_32(_x)
186 #define __cpu_to_le64(_x) __mdadm_bswap_64(_x)
187 #define __le16_to_cpu(_x) __mdadm_bswap_16(_x)
188 #define __le32_to_cpu(_x) __mdadm_bswap_32(_x)
189 #define __le64_to_cpu(_x) __mdadm_bswap_64(_x)
190
191 #define __cpu_to_be16(_x) (unsigned int)(_x)
192 #define __cpu_to_be32(_x) (unsigned int)(_x)
193 #define __cpu_to_be64(_x) (unsigned long long)(_x)
194 #define __be16_to_cpu(_x) (unsigned int)(_x)
195 #define __be32_to_cpu(_x) (unsigned int)(_x)
196 #define __be64_to_cpu(_x) (unsigned long long)(_x)
197 #else
198 # error "unknown endianness."
199 #endif
200 #endif /* __KLIBC__ */
201
202 /*
203 * Partially stolen from include/linux/unaligned/packed_struct.h
204 */
205 struct __una_u16 { __u16 x; } __attribute__ ((packed));
206 struct __una_u32 { __u32 x; } __attribute__ ((packed));
207
208 static inline __u16 __get_unaligned16(const void *p)
209 {
210 const struct __una_u16 *ptr = (const struct __una_u16 *)p;
211 return ptr->x;
212 }
213
214 static inline __u32 __get_unaligned32(const void *p)
215 {
216 const struct __una_u32 *ptr = (const struct __una_u32 *)p;
217 return ptr->x;
218 }
219
220 static inline void __put_unaligned16(__u16 val, void *p)
221 {
222 struct __una_u16 *ptr = (struct __una_u16 *)p;
223 ptr->x = val;
224 }
225
226 static inline void __put_unaligned32(__u32 val, void *p)
227 {
228 struct __una_u32 *ptr = (struct __una_u32 *)p;
229 ptr->x = val;
230 }
231
232 /*
233 * Check at compile time that something is of a particular type.
234 * Always evaluates to 1 so you may use it easily in comparisons.
235 */
236
237 #define typecheck(type,x) \
238 ({ type __dummy; \
239 typeof(x) __dummy2; \
240 (void)(&__dummy == &__dummy2); \
241 1; \
242 })
243
244 /*
245 * These inlines deal with timer wrapping correctly.
246 *
247 * time_after(a,b) returns true if the time a is after time b.
248 */
249
250 #define time_after(a,b) \
251 (typecheck(unsigned int, a) && \
252 typecheck(unsigned int, b) && \
253 ((int)((b) - (a)) < 0))
254
255 #define time_before(a,b) time_after(b,a)
256
257 /*
258 * min()/max()/clamp() macros that also do
259 * strict type-checking.. See the
260 * "unnecessary" pointer comparison.
261 */
262 #define min(x, y) ({ \
263 typeof(x) _min1 = (x); \
264 typeof(y) _min2 = (y); \
265 (void) (&_min1 == &_min2); \
266 _min1 < _min2 ? _min1 : _min2; })
267
268 #define max(x, y) ({ \
269 typeof(x) _max1 = (x); \
270 typeof(y) _max2 = (y); \
271 (void) (&_max1 == &_max2); \
272 _max1 > _max2 ? _max1 : _max2; })
273
274 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
275
276 extern const char Name[];
277
278 struct md_bb_entry {
279 unsigned long long sector;
280 int length;
281 };
282
283 struct md_bb {
284 int supported;
285 int count;
286 struct md_bb_entry *entries;
287 };
288
289 /* general information that might be extracted from a superblock */
290 struct mdinfo {
291 mdu_array_info_t array;
292 mdu_disk_info_t disk;
293 __u64 events;
294 int uuid[4];
295 char name[33];
296 unsigned long long data_offset;
297 unsigned long long new_data_offset;
298 unsigned long long component_size; /* same as array.size, except in
299 * sectors and up to 64bits.
300 */
301 unsigned long long custom_array_size; /* size for non-default sized
302 * arrays (in sectors)
303 */
304 #define NO_RESHAPE 0
305 #define VOLUME_RESHAPE 1
306 #define CONTAINER_RESHAPE 2
307 #define RESHAPE_NO_BACKUP 16 /* Mask 'or'ed in */
308 int reshape_active;
309 unsigned long long reshape_progress;
310 int recovery_blocked; /* for external metadata it
311 * indicates that there is
312 * reshape in progress in
313 * container,
314 * for native metadata it is
315 * reshape_active field mirror
316 */
317 int journal_device_required;
318 int journal_clean;
319
320 enum {
321 CONSISTENCY_POLICY_UNKNOWN,
322 CONSISTENCY_POLICY_NONE,
323 CONSISTENCY_POLICY_RESYNC,
324 CONSISTENCY_POLICY_BITMAP,
325 CONSISTENCY_POLICY_JOURNAL,
326 CONSISTENCY_POLICY_PPL,
327 } consistency_policy;
328
329 /* During reshape we can sometimes change the data_offset to avoid
330 * over-writing still-valid data. We need to know if there is space.
331 * So getinfo_super will fill in space_before and space_after in sectors.
332 * data_offset can be increased or decreased by this amount.
333 */
334 unsigned long long space_before, space_after;
335 union {
336 unsigned long long resync_start; /* per-array resync position */
337 unsigned long long recovery_start; /* per-device rebuild position */
338 #define MaxSector (~0ULL) /* resync/recovery complete position */
339 };
340 long bitmap_offset; /* 0 == none, 1 == a file */
341 unsigned int ppl_size;
342 int ppl_offset;
343 unsigned long long ppl_sector;
344 unsigned long safe_mode_delay; /* ms delay to mark clean */
345 int new_level, delta_disks, new_layout, new_chunk;
346 int errors;
347 unsigned long cache_size; /* size of raid456 stripe cache*/
348 int mismatch_cnt;
349 char text_version[50];
350
351 int container_member; /* for assembling external-metatdata arrays
352 * This is to be used internally by metadata
353 * handler only */
354 int container_enough; /* flag external handlers can set to
355 * indicate that subarrays have not enough (-1),
356 * enough to start (0), or all expected disks (1) */
357 char sys_name[32];
358 struct mdinfo *devs;
359 struct mdinfo *next;
360
361 /* Device info for mdmon: */
362 int recovery_fd;
363 int state_fd;
364 int bb_fd;
365 int ubb_fd;
366 #define DS_FAULTY 1
367 #define DS_INSYNC 2
368 #define DS_WRITE_MOSTLY 4
369 #define DS_SPARE 8
370 #define DS_BLOCKED 16
371 #define DS_REMOVE 1024
372 #define DS_UNBLOCK 2048
373 int prev_state, curr_state, next_state;
374
375 /* info read from sysfs */
376 enum {
377 ARRAY_CLEAR,
378 ARRAY_INACTIVE,
379 ARRAY_SUSPENDED,
380 ARRAY_READONLY,
381 ARRAY_READ_AUTO,
382 ARRAY_CLEAN,
383 ARRAY_ACTIVE,
384 ARRAY_WRITE_PENDING,
385 ARRAY_ACTIVE_IDLE,
386 ARRAY_BROKEN,
387 ARRAY_UNKNOWN_STATE,
388 } array_state;
389 struct md_bb bb;
390 };
391
392 struct createinfo {
393 int uid;
394 int gid;
395 int autof;
396 int mode;
397 int names;
398 int bblist;
399 struct supertype *supertype;
400 };
401
402 struct spare_criteria {
403 unsigned long long min_size;
404 unsigned int sector_size;
405 };
406
407 enum mode {
408 ASSEMBLE=1,
409 BUILD,
410 CREATE,
411 MANAGE,
412 MISC,
413 MONITOR,
414 GROW,
415 INCREMENTAL,
416 AUTODETECT,
417 mode_count
418 };
419
420 extern char short_options[];
421 extern char short_monitor_options[];
422 extern char short_bitmap_options[];
423 extern char short_bitmap_auto_options[];
424 extern struct option long_options[];
425 extern char Version[], Usage[], Help[], OptionHelp[],
426 *mode_help[],
427 Help_create[], Help_build[], Help_assemble[], Help_grow[],
428 Help_incr[],
429 Help_manage[], Help_misc[], Help_monitor[], Help_config[];
430
431 /* for option that don't have short equivilents, we assign arbitrary
432 * numbers later than any 'short' character option.
433 */
434 enum special_options {
435 AssumeClean = 300,
436 BitmapChunk,
437 WriteBehind,
438 ReAdd,
439 NoDegraded,
440 Sparc22,
441 BackupFile,
442 HomeHost,
443 AutoHomeHost,
444 AutoDetect,
445 Waitclean,
446 DetailPlatform,
447 KillSubarray,
448 UpdateSubarray,
449 IncrementalPath,
450 NoSharing,
451 HelpOptions,
452 Brief,
453 NoDevices,
454 ManageOpt,
455 Add,
456 AddSpare,
457 AddJournal,
458 Remove,
459 Fail,
460 Replace,
461 With,
462 MiscOpt,
463 WaitOpt,
464 ConfigFile,
465 ChunkSize,
466 WriteMostly,
467 FailFast,
468 NoFailFast,
469 Layout,
470 Auto,
471 Force,
472 SuperMinor,
473 EMail,
474 ProgramOpt,
475 Increment,
476 Fork,
477 Bitmap,
478 RebuildMapOpt,
479 InvalidBackup,
480 UdevRules,
481 FreezeReshape,
482 Continue,
483 OffRootOpt,
484 Prefer,
485 KillOpt,
486 DataOffset,
487 ExamineBB,
488 Dump,
489 Restore,
490 Action,
491 Nodes,
492 ClusterName,
493 ClusterConfirm,
494 WriteJournal,
495 ConsistencyPolicy,
496 };
497
498 enum prefix_standard {
499 JEDEC,
500 IEC
501 };
502
503 enum bitmap_update {
504 NoUpdate,
505 NameUpdate,
506 NodeNumUpdate,
507 };
508
509 enum flag_mode {
510 FlagDefault, FlagSet, FlagClear,
511 };
512
513 /* structures read from config file */
514 /* List of mddevice names and identifiers
515 * Identifiers can be:
516 * uuid=128-hex-uuid
517 * super-minor=decimal-minor-number-from-superblock
518 * devices=comma,separated,list,of,device,names,with,wildcards
519 *
520 * If multiple fields are present, the intersection of all matching
521 * devices is considered
522 */
523 #define UnSet (0xfffe)
524 struct mddev_ident {
525 char *devname;
526
527 int uuid_set;
528 int uuid[4];
529 char name[33];
530
531 int super_minor;
532
533 char *devices; /* comma separated list of device
534 * names with wild cards
535 */
536 int level;
537 int raid_disks;
538 int spare_disks;
539 struct supertype *st;
540 int autof; /* 1 for normal, 2 for partitioned */
541 char *spare_group;
542 char *bitmap_file;
543 int bitmap_fd;
544
545 char *container; /* /dev/whatever name of container, or
546 * uuid of container. You would expect
547 * this to be the 'devname' or UUID
548 * of some other entry.
549 */
550 char *member; /* subarray within a container */
551
552 struct mddev_ident *next;
553 union {
554 /* fields needed by different users of this structure */
555 int assembled; /* set when assembly succeeds */
556 };
557 };
558
559 struct context {
560 int readonly;
561 int runstop;
562 int verbose;
563 int brief;
564 int no_devices;
565 int force;
566 char *homehost;
567 int require_homehost;
568 char *prefer;
569 int export;
570 int test;
571 char *subarray;
572 char *update;
573 int scan;
574 int SparcAdjust;
575 int autof;
576 int delay;
577 int freeze_reshape;
578 char *backup_file;
579 int invalid_backup;
580 char *action;
581 int nodes;
582 char *homecluster;
583 };
584
585 struct shape {
586 int raiddisks;
587 int sparedisks;
588 int journaldisks;
589 int level;
590 int layout;
591 char *layout_str;
592 int chunk;
593 int bitmap_chunk;
594 char *bitmap_file;
595 int assume_clean;
596 int write_behind;
597 unsigned long long size;
598 int consistency_policy;
599 };
600
601 /* List of device names - wildcards expanded */
602 struct mddev_dev {
603 char *devname;
604 int disposition; /* 'a' for add, 'r' for remove, 'f' for fail,
605 * 'A' for re_add.
606 * Not set for names read from .config
607 */
608 enum flag_mode writemostly;
609 enum flag_mode failfast;
610 int used; /* set when used */
611 long long data_offset;
612 struct mddev_dev *next;
613 };
614
615 typedef struct mapping {
616 char *name;
617 int num;
618 } mapping_t;
619
620 struct mdstat_ent {
621 char devnm[32];
622 int active;
623 char *level;
624 char *pattern; /* U for up, _ for down */
625 int percent; /* -1 if no resync */
626 int resync; /* 3 if check, 2 if reshape, 1 if resync, 0 if recovery */
627 int devcnt;
628 int raid_disks;
629 char * metadata_version;
630 struct dev_member {
631 char *name;
632 struct dev_member *next;
633 } *members;
634 struct mdstat_ent *next;
635 };
636
637 extern struct mdstat_ent *mdstat_read(int hold, int start);
638 extern void mdstat_close(void);
639 extern void free_mdstat(struct mdstat_ent *ms);
640 extern int mdstat_wait(int seconds);
641 extern void mdstat_wait_fd(int fd, const sigset_t *sigmask);
642 extern int mddev_busy(char *devnm);
643 extern struct mdstat_ent *mdstat_by_component(char *name);
644 extern struct mdstat_ent *mdstat_by_subdev(char *subdev, char *container);
645
646 struct map_ent {
647 struct map_ent *next;
648 char devnm[32];
649 char metadata[20];
650 int uuid[4];
651 int bad;
652 char *path;
653 };
654 extern int map_update(struct map_ent **mpp, char *devnm, char *metadata,
655 int uuid[4], char *path);
656 extern void map_remove(struct map_ent **map, char *devnm);
657 extern struct map_ent *map_by_uuid(struct map_ent **map, int uuid[4]);
658 extern struct map_ent *map_by_devnm(struct map_ent **map, char *devnm);
659 extern void map_free(struct map_ent *map);
660 extern struct map_ent *map_by_name(struct map_ent **map, char *name);
661 extern void map_read(struct map_ent **melp);
662 extern int map_write(struct map_ent *mel);
663 extern void map_delete(struct map_ent **mapp, char *devnm);
664 extern void map_add(struct map_ent **melp,
665 char *devnm, char *metadata, int uuid[4], char *path);
666 extern int map_lock(struct map_ent **melp);
667 extern void map_unlock(struct map_ent **melp);
668 extern void map_fork(void);
669
670 /* various details can be requested */
671 enum sysfs_read_flags {
672 GET_LEVEL = (1 << 0),
673 GET_LAYOUT = (1 << 1),
674 GET_COMPONENT = (1 << 2),
675 GET_CHUNK = (1 << 3),
676 GET_CACHE = (1 << 4),
677 GET_MISMATCH = (1 << 5),
678 GET_VERSION = (1 << 6),
679 GET_DISKS = (1 << 7),
680 GET_SAFEMODE = (1 << 9),
681 GET_BITMAP_LOCATION = (1 << 10),
682
683 GET_DEVS = (1 << 20), /* gets role, major, minor */
684 GET_OFFSET = (1 << 21),
685 GET_SIZE = (1 << 22),
686 GET_STATE = (1 << 23),
687 GET_ERROR = (1 << 24),
688 GET_ARRAY_STATE = (1 << 25),
689 GET_CONSISTENCY_POLICY = (1 << 26),
690 GET_DEVS_ALL = (1 << 27),
691 };
692
693 /* If fd >= 0, get the array it is open on,
694 * else use devnm.
695 */
696 extern int sysfs_open(char *devnm, char *devname, char *attr);
697 extern int sysfs_init(struct mdinfo *mdi, int fd, char *devnm);
698 extern void sysfs_init_dev(struct mdinfo *mdi, dev_t devid);
699 extern void sysfs_free(struct mdinfo *sra);
700 extern struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options);
701 extern int sysfs_attr_match(const char *attr, const char *str);
702 extern int sysfs_match_word(const char *word, char **list);
703 extern int sysfs_set_str(struct mdinfo *sra, struct mdinfo *dev,
704 char *name, char *val);
705 extern int sysfs_set_num(struct mdinfo *sra, struct mdinfo *dev,
706 char *name, unsigned long long val);
707 extern int sysfs_set_num_signed(struct mdinfo *sra, struct mdinfo *dev,
708 char *name, long long val);
709 extern int sysfs_uevent(struct mdinfo *sra, char *event);
710 extern int sysfs_get_fd(struct mdinfo *sra, struct mdinfo *dev,
711 char *name);
712 extern int sysfs_fd_get_ll(int fd, unsigned long long *val);
713 extern int sysfs_get_ll(struct mdinfo *sra, struct mdinfo *dev,
714 char *name, unsigned long long *val);
715 extern int sysfs_fd_get_two(int fd, unsigned long long *v1, unsigned long long *v2);
716 extern int sysfs_get_two(struct mdinfo *sra, struct mdinfo *dev,
717 char *name, unsigned long long *v1, unsigned long long *v2);
718 extern int sysfs_fd_get_str(int fd, char *val, int size);
719 extern int sysfs_attribute_available(struct mdinfo *sra, struct mdinfo *dev,
720 char *name);
721 extern int sysfs_get_str(struct mdinfo *sra, struct mdinfo *dev,
722 char *name, char *val, int size);
723 extern int sysfs_set_safemode(struct mdinfo *sra, unsigned long ms);
724 extern int sysfs_set_array(struct mdinfo *info, int vers);
725 extern int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd, int resume);
726 extern int sysfs_disk_to_scsi_id(int fd, __u32 *id);
727 extern int sysfs_unique_holder(char *devnm, long rdev);
728 extern int sysfs_freeze_array(struct mdinfo *sra);
729 extern int sysfs_wait(int fd, int *msec);
730 extern int load_sys(char *path, char *buf, int len);
731 extern int zero_disk_range(int fd, unsigned long long sector, size_t count);
732 extern int reshape_prepare_fdlist(char *devname,
733 struct mdinfo *sra,
734 int raid_disks,
735 int nrdisks,
736 unsigned long blocks,
737 char *backup_file,
738 int *fdlist,
739 unsigned long long *offsets);
740 extern void reshape_free_fdlist(int *fdlist,
741 unsigned long long *offsets,
742 int size);
743 extern int reshape_open_backup_file(char *backup,
744 int fd,
745 char *devname,
746 long blocks,
747 int *fdlist,
748 unsigned long long *offsets,
749 char *sysfs_name,
750 int restart);
751 extern unsigned long compute_backup_blocks(int nchunk, int ochunk,
752 unsigned int ndata, unsigned int odata);
753 extern char *locate_backup(char *name);
754 extern char *make_backup(char *name);
755
756 extern int save_stripes(int *source, unsigned long long *offsets,
757 int raid_disks, int chunk_size, int level, int layout,
758 int nwrites, int *dest,
759 unsigned long long start, unsigned long long length,
760 char *buf);
761 extern int restore_stripes(int *dest, unsigned long long *offsets,
762 int raid_disks, int chunk_size, int level, int layout,
763 int source, unsigned long long read_offset,
764 unsigned long long start, unsigned long long length,
765 char *src_buf);
766
767 #ifndef Sendmail
768 #define Sendmail "/usr/lib/sendmail -t"
769 #endif
770
771 #define SYSLOG_FACILITY LOG_DAEMON
772 extern char *map_num_s(mapping_t *map, int num);
773 extern char *map_num(mapping_t *map, int num);
774 extern int map_name(mapping_t *map, char *name);
775 extern mapping_t r0layout[], r5layout[], r6layout[],
776 pers[], modes[], faultylayout[];
777 extern mapping_t consistency_policies[], sysfs_array_states[];
778
779 extern char *map_dev_preferred(int major, int minor, int create,
780 char *prefer);
781 static inline char *map_dev(int major, int minor, int create)
782 {
783 return map_dev_preferred(major, minor, create, NULL);
784 }
785
786 /**
787 * is_fd_valid() - check file descriptor.
788 * @fd: file descriptor.
789 *
790 * The function checks if @fd is nonnegative integer and shall be used only
791 * to verify open() result.
792 */
793 static inline int is_fd_valid(int fd)
794 {
795 return (fd > -1);
796 }
797
798 /**
799 * is_level456() - check whether given level is between inclusive 4 and 6.
800 * @level: level to check.
801 *
802 * Return: true if condition is met, false otherwise
803 */
804 static inline bool is_level456(int level)
805 {
806 return (level >= 4 && level <= 6);
807 }
808
809 /**
810 * close_fd() - verify, close and unset file descriptor.
811 * @fd: pointer to file descriptor.
812 *
813 * The function closes and invalidates file descriptor if appropriative. It
814 * ignores incorrect file descriptor quitely to simplify error handling.
815 */
816 static inline void close_fd(int *fd)
817 {
818 if (is_fd_valid(*fd) && close(*fd) == 0)
819 *fd = -1;
820 }
821
822 struct active_array;
823 struct metadata_update;
824
825 /* 'struct reshape' records the intermediate states of
826 * a general reshape.
827 * The starting geometry is converted to the 'before' geometry
828 * by at most an atomic level change. They could be the same.
829 * Similarly the 'after' geometry is converted to the final
830 * geometry by at most a level change.
831 * Note that 'before' and 'after' must have the same level.
832 * 'blocks' is the minimum number of sectors for a reshape unit.
833 * This will be a multiple of the stripe size in each of the
834 * 'before' and 'after' geometries.
835 * If 'blocks' is 0, no restriping is necessary.
836 * 'min_offset_change' is the minimum change to data_offset to
837 * allow the reshape to happen. It is at least the larger of
838 * the old and new chunk sizes, and typically the same as 'blocks'
839 * divided by number of data disks.
840 */
841 struct reshape {
842 int level;
843 int parity; /* number of parity blocks/devices */
844 struct {
845 int layout;
846 int data_disks;
847 } before, after;
848 unsigned long long backup_blocks;
849 unsigned long long min_offset_change;
850 unsigned long long stripes; /* number of old stripes that comprise 'blocks'*/
851 unsigned long long new_size; /* New size of array in sectors */
852 };
853
854 /* A superswitch provides entry point to a metadata handler.
855 *
856 * The superswitch primarily operates on some "metadata" that
857 * is accessed via the 'supertype'.
858 * This metadata has one of three possible sources.
859 * 1/ It is read from a single device. In this case it may not completely
860 * describe the array or arrays as some information might be on other
861 * devices.
862 * 2/ It is read from all devices in a container. In this case all
863 * information is present.
864 * 3/ It is created by ->init_super / ->add_to_super. In this case it will
865 * be complete once enough ->add_to_super calls have completed.
866 *
867 * When creating an array inside a container, the metadata will be
868 * formed by a combination of 2 and 3. The metadata or the array is read,
869 * then new information is added.
870 *
871 * The metadata must sometimes have a concept of a 'current' array
872 * and a 'current' device.
873 * The 'current' array is set by init_super to be the newly created array,
874 * or is set by super_by_fd when it finds it is looking at an array inside
875 * a container.
876 *
877 * The 'current' device is either the device that the metadata was read from
878 * in case 1, or the last device added by add_to_super in case 3.
879 * Case 2 does not identify a 'current' device.
880 */
881 extern struct superswitch {
882
883 /* Used to report details of metadata read from a component
884 * device. ->load_super has been called.
885 */
886 void (*examine_super)(struct supertype *st, char *homehost);
887 void (*brief_examine_super)(struct supertype *st, int verbose);
888 void (*brief_examine_subarrays)(struct supertype *st, int verbose);
889 void (*export_examine_super)(struct supertype *st);
890 int (*examine_badblocks)(struct supertype *st, int fd, char *devname);
891 int (*copy_metadata)(struct supertype *st, int from, int to);
892
893 /* Used to report details of an active array.
894 * ->load_super was possibly given a 'component' string.
895 */
896 void (*detail_super)(struct supertype *st, char *homehost,
897 char *subarray);
898 void (*brief_detail_super)(struct supertype *st, char *subarray);
899 void (*export_detail_super)(struct supertype *st);
900
901 /* Optional: platform hardware / firmware details */
902 int (*detail_platform)(int verbose, int enumerate_only, char *controller_path);
903 int (*export_detail_platform)(int verbose, char *controller_path);
904
905 /* Used:
906 * to get uuid to storing in bitmap metadata
907 * and 'reshape' backup-data metadata
908 * To see if a device is being re-added to an array it was part of.
909 */
910 void (*uuid_from_super)(struct supertype *st, int uuid[4]);
911
912 /* Extract generic details from metadata. This could be details about
913 * the container, or about an individual array within the container.
914 * The determination is made either by:
915 * load_super being given a 'component' string.
916 * validate_geometry determining what to create.
917 * The info includes both array information and device information.
918 * The particular device should be:
919 * The last device added by add_to_super
920 * The device the metadata was loaded from by load_super
921 * If 'map' is present, then it is an array raid_disks long
922 * (raid_disk must already be set and correct) and it is filled
923 * with 1 for slots that are thought to be active and 0 for slots which
924 * appear to be failed/missing.
925 * *info is zeroed out before data is added.
926 */
927 void (*getinfo_super)(struct supertype *st, struct mdinfo *info, char *map);
928 struct mdinfo *(*getinfo_super_disks)(struct supertype *st);
929 /* Check if the given metadata is flagged as belonging to "this"
930 * host. 0 for 'no', 1 for 'yes', -1 for "Don't record homehost"
931 */
932 int (*match_home)(struct supertype *st, char *homehost);
933
934 /* Make one of several generic modifications to metadata
935 * prior to assembly (or other times).
936 * sparc2.2 - first bug in early 0.90 metadata
937 * super-minor - change name of 0.90 metadata
938 * summaries - 'correct' any redundant data
939 * resync - mark array as dirty to trigger a resync.
940 * uuid - set new uuid - only 0.90 or 1.x
941 * name - change the name of the array (where supported)
942 * homehost - change which host this array is tied to.
943 * devicesize - If metadata is at start of device, change recorded
944 * device size to match actual device size
945 * byteorder - swap bytes for 0.90 metadata
946 *
947 * force-one - mark that device as uptodate, not old or failed.
948 * force-array - mark array as clean if it would not otherwise
949 * assemble
950 * assemble - not sure how this is different from force-one...
951 * linear-grow-new - add a new device to a linear array, but don't
952 * change the size: so superblock still matches
953 * linear-grow-update - now change the size of the array.
954 * writemostly - set the WriteMostly1 bit in the superblock devflags
955 * readwrite - clear the WriteMostly1 bit in the superblock devflags
956 * failfast - set the FailFast1 bit in the superblock
957 * nofailfast - clear the FailFast1 bit
958 * no-bitmap - clear any record that a bitmap is present.
959 * bbl - add a bad-block-log if possible
960 * no-bbl - remove any bad-block-log is it is empty.
961 * force-no-bbl - remove any bad-block-log even if empty.
962 * revert-reshape - If a reshape is in progress, modify metadata so
963 * it will resume going in the opposite direction.
964 */
965 int (*update_super)(struct supertype *st, struct mdinfo *info,
966 char *update,
967 char *devname, int verbose,
968 int uuid_set, char *homehost);
969
970 /* Create new metadata for new array as described. This could
971 * be a new container, or an array in a pre-existing container.
972 * Also used to zero metadata prior to writing it to invalidate old
973 * metadata.
974 */
975 int (*init_super)(struct supertype *st, mdu_array_info_t *info,
976 struct shape *s, char *name,
977 char *homehost, int *uuid,
978 unsigned long long data_offset);
979
980 /* update the metadata to include new device, either at create or
981 * when hot-adding a spare.
982 */
983 int (*add_to_super)(struct supertype *st, mdu_disk_info_t *dinfo,
984 int fd, char *devname,
985 unsigned long long data_offset);
986 /* update the metadata to delete a device,
987 * when hot-removing.
988 */
989 int (*remove_from_super)(struct supertype *st, mdu_disk_info_t *dinfo);
990
991 /* Write metadata to one device when fixing problems or adding
992 * a new device.
993 */
994 int (*store_super)(struct supertype *st, int fd);
995
996 /* Write all metadata for this array.
997 */
998 int (*write_init_super)(struct supertype *st);
999 /* Check if metadata read from one device is compatible with an array,
1000 * used when assembling an array, or pseudo-assembling was with
1001 * "--examine --brief"
1002 * If "st" has not yet been loaded the superblock from, "tst" is
1003 * moved in, otherwise the superblock in 'st' is compared with
1004 * 'tst'.
1005 */
1006 int (*compare_super)(struct supertype *st, struct supertype *tst,
1007 int verbose);
1008 /* Load metadata from a single device. If 'devname' is not NULL
1009 * print error messages as appropriate */
1010 int (*load_super)(struct supertype *st, int fd, char *devname);
1011 /* 'fd' is a 'container' md array - load array metadata from the
1012 * whole container.
1013 */
1014 int (*load_container)(struct supertype *st, int fd, char *devname);
1015 /* If 'arg' is a valid name of this metadata type, allocate and
1016 * return a 'supertype' for the particular minor version */
1017 struct supertype * (*match_metadata_desc)(char *arg);
1018 /* If a device has the given size, and the data_offset has been
1019 * requested - work out how much space is available for data.
1020 * This involves adjusting for reserved space (e.g. bitmaps)
1021 * and for any rounding.
1022 * 'mdadm' only calls this for existing arrays where a possible
1023 * spare is being added. However some super-handlers call it
1024 * internally from validate_geometry when creating an array.
1025 */
1026 __u64 (*avail_size)(struct supertype *st, __u64 size,
1027 unsigned long long data_offset);
1028 /*
1029 * Return spare criteria for array:
1030 * - minimum disk size can be used in array;
1031 * - sector size can be used in array.
1032 * Return values: 0 - for success and -EINVAL on error.
1033 */
1034 int (*get_spare_criteria)(struct supertype *st,
1035 struct spare_criteria *sc);
1036 /* Find somewhere to put a bitmap - possibly auto-size it - and
1037 * update the metadata to record this. The array may be newly
1038 * created, in which case data_size may be updated, or it might
1039 * already exist. Metadata handler can know if init_super
1040 * has been called, but not write_init_super.
1041 * 0: Success
1042 * -Exxxx: On error
1043 */
1044 int (*add_internal_bitmap)(struct supertype *st, int *chunkp,
1045 int delay, int write_behind,
1046 unsigned long long size, int may_change, int major);
1047 /* Perform additional setup required to activate a bitmap.
1048 */
1049 int (*set_bitmap)(struct supertype *st, struct mdinfo *info);
1050 /* Seek 'fd' to start of write-intent-bitmap. Must be an
1051 * md-native format bitmap
1052 */
1053 int (*locate_bitmap)(struct supertype *st, int fd, int node_num);
1054 /* if add_internal_bitmap succeeded for existing array, this
1055 * writes it out.
1056 */
1057 int (*write_bitmap)(struct supertype *st, int fd, enum bitmap_update update);
1058 /* Free the superblock and any other allocated data */
1059 void (*free_super)(struct supertype *st);
1060
1061 /* validate_geometry is called with an st returned by
1062 * match_metadata_desc.
1063 * It should check that the geometry described is compatible with
1064 * the metadata type. It will be called repeatedly as devices
1065 * added to validate changing size and new devices. If there are
1066 * inter-device dependencies, it should record sufficient details
1067 * so these can be validated.
1068 * Both 'size' and '*freesize' are in sectors. chunk is KiB.
1069 * Return value is:
1070 * 1: everything is OK
1071 * 0: not OK for some reason - if 'verbose', then error was reported.
1072 * -1: st->sb was NULL, 'subdev' is a member of a container of this
1073 * type, but array is not acceptable for some reason
1074 * message was reported even if verbose is 0.
1075 */
1076 int (*validate_geometry)(struct supertype *st, int level, int layout,
1077 int raiddisks,
1078 int *chunk, unsigned long long size,
1079 unsigned long long data_offset,
1080 char *subdev, unsigned long long *freesize,
1081 int consistency_policy, int verbose);
1082
1083 /* Return a linked list of 'mdinfo' structures for all arrays
1084 * in the container. For non-containers, it is like
1085 * getinfo_super with an allocated mdinfo.*/
1086 struct mdinfo *(*container_content)(struct supertype *st, char *subarray);
1087 /* query the supertype for default geometry */
1088 void (*default_geometry)(struct supertype *st, int *level, int *layout, int *chunk); /* optional */
1089 /* Permit subarray's to be deleted from inactive containers */
1090 int (*kill_subarray)(struct supertype *st,
1091 char *subarray_id); /* optional */
1092 /* Permit subarray's to be modified */
1093 int (*update_subarray)(struct supertype *st, char *subarray,
1094 char *update, struct mddev_ident *ident); /* optional */
1095 /* Check if reshape is supported for this external format.
1096 * st is obtained from super_by_fd() where st->subarray[0] is
1097 * initialized to indicate if reshape is being performed at the
1098 * container or subarray level
1099 */
1100 #define APPLY_METADATA_CHANGES 1
1101 #define ROLLBACK_METADATA_CHANGES 0
1102
1103 int (*reshape_super)(struct supertype *st,
1104 unsigned long long size, int level,
1105 int layout, int chunksize, int raid_disks,
1106 int delta_disks, char *backup, char *dev,
1107 int direction,
1108 int verbose); /* optional */
1109 int (*manage_reshape)( /* optional */
1110 int afd, struct mdinfo *sra, struct reshape *reshape,
1111 struct supertype *st, unsigned long blocks,
1112 int *fds, unsigned long long *offsets,
1113 int dests, int *destfd, unsigned long long *destoffsets);
1114
1115 /* for mdmon */
1116 int (*open_new)(struct supertype *c, struct active_array *a,
1117 int inst);
1118
1119 /* Tell the metadata handler the current state of the array.
1120 * This covers whether it is known to be consistent (no pending writes)
1121 * and how far along a resync is known to have progressed
1122 * (in a->resync_start).
1123 * resync status is really irrelevant if the array is not consistent,
1124 * but some metadata (DDF!) have a place to record the distinction.
1125 * If 'consistent' is '2', then the array can mark it dirty if a
1126 * resync/recovery/whatever is required, or leave it clean if not.
1127 * Return value is 0 dirty (not consistent) and 1 if clean.
1128 * it is only really important if consistent is passed in as '2'.
1129 */
1130 int (*set_array_state)(struct active_array *a, int consistent);
1131
1132 /* When the state of a device might have changed, we call set_disk to
1133 * tell the metadata what the current state is.
1134 * Typically this happens on spare->in_sync and (spare|in_sync)->faulty
1135 * transitions.
1136 * set_disk might be called when the state of the particular disk has
1137 * not in fact changed.
1138 */
1139 void (*set_disk)(struct active_array *a, int n, int state);
1140 void (*sync_metadata)(struct supertype *st);
1141 void (*process_update)(struct supertype *st,
1142 struct metadata_update *update);
1143 /* Prepare updates allocates extra memory that might be
1144 * needed. If the update cannot be understood, return 0.
1145 */
1146 int (*prepare_update)(struct supertype *st,
1147 struct metadata_update *update);
1148
1149 /* activate_spare will check if the array is degraded and, if it
1150 * is, try to find some spare space in the container.
1151 * On success, it add appropriate updates (For process_update) to
1152 * to the 'updates' list and returns a list of 'mdinfo' identifying
1153 * the device, or devices as there might be multiple missing
1154 * devices and multiple spares available.
1155 */
1156 struct mdinfo *(*activate_spare)(struct active_array *a,
1157 struct metadata_update **updates);
1158 /*
1159 * Return statically allocated string that represents metadata specific
1160 * controller domain of the disk. The domain is used in disk domain
1161 * matching functions. Disks belong to the same domain if the they have
1162 * the same domain from mdadm.conf and belong the same metadata domain.
1163 * Returning NULL or not providing this handler means that metadata
1164 * does not distinguish the differences between disks that belong to
1165 * different controllers. They are in the domain specified by
1166 * configuration file (mdadm.conf).
1167 * In case when the metadata has the notion of domains based on disk
1168 * it shall return NULL for disks that do not belong to the controller
1169 * the supported domains. Such disks will form another domain and won't
1170 * be mixed with supported ones.
1171 */
1172 const char *(*get_disk_controller_domain)(const char *path);
1173
1174 /* for external backup area */
1175 int (*recover_backup)(struct supertype *st, struct mdinfo *info);
1176
1177 /* validate container after assemble */
1178 int (*validate_container)(struct mdinfo *info);
1179
1180 /* write initial empty PPL on device */
1181 int (*write_init_ppl)(struct supertype *st, struct mdinfo *info, int fd);
1182
1183 /* validate ppl before assemble */
1184 int (*validate_ppl)(struct supertype *st, struct mdinfo *info,
1185 struct mdinfo *disk);
1186
1187 /* records new bad block in metadata */
1188 int (*record_bad_block)(struct active_array *a, int n,
1189 unsigned long long sector, int length);
1190
1191 /* clears bad block from metadata */
1192 int (*clear_bad_block)(struct active_array *a, int n,
1193 unsigned long long sector, int length);
1194
1195 /* get list of bad blocks from metadata */
1196 struct md_bb *(*get_bad_blocks)(struct active_array *a, int n);
1197
1198 int swapuuid; /* true if uuid is bigending rather than hostendian */
1199 int external;
1200 const char *name; /* canonical metadata name */
1201 } *superlist[];
1202
1203 extern struct superswitch super0, super1;
1204 extern struct superswitch super_imsm, super_ddf;
1205 extern struct superswitch mbr, gpt;
1206
1207 struct metadata_update {
1208 int len;
1209 char *buf;
1210 void *space; /* allocated space that monitor will use */
1211 void **space_list; /* list of allocated spaces that monitor can
1212 * use or that it returned.
1213 */
1214 struct metadata_update *next;
1215 };
1216
1217 /* A supertype holds a particular collection of metadata.
1218 * It identifies the metadata type by the superswitch, and the particular
1219 * sub-version of that metadata type.
1220 * metadata read in or created is stored in 'sb' and 'info'.
1221 * There are also fields used by mdmon to track containers.
1222 *
1223 * A supertype may refer to:
1224 * Just an array, possibly in a container
1225 * A container, not identifying any particular array
1226 * Info read from just one device, not yet fully describing the array/container.
1227 *
1228 *
1229 * A supertype is created by:
1230 * super_by_fd
1231 * guess_super
1232 * dup_super
1233 */
1234 struct supertype {
1235 struct superswitch *ss;
1236 int minor_version;
1237 int max_devs;
1238 char container_devnm[32]; /* devnm of container */
1239 void *sb;
1240 void *info;
1241 void *other; /* Hack used to convert v0.90 to v1.0 */
1242 unsigned long long devsize;
1243 unsigned long long data_offset; /* used by v1.x only */
1244 int ignore_hw_compat; /* used to inform metadata handlers that it should ignore
1245 HW/firmware related incompatability to load metadata.
1246 Used when examining metadata to display content of disk
1247 when user has no hw/firmare compatible system.
1248 */
1249 struct metadata_update *updates;
1250 struct metadata_update **update_tail;
1251
1252 /* extra stuff used by mdmon */
1253 struct active_array *arrays;
1254 int sock; /* listen to external programs */
1255 char devnm[32]; /* e.g. md0. This appears in metadata_version:
1256 * external:/md0/12
1257 */
1258 int devcnt;
1259 int retry_soon;
1260 int nodes;
1261 char *cluster_name;
1262
1263 struct mdinfo *devs;
1264
1265 };
1266
1267 extern struct supertype *super_by_fd(int fd, char **subarray);
1268 enum guess_types { guess_any, guess_array, guess_partitions };
1269 extern struct supertype *guess_super_type(int fd, enum guess_types guess_type);
1270 static inline struct supertype *guess_super(int fd) {
1271 return guess_super_type(fd, guess_any);
1272 }
1273 extern struct supertype *dup_super(struct supertype *st);
1274 extern int get_dev_size(int fd, char *dname, unsigned long long *sizep);
1275 extern int get_dev_sector_size(int fd, char *dname, unsigned int *sectsizep);
1276 extern int must_be_container(int fd);
1277 extern int dev_size_from_id(dev_t id, unsigned long long *size);
1278 extern int dev_sector_size_from_id(dev_t id, unsigned int *size);
1279 void wait_for(char *dev, int fd);
1280
1281 /*
1282 * Data structures for policy management.
1283 * Each device can have a policy structure that lists
1284 * various name/value pairs each possibly with a metadata associated.
1285 * The policy list is sorted by name/value/metadata
1286 */
1287 struct dev_policy {
1288 struct dev_policy *next;
1289 char *name; /* None of these strings are allocated. They are
1290 * all just references to strings which are known
1291 * to exist elsewhere.
1292 * name and metadata can be compared by address equality.
1293 */
1294 const char *metadata;
1295 const char *value;
1296 };
1297
1298 extern char pol_act[], pol_domain[], pol_metadata[], pol_auto[];
1299
1300 /* iterate over the sublist starting at list, having the same
1301 * 'name' as 'list', and matching the given metadata (Where
1302 * NULL matches anything
1303 */
1304 #define pol_for_each(item, list, _metadata) \
1305 for (item = list; \
1306 item && item->name == list->name; \
1307 item = item->next) \
1308 if (!(!_metadata || !item->metadata || _metadata == item->metadata)) \
1309 ; else
1310
1311 /*
1312 * policy records read from mdadm are largely just name-value pairs.
1313 * The names are constants, not strdupped
1314 */
1315 struct pol_rule {
1316 struct pol_rule *next;
1317 char *type; /* rule_policy or rule_part */
1318 struct rule {
1319 struct rule *next;
1320 char *name;
1321 char *value;
1322 char *dups; /* duplicates of 'value' with a partNN appended */
1323 } *rule;
1324 };
1325
1326 extern char rule_policy[], rule_part[];
1327 extern char rule_path[], rule_type[];
1328 extern char type_part[], type_disk[];
1329
1330 extern void policyline(char *line, char *type);
1331 extern void policy_add(char *type, ...);
1332 extern void policy_free(void);
1333
1334 extern struct dev_policy *path_policy(char **paths, char *type);
1335 extern struct dev_policy *disk_policy(struct mdinfo *disk);
1336 extern struct dev_policy *devid_policy(int devid);
1337 extern void dev_policy_free(struct dev_policy *p);
1338
1339 //extern void pol_new(struct dev_policy **pol, char *name, char *val, char *metadata);
1340 extern void pol_add(struct dev_policy **pol, char *name, char *val, char *metadata);
1341 extern struct dev_policy *pol_find(struct dev_policy *pol, char *name);
1342
1343 enum policy_action {
1344 act_default,
1345 act_include,
1346 act_re_add,
1347 act_spare, /* This only applies to bare devices */
1348 act_spare_same_slot, /* this allows non-bare devices,
1349 * but only if recent removal */
1350 act_force_spare, /* this allow non-bare devices in any case */
1351 act_err
1352 };
1353
1354 extern int policy_action_allows(struct dev_policy *plist, const char *metadata,
1355 enum policy_action want);
1356 extern int disk_action_allows(struct mdinfo *disk, const char *metadata,
1357 enum policy_action want);
1358
1359 struct domainlist {
1360 struct domainlist *next;
1361 const char *dom;
1362 };
1363
1364 extern int domain_test(struct domainlist *dom, struct dev_policy *pol,
1365 const char *metadata);
1366 extern struct domainlist *domain_from_array(struct mdinfo *mdi,
1367 const char *metadata);
1368 extern void domainlist_add_dev(struct domainlist **dom, int devid,
1369 const char *metadata);
1370 extern void domain_free(struct domainlist *dl);
1371 extern void domain_merge(struct domainlist **domp, struct dev_policy *pol,
1372 const char *metadata);
1373 void domain_add(struct domainlist **domp, char *domain);
1374
1375 extern void policy_save_path(char *id_path, struct map_ent *array);
1376 extern int policy_check_path(struct mdinfo *disk, struct map_ent *array);
1377
1378 extern void sysfs_rules_apply(char *devnm, struct mdinfo *dev);
1379 extern void sysfsline(char *line);
1380
1381 #if __GNUC__ < 3
1382 struct stat64;
1383 #endif
1384
1385 #define HAVE_NFTW we assume
1386 #define HAVE_FTW
1387
1388 #ifdef __UCLIBC__
1389 # include <features.h>
1390 # ifndef __UCLIBC_HAS_LFS__
1391 # define lseek64 lseek
1392 # endif
1393 # ifndef __UCLIBC_HAS_FTW__
1394 # undef HAVE_FTW
1395 # undef HAVE_NFTW
1396 # endif
1397 #endif
1398
1399 #ifdef __dietlibc__
1400 # undef HAVE_NFTW
1401 #endif
1402
1403 #if defined(__KLIBC__)
1404 # undef HAVE_NFTW
1405 # undef HAVE_FTW
1406 #endif
1407
1408 #ifndef HAVE_NFTW
1409 # define FTW_PHYS 1
1410 # ifndef HAVE_FTW
1411 struct FTW {};
1412 # endif
1413 #endif
1414
1415 #ifdef HAVE_FTW
1416 # include <ftw.h>
1417 #endif
1418
1419 extern int add_dev(const char *name, const struct stat *stb, int flag, struct FTW *s);
1420
1421 extern int Manage_ro(char *devname, int fd, int readonly);
1422 extern int Manage_run(char *devname, int fd, struct context *c);
1423 extern int Manage_stop(char *devname, int fd, int quiet,
1424 int will_retry);
1425 extern int Manage_subdevs(char *devname, int fd,
1426 struct mddev_dev *devlist, int verbose, int test,
1427 char *update, int force);
1428 extern int autodetect(void);
1429 extern int Grow_Add_device(char *devname, int fd, char *newdev);
1430 extern int Grow_addbitmap(char *devname, int fd,
1431 struct context *c, struct shape *s);
1432 extern int Grow_reshape(char *devname, int fd,
1433 struct mddev_dev *devlist,
1434 unsigned long long data_offset,
1435 struct context *c, struct shape *s);
1436 extern int Grow_restart(struct supertype *st, struct mdinfo *info,
1437 int *fdlist, int cnt, char *backup_file, int verbose);
1438 extern int Grow_continue(int mdfd, struct supertype *st,
1439 struct mdinfo *info, char *backup_file,
1440 int forked, int freeze_reshape);
1441 extern int Grow_consistency_policy(char *devname, int fd,
1442 struct context *c, struct shape *s);
1443
1444 extern int restore_backup(struct supertype *st,
1445 struct mdinfo *content,
1446 int working_disks,
1447 int spares,
1448 char **backup_filep,
1449 int verbose);
1450 extern int Grow_continue_command(char *devname, int fd,
1451 char *backup_file, int verbose);
1452
1453 extern int Assemble(struct supertype *st, char *mddev,
1454 struct mddev_ident *ident,
1455 struct mddev_dev *devlist,
1456 struct context *c);
1457
1458 extern int Build(char *mddev, struct mddev_dev *devlist,
1459 struct shape *s, struct context *c);
1460
1461 extern int Create(struct supertype *st, char *mddev,
1462 char *name, int *uuid,
1463 int subdevs, struct mddev_dev *devlist,
1464 struct shape *s,
1465 struct context *c,
1466 unsigned long long data_offset);
1467
1468 extern int Detail(char *dev, struct context *c);
1469 extern int Detail_Platform(struct superswitch *ss, int scan, int verbose, int export, char *controller_path);
1470 extern int Query(char *dev);
1471 extern int ExamineBadblocks(char *devname, int brief, struct supertype *forcest);
1472 extern int Examine(struct mddev_dev *devlist, struct context *c,
1473 struct supertype *forcest);
1474 extern int Monitor(struct mddev_dev *devlist,
1475 char *mailaddr, char *alert_cmd,
1476 struct context *c,
1477 int daemonise, int oneshot,
1478 int dosyslog, char *pidfile, int increments,
1479 int share);
1480
1481 extern int Kill(char *dev, struct supertype *st, int force, int verbose, int noexcl);
1482 extern int Kill_subarray(char *dev, char *subarray, int verbose);
1483 extern int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident *ident, int quiet);
1484 extern int Wait(char *dev);
1485 extern int WaitClean(char *dev, int verbose);
1486 extern int SetAction(char *dev, char *action);
1487
1488 extern int Incremental(struct mddev_dev *devlist, struct context *c,
1489 struct supertype *st);
1490 extern void RebuildMap(void);
1491 extern int IncrementalScan(struct context *c, char *devnm);
1492 extern int IncrementalRemove(char *devname, char *path, int verbose);
1493 extern int CreateBitmap(char *filename, int force, char uuid[16],
1494 unsigned long chunksize, unsigned long daemon_sleep,
1495 unsigned long write_behind,
1496 unsigned long long array_size,
1497 int major);
1498 extern int ExamineBitmap(char *filename, int brief, struct supertype *st);
1499 extern int IsBitmapDirty(char *filename);
1500 extern int Write_rules(char *rule_name);
1501 extern int bitmap_update_uuid(int fd, int *uuid, int swap);
1502
1503 /* calculate the size of the bitmap given the array size and bitmap chunksize */
1504 static inline unsigned long long
1505 bitmap_bits(unsigned long long array_size, unsigned long chunksize)
1506 {
1507 return (array_size * 512 + chunksize - 1) / chunksize;
1508 }
1509
1510 extern int Dump_metadata(char *dev, char *dir, struct context *c,
1511 struct supertype *st);
1512 extern int Restore_metadata(char *dev, char *dir, struct context *c,
1513 struct supertype *st, int only);
1514
1515 int md_array_valid(int fd);
1516 int md_array_active(int fd);
1517 int md_array_is_active(struct mdinfo *info);
1518 int md_get_array_info(int fd, struct mdu_array_info_s *array);
1519 int md_set_array_info(int fd, struct mdu_array_info_s *array);
1520 int md_get_disk_info(int fd, struct mdu_disk_info_s *disk);
1521 extern int get_linux_version(void);
1522 extern int mdadm_version(char *version);
1523 extern unsigned long long parse_size(char *size);
1524 extern int parse_uuid(char *str, int uuid[4]);
1525 int default_layout(struct supertype *st, int level, int verbose);
1526 extern int is_near_layout_10(int layout);
1527 extern int parse_layout_10(char *layout);
1528 extern int parse_layout_faulty(char *layout);
1529 extern int parse_num(int *dest, char *num);
1530 extern int parse_cluster_confirm_arg(char *inp, char **devname, int *slot);
1531 extern int check_ext2(int fd, char *name);
1532 extern int check_reiser(int fd, char *name);
1533 extern int check_raid(int fd, char *name);
1534 extern int check_partitions(int fd, char *dname,
1535 unsigned long long freesize,
1536 unsigned long long size);
1537 extern int fstat_is_blkdev(int fd, char *devname, dev_t *rdev);
1538 extern int stat_is_blkdev(char *devname, dev_t *rdev);
1539
1540 extern bool is_dev_alive(char *path);
1541 extern int get_mdp_major(void);
1542 extern int get_maj_min(char *dev, int *major, int *minor);
1543 extern int dev_open(char *dev, int flags);
1544 extern int open_dev(char *devnm);
1545 extern void reopen_mddev(int mdfd);
1546 extern int open_dev_flags(char *devnm, int flags);
1547 extern int open_dev_excl(char *devnm);
1548 extern int is_standard(char *dev, int *nump);
1549 extern int same_dev(char *one, char *two);
1550 extern int compare_paths (char* path1,char* path2);
1551 extern void enable_fds(int devices);
1552 extern void manage_fork_fds(int close_all);
1553 extern int continue_via_systemd(char *devnm, char *service_name);
1554
1555 extern int parse_auto(char *str, char *msg, int config);
1556 extern struct mddev_ident *conf_get_ident(char *dev);
1557 extern struct mddev_dev *conf_get_devs(void);
1558 extern int conf_test_dev(char *devname);
1559 extern int conf_test_metadata(const char *version, struct dev_policy *pol, int is_homehost);
1560 extern struct createinfo *conf_get_create_info(void);
1561 extern void set_conffile(char *file);
1562 extern char *conf_get_mailaddr(void);
1563 extern char *conf_get_mailfrom(void);
1564 extern char *conf_get_program(void);
1565 extern char *conf_get_homehost(int *require_homehostp);
1566 extern char *conf_get_homecluster(void);
1567 extern int conf_get_monitor_delay(void);
1568 extern char *conf_line(FILE *file);
1569 extern char *conf_word(FILE *file, int allow_key);
1570 extern void print_quoted(char *str);
1571 extern void print_escape(char *str);
1572 extern int use_udev(void);
1573 extern unsigned long GCD(unsigned long a, unsigned long b);
1574 extern int conf_name_is_free(char *name);
1575 extern int conf_verify_devnames(struct mddev_ident *array_list);
1576 extern int devname_matches(char *name, char *match);
1577 extern struct mddev_ident *conf_match(struct supertype *st,
1578 struct mdinfo *info,
1579 char *devname,
1580 int verbose, int *rvp);
1581
1582 extern void free_line(char *line);
1583 extern int match_oneof(char *devices, char *devname);
1584 extern void uuid_from_super(int uuid[4], mdp_super_t *super);
1585 extern const int uuid_zero[4];
1586 extern int same_uuid(int a[4], int b[4], int swapuuid);
1587 extern void copy_uuid(void *a, int b[4], int swapuuid);
1588 extern char *__fname_from_uuid(int id[4], int swap, char *buf, char sep);
1589 extern char *fname_from_uuid(struct supertype *st,
1590 struct mdinfo *info, char *buf, char sep);
1591 extern unsigned long calc_csum(void *super, int bytes);
1592 extern int enough(int level, int raid_disks, int layout, int clean,
1593 char *avail);
1594 extern int ask(char *mesg);
1595 extern unsigned long long get_component_size(int fd);
1596 extern void remove_partitions(int fd);
1597 extern int test_partition(int fd);
1598 extern int test_partition_from_id(dev_t id);
1599 extern int get_data_disks(int level, int layout, int raid_disks);
1600 extern unsigned long long calc_array_size(int level, int raid_disks, int layout,
1601 int chunksize, unsigned long long devsize);
1602 extern int flush_metadata_updates(struct supertype *st);
1603 extern void append_metadata_update(struct supertype *st, void *buf, int len);
1604 extern int assemble_container_content(struct supertype *st, int mdfd,
1605 struct mdinfo *content,
1606 struct context *c,
1607 char *chosen_name, int *result);
1608 #define INCR_NO 1
1609 #define INCR_UNSAFE 2
1610 #define INCR_ALREADY 4
1611 #define INCR_YES 8
1612 extern struct mdinfo *container_choose_spares(struct supertype *st,
1613 struct spare_criteria *criteria,
1614 struct domainlist *domlist,
1615 char *spare_group,
1616 const char *metadata, int get_one);
1617 extern int move_spare(char *from_devname, char *to_devname, dev_t devid);
1618 extern int add_disk(int mdfd, struct supertype *st,
1619 struct mdinfo *sra, struct mdinfo *info);
1620 extern int remove_disk(int mdfd, struct supertype *st,
1621 struct mdinfo *sra, struct mdinfo *info);
1622 extern int hot_remove_disk(int mdfd, unsigned long dev, int force);
1623 extern int sys_hot_remove_disk(int statefd, int force);
1624 extern int set_array_info(int mdfd, struct supertype *st, struct mdinfo *info);
1625 unsigned long long min_recovery_start(struct mdinfo *array);
1626
1627 extern char *human_size(long long bytes);
1628 extern char *human_size_brief(long long bytes, int prefix);
1629 extern void print_r10_layout(int layout);
1630
1631 extern char *find_free_devnm(int use_partitions);
1632
1633 extern void put_md_name(char *name);
1634 extern char *devid2kname(dev_t devid);
1635 extern char *devid2devnm(dev_t devid);
1636 extern dev_t devnm2devid(char *devnm);
1637 extern char *get_md_name(char *devnm);
1638
1639 extern char DefaultConfFile[];
1640
1641 extern int create_mddev(char *dev, char *name, int autof, int trustworthy,
1642 char *chosen, int block_udev);
1643 /* values for 'trustworthy' */
1644 #define LOCAL 1
1645 #define LOCAL_ANY 10
1646 #define FOREIGN 2
1647 #define METADATA 3
1648 extern int open_mddev(char *dev, int report_errors);
1649 extern int is_mddev(char *dev);
1650 extern int open_container(int fd);
1651 extern int metadata_container_matches(char *metadata, char *devnm);
1652 extern int metadata_subdev_matches(char *metadata, char *devnm);
1653 extern int is_container_member(struct mdstat_ent *ent, char *devname);
1654 extern int is_subarray_active(char *subarray, char *devname);
1655 extern int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet);
1656 extern struct superswitch *version_to_superswitch(char *vers);
1657
1658 extern int mdmon_running(char *devnm);
1659 extern int mdmon_pid(char *devnm);
1660 extern int check_env(char *name);
1661 extern __u32 random32(void);
1662 extern void random_uuid(__u8 *buf);
1663 extern int start_mdmon(char *devnm);
1664
1665 extern int child_monitor(int afd, struct mdinfo *sra, struct reshape *reshape,
1666 struct supertype *st, unsigned long stripes,
1667 int *fds, unsigned long long *offsets,
1668 int dests, int *destfd, unsigned long long *destoffsets);
1669 void abort_reshape(struct mdinfo *sra);
1670
1671 void *super1_make_v0(struct supertype *st, struct mdinfo *info, mdp_super_t *sb0);
1672
1673 extern char *stat2kname(struct stat *st);
1674 extern char *fd2kname(int fd);
1675 extern char *stat2devnm(struct stat *st);
1676 extern char *fd2devnm(int fd);
1677 extern void udev_block(char *devnm);
1678 extern void udev_unblock(void);
1679
1680 extern int in_initrd(void);
1681
1682 struct cmap_hooks {
1683 void *cmap_handle; /* corosync lib related */
1684
1685 int (*initialize)(cmap_handle_t *handle);
1686 int (*get_string)(cmap_handle_t handle,
1687 const char *string,
1688 char **name);
1689 int (*finalize)(cmap_handle_t handle);
1690 };
1691
1692 extern void set_cmap_hooks(void);
1693 extern void set_hooks(void);
1694
1695 struct dlm_hooks {
1696 void *dlm_handle; /* dlm lib related */
1697
1698 dlm_lshandle_t (*create_lockspace)(const char *name,
1699 unsigned int mode);
1700 dlm_lshandle_t (*open_lockspace)(const char *name);
1701 int (*release_lockspace)(const char *name, dlm_lshandle_t ls,
1702 int force);
1703 int (*ls_lock)(dlm_lshandle_t lockspace, uint32_t mode,
1704 struct dlm_lksb *lksb, uint32_t flags,
1705 const void *name, unsigned int namelen,
1706 uint32_t parent, void (*astaddr) (void *astarg),
1707 void *astarg, void (*bastaddr) (void *astarg),
1708 void *range);
1709 int (*ls_unlock_wait)(dlm_lshandle_t lockspace, uint32_t lkid,
1710 uint32_t flags, struct dlm_lksb *lksb);
1711 int (*ls_get_fd)(dlm_lshandle_t ls);
1712 int (*dispatch)(int fd);
1713 };
1714
1715 extern int get_cluster_name(char **name);
1716 extern int dlm_funs_ready(void);
1717 extern int cluster_get_dlmlock(void);
1718 extern int cluster_release_dlmlock(void);
1719 extern void set_dlm_hooks(void);
1720
1721 #define MSEC_TO_NSEC(msec) ((msec) * 1000000)
1722 #define USEC_TO_NSEC(usec) ((usec) * 1000)
1723 extern void sleep_for(unsigned int sec, long nsec, bool wake_after_interrupt);
1724
1725 #define _ROUND_UP(val, base) (((val) + (base) - 1) & ~(base - 1))
1726 #define ROUND_UP(val, base) _ROUND_UP(val, (typeof(val))(base))
1727 #define ROUND_UP_PTR(ptr, base) ((typeof(ptr)) \
1728 (ROUND_UP((unsigned long)(ptr), base)))
1729
1730 static inline int is_subarray(char *vers)
1731 {
1732 /* The version string for a 'subarray' (an array in a container)
1733 * is
1734 * /containername/componentname for normal read-write arrays
1735 * -containername/componentname for arrays which mdmon must not
1736 * reconfigure. They might be read-only
1737 * or might be undergoing reshape etc.
1738 * containername is e.g. md0, md_d1
1739 * componentname is dependant on the metadata. e.g. '1' 'S1' ...
1740 */
1741 return (*vers == '/' || *vers == '-');
1742 }
1743
1744 static inline char *to_subarray(struct mdstat_ent *ent, char *container)
1745 {
1746 return &ent->metadata_version[10+strlen(container)+1];
1747 }
1748
1749 /**
1750 * signal_s() - Wrapper for sigaction() with signal()-like interface.
1751 * @sig: The signal to set the signal handler to.
1752 * @handler: The signal handler.
1753 *
1754 * Return: previous handler or SIG_ERR on failure.
1755 */
1756 static inline sighandler_t signal_s(int sig, sighandler_t handler)
1757 {
1758 struct sigaction new_act;
1759 struct sigaction old_act;
1760
1761 new_act.sa_handler = handler;
1762 new_act.sa_flags = 0;
1763
1764 if (sigaction(sig, &new_act, &old_act) == 0)
1765 return old_act.sa_handler;
1766
1767 return SIG_ERR;
1768 }
1769
1770 #ifdef DEBUG
1771 #define dprintf(fmt, arg...) \
1772 fprintf(stderr, "%s: %s: "fmt, Name, __func__, ##arg)
1773 #define dprintf_cont(fmt, arg...) \
1774 fprintf(stderr, fmt, ##arg)
1775 #else
1776 #define dprintf(fmt, arg...) \
1777 ({ if (0) fprintf(stderr, "%s: %s: " fmt, Name, __func__, ##arg); 0; })
1778 #define dprintf_cont(fmt, arg...) \
1779 ({ if (0) fprintf(stderr, fmt, ##arg); 0; })
1780 #endif
1781 #include <assert.h>
1782 #include <stdarg.h>
1783 static inline int xasprintf(char **strp, const char *fmt, ...) {
1784 va_list ap;
1785 int ret;
1786 va_start(ap, fmt);
1787 ret = vasprintf(strp, fmt, ap);
1788 va_end(ap);
1789 assert(ret >= 0);
1790 return ret;
1791 }
1792
1793 #ifdef DEBUG
1794 #define pr_err(fmt, args...) fprintf(stderr, "%s: %s: "fmt, Name, __func__, ##args)
1795 #else
1796 #define pr_err(fmt, args...) fprintf(stderr, "%s: "fmt, Name, ##args)
1797 #endif
1798 #define cont_err(fmt ...) fprintf(stderr, " " fmt)
1799
1800 void *xmalloc(size_t len);
1801 void *xrealloc(void *ptr, size_t len);
1802 void *xcalloc(size_t num, size_t size);
1803 char *xstrdup(const char *str);
1804
1805 #define LEVEL_MULTIPATH (-4)
1806 #define LEVEL_LINEAR (-1)
1807 #define LEVEL_FAULTY (-5)
1808
1809 /* kernel module doesn't know about these */
1810 #define LEVEL_CONTAINER (-100)
1811 #define LEVEL_UNSUPPORTED (-200)
1812
1813 /* the kernel does know about this one ... */
1814 #define LEVEL_NONE (-1000000)
1815
1816 /* faulty stuff */
1817
1818 #define WriteTransient 0
1819 #define ReadTransient 1
1820 #define WritePersistent 2
1821 #define ReadPersistent 3
1822 #define WriteAll 4 /* doesn't go to device */
1823 #define ReadFixable 5
1824 #define Modes 6
1825
1826 #define ClearErrors 31
1827 #define ClearFaults 30
1828
1829 #define AllPersist 100 /* internal use only */
1830 #define NoPersist 101
1831
1832 #define ModeMask 0x1f
1833 #define ModeShift 5
1834
1835 #ifdef __TINYC__
1836 #undef minor
1837 #undef major
1838 #undef makedev
1839 #define minor(x) ((x)&0xff)
1840 #define major(x) (((x)>>8)&0xff)
1841 #define makedev(M,m) (((M)<<8) | (m))
1842 #endif
1843
1844 enum r0layout {
1845 RAID0_ORIG_LAYOUT = 1,
1846 RAID0_ALT_MULTIZONE_LAYOUT = 2,
1847 };
1848
1849 /* for raid4/5/6 */
1850 #define ALGORITHM_LEFT_ASYMMETRIC 0
1851 #define ALGORITHM_RIGHT_ASYMMETRIC 1
1852 #define ALGORITHM_LEFT_SYMMETRIC 2
1853 #define ALGORITHM_RIGHT_SYMMETRIC 3
1854
1855 /* Define non-rotating (raid4) algorithms. These allow
1856 * conversion of raid4 to raid5.
1857 */
1858 #define ALGORITHM_PARITY_0 4 /* P or P,Q are initial devices */
1859 #define ALGORITHM_PARITY_N 5 /* P or P,Q are final devices. */
1860
1861 /* DDF RAID6 layouts differ from md/raid6 layouts in two ways.
1862 * Firstly, the exact positioning of the parity block is slightly
1863 * different between the 'LEFT_*' modes of md and the "_N_*" modes
1864 * of DDF.
1865 * Secondly, or order of datablocks over which the Q syndrome is computed
1866 * is different.
1867 * Consequently we have different layouts for DDF/raid6 than md/raid6.
1868 * These layouts are from the DDFv1.2 spec.
1869 * Interestingly DDFv1.2-Errata-A does not specify N_CONTINUE but
1870 * leaves RLQ=3 as 'Vendor Specific'
1871 */
1872
1873 #define ALGORITHM_ROTATING_ZERO_RESTART 8 /* DDF PRL=6 RLQ=1 */
1874 #define ALGORITHM_ROTATING_N_RESTART 9 /* DDF PRL=6 RLQ=2 */
1875 #define ALGORITHM_ROTATING_N_CONTINUE 10 /*DDF PRL=6 RLQ=3 */
1876
1877 /* For every RAID5 algorithm we define a RAID6 algorithm
1878 * with exactly the same layout for data and parity, and
1879 * with the Q block always on the last device (N-1).
1880 * This allows trivial conversion from RAID5 to RAID6
1881 */
1882 #define ALGORITHM_LEFT_ASYMMETRIC_6 16
1883 #define ALGORITHM_RIGHT_ASYMMETRIC_6 17
1884 #define ALGORITHM_LEFT_SYMMETRIC_6 18
1885 #define ALGORITHM_RIGHT_SYMMETRIC_6 19
1886 #define ALGORITHM_PARITY_0_6 20
1887 #define ALGORITHM_PARITY_N_6 ALGORITHM_PARITY_N
1888
1889 /* Define PATH_MAX in case we don't use glibc or standard library does
1890 * not have PATH_MAX defined. Assume max path length is 4K characters.
1891 */
1892 #ifndef PATH_MAX
1893 #define PATH_MAX 4096
1894 #endif
1895
1896 #define RESYNC_NONE -1
1897 #define RESYNC_DELAYED -2
1898 #define RESYNC_PENDING -3
1899 #define RESYNC_REMOTE -4
1900 #define RESYNC_UNKNOWN -5
1901
1902 /* When using "GET_DISK_INFO" it isn't certain how high
1903 * we need to check. So we impose an absolute limit of
1904 * MAX_DISKS. This needs to be much more than the largest
1905 * number of devices any metadata can support. Currently
1906 * v1.x can support 1920
1907 */
1908 #define MAX_DISKS 4096
1909
1910 /* Sometimes the 'size' value passed needs to mean "Maximum".
1911 * In those cases with use MAX_SIZE
1912 */
1913 #define MAX_SIZE 1
1914
1915 /* We want to use unsigned numbers for sector counts, but need
1916 * a value for 'invalid'. Use '1'.
1917 */
1918 #define INVALID_SECTORS 1
1919 /* And another special number needed for --data_offset=variable */
1920 #define VARIABLE_OFFSET 3
1921
1922 /**
1923 * This is true for native and DDF, IMSM allows 16.
1924 */
1925 #define MD_NAME_MAX 32