Beispiel #1
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "util_pool_create");

	if (argc < 3)
		FATAL("usage: %s minlen len:path...", argv[0]);

	char *fname;
	size_t minsize = strtoul(argv[1], &fname, 0);

	for (int arg = 2; arg < argc; arg++) {
		size_t size = strtoul(argv[arg], &fname, 0);
		if (*fname != ':')
			FATAL("usage: %s minlen len:path...", argv[0]);
		fname++;

		int fd;
		if ((fd = util_pool_create(fname, size, minsize, S_IWUSR))
				== -1)
			OUT("!%s: util_pool_create", fname);
		else {
			OUT("%s: created", fname);
			close(fd);
		}
	}

	DONE(NULL);
}
Beispiel #2
0
/*
 * pmemlog_create -- create a log memory pool
 */
PMEMlogpool *
pmemlog_create(const char *path, size_t poolsize, mode_t mode)
{
    LOG(3, "path %s poolsize %zu mode %d", path, poolsize, mode);

    struct pool_set *set;

    if (util_pool_create(&set, path, poolsize, PMEMLOG_MIN_POOL,
                         LOG_HDR_SIG, LOG_FORMAT_MAJOR,
                         LOG_FORMAT_COMPAT, LOG_FORMAT_INCOMPAT,
                         LOG_FORMAT_RO_COMPAT, NULL,
                         REPLICAS_DISABLED) != 0) {
        LOG(2, "cannot create pool or pool set");
        return NULL;
    }

    ASSERT(set->nreplicas > 0);

    struct pool_replica *rep = set->replica[0];
    PMEMlogpool *plp = rep->part[0].addr;

    VALGRIND_REMOVE_PMEM_MAPPING(&plp->addr,
                                 sizeof(struct pmemlog) -
                                 ((uintptr_t)&plp->addr - (uintptr_t)&plp->hdr));

    plp->addr = plp;
    plp->size = rep->repsize;
    plp->set = set;
    plp->is_pmem = rep->is_pmem;
    plp->is_dax = rep->part[0].is_dax;

    /* create pool descriptor */
    if (pmemlog_descr_create(plp, rep->repsize) != 0) {
        LOG(2, "descriptor creation failed");
        goto err;
    }

    /* initialize runtime parts */
    if (pmemlog_runtime_init(plp, 0) != 0) {
        ERR("pool initialization failed");
        goto err;
    }

    if (util_poolset_chmod(set, mode))
        goto err;

    util_poolset_fdclose(set);

    LOG(3, "plp %p", plp);
    return plp;

err:
    LOG(4, "error clean up");
    int oerrno = errno;
    util_poolset_close(set, 1);
    errno = oerrno;
    return NULL;
}
Beispiel #3
0
int
main(int argc, char *argv[])
{
    START(argc, argv, "util_poolset");

    common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
                MAJOR_VERSION, MINOR_VERSION);

    if (argc < 5)
        UT_FATAL("usage: %s cmd minlen hdrsize [mockopts] setfile ...",
                 argv[0]);

    char *fname;
    struct pool_set *set;
    int ret;

    size_t minsize = strtoul(argv[2], &fname, 0);

    for (int arg = 3; arg < argc; arg++) {
        arg += mock_options(argv[arg]);
        fname = argv[arg];

        switch (argv[1][0]) {
        case 'c':
            ret = util_pool_create(&set, fname, 0, minsize,
                                   SIG, 1, 0, 0, 0, NULL, REPLICAS_ENABLED);
            if (ret == -1)
                UT_OUT("!%s: util_pool_create", fname);
            else {
                /*
                 * XXX: On Windows pool files are created with
                 * R/W permissions, so no need for chmod().
                 */
#ifndef _WIN32
                util_poolset_chmod(set, S_IWUSR | S_IRUSR);
#endif
                poolset_info(fname, set, 0);
                util_poolset_close(set, 0); /* do not delete */
            }
            break;
        case 'o':
            ret = util_pool_open(&set, fname, 0 /* rdonly */,
                                 minsize, SIG, 1, 0, 0, 0, NULL);
            if (ret == -1)
                UT_OUT("!%s: util_pool_open", fname);
            else {
                poolset_info(fname, set, 1);
                util_poolset_close(set, 0); /* do not delete */
            }
            break;
        }
    }

    common_fini();

    DONE(NULL);
}
Beispiel #4
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "util_poolset");

	out_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
			MAJOR_VERSION, MINOR_VERSION);
	util_init();

	if (argc < 5)
		UT_FATAL("usage: %s cmd minlen hdrsize [mockopts] setfile ...",
			argv[0]);

	char *fname;
	struct pool_set *set;
	int ret;

	size_t minsize = strtoul(argv[2], &fname, 0);

	for (int arg = 3; arg < argc; arg++) {
		arg += mock_options(argv[arg]);
		fname = argv[arg];

		switch (argv[1][0]) {
		case 'c':
			ret = util_pool_create(&set, fname, 0, minsize,
				SIG, 1, 0, 0, 0);
			if (ret == -1)
				UT_OUT("!%s: util_pool_create", fname);
			else {
				util_poolset_chmod(set, S_IWUSR | S_IRUSR);
				poolset_info(fname, set, 0);
				util_poolset_close(set, 0); /* do not delete */
			}
			break;
		case 'o':
			ret = util_pool_open(&set, fname, 0 /* rdonly */,
				minsize, SIG, 1, 0, 0, 0);
			if (ret == -1)
				UT_OUT("!%s: util_pool_open", fname);
			else {
				poolset_info(fname, set, 1);
				util_poolset_close(set, 0); /* do not delete */
			}
			break;
		}
	}

	out_fini();

	DONE(NULL);
}
Beispiel #5
0
/*
 * pmemlog_create -- create a log memory pool
 */
