From: mwilck@arcor.de
To: neilb@suse.de, linux-raid@vger.kernel.org
Cc: mwilck@arcor.de
Subject: [PATCH 10/27] DDF: allow empty slots in virt disk table
Date: Wed, 3 Jul 2013 22:27:50 +0200 [thread overview]
Message-ID: <1372883287-8859-11-git-send-email-mwilck@arcor.de> (raw)
In-Reply-To: <1372883287-8859-1-git-send-email-mwilck@arcor.de>
The DDF code was assuming that the VD slots 0..populated_vdes
were used and the rest was unused. Remove this assumption and
deal with empty slots instead.
Signed-off-by: Martin Wilck <mwilck@arcor.de>
---
super-ddf.c | 100 +++++++++++++++++++++++++++++++++-------------------------
1 files changed, 57 insertions(+), 43 deletions(-)
diff --git a/super-ddf.c b/super-ddf.c
index 8b7a621..0f955be 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -447,7 +447,7 @@ struct ddf_super {
#endif
#if DEBUG
-static int all_ff(char *guid);
+static int all_ff(const char *guid);
static void pr_state(struct ddf_super *ddf, const char *msg)
{
unsigned int i;
@@ -1059,7 +1059,7 @@ static int map_num1(struct num_mapping *map, int num)
return map[i].num2;
}
-static int all_ff(char *guid)
+static int all_ff(const char *guid)
{
int i;
for (i = 0; i < DDF_GUID_LEN; i++)
@@ -1156,11 +1156,13 @@ 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 i;
+ unsigned int i;
printf(" Virtual Disks : %d\n", cnt);
- for (i=0; i<cnt; 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");
@@ -1816,6 +1818,44 @@ static void make_header_guid(char *guid)
memcpy(guid+20, &stamp, 4);
}
+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++) {
+ if (all_ff(ddf->virt->entries[i].guid))
+ return i;
+ }
+ return DDF_NOTFOUND;
+}
+
+static unsigned int find_vde_by_name(const struct ddf_super *ddf,
+ const char *name)
+{
+ unsigned int i;
+ if (name == NULL)
+ return DDF_NOTFOUND;
+ 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,
+ sizeof(ddf->virt->entries[i].name)))
+ return i;
+ }
+ return DDF_NOTFOUND;
+}
+
+static unsigned int find_vde_by_guid(const struct ddf_super *ddf,
+ const char *guid)
+{
+ unsigned int i;
+ if (guid == NULL || all_ff(guid))
+ return DDF_NOTFOUND;
+ 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;
+}
+
static int init_super_ddf_bvd(struct supertype *st,
mdu_array_info_t *info,
unsigned long long size,
@@ -2209,33 +2249,13 @@ static int init_super_ddf_bvd(struct supertype *st,
struct vcl *vcl;
struct vd_config *vc;
- if (__be16_to_cpu(ddf->virt->populated_vdes)
- >= __be16_to_cpu(ddf->virt->max_vdes)) {
- pr_err("This ddf already has the "
- "maximum of %d virtual devices\n",
- __be16_to_cpu(ddf->virt->max_vdes));
+ if (find_vde_by_name(ddf, name) != DDF_NOTFOUND) {
+ pr_err("This ddf already has an array called %s\n", name);
return 0;
}
-
- if (name)
- for (venum = 0; venum < __be16_to_cpu(ddf->virt->max_vdes); venum++)
- if (!all_ff(ddf->virt->entries[venum].guid)) {
- char *n = ddf->virt->entries[venum].name;
-
- if (strncmp(name, n, 16) == 0) {
- pr_err("This ddf already"
- " has an array called %s\n",
- name);
- return 0;
- }
- }
-
- for (venum = 0; venum < __be16_to_cpu(ddf->virt->max_vdes); venum++)
- if (all_ff(ddf->virt->entries[venum].guid))
- break;
- if (venum == __be16_to_cpu(ddf->virt->max_vdes)) {
- pr_err("Cannot find spare slot for "
- "virtual disk - DDF is corrupt\n");
+ venum = find_unused_vde(ddf);
+ if (venum == DDF_NOTFOUND) {
+ pr_err("Cannot find spare slot for virtual disk\n");
return 0;
}
ve = &ddf->virt->entries[venum];
@@ -3760,8 +3780,8 @@ static int ddf_open_new(struct supertype *c, struct active_array *a, char *inst)
{
struct ddf_super *ddf = c->sb;
int n = atoi(inst);
- if (n >= (int)__be16_to_cpu(ddf->virt->populated_vdes)) {
- pr_err("%s: subarray index %d out of range\n", __func__, n);
+ if (all_ff(ddf->virt->entries[n].guid)) {
+ pr_err("%s: subarray %d doesn't exist\n", __func__, n);
return -ENODEV;
}
dprintf("ddf: open_new %d\n", n);
@@ -4112,10 +4132,8 @@ static void ddf_process_update(struct supertype *st,
return;
vd = (struct virtual_disk*)update->buf;
- ent = __be16_to_cpu(vd->populated_vdes);
- if (ent >= __be16_to_cpu(ddf->virt->max_vdes))
- return;
- if (!all_ff(ddf->virt->entries[ent].guid))
+ ent = find_unused_vde(ddf);
+ if (ent == DDF_NOTFOUND)
return;
ddf->virt->entries[ent] = vd->entries[0];
ddf->virt->populated_vdes = __cpu_to_be16(1 +
@@ -4150,14 +4168,10 @@ static void ddf_process_update(struct supertype *st,
memcpy(&vcl->conf, vc, update->len);
vcl->lba_offset = (__u64*)
&vcl->conf.phys_refnum[mppe];
- for (ent = 0;
- ent < __be16_to_cpu(ddf->virt->populated_vdes);
- ent++)
- if (memcmp(vc->guid, ddf->virt->entries[ent].guid,
- DDF_GUID_LEN) == 0) {
- vcl->vcnum = ent;
- break;
- }
+ ent = find_vde_by_guid(ddf, vc->guid);
+ if (ent == DDF_NOTFOUND)
+ return;
+ vcl->vcnum = ent;
ddf->conflist = vcl;
}
/* Set DDF_Transition on all Failed devices - to help
--
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 ` mwilck [this message]
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 ` [PATCH 13/27] DDF: Simplify allocation of "other BVDs" mwilck
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-11-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).