* [RFC/PATCH 0/6] DDF: safe big-endian types
@ 2013-07-21 17:28 mwilck
2013-07-21 17:28 ` [PATCH 1/6] DDF: add endian-safe typedefs mwilck
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: mwilck @ 2013-07-21 17:28 UTC (permalink / raw)
To: neilb, linux-raid; +Cc: mwilck
Hi Neil, hello list,
please review this patch series. I made so many endianness bugs
while working on DDF during the last months that I thought this
might be helpful - it will cause bugs to be caught by the
compiler which may otherwise turn up as hard-to-find runtime errors.
Note that the code *does not* compile after each patch, only
after the last one. I broke it down to make it more readable.
Patch 0005 and 0006 are separate because they are actual minor bugs
in the code that the endianness patch set helped me find.
I verified that the DDF unit tests aren't broken by this patch set.
Martin
Martin Wilck (6):
DDF: add endian-safe typedefs
DDF: convert big endian to be32 type
DDF: convert big-endian __u64 to be64 type
DDF: convert big-endian __u16 to be16 type
DDF: add_other_bvd: fix endianness bug
DDF: ddf_set_disk: fix minor endianness bug
super-ddf.c | 851 ++++++++++++++++++++++++++++++++---------------------------
1 files changed, 462 insertions(+), 389 deletions(-)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/6] DDF: add endian-safe typedefs
2013-07-21 17:28 [RFC/PATCH 0/6] DDF: safe big-endian types mwilck
@ 2013-07-21 17:28 ` mwilck
2013-07-21 17:28 ` [PATCH 2/6] DDF: convert big endian to be32 type mwilck
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: mwilck @ 2013-07-21 17:28 UTC (permalink / raw)
To: neilb, linux-raid; +Cc: mwilck
This adds typedefs for big-endian numbers. This will hopefully
reduce the number of endianness bugs I make.
---
super-ddf.c | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/super-ddf.c b/super-ddf.c
index d7da4c1..7f28d84 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -58,6 +58,42 @@ unsigned long crc32(
*
*/
+typedef struct __be16 {
+ __u16 _v16;
+} be16;
+#define be16_eq(x, y) ((x)._v16 == (y)._v16)
+
+typedef struct __be32 {
+ __u32 _v32;
+} be32;
+#define be32_eq(x, y) ((x)._v32 == (y)._v32)
+
+typedef struct __be64 {
+ __u64 _v64;
+} be64;
+#define be64_eq(x, y) ((x)._v64 == (y)._v64)
+
+#define be16_to_cpu(be) __be16_to_cpu((be)._v16)
+static inline be16 cpu_to_be16(__u16 x)
+{
+ be16 be = { ._v16 = __cpu_to_be16(x) };
+ return be;
+}
+
+#define be32_to_cpu(be) __be32_to_cpu((be)._v32)
+static inline be32 cpu_to_be32(__u32 x)
+{
+ be32 be = { ._v32 = __cpu_to_be32(x) };
+ return be;
+}
+
+#define be64_to_cpu(be) __be64_to_cpu((be)._v64)
+static inline be64 cpu_to_be64(__u64 x)
+{
+ be64 be = { ._v64 = __cpu_to_be64(x) };
+ return be;
+}
+
/* Primary Raid Level (PRL) */
#define DDF_RAID0 0x00
#define DDF_RAID1 0x01
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/6] DDF: convert big endian to be32 type
2013-07-21 17:28 [RFC/PATCH 0/6] DDF: safe big-endian types mwilck
2013-07-21 17:28 ` [PATCH 1/6] DDF: add endian-safe typedefs mwilck
@ 2013-07-21 17:28 ` mwilck
2013-07-21 17:28 ` [PATCH 3/6] DDF: convert big-endian __u64 to be64 type mwilck
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: mwilck @ 2013-07-21 17:28 UTC (permalink / raw)
To: neilb, linux-raid; +Cc: mwilck
Part 2 of endianness-safe conversion
---
super-ddf.c | 340 ++++++++++++++++++++++++++++++-----------------------------
1 files changed, 171 insertions(+), 169 deletions(-)
diff --git a/super-ddf.c b/super-ddf.c
index 7f28d84..5c016a4 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -131,28 +131,28 @@ static inline be64 cpu_to_be64(__u64 x)
#define DDF_2SPANNED 0x03 /* This is also weird - be careful */
/* Magic numbers */
-#define DDF_HEADER_MAGIC __cpu_to_be32(0xDE11DE11)
-#define DDF_CONTROLLER_MAGIC __cpu_to_be32(0xAD111111)
-#define DDF_PHYS_RECORDS_MAGIC __cpu_to_be32(0x22222222)
-#define DDF_PHYS_DATA_MAGIC __cpu_to_be32(0x33333333)
-#define DDF_VIRT_RECORDS_MAGIC __cpu_to_be32(0xDDDDDDDD)
-#define DDF_VD_CONF_MAGIC __cpu_to_be32(0xEEEEEEEE)
-#define DDF_SPARE_ASSIGN_MAGIC __cpu_to_be32(0x55555555)
-#define DDF_VU_CONF_MAGIC __cpu_to_be32(0x88888888)
-#define DDF_VENDOR_LOG_MAGIC __cpu_to_be32(0x01dBEEF0)
-#define DDF_BBM_LOG_MAGIC __cpu_to_be32(0xABADB10C)
+#define DDF_HEADER_MAGIC cpu_to_be32(0xDE11DE11)
+#define DDF_CONTROLLER_MAGIC cpu_to_be32(0xAD111111)
+#define DDF_PHYS_RECORDS_MAGIC cpu_to_be32(0x22222222)
+#define DDF_PHYS_DATA_MAGIC cpu_to_be32(0x33333333)
+#define DDF_VIRT_RECORDS_MAGIC cpu_to_be32(0xDDDDDDDD)
+#define DDF_VD_CONF_MAGIC cpu_to_be32(0xEEEEEEEE)
+#define DDF_SPARE_ASSIGN_MAGIC cpu_to_be32(0x55555555)
+#define DDF_VU_CONF_MAGIC cpu_to_be32(0x88888888)
+#define DDF_VENDOR_LOG_MAGIC cpu_to_be32(0x01dBEEF0)
+#define DDF_BBM_LOG_MAGIC cpu_to_be32(0xABADB10C)
#define DDF_GUID_LEN 24
#define DDF_REVISION_0 "01.00.00"
#define DDF_REVISION_2 "01.02.00"
struct ddf_header {
- __u32 magic; /* DDF_HEADER_MAGIC */
- __u32 crc;
+ be32 magic; /* DDF_HEADER_MAGIC */
+ be32 crc;
char guid[DDF_GUID_LEN];
char revision[8]; /* 01.02.00 */
- __u32 seq; /* starts at '1' */
- __u32 timestamp;
+ be32 seq; /* starts at '1' */
+ be32 timestamp;
__u8 openflag;
__u8 foreignflag;
__u8 enforcegroups;
@@ -164,7 +164,7 @@ struct ddf_header {
__u64 secondary_lba;
__u8 type;
__u8 pad2[3]; /* 0xff */
- __u32 workspace_len; /* sectors for vendor space -
+ be32 workspace_len; /* sectors for vendor space -
* at least 32768(sectors) */
__u64 workspace_lba;
__u16 max_pd_entries; /* one of 15, 63, 255, 1023, 4095 */
@@ -176,22 +176,22 @@ struct ddf_header {
__u16 max_primary_element_entries; /* 16, 64, 256, 1024, or 4096 */
__u8 pad3[54]; /* 0xff */
/* 192 bytes so far */
- __u32 controller_section_offset;
- __u32 controller_section_length;
- __u32 phys_section_offset;
- __u32 phys_section_length;
- __u32 virt_section_offset;
- __u32 virt_section_length;
- __u32 config_section_offset;
- __u32 config_section_length;
- __u32 data_section_offset;
- __u32 data_section_length;
- __u32 bbm_section_offset;
- __u32 bbm_section_length;
- __u32 diag_space_offset;
- __u32 diag_space_length;
- __u32 vendor_offset;
- __u32 vendor_length;
+ be32 controller_section_offset;
+ be32 controller_section_length;
+ be32 phys_section_offset;
+ be32 phys_section_length;
+ be32 virt_section_offset;
+ be32 virt_section_length;
+ be32 config_section_offset;
+ be32 config_section_length;
+ be32 data_section_offset;
+ be32 data_section_length;
+ be32 bbm_section_offset;
+ be32 bbm_section_length;
+ be32 diag_space_offset;
+ be32 diag_space_length;
+ be32 vendor_offset;
+ be32 vendor_length;
/* 256 bytes so far */
__u8 pad4[256]; /* 0xff */
};
@@ -203,8 +203,8 @@ struct ddf_header {
/* The content of the 'controller section' - global scope */
struct ddf_controller_data {
- __u32 magic; /* DDF_CONTROLLER_MAGIC */
- __u32 crc;
+ be32 magic; /* DDF_CONTROLLER_MAGIC */
+ be32 crc;
char guid[DDF_GUID_LEN];
struct controller_type {
__u16 vendor_id;
@@ -219,14 +219,14 @@ struct ddf_controller_data {
/* The content of phys_section - global scope */
struct phys_disk {
- __u32 magic; /* DDF_PHYS_RECORDS_MAGIC */
- __u32 crc;
+ be32 magic; /* DDF_PHYS_RECORDS_MAGIC */
+ be32 crc;
__u16 used_pdes;
__u16 max_pdes;
__u8 pad[52];
struct phys_disk_entry {
char guid[DDF_GUID_LEN];
- __u32 refnum;
+ be32 refnum;
__u16 type;
__u16 state;
__u64 config_size; /* DDF structures must be after here */
@@ -260,8 +260,8 @@ struct phys_disk {
/* The content of the virt_section global scope */
struct virtual_disk {
- __u32 magic; /* DDF_VIRT_RECORDS_MAGIC */
- __u32 crc;
+ be32 magic; /* DDF_VIRT_RECORDS_MAGIC */
+ be32 crc;
__u16 populated_vdes;
__u16 max_vdes;
__u8 pad[52];
@@ -314,11 +314,11 @@ struct virtual_disk {
*/
struct vd_config {
- __u32 magic; /* DDF_VD_CONF_MAGIC */
- __u32 crc;
+ be32 magic; /* DDF_VD_CONF_MAGIC */
+ be32 crc;
char guid[DDF_GUID_LEN];
- __u32 timestamp;
- __u32 seqnum;
+ be32 timestamp;
+ be32 seqnum;
__u8 pad0[24];
__u16 prim_elmnt_count;
__u8 chunk_shift; /* 0 == 512, 1==1024 etc */
@@ -332,7 +332,7 @@ struct vd_config {
* for concat I hope) */
__u64 array_blocks; /* blocks in array */
__u8 pad1[8];
- __u32 spare_refs[8];
+ be32 spare_refs[8];
__u8 cache_pol[8];
__u8 bg_rate;
__u8 pad2[3];
@@ -343,7 +343,7 @@ struct vd_config {
__u8 v2[16]; /* reserved- 0xff */
__u8 v3[16]; /* reserved- 0xff */
__u8 vendor[32];
- __u32 phys_refnum[0]; /* refnum of each disk in sequence */
+ be32 phys_refnum[0]; /* refnum of each disk in sequence */
/*__u64 lba_offset[0]; LBA offset in each phys. Note extents in a
bvd are always the same size */
};
@@ -359,9 +359,9 @@ struct vd_config {
#define DDF_cache_rallowed 64 /* enable read caching */
struct spare_assign {
- __u32 magic; /* DDF_SPARE_ASSIGN_MAGIC */
- __u32 crc;
- __u32 timestamp;
+ be32 magic; /* DDF_SPARE_ASSIGN_MAGIC */
+ be32 crc;
+ be32 timestamp;
__u8 reserved[7];
__u8 type;
__u16 populated; /* SAEs used */
@@ -381,10 +381,10 @@ struct spare_assign {
/* The data_section contents - local scope */
struct disk_data {
- __u32 magic; /* DDF_PHYS_DATA_MAGIC */
- __u32 crc;
+ be32 magic; /* DDF_PHYS_DATA_MAGIC */
+ be32 crc;
char guid[DDF_GUID_LEN];
- __u32 refnum; /* crc of some magic drive data ... */
+ be32 refnum; /* crc of some magic drive data ... */
__u8 forced_ref; /* set when above was not result of magic */
__u8 forced_guid; /* set if guid was forced rather than magic */
__u8 vendor[32];
@@ -393,15 +393,15 @@ struct disk_data {
/* bbm_section content */
struct bad_block_log {
- __u32 magic;
- __u32 crc;
+ be32 magic;
+ be32 crc;
__u16 entry_count;
- __u32 spare_count;
+ be32 spare_count;
__u8 pad[10];
__u64 first_spare;
struct mapped_block {
__u64 defective_start;
- __u32 replacement_start;
+ be32 replacement_start;
__u16 remap_count;
__u8 pad[2];
} entries[0];
@@ -503,31 +503,31 @@ static void pr_state(const struct ddf_super *ddf, const char *msg) {}
static void _ddf_set_updates_pending(struct ddf_super *ddf, const char *func)
{
ddf->updates_pending = 1;
- ddf->active->seq = __cpu_to_be32((__be32_to_cpu(ddf->active->seq)+1));
+ ddf->active->seq = cpu_to_be32((be32_to_cpu(ddf->active->seq)+1));
pr_state(ddf, func);
}
#define ddf_set_updates_pending(x) _ddf_set_updates_pending((x), __func__)
static unsigned int get_pd_index_from_refnum(const struct vcl *vc,
- __u32 refnum, unsigned int nmax,
+ be32 refnum, unsigned int nmax,
const struct vd_config **bvd,
unsigned int *idx);
-static unsigned int calc_crc(void *buf, int len)
+static be32 calc_crc(void *buf, int len)
{
/* crcs are always at the same place as in the ddf_header */
struct ddf_header *ddf = buf;
- __u32 oldcrc = ddf->crc;
+ be32 oldcrc = ddf->crc;
__u32 newcrc;
- ddf->crc = 0xffffffff;
+ ddf->crc = cpu_to_be32(0xffffffff);
newcrc = crc32(0, buf, len);
ddf->crc = oldcrc;
/* The crc is store (like everything) bigendian, so convert
* here for simplicity
*/
- return __cpu_to_be32(newcrc);
+ return cpu_to_be32(newcrc);
}
#define DDF_INVALID_LEVEL 0xff
@@ -750,9 +750,9 @@ static int load_ddf_header(int fd, unsigned long long lba,
if (read(fd, hdr, 512) != 512)
return 0;
- if (hdr->magic != DDF_HEADER_MAGIC)
+ if (!be32_eq(hdr->magic, DDF_HEADER_MAGIC))
return 0;
- if (calc_crc(hdr, 512) != hdr->crc)
+ if (!be32_eq(calc_crc(hdr, 512), hdr->crc))
return 0;
if (memcmp(anchor->guid, hdr->guid, DDF_GUID_LEN) != 0 ||
memcmp(anchor->revision, hdr->revision, 8) != 0 ||
@@ -768,10 +768,10 @@ static int load_ddf_header(int fd, unsigned long long lba,
}
static void *load_section(int fd, struct ddf_super *super, void *buf,
- __u32 offset_be, __u32 len_be, int check)
+ be32 offset_be, be32 len_be, int check)
{
- unsigned long long offset = __be32_to_cpu(offset_be);
- unsigned long long len = __be32_to_cpu(len_be);
+ unsigned long long offset = be32_to_cpu(offset_be);
+ unsigned long long len = be32_to_cpu(len_be);
int dofree = (buf == NULL);
if (check)
@@ -827,13 +827,13 @@ static int load_ddf_headers(int fd, struct ddf_super *super, char *devname)
devname, strerror(errno));
return 1;
}
- if (super->anchor.magic != DDF_HEADER_MAGIC) {
+ if (!be32_eq(super->anchor.magic, DDF_HEADER_MAGIC)) {
if (devname)
pr_err("no DDF anchor found on %s\n",
devname);
return 2;
}
- if (calc_crc(&super->anchor, 512) != super->anchor.crc) {
+ if (!be32_eq(calc_crc(&super->anchor, 512), super->anchor.crc)) {
if (devname)
pr_err("bad CRC on anchor on %s\n",
devname);
@@ -856,15 +856,16 @@ static int load_ddf_headers(int fd, struct ddf_super *super, char *devname)
"on %s\n", devname);
} else
super->active = &super->primary;
+
if (load_ddf_header(fd, __be64_to_cpu(super->anchor.secondary_lba),
dsize >> 9, 2,
&super->secondary, &super->anchor)) {
if (super->active == NULL
- || (__be32_to_cpu(super->primary.seq)
- < __be32_to_cpu(super->secondary.seq) &&
+ || (be32_to_cpu(super->primary.seq)
+ < be32_to_cpu(super->secondary.seq) &&
!super->secondary.openflag)
- || (__be32_to_cpu(super->primary.seq)
- == __be32_to_cpu(super->secondary.seq) &&
+ || (be32_to_cpu(super->primary.seq)
+ == be32_to_cpu(super->secondary.seq) &&
super->primary.openflag && !super->secondary.openflag)
)
super->active = &super->secondary;
@@ -887,13 +888,13 @@ static int load_ddf_global(int fd, struct ddf_super *super, char *devname)
super->active->phys_section_offset,
super->active->phys_section_length,
1);
- super->pdsize = __be32_to_cpu(super->active->phys_section_length) * 512;
+ super->pdsize = be32_to_cpu(super->active->phys_section_length) * 512;
super->virt = load_section(fd, super, NULL,
super->active->virt_section_offset,
super->active->virt_section_length,
1);
- super->vdsize = __be32_to_cpu(super->active->virt_section_length) * 512;
+ super->vdsize = be32_to_cpu(super->active->virt_section_length) * 512;
if (!ok ||
!super->phys ||
!super->virt) {
@@ -1025,13 +1026,13 @@ static int load_ddf_local(int fd, struct ddf_super *super,
vnum = 0;
for (confsec = 0;
- confsec < __be32_to_cpu(super->active->config_section_length);
+ confsec < be32_to_cpu(super->active->config_section_length);
confsec += super->conf_rec_len) {
struct vd_config *vd =
(struct vd_config *)((char*)conf + confsec*512);
struct vcl *vcl;
- if (vd->magic == DDF_SPARE_ASSIGN_MAGIC) {
+ if (be32_eq(vd->magic, DDF_SPARE_ASSIGN_MAGIC)) {
if (dl->spare)
continue;
if (posix_memalign((void**)&dl->spare, 512,
@@ -1044,7 +1045,7 @@ static int load_ddf_local(int fd, struct ddf_super *super,
memcpy(dl->spare, vd, super->conf_rec_len*512);
continue;
}
- if (vd->magic != DDF_VD_CONF_MAGIC)
+ if (!be32_eq(vd->magic, DDF_VD_CONF_MAGIC))
continue;
for (vcl = super->conflist; vcl; vcl = vcl->next) {
if (memcmp(vcl->conf.guid,
@@ -1059,8 +1060,8 @@ static int load_ddf_local(int fd, struct ddf_super *super,
add_other_bvd(vcl, vd, super->conf_rec_len*512);
continue;
}
- if (__be32_to_cpu(vd->seqnum) <=
- __be32_to_cpu(vcl->conf.seqnum))
+ if (be32_to_cpu(vd->seqnum) <=
+ be32_to_cpu(vcl->conf.seqnum))
continue;
} else {
if (posix_memalign((void**)&vcl, 512,
@@ -1363,7 +1364,7 @@ static void examine_vd(int n, struct ddf_super *sb, char *guid)
unsigned int i;
struct vd_config *vc = &vcl->conf;
- if (calc_crc(vc, crl*512) != vc->crc)
+ if (!be32_eq(calc_crc(vc, crl*512), vc->crc))
continue;
if (memcmp(vc->guid, guid, DDF_GUID_LEN) != 0)
continue;
@@ -1375,7 +1376,8 @@ static void examine_vd(int n, struct ddf_super *sb, char *guid)
int j;
int cnt = __be16_to_cpu(sb->phys->used_pdes);
for (j=0; j<cnt; j++)
- if (vc->phys_refnum[i] == sb->phys->entries[j].refnum)
+ if (be32_eq(vc->phys_refnum[i],
+ sb->phys->entries[j].refnum))
break;
if (i) printf(" ");
if (j < cnt)
@@ -1446,11 +1448,11 @@ static void examine_pds(struct ddf_super *sb)
//printf(" PD GUID[%d] : ", i); print_guid(pd->guid, 0);
//printf("\n");
printf(" %3d %08x ", i,
- __be32_to_cpu(pd->refnum));
+ be32_to_cpu(pd->refnum));
printf("%8lluK ",
(unsigned long long)__be64_to_cpu(pd->config_size)>>1);
for (dl = sb->dlist; dl ; dl = dl->next) {
- if (dl->disk.refnum == pd->refnum) {
+ if (be32_eq(dl->disk.refnum, pd->refnum)) {
char *dv = map_dev(dl->major, dl->minor, 0);
if (dv) {
printf("%-15s", dv);
@@ -1485,14 +1487,15 @@ static void examine_super_ddf(struct supertype *st, char *homehost)
{
struct ddf_super *sb = st->sb;
- printf(" Magic : %08x\n", __be32_to_cpu(sb->anchor.magic));
+ printf(" Magic : %08x\n", be32_to_cpu(sb->anchor.magic));
printf(" Version : %.8s\n", sb->anchor.revision);
printf("Controller GUID : "); print_guid(sb->controller.guid, 0);
printf("\n");
printf(" Container GUID : "); print_guid(sb->anchor.guid, 1);
printf("\n");
- printf(" Seq : %08x\n", __be32_to_cpu(sb->active->seq));
- printf(" Redundant hdr : %s\n", sb->secondary.magic == DDF_HEADER_MAGIC
+ printf(" Seq : %08x\n", be32_to_cpu(sb->active->seq));
+ printf(" Redundant hdr : %s\n", be32_eq(sb->secondary.magic,
+ DDF_HEADER_MAGIC)
?"yes" : "no");
examine_vds(sb);
examine_pds(sb);
@@ -1611,8 +1614,8 @@ static int copy_metadata_ddf(struct supertype *st, int from, int to)
if (read(from, buf, 512) != 512)
goto err;
ddf = buf;
- if (ddf->magic != DDF_HEADER_MAGIC ||
- calc_crc(ddf, 512) != ddf->crc ||
+ if (!be32_eq(ddf->magic, DDF_HEADER_MAGIC) ||
+ !be32_eq(calc_crc(ddf, 512), ddf->crc) ||
(memcmp(ddf->revision, DDF_REVISION_0, 8) != 0 &&
memcmp(ddf->revision, DDF_REVISION_2, 8) != 0))
goto err;
@@ -1702,7 +1705,7 @@ static int find_index_in_bvd(const struct ddf_super *ddf,
unsigned int i, j;
for (i = 0, j = 0; i < ddf->mppe &&
j < __be16_to_cpu(conf->prim_elmnt_count); i++) {
- if (conf->phys_refnum[i] != 0xffffffff) {
+ if (be32_to_cpu(conf->phys_refnum[i]) != 0xffffffff) {
if (n == j) {
*n_bvd = i;
return 1;
@@ -1764,14 +1767,14 @@ bad:
}
#endif
-static int find_phys(const struct ddf_super *ddf, __u32 phys_refnum)
+static int find_phys(const struct ddf_super *ddf, be32 phys_refnum)
{
/* Find the entry in phys_disk which has the given refnum
* and return it's index
*/
unsigned int i;
for (i = 0; i < __be16_to_cpu(ddf->phys->max_pdes); i++)
- if (ddf->phys->entries[i].refnum == phys_refnum)
+ if (be32_eq(ddf->phys->entries[i].refnum, phys_refnum))
return i;
return -1;
}
@@ -1846,7 +1849,7 @@ static void getinfo_super_ddf(struct supertype *st, struct mdinfo *info, char *m
info->disk.major = 0;
info->disk.minor = 0;
if (ddf->dlist) {
- info->disk.number = __be32_to_cpu(ddf->dlist->disk.refnum);
+ info->disk.number = be32_to_cpu(ddf->dlist->disk.refnum);
info->disk.raid_disk = find_phys(ddf, ddf->dlist->disk.refnum);
info->data_offset = __be64_to_cpu(ddf->phys->
@@ -1903,7 +1906,7 @@ static void getinfo_super_ddf_bvd(struct supertype *st, struct mdinfo *info, cha
info->array.md_minor = -1;
cptr = (__u32 *)(vc->conf.guid + 16);
info->array.ctime = DECADE + __be32_to_cpu(*cptr);
- info->array.utime = DECADE + __be32_to_cpu(vc->conf.timestamp);
+ info->array.utime = DECADE + be32_to_cpu(vc->conf.timestamp);
info->array.chunk_size = 512 << vc->conf.chunk_shift;
info->custom_array_size = 0;
@@ -1925,7 +1928,7 @@ static void getinfo_super_ddf_bvd(struct supertype *st, struct mdinfo *info, cha
}
for (dl = ddf->dlist; dl ; dl = dl->next)
- if (dl->disk.refnum == conf->phys_refnum[cd])
+ if (be32_eq(dl->disk.refnum, conf->phys_refnum[cd]))
break;
info->disk.major = 0;
@@ -2052,7 +2055,7 @@ static int update_super_ddf(struct supertype *st, struct mdinfo *info,
static void make_header_guid(char *guid)
{
- __u32 stamp;
+ be32 stamp;
/* Create a DDF Header of Virtual Disk GUID */
/* 24 bytes of fiction required.
@@ -2061,13 +2064,13 @@ static void make_header_guid(char *guid)
* Remaining 8 random number plus timestamp
*/
memcpy(guid, T10, sizeof(T10));
- stamp = __cpu_to_be32(0xdeadbeef);
+ stamp = cpu_to_be32(0xdeadbeef);
memcpy(guid+8, &stamp, 4);
- stamp = __cpu_to_be32(0);
+ stamp = cpu_to_be32(0);
memcpy(guid+12, &stamp, 4);
- stamp = __cpu_to_be32(time(0) - DECADE);
+ stamp = cpu_to_be32(time(0) - DECADE);
memcpy(guid+16, &stamp, 4);
- stamp = random32();
+ stamp._v32 = random32();
memcpy(guid+20, &stamp, 4);
}
@@ -2189,8 +2192,8 @@ static int init_super_ddf(struct supertype *st,
make_header_guid(ddf->anchor.guid);
memcpy(ddf->anchor.revision, DDF_REVISION_2, 8);
- ddf->anchor.seq = __cpu_to_be32(1);
- ddf->anchor.timestamp = __cpu_to_be32(time(0) - DECADE);
+ ddf->anchor.seq = cpu_to_be32(1);
+ ddf->anchor.timestamp = cpu_to_be32(time(0) - DECADE);
ddf->anchor.openflag = 0xFF;
ddf->anchor.foreignflag = 0;
ddf->anchor.enforcegroups = 0; /* Is this best?? */
@@ -2201,7 +2204,7 @@ static int init_super_ddf(struct supertype *st,
ddf->anchor.secondary_lba = ~(__u64)0;
ddf->anchor.type = DDF_HEADER_ANCHOR;
memset(ddf->anchor.pad2, 0xff, 3);
- ddf->anchor.workspace_len = __cpu_to_be32(32768); /* Must be reserved */
+ ddf->anchor.workspace_len = cpu_to_be32(32768); /* Must be reserved */
ddf->anchor.workspace_lba = ~(__u64)0; /* Put this at bottom
of 32M reserved.. */
max_phys_disks = 1023; /* Should be enough */
@@ -2218,8 +2221,8 @@ static int init_super_ddf(struct supertype *st,
/* controller sections is one sector long immediately
* after the ddf header */
sector = 1;
- ddf->anchor.controller_section_offset = __cpu_to_be32(sector);
- ddf->anchor.controller_section_length = __cpu_to_be32(1);
+ ddf->anchor.controller_section_offset = cpu_to_be32(sector);
+ ddf->anchor.controller_section_length = cpu_to_be32(1);
sector += 1;
/* phys is 8 sectors after that */
@@ -2230,9 +2233,9 @@ static int init_super_ddf(struct supertype *st,
case 2: case 8: case 32: case 128: case 512: break;
default: abort();
}
- ddf->anchor.phys_section_offset = __cpu_to_be32(sector);
+ ddf->anchor.phys_section_offset = cpu_to_be32(sector);
ddf->anchor.phys_section_length =
- __cpu_to_be32(pdsize/512); /* max_primary_element_entries/8 */
+ cpu_to_be32(pdsize/512); /* max_primary_element_entries/8 */
sector += pdsize/512;
/* virt is another 32 sectors */
@@ -2243,26 +2246,26 @@ static int init_super_ddf(struct supertype *st,
case 2: case 8: case 32: case 128: case 512: break;
default: abort();
}
- ddf->anchor.virt_section_offset = __cpu_to_be32(sector);
+ ddf->anchor.virt_section_offset = cpu_to_be32(sector);
ddf->anchor.virt_section_length =
- __cpu_to_be32(vdsize/512); /* max_vd_entries/8 */
+ cpu_to_be32(vdsize/512); /* max_vd_entries/8 */
sector += vdsize/512;
clen = ddf->conf_rec_len * (ddf->max_part+1);
- ddf->anchor.config_section_offset = __cpu_to_be32(sector);
- ddf->anchor.config_section_length = __cpu_to_be32(clen);
+ ddf->anchor.config_section_offset = cpu_to_be32(sector);
+ ddf->anchor.config_section_length = cpu_to_be32(clen);
sector += clen;
- ddf->anchor.data_section_offset = __cpu_to_be32(sector);
- ddf->anchor.data_section_length = __cpu_to_be32(1);
+ ddf->anchor.data_section_offset = cpu_to_be32(sector);
+ ddf->anchor.data_section_length = cpu_to_be32(1);
sector += 1;
- ddf->anchor.bbm_section_length = __cpu_to_be32(0);
- ddf->anchor.bbm_section_offset = __cpu_to_be32(0xFFFFFFFF);
- ddf->anchor.diag_space_length = __cpu_to_be32(0);
- ddf->anchor.diag_space_offset = __cpu_to_be32(0xFFFFFFFF);
- ddf->anchor.vendor_length = __cpu_to_be32(0);
- ddf->anchor.vendor_offset = __cpu_to_be32(0xFFFFFFFF);
+ ddf->anchor.bbm_section_length = cpu_to_be32(0);
+ ddf->anchor.bbm_section_offset = cpu_to_be32(0xFFFFFFFF);
+ ddf->anchor.diag_space_length = cpu_to_be32(0);
+ ddf->anchor.diag_space_offset = cpu_to_be32(0xFFFFFFFF);
+ ddf->anchor.vendor_length = cpu_to_be32(0);
+ ddf->anchor.vendor_offset = cpu_to_be32(0xFFFFFFFF);
memset(ddf->anchor.pad4, 0xff, 256);
@@ -2452,8 +2455,8 @@ static int init_super_ddf_bvd(struct supertype *st,
vc->magic = DDF_VD_CONF_MAGIC;
memcpy(vc->guid, ve->guid, DDF_GUID_LEN);
- vc->timestamp = __cpu_to_be32(time(0)-DECADE);
- vc->seqnum = __cpu_to_be32(1);
+ vc->timestamp = cpu_to_be32(time(0)-DECADE);
+ vc->seqnum = cpu_to_be32(1);
memset(vc->pad0, 0xff, 24);
vc->chunk_shift = chunk_to_shift(info->chunk_size);
if (layout_md2ddf(info, vc) == -1 ||
@@ -2475,14 +2478,14 @@ static int init_super_ddf_bvd(struct supertype *st,
calc_array_size(info->level, info->raid_disks, info->layout,
info->chunk_size, info->size*2));
memset(vc->pad1, 0xff, 8);
- vc->spare_refs[0] = 0xffffffff;
- vc->spare_refs[1] = 0xffffffff;
- vc->spare_refs[2] = 0xffffffff;
- vc->spare_refs[3] = 0xffffffff;
- vc->spare_refs[4] = 0xffffffff;
- vc->spare_refs[5] = 0xffffffff;
- vc->spare_refs[6] = 0xffffffff;
- vc->spare_refs[7] = 0xffffffff;
+ vc->spare_refs[0] = cpu_to_be32(0xffffffff);
+ vc->spare_refs[1] = cpu_to_be32(0xffffffff);
+ vc->spare_refs[2] = cpu_to_be32(0xffffffff);
+ vc->spare_refs[3] = cpu_to_be32(0xffffffff);
+ vc->spare_refs[4] = cpu_to_be32(0xffffffff);
+ vc->spare_refs[5] = cpu_to_be32(0xffffffff);
+ vc->spare_refs[6] = cpu_to_be32(0xffffffff);
+ vc->spare_refs[7] = cpu_to_be32(0xffffffff);
memset(vc->cache_pol, 0, 8);
vc->bg_rate = 0x80;
memset(vc->pad2, 0xff, 3);
@@ -2599,7 +2602,7 @@ static void add_to_super_ddf_bvd(struct supertype *st,
ddf->phys->entries[dl->pdnum].type &= ~__cpu_to_be16(DDF_Global_Spare);
ddf->phys->entries[dl->pdnum].type |= __cpu_to_be16(DDF_Active_in_VD);
dprintf("%s: added disk %d/%08x to VD %d/%s as disk %d\n",
- __func__, dl->pdnum, __be32_to_cpu(dl->disk.refnum),
+ __func__, dl->pdnum, be32_to_cpu(dl->disk.refnum),
ddf->currentconf->vcnum, guid_str(vc->guid),
dk->raid_disk);
ddf_set_updates_pending(ddf);
@@ -2679,10 +2682,11 @@ static int add_to_super_ddf(struct supertype *st,
do {
/* Cannot be bothered finding a CRC of some irrelevant details*/
- dd->disk.refnum = random32();
+ dd->disk.refnum._v32 = random32();
for (i = __be16_to_cpu(ddf->active->max_pd_entries);
i > 0; i--)
- if (ddf->phys->entries[i-1].refnum == dd->disk.refnum)
+ if (be32_eq(ddf->phys->entries[i-1].refnum,
+ dd->disk.refnum))
break;
} while (i > 0);
@@ -2863,7 +2867,7 @@ static int __write_ddf_structure(struct dl *d, struct ddf_super *ddf, __u8 type)
}
if (c) {
dprintf("writing conf record %i on disk %08x for %s/%u\n",
- i, __be32_to_cpu(d->disk.refnum),
+ i, be32_to_cpu(d->disk.refnum),
guid_str(vdc->guid),
vdc->sec_elmnt_seq);
vdc->seqnum = header->seq;
@@ -2935,7 +2939,7 @@ static int _write_super_to_disk(struct ddf_super *ddf, struct dl *d)
memcpy(&ddf->secondary, &ddf->anchor, 512);
ddf->anchor.openflag = 0xFF; /* 'open' means nothing */
- ddf->anchor.seq = 0xFFFFFFFF; /* no sequencing in anchor */
+ ddf->anchor.seq = cpu_to_be32(0xFFFFFFFF); /* no sequencing in anchor */
ddf->anchor.crc = calc_crc(&ddf->anchor, 512);
if (!__write_ddf_structure(d, ddf, DDF_HEADER_PRIMARY))
@@ -3443,7 +3447,7 @@ static int load_super_ddf_all(struct supertype *st, int fd,
rv = load_ddf_headers(dfd, super, NULL);
close(dfd);
if (rv == 0) {
- seq = __be32_to_cpu(super->active->seq);
+ seq = be32_to_cpu(super->active->seq);
if (super->active->openflag)
seq--;
if (!best || seq > bestseq) {
@@ -3562,7 +3566,7 @@ static int check_secondary(const struct vcl *vc)
}
static unsigned int get_pd_index_from_refnum(const struct vcl *vc,
- __u32 refnum, unsigned int nmax,
+ be32 refnum, unsigned int nmax,
const struct vd_config **bvd,
unsigned int *idx)
{
@@ -3573,9 +3577,9 @@ static unsigned int get_pd_index_from_refnum(const struct vcl *vc,
for (i = 0, j = 0 ; i < nmax ; i++) {
/* j counts valid entries for this BVD */
- if (vc->conf.phys_refnum[i] != 0xffffffff)
+ if (be32_to_cpu(vc->conf.phys_refnum[i]) != 0xffffffff)
j++;
- if (vc->conf.phys_refnum[i] == refnum) {
+ if (be32_eq(vc->conf.phys_refnum[i], refnum)) {
*bvd = &vc->conf;
*idx = i;
return sec * cnt + j - 1;
@@ -3590,9 +3594,9 @@ static unsigned int get_pd_index_from_refnum(const struct vcl *vc,
if (sec == DDF_UNUSED_BVD)
continue;
for (i = 0, j = 0 ; i < nmax ; i++) {
- if (vd->phys_refnum[i] != 0xffffffff)
+ if (be32_to_cpu(vd->phys_refnum[i]) != 0xffffffff)
j++;
- if (vd->phys_refnum[i] == refnum) {
+ if (be32_eq(vd->phys_refnum[i], refnum)) {
*bvd = vd;
*idx = i;
return sec * cnt + j - 1;
@@ -3649,7 +3653,7 @@ static struct mdinfo *container_content_ddf(struct supertype *st, char *subarray
cptr = (__u32 *)(vc->conf.guid + 16);
this->array.ctime = DECADE + __be32_to_cpu(*cptr);
this->array.utime = DECADE +
- __be32_to_cpu(vc->conf.timestamp);
+ be32_to_cpu(vc->conf.timestamp);
this->array.chunk_size = 512 << vc->conf.chunk_shift;
i = vc->vcnum;
@@ -3688,7 +3692,8 @@ static struct mdinfo *container_content_ddf(struct supertype *st, char *subarray
unsigned int iphys;
int stt;
- if (ddf->phys->entries[pd].refnum == 0xFFFFFFFF)
+ if (be32_to_cpu(ddf->phys->entries[pd].refnum)
+ == 0xFFFFFFFF)
continue;
stt = __be16_to_cpu(ddf->phys->entries[pd].state);
@@ -3705,8 +3710,8 @@ static struct mdinfo *container_content_ddf(struct supertype *st, char *subarray
this->array.working_disks++;
for (d = ddf->dlist; d ; d=d->next)
- if (d->disk.refnum ==
- ddf->phys->entries[pd].refnum)
+ if (be32_eq(d->disk.refnum,
+ ddf->phys->entries[pd].refnum))
break;
if (d == NULL)
/* Haven't found that one yet, maybe there are others */
@@ -3716,14 +3721,14 @@ static struct mdinfo *container_content_ddf(struct supertype *st, char *subarray
dev->next = this->devs;
this->devs = dev;
- dev->disk.number = __be32_to_cpu(d->disk.refnum);
+ dev->disk.number = be32_to_cpu(d->disk.refnum);
dev->disk.major = d->major;
dev->disk.minor = d->minor;
dev->disk.raid_disk = i;
dev->disk.state = (1<<MD_DISK_SYNC)|(1<<MD_DISK_ACTIVE);
dev->recovery_start = MaxSector;
- dev->events = __be32_to_cpu(ddf->primary.seq);
+ dev->events = be32_to_cpu(ddf->primary.seq);
dev->data_offset =
__be64_to_cpu(LBA_OFFSET(ddf, bvd)[iphys]);
dev->component_size = __be64_to_cpu(bvd->blocks);
@@ -3810,10 +3815,10 @@ static int compare_super_ddf(struct supertype *st, struct supertype *tst)
if (memcmp(first->anchor.guid, second->anchor.guid, DDF_GUID_LEN) != 0)
return 2;
- if (first->anchor.seq != second->anchor.seq) {
+ if (!be32_eq(first->anchor.seq, second->anchor.seq)) {
dprintf("%s: sequence number mismatch %u/%u\n", __func__,
- __be32_to_cpu(first->anchor.seq),
- __be32_to_cpu(second->anchor.seq));
+ be32_to_cpu(first->anchor.seq),
+ be32_to_cpu(second->anchor.seq));
return 3;
}
if (first->max_part != second->max_part ||
@@ -3826,18 +3831,19 @@ static int compare_super_ddf(struct supertype *st, struct supertype *tst)
max_pds = __be16_to_cpu(first->phys->used_pdes);
for (dl2 = second->dlist; dl2; dl2 = dl2->next) {
for (pd = 0; pd < max_pds; pd++)
- if (first->phys->entries[pd].refnum == dl2->disk.refnum)
+ if (be32_eq(first->phys->entries[pd].refnum,
+ dl2->disk.refnum))
break;
if (pd == max_pds) {
dprintf("%s: no match for disk %08x\n", __func__,
- __be32_to_cpu(dl2->disk.refnum));
+ be32_to_cpu(dl2->disk.refnum));
return 3;
}
}
max_vds = __be16_to_cpu(first->active->max_vd_entries);
for (vl2 = second->conflist; vl2; vl2 = vl2->next) {
- if (vl2->conf.magic != DDF_VD_CONF_MAGIC)
+ if (!be32_eq(vl2->conf.magic, DDF_VD_CONF_MAGIC))
continue;
for (vd = 0; vd < max_vds; vd++)
if (!memcmp(first->virt->entries[vd].guid,
@@ -3900,7 +3906,7 @@ static int compare_super_ddf(struct supertype *st, struct supertype *tst)
for (dl2 = second->dlist; dl2; dl2 = dl2->next) {
for (dl1 = first->dlist; dl1; dl1 = dl1->next)
- if (dl1->disk.refnum == dl2->disk.refnum)
+ if (be32_eq(dl1->disk.refnum, dl2->disk.refnum))
break;
if (dl1)
continue;
@@ -3917,7 +3923,8 @@ static int compare_super_ddf(struct supertype *st, struct supertype *tst)
dl1->next = first->dlist;
dl1->fd = -1;
for (pd = 0; pd < max_pds; pd++)
- if (first->phys->entries[pd].refnum == dl1->disk.refnum)
+ if (be32_eq(first->phys->entries[pd].refnum,
+ dl1->disk.refnum))
break;
dl1->pdnum = pd;
if (dl2->spare) {
@@ -3944,7 +3951,7 @@ static int compare_super_ddf(struct supertype *st, struct supertype *tst)
}
first->dlist = dl1;
dprintf("%s: added disk %d: %08x\n", __func__, dl1->pdnum,
- __be32_to_cpu(dl1->disk.refnum));
+ be32_to_cpu(dl1->disk.refnum));
}
return 0;
@@ -4147,7 +4154,7 @@ static void ddf_set_disk(struct active_array *a, int n, int state)
* If it is now in_sync, insert it. */
dprintf("%s: phys disk not found for %d: %d/%d ref %08x\n",
__func__, dl->pdnum, dl->major, dl->minor,
- __be32_to_cpu(dl->disk.refnum));
+ be32_to_cpu(dl->disk.refnum));
dprintf("%s: array %u disk %u ref %08x pd %d\n",
__func__, inst, n_bvd, vc->phys_refnum[n_bvd], pd);
if ((state & DS_INSYNC) && ! (state & DS_FAULTY)) {
@@ -4349,7 +4356,7 @@ static void ddf_process_update(struct supertype *st,
* a spare-assignment record.
*/
struct ddf_super *ddf = st->sb;
- __u32 *magic = (__u32*)update->buf;
+ be32 *magic = (be32 *)update->buf;
struct phys_disk *pd;
struct virtual_disk *vd;
struct vd_config *vc;
@@ -4358,10 +4365,9 @@ static void ddf_process_update(struct supertype *st,
unsigned int ent;
unsigned int pdnum, pd2, len;
- dprintf("Process update %x\n", *magic);
+ dprintf("Process update %x\n", be32_to_cpu(*magic));
- switch (*magic) {
- case DDF_PHYS_RECORDS_MAGIC:
+ if (be32_eq(*magic, DDF_PHYS_RECORDS_MAGIC)) {
if (update->len != (sizeof(struct phys_disk) +
sizeof(struct phys_disk_entry)))
@@ -4410,9 +4416,7 @@ static void ddf_process_update(struct supertype *st,
for (a = st->arrays ; a; a=a->next)
a->check_degraded = 1;
}
- break;
-
- case DDF_VIRT_RECORDS_MAGIC:
+ } else if (be32_eq(*magic, DDF_VIRT_RECORDS_MAGIC)) {
if (update->len != (sizeof(struct virtual_disk) +
sizeof(struct virtual_entry)))
@@ -4445,9 +4449,9 @@ static void ddf_process_update(struct supertype *st,
ddf->virt->entries[ent].init_state);
}
ddf_set_updates_pending(ddf);
- break;
+ }
- case DDF_VD_CONF_MAGIC:
+ else if (be32_eq(*magic, DDF_VD_CONF_MAGIC)) {
vc = (struct vd_config*)update->buf;
len = ddf->conf_rec_len * 512;
if ((unsigned int)update->len != len * vc->sec_elmnt_count) {
@@ -4512,7 +4516,7 @@ static void ddf_process_update(struct supertype *st,
continue;
dprintf("dev %d/%08x has %s (sec=%u) at %d\n",
dl->pdnum,
- __be32_to_cpu(dl->disk.refnum),
+ be32_to_cpu(dl->disk.refnum),
guid_str(conf->guid),
conf->sec_elmnt_seq, vn);
/* Clear the Transition flag */
@@ -4583,10 +4587,8 @@ static void ddf_process_update(struct supertype *st,
}
ddf_set_updates_pending(ddf);
- break;
- case DDF_SPARE_ASSIGN_MAGIC:
- default: break;
}
+ /* case DDF_SPARE_ASSIGN_MAGIC */
}
static void ddf_prepare_update(struct supertype *st,
@@ -4597,8 +4599,8 @@ static void ddf_prepare_update(struct supertype *st,
* If a malloc is needed, do it here.
*/
struct ddf_super *ddf = st->sb;
- __u32 *magic = (__u32*)update->buf;
- if (*magic == DDF_VD_CONF_MAGIC) {
+ be32 *magic = (be32 *)update->buf;
+ if (be32_eq(*magic, DDF_VD_CONF_MAGIC)) {
struct vcl *vcl;
struct vd_config *conf = (struct vd_config *) update->buf;
if (posix_memalign(&update->space, 512,
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/6] DDF: convert big-endian __u64 to be64 type
2013-07-21 17:28 [RFC/PATCH 0/6] DDF: safe big-endian types mwilck
2013-07-21 17:28 ` [PATCH 1/6] DDF: add endian-safe typedefs mwilck
2013-07-21 17:28 ` [PATCH 2/6] DDF: convert big endian to be32 type mwilck
@ 2013-07-21 17:28 ` mwilck
2013-07-21 17:28 ` [PATCH 4/6] DDF: convert big-endian __u16 to be16 type mwilck
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: mwilck @ 2013-07-21 17:28 UTC (permalink / raw)
To: neilb, linux-raid; +Cc: mwilck
---
super-ddf.c | 112 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 56 insertions(+), 56 deletions(-)
diff --git a/super-ddf.c b/super-ddf.c
index 5c016a4..91bfe9e 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -160,13 +160,13 @@ struct ddf_header {
__u8 pad1[12]; /* 12 * 0xff */
/* 64 bytes so far */
__u8 header_ext[32]; /* reserved: fill with 0xff */
- __u64 primary_lba;
- __u64 secondary_lba;
+ be64 primary_lba;
+ be64 secondary_lba;
__u8 type;
__u8 pad2[3]; /* 0xff */
be32 workspace_len; /* sectors for vendor space -
* at least 32768(sectors) */
- __u64 workspace_lba;
+ be64 workspace_lba;
__u16 max_pd_entries; /* one of 15, 63, 255, 1023, 4095 */
__u16 max_vd_entries; /* 2^(4,6,8,10,12)-1 : i.e. as above */
__u16 max_partitions; /* i.e. max num of configuration
@@ -229,7 +229,7 @@ struct phys_disk {
be32 refnum;
__u16 type;
__u16 state;
- __u64 config_size; /* DDF structures must be after here */
+ be64 config_size; /* DDF structures must be after here */
char path[18]; /* another horrible structure really */
__u8 pad[6];
} entries[0];
@@ -327,10 +327,10 @@ struct vd_config {
__u8 sec_elmnt_count;
__u8 sec_elmnt_seq;
__u8 srl;
- __u64 blocks; /* blocks per component could be different
+ be64 blocks; /* blocks per component could be different
* on different component devices...(only
* for concat I hope) */
- __u64 array_blocks; /* blocks in array */
+ be64 array_blocks; /* blocks in array */
__u8 pad1[8];
be32 spare_refs[8];
__u8 cache_pol[8];
@@ -347,7 +347,7 @@ struct vd_config {
/*__u64 lba_offset[0]; LBA offset in each phys. Note extents in a
bvd are always the same size */
};
-#define LBA_OFFSET(ddf, vd) ((__u64 *) &(vd)->phys_refnum[(ddf)->mppe])
+#define LBA_OFFSET(ddf, vd) ((be64 *) &(vd)->phys_refnum[(ddf)->mppe])
/* vd_config.cache_pol[7] is a bitmap */
#define DDF_cache_writeback 1 /* else writethrough */
@@ -398,9 +398,9 @@ struct bad_block_log {
__u16 entry_count;
be32 spare_count;
__u8 pad[10];
- __u64 first_spare;
+ be64 first_spare;
struct mapped_block {
- __u64 defective_start;
+ be64 defective_start;
be32 replacement_start;
__u16 remap_count;
__u8 pad[2];
@@ -460,9 +460,9 @@ struct ddf_super {
char *devname;
int fd;
unsigned long long size; /* sectors */
- unsigned long long primary_lba; /* sectors */
- unsigned long long secondary_lba; /* sectors */
- unsigned long long workspace_lba; /* sectors */
+ be64 primary_lba; /* sectors */
+ be64 secondary_lba; /* sectors */
+ be64 workspace_lba; /* sectors */
int pdnum; /* index in ->phys */
struct spare_assign *spare;
void *mdupdate; /* hold metadata update */
@@ -756,8 +756,8 @@ static int load_ddf_header(int fd, unsigned long long lba,
return 0;
if (memcmp(anchor->guid, hdr->guid, DDF_GUID_LEN) != 0 ||
memcmp(anchor->revision, hdr->revision, 8) != 0 ||
- anchor->primary_lba != hdr->primary_lba ||
- anchor->secondary_lba != hdr->secondary_lba ||
+ !be64_eq(anchor->primary_lba, hdr->primary_lba) ||
+ !be64_eq(anchor->secondary_lba, hdr->secondary_lba) ||
hdr->type != type ||
memcmp(anchor->pad2, hdr->pad2, 512 -
offsetof(struct ddf_header, pad2)) != 0)
@@ -792,9 +792,9 @@ static void *load_section(int fd, struct ddf_super *super, void *buf,
return NULL;
if (super->active->type == 1)
- offset += __be64_to_cpu(super->active->primary_lba);
+ offset += be64_to_cpu(super->active->primary_lba);
else
- offset += __be64_to_cpu(super->active->secondary_lba);
+ offset += be64_to_cpu(super->active->secondary_lba);
if ((unsigned long long)lseek64(fd, offset<<9, 0) != (offset<<9)) {
if (dofree)
@@ -848,7 +848,7 @@ static int load_ddf_headers(int fd, struct ddf_super *super, char *devname)
return 2;
}
super->active = NULL;
- if (load_ddf_header(fd, __be64_to_cpu(super->anchor.primary_lba),
+ if (load_ddf_header(fd, be64_to_cpu(super->anchor.primary_lba),
dsize >> 9, 1,
&super->primary, &super->anchor) == 0) {
if (devname)
@@ -857,7 +857,7 @@ static int load_ddf_headers(int fd, struct ddf_super *super, char *devname)
} else
super->active = &super->primary;
- if (load_ddf_header(fd, __be64_to_cpu(super->anchor.secondary_lba),
+ if (load_ddf_header(fd, be64_to_cpu(super->anchor.secondary_lba),
dsize >> 9, 2,
&super->secondary, &super->anchor)) {
if (super->active == NULL
@@ -1398,9 +1398,9 @@ static void examine_vd(int n, struct ddf_super *sb, char *guid)
map_num(ddf_sec_level, vc->srl) ?: "-unknown-");
}
printf(" Device Size[%d] : %llu\n", n,
- (unsigned long long)__be64_to_cpu(vc->blocks)/2);
+ be64_to_cpu(vc->blocks)/2);
printf(" Array Size[%d] : %llu\n", n,
- (unsigned long long)__be64_to_cpu(vc->array_blocks)/2);
+ be64_to_cpu(vc->array_blocks)/2);
}
}
@@ -1450,7 +1450,7 @@ static void examine_pds(struct ddf_super *sb)
printf(" %3d %08x ", i,
be32_to_cpu(pd->refnum));
printf("%8lluK ",
- (unsigned long long)__be64_to_cpu(pd->config_size)>>1);
+ be64_to_cpu(pd->config_size)>>1);
for (dl = sb->dlist; dl ; dl = dl->next) {
if (be32_eq(dl->disk.refnum, pd->refnum)) {
char *dv = map_dev(dl->major, dl->minor, 0);
@@ -1621,10 +1621,10 @@ static int copy_metadata_ddf(struct supertype *st, int from, int to)
goto err;
offset = dsize - 512;
- if ((__be64_to_cpu(ddf->primary_lba) << 9) < offset)
- offset = __be64_to_cpu(ddf->primary_lba) << 9;
- if ((__be64_to_cpu(ddf->secondary_lba) << 9) < offset)
- offset = __be64_to_cpu(ddf->secondary_lba) << 9;
+ if ((be64_to_cpu(ddf->primary_lba) << 9) < offset)
+ offset = be64_to_cpu(ddf->primary_lba) << 9;
+ if ((be64_to_cpu(ddf->secondary_lba) << 9) < offset)
+ offset = be64_to_cpu(ddf->secondary_lba) << 9;
bytes = dsize - offset;
@@ -1852,7 +1852,7 @@ static void getinfo_super_ddf(struct supertype *st, struct mdinfo *info, char *m
info->disk.number = be32_to_cpu(ddf->dlist->disk.refnum);
info->disk.raid_disk = find_phys(ddf, ddf->dlist->disk.refnum);
- info->data_offset = __be64_to_cpu(ddf->phys->
+ info->data_offset = be64_to_cpu(ddf->phys->
entries[info->disk.raid_disk].
config_size);
info->component_size = ddf->dlist->size - info->data_offset;
@@ -1920,11 +1920,11 @@ static void getinfo_super_ddf_bvd(struct supertype *st, struct mdinfo *info, cha
if (cd >= 0 && (unsigned)cd < ddf->mppe) {
info->data_offset =
- __be64_to_cpu(LBA_OFFSET(ddf, conf)[cd]);
+ be64_to_cpu(LBA_OFFSET(ddf, conf)[cd]);
if (vc->block_sizes)
info->component_size = vc->block_sizes[cd];
else
- info->component_size = __be64_to_cpu(conf->blocks);
+ info->component_size = be64_to_cpu(conf->blocks);
}
for (dl = ddf->dlist; dl ; dl = dl->next)
@@ -2200,13 +2200,13 @@ static int init_super_ddf(struct supertype *st,
ddf->anchor.pad0 = 0xff;
memset(ddf->anchor.pad1, 0xff, 12);
memset(ddf->anchor.header_ext, 0xff, 32);
- ddf->anchor.primary_lba = ~(__u64)0;
- ddf->anchor.secondary_lba = ~(__u64)0;
+ ddf->anchor.primary_lba = cpu_to_be64(~(__u64)0);
+ ddf->anchor.secondary_lba = cpu_to_be64(~(__u64)0);
ddf->anchor.type = DDF_HEADER_ANCHOR;
memset(ddf->anchor.pad2, 0xff, 3);
ddf->anchor.workspace_len = cpu_to_be32(32768); /* Must be reserved */
- ddf->anchor.workspace_lba = ~(__u64)0; /* Put this at bottom
- of 32M reserved.. */
+ /* Put this at bottom of 32M reserved.. */
+ ddf->anchor.workspace_lba = cpu_to_be64(~(__u64)0);
max_phys_disks = 1023; /* Should be enough */
ddf->anchor.max_pd_entries = __cpu_to_be16(max_phys_disks);
max_virt_disks = 255;
@@ -2383,13 +2383,13 @@ static struct extent *get_extents(struct ddf_super *ddf, struct dl *dl)
get_pd_index_from_refnum(v, dl->disk.refnum, ddf->mppe,
&bvd, &ibvd) == DDF_NOTFOUND)
continue;
- rv[n].start = __be64_to_cpu(LBA_OFFSET(ddf, bvd)[ibvd]);
- rv[n].size = __be64_to_cpu(bvd->blocks);
+ rv[n].start = be64_to_cpu(LBA_OFFSET(ddf, bvd)[ibvd]);
+ rv[n].size = be64_to_cpu(bvd->blocks);
n++;
}
qsort(rv, n, sizeof(*rv), cmp_extent);
- rv[n].start = __be64_to_cpu(ddf->phys->entries[dl->pdnum].config_size);
+ rv[n].start = be64_to_cpu(ddf->phys->entries[dl->pdnum].config_size);
rv[n].size = 0;
return rv;
}
@@ -2473,8 +2473,8 @@ static int init_super_ddf_bvd(struct supertype *st,
free(vcl);
return 0;
}
- vc->blocks = __cpu_to_be64(info->size * 2);
- vc->array_blocks = __cpu_to_be64(
+ vc->blocks = cpu_to_be64(info->size * 2);
+ vc->array_blocks = cpu_to_be64(
calc_array_size(info->level, info->raid_disks, info->layout,
info->chunk_size, info->size*2));
memset(vc->pad1, 0xff, 8);
@@ -2562,7 +2562,7 @@ static void add_to_super_ddf_bvd(struct supertype *st,
return;
i = 0; pos = 0;
- blocks = __be64_to_cpu(vc->blocks);
+ blocks = be64_to_cpu(vc->blocks);
if (ddf->currentconf->block_sizes)
blocks = ddf->currentconf->block_sizes[dk->raid_disk];
@@ -2580,7 +2580,7 @@ static void add_to_super_ddf_bvd(struct supertype *st,
ddf->currentdev = dk->raid_disk;
vc->phys_refnum[raid_disk] = dl->disk.refnum;
- LBA_OFFSET(ddf, vc)[raid_disk] = __cpu_to_be64(pos);
+ LBA_OFFSET(ddf, vc)[raid_disk] = cpu_to_be64(pos);
for (i = 0; i < ddf->max_part ; i++)
if (dl->vlist[i] == NULL)
@@ -2727,13 +2727,13 @@ static int add_to_super_ddf(struct supertype *st,
#define __calc_lba(new, old, lba, mb) do { \
unsigned long long dif; \
if ((old) != NULL) \
- dif = (old)->size - __be64_to_cpu((old)->lba); \
+ dif = (old)->size - be64_to_cpu((old)->lba); \
else \
dif = (new)->size; \
if ((new)->size > dif) \
- (new)->lba = __cpu_to_be64((new)->size - dif); \
+ (new)->lba = cpu_to_be64((new)->size - dif); \
else \
- (new)->lba = __cpu_to_be64((new)->size - (mb*1024*2)); \
+ (new)->lba = cpu_to_be64((new)->size - (mb*1024*2)); \
} while (0)
__calc_lba(dd, ddf->dlist, workspace_lba, 32);
__calc_lba(dd, ddf->dlist, primary_lba, 16);
@@ -2816,11 +2816,11 @@ static int __write_ddf_structure(struct dl *d, struct ddf_super *ddf, __u8 type)
switch (type) {
case DDF_HEADER_PRIMARY:
header = &ddf->primary;
- sector = __be64_to_cpu(header->primary_lba);
+ sector = be64_to_cpu(header->primary_lba);
break;
case DDF_HEADER_SECONDARY:
header = &ddf->secondary;
- sector = __be64_to_cpu(header->secondary_lba);
+ sector = be64_to_cpu(header->secondary_lba);
break;
default:
return 0;
@@ -2919,21 +2919,21 @@ static int _write_super_to_disk(struct ddf_super *ddf, struct dl *d)
*/
get_dev_size(fd, NULL, &size);
size /= 512;
- if (d->workspace_lba != 0)
+ if (be64_to_cpu(d->workspace_lba) != 0ULL)
ddf->anchor.workspace_lba = d->workspace_lba;
else
ddf->anchor.workspace_lba =
- __cpu_to_be64(size - 32*1024*2);
- if (d->primary_lba != 0)
+ cpu_to_be64(size - 32*1024*2);
+ if (be64_to_cpu(d->primary_lba) != 0ULL)
ddf->anchor.primary_lba = d->primary_lba;
else
ddf->anchor.primary_lba =
- __cpu_to_be64(size - 16*1024*2);
- if (d->secondary_lba != 0)
+ cpu_to_be64(size - 16*1024*2);
+ if (be64_to_cpu(d->secondary_lba) != 0ULL)
ddf->anchor.secondary_lba = d->secondary_lba;
else
ddf->anchor.secondary_lba =
- __cpu_to_be64(size - 32*1024*2);
+ cpu_to_be64(size - 32*1024*2);
ddf->anchor.seq = ddf->active->seq;
memcpy(&ddf->primary, &ddf->anchor, 512);
memcpy(&ddf->secondary, &ddf->anchor, 512);
@@ -3550,7 +3550,7 @@ static int check_secondary(const struct vcl *vc)
pr_err("Different strip sizes for BVDs are unsupported\n");
return -1;
}
- if (bvd->array_blocks != conf->array_blocks) {
+ if (!be64_eq(bvd->array_blocks, conf->array_blocks)) {
pr_err("Different BVD sizes are unsupported\n");
return -1;
}
@@ -3673,7 +3673,7 @@ static struct mdinfo *container_content_ddf(struct supertype *st, char *subarray
this->name[j] = 0;
memset(this->uuid, 0, sizeof(this->uuid));
- this->component_size = __be64_to_cpu(vc->conf.blocks);
+ this->component_size = be64_to_cpu(vc->conf.blocks);
this->array.size = this->component_size / 2;
this->container_member = i;
@@ -3730,8 +3730,8 @@ static struct mdinfo *container_content_ddf(struct supertype *st, char *subarray
dev->events = be32_to_cpu(ddf->primary.seq);
dev->data_offset =
- __be64_to_cpu(LBA_OFFSET(ddf, bvd)[iphys]);
- dev->component_size = __be64_to_cpu(bvd->blocks);
+ be64_to_cpu(LBA_OFFSET(ddf, bvd)[iphys]);
+ dev->component_size = be64_to_cpu(bvd->blocks);
if (d->devname)
strcpy(dev->name, d->devname);
}
@@ -4161,7 +4161,7 @@ static void ddf_set_disk(struct active_array *a, int n, int state)
pd = dl->pdnum; /* FIXME: is this really correct ? */
vc->phys_refnum[n_bvd] = dl->disk.refnum;
LBA_OFFSET(ddf, vc)[n_bvd] =
- __cpu_to_be64(mdi->data_offset);
+ cpu_to_be64(mdi->data_offset);
ddf->phys->entries[pd].type &=
~__cpu_to_be16(DDF_Global_Spare);
ddf->phys->entries[pd].type |=
@@ -4821,7 +4821,7 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a,
vc->phys_refnum[di->disk.raid_disk] =
ddf->phys->entries[dl->pdnum].refnum;
LBA_OFFSET(ddf, vc)[di->disk.raid_disk]
- = __cpu_to_be64(di->data_offset);
+ = cpu_to_be64(di->data_offset);
}
*updates = mu;
return rv;
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/6] DDF: convert big-endian __u16 to be16 type
2013-07-21 17:28 [RFC/PATCH 0/6] DDF: safe big-endian types mwilck
` (2 preceding siblings ...)
2013-07-21 17:28 ` [PATCH 3/6] DDF: convert big-endian __u64 to be64 type mwilck
@ 2013-07-21 17:28 ` mwilck
2013-07-21 17:28 ` [PATCH 5/6] DDF: add_other_bvd: fix endianness bug mwilck
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: mwilck @ 2013-07-21 17:28 UTC (permalink / raw)
To: neilb, linux-raid; +Cc: mwilck
Last step of endian-safe recoding. This requires also bit
operations.
---
super-ddf.c | 357 ++++++++++++++++++++++++++++++++---------------------------
1 files changed, 195 insertions(+), 162 deletions(-)
diff --git a/super-ddf.c b/super-ddf.c
index 91bfe9e..bd42194 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -62,6 +62,10 @@ typedef struct __be16 {
__u16 _v16;
} be16;
#define be16_eq(x, y) ((x)._v16 == (y)._v16)
+#define be16_and(x, y) ((x)._v16 & (y)._v16)
+#define be16_or(x, y) ((x)._v16 | (y)._v16)
+#define be16_clear(x, y) ((x)._v16 &= ~(y)._v16)
+#define be16_set(x, y) ((x)._v16 |= (y)._v16)
typedef struct __be32 {
__u32 _v32;
@@ -167,13 +171,13 @@ struct ddf_header {
be32 workspace_len; /* sectors for vendor space -
* at least 32768(sectors) */
be64 workspace_lba;
- __u16 max_pd_entries; /* one of 15, 63, 255, 1023, 4095 */
- __u16 max_vd_entries; /* 2^(4,6,8,10,12)-1 : i.e. as above */
- __u16 max_partitions; /* i.e. max num of configuration
+ be16 max_pd_entries; /* one of 15, 63, 255, 1023, 4095 */
+ be16 max_vd_entries; /* 2^(4,6,8,10,12)-1 : i.e. as above */
+ be16 max_partitions; /* i.e. max num of configuration
record entries per disk */
- __u16 config_record_len; /* 1 +ROUNDUP(max_primary_element_entries
+ be16 config_record_len; /* 1 +ROUNDUP(max_primary_element_entries
*12/512) */
- __u16 max_primary_element_entries; /* 16, 64, 256, 1024, or 4096 */
+ be16 max_primary_element_entries; /* 16, 64, 256, 1024, or 4096 */
__u8 pad3[54]; /* 0xff */
/* 192 bytes so far */
be32 controller_section_offset;
@@ -207,10 +211,10 @@ struct ddf_controller_data {
be32 crc;
char guid[DDF_GUID_LEN];
struct controller_type {
- __u16 vendor_id;
- __u16 device_id;
- __u16 sub_vendor_id;
- __u16 sub_device_id;
+ be16 vendor_id;
+ be16 device_id;
+ be16 sub_vendor_id;
+ be16 sub_device_id;
} type;
char product_id[16];
__u8 pad[8]; /* 0xff */
@@ -221,14 +225,14 @@ struct ddf_controller_data {
struct phys_disk {
be32 magic; /* DDF_PHYS_RECORDS_MAGIC */
be32 crc;
- __u16 used_pdes;
- __u16 max_pdes;
+ be16 used_pdes;
+ be16 max_pdes;
__u8 pad[52];
struct phys_disk_entry {
char guid[DDF_GUID_LEN];
be32 refnum;
- __u16 type;
- __u16 state;
+ be16 type;
+ be16 state;
be64 config_size; /* DDF structures must be after here */
char path[18]; /* another horrible structure really */
__u8 pad[6];
@@ -262,15 +266,15 @@ struct phys_disk {
struct virtual_disk {
be32 magic; /* DDF_VIRT_RECORDS_MAGIC */
be32 crc;
- __u16 populated_vdes;
- __u16 max_vdes;
+ be16 populated_vdes;
+ be16 max_vdes;
__u8 pad[52];
struct virtual_entry {
char guid[DDF_GUID_LEN];
- __u16 unit;
+ be16 unit;
__u16 pad0; /* 0xffff */
- __u16 guid_crc;
- __u16 type;
+ be16 guid_crc;
+ be16 type;
__u8 state;
__u8 init_state;
__u8 pad1[14];
@@ -320,7 +324,7 @@ struct vd_config {
be32 timestamp;
be32 seqnum;
__u8 pad0[24];
- __u16 prim_elmnt_count;
+ be16 prim_elmnt_count;
__u8 chunk_shift; /* 0 == 512, 1==1024 etc */
__u8 prl;
__u8 rlq;
@@ -364,12 +368,12 @@ struct spare_assign {
be32 timestamp;
__u8 reserved[7];
__u8 type;
- __u16 populated; /* SAEs used */
- __u16 max; /* max SAEs */
+ be16 populated; /* SAEs used */
+ be16 max; /* max SAEs */
__u8 pad[8];
struct spare_assign_entry {
char guid[DDF_GUID_LEN];
- __u16 secondary_element;
+ be16 secondary_element;
__u8 pad[6];
} spare_ents[0];
};
@@ -395,14 +399,14 @@ struct disk_data {
struct bad_block_log {
be32 magic;
be32 crc;
- __u16 entry_count;
+ be16 entry_count;
be32 spare_count;
__u8 pad[10];
be64 first_spare;
struct mapped_block {
be64 defective_start;
be32 replacement_start;
- __u16 remap_count;
+ be16 remap_count;
__u8 pad[2];
} entries[0];
};
@@ -487,7 +491,7 @@ static void pr_state(struct ddf_super *ddf, const char *msg)
{
unsigned int i;
dprintf("%s/%s: ", __func__, msg);
- for (i = 0; i < __be16_to_cpu(ddf->active->max_vd_entries); i++) {
+ for (i = 0; i < be16_to_cpu(ddf->active->max_vd_entries); i++) {
if (all_ff(ddf->virt->entries[i].guid))
continue;
dprintf("%u(s=%02x i=%02x) ", i,
@@ -542,7 +546,7 @@ static int err_bad_md_layout(const mdu_array_info_t *array)
static int layout_md2ddf(const mdu_array_info_t *array,
struct vd_config *conf)
{
- __u16 prim_elmnt_count = __cpu_to_be16(array->raid_disks);
+ be16 prim_elmnt_count = cpu_to_be16(array->raid_disks);
__u8 prl = DDF_INVALID_LEVEL, rlq = 0;
__u8 sec_elmnt_count = 1;
__u8 srl = DDF_NO_SECONDARY;
@@ -611,12 +615,12 @@ static int layout_md2ddf(const mdu_array_info_t *array,
case 10:
if (array->raid_disks % 2 == 0 && array->layout == 0x102) {
rlq = DDF_RAID1_SIMPLE;
- prim_elmnt_count = __cpu_to_be16(2);
+ prim_elmnt_count = cpu_to_be16(2);
sec_elmnt_count = array->raid_disks / 2;
} else if (array->raid_disks % 3 == 0
&& array->layout == 0x103) {
rlq = DDF_RAID1_MULTI;
- prim_elmnt_count = __cpu_to_be16(3);
+ prim_elmnt_count = cpu_to_be16(3);
sec_elmnt_count = array->raid_disks / 3;
} else
return err_bad_md_layout(array);
@@ -637,7 +641,7 @@ static int layout_md2ddf(const mdu_array_info_t *array,
static int err_bad_ddf_layout(const struct vd_config *conf)
{
pr_err("DDF RAID %u qualifier %u with %u disks is unsupported\n",
- conf->prl, conf->rlq, __be16_to_cpu(conf->prim_elmnt_count));
+ conf->prl, conf->rlq, be16_to_cpu(conf->prim_elmnt_count));
return -1;
}
@@ -646,7 +650,7 @@ static int layout_ddf2md(const struct vd_config *conf,
{
int level = LEVEL_UNSUPPORTED;
int layout = 0;
- int raiddisks = __be16_to_cpu(conf->prim_elmnt_count);
+ int raiddisks = be16_to_cpu(conf->prim_elmnt_count);
if (conf->sec_elmnt_count > 1) {
/* see also check_secondary() */
@@ -907,9 +911,9 @@ static int load_ddf_global(int fd, struct ddf_super *super, char *devname)
super->conflist = NULL;
super->dlist = NULL;
- super->max_part = __be16_to_cpu(super->active->max_partitions);
- super->mppe = __be16_to_cpu(super->active->max_primary_element_entries);
- super->conf_rec_len = __be16_to_cpu(super->active->config_record_len);
+ super->max_part = be16_to_cpu(super->active->max_partitions);
+ super->mppe = be16_to_cpu(super->active->max_primary_element_entries);
+ super->conf_rec_len = be16_to_cpu(super->active->config_record_len);
return 0;
}
@@ -969,7 +973,8 @@ static int load_ddf_local(int fd, struct ddf_super *super,
unsigned int i;
unsigned int confsec;
int vnum;
- unsigned int max_virt_disks = __be16_to_cpu(super->active->max_vd_entries);
+ unsigned int max_virt_disks = be16_to_cpu
+ (super->active->max_vd_entries);
unsigned long long dsize;
/* First the local disk info */
@@ -1008,7 +1013,7 @@ static int load_ddf_local(int fd, struct ddf_super *super,
dl->vlist[i] = NULL;
super->dlist = dl;
dl->pdnum = -1;
- for (i = 0; i < __be16_to_cpu(super->active->max_pd_entries); i++)
+ for (i = 0; i < be16_to_cpu(super->active->max_pd_entries); i++)
if (memcmp(super->phys->entries[i].guid,
dl->disk.guid, DDF_GUID_LEN) == 0)
dl->pdnum = i;
@@ -1371,10 +1376,10 @@ static void examine_vd(int n, struct ddf_super *sb, char *guid)
/* Ok, we know about this VD, let's give more details */
printf(" Raid Devices[%d] : %d (", n,
- __be16_to_cpu(vc->prim_elmnt_count));
- for (i = 0; i < __be16_to_cpu(vc->prim_elmnt_count); i++) {
+ be16_to_cpu(vc->prim_elmnt_count));
+ for (i = 0; i < be16_to_cpu(vc->prim_elmnt_count); i++) {
int j;
- int cnt = __be16_to_cpu(sb->phys->used_pdes);
+ int cnt = be16_to_cpu(sb->phys->used_pdes);
for (j=0; j<cnt; j++)
if (be32_eq(vc->phys_refnum[i],
sb->phys->entries[j].refnum))
@@ -1406,18 +1411,18 @@ static void examine_vd(int n, struct ddf_super *sb, char *guid)
static void examine_vds(struct ddf_super *sb)
{
- int cnt = __be16_to_cpu(sb->virt->populated_vdes);
+ int cnt = be16_to_cpu(sb->virt->populated_vdes);
unsigned int i;
printf(" Virtual Disks : %d\n", cnt);
- for (i = 0; i < __be16_to_cpu(sb->virt->max_vdes); i++) {
+ for (i = 0; i < be16_to_cpu(sb->virt->max_vdes); i++) {
struct virtual_entry *ve = &sb->virt->entries[i];
if (all_ff(ve->guid))
continue;
printf("\n");
printf(" VD GUID[%d] : ", i); print_guid(ve->guid, 1);
printf("\n");
- printf(" unit[%d] : %d\n", i, __be16_to_cpu(ve->unit));
+ printf(" unit[%d] : %d\n", i, be16_to_cpu(ve->unit));
printf(" state[%d] : %s, %s%s\n", i,
map_num(ddf_state, ve->state & 7),
(ve->state & 8) ? "Morphing, ": "",
@@ -1434,7 +1439,7 @@ static void examine_vds(struct ddf_super *sb)
static void examine_pds(struct ddf_super *sb)
{
- int cnt = __be16_to_cpu(sb->phys->used_pdes);
+ int cnt = be16_to_cpu(sb->phys->used_pdes);
int i;
struct dl *dl;
printf(" Physical Disks : %d\n", cnt);
@@ -1442,8 +1447,8 @@ static void examine_pds(struct ddf_super *sb)
for (i=0 ; i<cnt ; i++) {
struct phys_disk_entry *pd = &sb->phys->entries[i];
- int type = __be16_to_cpu(pd->type);
- int state = __be16_to_cpu(pd->state);
+ int type = be16_to_cpu(pd->type);
+ int state = be16_to_cpu(pd->state);
//printf(" PD GUID[%d] : ", i); print_guid(pd->guid, 0);
//printf("\n");
@@ -1531,7 +1536,7 @@ static unsigned int get_vd_num_of_subarray(struct supertype *st)
if (sub != NULL)
vcnum = strtoul(sub + 1, &end, 10);
if (sub == NULL || *sub == '\0' || *end != '\0' ||
- vcnum >= __be16_to_cpu(ddf->active->max_vd_entries))
+ vcnum >= be16_to_cpu(ddf->active->max_vd_entries))
return DDF_NOTFOUND;
return vcnum;
@@ -1560,7 +1565,7 @@ static void brief_examine_subarrays_ddf(struct supertype *st, int verbose)
getinfo_super_ddf(st, &info, NULL);
fname_from_uuid(st, &info, nbuf, ':');
- for (i = 0; i < __be16_to_cpu(ddf->virt->max_vdes); i++) {
+ for (i = 0; i < be16_to_cpu(ddf->virt->max_vdes); i++) {
struct virtual_entry *ve = &ddf->virt->entries[i];
struct vcl vcl;
char nbuf1[64];
@@ -1704,7 +1709,7 @@ static int find_index_in_bvd(const struct ddf_super *ddf,
*/
unsigned int i, j;
for (i = 0, j = 0; i < ddf->mppe &&
- j < __be16_to_cpu(conf->prim_elmnt_count); i++) {
+ j < be16_to_cpu(conf->prim_elmnt_count); i++) {
if (be32_to_cpu(conf->phys_refnum[i]) != 0xffffffff) {
if (n == j) {
*n_bvd = i;
@@ -1714,7 +1719,7 @@ static int find_index_in_bvd(const struct ddf_super *ddf,
}
}
dprintf("%s: couldn't find BVD member %u (total %u)\n",
- __func__, n, __be16_to_cpu(conf->prim_elmnt_count));
+ __func__, n, be16_to_cpu(conf->prim_elmnt_count));
return 0;
}
@@ -1742,7 +1747,7 @@ static struct vd_config *find_vdcr(struct ddf_super *ddf, unsigned int inst,
__func__, conf->sec_elmnt_count);
goto bad;
}
- nsec = n / __be16_to_cpu(conf->prim_elmnt_count);
+ nsec = n / be16_to_cpu(conf->prim_elmnt_count);
if (conf->sec_elmnt_seq != nsec) {
for (ibvd = 1; ibvd < conf->sec_elmnt_count; ibvd++) {
if (v->other_bvds[ibvd-1]->sec_elmnt_seq
@@ -1773,7 +1778,7 @@ static int find_phys(const struct ddf_super *ddf, be32 phys_refnum)
* and return it's index
*/
unsigned int i;
- for (i = 0; i < __be16_to_cpu(ddf->phys->max_pdes); i++)
+ for (i = 0; i < be16_to_cpu(ddf->phys->max_pdes); i++)
if (be32_eq(ddf->phys->entries[i].refnum, phys_refnum))
return i;
return -1;
@@ -1835,7 +1840,7 @@ static void getinfo_super_ddf(struct supertype *st, struct mdinfo *info, char *m
}
memset(info, 0, sizeof(*info));
- info->array.raid_disks = __be16_to_cpu(ddf->phys->used_pdes);
+ info->array.raid_disks = be16_to_cpu(ddf->phys->used_pdes);
info->array.level = LEVEL_CONTAINER;
info->array.layout = 0;
info->array.md_minor = -1;
@@ -1879,8 +1884,10 @@ static void getinfo_super_ddf(struct supertype *st, struct mdinfo *info, char *m
int i;
for (i = 0 ; i < map_disks; i++) {
if (i < info->array.raid_disks &&
- (__be16_to_cpu(ddf->phys->entries[i].state) & DDF_Online) &&
- !(__be16_to_cpu(ddf->phys->entries[i].state) & DDF_Failed))
+ (be16_to_cpu(ddf->phys->entries[i].state)
+ & DDF_Online) &&
+ !(be16_to_cpu(ddf->phys->entries[i].state)
+ & DDF_Failed))
map[i] = 1;
else
map[i] = 0;
@@ -1911,7 +1918,7 @@ static void getinfo_super_ddf_bvd(struct supertype *st, struct mdinfo *info, cha
info->custom_array_size = 0;
conf = &vc->conf;
- n_prim = __be16_to_cpu(conf->prim_elmnt_count);
+ n_prim = be16_to_cpu(conf->prim_elmnt_count);
if (conf->sec_elmnt_count > 1 && cd >= n_prim) {
int ibvd = cd / n_prim - 1;
cd %= n_prim;
@@ -1938,7 +1945,7 @@ static void getinfo_super_ddf_bvd(struct supertype *st, struct mdinfo *info, cha
info->disk.major = dl->major;
info->disk.minor = dl->minor;
info->disk.raid_disk = cd + conf->sec_elmnt_seq
- * __be16_to_cpu(conf->prim_elmnt_count);
+ * be16_to_cpu(conf->prim_elmnt_count);
info->disk.number = dl->pdnum;
info->disk.state = (1<<MD_DISK_SYNC)|(1<<MD_DISK_ACTIVE);
}
@@ -1977,8 +1984,10 @@ static void getinfo_super_ddf_bvd(struct supertype *st, struct mdinfo *info, cha
if (j < info->array.raid_disks) {
int i = find_phys(ddf, vc->conf.phys_refnum[j]);
if (i >= 0 &&
- (__be16_to_cpu(ddf->phys->entries[i].state) & DDF_Online) &&
- !(__be16_to_cpu(ddf->phys->entries[i].state) & DDF_Failed))
+ (be16_to_cpu(ddf->phys->entries[i].state)
+ & DDF_Online) &&
+ !(be16_to_cpu(ddf->phys->entries[i].state)
+ & DDF_Failed))
map[i] = 1;
}
}
@@ -2077,7 +2086,7 @@ static void make_header_guid(char *guid)
static unsigned int find_unused_vde(const struct ddf_super *ddf)
{
unsigned int i;
- for (i = 0; i < __be16_to_cpu(ddf->virt->max_vdes); i++) {
+ for (i = 0; i < be16_to_cpu(ddf->virt->max_vdes); i++) {
if (all_ff(ddf->virt->entries[i].guid))
return i;
}
@@ -2090,7 +2099,7 @@ static unsigned int find_vde_by_name(const struct ddf_super *ddf,
unsigned int i;
if (name == NULL)
return DDF_NOTFOUND;
- for (i = 0; i < __be16_to_cpu(ddf->virt->max_vdes); i++) {
+ for (i = 0; i < be16_to_cpu(ddf->virt->max_vdes); i++) {
if (all_ff(ddf->virt->entries[i].guid))
continue;
if (!strncmp(name, ddf->virt->entries[i].name,
@@ -2106,7 +2115,7 @@ static unsigned int find_vde_by_guid(const struct ddf_super *ddf,
unsigned int i;
if (guid == NULL || all_ff(guid))
return DDF_NOTFOUND;
- for (i = 0; i < __be16_to_cpu(ddf->virt->max_vdes); i++)
+ for (i = 0; i < be16_to_cpu(ddf->virt->max_vdes); i++)
if (!memcmp(ddf->virt->entries[i].guid, guid, DDF_GUID_LEN))
return i;
return DDF_NOTFOUND;
@@ -2208,15 +2217,15 @@ static int init_super_ddf(struct supertype *st,
/* Put this at bottom of 32M reserved.. */
ddf->anchor.workspace_lba = cpu_to_be64(~(__u64)0);
max_phys_disks = 1023; /* Should be enough */
- ddf->anchor.max_pd_entries = __cpu_to_be16(max_phys_disks);
+ ddf->anchor.max_pd_entries = cpu_to_be16(max_phys_disks);
max_virt_disks = 255;
- ddf->anchor.max_vd_entries = __cpu_to_be16(max_virt_disks); /* ?? */
- ddf->anchor.max_partitions = __cpu_to_be16(64); /* ?? */
+ ddf->anchor.max_vd_entries = cpu_to_be16(max_virt_disks); /* ?? */
+ ddf->anchor.max_partitions = cpu_to_be16(64); /* ?? */
ddf->max_part = 64;
ddf->mppe = 256;
ddf->conf_rec_len = 1 + ROUND_UP(ddf->mppe * (4+8), 512)/512;
- ddf->anchor.config_record_len = __cpu_to_be16(ddf->conf_rec_len);
- ddf->anchor.max_primary_element_entries = __cpu_to_be16(ddf->mppe);
+ ddf->anchor.config_record_len = cpu_to_be16(ddf->conf_rec_len);
+ ddf->anchor.max_primary_element_entries = cpu_to_be16(ddf->mppe);
memset(ddf->anchor.pad3, 0xff, 54);
/* controller sections is one sector long immediately
* after the ddf header */
@@ -2294,10 +2303,10 @@ static int init_super_ddf(struct supertype *st,
for (i = strlen(T10) ; i+hostlen < 24; i++)
ddf->controller.guid[i] = ' ';
- ddf->controller.type.vendor_id = __cpu_to_be16(0xDEAD);
- ddf->controller.type.device_id = __cpu_to_be16(0xBEEF);
- ddf->controller.type.sub_vendor_id = 0;
- ddf->controller.type.sub_device_id = 0;
+ ddf->controller.type.vendor_id = cpu_to_be16(0xDEAD);
+ ddf->controller.type.device_id = cpu_to_be16(0xBEEF);
+ ddf->controller.type.sub_vendor_id = cpu_to_be16(0);
+ ddf->controller.type.sub_device_id = cpu_to_be16(0);
memcpy(ddf->controller.product_id, "What Is My PID??", 16);
memset(ddf->controller.pad, 0xff, 8);
memset(ddf->controller.vendor_data, 0xff, 448);
@@ -2314,8 +2323,8 @@ static int init_super_ddf(struct supertype *st,
memset(pd, 0xff, pdsize);
memset(pd, 0, sizeof(*pd));
pd->magic = DDF_PHYS_RECORDS_MAGIC;
- pd->used_pdes = __cpu_to_be16(0);
- pd->max_pdes = __cpu_to_be16(max_phys_disks);
+ pd->used_pdes = cpu_to_be16(0);
+ pd->max_pdes = cpu_to_be16(max_phys_disks);
memset(pd->pad, 0xff, 52);
for (i = 0; i < max_phys_disks; i++)
memset(pd->entries[i].guid, 0xff, DDF_GUID_LEN);
@@ -2328,8 +2337,8 @@ static int init_super_ddf(struct supertype *st,
ddf->vdsize = vdsize;
memset(vd, 0, vdsize);
vd->magic = DDF_VIRT_RECORDS_MAGIC;
- vd->populated_vdes = __cpu_to_be16(0);
- vd->max_vdes = __cpu_to_be16(max_virt_disks);
+ vd->populated_vdes = cpu_to_be16(0);
+ vd->max_vdes = cpu_to_be16(max_virt_disks);
memset(vd->pad, 0xff, 52);
for (i=0; i<max_virt_disks; i++)
@@ -2426,10 +2435,11 @@ static int init_super_ddf_bvd(struct supertype *st,
* timestamp, random number
*/
make_header_guid(ve->guid);
- ve->unit = __cpu_to_be16(info->md_minor);
+ ve->unit = cpu_to_be16(info->md_minor);
ve->pad0 = 0xFFFF;
- ve->guid_crc = crc32(0, (unsigned char*)ddf->anchor.guid, DDF_GUID_LEN);
- ve->type = 0;
+ ve->guid_crc._v16 = crc32(0, (unsigned char *)ddf->anchor.guid,
+ DDF_GUID_LEN);
+ ve->type = cpu_to_be16(0);
ve->state = DDF_state_degraded; /* Will be modified as devices are added */
if (info->state & 1) /* clean */
ve->init_state = DDF_init_full;
@@ -2441,7 +2451,7 @@ static int init_super_ddf_bvd(struct supertype *st,
if (name)
strncpy(ve->name, name, 16);
ddf->virt->populated_vdes =
- __cpu_to_be16(__be16_to_cpu(ddf->virt->populated_vdes)+1);
+ cpu_to_be16(be16_to_cpu(ddf->virt->populated_vdes)+1);
/* Now create a new vd_config */
if (posix_memalign((void**)&vcl, 512,
@@ -2460,7 +2470,7 @@ static int init_super_ddf_bvd(struct supertype *st,
memset(vc->pad0, 0xff, 24);
vc->chunk_shift = chunk_to_shift(info->chunk_size);
if (layout_md2ddf(info, vc) == -1 ||
- __be16_to_cpu(vc->prim_elmnt_count) > ddf->mppe) {
+ be16_to_cpu(vc->prim_elmnt_count) > ddf->mppe) {
pr_err("%s: unsupported RAID level/layout %d/%d with %d disks\n",
__func__, info->level, info->layout, info->raid_disks);
free(vcl);
@@ -2551,7 +2561,7 @@ static void add_to_super_ddf_bvd(struct supertype *st,
vc = &ddf->currentconf->conf;
if (vc->sec_elmnt_count > 1) {
- unsigned int n = __be16_to_cpu(vc->prim_elmnt_count);
+ unsigned int n = be16_to_cpu(vc->prim_elmnt_count);
if (raid_disk >= n)
vc = ddf->currentconf->other_bvds[raid_disk / n - 1];
raid_disk %= n;
@@ -2599,8 +2609,10 @@ static void add_to_super_ddf_bvd(struct supertype *st,
ddf->virt->entries[i].state =
(ddf->virt->entries[i].state & ~DDF_state_mask)
| get_svd_state(ddf, ddf->currentconf);
- ddf->phys->entries[dl->pdnum].type &= ~__cpu_to_be16(DDF_Global_Spare);
- ddf->phys->entries[dl->pdnum].type |= __cpu_to_be16(DDF_Active_in_VD);
+ be16_clear(ddf->phys->entries[dl->pdnum].type,
+ cpu_to_be16(DDF_Global_Spare));
+ be16_set(ddf->phys->entries[dl->pdnum].type,
+ cpu_to_be16(DDF_Active_in_VD));
dprintf("%s: added disk %d/%08x to VD %d/%s as disk %d\n",
__func__, dl->pdnum, be32_to_cpu(dl->disk.refnum),
ddf->currentconf->vcnum, guid_str(vc->guid),
@@ -2611,7 +2623,7 @@ static void add_to_super_ddf_bvd(struct supertype *st,
static unsigned int find_unused_pde(const struct ddf_super *ddf)
{
unsigned int i;
- for (i = 0; i < __be16_to_cpu(ddf->phys->max_pdes); i++) {
+ for (i = 0; i < be16_to_cpu(ddf->phys->max_pdes); i++) {
if (all_ff(ddf->phys->entries[i].guid))
return i;
}
@@ -2683,7 +2695,7 @@ static int add_to_super_ddf(struct supertype *st,
do {
/* Cannot be bothered finding a CRC of some irrelevant details*/
dd->disk.refnum._v32 = random32();
- for (i = __be16_to_cpu(ddf->active->max_pd_entries);
+ for (i = be16_to_cpu(ddf->active->max_pd_entries);
i > 0; i--)
if (be32_eq(ddf->phys->entries[i-1].refnum,
dd->disk.refnum))
@@ -2707,17 +2719,17 @@ static int add_to_super_ddf(struct supertype *st,
pd = xmalloc(len);
pd->magic = DDF_PHYS_RECORDS_MAGIC;
- pd->used_pdes = __cpu_to_be16(n);
+ pd->used_pdes = cpu_to_be16(n);
pde = &pd->entries[0];
dd->mdupdate = pd;
} else
- ddf->phys->used_pdes = __cpu_to_be16(
- 1 + __be16_to_cpu(ddf->phys->used_pdes));
+ ddf->phys->used_pdes = cpu_to_be16(
+ 1 + be16_to_cpu(ddf->phys->used_pdes));
memcpy(pde->guid, dd->disk.guid, DDF_GUID_LEN);
pde->refnum = dd->disk.refnum;
- pde->type = __cpu_to_be16(DDF_Forced_PD_GUID | DDF_Global_Spare);
- pde->state = __cpu_to_be16(DDF_Online);
+ pde->type = cpu_to_be16(DDF_Forced_PD_GUID | DDF_Global_Spare);
+ pde->state = cpu_to_be16(DDF_Online);
dd->size = size;
/*
* If there is already a device in dlist, try to reserve the same
@@ -2782,8 +2794,8 @@ static int remove_from_super_ddf(struct supertype *st, mdu_disk_info_t *dk)
pd = xmalloc(len);
pd->magic = DDF_PHYS_RECORDS_MAGIC;
- pd->used_pdes = __cpu_to_be16(dl->pdnum);
- pd->entries[0].state = __cpu_to_be16(DDF_Missing);
+ pd->used_pdes = cpu_to_be16(dl->pdnum);
+ pd->entries[0].state = cpu_to_be16(DDF_Missing);
append_metadata_update(st, pd, len);
}
return 0;
@@ -3010,7 +3022,7 @@ static int write_init_super_ddf(struct supertype *st)
vd = xmalloc(len);
*vd = *ddf->virt;
vd->entries[0] = ddf->virt->entries[currentconf->vcnum];
- vd->populated_vdes = __cpu_to_be16(currentconf->vcnum);
+ vd->populated_vdes = cpu_to_be16(currentconf->vcnum);
append_metadata_update(st, vd, len);
/* Then the vd_config */
@@ -3542,7 +3554,7 @@ static int check_secondary(const struct vcl *vc)
pr_err("Different RAID levels for BVDs are unsupported\n");
return -1;
}
- if (bvd->prim_elmnt_count != conf->prim_elmnt_count) {
+ if (!be16_eq(bvd->prim_elmnt_count, conf->prim_elmnt_count)) {
pr_err("All BVDs must have the same number of primary elements\n");
return -1;
}
@@ -3572,7 +3584,7 @@ static unsigned int get_pd_index_from_refnum(const struct vcl *vc,
{
unsigned int i, j, n, sec, cnt;
- cnt = __be16_to_cpu(vc->conf.prim_elmnt_count);
+ cnt = be16_to_cpu(vc->conf.prim_elmnt_count);
sec = (vc->conf.sec_elmnt_count == 1 ? 0 : vc->conf.sec_elmnt_seq);
for (i = 0, j = 0 ; i < nmax ; i++) {
@@ -3685,7 +3697,7 @@ static struct mdinfo *container_content_ddf(struct supertype *st, char *subarray
sprintf(this->text_version, "/%s/%d",
st->container_devnm, this->container_member);
- for (pd = 0; pd < __be16_to_cpu(ddf->phys->used_pdes); pd++) {
+ for (pd = 0; pd < be16_to_cpu(ddf->phys->used_pdes); pd++) {
struct mdinfo *dev;
struct dl *d;
const struct vd_config *bvd;
@@ -3696,7 +3708,7 @@ static struct mdinfo *container_content_ddf(struct supertype *st, char *subarray
== 0xFFFFFFFF)
continue;
- stt = __be16_to_cpu(ddf->phys->entries[pd].state);
+ stt = be16_to_cpu(ddf->phys->entries[pd].state);
if ((stt & (DDF_Online|DDF_Failed|DDF_Rebuilding))
!= DDF_Online)
continue;
@@ -3822,13 +3834,14 @@ static int compare_super_ddf(struct supertype *st, struct supertype *tst)
return 3;
}
if (first->max_part != second->max_part ||
- first->phys->used_pdes != second->phys->used_pdes ||
- first->virt->populated_vdes != second->virt->populated_vdes) {
+ !be16_eq(first->phys->used_pdes, second->phys->used_pdes) ||
+ !be16_eq(first->virt->populated_vdes,
+ second->virt->populated_vdes)) {
dprintf("%s: PD/VD number mismatch\n", __func__);
return 3;
}
- max_pds = __be16_to_cpu(first->phys->used_pdes);
+ max_pds = be16_to_cpu(first->phys->used_pdes);
for (dl2 = second->dlist; dl2; dl2 = dl2->next) {
for (pd = 0; pd < max_pds; pd++)
if (be32_eq(first->phys->entries[pd].refnum,
@@ -3841,7 +3854,7 @@ static int compare_super_ddf(struct supertype *st, struct supertype *tst)
}
}
- max_vds = __be16_to_cpu(first->active->max_vd_entries);
+ max_vds = be16_to_cpu(first->active->max_vd_entries);
for (vl2 = second->conflist; vl2; vl2 = vl2->next) {
if (!be32_eq(vl2->conf.magic, DDF_VD_CONF_MAGIC))
continue;
@@ -4026,7 +4039,7 @@ static int get_bvd_state(const struct ddf_super *ddf,
const struct vd_config *vc)
{
unsigned int i, n_bvd, working = 0;
- unsigned int n_prim = __be16_to_cpu(vc->prim_elmnt_count);
+ unsigned int n_prim = be16_to_cpu(vc->prim_elmnt_count);
int pd, st, state;
for (i = 0; i < n_prim; i++) {
if (!find_index_in_bvd(ddf, vc, i, &n_bvd))
@@ -4034,7 +4047,7 @@ static int get_bvd_state(const struct ddf_super *ddf,
pd = find_phys(ddf, vc->phys_refnum[n_bvd]);
if (pd < 0)
continue;
- st = __be16_to_cpu(ddf->phys->entries[pd].state);
+ st = be16_to_cpu(ddf->phys->entries[pd].state);
if ((st & (DDF_Online|DDF_Failed|DDF_Rebuilding))
== DDF_Online)
working++;
@@ -4162,21 +4175,24 @@ static void ddf_set_disk(struct active_array *a, int n, int state)
vc->phys_refnum[n_bvd] = dl->disk.refnum;
LBA_OFFSET(ddf, vc)[n_bvd] =
cpu_to_be64(mdi->data_offset);
- ddf->phys->entries[pd].type &=
- ~__cpu_to_be16(DDF_Global_Spare);
- ddf->phys->entries[pd].type |=
- __cpu_to_be16(DDF_Active_in_VD);
+ be16_clear(ddf->phys->entries[pd].type,
+ cpu_to_be16(DDF_Global_Spare));
+ be16_set(ddf->phys->entries[pd].type,
+ cpu_to_be16(DDF_Active_in_VD));
ddf_set_updates_pending(ddf);
}
} else {
- int old = ddf->phys->entries[pd].state;
+ be16 old = ddf->phys->entries[pd].state;
if (state & DS_FAULTY)
- ddf->phys->entries[pd].state |= __cpu_to_be16(DDF_Failed);
+ be16_set(ddf->phys->entries[pd].state,
+ cpu_to_be16(DDF_Failed));
if (state & DS_INSYNC) {
- ddf->phys->entries[pd].state |= __cpu_to_be16(DDF_Online);
- ddf->phys->entries[pd].state &= __cpu_to_be16(~DDF_Rebuilding);
+ be16_set(ddf->phys->entries[pd].state,
+ cpu_to_be16(DDF_Online));
+ be16_clear(ddf->phys->entries[pd].state,
+ cpu_to_be16(DDF_Rebuilding));
}
- if (old != ddf->phys->entries[pd].state)
+ if (!be16_eq(old, ddf->phys->entries[pd].state))
ddf_set_updates_pending(ddf);
}
@@ -4291,7 +4307,7 @@ static int kill_subarray_ddf(struct supertype *st)
}
memset(vd, 0 , len);
vd->magic = DDF_VIRT_RECORDS_MAGIC;
- vd->populated_vdes = 0;
+ vd->populated_vdes = cpu_to_be16(0);
memcpy(vd->entries[0].guid, conf->guid, DDF_GUID_LEN);
/* we use DDF_state_deleted as marker */
vd->entries[0].state = DDF_state_deleted;
@@ -4309,7 +4325,7 @@ static void copy_matching_bvd(struct ddf_super *ddf,
const struct metadata_update *update)
{
unsigned int mppe =
- __be16_to_cpu(ddf->anchor.max_primary_element_entries);
+ be16_to_cpu(ddf->anchor.max_primary_element_entries);
unsigned int len = ddf->conf_rec_len * 512;
char *p;
struct vd_config *vc;
@@ -4374,13 +4390,14 @@ static void ddf_process_update(struct supertype *st,
return;
pd = (struct phys_disk*)update->buf;
- ent = __be16_to_cpu(pd->used_pdes);
- if (ent >= __be16_to_cpu(ddf->phys->max_pdes))
+ ent = be16_to_cpu(pd->used_pdes);
+ if (ent >= be16_to_cpu(ddf->phys->max_pdes))
return;
- if (pd->entries[0].state & __cpu_to_be16(DDF_Missing)) {
+ if (be16_and(pd->entries[0].state, cpu_to_be16(DDF_Missing))) {
struct dl **dlp;
/* removing this disk. */
- ddf->phys->entries[ent].state |= __cpu_to_be16(DDF_Missing);
+ be16_set(ddf->phys->entries[ent].state,
+ cpu_to_be16(DDF_Missing));
for (dlp = &ddf->dlist; *dlp; dlp = &(*dlp)->next) {
struct dl *dl = *dlp;
if (dl->pdnum == (signed)ent) {
@@ -4399,8 +4416,8 @@ static void ddf_process_update(struct supertype *st,
if (!all_ff(ddf->phys->entries[ent].guid))
return;
ddf->phys->entries[ent] = pd->entries[0];
- ddf->phys->used_pdes = __cpu_to_be16(1 +
- __be16_to_cpu(ddf->phys->used_pdes));
+ ddf->phys->used_pdes = cpu_to_be16
+ (1 + be16_to_cpu(ddf->phys->used_pdes));
ddf_set_updates_pending(ddf);
if (ddf->add_list) {
struct active_array *a;
@@ -4440,8 +4457,8 @@ static void ddf_process_update(struct supertype *st,
return;
ddf->virt->entries[ent] = vd->entries[0];
ddf->virt->populated_vdes =
- __cpu_to_be16(
- 1 + __be16_to_cpu(
+ cpu_to_be16(
+ 1 + be16_to_cpu(
ddf->virt->populated_vdes));
dprintf("%s: added VD %s in slot %d(s=%02x i=%02x)\n",
__func__, guid_str(vd->entries[0].guid), ent,
@@ -4495,11 +4512,12 @@ static void ddf_process_update(struct supertype *st,
/* Set DDF_Transition on all Failed devices - to help
* us detect those that are no longer in use
*/
- for (pdnum = 0; pdnum < __be16_to_cpu(ddf->phys->used_pdes); pdnum++)
- if (ddf->phys->entries[pdnum].state
- & __be16_to_cpu(DDF_Failed))
- ddf->phys->entries[pdnum].state
- |= __be16_to_cpu(DDF_Transition);
+ for (pdnum = 0; pdnum < be16_to_cpu(ddf->phys->used_pdes);
+ pdnum++)
+ if (be16_and(ddf->phys->entries[pdnum].state,
+ cpu_to_be16(DDF_Failed)))
+ be16_set(ddf->phys->entries[pdnum].state,
+ cpu_to_be16(DDF_Transition));
/* Now make sure vlist is correct for each dl. */
for (dl = ddf->dlist; dl; dl = dl->next) {
unsigned int vn = 0;
@@ -4520,10 +4538,12 @@ static void ddf_process_update(struct supertype *st,
guid_str(conf->guid),
conf->sec_elmnt_seq, vn);
/* Clear the Transition flag */
- if (ddf->phys->entries[dl->pdnum].state
- & __be16_to_cpu(DDF_Failed))
- ddf->phys->entries[dl->pdnum].state &=
- ~__be16_to_cpu(DDF_Transition);
+ if (be16_and
+ (ddf->phys->entries[dl->pdnum].state,
+ cpu_to_be16(DDF_Failed)))
+ be16_clear(ddf->phys
+ ->entries[dl->pdnum].state,
+ cpu_to_be16(DDF_Transition));
dl->vlist[vn++] = vcl;
vstate = ddf->virt->entries[vcl->vcnum].state
& DDF_state_mask;
@@ -4534,29 +4554,35 @@ static void ddf_process_update(struct supertype *st,
while (vn < ddf->max_part)
dl->vlist[vn++] = NULL;
if (dl->vlist[0]) {
- ddf->phys->entries[dl->pdnum].type &=
- ~__cpu_to_be16(DDF_Global_Spare);
- if (!(ddf->phys->entries[dl->pdnum].type &
- __cpu_to_be16(DDF_Active_in_VD))) {
- ddf->phys->entries[dl->pdnum].type |=
- __cpu_to_be16(DDF_Active_in_VD);
+ be16_clear(ddf->phys->entries[dl->pdnum].type,
+ cpu_to_be16(DDF_Global_Spare));
+ if (!be16_and(ddf->phys
+ ->entries[dl->pdnum].type,
+ cpu_to_be16(DDF_Active_in_VD))) {
+ be16_set(ddf->phys
+ ->entries[dl->pdnum].type,
+ cpu_to_be16(DDF_Active_in_VD));
if (in_degraded)
- ddf->phys->entries[dl->pdnum].state |=
- __cpu_to_be16(DDF_Rebuilding);
+ be16_set(ddf->phys
+ ->entries[dl->pdnum]
+ .state,
+ cpu_to_be16
+ (DDF_Rebuilding));
}
}
if (dl->spare) {
- ddf->phys->entries[dl->pdnum].type &=
- ~__cpu_to_be16(DDF_Global_Spare);
- ddf->phys->entries[dl->pdnum].type |=
- __cpu_to_be16(DDF_Spare);
+ be16_clear(ddf->phys->entries[dl->pdnum].type,
+ cpu_to_be16(DDF_Global_Spare));
+ be16_set(ddf->phys->entries[dl->pdnum].type,
+ cpu_to_be16(DDF_Spare));
}
if (!dl->vlist[0] && !dl->spare) {
- ddf->phys->entries[dl->pdnum].type |=
- __cpu_to_be16(DDF_Global_Spare);
- ddf->phys->entries[dl->pdnum].type &=
- ~__cpu_to_be16(DDF_Spare |
- DDF_Active_in_VD);
+ be16_set(ddf->phys->entries[dl->pdnum].type,
+ cpu_to_be16(DDF_Global_Spare));
+ be16_clear(ddf->phys->entries[dl->pdnum].type,
+ cpu_to_be16(DDF_Spare));
+ be16_clear(ddf->phys->entries[dl->pdnum].type,
+ cpu_to_be16(DDF_Active_in_VD));
}
}
@@ -4565,24 +4591,27 @@ static void ddf_process_update(struct supertype *st,
* Once done, we need to update all dl->pdnum numbers.
*/
pd2 = 0;
- for (pdnum = 0; pdnum < __be16_to_cpu(ddf->phys->used_pdes); pdnum++)
- if ((ddf->phys->entries[pdnum].state
- & __be16_to_cpu(DDF_Failed))
- && (ddf->phys->entries[pdnum].state
- & __be16_to_cpu(DDF_Transition)))
+ for (pdnum = 0; pdnum < be16_to_cpu(ddf->phys->used_pdes);
+ pdnum++)
+ if (be16_and(ddf->phys->entries[pdnum].state,
+ cpu_to_be16(DDF_Failed))
+ && be16_and(ddf->phys->entries[pdnum].state,
+ cpu_to_be16(DDF_Transition)))
/* skip this one */;
else if (pdnum == pd2)
pd2++;
else {
- ddf->phys->entries[pd2] = ddf->phys->entries[pdnum];
+ ddf->phys->entries[pd2] =
+ ddf->phys->entries[pdnum];
for (dl = ddf->dlist; dl; dl = dl->next)
if (dl->pdnum == (int)pdnum)
dl->pdnum = pd2;
pd2++;
}
- ddf->phys->used_pdes = __cpu_to_be16(pd2);
+ ddf->phys->used_pdes = cpu_to_be16(pd2);
while (pd2 < pdnum) {
- memset(ddf->phys->entries[pd2].guid, 0xff, DDF_GUID_LEN);
+ memset(ddf->phys->entries[pd2].guid, 0xff,
+ DDF_GUID_LEN);
pd2++;
}
@@ -4658,7 +4687,8 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a,
working ++;
}
- dprintf("ddf_activate: working=%d (%d) level=%d\n", working, a->info.array.raid_disks,
+ dprintf("ddf_activate: working=%d (%d) level=%d\n", working,
+ a->info.array.raid_disks,
a->info.array.level);
if (working == a->info.array.raid_disks)
return NULL; /* array not degraded */
@@ -4710,14 +4740,16 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a,
}
if (d2)
continue;
- if (ddf->phys->entries[dl->pdnum].type &
- __cpu_to_be16(DDF_Spare)) {
+ if (be16_and(ddf->phys->entries[dl->pdnum].type,
+ cpu_to_be16(DDF_Spare))) {
/* Check spare assign record */
if (dl->spare) {
if (dl->spare->type & DDF_spare_dedicated) {
/* check spare_ents for guid */
for (j = 0 ;
- j < __be16_to_cpu(dl->spare->populated);
+ j < be16_to_cpu
+ (dl->spare
+ ->populated);
j++) {
if (memcmp(dl->spare->spare_ents[j].guid,
ddf->virt->entries[a->info.container_member].guid,
@@ -4727,11 +4759,12 @@ static struct mdinfo *ddf_activate_spare(struct active_array *a,
} else
is_global = 1;
}
- } else if (ddf->phys->entries[dl->pdnum].type &
- __cpu_to_be16(DDF_Global_Spare)) {
+ } else if (be16_and(ddf->phys->entries[dl->pdnum].type,
+ cpu_to_be16(DDF_Global_Spare))) {
is_global = 1;
- } else if (!(ddf->phys->entries[dl->pdnum].state &
- __cpu_to_be16(DDF_Failed))) {
+ } else if (!be16_and(ddf->phys
+ ->entries[dl->pdnum].state,
+ cpu_to_be16(DDF_Failed))) {
/* we can possibly use some of this */
is_global = 1;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/6] DDF: add_other_bvd: fix endianness bug
2013-07-21 17:28 [RFC/PATCH 0/6] DDF: safe big-endian types mwilck
` (3 preceding siblings ...)
2013-07-21 17:28 ` [PATCH 4/6] DDF: convert big-endian __u16 to be16 type mwilck
@ 2013-07-21 17:28 ` mwilck
2013-07-21 17:28 ` [PATCH 6/6] DDF: ddf_set_disk: fix minor " mwilck
2013-07-23 4:06 ` [RFC/PATCH 0/6] DDF: safe big-endian types NeilBrown
6 siblings, 0 replies; 8+ messages in thread
From: mwilck @ 2013-07-21 17:28 UTC (permalink / raw)
To: neilb, linux-raid; +Cc: mwilck
---
super-ddf.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/super-ddf.c b/super-ddf.c
index bd42194..ff71be2 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -949,7 +949,8 @@ static void add_other_bvd(struct vcl *vcl, struct vd_config *vd,
break;
if (i < vcl->conf.sec_elmnt_count-1) {
- if (vd->seqnum <= vcl->other_bvds[i]->seqnum)
+ if (be32_to_cpu(vd->seqnum) <=
+ be32_to_cpu(vcl->other_bvds[i]->seqnum))
return;
} else {
for (i = 0; i < vcl->conf.sec_elmnt_count-1; i++)
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 6/6] DDF: ddf_set_disk: fix minor endianness bug
2013-07-21 17:28 [RFC/PATCH 0/6] DDF: safe big-endian types mwilck
` (4 preceding siblings ...)
2013-07-21 17:28 ` [PATCH 5/6] DDF: add_other_bvd: fix endianness bug mwilck
@ 2013-07-21 17:28 ` mwilck
2013-07-23 4:06 ` [RFC/PATCH 0/6] DDF: safe big-endian types NeilBrown
6 siblings, 0 replies; 8+ messages in thread
From: mwilck @ 2013-07-21 17:28 UTC (permalink / raw)
To: neilb, linux-raid; +Cc: mwilck
---
super-ddf.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/super-ddf.c b/super-ddf.c
index ff71be2..5a0c998 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -4170,7 +4170,8 @@ static void ddf_set_disk(struct active_array *a, int n, int state)
__func__, dl->pdnum, dl->major, dl->minor,
be32_to_cpu(dl->disk.refnum));
dprintf("%s: array %u disk %u ref %08x pd %d\n",
- __func__, inst, n_bvd, vc->phys_refnum[n_bvd], pd);
+ __func__, inst, n_bvd,
+ be32_to_cpu(vc->phys_refnum[n_bvd]), pd);
if ((state & DS_INSYNC) && ! (state & DS_FAULTY)) {
pd = dl->pdnum; /* FIXME: is this really correct ? */
vc->phys_refnum[n_bvd] = dl->disk.refnum;
--
1.7.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [RFC/PATCH 0/6] DDF: safe big-endian types
2013-07-21 17:28 [RFC/PATCH 0/6] DDF: safe big-endian types mwilck
` (5 preceding siblings ...)
2013-07-21 17:28 ` [PATCH 6/6] DDF: ddf_set_disk: fix minor " mwilck
@ 2013-07-23 4:06 ` NeilBrown
6 siblings, 0 replies; 8+ messages in thread
From: NeilBrown @ 2013-07-23 4:06 UTC (permalink / raw)
To: mwilck; +Cc: linux-raid
[-- Attachment #1: Type: text/plain, Size: 1475 bytes --]
On Sun, 21 Jul 2013 19:28:18 +0200 mwilck@arcor.de wrote:
> Hi Neil, hello list,
>
> please review this patch series. I made so many endianness bugs
> while working on DDF during the last months that I thought this
> might be helpful - it will cause bugs to be caught by the
> compiler which may otherwise turn up as hard-to-find runtime errors.
I like this a lot - thanks!
>
> Note that the code *does not* compile after each patch, only
> after the last one. I broke it down to make it more readable.
>
> Patch 0005 and 0006 are separate because they are actual minor bugs
> in the code that the endianness patch set helped me find.
I really prefer the compile to never break. Thanks for highlighting those
two fixes more me, but I've taken the liberty of just merging them back to
where they are needed.
I applied these and all the other patches you sent and pushed it all out.
Thanks a lot!
NeilBrown
>
> I verified that the DDF unit tests aren't broken by this patch set.
>
> Martin
>
> Martin Wilck (6):
> DDF: add endian-safe typedefs
> DDF: convert big endian to be32 type
> DDF: convert big-endian __u64 to be64 type
> DDF: convert big-endian __u16 to be16 type
> DDF: add_other_bvd: fix endianness bug
> DDF: ddf_set_disk: fix minor endianness bug
>
> super-ddf.c | 851 ++++++++++++++++++++++++++++++++---------------------------
> 1 files changed, 462 insertions(+), 389 deletions(-)
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-07-23 4:06 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-21 17:28 [RFC/PATCH 0/6] DDF: safe big-endian types mwilck
2013-07-21 17:28 ` [PATCH 1/6] DDF: add endian-safe typedefs mwilck
2013-07-21 17:28 ` [PATCH 2/6] DDF: convert big endian to be32 type mwilck
2013-07-21 17:28 ` [PATCH 3/6] DDF: convert big-endian __u64 to be64 type mwilck
2013-07-21 17:28 ` [PATCH 4/6] DDF: convert big-endian __u16 to be16 type mwilck
2013-07-21 17:28 ` [PATCH 5/6] DDF: add_other_bvd: fix endianness bug mwilck
2013-07-21 17:28 ` [PATCH 6/6] DDF: ddf_set_disk: fix minor " mwilck
2013-07-23 4:06 ` [RFC/PATCH 0/6] DDF: safe big-endian types NeilBrown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).