PMEMlogpool *
pmemlog_create(const char *path, size_t poolsize, mode_t mode)
{
    LOG(3, "path %s poolsize %zu mode %d", path, poolsize, mode);

    int created = 0;
    int fd;
    if (poolsize != 0) {
        /* create a new memory pool file */
        fd = util_pool_create(path, poolsize, PMEMLOG_MIN_POOL, mode);
        created = 1;
    } else {
        /* open an existing file */
        fd = util_pool_open(path, &poolsize, PMEMLOG_MIN_POOL);
    }
    if (fd == -1)
        return NULL;	/* errno set by util_pool_create/open() */

    PMEMlogpool *plp = pmemlog_map_common(fd, poolsize, 0, 1);
    if (plp == NULL && created)
        unlink(path);	/* delete file if pool creation failed */

    return plp;
}
Beispiel #6
0
Datei: obj.c Projekt: jxy859/nvml
/*
 * pmemobj_create -- create a transactional memory pool (set)
 */
PMEMobjpool *
pmemobj_create(const char *path, const char *layout, size_t poolsize,
		mode_t mode)
{
	LOG(3, "path %s layout %s poolsize %zu mode %o",
			path, layout, poolsize, mode);

	/* check length of layout */
	if (layout && (strlen(layout) >= PMEMOBJ_MAX_LAYOUT)) {
		ERR("Layout too long");
		errno = EINVAL;
		return NULL;
	}

	struct pool_set *set;

	if (util_pool_create(&set, path, poolsize, PMEMOBJ_MIN_POOL,
			roundup(sizeof (struct pmemobjpool), Pagesize),
			OBJ_HDR_SIG, OBJ_FORMAT_MAJOR,
			OBJ_FORMAT_COMPAT, OBJ_FORMAT_INCOMPAT,
			OBJ_FORMAT_RO_COMPAT) != 0) {
		LOG(2, "cannot create pool or pool set");
		return NULL;
	}

	ASSERT(set->nreplicas > 0);

	PMEMobjpool *pop;
	for (unsigned r = 0; r < set->nreplicas; r++) {
		struct pool_replica *rep = set->replica[r];
		pop = rep->part[0].addr;

		VALGRIND_REMOVE_PMEM_MAPPING(&pop->addr,
			sizeof (struct pmemobjpool) -
			((uintptr_t)&pop->addr - (uintptr_t)&pop->hdr));

		pop->addr = pop;
		pop->size = rep->repsize;

		/* create pool descriptor */
		if (pmemobj_descr_create(pop, layout, set->poolsize) != 0) {
			LOG(2, "descriptor creation failed");
			goto err;
		}

		/* initialize replica runtime - is_pmem, funcs, ... */
		if (pmemobj_replica_init(pop, rep->is_pmem) != 0) {
			ERR("pool initialization failed");
			goto err;
		}

		/* link replicas */
		if (r < set->nreplicas - 1)
			pop->replica = set->replica[r + 1]->part[0].addr;
	}

	pop = set->replica[0]->part[0].addr;
	pop->is_master_replica = 1;

	for (unsigned r = 1; r < set->nreplicas; r++) {
		PMEMobjpool *rep = set->replica[r]->part[0].addr;
		rep->is_master_replica = 0;
	}

	VALGRIND_DO_CREATE_MEMPOOL(pop, 0, 0);

	/* initialize runtime parts - lanes, obj stores, ... */
	if (pmemobj_runtime_init(pop, 0, 1 /* boot*/) != 0) {
		ERR("pool initialization failed");
		goto err;
	}

	if (util_poolset_chmod(set, mode))
		goto err;

	util_poolset_fdclose(set);

	util_poolset_free(set);

	LOG(3, "pop %p", pop);

	return pop;

err:
	LOG(4, "error clean up");
	int oerrno = errno;
	util_poolset_close(set, 1);
	errno = oerrno;
	return NULL;
}
Beispiel #7
0
Datei: blk.c Projekt: xguo/nvml
/*
 * pmemblk_create -- create a block memory pool
 */
