static void sma_init(struct stevedore *parent, int ac, char * const *av) { const char *e; uintmax_t u; struct sma_sc *sc; ASSERT_MGT(); ALLOC_OBJ(sc, SMA_SC_MAGIC); AN(sc); sc->sma_max = SIZE_MAX; assert(sc->sma_max == SIZE_MAX); parent->priv = sc; AZ(av[ac]); if (ac > 1) ARGV_ERR("(-smalloc) too many arguments\n"); if (ac == 0 || *av[0] == '\0') return; e = str2bytes(av[0], &u, 0); if (e != NULL) ARGV_ERR("(-smalloc) size \"%s\": %s\n", av[0], e); if ((u != (uintmax_t)(size_t)u)) ARGV_ERR("(-smalloc) size \"%s\": too big\n", av[0]); if (u < 1024*1024) ARGV_ERR("(-smalloc) size \"%s\": too small, " "did you forget to specify M or G?\n", av[0]); sc->sma_max = u; }
void WAIT_tweak_waiter(struct cli *cli, const char *arg) { int i; ASSERT_MGT(); if (arg == NULL) { if (waiter == NULL) VCLI_Out(cli, "default"); else VCLI_Out(cli, "%s", waiter->name); VCLI_Out(cli, " ("); for (i = 0; vca_waiters[i] != NULL; i++) VCLI_Out(cli, "%s%s", i == 0 ? "" : ", ", vca_waiters[i]->name); VCLI_Out(cli, ")"); return; } if (!strcmp(arg, "default")) { waiter = NULL; return; } for (i = 0; vca_waiters[i]; i++) { if (!strcmp(arg, vca_waiters[i]->name)) { waiter = vca_waiters[i]; return; } } VCLI_Out(cli, "Unknown waiter"); VCLI_SetResult(cli, CLIS_PARAM); }
int Wait_Argument(struct vsb *vsb, const char *arg) { int i; ASSERT_MGT(); if (arg == NULL) { if (waiter == NULL) VSB_printf(vsb, "default"); else VSB_printf(vsb, "%s", waiter->name); VSB_printf(vsb, " (possible values: "); for (i = 0; waiter_impls[i] != NULL; i++) VSB_printf(vsb, "%s%s", i == 0 ? "" : ", ", waiter_impls[i]->name); VSB_printf(vsb, ")"); return(0); } if (!strcmp(arg, WAITER_DEFAULT)) { waiter = waiter_impls[0]; return(0); } for (i = 0; waiter_impls[i]; i++) { if (!strcmp(arg, waiter_impls[i]->name)) { waiter = waiter_impls[i]; return(0); } } VSB_printf(vsb, "Unknown waiter"); return (-1); }
void Wait_config(const char *arg) { ASSERT_MGT(); if (arg != NULL) waiter = MGT_Pick(waiter_choice, arg, "waiter"); else waiter = waiter_choice[0].ptr; }
stv_cli_list(struct cli *cli, const char * const *av, void *priv) { struct stevedore *stv; ASSERT_MGT(); (void)av; (void)priv; VCLI_Out(cli, "Storage devices:\n"); STV_Foreach(stv) VCLI_Out(cli, "\tstorage.%s = %s\n", stv->ident, stv->name); }
void STV_Config_Transient(void) { ASSERT_MGT(); VCLS_AddFunc(mgt_cls, MCF_AUTH, cli_stv); if (stv_transient == NULL) STV_Config(TRANSIENT_STORAGE "=default"); AN(stv_transient); VTAILQ_INSERT_TAIL(&stevedores, stv_transient, list); }
void smp_newsilo(struct smp_sc *sc) { struct smp_ident *si; ASSERT_MGT(); assert(strlen(SMP_IDENT_STRING) < sizeof si->ident); /* Choose a new random number */ AZ(VRND_RandomCrypto(&sc->unique, sizeof sc->unique)); smp_reset_sign(&sc->idn); si = sc->ident; memset(si, 0, sizeof *si); strcpy(si->ident, SMP_IDENT_STRING); si->byte_order = 0x12345678; si->size = sizeof *si; si->major_version = 2; si->unique = sc->unique; si->mediasize = sc->mediasize; si->granularity = sc->granularity; /* * Aim for cache-line-width */ si->align = sizeof(void*) * 2; sc->align = si->align; si->stuff[SMP_BAN1_STUFF] = sc->granularity; si->stuff[SMP_BAN2_STUFF] = si->stuff[SMP_BAN1_STUFF] + 1024*1024; si->stuff[SMP_SEG1_STUFF] = si->stuff[SMP_BAN2_STUFF] + 1024*1024; si->stuff[SMP_SEG2_STUFF] = si->stuff[SMP_SEG1_STUFF] + 1024*1024; si->stuff[SMP_SPC_STUFF] = si->stuff[SMP_SEG2_STUFF] + 1024*1024; si->stuff[SMP_END_STUFF] = si->mediasize; assert(si->stuff[SMP_SPC_STUFF] < si->stuff[SMP_END_STUFF]); smp_new_signspace(sc, &sc->ban1, si->stuff[SMP_BAN1_STUFF], smp_stuff_len(sc, SMP_BAN1_STUFF), "BAN 1"); smp_new_signspace(sc, &sc->ban2, si->stuff[SMP_BAN2_STUFF], smp_stuff_len(sc, SMP_BAN2_STUFF), "BAN 2"); smp_new_signspace(sc, &sc->seg1, si->stuff[SMP_SEG1_STUFF], smp_stuff_len(sc, SMP_SEG1_STUFF), "SEG 1"); smp_new_signspace(sc, &sc->seg2, si->stuff[SMP_SEG2_STUFF], smp_stuff_len(sc, SMP_SEG2_STUFF), "SEG 2"); smp_append_sign(&sc->idn, si, sizeof *si); smp_sync_sign(&sc->idn); }
void smp_mgt_init(struct stevedore *parent, int ac, char * const *av) { struct smp_sc *sc; struct smp_sign sgn; void *target; int i; ASSERT_MGT(); AZ(av[ac]); /* Necessary alignment. See also smp_object::__filler__ */ assert(sizeof(struct smp_object) % 8 == 0); #define SIZOF(foo) fprintf(stderr, \ "sizeof(%s) = %zu = 0x%zx\n", #foo, sizeof(foo), sizeof(foo)); SIZOF(struct smp_ident); SIZOF(struct smp_sign); SIZOF(struct smp_segptr); SIZOF(struct smp_object); #undef SIZOF /* See comments in storage_persistent.h */ assert(sizeof(struct smp_ident) == SMP_IDENT_SIZE); /* Allocate softc */ ALLOC_OBJ(sc, SMP_SC_MAGIC); XXXAN(sc); sc->parent = parent; sc->fd = -1; VTAILQ_INIT(&sc->segments); /* Argument processing */ if (ac != 2) ARGV_ERR("(-spersistent) wrong number of arguments\n"); i = STV_GetFile(av[0], &sc->fd, &sc->filename, "-spersistent"); if (i == 2) ARGV_ERR("(-spersistent) need filename (not directory)\n"); sc->align = sizeof(void*) * 2; sc->granularity = getpagesize(); sc->mediasize = STV_FileSize(sc->fd, av[1], &sc->granularity, "-spersistent"); AZ(ftruncate(sc->fd, sc->mediasize)); /* Try to determine correct mmap address */ i = read(sc->fd, &sgn, sizeof sgn); assert(i == sizeof sgn); if (!strcmp(sgn.ident, "SILO")) target = (void*)(uintptr_t)sgn.mapped; else target = NULL; sc->base = (void*)mmap(target, sc->mediasize, PROT_READ|PROT_WRITE, MAP_NOCORE | MAP_NOSYNC | MAP_SHARED, sc->fd, 0); if (sc->base == MAP_FAILED) ARGV_ERR("(-spersistent) failed to mmap (%s)\n", strerror(errno)); smp_def_sign(sc, &sc->idn, 0, "SILO"); sc->ident = SIGN_DATA(&sc->idn); i = smp_valid_silo(sc); if (i) { printf("Warning SILO (%s) not reloaded (reason=%d)\n", sc->filename, i); smp_newsilo(sc); } AZ(smp_valid_silo(sc)); smp_metrics(sc); parent->priv = sc; /* XXX: only for sendfile I guess... */ mgt_child_inherit(sc->fd, "storage_persistent"); }