From: mwilck@arcor.de
To: neilb@suse.de, linux-raid@vger.kernel.org
Cc: mwilck@arcor.de
Subject: [PATCH 13/27] DDF: Simplify allocation of "other BVDs"
Date: Wed, 3 Jul 2013 22:27:53 +0200 [thread overview]
Message-ID: <1372883287-8859-14-git-send-email-mwilck@arcor.de> (raw)
In-Reply-To: <1372883287-8859-1-git-send-email-mwilck@arcor.de>
Instead of allocating the other_bvds array and every element
separately, allocate all in a single chunk. Also, move allocation
in a subroutine as it's used in several places.
Signed-off-by: Martin Wilck <mwilck@arcor.de>
---
super-ddf.c | 86 ++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 53 insertions(+), 33 deletions(-)
diff --git a/super-ddf.c b/super-ddf.c
index 933485d..1ff8a28 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -863,13 +863,35 @@ static int load_ddf_global(int fd, struct ddf_super *super, char *devname)
return 0;
}
+#define DDF_UNUSED_BVD 0xff
+static int alloc_other_bvds(const struct ddf_super *ddf, struct vcl *vcl)
+{
+ unsigned int n_vds = vcl->conf.sec_elmnt_count - 1;
+ unsigned int i, vdsize;
+ void *p;
+ if (n_vds == 0) {
+ vcl->other_bvds = NULL;
+ return 0;
+ }
+ vdsize = ddf->conf_rec_len * 512;
+ if (posix_memalign(&p, 512, n_vds *
+ (vdsize + sizeof(struct vd_config *))) != 0)
+ return -1;
+ vcl->other_bvds = (struct vd_config **) (p + n_vds * vdsize);
+ for (i = 0; i < n_vds; i++) {
+ vcl->other_bvds[i] = p + i * vdsize;
+ memset(vcl->other_bvds[i], 0, vdsize);
+ vcl->other_bvds[i]->sec_elmnt_seq = DDF_UNUSED_BVD;
+ }
+ return 0;
+}
+
static void add_other_bvd(struct vcl *vcl, struct vd_config *vd,
unsigned int len)
{
int i;
for (i = 0; i < vcl->conf.sec_elmnt_count-1; i++)
- if (vcl->other_bvds[i] != NULL &&
- vcl->other_bvds[i]->sec_elmnt_seq == vd->sec_elmnt_seq)
+ if (vcl->other_bvds[i]->sec_elmnt_seq == vd->sec_elmnt_seq)
break;
if (i < vcl->conf.sec_elmnt_count-1) {
@@ -877,18 +899,13 @@ static void add_other_bvd(struct vcl *vcl, struct vd_config *vd,
return;
} else {
for (i = 0; i < vcl->conf.sec_elmnt_count-1; i++)
- if (vcl->other_bvds[i] == NULL)
+ if (vcl->other_bvds[i]->sec_elmnt_seq == DDF_UNUSED_BVD)
break;
if (i == vcl->conf.sec_elmnt_count-1) {
pr_err("no space for sec level config %u, count is %u\n",
vd->sec_elmnt_seq, vcl->conf.sec_elmnt_count);
return;
}
- if (posix_memalign((void **)&vcl->other_bvds[i], 512, len)
- != 0) {
- pr_err("%s could not allocate vd buf\n", __func__);
- return;
- }
}
memcpy(vcl->other_bvds[i], vd, len);
}
@@ -1006,12 +1023,13 @@ static int load_ddf_local(int fd, struct ddf_super *super,
}
vcl->next = super->conflist;
vcl->block_sizes = NULL; /* FIXME not for CONCAT */
- if (vd->sec_elmnt_count > 1)
- vcl->other_bvds =
- xcalloc(vd->sec_elmnt_count - 1,
- sizeof(struct vd_config *));
- else
- vcl->other_bvds = NULL;
+ vcl->conf.sec_elmnt_count = vd->sec_elmnt_count;
+ if (alloc_other_bvds(super, vcl) != 0) {
+ pr_err("%s could not allocate other bvds\n",
+ __func__);
+ free(vcl);
+ return 1;
+ };
super->conflist = vcl;
dl->vlist[vnum++] = vcl;
}
@@ -1129,13 +1147,12 @@ static void free_super_ddf(struct supertype *st)
ddf->conflist = v->next;
if (v->block_sizes)
free(v->block_sizes);
- if (v->other_bvds) {
- int i;
- for (i = 0; i < v->conf.sec_elmnt_count-1; i++)
- if (v->other_bvds[i] != NULL)
- free(v->other_bvds[i]);
- free(v->other_bvds);
- }
+ if (v->other_bvds)
+ /*
+ v->other_bvds[0] points to beginning of buffer,
+ see alloc_other_bvds()
+ */
+ free(v->other_bvds[0]);
free(v);
}
while (ddf->dlist) {
@@ -1663,8 +1680,6 @@ static struct vd_config *find_vdcr(struct ddf_super *ddf, unsigned int inst,
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] == NULL)
- continue;
if (v->other_bvds[ibvd-1]->sec_elmnt_seq
== nsec)
break;
@@ -2359,8 +2374,6 @@ static int init_super_ddf_bvd(struct supertype *st,
vcl->lba_offset = (__u64*) &vcl->conf.phys_refnum[ddf->mppe];
vcl->vcnum = venum;
vcl->block_sizes = NULL; /* FIXME not for CONCAT */
- vcl->other_bvds = NULL;
-
vc = &vcl->conf;
vc->magic = DDF_VD_CONF_MAGIC;
@@ -2377,6 +2390,12 @@ static int init_super_ddf_bvd(struct supertype *st,
return 0;
}
vc->sec_elmnt_seq = 0;
+ if (alloc_other_bvds(ddf, vcl) != 0) {
+ pr_err("%s could not allocate other bvds\n",
+ __func__);
+ free(vcl);
+ return 0;
+ }
vc->blocks = __cpu_to_be64(info->size * 2);
vc->array_blocks = __cpu_to_be64(
calc_array_size(info->level, info->raid_disks, info->layout,
@@ -3391,7 +3410,7 @@ static int check_secondary(const struct vcl *vc)
__set_sec_seen(conf->sec_elmnt_seq);
for (i = 0; i < conf->sec_elmnt_count-1; i++) {
const struct vd_config *bvd = vc->other_bvds[i];
- if (bvd == NULL)
+ if (bvd->sec_elmnt_seq == DDF_UNUSED_BVD)
continue;
if (bvd->srl != conf->srl) {
pr_err("Inconsistent secondary RAID level across BVDs\n");
@@ -3449,9 +3468,9 @@ static unsigned int get_pd_index_from_refnum(const struct vcl *vc,
for (n = 1; n < vc->conf.sec_elmnt_count; n++) {
struct vd_config *vd = vc->other_bvds[n-1];
- if (vd == NULL)
- continue;
sec = vd->sec_elmnt_seq;
+ if (sec == DDF_UNUSED_BVD)
+ continue;
for (i = 0, j = 0 ; i < nmax ; i++) {
if (vd->phys_refnum[i] != 0xffffffff)
j++;
@@ -3753,12 +3772,13 @@ static int compare_super_ddf(struct supertype *st, struct supertype *tst)
vl1->next = first->conflist;
vl1->block_sizes = NULL;
- if (vl2->conf.sec_elmnt_count > 1) {
- vl1->other_bvds = xcalloc(vl2->conf.sec_elmnt_count - 1,
- sizeof(struct vd_config *));
- } else
- vl1->other_bvds = NULL;
memcpy(&vl1->conf, &vl2->conf, first->conf_rec_len*512);
+ if (alloc_other_bvds(first, vl1) != 0) {
+ pr_err("%s could not allocate other bvds\n",
+ __func__);
+ free(vl1);
+ return 3;
+ }
vl1->lba_offset = (__u64 *)
&vl1->conf.phys_refnum[first->mppe];
for (vd = 0; vd < max_vds; vd++)
--
1.7.1
next prev parent reply other threads:[~2013-07-03 20:27 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-03 20:27 DDF/RAID10 patch series mwilck
2013-07-03 20:27 ` [PATCH 01/27] DDF (cleanup): use a common macro for failed searches mwilck
2013-07-03 20:27 ` [PATCH 02/27] DDF: check_secondary: fix treatment of missing BVDs mwilck
2013-07-03 20:27 ` [PATCH 03/27] DDF: load_ddf_headers: use secondary header as fallback mwilck
2013-07-08 5:43 ` NeilBrown
2013-07-08 20:56 ` Martin Wilck
2013-07-03 20:27 ` [PATCH 04/27] DDF: handle "open flag" according to spec mwilck
2013-07-03 20:27 ` [PATCH 05/27] DDF: Implement store_super_ddf mwilck
2013-07-08 5:48 ` NeilBrown
2013-07-10 17:37 ` Martin Wilck
2013-07-15 5:31 ` NeilBrown
2013-07-18 18:48 ` [PATCH 1/3] DDF: increase seq number in ddf_set_updates_pending mwilck
2013-07-18 18:49 ` [PATCH 2/3] DDF: make "null_aligned" a static buffer mwilck
2013-07-18 18:49 ` [PATCH 3/3] DDF: factor out writing super block to single disk mwilck
2013-07-18 18:51 ` [PATCH 05/27] DDF: Implement store_super_ddf Martin Wilck
2013-07-03 20:27 ` [PATCH 06/27] DDF: ddf_open_new: implement minimal consistency check mwilck
2013-07-03 20:27 ` [PATCH 07/27] DDF: find_vdcr: account for secondary RAID level mwilck
2013-07-08 6:16 ` NeilBrown
2013-07-08 21:03 ` Martin Wilck
2013-07-03 20:27 ` [PATCH 08/27] DDF: ddf_set_disk: move status logic to separate function mwilck
2013-07-03 20:27 ` [PATCH 09/27] DDF: get_svd_state: Status logic for secondary RAID level mwilck
2013-07-03 20:27 ` [PATCH 10/27] DDF: allow empty slots in virt disk table mwilck
2013-07-03 20:27 ` [PATCH 11/27] DDF: layout_ddf2md: new DDF->md RAID layout conversion mwilck
2013-07-08 6:48 ` NeilBrown
2013-07-08 21:06 ` Martin Wilck
2013-07-03 20:27 ` [PATCH 12/27] DDF: layout_md2ddf: new md->DDF " mwilck
2013-07-08 6:28 ` NeilBrown
2013-07-03 20:27 ` mwilck [this message]
2013-07-03 20:27 ` [PATCH 14/27] DDF: init_super_ddf_bvd: initialize other bvds mwilck
2013-07-03 20:27 ` [PATCH 15/27] DDF: validate_geometry_ddf: support RAID10 mwilck
2013-07-03 20:27 ` [PATCH 16/27] DDF: use LBA_OFFSET macro instead of lba_offset field mwilck
2013-07-03 20:27 ` [PATCH 17/27] DDF: get_extents: support secondary RAID level mwilck
2013-07-03 20:27 ` [PATCH 18/27] DDF: add_to_super_ddf: allow empty slots in phys disk table mwilck
2013-07-03 20:27 ` [PATCH 19/27] DDF: add_to_super_ddf: Use same amount of workspace as other disks mwilck
2013-07-03 20:28 ` [PATCH 20/27] DDF: add_to_super_ddf: RAID10 changes mwilck
2013-07-03 20:28 ` [PATCH 21/27] DDF: add_to_super_ddf_bvd: use get_svd_state() mwilck
2013-07-03 20:28 ` [PATCH 22/27] DDF: getinfo_super_ddf_bvd: lba_offset calculation for RAID10 mwilck
2013-07-03 20:28 ` [PATCH 23/27] DDF: guid_str: convenience function to print GUID for debugging mwilck
2013-07-03 20:28 ` [PATCH 24/27] DDF: ddf_set_array_state: more meaningful output mwilck
2013-07-03 20:28 ` [PATCH 25/27] DDF: ddf_process_update: handle update of conf records for SVD mwilck
2013-07-03 20:28 ` [PATCH 26/27] DDF: ddf_process_update: Fix vlist treatment for SVDs mwilck
2013-07-03 20:28 ` [PATCH 27/27] tests/10ddf-create: add RAID 10 array mwilck
2013-07-04 10:10 ` DDF/RAID10 patch series NeilBrown
2013-07-08 6:53 ` NeilBrown
2013-07-08 21:50 ` Fixes for the DDF " mwilck
2013-07-08 21:50 ` [PATCH 28/39] test/10-ddf-create: fix comments mwilck
2013-07-08 21:50 ` [PATCH 29/39] Monitor: Don't write metadata in inactive array state mwilck
2013-07-08 21:50 ` [PATCH 30/39] DDF: write_init_super_ddf: don't zero superblocks for subarrays mwilck
2013-07-08 21:50 ` [PATCH 31/39] DDF: implement kill_subarray mwilck
2013-07-08 21:50 ` [PATCH 32/39] DDF: getinfo_super_ddf_bvd: identify disk by refnum mwilck
2013-07-08 21:50 ` [PATCH 33/39] DDF: getinfo_super_ddf_bvd: fix raid_disk calculation mwilck
2013-07-08 21:50 ` [PATCH 34/39] DDF: fix endianness of refnum in debug messages mwilck
2013-07-08 21:50 ` [PATCH 35/39] DDF: add debug message in add_super_ddf_bvd mwilck
2013-07-08 21:50 ` [PATCH 36/39] DDF: ddf_process_update: add debug messages fore adding VDs mwilck
2013-07-08 21:50 ` [PATCH 37/39] DDF: guid_str: more readable output mwilck
2013-07-08 21:50 ` [PATCH 38/39] DDF: ddf_process_update: some more debug messages mwilck
2013-07-08 21:50 ` [PATCH 39/39] DDF: ddf_process_update: Fix updates for SVDs mwilck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1372883287-8859-14-git-send-email-mwilck@arcor.de \
--to=mwilck@arcor.de \
--cc=linux-raid@vger.kernel.org \
--cc=neilb@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).