]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdadm.h
sysfs: Avoid if and return on the same line
[thirdparty/mdadm.git] / mdadm.h
diff --git a/mdadm.h b/mdadm.h
old mode 100644 (file)
new mode 100755 (executable)
index 5633663..1fd38a3
--- a/mdadm.h
+++ b/mdadm.h
@@ -35,6 +35,7 @@ extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
 
 #include       <sys/types.h>
 #include       <sys/stat.h>
+#include       <stdint.h>
 #include       <stdlib.h>
 #include       <time.h>
 #include       <sys/time.h>
@@ -51,6 +52,31 @@ extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
 #define srandom srand
 #endif
 
+#ifdef NO_COROSYNC
+#define CS_OK 1
+typedef uint64_t cmap_handle_t;
+#else
+#include       <corosync/cmap.h>
+#endif
+
+#ifndef NO_DLM
+#include       <libdlm.h>
+#include       <errno.h>
+#else
+#define LKF_NOQUEUE    0x00000001
+#define LKM_PWMODE     4
+#define EUNLOCK                0x10002
+
+typedef void *dlm_lshandle_t;
+
+struct dlm_lksb {
+       int sb_status;
+       uint32_t sb_lkid;
+       char sb_flags;
+       char *sb_lvbptr;
+};
+#endif
+
 #include       <linux/kdev_t.h>
 /*#include     <linux/fs.h> */
 #include       <sys/mount.h>
@@ -112,20 +138,20 @@ extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
  * and there is no standard conversion function so... */
 /* And dietlibc doesn't think byteswap is ok, so.. */
 /*  #include <byteswap.h> */
-#define bswap_16(x) (((x) & 0x00ffU) << 8 | \
-                    ((x) & 0xff00U) >> 8)
-#define bswap_32(x) (((x) & 0x000000ffU) << 24 | \
-                    ((x) & 0xff000000U) >> 24 | \
-                    ((x) & 0x0000ff00U) << 8  | \
-                    ((x) & 0x00ff0000U) >> 8)
-#define bswap_64(x) (((x) & 0x00000000000000ffULL) << 56 | \
-                    ((x) & 0xff00000000000000ULL) >> 56 | \
-                    ((x) & 0x000000000000ff00ULL) << 40 | \
-                    ((x) & 0x00ff000000000000ULL) >> 40 | \
-                    ((x) & 0x0000000000ff0000ULL) << 24 | \
-                    ((x) & 0x0000ff0000000000ULL) >> 24 | \
-                    ((x) & 0x00000000ff000000ULL) << 8 | \
-                    ((x) & 0x000000ff00000000ULL) >> 8)
+#define __mdadm_bswap_16(x) (((x) & 0x00ffU) << 8 | \
+                            ((x) & 0xff00U) >> 8)
+#define __mdadm_bswap_32(x) (((x) & 0x000000ffU) << 24 | \
+                            ((x) & 0xff000000U) >> 24 | \
+                            ((x) & 0x0000ff00U) << 8  | \
+                            ((x) & 0x00ff0000U) >> 8)
+#define __mdadm_bswap_64(x) (((x) & 0x00000000000000ffULL) << 56 | \
+                            ((x) & 0xff00000000000000ULL) >> 56 | \
+                            ((x) & 0x000000000000ff00ULL) << 40 | \
+                            ((x) & 0x00ff000000000000ULL) >> 40 | \
+                            ((x) & 0x0000000000ff0000ULL) << 24 | \
+                            ((x) & 0x0000ff0000000000ULL) >> 24 | \
+                            ((x) & 0x00000000ff000000ULL) << 8 |  \
+                            ((x) & 0x000000ff00000000ULL) >> 8)
 
 #if !defined(__KLIBC__)
 #if BYTE_ORDER == LITTLE_ENDIAN
@@ -136,19 +162,19 @@ extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
 #define __le32_to_cpu(_x) (unsigned int)(_x)
 #define __le64_to_cpu(_x) (unsigned long long)(_x)
 
-#define        __cpu_to_be16(_x) bswap_16(_x)
-#define __cpu_to_be32(_x) bswap_32(_x)
-#define __cpu_to_be64(_x) bswap_64(_x)
-#define        __be16_to_cpu(_x) bswap_16(_x)
-#define __be32_to_cpu(_x) bswap_32(_x)
-#define __be64_to_cpu(_x) bswap_64(_x)
+#define        __cpu_to_be16(_x) __mdadm_bswap_16(_x)
+#define __cpu_to_be32(_x) __mdadm_bswap_32(_x)
+#define __cpu_to_be64(_x) __mdadm_bswap_64(_x)
+#define        __be16_to_cpu(_x) __mdadm_bswap_16(_x)
+#define __be32_to_cpu(_x) __mdadm_bswap_32(_x)
+#define __be64_to_cpu(_x) __mdadm_bswap_64(_x)
 #elif BYTE_ORDER == BIG_ENDIAN