PMEMblkpool *
pmemblk_create(const char *path, size_t bsize, size_t poolsize,
		mode_t mode)
{
	LOG(3, "path %s bsize %zu poolsize %zu mode %o",
			path, bsize, poolsize, mode);

	/* check if bsize is valid */
	if (bsize == 0) {
		ERR("Invalid block size %zu", bsize);
		errno = EINVAL;
		return NULL;
	}

	if (bsize > UINT32_MAX) {
		ERR("Invalid block size %zu", bsize);
		errno = EINVAL;
		return NULL;
	}

	struct pool_set *set;

	if (util_pool_create(&set, path, poolsize, PMEMBLK_MIN_POOL,
			roundup(sizeof (struct pmemblk), Pagesize),
			BLK_HDR_SIG, BLK_FORMAT_MAJOR,
			BLK_FORMAT_COMPAT, BLK_FORMAT_INCOMPAT,
			BLK_FORMAT_RO_COMPAT) != 0) {
		LOG(2, "cannot create pool or pool set");
		return NULL;
	}

	ASSERT(set->nreplicas > 0);

	struct pool_replica *rep = set->replica[0];
	PMEMblkpool *pbp = rep->part[0].addr;

	pbp->addr = pbp;
	pbp->size = rep->repsize;

	VALGRIND_REMOVE_PMEM_MAPPING(&pbp->addr,
			sizeof (struct pmemblk) -
			((uintptr_t)&pbp->addr - (uintptr_t)&pbp->hdr));

	if (set->nreplicas > 1) {
		ERR("replicas not supported");
		goto err;
	}

	/* create pool descriptor */
	if (pmemblk_descr_create(pbp, (uint32_t)bsize, set->zeroed) != 0) {
		LOG(2, "descriptor creation failed");
		goto err;
	}

	/* initialize runtime parts */
	if (pmemblk_runtime_init(pbp, bsize, 0, rep->is_pmem) != 0) {
		ERR("pool initialization failed");
		goto err;
	}

	if (util_poolset_chmod(set, mode))
		goto err;

	util_poolset_fdclose(set);

	util_poolset_free(set);

	LOG(3, "pbp %p", pbp);
	return pbp;

err:
	LOG(4, "error clean up");
	int oerrno = errno;
	util_poolset_close(set, 1);
	errno = oerrno;
	return NULL;
}
Beispiel #8
0
int
main(int argc, char *argv[])
{
	START(argc, argv, "util_poolset");

	common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
			MAJOR_VERSION, MINOR_VERSION);

	if (argc < 3)
		UT_FATAL("usage: %s cmd minsize [mockopts] "
			"setfile ...", argv[0]);

	char *fname;
	struct pool_set *set;
	int ret;

	size_t minsize = strtoul(argv[2], &fname, 0);

	for (int arg = 3; arg < argc; arg++) {
		arg += mock_options(argv[arg]);
		fname = argv[arg];
		struct pool_attr attr;
		memset(&attr, 0, sizeof(attr));
		memcpy(attr.signature, SIG, sizeof(SIG));
		attr.major = 1;

		switch (argv[1][0]) {
		case 'c':
			ret = util_pool_create(&set, fname, 0, minsize,
				MIN_PART, &attr, NULL, REPLICAS_ENABLED);
			if (ret == -1)
				UT_OUT("!%s: util_pool_create", fname);
			else {
				/*
				 * XXX: On Windows pool files are created with
				 * R/W permissions, so no need for chmod().
				 */
#ifndef _WIN32
				util_poolset_chmod(set, S_IWUSR | S_IRUSR);
#endif
				poolset_info(fname, set, 0);
				util_poolset_close(set, DO_NOT_DELETE_PARTS);
			}
			break;
		case 'o':
			attr.incompat_features = TEST_FORMAT_INCOMPAT_CHECK;
			ret = util_pool_open(&set, fname, 0 /* rdonly */,
				MIN_PART, &attr, NULL, false, NULL);
			if (ret == -1)
				UT_OUT("!%s: util_pool_open", fname);
			else {
				poolset_info(fname, set, 1);
				util_poolset_close(set, DO_NOT_DELETE_PARTS);
			}
			break;
		case 'e':
			attr.incompat_features = TEST_FORMAT_INCOMPAT_CHECK;
			ret = util_pool_open(&set, fname, 0 /* rdonly */,
				MIN_PART, &attr, NULL, false, NULL);
			UT_ASSERTeq(ret, 0);
			void *nptr = util_pool_extend(set, Extend_size);
			if (nptr == NULL)
				UT_OUT("!%s: util_pool_extend", fname);
			else {
				poolset_info(fname, set, 1);
			}
			util_poolset_close(set, DO_NOT_DELETE_PARTS);
			break;
		}
	}

	common_fini();

	DONE(NULL);
}
Beispiel #9
0
static inline
#endif
PMEMblkpool *
pmemblk_createU(const char *path, size_t bsize, size_t poolsize, mode_t mode)
{
	LOG(3, "path %s bsize %zu poolsize %zu mode %o",
			path, bsize, poolsize, mode);

	/* check if bsize is valid */
	if (bsize == 0) {
		ERR("Invalid block size %zu", bsize);
		errno = EINVAL;
		return NULL;
	}

	if (bsize > UINT32_MAX) {
		ERR("Invalid block size %zu", bsize);
		errno = EINVAL;
		return NULL;
	}

	struct pool_set *set;

	if (util_pool_create(&set, path, poolsize, PMEMBLK_MIN_POOL,
			BLK_HDR_SIG, BLK_FORMAT_MAJOR,
			BLK_FORMAT_COMPAT, BLK_FORMAT_INCOMPAT,
			BLK_FORMAT_RO_COMPAT, NULL,
			REPLICAS_DISABLED) != 0) {
		LOG(2, "cannot create pool or pool set");
		return NULL;
	}

	ASSERT(set->nreplicas > 0);

	struct pool_replica *rep = set->replica[0];
	PMEMblkpool *pbp = rep->part[0].addr;

	VALGRIND_REMOVE_PMEM_MAPPING(&pbp->addr,
			sizeof(struct pmemblk) -
			((uintptr_t)&pbp->addr - (uintptr_t)&pbp->hdr));

	pbp->addr = pbp;
	pbp->size = rep->repsize;
	pbp->set = set;
	pbp->is_pmem = rep->is_pmem;
	pbp->is_dev_dax = rep->part[0].is_dev_dax;

	/* is_dev_dax implies is_pmem */
	ASSERT(!pbp->is_dev_dax || pbp->is_pmem);

	/* create pool descriptor */
	blk_descr_create(pbp, (uint32_t)bsize, set->zeroed);

	/* initialize runtime parts */
	if (blk_runtime_init(pbp, bsize, 0) != 0) {
		ERR("pool initialization failed");
		goto err;
	}

	if (util_poolset_chmod(set, mode))
		goto err;

	util_poolset_fdclose(set);

	LOG(3, "pbp %p", pbp);
	return pbp;

err:
	LOG(4, "error clean up");
	int oerrno = errno;
	util_poolset_close(set, DELETE_CREATED_PARTS);
	errno = oerrno;
	return NULL;
}