Exemple #1
0
int
mds_bmap_read_v1(struct bmapc_memb *b, void *readh)
{
	struct {
		uint8_t		crcstates[128];
		uint8_t		repls[24];
		uint64_t	crcs[128];
		uint32_t	gen;
		uint32_t	replpol;
	} bod;
	struct fidc_membh *f;
	struct iovec iovs[2];
	uint64_t crc, od_crc;
	int i, rc, vfsid;
	size_t nb, bsz;
	struct bmap_mds_info *bmi = bmap_2_bmi(b);

	bsz = sizeof(bod) + sizeof(crc);

	iovs[0].iov_base = &bod;
	iovs[0].iov_len = sizeof(bod);
	iovs[1].iov_base = &od_crc;
	iovs[1].iov_len = sizeof(od_crc);
	f = b->bcm_fcmh;
	slfid_to_vfsid(fcmh_2_fid(f), &vfsid);
	rc = mdsio_preadv(vfsid, &rootcreds, iovs, nitems(iovs), &nb,
	    bsz * b->bcm_bmapno + 0x1000, readh);

	if (rc)
		return (rc);
	if (nb == 0)
		return (SLERR_BMAP_INVALID);
	if (nb != bsz)
		return (SLERR_SHORTIO);

	psc_crc64_calc(&crc, &bod, sizeof(bod));
	if (crc != od_crc)
		return (PFLERR_BADCRC);
	for (i = 0; i < 128; i++)
		bmi->bmi_crcstates[i] = bod.crcstates[i];
	for (i = 0; i < 24; i++)
		bmi->bmi_repls[i] = bod.repls[i];
	for (i = 0; i < 128; i++)
		bmap_2_crcs(b, i) = bod.crcs[i];
	bmap_2_bgen(b) = bod.gen;
	bmap_2_replpol(b) = bod.replpol;
	return (0);
}
Exemple #2
0
int
mds_ino_read_v1(struct slash_inode_handle *ih)
{
	struct {
		uint16_t	version;
		uint16_t	flags;
		uint32_t	bsz;
		uint32_t	nrepls;
		uint32_t	replpol;
		sl_replica_t	repls[4];
	} ino;
	struct fidc_membh *f;
	struct iovec iovs[2];
	uint64_t crc, od_crc;
	int i, rc, vfsid;
	size_t nb;

	iovs[0].iov_base = &ino;
	iovs[0].iov_len = sizeof(ino);
	iovs[1].iov_base = &od_crc;
	iovs[1].iov_len = sizeof(od_crc);

	f = inoh_2_fcmh(ih);
	slfid_to_vfsid(fcmh_2_fid(f), &vfsid);
	rc = mdsio_preadv(vfsid, &rootcreds, iovs, nitems(iovs), &nb, 0,
	    inoh_2_mfh(ih));

	if (rc)
		return (rc);
	if (nb != sizeof(ino) + sizeof(od_crc))
		return (SLERR_SHORTIO);

	psc_crc64_calc(&crc, &ino, sizeof(ino));
	if (crc != od_crc)
		return (PFLERR_BADCRC);
	ih->inoh_ino.ino_version = INO_VERSION;
	ih->inoh_ino.ino_bsz = ino.bsz;
	ih->inoh_ino.ino_nrepls = ino.nrepls;
	ih->inoh_ino.ino_replpol = ino.replpol;
	for (i = 0; i < 4; i++)
		ih->inoh_ino.ino_repls[i] = ino.repls[i];
	return (0);
}
Exemple #3
0
void
pfl_odt_load(struct pfl_odt **tp, struct pfl_odt_ops *odtops, int oflg,
    const char *fn, const char *fmt, ...)
{
	struct pfl_odt_hdr *h;
	struct pfl_odt *t;
	uint64_t crc;
	va_list ap;

	*tp = t = PSCALLOC(sizeof(*t));
	t->odt_ops = *odtops;
	INIT_SPINLOCK(&t->odt_lock);
	INIT_PSC_LISTENTRY(&t->odt_lentry);

	va_start(ap, fmt);
	vsnprintf(t->odt_name, sizeof(t->odt_name), fmt, ap);
	va_end(ap);

	t->odt_iostats.rd = pfl_opstat_init("odt-%s-rd", t->odt_name);
	t->odt_iostats.wr = pfl_opstat_init("odt-%s-wr", t->odt_name);

	h = t->odt_hdr = PSCALLOC(sizeof(*h));

	/* pfl_odt_open() and slm_odt_open() */
	odtops->odtop_open(t, fn, oflg);

	psc_crc64_calc(&crc, t->odt_hdr, sizeof(*t->odt_hdr) -
	    sizeof(t->odt_hdr->odth_crc));
	pfl_assert(h->odth_crc == crc);

	t->odt_bitmap = psc_vbitmap_newf(h->odth_nitems, PVBF_AUTO);
	pfl_assert(t->odt_bitmap);
	/*
 	 * Skip the first slot, so that we can detect whether we have
 	 * assigned a lease easily.
 	 */
	psc_vbitmap_set(t->odt_bitmap, 0);

	PFLOG_ODT(PLL_DIAG, t, "loaded");

	pll_add(&pfl_odtables, t);
}
Exemple #4
0
int
pfl_odt_create(const char *fn, int64_t nitems, size_t itemsz,
    int overwrite, size_t startoff, size_t pad, int tflg)
{
	int rc;
	int64_t	item;
	struct pfl_odt_slotftr f;
	struct pfl_odt_hdr *h;
	struct pfl_odt *t;

	t = PSCALLOC(sizeof(*t));
	t->odt_ops = pfl_odtops;
	INIT_SPINLOCK(&t->odt_lock);
	snprintf(t->odt_name, sizeof(t->odt_name), "%s", pfl_basename(fn));

	t->odt_iostats.rd = pfl_opstat_init("odt-%s-rd", t->odt_name);
	t->odt_iostats.wr = pfl_opstat_init("odt-%s-wr", t->odt_name);

	h = PSCALLOC(sizeof(*h));
	memset(h, 0, sizeof(*h));
	h->odth_nitems = nitems;
	h->odth_itemsz = itemsz;
	h->odth_slotsz = itemsz + pad + sizeof(f);
	h->odth_options = tflg;
	h->odth_start = startoff;
	t->odt_hdr = h;
	psc_crc64_calc(&h->odth_crc, h, sizeof(*h) - sizeof(h->odth_crc));

	/* pfl_odt_new() and slm_odt_new() */
	rc = t->odt_ops.odtop_new(t, fn, overwrite);
	if (rc)
		return (rc);

	for (item = 0; item < nitems; item++)
		_pfl_odt_doput(t, item, NULL, &f, 0);

	PFLOG_ODT(PLL_DIAG, t, "created");

	pfl_odt_release(t);
	return (0);
}
Exemple #5
0
int
mds_inox_read_v1(struct slash_inode_handle *ih)
{
	struct {
		sl_snap_t	snaps[1];
		sl_replica_t	repls[60];
	} inox;
	struct fidc_membh *f;
	struct iovec iovs[2];
	uint64_t crc, od_crc;
	int i, rc, vfsid;
	size_t nb;

	memset(&inox, 0, sizeof(inox));

	iovs[0].iov_base = &inox;
	iovs[0].iov_len = sizeof(inox);
	iovs[1].iov_base = &od_crc;
	iovs[1].iov_len = sizeof(od_crc);

	f = inoh_2_fcmh(ih);
	slfid_to_vfsid(fcmh_2_fid(f), &vfsid);
	rc = mdsio_preadv(vfsid, &rootcreds, iovs, nitems(iovs), &nb,
	    0x400, inoh_2_mfh(ih));

	if (rc)
		return (rc);
	if (pfl_memchk(&inox, 0, sizeof(inox)) && od_crc == 0)
		return (0);
	if (nb != sizeof(inox) + sizeof(od_crc))
		return (SLERR_SHORTIO);

	psc_crc64_calc(&crc, &inox, sizeof(inox));
	if (crc != od_crc)
		return (PFLERR_BADCRC);
	for (i = 0; i < 60; i++)
		ih->inoh_extras->inox_repls[i] = inox.repls[i];
	return (0);
}
Exemple #6
0
int
mds_inode_update_interrupted(int vfsid, struct slash_inode_handle *ih,
    int *rc)
{
	char fn[NAME_MAX + 1];
	struct srt_stat sstb;
	struct iovec iovs[2];
	uint64_t crc, od_crc;
	void *h = NULL, *th;
	mdsio_fid_t inum;
	int exists = 0;
	size_t nb;

	th = inoh_2_mfh(ih);

	snprintf(fn, sizeof(fn), "%016"PRIx64".update",
	    inoh_2_fid(ih));

	*rc = mdsio_lookup(vfsid, mds_tmpdir_inum[vfsid], fn, &inum,
	    &rootcreds, NULL);
	if (*rc)
		PFL_GOTOERR(out, *rc);

	*rc = mdsio_opencreatef(vfsid, inum, &rootcreds, O_RDONLY,
	    MDSIO_OPENCRF_NOLINK, 0644, NULL, NULL, NULL, &h, NULL,
	    NULL, 0);
	if (*rc)
		PFL_GOTOERR(out, *rc);

	iovs[0].iov_base = &ih->inoh_ino;
	iovs[0].iov_len = sizeof(ih->inoh_ino);
	iovs[1].iov_base = &od_crc;
	iovs[1].iov_len = sizeof(od_crc);
	*rc = mdsio_preadv(vfsid, &rootcreds, iovs, nitems(iovs), &nb, 0, h);
	if (*rc)
		PFL_GOTOERR(out, *rc);

	psc_crc64_calc(&crc, &ih->inoh_ino, sizeof(ih->inoh_ino));
	if (crc != od_crc) {
		*rc = PFLERR_BADCRC;
		PFL_GOTOERR(out, *rc);
	}

	exists = 1;

	psc_assert(ih->inoh_extras == NULL);
	ih->inoh_extras = PSCALLOC(INOX_SZ);

	inoh_2_mfh(ih) = h;
	*rc = mds_inox_ensure_loaded(ih);
	if (*rc)
		PFL_GOTOERR(out, *rc);

	inoh_2_mfh(ih) = th;

	memset(&sstb, 0, sizeof(sstb));
	*rc = mdsio_setattr(vfsid, 0, &sstb, SL_SETATTRF_METASIZE,
	    &rootcreds, NULL, th, NULL);
	if (*rc)
		PFL_GOTOERR(out, *rc);

	*rc = mds_inode_dump(vfsid, NULL, ih, h);
	if (*rc)
		PFL_GOTOERR(out, *rc);

	mdsio_unlink(vfsid, mds_tmpdir_inum[vfsid], NULL, fn,
	    &rootcreds, NULL, NULL);

 out:
	if (h)
		mdsio_release(vfsid, &rootcreds, h);
	if (*rc)
		mdsio_unlink(vfsid, mds_tmpdir_inum[vfsid], NULL, fn,
		    &rootcreds, NULL, NULL);
	inoh_2_mfh(ih) = th;
	return (exists);
}