Ejemplo n.º 1
0
Archivo: odtable.c Proyecto: pscedu/pfl
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);
}
Ejemplo n.º 2
0
int
main(int argc, char *argv[])
{
	int c, i, rc, verbose = 0, oflg = ODTBL_FLG_RDONLY, tflg = ODTBL_OPT_CRC;
	struct pfl_odt *t;
	char *p, *fn;

	pfl_init();
	pscthr_init(0, NULL, 0, "odtable");

	while ((c = getopt(argc, argv, "CcdF:n:osvX:z:")) != -1)
		switch (c) {
		case 'C':
			create_table = 1;
			break;
		case 'c':
			tflg |= ODTBL_OPT_CRC;
			break;
		case 'd':
			dump = 1;
			break;
		case 'F':
			num_free = atoi(optarg);
			oflg &= ~ODTBL_FLG_RDONLY;
			break;
		case 'n':
			num_puts = atoi(optarg);
			oflg &= ~ODTBL_FLG_RDONLY;
			break;
		case 'o':
			overwrite = 1;
			break;
		case 's':
			item_size = atoi(optarg);
			break;
		case 'v':
			verbose = 1;
			break;
		case 'X':
			fmt = optarg;
			break;
		case 'z':
			nitems = atoi(optarg);
			break;
		default:
			usage();
		}

	argc -= optind;
	argv += optind;
	if (argc != 1)
		usage();

	fn = argv[0];

	if (create_table) {
		rc = pfl_odt_create(fn, nitems, item_size, overwrite,
		    ODT_ITEM_START, 0, tflg);
		if (!rc && verbose)
			warnx("created od-table %s "
			    "(elemsize=%zu, nitems=%zu)",
			    fn, item_size, nitems);
		exit(0);
	}

	pfl_odt_load(&t, &pfl_odtops, oflg, fn, "%s", fn);
	pfl_odt_check(t, visit, &t);

	for (i = 0; i < num_puts; i++) {
		size_t elem;

		elem = pfl_odt_allocslot(t);
		pfl_odt_allocitem(t, (void **)&p);
		snprintf(p, item_size, "... put_number=%d ...", i);
		pfl_odt_putitem(t, elem, p, 1);
		PSCFREE(p);
	}

	/* XXX find in-use slot to free */
	for (i = 0; i < num_free; i++)
		pfl_odt_freeitem(t, i);

	pfl_odt_release(t);
	exit(0);
}
Ejemplo n.º 3
0
int
main(int argc, char *argv[])
{
	int c, i, verbose = 0, oflg = ODTBL_FLG_RDONLY,
	    tflg = ODTBL_OPT_CRC;
	struct pfl_odt_receipt *r;
	struct pfl_odt *t;
	char *p, *fn;

	pfl_init();
	progname = argv[0];
	while ((c = getopt(argc, argv, "CcDe:F:n:osvX:Zz:")) != -1)
		switch (c) {
		case 'C':
			create_table = 1;
			break;
		case 'c':
			tflg |= ODTBL_OPT_CRC;
			break;
		case 'e':
			elem_size = atoi(optarg);
			break;
		case 'F':
			num_free = atoi(optarg);
			oflg &= ~ODTBL_FLG_RDONLY;
			break;
		case 'n':
			num_puts = atoi(optarg);
			oflg &= ~ODTBL_FLG_RDONLY;
			break;
		case 'o':
			overwrite = 1;
			break;
		case 's':
			show = 1;
			break;
		case 'v':
			verbose = 1;
			break;
		case 'X':
			fmt = optarg;
			break;
		case 'Z':
			tflg |= ODTBL_OPT_SYNC;
			break;
		case 'z':
			nelems = atoi(optarg);
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;
	if (argc != 1)
		usage();
	fn = argv[0];

	if (create_table) {
		pfl_odt_create(fn, nelems, elem_size, overwrite,
		    0x1000, 0, tflg);
		if (verbose)
			warnx("created od-table %s "
			    "(elemsize=%zu, nelems=%zu)",
			    fn, elem_size, nelems);
		exit(0);
	}

	pfl_odt_load(&t, &pfl_odtops_mmap, oflg, fn, "%s", fn);
	pfl_odt_check(t, visit, &t);

	for (i = 0; i < num_puts; i++) {
		size_t elem;

		elem = pfl_odt_allocslot(t);
		pfl_odt_mapitem(t, elem, &p);
		snprintf(p, elem_size, "... put_number=%d ...", i);
		pfl_odt_putitem(t, elem, p);
		pfl_odt_freebuf(t, p, NULL);
	}

	DYNARRAY_FOREACH(r, i, &rcpts)
		pfl_odt_freeitem(t, r);

	pfl_odt_release(t);
	psc_dynarray_free(&rcpts);
	exit(0);
}