-#define        __cpu_to_le16(_x) bswap_16(_x)
-#define __cpu_to_le32(_x) bswap_32(_x)
-#define __cpu_to_le64(_x) bswap_64(_x)
-#define        __le16_to_cpu(_x) bswap_16(_x)
-#define __le32_to_cpu(_x) bswap_32(_x)
-#define __le64_to_cpu(_x) bswap_64(_x)
+#define        __cpu_to_le16(_x) __mdadm_bswap_16(_x)
+#define __cpu_to_le32(_x) __mdadm_bswap_32(_x)
+#define __cpu_to_le64(_x) __mdadm_bswap_64(_x)
+#define        __le16_to_cpu(_x) __mdadm_bswap_16(_x)
+#define __le32_to_cpu(_x) __mdadm_bswap_32(_x)
+#define __le64_to_cpu(_x) __mdadm_bswap_64(_x)
 
 #define        __cpu_to_be16(_x) (unsigned int)(_x)
 #define __cpu_to_be32(_x) (unsigned int)(_x)
@@ -161,6 +187,31 @@ extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
 #endif
 #endif /* __KLIBC__ */
 
+/*
+  * Check at compile time that something is of a particular type.
+  * Always evaluates to 1 so you may use it easily in comparisons.
+*/
+
+#define typecheck(type,x) \
+({        type __dummy; \
+          typeof(x) __dummy2; \
+          (void)(&__dummy == &__dummy2); \
+          1; \
+})
+
+/*
+ *  These inlines deal with timer wrapping correctly.
+ *
+ * time_after(a,b) returns true if the time a is after time b.
+*/
+
+#define time_after(a,b)        \
+        (typecheck(unsigned int, a) && \
+         typecheck(unsigned int, b) && \
+         ((int)((b) - (a)) < 0))
+
+#define time_before(a,b)        time_after(b,a)
+
 /*
  * min()/max()/clamp() macros that also do
  * strict type-checking.. See the
@@ -210,6 +261,9 @@ struct mdinfo {
                                                   * for native metadata it is
                                                   * reshape_active field mirror
                                                   */
+       int journal_device_required;
+       int journal_clean;
+
        /* During reshape we can sometimes change the data_offset to avoid
         * over-writing still-valid data.  We need to know if there is space.
         * So getinfo_super will fill in space_before and space_after in sectors.
@@ -235,7 +289,7 @@ struct mdinfo {
        int container_enough; /* flag external handlers can set to
                               * indicate that subarrays have not enough (-1),
                               * enough to start (0), or all expected disks (1) */
-       char            sys_name[20];
+       char            sys_name[32];
        struct mdinfo *devs;
        struct mdinfo *next;
 
