unsigned magic;
#define VDI_RANDOM_MAGIC 0x3771ae23
struct director dir;
+
+ unsigned retries;
struct vdi_random_host *hosts;
unsigned nhosts;
};
CAST_OBJ_NOTNULL(vs, sp->director->priv, VDI_RANDOM_MAGIC);
k = 0;
- for (k = 0; k < 4; ) { /* XXX: 4 is arbitrary */
+ for (k = 0; k < vs->retries; ) {
r = random() / 2147483648.0; /* 2^31 */
assert(r >= 0.0 && r < 1.0);
struct vdi_random *vs;
const struct vrt_dir_random_entry *te;
struct vdi_random_host *vh;
- double s;
int i;
(void)cli;
vs->dir.getfd = vdi_random_getfd;
vs->dir.fini = vdi_random_fini;
- s = 0;
+ vs->retries = t->retries;
+ if (vs->retries == 0)
+ vs->retries = t->nmember;
vh = vs->hosts;
te = t->members;
for (i = 0; i < t->nmember; i++, vh++, te++) {
{
struct token *t_field, *t_be;
int nbh, nelem;
- struct fld_spec *fs;
- unsigned u;
+ struct fld_spec *fs, *mfs;
+ unsigned u, retries;
const char *first;
- fs = vcc_FldSpec(tl, "!backend", "!weight", NULL);
+ fs = vcc_FldSpec(tl, "?retries", NULL);
+
+ retries = 0;
+ while (tl->t->tok != '{') {
+ vcc_IsField(tl, &t_field, fs);
+ ERRCHK(tl);
+ if (vcc_IdIs(t_field, "retries")) {
+ ExpectErr(tl, CNUM);
+ retries = vcc_UintVal(tl);
+ ERRCHK(tl);
+ vcc_NextToken(tl);
+ ExpectErr(tl, ';');
+ vcc_NextToken(tl);
+ } else {
+ ErrInternal(tl);
+ }
+ }
+
+ mfs = vcc_FldSpec(tl, "!backend", "!weight", NULL);
Fc(tl, 0,
"\nstatic const struct vrt_dir_random_entry vdre_%.*s[] = {\n",
for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */
first = "";
t_be = tl->t;
- vcc_ResetFldSpec(fs);
+ vcc_ResetFldSpec(mfs);
nbh = -1;
ExpectErr(tl, '{');
Fc(tl, 0, "\t{");
while (tl->t->tok != '}') { /* Member fields */
- vcc_IsField(tl, &t_field, fs);
+ vcc_IsField(tl, &t_field, mfs);
ERRCHK(tl);
if (vcc_IdIs(t_field, "backend")) {
vcc_ParseBackendHost(tl, &nbh,
} else if (vcc_IdIs(t_field, "weight")) {
ExpectErr(tl, CNUM);
u = vcc_UintVal(tl);
+ ERRCHK(tl);
if (u == 0) {
vsb_printf(tl->sb,
"The .weight must be higher "
}
first = ", ";
}
- vcc_FieldsOk(tl, fs);
+ vcc_FieldsOk(tl, mfs);
if (tl->err) {
vsb_printf(tl->sb,
"\nIn member host specfication starting at:\n");
"\nstatic const struct vrt_dir_random vdr_%.*s = {\n",
PF(t_dir));
Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_dir));
+ Fc(tl, 0, "\t.retries = %u,\n", retries);
Fc(tl, 0, "\t.nmember = %d,\n", nelem);
Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(t_dir));
Fc(tl, 0, "};\n");