Esempio n. 1
0
int
main(int argc, char *argv[])
{
	int c;

	pfl_init();
	progname = argv[0];
	while ((c = getopt(argc, argv, "cD:")) != -1)
		switch (c) {
		case 'c':
			create = 1;
			break;
		case 'D':
			sl_datadir = optarg;
			break;
		default:
			usage();
		}
	argc -= optind;
	if (argc)
		usage();
	if (create)
		authbuf_createkeyfile();
	else
		authbuf_checkkeyfile();
	exit(0);
}
Esempio n. 2
0
int
main(int argc, char *argv[])
{
	union pfl_sockaddr psa;
	struct ifaddrs *ifa;
	char ifn[IFNAMSIZ];

	progname = argv[0];
	    pfl_init();
	if (getopt(argc, argv, "") != -1)
		usage();
	argc -= optind;
	argv += optind;
	if (argc == 1)
		dst = argv[0];
	else if (argc)
		usage();

	memset(&psa, 0, sizeof(psa));
	psa.sin.sin_family = AF_INET;
#ifdef SA_LEN
	psa.sin.sin_len = sizeof(psa.sin);
#endif
	inet_pton(AF_INET, dst, &psa.sin.sin_addr.s_addr);

	pflnet_getifaddrs(&ifa);
	pflnet_getifnfordst(ifa, &psa.sa, ifn);
	pflnet_freeifaddrs(ifa);

	printf("%s\n", ifn);
	exit(0);
}
Esempio n. 3
0
int
main(int argc, char *argv[])
{
	pfl_init();
	progname = argv[0];
	psc_ctlcli_main(SL_PATH_SLICTLSOCK, argc, argv, opts,
	    nitems(opts));
	exit(0);
}
Esempio n. 4
0
int
main(int argc, char *argv[])
{
	struct thr *t, *threads;
	int rc, c, j;
	long l;

	pfl_init();
	while ((c = getopt(argc, argv, "i:n:")) != -1)
		switch (c) {
		case 'i':
			l = strtol(optarg, NULL, 10);
			if (l < 0 || l > INT_MAX)
				errx(1, "invalid iterations: %s", optarg);
			iterations = (int)l;
			break;
		case 'n':
			l = strtol(optarg, NULL, 10);
			if (l < 0 || l > INT_MAX)
				errx(1, "invalid nthreads: %s", optarg);
			nthreads = (int)l;
			break;
		default:
			usage();
		}
	argc -= optind;
	if (argc)
		usage();

	if ((threads = calloc(nthreads, sizeof(*threads))) == NULL)
		err(1, "calloc");

	pfl_multiwaitcond_init(&mastermlc, NULL, 0, "master");

	for (j = 0, t = threads; j < nthreads; j++, t++) {
		pfl_multiwaitcond_init(&t->t_mlc, NULL, 0, "cond%d", j);

		pfl_multiwait_init(&t->t_ml, "ml%d", j);
		rc = pfl_multiwait_addcond(&t->t_ml, &mastermlc);
		if (rc)
			psc_fatal("addcond");
		rc = pfl_multiwait_addcond(&t->t_ml, &t->t_mlc);
		if (rc)
			psc_fatal("addcond");

		rc = pthread_create(&t->t_pthread, NULL, thr_main, t);
		if (rc)
			errx(1, "pthread_create: %s", strerror(rc));
		sched_yield();
	}

	for (j = 0; j < iterations; j++) {
		pfl_multiwaitcond_wakeup(&mastermlc);
		usleep(100);
	}
	exit(0);
}
Esempio n. 5
0
int
main(int argc, char *argv[])
{
	pfl_init();
	progname = argv[0];
	if (getopt(argc, argv, "") != -1)
		usage();
	argc -= optind;
	if (argc)
		usage();

	psc_prsig();
	exit(0);
}
Esempio n. 6
0
int
main(int argc, char *argv[])
{
	size_t sz;
	void *p;

	pfl_init();
	if (getopt(argc, argv, "") != -1)
		usage();
	argc -= optind;
	if (argc)
		usage();

	p = PSCALLOC(213);
	p = psc_realloc(p, 65536, 0);
	p = psc_realloc(p, 0, 0);
	p = psc_realloc(p, 128, 0);
	p = psc_realloc(p, 0, 0);
	PSCFREE(p);

	p = PSCALLOC(128);
	PSCFREE(p);

	p = psc_alloc(24, PAF_PAGEALIGN);
	psc_free(p, PAF_PAGEALIGN);

	p = PSCALLOC(24);
	p = psc_realloc(p, 128, 0);
	PSCFREE(p);

	p = psc_alloc(8, PAF_LOCK);
	*(uint64_t *)p = 0;
	psc_free(p, PAF_LOCK, (size_t)8);

	sz = 1024;
	p = psc_alloc(sz, PAF_LOCK | PAF_PAGEALIGN);
	memset(p, 0, sz);
	psc_free(p, PAF_LOCK | PAF_PAGEALIGN, sz);

	exit(0);
}
Esempio n. 7
0
int
main(__unusedx int argc, char *argv[])
{
	char buf[BUFSIZ];
	int dopipe = 0;
	ssize_t rc;
	FILE *fp;

	pfl_init();
	if (getopt(argc, argv, "") != -1)
		usage();
	argc -= optind;
	if (argc)
		usage();

	pfl_setprocesstitle(argv, "foobar %d", 13);

	fp = fopen(_PATH_CMDLINE, "r");
	if (fp == NULL) {
		dopipe = 1;
		snprintf(buf, sizeof(buf),
		    "ps -o command -p %d | tail -1", getpid());
		fp = popen(buf, "r");
		if (fp == NULL)
			err(1, "popen %s", buf);
	}
	rc = fread(buf, 1, sizeof(buf), fp);
	if (!feof(fp))
		err(1, _PATH_CMDLINE);
	if (ferror(fp))
		err(1, _PATH_CMDLINE);
	if (dopipe)
		pclose(fp);
	else
		fclose(fp);

	buf[rc] = '\0';
	buf[strcspn(buf, "\n")] = '\0';
	pfl_assert(strstr(buf, "foobar 13"));
	exit(0);
}
Esempio n. 8
0
int
main(int argc, char *argv[])
{
    int c, i, rc = 0;

    progname = argv[0];
    pfl_init();
    while ((c = getopt(argc, argv, "n:i:")) != -1)
        switch (c) {
        case 'n':
            nthreads = atoi(optarg);
            break;
        case 'i':
            iterations = atoi(optarg);
            break;
        default:
            usage();
        }
    argc -= optind;
    if (argc)
        usage();

    psclog_debug("nthreads = %d", nthreads);

    psc_waitq_init(&waitq);

    for (i = 0; i < nthreads; i++)
        pscthr_init(0, child_main, NULL, 0, "thr%d", i);

    sleep(1);
    psc_waitq_wakeall(&waitq);
    sleep(2);

    i = nthreads * iterations;
    while (i--) {
        psc_waitq_wakeone(&waitq);
        usleep(30);
    }
    return rc;
}
Esempio n. 9
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);
}
Esempio n. 10
0
int
main(int argc, char *argv[])
{
	char c, *p, *noncanon_mp, *cmd, *path_env, dir[PATH_MAX];
	struct pscfs_args args = PSCFS_ARGS_INIT(0, NULL);
	struct psc_dynarray startup_cmds = DYNARRAY_INIT;
	const char *progpath = argv[0];
	int rc, i, unmount_first = 0;

	pfl_init();

	pscfs_addarg(&args, "");		/* progname/argv[0] */
	pscfs_addarg(&args, "-o");
	pscfs_addarg(&args, STD_MOUNT_OPTIONS);

	p = getenv("CTL_SOCK_FILE");
	if (p)
		ctlsockfn = p;

	while ((c = getopt(argc, argv, "dL:o:S:U")) != -1)
		switch (c) {
		case 'd':
			pscfs_addarg(&args, "-odebug");
			break;
		case 'L':
			psc_dynarray_add(&startup_cmds, optarg);
			break;
		case 'o':
			if (!opt_lookup(optarg)) {
				pscfs_addarg(&args, "-o");
				pscfs_addarg(&args, optarg);
			}
			break;
		case 'S':
			ctlsockfn = optarg;
			break;
		case 'U':
			unmount_first = 1;
			break;
		default:
			usage();
		}
	argc -= optind;
	argv += optind;
	if (argc != 1)
		usage();

	pscthr_init(PFL_THRT_FSMGR, NULL, 0, "fsmgrthr");

	noncanon_mp = argv[0];
	if (unmount_first)
		unmount(noncanon_mp);

	/* canonicalize mount path */
	if (realpath(noncanon_mp, mountpoint) == NULL)
		psc_fatal("realpath %s", noncanon_mp);

	pscfs_mount(mountpoint, &args);
	pscfs_freeargs(&args);

	ctlthr_spawn();

	pfl_opstimerthr_spawn(PFL_THRT_OPSTIMER, "opstimerthr");
	pfl_workq_init(128, 1024, 1024);
	pfl_wkthr_spawn(PFL_THRT_WORKER, 4, 0, "wkthr%d");

	pscfs_entry_timeout = 8.;
	pscfs_attr_timeout = 8.;

	/*
	 * Here, $p = (directory this daemon binary resides in).
	 * Now we add the following to $PATH:
	 *
	 *   1) $p
	 *   2) $p/../wokctl (for developers)
	 */
	pfl_dirname(progpath, dir);
	p = getenv("PATH");
	rc = pfl_asprintf(&path_env, "%s:%s/../wokctl%s%s", dir, dir,
	    p ? ":" : "", p ? p : "");
	psc_assert(rc != -1);
	setenv("PATH", path_env, 1);

	/*
 	 * If wokctl (see file wokctl.c) misbehaves because it is given 
 	 * a wrong arugment, it is hard to debug from our end because 
 	 * we won't be receiving anything useful via the socket. This 
 	 * should be changed to a native call someday.
 	 *
 	 * If the client does not come up, double/triple checkout 
 	 * the name of your slash2 shared library. I wish I can
 	 * add more verbose debugging information.
 	 */
	DYNARRAY_FOREACH(cmd, i, &startup_cmds)
		pfl_systemf("wokctl -S %s %s", ctlsockfn, cmd);

	exit(pscfs_main(32, ""));
}
Esempio n. 11
0
int
main(int argc, char *argv[])
{
    struct thr *thr;
    pthread_t pthr;
    int c, rc, i;

    pfl_init();
    progname = argv[0];
    while ((c = getopt(argc, argv, "i:n:")) != -1)
        switch (c) {
        case 'i':
            niter = atoi(optarg);
            break;
        case 'n':
            nthr = atoi(optarg);
            break;
        default:
            usage();
        }
    argc -= optind;
    if (argc)
        usage();

    psc_assert(psc_atomic64_read(&v64) == UINT64_C(100000000000));
    TEST(psc_atomic64, set, &v64, &v64, UINT64_C(2000000000000), UINT64_C(2000000000000));
    TEST(psc_atomic64, add, &v64, &v64, 15, UINT64_C(2000000000015));
    TEST(psc_atomic64, sub, &v64, &v64, 9, UINT64_C(2000000000006));
    TEST1(psc_atomic64, inc, &v64, UINT64_C(2000000000007));
    TEST1(psc_atomic64, dec, &v64, UINT64_C(2000000000006));

    psc_atomic16_set(&v16, 2);
    TEST(psc_atomic16, set, &v16, &v16, 200, 200);
    TEST(psc_atomic16, add, &v16, &v16, 15, 215);
    TEST(psc_atomic16, sub, &v16, &v16, 9, 206);
    TEST1(psc_atomic16, inc, &v16, 207);
    TEST1(psc_atomic16, dec, &v16, 206);
    TEST1V(psc_atomic16, dec_and_test0, &v16, 205, 0);
    TEST(psc_atomic16, set, &v16, &v16, 1, 1);
    TEST1V(psc_atomic16, dec_and_test0, &v16, 0, 1);
    TEST(psc_atomic16, setmask, &v16, &v16, 0x75, 0x75);
    TEST(psc_atomic16, clearmask, &v16, &v16, 0x41, 0x34);
    TEST(psc_atomic16, set, &v16, &v16, 0, 0);

    psc_atomic32_set(&v32, 2);
    TEST(psc_atomic32, set, &v32, &v32, 200, 200);
    TEST(psc_atomic32, add, &v32, &v32, 15, 215);
    TEST(psc_atomic32, sub, &v32, &v32, 9, 206);
    TEST1(psc_atomic32, inc, &v32, 207);
    TEST1(psc_atomic32, dec, &v32, 206);
    TEST1V(psc_atomic32, dec_and_test0, &v32, 205, 0);
    TEST(psc_atomic32, set, &v32, &v32, 1, 1);
    TEST1V(psc_atomic32, dec_and_test0, &v32, 0, 1);
    TEST(psc_atomic32, setmask, &v32, &v32, 0x75, 0x75);
    TEST(psc_atomic32, clearmask, &v32, &v32, 0x41, 0x34);
    TEST(psc_atomic32, set, &v32, &v32, 0, 0);

    psc_atomic64_set(&v64, 2);
    TEST(psc_atomic64, set, &v64, &v64, 200, 200);
    TEST(psc_atomic64, add, &v64, &v64, 15, 215);
    TEST(psc_atomic64, sub, &v64, &v64, 9, 206);
    TEST1(psc_atomic64, inc, &v64, 207);
    TEST1(psc_atomic64, dec, &v64, 206);
    TEST1V(psc_atomic64, dec_and_test0, &v64, 205, 0);
    TEST(psc_atomic64, set, &v64, &v64, 1, 1);
    TEST1V(psc_atomic64, dec_and_test0, &v64, 0, 1);
    TEST(psc_atomic64, setmask, &v64, &v64, 0x75, 0x75);
    TEST(psc_atomic64, clearmask, &v64, &v64, 0x41, 0x34);
    TEST(psc_atomic64, set, &v64, &v64, 0, 0);

    TEST1(psc_atomic16, inc, &v16, 1);
    TEST1V(psc_atomic16, dec_and_test0, &v16, 0, 1);

    rc = pthread_barrier_init(&barrier, NULL, nthr + 1);
    if (rc)
        psc_fatalx("pthread_barrier_init: %s", strerror(rc));
    for (i = 0; i < nthr; i++) {
        thr = PSCALLOC(sizeof(*thr));
        thr->pos = i;
        rc = pthread_create(&pthr, NULL, startf, thr);
        if (rc)
            psc_fatalx("pthread_create: %s", strerror(rc));
    }
    pthread_barrier_wait(&barrier);
    pthread_barrier_wait(&barrier);
    exit(0);
}
Esempio n. 12
0
int
main(int argc, char *argv[])
{
	struct psc_vbitmap *vb, vba = VBITMAP_INIT_AUTO;
	size_t elem, j, cap, len, off;
	int i, c, u, t;

	pfl_init();
	while ((c = getopt(argc, argv, "")) != -1)
		switch (c) {
		default:
			usage();
		}

	argc -= optind;
	if (argc)
		usage();

	for (i = 0; i < 79; i++)
		if (psc_vbitmap_next(&vba, &j) != 1)
			psc_fatalx("psc_vbitmap_next failed with auto");
		else if (j != (size_t)i)
			psc_fatalx("elem %d is not supposed to be %zu", i, j);

	if ((vb = psc_vbitmap_new(213)) == NULL)
		psc_fatal("psc_vbitmap_new");

	psc_vbitmap_setrange(vb, 13, 9);
	psc_vbitmap_printbin1(vb);
	for (i = 0; i < 13; i++)
		pfl_assert(psc_vbitmap_get(vb, i) == 0);
	for (j = 0; j < 9; j++, i++)
	    pfl_assert(psc_vbitmap_get(vb, i) == 1);
	for (j = 0; j < 25; j++, i++)
	    pfl_assert(psc_vbitmap_get(vb, i) == 0);

	psc_vbitmap_clearall(vb);
	for (i = 0; i < 213; i++)
	    pfl_assert(psc_vbitmap_get(vb, i) == 0);

	psc_vbitmap_setrange(vb, 25, 3);
	for (i = 0; i < 25; i++)
		pfl_assert(psc_vbitmap_get(vb, i) == 0);
	for (j = 0; j < 3; j++, i++)
	    pfl_assert(psc_vbitmap_get(vb, i) == 1);
	for (j = 0; j < 25; j++, i++)
	    pfl_assert(psc_vbitmap_get(vb, i) == 0);

	psc_vbitmap_clearall(vb);
	for (i = 0; i < 213; i++)
	    pfl_assert(psc_vbitmap_get(vb, i) == 0);

	for (i = 0; i < 213; i++)
		if (!psc_vbitmap_next(vb, &elem))
			psc_fatalx("out of elements at pos %d", i);

	if (psc_vbitmap_next(vb, &elem))
		psc_fatalx("an unexpected extra unused elem was found; pos=%zu", elem);

	psc_vbitmap_getstats(vb, &u, &t);
	if (u != 213 || t != 213)
		psc_fatalx("wrong size, got %d,%d want %d", u, t, 213);

	psc_vbitmap_unsetrange(vb, 13, 2);
	for (i = 0; i < 13; i++)
		pfl_assert(psc_vbitmap_get(vb, i) == 1);
	for (j = 0; j < 2; j++, i++)
	    pfl_assert(psc_vbitmap_get(vb, i) == 0);
	for (j = 0; j < 25; j++, i++)
	    pfl_assert(psc_vbitmap_get(vb, i) == 1);

	if (psc_vbitmap_resize(vb, NELEM) == -1)
		psc_fatal("psc_vbitmap_resize");

	pfl_assert(psc_vbitmap_getsize(vb) == NELEM);

	/* fill up bitmap */
	for (i = 0; i < NELEM - 211; i++)
		if (!psc_vbitmap_next(vb, &elem))
			psc_fatalx("out of elements at iter %d", i);

	/* try one past end of filled bitmap */
	if (psc_vbitmap_next(vb, &elem))
		psc_fatalx("an unexpected extra unused elem was found; pos=%zu", elem);

	/* free some slots */
	for (i = 0, elem = 0; elem < NELEM; i++, elem += NELEM / 10)
		psc_vbitmap_unset(vb, elem);

	t = psc_vbitmap_nfree(vb);
	if (t != i)
		psc_fatalx("wrong number of free elements; has=%d want=%d", t, i);
	psc_vbitmap_invert(vb);
	t = psc_vbitmap_nfree(vb);
	if (t != NELEM - i)
		psc_fatalx("wrong number of inverted elements; has=%d want=%d",
		    t, NELEM - i);
	psc_vbitmap_invert(vb);
	t = psc_vbitmap_nfree(vb);
	if (t != i)
		psc_fatalx("wrong number of original elements; has=%d want=%d", t, i);

	/* try to re-grab the freed slots */
	for (i = 0; i <= 10; i++)
		if (!psc_vbitmap_next(vb, &elem))
			psc_fatalx("out of elements, request %d/%d", i, 10);

	/* try one past end of filled bitmap */
	if (psc_vbitmap_next(vb, &elem))
		psc_fatalx("an unexpected extra unused elem was found; pos=%zu", elem);

	psc_vbitmap_setval_range(vb, 0, NELEM, 0);
	CHECK_RANGE(vb, 0, 581, 371);
	CHECK_RANGE(vb, 0, 581, 1);
	pfl_assert(pfl_vbitmap_isempty(vb));

	psc_vbitmap_setval_range(vb, 0, NELEM, 1);
	CHECK_RANGE(vb, 1, 581, 371);
	CHECK_RANGE(vb, 1, 581, 1);
	pfl_assert(psc_vbitmap_isfull(vb));

	psc_vbitmap_free(vb);

	vb = psc_vbitmap_newf(0, PVBF_AUTO);
	pfl_assert(vb);
	pfl_assert(pfl_vbitmap_isempty(vb));
	pfl_assert(psc_vbitmap_getsize(vb) == 0);
	pfl_assert(psc_vbitmap_resize(vb, 6) == 0);
	pfl_assert(psc_vbitmap_getsize(vb) == 6);
	pfl_assert(pfl_vbitmap_isempty(vb));
	psc_vbitmap_free(vb);

	vb = psc_vbitmap_newf(0, PVBF_AUTO);
	cap = psc_vbitmap_getsize(vb);
	off = 0;
	len = 6;
	if (off + len > cap)
		psc_vbitmap_resize(vb, off + len);
	psc_vbitmap_setrange(vb, off, len);
	ENSURE(vb, "111111");
	CHECK_RANGE(vb, 1, 2, 4);

	psc_vbitmap_clearall(vb);
	pfl_assert(psc_vbitmap_setval_range(vb, 2, 4, 1) == 0);
	CHECK_RANGE(vb, 1, 2, 4);
	ENSURE(vb, "001111");
	psc_vbitmap_free(vb);

	vb = psc_vbitmap_new(0);
	for (i = 1; i < 101; i++) {
		if (psc_vbitmap_resize(vb, i) == -1)
			psc_fatal("psc_vbitmap_new");
		psc_vbitmap_setval(vb, i - 1, i % 2);
		pfl_assert(psc_vbitmap_get(vb, i - 1) == i % 2);
	}
	psc_vbitmap_free(vb);

	for (cap = 0; cap < 100; cap++) {
		for (off = 1; off < cap; off++) {
			for (len = 1; off + len < cap; len++) {
				size_t last;

				last = cap - off - len;
				vb = psc_vbitmap_new(cap);
				psc_vbitmap_setrange(vb, off, len);
				ENSURE(vb, "%0*d%*d%0*d", (int)off, 0,
				    (int)len, 1, (int)last, 0);
				CHECK_RANGE(vb, 0, 0, off);
				CHECK_RANGE(vb, 1, off, len);
				CHECK_RANGE(vb, 0, off+len, last);
				psc_vbitmap_free(vb);
			}
		}
	}

	vb = psc_vbitmap_new(8200);
	pfl_assert(pfl_vbitmap_isempty(vb));
	CHECK_RANGE(vb, 0, 8, 8192);
	psc_vbitmap_free(vb);

	vb = psc_vbitmap_new(16);
	ENSURE_ABBR(vb, "0:8,00000000");
	psc_vbitmap_free(vb);

	vb = psc_vbitmap_new(40);
	psc_vbitmap_setval_range(vb, 0, 10, 0);
	psc_vbitmap_setval_range(vb, 10, 10, 1);
	ENSURE(vb, "0000000000111111111100000000000000000000");
	ENSURE_ABBR(vb, "0:10,1:10,0:12,00000000");
	psc_vbitmap_free(vb);

	vb = psc_vbitmap_new(16);
	ENSURE(vb, "0000000000000000");
	pfl_assert(pfl_vbitmap_isempty(vb));
	CHECK_RANGE(vb, 0, 8, 8);
	CHECK_RANGE(vb, 0, 9, 7);
	psc_vbitmap_setval(vb, 15, 1);
	ENSURE(vb, "0000000000000001");
	CHECK_RANGE(vb, 0, 9, 6);
	CHECK_RANGE(vb, 1, 15, 1);
	pfl_assert(pfl_vbitmap_israngeset(vb, 0, 8, 8) == 0);
	pfl_assert(pfl_vbitmap_israngeset(vb, 1, 8, 8) == 0);
	psc_vbitmap_clearall(vb);
	pfl_assert(pfl_vbitmap_isempty(vb));
	psc_vbitmap_free(vb);

	exit(0);
}
Esempio n. 13
0
int
main(int argc, char *argv[])
{
	ssize_t nents = SLJ_MDS_JNENTS;
	char *endp, c, fn[PATH_MAX];
	uint64_t uuid = 0;
	long l;

	pfl_init();
	sl_subsys_register();

	fn[0] = '\0';
	progname = argv[0];
	while ((c = getopt(argc, argv, "b:D:fn:qu:v")) != -1)
		switch (c) {
		case 'b':
			strlcpy(fn, optarg, sizeof(fn));
			break;
		case 'D':
			datadir = optarg;
			break;
		case 'f':
			format = 1;
			break;
		case 'n':
			endp = NULL;
			l = strtol(optarg, &endp, 10);
			if (l <= 0 || l > INT_MAX ||
			    endp == optarg || *endp)
				errx(1, "invalid -n nentries: %s",
				    optarg);
			nents = (ssize_t)l;
			break;
		case 'q':
			query = 1;
			break;
		case 'u':
			endp = NULL;
			uuid = (uint64_t)strtoull(optarg, &endp, 16);
			if (endp == optarg || *endp)
				errx(1, "invalid -u fsuuid: %s",
				    optarg);
			break;
		case 'v':
			verbose = 1;
			break;
		default:
			usage();
		}
	argc -= optind;
	if (argc)
		usage();

	if (fn[0] == '\0') {
		if (mkdir(datadir, 0700) == -1)
			if (errno != EEXIST)
				err(1, "mkdir: %s", datadir);

		xmkfn(fn, "%s/%s", datadir, SL_FN_OPJOURNAL);
	}

	if (format) {
		if (!uuid)
			psc_fatalx("no fsuuid specified");
		pjournal_format(fn, nents, SLJ_MDS_ENTSIZE,
		    SLJ_MDS_READSZ, uuid);
		if (verbose)
			warnx("created log file %s with %zu %d-byte entries "
			      "(uuid=%"PRIx64")",
			      fn, nents, SLJ_MDS_ENTSIZE, uuid);
	} else if (query)
		pjournal_dump(fn);
	else
		usage();
	exit(0);
}
Esempio n. 14
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);
}
Esempio n. 15
0
int
main(int argc, char *argv[])
{
	struct psc_vbitmap *vb, vba = VBITMAP_INIT_AUTO;
	int i, c, u, t;
	size_t elem, j;

	pfl_init();
	progname = argv[0];
	while ((c = getopt(argc, argv, "")) != -1)
		switch (c) {
		default:
			usage();
		}

	argc -= optind;
	if (argc)
		usage();

	for (i = 0; i < 79; i++)
		if (psc_vbitmap_next(&vba, &j) != 1)
			psc_fatalx("psc_vbitmap_next failed with auto");
		else if (j != (size_t)i)
			psc_fatalx("elem %d is not supposed to be %zu", i, j);

	if ((vb = psc_vbitmap_new(213)) == NULL)
		psc_fatal("psc_vbitmap_new");

	psc_vbitmap_setrange(vb, 13, 9);
	psc_vbitmap_printbin1(vb);
	for (i = 0; i < 13; i++)
		psc_assert(psc_vbitmap_get(vb, i) == 0);
	for (j = 0; j < 9; j++, i++)
	    psc_assert(psc_vbitmap_get(vb, i) == 1);
	for (j = 0; j < 25; j++, i++)
	    psc_assert(psc_vbitmap_get(vb, i) == 0);

	psc_vbitmap_clearall(vb);
	for (i = 0; i < 213; i++)
	    psc_assert(psc_vbitmap_get(vb, i) == 0);

	psc_vbitmap_setrange(vb, 25, 3);
	for (i = 0; i < 25; i++)
		psc_assert(psc_vbitmap_get(vb, i) == 0);
	for (j = 0; j < 3; j++, i++)
	    psc_assert(psc_vbitmap_get(vb, i) == 1);
	for (j = 0; j < 25; j++, i++)
	    psc_assert(psc_vbitmap_get(vb, i) == 0);

	psc_vbitmap_clearall(vb);
	for (i = 0; i < 213; i++)
	    psc_assert(psc_vbitmap_get(vb, i) == 0);

	for (i = 0; i < 213; i++)
		if (!psc_vbitmap_next(vb, &elem))
			psc_fatalx("out of elements at pos %d", i);

	if (psc_vbitmap_next(vb, &elem))
		psc_fatalx("an unexpected extra unused elem was found; pos=%zu", elem);

	psc_vbitmap_getstats(vb, &u, &t);
	if (u != 213 || t != 213)
		psc_fatalx("wrong size, got %d,%d want %d", u, t, 213);

	psc_vbitmap_unsetrange(vb, 13, 2);
	for (i = 0; i < 13; i++)
		psc_assert(psc_vbitmap_get(vb, i) == 1);
	for (j = 0; j < 2; j++, i++)
	    psc_assert(psc_vbitmap_get(vb, i) == 0);
	for (j = 0; j < 25; j++, i++)
	    psc_assert(psc_vbitmap_get(vb, i) == 1);

	if (psc_vbitmap_resize(vb, NELEM) == -1)
		psc_fatal("psc_vbitmap_new");

	psc_assert(psc_vbitmap_getsize(vb) == NELEM);

	/* fill up bitmap */
	for (i = 0; i < NELEM - 211; i++)
		if (!psc_vbitmap_next(vb, &elem))
			psc_fatalx("out of elements at iter %d", i);

	/* try one past end of filled bitmap */
	if (psc_vbitmap_next(vb, &elem))
		psc_fatalx("an unexpected extra unused elem was found; pos=%zu", elem);

	/* free some slots */
	for (i = 0, elem = 0; elem < NELEM; i++, elem += NELEM / 10)
		psc_vbitmap_unset(vb, elem);

	t = psc_vbitmap_nfree(vb);
	if (t != i)
		psc_fatalx("wrong number of free elements; has=%d want=%d", t, i);
	psc_vbitmap_invert(vb);
	t = psc_vbitmap_nfree(vb);
	if (t != NELEM - i)
		psc_fatalx("wrong number of inverted elements; has=%d want=%d",
		    t, NELEM - i);
	psc_vbitmap_invert(vb);
	t = psc_vbitmap_nfree(vb);
	if (t != i)
		psc_fatalx("wrong number of original elements; has=%d want=%d", t, i);

	/* try to re-grab the freed slots */
	for (i = 0; i <= 10; i++)
		if (!psc_vbitmap_next(vb, &elem))
			psc_fatalx("out of elements, request %d/%d", i, 10);

	/* try one past end of filled bitmap */
	if (psc_vbitmap_next(vb, &elem))
		psc_fatalx("an unexpected extra unused elem was found; pos=%zu", elem);

	psc_vbitmap_setval_range(vb, 0, NELEM, 0);
	psc_assert(pfl_vbitmap_israngeset(vb, 0, 581, 371));
	psc_assert(pfl_vbitmap_israngeset(vb, 1, 581, 371) == 0);
	psc_assert(pfl_vbitmap_israngeset(vb, 0, 581, 1));
	psc_assert(pfl_vbitmap_israngeset(vb, 1, 581, 1) == 0);
	psc_assert(pfl_vbitmap_isempty(vb));

	psc_vbitmap_setval_range(vb, 0, NELEM, 1);
	psc_assert(pfl_vbitmap_israngeset(vb, 1, 581, 371));
	psc_assert(pfl_vbitmap_israngeset(vb, 0, 581, 371) == 0);
	psc_assert(pfl_vbitmap_israngeset(vb, 1, 581, 1));
	psc_assert(pfl_vbitmap_israngeset(vb, 0, 581, 1) == 0);
	psc_assert(psc_vbitmap_isfull(vb));

	psc_vbitmap_free(vb);

	vb = psc_vbitmap_new(0);
	for (i = 1; i < 101; i++) {
		if (psc_vbitmap_resize(vb, i) == -1)
			psc_fatal("psc_vbitmap_new");
		psc_vbitmap_setval(vb, i - 1, i % 2);
		psc_assert(psc_vbitmap_get(vb, i - 1) == i % 2);
	}

	exit(0);
}