@@ -251,6 +305,8 @@ struct mdinfo {
        #define DS_UNBLOCK      2048
        int prev_state, curr_state, next_state;
 
+       /* info read from sysfs */
+       char            sysfs_array_state[20];
 };
 
 struct createinfo {
@@ -313,6 +369,7 @@ enum special_options {
        ManageOpt,
        Add,
        AddSpare,
+       AddJournal,
        Remove,
        Fail,
        Replace,
@@ -347,6 +404,7 @@ enum special_options {
        Nodes,
        ClusterName,
        ClusterConfirm,
+       WriteJournal,
 };
 
 enum prefix_standard {
@@ -434,6 +492,7 @@ struct context {
 struct shape {
        int     raiddisks;
        int     sparedisks;
+       int     journaldisks;
        int     level;
        int     layout;
        char    *layout_str;
@@ -532,6 +591,7 @@ enum sysfs_read_flags {
        GET_SIZE        = (1 << 22),
        GET_STATE       = (1 << 23),
        GET_ERROR       = (1 << 24),
+       GET_ARRAY_STATE = (1 << 25),
 };
 
 /* If fd >= 0, get the array it is open on,
@@ -571,7 +631,7 @@ extern int sysfs_disk_to_scsi_id(int fd, __u32 *id);
 extern int sysfs_unique_holder(char *devnm, long rdev);
 extern int sysfs_freeze_array(struct mdinfo *sra);
 extern int sysfs_wait(int fd, int *msec);
-extern int load_sys(char *path, char *buf);
+extern int load_sys(char *path, char *buf, int len);
 extern int reshape_prepare_fdlist(char *devname,
                                  struct mdinfo *sra,
                                  int raid_disks,
@@ -759,7 +819,8 @@ extern struct superswitch {
         *   readwrite - clear the WriteMostly1 bit in the superblock devflags
         *   no-bitmap - clear any record that a bitmap is present.
         *   bbl       - add a bad-block-log if possible
-        *   no-bbl    - remove and bad-block-log is it is empty.
+        *   no-bbl    - remove any bad-block-log is it is empty.
+        *   force-no-bbl - remove any bad-block-log even if empty.
         *   revert-reshape - If a reshape is in progress, modify metadata so
         *                    it will resume going in the opposite direction.
         */
@@ -835,6 +896,8 @@ extern struct superswitch {
         * created, in which case data_size may be updated, or it might
         * already exist.  Metadata handler can know if init_super
         * has been called, but not write_init_super.
+        *  0:     Success
+        * -Exxxx: On error
         */
        int (*add_internal_bitmap)(struct supertype *st, int *chunkp,
                                   int delay, int write_behind,
@@ -842,7 +905,7 @@ extern struct superswitch {
        /* Seek 'fd' to start of write-intent-bitmap.  Must be an
         * md-native format bitmap
         */
-       void (*locate_bitmap)(struct supertype *st, int fd);
+       int (*locate_bitmap)(struct supertype *st, int fd, int node_num);
        /* if add_internal_bitmap succeeded for existing array, this
         * writes it out.
         */
@@ -1377,8 +1440,8 @@ extern char *find_free_devnm(int use_partitions);
 
 extern void put_md_name(char *name);
 extern char *devid2kname(int devid);
-extern char *devid2devnm(int devid);
-extern int devnm2devid(char *devnm);
+extern char *devid2devnm(dev_t devid);
+extern dev_t devnm2devid(char *devnm);
 extern char *get_md_name(char *devnm);
 
 extern char DefaultConfFile[];
@@ -1413,12 +1476,51 @@ void abort_reshape(struct mdinfo *sra);
 
 void *super1_make_v0(struct supertype *st, struct mdinfo *info, mdp_super_t *sb0);
 
-extern void fmt_devname(char *name, int num);
+extern char *stat2kname(struct stat *st);
+extern char *fd2kname(int fd);
 extern char *stat2devnm(struct stat *st);
 extern char *fd2devnm(int fd);
 
 extern int in_initrd(void);
+
+struct cmap_hooks {
+       void *cmap_handle;      /* corosync lib related */
+
+       int (*initialize)(cmap_handle_t *handle);
+       int (*get_string)(cmap_handle_t handle,
+                         const char *string,
+                         char **name);
+       int (*finalize)(cmap_handle_t handle);
+};
+
+extern void set_cmap_hooks(void);
+extern void set_hooks(void);
+
+struct dlm_hooks {
+       void *dlm_handle;       /* dlm lib related */
+
+       dlm_lshandle_t (*create_lockspace)(const char *name,
+                                          unsigned int mode);
+       int (*release_lockspace)(const char *name, dlm_lshandle_t ls,
+                                int force);
+       int (*ls_lock)(dlm_lshandle_t lockspace, uint32_t mode,
+                      struct dlm_lksb *lksb, uint32_t flags,
+                      const void *name, unsigned int namelen,
+                      uint32_t parent, void (*astaddr) (void *astarg),
+                      void *astarg, void (*bastaddr) (void *astarg),
+                      void *range);
+       int (*ls_unlock)(dlm_lshandle_t lockspace, uint32_t lkid,
+                        uint32_t flags, struct dlm_lksb *lksb,
+                        void *astarg);
+       int (*ls_get_fd)(dlm_lshandle_t ls);
+       int (*dispatch)(int fd);
+};
+
 extern int get_cluster_name(char **name);
+extern int dlm_funs_ready(void);
+extern int cluster_get_dlmlock(int *lockid);
+extern int cluster_release_dlmlock(int lockid);
+extern void set_dlm_hooks(void);
 
 #define _ROUND_UP(val, base)   (((val) + (base) - 1) & ~(base - 1))
 #define ROUND_UP(val, base)    _ROUND_UP(val, (typeof(val))(base))