repo
stringlengths 1
152
⌀ | file
stringlengths 14
221
| code
stringlengths 501
25k
| file_length
int64 501
25k
| avg_line_length
float64 20
99.5
| max_line_length
int64 21
134
| extension_type
stringclasses 2
values |
|---|---|---|---|---|---|---|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/check.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* check.h -- pmempool check command header file
*/
int pmempool_check_func(const char *appname, int argc, char *argv[]);
void pmempool_check_help(const char *appname);
| 1,776
| 44.564103
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/info_cto.c
|
/*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* info_cto.c -- pmempool info command source file for cto pool
*/
#include <stdlib.h>
#include <stdbool.h>
#include <err.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <assert.h>
#include <inttypes.h>
#include "common.h"
#include "output.h"
#include "info.h"
/*
* info_cto_descriptor -- print pmemcto descriptor
*/
static void
info_cto_descriptor(struct pmem_info *pip)
{
int v = VERBOSE_DEFAULT;
if (!outv_check(v))
return;
outv(v, "\nPMEM CTO Header:\n");
struct pmemcto *pcp = pip->cto.pcp;
uint8_t *hdrptr = (uint8_t *)pcp + sizeof(pcp->hdr);
size_t hdrsize = sizeof(*pcp) - sizeof(pcp->hdr);
size_t hdroff = sizeof(pcp->hdr);
outv_hexdump(pip->args.vhdrdump, hdrptr, hdrsize, hdroff, 1);
/* check if layout is zeroed */
char *layout = util_check_memory((uint8_t *)pcp->layout,
sizeof(pcp->layout), 0) ?
pcp->layout : "(null)";
outv_field(v, "Layout", "%s", layout);
outv_field(v, "Base address", "%p", (void *)pcp->addr);
outv_field(v, "Size", "0x%zx", (size_t)pcp->size);
outv_field(v, "Consistent", "%d", pcp->consistent);
outv_field(v, "Root pointer", "%p", (void *)pcp->root);
}
/*
* pmempool_info_cto -- print information about cto pool type
*/
int
pmempool_info_cto(struct pmem_info *pip)
{
pip->cto.pcp = pool_set_file_map(pip->pfile, 0);
if (pip->cto.pcp == NULL)
return -1;
pip->cto.size = pip->pfile->size;
info_cto_descriptor(pip);
return 0;
}
| 3,043
| 30.708333
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/create.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* create.c -- pmempool create command source file
*/
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <errno.h>
#include <libgen.h>
#include <err.h>
#include "common.h"
#include "file.h"
#include "create.h"
#include "os.h"
#include "set.h"
#include "output.h"
#include "libpmemblk.h"
#include "libpmemlog.h"
#include "libpmemcto.h"
#include "libpmempool.h"
#define DEFAULT_MODE 0664
/*
* pmempool_create -- context and args for create command
*/
struct pmempool_create {
int verbose;
char *fname;
int fexists;
char *inherit_fname;
int max_size;
char *str_type;
struct pmem_pool_params params;
struct pmem_pool_params inherit_params;
char *str_size;
char *str_mode;
char *str_bsize;
uint64_t csize;
int write_btt_layout;
int force;
char *layout;
struct options *opts;
int clearbadblocks;
};
/*
* pmempool_create_default -- default args for create command
*/
static const struct pmempool_create pmempool_create_default = {
.verbose = 0,
.fname = NULL,
.fexists = 0,
.inherit_fname = NULL,
.max_size = 0,
.str_type = NULL,
.str_bsize = NULL,
.csize = 0,
.write_btt_layout = 0,
.force = 0,
.layout = NULL,
.clearbadblocks = 0,
.params = {
.type = PMEM_POOL_TYPE_UNKNOWN,
.size = 0,
.mode = DEFAULT_MODE,
}
};
/*
* help_str -- string for help message
*/
static const char * const help_str =
"Create pmem pool of specified size, type and name\n"
"\n"
"Common options:\n"
" -s, --size <size> size of pool\n"
" -M, --max-size use maximum available space on file system\n"
" -m, --mode <octal> set permissions to <octal> (the default is 0664)\n"
" -i, --inherit <file> take required parameters from specified pool file\n"
" -b, --clearbadblocks clear bad blocks in existing files\n"
" -f, --force remove the pool first\n"
" -v, --verbose increase verbosity level\n"
" -h, --help display this help and exit\n"
"\n"
"Options for PMEMBLK:\n"
" -w, --write-layout force writing the BTT layout\n"
"\n"
"Options for PMEMOBJ and PMEMCTO:\n"
" -l, --layout <name> layout name stored in pool's header\n"
"\n"
"For complete documentation see %s-create(1) manual page.\n"
;
/*
* long_options -- command line options
*/
static const struct option long_options[] = {
{"size", required_argument, NULL, 's' | OPT_ALL},
{"verbose", no_argument, NULL, 'v' | OPT_ALL},
{"help", no_argument, NULL, 'h' | OPT_ALL},
{"max-size", no_argument, NULL, 'M' | OPT_ALL},
{"inherit", required_argument, NULL, 'i' | OPT_ALL},
{"mode", required_argument, NULL, 'm' | OPT_ALL},
{"write-layout", no_argument, NULL, 'w' | OPT_BLK},
{"layout", required_argument, NULL, 'l' | OPT_OBJ |
OPT_CTO},
{"force", no_argument, NULL, 'f' | OPT_ALL},
{"clearbadblocks", no_argument, NULL, 'b' | OPT_ALL},
{NULL, 0, NULL, 0 },
};
/*
* print_usage -- print application usage short description
*/
static void
print_usage(const char *appname)
{
printf("Usage: %s create [<args>] <blk|log|obj|cto> [<bsize>] <file>\n",
appname);
}
/*
* print_version -- print version string
*/
static void
print_version(const char *appname)
{
printf("%s %s\n", appname, SRCVERSION);
}
/*
* pmempool_create_help -- print help message for create command
*/
void
pmempool_create_help(const char *appname)
{
print_usage(appname);
print_version(appname);
printf(help_str, appname);
}
/*
* pmempool_create_obj -- create pmem obj pool
*/
static int
pmempool_create_obj(struct pmempool_create *pcp)
{
PMEMobjpool *pop = pmemobj_create(pcp->fname, pcp->layout,
pcp->params.size, pcp->params.mode);
if (!pop) {
outv_err("'%s' -- %s\n", pcp->fname, pmemobj_errormsg());
return -1;
}
pmemobj_close(pop);
return 0;
}
/*
* pmempool_create_cto -- create pmem cto pool
*/
static int
pmempool_create_cto(struct pmempool_create *pcp)
{
PMEMctopool *ptp = pmemcto_create(pcp->fname, pcp->layout,
pcp->params.size, pcp->params.mode);
if (!ptp) {
outv_err("'%s' -- %s\n", pcp->fname, pmemcto_errormsg());
return -1;
}
pmemcto_close(ptp);
return 0;
}
/*
* pmempool_create_blk -- create pmem blk pool
*/
static int
pmempool_create_blk(struct pmempool_create *pcp)
{
int ret = 0;
if (pcp->params.blk.bsize == 0) {
outv(1, "No block size option passed"
" - picking minimum block size.\n");
pcp->params.blk.bsize = PMEMBLK_MIN_BLK;
}
PMEMblkpool *pbp = pmemblk_create(pcp->fname, pcp->params.blk.bsize,
pcp->params.size, pcp->params.mode);
if (!pbp) {
outv_err("'%s' -- %s\n", pcp->fname, pmemblk_errormsg());
return -1;
}
if (pcp->write_btt_layout) {
outv(1, "Writing BTT layout using block %d.\n",
pcp->write_btt_layout);
if (pmemblk_set_error(pbp, 0) || pmemblk_set_zero(pbp, 0)) {
outv_err("writing BTT layout to block 0 failed\n");
ret = -1;
}
}
pmemblk_close(pbp);
return ret;
}
/*
* pmempool_create_log -- create pmem log pool
*/
static int
pmempool_create_log(struct pmempool_create *pcp)
{
PMEMlogpool *plp = pmemlog_create(pcp->fname,
pcp->params.size, pcp->params.mode);
if (!plp) {
outv_err("'%s' -- %s\n", pcp->fname, pmemlog_errormsg());
return -1;
}
pmemlog_close(plp);
return 0;
}
/*
* pmempool_get_max_size -- return maximum allowed size of file
*/
#ifndef _WIN32
static int
pmempool_get_max_size(const char *fname, uint64_t *sizep)
{
struct statvfs buf;
int ret = 0;
char *name = strdup(fname);
if (name == NULL) {
return -1;
}
char *dir = dirname(name);
if (statvfs(dir, &buf))
ret = -1;
else
*sizep = buf.f_bsize * buf.f_bavail;
free(name);
return ret;
}
#else
static int
pmempool_get_max_size(const char *fname, uint64_t *sizep)
{
int ret = 0;
ULARGE_INTEGER freespace;
char *name = strdup(fname);
if (name == NULL) {
return -1;
}
char *dir = dirname(name);
wchar_t *str = util_toUTF16(dir);
if (str == NULL) {
free(name);
return -1;
}
if (GetDiskFreeSpaceExW(str, &freespace, NULL, NULL) == 0)
ret = -1;
else
*sizep = freespace.QuadPart;
free(str);
free(name);
return ret;
}
#endif
/*
* print_pool_params -- print some parameters of a pool
*/
static void
print_pool_params(struct pmem_pool_params *params)
{
outv(1, "\ttype : %s\n", out_get_pool_type_str(params->type));
outv(1, "\tsize : %s\n", out_get_size_str(params->size, 2));
outv(1, "\tmode : 0%o\n", params->mode);
switch (params->type) {
case PMEM_POOL_TYPE_BLK:
outv(1, "\tbsize : %s\n",
out_get_size_str(params->blk.bsize, 0));
break;
case PMEM_POOL_TYPE_OBJ:
outv(1, "\tlayout: '%s'\n", params->obj.layout);
break;
case PMEM_POOL_TYPE_CTO:
outv(1, "\tlayout: '%s'\n", params->cto.layout);
break;
default:
break;
}
}
/*
* inherit_pool_params -- inherit pool parameters from specified file
*/
static int
inherit_pool_params(struct pmempool_create *pcp)
{
outv(1, "Parsing pool: '%s'\n", pcp->inherit_fname);
/*
* If no type string passed, --inherit option must be passed
* so parse file and get required parameters.
*/
if (pmem_pool_parse_params(pcp->inherit_fname,
&pcp->inherit_params, 1)) {
if (errno)
perror(pcp->inherit_fname);
else
outv_err("%s: cannot determine type of pool\n",
pcp->inherit_fname);
return -1;
}
if (PMEM_POOL_TYPE_UNKNOWN == pcp->inherit_params.type) {
outv_err("'%s' -- unknown pool type\n",
pcp->inherit_fname);
return -1;
}
print_pool_params(&pcp->inherit_params);
return 0;
}
/*
* pmempool_create_parse_args -- parse command line args
*/
static int
pmempool_create_parse_args(struct pmempool_create *pcp, const char *appname,
int argc, char *argv[], struct options *opts)
{
int opt, ret;
while ((opt = util_options_getopt(argc, argv, "vhi:s:Mm:l:wfb",
opts)) != -1) {
switch (opt) {
case 'v':
pcp->verbose = 1;
break;
case 'h':
pmempool_create_help(appname);
exit(EXIT_SUCCESS);
case 's':
pcp->str_size = optarg;
ret = util_parse_size(optarg,
(size_t *)&pcp->params.size);
if (ret || pcp->params.size == 0) {
outv_err("invalid size value specified '%s'\n",
optarg);
return -1;
}
break;
case 'M':
pcp->max_size = 1;
break;
case 'm':
pcp->str_mode = optarg;
if (util_parse_mode(optarg, &pcp->params.mode)) {
outv_err("invalid mode value specified '%s'\n",
optarg);
return -1;
}
break;
case 'i':
pcp->inherit_fname = optarg;
break;
case 'w':
pcp->write_btt_layout = 1;
break;
case 'l':
pcp->layout = optarg;
break;
case 'f':
pcp->force = 1;
break;
case 'b':
pcp->clearbadblocks = 1;
break;
default:
print_usage(appname);
return -1;
}
}
/* check for <type>, <bsize> and <file> strings */
if (optind + 2 < argc) {
pcp->str_type = argv[optind];
pcp->str_bsize = argv[optind + 1];
pcp->fname = argv[optind + 2];
} else if (optind + 1 < argc) {
pcp->str_type = argv[optind];
pcp->fname = argv[optind + 1];
} else if (optind < argc) {
pcp->fname = argv[optind];
pcp->str_type = NULL;
} else {
print_usage(appname);
return -1;
}
return 0;
}
/*
* pmempool_create_func -- main function for create command
*/
int
pmempool_create_func(const char *appname, int argc, char *argv[])
{
int ret = 0;
struct pmempool_create pc = pmempool_create_default;
pc.opts = util_options_alloc(long_options, sizeof(long_options) /
sizeof(long_options[0]), NULL);
/* parse command line arguments */
ret = pmempool_create_parse_args(&pc, appname, argc, argv, pc.opts);
if (ret)
exit(EXIT_FAILURE);
/* set verbosity level */
out_set_vlevel(pc.verbose);
umask(0);
int exists = util_file_exists(pc.fname);
if (exists < 0)
return -1;
pc.fexists = exists;
int is_poolset = util_is_poolset_file(pc.fname) == 1;
if (pc.inherit_fname) {
if (inherit_pool_params(&pc)) {
outv_err("parsing pool '%s' failed\n",
pc.inherit_fname);
return -1;
}
}
/*
* Parse pool type and other parameters if --inherit option
* passed. It is possible to either pass --inherit option
* or pool type string in command line arguments. This is
* validated here.
*/
if (pc.str_type) {
/* parse pool type string if passed in command line arguments */
pc.params.type = pmem_pool_type_parse_str(pc.str_type);
if (PMEM_POOL_TYPE_UNKNOWN == pc.params.type) {
outv_err("'%s' -- unknown pool type\n", pc.str_type);
return -1;
}
if (PMEM_POOL_TYPE_BLK == pc.params.type) {
if (pc.str_bsize == NULL) {
outv_err("blk pool requires <bsize> "
"argument\n");
return -1;
}
if (util_parse_size(pc.str_bsize,
(size_t *)&pc.params.blk.bsize)) {
outv_err("cannot parse '%s' as block size\n",
pc.str_bsize);
return -1;
}
}
} else if (pc.inherit_fname) {
pc.params.type = pc.inherit_params.type;
} else {
/* neither pool type string nor --inherit options passed */
print_usage(appname);
return -1;
}
if (util_options_verify(pc.opts, pc.params.type))
return -1;
if (pc.params.type != PMEM_POOL_TYPE_BLK && pc.str_bsize != NULL) {
outv_err("invalid option specified for %s pool type"
" -- block size\n",
out_get_pool_type_str(pc.params.type));
return -1;
}
if (is_poolset) {
if (pc.params.size) {
outv_err("-s|--size cannot be used with "
"poolset file\n");
return -1;
}
if (pc.max_size) {
outv_err("-M|--max-size cannot be used with "
"poolset file\n");
return -1;
}
}
if (pc.params.size && pc.max_size) {
outv_err("-M|--max-size option cannot be used with -s|--size"
" option\n");
return -1;
}
size_t max_layout = pc.params.type == PMEM_POOL_TYPE_OBJ ?
PMEMOBJ_MAX_LAYOUT : PMEMCTO_MAX_LAYOUT;
if (pc.layout && strlen(pc.layout) >= max_layout) {
outv_err("Layout name is to long, maximum number of characters"
" (including the terminating null byte) is %zu\n",
max_layout);
return -1;
}
if (pc.inherit_fname) {
if (!pc.str_size && !pc.max_size)
pc.params.size = pc.inherit_params.size;
if (!pc.str_mode)
pc.params.mode = pc.inherit_params.mode;
switch (pc.params.type) {
case PMEM_POOL_TYPE_BLK:
if (!pc.str_bsize)
pc.params.blk.bsize =
pc.inherit_params.blk.bsize;
break;
case PMEM_POOL_TYPE_OBJ:
if (!pc.layout) {
memcpy(pc.params.obj.layout,
pc.inherit_params.obj.layout,
sizeof(pc.params.obj.layout));
} else {
size_t len = sizeof(pc.params.obj.layout);
strncpy(pc.params.obj.layout, pc.layout,
len - 1);
pc.params.obj.layout[len - 1] = '\0';
}
break;
case PMEM_POOL_TYPE_CTO:
if (!pc.layout) {
memcpy(pc.params.cto.layout,
pc.inherit_params.cto.layout,
sizeof(pc.params.cto.layout));
} else {
size_t len = sizeof(pc.params.cto.layout);
strncpy(pc.params.cto.layout, pc.layout,
len - 1);
pc.params.cto.layout[len - 1] = '\0';
}
break;
default:
break;
}
}
/*
* If neither --size nor --inherit options passed, check
* for --max-size option - if not passed use minimum pool size.
*/
uint64_t min_size = pmem_pool_get_min_size(pc.params.type);
if (pc.params.size == 0) {
if (pc.max_size) {
outv(1, "Maximum size option passed "
"- getting available space of file system.\n");
ret = pmempool_get_max_size(pc.fname,
&pc.params.size);
if (ret) {
outv_err("cannot get available space of fs\n");
return -1;
}
if (pc.params.size == 0) {
outv_err("No space left on device\n");
return -1;
}
outv(1, "Available space is %s\n",
out_get_size_str(pc.params.size, 2));
} else {
if (!pc.fexists) {
outv(1, "No size option passed "
"- picking minimum pool size.\n");
pc.params.size = min_size;
}
}
} else {
if (pc.params.size < min_size) {
outv_err("size must be >= %lu bytes\n", min_size);
return -1;
}
}
if (pc.force)
pmempool_rm(pc.fname, PMEMPOOL_RM_FORCE);
outv(1, "Creating pool: %s\n", pc.fname);
print_pool_params(&pc.params);
if (pc.clearbadblocks) {
int ret = util_pool_clear_badblocks(pc.fname,
1 /* ignore non-existing */);
if (ret) {
outv_err("'%s' -- clearing bad blocks failed\n",
pc.fname);
return -1;
}
}
switch (pc.params.type) {
case PMEM_POOL_TYPE_BLK:
ret = pmempool_create_blk(&pc);
break;
case PMEM_POOL_TYPE_LOG:
ret = pmempool_create_log(&pc);
break;
case PMEM_POOL_TYPE_OBJ:
ret = pmempool_create_obj(&pc);
break;
case PMEM_POOL_TYPE_CTO:
ret = pmempool_create_cto(&pc);
break;
default:
ret = -1;
break;
}
if (ret) {
outv_err("creating pool file failed\n");
if (!pc.fexists)
util_unlink(pc.fname);
}
util_options_free(pc.opts);
return ret;
}
| 16,310
| 22.60492
| 76
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/transform.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* transform.c -- pmempool transform command source file
*/
#include <stdio.h>
#include <libgen.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <stdbool.h>
#include <sys/mman.h>
#include <endian.h>
#include "common.h"
#include "output.h"
#include "transform.h"
#include "libpmempool.h"
/*
* pmempool_transform_context -- context and arguments for transform command
*/
struct pmempool_transform_context {
unsigned flags; /* flags which modify the command execution */
char *poolset_file_src; /* a path to a source poolset file */
char *poolset_file_dst; /* a path to a target poolset file */
};
/*
* pmempool_transform_default -- default arguments for transform command
*/
static const struct pmempool_transform_context pmempool_transform_default = {
.flags = 0,
.poolset_file_src = NULL,
.poolset_file_dst = NULL,
};
/*
* help_str -- string for help message
*/
static const char * const help_str =
"Modify internal structure of a poolset\n"
"\n"
"Common options:\n"
" -d, --dry-run do not apply changes, only check for viability of"
" transformation\n"
" -v, --verbose increase verbosity level\n"
" -h, --help display this help and exit\n"
"\n"
"For complete documentation see %s-transform(1) manual page.\n"
;
/*
* long_options -- command line options
*/
static const struct option long_options[] = {
{"dry-run", no_argument, NULL, 'd'},
{"help", no_argument, NULL, 'h'},
{"verbose", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0 },
};
/*
* print_usage -- print application usage short description
*/
static void
print_usage(const char *appname)
{
printf("usage: %s transform [<options>] <poolset_file_src>"
" <poolset_file_dst>\n", appname);
}
/*
* print_version -- print version string
*/
static void
print_version(const char *appname)
{
printf("%s %s\n", appname, SRCVERSION);
}
/*
* pmempool_transform_help -- print help message for the transform command
*/
void
pmempool_transform_help(const char *appname)
{
print_usage(appname);
print_version(appname);
printf(help_str, appname);
}
/*
* pmempool_check_parse_args -- parse command line arguments
*/
static int
pmempool_transform_parse_args(struct pmempool_transform_context *ctx,
const char *appname, int argc, char *argv[])
{
int opt;
while ((opt = getopt_long(argc, argv, "dhv",
long_options, NULL)) != -1) {
switch (opt) {
case 'd':
ctx->flags = PMEMPOOL_TRANSFORM_DRY_RUN;
break;
case 'h':
pmempool_transform_help(appname);
exit(EXIT_SUCCESS);
case 'v':
out_set_vlevel(1);
break;
default:
print_usage(appname);
exit(EXIT_FAILURE);
}
}
if (optind + 1 < argc) {
ctx->poolset_file_src = argv[optind];
ctx->poolset_file_dst = argv[optind + 1];
} else {
print_usage(appname);
exit(EXIT_FAILURE);
}
return 0;
}
/*
* pmempool_transform_func -- main function for the transform command
*/
int
pmempool_transform_func(const char *appname, int argc, char *argv[])
{
int ret;
struct pmempool_transform_context ctx = pmempool_transform_default;
/* parse command line arguments */
if ((ret = pmempool_transform_parse_args(&ctx, appname, argc, argv)))
return ret;
ret = pmempool_transform(ctx.poolset_file_src, ctx.poolset_file_dst,
ctx.flags);
if (ret) {
if (errno)
outv_err("%s\n", strerror(errno));
outv_err("failed to transform %s -> %s: %s\n",
ctx.poolset_file_src, ctx.poolset_file_dst,
pmempool_errormsg());
return -1;
} else {
outv(1, "%s -> %s: transformed\n", ctx.poolset_file_src,
ctx.poolset_file_dst);
return 0;
}
}
| 5,204
| 26.394737
| 77
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/info_blk.c
|
/*
* Copyright 2014-2018, Intel Corporation
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* info_blk.c -- pmempool info command source file for blk pool
*/
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <sys/param.h>
#include <endian.h>
#include "os.h"
#include "common.h"
#include "output.h"
#include "info.h"
#include "btt.h"
/*
* pmempool_info_get_range -- get blocks/data chunk range
*
* Get range based on command line arguments and maximum value.
* Return value:
* 0 - range is empty
* 1 - range is not empty
*/
static int
pmempool_info_get_range(struct pmem_info *pip, struct range *rangep,
struct range *curp, uint32_t max, uint64_t offset)
{
/* not using range */
if (!pip->args.use_range) {
rangep->first = 0;
rangep->last = max;
return 1;
}
if (curp->first > offset + max)
return 0;
if (curp->first >= offset)
rangep->first = curp->first - offset;
else
rangep->first = 0;
if (curp->last < offset)
return 0;
if (curp->last <= offset + max)
rangep->last = curp->last - offset;
else
rangep->last = max;
return 1;
}
/*
* info_blk_skip_block -- get action type for block/data chunk
*
* Return value indicating whether processing block/data chunk
* should be skipped.
*
* Return values:
* 0 - continue processing
* 1 - skip current block
*/
static int
info_blk_skip_block(struct pmem_info *pip, int is_zero,
int is_error)
{
if (pip->args.blk.skip_no_flag && !is_zero && !is_error)
return 1;
if (is_zero && pip->args.blk.skip_zeros)
return 1;
if (is_error && pip->args.blk.skip_error)
return 1;
return 0;
}
/*
* info_btt_data -- print block data and corresponding flags from map
*/
static int
info_btt_data(struct pmem_info *pip, int v, struct btt_info *infop,
uint64_t arena_off, uint64_t offset, uint64_t *countp)
{
if (!outv_check(v))
return 0;
int ret = 0;
size_t mapsize = infop->external_nlba * BTT_MAP_ENTRY_SIZE;
uint32_t *map = malloc(mapsize);
if (!map)
err(1, "Cannot allocate memory for BTT map");
uint8_t *block_buff = malloc(infop->external_lbasize);
if (!block_buff)
err(1, "Cannot allocate memory for pmemblk block buffer");
/* read btt map area */
if (pmempool_info_read(pip, (uint8_t *)map, mapsize,
arena_off + infop->mapoff)) {
outv_err("wrong BTT Map size or offset\n");
ret = -1;
goto error;
}
uint64_t i;
struct range *curp = NULL;
struct range range;
FOREACH_RANGE(curp, &pip->args.ranges) {
if (pmempool_info_get_range(pip, &range, curp,
infop->external_nlba - 1, offset) == 0)
continue;
for (i = range.first; i <= range.last; i++) {
uint32_t map_entry = le32toh(map[i]);
int is_init = (map_entry & ~BTT_MAP_ENTRY_LBA_MASK)
== 0;
int is_zero = (map_entry & ~BTT_MAP_ENTRY_LBA_MASK)
== BTT_MAP_ENTRY_ZERO || is_init;
int is_error = (map_entry & ~BTT_MAP_ENTRY_LBA_MASK)
== BTT_MAP_ENTRY_ERROR;
uint64_t blockno = is_init ? i :
map_entry & BTT_MAP_ENTRY_LBA_MASK;
if (info_blk_skip_block(pip,
is_zero, is_error))
continue;
/* compute block's data address */
uint64_t block_off = arena_off + infop->dataoff +
blockno * infop->internal_lbasize;
if (pmempool_info_read(pip, block_buff,
infop->external_lbasize, block_off)) {
outv_err("cannot read %lu block\n", i);
ret = -1;
goto error;
}
if (*countp == 0)
outv_title(v, "PMEM BLK blocks data");
/*
* Print block number, offset and flags
* from map entry.
*/
outv(v, "Block %10lu: offset: %s\n",
offset + i,
out_get_btt_map_entry(map_entry));
/* dump block's data */
outv_hexdump(v, block_buff, infop->external_lbasize,
block_off, 1);
*countp = *countp + 1;
}
}
error:
free(map);
free(block_buff);
return ret;
}
/*
* info_btt_map -- print all map entries
*/
static int
info_btt_map(struct pmem_info *pip, int v,
struct btt_info *infop, uint64_t arena_off,
uint64_t offset, uint64_t *count)
{
if (!outv_check(v) && !outv_check(pip->args.vstats))
return 0;
int ret = 0;
size_t mapsize = infop->external_nlba * BTT_MAP_ENTRY_SIZE;
uint32_t *map = malloc(mapsize);
if (!map)
err(1, "Cannot allocate memory for BTT map");
/* read btt map area */
if (pmempool_info_read(pip, (uint8_t *)map, mapsize,
arena_off + infop->mapoff)) {
outv_err("wrong BTT Map size or offset\n");
ret = -1;
goto error;
}
uint32_t arena_count = 0;
uint64_t i;
struct range *curp = NULL;
struct range range;
FOREACH_RANGE(curp, &pip->args.ranges) {
if (pmempool_info_get_range(pip, &range, curp,
infop->external_nlba - 1, offset) == 0)
continue;
for (i = range.first; i <= range.last; i++) {
uint32_t entry = le32toh(map[i]);
int is_zero = (entry & ~BTT_MAP_ENTRY_LBA_MASK) ==
BTT_MAP_ENTRY_ZERO ||
(entry & ~BTT_MAP_ENTRY_LBA_MASK) == 0;
int is_error = (entry & ~BTT_MAP_ENTRY_LBA_MASK) ==
BTT_MAP_ENTRY_ERROR;
if (info_blk_skip_block(pip,
is_zero, is_error) == 0) {
if (arena_count == 0)
outv_title(v, "PMEM BLK BTT Map");
if (is_zero)
pip->blk.stats.zeros++;
if (is_error)
pip->blk.stats.errors++;
if (!is_zero && !is_error)
pip->blk.stats.noflag++;
pip->blk.stats.total++;
arena_count++;
(*count)++;
outv(v, "%010lu: %s\n", offset + i,
out_get_btt_map_entry(entry));
}
}
}
error:
free(map);
return ret;
}
/*
* info_btt_flog -- print all flog entries
*/
static int
info_btt_flog(struct pmem_info *pip, int v,
struct btt_info *infop, uint64_t arena_off)
{
if (!outv_check(v))
return 0;
int ret = 0;
struct btt_flog *flogp = NULL;
struct btt_flog *flogpp = NULL;
uint64_t flog_size = infop->nfree *
roundup(2 * sizeof(struct btt_flog), BTT_FLOG_PAIR_ALIGN);
flog_size = roundup(flog_size, BTT_ALIGNMENT);
uint8_t *buff = malloc(flog_size);
if (!buff)
err(1, "Cannot allocate memory for FLOG entries");
if (pmempool_info_read(pip, buff, flog_size,
arena_off + infop->flogoff)) {
outv_err("cannot read BTT FLOG");
ret = -1;
goto error;
}
outv_title(v, "PMEM BLK BTT FLOG");
uint8_t *ptr = buff;
uint32_t i;
for (i = 0; i < infop->nfree; i++) {
flogp = (struct btt_flog *)ptr;
flogpp = flogp + 1;
btt_flog_convert2h(flogp);
btt_flog_convert2h(flogpp);
outv(v, "%010d:\n", i);
outv_field(v, "LBA", "0x%08x", flogp->lba);
outv_field(v, "Old map", "0x%08x: %s", flogp->old_map,
out_get_btt_map_entry(flogp->old_map));
outv_field(v, "New map", "0x%08x: %s", flogp->new_map,
out_get_btt_map_entry(flogp->new_map));
outv_field(v, "Seq", "0x%x", flogp->seq);
outv_field(v, "LBA'", "0x%08x", flogpp->lba);
outv_field(v, "Old map'", "0x%08x: %s", flogpp->old_map,
out_get_btt_map_entry(flogpp->old_map));
outv_field(v, "New map'", "0x%08x: %s", flogpp->new_map,
out_get_btt_map_entry(flogpp->new_map));
outv_field(v, "Seq'", "0x%x", flogpp->seq);
ptr += BTT_FLOG_PAIR_ALIGN;
}
error:
free(buff);
return ret;
}
/*
* info_btt_stats -- print btt related statistics
*/
static void
info_btt_stats(struct pmem_info *pip, int v)
{
if (pip->blk.stats.total > 0) {
outv_title(v, "PMEM BLK Statistics");
double perc_zeros = (double)pip->blk.stats.zeros /
(double)pip->blk.stats.total * 100.0;
double perc_errors = (double)pip->blk.stats.errors /
(double)pip->blk.stats.total * 100.0;
double perc_noflag = (double)pip->blk.stats.noflag /
(double)pip->blk.stats.total * 100.0;
outv_field(v, "Total blocks", "%u", pip->blk.stats.total);
outv_field(v, "Zeroed blocks", "%u [%s]", pip->blk.stats.zeros,
out_get_percentage(perc_zeros));
outv_field(v, "Error blocks", "%u [%s]", pip->blk.stats.errors,
out_get_percentage(perc_errors));
outv_field(v, "Blocks without flag", "%u [%s]",
pip->blk.stats.noflag,
out_get_percentage(perc_noflag));
}
}
/*
* info_btt_info -- print btt_info structure fields
*/
static int
info_btt_info(struct pmem_info *pip, int v, struct btt_info *infop)
{
outv_field(v, "Signature", "%.*s", BTTINFO_SIG_LEN, infop->sig);
outv_field(v, "UUID of container", "%s",
out_get_uuid_str(infop->parent_uuid));
outv_field(v, "Flags", "0x%x", infop->flags);
outv_field(v, "Major", "%d", infop->major);
outv_field(v, "Minor", "%d", infop->minor);
outv_field(v, "External LBA size", "%s",
out_get_size_str(infop->external_lbasize,
pip->args.human));
outv_field(v, "External LBA count", "%u", infop->external_nlba);
outv_field(v, "Internal LBA size", "%s",
out_get_size_str(infop->internal_lbasize,
pip->args.human));
outv_field(v, "Internal LBA count", "%u", infop->internal_nlba);
outv_field(v, "Free blocks", "%u", infop->nfree);
outv_field(v, "Info block size", "%s",
out_get_size_str(infop->infosize, pip->args.human));
outv_field(v, "Next arena offset", "0x%lx", infop->nextoff);
outv_field(v, "Arena data offset", "0x%lx", infop->dataoff);
outv_field(v, "Area map offset", "0x%lx", infop->mapoff);
outv_field(v, "Area flog offset", "0x%lx", infop->flogoff);
outv_field(v, "Info block backup offset", "0x%lx", infop->infooff);
outv_field(v, "Checksum", "%s", out_get_checksum(infop,
sizeof(*infop), &infop->checksum, 0));
return 0;
}
/*
* info_btt_layout -- print information about BTT layout
*/
static int
info_btt_layout(struct pmem_info *pip, os_off_t btt_off)
{
int ret = 0;
if (btt_off <= 0) {
outv_err("wrong BTT layout offset\n");
return -1;
}
struct btt_info *infop = NULL;
infop = malloc(sizeof(struct btt_info));
if (!infop)
err(1, "Cannot allocate memory for BTT Info structure");
int narena = 0;
uint64_t cur_lba = 0;
uint64_t count_data = 0;
uint64_t count_map = 0;
uint64_t offset = (uint64_t)btt_off;
uint64_t nextoff = 0;
do {
/* read btt info area */
if (pmempool_info_read(pip, infop, sizeof(*infop), offset)) {
ret = -1;
outv_err("cannot read BTT Info header\n");
goto err;
}
if (util_check_memory((uint8_t *)infop,
sizeof(*infop), 0) == 0) {
outv(1, "\n<No BTT layout>\n");
break;
}
outv(1, "\n[ARENA %d]", narena);
outv_title(1, "PMEM BLK BTT Info Header");
outv_hexdump(pip->args.vhdrdump, infop,
sizeof(*infop), offset, 1);
btt_info_convert2h(infop);
nextoff = infop->nextoff;
/* print btt info fields */
if (info_btt_info(pip, 1, infop)) {
ret = -1;
goto err;
}
/* dump blocks data */
if (info_btt_data(pip, pip->args.vdata,
infop, offset, cur_lba, &count_data)) {
ret = -1;
goto err;
}
/* print btt map entries and get statistics */
if (info_btt_map(pip, pip->args.blk.vmap, infop,
offset, cur_lba, &count_map)) {
ret = -1;
goto err;
}
/* print flog entries */
if (info_btt_flog(pip, pip->args.blk.vflog, infop,
offset)) {
ret = -1;
goto err;
}
/* increment LBA's counter before reading info backup */
cur_lba += infop->external_nlba;
/* read btt info backup area */
if (pmempool_info_read(pip, infop, sizeof(*infop),
offset + infop->infooff)) {
outv_err("wrong BTT Info Backup size or offset\n");
ret = -1;
goto err;
}
outv_title(pip->args.blk.vbackup,
"PMEM BLK BTT Info Header Backup");
if (outv_check(pip->args.blk.vbackup))
outv_hexdump(pip->args.vhdrdump, infop,
sizeof(*infop),
offset + infop->infooff, 1);
btt_info_convert2h(infop);
info_btt_info(pip, pip->args.blk.vbackup, infop);
offset += nextoff;
narena++;
} while (nextoff > 0);
info_btt_stats(pip, pip->args.vstats);
err:
if (infop)
free(infop);
return ret;
}
/*
* info_blk_descriptor -- print pmemblk descriptor
*/
static void
info_blk_descriptor(struct pmem_info *pip, int v, struct pmemblk *pbp)
{
size_t pmemblk_size;
#ifdef DEBUG
pmemblk_size = offsetof(struct pmemblk, write_lock);
#else
pmemblk_size = sizeof(*pbp);
#endif
outv_title(v, "PMEM BLK Header");
/* dump pmemblk header without pool_hdr */
outv_hexdump(pip->args.vhdrdump, (uint8_t *)pbp + sizeof(pbp->hdr),
pmemblk_size - sizeof(pbp->hdr), sizeof(pbp->hdr), 1);
outv_field(v, "Block size", "%s",
out_get_size_str(pbp->bsize, pip->args.human));
outv_field(v, "Is zeroed", pbp->is_zeroed ? "true" : "false");
}
/*
* pmempool_info_blk -- print information about block type pool
*/
int
pmempool_info_blk(struct pmem_info *pip)
{
int ret;
struct pmemblk *pbp = malloc(sizeof(struct pmemblk));
if (!pbp)
err(1, "Cannot allocate memory for pmemblk structure");
if (pmempool_info_read(pip, pbp, sizeof(struct pmemblk), 0)) {
outv_err("cannot read pmemblk header\n");
free(pbp);
return -1;
}
info_blk_descriptor(pip, VERBOSE_DEFAULT, pbp);
ssize_t btt_off = (char *)pbp->data - (char *)pbp->addr;
ret = info_btt_layout(pip, btt_off);
free(pbp);
return ret;
}
/*
* pmempool_info_btt -- print information about btt device
*/
int
pmempool_info_btt(struct pmem_info *pip)
{
int ret;
outv(1, "\nBTT Device");
ret = info_btt_layout(pip, DEFAULT_HDR_SIZE);
return ret;
}
| 14,521
| 24.611993
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/create.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* create.h -- pmempool create command header file
*/
int pmempool_create_func(const char *appname, int argc, char *argv[]);
void pmempool_create_help(const char *appname);
| 1,780
| 44.666667
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/pmempool.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmempool.c -- pmempool main source file
*/
#include <stdio.h>
#include <libgen.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <stdbool.h>
#include "common.h"
#include "output.h"
#include "info.h"
#include "create.h"
#include "dump.h"
#include "check.h"
#include "rm.h"
#include "convert.h"
#include "synchronize.h"
#include "transform.h"
#include "feature.h"
#include "set.h"
#ifndef _WIN32
#include "rpmem_common.h"
#include "rpmem_util.h"
#endif
#define APPNAME "pmempool"
/*
* command -- struct for pmempool commands definition
*/
struct command {
const char *name;
const char *brief;
int (*func)(const char *, int, char *[]);
void (*help)(const char *);
};
static const struct command *get_command(const char *cmd_str);
static void print_help(const char *appname);
/*
* long_options -- pmempool command line arguments
*/
static const struct option long_options[] = {
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0 },
};
/*
* help_help -- prints help message for help command
*/
static void
help_help(const char *appname)
{
printf("Usage: %s help <command>\n", appname);
}
/*
* help_func -- prints help message for specified command
*/
static int
help_func(const char *appname, int argc, char *argv[])
{
if (argc > 1) {
char *cmd_str = argv[1];
const struct command *cmdp = get_command(cmd_str);
if (cmdp && cmdp->help) {
cmdp->help(appname);
return 0;
} else {
outv_err("No help text for '%s' command\n", cmd_str);
return -1;
}
} else {
print_help(appname);
return -1;
}
}
/*
* commands -- definition of all pmempool commands
*/
static const struct command commands[] = {
{
.name = "info",
.brief = "print information and statistics about a pool",
.func = pmempool_info_func,
.help = pmempool_info_help,
},
{
.name = "create",
.brief = "create a pool",
.func = pmempool_create_func,
.help = pmempool_create_help,
},
{
.name = "dump",
.brief = "dump user data from a pool",
.func = pmempool_dump_func,
.help = pmempool_dump_help,
},
{
.name = "check",
.brief = "check consistency of a pool",
.func = pmempool_check_func,
.help = pmempool_check_help,
},
{
.name = "rm",
.brief = "remove pool or poolset",
.func = pmempool_rm_func,
.help = pmempool_rm_help,
},
{
.name = "convert",
.brief = "perform pool layout conversion",
.func = pmempool_convert_func,
.help = pmempool_convert_help,
},
{
.name = "sync",
.brief = "synchronize data between replicas",
.func = pmempool_sync_func,
.help = pmempool_sync_help,
},
{
.name = "transform",
.brief = "modify internal structure of a poolset",
.func = pmempool_transform_func,
.help = pmempool_transform_help,
},
{
.name = "feature",
.brief = "toggle / query pool features",
.func = pmempool_feature_func,
.help = pmempool_feature_help,
},
{
.name = "help",
.brief = "print help text about a command",
.func = help_func,
.help = help_help,
},
};
/*
* number of pmempool commands
*/
#define COMMANDS_NUMBER (sizeof(commands) / sizeof(commands[0]))
/*
* print_version -- prints pmempool version message
*/
static void
print_version(const char *appname)
{
printf("%s %s\n", appname, SRCVERSION);
}
/*
* print_usage -- prints pmempool usage message
*/
static void
print_usage(const char *appname)
{
printf("usage: %s [--version] [--help] <command> [<args>]\n", appname);
}
/*
* print_help -- prints pmempool help message
*/
static void
print_help(const char *appname)
{
print_usage(appname);
print_version(appname);
printf("\n");
printf("Options:\n");
printf(" -V, --version display version\n");
printf(" -h, --help display this help and exit\n");
printf("\n");
printf("The available commands are:\n");
unsigned i;
for (i = 0; i < COMMANDS_NUMBER; i++) {
const char *format = (strlen(commands[i].name) / 8)
? "%s\t- %s\n" : "%s\t\t- %s\n";
printf(format, commands[i].name, commands[i].brief);
}
printf("\n");
printf("For complete documentation see %s(1) manual page.\n", appname);
}
/*
* get_command -- returns command for specified command name
*/
static const struct command *
get_command(const char *cmd_str)
{
unsigned i;
for (i = 0; i < COMMANDS_NUMBER; i++) {
if (strcmp(cmd_str, commands[i].name) == 0)
return &commands[i];
}
return NULL;
}
int
main(int argc, char *argv[])
{
int opt;
int option_index;
int ret = 0;
#ifdef _WIN32
wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
for (int i = 0; i < argc; i++) {
argv[i] = util_toUTF8(wargv[i]);
if (argv[i] == NULL) {
for (i--; i >= 0; i--)
free(argv[i]);
outv_err("Error during arguments conversion\n");
return 1;
}
}
#endif
util_init();
#ifndef _WIN32
util_remote_init();
rpmem_util_cmds_init();
#endif
if (argc < 2) {
print_usage(APPNAME);
goto end;
}
while ((opt = getopt_long(2, argv, "Vh",
long_options, &option_index)) != -1) {
switch (opt) {
case 'V':
print_version(APPNAME);
goto end;
case 'h':
print_help(APPNAME);
goto end;
default:
print_usage(APPNAME);
ret = 1;
goto end;
}
}
char *cmd_str = argv[optind];
const struct command *cmdp = get_command(cmd_str);
if (cmdp) {
ret = cmdp->func(APPNAME, argc - 1, argv + 1);
} else {
outv_err("'%s' -- unknown command\n", cmd_str);
ret = 1;
}
#ifndef _WIN32
util_remote_fini();
rpmem_util_cmds_fini();
#endif
end:
#ifdef _WIN32
for (int i = argc; i > 0; i--)
free(argv[i - 1]);
#endif
if (ret)
return 1;
return 0;
}
| 7,204
| 21.728707
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/output.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* output.c -- definitions of output printing related functions
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdint.h>
#include <ctype.h>
#include <err.h>
#include <endian.h>
#include <inttypes.h>
#include <float.h>
#include "feature.h"
#include "common.h"
#include "output.h"
#define _STR(s) #s
#define STR(s) _STR(s)
#define TIME_STR_FMT "%a %b %d %Y %H:%M:%S"
#define UUID_STR_MAX 37
#define HEXDUMP_ROW_WIDTH 16
/*
* 2 chars + space per byte +
* space after 8 bytes and terminating NULL
*/
#define HEXDUMP_ROW_HEX_LEN (HEXDUMP_ROW_WIDTH * 3 + 1 + 1)
/* 1 printable char per byte + terminating NULL */
#define HEXDUMP_ROW_ASCII_LEN (HEXDUMP_ROW_WIDTH + 1)
#define SEPARATOR_CHAR '-'
#define MAX_INDENT 32
#define INDENT_CHAR ' '
static char out_indent_str[MAX_INDENT + 1];
static int out_indent_level;
static int out_vlevel;
static unsigned out_column_width = 20;
static FILE *out_fh;
static const char *out_prefix;
#define STR_MAX 256
/*
* outv_check -- verify verbosity level
*/
int
outv_check(int vlevel)
{
return vlevel && (out_vlevel >= vlevel);
}
/*
* out_set_col_width -- set column width
*
* See: outv_field() function
*/
void
out_set_col_width(unsigned col_width)
{
out_column_width = col_width;
}
/*
* out_set_vlevel -- set verbosity level
*/
void
out_set_vlevel(int vlevel)
{
out_vlevel = vlevel;
if (out_fh == NULL)
out_fh = stdout;
}
/*
* out_set_prefix -- set prefix to output format
*/
void
out_set_prefix(const char *prefix)
{
out_prefix = prefix;
}
/*
* out_set_stream -- set output stream
*/
void
out_set_stream(FILE *stream)
{
out_fh = stream;
memset(out_indent_str, INDENT_CHAR, MAX_INDENT);
}
/*
* outv_err -- print error message
*/
void
outv_err(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
outv_err_vargs(fmt, ap);
va_end(ap);
}
/*
* outv_err_vargs -- print error message
*/
void
outv_err_vargs(const char *fmt, va_list ap)
{
char *_str = strdup(fmt);
if (!_str)
err(1, "strdup");
char *str = _str;
fprintf(stderr, "error: ");
int errstr = str[0] == '!';
if (errstr)
str++;
char *nl = strchr(str, '\n');
if (nl)
*nl = '\0';
vfprintf(stderr, str, ap);
if (errstr)
fprintf(stderr, ": %s", strerror(errno));
fprintf(stderr, "\n");
free(_str);
}
/*
* outv_indent -- change indentation level by factor
*/
void
outv_indent(int vlevel, int i)
{
if (!outv_check(vlevel))
return;
out_indent_str[out_indent_level] = INDENT_CHAR;
out_indent_level += i;
if (out_indent_level < 0)
out_indent_level = 0;
if (out_indent_level > MAX_INDENT)
out_indent_level = MAX_INDENT;
out_indent_str[out_indent_level] = '\0';
}
/*
* _out_prefix -- print prefix if defined
*/
static void
_out_prefix(void)
{
if (out_prefix)
fprintf(out_fh, "%s: ", out_prefix);
}
/*
* _out_indent -- print indent
*/
static void
_out_indent(void)
{
fprintf(out_fh, "%s", out_indent_str);
}
/*
* outv -- print message taking into account verbosity level
*/
void
outv(int vlevel, const char *fmt, ...)
{
va_list ap;
if (!outv_check(vlevel))
return;
_out_prefix();
_out_indent();
va_start(ap, fmt);
vfprintf(out_fh, fmt, ap);
va_end(ap);
}
/*
* outv_nl -- print new line without indentation
*/
void
outv_nl(int vlevel)
{
if (!outv_check(vlevel))
return;
_out_prefix();
fprintf(out_fh, "\n");
}
void
outv_title(int vlevel, const char *fmt, ...)
{
va_list ap;
if (!outv_check(vlevel))
return;
fprintf(out_fh, "\n");
_out_prefix();
_out_indent();
va_start(ap, fmt);
vfprintf(out_fh, fmt, ap);
va_end(ap);
fprintf(out_fh, ":\n");
}
/*
* outv_field -- print field name and value in specified format
*
* Field name will have fixed width which can be changed by
* out_set_column_width() function.
* vlevel - verbosity level
* field - field name
* fmt - format form value
*/
void
outv_field(int vlevel, const char *field, const char *fmt, ...)
{
va_list ap;
if (!outv_check(vlevel))
return;
_out_prefix();
_out_indent();
va_start(ap, fmt);
fprintf(out_fh, "%-*s : ", out_column_width, field);
vfprintf(out_fh, fmt, ap);
fprintf(out_fh, "\n");
va_end(ap);
}
/*
* out_get_percentage -- return percentage string
*/
const char *
out_get_percentage(double perc)
{
static char str_buff[STR_MAX] = {0, };
int ret = 0;
if (perc > 0.0 && perc < 0.0001) {
ret = snprintf(str_buff, STR_MAX, "%e %%", perc);
if (ret < 0)
return "";
} else {
int decimal = 0;
if (perc >= 100.0 || perc < DBL_EPSILON)
decimal = 0;
else
decimal = 6;
ret = snprintf(str_buff, STR_MAX, "%.*f %%", decimal, perc);
if (ret < 0 || ret >= STR_MAX)
return "";
}
return str_buff;
}
/*
* out_get_size_str -- return size string
*
* human - if 1 return size in human-readable format
* if 2 return size in bytes and human-readable format
* otherwise return size in bytes.
*/
const char *
out_get_size_str(uint64_t size, int human)
{
static char str_buff[STR_MAX] = {0, };
char units[] = {
'K', 'M', 'G', 'T', '\0'
};
const int nunits = sizeof(units) / sizeof(units[0]);
int ret = 0;
if (!human) {
ret = snprintf(str_buff, STR_MAX, "%"PRIu64, size);
} else {
int i = -1;
double dsize = (double)size;
uint64_t csize = size;
while (csize >= 1024 && i < nunits) {
csize /= 1024;
dsize /= 1024.0;
i++;
}
if (i >= 0 && i < nunits)
if (human == 1)
ret = snprintf(str_buff, STR_MAX, "%.1f%c",
dsize, units[i]);
else
ret = snprintf(str_buff, STR_MAX, "%.1f%c [%"
PRIu64"]", dsize, units[i], size);
else
ret = snprintf(str_buff, STR_MAX, "%"PRIu64,
size);
}
if (ret < 0 || ret >= STR_MAX)
return "";
return str_buff;
}
/*
* out_get_uuid_str -- returns uuid in human readable format
*/
const char *
out_get_uuid_str(uuid_t uuid)
{
static char uuid_str[UUID_STR_MAX] = {0, };
int ret = util_uuid_to_string(uuid, uuid_str);
if (ret != 0) {
outv(2, "failed to covert uuid to string");
return NULL;
}
return uuid_str;
}
/*
* out_get_time_str -- returns time in human readable format
*/
const char *
out_get_time_str(time_t time)
{
static char str_buff[STR_MAX] = {0, };
struct tm *tm = util_localtime(&time);
if (tm) {
strftime(str_buff, STR_MAX, TIME_STR_FMT, tm);
} else {
int ret = snprintf(str_buff, STR_MAX, "unknown");
if (ret < 0 || ret >= STR_MAX)
return "";
}
return str_buff;
}
/*
* out_get_ascii_str -- get string with printable ASCII dump buffer
*
* Convert non-printable ASCII characters to dot '.'
* See: util_get_printable_ascii() function.
*/
static int
out_get_ascii_str(char *str, size_t str_len, const uint8_t *datap, size_t len)
{
int c = 0;
size_t i;
char pch;
if (str_len < len)
return -1;
for (i = 0; i < len; i++) {
pch = util_get_printable_ascii((char)datap[i]);
int t = snprintf(str + c, str_len - (size_t)c, "%c", pch);
if (t < 0)
return -1;
c += t;
}
return c;
}
/*
* out_get_hex_str -- get string with hexadecimal dump of buffer
*
* Hexadecimal bytes in format %02x, each one followed by space,
* additional space after every 8th byte.
*/
static int
out_get_hex_str(char *str, size_t str_len, const uint8_t *datap, size_t len)
{
int c = 0;
size_t i;
int t;
if (str_len < (3 * len + 1))
return -1;
for (i = 0; i < len; i++) {
/* add space after n*8 byte */
if (i && (i % 8) == 0) {
t = snprintf(str + c, str_len - (size_t)c, " ");
if (t < 0)
return -1;
c += t;
}
t = snprintf(str + c, str_len - (size_t)c, "%02x ", datap[i]);
if (t < 0)
return -1;
c += t;
}
return c;
}
/*
* outv_hexdump -- print buffer in canonical hex+ASCII format
*
* Print offset in hexadecimal,
* sixteen space-separated, two column, hexadecimal bytes,
* followed by the same sixteen bytes converted to printable ASCII characters
* enclosed in '|' characters.
*/
void
outv_hexdump(int vlevel, const void *addr, size_t len, size_t offset, int sep)
{
if (!outv_check(vlevel) || len <= 0)
return;
const uint8_t *datap = (uint8_t *)addr;
uint8_t row_hex_str[HEXDUMP_ROW_HEX_LEN] = {0, };
uint8_t row_ascii_str[HEXDUMP_ROW_ASCII_LEN] = {0, };
size_t curr = 0;
size_t prev = 0;
int repeated = 0;
int n = 0;
while (len) {
size_t curr_len = min(len, HEXDUMP_ROW_WIDTH);
/*
* Check if current row is the same as the previous one
* don't check it for first and last rows.
*/
if (len != curr_len && curr &&
!memcmp(datap + prev, datap + curr, curr_len)) {
if (!repeated) {
/* print star only for the first repeated */
fprintf(out_fh, "*\n");
repeated = 1;
}
} else {
repeated = 0;
/* row with hexadecimal bytes */
int rh = out_get_hex_str((char *)row_hex_str,
HEXDUMP_ROW_HEX_LEN, datap + curr, curr_len);
/* row with printable ascii chars */
int ra = out_get_ascii_str((char *)row_ascii_str,
HEXDUMP_ROW_ASCII_LEN, datap + curr, curr_len);
if (ra && rh)
n = fprintf(out_fh, "%08zx %-*s|%-*s|\n",
curr + offset,
HEXDUMP_ROW_HEX_LEN, row_hex_str,
HEXDUMP_ROW_WIDTH, row_ascii_str);
prev = curr;
}
len -= curr_len;
curr += curr_len;
}
if (sep && n) {
while (--n)
fprintf(out_fh, "%c", SEPARATOR_CHAR);
fprintf(out_fh, "\n");
}
}
/*
* out_get_checksum -- return checksum string with result
*/
const char *
out_get_checksum(void *addr, size_t len, uint64_t *csump, size_t skip_off)
{
static char str_buff[STR_MAX] = {0, };
int ret = 0;
/*
* The memory range can be mapped with PROT_READ, so allocate a new
* buffer for the checksum and calculate there.
*/
void *buf = Malloc(len);
if (buf == NULL) {
ret = snprintf(str_buff, STR_MAX, "failed");
if (ret < 0 || ret >= STR_MAX)
return "";
return str_buff;
}
memcpy(buf, addr, len);
uint64_t *ncsump = (uint64_t *)
((char *)buf + ((char *)csump - (char *)addr));
uint64_t csum = *csump;
/* validate checksum and get correct one */
int valid = util_validate_checksum(buf, len, ncsump, skip_off);
if (valid)
ret = snprintf(str_buff, STR_MAX, "0x%" PRIx64" [OK]",
le64toh(csum));
else
ret = snprintf(str_buff, STR_MAX,
"0x%" PRIx64 " [wrong! should be: 0x%" PRIx64 "]",
le64toh(csum), le64toh(*ncsump));
Free(buf);
if (ret < 0 || ret >= STR_MAX)
return "";
return str_buff;
}
/*
* out_get_btt_map_entry -- return BTT map entry with flags strings
*/
const char *
out_get_btt_map_entry(uint32_t map)
{
static char str_buff[STR_MAX] = {0, };
int is_init = (map & ~BTT_MAP_ENTRY_LBA_MASK) == 0;
int is_zero = (map & ~BTT_MAP_ENTRY_LBA_MASK) ==
BTT_MAP_ENTRY_ZERO;
int is_error = (map & ~BTT_MAP_ENTRY_LBA_MASK) ==
BTT_MAP_ENTRY_ERROR;
int is_normal = (map & ~BTT_MAP_ENTRY_LBA_MASK) ==
BTT_MAP_ENTRY_NORMAL;
uint32_t lba = map & BTT_MAP_ENTRY_LBA_MASK;
int ret = snprintf(str_buff, STR_MAX, "0x%08x state: %s", lba,
is_init ? "init" :
is_zero ? "zero" :
is_error ? "error" :
is_normal ? "normal" : "unknown");
if (ret < 0 || ret >= STR_MAX)
return "";
return str_buff;
}
/*
* out_get_pool_type_str -- get pool type string
*/
const char *
out_get_pool_type_str(pmem_pool_type_t type)
{
switch (type) {
case PMEM_POOL_TYPE_LOG:
return "log";
case PMEM_POOL_TYPE_BLK:
return "blk";
case PMEM_POOL_TYPE_OBJ:
return "obj";
case PMEM_POOL_TYPE_BTT:
return "btt";
case PMEM_POOL_TYPE_CTO:
return "cto";
default:
return "unknown";
}
}
/*
* out_get_pool_signature -- return signature of specified pool type
*/
const char *
out_get_pool_signature(pmem_pool_type_t type)
{
switch (type) {
case PMEM_POOL_TYPE_LOG:
return LOG_HDR_SIG;
case PMEM_POOL_TYPE_BLK:
return BLK_HDR_SIG;
case PMEM_POOL_TYPE_OBJ:
return OBJ_HDR_SIG;
case PMEM_POOL_TYPE_CTO:
return CTO_HDR_SIG;
default:
return NULL;
}
}
/*
* out_get_chunk_type_str -- get chunk type string
*/
const char *
out_get_chunk_type_str(enum chunk_type type)
{
switch (type) {
case CHUNK_TYPE_FOOTER:
return "footer";
case CHUNK_TYPE_FREE:
return "free";
case CHUNK_TYPE_USED:
return "used";
case CHUNK_TYPE_RUN:
return "run";
case CHUNK_TYPE_UNKNOWN:
default:
return "unknown";
}
}
/*
* out_get_chunk_flags -- get names of set flags for chunk header
*/
const char *
out_get_chunk_flags(uint16_t flags)
{
if (flags & CHUNK_FLAG_COMPACT_HEADER)
return "compact header";
else if (flags & CHUNK_FLAG_HEADER_NONE)
return "header none";
return "";
}
/*
* out_get_zone_magic_str -- get zone magic string with additional
* information about correctness of the magic value
*/
const char *
out_get_zone_magic_str(uint32_t magic)
{
static char str_buff[STR_MAX] = {0, };
const char *correct = NULL;
switch (magic) {
case 0:
correct = "uninitialized";
break;
case ZONE_HEADER_MAGIC:
correct = "OK";
break;
default:
correct = "wrong! should be " STR(ZONE_HEADER_MAGIC);
break;
}
int ret = snprintf(str_buff, STR_MAX, "0x%08x [%s]", magic, correct);
if (ret < 0 || ret >= STR_MAX)
return "";
return str_buff;
}
/*
* out_get_pmemoid_str -- get PMEMoid string
*/
const char *
out_get_pmemoid_str(PMEMoid oid, uint64_t uuid_lo)
{
static char str_buff[STR_MAX] = {0, };
int free_cor = 0;
int ret = 0;
char *correct = "OK";
if (oid.pool_uuid_lo && oid.pool_uuid_lo != uuid_lo) {
ret = snprintf(str_buff, STR_MAX,
"wrong! should be 0x%016"PRIx64, uuid_lo);
if (ret < 0 || ret >= STR_MAX)
err(1, "snprintf: %d", ret);
correct = strdup(str_buff);
if (!correct)
err(1, "Cannot allocate memory for PMEMoid string\n");
free_cor = 1;
}
ret = snprintf(str_buff, STR_MAX,
"off: 0x%016"PRIx64" pool_uuid_lo: 0x%016"
PRIx64" [%s]", oid.off, oid.pool_uuid_lo, correct);
if (free_cor)
free(correct);
if (ret < 0 || ret >= STR_MAX)
err(1, "snprintf: %d", ret);
return str_buff;
}
/*
* out_get_arch_machine_class_str -- get a string representation of the machine
* class
*/
const char *
out_get_arch_machine_class_str(uint8_t machine_class)
{
switch (machine_class) {
case PMDK_MACHINE_CLASS_64:
return "64";
default:
return "unknown";
}
}
/*
* out_get_arch_data_str -- get a string representation of the data endianness
*/
const char *
out_get_arch_data_str(uint8_t data)
{
switch (data) {
case PMDK_DATA_LE:
return "2's complement, little endian";
case PMDK_DATA_BE:
return "2's complement, big endian";
default:
return "unknown";
}
}
/*
* out_get_arch_machine_str -- get a string representation of the machine type
*/
const char *
out_get_arch_machine_str(uint16_t machine)
{
static char str_buff[STR_MAX] = {0, };
switch (machine) {
case PMDK_MACHINE_X86_64:
return "AMD X86-64";
case PMDK_MACHINE_AARCH64:
return "Aarch64";
default:
break;
}
int ret = snprintf(str_buff, STR_MAX, "unknown %u", machine);
if (ret < 0 || ret >= STR_MAX)
return "unknown";
return str_buff;
}
/*
* out_get_last_shutdown_str -- get a string representation of the finish state
*/
const char *
out_get_last_shutdown_str(uint8_t dirty)
{
if (dirty)
return "dirty";
else
return "clean";
}
/*
* out_get_alignment_descr_str -- get alignment descriptor string
*/
const char *
out_get_alignment_desc_str(uint64_t ad, uint64_t valid_ad)
{
static char str_buff[STR_MAX] = {0, };
int ret = 0;
if (ad == valid_ad)
ret = snprintf(str_buff, STR_MAX, "0x%016"PRIx64"[OK]", ad);
else
ret = snprintf(str_buff, STR_MAX, "0x%016"PRIx64" "
"[wrong! should be 0x%016"PRIx64"]", ad, valid_ad);
if (ret < 0 || ret >= STR_MAX)
return "";
return str_buff;
}
/*
* out_concat -- concatenate the new element to the list of strings
*
* If concatenation is successful it increments current position in the output
* string and number of elements in the list. Elements are separated with ", ".
*/
static int
out_concat(char *str_buff, int *curr, int *count, const char *str)
{
ASSERTne(str_buff, NULL);
ASSERTne(curr, NULL);
ASSERTne(str, NULL);
const char *separator = (count != NULL && *count > 0) ? ", " : "";
int ret = snprintf(str_buff + *curr,
(size_t)(STR_MAX - *curr), "%s%s", separator, str);
if (ret < 0 || *curr + ret >= STR_MAX)
return -1;
*curr += ret;
if (count)
++(*count);
return 0;
}
/*
* out_get_incompat_features_str -- (internal) get a string with names of
* incompatibility flags
*/
const char *
out_get_incompat_features_str(uint32_t incompat)
{
static char str_buff[STR_MAX] = {0};
features_t features = {POOL_FEAT_ZERO, incompat, POOL_FEAT_ZERO};
int ret = 0;
if (incompat == 0) {
/* print the value only */
return "0x0";
} else {
/* print the value and the left square bracket */
ret = snprintf(str_buff, STR_MAX, "0x%x [", incompat);
if (ret < 0 || ret >= STR_MAX) {
ERR("snprintf for incompat features: %d", ret);
return "<error>";
}
/* print names of known options */
int count = 0;
int curr = ret;
features_t found;
const char *feat;
while (((feat = util_feature2str(features, &found))) != NULL) {
util_feature_disable(&features, found);
ret = out_concat(str_buff, &curr, &count, feat);
if (ret < 0)
return "";
}
/* check if any unknown flags are set */
if (!util_feature_is_zero(features)) {
if (out_concat(str_buff, &curr, &count,
"?UNKNOWN_FLAG?"))
return "";
}
/* print the right square bracket */
if (out_concat(str_buff, &curr, NULL, "]"))
return "";
}
return str_buff;
}
| 18,971
| 20.292929
| 79
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/dump.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* dump.h -- pmempool dump command header file
*/
int pmempool_dump_func(const char *appname, int argc, char *argv[]);
void pmempool_dump_help(const char *appname);
| 1,772
| 44.461538
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/rm.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rm.h -- pmempool rm command header file
*/
void pmempool_rm_help(const char *appname);
int pmempool_rm_func(const char *appname, int argc, char *argv[]);
| 1,764
| 44.25641
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/feature.h
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* feature.h -- pmempool feature command header file
*/
int pmempool_feature_func(const char *appname, int argc, char *argv[]);
void pmempool_feature_help(const char *appname);
| 1,779
| 44.641026
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/feature.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* feature.c -- pmempool feature command source file
*/
#include <getopt.h>
#include <stdlib.h>
#include "common.h"
#include "feature.h"
#include "output.h"
#include "libpmempool.h"
/* operations over features */
enum feature_op {
undefined,
enable,
disable,
query
};
/*
* feature_ctx -- context and arguments for feature command
*/
struct feature_ctx {
int verbose;
const char *fname;
enum feature_op op;
enum pmempool_feature feature;
unsigned flags;
};
/*
* pmempool_feature_default -- default arguments for feature command
*/
static const struct feature_ctx pmempool_feature_default = {
.verbose = 0,
.fname = NULL,
.op = undefined,
.feature = UINT32_MAX,
.flags = 0
};
/*
* help_str -- string for help message
*/
static const char * const help_str =
"Toggle or query a pool feature\n"
"\n"
"For complete documentation see %s-feature(1) manual page.\n"
;
/*
* long_options -- command line options
*/
static const struct option long_options[] = {
{"enable", required_argument, NULL, 'e'},
{"disable", required_argument, NULL, 'd'},
{"query", required_argument, NULL, 'q'},
{"verbose", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0 },
};
/*
* print_usage -- print short description of application's usage
*/
static void
print_usage(const char *appname)
{
printf("Usage: %s feature [<args>] <file>\n", appname);
printf(
"feature: SINGLEHDR, CKSUM_2K, SHUTDOWN_STATE, CHECK_BAD_BLOCKS\n");
}
/*
* print_version -- print version string
*/
static void
print_version(const char *appname)
{
printf("%s %s\n", appname, SRCVERSION);
}
/*
* pmempool_feature_help -- print help message for feature command
*/
void
pmempool_feature_help(const char *appname)
{
print_usage(appname);
print_version(appname);
printf(help_str, appname);
}
/*
* feature_perform -- perform operation over function
*/
static int
feature_perform(struct feature_ctx *pfp)
{
int ret;
switch (pfp->op) {
case enable:
return pmempool_feature_enable(pfp->fname, pfp->feature,
pfp->flags);
case disable:
return pmempool_feature_disable(pfp->fname, pfp->feature,
pfp->flags);
case query:
ret = pmempool_feature_query(pfp->fname, pfp->feature,
pfp->flags);
if (ret < 0)
return 1;
printf("%d", ret);
return 0;
default:
ERR("Invalid option.");
return -1;
}
}
/*
* set_op -- set operation
*/
static void
set_op(const char *appname, struct feature_ctx *pfp, enum feature_op op,
const char *feature)
{
/* only one operation allowed */
if (pfp->op != undefined)
goto misuse;
pfp->op = op;
/* parse feature name */
uint32_t fval = util_str2pmempool_feature(feature);
if (fval == UINT32_MAX)
goto misuse;
pfp->feature = (enum pmempool_feature)fval;
return;
misuse:
print_usage(appname);
exit(EXIT_FAILURE);
}
/*
* parse_args -- parse command line arguments
*/
static int
parse_args(struct feature_ctx *pfp, const char *appname,
int argc, char *argv[])
{
int opt;
while ((opt = getopt_long(argc, argv, "vhe:d:q:h",
long_options, NULL)) != -1) {
switch (opt) {
case 'e':
set_op(appname, pfp, enable, optarg);
break;
case 'd':
set_op(appname, pfp, disable, optarg);
break;
case 'q':
set_op(appname, pfp, query, optarg);
break;
case 'v':
pfp->verbose = 2;
break;
case 'h':
pmempool_feature_help(appname);
exit(EXIT_SUCCESS);
default:
print_usage(appname);
exit(EXIT_FAILURE);
}
}
if (optind >= argc) {
print_usage(appname);
exit(EXIT_FAILURE);
}
pfp->fname = argv[optind];
return 0;
}
/*
* pmempool_feature_func -- main function for feature command
*/
int
pmempool_feature_func(const char *appname, int argc, char *argv[])
{
struct feature_ctx pf = pmempool_feature_default;
int ret = 0;
/* parse command line arguments */
ret = parse_args(&pf, appname, argc, argv);
if (ret)
return ret;
/* set verbosity level */
out_set_vlevel(pf.verbose);
return feature_perform(&pf);
}
| 5,562
| 22.472574
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/check.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* check.c -- pmempool check command source file
*/
#include <getopt.h>
#include <stdlib.h>
#include "common.h"
#include "check.h"
#include "output.h"
#include "set.h"
#include "file.h"
#include "libpmempool.h"
typedef enum
{
CHECK_RESULT_CONSISTENT,
CHECK_RESULT_NOT_CONSISTENT,
CHECK_RESULT_REPAIRED,
CHECK_RESULT_CANNOT_REPAIR,
CHECK_RESULT_SYNC_REQ,
CHECK_RESULT_ERROR
} check_result_t;
/*
* pmempool_check_context -- context and arguments for check command
*/
struct pmempool_check_context {
int verbose; /* verbosity level */
char *fname; /* file name */
struct pool_set_file *pfile;
bool repair; /* do repair */
bool backup; /* do backup */
bool advanced; /* do advanced repairs */
char *backup_fname; /* backup file name */
bool exec; /* do execute */
char ans; /* default answer on all questions or '?' */
};
/*
* pmempool_check_default -- default arguments for check command
*/
static const struct pmempool_check_context pmempool_check_default = {
.verbose = 1,
.fname = NULL,
.repair = false,
.backup = false,
.backup_fname = NULL,
.advanced = false,
.exec = true,
.ans = '?',
};
/*
* help_str -- string for help message
*/
static const char * const help_str =
"Check consistency of a pool\n"
"\n"
"Common options:\n"
" -r, --repair try to repair a pool file if possible\n"
" -y, --yes answer yes to all questions\n"
" -N, --no-exec don't execute, just show what would be done\n"
" -b, --backup <file> create backup of a pool file before executing\n"
" -a, --advanced perform advanced repairs\n"
" -q, --quiet be quiet and don't print any messages\n"
" -v, --verbose increase verbosity level\n"
" -h, --help display this help and exit\n"
"\n"
"For complete documentation see %s-check(1) manual page.\n"
;
/*
* long_options -- command line options
*/
static const struct option long_options[] = {
{"repair", no_argument, NULL, 'r'},
{"yes", no_argument, NULL, 'y'},
{"no-exec", no_argument, NULL, 'N'},
{"backup", required_argument, NULL, 'b'},
{"advanced", no_argument, NULL, 'a'},
{"quiet", no_argument, NULL, 'q'},
{"verbose", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0 },
};
/*
* print_usage -- print short description of application's usage
*/
static void
print_usage(const char *appname)
{
printf("Usage: %s check [<args>] <file>\n", appname);
}
/*
* print_version -- print version string
*/
static void
print_version(const char *appname)
{
printf("%s %s\n", appname, SRCVERSION);
}
/*
* pmempool_check_help -- print help message for check command
*/
void
pmempool_check_help(const char *appname)
{
print_usage(appname);
print_version(appname);
printf(help_str, appname);
}
/*
* pmempool_check_parse_args -- parse command line arguments
*/
static int
pmempool_check_parse_args(struct pmempool_check_context *pcp,
const char *appname, int argc, char *argv[])
{
int opt;
while ((opt = getopt_long(argc, argv, "ahvrNb:qy",
long_options, NULL)) != -1) {
switch (opt) {
case 'r':
pcp->repair = true;
break;
case 'y':
pcp->ans = 'y';
break;
case 'N':
pcp->exec = false;
break;
case 'b':
pcp->backup = true;
pcp->backup_fname = optarg;
break;
case 'a':
pcp->advanced = true;
break;
case 'q':
pcp->verbose = 0;
break;
case 'v':
pcp->verbose = 2;
break;
case 'h':
pmempool_check_help(appname);
exit(EXIT_SUCCESS);
default:
print_usage(appname);
exit(EXIT_FAILURE);
}
}
if (optind < argc) {
pcp->fname = argv[optind];
} else {
print_usage(appname);
exit(EXIT_FAILURE);
}
if (!pcp->repair && !pcp->exec) {
outv_err("'-N' option requires '-r'\n");
exit(EXIT_FAILURE);
}
if (!pcp->repair && pcp->backup) {
outv_err("'-b' option requires '-r'\n");
exit(EXIT_FAILURE);
}
return 0;
}
static check_result_t pmempool_check_2_check_res_t[] =
{
[PMEMPOOL_CHECK_RESULT_CONSISTENT] = CHECK_RESULT_CONSISTENT,
[PMEMPOOL_CHECK_RESULT_NOT_CONSISTENT] = CHECK_RESULT_NOT_CONSISTENT,
[PMEMPOOL_CHECK_RESULT_REPAIRED] = CHECK_RESULT_REPAIRED,
[PMEMPOOL_CHECK_RESULT_CANNOT_REPAIR] = CHECK_RESULT_CANNOT_REPAIR,
[PMEMPOOL_CHECK_RESULT_SYNC_REQ] = CHECK_RESULT_SYNC_REQ,
[PMEMPOOL_CHECK_RESULT_ERROR] = CHECK_RESULT_ERROR,
};
static const char *
check_ask(const char *msg)
{
char answer = ask_Yn('?', "%s", msg);
switch (answer) {
case 'y':
return "yes";
case 'n':
return "no";
default:
return "?";
}
}
static check_result_t
pmempool_check_perform(struct pmempool_check_context *pc)
{
struct pmempool_check_args args = {
.path = pc->fname,
.backup_path = pc->backup_fname,
.pool_type = PMEMPOOL_POOL_TYPE_DETECT,
.flags = PMEMPOOL_CHECK_FORMAT_STR
};
if (pc->repair)
args.flags |= PMEMPOOL_CHECK_REPAIR;
if (!pc->exec)
args.flags |= PMEMPOOL_CHECK_DRY_RUN;
if (pc->advanced)
args.flags |= PMEMPOOL_CHECK_ADVANCED;
if (pc->ans == 'y')
args.flags |= PMEMPOOL_CHECK_ALWAYS_YES;
if (pc->verbose == 2)
args.flags |= PMEMPOOL_CHECK_VERBOSE;
PMEMpoolcheck *ppc = pmempool_check_init(&args, sizeof(args));
if (ppc == NULL)
return CHECK_RESULT_ERROR;
struct pmempool_check_status *status = NULL;
while ((status = pmempool_check(ppc)) != NULL) {
switch (status->type) {
case PMEMPOOL_CHECK_MSG_TYPE_ERROR:
outv(1, "%s\n", status->str.msg);
break;
case PMEMPOOL_CHECK_MSG_TYPE_INFO:
outv(2, "%s\n", status->str.msg);
break;
case PMEMPOOL_CHECK_MSG_TYPE_QUESTION:
status->str.answer = check_ask(status->str.msg);
break;
default:
pmempool_check_end(ppc);
exit(EXIT_FAILURE);
}
}
enum pmempool_check_result ret = pmempool_check_end(ppc);
return pmempool_check_2_check_res_t[ret];
}
/*
* pmempool_check_func -- main function for check command
*/
int
pmempool_check_func(const char *appname, int argc, char *argv[])
{
int ret = 0;
check_result_t res = CHECK_RESULT_CONSISTENT;
struct pmempool_check_context pc = pmempool_check_default;
/* parse command line arguments */
ret = pmempool_check_parse_args(&pc, appname, argc, argv);
if (ret)
return ret;
/* set verbosity level */
out_set_vlevel(pc.verbose);
res = pmempool_check_perform(&pc);
switch (res) {
case CHECK_RESULT_CONSISTENT:
outv(2, "%s: consistent\n", pc.fname);
ret = 0;
break;
case CHECK_RESULT_NOT_CONSISTENT:
outv(1, "%s: not consistent\n", pc.fname);
ret = -1;
break;
case CHECK_RESULT_REPAIRED:
outv(1, "%s: repaired\n", pc.fname);
ret = 0;
break;
case CHECK_RESULT_CANNOT_REPAIR:
outv(1, "%s: cannot repair\n", pc.fname);
ret = -1;
break;
case CHECK_RESULT_SYNC_REQ:
outv(1, "%s: sync required\n", pc.fname);
ret = 0;
break;
case CHECK_RESULT_ERROR:
if (errno)
outv_err("%s\n", strerror(errno));
if (pc.repair)
outv_err("repairing failed\n");
else
outv_err("checking consistency failed\n");
ret = -1;
break;
default:
outv_err("status unknown\n");
ret = -1;
break;
}
return ret;
}
| 8,609
| 24.102041
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/convert.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* convert.h -- pmempool convert command header file
*/
#include <sys/types.h>
int pmempool_convert_func(const char *appname, int argc, char *argv[]);
void pmempool_convert_help(const char *appname);
| 1,808
| 43.121951
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/rm.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* rm.c -- pmempool rm command main source file
*/
#include <stdlib.h>
#include <getopt.h>
#include <unistd.h>
#include <err.h>
#include <stdio.h>
#include <fcntl.h>
#include "os.h"
#include "out.h"
#include "common.h"
#include "output.h"
#include "file.h"
#include "rm.h"
#include "set.h"
#ifdef USE_RPMEM
#include "librpmem.h"
#endif
enum ask_type {
ASK_SOMETIMES, /* ask before removing write-protected files */
ASK_ALWAYS, /* always ask */
ASK_NEVER, /* never ask */
};
/* verbosity level */
static int vlevel;
/* force remove and ignore errors */
static int force;
/* poolset files options */
#define RM_POOLSET_NONE (0)
#define RM_POOLSET_LOCAL (1 << 0)
#define RM_POOLSET_REMOTE (1 << 1)
#define RM_POOLSET_ALL (RM_POOLSET_LOCAL | RM_POOLSET_REMOTE)
static int rm_poolset_mode;
/* mode of interaction */
static enum ask_type ask_mode;
/* indicates whether librpmem is available */
static int rpmem_avail;
/* help message */
static const char * const help_str =
"Remove pool file or all files from poolset\n"
"\n"
"Available options:\n"
" -h, --help Print this help message.\n"
" -v, --verbose Be verbose.\n"
" -s, --only-pools Remove only pool files (default).\n"
" -a, --all Remove all poolset files - local and remote.\n"
" -l, --local Remove local poolset files\n"
" -r, --remote Remove remote poolset files\n"
" -f, --force Ignore nonexisting files.\n"
" -i, --interactive Prompt before every single removal.\n"
"\n"
"For complete documentation see %s-rm(1) manual page.\n";
/* short options string */
static const char *optstr = "hvsfialr";
/* long options */
static const struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"verbose", no_argument, NULL, 'v'},
{"only-pools", no_argument, NULL, 's'},
{"all", no_argument, NULL, 'a'},
{"local", no_argument, NULL, 'l'},
{"remote", no_argument, NULL, 'r'},
{"force", no_argument, NULL, 'f'},
{"interactive", no_argument, NULL, 'i'},
{NULL, 0, NULL, 0 },
};
/*
* print_usage -- print usage message
*/
static void
print_usage(const char *appname)
{
printf("Usage: %s rm [<args>] <files>\n", appname);
}
/*
* pmempool_rm_help -- print help message
*/
void
pmempool_rm_help(const char *appname)
{
print_usage(appname);
printf(help_str, appname);
}
/*
* rm_file -- remove single file
*/
static int
rm_file(const char *file)
{
int write_protected = os_access(file, W_OK) != 0;
char cask = 'y';
switch (ask_mode) {
case ASK_ALWAYS:
cask = '?';
break;
case ASK_NEVER:
cask = 'y';
break;
case ASK_SOMETIMES:
cask = write_protected ? '?' : 'y';
break;
default:
outv_err("unknown state");
return 1;
}
const char *pre_msg = write_protected ? "write-protected " : "";
char ans = ask_Yn(cask, "remove %sfile '%s' ?", pre_msg, file);
if (ans == INV_ANS)
outv(1, "invalid answer\n");
if (ans == 'y') {
if (util_unlink(file)) {
outv_err("cannot remove file '%s'", file);
return 1;
}
outv(1, "removed '%s'\n", file);
}
return 0;
}
/*
* remove_remote -- (internal) remove remote pool
*/
static int
remove_remote(const char *target, const char *pool_set)
{
#ifdef USE_RPMEM
char cask = 'y';
switch (ask_mode) {
case ASK_ALWAYS:
cask = '?';
break;
case ASK_NEVER:
case ASK_SOMETIMES:
cask = 'y';
break;
default:
outv_err("unknown state");
return 1;
}
char ans = ask_Yn(cask, "remove remote pool '%s' on '%s'?",
pool_set, target);
if (ans == INV_ANS)
outv(1, "invalid answer\n");
if (ans != 'y')
return 0;
if (!rpmem_avail) {
if (force) {
outv(1, "cannot remove '%s' on '%s' -- "
"librpmem not available", pool_set, target);
return 0;
}
outv_err("!cannot remove '%s' on '%s' -- "
"librpmem not available", pool_set, target);
return 1;
}
int flags = 0;
if (rm_poolset_mode & RM_POOLSET_REMOTE)
flags |= RPMEM_REMOVE_POOL_SET;
if (force)
flags |= RPMEM_REMOVE_FORCE;
int ret = Rpmem_remove(target, pool_set, flags);
if (ret) {
if (force) {
ret = 0;
outv(1, "cannot remove '%s' on '%s'",
pool_set, target);
} else {
/*
* Callback cannot return < 0 value because it
* is interpretted as error in parsing poolset file.
*/
ret = 1;
outv_err("!cannot remove '%s' on '%s'",
pool_set, target);
}
} else {
outv(1, "removed '%s' on '%s'\n",
pool_set, target);
}
return ret;
#else
outv_err("remote replication not supported");
return 1;
#endif
}
/*
* rm_poolset_cb -- (internal) callback for removing replicas
*/
static int
rm_poolset_cb(struct part_file *pf, void *arg)
{
int *error = (int *)arg;
int ret;
if (pf->is_remote) {
ret = remove_remote(pf->remote->node_addr,
pf->remote->pool_desc);
} else {
const char *part_file = pf->part->path;
outv(2, "part file : %s\n", part_file);
int exists = util_file_exists(part_file);
if (exists < 0)
ret = 1;
else if (!exists) {
/*
* Ignore not accessible file if force
* flag is set.
*/
if (force)
return 0;
ret = 1;
outv_err("!cannot remove file '%s'", part_file);
} else {
ret = rm_file(part_file);
}
}
if (ret)
*error = ret;
return 0;
}
/*
* rm_poolset -- remove files parsed from poolset file
*/
static int
rm_poolset(const char *file)
{
int error = 0;
int ret = util_poolset_foreach_part(file, rm_poolset_cb, &error);
if (ret == -1) {
outv_err("parsing poolset failed: %s\n",
out_get_errormsg());
return ret;
}
if (error && !force) {
outv_err("!removing '%s' failed\n", file);
return error;
}
return 0;
}
/*
* pmempool_rm_func -- main function for rm command
*/
int
pmempool_rm_func(const char *appname, int argc, char *argv[])
{
/* by default do not remove any poolset files */
rm_poolset_mode = RM_POOLSET_NONE;
int opt;
while ((opt = getopt_long(argc, argv, optstr,
long_options, NULL)) != -1) {
switch (opt) {
case 'h':
pmempool_rm_help(appname);
return 0;
case 'v':
vlevel++;
break;
case 's':
rm_poolset_mode = RM_POOLSET_NONE;
break;
case 'a':
rm_poolset_mode |= RM_POOLSET_ALL;
break;
case 'l':
rm_poolset_mode |= RM_POOLSET_LOCAL;
break;
case 'r':
rm_poolset_mode |= RM_POOLSET_REMOTE;
break;
case 'f':
force = 1;
ask_mode = ASK_NEVER;
break;
case 'i':
ask_mode = ASK_ALWAYS;
break;
default:
print_usage(appname);
return 1;
}
}
out_set_vlevel(vlevel);
if (optind == argc) {
print_usage(appname);
return 1;
}
#ifdef USE_RPMEM
/*
* Try to load librpmem, if loading failed -
* assume it is not available.
*/
util_remote_init();
rpmem_avail = !util_remote_load();
#endif
int lret = 0;
for (int i = optind; i < argc; i++) {
char *file = argv[i];
/* check if file exists and we can read it */
int exists = os_access(file, F_OK | R_OK) == 0;
if (!exists) {
/* ignore not accessible file if force flag is set */
if (force)
continue;
outv_err("!cannot remove '%s'", file);
lret = 1;
continue;
}
int is_poolset = util_is_poolset_file(file);
if (is_poolset < 0) {
outv(1, "%s: cannot determine type of file", file);
if (force)
continue;
}
if (is_poolset)
outv(2, "poolset file: %s\n", file);
else
outv(2, "pool file : %s\n", file);
int ret;
if (is_poolset) {
ret = rm_poolset(file);
if (!ret && (rm_poolset_mode & RM_POOLSET_LOCAL))
ret = rm_file(file);
} else {
ret = rm_file(file);
}
if (ret)
lret = ret;
}
return lret;
}
| 9,106
| 21.48642
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/synchronize.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* synchronize.h -- pmempool sync command header file
*/
int pmempool_sync_func(const char *appname, int argc, char *argv[]);
void pmempool_sync_help(const char *appname);
| 1,779
| 44.641026
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/common.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* common.h -- declarations of common functions
*/
#include <stdint.h>
#include <stddef.h>
#include <stdarg.h>
#include <stdbool.h>
#include "queue.h"
#include "log.h"
#include "blk.h"
#include "libpmemobj.h"
#include "libpmemcto.h"
#include "cto.h"
#include "lane.h"
#include "ulog.h"
#include "memops.h"
#include "pmalloc.h"
#include "list.h"
#include "obj.h"
#include "memblock.h"
#include "heap_layout.h"
#include "tx.h"
#include "heap.h"
#include "btt_layout.h"
/* XXX - modify Linux makefiles to generate srcversion.h and remove #ifdef */
#ifdef _WIN32
#include "srcversion.h"
#endif
#define COUNT_OF(x) (sizeof(x) / sizeof(0[x]))
#define OPT_SHIFT 12
#define OPT_MASK (~((1 << OPT_SHIFT) - 1))
#define OPT_LOG (1 << (PMEM_POOL_TYPE_LOG + OPT_SHIFT))
#define OPT_BLK (1 << (PMEM_POOL_TYPE_BLK + OPT_SHIFT))
#define OPT_OBJ (1 << (PMEM_POOL_TYPE_OBJ + OPT_SHIFT))
#define OPT_BTT (1 << (PMEM_POOL_TYPE_BTT + OPT_SHIFT))
#define OPT_CTO (1 << (PMEM_POOL_TYPE_CTO + OPT_SHIFT))
#define OPT_ALL (OPT_LOG | OPT_BLK | OPT_OBJ | OPT_BTT | OPT_CTO)
#define OPT_REQ_SHIFT 8
#define OPT_REQ_MASK ((1 << OPT_REQ_SHIFT) - 1)
#define _OPT_REQ(c, n) ((c) << (OPT_REQ_SHIFT * (n)))
#define OPT_REQ0(c) _OPT_REQ(c, 0)
#define OPT_REQ1(c) _OPT_REQ(c, 1)
#define OPT_REQ2(c) _OPT_REQ(c, 2)
#define OPT_REQ3(c) _OPT_REQ(c, 3)
#define OPT_REQ4(c) _OPT_REQ(c, 4)
#define OPT_REQ5(c) _OPT_REQ(c, 5)
#define OPT_REQ6(c) _OPT_REQ(c, 6)
#define OPT_REQ7(c) _OPT_REQ(c, 7)
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
#define FOREACH_RANGE(range, ranges)\
LIST_FOREACH(range, &(ranges)->head, next)
#define PLIST_OFF_TO_PTR(pop, off)\
((off) == 0 ? NULL : (void *)((uintptr_t)(pop) + (off) - OBJ_OOB_SIZE))
#define ENTRY_TO_ALLOC_HDR(entry)\
((void *)((uintptr_t)(entry) - sizeof(struct allocation_header)))
#define OBJH_FROM_PTR(ptr)\
((void *)((uintptr_t)(ptr) - sizeof(struct legacy_object_header)))
#define DEFAULT_HDR_SIZE 4096UL /* 4 KB */
#define DEFAULT_DESC_SIZE 4096UL /* 4 KB */
#define POOL_HDR_DESC_SIZE (DEFAULT_HDR_SIZE + DEFAULT_DESC_SIZE)
#define PTR_TO_ALLOC_HDR(ptr)\
((void *)((uintptr_t)(ptr) -\
sizeof(struct legacy_object_header)))
#define OBJH_TO_PTR(objh)\
((void *)((uintptr_t)(objh) + sizeof(struct legacy_object_header)))
/* invalid answer for ask_* functions */
#define INV_ANS '\0'
#define FORMAT_PRINTF(a, b) __attribute__((__format__(__printf__, (a), (b))))
/*
* pmem_pool_type_t -- pool types
*/
typedef enum {
PMEM_POOL_TYPE_LOG = 0x01,
PMEM_POOL_TYPE_BLK = 0x02,
PMEM_POOL_TYPE_OBJ = 0x04,
PMEM_POOL_TYPE_BTT = 0x08,
PMEM_POOL_TYPE_CTO = 0x10,
PMEM_POOL_TYPE_ALL = 0x1f,
PMEM_POOL_TYPE_UNKNOWN = 0x80,
} pmem_pool_type_t;
struct option_requirement {
int opt;
pmem_pool_type_t type;
uint64_t req;
};
struct options {
const struct option *opts;
size_t noptions;
char *bitmap;
const struct option_requirement *req;
};
struct pmem_pool_params {
pmem_pool_type_t type;
char signature[POOL_HDR_SIG_LEN];
uint64_t size;
mode_t mode;
int is_poolset;
int is_part;
int is_checksum_ok;
union {
struct {
uint64_t bsize;
} blk;
struct {
char layout[PMEMOBJ_MAX_LAYOUT];
} obj;
struct {
char layout[PMEMCTO_MAX_LAYOUT];
} cto;
};
};
struct pool_set_file {
int fd;
char *fname;
void *addr;
size_t size;
struct pool_set *poolset;
size_t replica;
time_t mtime;
mode_t mode;
bool fileio;
};
struct pool_set_file *pool_set_file_open(const char *fname,
int rdonly, int check);
void pool_set_file_close(struct pool_set_file *file);
int pool_set_file_read(struct pool_set_file *file, void *buff,
size_t nbytes, uint64_t off);
int pool_set_file_write(struct pool_set_file *file, void *buff,
size_t nbytes, uint64_t off);
int pool_set_file_set_replica(struct pool_set_file *file, size_t replica);
size_t pool_set_file_nreplicas(struct pool_set_file *file);
void *pool_set_file_map(struct pool_set_file *file, uint64_t offset);
void pool_set_file_persist(struct pool_set_file *file,
const void *addr, size_t len);
struct range {
LIST_ENTRY(range) next;
uint64_t first;
uint64_t last;
};
struct ranges {
LIST_HEAD(rangeshead, range) head;
};
pmem_pool_type_t pmem_pool_type_parse_hdr(const struct pool_hdr *hdrp);
pmem_pool_type_t pmem_pool_type(const void *base_pool_addr);
int pmem_pool_checksum(const void *base_pool_addr);
pmem_pool_type_t pmem_pool_type_parse_str(const char *str);
uint64_t pmem_pool_get_min_size(pmem_pool_type_t type);
int pmem_pool_parse_params(const char *fname, struct pmem_pool_params *paramsp,
int check);
int util_poolset_map(const char *fname, struct pool_set **poolset, int rdonly);
struct options *util_options_alloc(const struct option *options,
size_t nopts, const struct option_requirement *req);
void util_options_free(struct options *opts);
int util_options_verify(const struct options *opts, pmem_pool_type_t type);
int util_options_getopt(int argc, char *argv[], const char *optstr,
const struct options *opts);
int util_validate_checksum(void *addr, size_t len, uint64_t *csum,
uint64_t skip_off);
pmem_pool_type_t util_get_pool_type_second_page(const void *pool_base_addr);
int util_parse_mode(const char *str, mode_t *mode);
int util_parse_ranges(const char *str, struct ranges *rangesp,
struct range entire);
int util_ranges_add(struct ranges *rangesp, struct range range);
void util_ranges_clear(struct ranges *rangesp);
int util_ranges_contain(const struct ranges *rangesp, uint64_t n);
int util_ranges_empty(const struct ranges *rangesp);
int util_check_memory(const uint8_t *buff, size_t len, uint8_t val);
int util_parse_chunk_types(const char *str, uint64_t *types);
int util_parse_lane_sections(const char *str, uint64_t *types);
char ask(char op, char *answers, char def_ans, const char *fmt, va_list ap);
char ask_yn(char op, char def_ans, const char *fmt, va_list ap);
char ask_Yn(char op, const char *fmt, ...) FORMAT_PRINTF(2, 3);
char ask_yN(char op, const char *fmt, ...) FORMAT_PRINTF(2, 3);
unsigned util_heap_max_zone(size_t size);
int util_pool_clear_badblocks(const char *path, int create);
static const struct range ENTIRE_UINT64 = {
{ NULL, NULL }, /* range */
0, /* first */
UINT64_MAX /* last */
};
| 7,787
| 31.181818
| 79
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/info_log.c
|
/*
* Copyright 2014-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* info_log.c -- pmempool info command source file for log pool
*/
#include <stdbool.h>
#include <stdlib.h>
#include <err.h>
#include <sys/mman.h>
#include "common.h"
#include "output.h"
#include "info.h"
/*
* info_log_data -- print used data from log pool
*/
static int
info_log_data(struct pmem_info *pip, int v, struct pmemlog *plp)
{
if (!outv_check(v))
return 0;
uint64_t size_used = plp->write_offset - plp->start_offset;
if (size_used == 0)
return 0;
uint8_t *addr = pool_set_file_map(pip->pfile, plp->start_offset);
if (addr == MAP_FAILED) {
warn("%s", pip->file_name);
outv_err("cannot read pmem log data\n");
return -1;
}
if (pip->args.log.walk == 0) {
outv_title(v, "PMEMLOG data");
struct range *curp = NULL;
LIST_FOREACH(curp, &pip->args.ranges.head, next) {
uint8_t *ptr = addr + curp->first;
if (curp->last >= size_used)
curp->last = size_used - 1;
uint64_t count = curp->last - curp->first + 1;
outv_hexdump(v, ptr, count, curp->first +
plp->start_offset, 1);
size_used -= count;
if (!size_used)
break;
}
} else {
/*
* Walk through used data with fixed chunk size
* passed by user.
*/
uint64_t nchunks = size_used / pip->args.log.walk;
outv_title(v, "PMEMLOG data [chunks: total = %lu size = %ld]",
nchunks, pip->args.log.walk);
struct range *curp = NULL;
LIST_FOREACH(curp, &pip->args.ranges.head, next) {
uint64_t i;
for (i = curp->first; i <= curp->last &&
i < nchunks; i++) {
outv(v, "Chunk %10lu:\n", i);
outv_hexdump(v, addr + i * pip->args.log.walk,
pip->args.log.walk,
plp->start_offset +
i * pip->args.log.walk,
1);
}
}
}
return 0;
}
/*
* info_logs_stats -- print log type pool statistics
*/
static void
info_log_stats(struct pmem_info *pip, int v, struct pmemlog *plp)
{
uint64_t size_total = plp->end_offset - plp->start_offset;
uint64_t size_used = plp->write_offset - plp->start_offset;
uint64_t size_avail = size_total - size_used;
if (size_total == 0)
return;
double perc_used = (double)size_used / (double)size_total * 100.0;
double perc_avail = 100.0 - perc_used;
outv_title(v, "PMEM LOG Statistics");
outv_field(v, "Total", "%s",
out_get_size_str(size_total, pip->args.human));
outv_field(v, "Available", "%s [%s]",
out_get_size_str(size_avail, pip->args.human),
out_get_percentage(perc_avail));
outv_field(v, "Used", "%s [%s]",
out_get_size_str(size_used, pip->args.human),
out_get_percentage(perc_used));
}
/*
* info_log_descriptor -- print pmemlog descriptor and return 1 if
* write offset is valid
*/
static int
info_log_descriptor(struct pmem_info *pip, int v, struct pmemlog *plp)
{
outv_title(v, "PMEM LOG Header");
/* dump pmemlog header without pool_hdr */
outv_hexdump(pip->args.vhdrdump, (uint8_t *)plp + sizeof(plp->hdr),
sizeof(*plp) - sizeof(plp->hdr),
sizeof(plp->hdr), 1);
log_convert2h(plp);
int write_offset_valid = plp->write_offset >= plp->start_offset &&
plp->write_offset <= plp->end_offset;
outv_field(v, "Start offset", "0x%lx", plp->start_offset);
outv_field(v, "Write offset", "0x%lx [%s]", plp->write_offset,
write_offset_valid ? "OK":"ERROR");
outv_field(v, "End offset", "0x%lx", plp->end_offset);
return write_offset_valid;
}
/*
* pmempool_info_log -- print information about log type pool
*/
int
pmempool_info_log(struct pmem_info *pip)
{
int ret = 0;
struct pmemlog *plp = malloc(sizeof(struct pmemlog));
if (!plp)
err(1, "Cannot allocate memory for pmemlog structure");
if (pmempool_info_read(pip, plp, sizeof(struct pmemlog), 0)) {
outv_err("cannot read pmemlog header\n");
free(plp);
return -1;
}
if (info_log_descriptor(pip, VERBOSE_DEFAULT, plp)) {
info_log_stats(pip, pip->args.vstats, plp);
ret = info_log_data(pip, pip->args.vdata, plp);
}
free(plp);
return ret;
}
| 5,477
| 27.831579
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/transform.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* transform.h -- pmempool transform command header file
*/
int pmempool_transform_func(const char *appname, int argc, char *argv[]);
void pmempool_transform_help(const char *appname);
| 1,792
| 44.974359
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/info.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* info.h -- pmempool info command header file
*/
#include "vec.h"
/*
* Verbose levels used in application:
*
* VERBOSE_DEFAULT:
* Default value for application's verbosity level.
* This is also set for data structures which should be
* printed without any command line argument.
*
* VERBOSE_MAX:
* Maximum value for application's verbosity level.
* This value is used when -v command line argument passed.
*
* VERBOSE_SILENT:
* This value is higher than VERBOSE_MAX and it is used only
* for verbosity levels of data structures which should _not_ be
* printed without specified command line arguments.
*/
#define VERBOSE_SILENT 0
#define VERBOSE_DEFAULT 1
#define VERBOSE_MAX 2
/*
* pmempool_info_args -- structure for storing command line arguments
*/
struct pmempool_info_args {
char *file; /* input file */
unsigned col_width; /* column width for printing fields */
bool human; /* sizes in human-readable formats */
bool force; /* force parsing pool */
pmem_pool_type_t type; /* forced pool type */
bool use_range; /* use range for blocks */
struct ranges ranges; /* range of block/chunks to dump */
int vlevel; /* verbosity level */
int vdata; /* verbosity level for data dump */
int vhdrdump; /* verbosity level for headers hexdump */
int vstats; /* verbosity level for statistics */
int vbadblocks; /* verbosity level for bad blocks */
struct {
size_t walk; /* data chunk size */
} log;
struct {
int vmap; /* verbosity level for BTT Map */
int vflog; /* verbosity level for BTT FLOG */
int vbackup; /* verbosity level for BTT Info backup */
bool skip_zeros; /* skip blocks marked with zero flag */
bool skip_error; /* skip blocks marked with error flag */
bool skip_no_flag; /* skip blocks not marked with any flag */
} blk;
struct {
int vlanes; /* verbosity level for lanes */
int vroot;
int vobjects;
int valloc;
int voobhdr;
int vheap;
int vzonehdr;
int vchunkhdr;
int vbitmap;
bool lanes_recovery;
bool ignore_empty_obj;
uint64_t chunk_types;
size_t replica;
struct ranges lane_ranges;
struct ranges type_ranges;
struct ranges zone_ranges;
struct ranges chunk_ranges;
} obj;
};
/*
* pmem_blk_stats -- structure with statistics for pmemblk
*/
struct pmem_blk_stats {
uint32_t total; /* number of processed blocks */
uint32_t zeros; /* number of blocks marked by zero flag */
uint32_t errors; /* number of blocks marked by error flag */
uint32_t noflag; /* number of blocks not marked with any flag */
};
struct pmem_obj_class_stats {
uint64_t n_units;
uint64_t n_used;
uint64_t unit_size;
uint64_t alignment;
uint32_t nallocs;
uint16_t flags;
};
struct pmem_obj_zone_stats {
uint64_t n_chunks;
uint64_t n_chunks_type[MAX_CHUNK_TYPE];
uint64_t size_chunks;
uint64_t size_chunks_type[MAX_CHUNK_TYPE];
VEC(, struct pmem_obj_class_stats) class_stats;
};
struct pmem_obj_type_stats {
TAILQ_ENTRY(pmem_obj_type_stats) next;
uint64_t type_num;
uint64_t n_objects;
uint64_t n_bytes;
};
struct pmem_obj_stats {
uint64_t n_total_objects;
uint64_t n_total_bytes;
uint64_t n_zones;
uint64_t n_zones_used;
struct pmem_obj_zone_stats *zone_stats;
TAILQ_HEAD(obj_type_stats_head, pmem_obj_type_stats) type_stats;
};
/*
* pmem_info -- context for pmeminfo application
*/
struct pmem_info {
const char *file_name; /* current file name */
struct pool_set_file *pfile;
struct pmempool_info_args args; /* arguments parsed from command line */
struct options *opts;
struct pool_set *poolset;
pmem_pool_type_t type;
struct pmem_pool_params params;
struct {
struct pmem_blk_stats stats;
} blk;
struct {
struct pmemobjpool *pop;
struct palloc_heap *heap;
struct alloc_class_collection *alloc_classes;
size_t size;
struct pmem_obj_stats stats;
uint64_t uuid_lo;
uint64_t objid;
} obj;
struct {
struct pmemcto *pcp;
size_t size;
} cto;
};
int pmempool_info_func(const char *appname, int argc, char *argv[]);
void pmempool_info_help(const char *appname);
int pmempool_info_read(struct pmem_info *pip, void *buff,
size_t nbytes, uint64_t off);
int pmempool_info_blk(struct pmem_info *pip);
int pmempool_info_log(struct pmem_info *pip);
int pmempool_info_obj(struct pmem_info *pip);
int pmempool_info_btt(struct pmem_info *pip);
int pmempool_info_cto(struct pmem_info *pip);
| 5,934
| 30.236842
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/output.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* output.h -- declarations of output printing related functions
*/
#include <time.h>
#include <stdint.h>
#include <stdio.h>
void out_set_vlevel(int vlevel);
void out_set_stream(FILE *stream);
void out_set_prefix(const char *prefix);
void out_set_col_width(unsigned col_width);
void outv_err(const char *fmt, ...) FORMAT_PRINTF(1, 2);
void out_err(const char *file, int line, const char *func,
const char *fmt, ...) FORMAT_PRINTF(4, 5);
void outv_err_vargs(const char *fmt, va_list ap);
void outv_indent(int vlevel, int i);
void outv(int vlevel, const char *fmt, ...) FORMAT_PRINTF(2, 3);
void outv_nl(int vlevel);
int outv_check(int vlevel);
void outv_title(int vlevel, const char *fmt, ...) FORMAT_PRINTF(2, 3);
void outv_field(int vlevel, const char *field, const char *fmt,
...) FORMAT_PRINTF(3, 4);
void outv_hexdump(int vlevel, const void *addr, size_t len, size_t offset,
int sep);
const char *out_get_uuid_str(uuid_t uuid);
const char *out_get_time_str(time_t time);
const char *out_get_size_str(uint64_t size, int human);
const char *out_get_percentage(double percentage);
const char *out_get_checksum(void *addr, size_t len, uint64_t *csump,
uint64_t skip_off);
const char *out_get_btt_map_entry(uint32_t map);
const char *out_get_pool_type_str(pmem_pool_type_t type);
const char *out_get_pool_signature(pmem_pool_type_t type);
const char *out_get_tx_state_str(uint64_t state);
const char *out_get_chunk_type_str(enum chunk_type type);
const char *out_get_chunk_flags(uint16_t flags);
const char *out_get_zone_magic_str(uint32_t magic);
const char *out_get_pmemoid_str(PMEMoid oid, uint64_t uuid_lo);
const char *out_get_arch_machine_class_str(uint8_t machine_class);
const char *out_get_arch_data_str(uint8_t data);
const char *out_get_arch_machine_str(uint16_t machine);
const char *out_get_last_shutdown_str(uint8_t dirty);
const char *out_get_alignment_desc_str(uint64_t ad, uint64_t cur_ad);
const char *out_get_incompat_features_str(uint32_t incompat);
| 3,585
| 44.974359
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/synchronize.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* synchronize.c -- pmempool sync command source file
*/
#include "synchronize.h"
#include <stdio.h>
#include <libgen.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <stdbool.h>
#include <sys/mman.h>
#include <endian.h>
#include "common.h"
#include "output.h"
#include "libpmempool.h"
/*
* pmempool_sync_context -- context and arguments for sync command
*/
struct pmempool_sync_context {
unsigned flags; /* flags which modify the command execution */
char *poolset_file; /* a path to a poolset file */
};
/*
* pmempool_sync_default -- default arguments for sync command
*/
static const struct pmempool_sync_context pmempool_sync_default = {
.flags = 0,
.poolset_file = NULL,
};
/*
* help_str -- string for help message
*/
static const char * const help_str =
"Check consistency of a pool\n"
"\n"
"Common options:\n"
" -b, --bad-blocks fix bad blocks - it requires creating or reading special recovery files\n"
" -d, --dry-run do not apply changes, only check for viability of synchronization\n"
" -v, --verbose increase verbosity level\n"
" -h, --help display this help and exit\n"
"\n"
"For complete documentation see %s-sync(1) manual page.\n"
;
/*
* long_options -- command line options
*/
static const struct option long_options[] = {
{"bad-blocks", no_argument, NULL, 'b'},
{"dry-run", no_argument, NULL, 'd'},
{"help", no_argument, NULL, 'h'},
{"verbose", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0 },
};
/*
* print_usage -- (internal) print application usage short description
*/
static void
print_usage(const char *appname)
{
printf("usage: %s sync [<options>] <poolset_file>\n", appname);
}
/*
* print_version -- (internal) print version string
*/
static void
print_version(const char *appname)
{
printf("%s %s\n", appname, SRCVERSION);
}
/*
* pmempool_sync_help -- print help message for the sync command
*/
void
pmempool_sync_help(const char *appname)
{
print_usage(appname);
print_version(appname);
printf(help_str, appname);
}
/*
* pmempool_sync_parse_args -- (internal) parse command line arguments
*/
static int
pmempool_sync_parse_args(struct pmempool_sync_context *ctx, const char *appname,
int argc, char *argv[])
{
int opt;
while ((opt = getopt_long(argc, argv, "bdhv",
long_options, NULL)) != -1) {
switch (opt) {
case 'd':
ctx->flags |= PMEMPOOL_SYNC_DRY_RUN;
break;
case 'b':
ctx->flags |= PMEMPOOL_SYNC_FIX_BAD_BLOCKS;
break;
case 'h':
pmempool_sync_help(appname);
exit(EXIT_SUCCESS);
case 'v':
out_set_vlevel(1);
break;
default:
print_usage(appname);
exit(EXIT_FAILURE);
}
}
if (optind < argc) {
ctx->poolset_file = argv[optind];
} else {
print_usage(appname);
exit(EXIT_FAILURE);
}
return 0;
}
/*
* pmempool_sync_func -- main function for the sync command
*/
int
pmempool_sync_func(const char *appname, int argc, char *argv[])
{
int ret = 0;
struct pmempool_sync_context ctx = pmempool_sync_default;
/* parse command line arguments */
if ((ret = pmempool_sync_parse_args(&ctx, appname, argc, argv)))
return ret;
ret = pmempool_sync(ctx.poolset_file, ctx.flags);
if (ret) {
outv_err("failed to synchronize: %s\n", pmempool_errormsg());
if (errno)
outv_err("%s\n", strerror(errno));
return -1;
} else {
outv(1, "%s: synchronized\n", ctx.poolset_file);
return 0;
}
}
| 5,014
| 25.818182
| 98
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/pmempool/convert.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* convert.c -- pmempool convert command source file
*/
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "convert.h"
#include "os.h"
#ifdef _WIN32
static const char *delimeter = ";";
static const char *convert_bin = "\\pmdk-convert.exe";
#else
static const char *delimeter = ":";
static const char *convert_bin = "/pmdk-convert";
#endif // _WIN32
static int
pmempool_convert_get_path(char *p, size_t max_len)
{
char *path = strdup(os_getenv("PATH"));
if (!path) {
perror("strdup");
return -1;
}
char *dir = strtok(path, delimeter);
while (dir) {
size_t length = strlen(dir) + strlen(convert_bin) + 1;
if (length > max_len) {
fprintf(stderr, "very long dir in PATH, ignoring\n");
continue;
}
strcpy(p, dir);
strcat(p, convert_bin);
if (os_access(p, F_OK) == 0) {
free(path);
return 0;
}
dir = strtok(NULL, delimeter);
}
free(path);
return -1;
}
/*
* pmempool_convert_help -- print help message for convert command. This is
* help message from pmdk-convert tool.
*/
void
pmempool_convert_help(const char *appname)
{
char path[4096];
if (pmempool_convert_get_path(path, sizeof(path))) {
fprintf(stderr,
"pmdk-convert is not installed. Please install it.\n");
exit(1);
}
char *args[] = { path, "-h", NULL };
os_execv(path, args);
perror("execv");
exit(1);
}
/*
* pmempool_convert_func -- main function for convert command.
* It invokes pmdk-convert tool.
*/
int
pmempool_convert_func(const char *appname, int argc, char *argv[])
{
char path[4096];
if (pmempool_convert_get_path(path, sizeof(path))) {
fprintf(stderr,
"pmdk-convert is not installed. Please install it.\n");
exit(1);
}
char **args = malloc(((size_t)argc + 1) * sizeof(*args));
if (!args) {
perror("malloc");
exit(1);
}
args[0] = path;
for (int i = 1; i < argc; ++i)
args[i] = argv[i];
args[argc] = NULL;
os_execv(args[0], args);
perror("execv");
free(args);
exit(1);
}
| 3,619
| 24.673759
| 75
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/tools/daxio/daxio.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* daxio.c -- simple app for reading and writing data from/to
* Device DAX device using mmap instead of file I/O API
*/
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <limits.h>
#include <string.h>
#include <ndctl/libndctl.h>
#include <ndctl/libdaxctl.h>
#include <libpmem.h>
#include "util.h"
#include "os_dimm.h"
#define ALIGN_UP(size, align) (((size) + (align) - 1) & ~((align) - 1))
#define ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
#define ERR(fmt, ...)\
do {\
fprintf(stderr, "daxio: " fmt, ##__VA_ARGS__);\
} while (0)
#define FAIL(func)\
do {\
fprintf(stderr, "daxio: %s:%d: %s: %s\n",\
__func__, __LINE__, func, strerror(errno));\
} while (0)
struct daxio_device {
char *path;
int fd;
size_t size; /* actual file/device size */
int is_devdax;
/* Device DAX only */
size_t align; /* internal device alignment */
char *addr; /* mapping base address */
size_t maplen; /* mapping length */
size_t offset; /* seek or skip */
unsigned major;
unsigned minor;
struct ndctl_ctx *ndctl_ctx;
struct ndctl_region *region; /* parent region */
};
/*
* daxio_context -- context and arguments
*/
struct daxio_context {
size_t len; /* total length of I/O */
int zero;
struct daxio_device src;
struct daxio_device dst;
};
/*
* default context
*/
static struct daxio_context Ctx = {
SIZE_MAX, /* len */
0, /* zero */
{ NULL, -1, SIZE_MAX, 0, 0, NULL, 0, 0, 0, 0, NULL, NULL },
{ NULL, -1, SIZE_MAX, 0, 0, NULL, 0, 0, 0, 0, NULL, NULL },
};
/*
* print_version -- print daxio version
*/
static void
print_version(void)
{
printf("%s\n", SRCVERSION);
}
/*
* print_usage -- print short description of usage
*/
static void
print_usage(void)
{
printf("Usage: daxio [option] ...\n");
printf("Valid options:\n");
printf("-i, --input=FILE - input device/file (default stdin)\n");
printf("-o, --output=FILE - output device/file (default stdout)\n");
printf("-k, --skip=BYTES - skip offset for input (default 0)\n");
printf("-s, --seek=BYTES - seek offset for output (default 0)\n");
printf("-l, --len=BYTES - total length to perform the I/O\n");
printf("-z, --zero - zeroing the device\n");
printf("-h. --help - print this help\n");
printf("-V, --version - display version of daxio\n");
}
/*
* long_options -- command line options
*/
static const struct option long_options[] = {
{"input", required_argument, NULL, 'i'},
{"output", required_argument, NULL, 'o'},
{"skip", required_argument, NULL, 'k'},
{"seek", required_argument, NULL, 's'},
{"len", required_argument, NULL, 'l'},
{"zero", no_argument, NULL, 'z'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0 },
};
/*
* parse_args -- (internal) parse command line arguments
*/
static int
parse_args(struct daxio_context *ctx, int argc, char * const argv[])
{
int opt;
size_t offset;
size_t len;
while ((opt = getopt_long(argc, argv, "i:o:k:s:l:zhV",
long_options, NULL)) != -1) {
switch (opt) {
case 'i':
ctx->src.path = optarg;
break;
case 'o':
ctx->dst.path = optarg;
break;
case 'k':
if (util_parse_size(optarg, &offset)) {
ERR("'%s' -- invalid input offset\n", optarg);
return -1;
}
ctx->src.offset = offset;
break;
case 's':
if (util_parse_size(optarg, &offset)) {
ERR("'%s' -- invalid output offset\n", optarg);
return -1;
}
ctx->dst.offset = offset;
break;
case 'l':
if (util_parse_size(optarg, &len)) {
ERR("'%s' -- invalid length\n", optarg);
return -1;
}
ctx->len = len;
break;
case 'z':
ctx->zero = 1;
break;
case 'h':
print_usage();
exit(EXIT_SUCCESS);
case 'V':
print_version();
exit(EXIT_SUCCESS);
default:
print_usage();
exit(EXIT_FAILURE);
}
}
return 0;
}
/*
* validate_args -- (internal) validate command line arguments
*/
static int
validate_args(struct daxio_context *ctx)
{
if (ctx->zero && ctx->dst.path == NULL) {
ERR("zeroing flag specified but no output file provided\n");
return -1;
}
if (!ctx->zero && ctx->src.path == NULL && ctx->dst.path == NULL) {
ERR("an input file and/or an output file must be provided\n");
return -1;
}
/* if no input file provided, use stdin */
if (ctx->src.path == NULL) {
if (ctx->src.offset != 0) {
ERR(
"skip offset specified but no input file provided\n");
return -1;
}
ctx->src.fd = STDIN_FILENO;
ctx->src.path = "STDIN";
}
/* if no output file provided, use stdout */
if (ctx->dst.path == NULL) {
if (ctx->dst.offset != 0) {
ERR(
"seek offset specified but no output file provided\n");
return -1;
}
ctx->dst.fd = STDOUT_FILENO;
ctx->dst.path = "STDOUT";
}
return 0;
}
/*
* match_dev_dax -- (internal) find Device DAX by major/minor device number
*/
static int
match_dev_dax(struct daxio_device *dev, struct daxctl_region *dax_region)
{
struct daxctl_dev *d;
daxctl_dev_foreach(dax_region, d) {
if (dev->major == (unsigned)daxctl_dev_get_major(d) &&
dev->minor == (unsigned)daxctl_dev_get_minor(d)) {
dev->size = daxctl_dev_get_size(d);
return 1;
}
}
return 0;
}
/*
* find_dev_dax -- (internal) check if device is Device DAX
*
* If there is matching Device DAX, find its region, size and alignment.
*/
static int
find_dev_dax(struct ndctl_ctx *ndctl_ctx, struct daxio_device *dev)
{
struct ndctl_bus *bus;
struct ndctl_region *region;
struct ndctl_dax *dax;
struct daxctl_region *dax_region;
ndctl_bus_foreach(ndctl_ctx, bus) {
ndctl_region_foreach(bus, region) {
ndctl_dax_foreach(region, dax) {
dax_region = ndctl_dax_get_daxctl_region(dax);
if (match_dev_dax(dev, dax_region)) {
dev->is_devdax = 1;
dev->align = ndctl_dax_get_align(dax);
dev->region = region;
return 1;
}
}
}
}
/* try with dax regions */
struct daxctl_ctx *daxctl_ctx;
if (daxctl_new(&daxctl_ctx))
return 0;
int ret = 0;
daxctl_region_foreach(daxctl_ctx, dax_region) {
if (match_dev_dax(dev, dax_region)) {
dev->is_devdax = 1;
dev->align = daxctl_region_get_align(dax_region);
dev->region = region;
ret = 1;
goto end;
}
}
end:
daxctl_unref(daxctl_ctx);
return ret;
}
/*
* setup_device -- (internal) open/mmap file/device
*/
static int
setup_device(struct ndctl_ctx *ndctl_ctx, struct daxio_device *dev, int is_dst)
{
int ret;
int flags = O_RDWR;
int prot = is_dst ? PROT_WRITE : PROT_READ;
if (dev->fd != -1) {
dev->size = SIZE_MAX;
return 0; /* stdin/stdout */
}
/* try to open file/device (if exists) */
dev->fd = open(dev->path, flags, S_IRUSR|S_IWUSR);
if (dev->fd == -1) {
ret = errno;
if (ret == ENOENT && is_dst) {
/* file does not exist - create it */
flags = O_CREAT|O_WRONLY|O_TRUNC;
dev->size = SIZE_MAX;
dev->fd = open(dev->path, flags, S_IRUSR|S_IWUSR);
if (dev->fd == -1) {
FAIL("open");
return -1;
}
return 0;
} else {
ERR("failed to open '%s': %s\n", dev->path,
strerror(errno));
return -1;
}
}
struct stat stbuf;
ret = fstat(dev->fd, &stbuf);
if (ret == -1) {
FAIL("stat");
return -1;
}
/* check if this is regular file or device */
if (S_ISREG(stbuf.st_mode)) {
if (is_dst) {
flags = O_RDWR|O_TRUNC;
dev->size = SIZE_MAX;
} else {
dev->size = (size_t)stbuf.st_size;
}
} else if (S_ISBLK(stbuf.st_mode)) {
dev->size = (size_t)stbuf.st_size;
} else if (S_ISCHR(stbuf.st_mode)) {
dev->size = SIZE_MAX;
dev->major = major(stbuf.st_rdev);
dev->minor = minor(stbuf.st_rdev);
} else {
return -1;
}
/* check if this is Device DAX */
if (S_ISCHR(stbuf.st_mode))
find_dev_dax(ndctl_ctx, dev);
if (!dev->is_devdax)
return 0;
if (is_dst) {
/* XXX - clear only badblocks in range bound by offset/len */
if (os_dimm_devdax_clear_badblocks_all(dev->path)) {
ERR("failed to clear badblocks on \"%s\"\n",
dev->path);
return -1;
}
}
if (dev->align == ULONG_MAX) {
ERR("cannot determine device alignment for \"%s\"\n",
dev->path);
return -1;
}
if (dev->offset > dev->size) {
ERR("'%zu' -- offset beyond device size (%zu)\n",
dev->offset, dev->size);
return -1;
}
/* align len/offset to the internal device alignment */
dev->maplen = ALIGN_UP(dev->size, dev->align);
size_t offset = ALIGN_DOWN(dev->offset, dev->align);
dev->offset = dev->offset - offset;
dev->maplen = dev->maplen - offset;
dev->addr = mmap(NULL, dev->maplen, prot, MAP_SHARED, dev->fd,
(off_t)offset);
if (dev->addr == MAP_FAILED) {
FAIL("mmap");
return -1;
}
return 0;
}
/*
* setup_devices -- (internal) open/mmap input and output
*/
static int
setup_devices(struct ndctl_ctx *ndctl_ctx, struct daxio_context *ctx)
{
if (!ctx->zero &&
setup_device(ndctl_ctx, &ctx->src, 0))
return -1;
return setup_device(ndctl_ctx, &ctx->dst, 1);
}
/*
* adjust_io_len -- (internal) calculate I/O length if not specified
*/
static void
adjust_io_len(struct daxio_context *ctx)
{
size_t src_len = ctx->src.maplen - ctx->src.offset;
size_t dst_len = ctx->dst.maplen - ctx->dst.offset;
size_t max_len = SIZE_MAX;
if (ctx->zero)
assert(ctx->dst.is_devdax);
else
assert(ctx->src.is_devdax || ctx->dst.is_devdax);
if (ctx->src.is_devdax)
max_len = src_len;
if (ctx->dst.is_devdax)
max_len = max_len < dst_len ? max_len : dst_len;
/* if length is specified and is not bigger than mmaped region */
if (ctx->len != SIZE_MAX && ctx->len <= max_len)
return;
/* adjust len to device size */
ctx->len = max_len;
}
/*
* cleanup_device -- (internal) unmap/close file/device
*/
static void
cleanup_device(struct daxio_device *dev)
{
if (dev->addr)
(void) munmap(dev->addr, dev->maplen);
if (dev->path && dev->fd != -1)
(void) close(dev->fd);
}
/*
* cleanup_devices -- (internal) unmap/close input and output
*/
static void
cleanup_devices(struct daxio_context *ctx)
{
cleanup_device(&ctx->dst);
if (!ctx->zero)
cleanup_device(&ctx->src);
}
/*
* do_io -- (internal) write data to device/file
*/
static int
do_io(struct ndctl_ctx *ndctl_ctx, struct daxio_context *ctx)
{
ssize_t cnt = 0;
assert(ctx->src.is_devdax || ctx->dst.is_devdax);
if (ctx->zero) {
if (ctx->dst.offset > ctx->dst.maplen) {
ERR("output offset larger than device size");
return -1;
}
if (ctx->dst.offset + ctx->len > ctx->dst.maplen) {
ERR("output offset beyond device size");
return -1;
}
char *dst_addr = ctx->dst.addr + ctx->dst.offset;
pmem_memset_persist(dst_addr, 0, ctx->len);
cnt = (ssize_t)ctx->len;
} else if (ctx->src.is_devdax && ctx->dst.is_devdax) {
/* memcpy between src and dst */
char *src_addr = ctx->src.addr + ctx->src.offset;
char *dst_addr = ctx->dst.addr + ctx->dst.offset;
pmem_memcpy_persist(dst_addr, src_addr, ctx->len);
cnt = (ssize_t)ctx->len;
} else if (ctx->src.is_devdax) {
/* write to file directly from mmap'ed src */
char *src_addr = ctx->src.addr + ctx->src.offset;
if (ctx->dst.offset) {
if (lseek(ctx->dst.fd, (off_t)ctx->dst.offset,
SEEK_SET) < 0) {
FAIL("lseek");
goto err;
}
}
do {
ssize_t wcnt = write(ctx->dst.fd, src_addr + cnt,
ctx->len - (size_t)cnt);
if (wcnt == -1) {
FAIL("write");
goto err;
}
cnt += wcnt;
} while ((size_t)cnt < ctx->len);
} else if (ctx->dst.is_devdax) {
/* read from file directly to mmap'ed dst */
char *dst_addr = ctx->dst.addr + ctx->dst.offset;
if (ctx->src.offset) {
if (lseek(ctx->src.fd, (off_t)ctx->src.offset,
SEEK_SET) < 0) {
FAIL("lseek");
return -1;
}
}
do {
ssize_t rcnt = read(ctx->src.fd, dst_addr + cnt,
ctx->len - (size_t)cnt);
if (rcnt == -1) {
FAIL("read");
goto err;
}
/* end of file */
if (rcnt == 0)
break;
cnt = cnt + rcnt;
} while ((size_t)cnt < ctx->len);
pmem_persist(dst_addr, (size_t)cnt);
if ((size_t)cnt != ctx->len)
ERR("requested size %zu larger than source\n",
ctx->len);
}
ERR("copied %zd bytes to device \"%s\"\n", cnt, ctx->dst.path);
return 0;
err:
ERR("failed to perform I/O\n");
return -1;
}
int
main(int argc, char **argv)
{
struct ndctl_ctx *ndctl_ctx;
int ret = EXIT_SUCCESS;
if (parse_args(&Ctx, argc, argv))
return EXIT_FAILURE;
if (validate_args(&Ctx))
return EXIT_FAILURE;
if (ndctl_new(&ndctl_ctx))
return EXIT_FAILURE;
if (setup_devices(ndctl_ctx, &Ctx)) {
ret = EXIT_FAILURE;
goto err;
}
if (!Ctx.src.is_devdax && !Ctx.dst.is_devdax) {
ERR("neither input nor output is device dax\n");
ret = EXIT_FAILURE;
goto err;
}
adjust_io_len(&Ctx);
if (do_io(ndctl_ctx, &Ctx))
ret = EXIT_FAILURE;
err:
cleanup_devices(&Ctx);
ndctl_unref(ndctl_ctx);
return ret;
}
| 14,464
| 22.713115
| 79
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/libpmemlog/log.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* log.h -- internal definitions for libpmem log module
*/
#ifndef LOG_H
#define LOG_H 1
#include <stdint.h>
#include <stddef.h>
#include <endian.h>
#include "ctl.h"
#include "util.h"
#include "os_thread.h"
#include "pool_hdr.h"
#ifdef __cplusplus
extern "C" {
#endif
#define PMEMLOG_LOG_PREFIX "libpmemlog"
#define PMEMLOG_LOG_LEVEL_VAR "PMEMLOG_LOG_LEVEL"
#define PMEMLOG_LOG_FILE_VAR "PMEMLOG_LOG_FILE"
/* attributes of the log memory pool format for the pool header */
#define LOG_HDR_SIG "PMEMLOG" /* must be 8 bytes including '\0' */
#define LOG_FORMAT_MAJOR 1
#define LOG_FORMAT_FEAT_DEFAULT \
{0x0000, POOL_FEAT_INCOMPAT_DEFAULT, 0x0000}
#define LOG_FORMAT_FEAT_CHECK \
{0x0000, POOL_FEAT_INCOMPAT_VALID, 0x0000}
static const features_t log_format_feat_default = LOG_FORMAT_FEAT_DEFAULT;
struct pmemlog {
struct pool_hdr hdr; /* memory pool header */
/* root info for on-media format... */
uint64_t start_offset; /* start offset of the usable log space */
uint64_t end_offset; /* maximum offset of the usable log space */
uint64_t write_offset; /* current write point for the log */
/* some run-time state, allocated out of memory pool... */
void *addr; /* mapped region */
size_t size; /* size of mapped region */
int is_pmem; /* true if pool is PMEM */
int rdonly; /* true if pool is opened read-only */
os_rwlock_t *rwlockp; /* pointer to RW lock */
int is_dev_dax; /* true if mapped on device dax */
struct ctl *ctl; /* top level node of the ctl tree structure */
struct pool_set *set; /* pool set info */
};
/* data area starts at this alignment after the struct pmemlog above */
#define LOG_FORMAT_DATA_ALIGN ((uintptr_t)4096)
/*
* log_convert2h -- convert pmemlog structure to host byte order
*/
static inline void
log_convert2h(struct pmemlog *plp)
{
plp->start_offset = le64toh(plp->start_offset);
plp->end_offset = le64toh(plp->end_offset);
plp->write_offset = le64toh(plp->write_offset);
}
/*
* log_convert2le -- convert pmemlog structure to LE byte order
*/
static inline void
log_convert2le(struct pmemlog *plp)
{
plp->start_offset = htole64(plp->start_offset);
plp->end_offset = htole64(plp->end_offset);
plp->write_offset = htole64(plp->write_offset);
}
#ifdef __cplusplus
}
#endif
#endif
| 3,867
| 31.504202
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/libpmemlog/log.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* log.c -- log memory pool entry points for libpmem
*/
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/param.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <stdint.h>
#include <stdbool.h>
#include "libpmem.h"
#include "libpmemlog.h"
#include "ctl_global.h"
#include "os.h"
#include "set.h"
#include "out.h"
#include "log.h"
#include "mmap.h"
#include "sys_util.h"
#include "util_pmem.h"
#include "valgrind_internal.h"
static const struct pool_attr Log_create_attr = {
LOG_HDR_SIG,
LOG_FORMAT_MAJOR,
LOG_FORMAT_FEAT_DEFAULT,
{0}, {0}, {0}, {0}, {0}
};
static const struct pool_attr Log_open_attr = {
LOG_HDR_SIG,
LOG_FORMAT_MAJOR,
LOG_FORMAT_FEAT_CHECK,
{0}, {0}, {0}, {0}, {0}
};
/*
* log_descr_create -- (internal) create log memory pool descriptor
*/
static void
log_descr_create(PMEMlogpool *plp, size_t poolsize)
{
LOG(3, "plp %p poolsize %zu", plp, poolsize);
ASSERTeq(poolsize % Pagesize, 0);
/* create required metadata */
plp->start_offset = htole64(roundup(sizeof(*plp),
LOG_FORMAT_DATA_ALIGN));
plp->end_offset = htole64(poolsize);
plp->write_offset = plp->start_offset;
/* store non-volatile part of pool's descriptor */
util_persist(plp->is_pmem, &plp->start_offset, 3 * sizeof(uint64_t));
}
/*
* log_descr_check -- (internal) validate log memory pool descriptor
*/
static int
log_descr_check(PMEMlogpool *plp, size_t poolsize)
{
LOG(3, "plp %p poolsize %zu", plp, poolsize);
struct pmemlog hdr = *plp;
log_convert2h(&hdr);
if ((hdr.start_offset !=
roundup(sizeof(*plp), LOG_FORMAT_DATA_ALIGN)) ||
(hdr.end_offset != poolsize) ||
(hdr.start_offset > hdr.end_offset)) {
ERR("wrong start/end offsets "
"(start: %" PRIu64 " end: %" PRIu64 "), "
"pool size %zu",
hdr.start_offset, hdr.end_offset, poolsize);
errno = EINVAL;
return -1;
}
if ((hdr.write_offset > hdr.end_offset) || (hdr.write_offset <
hdr.start_offset)) {
ERR("wrong write offset (start: %" PRIu64 " end: %" PRIu64
" write: %" PRIu64 ")",
hdr.start_offset, hdr.end_offset, hdr.write_offset);
errno = EINVAL;
return -1;
}
LOG(3, "start: %" PRIu64 ", end: %" PRIu64 ", write: %" PRIu64 "",
hdr.start_offset, hdr.end_offset, hdr.write_offset);
return 0;
}
/*
* log_runtime_init -- (internal) initialize log memory pool runtime data
*/
static int
log_runtime_init(PMEMlogpool *plp, int rdonly)
{
LOG(3, "plp %p rdonly %d", plp, rdonly);
/* remove volatile part of header */
VALGRIND_REMOVE_PMEM_MAPPING(&plp->addr,
sizeof(struct pmemlog) -
sizeof(struct pool_hdr) -
3 * sizeof(uint64_t));
/*
* Use some of the memory pool area for run-time info. This
* run-time state is never loaded from the file, it is always
* created here, so no need to worry about byte-order.
*/
plp->rdonly = rdonly;
if ((plp->rwlockp = Malloc(sizeof(*plp->rwlockp))) == NULL) {
ERR("!Malloc for a RW lock");
return -1;
}
if ((errno = os_rwlock_init(plp->rwlockp))) {
ERR("!os_rwlock_init");
Free((void *)plp->rwlockp);
return -1;
}
/*
* If possible, turn off all permissions on the pool header page.
*
* The prototype PMFS doesn't allow this when large pages are in
* use. It is not considered an error if this fails.
*/
RANGE_NONE(plp->addr, sizeof(struct pool_hdr), plp->is_dev_dax);
/* the rest should be kept read-only (debug version only) */
RANGE_RO((char *)plp->addr + sizeof(struct pool_hdr),
plp->size - sizeof(struct pool_hdr), plp->is_dev_dax);
return 0;
}
/*
* pmemlog_createU -- create a log memory pool
*/
#ifndef _WIN32
static inline
#endif
PMEMlogpool *
pmemlog_createU(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,
PMEMLOG_MIN_PART, &Log_create_attr, 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_dev_dax = rep->part[0].is_dev_dax;
/* is_dev_dax implies is_pmem */
ASSERT(!plp->is_dev_dax || plp->is_pmem);
/* create pool descriptor */
log_descr_create(plp, rep->repsize);
/* initialize runtime parts */
if (log_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, DELETE_CREATED_PARTS);
errno = oerrno;
return NULL;
}
#ifndef _WIN32
/*
* pmemlog_create -- create a log memory pool
*/
PMEMlogpool *
pmemlog_create(const char *path, size_t poolsize, mode_t mode)
{
return pmemlog_createU(path, poolsize, mode);
}
#else
/*
* pmemlog_createW -- create a log memory pool
*/
PMEMlogpool *
pmemlog_createW(const wchar_t *path, size_t poolsize, mode_t mode)
{
char *upath = util_toUTF8(path);
if (upath == NULL)
return NULL;
PMEMlogpool *ret = pmemlog_createU(upath, poolsize, mode);
util_free_UTF8(upath);
return ret;
}
#endif
/*
* log_open_common -- (internal) open a log memory pool
*
* This routine does all the work, but takes a cow flag so internal
* calls can map a read-only pool if required.
*/
static PMEMlogpool *
log_open_common(const char *path, unsigned flags)
{
LOG(3, "path %s flags 0x%x", path, flags);
struct pool_set *set;
if (util_pool_open(&set, path, PMEMLOG_MIN_PART, &Log_open_attr,
NULL, NULL, flags) != 0) {
LOG(2, "cannot open 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_dev_dax = rep->part[0].is_dev_dax;
/* is_dev_dax implies is_pmem */
ASSERT(!plp->is_dev_dax || plp->is_pmem);
if (set->nreplicas > 1) {
errno = ENOTSUP;
ERR("!replicas not supported");
goto err;
}
/* validate pool descriptor */
if (log_descr_check(plp, rep->repsize) != 0) {
LOG(2, "descriptor check failed");
goto err;
}
/* initialize runtime parts */
if (log_runtime_init(plp, set->rdonly) != 0) {
ERR("pool initialization failed");
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, DO_NOT_DELETE_PARTS);
errno = oerrno;
return NULL;
}
/*
* pmemlog_openU -- open an existing log memory pool
*/
#ifndef _WIN32
static inline
#endif
PMEMlogpool *
pmemlog_openU(const char *path)
{
LOG(3, "path %s", path);
return log_open_common(path, 0);
}
#ifndef _WIN32
/*
* pmemlog_open -- open an existing log memory pool
*/
PMEMlogpool *
pmemlog_open(const char *path)
{
return pmemlog_openU(path);
}
#else
/*
* pmemlog_openW -- open an existing log memory pool
*/
PMEMlogpool *
pmemlog_openW(const wchar_t *path)
{
char *upath = util_toUTF8(path);
if (upath == NULL)
return NULL;
PMEMlogpool *ret = pmemlog_openU(upath);
util_free_UTF8(upath);
return ret;
}
#endif
/*
* pmemlog_close -- close a log memory pool
*/
void
pmemlog_close(PMEMlogpool *plp)
{
LOG(3, "plp %p", plp);
if ((errno = os_rwlock_destroy(plp->rwlockp)))
ERR("!os_rwlock_destroy");
Free((void *)plp->rwlockp);
util_poolset_close(plp->set, DO_NOT_DELETE_PARTS);
}
/*
* pmemlog_nbyte -- return usable size of a log memory pool
*/
size_t
pmemlog_nbyte(PMEMlogpool *plp)
{
LOG(3, "plp %p", plp);
if ((errno = os_rwlock_rdlock(plp->rwlockp))) {
ERR("!os_rwlock_rdlock");
return (size_t)-1;
}
size_t size = le64toh(plp->end_offset) - le64toh(plp->start_offset);
LOG(4, "plp %p nbyte %zu", plp, size);
util_rwlock_unlock(plp->rwlockp);
return size;
}
/*
* log_persist -- (internal) persist data, then metadata
*
* On entry, the write lock should be held.
*/
static void
log_persist(PMEMlogpool *plp, uint64_t new_write_offset)
{
uint64_t old_write_offset = le64toh(plp->write_offset);
size_t length = new_write_offset - old_write_offset;
/* unprotect the log space range (debug version only) */
RANGE_RW((char *)plp->addr + old_write_offset, length, plp->is_dev_dax);
/* persist the data */
if (plp->is_pmem)
pmem_drain(); /* data already flushed */
else
pmem_msync((char *)plp->addr + old_write_offset, length);
/* protect the log space range (debug version only) */
RANGE_RO((char *)plp->addr + old_write_offset, length, plp->is_dev_dax);
/* unprotect the pool descriptor (debug version only) */
RANGE_RW((char *)plp->addr + sizeof(struct pool_hdr),
LOG_FORMAT_DATA_ALIGN, plp->is_dev_dax);
/* write the metadata */
plp->write_offset = htole64(new_write_offset);
/* persist the metadata */
if (plp->is_pmem)
pmem_persist(&plp->write_offset, sizeof(plp->write_offset));
else
pmem_msync(&plp->write_offset, sizeof(plp->write_offset));
/* set the write-protection again (debug version only) */
RANGE_RO((char *)plp->addr + sizeof(struct pool_hdr),
LOG_FORMAT_DATA_ALIGN, plp->is_dev_dax);
}
/*
* pmemlog_append -- add data to a log memory pool
*/
int
pmemlog_append(PMEMlogpool *plp, const void *buf, size_t count)
{
int ret = 0;
LOG(3, "plp %p buf %p count %zu", plp, buf, count);
if (plp->rdonly) {
ERR("can't append to read-only log");
errno = EROFS;
return -1;
}
if ((errno = os_rwlock_wrlock(plp->rwlockp))) {
ERR("!os_rwlock_wrlock");
return -1;
}
/* get the current values */
uint64_t end_offset = le64toh(plp->end_offset);
uint64_t write_offset = le64toh(plp->write_offset);
if (write_offset >= end_offset) {
/* no space left */
errno = ENOSPC;
ERR("!pmemlog_append");
ret = -1;
goto end;
}
/* make sure we don't write past the available space */
if (count > (end_offset - write_offset)) {
errno = ENOSPC;
ERR("!pmemlog_append");
ret = -1;
goto end;
}
char *data = plp->addr;
/*
* unprotect the log space range, where the new data will be stored
* (debug version only)
*/
RANGE_RW(&data[write_offset], count, plp->is_dev_dax);
if (plp->is_pmem)
pmem_memcpy_nodrain(&data[write_offset], buf, count);
else
memcpy(&data[write_offset], buf, count);
/* protect the log space range (debug version only) */
RANGE_RO(&data[write_offset], count, plp->is_dev_dax);
write_offset += count;
/* persist the data and the metadata */
log_persist(plp, write_offset);
end:
util_rwlock_unlock(plp->rwlockp);
return ret;
}
/*
* pmemlog_appendv -- add gathered data to a log memory pool
*/
int
pmemlog_appendv(PMEMlogpool *plp, const struct iovec *iov, int iovcnt)
{
LOG(3, "plp %p iovec %p iovcnt %d", plp, iov, iovcnt);
int ret = 0;
int i;
if (iovcnt < 0) {
errno = EINVAL;
ERR("iovcnt is less than zero: %d", iovcnt);
return -1;
}
if (plp->rdonly) {
ERR("can't append to read-only log");
errno = EROFS;
return -1;
}
if ((errno = os_rwlock_wrlock(plp->rwlockp))) {
ERR("!os_rwlock_wrlock");
return -1;
}
/* get the current values */
uint64_t end_offset = le64toh(plp->end_offset);
uint64_t write_offset = le64toh(plp->write_offset);
if (write_offset >= end_offset) {
/* no space left */
errno = ENOSPC;
ERR("!pmemlog_appendv");
ret = -1;
goto end;
}
char *data = plp->addr;
uint64_t count = 0;
char *buf;
/* calculate required space */
for (i = 0; i < iovcnt; ++i)
count += iov[i].iov_len;
/* check if there is enough free space */
if (count > (end_offset - write_offset)) {
errno = ENOSPC;
ret = -1;
goto end;
}
/* append the data */
for (i = 0; i < iovcnt; ++i) {
buf = iov[i].iov_base;
count = iov[i].iov_len;
/*
* unprotect the log space range, where the new data will be
* stored (debug version only)
*/
RANGE_RW(&data[write_offset], count, plp->is_dev_dax);
if (plp->is_pmem)
pmem_memcpy_nodrain(&data[write_offset], buf, count);
else
memcpy(&data[write_offset], buf, count);
/*
* protect the log space range (debug version only)
*/
RANGE_RO(&data[write_offset], count, plp->is_dev_dax);
write_offset += count;
}
/* persist the data and the metadata */
log_persist(plp, write_offset);
end:
util_rwlock_unlock(plp->rwlockp);
return ret;
}
/*
* pmemlog_tell -- return current write point in a log memory pool
*/
long long
pmemlog_tell(PMEMlogpool *plp)
{
LOG(3, "plp %p", plp);
if ((errno = os_rwlock_rdlock(plp->rwlockp))) {
ERR("!os_rwlock_rdlock");
return (os_off_t)-1;
}
ASSERT(le64toh(plp->write_offset) >= le64toh(plp->start_offset));
long long wp = (long long)(le64toh(plp->write_offset) -
le64toh(plp->start_offset));
LOG(4, "write offset %lld", wp);
util_rwlock_unlock(plp->rwlockp);
return wp;
}
/*
* pmemlog_rewind -- discard all data, resetting a log memory pool to empty
*/
void
pmemlog_rewind(PMEMlogpool *plp)
{
LOG(3, "plp %p", plp);
if (plp->rdonly) {
ERR("can't rewind read-only log");
errno = EROFS;
return;
}
if ((errno = os_rwlock_wrlock(plp->rwlockp))) {
ERR("!os_rwlock_wrlock");
return;
}
/* unprotect the pool descriptor (debug version only) */
RANGE_RW((char *)plp->addr + sizeof(struct pool_hdr),
LOG_FORMAT_DATA_ALIGN, plp->is_dev_dax);
plp->write_offset = plp->start_offset;
if (plp->is_pmem)
pmem_persist(&plp->write_offset, sizeof(uint64_t));
else
pmem_msync(&plp->write_offset, sizeof(uint64_t));
/* set the write-protection again (debug version only) */
RANGE_RO((char *)plp->addr + sizeof(struct pool_hdr),
LOG_FORMAT_DATA_ALIGN, plp->is_dev_dax);
util_rwlock_unlock(plp->rwlockp);
}
/*
* pmemlog_walk -- walk through all data in a log memory pool
*
* chunksize of 0 means process_chunk gets called once for all data
* as a single chunk.
*/
void
pmemlog_walk(PMEMlogpool *plp, size_t chunksize,
int (*process_chunk)(const void *buf, size_t len, void *arg), void *arg)
{
LOG(3, "plp %p chunksize %zu", plp, chunksize);
/*
* We are assuming that the walker doesn't change the data it's reading
* in place. We prevent everyone from changing the data behind our back
* until we are done with processing it.
*/
if ((errno = os_rwlock_rdlock(plp->rwlockp))) {
ERR("!os_rwlock_rdlock");
return;
}
char *data = plp->addr;
uint64_t write_offset = le64toh(plp->write_offset);
uint64_t data_offset = le64toh(plp->start_offset);
size_t len;
if (chunksize == 0) {
/* most common case: process everything at once */
len = write_offset - data_offset;
LOG(3, "length %zu", len);
(*process_chunk)(&data[data_offset], len, arg);
} else {
/*
* Walk through the complete record, chunk by chunk.
* The callback returns 0 to terminate the walk.
*/
while (data_offset < write_offset) {
len = MIN(chunksize, write_offset - data_offset);
if (!(*process_chunk)(&data[data_offset], len, arg))
break;
data_offset += chunksize;
}
}
util_rwlock_unlock(plp->rwlockp);
}
/*
* pmemlog_checkU -- log memory pool consistency check
*
* Returns true if consistent, zero if inconsistent, -1/error if checking
* cannot happen due to other errors.
*/
#ifndef _WIN32
static inline
#endif
int
pmemlog_checkU(const char *path)
{
LOG(3, "path \"%s\"", path);
PMEMlogpool *plp = log_open_common(path, POOL_OPEN_COW);
if (plp == NULL)
return -1; /* errno set by log_open_common() */
int consistent = 1;
/* validate pool descriptor */
uint64_t hdr_start = le64toh(plp->start_offset);
uint64_t hdr_end = le64toh(plp->end_offset);
uint64_t hdr_write = le64toh(plp->write_offset);
if (hdr_start != roundup(sizeof(*plp), LOG_FORMAT_DATA_ALIGN)) {
ERR("wrong value of start_offset");
consistent = 0;
}
if (hdr_end != plp->size) {
ERR("wrong value of end_offset");
consistent = 0;
}
if (hdr_start > hdr_end) {
ERR("start_offset greater than end_offset");
consistent = 0;
}
if (hdr_start > hdr_write) {
ERR("start_offset greater than write_offset");
consistent = 0;
}
if (hdr_write > hdr_end) {
ERR("write_offset greater than end_offset");
consistent = 0;
}
pmemlog_close(plp);
if (consistent)
LOG(4, "pool consistency check OK");
return consistent;
}
#ifndef _WIN32
/*
* pmemlog_check -- log memory pool consistency check
*
* Returns true if consistent, zero if inconsistent, -1/error if checking
* cannot happen due to other errors.
*/
int
pmemlog_check(const char *path)
{
return pmemlog_checkU(path);
}
#else
/*
* pmemlog_checkW -- log memory pool consistency check
*/
int
pmemlog_checkW(const wchar_t *path)
{
char *upath = util_toUTF8(path);
if (upath == NULL)
return -1;
int ret = pmemlog_checkU(upath);
util_free_UTF8(upath);
return ret;
}
#endif
/*
* pmemlog_ctl_getU -- programmatically executes a read ctl query
*/
#ifndef _WIN32
static inline
#endif
int
pmemlog_ctl_getU(PMEMlogpool *plp, const char *name, void *arg)
{
LOG(3, "plp %p name %s arg %p", plp, name, arg);
return ctl_query(plp == NULL ? NULL : plp->ctl, plp,
CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_READ, arg);
}
/*
* pmemblk_ctl_setU -- programmatically executes a write ctl query
*/
#ifndef _WIN32
static inline
#endif
int
pmemlog_ctl_setU(PMEMlogpool *plp, const char *name, void *arg)
{
LOG(3, "plp %p name %s arg %p", plp, name, arg);
return ctl_query(plp == NULL ? NULL : plp->ctl, plp,
CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_WRITE, arg);
}
/*
* pmemlog_ctl_execU -- programmatically executes a runnable ctl query
*/
#ifndef _WIN32
static inline
#endif
int
pmemlog_ctl_execU(PMEMlogpool *plp, const char *name, void *arg)
{
LOG(3, "plp %p name %s arg %p", plp, name, arg);
return ctl_query(plp == NULL ? NULL : plp->ctl, plp,
CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_RUNNABLE, arg);
}
#ifndef _WIN32
/*
* pmemlog_ctl_get -- programmatically executes a read ctl query
*/
int
pmemlog_ctl_get(PMEMlogpool *plp, const char *name, void *arg)
{
return pmemlog_ctl_getU(plp, name, arg);
}
/*
* pmemlog_ctl_set -- programmatically executes a write ctl query
*/
int
pmemlog_ctl_set(PMEMlogpool *plp, const char *name, void *arg)
{
return pmemlog_ctl_setU(plp, name, arg);
}
/*
* pmemlog_ctl_exec -- programmatically executes a runnable ctl query
*/
int
pmemlog_ctl_exec(PMEMlogpool *plp, const char *name, void *arg)
{
return pmemlog_ctl_execU(plp, name, arg);
}
#else
/*
* pmemlog_ctl_getW -- programmatically executes a read ctl query
*/
int
pmemlog_ctl_getW(PMEMlogpool *plp, const wchar_t *name, void *arg)
{
char *uname = util_toUTF8(name);
if (uname == NULL)
return -1;
int ret = pmemlog_ctl_getU(plp, uname, arg);
util_free_UTF8(uname);
return ret;
}
/*
* pmemlog_ctl_setW -- programmatically executes a write ctl query
*/
int
pmemlog_ctl_setW(PMEMlogpool *plp, const wchar_t *name, void *arg)
{
char *uname = util_toUTF8(name);
if (uname == NULL)
return -1;
int ret = pmemlog_ctl_setU(plp, uname, arg);
util_free_UTF8(uname);
return ret;
}
/*
* pmemlog_ctl_execW -- programmatically executes a runnable ctl query
*/
int
pmemlog_ctl_execW(PMEMlogpool *plp, const wchar_t *name, void *arg)
{
char *uname = util_toUTF8(name);
if (uname == NULL)
return -1;
int ret = pmemlog_ctl_execU(plp, uname, arg);
util_free_UTF8(uname);
return ret;
}
#endif
| 21,207
| 21.902808
| 75
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/libpmemlog/libpmemlog_main.c
|
/*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libpmemlog_main.c -- entry point for libpmemlog.dll
*
* XXX - This is a placeholder. All the library initialization/cleanup
* that is done in library ctors/dtors, as well as TLS initialization
* should be moved here.
*/
void libpmemlog_init(void);
void libpmemlog_fini(void);
int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
libpmemlog_init();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
libpmemlog_fini();
break;
}
return TRUE;
}
| 2,184
| 34.241935
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/libpmemlog/libpmemlog.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* libpmemlog.c -- pmem entry points for libpmemlog
*/
#include <stdio.h>
#include <stdint.h>
#include "libpmemlog.h"
#include "ctl_global.h"
#include "pmemcommon.h"
#include "log.h"
/*
* The variable from which the config is directly loaded. The string
* cannot contain any comments or extraneous white characters.
*/
#define LOG_CONFIG_ENV_VARIABLE "PMEMLOG_CONF"
/*
* The variable that points to a config file from which the config is loaded.
*/
#define LOG_CONFIG_FILE_ENV_VARIABLE "PMEMLOG_CONF_FILE"
/*
* log_ctl_init_and_load -- (static) initializes CTL and loads configuration
* from env variable and file
*/
static int
log_ctl_init_and_load(PMEMlogpool *plp)
{
LOG(3, "plp %p", plp);
if (plp != NULL && (plp->ctl = ctl_new()) == NULL) {
LOG(2, "!ctl_new");
return -1;
}
char *env_config = os_getenv(LOG_CONFIG_ENV_VARIABLE);
if (env_config != NULL) {
if (ctl_load_config_from_string(plp ? plp->ctl : NULL,
plp, env_config) != 0) {
LOG(2, "unable to parse config stored in %s "
"environment variable",
LOG_CONFIG_ENV_VARIABLE);
goto err;
}
}
char *env_config_file = os_getenv(LOG_CONFIG_FILE_ENV_VARIABLE);
if (env_config_file != NULL && env_config_file[0] != '\0') {
if (ctl_load_config_from_file(plp ? plp->ctl : NULL,
plp, env_config_file) != 0) {
LOG(2, "unable to parse config stored in %s "
"file (from %s environment variable)",
env_config_file,
LOG_CONFIG_FILE_ENV_VARIABLE);
goto err;
}
}
return 0;
err:
if (plp)
ctl_delete(plp->ctl);
return -1;
}
/*
* log_init -- load-time initialization for log
*
* Called automatically by the run-time loader.
*/
ATTR_CONSTRUCTOR
void
libpmemlog_init(void)
{
ctl_global_register();
if (log_ctl_init_and_load(NULL))
FATAL("error: %s", pmemlog_errormsg());
common_init(PMEMLOG_LOG_PREFIX, PMEMLOG_LOG_LEVEL_VAR,
PMEMLOG_LOG_FILE_VAR, PMEMLOG_MAJOR_VERSION,
PMEMLOG_MINOR_VERSION);
LOG(3, NULL);
}
/*
* libpmemlog_fini -- libpmemlog cleanup routine
*
* Called automatically when the process terminates.
*/
ATTR_DESTRUCTOR
void
libpmemlog_fini(void)
{
LOG(3, NULL);
common_fini();
}
/*
* pmemlog_check_versionU -- see if lib meets application version requirements
*/
#ifndef _WIN32
static inline
#endif
const char *
pmemlog_check_versionU(unsigned major_required, unsigned minor_required)
{
LOG(3, "major_required %u minor_required %u",
major_required, minor_required);
if (major_required != PMEMLOG_MAJOR_VERSION) {
ERR("libpmemlog major version mismatch (need %u, found %u)",
major_required, PMEMLOG_MAJOR_VERSION);
return out_get_errormsg();
}
if (minor_required > PMEMLOG_MINOR_VERSION) {
ERR("libpmemlog minor version mismatch (need %u, found %u)",
minor_required, PMEMLOG_MINOR_VERSION);
return out_get_errormsg();
}
return NULL;
}
#ifndef _WIN32
/*
* pmemlog_check_version -- see if lib meets application version requirements
*/
const char *
pmemlog_check_version(unsigned major_required, unsigned minor_required)
{
return pmemlog_check_versionU(major_required, minor_required);
}
#else
/*
* pmemlog_check_versionW -- see if lib meets application version requirements
*/
const wchar_t *
pmemlog_check_versionW(unsigned major_required, unsigned minor_required)
{
if (pmemlog_check_versionU(major_required, minor_required) != NULL)
return out_get_errormsgW();
else
return NULL;
}
#endif
/*
* pmemlog_set_funcs -- allow overriding libpmemlog's call to malloc, etc.
*/
void
pmemlog_set_funcs(
void *(*malloc_func)(size_t size),
void (*free_func)(void *ptr),
void *(*realloc_func)(void *ptr, size_t size),
char *(*strdup_func)(const char *s))
{
LOG(3, NULL);
util_set_alloc_funcs(malloc_func, free_func, realloc_func, strdup_func);
}
/*
* pmemlog_errormsgU -- return last error message
*/
#ifndef _WIN32
static inline
#endif
const char *
pmemlog_errormsgU(void)
{
return out_get_errormsg();
}
#ifndef _WIN32
/*
* pmemlog_errormsg -- return last error message
*/
const char *
pmemlog_errormsg(void)
{
return pmemlog_errormsgU();
}
#else
/*
* pmemlog_errormsgW -- return last error message as wchar_t
*/
const wchar_t *
pmemlog_errormsgW(void)
{
return out_get_errormsgW();
}
#endif
| 5,816
| 24.181818
| 78
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/freebsd/include/endian.h
|
/*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* endian.h -- redirect for FreeBSD <sys/endian.h>
*/
#include <sys/endian.h>
| 1,680
| 43.236842
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/freebsd/include/features.h
|
/*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* features.h -- Empty file redirect
*/
| 1,641
| 44.611111
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/freebsd/include/sys/sysmacros.h
|
/*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* sys/sysmacros.h -- Empty file redirect
*/
| 1,646
| 44.75
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/freebsd/include/linux/kdev_t.h
|
/*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* linux/kdev_t.h -- Empty file redirect
*/
| 1,645
| 44.722222
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/freebsd/include/linux/limits.h
|
/*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* linux/limits.h -- Empty file redirect
*/
| 1,645
| 44.722222
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_dimm_none.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_dimm_none.c -- fake dimm functions
*/
#include "out.h"
#include "os.h"
#include "os_dimm.h"
/*
* os_dimm_uid -- returns empty uid
*/
int
os_dimm_uid(const char *path, char *uid, size_t *len)
{
LOG(3, "path %s, uid %p, len %lu", path, uid, *len);
if (uid == NULL) {
*len = 1;
} else {
*uid = '\0';
}
return 0;
}
/*
* os_dimm_usc -- returns fake unsafe shutdown count
*/
int
os_dimm_usc(const char *path, uint64_t *usc)
{
LOG(3, "path %s, usc %p", path, usc);
*usc = 0;
return 0;
}
/*
* os_dimm_files_namespace_badblocks -- fake os_dimm_files_namespace_badblocks()
*/
int
os_dimm_files_namespace_badblocks(const char *path, struct badblocks *bbs)
{
LOG(3, "path %s", path);
os_stat_t st;
if (os_stat(path, &st)) {
ERR("!stat %s", path);
return -1;
}
return 0;
}
/*
* os_dimm_devdax_clear_badblocks -- fake bad block clearing routine
*/
int
os_dimm_devdax_clear_badblocks(const char *path, struct badblocks *bbs)
{
LOG(3, "path %s badblocks %p", path, bbs);
return 0;
}
/*
* os_dimm_devdax_clear_badblocks_all -- fake bad block clearing routine
*/
int
os_dimm_devdax_clear_badblocks_all(const char *path)
{
LOG(3, "path %s", path);
return 0;
}
| 2,793
| 25.609524
| 80
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/ctl.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ctl.h -- internal declaration of statistics and control related structures
*/
#ifndef PMDK_CTL_H
#define PMDK_CTL_H 1
#include "queue.h"
#include "errno.h"
#include "out.h"
#ifdef __cplusplus
extern "C" {
#endif
struct ctl;
struct ctl_index {
const char *name;
long value;
SLIST_ENTRY(ctl_index) entry;
};
SLIST_HEAD(ctl_indexes, ctl_index);
enum ctl_query_source {
CTL_UNKNOWN_QUERY_SOURCE,
/* query executed directly from the program */
CTL_QUERY_PROGRAMMATIC,
/* query executed from the config file */
CTL_QUERY_CONFIG_INPUT,
MAX_CTL_QUERY_SOURCE
};
enum ctl_query_type {
CTL_QUERY_READ,
CTL_QUERY_WRITE,
CTL_QUERY_RUNNABLE,
MAX_CTL_QUERY_TYPE
};
typedef int (*node_callback)(void *ctx, enum ctl_query_source type,
void *arg, struct ctl_indexes *indexes);
enum ctl_node_type {
CTL_NODE_UNKNOWN,
CTL_NODE_NAMED,
CTL_NODE_LEAF,
CTL_NODE_INDEXED,
MAX_CTL_NODE
};
typedef int (*ctl_arg_parser)(const void *arg, void *dest, size_t dest_size);
struct ctl_argument_parser {
size_t dest_offset; /* offset of the field inside of the argument */
size_t dest_size; /* size of the field inside of the argument */
ctl_arg_parser parser;
};
struct ctl_argument {
size_t dest_size; /* sizeof the entire argument */
struct ctl_argument_parser parsers[]; /* array of 'fields' in arg */
};
#define sizeof_member(t, m) sizeof(((t *)0)->m)
#define CTL_ARG_PARSER(t, p)\
{0, sizeof(t), p}
#define CTL_ARG_PARSER_STRUCT(t, m, p)\
{offsetof(t, m), sizeof_member(t, m), p}
#define CTL_ARG_PARSER_END {0, 0, NULL}
/*
* CTL Tree node structure, do not use directly. All the necessery functionality
* is provided by the included macros.
*/
struct ctl_node {
const char *name;
enum ctl_node_type type;
node_callback cb[MAX_CTL_QUERY_TYPE];
struct ctl_argument *arg;
struct ctl_node *children;
};
struct ctl *ctl_new(void);
void ctl_delete(struct ctl *stats);
int ctl_load_config_from_string(struct ctl *ctl, void *ctx,
const char *cfg_string);
int ctl_load_config_from_file(struct ctl *ctl, void *ctx,
const char *cfg_file);
/* Use through CTL_REGISTER_MODULE, never directly */
void ctl_register_module_node(struct ctl *c,
const char *name, struct ctl_node *n);
int ctl_arg_boolean(const void *arg, void *dest, size_t dest_size);
#define CTL_ARG_BOOLEAN {sizeof(int),\
{{0, sizeof(int), ctl_arg_boolean},\
CTL_ARG_PARSER_END}};
int ctl_arg_integer(const void *arg, void *dest, size_t dest_size);
#define CTL_ARG_INT {sizeof(int),\
{{0, sizeof(int), ctl_arg_integer},\
CTL_ARG_PARSER_END}};
#define CTL_ARG_LONG_LONG {sizeof(long long),\
{{0, sizeof(long long), ctl_arg_integer},\
CTL_ARG_PARSER_END}};
int ctl_arg_string(const void *arg, void *dest, size_t dest_size);
#define CTL_ARG_STRING(len) {len,\
{{0, len, ctl_arg_string},\
CTL_ARG_PARSER_END}};
#define CTL_STR(name) #name
#define CTL_NODE_END {NULL, CTL_NODE_UNKNOWN, {NULL, NULL, NULL}, NULL, NULL}
#define CTL_NODE(name)\
ctl_node_##name
int ctl_query(struct ctl *ctl, void *ctx, enum ctl_query_source source,
const char *name, enum ctl_query_type type, void *arg);
/* Declaration of a new child node */
#define CTL_CHILD(name)\
{CTL_STR(name), CTL_NODE_NAMED, {NULL, NULL, NULL}, NULL,\
(struct ctl_node *)CTL_NODE(name)}
/* Declaration of a new indexed node */
#define CTL_INDEXED(name)\
{CTL_STR(name), CTL_NODE_INDEXED, {NULL, NULL, NULL}, NULL,\
(struct ctl_node *)CTL_NODE(name)}
#define CTL_READ_HANDLER(name)\
ctl_##name##_read
#define CTL_WRITE_HANDLER(name)\
ctl_##name##_write
#define CTL_RUNNABLE_HANDLER(name)\
ctl_##name##_runnable
#define CTL_ARG(name)\
ctl_arg_##name
/*
* Declaration of a new read-only leaf. If used the corresponding read function
* must be declared by CTL_READ_HANDLER macro.
*/
#define CTL_LEAF_RO(name)\
{CTL_STR(name), CTL_NODE_LEAF, {CTL_READ_HANDLER(name), NULL, NULL}, NULL, NULL}
/*
* Declaration of a new write-only leaf. If used the corresponding write
* function must be declared by CTL_WRITE_HANDLER macro.
*/
#define CTL_LEAF_WO(name)\
{CTL_STR(name), CTL_NODE_LEAF, {NULL, CTL_WRITE_HANDLER(name), NULL},\
&CTL_ARG(name), NULL}
/*
* Declaration of a new runnable leaf. If used the corresponding run
* function must be declared by CTL_RUNNABLE_HANDLER macro.
*/
#define CTL_LEAF_RUNNABLE(name)\
{CTL_STR(name), CTL_NODE_LEAF, {NULL, NULL, CTL_RUNNABLE_HANDLER(name)},\
NULL, NULL}
/*
* Declaration of a new read-write leaf. If used both read and write function
* must be declared by CTL_READ_HANDLER and CTL_WRITE_HANDLER macros.
*/
#define CTL_LEAF_RW(name)\
{CTL_STR(name), CTL_NODE_LEAF,\
{CTL_READ_HANDLER(name), CTL_WRITE_HANDLER(name), NULL},\
&CTL_ARG(name), NULL}
#define CTL_REGISTER_MODULE(_ctl, name)\
ctl_register_module_node((_ctl), CTL_STR(name),\
(struct ctl_node *)CTL_NODE(name))
#ifdef __cplusplus
}
#endif
#endif
| 6,437
| 27.113537
| 80
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_windows.c
|
/*
* Copyright 2017-2018, Intel Corporation
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_windows.c -- windows abstraction layer
*/
#include <io.h>
#include <sys/locking.h>
#include <errno.h>
#include <pmemcompat.h>
#include "util.h"
#include "os.h"
#include "out.h"
#define UTF8_BOM "\xEF\xBB\xBF"
/*
* os_open -- open abstraction layer
*/
int
os_open(const char *pathname, int flags, ...)
{
wchar_t *path = util_toUTF16(pathname);
if (path == NULL)
return -1;
int ret;
if (flags & O_CREAT) {
va_list arg;
va_start(arg, flags);
mode_t mode = va_arg(arg, mode_t);
va_end(arg);
ret = _wopen(path, flags, mode);
} else {
ret = _wopen(path, flags);
}
util_free_UTF16(path);
/* BOM skipping should not modify errno */
int orig_errno = errno;
/*
* text files on windows can contain BOM. As we open files
* in binary mode we have to detect bom and skip it
*/
if (ret != -1) {
char bom[3];
if (_read(ret, bom, sizeof(bom)) != 3 ||
memcmp(bom, UTF8_BOM, 3) != 0) {
/* UTF-8 bom not found - reset file to the beginning */
_lseek(ret, 0, SEEK_SET);
}
}
errno = orig_errno;
return ret;
}
/*
* os_fsync -- fsync abstraction layer
*/
int
os_fsync(int fd)
{
HANDLE handle = (HANDLE) _get_osfhandle(fd);
if (handle == INVALID_HANDLE_VALUE) {
errno = EBADF;
return -1;
}
if (!FlushFileBuffers(handle)) {
errno = EINVAL;
return -1;
}
return 0;
}
/*
* os_fsync_dir -- fsync the directory
*/
int
os_fsync_dir(const char *dir_name)
{
/* XXX not used and not implemented */
ASSERT(0);
return -1;
}
/*
* os_stat -- stat abstraction layer
*/
int
os_stat(const char *pathname, os_stat_t *buf)
{
wchar_t *path = util_toUTF16(pathname);
if (path == NULL)
return -1;
int ret = _wstat64(path, buf);
util_free_UTF16(path);
return ret;
}
/*
* os_unlink -- unlink abstraction layer
*/
int
os_unlink(const char *pathname)
{
wchar_t *path = util_toUTF16(pathname);
if (path == NULL)
return -1;
int ret = _wunlink(path);
util_free_UTF16(path);
return ret;
}
/*
* os_access -- access abstraction layer
*/
int
os_access(const char *pathname, int mode)
{
wchar_t *path = util_toUTF16(pathname);
if (path == NULL)
return -1;
int ret = _waccess(path, mode);
util_free_UTF16(path);
return ret;
}
/*
* os_skipBOM -- (internal) Skip BOM in file stream
*
* text files on windows can contain BOM. We have to detect bom and skip it.
*/
static void
os_skipBOM(FILE *file)
{
if (file == NULL)
return;
/* BOM skipping should not modify errno */
int orig_errno = errno;
/* UTF-8 BOM */
uint8_t bom[3];
size_t read_num = fread(bom, sizeof(bom[0]), sizeof(bom), file);
if (read_num != ARRAY_SIZE(bom))
goto out;
if (memcmp(bom, UTF8_BOM, ARRAY_SIZE(bom)) != 0) {
/* UTF-8 bom not found - reset file to the beginning */
fseek(file, 0, SEEK_SET);
}
out:
errno = orig_errno;
}
/*
* os_fopen -- fopen abstraction layer
*/
FILE *
os_fopen(const char *pathname, const char *mode)
{
wchar_t *path = util_toUTF16(pathname);
if (path == NULL)
return NULL;
wchar_t *wmode = util_toUTF16(mode);
if (wmode == NULL) {
util_free_UTF16(path);
return NULL;
}
FILE *ret = _wfopen(path, wmode);
util_free_UTF16(path);
util_free_UTF16(wmode);
os_skipBOM(ret);
return ret;
}
/*
* os_fdopen -- fdopen abstraction layer
*/
FILE *
os_fdopen(int fd, const char *mode)
{
FILE *ret = fdopen(fd, mode);
os_skipBOM(ret);
return ret;
}
/*
* os_chmod -- chmod abstraction layer
*/
int
os_chmod(const char *pathname, mode_t mode)
{
wchar_t *path = util_toUTF16(pathname);
if (path == NULL)
return -1;
int ret = _wchmod(path, mode);
util_free_UTF16(path);
return ret;
}
/*
* os_mkstemp -- generate a unique temporary filename from template
*/
int
os_mkstemp(char *temp)
{
unsigned rnd;
wchar_t *utemp = util_toUTF16(temp);
if (utemp == NULL)
return -1;
wchar_t *path = _wmktemp(utemp);
if (path == NULL) {
util_free_UTF16(utemp);
return -1;
}
wchar_t *npath = Malloc(sizeof(*npath) * wcslen(path) + _MAX_FNAME);
if (npath == NULL) {
util_free_UTF16(utemp);
return -1;
}
wcscpy(npath, path);
util_free_UTF16(utemp);
/*
* Use rand_s to generate more unique tmp file name than _mktemp do.
* In case with multiple threads and multiple files even after close()
* file name conflicts occurred.
* It resolved issue with synchronous removing
* multiples files by system.
*/
rand_s(&rnd);
int ret = _snwprintf(npath + wcslen(npath), _MAX_FNAME, L"%u", rnd);
if (ret < 0)
goto out;
/*
* Use O_TEMPORARY flag to make sure the file is deleted when
* the last file descriptor is closed. Also, it prevents opening
* this file from another process.
*/
ret = _wopen(npath, O_RDWR | O_CREAT | O_EXCL | O_TEMPORARY,
S_IWRITE | S_IREAD);
out:
Free(npath);
return ret;
}
/*
* os_posix_fallocate -- allocate file space
*/
int
os_posix_fallocate(int fd, os_off_t offset, os_off_t len)
{
/*
* From POSIX:
* "EINVAL -- The len argument was zero or the offset argument was
* less than zero."
*
* From Linux man-page:
* "EINVAL -- offset was less than 0, or len was less than or
* equal to 0"
*/
if (offset < 0 || len <= 0)
return EINVAL;
/*
* From POSIX:
* "EFBIG -- The value of offset+len is greater than the maximum
* file size."
*
* Overflow can't be checked for by _chsize_s, since it only gets
* the sum.
*/
if (offset + len < offset)
return EFBIG;
/*
* posix_fallocate should not clobber errno, but
* _filelengthi64 might set errno.
*/
int orig_errno = errno;
__int64 current_size = _filelengthi64(fd);
int file_length_errno = errno;
errno = orig_errno;
if (current_size < 0)
return file_length_errno;
__int64 requested_size = offset + len;
if (requested_size <= current_size)
return 0;
return _chsize_s(fd, requested_size);
}
/*
* os_ftruncate -- truncate a file to a specified length
*/
int
os_ftruncate(int fd, os_off_t length)
{
return _chsize_s(fd, length);
}
/*
* os_flock -- apply or remove an advisory lock on an open file
*/
int
os_flock(int fd, int operation)
{
int flags = 0;
SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);
switch (operation & (OS_LOCK_EX | OS_LOCK_SH | OS_LOCK_UN)) {
case OS_LOCK_EX:
case OS_LOCK_SH:
if (operation & OS_LOCK_NB)
flags = _LK_NBLCK;
else
flags = _LK_LOCK;
break;
case OS_LOCK_UN:
flags = _LK_UNLCK;
break;
default:
errno = EINVAL;
return -1;
}
os_off_t filelen = _filelengthi64(fd);
if (filelen < 0)
return -1;
/* for our purpose it's enough to lock the first page of the file */
long len = (filelen > systemInfo.dwPageSize) ?
systemInfo.dwPageSize : (long)filelen;
int res = _locking(fd, flags, len);
if (res != 0 && errno == EACCES)
errno = EWOULDBLOCK; /* for consistency with flock() */
return res;
}
/*
* os_writev -- windows version of writev function
*
* XXX: _write and other similar functions are 32 bit on windows
* if size of data is bigger then 2^32, this function
* will be not atomic.
*/
ssize_t
os_writev(int fd, const struct iovec *iov, int iovcnt)
{
size_t size = 0;
/* XXX: _write is 32 bit on windows */
for (int i = 0; i < iovcnt; i++)
size += iov[i].iov_len;
void *buf = malloc(size);
if (buf == NULL)
return ENOMEM;
char *it_buf = buf;
for (int i = 0; i < iovcnt; i++) {
memcpy(it_buf, iov[i].iov_base, iov[i].iov_len);
it_buf += iov[i].iov_len;
}
ssize_t written = 0;
while (size > 0) {
int ret = _write(fd, buf, size >= MAXUINT ?
MAXUINT : (unsigned)size);
if (ret == -1) {
written = -1;
break;
}
written += ret;
size -= ret;
}
free(buf);
return written;
}
#define NSEC_IN_SEC 1000000000ull
/* number of useconds between 1970-01-01T00:00:00Z and 1601-01-01T00:00:00Z */
#define DELTA_WIN2UNIX (11644473600000000ull)
/*
* clock_gettime -- returns elapsed time since the system was restarted
* or since Epoch, depending on the mode id
*/
int
os_clock_gettime(int id, struct timespec *ts)
{
switch (id) {
case CLOCK_MONOTONIC:
{
LARGE_INTEGER time;
LARGE_INTEGER frequency;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&time);
ts->tv_sec = time.QuadPart / frequency.QuadPart;
ts->tv_nsec = (long)(
(time.QuadPart % frequency.QuadPart) *
NSEC_IN_SEC / frequency.QuadPart);
}
break;
case CLOCK_REALTIME:
{
FILETIME ctime_ft;
GetSystemTimeAsFileTime(&ctime_ft);
ULARGE_INTEGER ctime = {
.HighPart = ctime_ft.dwHighDateTime,
.LowPart = ctime_ft.dwLowDateTime,
};
ts->tv_sec = (ctime.QuadPart - DELTA_WIN2UNIX * 10)
/ 10000000;
ts->tv_nsec = ((ctime.QuadPart - DELTA_WIN2UNIX * 10)
% 10000000) * 100;
}
break;
default:
SetLastError(EINVAL);
return -1;
}
return 0;
}
/*
* os_setenv -- change or add an environment variable
*/
int
os_setenv(const char *name, const char *value, int overwrite)
{
errno_t err;
/*
* If caller doesn't want to overwrite make sure that a environment
* variable with the same name doesn't exist.
*/
if (!overwrite && getenv(name))
return 0;
/*
* _putenv_s returns a non-zero error code on failure but setenv
* needs to return -1 on failure, let's translate the error code.
*/
if ((err = _putenv_s(name, value)) != 0) {
errno = err;
return -1;
}
return 0;
}
/*
* os_unsetenv -- remove an environment variable
*/
int
os_unsetenv(const char *name)
{
errno_t err;
if ((err = _putenv_s(name, "")) != 0) {
errno = err;
return -1;
}
return 0;
}
/*
* os_getenv -- getenv abstraction layer
*/
char *
os_getenv(const char *name)
{
return getenv(name);
}
/*
* rand_r -- rand_r for windows
*
* XXX: RAND_MAX is equal 0x7fff on Windows, so to get 32 bit random number
* we need to merge two numbers returned by rand_s().
* It is not to the best solution as subsequences returned by rand_s are
* not guaranteed to be independent.
*
* XXX: Windows doesn't implement deterministic thread-safe pseudorandom
* generator (generator which can be initialized by seed ).
* We have to chose between a deterministic nonthread-safe generator
* (rand(), srand()) or a non-deterministic thread-safe generator(rand_s())
* as thread-safety is more important, a seed parameter is ignored in this
* implementation.
*/
unsigned
os_rand_r(unsigned *seedp)
{
UNREFERENCED_PARAMETER(seedp);
unsigned part1, part2;
rand_s(&part1);
rand_s(&part2);
return part1 << 16 | part2;
}
/*
* sys_siglist -- map of signal to human readable messages like sys_siglist
*/
const char * const sys_siglist[] = {
"Unknown signal 0", /* 0 */
"Hangup", /* 1 */
"Interrupt", /* 2 */
"Quit", /* 3 */
"Illegal instruction", /* 4 */
"Trace/breakpoint trap", /* 5 */
"Aborted", /* 6 */
"Bus error", /* 7 */
"Floating point exception", /* 8 */
"Killed", /* 9 */
"User defined signal 1", /* 10 */
"Segmentation fault", /* 11 */
"User defined signal 2", /* 12 */
"Broken pipe", /* 13 */
"Alarm clock", /* 14 */
"Terminated", /* 15 */
"Stack fault", /* 16 */
"Child exited", /* 17 */
"Continued", /* 18 */
"Stopped (signal)", /* 19 */
"Stopped", /* 20 */
"Stopped (tty input)", /* 21 */
"Stopped (tty output)", /* 22 */
"Urgent I/O condition", /* 23 */
"CPU time limit exceeded", /* 24 */
"File size limit exceeded", /* 25 */
"Virtual timer expired", /* 26 */
"Profiling timer expired", /* 27 */
"Window changed", /* 28 */
"I/O possible", /* 29 */
"Power failure", /* 30 */
"Bad system call", /* 31 */
"Unknown signal 32" /* 32 */
};
int sys_siglist_size = ARRAYSIZE(sys_siglist);
/*
* string constants for strsignal
* XXX: ideally this should have the signal number as the suffix but then we
* should use a buffer from thread local storage, so deferring the same till
* we need it
* NOTE: In Linux strsignal uses TLS for the same reason but if it fails to get
* a thread local buffer it falls back to using a static buffer trading the
* thread safety.
*/
#define STR_REALTIME_SIGNAL "Real-time signal"
#define STR_UNKNOWN_SIGNAL "Unknown signal"
/*
* strsignal -- returns a string describing the signal number 'sig'
*
* XXX: According to POSIX, this one is of type 'char *', but in our
* implementation it returns 'const char *'.
*/
const char *
os_strsignal(int sig)
{
if (sig >= 0 && sig < ARRAYSIZE(sys_siglist))
return sys_siglist[sig];
else if (sig >= 34 && sig <= 64)
return STR_REALTIME_SIGNAL;
else
return STR_UNKNOWN_SIGNAL;
}
int
os_execv(const char *path, char *const argv[])
{
wchar_t *wpath = util_toUTF16(path);
if (wpath == NULL)
return -1;
int argc = 0;
while (argv[argc])
argc++;
int ret;
wchar_t **wargv = Zalloc((argc + 1) * sizeof(wargv[0]));
if (!wargv) {
ret = -1;
goto wargv_alloc_failed;
}
for (int i = 0; i < argc; ++i) {
wargv[i] = util_toUTF16(argv[i]);
if (!wargv[i]) {
ret = -1;
goto end;
}
}
intptr_t iret = _wexecv(wpath, wargv);
if (iret == 0)
ret = 0;
else
ret = -1;
end:
for (int i = 0; i < argc; ++i)
util_free_UTF16(wargv[i]);
Free(wargv);
wargv_alloc_failed:
util_free_UTF16(wpath);
return ret;
}
| 14,725
| 20.655882
| 79
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_deep.h
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_deep.h -- abstraction layer for common usage of deep_* functions
*/
#ifndef PMDK_OS_DEEP_PERSIST_H
#define PMDK_OS_DEEP_PERSIST_H 1
#include <stdint.h>
#include <stddef.h>
#include "set.h"
#ifdef __cplusplus
extern "C" {
#endif
int os_range_deep_common(uintptr_t addr, size_t len);
int os_part_deep_common(struct pool_replica *rep, unsigned partidx, void *addr,
size_t len, int flush);
#ifdef __cplusplus
}
#endif
#endif
| 2,042
| 34.842105
| 79
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_thread_posix.c
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_thread_posix.c -- Posix thread abstraction layer
*/
#define _GNU_SOURCE
#include <pthread.h>
#ifdef __FreeBSD__
#include <pthread_np.h>
#endif
#include <semaphore.h>
#include "os_thread.h"
#include "util.h"
typedef struct {
pthread_t thread;
} internal_os_thread_t;
/*
* os_once -- pthread_once abstraction layer
*/
int
os_once(os_once_t *o, void (*func)(void))
{
COMPILE_ERROR_ON(sizeof(os_once_t) < sizeof(pthread_once_t));
return pthread_once((pthread_once_t *)o, func);
}
/*
* os_tls_key_create -- pthread_key_create abstraction layer
*/
int
os_tls_key_create(os_tls_key_t *key, void (*destructor)(void *))
{
COMPILE_ERROR_ON(sizeof(os_tls_key_t) < sizeof(pthread_key_t));
return pthread_key_create((pthread_key_t *)key, destructor);
}
/*
* os_tls_key_delete -- pthread_key_delete abstraction layer
*/
int
os_tls_key_delete(os_tls_key_t key)
{
return pthread_key_delete((pthread_key_t)key);
}
/*
* os_tls_setspecific -- pthread_key_setspecific abstraction layer
*/
int
os_tls_set(os_tls_key_t key, const void *value)
{
return pthread_setspecific((pthread_key_t)key, value);
}
/*
* os_tls_get -- pthread_key_getspecific abstraction layer
*/
void *
os_tls_get(os_tls_key_t key)
{
return pthread_getspecific((pthread_key_t)key);
}
/*
* os_mutex_init -- pthread_mutex_init abstraction layer
*/
int
os_mutex_init(os_mutex_t *__restrict mutex)
{
COMPILE_ERROR_ON(sizeof(os_mutex_t) < sizeof(pthread_mutex_t));
return pthread_mutex_init((pthread_mutex_t *)mutex, NULL);
}
/*
* os_mutex_destroy -- pthread_mutex_destroy abstraction layer
*/
int
os_mutex_destroy(os_mutex_t *__restrict mutex)
{
return pthread_mutex_destroy((pthread_mutex_t *)mutex);
}
/*
* os_mutex_lock -- pthread_mutex_lock abstraction layer
*/
int
os_mutex_lock(os_mutex_t *__restrict mutex)
{
return pthread_mutex_lock((pthread_mutex_t *)mutex);
}
/*
* os_mutex_trylock -- pthread_mutex_trylock abstraction layer
*/
int
os_mutex_trylock(os_mutex_t *__restrict mutex)
{
return pthread_mutex_trylock((pthread_mutex_t *)mutex);
}
/*
* os_mutex_unlock -- pthread_mutex_unlock abstraction layer
*/
int
os_mutex_unlock(os_mutex_t *__restrict mutex)
{
return pthread_mutex_unlock((pthread_mutex_t *)mutex);
}
/*
* os_mutex_timedlock -- pthread_mutex_timedlock abstraction layer
*/
int
os_mutex_timedlock(os_mutex_t *__restrict mutex,
const struct timespec *abstime)
{
return pthread_mutex_timedlock((pthread_mutex_t *)mutex, abstime);
}
/*
* os_rwlock_init -- pthread_rwlock_init abstraction layer
*/
int
os_rwlock_init(os_rwlock_t *__restrict rwlock)
{
COMPILE_ERROR_ON(sizeof(os_rwlock_t) < sizeof(pthread_rwlock_t));
return pthread_rwlock_init((pthread_rwlock_t *)rwlock, NULL);
}
/*
* os_rwlock_destroy -- pthread_rwlock_destroy abstraction layer
*/
int
os_rwlock_destroy(os_rwlock_t *__restrict rwlock)
{
return pthread_rwlock_destroy((pthread_rwlock_t *)rwlock);
}
/*
* os_rwlock_rdlock - pthread_rwlock_rdlock abstraction layer
*/
int
os_rwlock_rdlock(os_rwlock_t *__restrict rwlock)
{
return pthread_rwlock_rdlock((pthread_rwlock_t *)rwlock);
}
/*
* os_rwlock_wrlock -- pthread_rwlock_wrlock abstraction layer
*/
int
os_rwlock_wrlock(os_rwlock_t *__restrict rwlock)
{
return pthread_rwlock_wrlock((pthread_rwlock_t *)rwlock);
}
/*
* os_rwlock_unlock -- pthread_rwlock_unlock abstraction layer
*/
int
os_rwlock_unlock(os_rwlock_t *__restrict rwlock)
{
return pthread_rwlock_unlock((pthread_rwlock_t *)rwlock);
}
/*
* os_rwlock_tryrdlock -- pthread_rwlock_tryrdlock abstraction layer
*/
int
os_rwlock_tryrdlock(os_rwlock_t *__restrict rwlock)
{
return pthread_rwlock_tryrdlock((pthread_rwlock_t *)rwlock);
}
/*
* os_rwlock_tryrwlock -- pthread_rwlock_trywrlock abstraction layer
*/
int
os_rwlock_trywrlock(os_rwlock_t *__restrict rwlock)
{
return pthread_rwlock_trywrlock((pthread_rwlock_t *)rwlock);
}
/*
* os_rwlock_timedrdlock -- pthread_rwlock_timedrdlock abstraction layer
*/
int
os_rwlock_timedrdlock(os_rwlock_t *__restrict rwlock,
const struct timespec *abstime)
{
return pthread_rwlock_timedrdlock((pthread_rwlock_t *)rwlock, abstime);
}
/*
* os_rwlock_timedwrlock -- pthread_rwlock_timedwrlock abstraction layer
*/
int
os_rwlock_timedwrlock(os_rwlock_t *__restrict rwlock,
const struct timespec *abstime)
{
return pthread_rwlock_timedwrlock((pthread_rwlock_t *)rwlock, abstime);
}
/*
* os_spin_init -- pthread_spin_init abstraction layer
*/
int
os_spin_init(os_spinlock_t *lock, int pshared)
{
COMPILE_ERROR_ON(sizeof(os_spinlock_t) < sizeof(pthread_spinlock_t));
return pthread_spin_init((pthread_spinlock_t *)lock, pshared);
}
/*
* os_spin_destroy -- pthread_spin_destroy abstraction layer
*/
int
os_spin_destroy(os_spinlock_t *lock)
{
return pthread_spin_destroy((pthread_spinlock_t *)lock);
}
/*
* os_spin_lock -- pthread_spin_lock abstraction layer
*/
int
os_spin_lock(os_spinlock_t *lock)
{
return pthread_spin_lock((pthread_spinlock_t *)lock);
}
/*
* os_spin_unlock -- pthread_spin_unlock abstraction layer
*/
int
os_spin_unlock(os_spinlock_t *lock)
{
return pthread_spin_unlock((pthread_spinlock_t *)lock);
}
/*
* os_spin_trylock -- pthread_spin_trylock abstraction layer
*/
int
os_spin_trylock(os_spinlock_t *lock)
{
return pthread_spin_trylock((pthread_spinlock_t *)lock);
}
/*
* os_cond_init -- pthread_cond_init abstraction layer
*/
int
os_cond_init(os_cond_t *__restrict cond)
{
COMPILE_ERROR_ON(sizeof(os_cond_t) < sizeof(pthread_cond_t));
return pthread_cond_init((pthread_cond_t *)cond, NULL);
}
/*
* os_cond_destroy -- pthread_cond_destroy abstraction layer
*/
int
os_cond_destroy(os_cond_t *__restrict cond)
{
return pthread_cond_destroy((pthread_cond_t *)cond);
}
/*
* os_cond_broadcast -- pthread_cond_broadcast abstraction layer
*/
int
os_cond_broadcast(os_cond_t *__restrict cond)
{
return pthread_cond_broadcast((pthread_cond_t *)cond);
}
/*
* os_cond_signal -- pthread_cond_signal abstraction layer
*/
int
os_cond_signal(os_cond_t *__restrict cond)
{
return pthread_cond_signal((pthread_cond_t *)cond);
}
/*
* os_cond_timedwait -- pthread_cond_timedwait abstraction layer
*/
int
os_cond_timedwait(os_cond_t *__restrict cond,
os_mutex_t *__restrict mutex, const struct timespec *abstime)
{
return pthread_cond_timedwait((pthread_cond_t *)cond,
(pthread_mutex_t *)mutex, abstime);
}
/*
* os_cond_wait -- pthread_cond_wait abstraction layer
*/
int
os_cond_wait(os_cond_t *__restrict cond,
os_mutex_t *__restrict mutex)
{
return pthread_cond_wait((pthread_cond_t *)cond,
(pthread_mutex_t *)mutex);
}
/*
* os_thread_create -- pthread_create abstraction layer
*/
int
os_thread_create(os_thread_t *thread, const os_thread_attr_t *attr,
void *(*start_routine)(void *), void *arg)
{
COMPILE_ERROR_ON(sizeof(os_thread_t) < sizeof(internal_os_thread_t));
internal_os_thread_t *thread_info = (internal_os_thread_t *)thread;
return pthread_create(&thread_info->thread, (pthread_attr_t *)attr,
start_routine, arg);
}
/*
* os_thread_join -- pthread_join abstraction layer
*/
int
os_thread_join(os_thread_t *thread, void **result)
{
internal_os_thread_t *thread_info = (internal_os_thread_t *)thread;
return pthread_join(thread_info->thread, result);
}
/*
* os_thread_self -- pthread_self abstraction layer
*/
void
os_thread_self(os_thread_t *thread)
{
internal_os_thread_t *thread_info = (internal_os_thread_t *)thread;
thread_info->thread = pthread_self();
}
/*
* os_thread_atfork -- pthread_atfork abstraction layer
*/
int
os_thread_atfork(void (*prepare)(void), void (*parent)(void),
void (*child)(void))
{
return pthread_atfork(prepare, parent, child);
}
/*
* os_thread_setaffinity_np -- pthread_atfork abstraction layer
*/
int
os_thread_setaffinity_np(os_thread_t *thread, size_t set_size,
const os_cpu_set_t *set)
{
COMPILE_ERROR_ON(sizeof(os_cpu_set_t) < sizeof(cpu_set_t));
internal_os_thread_t *thread_info = (internal_os_thread_t *)thread;
return pthread_setaffinity_np(thread_info->thread, set_size,
(cpu_set_t *)set);
}
/*
* os_cpu_zero -- CP_ZERO abstraction layer
*/
void
os_cpu_zero(os_cpu_set_t *set)
{
CPU_ZERO((cpu_set_t *)set);
}
/*
* os_cpu_set -- CP_SET abstraction layer
*/
void
os_cpu_set(size_t cpu, os_cpu_set_t *set)
{
CPU_SET(cpu, (cpu_set_t *)set);
}
/*
* os_semaphore_init -- initializes semaphore instance
*/
int
os_semaphore_init(os_semaphore_t *sem, unsigned value)
{
COMPILE_ERROR_ON(sizeof(os_semaphore_t) < sizeof(sem_t));
return sem_init((sem_t *)sem, 0, value);
}
/*
* os_semaphore_destroy -- destroys a semaphore instance
*/
int
os_semaphore_destroy(os_semaphore_t *sem)
{
return sem_destroy((sem_t *)sem);
}
/*
* os_semaphore_wait -- decreases the value of the semaphore
*/
int
os_semaphore_wait(os_semaphore_t *sem)
{
return sem_wait((sem_t *)sem);
}
/*
* os_semaphore_trywait -- tries to decrease the value of the semaphore
*/
int
os_semaphore_trywait(os_semaphore_t *sem)
{
return sem_trywait((sem_t *)sem);
}
/*
* os_semaphore_post -- increases the value of the semaphore
*/
int
os_semaphore_post(os_semaphore_t *sem)
{
return sem_post((sem_t *)sem);
}
| 10,705
| 21.974249
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/ctl_global.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ctl_global.h -- definitions for the global CTL namespace
*/
#ifndef PMDK_CTL_GLOBAL_H
#define PMDK_CTL_GLOBAL_H 1
#ifdef __cplusplus
extern "C" {
#endif
void ctl_global_register(void);
#ifdef __cplusplus
}
#endif
#endif
| 1,834
| 34.980392
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/file.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* file.h -- internal definitions for file module
*/
#ifndef PMDK_FILE_H
#define PMDK_FILE_H 1
#include <stddef.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <limits.h>
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
#define NAME_MAX _MAX_FNAME
#endif
struct file_info {
char filename[NAME_MAX + 1];
int is_dir;
};
struct dir_handle {
const char *path;
#ifdef _WIN32
HANDLE handle;
char *_file;
#else
DIR *dirp;
#endif
};
enum file_type {
OTHER_ERROR = -2,
NOT_EXISTS = -1,
TYPE_NORMAL = 1,
TYPE_DEVDAX = 2
};
int util_file_dir_open(struct dir_handle *a, const char *path);
int util_file_dir_next(struct dir_handle *a, struct file_info *info);
int util_file_dir_close(struct dir_handle *a);
int util_file_dir_remove(const char *path);
int util_file_exists(const char *path);
enum file_type util_fd_get_type(int fd);
enum file_type util_file_get_type(const char *path);
int util_ddax_region_find(const char *path);
ssize_t util_file_get_size(const char *path);
size_t util_file_device_dax_alignment(const char *path);
void *util_file_map_whole(const char *path);
int util_file_zero(const char *path, os_off_t off, size_t len);
ssize_t util_file_pread(const char *path, void *buffer, size_t size,
os_off_t offset);
ssize_t util_file_pwrite(const char *path, const void *buffer, size_t size,
os_off_t offset);
int util_tmpfile(const char *dir, const char *templ, int flags);
int util_is_absolute_path(const char *path);
int util_file_create(const char *path, size_t size, size_t minsize);
int util_file_open(const char *path, size_t *size, size_t minsize, int flags);
int util_unlink(const char *path);
int util_unlink_flock(const char *path);
int util_file_mkdir(const char *path, mode_t mode);
int util_write_all(int fd, const char *buf, size_t count);
#ifndef _WIN32
#define util_read read
#define util_write write
#else
/* XXX - consider adding an assertion on (count <= UINT_MAX) */
#define util_read(fd, buf, count) read(fd, buf, (unsigned)(count))
#define util_write(fd, buf, count) write(fd, buf, (unsigned)(count))
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
#ifdef __cplusplus
}
#endif
#endif
| 3,839
| 31.268908
| 78
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/uuid_freebsd.c
|
/*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* uuid_freebsd.c -- FreeBSD-specific implementation for UUID generation
*/
#include "uuid.h"
/* XXX Can't include <uuid/uuid.h> because it also defines uuid_t */
void uuid_generate(uuid_t);
/*
* util_uuid_generate -- generate a uuid
*
* Uses the available FreeBSD uuid_generate library function.
*/
int
util_uuid_generate(uuid_t uuid)
{
uuid_generate(uuid);
return 0;
}
| 1,987
| 35.814815
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/file_posix.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* file_posix.c -- Posix versions of file APIs
*/
/* for O_TMPFILE */
#define _GNU_SOURCE
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
#include "os.h"
#include "file.h"
#include "out.h"
#define MAX_SIZE_LENGTH 64
#define DAX_REGION_ID_LEN 6 /* 5 digits + \0 */
/*
* util_tmpfile_mkstemp -- (internal) create temporary file
* if O_TMPFILE not supported
*/
static int
util_tmpfile_mkstemp(const char *dir, const char *templ)
{
/* the templ must start with a path separator */
ASSERTeq(templ[0], '/');
int oerrno;
int fd = -1;
char *fullname = alloca(strlen(dir) + strlen(templ) + 1);
(void) strcpy(fullname, dir);
(void) strcat(fullname, templ);
sigset_t set, oldset;
sigfillset(&set);
(void) sigprocmask(SIG_BLOCK, &set, &oldset);
mode_t prev_umask = umask(S_IRWXG | S_IRWXO);
fd = os_mkstemp(fullname);
umask(prev_umask);
if (fd < 0) {
ERR("!mkstemp");
goto err;
}
(void) os_unlink(fullname);
(void) sigprocmask(SIG_SETMASK, &oldset, NULL);
LOG(3, "unlinked file is \"%s\"", fullname);
return fd;
err:
oerrno = errno;
(void) sigprocmask(SIG_SETMASK, &oldset, NULL);
if (fd != -1)
(void) os_close(fd);
errno = oerrno;
return -1;
}
/*
* util_tmpfile -- create temporary file
*/
int
util_tmpfile(const char *dir, const char *templ, int flags)
{
LOG(3, "dir \"%s\" template \"%s\" flags %x", dir, templ, flags);
/* only O_EXCL is allowed here */
ASSERT(flags == 0 || flags == O_EXCL);
#ifdef O_TMPFILE
int fd = open(dir, O_TMPFILE | O_RDWR | flags, S_IRUSR | S_IWUSR);
/*
* Open can fail if underlying file system does not support O_TMPFILE
* flag.
*/
if (fd >= 0)
return fd;
if (errno != EOPNOTSUPP) {
ERR("!open");
return -1;
}
#endif
return util_tmpfile_mkstemp(dir, templ);
}
/*
* util_is_absolute_path -- check if the path is an absolute one
*/
int
util_is_absolute_path(const char *path)
{
LOG(3, "path: %s", path);
if (path[0] == OS_DIR_SEPARATOR)
return 1;
else
return 0;
}
/*
* util_create_mkdir -- creates new dir
*/
int
util_file_mkdir(const char *path, mode_t mode)
{
LOG(3, "path: %s mode: %o", path, mode);
return mkdir(path, mode);
}
/*
* util_file_dir_open -- open a directory
*/
int
util_file_dir_open(struct dir_handle *handle, const char *path)
{
LOG(3, "handle: %p path: %s", handle, path);
handle->dirp = opendir(path);
return handle->dirp == NULL;
}
/*
* util_file_dir_next -- read next file in directory
*/
int
util_file_dir_next(struct dir_handle *handle, struct file_info *info)
{
LOG(3, "handle: %p info: %p", handle, info);
struct dirent *d = readdir(handle->dirp);
if (d == NULL)
return 1; /* break */
info->filename[NAME_MAX] = '\0';
strncpy(info->filename, d->d_name, NAME_MAX + 1);
if (info->filename[NAME_MAX] != '\0')
return -1; /* filename truncated */
info->is_dir = d->d_type == DT_DIR;
return 0; /* continue */
}
/*
* util_file_dir_close -- close a directory
*/
int
util_file_dir_close(struct dir_handle *handle)
{
LOG(3, "path: %p", handle);
return closedir(handle->dirp);
}
/*
* util_file_dir_remove -- remove directory
*/
int
util_file_dir_remove(const char *path)
{
LOG(3, "path: %s", path);
return rmdir(path);
}
/*
* device_dax_alignment -- (internal) checks the alignment of given Device DAX
*/
static size_t
device_dax_alignment(const char *path)
{
LOG(3, "path \"%s\"", path);
os_stat_t st;
int olderrno;
if (os_stat(path, &st) < 0) {
ERR("!stat \"%s\"", path);
return 0;
}
char spath[PATH_MAX];
snprintf(spath, PATH_MAX, "/sys/dev/char/%u:%u/device/align",
os_major(st.st_rdev), os_minor(st.st_rdev));
LOG(4, "device align path \"%s\"", spath);
int fd = os_open(spath, O_RDONLY);
if (fd < 0) {
ERR("!open \"%s\"", spath);
return 0;
}
size_t size = 0;
char sizebuf[MAX_SIZE_LENGTH + 1];
ssize_t nread;
if ((nread = read(fd, sizebuf, MAX_SIZE_LENGTH)) < 0) {
ERR("!read");
goto out;
}
sizebuf[nread] = 0; /* null termination */
char *endptr;
olderrno = errno;
errno = 0;
/* 'align' is in decimal format */
size = strtoull(sizebuf, &endptr, 10);
if (endptr == sizebuf || *endptr != '\n' ||
(size == ULLONG_MAX && errno == ERANGE)) {
ERR("invalid device alignment %s", sizebuf);
size = 0;
goto out;
}
/*
* If the alignment value is not a power of two, try with
* hex format, as this is how it was printed in older kernels.
* Just in case someone is using kernel <4.9.
*/
if ((size & (size - 1)) != 0) {
size = strtoull(sizebuf, &endptr, 16);
if (endptr == sizebuf || *endptr != '\n' ||
(size == ULLONG_MAX && errno == ERANGE)) {
ERR("invalid device alignment %s", sizebuf);
size = 0;
goto out;
}
}
errno = olderrno;
out:
olderrno = errno;
(void) os_close(fd);
errno = olderrno;
LOG(4, "device alignment %zu", size);
return size;
}
/*
* util_file_device_dax_alignment -- returns internal Device DAX alignment
*/
size_t
util_file_device_dax_alignment(const char *path)
{
LOG(3, "path \"%s\"", path);
return device_dax_alignment(path);
}
/*
* util_ddax_region_find -- returns Device DAX region id
*/
int
util_ddax_region_find(const char *path)
{
LOG(3, "path \"%s\"", path);
int dax_reg_id_fd;
char dax_region_path[PATH_MAX];
char reg_id[DAX_REGION_ID_LEN];
char *end_addr;
os_stat_t st;
ASSERTne(path, NULL);
if (os_stat(path, &st) < 0) {
ERR("!stat \"%s\"", path);
return -1;
}
dev_t dev_id = st.st_rdev;
unsigned major = os_major(dev_id);
unsigned minor = os_minor(dev_id);
int ret = snprintf(dax_region_path, PATH_MAX,
"/sys/dev/char/%u:%u/device/dax_region/id",
major, minor);
if (ret < 0) {
ERR("snprintf(%p, %d, /sys/dev/char/%u:%u/device/"
"dax_region/id, %u, %u): %d",
dax_region_path, PATH_MAX, major, minor, major, minor,
ret);
return -1;
}
if ((dax_reg_id_fd = os_open(dax_region_path, O_RDONLY)) < 0) {
LOG(1, "!open(\"%s\", O_RDONLY)", dax_region_path);
return -1;
}
ssize_t len = read(dax_reg_id_fd, reg_id, DAX_REGION_ID_LEN);
if (len == -1) {
ERR("!read(%d, %p, %d)", dax_reg_id_fd,
reg_id, DAX_REGION_ID_LEN);
goto err;
} else if (len < 2 || reg_id[len - 1] != '\n') {
errno = EINVAL;
ERR("!read(%d, %p, %d) invalid format", dax_reg_id_fd,
reg_id, DAX_REGION_ID_LEN);
goto err;
}
int olderrno = errno;
errno = 0;
long reg_num = strtol(reg_id, &end_addr, 10);
if ((errno == ERANGE && (reg_num == LONG_MAX || reg_num == LONG_MIN)) ||
(errno != 0 && reg_num == 0)) {
ERR("!strtol(%p, %p, 10)", reg_id, end_addr);
goto err;
}
errno = olderrno;
if (end_addr == reg_id) {
ERR("!strtol(%p, %p, 10) no digits were found",
reg_id, end_addr);
goto err;
}
if (*end_addr != '\n') {
ERR("!strtol(%s, %s, 10) invalid format",
reg_id, end_addr);
goto err;
}
os_close(dax_reg_id_fd);
return (int)reg_num;
err:
os_close(dax_reg_id_fd);
return -1;
}
| 8,608
| 21.835544
| 78
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/util_pmem.h
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_pmem.h -- internal definitions for pmem utils
*/
#ifndef PMDK_UTIL_PMEM_H
#define PMDK_UTIL_PMEM_H 1
#include "libpmem.h"
#include "out.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* util_persist -- flush to persistence
*/
static inline void
util_persist(int is_pmem, const void *addr, size_t len)
{
LOG(3, "is_pmem %d, addr %p, len %zu", is_pmem, addr, len);
if (is_pmem)
pmem_persist(addr, len);
else if (pmem_msync(addr, len))
FATAL("!pmem_msync");
}
/*
* util_persist_auto -- flush to persistence
*/
static inline void
util_persist_auto(int is_pmem, const void *addr, size_t len)
{
LOG(3, "is_pmem %d, addr %p, len %zu", is_pmem, addr, len);
util_persist(is_pmem || pmem_is_pmem(addr, len), addr, len);
}
#ifdef __cplusplus
}
#endif
#endif /* util_pmem.h */
| 2,398
| 30.155844
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/util_posix.c
|
/*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_posix.c -- Abstraction layer for misc utilities (Posix implementation)
*/
#include <string.h>
#include <util.h>
#include <limits.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
#include "os.h"
#include "out.h"
/* pass through for Posix */
void
util_strerror(int errnum, char *buff, size_t bufflen)
{
strerror_r(errnum, buff, bufflen);
}
/*
* util_part_realpath -- get canonicalized absolute pathname
*
* As paths used in a poolset file have to be absolute (checked when parsing
* a poolset file), here we only have to resolve symlinks.
*/
char *
util_part_realpath(const char *path)
{
return realpath(path, NULL);
}
/*
* util_compare_file_inodes -- compare device and inodes of two files;
* this resolves hard links
*/
int
util_compare_file_inodes(const char *path1, const char *path2)
{
struct stat sb1, sb2;
if (os_stat(path1, &sb1)) {
if (errno != ENOENT) {
ERR("!stat failed for %s", path1);
return -1;
}
LOG(1, "stat failed for %s", path1);
errno = 0;
return strcmp(path1, path2) != 0;
}
if (os_stat(path2, &sb2)) {
if (errno != ENOENT) {
ERR("!stat failed for %s", path2);
return -1;
}
LOG(1, "stat failed for %s", path2);
errno = 0;
return strcmp(path1, path2) != 0;
}
return sb1.st_dev != sb2.st_dev || sb1.st_ino != sb2.st_ino;
}
/*
* util_aligned_malloc -- allocate aligned memory
*/
void *
util_aligned_malloc(size_t alignment, size_t size)
{
void *retval = NULL;
errno = posix_memalign(&retval, alignment, size);
return retval;
}
/*
* util_aligned_free -- free allocated memory in util_aligned_malloc
*/
void
util_aligned_free(void *ptr)
{
free(ptr);
}
/*
* util_getexecname -- return name of current executable
*/
char *
util_getexecname(char *path, size_t pathlen)
{
ssize_t cc;
#ifdef __FreeBSD__
#include <sys/types.h>
#include <sys/sysctl.h>
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
cc = (sysctl(mib, 4, path, &pathlen, NULL, 0) == -1) ?
-1 : (ssize_t)pathlen;
#else
cc = readlink("/proc/self/exe", path, pathlen);
#endif
if (cc == -1)
strcpy(path, "unknown");
else
path[cc] = '\0';
return path;
}
| 3,778
| 25.243056
| 78
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/pmemcommon.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pmemcommon.h -- definitions for "common" module
*/
#ifndef PMEMCOMMON_H
#define PMEMCOMMON_H 1
#include "util.h"
#include "out.h"
#include "mmap.h"
#ifdef __cplusplus
extern "C" {
#endif
static inline void
common_init(const char *log_prefix, const char *log_level_var,
const char *log_file_var, int major_version,
int minor_version)
{
util_init();
out_init(log_prefix, log_level_var, log_file_var, major_version,
minor_version);
util_mmap_init();
}
static inline void
common_fini(void)
{
util_mmap_fini();
out_fini();
}
#ifdef __cplusplus
}
#endif
#endif
| 2,182
| 29.746479
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/badblock_linux.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* badblock_linux.c - implementation of the linux bad block API
*/
#define _GNU_SOURCE
#include <fcntl.h>
#include <linux/falloc.h>
#include "file.h"
#include "os.h"
#include "out.h"
#include "extent.h"
#include "os_dimm.h"
#include "os_badblock.h"
#include "badblock.h"
#include "vec.h"
/*
* os_badblocks_get -- returns 0 and bad blocks in the 'bbs' array
* (that has to be pre-allocated)
* or -1 in case of an error
*/
int
os_badblocks_get(const char *file, struct badblocks *bbs)
{
LOG(3, "file %s badblocks %p", file, bbs);
ASSERTne(bbs, NULL);
VEC(bbsvec, struct bad_block) bbv = VEC_INITIALIZER;
struct extents *exts = NULL;
long extents = 0;
unsigned long long bb_beg;
unsigned long long bb_end;
unsigned long long bb_len;
unsigned long long bb_off;
unsigned long long ext_beg;
unsigned long long ext_end;
unsigned long long not_block_aligned;
int bb_found = -1; /* -1 means an error */
memset(bbs, 0, sizeof(*bbs));
if (os_dimm_files_namespace_badblocks(file, bbs)) {
LOG(1, "checking the file for bad blocks failed -- '%s'", file);
goto error_free_all;
}
if (bbs->bb_cnt == 0) {
bb_found = 0;
goto exit_free_all;
}
exts = Zalloc(sizeof(struct extents));
if (exts == NULL) {
ERR("!Zalloc");
goto error_free_all;
}
extents = os_extents_count(file, exts);
if (extents < 0) {
LOG(1, "counting file's extents failed -- '%s'", file);
goto error_free_all;
}
if (extents == 0) {
/* dax device has no extents */
bb_found = (int)bbs->bb_cnt;
for (unsigned b = 0; b < bbs->bb_cnt; b++) {
LOG(4, "bad block found: offset: %llu, length: %u",
bbs->bbv[b].offset,
bbs->bbv[b].length);
}
goto exit_free_all;
}
exts->extents = Zalloc(exts->extents_count * sizeof(struct extent));
if (exts->extents == NULL) {
ERR("!Zalloc");
goto error_free_all;
}
if (os_extents_get(file, exts)) {
LOG(1, "getting file's extents failed -- '%s'", file);
goto error_free_all;
}
bb_found = 0;
for (unsigned b = 0; b < bbs->bb_cnt; b++) {
bb_beg = bbs->bbv[b].offset;
bb_end = bb_beg + bbs->bbv[b].length - 1;
for (unsigned e = 0; e < exts->extents_count; e++) {
ext_beg = exts->extents[e].offset_physical;
ext_end = ext_beg + exts->extents[e].length - 1;
/* check if the bad block overlaps with file's extent */
if (bb_beg > ext_end || ext_beg > bb_end)
continue;
bb_found++;
bb_beg = (bb_beg > ext_beg) ? bb_beg : ext_beg;
bb_end = (bb_end < ext_end) ? bb_end : ext_end;
bb_len = bb_end - bb_beg + 1;
bb_off = bb_beg + exts->extents[e].offset_logical
- exts->extents[e].offset_physical;
/* check if offset is block-aligned */
not_block_aligned = bb_off & (exts->blksize - 1);
if (not_block_aligned) {
bb_off -= not_block_aligned;
bb_len += not_block_aligned;
}
/* check if length is block-aligned */
bb_len = ALIGN_UP(bb_len, exts->blksize);
LOG(4, "bad block found: offset: %llu, length: %llu",
bb_off, bb_len);
/*
* Form a new bad block structure with offset and length
* expressed in bytes and offset relative
* to the beginning of the file.
*/
struct bad_block bb;
bb.offset = bb_off;
bb.length = (unsigned)(bb_len);
/* unknown healthy replica */
bb.nhealthy = NO_HEALTHY_REPLICA;
/* add the new bad block to the vector */
if (VEC_PUSH_BACK(&bbv, bb)) {
VEC_DELETE(&bbv);
bb_found = -1;
goto error_free_all;
}
}
}
error_free_all:
Free(bbs->bbv);
bbs->bbv = NULL;
bbs->bb_cnt = 0;
exit_free_all:
if (exts) {
Free(exts->extents);
Free(exts);
}
if (extents > 0 && bb_found > 0) {
bbs->bbv = VEC_ARR(&bbv);
bbs->bb_cnt = (unsigned)VEC_SIZE(&bbv);
LOG(10, "number of bad blocks detected: %u", bbs->bb_cnt);
/* sanity check */
ASSERTeq((unsigned)bb_found, bbs->bb_cnt);
}
return (bb_found >= 0) ? 0 : -1;
}
/*
* os_badblocks_count -- returns number of bad blocks in the file
* or -1 in case of an error
*/
long
os_badblocks_count(const char *file)
{
LOG(3, "file %s", file);
struct badblocks *bbs = badblocks_new();
if (bbs == NULL)
return -1;
int ret = os_badblocks_get(file, bbs);
long count = (ret == 0) ? (long)bbs->bb_cnt : -1;
badblocks_delete(bbs);
return count;
}
/*
* os_badblocks_check_file -- check if the file contains bad blocks
*
* Return value:
* -1 : an error
* 0 : no bad blocks
* 1 : bad blocks detected
*/
int
os_badblocks_check_file(const char *file)
{
LOG(3, "file %s", file);
long bbsc = os_badblocks_count(file);
if (bbsc < 0) {
LOG(1, "counting bad blocks failed -- '%s'", file);
return -1;
}
if (bbsc > 0) {
LOG(1, "pool file '%s' contains %li bad block(s)", file, bbsc);
return 1;
}
return 0;
}
/*
* os_badblocks_clear_file -- clear the given bad blocks in the regular file
* (not in a dax device)
*/
static int
os_badblocks_clear_file(const char *file, struct badblocks *bbs)
{
LOG(3, "file %s badblocks %p", file, bbs);
ASSERTne(bbs, NULL);
int ret = 0;
int fd;
if ((fd = open(file, O_RDWR)) < 0) {
ERR("!open: %s", file);
return -1;
}
for (unsigned b = 0; b < bbs->bb_cnt; b++) {
off_t offset = (off_t)bbs->bbv[b].offset;
off_t length = (off_t)bbs->bbv[b].length;
LOG(10,
"clearing bad block: logical offset %li length %li (in 512B sectors)",
B2SEC(offset), B2SEC(length));
/* deallocate bad blocks */
if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
offset, length)) {
ERR("!fallocate");
ret = -1;
break;
}
/* allocate new blocks */
if (fallocate(fd, FALLOC_FL_KEEP_SIZE, offset, length)) {
ERR("!fallocate");
ret = -1;
break;
}
}
close(fd);
return ret;
}
/*
* os_badblocks_clear -- clears the given bad blocks in a file
* (regular file or dax device)
*/
int
os_badblocks_clear(const char *file, struct badblocks *bbs)
{
LOG(3, "file %s badblocks %p", file, bbs);
ASSERTne(bbs, NULL);
enum file_type type = util_file_get_type(file);
if (type < 0)
return -1;
if (type == TYPE_DEVDAX)
return os_dimm_devdax_clear_badblocks(file, bbs);
return os_badblocks_clear_file(file, bbs);
}
/*
* os_badblocks_clear_all -- clears all bad blocks in a file
* (regular file or dax device)
*/
int
os_badblocks_clear_all(const char *file)
{
LOG(3, "file %s", file);
enum file_type type = util_file_get_type(file);
if (type < 0)
return -1;
if (type == TYPE_DEVDAX)
return os_dimm_devdax_clear_badblocks_all(file);
struct badblocks *bbs = badblocks_new();
if (bbs == NULL)
return -1;
int ret = os_badblocks_get(file, bbs);
if (ret) {
LOG(1, "checking bad blocks in the file failed -- '%s'", file);
goto error_free_all;
}
if (bbs->bb_cnt > 0) {
ret = os_badblocks_clear_file(file, bbs);
if (ret < 0) {
LOG(1, "clearing bad blocks in the file failed -- '%s'",
file);
goto error_free_all;
}
}
error_free_all:
badblocks_delete(bbs);
return ret;
}
| 8,635
| 22.790634
| 76
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/util.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util.c -- very basic utilities
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <endian.h>
#include <errno.h>
#include <time.h>
#include "util.h"
#include "valgrind_internal.h"
/* library-wide page size */
unsigned long long Pagesize;
/* allocation/mmap granularity */
unsigned long long Mmap_align;
/*
* our versions of malloc & friends start off pointing to the libc versions
*/
Malloc_func Malloc = malloc;
Free_func Free = free;
Realloc_func Realloc = realloc;
Strdup_func Strdup = strdup;
/*
* Zalloc -- allocate zeroed memory
*/
void *
Zalloc(size_t sz)
{
void *ret = Malloc(sz);
if (!ret)
return NULL;
return memset(ret, 0, sz);
}
#if ANY_VG_TOOL_ENABLED
/* initialized to true if the process is running inside Valgrind */
unsigned _On_valgrind;
#endif
#if VG_PMEMCHECK_ENABLED
#define LIB_LOG_LEN 20
#define FUNC_LOG_LEN 50
#define SUFFIX_LEN 7
/* true if pmreorder instrumentization has to be enabled */
int _Pmreorder_emit;
/*
* util_emit_log -- emits lib and func name with appropriate suffix
* to pmemcheck store log file
*/
void
util_emit_log(const char *lib, const char *func, int order)
{
char lib_name[LIB_LOG_LEN];
char func_name[FUNC_LOG_LEN];
char suffix[SUFFIX_LEN];
size_t lib_len = strlen(lib);
size_t func_len = strlen(func);
if (order == 0)
strcpy(suffix, ".BEGIN");
else
strcpy(suffix, ".END");
size_t suffix_len = strlen(suffix);
if (lib_len + suffix_len + 1 > LIB_LOG_LEN) {
VALGRIND_EMIT_LOG("Library name is too long");
return;
}
if (func_len + suffix_len + 1 > FUNC_LOG_LEN) {
VALGRIND_EMIT_LOG("Function name is too long");
return;
}
strcpy(lib_name, lib);
strcat(lib_name, suffix);
strcpy(func_name, func);
strcat(func_name, suffix);
if (order == 0) {
VALGRIND_EMIT_LOG(func_name);
VALGRIND_EMIT_LOG(lib_name);
} else {
VALGRIND_EMIT_LOG(lib_name);
VALGRIND_EMIT_LOG(func_name);
}
}
#endif
/*
* util_is_zeroed -- check if given memory range is all zero
*/
int
util_is_zeroed(const void *addr, size_t len)
{
const char *a = addr;
if (len == 0)
return 1;
if (a[0] == 0 && memcmp(a, a + 1, len - 1) == 0)
return 1;
return 0;
}
/*
* util_checksum -- compute Fletcher64 checksum
*
* csump points to where the checksum lives, so that location
* is treated as zeros while calculating the checksum. The
* checksummed data is assumed to be in little endian order.
* If insert is true, the calculated checksum is inserted into
* the range at *csump. Otherwise the calculated checksum is
* checked against *csump and the result returned (true means
* the range checksummed correctly).
*/
int
util_checksum(void *addr, size_t len, uint64_t *csump,
int insert, size_t skip_off)
{
if (len % 4 != 0)
abort();
uint32_t *p32 = addr;
uint32_t *p32end = (uint32_t *)((char *)addr + len);
uint32_t *skip;
uint32_t lo32 = 0;
uint32_t hi32 = 0;
uint64_t csum;
if (skip_off)
skip = (uint32_t *)((char *)addr + skip_off);
else
skip = (uint32_t *)((char *)addr + len);
while (p32 < p32end)
if (p32 == (uint32_t *)csump || p32 >= skip) {
/* lo32 += 0; treat first 32-bits as zero */
p32++;
hi32 += lo32;
/* lo32 += 0; treat second 32-bits as zero */
p32++;
hi32 += lo32;
} else {
lo32 += le32toh(*p32);
++p32;
hi32 += lo32;
}
csum = (uint64_t)hi32 << 32 | lo32;
if (insert) {
*csump = htole64(csum);
return 1;
}
return *csump == htole64(csum);
}
/*
* util_checksum_seq -- compute sequential Fletcher64 checksum
*
* Merges checksum from the old buffer with checksum for current buffer.
*/
uint64_t
util_checksum_seq(const void *addr, size_t len, uint64_t csum)
{
if (len % 4 != 0)
abort();
const uint32_t *p32 = addr;
const uint32_t *p32end = (const uint32_t *)((const char *)addr + len);
uint32_t lo32 = (uint32_t)csum;
uint32_t hi32 = (uint32_t)(csum >> 32);
while (p32 < p32end) {
lo32 += le32toh(*p32);
++p32;
hi32 += lo32;
}
return (uint64_t)hi32 << 32 | lo32;
}
/*
* util_set_alloc_funcs -- allow one to override malloc, etc.
*/
void
util_set_alloc_funcs(void *(*malloc_func)(size_t size),
void (*free_func)(void *ptr),
void *(*realloc_func)(void *ptr, size_t size),
char *(*strdup_func)(const char *s))
{
Malloc = (malloc_func == NULL) ? malloc : malloc_func;
Free = (free_func == NULL) ? free : free_func;
Realloc = (realloc_func == NULL) ? realloc : realloc_func;
Strdup = (strdup_func == NULL) ? strdup : strdup_func;
}
/*
* util_fgets -- fgets wrapper with conversion CRLF to LF
*/
char *
util_fgets(char *buffer, int max, FILE *stream)
{
char *str = fgets(buffer, max, stream);
if (str == NULL)
goto end;
int len = (int)strlen(str);
if (len < 2)
goto end;
if (str[len - 2] == '\r' && str[len - 1] == '\n') {
str[len - 2] = '\n';
str[len - 1] = '\0';
}
end:
return str;
}
struct suff {
const char *suff;
uint64_t mag;
};
/*
* util_parse_size -- parse size from string
*/
int
util_parse_size(const char *str, size_t *sizep)
{
const struct suff suffixes[] = {
{ "B", 1ULL },
{ "K", 1ULL << 10 }, /* JEDEC */
{ "M", 1ULL << 20 },
{ "G", 1ULL << 30 },
{ "T", 1ULL << 40 },
{ "P", 1ULL << 50 },
{ "KiB", 1ULL << 10 }, /* IEC */
{ "MiB", 1ULL << 20 },
{ "GiB", 1ULL << 30 },
{ "TiB", 1ULL << 40 },
{ "PiB", 1ULL << 50 },
{ "kB", 1000ULL }, /* SI */
{ "MB", 1000ULL * 1000 },
{ "GB", 1000ULL * 1000 * 1000 },
{ "TB", 1000ULL * 1000 * 1000 * 1000 },
{ "PB", 1000ULL * 1000 * 1000 * 1000 * 1000 }
};
int res = -1;
unsigned i;
size_t size = 0;
char unit[9] = {0};
int ret = sscanf(str, "%zu%8s", &size, unit);
if (ret == 1) {
res = 0;
} else if (ret == 2) {
for (i = 0; i < ARRAY_SIZE(suffixes); ++i) {
if (strcmp(suffixes[i].suff, unit) == 0) {
size = size * suffixes[i].mag;
res = 0;
break;
}
}
} else {
return -1;
}
if (sizep && res == 0)
*sizep = size;
return res;
}
/*
* util_init -- initialize the utils
*
* This is called from the library initialization code.
*/
void
util_init(void)
{
/* XXX - replace sysconf() with util_get_sys_xxx() */
if (Pagesize == 0)
Pagesize = (unsigned long) sysconf(_SC_PAGESIZE);
#ifndef _WIN32
Mmap_align = Pagesize;
#else
if (Mmap_align == 0) {
SYSTEM_INFO si;
GetSystemInfo(&si);
Mmap_align = si.dwAllocationGranularity;
}
#endif
#if ANY_VG_TOOL_ENABLED
_On_valgrind = RUNNING_ON_VALGRIND;
#endif
#if VG_PMEMCHECK_ENABLED
if (On_valgrind) {
char *pmreorder_env = getenv("PMREORDER_EMIT_LOG");
if (pmreorder_env)
_Pmreorder_emit = atoi(pmreorder_env);
} else {
_Pmreorder_emit = 0;
}
#endif
}
/*
* util_concat_str -- concatenate two strings
*/
char *
util_concat_str(const char *s1, const char *s2)
{
char *result = malloc(strlen(s1) + strlen(s2) + 1);
if (!result)
return NULL;
strcpy(result, s1);
strcat(result, s2);
return result;
}
/*
* util_localtime -- a wrapper for localtime function
*
* localtime can set nonzero errno even if it succeeds (e.g. when there is no
* /etc/localtime file under Linux) and we do not want the errno to be polluted
* in such cases.
*/
struct tm *
util_localtime(const time_t *timep)
{
int oerrno = errno;
struct tm *tm = localtime(timep);
if (tm != NULL)
errno = oerrno;
return tm;
}
/*
* util_safe_strcpy -- copies string from src to dst, returns -1
* when length of source string (including null-terminator)
* is greater than max_length, 0 otherwise
*
* For gcc (found in version 8.1.1) calling this function with
* max_length equal to dst size produces -Wstringop-truncation warning
*
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85902
*/
#ifdef STRINGOP_TRUNCATION_SUPPORTED
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
#endif
int
util_safe_strcpy(char *dst, const char *src, size_t max_length)
{
if (max_length == 0)
return -1;
strncpy(dst, src, max_length);
return dst[max_length - 1] == '\0' ? 0 : -1;
}
#ifdef STRINGOP_TRUNCATION_SUPPORTED
#pragma GCC diagnostic pop
#endif
| 9,626
| 22.19759
| 79
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/ctl.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ctl.c -- implementation of the interface for examination and modification of
* the library's internal state
*/
#include "ctl.h"
#include "os.h"
#define CTL_MAX_ENTRIES 100
#define MAX_CONFIG_FILE_LEN (1 << 20) /* 1 megabyte */
#define CTL_STRING_QUERY_SEPARATOR ";"
#define CTL_NAME_VALUE_SEPARATOR "="
#define CTL_QUERY_NODE_SEPARATOR "."
#define CTL_VALUE_ARG_SEPARATOR ","
static int ctl_global_first_free = 0;
static struct ctl_node CTL_NODE(global)[CTL_MAX_ENTRIES];
/*
* This is the top level node of the ctl tree structure. Each node can contain
* children and leaf nodes.
*
* Internal nodes simply create a new path in the tree whereas child nodes are
* the ones providing the read/write functionality by the means of callbacks.
*
* Each tree node must be NULL-terminated, CTL_NODE_END macro is provided for
* convience.
*/
struct ctl {
struct ctl_node root[CTL_MAX_ENTRIES];
int first_free;
};
/*
* ctl_find_node -- (internal) searches for a matching entry point in the
* provided nodes
*
* The caller is responsible for freeing all of the allocated indexes,
* regardless of the return value.
*/
static struct ctl_node *
ctl_find_node(struct ctl_node *nodes, const char *name,
struct ctl_indexes *indexes)
{
LOG(3, "nodes %p name %s indexes %p", nodes, name, indexes);
struct ctl_node *n = NULL;
char *sptr = NULL;
char *parse_str = Strdup(name);
if (parse_str == NULL)
return NULL;
char *node_name = strtok_r(parse_str, CTL_QUERY_NODE_SEPARATOR, &sptr);
/*
* Go through the string and separate tokens that correspond to nodes
* in the main ctl tree.
*/
while (node_name != NULL) {
char *endptr;
/*
* Ignore errno from strtol: FreeBSD returns EINVAL if no
* conversion is performed. Linux does not, but endptr
* check is valid in both cases.
*/
int tmp_errno = errno;
long index_value = strtol(node_name, &endptr, 0);
errno = tmp_errno;
struct ctl_index *index_entry = NULL;
if (endptr != node_name) { /* a valid index */
index_entry = Malloc(sizeof(*index_entry));
if (index_entry == NULL)
goto error;
index_entry->value = index_value;
SLIST_INSERT_HEAD(indexes, index_entry, entry);
}
for (n = &nodes[0]; n->name != NULL; ++n) {
if (index_entry && n->type == CTL_NODE_INDEXED)
break;
else if (strcmp(n->name, node_name) == 0)
break;
}
if (n->name == NULL)
goto error;
if (index_entry)
index_entry->name = n->name;
nodes = n->children;
node_name = strtok_r(NULL, CTL_QUERY_NODE_SEPARATOR, &sptr);
}
Free(parse_str);
return n;
error:
Free(parse_str);
return NULL;
}
/*
* ctl_delete_indexes --
* (internal) removes and frees all entires on the index list
*/
static void
ctl_delete_indexes(struct ctl_indexes *indexes)
{
while (!SLIST_EMPTY(indexes)) {
struct ctl_index *index = SLIST_FIRST(indexes);
SLIST_REMOVE_HEAD(indexes, entry);
Free(index);
}
}
/*
* ctl_parse_args -- (internal) parses a string argument based on the node
* structure
*/
static void *
ctl_parse_args(struct ctl_argument *arg_proto, char *arg)
{
ASSERTne(arg, NULL);
char *dest_arg = Malloc(arg_proto->dest_size);
if (dest_arg == NULL)
return NULL;
char *sptr = NULL;
char *arg_sep = strtok_r(arg, CTL_VALUE_ARG_SEPARATOR, &sptr);
for (struct ctl_argument_parser *p = arg_proto->parsers;
p->parser != NULL; ++p) {
ASSERT(p->dest_offset + p->dest_size <= arg_proto->dest_size);
if (arg_sep == NULL)
goto error_parsing;
if (p->parser(arg_sep, dest_arg + p->dest_offset,
p->dest_size) != 0)
goto error_parsing;
arg_sep = strtok_r(NULL, CTL_VALUE_ARG_SEPARATOR, &sptr);
}
return dest_arg;
error_parsing:
Free(dest_arg);
return NULL;
}
/*
* ctl_query_get_real_args -- (internal) returns a pointer with actual argument
* structure as required by the node callback
*/
static void *
ctl_query_get_real_args(struct ctl_node *n, void *write_arg,
enum ctl_query_source source)
{
void *real_arg = NULL;
switch (source) {
case CTL_QUERY_CONFIG_INPUT:
real_arg = ctl_parse_args(n->arg, write_arg);
break;
case CTL_QUERY_PROGRAMMATIC:
real_arg = write_arg;
break;
default:
ASSERT(0);
break;
}
return real_arg;
}
/*
* ctl_query_cleanup_real_args -- (internal) cleanups relevant argument
* structures allocated as a result of the get_real_args call
*/
static void
ctl_query_cleanup_real_args(struct ctl_node *n, void *real_arg,
enum ctl_query_source source)
{
switch (source) {
case CTL_QUERY_CONFIG_INPUT:
Free(real_arg);
break;
case CTL_QUERY_PROGRAMMATIC:
break;
default:
ASSERT(0);
break;
}
}
/*
* ctl_exec_query_read -- (internal) calls the read callback of a node
*/
static int
ctl_exec_query_read(void *ctx, struct ctl_node *n,
enum ctl_query_source source, void *arg, struct ctl_indexes *indexes)
{
if (arg == NULL) {
ERR("read queries require non-NULL argument");
errno = EINVAL;
return -1;
}
return n->cb[CTL_QUERY_READ](ctx, source, arg, indexes);
}
/*
* ctl_exec_query_write -- (internal) calls the write callback of a node
*/
static int
ctl_exec_query_write(void *ctx, struct ctl_node *n,
enum ctl_query_source source, void *arg, struct ctl_indexes *indexes)
{
if (arg == NULL) {
ERR("write queries require non-NULL argument");
errno = EINVAL;
return -1;
}
void *real_arg = ctl_query_get_real_args(n, arg, source);
if (real_arg == NULL) {
errno = EINVAL;
ERR("invalid arguments");
return -1;
}
int ret = n->cb[CTL_QUERY_WRITE](ctx, source, real_arg, indexes);
ctl_query_cleanup_real_args(n, real_arg, source);
return ret;
}
/*
* ctl_exec_query_runnable -- (internal) calls the run callback of a node
*/
static int
ctl_exec_query_runnable(void *ctx, struct ctl_node *n,
enum ctl_query_source source, void *arg, struct ctl_indexes *indexes)
{
return n->cb[CTL_QUERY_RUNNABLE](ctx, source, arg, indexes);
}
static int (*ctl_exec_query[MAX_CTL_QUERY_TYPE])(void *ctx,
struct ctl_node *n, enum ctl_query_source source, void *arg,
struct ctl_indexes *indexes) = {
ctl_exec_query_read,
ctl_exec_query_write,
ctl_exec_query_runnable,
};
/*
* ctl_query -- (internal) parses the name and calls the appropriate methods
* from the ctl tree
*/
int
ctl_query(struct ctl *ctl, void *ctx, enum ctl_query_source source,
const char *name, enum ctl_query_type type, void *arg)
{
LOG(3, "ctl %p ctx %p source %d name %s type %d arg %p",
ctl, ctx, source, name, type, arg);
if (name == NULL) {
ERR("invalid query");
errno = EINVAL;
return -1;
}
/*
* All of the indexes are put on this list so that the handlers can
* easily retrieve the index values. The list is cleared once the ctl
* query has been handled.
*/
struct ctl_indexes indexes;
SLIST_INIT(&indexes);
int ret = -1;
struct ctl_node *n = ctl_find_node(CTL_NODE(global),
name, &indexes);
if (n == NULL && ctl) {
ctl_delete_indexes(&indexes);
n = ctl_find_node(ctl->root, name, &indexes);
}
if (n == NULL || n->type != CTL_NODE_LEAF || n->cb[type] == NULL) {
ERR("invalid query entry point %s", name);
errno = EINVAL;
goto out;
}
ret = ctl_exec_query[type](ctx, n, source, arg, &indexes);
out:
ctl_delete_indexes(&indexes);
return ret;
}
/*
* ctl_register_module_node -- adds a new node to the CTL tree root.
*/
void
ctl_register_module_node(struct ctl *c, const char *name, struct ctl_node *n)
{
struct ctl_node *nnode = c == NULL ?
&CTL_NODE(global)[ctl_global_first_free++] :
&c->root[c->first_free++];
nnode->children = n;
nnode->type = CTL_NODE_NAMED;
nnode->name = name;
}
/*
* ctl_parse_query -- (internal) splits an entire query string
* into name and value
*/
static int
ctl_parse_query(char *qbuf, char **name, char **value)
{
if (qbuf == NULL)
return -1;
char *sptr;
*name = strtok_r(qbuf, CTL_NAME_VALUE_SEPARATOR, &sptr);
if (*name == NULL)
return -1;
*value = strtok_r(NULL, CTL_NAME_VALUE_SEPARATOR, &sptr);
if (*value == NULL)
return -1;
/* the value itself mustn't include CTL_NAME_VALUE_SEPARATOR */
char *extra = strtok_r(NULL, CTL_NAME_VALUE_SEPARATOR, &sptr);
if (extra != NULL)
return -1;
return 0;
}
/*
* ctl_load_config -- executes the entire query collection from a provider
*/
static int
ctl_load_config(struct ctl *ctl, void *ctx, char *buf)
{
int r = 0;
char *sptr = NULL; /* for internal use of strtok */
char *name;
char *value;
ASSERTne(buf, NULL);
char *qbuf = strtok_r(buf, CTL_STRING_QUERY_SEPARATOR, &sptr);
while (qbuf != NULL) {
r = ctl_parse_query(qbuf, &name, &value);
if (r != 0) {
ERR("failed to parse query %s", qbuf);
return -1;
}
r = ctl_query(ctl, ctx, CTL_QUERY_CONFIG_INPUT,
name, CTL_QUERY_WRITE, value);
if (r < 0 && ctx != NULL)
return -1;
qbuf = strtok_r(NULL, CTL_STRING_QUERY_SEPARATOR, &sptr);
}
return 0;
}
/*
* ctl_load_config_from_string -- loads obj configuration from string
*/
int
ctl_load_config_from_string(struct ctl *ctl, void *ctx, const char *cfg_string)
{
LOG(3, "ctl %p ctx %p cfg_string \"%s\"", ctl, ctx, cfg_string);
char *buf = Strdup(cfg_string);
if (buf == NULL) {
ERR("!Strdup");
return -1;
}
int ret = ctl_load_config(ctl, ctx, buf);
Free(buf);
return ret;
}
/*
* ctl_load_config_from_file -- loads obj configuration from file
*
* This function opens up the config file, allocates a buffer of size equal to
* the size of the file, reads its content and sanitizes it for ctl_load_config.
*/
int
ctl_load_config_from_file(struct ctl *ctl, void *ctx, const char *cfg_file)
{
LOG(3, "ctl %p ctx %p cfg_file \"%s\"", ctl, ctx, cfg_file);
int ret = -1;
FILE *fp = os_fopen(cfg_file, "r");
if (fp == NULL)
return ret;
int err;
if ((err = fseek(fp, 0, SEEK_END)) != 0)
goto error_file_parse;
long fsize = ftell(fp);
if (fsize == -1)
goto error_file_parse;
if (fsize > MAX_CONFIG_FILE_LEN) {
ERR("Config file too large");
goto error_file_parse;
}
if ((err = fseek(fp, 0, SEEK_SET)) != 0)
goto error_file_parse;
char *buf = Zalloc((size_t)fsize + 1); /* +1 for NULL-termination */
if (buf == NULL) {
ERR("!Zalloc");
goto error_file_parse;
}
size_t bufpos = 0;
int c;
int is_comment_section = 0;
while ((c = fgetc(fp)) != EOF) {
if (c == '#')
is_comment_section = 1;
else if (c == '\n')
is_comment_section = 0;
else if (!is_comment_section && !isspace(c))
buf[bufpos++] = (char)c;
}
ret = ctl_load_config(ctl, ctx, buf);
Free(buf);
error_file_parse:
(void) fclose(fp);
return ret;
}
/*
* ctl_new -- allocates and initalizes ctl data structures
*/
struct ctl *
ctl_new(void)
{
struct ctl *c = Zalloc(sizeof(struct ctl));
if (c == NULL) {
ERR("!Zalloc");
return NULL;
}
c->first_free = 0;
return c;
}
/*
* ctl_delete -- deletes ctl
*/
void
ctl_delete(struct ctl *c)
{
Free(c);
}
/*
* ctl_parse_ll -- (internal) parses and returns a long long signed integer
*/
static long long
ctl_parse_ll(const char *str)
{
char *endptr;
int olderrno = errno;
errno = 0;
long long val = strtoll(str, &endptr, 0);
if (endptr == str || errno != 0)
return LLONG_MIN;
errno = olderrno;
return val;
}
/*
* ctl_arg_boolean -- checks whether the provided argument contains
* either a 1 or y or Y.
*/
int
ctl_arg_boolean(const void *arg, void *dest, size_t dest_size)
{
int *intp = dest;
char in = ((char *)arg)[0];
if (tolower(in) == 'y' || in == '1') {
*intp = 1;
return 0;
} else if (tolower(in) == 'n' || in == '0') {
*intp = 0;
return 0;
}
return -1;
}
/*
* ctl_arg_integer -- parses signed integer argument
*/
int
ctl_arg_integer(const void *arg, void *dest, size_t dest_size)
{
long long val = ctl_parse_ll(arg);
if (val == LLONG_MIN)
return -1;
switch (dest_size) {
case sizeof(int):
if (val > INT_MAX || val < INT_MIN)
return -1;
*(int *)dest = (int)val;
break;
case sizeof(long long):
*(long long *)dest = val;
break;
case sizeof(uint8_t):
if (val > UINT8_MAX || val < 0)
return -1;
*(uint8_t *)dest = (uint8_t)val;
break;
default:
ERR("invalid destination size %zu", dest_size);
errno = EINVAL;
return -1;
}
return 0;
}
/*
* ctl_arg_string -- verifies length and copies a string argument into a zeroed
* buffer
*/
int
ctl_arg_string(const void *arg, void *dest, size_t dest_size)
{
/* check if the incoming string is longer or equal to dest_size */
if (strnlen(arg, dest_size) == dest_size)
return -1;
strncpy(dest, arg, dest_size);
return 0;
}
| 14,069
| 22.217822
| 80
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/pool_hdr.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pool_hdr.c -- pool header utilities
*/
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <endian.h>
#include "out.h"
#include "pool_hdr.h"
/* Determine ISA for which PMDK is currently compiled */
#if defined(__x86_64) || defined(_M_X64)
/* x86 -- 64 bit */
#define PMDK_MACHINE PMDK_MACHINE_X86_64
#define PMDK_MACHINE_CLASS PMDK_MACHINE_CLASS_64
#elif defined(__aarch64__)
/* 64 bit ARM not supported yet */
#define PMDK_MACHINE PMDK_MACHINE_AARCH64
#define PMDK_MACHINE_CLASS PMDK_MACHINE_CLASS_64
#else
/* add appropriate definitions here when porting PMDK to another ISA */
#error unable to recognize ISA at compile time
#endif
/*
* arch_machine -- (internal) determine endianness
*/
static uint8_t
arch_data(void)
{
uint16_t word = (PMDK_DATA_BE << 8) + PMDK_DATA_LE;
return ((uint8_t *)&word)[0];
}
/*
* util_get_arch_flags -- get architecture identification flags
*/
void
util_get_arch_flags(struct arch_flags *arch_flags)
{
memset(arch_flags, 0, sizeof(*arch_flags));
arch_flags->machine = PMDK_MACHINE;
arch_flags->machine_class = PMDK_MACHINE_CLASS;
arch_flags->data = arch_data();
arch_flags->alignment_desc = alignment_desc();
}
/*
* util_convert2le_hdr -- convert pool_hdr into little-endian byte order
*/
void
util_convert2le_hdr(struct pool_hdr *hdrp)
{
hdrp->major = htole32(hdrp->major);
hdrp->features.compat = htole32(hdrp->features.compat);
hdrp->features.incompat = htole32(hdrp->features.incompat);
hdrp->features.ro_compat = htole32(hdrp->features.ro_compat);
hdrp->arch_flags.alignment_desc =
htole64(hdrp->arch_flags.alignment_desc);
hdrp->arch_flags.machine = htole16(hdrp->arch_flags.machine);
hdrp->crtime = htole64(hdrp->crtime);
hdrp->checksum = htole64(hdrp->checksum);
}
/*
* util_convert2h_hdr_nocheck -- convert pool_hdr into host byte order
*/
void
util_convert2h_hdr_nocheck(struct pool_hdr *hdrp)
{
hdrp->major = le32toh(hdrp->major);
hdrp->features.compat = le32toh(hdrp->features.compat);
hdrp->features.incompat = le32toh(hdrp->features.incompat);
hdrp->features.ro_compat = le32toh(hdrp->features.ro_compat);
hdrp->crtime = le64toh(hdrp->crtime);
hdrp->arch_flags.machine = le16toh(hdrp->arch_flags.machine);
hdrp->arch_flags.alignment_desc =
le64toh(hdrp->arch_flags.alignment_desc);
hdrp->checksum = le64toh(hdrp->checksum);
}
/*
* util_arch_flags_check -- validates arch_flags
*/
int
util_check_arch_flags(const struct arch_flags *arch_flags)
{
struct arch_flags cur_af;
int ret = 0;
util_get_arch_flags(&cur_af);
if (!util_is_zeroed(&arch_flags->reserved,
sizeof(arch_flags->reserved))) {
ERR("invalid reserved values");
ret = -1;
}
if (arch_flags->machine != cur_af.machine) {
ERR("invalid machine value");
ret = -1;
}
if (arch_flags->data != cur_af.data) {
ERR("invalid data value");
ret = -1;
}
if (arch_flags->machine_class != cur_af.machine_class) {
ERR("invalid machine_class value");
ret = -1;
}
if (arch_flags->alignment_desc != cur_af.alignment_desc) {
ERR("invalid alignment_desc value");
ret = -1;
}
return ret;
}
/*
* util_get_unknown_features -- filter out unknown features flags
*/
features_t
util_get_unknown_features(features_t features, features_t known)
{
features_t unknown;
unknown.compat = util_get_not_masked_bits(
features.compat, known.compat);
unknown.incompat = util_get_not_masked_bits(
features.incompat, known.incompat);
unknown.ro_compat = util_get_not_masked_bits(
features.ro_compat, known.ro_compat);
return unknown;
}
/*
* util_feature_check -- check features masks
*/
int
util_feature_check(struct pool_hdr *hdrp, features_t known)
{
LOG(3, "hdrp %p features {incompat %#x ro_compat %#x compat %#x}",
hdrp,
known.incompat, known.ro_compat, known.compat);
features_t unknown = util_get_unknown_features(hdrp->features, known);
/* check incompatible ("must support") features */
if (unknown.incompat) {
ERR("unsafe to continue due to unknown incompat "\
"features: %#x", unknown.incompat);
errno = EINVAL;
return -1;
}
/* check RO-compatible features (force RO if unsupported) */
if (unknown.ro_compat) {
ERR("switching to read-only mode due to unknown ro_compat "\
"features: %#x", unknown.ro_compat);
return 0;
}
/* check compatible ("may") features */
if (unknown.compat) {
LOG(3, "ignoring unknown compat features: %#x", unknown.compat);
}
return 1;
}
/*
* util_feature_cmp -- compares features with reference
*
* returns 1 if features and reference match and 0 otherwise
*/
int
util_feature_cmp(features_t features, features_t ref)
{
LOG(3, "features {incompat %#x ro_compat %#x compat %#x}"
"ref {incompat %#x ro_compat %#x compat %#x}",
features.incompat, features.ro_compat, features.compat,
ref.incompat, ref.ro_compat, ref.compat);
return features.compat == ref.compat &&
features.incompat == ref.incompat &&
features.ro_compat == ref.ro_compat;
}
/*
* util_feature_is_zero -- check if features flags are zeroed
*
* returns 1 if features is zeroed and 0 otherwise
*/
int
util_feature_is_zero(features_t features)
{
const uint32_t bits =
features.compat | features.incompat |
features.ro_compat;
return bits ? 0 : 1;
}
/*
* util_feature_is_set -- check if feature flag is set in features
*
* returns 1 if feature flag is set and 0 otherwise
*/
int
util_feature_is_set(features_t features, features_t flag)
{
uint32_t bits = 0;
bits |= features.compat & flag.compat;
bits |= features.incompat & flag.incompat;
bits |= features.ro_compat & flag.ro_compat;
return bits ? 1 : 0;
}
/*
* util_feature_enable -- enable feature
*/
void
util_feature_enable(features_t *features, features_t new_feature)
{
#define FEATURE_ENABLE(flags, X) \
(flags) |= (X)
FEATURE_ENABLE(features->compat, new_feature.compat);
FEATURE_ENABLE(features->incompat, new_feature.incompat);
FEATURE_ENABLE(features->ro_compat, new_feature.ro_compat);
#undef FEATURE_ENABLE
}
/*
* util_feature_disable -- (internal) disable feature
*/
void
util_feature_disable(features_t *features, features_t old_feature)
{
#define FEATURE_DISABLE(flags, X) \
(flags) &= ~(X)
FEATURE_DISABLE(features->compat, old_feature.compat);
FEATURE_DISABLE(features->incompat, old_feature.incompat);
FEATURE_DISABLE(features->ro_compat, old_feature.ro_compat);
#undef FEATURE_DISABLE
}
static const features_t feature_2_pmempool_feature_map[] = {
FEAT_INCOMPAT(SINGLEHDR), /* PMEMPOOL_FEAT_SINGLEHDR */
FEAT_INCOMPAT(CKSUM_2K), /* PMEMPOOL_FEAT_CKSUM_2K */
FEAT_INCOMPAT(SDS), /* PMEMPOOL_FEAT_SHUTDOWN_STATE */
FEAT_COMPAT(CHECK_BAD_BLOCKS), /* PMEMPOOL_FEAT_CHECK_BAD_BLOCKS */
};
#define FEAT_2_PMEMPOOL_FEATURE_MAP_SIZE \
ARRAY_SIZE(feature_2_pmempool_feature_map)
static const char *str_2_pmempool_feature_map[] = {
"SINGLEHDR",
"CKSUM_2K",
"SHUTDOWN_STATE",
"CHECK_BAD_BLOCKS",
};
#define PMEMPOOL_FEATURE_2_STR_MAP_SIZE ARRAY_SIZE(str_2_pmempool_feature_map)
/*
* util_str2feature -- convert string to feat_flags value
*/
features_t
util_str2feature(const char *str)
{
/* all features have to be named in incompat_features_str array */
COMPILE_ERROR_ON(FEAT_2_PMEMPOOL_FEATURE_MAP_SIZE !=
PMEMPOOL_FEATURE_2_STR_MAP_SIZE);
for (uint32_t f = 0; f < PMEMPOOL_FEATURE_2_STR_MAP_SIZE; ++f) {
if (strcmp(str, str_2_pmempool_feature_map[f]) == 0) {
return feature_2_pmempool_feature_map[f];
}
}
return features_zero;
}
/*
* util_feature2pmempool_feature -- convert feature to pmempool_feature
*/
uint32_t
util_feature2pmempool_feature(features_t feat)
{
for (uint32_t pf = 0; pf < FEAT_2_PMEMPOOL_FEATURE_MAP_SIZE; ++pf) {
const features_t *record =
&feature_2_pmempool_feature_map[pf];
if (util_feature_cmp(feat, *record)) {
return pf;
}
}
return UINT32_MAX;
}
/*
* util_str2pmempool_feature -- convert string to uint32_t enum pmempool_feature
* equivalent
*/
uint32_t
util_str2pmempool_feature(const char *str)
{
features_t fval = util_str2feature(str);
if (util_feature_is_zero(fval))
return UINT32_MAX;
return util_feature2pmempool_feature(fval);
}
/*
* util_feature2str -- convert uint32_t feature to string
*/
const char *
util_feature2str(features_t features, features_t *found)
{
for (uint32_t i = 0; i < FEAT_2_PMEMPOOL_FEATURE_MAP_SIZE; ++i) {
const features_t *record = &feature_2_pmempool_feature_map[i];
if (util_feature_is_set(features, *record)) {
if (found)
memcpy(found, record, sizeof(features_t));
return str_2_pmempool_feature_map[i];
}
}
return NULL;
}
| 10,132
| 26.312668
| 80
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/uuid_windows.c
|
/*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* uuid_windows.c -- pool set utilities with OS-specific implementation
*/
#include "uuid.h"
#include "out.h"
/*
* util_uuid_generate -- generate a uuid
*/
int
util_uuid_generate(uuid_t uuid)
{
HRESULT res = CoCreateGuid((GUID *)(uuid));
if (res != S_OK) {
ERR("CoCreateGuid");
return -1;
}
return 0;
}
| 1,921
| 35.264151
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/shutdown_state.h
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* shutdown_state.h -- unsafe shudown detection
*/
#ifndef PMDK_SHUTDOWN_STATE_H
#define PMDK_SHUTDOWN_STATE_H 1
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
struct pool_replica;
struct shutdown_state {
uint64_t usc;
uint64_t uuid; /* UID checksum */
uint8_t dirty;
uint8_t reserved[39];
uint64_t checksum;
};
int shutdown_state_init(struct shutdown_state *sds, struct pool_replica *rep);
int shutdown_state_add_part(struct shutdown_state *sds, const char *path,
struct pool_replica *rep);
void shutdown_state_set_dirty(struct shutdown_state *sds,
struct pool_replica *rep);
void shutdown_state_clear_dirty(struct shutdown_state *sds,
struct pool_replica *rep);
int shutdown_state_check(struct shutdown_state *curr_sds,
struct shutdown_state *pool_sds, struct pool_replica *rep);
#ifdef __cplusplus
}
#endif
#endif /* shutdown_state.h */
| 2,475
| 33.873239
| 78
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/uuid.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* uuid.h -- internal definitions for uuid module
*/
#ifndef PMDK_UUID_H
#define PMDK_UUID_H 1
#include <stdint.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Structure for binary version of uuid. From RFC4122,
* https://tools.ietf.org/html/rfc4122
*/
struct uuid {
uint32_t time_low;
uint16_t time_mid;
uint16_t time_hi_and_ver;
uint8_t clock_seq_hi;
uint8_t clock_seq_low;
uint8_t node[6];
};
#define POOL_HDR_UUID_LEN 16 /* uuid byte length */
#define POOL_HDR_UUID_STR_LEN 37 /* uuid string length */
#define POOL_HDR_UUID_GEN_FILE "/proc/sys/kernel/random/uuid"
typedef unsigned char uuid_t[POOL_HDR_UUID_LEN]; /* 16 byte binary uuid value */
int util_uuid_generate(uuid_t uuid);
int util_uuid_to_string(const uuid_t u, char *buf);
int util_uuid_from_string(const char uuid[POOL_HDR_UUID_STR_LEN],
struct uuid *ud);
/*
* uuidcmp -- compare two uuids
*/
static inline int
uuidcmp(const uuid_t uuid1, const uuid_t uuid2)
{
return memcmp(uuid1, uuid2, POOL_HDR_UUID_LEN);
}
#ifdef __cplusplus
}
#endif
#endif
| 2,660
| 30.305882
| 80
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/badblock.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* badblock.c - common part of implementation of bad blocks API
*/
#define _GNU_SOURCE
#include <fcntl.h>
#include <inttypes.h>
#include <errno.h>
#include "file.h"
#include "os.h"
#include "out.h"
#include "extent.h"
#include "os_badblock.h"
#include "badblock.h"
/*
* badblocks_new -- zalloc bad blocks structure
*/
struct badblocks *
badblocks_new(void)
{
LOG(3, " ");
struct badblocks *bbs = Zalloc(sizeof(struct badblocks));
if (bbs == NULL) {
ERR("!Zalloc");
}
return bbs;
}
/*
* badblocks_delete -- free bad blocks structure
*/
void
badblocks_delete(struct badblocks *bbs)
{
LOG(3, "badblocks %p", bbs);
if (bbs == NULL)
return;
Free(bbs->bbv);
Free(bbs);
}
/* helper structure for badblocks_check_file_cb() */
struct check_file_cb {
int n_files_bbs; /* number of files with bad blocks */
int create; /* poolset is just being created */
};
/*
* badblocks_check_file_cb -- (internal) callback checking bad blocks
* in the given file
*/
static int
badblocks_check_file_cb(struct part_file *pf, void *arg)
{
LOG(3, "part_file %p arg %p", pf, arg);
struct check_file_cb *pcfcb = arg;
if (pf->is_remote) {
/*
* Remote replicas are checked for bad blocks
* while opening in util_pool_open_remote().
*/
return 0;
}
int exists = util_file_exists(pf->part->path);
if (exists < 0)
return -1;
if (!exists)
/* the part does not exist, so it has no bad blocks */
return 0;
int ret = os_badblocks_check_file(pf->part->path);
if (ret < 0) {
ERR("checking the pool file for bad blocks failed -- '%s'",
pf->part->path);
return -1;
}
if (ret > 0) {
ERR("part file contains bad blocks -- '%s'", pf->part->path);
pcfcb->n_files_bbs++;
pf->part->has_bad_blocks = 1;
}
return 0;
}
/*
* badblocks_check_poolset -- checks if the pool set contains bad blocks
*
* Return value:
* -1 error
* 0 pool set does not contain bad blocks
* 1 pool set contains bad blocks
*/
int
badblocks_check_poolset(struct pool_set *set, int create)
{
LOG(3, "set %p create %i", set, create);
struct check_file_cb cfcb;
cfcb.n_files_bbs = 0;
cfcb.create = create;
if (util_poolset_foreach_part_struct(set, badblocks_check_file_cb,
&cfcb)) {
return -1;
}
if (cfcb.n_files_bbs) {
LOG(1, "%i pool file(s) contain bad blocks", cfcb.n_files_bbs);
set->has_bad_blocks = 1;
}
return (cfcb.n_files_bbs > 0);
}
/*
* badblocks_clear_poolset_cb -- (internal) callback clearing bad blocks
* in the given file
*/
static int
badblocks_clear_poolset_cb(struct part_file *pf, void *arg)
{
LOG(3, "part_file %p arg %p", pf, arg);
int *create = arg;
if (pf->is_remote) { /* XXX not supported yet */
LOG(1,
"WARNING: clearing bad blocks in remote replicas is not supported yet -- '%s:%s'",
pf->remote->node_addr, pf->remote->pool_desc);
return 0;
}
if (*create) {
/*
* Poolset is just being created - check if file exists
* and if we can read it.
*/
int exists = util_file_exists(pf->part->path);
if (exists < 0)
return -1;
if (!exists)
return 0;
}
int ret = os_badblocks_clear_all(pf->part->path);
if (ret < 0) {
ERR("clearing bad blocks in the pool file failed -- '%s'",
pf->part->path);
errno = EIO;
return -1;
}
pf->part->has_bad_blocks = 0;
return 0;
}
/*
* badblocks_clear_poolset -- clears bad blocks in the pool set
*/
int
badblocks_clear_poolset(struct pool_set *set, int create)
{
LOG(3, "set %p create %i", set, create);
if (util_poolset_foreach_part_struct(set, badblocks_clear_poolset_cb,
&create)) {
return -1;
}
set->has_bad_blocks = 0;
return 0;
}
/*
* badblocks_recovery_file_alloc -- allocate name of bad block recovery file,
* the allocated name has to be freed
* using Free()
*/
char *
badblocks_recovery_file_alloc(const char *file, unsigned rep, unsigned part)
{
LOG(3, "file %s rep %u part %u", file, rep, part);
char bbs_suffix[32];
char *path;
sprintf(bbs_suffix, "_r%u_p%u_badblocks.txt", rep, part);
size_t len_file = strlen(file);
size_t len_bbs_suffix = strlen(bbs_suffix);
size_t len_path = len_file + len_bbs_suffix;
path = Zalloc(len_path + 1);
if (path == NULL) {
ERR("!Zalloc");
return NULL;
}
strncpy(path, file, len_file);
strncat(path, bbs_suffix, len_bbs_suffix);
return path;
}
/*
* badblocks_recovery_file_exists -- check if any bad block recovery file exists
*
* Returns:
* 0 when there are no bad block recovery files and
* 1 when there is at least one bad block recovery file.
*/
int
badblocks_recovery_file_exists(struct pool_set *set)
{
LOG(3, "set %p", set);
int recovery_file_exists = 0;
for (unsigned r = 0; r < set->nreplicas; ++r) {
struct pool_replica *rep = set->replica[r];
/* XXX: not supported yet */
if (rep->remote)
continue;
for (unsigned p = 0; p < rep->nparts; ++p) {
const char *path = PART(rep, p)->path;
int exists = util_file_exists(path);
if (exists < 0)
return -1;
if (!exists) {
/* part file does not exist - skip it */
continue;
}
char *rec_file =
badblocks_recovery_file_alloc(set->path, r, p);
if (rec_file == NULL) {
LOG(1,
"allocating name of bad block recovery file failed");
return -1;
}
exists = util_file_exists(rec_file);
if (exists < 0) {
Free(rec_file);
return -1;
}
if (exists) {
LOG(3, "bad block recovery file exists: %s",
rec_file);
recovery_file_exists = 1;
}
Free(rec_file);
if (recovery_file_exists)
return 1;
}
}
return 0;
}
| 7,257
| 21.968354
| 85
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/uuid.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* uuid.c -- uuid utilities
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "uuid.h"
#include "out.h"
/*
* util_uuid_to_string -- generate a string form of the uuid
*/
int
util_uuid_to_string(const uuid_t u, char *buf)
{
int len; /* size that is returned from sprintf call */
if (buf == NULL) {
LOG(2, "invalid buffer for uuid string");
return -1;
}
if (u == NULL) {
LOG(2, "invalid uuid structure");
return -1;
}
struct uuid *uuid = (struct uuid *)u;
len = snprintf(buf, POOL_HDR_UUID_STR_LEN,
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
uuid->time_low, uuid->time_mid, uuid->time_hi_and_ver,
uuid->clock_seq_hi, uuid->clock_seq_low, uuid->node[0],
uuid->node[1], uuid->node[2], uuid->node[3], uuid->node[4],
uuid->node[5]);
if (len != POOL_HDR_UUID_STR_LEN - 1) {
LOG(2, "snprintf(uuid): %d", len);
return -1;
}
return 0;
}
/*
* util_uuid_from_string -- generate a binary form of the uuid
*
* uuid string read from /proc/sys/kernel/random/uuid. UUID string
* format example:
* f81d4fae-7dec-11d0-a765-00a0c91e6bf6
*/
int
util_uuid_from_string(const char *uuid, struct uuid *ud)
{
if (strlen(uuid) != 36) {
LOG(2, "invalid uuid string");
return -1;
}
if (uuid[8] != '-' || uuid[13] != '-' || uuid[18] != '-' ||
uuid[23] != '-') {
LOG(2, "invalid uuid string");
return -1;
}
int n = sscanf(uuid,
"%08x-%04hx-%04hx-%02hhx%02hhx-"
"%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
&ud->time_low, &ud->time_mid, &ud->time_hi_and_ver,
&ud->clock_seq_hi, &ud->clock_seq_low, &ud->node[0],
&ud->node[1], &ud->node[2], &ud->node[3], &ud->node[4],
&ud->node[5]);
if (n != 11) {
LOG(2, "sscanf(uuid)");
return -1;
}
return 0;
}
| 3,333
| 28.504425
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/queue.h
|
/*
* Source: glibc 2.24 (git://sourceware.org/glibc.git /misc/sys/queue.h)
*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)queue.h 8.5 (Berkeley) 8/20/94
*/
#ifndef _SYS_QUEUE_H_
#define _SYS_QUEUE_H_
/*
* This file defines five types of data structures: singly-linked lists,
* lists, simple queues, tail queues, and circular queues.
*
* A singly-linked list is headed by a single forward pointer. The
* elements are singly linked for minimum space and pointer manipulation
* overhead at the expense of O(n) removal for arbitrary elements. New
* elements can be added to the list after an existing element or at the
* head of the list. Elements being removed from the head of the list
* should use the explicit macro for this purpose for optimum
* efficiency. A singly-linked list may only be traversed in the forward
* direction. Singly-linked lists are ideal for applications with large
* datasets and few or no removals or for implementing a LIFO queue.
*
* A list is headed by a single forward pointer (or an array of forward
* pointers for a hash table header). The elements are doubly linked
* so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before
* or after an existing element or at the head of the list. A list
* may only be traversed in the forward direction.
*
* A simple queue is headed by a pair of pointers, one the head of the
* list and the other to the tail of the list. The elements are singly
* linked to save space, so elements can only be removed from the
* head of the list. New elements can be added to the list after
* an existing element, at the head of the list, or at the end of the
* list. A simple queue may only be traversed in the forward direction.
*
* A tail queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or
* after an existing element, at the head of the list, or at the end of
* the list. A tail queue may be traversed in either direction.
*
* A circle queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or after
* an existing element, at the head of the list, or at the end of the list.
* A circle queue may be traversed in either direction, but has a more
* complex end of list detection.
*
* For details on the use of these macros, see the queue(3) manual page.
*/
/*
* XXX This is a workaround for a bug in the llvm's static analyzer. For more
* info see https://github.com/pmem/issues/issues/309.
*/
#ifdef __clang_analyzer__
static void custom_assert(void)
{
abort();
}
#define ANALYZER_ASSERT(x) (__builtin_expect(!(x), 0) ? (void)0 : custom_assert())
#else
#define ANALYZER_ASSERT(x) do {} while (0)
#endif
/*
* List definitions.
*/
#define LIST_HEAD(name, type) \
struct name { \
struct type *lh_first; /* first element */ \
}
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
#ifdef __cplusplus
#define _CAST_AND_ASSIGN(x, y) x = (__typeof__(x))y;
#else
#define _CAST_AND_ASSIGN(x, y) x = (void *)(y);
#endif
#define LIST_ENTRY(type) \
struct { \
struct type *le_next; /* next element */ \
struct type **le_prev; /* address of previous next element */ \
}
/*
* List functions.
*/
#define LIST_INIT(head) do { \
(head)->lh_first = NULL; \
} while (/*CONSTCOND*/0)
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
(listelm)->field.le_next->field.le_prev = \
&(elm)->field.le_next; \
(listelm)->field.le_next = (elm); \
(elm)->field.le_prev = &(listelm)->field.le_next; \
} while (/*CONSTCOND*/0)
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.le_prev = (listelm)->field.le_prev; \
(elm)->field.le_next = (listelm); \
*(listelm)->field.le_prev = (elm); \
(listelm)->field.le_prev = &(elm)->field.le_next; \
} while (/*CONSTCOND*/0)
#define LIST_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.le_next = (head)->lh_first) != NULL) \
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
(head)->lh_first = (elm); \
(elm)->field.le_prev = &(head)->lh_first; \
} while (/*CONSTCOND*/0)
#define LIST_REMOVE(elm, field) do { \
ANALYZER_ASSERT((elm) != NULL); \
if ((elm)->field.le_next != NULL) \
(elm)->field.le_next->field.le_prev = \
(elm)->field.le_prev; \
*(elm)->field.le_prev = (elm)->field.le_next; \
} while (/*CONSTCOND*/0)
#define LIST_FOREACH(var, head, field) \
for ((var) = ((head)->lh_first); \
(var); \
(var) = ((var)->field.le_next))
/*
* List access methods.
*/
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
#define LIST_FIRST(head) ((head)->lh_first)
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
/*
* Singly-linked List definitions.
*/
#define SLIST_HEAD(name, type) \
struct name { \
struct type *slh_first; /* first element */ \
}
#define SLIST_HEAD_INITIALIZER(head) \
{ NULL }
#define SLIST_ENTRY(type) \
struct { \
struct type *sle_next; /* next element */ \
}
/*
* Singly-linked List functions.
*/
#define SLIST_INIT(head) do { \
(head)->slh_first = NULL; \
} while (/*CONSTCOND*/0)
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
(elm)->field.sle_next = (slistelm)->field.sle_next; \
(slistelm)->field.sle_next = (elm); \
} while (/*CONSTCOND*/0)
#define SLIST_INSERT_HEAD(head, elm, field) do { \
(elm)->field.sle_next = (head)->slh_first; \
(head)->slh_first = (elm); \
} while (/*CONSTCOND*/0)
#define SLIST_REMOVE_HEAD(head, field) do { \
(head)->slh_first = (head)->slh_first->field.sle_next; \
} while (/*CONSTCOND*/0)
#define SLIST_REMOVE(head, elm, type, field) do { \
if ((head)->slh_first == (elm)) { \
SLIST_REMOVE_HEAD((head), field); \
} \
else { \
struct type *curelm = (head)->slh_first; \
while(curelm->field.sle_next != (elm)) \
curelm = curelm->field.sle_next; \
curelm->field.sle_next = \
curelm->field.sle_next->field.sle_next; \
} \
} while (/*CONSTCOND*/0)
#define SLIST_FOREACH(var, head, field) \
for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
/*
* Singly-linked List access methods.
*/
#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
#define SLIST_FIRST(head) ((head)->slh_first)
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
/*
* Singly-linked Tail queue declarations.
*/
#define STAILQ_HEAD(name, type) \
struct name { \
struct type *stqh_first; /* first element */ \
struct type **stqh_last; /* addr of last next element */ \
}
#define STAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).stqh_first }
#define STAILQ_ENTRY(type) \
struct { \
struct type *stqe_next; /* next element */ \
}
/*
* Singly-linked Tail queue functions.
*/
#define STAILQ_INIT(head) do { \
(head)->stqh_first = NULL; \
(head)->stqh_last = &(head)->stqh_first; \
} while (/*CONSTCOND*/0)
#define STAILQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \
(head)->stqh_last = &(elm)->field.stqe_next; \
(head)->stqh_first = (elm); \
} while (/*CONSTCOND*/0)
#define STAILQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.stqe_next = NULL; \
*(head)->stqh_last = (elm); \
(head)->stqh_last = &(elm)->field.stqe_next; \
} while (/*CONSTCOND*/0)
#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
(head)->stqh_last = &(elm)->field.stqe_next; \
(listelm)->field.stqe_next = (elm); \
} while (/*CONSTCOND*/0)
#define STAILQ_REMOVE_HEAD(head, field) do { \
if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == NULL) \
(head)->stqh_last = &(head)->stqh_first; \
} while (/*CONSTCOND*/0)
#define STAILQ_REMOVE(head, elm, type, field) do { \
if ((head)->stqh_first == (elm)) { \
STAILQ_REMOVE_HEAD((head), field); \
} else { \
struct type *curelm = (head)->stqh_first; \
while (curelm->field.stqe_next != (elm)) \
curelm = curelm->field.stqe_next; \
if ((curelm->field.stqe_next = \
curelm->field.stqe_next->field.stqe_next) == NULL) \
(head)->stqh_last = &(curelm)->field.stqe_next; \
} \
} while (/*CONSTCOND*/0)
#define STAILQ_FOREACH(var, head, field) \
for ((var) = ((head)->stqh_first); \
(var); \
(var) = ((var)->field.stqe_next))
#define STAILQ_CONCAT(head1, head2) do { \
if (!STAILQ_EMPTY((head2))) { \
*(head1)->stqh_last = (head2)->stqh_first; \
(head1)->stqh_last = (head2)->stqh_last; \
STAILQ_INIT((head2)); \
} \
} while (/*CONSTCOND*/0)
/*
* Singly-linked Tail queue access methods.
*/
#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
#define STAILQ_FIRST(head) ((head)->stqh_first)
#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
/*
* Simple queue definitions.
*/
#define SIMPLEQ_HEAD(name, type) \
struct name { \
struct type *sqh_first; /* first element */ \
struct type **sqh_last; /* addr of last next element */ \
}
#define SIMPLEQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).sqh_first }
#define SIMPLEQ_ENTRY(type) \
struct { \
struct type *sqe_next; /* next element */ \
}
/*
* Simple queue functions.
*/
#define SIMPLEQ_INIT(head) do { \
(head)->sqh_first = NULL; \
(head)->sqh_last = &(head)->sqh_first; \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
(head)->sqh_last = &(elm)->field.sqe_next; \
(head)->sqh_first = (elm); \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.sqe_next = NULL; \
*(head)->sqh_last = (elm); \
(head)->sqh_last = &(elm)->field.sqe_next; \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
(head)->sqh_last = &(elm)->field.sqe_next; \
(listelm)->field.sqe_next = (elm); \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_REMOVE_HEAD(head, field) do { \
if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
(head)->sqh_last = &(head)->sqh_first; \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_REMOVE(head, elm, type, field) do { \
if ((head)->sqh_first == (elm)) { \
SIMPLEQ_REMOVE_HEAD((head), field); \
} else { \
struct type *curelm = (head)->sqh_first; \
while (curelm->field.sqe_next != (elm)) \
curelm = curelm->field.sqe_next; \
if ((curelm->field.sqe_next = \
curelm->field.sqe_next->field.sqe_next) == NULL) \
(head)->sqh_last = &(curelm)->field.sqe_next; \
} \
} while (/*CONSTCOND*/0)
#define SIMPLEQ_FOREACH(var, head, field) \
for ((var) = ((head)->sqh_first); \
(var); \
(var) = ((var)->field.sqe_next))
/*
* Simple queue access methods.
*/
#define SIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL)
#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
/*
* Tail queue definitions.
*/
#define _TAILQ_HEAD(name, type, qual) \
struct name { \
qual type *tqh_first; /* first element */ \
qual type *qual *tqh_last; /* addr of last next element */ \
}
#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,)
#define TAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).tqh_first }
#define _TAILQ_ENTRY(type, qual) \
struct { \
qual type *tqe_next; /* next element */ \
qual type *qual *tqe_prev; /* address of previous next element */\
}
#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type,)
/*
* Tail queue functions.
*/
#define TAILQ_INIT(head) do { \
(head)->tqh_first = NULL; \
(head)->tqh_last = &(head)->tqh_first; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
(head)->tqh_first->field.tqe_prev = \
&(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(head)->tqh_first = (elm); \
(elm)->field.tqe_prev = &(head)->tqh_first; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.tqe_next = NULL; \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &(elm)->field.tqe_next; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
(elm)->field.tqe_next->field.tqe_prev = \
&(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(listelm)->field.tqe_next = (elm); \
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
} while (/*CONSTCOND*/0)
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
(elm)->field.tqe_next = (listelm); \
*(listelm)->field.tqe_prev = (elm); \
(listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
} while (/*CONSTCOND*/0)
#define TAILQ_REMOVE(head, elm, field) do { \
ANALYZER_ASSERT((elm) != NULL); \
if (((elm)->field.tqe_next) != NULL) \
(elm)->field.tqe_next->field.tqe_prev = \
(elm)->field.tqe_prev; \
else \
(head)->tqh_last = (elm)->field.tqe_prev; \
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
} while (/*CONSTCOND*/0)
#define TAILQ_FOREACH(var, head, field) \
for ((var) = ((head)->tqh_first); \
(var); \
(var) = ((var)->field.tqe_next))
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \
(var); \
(var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
#define TAILQ_CONCAT(head1, head2, field) do { \
if (!TAILQ_EMPTY(head2)) { \
*(head1)->tqh_last = (head2)->tqh_first; \
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
(head1)->tqh_last = (head2)->tqh_last; \
TAILQ_INIT((head2)); \
} \
} while (/*CONSTCOND*/0)
/*
* Tail queue access methods.
*/
#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
#define TAILQ_FIRST(head) ((head)->tqh_first)
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
#define TAILQ_LAST(head, headname) \
(*(((struct headname *)((head)->tqh_last))->tqh_last))
#define TAILQ_PREV(elm, headname, field) \
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
/*
* Circular queue definitions.
*/
#define CIRCLEQ_HEAD(name, type) \
struct name { \
struct type *cqh_first; /* first element */ \
struct type *cqh_last; /* last element */ \
}
#define CIRCLEQ_HEAD_INITIALIZER(head) \
{ (void *)&(head), (void *)&(head) }
#define CIRCLEQ_ENTRY(type) \
struct { \
struct type *cqe_next; /* next element */ \
struct type *cqe_prev; /* previous element */ \
}
/*
* Circular queue functions.
*/
#define CIRCLEQ_INIT(head) do { \
_CAST_AND_ASSIGN((head)->cqh_first, (head)); \
_CAST_AND_ASSIGN((head)->cqh_last, (head)); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
(elm)->field.cqe_prev = (listelm); \
if ((listelm)->field.cqe_next == (void *)(head)) \
(head)->cqh_last = (elm); \
else \
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
(listelm)->field.cqe_next = (elm); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
(elm)->field.cqe_next = (listelm); \
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
if ((listelm)->field.cqe_prev == (void *)(head)) \
(head)->cqh_first = (elm); \
else \
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
(listelm)->field.cqe_prev = (elm); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
(elm)->field.cqe_next = (head)->cqh_first; \
(elm)->field.cqe_prev = (void *)(head); \
if ((head)->cqh_last == (void *)(head)) \
(head)->cqh_last = (elm); \
else \
(head)->cqh_first->field.cqe_prev = (elm); \
(head)->cqh_first = (elm); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
_CAST_AND_ASSIGN((elm)->field.cqe_next, (head)); \
(elm)->field.cqe_prev = (head)->cqh_last; \
if ((head)->cqh_first == (void *)(head)) \
(head)->cqh_first = (elm); \
else \
(head)->cqh_last->field.cqe_next = (elm); \
(head)->cqh_last = (elm); \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_REMOVE(head, elm, field) do { \
if ((elm)->field.cqe_next == (void *)(head)) \
(head)->cqh_last = (elm)->field.cqe_prev; \
else \
(elm)->field.cqe_next->field.cqe_prev = \
(elm)->field.cqe_prev; \
if ((elm)->field.cqe_prev == (void *)(head)) \
(head)->cqh_first = (elm)->field.cqe_next; \
else \
(elm)->field.cqe_prev->field.cqe_next = \
(elm)->field.cqe_next; \
} while (/*CONSTCOND*/0)
#define CIRCLEQ_FOREACH(var, head, field) \
for ((var) = ((head)->cqh_first); \
(var) != (const void *)(head); \
(var) = ((var)->field.cqe_next))
#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
for ((var) = ((head)->cqh_last); \
(var) != (const void *)(head); \
(var) = ((var)->field.cqe_prev))
/*
* Circular queue access methods.
*/
#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
#define CIRCLEQ_LAST(head) ((head)->cqh_last)
#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
#define CIRCLEQ_LOOP_NEXT(head, elm, field) \
(((elm)->field.cqe_next == (void *)(head)) \
? ((head)->cqh_first) \
: ((elm)->field.cqe_next))
#define CIRCLEQ_LOOP_PREV(head, elm, field) \
(((elm)->field.cqe_prev == (void *)(head)) \
? ((head)->cqh_last) \
: ((elm)->field.cqe_prev))
/*
* Sorted queue functions.
*/
#define SORTEDQ_HEAD(name, type) CIRCLEQ_HEAD(name, type)
#define SORTEDQ_HEAD_INITIALIZER(head) CIRCLEQ_HEAD_INITIALIZER(head)
#define SORTEDQ_ENTRY(type) CIRCLEQ_ENTRY(type)
#define SORTEDQ_INIT(head) CIRCLEQ_INIT(head)
#define SORTEDQ_INSERT(head, elm, field, type, comparer) { \
type *_elm_it; \
for (_elm_it = (head)->cqh_first; \
((_elm_it != (void *)(head)) && \
(comparer(_elm_it, (elm)) < 0)); \
_elm_it = _elm_it->field.cqe_next) \
/*NOTHING*/; \
if (_elm_it == (void *)(head)) \
CIRCLEQ_INSERT_TAIL(head, elm, field); \
else \
CIRCLEQ_INSERT_BEFORE(head, _elm_it, elm, field); \
}
#define SORTEDQ_REMOVE(head, elm, field) CIRCLEQ_REMOVE(head, elm, field)
#define SORTEDQ_FOREACH(var, head, field) CIRCLEQ_FOREACH(var, head, field)
#define SORTEDQ_FOREACH_REVERSE(var, head, field) \
CIRCLEQ_FOREACH_REVERSE(var, head, field)
/*
* Sorted queue access methods.
*/
#define SORTEDQ_EMPTY(head) CIRCLEQ_EMPTY(head)
#define SORTEDQ_FIRST(head) CIRCLEQ_FIRST(head)
#define SORTEDQ_LAST(head) CIRCLEQ_LAST(head)
#define SORTEDQ_NEXT(elm, field) CIRCLEQ_NEXT(elm, field)
#define SORTEDQ_PREV(elm, field) CIRCLEQ_PREV(elm, field)
#endif /* sys/queue.h */
| 21,518
| 32.888189
| 82
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/set.h
|
/*
* Copyright 2014-2018, Intel Corporation
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* set.h -- internal definitions for set module
*/
#ifndef PMDK_SET_H
#define PMDK_SET_H 1
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include "out.h"
#include "vec.h"
#include "pool_hdr.h"
#include "librpmem.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* pool sets & replicas
*/
#define POOLSET_HDR_SIG "PMEMPOOLSET"
#define POOLSET_HDR_SIG_LEN 11 /* does NOT include '\0' */
#define POOLSET_REPLICA_SIG "REPLICA"
#define POOLSET_REPLICA_SIG_LEN 7 /* does NOT include '\0' */
#define POOLSET_OPTION_SIG "OPTION"
#define POOLSET_OPTION_SIG_LEN 6 /* does NOT include '\0' */
/* pool set option flags */
enum pool_set_option_flag {
OPTION_UNKNOWN = 0x0,
OPTION_SINGLEHDR = 0x1, /* pool headers only in the first part */
OPTION_NOHDRS = 0x2, /* no pool headers, remote replicas only */
};
struct pool_set_option {
const char *name;
enum pool_set_option_flag flag;
};
#define POOL_LOCAL 0
#define POOL_REMOTE 1
#define REPLICAS_DISABLED 0
#define REPLICAS_ENABLED 1
/* util_pool_open flags */
#define POOL_OPEN_COW 1 /* copy-on-write mode */
#define POOL_OPEN_IGNORE_SDS 2 /* ignore shutdown state */
#define POOL_OPEN_IGNORE_BAD_BLOCKS 4 /* ignore bad blocks */
#define POOL_OPEN_CHECK_BAD_BLOCKS 8 /* check bad blocks */
enum del_parts_mode {
DO_NOT_DELETE_PARTS, /* do not delete part files */
DELETE_CREATED_PARTS, /* delete only newly created parts files */
DELETE_ALL_PARTS /* force delete all parts files */
};
struct pool_set_part {
/* populated by a pool set file parser */
const char *path;
size_t filesize; /* aligned to page size */
int fd;
int flags; /* stores flags used when opening the file */
/* valid only if fd >= 0 */
int is_dev_dax; /* indicates if the part is on device dax */
size_t alignment; /* internal alignment (Device DAX only) */
int created; /* indicates newly created (zeroed) file */
/* util_poolset_open/create */
void *remote_hdr; /* allocated header for remote replica */
void *hdr; /* base address of header */
size_t hdrsize; /* size of the header mapping */
int hdr_map_sync; /* header mapped with MAP_SYNC */
void *addr; /* base address of the mapping */
size_t size; /* size of the mapping - page aligned */
int map_sync; /* part has been mapped with MAP_SYNC flag */
int rdonly; /* is set based on compat features, affects */
/* the whole poolset */
uuid_t uuid;
int has_bad_blocks; /* part file contains bad blocks */
int sds_dirty_modified; /* sds dirty flag was set */
};
struct pool_set_directory {
const char *path;
size_t resvsize; /* size of the address space reservation */
};
struct remote_replica {
void *rpp; /* RPMEMpool opaque handle */
char *node_addr; /* address of a remote node */
/* poolset descriptor is a pool set file name on a remote node */
char *pool_desc; /* descriptor of a poolset */
};
struct pool_replica {
unsigned nparts;
unsigned nallocated;
unsigned nhdrs; /* should be 0, 1 or nparts */
size_t repsize; /* total size of all the parts (mappings) */
size_t resvsize; /* min size of the address space reservation */
int is_pmem; /* true if all the parts are in PMEM */
void *mapaddr; /* base address (libpmemcto only) */
struct remote_replica *remote; /* not NULL if the replica */
/* is a remote one */
VEC(, struct pool_set_directory) directory;
struct pool_set_part part[];
};
struct pool_set {
char *path; /* path of the poolset file */
unsigned nreplicas;
uuid_t uuid;
int rdonly;
int zeroed; /* true if all the parts are new files */
size_t poolsize; /* the smallest replica size */
int has_bad_blocks; /* pool set contains bad blocks */
int remote; /* true if contains a remote replica */
unsigned options; /* enabled pool set options */
int directory_based;
size_t resvsize;
unsigned next_id;
unsigned next_directory_id;
int ignore_sds; /* don't use shutdown state */
struct pool_replica *replica[];
};
struct part_file {
int is_remote;
/*
* Pointer to the part file structure -
* - not-NULL only for a local part file
*/
struct pool_set_part *part;
/*
* Pointer to the replica structure -
* - not-NULL only for a remote replica
*/
struct remote_replica *remote;
};
struct pool_attr {
char signature[POOL_HDR_SIG_LEN]; /* pool signature */
uint32_t major; /* format major version number */
features_t features; /* features flags */
unsigned char poolset_uuid[POOL_HDR_UUID_LEN]; /* pool uuid */
unsigned char first_part_uuid[POOL_HDR_UUID_LEN]; /* first part uuid */
unsigned char prev_repl_uuid[POOL_HDR_UUID_LEN]; /* prev replica uuid */
unsigned char next_repl_uuid[POOL_HDR_UUID_LEN]; /* next replica uuid */
unsigned char arch_flags[POOL_HDR_ARCH_LEN]; /* arch flags */
};
/* get index of the (r)th replica */
static inline unsigned
REPidx(const struct pool_set *set, unsigned r)
{
ASSERTne(set->nreplicas, 0);
return (set->nreplicas + r) % set->nreplicas;
}
/* get index of the (r + 1)th replica */
static inline unsigned
REPNidx(const struct pool_set *set, unsigned r)
{
ASSERTne(set->nreplicas, 0);
return (set->nreplicas + r + 1) % set->nreplicas;
}
/* get index of the (r - 1)th replica */
static inline unsigned
REPPidx(const struct pool_set *set, unsigned r)
{
ASSERTne(set->nreplicas, 0);
return (set->nreplicas + r - 1) % set->nreplicas;
}
/* get index of the (r)th part */
static inline unsigned
PARTidx(const struct pool_replica *rep, unsigned p)
{
ASSERTne(rep->nparts, 0);
return (rep->nparts + p) % rep->nparts;
}
/* get index of the (r + 1)th part */
static inline unsigned
PARTNidx(const struct pool_replica *rep, unsigned p)
{
ASSERTne(rep->nparts, 0);
return (rep->nparts + p + 1) % rep->nparts;
}
/* get index of the (r - 1)th part */
static inline unsigned
PARTPidx(const struct pool_replica *rep, unsigned p)
{
ASSERTne(rep->nparts, 0);
return (rep->nparts + p - 1) % rep->nparts;
}
/* get index of the (r)th part */
static inline unsigned
HDRidx(const struct pool_replica *rep, unsigned p)
{
ASSERTne(rep->nhdrs, 0);
return (rep->nhdrs + p) % rep->nhdrs;
}
/* get index of the (r + 1)th part */
static inline unsigned
HDRNidx(const struct pool_replica *rep, unsigned p)
{
ASSERTne(rep->nhdrs, 0);
return (rep->nhdrs + p + 1) % rep->nhdrs;
}
/* get index of the (r - 1)th part */
static inline unsigned
HDRPidx(const struct pool_replica *rep, unsigned p)
{
ASSERTne(rep->nhdrs, 0);
return (rep->nhdrs + p - 1) % rep->nhdrs;
}
/* get (r)th replica */
static inline struct pool_replica *
REP(const struct pool_set *set, unsigned r)
{
return set->replica[REPidx(set, r)];
}
/* get (r + 1)th replica */
static inline struct pool_replica *
REPN(const struct pool_set *set, unsigned r)
{
return set->replica[REPNidx(set, r)];
}
/* get (r - 1)th replica */
static inline struct pool_replica *
REPP(const struct pool_set *set, unsigned r)
{
return set->replica[REPPidx(set, r)];
}
/* get (p)th part */
static inline struct pool_set_part *
PART(struct pool_replica *rep, unsigned p)
{
return &rep->part[PARTidx(rep, p)];
}
/* get (p + 1)th part */
static inline struct pool_set_part *
PARTN(struct pool_replica *rep, unsigned p)
{
return &rep->part[PARTNidx(rep, p)];
}
/* get (p - 1)th part */
static inline struct pool_set_part *
PARTP(struct pool_replica *rep, unsigned p)
{
return &rep->part[PARTPidx(rep, p)];
}
/* get (p)th header */
static inline struct pool_hdr *
HDR(struct pool_replica *rep, unsigned p)
{
return (struct pool_hdr *)(rep->part[HDRidx(rep, p)].hdr);
}
/* get (p + 1)th header */
static inline struct pool_hdr *
HDRN(struct pool_replica *rep, unsigned p)
{
return (struct pool_hdr *)(rep->part[HDRNidx(rep, p)].hdr);
}
/* get (p - 1)th header */
static inline struct pool_hdr *
HDRP(struct pool_replica *rep, unsigned p)
{
return (struct pool_hdr *)(rep->part[HDRPidx(rep, p)].hdr);
}
extern int Prefault_at_open;
extern int Prefault_at_create;
int util_poolset_parse(struct pool_set **setp, const char *path, int fd);
int util_poolset_read(struct pool_set **setp, const char *path);
int util_poolset_create_set(struct pool_set **setp, const char *path,
size_t poolsize, size_t minsize, int ignore_sds);
int util_poolset_open(struct pool_set *set);
void util_poolset_close(struct pool_set *set, enum del_parts_mode del);
void util_poolset_free(struct pool_set *set);
int util_poolset_chmod(struct pool_set *set, mode_t mode);
void util_poolset_fdclose(struct pool_set *set);
void util_poolset_fdclose_always(struct pool_set *set);
int util_is_poolset_file(const char *path);
int util_poolset_foreach_part_struct(struct pool_set *set,
int (*cb)(struct part_file *pf, void *arg), void *arg);
int util_poolset_foreach_part(const char *path,
int (*cb)(struct part_file *pf, void *arg), void *arg);
size_t util_poolset_size(const char *path);
int util_replica_deep_common(const void *addr, size_t len,
struct pool_set *set, unsigned replica_id, int flush);
int util_replica_deep_persist(const void *addr, size_t len,
struct pool_set *set, unsigned replica_id);
int util_replica_deep_drain(const void *addr, size_t len,
struct pool_set *set, unsigned replica_id);
int util_pool_create(struct pool_set **setp, const char *path, size_t poolsize,
size_t minsize, size_t minpartsize, const struct pool_attr *attr,
unsigned *nlanes, int can_have_rep);
int util_pool_create_uuids(struct pool_set **setp, const char *path,
size_t poolsize, size_t minsize, size_t minpartsize,
const struct pool_attr *attr, unsigned *nlanes, int can_have_rep,
int remote);
int util_part_open(struct pool_set_part *part, size_t minsize, int create);
void util_part_fdclose(struct pool_set_part *part);
int util_replica_open(struct pool_set *set, unsigned repidx, int flags);
int util_replica_set_attr(struct pool_replica *rep,
const struct rpmem_pool_attr *rattr);
void util_pool_hdr2attr(struct pool_attr *attr, struct pool_hdr *hdr);
void util_pool_attr2hdr(struct pool_hdr *hdr,
const struct pool_attr *attr);
int util_replica_close(struct pool_set *set, unsigned repidx);
int util_map_part(struct pool_set_part *part, void *addr, size_t size,
size_t offset, int flags, int rdonly);
int util_unmap_part(struct pool_set_part *part);
int util_unmap_parts(struct pool_replica *rep, unsigned start_index,
unsigned end_index);
int util_header_create(struct pool_set *set, unsigned repidx, unsigned partidx,
const struct pool_attr *attr, int overwrite);
int util_map_hdr(struct pool_set_part *part, int flags, int rdonly);
int util_unmap_hdr(struct pool_set_part *part);
int util_pool_has_device_dax(struct pool_set *set);
int util_pool_open_nocheck(struct pool_set *set, unsigned flags);
int util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize,
const struct pool_attr *attr, unsigned *nlanes, void *addr,
unsigned flags);
int util_pool_open_remote(struct pool_set **setp, const char *path, int cow,
size_t minpartsize, struct rpmem_pool_attr *rattr);
void *util_pool_extend(struct pool_set *set, size_t *size, size_t minpartsize);
void util_remote_init(void);
void util_remote_fini(void);
int util_update_remote_header(struct pool_set *set, unsigned repn);
void util_remote_init_lock(void);
void util_remote_destroy_lock(void);
int util_pool_close_remote(RPMEMpool *rpp);
void util_remote_unload(void);
void util_replica_fdclose(struct pool_replica *rep);
int util_poolset_remote_open(struct pool_replica *rep, unsigned repidx,
size_t minsize, int create, void *pool_addr,
size_t pool_size, unsigned *nlanes);
int util_remote_load(void);
int util_replica_open_remote(struct pool_set *set, unsigned repidx, int flags);
int util_poolset_remote_replica_open(struct pool_set *set, unsigned repidx,
size_t minsize, int create, unsigned *nlanes);
int util_replica_close_local(struct pool_replica *rep, unsigned repn,
enum del_parts_mode del);
int util_replica_close_remote(struct pool_replica *rep, unsigned repn,
enum del_parts_mode del);
extern int (*Rpmem_persist)(RPMEMpool *rpp, size_t offset, size_t length,
unsigned lane, unsigned flags);
extern int (*Rpmem_deep_persist)(RPMEMpool *rpp, size_t offset, size_t length,
unsigned lane);
extern int (*Rpmem_read)(RPMEMpool *rpp, void *buff, size_t offset,
size_t length, unsigned lane);
extern int (*Rpmem_close)(RPMEMpool *rpp);
extern int (*Rpmem_remove)(const char *target,
const char *pool_set_name, int flags);
extern int (*Rpmem_set_attr)(RPMEMpool *rpp,
const struct rpmem_pool_attr *rattr);
#ifdef __cplusplus
}
#endif
#endif
| 14,162
| 31.261959
| 80
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_dimm_windows.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_dimm_windows.c -- implementation of DIMMs API based on winapi
*/
#include "out.h"
#include "os.h"
#include "os_dimm.h"
#include "util.h"
#define GUID_SIZE sizeof("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
/*
* os_dimm_volume -- returns volume handle
*/
static HANDLE
os_dimm_volume_handle(const char *path)
{
wchar_t mount[MAX_PATH];
wchar_t volume[MAX_PATH];
wchar_t *wpath = util_toUTF16(path);
if (wpath == NULL)
return INVALID_HANDLE_VALUE;
if (!GetVolumePathNameW(wpath, mount, MAX_PATH)) {
ERR("!GetVolumePathNameW");
util_free_UTF16(wpath);
return INVALID_HANDLE_VALUE;
}
util_free_UTF16(wpath);
/* get volume name - "\\?\Volume{VOLUME_GUID}\" */
if (!GetVolumeNameForVolumeMountPointW(mount, volume, MAX_PATH) ||
wcslen(volume) == 0 || volume[wcslen(volume) - 1] != L'\\') {
ERR("!GetVolumeNameForVolumeMountPointW");
return INVALID_HANDLE_VALUE;
}
/*
* Remove trailing \\ as "CreateFile processes a volume GUID path with
* an appended backslash as the root directory of the volume."
*/
volume[wcslen(volume) - 1] = L'\0';
HANDLE h = CreateFileW(volume, /* path to the file */
/* request access to send ioctl to the file */
FILE_READ_ATTRIBUTES,
/* do not block access to the file */
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL, /* security attributes */
OPEN_EXISTING, /* open only if it exists */
FILE_ATTRIBUTE_NORMAL, /* no attributes */
NULL); /* used only for new files */
if (h == INVALID_HANDLE_VALUE)
ERR("!CreateFileW");
return h;
}
/*
* os_dimm_uid -- returns a file uid based on dimm guid
*/
int
os_dimm_uid(const char *path, char *uid, size_t *len)
{
LOG(3, "path %s, uid %p, len %lu", path, uid, *len);
if (uid == NULL) {
*len = GUID_SIZE;
} else {
ASSERT(*len >= GUID_SIZE);
HANDLE vHandle = os_dimm_volume_handle(path);
if (vHandle == INVALID_HANDLE_VALUE)
return -1;
STORAGE_DEVICE_NUMBER_EX sdn;
sdn.DeviceNumber = -1;
DWORD dwBytesReturned = 0;
if (!DeviceIoControl(vHandle,
IOCTL_STORAGE_GET_DEVICE_NUMBER_EX,
NULL, 0,
&sdn, sizeof(sdn),
&dwBytesReturned, NULL)) {
/*
* IOCTL_STORAGE_GET_DEVICE_NUMBER_EX is not supported
* on this server
*/
memset(uid, 0, *len);
CloseHandle(vHandle);
return 0;
}
GUID guid = sdn.DeviceGuid;
snprintf(uid, GUID_SIZE,
"%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX",
guid.Data1, guid.Data2, guid.Data3, guid.Data4[0],
guid.Data4[1], guid.Data4[2], guid.Data4[3],
guid.Data4[4], guid.Data4[5], guid.Data4[6],
guid.Data4[7]);
CloseHandle(vHandle);
}
return 0;
}
/*
* os_dimm_usc -- returns unsafe shutdown count
*/
int
os_dimm_usc(const char *path, uint64_t *usc)
{
LOG(3, "path %s, usc %p", path, usc);
*usc = 0;
HANDLE vHandle = os_dimm_volume_handle(path);
if (vHandle == INVALID_HANDLE_VALUE)
return -1;
STORAGE_PROPERTY_QUERY prop;
DWORD dwSize;
prop.PropertyId = StorageDeviceUnsafeShutdownCount;
prop.QueryType = PropertyExistsQuery;
prop.AdditionalParameters[0] = 0;
STORAGE_DEVICE_UNSAFE_SHUTDOWN_COUNT ret;
BOOL bResult = DeviceIoControl(vHandle,
IOCTL_STORAGE_QUERY_PROPERTY,
&prop, sizeof(prop),
&ret, sizeof(ret),
(LPDWORD)&dwSize, (LPOVERLAPPED)NULL);
if (!bResult) {
CloseHandle(vHandle);
return 0; /* STORAGE_PROPERTY_QUERY not supported */
}
prop.QueryType = PropertyStandardQuery;
bResult = DeviceIoControl(vHandle,
IOCTL_STORAGE_QUERY_PROPERTY,
&prop, sizeof(prop),
&ret, sizeof(ret),
(LPDWORD)&dwSize, (LPOVERLAPPED)NULL);
CloseHandle(vHandle);
if (!bResult)
return -1;
*usc = ret.UnsafeShutdownCount;
return 0;
}
/*
* os_dimm_files_namespace_badblocks -- fake os_dimm_files_namespace_badblocks()
*/
int
os_dimm_files_namespace_badblocks(const char *path, struct badblocks *bbs)
{
LOG(3, "path %s", path);
os_stat_t st;
if (os_stat(path, &st)) {
ERR("!stat %s", path);
return -1;
}
return 0;
}
/*
* os_dimm_devdax_clear_badblocks -- fake bad block clearing routine
*/
int
os_dimm_devdax_clear_badblocks(const char *path, struct badblocks *bbs)
{
LOG(3, "path %s badblocks %p", path, bbs);
return 0;
}
/*
* os_dimm_devdax_clear_badblocks_all -- fake bad block clearing routine
*/
int
os_dimm_devdax_clear_badblocks_all(const char *path)
{
LOG(3, "path %s", path);
return 0;
}
| 5,931
| 26.086758
| 80
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/dlsym.h
|
/*
* Copyright 2016-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* dlsym.h -- dynamic linking utilities with library-specific implementation
*/
#ifndef PMDK_DLSYM_H
#define PMDK_DLSYM_H 1
#include "out.h"
#if defined(USE_LIBDL) && !defined(_WIN32)
#include <dlfcn.h>
/*
* util_dlopen -- calls real dlopen()
*/
static inline void *
util_dlopen(const char *filename)
{
LOG(3, "filename %s", filename);
return dlopen(filename, RTLD_NOW);
}
/*
* util_dlerror -- calls real dlerror()
*/
static inline char *
util_dlerror(void)
{
return dlerror();
}
/*
* util_dlsym -- calls real dlsym()
*/
static inline void *
util_dlsym(void *handle, const char *symbol)
{
LOG(3, "handle %p symbol %s", handle, symbol);
return dlsym(handle, symbol);
}
/*
* util_dlclose -- calls real dlclose()
*/
static inline int
util_dlclose(void *handle)
{
LOG(3, "handle %p", handle);
return dlclose(handle);
}
#else /* empty functions */
/*
* util_dlopen -- empty function
*/
static inline void *
util_dlopen(const char *filename)
{
errno = ENOSYS;
return NULL;
}
/*
* util_dlerror -- empty function
*/
static inline char *
util_dlerror(void)
{
errno = ENOSYS;
return NULL;
}
/*
* util_dlsym -- empty function
*/
static inline void *
util_dlsym(void *handle, const char *symbol)
{
errno = ENOSYS;
return NULL;
}
/*
* util_dlclose -- empty function
*/
static inline int
util_dlclose(void *handle)
{
errno = ENOSYS;
return 0;
}
#endif
#endif
| 3,000
| 21.56391
| 76
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/shutdown_state.c
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* shutdown_state.c -- unsafe shudown detection
*/
#include <string.h>
#include <stdbool.h>
#include <endian.h>
#include "shutdown_state.h"
#include "os_dimm.h"
#include "out.h"
#include "util.h"
#include "os_deep.h"
#include "set.h"
#define FLUSH_SDS(sds, rep) \
if ((rep) != NULL) os_part_deep_common(rep, 0, sds, sizeof(*(sds)), 1)
/*
* shutdown_state_checksum -- (internal) counts SDS checksum and flush it
*/
static void
shutdown_state_checksum(struct shutdown_state *sds, struct pool_replica *rep)
{
LOG(3, "sds %p", sds);
util_checksum(sds, sizeof(*sds), &sds->checksum, 1, 0);
FLUSH_SDS(sds, rep);
}
/*
* shutdown_state_init -- initializes shutdown_state struct
*/
int
shutdown_state_init(struct shutdown_state *sds, struct pool_replica *rep)
{
/* check if we didn't change size of shutdown_state accidentally */
COMPILE_ERROR_ON(sizeof(struct shutdown_state) != 64);
LOG(3, "sds %p", sds);
memset(sds, 0, sizeof(*sds));
shutdown_state_checksum(sds, rep);
return 0;
}
/*
* shutdown_state_add_part -- adds file uuid and usc to shutdown_state struct
*
* if path does not exist it will fail which does NOT mean shutdown failure
*/
int
shutdown_state_add_part(struct shutdown_state *sds, const char *path,
struct pool_replica *rep)
{
LOG(3, "sds %p, path %s", sds, path);
size_t len = 0;
char *uid;
uint64_t usc;
if (os_dimm_usc(path, &usc)) {
ERR("cannot read unsafe shutdown count of %s", path);
return 1;
}
if (os_dimm_uid(path, NULL, &len)) {
ERR("cannot read uuid of %s", path);
return 1;
}
len += 4 - len % 4;
uid = Zalloc(len);
if (uid == NULL) {
ERR("!Zalloc");
return 1;
}
if (os_dimm_uid(path, uid, &len)) {
ERR("cannot read uuid of %s", path);
Free(uid);
return 1;
}
sds->usc = htole64(le64toh(sds->usc) + usc);
uint64_t tmp;
util_checksum(uid, len, &tmp, 1, 0);
sds->uuid = htole64(le64toh(sds->uuid) + tmp);
FLUSH_SDS(sds, rep);
Free(uid);
shutdown_state_checksum(sds, rep);
return 0;
}
/*
* shutdown_state_set_dirty -- sets dirty pool flag
*/
void
shutdown_state_set_dirty(struct shutdown_state *sds, struct pool_replica *rep)
{
LOG(3, "sds %p", sds);
sds->dirty = 1;
rep->part[0].sds_dirty_modified = 1;
FLUSH_SDS(sds, rep);
shutdown_state_checksum(sds, rep);
}
/*
* shutdown_state_clear_dirty -- clears dirty pool flag
*/
void
shutdown_state_clear_dirty(struct shutdown_state *sds, struct pool_replica *rep)
{
LOG(3, "sds %p", sds);
struct pool_set_part part = rep->part[0];
/*
* If a dirty flag was set in previous program execution it should be
* preserved as it stores information about potential ADR failure.
*/
if (part.sds_dirty_modified != 1)
return;
sds->dirty = 0;
part.sds_dirty_modified = 0;
FLUSH_SDS(sds, rep);
shutdown_state_checksum(sds, rep);
}
/*
* shutdown_state_reinit -- (internal) reinitializes shutdown_state struct
*/
static void
shutdown_state_reinit(struct shutdown_state *curr_sds,
struct shutdown_state *pool_sds, struct pool_replica *rep)
{
LOG(3, "curr_sds %p, pool_sds %p", curr_sds, pool_sds);
shutdown_state_init(pool_sds, rep);
pool_sds->uuid = htole64(curr_sds->uuid);
pool_sds->usc = htole64(curr_sds->usc);
pool_sds->dirty = 0;
FLUSH_SDS(pool_sds, rep);
shutdown_state_checksum(pool_sds, rep);
}
/*
* shutdown_state_check -- compares and fixes shutdown state
*/
int
shutdown_state_check(struct shutdown_state *curr_sds,
struct shutdown_state *pool_sds, struct pool_replica *rep)
{
LOG(3, "curr_sds %p, pool_sds %p", curr_sds, pool_sds);
if (util_is_zeroed(pool_sds, sizeof(*pool_sds)) &&
!util_is_zeroed(curr_sds, sizeof(*curr_sds))) {
shutdown_state_reinit(curr_sds, pool_sds, rep);
return 0;
}
bool is_uuid_usc_correct =
le64toh(pool_sds->usc) == le64toh(curr_sds->usc) &&
le64toh(pool_sds->uuid) == le64toh(curr_sds->uuid);
bool is_checksum_correct = util_checksum(pool_sds,
sizeof(*pool_sds), &pool_sds->checksum, 0, 0);
int dirty = pool_sds->dirty;
if (!is_checksum_correct) {
/* the program was killed during opening or closing the pool */
LOG(2, "incorrect checksum - SDS will be reinitialized");
shutdown_state_reinit(curr_sds, pool_sds, rep);
return 0;
}
if (is_uuid_usc_correct) {
if (dirty == 0)
return 0;
/*
* the program was killed when the pool was opened
* but there wasn't an ADR failure
*/
LOG(2,
"the pool was not closed - SDS will be reinitialized");
shutdown_state_reinit(curr_sds, pool_sds, rep);
return 0;
}
if (dirty == 0) {
/* an ADR failure but the pool was closed */
LOG(2,
"an ADR failure was detected but the pool was closed - SDS will be reinitialized");
shutdown_state_reinit(curr_sds, pool_sds, rep);
return 0;
}
/* an ADR failure - the pool might be corrupted */
ERR("an ADR failure was detected, the pool might be corrupted");
return 1;
}
| 6,440
| 25.615702
| 86
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_thread_windows.c
|
/*
* Copyright 2015-2018, Intel Corporation
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_thread_windows.c -- (imperfect) POSIX-like threads for Windows
*
* Loosely inspired by:
* http://locklessinc.com/articles/pthreads_on_windows/
*/
#include <time.h>
#include <synchapi.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include "os_thread.h"
#include "util.h"
#include "out.h"
typedef struct {
unsigned attr;
CRITICAL_SECTION lock;
} internal_os_mutex_t;
typedef struct {
unsigned attr;
char is_write;
SRWLOCK lock;
} internal_os_rwlock_t;
typedef struct {
unsigned attr;
CONDITION_VARIABLE cond;
} internal_os_cond_t;
typedef long long internal_os_once_t;
typedef struct {
HANDLE handle;
} internal_semaphore_t;
typedef struct {
GROUP_AFFINITY affinity;
} internal_os_cpu_set_t;
typedef struct {
HANDLE thread_handle;
void *arg;
void *(*start_routine)(void *);
void *result;
} internal_os_thread_t;
/* number of useconds between 1970-01-01T00:00:00Z and 1601-01-01T00:00:00Z */
#define DELTA_WIN2UNIX (11644473600000000ull)
#define TIMED_LOCK(action, ts) {\
if ((action) == TRUE)\
return 0;\
unsigned long long et = (ts)->tv_sec * 1000000000 + (ts)->tv_nsec;\
while (1) {\
FILETIME _t;\
GetSystemTimeAsFileTime(&_t);\
ULARGE_INTEGER _UI = {\
.HighPart = _t.dwHighDateTime,\
.LowPart = _t.dwLowDateTime,\
};\
if (100 * _UI.QuadPart - 1000 * DELTA_WIN2UNIX >= et)\
return ETIMEDOUT;\
if ((action) == TRUE)\
return 0;\
Sleep(1);\
}\
return ETIMEDOUT;\
}
/*
* os_mutex_init -- initializes mutex
*/
int
os_mutex_init(os_mutex_t *__restrict mutex)
{
COMPILE_ERROR_ON(sizeof(os_mutex_t) < sizeof(internal_os_mutex_t));
internal_os_mutex_t *mutex_internal = (internal_os_mutex_t *)mutex;
InitializeCriticalSection(&mutex_internal->lock);
return 0;
}
/*
* os_mutex_destroy -- destroys mutex
*/
int
os_mutex_destroy(os_mutex_t *__restrict mutex)
{
internal_os_mutex_t *mutex_internal = (internal_os_mutex_t *)mutex;
DeleteCriticalSection(&mutex_internal->lock);
return 0;
}
/*
* os_mutex_lock -- locks mutex
*/
_Use_decl_annotations_
int
os_mutex_lock(os_mutex_t *__restrict mutex)
{
internal_os_mutex_t *mutex_internal = (internal_os_mutex_t *)mutex;
EnterCriticalSection(&mutex_internal->lock);
if (mutex_internal->lock.RecursionCount > 1) {
LeaveCriticalSection(&mutex_internal->lock);
FATAL("deadlock detected");
}
return 0;
}
/*
* os_mutex_trylock -- tries lock mutex
*/
_Use_decl_annotations_
int
os_mutex_trylock(os_mutex_t *__restrict mutex)
{
internal_os_mutex_t *mutex_internal = (internal_os_mutex_t *)mutex;
if (TryEnterCriticalSection(&mutex_internal->lock) == FALSE)
return EBUSY;
if (mutex_internal->lock.RecursionCount > 1) {
LeaveCriticalSection(&mutex_internal->lock);
return EBUSY;
}
return 0;
}
/*
* os_mutex_timedlock -- tries lock mutex with timeout
*/
int
os_mutex_timedlock(os_mutex_t *__restrict mutex,
const struct timespec *abstime)
{
TIMED_LOCK((os_mutex_trylock(mutex) == 0), abstime);
}
/*
* os_mutex_unlock -- unlocks mutex
*/
int
os_mutex_unlock(os_mutex_t *__restrict mutex)
{
internal_os_mutex_t *mutex_internal = (internal_os_mutex_t *)mutex;
LeaveCriticalSection(&mutex_internal->lock);
return 0;
}
/*
* os_rwlock_init -- initializes rwlock
*/
int
os_rwlock_init(os_rwlock_t *__restrict rwlock)
{
COMPILE_ERROR_ON(sizeof(os_rwlock_t) < sizeof(internal_os_rwlock_t));
internal_os_rwlock_t *rwlock_internal = (internal_os_rwlock_t *)rwlock;
InitializeSRWLock(&rwlock_internal->lock);
return 0;
}
/*
* os_rwlock_destroy -- destroys rwlock
*/
int
os_rwlock_destroy(os_rwlock_t *__restrict rwlock)
{
/* do nothing */
UNREFERENCED_PARAMETER(rwlock);
return 0;
}
/*
* os_rwlock_rdlock -- get shared lock
*/
int
os_rwlock_rdlock(os_rwlock_t *__restrict rwlock)
{
internal_os_rwlock_t *rwlock_internal = (internal_os_rwlock_t *)rwlock;
AcquireSRWLockShared(&rwlock_internal->lock);
rwlock_internal->is_write = 0;
return 0;
}
/*
* os_rwlock_wrlock -- get exclusive lock
*/
int
os_rwlock_wrlock(os_rwlock_t *__restrict rwlock)
{
internal_os_rwlock_t *rwlock_internal = (internal_os_rwlock_t *)rwlock;
AcquireSRWLockExclusive(&rwlock_internal->lock);
rwlock_internal->is_write = 1;
return 0;
}
/*
* os_rwlock_tryrdlock -- tries get shared lock
*/
int
os_rwlock_tryrdlock(os_rwlock_t *__restrict rwlock)
{
internal_os_rwlock_t *rwlock_internal = (internal_os_rwlock_t *)rwlock;
if (TryAcquireSRWLockShared(&rwlock_internal->lock) == FALSE) {
return EBUSY;
} else {
rwlock_internal->is_write = 0;
return 0;
}
}
/*
* os_rwlock_trywrlock -- tries get exclusive lock
*/
_Use_decl_annotations_
int
os_rwlock_trywrlock(os_rwlock_t *__restrict rwlock)
{
internal_os_rwlock_t *rwlock_internal = (internal_os_rwlock_t *)rwlock;
if (TryAcquireSRWLockExclusive(&rwlock_internal->lock) == FALSE) {
return EBUSY;
} else {
rwlock_internal->is_write = 1;
return 0;
}
}
/*
* os_rwlock_timedrdlock -- gets shared lock with timeout
*/
int
os_rwlock_timedrdlock(os_rwlock_t *__restrict rwlock,
const struct timespec *abstime)
{
TIMED_LOCK((os_rwlock_tryrdlock(rwlock) == 0), abstime);
}
/*
* os_rwlock_timedwrlock -- gets exclusive lock with timeout
*/
int
os_rwlock_timedwrlock(os_rwlock_t *__restrict rwlock,
const struct timespec *abstime)
{
TIMED_LOCK((os_rwlock_trywrlock(rwlock) == 0), abstime);
}
/*
* os_rwlock_unlock -- unlocks rwlock
*/
_Use_decl_annotations_
int
os_rwlock_unlock(os_rwlock_t *__restrict rwlock)
{
internal_os_rwlock_t *rwlock_internal = (internal_os_rwlock_t *)rwlock;
if (rwlock_internal->is_write)
ReleaseSRWLockExclusive(&rwlock_internal->lock);
else
ReleaseSRWLockShared(&rwlock_internal->lock);
return 0;
}
/*
* os_cond_init -- initializes condition variable
*/
int
os_cond_init(os_cond_t *__restrict cond)
{
COMPILE_ERROR_ON(sizeof(os_cond_t) < sizeof(internal_os_cond_t));
internal_os_cond_t *cond_internal = (internal_os_cond_t *)cond;
InitializeConditionVariable(&cond_internal->cond);
return 0;
}
/*
* os_cond_destroy -- destroys condition variable
*/
int
os_cond_destroy(os_cond_t *__restrict cond)
{
/* do nothing */
UNREFERENCED_PARAMETER(cond);
return 0;
}
/*
* os_cond_broadcast -- broadcast condition variable
*/
int
os_cond_broadcast(os_cond_t *__restrict cond)
{
internal_os_cond_t *cond_internal = (internal_os_cond_t *)cond;
WakeAllConditionVariable(&cond_internal->cond);
return 0;
}
/*
* os_cond_wait -- signal condition variable
*/
int
os_cond_signal(os_cond_t *__restrict cond)
{
internal_os_cond_t *cond_internal = (internal_os_cond_t *)cond;
WakeConditionVariable(&cond_internal->cond);
return 0;
}
/*
* get_rel_wait -- (internal) convert timespec to windows timeout
*/
static DWORD
get_rel_wait(const struct timespec *abstime)
{
struct __timeb64 t;
_ftime64_s(&t);
time_t now_ms = t.time * 1000 + t.millitm;
time_t ms = (time_t)(abstime->tv_sec * 1000 +
abstime->tv_nsec / 1000000);
DWORD rel_wait = (DWORD)(ms - now_ms);
return rel_wait < 0 ? 0 : rel_wait;
}
/*
* os_cond_timedwait -- waits on condition variable with timeout
*/
int
os_cond_timedwait(os_cond_t *__restrict cond,
os_mutex_t *__restrict mutex, const struct timespec *abstime)
{
internal_os_cond_t *cond_internal = (internal_os_cond_t *)cond;
internal_os_mutex_t *mutex_internal = (internal_os_mutex_t *)mutex;
BOOL ret;
SetLastError(0);
ret = SleepConditionVariableCS(&cond_internal->cond,
&mutex_internal->lock, get_rel_wait(abstime));
if (ret == FALSE)
return (GetLastError() == ERROR_TIMEOUT) ? ETIMEDOUT : EINVAL;
return 0;
}
/*
* os_cond_wait -- waits on condition variable
*/
int
os_cond_wait(os_cond_t *__restrict cond,
os_mutex_t *__restrict mutex)
{
internal_os_cond_t *cond_internal = (internal_os_cond_t *)cond;
internal_os_mutex_t *mutex_internal = (internal_os_mutex_t *)mutex;
/* XXX - return error code based on GetLastError() */
BOOL ret;
ret = SleepConditionVariableCS(&cond_internal->cond,
&mutex_internal->lock, INFINITE);
return (ret == FALSE) ? EINVAL : 0;
}
/*
* os_once -- once-only function call
*/
int
os_once(os_once_t *once, void (*func)(void))
{
internal_os_once_t *once_internal = (internal_os_once_t *)once;
internal_os_once_t tmp;
while ((tmp = *once_internal) != 2) {
if (tmp == 1)
continue; /* another thread is already calling func() */
/* try to be the first one... */
if (!util_bool_compare_and_swap64(once_internal, tmp, 1))
continue; /* sorry, another thread was faster */
func();
if (!util_bool_compare_and_swap64(once_internal, 1, 2)) {
ERR("error setting once");
return -1;
}
}
return 0;
}
/*
* os_tls_key_create -- creates a new tls key
*/
int
os_tls_key_create(os_tls_key_t *key, void (*destructor)(void *))
{
*key = FlsAlloc(destructor);
if (*key == TLS_OUT_OF_INDEXES)
return EAGAIN;
return 0;
}
/*
* os_tls_key_delete -- deletes key from tls
*/
int
os_tls_key_delete(os_tls_key_t key)
{
if (!FlsFree(key))
return EINVAL;
return 0;
}
/*
* os_tls_set -- sets a value in tls
*/
int
os_tls_set(os_tls_key_t key, const void *value)
{
if (!FlsSetValue(key, (LPVOID)value))
return ENOENT;
return 0;
}
/*
* os_tls_get -- gets a value from tls
*/
void *
os_tls_get(os_tls_key_t key)
{
return FlsGetValue(key);
}
/* threading */
/*
* os_thread_start_routine_wrapper is a start routine for _beginthreadex() and
* it helps:
*
* - wrap the os_thread_create's start function
*/
static unsigned __stdcall
os_thread_start_routine_wrapper(void *arg)
{
internal_os_thread_t *thread_info = (internal_os_thread_t *)arg;
thread_info->result = thread_info->start_routine(thread_info->arg);
return 0;
}
/*
* os_thread_create -- starts a new thread
*/
int
os_thread_create(os_thread_t *thread, const os_thread_attr_t *attr,
void *(*start_routine)(void *), void *arg)
{
COMPILE_ERROR_ON(sizeof(os_thread_t) < sizeof(internal_os_thread_t));
internal_os_thread_t *thread_info = (internal_os_thread_t *)thread;
thread_info->start_routine = start_routine;
thread_info->arg = arg;
thread_info->thread_handle = (HANDLE)_beginthreadex(NULL, 0,
os_thread_start_routine_wrapper, thread_info, CREATE_SUSPENDED,
NULL);
if (thread_info->thread_handle == 0) {
free(thread_info);
return errno;
}
if (ResumeThread(thread_info->thread_handle) == -1) {
free(thread_info);
return EAGAIN;
}
return 0;
}
/*
* os_thread_join -- joins a thread
*/
int
os_thread_join(os_thread_t *thread, void **result)
{
internal_os_thread_t *internal_thread = (internal_os_thread_t *)thread;
WaitForSingleObject(internal_thread->thread_handle, INFINITE);
CloseHandle(internal_thread->thread_handle);
if (result != NULL)
*result = internal_thread->result;
return 0;
}
/*
* os_thread_self -- returns handle to calling thread
*/
void
os_thread_self(os_thread_t *thread)
{
internal_os_thread_t *internal_thread = (internal_os_thread_t *)thread;
internal_thread->thread_handle = GetCurrentThread();
}
/*
* os_cpu_zero -- clears cpu set
*/
void
os_cpu_zero(os_cpu_set_t *set)
{
internal_os_cpu_set_t *internal_set = (internal_os_cpu_set_t *)set;
memset(&internal_set->affinity, 0, sizeof(internal_set->affinity));
}
/*
* os_cpu_set -- adds cpu to set
*/
void
os_cpu_set(size_t cpu, os_cpu_set_t *set)
{
internal_os_cpu_set_t *internal_set = (internal_os_cpu_set_t *)set;
int sum = 0;
int group_max = GetActiveProcessorGroupCount();
int group = 0;
while (group < group_max) {
sum += GetActiveProcessorCount(group);
if (sum > cpu) {
/*
* XXX: can't set affinity to two different cpu groups
*/
if (internal_set->affinity.Group != group) {
internal_set->affinity.Mask = 0;
internal_set->affinity.Group = group;
}
cpu -= sum - GetActiveProcessorCount(group);
internal_set->affinity.Mask |= 1LL << cpu;
return;
}
group++;
}
FATAL("os_cpu_set cpu out of bounds");
}
/*
* os_thread_setaffinity_np -- sets affinity of the thread
*/
int
os_thread_setaffinity_np(os_thread_t *thread, size_t set_size,
const os_cpu_set_t *set)
{
internal_os_cpu_set_t *internal_set = (internal_os_cpu_set_t *)set;
internal_os_thread_t *internal_thread = (internal_os_thread_t *)thread;
int ret = SetThreadGroupAffinity(internal_thread->thread_handle,
&internal_set->affinity, NULL);
return ret != 0 ? 0 : EINVAL;
}
/*
* os_semaphore_init -- initializes a new semaphore instance
*/
int
os_semaphore_init(os_semaphore_t *sem, unsigned value)
{
internal_semaphore_t *internal_sem = (internal_semaphore_t *)sem;
internal_sem->handle = CreateSemaphore(NULL,
value, LONG_MAX, NULL);
return internal_sem->handle != 0 ? 0 : -1;
}
/*
* os_semaphore_destroy -- destroys a semaphore instance
*/
int
os_semaphore_destroy(os_semaphore_t *sem)
{
internal_semaphore_t *internal_sem = (internal_semaphore_t *)sem;
BOOL ret = CloseHandle(internal_sem->handle);
return ret ? 0 : -1;
}
/*
* os_semaphore_wait -- decreases the value of the semaphore
*/
int
os_semaphore_wait(os_semaphore_t *sem)
{
internal_semaphore_t *internal_sem = (internal_semaphore_t *)sem;
DWORD ret = WaitForSingleObject(internal_sem->handle, INFINITE);
return ret == WAIT_OBJECT_0 ? 0 : -1;
}
/*
* os_semaphore_trywait -- tries to decrease the value of the semaphore
*/
int
os_semaphore_trywait(os_semaphore_t *sem)
{
internal_semaphore_t *internal_sem = (internal_semaphore_t *)sem;
DWORD ret = WaitForSingleObject(internal_sem->handle, 0);
if (ret == WAIT_TIMEOUT)
errno = EAGAIN;
return ret == WAIT_OBJECT_0 ? 0 : -1;
}
/*
* os_semaphore_post -- increases the value of the semaphore
*/
int
os_semaphore_post(os_semaphore_t *sem)
{
internal_semaphore_t *internal_sem = (internal_semaphore_t *)sem;
BOOL ret = ReleaseSemaphore(internal_sem->handle, 1, NULL);
return ret ? 0 : -1;
}
| 15,381
| 22.412481
| 78
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/out.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* out.c -- support for logging, tracing, and assertion output
*
* Macros like LOG(), OUT, ASSERT(), etc. end up here.
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include <errno.h>
#include "out.h"
#include "os.h"
#include "os_thread.h"
#include "valgrind_internal.h"
#include "util.h"
/* XXX - modify Linux makefiles to generate srcversion.h and remove #ifdef */
#ifdef _WIN32
#include "srcversion.h"
#endif
static const char *Log_prefix;
static int Log_level;
static FILE *Out_fp;
static unsigned Log_alignment;
#ifndef NO_LIBPTHREAD
#define MAXPRINT 8192 /* maximum expected log line */
#else
#define MAXPRINT 256 /* maximum expected log line for libpmem */
#endif
struct errormsg
{
char msg[MAXPRINT];
#ifdef _WIN32
wchar_t wmsg[MAXPRINT];
#endif
};
#ifndef NO_LIBPTHREAD
static os_once_t Last_errormsg_key_once = OS_ONCE_INIT;
static os_tls_key_t Last_errormsg_key;
static void
_Last_errormsg_key_alloc(void)
{
int pth_ret = os_tls_key_create(&Last_errormsg_key, free);
if (pth_ret)
FATAL("!os_thread_key_create");
VALGRIND_ANNOTATE_HAPPENS_BEFORE(&Last_errormsg_key_once);
}
static void
Last_errormsg_key_alloc(void)
{
os_once(&Last_errormsg_key_once, _Last_errormsg_key_alloc);
/*
* Workaround Helgrind's bug:
* https://bugs.kde.org/show_bug.cgi?id=337735
*/
VALGRIND_ANNOTATE_HAPPENS_AFTER(&Last_errormsg_key_once);
}
static inline void
Last_errormsg_fini(void)
{
void *p = os_tls_get(Last_errormsg_key);
if (p) {
free(p);
(void) os_tls_set(Last_errormsg_key, NULL);
}
(void) os_tls_key_delete(Last_errormsg_key);
}
static inline struct errormsg *
Last_errormsg_get(void)
{
Last_errormsg_key_alloc();
struct errormsg *errormsg = os_tls_get(Last_errormsg_key);
if (errormsg == NULL) {
errormsg = malloc(sizeof(struct errormsg));
if (errormsg == NULL)
FATAL("!malloc");
/* make sure it contains empty string initially */
errormsg->msg[0] = '\0';
int ret = os_tls_set(Last_errormsg_key, errormsg);
if (ret)
FATAL("!os_tls_set");
}
return errormsg;
}
#else
/*
* We don't want libpmem to depend on libpthread. Instead of using pthread
* API to dynamically allocate thread-specific error message buffer, we put
* it into TLS. However, keeping a pretty large static buffer (8K) in TLS
* may lead to some issues, so the maximum message length is reduced.
* Fortunately, it looks like the longest error message in libpmem should
* not be longer than about 90 chars (in case of pmem_check_version()).
*/
static __thread struct errormsg Last_errormsg;
static inline void
Last_errormsg_key_alloc(void)
{
}
static inline void
Last_errormsg_fini(void)
{
}
static inline const struct errormsg *
Last_errormsg_get(void)
{
return &Last_errormsg.msg[0];
}
#endif /* NO_LIBPTHREAD */
/*
* out_init -- initialize the log
*
* This is called from the library initialization code.
*/
void
out_init(const char *log_prefix, const char *log_level_var,
const char *log_file_var, int major_version,
int minor_version)
{
static int once;
/* only need to initialize the out module once */
if (once)
return;
once++;
Log_prefix = log_prefix;
#ifdef DEBUG
char *log_level;
char *log_file;
if ((log_level = os_getenv(log_level_var)) != NULL) {
Log_level = atoi(log_level);
if (Log_level < 0) {
Log_level = 0;
}
}
if ((log_file = os_getenv(log_file_var)) != NULL &&
log_file[0] != '\0') {
/* reserve more than enough space for a PID + '\0' */
char log_file_pid[PATH_MAX];
size_t len = strlen(log_file);
if (len > 0 && log_file[len - 1] == '-') {
int ret = snprintf(log_file_pid, PATH_MAX, "%s%d",
log_file, getpid());
if (ret < 0 || ret >= PATH_MAX) {
ERR("snprintf: %d", ret);
abort();
}
log_file = log_file_pid;
}
if ((Out_fp = os_fopen(log_file, "w")) == NULL) {
char buff[UTIL_MAX_ERR_MSG];
util_strerror(errno, buff, UTIL_MAX_ERR_MSG);
fprintf(stderr, "Error (%s): %s=%s: %s\n",
log_prefix, log_file_var,
log_file, buff);
abort();
}
}
#endif /* DEBUG */
char *log_alignment = os_getenv("PMDK_LOG_ALIGN");
if (log_alignment) {
int align = atoi(log_alignment);
if (align > 0)
Log_alignment = (unsigned)align;
}
if (Out_fp == NULL)
Out_fp = stderr;
else
setlinebuf(Out_fp);
#ifdef DEBUG
static char namepath[PATH_MAX];
LOG(1, "pid %d: program: %s", getpid(),
util_getexecname(namepath, PATH_MAX));
#endif
LOG(1, "%s version %d.%d", log_prefix, major_version, minor_version);
static __attribute__((used)) const char *version_msg =
"src version: " SRCVERSION;
LOG(1, "%s", version_msg);
#if VG_PMEMCHECK_ENABLED
/*
* Attribute "used" to prevent compiler from optimizing out the variable
* when LOG expands to no code (!DEBUG)
*/
static __attribute__((used)) const char *pmemcheck_msg =
"compiled with support for Valgrind pmemcheck";
LOG(1, "%s", pmemcheck_msg);
#endif /* VG_PMEMCHECK_ENABLED */
#if VG_HELGRIND_ENABLED
static __attribute__((used)) const char *helgrind_msg =
"compiled with support for Valgrind helgrind";
LOG(1, "%s", helgrind_msg);
#endif /* VG_HELGRIND_ENABLED */
#if VG_MEMCHECK_ENABLED
static __attribute__((used)) const char *memcheck_msg =
"compiled with support for Valgrind memcheck";
LOG(1, "%s", memcheck_msg);
#endif /* VG_MEMCHECK_ENABLED */
#if VG_DRD_ENABLED
static __attribute__((used)) const char *drd_msg =
"compiled with support for Valgrind drd";
LOG(1, "%s", drd_msg);
#endif /* VG_DRD_ENABLED */
#if SDS_ENABLED
static __attribute__((used)) const char *shutdown_state_msg =
"compiled with support for shutdown state";
LOG(1, "%s", shutdown_state_msg);
#endif
Last_errormsg_key_alloc();
}
/*
* out_fini -- close the log file
*
* This is called to close log file before process stop.
*/
void
out_fini(void)
{
if (Out_fp != NULL && Out_fp != stderr) {
fclose(Out_fp);
Out_fp = stderr;
}
Last_errormsg_fini();
}
/*
* out_print_func -- default print_func, goes to stderr or Out_fp
*/
static void
out_print_func(const char *s)
{
/* to suppress drd false-positive */
/* XXX: confirm real nature of this issue: pmem/issues#863 */
#ifdef SUPPRESS_FPUTS_DRD_ERROR
VALGRIND_ANNOTATE_IGNORE_READS_BEGIN();
VALGRIND_ANNOTATE_IGNORE_WRITES_BEGIN();
#endif
fputs(s, Out_fp);
#ifdef SUPPRESS_FPUTS_DRD_ERROR
VALGRIND_ANNOTATE_IGNORE_READS_END();
VALGRIND_ANNOTATE_IGNORE_WRITES_END();
#endif
}
/*
* calling Print(s) calls the current print_func...
*/
typedef void (*Print_func)(const char *s);
typedef int (*Vsnprintf_func)(char *str, size_t size, const char *format,
va_list ap);
static Print_func Print = out_print_func;
static Vsnprintf_func Vsnprintf = vsnprintf;
/*
* out_set_print_func -- allow override of print_func used by out module
*/
void
out_set_print_func(void (*print_func)(const char *s))
{
LOG(3, "print %p", print_func);
Print = (print_func == NULL) ? out_print_func : print_func;
}
/*
* out_set_vsnprintf_func -- allow override of vsnprintf_func used by out module
*/
void
out_set_vsnprintf_func(int (*vsnprintf_func)(char *str, size_t size,
const char *format, va_list ap))
{
LOG(3, "vsnprintf %p", vsnprintf_func);
Vsnprintf = (vsnprintf_func == NULL) ? vsnprintf : vsnprintf_func;
}
/*
* out_snprintf -- (internal) custom snprintf implementation
*/
FORMAT_PRINTF(3, 4)
static int
out_snprintf(char *str, size_t size, const char *format, ...)
{
int ret;
va_list ap;
va_start(ap, format);
ret = Vsnprintf(str, size, format, ap);
va_end(ap);
return (ret);
}
/*
* out_common -- common output code, all output goes through here
*/
static void
out_common(const char *file, int line, const char *func, int level,
const char *suffix, const char *fmt, va_list ap)
{
int oerrno = errno;
char buf[MAXPRINT];
unsigned cc = 0;
int ret;
const char *sep = "";
char errstr[UTIL_MAX_ERR_MSG] = "";
if (file) {
char *f = strrchr(file, OS_DIR_SEPARATOR);
if (f)
file = f + 1;
ret = out_snprintf(&buf[cc], MAXPRINT - cc,
"<%s>: <%d> [%s:%d %s] ",
Log_prefix, level, file, line, func);
if (ret < 0) {
Print("out_snprintf failed");
goto end;
}
cc += (unsigned)ret;
if (cc < Log_alignment) {
memset(buf + cc, ' ', Log_alignment - cc);
cc = Log_alignment;
}
}
if (fmt) {
if (*fmt == '!') {
fmt++;
sep = ": ";
util_strerror(errno, errstr, UTIL_MAX_ERR_MSG);
}
ret = Vsnprintf(&buf[cc], MAXPRINT - cc, fmt, ap);
if (ret < 0) {
Print("Vsnprintf failed");
goto end;
}
cc += (unsigned)ret;
}
out_snprintf(&buf[cc], MAXPRINT - cc, "%s%s%s", sep, errstr, suffix);
Print(buf);
end:
errno = oerrno;
}
/*
* out_error -- common error output code, all error messages go through here
*/
static void
out_error(const char *file, int line, const char *func,
const char *suffix, const char *fmt, va_list ap)
{
int oerrno = errno;
unsigned cc = 0;
int ret;
const char *sep = "";
char errstr[UTIL_MAX_ERR_MSG] = "";
char *errormsg = (char *)out_get_errormsg();
if (fmt) {
if (*fmt == '!') {
fmt++;
sep = ": ";
util_strerror(errno, errstr, UTIL_MAX_ERR_MSG);
}
ret = Vsnprintf(&errormsg[cc], MAXPRINT, fmt, ap);
if (ret < 0) {
strcpy(errormsg, "Vsnprintf failed");
goto end;
}
cc += (unsigned)ret;
out_snprintf(&errormsg[cc], MAXPRINT - cc, "%s%s",
sep, errstr);
}
#ifdef DEBUG
if (Log_level >= 1) {
char buf[MAXPRINT];
cc = 0;
if (file) {
char *f = strrchr(file, OS_DIR_SEPARATOR);
if (f)
file = f + 1;
ret = out_snprintf(&buf[cc], MAXPRINT,
"<%s>: <1> [%s:%d %s] ",
Log_prefix, file, line, func);
if (ret < 0) {
Print("out_snprintf failed");
goto end;
}
cc += (unsigned)ret;
if (cc < Log_alignment) {
memset(buf + cc, ' ', Log_alignment - cc);
cc = Log_alignment;
}
}
out_snprintf(&buf[cc], MAXPRINT - cc, "%s%s", errormsg,
suffix);
Print(buf);
}
#endif
end:
errno = oerrno;
}
/*
* out -- output a line, newline added automatically
*/
void
out(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
out_common(NULL, 0, NULL, 0, "\n", fmt, ap);
va_end(ap);
}
/*
* out_nonl -- output a line, no newline added automatically
*/
void
out_nonl(int level, const char *fmt, ...)
{
va_list ap;
if (Log_level < level)
return;
va_start(ap, fmt);
out_common(NULL, 0, NULL, level, "", fmt, ap);
va_end(ap);
}
/*
* out_log -- output a log line if Log_level >= level
*/
void
out_log(const char *file, int line, const char *func, int level,
const char *fmt, ...)
{
va_list ap;
if (Log_level < level)
return;
va_start(ap, fmt);
out_common(file, line, func, level, "\n", fmt, ap);
va_end(ap);
}
/*
* out_fatal -- output a fatal error & die (i.e. assertion failure)
*/
void
out_fatal(const char *file, int line, const char *func,
const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
out_common(file, line, func, 1, "\n", fmt, ap);
va_end(ap);
abort();
}
/*
* out_err -- output an error message
*/
void
out_err(const char *file, int line, const char *func,
const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
out_error(file, line, func, "\n", fmt, ap);
va_end(ap);
}
/*
* out_get_errormsg -- get the last error message
*/
const char *
out_get_errormsg(void)
{
const struct errormsg *errormsg = Last_errormsg_get();
return &errormsg->msg[0];
}
#ifdef _WIN32
/*
* out_get_errormsgW -- get the last error message in wchar_t
*/
const wchar_t *
out_get_errormsgW(void)
{
struct errormsg *errormsg = Last_errormsg_get();
const char *utf8 = &errormsg->msg[0];
wchar_t *utf16 = &errormsg->wmsg[0];
if (util_toUTF16_buff(utf8, utf16, sizeof(errormsg->wmsg)) != 0)
FATAL("!Failed to convert string");
return (const wchar_t *)utf16;
}
#endif
| 13,370
| 21.817406
| 80
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/sys_util.h
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* sys_util.h -- internal utility wrappers around system functions
*/
#ifndef PMDK_SYS_UTIL_H
#define PMDK_SYS_UTIL_H 1
#include <errno.h>
#include "os_thread.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* util_mutex_init -- os_mutex_init variant that never fails from
* caller perspective. If os_mutex_init failed, this function aborts
* the program.
*/
static inline void
util_mutex_init(os_mutex_t *m)
{
int tmp = os_mutex_init(m);
if (tmp) {
errno = tmp;
FATAL("!os_mutex_init");
}
}
/*
* util_mutex_destroy -- os_mutex_destroy variant that never fails from
* caller perspective. If os_mutex_destroy failed, this function aborts
* the program.
*/
static inline void
util_mutex_destroy(os_mutex_t *m)
{
int tmp = os_mutex_destroy(m);
if (tmp) {
errno = tmp;
FATAL("!os_mutex_destroy");
}
}
/*
* util_mutex_lock -- os_mutex_lock variant that never fails from
* caller perspective. If os_mutex_lock failed, this function aborts
* the program.
*/
static inline void
util_mutex_lock(os_mutex_t *m)
{
int tmp = os_mutex_lock(m);
if (tmp) {
errno = tmp;
FATAL("!os_mutex_lock");
}
}
/*
* util_mutex_trylock -- os_mutex_trylock variant that never fails from
* caller perspective (other than EBUSY). If util_mutex_trylock failed, this
* function aborts the program.
* Returns 0 if locked successfully, otherwise returns EBUSY.
*/
static inline int
util_mutex_trylock(os_mutex_t *m)
{
int tmp = os_mutex_trylock(m);
if (tmp && tmp != EBUSY) {
errno = tmp;
FATAL("!os_mutex_trylock");
}
return tmp;
}
/*
* util_mutex_unlock -- os_mutex_unlock variant that never fails from
* caller perspective. If os_mutex_unlock failed, this function aborts
* the program.
*/
static inline void
util_mutex_unlock(os_mutex_t *m)
{
int tmp = os_mutex_unlock(m);
if (tmp) {
errno = tmp;
FATAL("!os_mutex_unlock");
}
}
/*
* util_rwlock_init -- os_rwlock_init variant that never fails from
* caller perspective. If os_rwlock_init failed, this function aborts
* the program.
*/
static inline void
util_rwlock_init(os_rwlock_t *m)
{
int tmp = os_rwlock_init(m);
if (tmp) {
errno = tmp;
FATAL("!os_rwlock_init");
}
}
/*
* util_rwlock_rdlock -- os_rwlock_rdlock variant that never fails from
* caller perspective. If os_rwlock_rdlock failed, this function aborts
* the program.
*/
static inline void
util_rwlock_rdlock(os_rwlock_t *m)
{
int tmp = os_rwlock_rdlock(m);
if (tmp) {
errno = tmp;
FATAL("!os_rwlock_rdlock");
}
}
/*
* util_rwlock_wrlock -- os_rwlock_wrlock variant that never fails from
* caller perspective. If os_rwlock_wrlock failed, this function aborts
* the program.
*/
static inline void
util_rwlock_wrlock(os_rwlock_t *m)
{
int tmp = os_rwlock_wrlock(m);
if (tmp) {
errno = tmp;
FATAL("!os_rwlock_wrlock");
}
}
/*
* util_rwlock_unlock -- os_rwlock_unlock variant that never fails from
* caller perspective. If os_rwlock_unlock failed, this function aborts
* the program.
*/
static inline void
util_rwlock_unlock(os_rwlock_t *m)
{
int tmp = os_rwlock_unlock(m);
if (tmp) {
errno = tmp;
FATAL("!os_rwlock_unlock");
}
}
/*
* util_rwlock_destroy -- os_rwlock_destroy variant that never fails from
* caller perspective. If os_rwlock_destroy failed, this function aborts
* the program.
*/
static inline void
util_rwlock_destroy(os_rwlock_t *m)
{
int tmp = os_rwlock_destroy(m);
if (tmp) {
errno = tmp;
FATAL("!os_rwlock_destroy");
}
}
/*
* util_spin_init -- os_spin_init variant that logs on fail and sets errno.
*/
static inline int
util_spin_init(os_spinlock_t *lock, int pshared)
{
int tmp = os_spin_init(lock, pshared);
if (tmp) {
errno = tmp;
ERR("!os_spin_init");
}
return tmp;
}
/*
* util_spin_destroy -- os_spin_destroy variant that never fails from
* caller perspective. If os_spin_destroy failed, this function aborts
* the program.
*/
static inline void
util_spin_destroy(os_spinlock_t *lock)
{
int tmp = os_spin_destroy(lock);
if (tmp) {
errno = tmp;
FATAL("!os_spin_destroy");
}
}
/*
* util_spin_lock -- os_spin_lock variant that never fails from caller
* perspective. If os_spin_lock failed, this function aborts the program.
*/
static inline void
util_spin_lock(os_spinlock_t *lock)
{
int tmp = os_spin_lock(lock);
if (tmp) {
errno = tmp;
FATAL("!os_spin_lock");
}
}
/*
* util_spin_unlock -- os_spin_unlock variant that never fails
* from caller perspective. If os_spin_unlock failed,
* this function aborts the program.
*/
static inline void
util_spin_unlock(os_spinlock_t *lock)
{
int tmp = os_spin_unlock(lock);
if (tmp) {
errno = tmp;
FATAL("!os_spin_unlock");
}
}
/*
* util_semaphore_init -- os_semaphore_init variant that never fails
* from caller perspective. If os_semaphore_init failed,
* this function aborts the program.
*/
static inline void
util_semaphore_init(os_semaphore_t *sem, unsigned value)
{
if (os_semaphore_init(sem, value))
FATAL("!os_semaphore_init");
}
/*
* util_semaphore_destroy -- deletes a semaphore instance
*/
static inline void
util_semaphore_destroy(os_semaphore_t *sem)
{
if (os_semaphore_destroy(sem) != 0)
FATAL("!os_semaphore_destroy");
}
/*
* util_semaphore_wait -- decreases the value of the semaphore
*/
static inline void
util_semaphore_wait(os_semaphore_t *sem)
{
errno = 0;
int ret;
do {
ret = os_semaphore_wait(sem);
} while (errno == EINTR); /* signal interrupt */
if (ret != 0)
FATAL("!os_semaphore_wait");
}
/*
* util_semaphore_trywait -- tries to decrease the value of the semaphore
*/
static inline int
util_semaphore_trywait(os_semaphore_t *sem)
{
errno = 0;
int ret;
do {
ret = os_semaphore_trywait(sem);
} while (errno == EINTR); /* signal interrupt */
if (ret != 0 && errno != EAGAIN)
FATAL("!os_semaphore_trywait");
return ret;
}
/*
* util_semaphore_post -- increases the value of the semaphore
*/
static inline void
util_semaphore_post(os_semaphore_t *sem)
{
if (os_semaphore_post(sem) != 0)
FATAL("!os_semaphore_post");
}
#ifdef __cplusplus
}
#endif
#endif
| 7,640
| 22.154545
| 76
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os.h
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os.h -- os abstaction layer
*/
#ifndef PMDK_OS_H
#define PMDK_OS_H 1
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include "errno_freebsd.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _WIN32
#define OS_DIR_SEPARATOR '/'
#define OS_DIR_SEP_STR "/"
#else
#define OS_DIR_SEPARATOR '\\'
#define OS_DIR_SEP_STR "\\"
#endif
#ifndef _WIN32
/* madvise() */
#ifdef __FreeBSD__
#define os_madvise minherit
#define MADV_DONTFORK INHERIT_NONE
#else
#define os_madvise madvise
#endif
/* dlopen() */
#ifdef __FreeBSD__
#define RTLD_DEEPBIND 0 /* XXX */
#endif
/* major(), minor() */
#ifdef __FreeBSD__
#define os_major (unsigned)major
#define os_minor (unsigned)minor
#else
#define os_major major
#define os_minor minor
#endif
#endif /* #ifndef _WIN32 */
struct iovec;
/* os_flock */
#define OS_LOCK_SH 1
#define OS_LOCK_EX 2
#define OS_LOCK_NB 4
#define OS_LOCK_UN 8
#ifndef _WIN32
typedef struct stat os_stat_t;
#define os_fstat fstat
#define os_lseek lseek
#else
typedef struct _stat64 os_stat_t;
#define os_fstat _fstat64
#define os_lseek _lseeki64
#endif
#define os_close close
#define os_fclose fclose
#ifndef _WIN32
typedef off_t os_off_t;
#else
/* XXX: os_off_t defined in platform.h */
#endif
int os_open(const char *pathname, int flags, ...);
int os_fsync(int fd);
int os_fsync_dir(const char *dir_name);
int os_stat(const char *pathname, os_stat_t *buf);
int os_unlink(const char *pathname);
int os_access(const char *pathname, int mode);
FILE *os_fopen(const char *pathname, const char *mode);
FILE *os_fdopen(int fd, const char *mode);
int os_chmod(const char *pathname, mode_t mode);
int os_mkstemp(char *temp);
int os_posix_fallocate(int fd, os_off_t offset, os_off_t len);
int os_ftruncate(int fd, os_off_t length);
int os_flock(int fd, int operation);
ssize_t os_writev(int fd, const struct iovec *iov, int iovcnt);
int os_clock_gettime(int id, struct timespec *ts);
unsigned os_rand_r(unsigned *seedp);
int os_unsetenv(const char *name);
int os_setenv(const char *name, const char *value, int overwrite);
char *os_getenv(const char *name);
const char *os_strsignal(int sig);
int os_execv(const char *path, char *const argv[]);
/*
* XXX: missing APis (used in ut_file.c)
*
* rename
* read
* write
*/
#ifdef __cplusplus
}
#endif
#endif /* os.h */
| 3,902
| 25.917241
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/mmap.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mmap.h -- internal definitions for mmap module
*/
#ifndef PMDK_MMAP_H
#define PMDK_MMAP_H 1
#include <stddef.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include "out.h"
#include "queue.h"
#include "os.h"
#ifdef __cplusplus
extern "C" {
#endif
extern int Mmap_no_random;
extern void *Mmap_hint;
extern char *Mmap_mapfile;
void *util_map_sync(void *addr, size_t len, int proto, int flags, int fd,
os_off_t offset, int *map_sync);
void *util_map(int fd, size_t len, int flags, int rdonly,
size_t req_align, int *map_sync);
int util_unmap(void *addr, size_t len);
void *util_map_tmpfile(const char *dir, size_t size, size_t req_align);
#ifdef __FreeBSD__
#define MAP_NORESERVE 0
#define OS_MAPFILE "/proc/curproc/map"
#else
#define OS_MAPFILE "/proc/self/maps"
#endif
#ifndef MAP_SYNC
#define MAP_SYNC 0x80000
#endif
#ifndef MAP_SHARED_VALIDATE
#define MAP_SHARED_VALIDATE 0x03
#endif
/*
* macros for micromanaging range protections for the debug version
*/
#ifdef DEBUG
#define RANGE(addr, len, is_dev_dax, type) do {\
if (!is_dev_dax) ASSERT(util_range_##type(addr, len) >= 0);\
} while (0)
#else
#define RANGE(addr, len, is_dev_dax, type) do {} while (0)
#endif
#define RANGE_RO(addr, len, is_dev_dax) RANGE(addr, len, is_dev_dax, ro)
#define RANGE_RW(addr, len, is_dev_dax) RANGE(addr, len, is_dev_dax, rw)
#define RANGE_NONE(addr, len, is_dev_dax) RANGE(addr, len, is_dev_dax, none)
/* pmem mapping type */
enum pmem_map_type {
PMEM_DEV_DAX, /* device dax */
PMEM_MAP_SYNC, /* mapping with MAP_SYNC flag on dax fs */
MAX_PMEM_TYPE
};
/*
* this structure tracks the file mappings outstanding per file handle
*/
struct map_tracker {
SORTEDQ_ENTRY(map_tracker) entry;
uintptr_t base_addr;
uintptr_t end_addr;
int region_id;
enum pmem_map_type type;
#ifdef _WIN32
/* Windows-specific data */
HANDLE FileHandle;
HANDLE FileMappingHandle;
DWORD Access;
os_off_t Offset;
size_t FileLen;
#endif
};
void util_mmap_init(void);
void util_mmap_fini(void);
int util_range_ro(void *addr, size_t len);
int util_range_rw(void *addr, size_t len);
int util_range_none(void *addr, size_t len);
char *util_map_hint_unused(void *minaddr, size_t len, size_t align);
char *util_map_hint(size_t len, size_t req_align);
#define MEGABYTE ((uintptr_t)1 << 20)
#define GIGABYTE ((uintptr_t)1 << 30)
/*
* util_map_hint_align -- choose the desired mapping alignment
*
* The smallest supported alignment is 2 megabytes because of the object
* alignment requirements. Changing this value to 4 kilobytes constitues a
* layout change.
*
* Use 1GB page alignment only if the mapping length is at least
* twice as big as the page size.
*/
static inline size_t
util_map_hint_align(size_t len, size_t req_align)
{
size_t align = 2 * MEGABYTE;
if (req_align)
align = req_align;
else if (len >= 2 * GIGABYTE)
align = GIGABYTE;
return align;
}
int util_range_register(const void *addr, size_t len, const char *path,
enum pmem_map_type type);
int util_range_unregister(const void *addr, size_t len);
struct map_tracker *util_range_find(uintptr_t addr, size_t len);
int util_range_is_pmem(const void *addr, size_t len);
#ifdef __cplusplus
}
#endif
#endif
| 4,854
| 27.063584
| 76
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_auto_flush_windows.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_auto_flush_windows.c -- Windows abstraction layer for auto flush detection
*/
#include <windows.h>
#include <inttypes.h>
#include "out.h"
#include "os.h"
#include "endian.h"
#include "os_auto_flush_windows.h"
/*
* is_nfit_available -- (internal) check if platform supports NFIT table.
*/
static int
is_nfit_available()
{
LOG(3, "is_nfit_available()");
DWORD signatures_size;
char *signatures = NULL;
int is_nfit = 0;
DWORD offset = 0;
signatures_size = EnumSystemFirmwareTables(ACPI_SIGNATURE, NULL, 0);
if (signatures_size == 0) {
ERR("!EnumSystemFirmwareTables");
return -1;
}
signatures = (char *)Malloc(signatures_size + 1);
if (signatures == NULL) {
ERR("!malloc");
return -1;
}
int ret = EnumSystemFirmwareTables(ACPI_SIGNATURE,
signatures, signatures_size);
signatures[signatures_size] = '\0';
if (ret != signatures_size) {
ERR("!EnumSystemFirmwareTables");
goto err;
}
while (offset <= signatures_size) {
int nfit_sig = strncmp(signatures + offset,
NFIT_STR_SIGNATURE, NFIT_SIGNATURE_LEN);
if (nfit_sig == 0) {
is_nfit = 1;
break;
}
offset += NFIT_SIGNATURE_LEN;
}
Free(signatures);
return is_nfit;
err:
Free(signatures);
return -1;
}
/*
* is_auto_flush_cap_set -- (internal) check if specific
* capabilities bits are set.
*
* ACPI 6.2A Specification:
* Bit[0] - CPU Cache Flush to NVDIMM Durability on
* Power Loss Capable. If set to 1, indicates that platform
* ensures the entire CPU store data path is flushed to
* persistent memory on system power loss.
* Bit[1] - Memory Controller Flush to NVDIMM Durability on Power Loss Capable.
* If set to 1, indicates that platform provides mechanisms to automatically
* flush outstanding write data from the memory controller to persistent memory
* in the event of platform power loss. Note: If bit 0 is set to 1 then this bit
* shall be set to 1 as well.
*/
static int
is_auto_flush_cap_set(uint32_t capabilities)
{
LOG(3, "is_auto_flush_cap_set capabilities 0x%" PRIx32, capabilities);
int CPU_cache_flush = CHECK_BIT(capabilities, 0);
int memory_controller_flush = CHECK_BIT(capabilities, 1);
LOG(15, "CPU_cache_flush %d, memory_controller_flush %d",
CPU_cache_flush, memory_controller_flush);
if (memory_controller_flush == 1 && CPU_cache_flush == 1)
return 1;
return 0;
}
/*
* parse_nfit_buffer -- (internal) parse nfit buffer
* if platform_capabilities struct is available return pcs structure.
*/
static struct platform_capabilities
parse_nfit_buffer(const unsigned char *nfit_buffer, unsigned long buffer_size)
{
LOG(3, "parse_nfit_buffer nfit_buffer %s, buffer_size %lu",
nfit_buffer, buffer_size);
uint16_t type;
uint16_t length;
size_t offset = sizeof(struct nfit_header);
struct platform_capabilities pcs = {0};
while (offset < buffer_size) {
type = *(nfit_buffer + offset);
length = *(nfit_buffer + offset + 2);
if (type == PCS_TYPE_NUMBER) {
if (length == sizeof(struct platform_capabilities)) {
memmove(&pcs, nfit_buffer + offset, length);
return pcs;
}
}
offset += length;
}
return pcs;
}
/*
* os_auto_flush -- check if platform supports auto flush.
*/
int
os_auto_flush(void)
{
LOG(3, NULL);
DWORD nfit_buffer_size = 0;
DWORD nfit_written = 0;
PVOID nfit_buffer = NULL;
struct nfit_header *nfit_data;
struct platform_capabilities *pc = NULL;
int eADR = 0;
int is_nfit = is_nfit_available();
if (is_nfit == 0) {
LOG(15, "ACPI NFIT table not available");
return 0;
}
if (is_nfit < 0 || is_nfit != 1) {
LOG(1, "!is_nfit_available");
return -1;
}
/* get the entire nfit size */
nfit_buffer_size = GetSystemFirmwareTable(
(DWORD)ACPI_SIGNATURE, (DWORD)NFIT_REV_SIGNATURE, NULL, 0);
if (nfit_buffer_size == 0) {
ERR("!GetSystemFirmwareTable");
return -1;
}
/* reserve buffer */
nfit_buffer = (unsigned char *)Malloc(nfit_buffer_size);
if (nfit_buffer == NULL) {
ERR("!malloc");
goto err;
}
/* write actual nfit to buffer */
nfit_written = GetSystemFirmwareTable(
(DWORD)ACPI_SIGNATURE, (DWORD)NFIT_REV_SIGNATURE,
nfit_buffer, nfit_buffer_size);
if (nfit_written == 0) {
ERR("!GetSystemFirmwareTable");
goto err;
}
if (nfit_buffer_size != nfit_written) {
errno = ERROR_INVALID_DATA;
ERR("!GetSystemFirmwareTable invalid data");
goto err;
}
nfit_data = (struct nfit_header *)nfit_buffer;
int nfit_sig = strncmp(nfit_data->signature,
NFIT_STR_SIGNATURE, NFIT_SIGNATURE_LEN);
if (nfit_sig != 0) {
ERR("!NFIT buffer has invalid data");
goto err;
}
struct platform_capabilities pcs = parse_nfit_buffer(
nfit_buffer, nfit_buffer_size);
eADR = is_auto_flush_cap_set(pcs.capabilities);
Free(nfit_buffer);
return eADR;
err:
Free(nfit_buffer);
return -1;
}
| 6,369
| 27.311111
| 80
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_dimm.h
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_dimm.h -- DIMMs API based on the ndctl library
*/
#ifndef PMDK_OS_DIMM_H
#define PMDK_OS_DIMM_H 1
#include <string.h>
#include <stdint.h>
#include "os_badblock.h"
#ifdef __cplusplus
extern "C" {
#endif
int os_dimm_uid(const char *path, char *uid, size_t *len);
int os_dimm_usc(const char *path, uint64_t *usc);
int os_dimm_files_namespace_badblocks(const char *path, struct badblocks *bbs);
int os_dimm_devdax_clear_badblocks_all(const char *path);
int os_dimm_devdax_clear_badblocks(const char *path, struct badblocks *bbs);
#ifdef __cplusplus
}
#endif
#endif
| 2,180
| 35.35
| 79
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/fs_windows.c
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* fs_windows.c -- file system traversal windows implementation
*/
#include <windows.h>
#include "util.h"
#include "out.h"
#include "vec.h"
#include "fs.h"
struct fs {
size_t dirlen;
WIN32_FIND_DATAW ffd;
HANDLE hFind;
int first_done;
const char *dir;
struct fs_entry entry;
};
/*
* fs_new -- creates fs traversal instance
*/
struct fs *
fs_new(const char *path)
{
size_t pathlen = strlen(path);
char *search_path = Malloc(strlen(path) + sizeof("\\*\0"));
if (search_path == NULL)
goto error_spath_alloc;
strcpy(search_path, path);
strcpy(search_path + pathlen, "\\*\0");
wchar_t *pathw = util_toUTF16(search_path);
if (pathw == NULL)
goto error_path_alloc;
struct fs *f = Zalloc(sizeof(*f));
if (f == NULL)
goto error_fs_alloc;
f->first_done = 0;
f->hFind = FindFirstFileW(pathw, &f->ffd);
if (f->hFind == INVALID_HANDLE_VALUE)
goto error_fff;
f->dir = path;
f->dirlen = pathlen;
util_free_UTF16(pathw);
Free(search_path);
return f;
error_fff:
Free(f);
error_fs_alloc:
util_free_UTF16(pathw);
error_path_alloc:
Free(search_path);
error_spath_alloc:
return NULL;
}
/*
* fs_read -- reads an entry from the fs path
*/
struct fs_entry *
fs_read(struct fs *f)
{
util_free_UTF8((char *)f->entry.name);
Free((char *)f->entry.path);
f->entry.name = NULL;
f->entry.path = NULL;
if (f->first_done) {
if (FindNextFileW(f->hFind, &f->ffd) == 0)
return NULL;
} else {
f->first_done = 1;
}
if (f->ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
f->entry.type = FS_ENTRY_DIRECTORY;
else
f->entry.type = FS_ENTRY_FILE;
f->entry.name = util_toUTF8(f->ffd.cFileName);
if (f->entry.name == NULL)
return NULL;
f->entry.namelen = strnlen(f->entry.name, MAX_PATH);
f->entry.pathlen = f->dirlen + f->entry.namelen + 1;
char *path = Zalloc(f->entry.pathlen + 1);
if (path == NULL) {
util_free_UTF8((char *)f->entry.name);
return NULL;
}
strcpy(path, f->dir);
path[f->dirlen] = '\\';
strcpy(path + f->dirlen + 1, f->entry.name);
f->entry.path = path;
f->entry.level = 1;
return &f->entry;
}
/*
* fs_delete -- deletes a fs traversal instance
*/
void
fs_delete(struct fs *f)
{
util_free_UTF8((char *)f->entry.name);
Free((char *)f->entry.path);
FindClose(f->hFind);
Free(f);
}
| 3,862
| 24.248366
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/badblock_windows.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* badblock_windows.c - implementation of the windows bad block API
*/
#include "out.h"
#include "os_badblock.h"
/*
* os_badblocks_check_file -- check if the file contains bad blocks
*
* Return value:
* -1 : an error
* 0 : no bad blocks
* 1 : bad blocks detected
*/
int
os_badblocks_check_file(const char *file)
{
LOG(3, "file %s", file);
return 0;
}
/*
* os_badblocks_count -- returns number of bad blocks in the file
* or -1 in case of an error
*/
long
os_badblocks_count(const char *file)
{
LOG(3, "file %s", file);
return 0;
}
/*
* os_badblocks_get -- returns list of bad blocks in the file
*/
int
os_badblocks_get(const char *file, struct badblocks *bbs)
{
LOG(3, "file %s", file);
return 0;
}
/*
* os_badblocks_clear -- clears the given bad blocks in a file
* (regular file or dax device)
*/
int
os_badblocks_clear(const char *file, struct badblocks *bbs)
{
LOG(3, "file %s badblocks %p", file, bbs);
return 0;
}
/*
* os_badblocks_clear_all -- clears all bad blocks in a file
* (regular file or dax device)
*/
int
os_badblocks_clear_all(const char *file)
{
LOG(3, "file %s", file);
return 0;
}
| 2,812
| 26.578431
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/util.h
|
/*
* Copyright 2014-2018, Intel Corporation
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util.h -- internal definitions for util module
*/
#ifndef PMDK_UTIL_H
#define PMDK_UTIL_H 1
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <ctype.h>
#ifdef _MSC_VER
#include <intrin.h> /* popcnt, bitscan */
#endif
#include <sys/param.h>
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned long long Pagesize;
extern unsigned long long Mmap_align;
#define CACHELINE_SIZE 64ULL
#define PAGE_ALIGNED_DOWN_SIZE(size) ((size) & ~(Pagesize - 1))
#define PAGE_ALIGNED_UP_SIZE(size)\
PAGE_ALIGNED_DOWN_SIZE((size) + (Pagesize - 1))
#define IS_PAGE_ALIGNED(size) (((size) & (Pagesize - 1)) == 0)
#define PAGE_ALIGN_UP(addr) ((void *)PAGE_ALIGNED_UP_SIZE((uintptr_t)(addr)))
#define ALIGN_UP(size, align) (((size) + (align) - 1) & ~((align) - 1))
#define ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
#define ADDR_SUM(vp, lp) ((void *)((char *)(vp) + (lp)))
#define util_alignof(t) offsetof(struct {char _util_c; t _util_m; }, _util_m)
#define FORMAT_PRINTF(a, b) __attribute__((__format__(__printf__, (a), (b))))
/*
* overridable names for malloc & friends used by this library
*/
typedef void *(*Malloc_func)(size_t size);
typedef void (*Free_func)(void *ptr);
typedef void *(*Realloc_func)(void *ptr, size_t size);
typedef char *(*Strdup_func)(const char *s);
extern Malloc_func Malloc;
extern Free_func Free;
extern Realloc_func Realloc;
extern Strdup_func Strdup;
extern void *Zalloc(size_t sz);
void util_init(void);
int util_is_zeroed(const void *addr, size_t len);
int util_checksum(void *addr, size_t len, uint64_t *csump,
int insert, size_t skip_off);
uint64_t util_checksum_seq(const void *addr, size_t len, uint64_t csum);
int util_parse_size(const char *str, size_t *sizep);
char *util_fgets(char *buffer, int max, FILE *stream);
char *util_getexecname(char *path, size_t pathlen);
char *util_part_realpath(const char *path);
int util_compare_file_inodes(const char *path1, const char *path2);
void *util_aligned_malloc(size_t alignment, size_t size);
void util_aligned_free(void *ptr);
struct tm *util_localtime(const time_t *timep);
int util_safe_strcpy(char *dst, const char *src, size_t max_length);
#ifdef _WIN32
char *util_toUTF8(const wchar_t *wstr);
wchar_t *util_toUTF16(const char *wstr);
void util_free_UTF8(char *str);
void util_free_UTF16(wchar_t *str);
int util_toUTF16_buff(const char *in, wchar_t *out, size_t out_size);
int util_toUTF8_buff(const wchar_t *in, char *out, size_t out_size);
#endif
#define UTIL_MAX_ERR_MSG 128
void util_strerror(int errnum, char *buff, size_t bufflen);
void util_set_alloc_funcs(
void *(*malloc_func)(size_t size),
void (*free_func)(void *ptr),
void *(*realloc_func)(void *ptr, size_t size),
char *(*strdup_func)(const char *s));
/*
* Macro calculates number of elements in given table
*/
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
#ifdef _MSC_VER
#define force_inline inline __forceinline
#define NORETURN __declspec(noreturn)
#else
#define force_inline __attribute__((always_inline)) inline
#define NORETURN __attribute__((noreturn))
#endif
#define util_get_not_masked_bits(x, mask) ((x) & ~(mask))
/*
* util_setbit -- setbit macro substitution which properly deals with types
*/
static inline void
util_setbit(uint8_t *b, uint32_t i)
{
b[i / 8] = (uint8_t)(b[i / 8] | (uint8_t)(1 << (i % 8)));
}
/*
* util_clrbit -- clrbit macro substitution which properly deals with types
*/
static inline void
util_clrbit(uint8_t *b, uint32_t i)
{
b[i / 8] = (uint8_t)(b[i / 8] & (uint8_t)(~(1 << (i % 8))));
}
#define util_isset(a, i) isset(a, i)
#define util_isclr(a, i) isclr(a, i)
#define util_flag_isset(a, f) ((a) & (f))
#define util_flag_isclr(a, f) (((a) & (f)) == 0)
/*
* util_is_pow2 -- returns !0 when there's only 1 bit set in v, 0 otherwise
*/
static force_inline int
util_is_pow2(uint64_t v)
{
return v && !(v & (v - 1));
}
/*
* util_div_ceil -- divides a by b and rounds up the result
*/
static force_inline unsigned
util_div_ceil(unsigned a, unsigned b)
{
return (unsigned)(((unsigned long)a + b - 1) / b);
}
/*
* util_bool_compare_and_swap -- perform an atomic compare and swap
* util_fetch_and_* -- perform an operation atomically, return old value
* util_synchronize -- issue a full memory barrier
* util_popcount -- count number of set bits
* util_lssb_index -- return index of least significant set bit,
* undefined on zero
* util_mssb_index -- return index of most significant set bit
* undefined on zero
*
* XXX assertions needed on (value != 0) in both versions of bitscans
*
*/
#ifndef _MSC_VER
/*
* ISO C11 -- 7.17.1.4
* memory_order - an enumerated type whose enumerators identify memory ordering
* constraints.
*/
typedef enum {
memory_order_relaxed = __ATOMIC_RELAXED,
memory_order_consume = __ATOMIC_CONSUME,
memory_order_acquire = __ATOMIC_ACQUIRE,
memory_order_release = __ATOMIC_RELEASE,
memory_order_acq_rel = __ATOMIC_ACQ_REL,
memory_order_seq_cst = __ATOMIC_SEQ_CST
} memory_order;
/*
* ISO C11 -- 7.17.7.2 The atomic_load generic functions
* Integer width specific versions as supplement for:
*
*
* #include <stdatomic.h>
* C atomic_load(volatile A *object);
* C atomic_load_explicit(volatile A *object, memory_order order);
*
* The atomic_load interface doesn't return the loaded value, but instead
* copies it to a specified address -- see comments at the MSVC version.
*
* Also, instead of generic functions, two versions are available:
* for 32 bit fundamental integers, and for 64 bit ones.
*/
#define util_atomic_load_explicit32 __atomic_load
#define util_atomic_load_explicit64 __atomic_load
/*
* ISO C11 -- 7.17.7.1 The atomic_store generic functions
* Integer width specific versions as supplement for:
*
* #include <stdatomic.h>
* void atomic_store(volatile A *object, C desired);
* void atomic_store_explicit(volatile A *object, C desired,
* memory_order order);
*/
#define util_atomic_store_explicit32 __atomic_store_n
#define util_atomic_store_explicit64 __atomic_store_n
/*
* https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html
* https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
* https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions
*/
#define util_bool_compare_and_swap32 __sync_bool_compare_and_swap
#define util_bool_compare_and_swap64 __sync_bool_compare_and_swap
#define util_fetch_and_add32 __sync_fetch_and_add
#define util_fetch_and_add64 __sync_fetch_and_add
#define util_fetch_and_sub32 __sync_fetch_and_sub
#define util_fetch_and_sub64 __sync_fetch_and_sub
#define util_fetch_and_and32 __sync_fetch_and_and
#define util_fetch_and_and64 __sync_fetch_and_and
#define util_fetch_and_or32 __sync_fetch_and_or
#define util_fetch_and_or64 __sync_fetch_and_or
#define util_synchronize __sync_synchronize
#define util_popcount(value) ((unsigned char)__builtin_popcount(value))
#define util_popcount64(value) ((unsigned char)__builtin_popcountll(value))
#define util_lssb_index(value) ((unsigned char)__builtin_ctz(value))
#define util_lssb_index64(value) ((unsigned char)__builtin_ctzll(value))
#define util_mssb_index(value) ((unsigned char)(31 - __builtin_clz(value)))
#define util_mssb_index64(value) ((unsigned char)(63 - __builtin_clzll(value)))
#else
/* ISO C11 -- 7.17.1.4 */
typedef enum {
memory_order_relaxed,
memory_order_consume,
memory_order_acquire,
memory_order_release,
memory_order_acq_rel,
memory_order_seq_cst
} memory_order;
/*
* ISO C11 -- 7.17.7.2 The atomic_load generic functions
* Integer width specific versions as supplement for:
*
*
* #include <stdatomic.h>
* C atomic_load(volatile A *object);
* C atomic_load_explicit(volatile A *object, memory_order order);
*
* The atomic_load interface doesn't return the loaded value, but instead
* copies it to a specified address.
* The MSVC specific implementation needs to trigger a barrier (at least
* compiler barrier) after the load from the volatile value. The actual load
* from the volatile value itself is expected to be atomic.
*
* The actual isnterface here:
* #include <util.h>
* void util_atomic_load32(volatile A *object, A *destination);
* void util_atomic_load64(volatile A *object, A *destination);
* void util_atomic_load_explicit32(volatile A *object, A *destination,
* memory_order order);
* void util_atomic_load_explicit64(volatile A *object, A *destination,
* memory_order order);
*/
#ifndef _M_X64
#error MSVC ports of util_atomic_ only work on X86_64
#endif
#if _MSC_VER >= 2000
#error util_atomic_ utility functions not tested with this version of VC++
#error These utility functions are not future proof, as they are not
#error based on publicly available documentation.
#endif
#define util_atomic_load_explicit(object, dest, order)\
do {\
COMPILE_ERROR_ON(order != memory_order_seq_cst &&\
order != memory_order_consume &&\
order != memory_order_acquire &&\
order != memory_order_relaxed);\
*dest = *object;\
if (order == memory_order_seq_cst ||\
order == memory_order_consume ||\
order == memory_order_acquire)\
_ReadWriteBarrier();\
} while (0)
#define util_atomic_load_explicit32 util_atomic_load_explicit
#define util_atomic_load_explicit64 util_atomic_load_explicit
/* ISO C11 -- 7.17.7.1 The atomic_store generic functions */
#define util_atomic_store_explicit64(object, desired, order)\
do {\
COMPILE_ERROR_ON(order != memory_order_seq_cst &&\
order != memory_order_release &&\
order != memory_order_relaxed);\
if (order == memory_order_seq_cst) {\
_InterlockedExchange64(\
(volatile long long *)object, desired);\
} else {\
if (order == memory_order_release)\
_ReadWriteBarrier();\
*object = desired;\
}\
} while (0)
#define util_atomic_store_explicit32(object, desired, order)\
do {\
COMPILE_ERROR_ON(order != memory_order_seq_cst &&\
order != memory_order_release &&\
order != memory_order_relaxed);\
if (order == memory_order_seq_cst) {\
_InterlockedExchange(\
(volatile long *)object, desired);\
} else {\
if (order == memory_order_release)\
_ReadWriteBarrier();\
*object = desired;\
}\
} while (0)
/*
* https://msdn.microsoft.com/en-us/library/hh977022.aspx
*/
static __inline int
bool_compare_and_swap32_VC(volatile LONG *ptr,
LONG oldval, LONG newval)
{
LONG old = InterlockedCompareExchange(ptr, newval, oldval);
return (old == oldval);
}
static __inline int
bool_compare_and_swap64_VC(volatile LONG64 *ptr,
LONG64 oldval, LONG64 newval)
{
LONG64 old = InterlockedCompareExchange64(ptr, newval, oldval);
return (old == oldval);
}
#define util_bool_compare_and_swap32(p, o, n)\
bool_compare_and_swap32_VC((LONG *)(p), (LONG)(o), (LONG)(n))
#define util_bool_compare_and_swap64(p, o, n)\
bool_compare_and_swap64_VC((LONG64 *)(p), (LONG64)(o), (LONG64)(n))
#define util_fetch_and_add32(ptr, value)\
InterlockedExchangeAdd((LONG *)(ptr), value)
#define util_fetch_and_add64(ptr, value)\
InterlockedExchangeAdd64((LONG64 *)(ptr), value)
#define util_fetch_and_sub32(ptr, value)\
InterlockedExchangeSubtract((LONG *)(ptr), value)
#define util_fetch_and_sub64(ptr, value)\
InterlockedExchangeAdd64((LONG64 *)(ptr), -((LONG64)(value)))
#define util_fetch_and_and32(ptr, value)\
InterlockedAnd((LONG *)(ptr), value)
#define util_fetch_and_and64(ptr, value)\
InterlockedAnd64((LONG64 *)(ptr), value)
#define util_fetch_and_or32(ptr, value)\
InterlockedOr((LONG *)(ptr), value)
#define util_fetch_and_or64(ptr, value)\
InterlockedOr64((LONG64 *)(ptr), value)
static __inline void
util_synchronize(void)
{
MemoryBarrier();
}
#define util_popcount(value) (unsigned char)__popcnt(value)
#define util_popcount64(value) (unsigned char)__popcnt64(value)
static __inline unsigned char
util_lssb_index(int value)
{
unsigned long ret;
_BitScanForward(&ret, value);
return (unsigned char)ret;
}
static __inline unsigned char
util_lssb_index64(long long value)
{
unsigned long ret;
_BitScanForward64(&ret, value);
return (unsigned char)ret;
}
static __inline unsigned char
util_mssb_index(int value)
{
unsigned long ret;
_BitScanReverse(&ret, value);
return (unsigned char)ret;
}
static __inline unsigned char
util_mssb_index64(long long value)
{
unsigned long ret;
_BitScanReverse64(&ret, value);
return (unsigned char)ret;
}
#endif
/* ISO C11 -- 7.17.7 Operations on atomic types */
#define util_atomic_load32(object, dest)\
util_atomic_load_explicit32(object, dest, memory_order_seqcst)
#define util_atomic_load64(object, dest)\
util_atomic_load_explicit64(object, dest, memory_order_seqcst)
#define util_atomic_store32(object, desired)\
util_atomic_store_explicit32(object, desired, memory_order_seqcst)
#define util_atomic_store64(object, desired)\
util_atomic_store_explicit64(object, desired, memory_order_seqcst)
/*
* util_get_printable_ascii -- convert non-printable ascii to dot '.'
*/
static inline char
util_get_printable_ascii(char c)
{
return isprint((unsigned char)c) ? c : '.';
}
char *util_concat_str(const char *s1, const char *s2);
#if !defined(likely)
#if defined(__GNUC__)
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else
#define likely(x) (!!(x))
#define unlikely(x) (!!(x))
#endif
#endif
#if defined(__CHECKER__)
#define COMPILE_ERROR_ON(cond)
#define ASSERT_COMPILE_ERROR_ON(cond)
#elif defined(_MSC_VER)
#define COMPILE_ERROR_ON(cond) C_ASSERT(!(cond))
/* XXX - can't be done with C_ASSERT() unless we have __builtin_constant_p() */
#define ASSERT_COMPILE_ERROR_ON(cond) do {} while (0)
#else
#define COMPILE_ERROR_ON(cond) ((void)sizeof(char[(cond) ? -1 : 1]))
#define ASSERT_COMPILE_ERROR_ON(cond) COMPILE_ERROR_ON(cond)
#endif
#ifndef _MSC_VER
#define ATTR_CONSTRUCTOR __attribute__((constructor)) static
#define ATTR_DESTRUCTOR __attribute__((destructor)) static
#else
#define ATTR_CONSTRUCTOR
#define ATTR_DESTRUCTOR
#endif
#ifndef _MSC_VER
#define CONSTRUCTOR(fun) ATTR_CONSTRUCTOR
#else
#ifdef __cplusplus
#define CONSTRUCTOR(fun) \
void fun(); \
struct _##fun { \
_##fun() { \
fun(); \
} \
}; static _##fun foo; \
static
#else
#define CONSTRUCTOR(fun) \
MSVC_CONSTR(fun) \
static
#endif
#endif
#ifdef __GNUC__
#define CHECK_FUNC_COMPATIBLE(func1, func2)\
COMPILE_ERROR_ON(!__builtin_types_compatible_p(typeof(func1),\
typeof(func2)))
#else
#define CHECK_FUNC_COMPATIBLE(func1, func2) do {} while (0)
#endif /* __GNUC__ */
#ifdef __cplusplus
}
#endif
#endif /* util.h */
| 16,304
| 29.880682
| 79
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/valgrind_internal.h
|
/*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* valgrind_internal.h -- internal definitions for valgrind macros
*/
#ifndef PMDK_VALGRIND_INTERNAL_H
#define PMDK_VALGRIND_INTERNAL_H 1
#ifndef _WIN32
#ifndef VALGRIND_ENABLED
#define VALGRIND_ENABLED 1
#endif
#endif
#if VALGRIND_ENABLED
#define VG_PMEMCHECK_ENABLED 1
#define VG_HELGRIND_ENABLED 1
#define VG_MEMCHECK_ENABLED 1
#define VG_DRD_ENABLED 1
#endif
#if VG_PMEMCHECK_ENABLED || VG_HELGRIND_ENABLED || VG_MEMCHECK_ENABLED || \
VG_DRD_ENABLED
#define ANY_VG_TOOL_ENABLED 1
#else
#define ANY_VG_TOOL_ENABLED 0
#endif
#if ANY_VG_TOOL_ENABLED
extern unsigned _On_valgrind;
#define On_valgrind __builtin_expect(_On_valgrind, 0)
#include "valgrind/valgrind.h"
#else
#define On_valgrind (0)
#endif
#if VG_HELGRIND_ENABLED
#include "valgrind/helgrind.h"
#endif
#if VG_DRD_ENABLED
#include "valgrind/drd.h"
#endif
#if VG_HELGRIND_ENABLED || VG_DRD_ENABLED
#define VALGRIND_ANNOTATE_HAPPENS_BEFORE(obj) do {\
if (On_valgrind) \
ANNOTATE_HAPPENS_BEFORE((obj));\
} while (0)
#define VALGRIND_ANNOTATE_HAPPENS_AFTER(obj) do {\
if (On_valgrind) \
ANNOTATE_HAPPENS_AFTER((obj));\
} while (0)
#define VALGRIND_ANNOTATE_NEW_MEMORY(addr, size) do {\
if (On_valgrind) \
ANNOTATE_NEW_MEMORY((addr), (size));\
} while (0)
#define VALGRIND_ANNOTATE_IGNORE_READS_BEGIN() do {\
if (On_valgrind) \
ANNOTATE_IGNORE_READS_BEGIN();\
} while (0)
#define VALGRIND_ANNOTATE_IGNORE_READS_END() do {\
if (On_valgrind) \
ANNOTATE_IGNORE_READS_END();\
} while (0)
#define VALGRIND_ANNOTATE_IGNORE_WRITES_BEGIN() do {\
if (On_valgrind) \
ANNOTATE_IGNORE_WRITES_BEGIN();\
} while (0)
#define VALGRIND_ANNOTATE_IGNORE_WRITES_END() do {\
if (On_valgrind) \
ANNOTATE_IGNORE_WRITES_END();\
} while (0)
#else
#define VALGRIND_ANNOTATE_HAPPENS_BEFORE(obj) do { (void)(obj); } while (0)
#define VALGRIND_ANNOTATE_HAPPENS_AFTER(obj) do { (void)(obj); } while (0)
#define VALGRIND_ANNOTATE_NEW_MEMORY(addr, size) do {\
(void) (addr);\
(void) (size);\
} while (0)
#define VALGRIND_ANNOTATE_IGNORE_READS_BEGIN() do {} while (0)
#define VALGRIND_ANNOTATE_IGNORE_READS_END() do {} while (0)
#define VALGRIND_ANNOTATE_IGNORE_WRITES_BEGIN() do {} while (0)
#define VALGRIND_ANNOTATE_IGNORE_WRITES_END() do {} while (0)
#endif
#if VG_PMEMCHECK_ENABLED
#include "valgrind/pmemcheck.h"
extern void util_emit_log(const char *lib, const char *func, int order);
extern int _Pmreorder_emit;
#define Pmreorder_emit __builtin_expect(_Pmreorder_emit, 0)
#define VALGRIND_REGISTER_PMEM_MAPPING(addr, len) do {\
if (On_valgrind)\
VALGRIND_PMC_REGISTER_PMEM_MAPPING((addr), (len));\
} while (0)
#define VALGRIND_REGISTER_PMEM_FILE(desc, base_addr, size, offset) do {\
if (On_valgrind)\
VALGRIND_PMC_REGISTER_PMEM_FILE((desc), (base_addr), (size), \
(offset));\
} while (0)
#define VALGRIND_REMOVE_PMEM_MAPPING(addr, len) do {\
if (On_valgrind)\
VALGRIND_PMC_REMOVE_PMEM_MAPPING((addr), (len));\
} while (0)
#define VALGRIND_CHECK_IS_PMEM_MAPPING(addr, len) do {\
if (On_valgrind)\
VALGRIND_PMC_CHECK_IS_PMEM_MAPPING((addr), (len));\
} while (0)
#define VALGRIND_PRINT_PMEM_MAPPINGS do {\
if (On_valgrind)\
VALGRIND_PMC_PRINT_PMEM_MAPPINGS;\
} while (0)
#define VALGRIND_DO_FLUSH(addr, len) do {\
if (On_valgrind)\
VALGRIND_PMC_DO_FLUSH((addr), (len));\
} while (0)
#define VALGRIND_DO_FENCE do {\
if (On_valgrind)\
VALGRIND_PMC_DO_FENCE;\
} while (0)
#define VALGRIND_DO_PERSIST(addr, len) do {\
if (On_valgrind) {\
VALGRIND_PMC_DO_FLUSH((addr), (len));\
VALGRIND_PMC_DO_FENCE;\
}\
} while (0)
#define VALGRIND_SET_CLEAN(addr, len) do {\
if (On_valgrind)\
VALGRIND_PMC_SET_CLEAN(addr, len);\
} while (0)
#define VALGRIND_WRITE_STATS do {\
if (On_valgrind)\
VALGRIND_PMC_WRITE_STATS;\
} while (0)
#define VALGRIND_LOG_STORES do {\
if (On_valgrind)\
VALGRIND_PMC_LOG_STORES;\
} while (0)
#define VALGRIND_NO_LOG_STORES do {\
if (On_valgrind)\
VALGRIND_PMC_NO_LOG_STORES;\
} while (0)
#define VALGRIND_ADD_LOG_REGION(addr, len) do {\
if (On_valgrind)\
VALGRIND_PMC_ADD_LOG_REGION((addr), (len));\
} while (0)
#define VALGRIND_REMOVE_LOG_REGION(addr, len) do {\
if (On_valgrind)\ \
VALGRIND_PMC_REMOVE_LOG_REGION((addr), (len));\
} while (0)
#define VALGRIND_EMIT_LOG(emit_log) do {\
if (On_valgrind)\
VALGRIND_PMC_EMIT_LOG((emit_log));\
} while (0)
#define VALGRIND_START_TX do {\
if (On_valgrind)\
VALGRIND_PMC_START_TX;\
} while (0)
#define VALGRIND_START_TX_N(txn) do {\
if (On_valgrind)\
VALGRIND_PMC_START_TX_N(txn);\
} while (0)
#define VALGRIND_END_TX do {\
if (On_valgrind)\
VALGRIND_PMC_END_TX;\
} while (0)
#define VALGRIND_END_TX_N(txn) do {\
if (On_valgrind)\
VALGRIND_PMC_END_TX_N(txn);\
} while (0)
#define VALGRIND_ADD_TO_TX(addr, len) do {\
if (On_valgrind)\
VALGRIND_PMC_ADD_TO_TX(addr, len);\
} while (0)
#define VALGRIND_ADD_TO_TX_N(txn, addr, len) do {\
if (On_valgrind)\
VALGRIND_PMC_ADD_TO_TX_N(txn, addr, len);\
} while (0)
#define VALGRIND_REMOVE_FROM_TX(addr, len) do {\
if (On_valgrind)\
VALGRIND_PMC_REMOVE_FROM_TX(addr, len);\
} while (0)
#define VALGRIND_REMOVE_FROM_TX_N(txn, addr, len) do {\
if (On_valgrind)\
VALGRIND_PMC_REMOVE_FROM_TX_N(txn, addr, len);\
} while (0)
#define VALGRIND_ADD_TO_GLOBAL_TX_IGNORE(addr, len) do {\
if (On_valgrind)\
VALGRIND_PMC_ADD_TO_GLOBAL_TX_IGNORE(addr, len);\
} while (0)
/*
* Logs library and function name with proper suffix
* to pmemcheck store log file.
*/
#define PMEMOBJ_API_START()\
if (Pmreorder_emit)\
util_emit_log("libpmemobj", __func__, 0);
#define PMEMOBJ_API_END()\
if (Pmreorder_emit)\
util_emit_log("libpmemobj", __func__, 1);
#else
#define Pmreorder_emit (0)
#define VALGRIND_REGISTER_PMEM_MAPPING(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_REGISTER_PMEM_FILE(desc, base_addr, size, offset) do {\
(void) (desc);\
(void) (base_addr);\
(void) (size);\
(void) (offset);\
} while (0)
#define VALGRIND_REMOVE_PMEM_MAPPING(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_CHECK_IS_PMEM_MAPPING(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_PRINT_PMEM_MAPPINGS do {} while (0)
#define VALGRIND_DO_FLUSH(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_DO_FENCE do {} while (0)
#define VALGRIND_DO_PERSIST(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_SET_CLEAN(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_WRITE_STATS do {} while (0)
#define VALGRIND_LOG_STORES do {} while (0)
#define VALGRIND_NO_LOG_STORES do {} while (0)
#define VALGRIND_ADD_LOG_REGION(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_REMOVE_LOG_REGION(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_EMIT_LOG(emit_log) do {\
(void) (emit_log);\
} while (0)
#define VALGRIND_START_TX do {} while (0)
#define VALGRIND_START_TX_N(txn) do { (void) (txn); } while (0)
#define VALGRIND_END_TX do {} while (0)
#define VALGRIND_END_TX_N(txn) do {\
(void) (txn);\
} while (0)
#define VALGRIND_ADD_TO_TX(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_ADD_TO_TX_N(txn, addr, len) do {\
(void) (txn);\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_REMOVE_FROM_TX(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_REMOVE_FROM_TX_N(txn, addr, len) do {\
(void) (txn);\
(void) (addr);\
(void) (len);\
} while (0)
#define VALGRIND_ADD_TO_GLOBAL_TX_IGNORE(addr, len) do {\
(void) (addr);\
(void) (len);\
} while (0)
#define PMEMOBJ_API_START() do {} while (0)
#define PMEMOBJ_API_END() do {} while (0)
#endif
#if VG_MEMCHECK_ENABLED
#include "valgrind/memcheck.h"
#define VALGRIND_DO_DISABLE_ERROR_REPORTING do {\
if (On_valgrind)\
VALGRIND_DISABLE_ERROR_REPORTING;\
} while (0)
#define VALGRIND_DO_ENABLE_ERROR_REPORTING do {\
if (On_valgrind)\
VALGRIND_ENABLE_ERROR_REPORTING;\
} while (0)
#define VALGRIND_DO_CREATE_MEMPOOL(heap, rzB, is_zeroed) do {\
if (On_valgrind)\
VALGRIND_CREATE_MEMPOOL(heap, rzB, is_zeroed);\
} while (0)
#define VALGRIND_DO_DESTROY_MEMPOOL(heap) do {\
if (On_valgrind)\
VALGRIND_DESTROY_MEMPOOL(heap);\
} while (0)
#define VALGRIND_DO_MEMPOOL_ALLOC(heap, addr, size) do {\
if (On_valgrind)\
VALGRIND_MEMPOOL_ALLOC(heap, addr, size);\
} while (0)
#define VALGRIND_DO_MEMPOOL_FREE(heap, addr) do {\
if (On_valgrind)\
VALGRIND_MEMPOOL_FREE(heap, addr);\
} while (0)
#define VALGRIND_DO_MEMPOOL_CHANGE(heap, addrA, addrB, size) do {\
if (On_valgrind)\
VALGRIND_MEMPOOL_CHANGE(heap, addrA, addrB, size);\
} while (0)
#define VALGRIND_DO_MAKE_MEM_DEFINED(addr, len) do {\
if (On_valgrind)\
VALGRIND_MAKE_MEM_DEFINED(addr, len);\
} while (0)
#define VALGRIND_DO_MAKE_MEM_UNDEFINED(addr, len) do {\
if (On_valgrind)\
VALGRIND_MAKE_MEM_UNDEFINED(addr, len);\
} while (0)
#define VALGRIND_DO_MAKE_MEM_NOACCESS(addr, len) do {\
if (On_valgrind)\
VALGRIND_MAKE_MEM_NOACCESS(addr, len);\
} while (0)
#define VALGRIND_DO_CHECK_MEM_IS_ADDRESSABLE(addr, len) do {\
if (On_valgrind)\
VALGRIND_CHECK_MEM_IS_ADDRESSABLE(addr, len);\
} while (0)
#else
#define VALGRIND_DO_DISABLE_ERROR_REPORTING do {} while (0)
#define VALGRIND_DO_ENABLE_ERROR_REPORTING do {} while (0)
#define VALGRIND_DO_CREATE_MEMPOOL(heap, rzB, is_zeroed)\
do { (void) (heap); (void) (rzB); (void) (is_zeroed); } while (0)
#define VALGRIND_DO_DESTROY_MEMPOOL(heap)\
do { (void) (heap); } while (0)
#define VALGRIND_DO_MEMPOOL_ALLOC(heap, addr, size)\
do { (void) (heap); (void) (addr); (void) (size); } while (0)
#define VALGRIND_DO_MEMPOOL_FREE(heap, addr)\
do { (void) (heap); (void) (addr); } while (0)
#define VALGRIND_DO_MEMPOOL_CHANGE(heap, addrA, addrB, size)\
do {\
(void) (heap); (void) (addrA); (void) (addrB); (void) (size);\
} while (0)
#define VALGRIND_DO_MAKE_MEM_DEFINED(addr, len)\
do { (void) (addr); (void) (len); } while (0)
#define VALGRIND_DO_MAKE_MEM_UNDEFINED(addr, len)\
do { (void) (addr); (void) (len); } while (0)
#define VALGRIND_DO_MAKE_MEM_NOACCESS(addr, len)\
do { (void) (addr); (void) (len); } while (0)
#define VALGRIND_DO_CHECK_MEM_IS_ADDRESSABLE(addr, len)\
do { (void) (addr); (void) (len); } while (0)
#endif
#endif
| 11,923
| 23.738589
| 75
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_posix.c
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_posix.c -- abstraction layer for basic Posix functions
*/
#define _GNU_SOURCE
#include <fcntl.h>
#include <stdarg.h>
#include <sys/file.h>
#ifdef __FreeBSD__
#include <sys/mount.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include "util.h"
#include "out.h"
#include "os.h"
/*
* os_open -- open abstraction layer
*/
int
os_open(const char *pathname, int flags, ...)
{
int mode_required = (flags & O_CREAT) == O_CREAT;
#ifdef O_TMPFILE
mode_required |= (flags & O_TMPFILE) == O_TMPFILE;
#endif
if (mode_required) {
va_list arg;
va_start(arg, flags);
/* Clang requires int due to auto-promotion */
int mode = va_arg(arg, int);
va_end(arg);
return open(pathname, flags, (mode_t)mode);
} else {
return open(pathname, flags);
}
}
/*
* os_fsync -- fsync abstraction layer
*/
int
os_fsync(int fd)
{
return fsync(fd);
}
/*
* os_fsync_dir -- fsync the directory
*/
int
os_fsync_dir(const char *dir_name)
{
int fd = os_open(dir_name, O_RDONLY | O_DIRECTORY);
if (fd < 0)
return -1;
int ret = os_fsync(fd);
os_close(fd);
return ret;
}
/*
* os_stat -- stat abstraction layer
*/
int
os_stat(const char *pathname, os_stat_t *buf)
{
return stat(pathname, buf);
}
/*
* os_unlink -- unlink abstraction layer
*/
int
os_unlink(const char *pathname)
{
return unlink(pathname);
}
/*
* os_access -- access abstraction layer
*/
int
os_access(const char *pathname, int mode)
{
return access(pathname, mode);
}
/*
* os_fopen -- fopen abstraction layer
*/
FILE *
os_fopen(const char *pathname, const char *mode)
{
return fopen(pathname, mode);
}
/*
* os_fdopen -- fdopen abstraction layer
*/
FILE *
os_fdopen(int fd, const char *mode)
{
return fdopen(fd, mode);
}
/*
* os_chmod -- chmod abstraction layer
*/
int
os_chmod(const char *pathname, mode_t mode)
{
return chmod(pathname, mode);
}
/*
* os_mkstemp -- mkstemp abstraction layer
*/
int
os_mkstemp(char *temp)
{
return mkstemp(temp);
}
/*
* os_posix_fallocate -- posix_fallocate abstraction layer
*/
int
os_posix_fallocate(int fd, os_off_t offset, off_t len)
{
#ifdef __FreeBSD__
struct stat fbuf;
struct statfs fsbuf;
/*
* XXX Workaround for https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=223287
*
* FreeBSD implements posix_fallocate with a simple block allocation/zero
* loop. If the requested size is unreasonably large, this can result in
* an uninterruptable system call that will suck up all the space in the
* file system and could take hours to fail. To avoid this, make a crude
* check to see if the requested allocation is larger than the available
* space in the file system (minus any blocks already allocated to the
* file), and if so, immediately return ENOSPC. We do the check only if
* the offset is 0; otherwise, trying to figure out how many additional
* blocks are required is too complicated.
*
* This workaround is here mostly to fail "absurdly" large requests for
* testing purposes; however, it is coded to allow normal (albeit slow)
* operation if the space can actually be allocated. Because of the way
* PMDK uses posix_fallocate, supporting Linux-style fallocate in
* FreeBSD should be considered.
*/
if (offset == 0) {
if (fstatfs(fd, &fsbuf) == -1 || fstat(fd, &fbuf) == -1)
return errno;
size_t reqd_blocks =
(((size_t)len + (fsbuf.f_bsize - 1)) / fsbuf.f_bsize)
- (size_t)fbuf.st_blocks;
if (reqd_blocks > (size_t)fsbuf.f_bavail)
return ENOSPC;
}
#endif
return posix_fallocate(fd, offset, len);
}
/*
* os_ftruncate -- ftruncate abstraction layer
*/
int
os_ftruncate(int fd, os_off_t length)
{
return ftruncate(fd, length);
}
/*
* os_flock -- flock abstraction layer
*/
int
os_flock(int fd, int operation)
{
int opt = 0;
if (operation & OS_LOCK_EX)
opt |= LOCK_EX;
if (operation & OS_LOCK_SH)
opt |= LOCK_SH;
if (operation & OS_LOCK_UN)
opt |= LOCK_UN;
if (operation & OS_LOCK_NB)
opt |= LOCK_NB;
return flock(fd, opt);
}
/*
* os_writev -- writev abstraction layer
*/
ssize_t
os_writev(int fd, const struct iovec *iov, int iovcnt)
{
return writev(fd, iov, iovcnt);
}
/*
* os_clock_gettime -- clock_gettime abstraction layer
*/
int
os_clock_gettime(int id, struct timespec *ts)
{
return clock_gettime(id, ts);
}
/*
* os_rand_r -- rand_r abstraction layer
*/
unsigned
os_rand_r(unsigned *seedp)
{
return (unsigned)rand_r(seedp);
}
/*
* os_unsetenv -- unsetenv abstraction layer
*/
int
os_unsetenv(const char *name)
{
return unsetenv(name);
}
/*
* os_setenv -- setenv abstraction layer
*/
int
os_setenv(const char *name, const char *value, int overwrite)
{
return setenv(name, value, overwrite);
}
/*
* secure_getenv -- provide GNU secure_getenv for FreeBSD
*/
#ifndef __USE_GNU
static char *
secure_getenv(const char *name)
{
if (issetugid() != 0)
return NULL;
return getenv(name);
}
#endif
/*
* os_getenv -- getenv abstraction layer
*/
char *
os_getenv(const char *name)
{
return secure_getenv(name);
}
/*
* os_strsignal -- strsignal abstraction layer
*/
const char *
os_strsignal(int sig)
{
return strsignal(sig);
}
int
os_execv(const char *path, char *const argv[])
{
return execv(path, argv);
}
| 6,879
| 20.234568
| 78
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/vecq.h
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vecq.h -- vector queue (FIFO) interface
*/
#ifndef PMDK_VECQ_H
#define PMDK_VECQ_H 1
#include <stddef.h>
#include "util.h"
#include "out.h"
#ifdef __cplusplus
extern "C" {
#endif
#define VECQ_INIT_SIZE (64)
#define VECQ(name, type)\
struct name {\
type *buffer;\
size_t capacity;\
size_t front;\
size_t back;\
}
#define VECQ_INIT(vec) do {\
(vec)->buffer = NULL;\
(vec)->capacity = 0;\
(vec)->front = 0;\
(vec)->back = 0;\
} while (0)
#define VECQ_REINIT(vec) do {\
VALGRIND_ANNOTATE_NEW_MEMORY((vec), sizeof(*vec));\
VALGRIND_ANNOTATE_NEW_MEMORY((vec)->buffer,\
(sizeof(*(vec)->buffer) * ((vec)->capacity)));\
(vec)->front = 0;\
(vec)->back = 0;\
} while (0)
#define VECQ_FRONT_POS(vec)\
((vec)->front & ((vec)->capacity - 1))
#define VECQ_BACK_POS(vec)\
((vec)->back & ((vec)->capacity - 1))
#define VECQ_FRONT(vec)\
(vec)->buffer[VECQ_FRONT_POS(vec)]
#define VECQ_BACK(vec)\
(vec)->buffer[VECQ_BACK_POS(vec)]
#define VECQ_DEQUEUE(vec)\
((vec)->buffer[(((vec)->front++) & ((vec)->capacity - 1))])
#define VECQ_SIZE(vec)\
((vec)->back - (vec)->front)
static inline int
vecq_grow(void *vec, size_t s)
{
VECQ(vvec, void) *vecp = (struct vvec *)vec;
size_t ncapacity = vecp->capacity == 0 ?
VECQ_INIT_SIZE : vecp->capacity * 2;
void *tbuf = Realloc(vecp->buffer, s * ncapacity);
if (tbuf == NULL) {
ERR("!Realloc");
return -1;
}
vecp->buffer = tbuf;
vecp->capacity = ncapacity;
return 0;
}
#define VECQ_GROW(vec)\
vecq_grow((void *)vec, sizeof(*(vec)->buffer))
#define VECQ_INSERT(vec, element)\
(VECQ_BACK(vec) = element, (vec)->back += 1, 0)
#define VECQ_ENQUEUE(vec, element)\
((vec)->capacity == VECQ_SIZE(vec) ?\
(VECQ_GROW(vec) == 0 ? VECQ_INSERT(vec, element) : -1) :\
VECQ_INSERT(vec, element))
#define VECQ_CAPACITY(vec)\
((vec)->capacity)
#define VECQ_FOREACH(el, vec)\
for (size_t _vec_i = 0;\
_vec_i < VECQ_SIZE(vec) &&\
(((el) = (vec)->buffer[_vec_i & ((vec)->capacity - 1)]), 1);\
++_vec_i)
#define VECQ_FOREACH_REVERSE(el, vec)\
for (size_t _vec_i = VECQ_SIZE(vec);\
_vec_i > 0 &&\
(((el) = (vec)->buffer[(_vec_i - 1) & ((vec)->capacity - 1)]), 1);\
--_vec_i)
#define VECQ_CLEAR(vec) do {\
(vec)->front = 0;\
(vec)->back = 0;\
} while (0)
#define VECQ_DELETE(vec) do {\
Free((vec)->buffer);\
(vec)->buffer = NULL;\
(vec)->capacity = 0;\
(vec)->front = 0;\
(vec)->back = 0;\
} while (0)
#ifdef __cplusplus
}
#endif
#endif /* PMDK_VECQ_H */
| 4,023
| 25.473684
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_deep_linux.c
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_deep_linux.c -- Linux abstraction layer
*/
#define _GNU_SOURCE
#include <inttypes.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "out.h"
#include "os.h"
#include "mmap.h"
#include "file.h"
#include "libpmem.h"
#include "os_deep.h"
/*
* os_deep_flush_write -- (internal) perform write to deep_flush file
* on given region_id
*/
static int
os_deep_flush_write(int region_id)
{
LOG(3, "region_id %d", region_id);
char deep_flush_path[PATH_MAX];
int deep_flush_fd;
snprintf(deep_flush_path, PATH_MAX,
"/sys/bus/nd/devices/region%d/deep_flush", region_id);
if ((deep_flush_fd = os_open(deep_flush_path, O_WRONLY)) < 0) {
LOG(1, "!os_open(\"%s\", O_WRONLY)", deep_flush_path);
return -1;
}
if (write(deep_flush_fd, "1", 1) != 1) {
LOG(1, "!write(%d, \"1\")", deep_flush_fd);
int oerrno = errno;
os_close(deep_flush_fd);
errno = oerrno;
return -1;
}
os_close(deep_flush_fd);
return 0;
}
/*
* os_deep_type -- (internal) perform deep operation based on a pmem
* mapping type
*/
static int
os_deep_type(const struct map_tracker *mt, void *addr, size_t len)
{
LOG(15, "mt %p addr %p len %zu", mt, addr, len);
switch (mt->type) {
case PMEM_DEV_DAX:
pmem_drain();
if (os_deep_flush_write(mt->region_id) < 0) {
if (errno == ENOENT) {
errno = ENOTSUP;
LOG(1, "!deep_flush not supported");
} else {
LOG(2, "cannot write to deep_flush"
"in region %d", mt->region_id);
}
return -1;
}
return 0;
case PMEM_MAP_SYNC:
return pmem_msync(addr, len);
default:
ASSERT(0);
return -1;
}
}
/*
* os_range_deep_common -- perform deep action of given address range
*/
int
os_range_deep_common(uintptr_t addr, size_t len)
{
LOG(3, "addr 0x%016" PRIxPTR " len %zu", addr, len);
while (len != 0) {
const struct map_tracker *mt = util_range_find(addr, len);
/* no more overlapping track regions or NOT a device DAX */
if (mt == NULL) {
LOG(15, "pmem_msync addr %p, len %lu",
(void *)addr, len);
return pmem_msync((void *)addr, len);
}
/*
* For range that intersects with the found mapping
* write to (Device DAX) deep_flush file.
* Call msync for the non-intersecting part.
*/
if (mt->base_addr > addr) {
size_t curr_len = mt->base_addr - addr;
if (curr_len > len)
curr_len = len;
if (pmem_msync((void *)addr, curr_len) != 0)
return -1;
len -= curr_len;
if (len == 0)
return 0;
addr = mt->base_addr;
}
size_t mt_in_len = mt->end_addr - addr;
size_t persist_len = MIN(len, mt_in_len);
if (os_deep_type(mt, (void *)addr, persist_len))
return -1;
if (mt->end_addr >= addr + len)
return 0;
len -= mt_in_len;
addr = mt->end_addr;
}
return 0;
}
/*
* os_part_deep_common -- common function to handle both
* deep_persist and deep_drain part flush cases.
*/
int
os_part_deep_common(struct pool_replica *rep, unsigned partidx, void *addr,
size_t len, int flush)
{
LOG(3, "part %p part %d addr %p len %lu flush %d",
rep, partidx, addr, len, flush);
if (!rep->is_pmem) {
/*
* In case of part on non-pmem call msync on the range
* to deep flush the data. Deep drain is empty as all
* data is msynced to persistence.
*/
if (!flush)
return 0;
if (pmem_msync(addr, len)) {
LOG(1, "pmem_msync(%p, %lu)", addr, len);
return -1;
}
return 0;
}
struct pool_set_part part = rep->part[partidx];
/* Call deep flush if it was requested */
if (flush) {
LOG(15, "pmem_deep_flush addr %p, len %lu", addr, len);
pmem_deep_flush(addr, len);
}
/*
* Before deep drain call normal drain to ensure that data
* is at least in WPQ.
*/
pmem_drain();
if (part.is_dev_dax) {
/*
* During deep_drain for part on device DAX search for
* device region id, and perform WPQ flush on found
* device DAX region.
*/
int region_id = util_ddax_region_find(part.path);
if (region_id < 0) {
if (errno == ENOENT) {
errno = ENOTSUP;
LOG(1, "!deep_flush not supported");
} else {
LOG(1, "invalid dax_region id %d", region_id);
}
return -1;
}
if (os_deep_flush_write(region_id)) {
LOG(1, "ddax_deep_flush_write(%d)",
region_id);
return -1;
}
} else {
/*
* For deep_drain on normal pmem it is enough to
* call msync on one page.
*/
if (pmem_msync(addr, MIN(Pagesize, len))) {
LOG(1, "pmem_msync(%p, %lu)", addr, len);
return -1;
}
}
return 0;
}
| 6,006
| 24.561702
| 75
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/ctl_global.c
|
/*
* Copyright 2016-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ctl_global.c -- implementation of the global CTL namespace
*/
#include "ctl.h"
#include "set.h"
#include "out.h"
#include "ctl_global.h"
static int
CTL_READ_HANDLER(at_create)(void *ctx, enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
int *arg_out = arg;
*arg_out = Prefault_at_create;
return 0;
}
static int
CTL_WRITE_HANDLER(at_create)(void *ctx, enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
int arg_in = *(int *)arg;
Prefault_at_create = arg_in;
return 0;
}
static int
CTL_READ_HANDLER(at_open)(void *ctx, enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
int *arg_out = arg;
*arg_out = Prefault_at_open;
return 0;
}
static int
CTL_WRITE_HANDLER(at_open)(void *ctx, enum ctl_query_source source,
void *arg, struct ctl_indexes *indexes)
{
int arg_in = *(int *)arg;
Prefault_at_open = arg_in;
return 0;
}
static struct ctl_argument CTL_ARG(at_create) = CTL_ARG_BOOLEAN;
static struct ctl_argument CTL_ARG(at_open) = CTL_ARG_BOOLEAN;
static const struct ctl_node CTL_NODE(prefault)[] = {
CTL_LEAF_RW(at_create),
CTL_LEAF_RW(at_open),
CTL_NODE_END
};
void
ctl_global_register(void)
{
CTL_REGISTER_MODULE(NULL, prefault);
}
| 2,839
| 27.686869
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_dimm_ndctl.c
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_dimm_ndctl.c -- implementation of DIMMs API based on the ndctl library
*/
#define _GNU_SOURCE
#include <sys/types.h>
#include <libgen.h>
#include <limits.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ndctl/libndctl.h>
#include <ndctl/libdaxctl.h>
/* XXX: workaround for missing PAGE_SIZE - should be fixed in linux/ndctl.h */
#include <sys/user.h>
#include <linux/ndctl.h>
#include "out.h"
#include "os.h"
#include "os_dimm.h"
#include "os_badblock.h"
#include "badblock.h"
#include "vec.h"
/*
* http://pmem.io/documents/NVDIMM_DSM_Interface-V1.6.pdf
* Table 3-2 SMART amd Health Data - Validity flags
* Bit[5] – If set to 1, indicates that Unsafe Shutdown Count
* field is valid
*/
#define USC_VALID_FLAG (1 << 5)
#define FOREACH_BUS_REGION_NAMESPACE(ctx, bus, region, ndns) \
ndctl_bus_foreach(ctx, bus) \
ndctl_region_foreach(bus, region) \
ndctl_namespace_foreach(region, ndns) \
/*
* os_dimm_match_device -- (internal) returns 1 if the device matches
* with the given file, 0 if it doesn't match,
* and -1 in case of error.
*/
static int
os_dimm_match_device(const os_stat_t *st, const char *devname)
{
LOG(3, "st %p devname %s", st, devname);
if (*devname == '\0')
return 0;
char path[PATH_MAX];
os_stat_t stat;
int ret;
if ((ret = snprintf(path, PATH_MAX, "/dev/%s", devname)) < 0) {
ERR("snprintf: %d", ret);
return -1;
}
if (os_stat(path, &stat)) {
ERR("!stat %s", path);
return -1;
}
dev_t dev = S_ISCHR(st->st_mode) ? st->st_rdev : st->st_dev;
if (dev == stat.st_rdev) {
LOG(4, "found matching device: %s", path);
return 1;
}
LOG(10, "skipping not matching device: %s", path);
return 0;
}
/*
* os_dimm_region_namespace -- (internal) returns the region
* (and optionally the namespace)
* where the given file is located
*/
static int
os_dimm_region_namespace(struct ndctl_ctx *ctx, const os_stat_t *st,
struct ndctl_region **pregion,
struct ndctl_namespace **pndns)
{
LOG(3, "ctx %p stat %p pregion %p pnamespace %p",
ctx, st, pregion, pndns);
struct ndctl_bus *bus;
struct ndctl_region *region;
struct ndctl_namespace *ndns;
ASSERTne(pregion, NULL);
*pregion = NULL;
if (pndns)
*pndns = NULL;
FOREACH_BUS_REGION_NAMESPACE(ctx, bus, region, ndns) {
struct ndctl_btt *btt;
struct ndctl_dax *dax = NULL;
struct ndctl_pfn *pfn;
const char *devname;
if ((dax = ndctl_namespace_get_dax(ndns))) {
struct daxctl_region *dax_region;
dax_region = ndctl_dax_get_daxctl_region(dax);
if (!dax_region) {
ERR("!cannot find dax region");
return -1;
}
struct daxctl_dev *dev;
daxctl_dev_foreach(dax_region, dev) {
devname = daxctl_dev_get_devname(dev);
int ret = os_dimm_match_device(st, devname);
if (ret < 0)
return ret;
if (ret) {
*pregion = region;
if (pndns)
*pndns = ndns;
return 0;
}
}
} else {
if ((btt = ndctl_namespace_get_btt(ndns))) {
devname = ndctl_btt_get_block_device(btt);
} else if ((pfn = ndctl_namespace_get_pfn(ndns))) {
devname = ndctl_pfn_get_block_device(pfn);
} else {
devname =
ndctl_namespace_get_block_device(ndns);
}
int ret = os_dimm_match_device(st, devname);
if (ret < 0)
return ret;
if (ret) {
*pregion = region;
if (pndns)
*pndns = ndns;
return 0;
}
}
}
LOG(10, "did not found any matching device");
return 0;
}
/*
* os_dimm_interleave_set -- (internal) returns set of dimms
* where the pool file is located
*/
static struct ndctl_interleave_set *
os_dimm_interleave_set(struct ndctl_ctx *ctx, const os_stat_t *st)
{
LOG(3, "ctx %p stat %p", ctx, st);
struct ndctl_region *region = NULL;
if (os_dimm_region_namespace(ctx, st, ®ion, NULL))
return NULL;
return region ? ndctl_region_get_interleave_set(region) : NULL;
}
/*
* os_dimm_uid -- returns a file uid based on dimms uids
*
* if uid == null then function will return required buffer size
*/
int
os_dimm_uid(const char *path, char *uid, size_t *buff_len)
{
LOG(3, "path %s, uid %p, len %lu", path, uid, *buff_len);
os_stat_t st;
struct ndctl_ctx *ctx;
struct ndctl_interleave_set *set;
struct ndctl_dimm *dimm;
int ret = 0;
if (os_stat(path, &st)) {
ERR("!stat %s", path);
return -1;
}
if (ndctl_new(&ctx)) {
ERR("!ndctl_new");
return -1;
}
if (uid == NULL) {
*buff_len = 1; /* '\0' */
}
set = os_dimm_interleave_set(ctx, &st);
if (set == NULL)
goto end;
if (uid == NULL) {
ndctl_dimm_foreach_in_interleave_set(set, dimm) {
*buff_len += strlen(ndctl_dimm_get_unique_id(dimm));
}
goto end;
}
size_t len = 1;
ndctl_dimm_foreach_in_interleave_set(set, dimm) {
const char *dimm_uid = ndctl_dimm_get_unique_id(dimm);
len += strlen(dimm_uid);
if (len > *buff_len) {
ret = -1;
goto end;
}
strncat(uid, dimm_uid, *buff_len);
}
end:
ndctl_unref(ctx);
return ret;
}
/*
* os_dimm_usc -- returns unsafe shutdown count
*/
int
os_dimm_usc(const char *path, uint64_t *usc)
{
LOG(3, "path %s, uid %p", path, usc);
os_stat_t st;
struct ndctl_ctx *ctx;
int ret = -1;
*usc = 0;
if (os_stat(path, &st)) {
ERR("!stat %s", path);
return -1;
}
if (ndctl_new(&ctx)) {
ERR("!ndctl_new");
return -1;
}
struct ndctl_interleave_set *iset =
os_dimm_interleave_set(ctx, &st);
if (iset == NULL)
goto out;
struct ndctl_dimm *dimm;
ndctl_dimm_foreach_in_interleave_set(iset, dimm) {
struct ndctl_cmd *cmd = ndctl_dimm_cmd_new_smart(dimm);
if (cmd == NULL) {
ERR("!ndctl_dimm_cmd_new_smart");
goto err;
}
if (ndctl_cmd_submit(cmd)) {
ERR("!ndctl_cmd_submit");
goto err;
}
if (!(ndctl_cmd_smart_get_flags(cmd) & USC_VALID_FLAG)) {
/* dimm doesn't support unsafe shutdown count */
continue;
}
*usc += ndctl_cmd_smart_get_shutdown_count(cmd);
}
out:
ret = 0;
err:
ndctl_unref(ctx);
return ret;
}
/*
* os_dimm_get_namespace_bounds -- (internal) returns the bounds
* (offset and size) of the given namespace
* relative to the beginning of its region
*/
static int
os_dimm_get_namespace_bounds(struct ndctl_region *region,
struct ndctl_namespace *ndns,
unsigned long long *ns_offset,
unsigned long long *ns_size)
{
LOG(3, "region %p namespace %p ns_offset %p ns_size %p",
region, ndns, ns_offset, ns_size);
struct ndctl_pfn *pfn = ndctl_namespace_get_pfn(ndns);
struct ndctl_dax *dax = ndctl_namespace_get_dax(ndns);
ASSERTne(ns_offset, NULL);
ASSERTne(ns_size, NULL);
if (pfn) {
*ns_offset = ndctl_pfn_get_resource(pfn);
if (*ns_offset == ULLONG_MAX) {
ERR("!(pfn) cannot read offset of the namespace");
return -1;
}
*ns_size = ndctl_pfn_get_size(pfn);
if (*ns_size == ULLONG_MAX) {
ERR("!(pfn) cannot read size of the namespace");
return -1;
}
LOG(10, "(pfn) ns_offset 0x%llx ns_size %llu",
*ns_offset, *ns_size);
} else if (dax) {
*ns_offset = ndctl_dax_get_resource(dax);
if (*ns_offset == ULLONG_MAX) {
ERR("!(dax) cannot read offset of the namespace");
return -1;
}
*ns_size = ndctl_dax_get_size(dax);
if (*ns_size == ULLONG_MAX) {
ERR("!(dax) cannot read size of the namespace");
return -1;
}
LOG(10, "(dax) ns_offset 0x%llx ns_size %llu",
*ns_offset, *ns_size);
} else { /* raw or btt */
*ns_offset = ndctl_namespace_get_resource(ndns);
if (*ns_offset == ULLONG_MAX) {
ERR("!(raw/btt) cannot read offset of the namespace");
return -1;
}
*ns_size = ndctl_namespace_get_size(ndns);
if (*ns_size == ULLONG_MAX) {
ERR("!(raw/btt) cannot read size of the namespace");
return -1;
}
LOG(10, "(raw/btt) ns_offset 0x%llx ns_size %llu",
*ns_offset, *ns_size);
}
unsigned long long region_offset = ndctl_region_get_resource(region);
if (region_offset == ULLONG_MAX) {
ERR("!cannot read offset of the region");
return -1;
}
LOG(10, "region_offset 0x%llx", region_offset);
*ns_offset -= region_offset;
return 0;
}
/*
* os_dimm_namespace_get_badblocks -- (internal) returns bad blocks
* in the given namespace
*/
static int
os_dimm_namespace_get_badblocks(struct ndctl_region *region,
struct ndctl_namespace *ndns,
struct badblocks *bbs)
{
LOG(3, "region %p, namespace %p", region, ndns);
ASSERTne(bbs, NULL);
unsigned long long ns_beg, ns_size, ns_end;
unsigned long long bb_beg, bb_end;
unsigned long long beg, end;
VEC(bbsvec, struct bad_block) bbv = VEC_INITIALIZER;
bbs->ns_resource = 0;
bbs->bb_cnt = 0;
bbs->bbv = NULL;
if (os_dimm_get_namespace_bounds(region, ndns, &ns_beg, &ns_size)) {
LOG(1, "cannot read namespace's bounds");
return -1;
}
ns_end = ns_beg + ns_size - 1;
LOG(10, "namespace: begin %llu, end %llu size %llu (in 512B sectors)",
B2SEC(ns_beg), B2SEC(ns_end + 1) - 1, B2SEC(ns_size));
struct badblock *bb;
ndctl_region_badblock_foreach(region, bb) {
/*
* libndctl returns offset and length of a bad block
* both expressed in 512B sectors and offset is relative
* to the beginning of the region.
*/
bb_beg = SEC2B(bb->offset);
bb_end = bb_beg + SEC2B(bb->len) - 1;
LOG(10,
"region bad block: begin %llu end %llu length %u (in 512B sectors)",
bb->offset, bb->offset + bb->len - 1, bb->len);
if (bb_beg > ns_end || ns_beg > bb_end)
continue;
beg = (bb_beg > ns_beg) ? bb_beg : ns_beg;
end = (bb_end < ns_end) ? bb_end : ns_end;
/*
* Form a new bad block structure with offset and length
* expressed in bytes and offset relative to the beginning
* of the namespace.
*/
struct bad_block bbn;
bbn.offset = beg - ns_beg;
bbn.length = (unsigned)(end - beg + 1);
bbn.nhealthy = NO_HEALTHY_REPLICA; /* unknown healthy replica */
/* add the new bad block to the vector */
if (VEC_PUSH_BACK(&bbv, bbn)) {
VEC_DELETE(&bbv);
return -1;
}
LOG(4,
"namespace bad block: begin %llu end %llu length %llu (in 512B sectors)",
B2SEC(beg - ns_beg), B2SEC(end - ns_beg),
B2SEC(end - beg) + 1);
}
bbs->bb_cnt = (unsigned)VEC_SIZE(&bbv);
bbs->bbv = VEC_ARR(&bbv);
bbs->ns_resource = ns_beg + ndctl_region_get_resource(region);
LOG(4, "number of bad blocks detected: %u", bbs->bb_cnt);
return 0;
}
/*
* os_dimm_files_namespace_bus -- (internal) returns bus where the given
* file is located
*/
static int
os_dimm_files_namespace_bus(struct ndctl_ctx *ctx,
const char *path,
struct ndctl_bus **pbus)
{
LOG(3, "ctx %p path %s pbus %p", ctx, path, pbus);
ASSERTne(pbus, NULL);
struct ndctl_region *region;
struct ndctl_namespace *ndns;
os_stat_t st;
if (os_stat(path, &st)) {
ERR("!stat %s", path);
return -1;
}
int rv = os_dimm_region_namespace(ctx, &st, ®ion, &ndns);
if (rv) {
LOG(1, "getting region and namespace failed");
return -1;
}
if (!region) {
ERR("region unknown");
return -1;
}
*pbus = ndctl_region_get_bus(region);
return 0;
}
/*
* os_dimm_files_namespace_badblocks_bus -- (internal) returns badblocks
* in the namespace where the given
* file is located
* (optionally returns also the bus)
*/
static int
os_dimm_files_namespace_badblocks_bus(struct ndctl_ctx *ctx,
const char *path,
struct ndctl_bus **pbus,
struct badblocks *bbs)
{
LOG(3, "ctx %p path %s pbus %p badblocks %p", ctx, path, pbus, bbs);
struct ndctl_region *region;
struct ndctl_namespace *ndns;
os_stat_t st;
if (os_stat(path, &st)) {
ERR("!stat %s", path);
return -1;
}
int rv = os_dimm_region_namespace(ctx, &st, ®ion, &ndns);
if (rv) {
LOG(1, "getting region and namespace failed");
return -1;
}
memset(bbs, 0, sizeof(*bbs));
if (region == NULL || ndns == NULL)
return 0;
if (pbus)
*pbus = ndctl_region_get_bus(region);
return os_dimm_namespace_get_badblocks(region, ndns, bbs);
}
/*
* os_dimm_files_namespace_badblocks -- returns badblocks in the namespace
* where the given file is located
*/
int
os_dimm_files_namespace_badblocks(const char *path, struct badblocks *bbs)
{
LOG(3, "path %s", path);
struct ndctl_ctx *ctx;
if (ndctl_new(&ctx)) {
ERR("!ndctl_new");
return -1;
}
int ret = os_dimm_files_namespace_badblocks_bus(ctx, path, NULL, bbs);
ndctl_unref(ctx);
return ret;
}
/*
* os_dimm_devdax_clear_one_badblock -- (internal) clear one bad block
* in the dax device
*/
static int
os_dimm_devdax_clear_one_badblock(struct ndctl_bus *bus,
unsigned long long address,
unsigned long long length)
{
LOG(3, "bus %p address 0x%llx length %llu (bytes)",
bus, address, length);
int ret = 0;
struct ndctl_cmd *cmd_ars_cap = ndctl_bus_cmd_new_ars_cap(bus,
address, length);
if (cmd_ars_cap == NULL) {
ERR("failed to create cmd (bus '%s')",
ndctl_bus_get_provider(bus));
return -1;
}
if ((ret = ndctl_cmd_submit(cmd_ars_cap)) < 0) {
ERR("failed to submit cmd (bus '%s')",
ndctl_bus_get_provider(bus));
goto out_ars_cap;
}
struct ndctl_cmd *cmd_ars_start =
ndctl_bus_cmd_new_ars_start(cmd_ars_cap, ND_ARS_PERSISTENT);
if (cmd_ars_start == NULL) {
ERR("ndctl_bus_cmd_new_ars_start() failed");
goto out_ars_cap;
}
if ((ret = ndctl_cmd_submit(cmd_ars_start)) < 0) {
ERR("failed to submit cmd (bus '%s')",
ndctl_bus_get_provider(bus));
goto out_ars_start;
}
struct ndctl_cmd *cmd_ars_status;
do {
cmd_ars_status = ndctl_bus_cmd_new_ars_status(cmd_ars_cap);
if (cmd_ars_status == NULL) {
ERR("ndctl_bus_cmd_new_ars_status() failed");
goto out_ars_start;
}
if ((ret = ndctl_cmd_submit(cmd_ars_status)) < 0) {
ERR("failed to submit cmd (bus '%s')",
ndctl_bus_get_provider(bus));
goto out_ars_status;
}
} while (ndctl_cmd_ars_in_progress(cmd_ars_status));
struct ndctl_range range;
ndctl_cmd_ars_cap_get_range(cmd_ars_cap, &range);
struct ndctl_cmd *cmd_clear_error = ndctl_bus_cmd_new_clear_error(
range.address, range.length, cmd_ars_cap);
if ((ret = ndctl_cmd_submit(cmd_clear_error)) < 0) {
ERR("failed to submit cmd (bus '%s')",
ndctl_bus_get_provider(bus));
goto out_clear_error;
}
size_t cleared = ndctl_cmd_clear_error_get_cleared(cmd_clear_error);
LOG(4, "cleared %zu out of %llu bad blocks", cleared, length);
ret = cleared == length ? 0 : -1;
out_clear_error:
ndctl_cmd_unref(cmd_clear_error);
out_ars_status:
ndctl_cmd_unref(cmd_ars_status);
out_ars_start:
ndctl_cmd_unref(cmd_ars_start);
out_ars_cap:
ndctl_cmd_unref(cmd_ars_cap);
return ret;
}
/*
* os_dimm_devdax_clear_badblocks -- clear the given bad blocks in the dax
* device (or all of them if 'pbbs' is not set)
*/
int
os_dimm_devdax_clear_badblocks(const char *path, struct badblocks *pbbs)
{
LOG(3, "path %s badblocks %p", path, pbbs);
struct ndctl_ctx *ctx;
struct ndctl_bus *bus;
int ret = -1;
if (ndctl_new(&ctx)) {
ERR("!ndctl_new");
return -1;
}
struct badblocks *bbs = badblocks_new();
if (bbs == NULL)
goto exit_free_all;
if (pbbs) {
ret = os_dimm_files_namespace_bus(ctx, path, &bus);
if (ret) {
LOG(1, "getting bad blocks' bus failed -- %s", path);
goto exit_free_all;
}
badblocks_delete(bbs);
bbs = pbbs;
} else {
ret = os_dimm_files_namespace_badblocks_bus(ctx, path, &bus,
bbs);
if (ret) {
LOG(1, "getting bad blocks for the file failed -- %s",
path);
goto exit_free_all;
}
}
if (bbs->bb_cnt == 0 || bbs->bbv == NULL) /* OK - no bad blocks found */
goto exit_free_all;
LOG(4, "clearing %u bad block(s)...", bbs->bb_cnt);
unsigned b;
for (b = 0; b < bbs->bb_cnt; b++) {
LOG(4,
"clearing bad block: offset %llu length %u (in 512B sectors)",
B2SEC(bbs->bbv[b].offset), B2SEC(bbs->bbv[b].length));
ret = os_dimm_devdax_clear_one_badblock(bus,
bbs->bbv[b].offset + bbs->ns_resource,
bbs->bbv[b].length);
if (ret) {
LOG(1,
"failed to clear bad block: offset %llu length %u (in 512B sectors)",
B2SEC(bbs->bbv[b].offset),
B2SEC(bbs->bbv[b].length));
goto exit_free_all;
}
}
exit_free_all:
if (!pbbs)
badblocks_delete(bbs);
ndctl_unref(ctx);
return ret;
}
/*
* os_dimm_devdax_clear_badblocks_all -- clear all bad blocks in the dax device
*/
int
os_dimm_devdax_clear_badblocks_all(const char *path)
{
LOG(3, "path %s", path);
return os_dimm_devdax_clear_badblocks(path, NULL);
}
| 18,252
| 23.272606
| 80
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/fs.h
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* fs.h -- file system traversal abstraction layer
*/
#ifndef PMDK_FS_H
#define PMDK_FS_H 1
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
struct fs;
enum fs_entry_type {
FS_ENTRY_FILE,
FS_ENTRY_DIRECTORY,
FS_ENTRY_SYMLINK,
FS_ENTRY_OTHER,
MAX_FS_ENTRY_TYPES
};
struct fs_entry {
enum fs_entry_type type;
const char *name;
size_t namelen;
const char *path;
size_t pathlen;
/* the depth of the traversal */
/* XXX long on FreeBSD. Linux uses short. No harm in it being bigger */
long level;
};
struct fs *fs_new(const char *path);
void fs_delete(struct fs *f);
/* this call invalidates the previous entry */
struct fs_entry *fs_read(struct fs *f);
#ifdef __cplusplus
}
#endif
#endif /* PMDK_FS_H */
| 2,342
| 27.925926
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/vec.h
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* vec.h -- vector interface
*/
#ifndef PMDK_VEC_H
#define PMDK_VEC_H 1
#include <stddef.h>
#include "valgrind_internal.h"
#include "util.h"
#include "out.h"
#ifdef __cplusplus
extern "C" {
#endif
#define VEC_INIT_SIZE (64)
#define VEC(name, type)\
struct name {\
type *buffer;\
size_t size;\
size_t capacity;\
}
#define VEC_INITIALIZER {NULL, 0, 0}
#define VEC_INIT(vec) do {\
(vec)->buffer = NULL;\
(vec)->size = 0;\
(vec)->capacity = 0;\
} while (0)
#define VEC_MOVE(vecl, vecr) do {\
(vecl)->buffer = (vecr)->buffer;\
(vecl)->size = (vecr)->size;\
(vecl)->capacity = (vecr)->capacity;\
(vecr)->buffer = NULL;\
(vecr)->size = 0;\
(vecr)->capacity = 0;\
} while (0)
#define VEC_REINIT(vec) do {\
VALGRIND_ANNOTATE_NEW_MEMORY((vec), sizeof(*vec));\
VALGRIND_ANNOTATE_NEW_MEMORY((vec)->buffer,\
(sizeof(*(vec)->buffer) * ((vec)->capacity)));\
(vec)->size = 0;\
} while (0)
static inline int
vec_reserve(void *vec, size_t ncapacity, size_t s)
{
size_t ncap = ncapacity == 0 ? VEC_INIT_SIZE : ncapacity;
VEC(vvec, void) *vecp = (struct vvec *)vec;
void *tbuf = Realloc(vecp->buffer, s * ncap);
if (tbuf == NULL) {
ERR("!Realloc");
return -1;
}
vecp->buffer = tbuf;
vecp->capacity = ncap;
return 0;
}
#define VEC_RESERVE(vec, ncapacity)\
(((vec)->size == 0 || (ncapacity) > (vec)->size) ?\
vec_reserve((void *)vec, ncapacity, sizeof(*(vec)->buffer)) :\
0)
#define VEC_POP_BACK(vec) do {\
(vec)->size -= 1;\
} while (0)
#define VEC_FRONT(vec)\
(vec)->buffer[0]
#define VEC_BACK(vec)\
(vec)->buffer[(vec)->size - 1]
#define VEC_ERASE_BY_POS(vec, pos) do {\
if ((pos) != ((vec)->size - 1))\
(vec)->buffer[(pos)] = VEC_BACK(vec);\
VEC_POP_BACK(vec);\
} while (0)
#define VEC_ERASE_BY_PTR(vec, element) do {\
if ((element) != &VEC_BACK(vec))\
*(element) = VEC_BACK(vec);\
VEC_POP_BACK(vec);\
} while (0)
#define VEC_INSERT(vec, element)\
((vec)->buffer[(vec)->size - 1] = (element), 0)
#define VEC_INC_SIZE(vec)\
(((vec)->size++), 0)
#define VEC_INC_BACK(vec)\
((vec)->capacity == (vec)->size ?\
(VEC_RESERVE((vec), ((vec)->capacity * 2)) == 0 ?\
VEC_INC_SIZE(vec) : -1) :\
VEC_INC_SIZE(vec))
#define VEC_PUSH_BACK(vec, element)\
(VEC_INC_BACK(vec) == 0? VEC_INSERT(vec, element) : -1)
#define VEC_FOREACH(el, vec)\
for (size_t _vec_i = 0;\
_vec_i < (vec)->size && (((el) = (vec)->buffer[_vec_i]), 1);\
++_vec_i)
#define VEC_FOREACH_REVERSE(el, vec)\
for (size_t _vec_i = ((vec)->size);\
_vec_i != 0 && (((el) = (vec)->buffer[_vec_i - 1]), 1);\
--_vec_i)
#define VEC_FOREACH_BY_POS(elpos, vec)\
for ((elpos) = 0; (elpos) < (vec)->size; ++(elpos))
#define VEC_FOREACH_BY_PTR(el, vec)\
for (size_t _vec_i = 0;\
_vec_i < (vec)->size && (((el) = &(vec)->buffer[_vec_i]), 1);\
++_vec_i)
#define VEC_SIZE(vec)\
((vec)->size)
#define VEC_CAPACITY(vec)\
((vec)->capacity)
#define VEC_ARR(vec)\
((vec)->buffer)
#define VEC_GET(vec, id)\
(&(vec)->buffer[id])
#define VEC_CLEAR(vec) do {\
(vec)->size = 0;\
} while (0)
#define VEC_DELETE(vec) do {\
Free((vec)->buffer);\
(vec)->buffer = NULL;\
(vec)->size = 0;\
(vec)->capacity = 0;\
} while (0)
#ifdef __cplusplus
}
#endif
#endif /* PMDK_VEC_H */
| 4,773
| 24.666667
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/badblock.h
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* badblock.h - common part of bad blocks API
*/
#ifndef PMDK_BADBLOCK_POOLSET_H
#define PMDK_BADBLOCK_POOLSET_H 1
#include "set.h"
#ifdef __cplusplus
extern "C" {
#endif
struct badblocks *badblocks_new(void);
void badblocks_delete(struct badblocks *bbs);
int badblocks_check_poolset(struct pool_set *set, int create);
int badblocks_clear_poolset(struct pool_set *set, int create);
char *badblocks_recovery_file_alloc(const char *file,
unsigned rep, unsigned part);
int badblocks_recovery_file_exists(struct pool_set *set);
#ifdef __cplusplus
}
#endif
#endif /* PMDK_BADBLOCK_POOLSET_H */
| 2,203
| 35.131148
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_auto_flush_linux.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_auto_flush_linux.c -- Linux abstraction layer for auto flush detection
*/
#define _GNU_SOURCE
#include <inttypes.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <string.h>
#include "out.h"
#include "os.h"
#include "fs.h"
#include "os_auto_flush.h"
#define BUS_DEVICE_PATH "/sys/bus/nd/devices"
#define PERSISTENCE_DOMAIN "persistence_domain"
#define DOMAIN_VALUE_LEN 32
/*
* check_cpu_cache -- (internal) check if file contains "cpu_cache" entry
*/
static int
check_cpu_cache(const char *domain_path)
{
LOG(3, "domain_path: %s", domain_path);
char domain_value[DOMAIN_VALUE_LEN];
int domain_fd;
int cpu_cache = 0;
if ((domain_fd = os_open(domain_path, O_RDONLY)) < 0) {
LOG(1, "!open(\"%s\", O_RDONLY)", domain_path);
goto end;
}
ssize_t len = read(domain_fd, domain_value,
DOMAIN_VALUE_LEN);
if (len == -1) {
ERR("!read(%d, %p, %d)", domain_fd,
domain_value, DOMAIN_VALUE_LEN);
cpu_cache = -1;
goto end;
} else if (domain_value[len - 1] != '\n') {
ERR("!read(%d, %p, %d) invalid format",
domain_fd, domain_value,
DOMAIN_VALUE_LEN);
cpu_cache = -1;
goto end;
}
LOG(15, "detected persistent_domain: %s", domain_value);
if (strncmp(domain_value, "cpu_cache", strlen("cpu_cache")) == 0) {
LOG(15, "cpu_cache in persistent_domain: %s", domain_path);
cpu_cache = 1;
} else {
LOG(15, "cpu_cache not in persistent_domain: %s", domain_path);
cpu_cache = 0;
}
end:
if (domain_fd >= 0)
os_close(domain_fd);
return cpu_cache;
}
/*
* check_domain_in_region -- (internal) check if region
* contains persistence_domain file
*/
static int
check_domain_in_region(const char *region_path)
{
LOG(3, "region_path: %s", region_path);
struct fs *reg = NULL;
struct fs_entry *reg_entry;
char domain_path[PATH_MAX];
int cpu_cache = 0;
reg = fs_new(region_path);
if (reg == NULL) {
ERR("!fs_new: \"%s\"", region_path);
cpu_cache = -1;
goto end;
}
while ((reg_entry = fs_read(reg)) != NULL) {
/*
* persistence_domain has to be a file type entry
* and it has to be first level child for region;
* there is no need to run into deeper levels
*/
if (reg_entry->type != FS_ENTRY_FILE ||
strcmp(reg_entry->name,
PERSISTENCE_DOMAIN) != 0 ||
reg_entry->level != 1)
continue;
int ret = snprintf(domain_path, PATH_MAX,
"%s/"PERSISTENCE_DOMAIN,
region_path);
if (ret < 0) {
ERR("snprintf(%p, %d,"
"%s/"PERSISTENCE_DOMAIN", %s): %d",
domain_path, PATH_MAX,
region_path, region_path, ret);
cpu_cache = -1;
goto end;
}
cpu_cache = check_cpu_cache(domain_path);
}
end:
if (reg)
fs_delete(reg);
return cpu_cache;
}
/*
* os_auto_flush -- check if platform supports auto flush for all regions
*
* Traverse "/sys/bus/nd/devices" path to find all the nvdimm regions,
* then for each region checks if "persistence_domain" file exists and
* contains "cpu_cache" string.
* If for any region "persistence_domain" entry does not exists, or its
* context is not as expected, assume eADR is not available on this platform.
*/
int
os_auto_flush(void)
{
LOG(15, NULL);
char *device_path;
int cpu_cache = 0;
device_path = BUS_DEVICE_PATH;
os_stat_t sdev;
if (os_stat(device_path, &sdev) != 0 ||
S_ISDIR(sdev.st_mode) == 0) {
LOG(3, "eADR not supported");
return cpu_cache;
}
struct fs *dev = fs_new(device_path);
if (dev == NULL) {
ERR("!fs_new: \"%s\"", device_path);
return -1;
}
struct fs_entry *dev_entry;
while ((dev_entry = fs_read(dev)) != NULL) {
/*
* Skip if not a symlink, because we expect that
* region on sysfs path is a symlink.
* Skip if depth is different than 1, bacause region
* we are interested in should be the first level
* child for device.
*/
if ((dev_entry->type != FS_ENTRY_SYMLINK) ||
!strstr(dev_entry->name, "region") ||
dev_entry->level != 1)
continue;
LOG(15, "Start traversing region: %s", dev_entry->path);
cpu_cache = check_domain_in_region(dev_entry->path);
if (cpu_cache != 1)
goto end;
}
end:
fs_delete(dev);
return cpu_cache;
}
| 5,669
| 26
| 77
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_auto_flush_windows.h
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PMDK_OS_AUTO_FLUSH_WINDOWS_H
#define PMDK_OS_AUTO_FLUSH_WINDOWS_H 1
#define ACPI_SIGNATURE 0x41435049 /* hex value of ACPI signature */
#define NFIT_REV_SIGNATURE 0x5449464e /* hex value of htonl(NFIT) signature */
#define NFIT_STR_SIGNATURE "NFIT"
#define NFIT_SIGNATURE_LEN 4
#define NFIT_OEM_ID_LEN 6
#define NFIT_OEM_TABLE_ID_LEN 8
#define NFIT_MAX_STRUCTURES 8
#define PCS_RESERVED 3
#define PCS_RESERVED_2 4
#define PCS_TYPE_NUMBER 7
/* check if bit on 'bit' position in number 'num' is set */
#define CHECK_BIT(num, bit) (((num) >> (bit)) & 1)
/*
* sets alignment of members of structure
*/
#pragma pack(1)
struct platform_capabilities
{
uint16_t type;
uint16_t length;
uint8_t highest_valid;
uint8_t reserved[PCS_RESERVED];
uint32_t capabilities;
uint8_t reserved2[PCS_RESERVED_2];
};
struct nfit_header
{
uint8_t signature[NFIT_SIGNATURE_LEN];
uint32_t length;
uint8_t revision;
uint8_t checksum;
uint8_t oem_id[NFIT_OEM_ID_LEN];
uint8_t oem_table_id[NFIT_OEM_TABLE_ID_LEN];
uint32_t oem_revision;
uint8_t creator_id[4];
uint32_t creator_revision;
uint32_t reserved;
};
#pragma pack()
#endif
| 2,730
| 32.716049
| 78
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/file_windows.c
|
/*
* Copyright 2015-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* file_windows.c -- Windows emulation of Linux-specific system calls
*/
/*
* XXX - The initial approach to PMDK for Windows port was to minimize the
* amount of changes required in the core part of the library, and to avoid
* preprocessor conditionals, if possible. For that reason, some of the
* Linux system calls that have no equivalents on Windows have been emulated
* using Windows API.
* Note that it was not a goal to fully emulate POSIX-compliant behavior
* of mentioned functions. They are used only internally, so current
* implementation is just good enough to satisfy PMDK needs and to make it
* work on Windows.
*/
#include <windows.h>
#include <sys/stat.h>
#include <sys/file.h>
#include "file.h"
#include "out.h"
#include "os.h"
/*
* util_tmpfile -- create a temporary file
*/
int
util_tmpfile(const char *dir, const char *templ, int flags)
{
LOG(3, "dir \"%s\" template \"%s\" flags %x", dir, templ, flags);
/* only O_EXCL is allowed here */
ASSERT(flags == 0 || flags == O_EXCL);
int oerrno;
int fd = -1;
size_t len = strlen(dir) + strlen(templ) + 1;
char *fullname = Malloc(sizeof(*fullname) * len);
if (fullname == NULL) {
ERR("!Malloc");
return -1;
}
int ret = _snprintf(fullname, len, "%s%s", dir, templ);
if (ret < 0 || ret >= len) {
ERR("snprintf: %d", ret);
goto err;
}
LOG(4, "fullname \"%s\"", fullname);
/*
* XXX - block signals and modify file creation mask for the time
* of mkstmep() execution. Restore previous settings once the file
* is created.
*/
fd = os_mkstemp(fullname);
if (fd < 0) {
ERR("!os_mkstemp");
goto err;
}
/*
* There is no point to use unlink() here. First, because it does not
* work on open files. Second, because the file is created with
* O_TEMPORARY flag, and it looks like such temp files cannot be open
* from another process, even though they are visible on
* the filesystem.
*/
Free(fullname);
return fd;
err:
Free(fullname);
oerrno = errno;
if (fd != -1)
(void) os_close(fd);
errno = oerrno;
return -1;
}
/*
* util_is_absolute_path -- check if the path is absolute
*/
int
util_is_absolute_path(const char *path)
{
LOG(3, "path \"%s\"", path);
if (path == NULL || path[0] == '\0')
return 0;
if (path[0] == '\\' || path[1] == ':')
return 1;
return 0;
}
/*
* util_file_mkdir -- creates new dir
*/
int
util_file_mkdir(const char *path, mode_t mode)
{
/*
* On windows we cannot create read only dir so mode
* parameter is useless.
*/
UNREFERENCED_PARAMETER(mode);
LOG(3, "path: %s mode: %d", path, mode);
return _mkdir(path);
}
/*
* util_file_dir_open -- open a directory
*/
int
util_file_dir_open(struct dir_handle *handle, const char *path)
{
/* init handle */
handle->handle = NULL;
handle->path = path;
return 0;
}
/*
* util_file_dir_next - read next file in directory
*/
int
util_file_dir_next(struct dir_handle *handle, struct file_info *info)
{
WIN32_FIND_DATAA data;
if (handle->handle == NULL) {
handle->handle = FindFirstFileA(handle->path, &data);
if (handle->handle == NULL)
return 1;
} else {
if (FindNextFileA(handle->handle, &data) == 0)
return 1;
}
info->filename[NAME_MAX] = '\0';
strncpy(info->filename, data.cFileName, NAME_MAX + 1);
if (info->filename[NAME_MAX] != '\0')
return -1; /* filename truncated */
info->is_dir = data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
return 0;
}
/*
* util_file_dir_close -- close a directory
*/
int
util_file_dir_close(struct dir_handle *handle)
{
return FindClose(handle->handle);
}
/*
* util_file_dir_close -- remove directory
*/
int
util_file_dir_remove(const char *path)
{
return RemoveDirectoryA(path) == 0 ? -1 : 0;
}
/*
* util_file_device_dax_alignment -- returns internal Device DAX alignment
*/
size_t
util_file_device_dax_alignment(const char *path)
{
LOG(3, "path \"%s\"", path);
return 0;
}
/*
* util_ddax_region_find -- returns DEV dax region id that contains file
*/
int
util_ddax_region_find(const char *path)
{
LOG(3, "path \"%s\"", path);
return -1;
}
| 5,660
| 24.16
| 76
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_auto_flush.h
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_auto_flush.h -- abstraction layer for auto flush detection functionality
*/
#ifndef PMDK_OS_AUTO_FLUSH_H
#define PMDK_OS_AUTO_FLUSH_H 1
#ifdef __cplusplus
extern "C" {
#endif
int os_auto_flush(void);
#ifdef __cplusplus
}
#endif
#endif
| 1,847
| 35.235294
| 78
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/fs_posix.c
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* fs_posix.c -- file system traversal Posix implementation
*/
#include <fts.h>
#include "util.h"
#include "out.h"
#include "vec.h"
#include "fs.h"
struct fs {
FTS *ft;
struct fs_entry entry;
};
/*
* fs_new -- creates fs traversal instance
*/
struct fs *
fs_new(const char *path)
{
struct fs *f = Zalloc(sizeof(*f));
if (f == NULL)
goto error_fs_alloc;
const char *paths[2] = {path, NULL};
f->ft = fts_open((char * const *)paths, FTS_COMFOLLOW | FTS_XDEV, NULL);
if (f->ft == NULL)
goto error_fts_open;
return f;
error_fts_open:
Free(f);
error_fs_alloc:
return NULL;
}
/*
* fs_read -- reads an entry from the fs path
*/
struct fs_entry *
fs_read(struct fs *f)
{
FTSENT *entry = fts_read(f->ft);
if (entry == NULL)
return NULL;
switch (entry->fts_info) {
case FTS_D:
f->entry.type = FS_ENTRY_DIRECTORY;
break;
case FTS_F:
f->entry.type = FS_ENTRY_FILE;
break;
case FTS_SL:
f->entry.type = FS_ENTRY_SYMLINK;
break;
default:
f->entry.type = FS_ENTRY_OTHER;
break;
}
f->entry.name = entry->fts_name;
f->entry.namelen = entry->fts_namelen;
f->entry.path = entry->fts_path;
f->entry.pathlen = entry->fts_pathlen;
f->entry.level = entry->fts_level;
return &f->entry;
}
/*
* fs_delete -- deletes a fs traversal instance
*/
void
fs_delete(struct fs *f)
{
fts_close(f->ft);
Free(f);
}
| 2,946
| 24.850877
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/errno_freebsd.h
|
/*
* Copyright 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* errno_freebsd.h -- map Linux errno's to something close on FreeBSD
*/
#ifndef PMDK_ERRNO_FREEBSD_H
#define PMDK_ERRNO_FREEBSD_H 1
#ifdef __FreeBSD__
#define EBADFD EBADF
#define ELIBACC EINVAL
#define EMEDIUMTYPE EOPNOTSUPP
#define ENOMEDIUM ENODEV
#define EREMOTEIO EIO
#endif
#endif /* PMDK_ERRNO_FREEBSD_H */
| 1,919
| 38.183673
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/mmap.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mmap.c -- mmap utilities
*/
#include <errno.h>
#include <inttypes.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include "file.h"
#include "queue.h"
#include "mmap.h"
#include "sys_util.h"
#include "os.h"
int Mmap_no_random;
void *Mmap_hint;
static os_rwlock_t Mmap_list_lock;
static SORTEDQ_HEAD(map_list_head, map_tracker) Mmap_list =
SORTEDQ_HEAD_INITIALIZER(Mmap_list);
/*
* util_mmap_init -- initialize the mmap utils
*
* This is called from the library initialization code.
*/
void
util_mmap_init(void)
{
LOG(3, NULL);
util_rwlock_init(&Mmap_list_lock);
/*
* For testing, allow overriding the default mmap() hint address.
* If hint address is defined, it also disables address randomization.
*/
char *e = os_getenv("PMEM_MMAP_HINT");
if (e) {
char *endp;
errno = 0;
unsigned long long val = strtoull(e, &endp, 16);
if (errno || endp == e) {
LOG(2, "Invalid PMEM_MMAP_HINT");
} else if (os_access(OS_MAPFILE, R_OK)) {
LOG(2, "No /proc, PMEM_MMAP_HINT ignored");
} else {
Mmap_hint = (void *)val;
Mmap_no_random = 1;
LOG(3, "PMEM_MMAP_HINT set to %p", Mmap_hint);
}
}
}
/*
* util_mmap_fini -- clean up the mmap utils
*
* This is called before process stop.
*/
void
util_mmap_fini(void)
{
LOG(3, NULL);
util_rwlock_destroy(&Mmap_list_lock);
}
/*
* util_map -- memory map a file
*
* This is just a convenience function that calls mmap() with the
* appropriate arguments and includes our trace points.
*/
void *
util_map(int fd, size_t len, int flags, int rdonly, size_t req_align,
int *map_sync)
{
LOG(3, "fd %d len %zu flags %d rdonly %d req_align %zu map_sync %p",
fd, len, flags, rdonly, req_align, map_sync);
void *base;
void *addr = util_map_hint(len, req_align);
if (addr == MAP_FAILED) {
ERR("cannot find a contiguous region of given size");
return NULL;
}
if (req_align)
ASSERTeq((uintptr_t)addr % req_align, 0);
int proto = rdonly ? PROT_READ : PROT_READ|PROT_WRITE;
base = util_map_sync(addr, len, proto, flags, fd, 0, map_sync);
if (base == MAP_FAILED) {
ERR("!mmap %zu bytes", len);
return NULL;
}
LOG(3, "mapped at %p", base);
return base;
}
/*
* util_unmap -- unmap a file
*
* This is just a convenience function that calls munmap() with the
* appropriate arguments and includes our trace points.
*/
int
util_unmap(void *addr, size_t len)
{
LOG(3, "addr %p len %zu", addr, len);
/*
* XXX Workaround for https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=169608
*/
#ifdef __FreeBSD__
if (!IS_PAGE_ALIGNED((uintptr_t)addr)) {
errno = EINVAL;
ERR("!munmap");
return -1;
}
#endif
int retval = munmap(addr, len);
if (retval < 0)
ERR("!munmap");
return retval;
}
/*
* util_map_tmpfile -- reserve space in an unlinked file and memory-map it
*
* size must be multiple of page size.
*/
void *
util_map_tmpfile(const char *dir, size_t size, size_t req_align)
{
int oerrno;
if (((os_off_t)size) < 0) {
ERR("invalid size (%zu) for os_off_t", size);
errno = EFBIG;
return NULL;
}
int fd = util_tmpfile(dir, OS_DIR_SEP_STR "vmem.XXXXXX", O_EXCL);
if (fd == -1) {
LOG(2, "cannot create temporary file in dir %s", dir);
goto err;
}
if ((errno = os_posix_fallocate(fd, 0, (os_off_t)size)) != 0) {
ERR("!posix_fallocate");
goto err;
}
void *base;
if ((base = util_map(fd, size, MAP_SHARED,
0, req_align, NULL)) == NULL) {
LOG(2, "cannot mmap temporary file");
goto err;
}
(void) os_close(fd);
return base;
err:
oerrno = errno;
if (fd != -1)
(void) os_close(fd);
errno = oerrno;
return NULL;
}
/*
* util_range_ro -- set a memory range read-only
*/
int
util_range_ro(void *addr, size_t len)
{
LOG(3, "addr %p len %zu", addr, len);
uintptr_t uptr;
int retval;
/*
* mprotect requires addr to be a multiple of pagesize, so
* adjust addr and len to represent the full 4k chunks
* covering the given range.
*/
/* increase len by the amount we gain when we round addr down */
len += (uintptr_t)addr & (Pagesize - 1);
/* round addr down to page boundary */
uptr = (uintptr_t)addr & ~(Pagesize - 1);
if ((retval = mprotect((void *)uptr, len, PROT_READ)) < 0)
ERR("!mprotect: PROT_READ");
return retval;
}
/*
* util_range_rw -- set a memory range read-write
*/
int
util_range_rw(void *addr, size_t len)
{
LOG(3, "addr %p len %zu", addr, len);
uintptr_t uptr;
int retval;
/*
* mprotect requires addr to be a multiple of pagesize, so
* adjust addr and len to represent the full 4k chunks
* covering the given range.
*/
/* increase len by the amount we gain when we round addr down */
len += (uintptr_t)addr & (Pagesize - 1);
/* round addr down to page boundary */
uptr = (uintptr_t)addr & ~(Pagesize - 1);
if ((retval = mprotect((void *)uptr, len, PROT_READ|PROT_WRITE)) < 0)
ERR("!mprotect: PROT_READ|PROT_WRITE");
return retval;
}
/*
* util_range_none -- set a memory range for no access allowed
*/
int
util_range_none(void *addr, size_t len)
{
LOG(3, "addr %p len %zu", addr, len);
uintptr_t uptr;
int retval;
/*
* mprotect requires addr to be a multiple of pagesize, so
* adjust addr and len to represent the full 4k chunks
* covering the given range.
*/
/* increase len by the amount we gain when we round addr down */
len += (uintptr_t)addr & (Pagesize - 1);
/* round addr down to page boundary */
uptr = (uintptr_t)addr & ~(Pagesize - 1);
if ((retval = mprotect((void *)uptr, len, PROT_NONE)) < 0)
ERR("!mprotect: PROT_NONE");
return retval;
}
/*
* util_range_comparer -- (internal) compares the two mapping trackers
*/
static intptr_t
util_range_comparer(struct map_tracker *a, struct map_tracker *b)
{
return ((intptr_t)a->base_addr - (intptr_t)b->base_addr);
}
/*
* util_range_find_unlocked -- (internal) find the map tracker
* for given address range
*
* Returns the first entry at least partially overlapping given range.
* It's up to the caller to check whether the entry exactly matches the range,
* or if the range spans multiple entries.
*/
static struct map_tracker *
util_range_find_unlocked(uintptr_t addr, size_t len)
{
LOG(10, "addr 0x%016" PRIxPTR " len %zu", addr, len);
uintptr_t end = addr + len;
struct map_tracker *mt;
SORTEDQ_FOREACH(mt, &Mmap_list, entry) {
if (addr < mt->end_addr &&
(addr >= mt->base_addr || end > mt->base_addr))
goto out;
/* break if there is no chance to find matching entry */
if (addr < mt->base_addr)
break;
}
mt = NULL;
out:
return mt;
}
/*
* util_range_find -- find the map tracker for given address range
* the same as util_range_find_unlocked but locked
*/
struct map_tracker *
util_range_find(uintptr_t addr, size_t len)
{
LOG(10, "addr 0x%016" PRIxPTR " len %zu", addr, len);
util_rwlock_rdlock(&Mmap_list_lock);
struct map_tracker *mt = util_range_find_unlocked(addr, len);
util_rwlock_unlock(&Mmap_list_lock);
return mt;
}
/*
* util_range_register -- add a memory range into a map tracking list
*/
int
util_range_register(const void *addr, size_t len, const char *path,
enum pmem_map_type type)
{
LOG(3, "addr %p len %zu path %s type %d", addr, len, path, type);
/* check if not tracked already */
if (util_range_find((uintptr_t)addr, len) != NULL) {
ERR(
"duplicated persistent memory range; presumably unmapped with munmap() instead of pmem_unmap(): addr %p len %zu",
addr, len);
errno = ENOMEM;
return -1;
}
struct map_tracker *mt;
mt = Malloc(sizeof(struct map_tracker));
if (mt == NULL) {
ERR("!Malloc");
return -1;
}
mt->base_addr = (uintptr_t)addr;
mt->end_addr = mt->base_addr + len;
mt->type = type;
if (type == PMEM_DEV_DAX)
mt->region_id = util_ddax_region_find(path);
util_rwlock_wrlock(&Mmap_list_lock);
SORTEDQ_INSERT(&Mmap_list, mt, entry, struct map_tracker,
util_range_comparer);
util_rwlock_unlock(&Mmap_list_lock);
return 0;
}
/*
* util_range_split -- (internal) remove or split a map tracking entry
*/
static int
util_range_split(struct map_tracker *mt, const void *addrp, const void *endp)
{
LOG(3, "begin %p end %p", addrp, endp);
uintptr_t addr = (uintptr_t)addrp;
uintptr_t end = (uintptr_t)endp;
ASSERTne(mt, NULL);
if (addr == end || addr % Mmap_align != 0 || end % Mmap_align != 0) {
ERR(
"invalid munmap length, must be non-zero and page aligned");
return -1;
}
struct map_tracker *mtb = NULL;
struct map_tracker *mte = NULL;
/*
* 1) b e b e
* xxxxxxxxxxxxx => xxx.......xxxx - mtb+mte
* 2) b e b e
* xxxxxxxxxxxxx => xxxxxxx....... - mtb
* 3) b e b e
* xxxxxxxxxxxxx => ........xxxxxx - mte
* 4) b e b e
* xxxxxxxxxxxxx => .............. - <none>
*/
if (addr > mt->base_addr) {
/* case #1/2 */
/* new mapping at the beginning */
mtb = Malloc(sizeof(struct map_tracker));
if (mtb == NULL) {
ERR("!Malloc");
goto err;
}
mtb->base_addr = mt->base_addr;
mtb->end_addr = addr;
mtb->region_id = mt->region_id;
mtb->type = mt->type;
}
if (end < mt->end_addr) {
/* case #1/3 */
/* new mapping at the end */
mte = Malloc(sizeof(struct map_tracker));
if (mte == NULL) {
ERR("!Malloc");
goto err;
}
mte->base_addr = end;
mte->end_addr = mt->end_addr;
mte->region_id = mt->region_id;
mte->type = mt->type;
}
SORTEDQ_REMOVE(&Mmap_list, mt, entry);
if (mtb) {
SORTEDQ_INSERT(&Mmap_list, mtb, entry,
struct map_tracker, util_range_comparer);
}
if (mte) {
SORTEDQ_INSERT(&Mmap_list, mte, entry,
struct map_tracker, util_range_comparer);
}
/* free entry for the original mapping */
Free(mt);
return 0;
err:
Free(mtb);
Free(mte);
return -1;
}
/*
* util_range_unregister -- remove a memory range
* from map tracking list
*
* Remove the region between [begin,end]. If it's in a middle of the existing
* mapping, it results in two new map trackers.
*/
int
util_range_unregister(const void *addr, size_t len)
{
LOG(3, "addr %p len %zu", addr, len);
int ret = 0;
util_rwlock_wrlock(&Mmap_list_lock);
/*
* Changes in the map tracker list must match the underlying behavior.
*
* $ man 2 mmap:
* The address addr must be a multiple of the page size (but length
* need not be). All pages containing a part of the indicated range
* are unmapped.
*
* This means that we must align the length to the page size.
*/
len = PAGE_ALIGNED_UP_SIZE(len);
void *end = (char *)addr + len;
/* XXX optimize the loop */
struct map_tracker *mt;
while ((mt = util_range_find_unlocked((uintptr_t)addr, len)) != NULL) {
if (util_range_split(mt, addr, end) != 0) {
ret = -1;
break;
}
}
util_rwlock_unlock(&Mmap_list_lock);
return ret;
}
/*
* util_range_is_pmem -- return true if entire range
* is persistent memory
*/
int
util_range_is_pmem(const void *addrp, size_t len)
{
LOG(10, "addr %p len %zu", addrp, len);
uintptr_t addr = (uintptr_t)addrp;
int retval = 1;
util_rwlock_rdlock(&Mmap_list_lock);
do {
struct map_tracker *mt = util_range_find(addr, len);
if (mt == NULL) {
LOG(4, "address not found 0x%016" PRIxPTR, addr);
retval = 0;
break;
}
LOG(10, "range found - begin 0x%016" PRIxPTR
" end 0x%016" PRIxPTR,
mt->base_addr, mt->end_addr);
if (mt->base_addr > addr) {
LOG(10, "base address doesn't match: "
"0x%" PRIxPTR " > 0x%" PRIxPTR,
mt->base_addr, addr);
retval = 0;
break;
}
uintptr_t map_len = mt->end_addr - addr;
if (map_len > len)
map_len = len;
len -= map_len;
addr += map_len;
} while (len > 0);
util_rwlock_unlock(&Mmap_list_lock);
return retval;
}
| 13,289
| 22.315789
| 115
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_thread.h
|
/*
* Copyright 2015-2018, Intel Corporation
* Copyright (c) 2016, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_thread.h -- os thread abstraction layer
*/
#ifndef OS_THREAD_H
#define OS_THREAD_H 1
#include <stdint.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef union {
long long align;
char padding[44]; /* linux: 40 windows: 44 */
} os_mutex_t;
typedef union {
long long align;
char padding[56]; /* linux: 56 windows: 13 */
} os_rwlock_t;
typedef union {
long long align;
char padding[48]; /* linux: 48 windows: 12 */
} os_cond_t;
typedef union {
long long align;
char padding[32]; /* linux: 8 windows: 32 */
} os_thread_t;
typedef union {
long long align; /* linux: long windows: 8 FreeBSD: 12 */
char padding[16]; /* 16 to be safe */
} os_once_t;
#define OS_ONCE_INIT { .padding = {0} }
typedef unsigned os_tls_key_t;
typedef union {
long long align;
char padding[56]; /* linux: 56 windows: 8 */
} os_semaphore_t;
typedef union {
long long align;
char padding[56]; /* linux: 56 windows: 8 */
} os_thread_attr_t;
typedef union {
long long align;
char padding[512];
} os_cpu_set_t;
#ifdef __FreeBSD__
#define cpu_set_t cpuset_t
typedef uintptr_t os_spinlock_t;
#else
typedef volatile int os_spinlock_t; /* XXX: not implemented on windows */
#endif
void os_cpu_zero(os_cpu_set_t *set);
void os_cpu_set(size_t cpu, os_cpu_set_t *set);
#ifndef _WIN32
#define _When_(...)
#endif
int os_once(os_once_t *o, void (*func)(void));
int os_tls_key_create(os_tls_key_t *key, void (*destructor)(void *));
int os_tls_key_delete(os_tls_key_t key);
int os_tls_set(os_tls_key_t key, const void *value);
void *os_tls_get(os_tls_key_t key);
int os_mutex_init(os_mutex_t *__restrict mutex);
int os_mutex_destroy(os_mutex_t *__restrict mutex);
_When_(return == 0, _Acquires_lock_(mutex->lock))
int os_mutex_lock(os_mutex_t *__restrict mutex);
_When_(return == 0, _Acquires_lock_(mutex->lock))
int os_mutex_trylock(os_mutex_t *__restrict mutex);
int os_mutex_unlock(os_mutex_t *__restrict mutex);
/* XXX - non POSIX */
int os_mutex_timedlock(os_mutex_t *__restrict mutex,
const struct timespec *abstime);
int os_rwlock_init(os_rwlock_t *__restrict rwlock);
int os_rwlock_destroy(os_rwlock_t *__restrict rwlock);
int os_rwlock_rdlock(os_rwlock_t *__restrict rwlock);
int os_rwlock_wrlock(os_rwlock_t *__restrict rwlock);
int os_rwlock_tryrdlock(os_rwlock_t *__restrict rwlock);
_When_(return == 0, _Acquires_exclusive_lock_(rwlock->lock))
int os_rwlock_trywrlock(os_rwlock_t *__restrict rwlock);
_When_(rwlock->is_write != 0, _Requires_exclusive_lock_held_(rwlock->lock))
_When_(rwlock->is_write == 0, _Requires_shared_lock_held_(rwlock->lock))
int os_rwlock_unlock(os_rwlock_t *__restrict rwlock);
int os_rwlock_timedrdlock(os_rwlock_t *__restrict rwlock,
const struct timespec *abstime);
int os_rwlock_timedwrlock(os_rwlock_t *__restrict rwlock,
const struct timespec *abstime);
int os_spin_init(os_spinlock_t *lock, int pshared);
int os_spin_destroy(os_spinlock_t *lock);
int os_spin_lock(os_spinlock_t *lock);
int os_spin_unlock(os_spinlock_t *lock);
int os_spin_trylock(os_spinlock_t *lock);
int os_cond_init(os_cond_t *__restrict cond);
int os_cond_destroy(os_cond_t *__restrict cond);
int os_cond_broadcast(os_cond_t *__restrict cond);
int os_cond_signal(os_cond_t *__restrict cond);
int os_cond_timedwait(os_cond_t *__restrict cond,
os_mutex_t *__restrict mutex, const struct timespec *abstime);
int os_cond_wait(os_cond_t *__restrict cond,
os_mutex_t *__restrict mutex);
/* threading */
int os_thread_create(os_thread_t *thread, const os_thread_attr_t *attr,
void *(*start_routine)(void *), void *arg);
int os_thread_join(os_thread_t *thread, void **result);
void os_thread_self(os_thread_t *thread);
/* thread affinity */
int os_thread_setaffinity_np(os_thread_t *thread, size_t set_size,
const os_cpu_set_t *set);
int os_thread_atfork(void (*prepare)(void), void (*parent)(void),
void (*child)(void));
int os_semaphore_init(os_semaphore_t *sem, unsigned value);
int os_semaphore_destroy(os_semaphore_t *sem);
int os_semaphore_wait(os_semaphore_t *sem);
int os_semaphore_trywait(os_semaphore_t *sem);
int os_semaphore_post(os_semaphore_t *sem);
#ifdef __cplusplus
}
#endif
#endif /* OS_THREAD_H */
| 5,833
| 31.054945
| 75
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/uuid_linux.c
|
/*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* uuid_linux.c -- pool set utilities with OS-specific implementation
*/
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include "uuid.h"
#include "os.h"
#include "out.h"
/*
* util_uuid_generate -- generate a uuid
*
* This function reads the uuid string from /proc/sys/kernel/random/uuid
* It converts this string into the binary uuid format as specified in
* https://www.ietf.org/rfc/rfc4122.txt
*/
int
util_uuid_generate(uuid_t uuid)
{
char uu[POOL_HDR_UUID_STR_LEN];
int fd = os_open(POOL_HDR_UUID_GEN_FILE, O_RDONLY);
if (fd < 0) {
/* Fatal error */
LOG(2, "!open(uuid)");
return -1;
}
ssize_t num = read(fd, uu, POOL_HDR_UUID_STR_LEN);
if (num < POOL_HDR_UUID_STR_LEN) {
/* Fatal error */
LOG(2, "!read(uuid)");
os_close(fd);
return -1;
}
os_close(fd);
uu[POOL_HDR_UUID_STR_LEN - 1] = '\0';
int ret = util_uuid_from_string(uu, (struct uuid *)uuid);
if (ret < 0)
return ret;
return 0;
}
| 2,550
| 31.291139
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_badblock.h
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_badblock.h -- linux bad block API
*/
#ifndef PMDK_BADBLOCK_H
#define PMDK_BADBLOCK_H 1
#include <stdint.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#define B2SEC(n) ((n) >> 9) /* convert bytes to sectors */
#define SEC2B(n) ((n) << 9) /* convert sectors to bytes */
#define NO_HEALTHY_REPLICA ((int)(-1))
/*
* 'struct badblock' is already defined in ndctl/libndctl.h,
* so we cannot use this name.
*
* libndctl returns offset relative to the beginning of the region,
* but in this structure we save offset relative to the beginning of:
* - namespace (before os_badblocks_get())
* and
* - file (before sync_recalc_badblocks())
* and
* - pool (after sync_recalc_badblocks())
*/
struct bad_block {
/*
* offset in bytes relative to the beginning of
* - namespace (before os_badblocks_get())
* and
* - file (before sync_recalc_badblocks())
* and
* - pool (after sync_recalc_badblocks())
*/
unsigned long long offset;
/* length in bytes */
unsigned length;
/* number of healthy replica to fix this bad block */
int nhealthy;
};
struct badblocks {
unsigned long long ns_resource; /* address of the namespace */
unsigned bb_cnt; /* number of bad blocks */
struct bad_block *bbv; /* array of bad blocks */
};
long os_badblocks_count(const char *path);
int os_badblocks_get(const char *file, struct badblocks *bbs);
int os_badblocks_clear(const char *path, struct badblocks *bbs);
int os_badblocks_clear_all(const char *file);
int os_badblocks_check_file(const char *path);
#ifdef __cplusplus
}
#endif
#endif /* PMDK_BADBLOCK_H */
| 3,200
| 31.333333
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/extent.h
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* extent.h -- fs extent query API
*/
#ifndef PMDK_EXTENT_H
#define PMDK_EXTENT_H 1
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
struct extent {
uint64_t offset_physical;
uint64_t offset_logical;
uint64_t length;
};
struct extents {
uint64_t blksize;
uint32_t extents_count;
struct extent *extents;
};
long os_extents_count(const char *path, struct extents *exts);
int os_extents_get(const char *path, struct extents *exts);
#ifdef __cplusplus
}
#endif
#endif /* PMDK_EXTENT_H */
| 2,129
| 30.791045
| 74
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/out.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* out.h -- definitions for "out" module
*/
#ifndef PMDK_OUT_H
#define PMDK_OUT_H 1
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include "util.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Suppress errors which are after appropriate ASSERT* macro for nondebug
* builds.
*/
#if !defined(DEBUG) && (defined(__clang_analyzer__) || defined(__COVERITY__))
#define OUT_FATAL_DISCARD_NORETURN __attribute__((noreturn))
#else
#define OUT_FATAL_DISCARD_NORETURN
#endif
#ifndef EVALUATE_DBG_EXPRESSIONS
#if defined(DEBUG) || defined(__clang_analyzer__) || defined(__COVERITY__)
#define EVALUATE_DBG_EXPRESSIONS 1
#else
#define EVALUATE_DBG_EXPRESSIONS 0
#endif
#endif
#ifdef DEBUG
#define OUT_LOG out_log
#define OUT_NONL out_nonl
#define OUT_FATAL out_fatal
#define OUT_FATAL_ABORT out_fatal
#else
static __attribute__((always_inline)) inline void
out_log_discard(const char *file, int line, const char *func, int level,
const char *fmt, ...)
{
(void) file;
(void) line;
(void) func;
(void) level;
(void) fmt;
}
static __attribute__((always_inline)) inline void
out_nonl_discard(int level, const char *fmt, ...)
{
(void) level;
(void) fmt;
}
static __attribute__((always_inline)) OUT_FATAL_DISCARD_NORETURN inline void
out_fatal_discard(const char *file, int line, const char *func,
const char *fmt, ...)
{
(void) file;
(void) line;
(void) func;
(void) fmt;
}
static __attribute__((always_inline)) NORETURN inline void
out_fatal_abort(const char *file, int line, const char *func,
const char *fmt, ...)
{
(void) file;
(void) line;
(void) func;
(void) fmt;
abort();
}
#define OUT_LOG out_log_discard
#define OUT_NONL out_nonl_discard
#define OUT_FATAL out_fatal_discard
#define OUT_FATAL_ABORT out_fatal_abort
#endif
/* produce debug/trace output */
#define LOG(level, ...) do { \
if (!EVALUATE_DBG_EXPRESSIONS) break;\
OUT_LOG(__FILE__, __LINE__, __func__, level, __VA_ARGS__);\
} while (0)
/* produce debug/trace output without prefix and new line */
#define LOG_NONL(level, ...) do { \
if (!EVALUATE_DBG_EXPRESSIONS) break; \
OUT_NONL(level, __VA_ARGS__); \
} while (0)
/* produce output and exit */
#define FATAL(...)\
OUT_FATAL_ABORT(__FILE__, __LINE__, __func__, __VA_ARGS__)
/* assert a condition is true at runtime */
#define ASSERT_rt(cnd) do { \
if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \
OUT_FATAL(__FILE__, __LINE__, __func__, "assertion failure: %s", #cnd);\
} while (0)
/* assertion with extra info printed if assertion fails at runtime */
#define ASSERTinfo_rt(cnd, info) do { \
if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \
OUT_FATAL(__FILE__, __LINE__, __func__, \
"assertion failure: %s (%s = %s)", #cnd, #info, info);\
} while (0)
/* assert two integer values are equal at runtime */
#define ASSERTeq_rt(lhs, rhs) do { \
if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) == (rhs))) break; \
OUT_FATAL(__FILE__, __LINE__, __func__,\
"assertion failure: %s (0x%llx) == %s (0x%llx)", #lhs,\
(unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \
} while (0)
/* assert two integer values are not equal at runtime */
#define ASSERTne_rt(lhs, rhs) do { \
if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) != (rhs))) break; \
OUT_FATAL(__FILE__, __LINE__, __func__,\
"assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\
(unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \
} while (0)
/* assert a condition is true */
#define ASSERT(cnd)\
do {\
/*\
* Detect useless asserts on always true expression. Please use\
* COMPILE_ERROR_ON(!cnd) or ASSERT_rt(cnd) in such cases.\
*/\
if (__builtin_constant_p(cnd))\
ASSERT_COMPILE_ERROR_ON(cnd);\
ASSERT_rt(cnd);\
} while (0)
/* assertion with extra info printed if assertion fails */
#define ASSERTinfo(cnd, info)\
do {\
/* See comment in ASSERT. */\
if (__builtin_constant_p(cnd))\
ASSERT_COMPILE_ERROR_ON(cnd);\
ASSERTinfo_rt(cnd, info);\
} while (0)
/* assert two integer values are equal */
#define ASSERTeq(lhs, rhs)\
do {\
/* See comment in ASSERT. */\
if (__builtin_constant_p(lhs) && __builtin_constant_p(rhs))\
ASSERT_COMPILE_ERROR_ON((lhs) == (rhs));\
ASSERTeq_rt(lhs, rhs);\
} while (0)
/* assert two integer values are not equal */
#define ASSERTne(lhs, rhs)\
do {\
/* See comment in ASSERT. */\
if (__builtin_constant_p(lhs) && __builtin_constant_p(rhs))\
ASSERT_COMPILE_ERROR_ON((lhs) != (rhs));\
ASSERTne_rt(lhs, rhs);\
} while (0)
#define ERR(...)\
out_err(__FILE__, __LINE__, __func__, __VA_ARGS__)
void out_init(const char *log_prefix, const char *log_level_var,
const char *log_file_var, int major_version,
int minor_version);
void out_fini(void);
void out(const char *fmt, ...) FORMAT_PRINTF(1, 2);
void out_nonl(int level, const char *fmt, ...) FORMAT_PRINTF(2, 3);
void out_log(const char *file, int line, const char *func, int level,
const char *fmt, ...) FORMAT_PRINTF(5, 6);
void out_err(const char *file, int line, const char *func,
const char *fmt, ...) FORMAT_PRINTF(4, 5);
void NORETURN out_fatal(const char *file, int line, const char *func,
const char *fmt, ...) FORMAT_PRINTF(4, 5);
void out_set_print_func(void (*print_func)(const char *s));
void out_set_vsnprintf_func(int (*vsnprintf_func)(char *str, size_t size,
const char *format, va_list ap));
#ifdef _WIN32
#ifndef PMDK_UTF8_API
#define out_get_errormsg out_get_errormsgW
#else
#define out_get_errormsg out_get_errormsgU
#endif
#endif
#ifndef _WIN32
const char *out_get_errormsg(void);
#else
const char *out_get_errormsgU(void);
const wchar_t *out_get_errormsgW(void);
#endif
#ifdef __cplusplus
}
#endif
#endif
| 7,218
| 28.226721
| 77
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/util_windows.c
|
/*
* Copyright 2015-2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* util_windows.c -- misc utilities with OS-specific implementation
*/
#include <string.h>
#include <tchar.h>
#include <errno.h>
#include "util.h"
#include "out.h"
#include "file.h"
/* Windows CRT doesn't support all errors, add unmapped here */
#define ENOTSUP_STR "Operation not supported"
#define ECANCELED_STR "Operation canceled"
#define ENOERROR 0
#define ENOERROR_STR "Success"
#define UNMAPPED_STR "Unmapped error"
/*
* util_strerror -- return string describing error number
*
* XXX: There are many other POSIX error codes that are not recognized by
* strerror_s(), so eventually we may want to implement this in a similar
* fashion as strsignal().
*/
void
util_strerror(int errnum, char *buff, size_t bufflen)
{
switch (errnum) {
case ENOERROR:
strcpy_s(buff, bufflen, ENOERROR_STR);
break;
case ENOTSUP:
strcpy_s(buff, bufflen, ENOTSUP_STR);
break;
case ECANCELED:
strcpy_s(buff, bufflen, ECANCELED_STR);
break;
default:
if (strerror_s(buff, bufflen, errnum))
strcpy_s(buff, bufflen, UNMAPPED_STR);
}
}
/*
* util_part_realpath -- get canonicalized absolute pathname for a part file
*
* On Windows, paths cannot be symlinks and paths used in a poolset have to
* be absolute (checked when parsing a poolset file), so we just return
* the path.
*/
char *
util_part_realpath(const char *path)
{
return strdup(path);
}
/*
* util_compare_file_inodes -- compare device and inodes of two files
*/
int
util_compare_file_inodes(const char *path1, const char *path2)
{
return strcmp(path1, path2) != 0;
}
/*
* util_aligned_malloc -- allocate aligned memory
*/
void *
util_aligned_malloc(size_t alignment, size_t size)
{
return _aligned_malloc(size, alignment);
}
/*
* util_aligned_free -- free allocated memory in util_aligned_malloc
*/
void
util_aligned_free(void *ptr)
{
_aligned_free(ptr);
}
/*
* util_toUTF8 -- allocating conversion from wide char string to UTF8
*/
char *
util_toUTF8(const wchar_t *wstr)
{
int size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wstr, -1,
NULL, 0, NULL, NULL);
if (size == 0)
goto err;
char *str = Malloc(size * sizeof(char));
if (str == NULL)
goto out;
if (WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wstr, -1, str,
size, NULL, NULL) == 0) {
Free(str);
goto err;
}
out:
return str;
err:
errno = EINVAL;
return NULL;
}
/*
* util_free_UTF8 -- free UTF8 string
*/
void util_free_UTF8(char *str) {
Free(str);
}
/*
* util_toUTF16 -- allocating conversion from UTF8 to wide char string
*/
wchar_t *
util_toUTF16(const char *str)
{
int size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str, -1,
NULL, 0);
if (size == 0)
goto err;
wchar_t *wstr = Malloc(size * sizeof(wchar_t));
if (wstr == NULL)
goto out;
if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str, -1, wstr,
size) == 0) {
Free(wstr);
goto err;
}
out:
return wstr;
err:
errno = EINVAL;
return NULL;
}
/*
* util_free_UTF16 -- free wide char string
*/
void
util_free_UTF16(wchar_t *wstr)
{
Free(wstr);
}
/*
* util_toUTF16_buff -- non-allocating conversion from UTF8 to wide char string
*
* The user responsible for supplying a large enough out buffer.
*/
int
util_toUTF16_buff(const char *in, wchar_t *out, size_t out_size)
{
ASSERT(out != NULL);
int size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, in,
-1, NULL, 0);
if (size == 0 || out_size < size)
goto err;
if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, in, -1,
out, size) == 0)
goto err;
return 0;
err:
errno = EINVAL;
return -1;
}
/*
* util_toUTF8_buff -- non-allocating conversion from wide char string to UTF8
*
* The user responsible for supplying a large enough out buffer.
*/
int
util_toUTF8_buff(const wchar_t *in, char *out, size_t out_size)
{
ASSERT(out != NULL);
int size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, in, -1,
NULL, 0, NULL, NULL);
if (size == 0 || out_size < size)
goto err;
if (WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, in, -1,
out, size, NULL, NULL) == 0)
goto err;
return 0;
err:
errno = EINVAL;
return -1;
}
/*
* util_getexecname -- return name of current executable
*/
char *
util_getexecname(char *path, size_t pathlen)
{
ssize_t cc;
if ((cc = GetModuleFileNameA(NULL, path, (DWORD)pathlen)) == 0)
strcpy(path, "unknown");
else
path[cc] = '\0';
return path;
}
| 5,980
| 22.454902
| 79
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/extent_freebsd.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* extent_freebsd.c - implementation of the FreeBSD fs extent query API
* XXX THIS IS CURRENTLY A DUMMY MODULE.
*/
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "file.h"
#include "out.h"
#include "extent.h"
/*
* os_extents_count -- get number of extents of the given file
* (and optionally read its block size)
*/
long
os_extents_count(const char *path, struct extents *exts)
{
LOG(3, "path %s extents %p", path, exts);
return -1;
}
/*
* os_extents_get -- get extents of the given file
* (and optionally read its block size)
*/
int
os_extents_get(const char *path, struct extents *exts)
{
LOG(3, "path %s extents %p", path, exts);
return -1;
}
| 2,325
| 32.710145
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/mmap_posix.c
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mmap_posix.c -- memory-mapped files for Posix
*/
#include <stdio.h>
#include <sys/mman.h>
#include <sys/param.h>
#include "mmap.h"
#include "out.h"
#include "os.h"
#define PROCMAXLEN 2048 /* maximum expected line length in /proc files */
char *Mmap_mapfile = OS_MAPFILE; /* Should be modified only for testing */
#ifdef __FreeBSD__
static const char * const sscanf_os = "%p %p";
#else
static const char * const sscanf_os = "%p-%p";
#endif
/*
* util_map_hint_unused -- use /proc to determine a hint address for mmap()
*
* This is a helper function for util_map_hint().
* It opens up /proc/self/maps and looks for the first unused address
* in the process address space that is:
* - greater or equal 'minaddr' argument,
* - large enough to hold range of given length,
* - aligned to the specified unit.
*
* Asking for aligned address like this will allow the DAX code to use large
* mappings. It is not an error if mmap() ignores the hint and chooses
* different address.
*/
char *
util_map_hint_unused(void *minaddr, size_t len, size_t align)
{
LOG(3, "minaddr %p len %zu align %zu", minaddr, len, align);
ASSERT(align > 0);
FILE *fp;
if ((fp = os_fopen(Mmap_mapfile, "r")) == NULL) {
ERR("!%s", Mmap_mapfile);
return MAP_FAILED;
}
char line[PROCMAXLEN]; /* for fgets() */
char *lo = NULL; /* beginning of current range in maps file */
char *hi = NULL; /* end of current range in maps file */
char *raddr = minaddr; /* ignore regions below 'minaddr' */
if (raddr == NULL)
raddr += Pagesize;
raddr = (char *)roundup((uintptr_t)raddr, align);
while (fgets(line, PROCMAXLEN, fp) != NULL) {
/* check for range line */
if (sscanf(line, sscanf_os, &lo, &hi) == 2) {
LOG(4, "%p-%p", lo, hi);
if (lo > raddr) {
if ((uintptr_t)(lo - raddr) >= len) {
LOG(4, "unused region of size %zu "
"found at %p",
lo - raddr, raddr);
break;
} else {
LOG(4, "region is too small: %zu < %zu",
lo - raddr, len);
}
}
if (hi > raddr) {
raddr = (char *)roundup((uintptr_t)hi, align);
LOG(4, "nearest aligned addr %p", raddr);
}
if (raddr == NULL) {
LOG(4, "end of address space reached");
break;
}
}
}
/*
* Check for a case when this is the last unused range in the address
* space, but is not large enough. (very unlikely)
*/
if ((raddr != NULL) && (UINTPTR_MAX - (uintptr_t)raddr < len)) {
LOG(4, "end of address space reached");
raddr = MAP_FAILED;
}
fclose(fp);
LOG(3, "returning %p", raddr);
return raddr;
}
/*
* util_map_hint -- determine hint address for mmap()
*
* If PMEM_MMAP_HINT environment variable is not set, we let the system to pick
* the randomized mapping address. Otherwise, a user-defined hint address
* is used.
*
* ALSR in 64-bit Linux kernel uses 28-bit of randomness for mmap
* (bit positions 12-39), which means the base mapping address is randomized
* within [0..1024GB] range, with 4KB granularity. Assuming additional
* 1GB alignment, it results in 1024 possible locations.
*
* Configuring the hint address via PMEM_MMAP_HINT environment variable
* disables address randomization. In such case, the function will search for
* the first unused, properly aligned region of given size, above the specified
* address.
*/
char *
util_map_hint(size_t len, size_t req_align)
{
LOG(3, "len %zu req_align %zu", len, req_align);
char *hint_addr = MAP_FAILED;
/* choose the desired alignment based on the requested length */
size_t align = util_map_hint_align(len, req_align);
if (Mmap_no_random) {
LOG(4, "user-defined hint %p", Mmap_hint);
hint_addr = util_map_hint_unused(Mmap_hint, len, align);
} else {
/*
* Create dummy mapping to find an unused region of given size.
* Request for increased size for later address alignment.
* Use MAP_PRIVATE with read-only access to simulate
* zero cost for overcommit accounting. Note: MAP_NORESERVE
* flag is ignored if overcommit is disabled (mode 2).
*/
char *addr = mmap(NULL, len + align, PROT_READ,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (addr != MAP_FAILED) {
LOG(4, "system choice %p", addr);
hint_addr = (char *)roundup((uintptr_t)addr, align);
munmap(addr, len + align);
}
}
LOG(4, "hint %p", hint_addr);
return hint_addr;
}
/*
* util_map_sync -- memory map given file into memory, if MAP_SHARED flag is
* provided it attempts to use MAP_SYNC flag. Otherwise it fallbacks to
* mmap(2).
*/
void *
util_map_sync(void *addr, size_t len, int proto, int flags, int fd,
os_off_t offset, int *map_sync)
{
LOG(15, "addr %p len %zu proto %x flags %x fd %d offset %ld "
"map_sync %p", addr, len, proto, flags, fd, offset, map_sync);
if (map_sync)
*map_sync = 0;
/* if map_sync is NULL do not even try to mmap with MAP_SYNC flag */
if (!map_sync || flags & MAP_PRIVATE)
return mmap(addr, len, proto, flags, fd, offset);
/* MAP_SHARED */
void *ret = mmap(addr, len, proto,
flags | MAP_SHARED_VALIDATE | MAP_SYNC,
fd, offset);
if (ret != MAP_FAILED) {
LOG(4, "mmap with MAP_SYNC succeeded");
*map_sync = 1;
return ret;
}
if (errno == EINVAL || errno == ENOTSUP) {
LOG(4, "mmap with MAP_SYNC not supported");
return mmap(addr, len, proto, flags, fd, offset);
}
/* other error */
return MAP_FAILED;
}
| 6,914
| 30.289593
| 79
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/badblock_freebsd.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* badblock_freebsd.c - implementation of the FreeBSD bad block API
*/
#include "out.h"
#include "os_badblock.h"
/*
* os_badblocks_check_file -- check if the file contains bad blocks
*
* Return value:
* -1 : an error
* 0 : no bad blocks
* 1 : bad blocks detected
*/
int
os_badblocks_check_file(const char *file)
{
LOG(3, "file %s", file);
return 0;
}
/*
* os_badblocks_count -- returns number of bad blocks in the file
* or -1 in case of an error
*/
long
os_badblocks_count(const char *file)
{
LOG(3, "file %s", file);
return 0;
}
/*
* os_badblocks_get -- returns list of bad blocks in the file
*/
int
os_badblocks_get(const char *file, struct badblocks *bbs)
{
LOG(3, "file %s", file);
return 0;
}
/*
* os_badblocks_clear -- clears the given bad blocks in a file
* (regular file or dax device)
*/
int
os_badblocks_clear(const char *file, struct badblocks *bbs)
{
LOG(3, "file %s badblocks %p", file, bbs);
return 0;
}
/*
* os_badblocks_clear_all -- clears all bad blocks in a file
* (regular file or dax device)
*/
int
os_badblocks_clear_all(const char *file)
{
LOG(3, "file %s", file);
return 0;
}
| 2,812
| 26.578431
| 74
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/pool_hdr.h
|
/*
* Copyright 2014-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* pool_hdr.h -- internal definitions for pool header module
*/
#ifndef PMDK_POOL_HDR_H
#define PMDK_POOL_HDR_H 1
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
#include "uuid.h"
#include "shutdown_state.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Number of bits per type in alignment descriptor
*/
#define ALIGNMENT_DESC_BITS 4
/*
* architecture identification flags
*
* These flags allow to unambiguously determine the architecture
* on which the pool was created.
*
* The alignment_desc field contains information about alignment
* of the following basic types:
* - char
* - short
* - int
* - long
* - long long
* - size_t
* - os_off_t
* - float
* - double
* - long double
* - void *
*
* The alignment of each type is computed as an offset of field
* of specific type in the following structure:
* struct {
* char byte;
* type field;
* };
*
* The value is decremented by 1 and masked by 4 bits.
* Multiple alignments are stored on consecutive 4 bits of each
* type in the order specified above.
*
* The values used in the machine, and machine_class fields are in
* principle independent of operating systems, and object formats.
* In practice they happen to match constants used in ELF object headers.
*/
struct arch_flags {
uint64_t alignment_desc; /* alignment descriptor */
uint8_t machine_class; /* address size -- 64 bit or 32 bit */
uint8_t data; /* data encoding -- LE or BE */
uint8_t reserved[4];
uint16_t machine; /* required architecture */
};
#define POOL_HDR_ARCH_LEN sizeof(struct arch_flags)
/* possible values of the machine class field in the above struct */
#define PMDK_MACHINE_CLASS_64 2 /* 64 bit pointers, 64 bit size_t */
/* possible values of the machine field in the above struct */
#define PMDK_MACHINE_X86_64 62
#define PMDK_MACHINE_AARCH64 183
/* possible values of the data field in the above struct */
#define PMDK_DATA_LE 1 /* 2's complement, little endian */
#define PMDK_DATA_BE 2 /* 2's complement, big endian */
/*
* features flags
*/
typedef struct {
uint32_t compat; /* mask: compatible "may" features */
uint32_t incompat; /* mask: "must support" features */
uint32_t ro_compat; /* mask: force RO if unsupported */
} features_t;
/*
* header used at the beginning of all types of memory pools
*
* for pools build on persistent memory, the integer types
* below are stored in little-endian byte order.
*/
#define POOL_HDR_SIG_LEN 8
struct pool_hdr {
char signature[POOL_HDR_SIG_LEN];
uint32_t major; /* format major version number */
features_t features; /* features flags */
uuid_t poolset_uuid; /* pool set UUID */
uuid_t uuid; /* UUID of this file */
uuid_t prev_part_uuid; /* prev part */
uuid_t next_part_uuid; /* next part */
uuid_t prev_repl_uuid; /* prev replica */
uuid_t next_repl_uuid; /* next replica */
uint64_t crtime; /* when created (seconds since epoch) */
struct arch_flags arch_flags; /* architecture identification flags */
unsigned char unused[1904]; /* must be zero */
/* not checksumed */
unsigned char unused2[1976]; /* must be zero */
struct shutdown_state sds; /* shutdown status */
uint64_t checksum; /* checksum of above fields */
};
#define POOL_HDR_SIZE (sizeof(struct pool_hdr))
#define POOL_DESC_SIZE 4096
void util_convert2le_hdr(struct pool_hdr *hdrp);
void util_convert2h_hdr_nocheck(struct pool_hdr *hdrp);
void util_get_arch_flags(struct arch_flags *arch_flags);
int util_check_arch_flags(const struct arch_flags *arch_flags);
features_t util_get_unknown_features(features_t features, features_t known);
int util_feature_check(struct pool_hdr *hdrp, features_t features);
int util_feature_cmp(features_t features, features_t ref);
int util_feature_is_zero(features_t features);
int util_feature_is_set(features_t features, features_t flag);
void util_feature_enable(features_t *features, features_t new_feature);
void util_feature_disable(features_t *features, features_t new_feature);
const char *util_feature2str(features_t feature, features_t *found);
features_t util_str2feature(const char *str);
uint32_t util_str2pmempool_feature(const char *str);
uint32_t util_feature2pmempool_feature(features_t feat);
/*
* set of macros for determining the alignment descriptor
*/
#define DESC_MASK ((1 << ALIGNMENT_DESC_BITS) - 1)
#define alignment_of(t) offsetof(struct { char c; t x; }, x)
#define alignment_desc_of(t) (((uint64_t)alignment_of(t) - 1) & DESC_MASK)
#define alignment_desc()\
(alignment_desc_of(char) << 0 * ALIGNMENT_DESC_BITS) |\
(alignment_desc_of(short) << 1 * ALIGNMENT_DESC_BITS) |\
(alignment_desc_of(int) << 2 * ALIGNMENT_DESC_BITS) |\
(alignment_desc_of(long) << 3 * ALIGNMENT_DESC_BITS) |\
(alignment_desc_of(long long) << 4 * ALIGNMENT_DESC_BITS) |\
(alignment_desc_of(size_t) << 5 * ALIGNMENT_DESC_BITS) |\
(alignment_desc_of(off_t) << 6 * ALIGNMENT_DESC_BITS) |\
(alignment_desc_of(float) << 7 * ALIGNMENT_DESC_BITS) |\
(alignment_desc_of(double) << 8 * ALIGNMENT_DESC_BITS) |\
(alignment_desc_of(long double) << 9 * ALIGNMENT_DESC_BITS) |\
(alignment_desc_of(void *) << 10 * ALIGNMENT_DESC_BITS)
#define POOL_FEAT_ZERO 0x0000U
static const features_t features_zero =
{POOL_FEAT_ZERO, POOL_FEAT_ZERO, POOL_FEAT_ZERO};
/*
* compat features
*/
#define POOL_FEAT_CHECK_BAD_BLOCKS 0x0001U /* check bad blocks in a pool */
#define POOL_FEAT_COMPAT_ALL \
(POOL_FEAT_CHECK_BAD_BLOCKS)
#define FEAT_COMPAT(X) \
{POOL_FEAT_##X, POOL_FEAT_ZERO, POOL_FEAT_ZERO}
/*
* incompat features
*/
#define POOL_FEAT_SINGLEHDR 0x0001U /* pool header only in the first part */
#define POOL_FEAT_CKSUM_2K 0x0002U /* only first 2K of hdr checksummed */
#define POOL_FEAT_SDS 0x0004U /* check shutdown state */
#define POOL_FEAT_INCOMPAT_ALL \
(POOL_FEAT_SINGLEHDR | POOL_FEAT_CKSUM_2K | POOL_FEAT_SDS)
/*
* incompat features effective values (if applicable)
*/
#ifdef SDS_ENABLED
#define POOL_E_FEAT_SDS POOL_FEAT_SDS
#else
#define POOL_E_FEAT_SDS 0x0000U /* empty */
#endif
#define POOL_FEAT_COMPAT_VALID \
(POOL_FEAT_CHECK_BAD_BLOCKS)
#define POOL_FEAT_INCOMPAT_VALID \
(POOL_FEAT_SINGLEHDR | POOL_FEAT_CKSUM_2K | POOL_E_FEAT_SDS)
#ifdef _WIN32
#define POOL_FEAT_INCOMPAT_DEFAULT \
(POOL_FEAT_CKSUM_2K | POOL_E_FEAT_SDS)
#else
/*
* shutdown state support on Linux requires root access
* so it is disabled by default
*/
#define POOL_FEAT_INCOMPAT_DEFAULT \
(POOL_FEAT_CKSUM_2K)
#endif
#define FEAT_INCOMPAT(X) \
{POOL_FEAT_ZERO, POOL_FEAT_##X, POOL_FEAT_ZERO}
#define POOL_FEAT_VALID \
{POOL_FEAT_COMPAT_VALID, POOL_FEAT_INCOMPAT_VALID, POOL_FEAT_ZERO}
/*
* defines the first not checksummed field - all fields after this will be
* ignored during checksum calculations.
*/
#define POOL_HDR_CSUM_2K_END_OFF offsetof(struct pool_hdr, unused2)
#define POOL_HDR_CSUM_4K_END_OFF offsetof(struct pool_hdr, checksum)
/*
* pick the first not checksummed field. 2K variant is used if
* POOL_FEAT_CKSUM_2K incompat feature is set.
*/
#define POOL_HDR_CSUM_END_OFF(hdrp) \
((hdrp)->features.incompat & POOL_FEAT_CKSUM_2K) \
? POOL_HDR_CSUM_2K_END_OFF : POOL_HDR_CSUM_4K_END_OFF
/* ignore shutdown state if incompat feature is disabled */
#define IGNORE_SDS(hdrp) \
(((hdrp) != NULL) && (((hdrp)->features.incompat & POOL_FEAT_SDS) == 0))
#ifdef __cplusplus
}
#endif
#endif
| 8,929
| 31.830882
| 76
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/os_deep_windows.c
|
/*
* Copyright 2017-2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* os_deep_windows.c -- Windows abstraction layer for deep_* functions
*/
#include <windows.h>
#include "out.h"
#include "os.h"
#include "set.h"
#include "libpmem.h"
/*
* os_range_deep_common -- call msnyc for non DEV dax
*/
int
os_range_deep_common(uintptr_t addr, size_t len)
{
LOG(3, "os_range_deep_common addr %p len %lu", addr, len);
return pmem_msync((void *)addr, len);
}
/*
* os_part_deep_common -- common function to handle both
* deep_persist and deep_drain part flush cases.
*/
int
os_part_deep_common(struct pool_replica *rep, unsigned partidx, void *addr,
size_t len, int flush)
{
LOG(3, "part %p part %d addr %p len %lu flush %d",
rep, partidx, addr, len, flush);
if (!rep->is_pmem) {
/*
* In case of part on non-pmem call msync on the range
* to deep flush the data. Deep drain is empty as all
* data is msynced to persistence.
*/
if (!flush)
return 0;
if (pmem_msync(addr, len)) {
LOG(1, "pmem_msync(%p, %lu)", addr, len);
return -1;
}
return 0;
}
/* Call deep flush if it was requested */
if (flush) {
LOG(15, "pmem_deep_flush addr %p, len %lu", addr, len);
pmem_deep_flush(addr, len);
}
/*
* Before deep drain call normal drain to ensure that data
* is at least in WPQ.
*/
pmem_drain();
/*
* For deep_drain on normal pmem it is enough to
* call msync on one page.
*/
if (pmem_msync(addr, MIN(Pagesize, len))) {
LOG(1, "pmem_msync(%p, %lu)", addr, len);
return -1;
}
return 0;
}
| 3,086
| 28.970874
| 75
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/extent_linux.c
|
/*
* Copyright 2018, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* extent_linux.c - implementation of the linux fs extent query API
*/
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
#include <linux/fiemap.h>
#include "file.h"
#include "out.h"
#include "extent.h"
/*
* os_extents_common -- (internal) common part of getting extents
* of the given file
*
* Returns: number of extents the file consists of or -1 in case of an error.
* Sets: file descriptor, struct fiemap and struct extents.
*/
static long
os_extents_common(const char *path, struct extents *exts,
int *pfd, struct fiemap **pfmap)
{
LOG(3, "path %s exts %p pfd %p pfmap %p", path, exts, pfd, pfmap);
int fd = open(path, O_RDONLY);
if (fd == -1) {
ERR("!open %s", path);
return -1;
}
enum file_type type = util_fd_get_type(fd);
if (type < 0)
goto error_close;
struct stat st;
if (fstat(fd, &st) < 0) {
ERR("!fstat %d", fd);
goto error_close;
}
if (exts->extents_count == 0) {
LOG(10, "%s: block size: %li", path, (long int)st.st_blksize);
exts->blksize = (uint64_t)st.st_blksize;
}
/* devdax does not have any extents */
if (type == TYPE_DEVDAX) {
close(fd);
return 0;
}
struct fiemap *fmap = Zalloc(sizeof(struct fiemap));
if (fmap == NULL) {
ERR("!malloc");
goto error_close;
}
fmap->fm_start = 0;
fmap->fm_length = (size_t)st.st_size;
fmap->fm_flags = 0;
fmap->fm_extent_count = 0;
if (ioctl(fd, FS_IOC_FIEMAP, fmap) != 0) {
ERR("!ioctl %d", fd);
goto error_free;
}
if (exts->extents_count == 0) {
exts->extents_count = fmap->fm_mapped_extents;
LOG(4, "%s: number of extents: %u", path, exts->extents_count);
} else if (exts->extents_count != fmap->fm_mapped_extents) {
ERR("number of extents differs (was: %u, is: %u)",
exts->extents_count, fmap->fm_mapped_extents);
goto error_free;
}
*pfd = fd;
*pfmap = fmap;
return exts->extents_count;
error_free:
Free(fmap);
error_close:
close(fd);
return -1;
}
/*
* os_extents_count -- get number of extents of the given file
* (and optionally read its block size)
*/
long
os_extents_count(const char *path, struct extents *exts)
{
LOG(3, "path %s extents %p", path, exts);
struct fiemap *fmap = NULL;
int fd = -1;
ASSERTne(exts, NULL);
memset(exts, 0, sizeof(*exts));
long ret = os_extents_common(path, exts, &fd, &fmap);
Free(fmap);
if (fd != -1)
close(fd);
return ret;
}
/*
* os_extents_get -- get extents of the given file
* (and optionally read its block size)
*/
int
os_extents_get(const char *path, struct extents *exts)
{
LOG(3, "path %s extents %p", path, exts);
struct fiemap *fmap = NULL;
int fd = -1;
int ret = -1;
ASSERTne(exts, NULL);
if (exts->extents_count == 0)
return 0;
ASSERTne(exts->extents, NULL);
if (os_extents_common(path, exts, &fd, &fmap) <= 0)
goto error_free;
struct fiemap *newfmap = Realloc(fmap, sizeof(struct fiemap) +
fmap->fm_mapped_extents *
sizeof(struct fiemap_extent));
if (newfmap == NULL) {
ERR("!Realloc");
goto error_free;
}
fmap = newfmap;
fmap->fm_extent_count = fmap->fm_mapped_extents;
memset(fmap->fm_extents, 0, fmap->fm_mapped_extents *
sizeof(struct fiemap_extent));
if (ioctl(fd, FS_IOC_FIEMAP, fmap) != 0) {
ERR("!ioctl %d", fd);
goto error_free;
}
unsigned e;
for (e = 0; e < fmap->fm_extent_count; e++) {
exts->extents[e].offset_physical =
fmap->fm_extents[e].fe_physical;
exts->extents[e].offset_logical =
fmap->fm_extents[e].fe_logical;
exts->extents[e].length = fmap->fm_extents[e].fe_length;
}
ret = 0;
error_free:
Free(fmap);
if (fd != -1)
close(fd);
return ret;
}
| 5,272
| 23.755869
| 77
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/mmap_windows.c
|
/*
* Copyright 2015-2018, Intel Corporation
* Copyright (c) 2015-2017, Microsoft Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* mmap_windows.c -- memory-mapped files for Windows
*/
#include <sys/mman.h>
#include "mmap.h"
#include "out.h"
/*
* util_map_hint_unused -- use VirtualQuery to determine hint address
*
* This is a helper function for util_map_hint().
* It iterates through memory regions and looks for the first unused address
* in the process address space that is:
* - greater or equal 'minaddr' argument,
* - large enough to hold range of given length,
* - aligned to the specified unit.
*/
char *
util_map_hint_unused(void *minaddr, size_t len, size_t align)
{
LOG(3, "minaddr %p len %zu align %zu", minaddr, len, align);
ASSERT(align > 0);
MEMORY_BASIC_INFORMATION mi;
char *lo = NULL; /* beginning of current range in maps file */
char *hi = NULL; /* end of current range in maps file */
char *raddr = minaddr; /* ignore regions below 'minaddr' */
if (raddr == NULL)
raddr += Pagesize;
raddr = (char *)roundup((uintptr_t)raddr, align);
while ((uintptr_t)raddr < UINTPTR_MAX - len) {
size_t ret = VirtualQuery(raddr, &mi, sizeof(mi));
if (ret == 0) {
ERR("VirtualQuery %p", raddr);
return MAP_FAILED;
}
LOG(4, "addr %p len %zu state %d",
mi.BaseAddress, mi.RegionSize, mi.State);
if ((mi.State != MEM_FREE) || (mi.RegionSize < len)) {
raddr = (char *)mi.BaseAddress + mi.RegionSize;
raddr = (char *)roundup((uintptr_t)raddr, align);
LOG(4, "nearest aligned addr %p", raddr);
} else {
LOG(4, "unused region of size %zu found at %p",
mi.RegionSize, mi.BaseAddress);
return mi.BaseAddress;
}
}
LOG(4, "end of address space reached");
return MAP_FAILED;
}
/*
* util_map_hint -- determine hint address for mmap()
*
* XXX - Windows doesn't support large DAX pages yet, so there is
* no point in aligning for the same.
*/
char *
util_map_hint(size_t len, size_t req_align)
{
LOG(3, "len %zu req_align %zu", len, req_align);
char *hint_addr = MAP_FAILED;
/* choose the desired alignment based on the requested length */
size_t align = util_map_hint_align(len, req_align);
if (Mmap_no_random) {
LOG(4, "user-defined hint %p", Mmap_hint);
hint_addr = util_map_hint_unused(Mmap_hint, len, align);
} else {
/*
* Create dummy mapping to find an unused region of given size.
* Request for increased size for later address alignment.
*
* Use MAP_NORESERVE flag to only reserve the range of pages
* rather than commit. We don't want the pages to be actually
* backed by the operating system paging file, as the swap
* file is usually too small to handle terabyte pools.
*/
char *addr = mmap(NULL, len + align, PROT_READ,
MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0);
if (addr != MAP_FAILED) {
LOG(4, "system choice %p", addr);
hint_addr = (char *)roundup((uintptr_t)addr, align);
munmap(addr, len + align);
}
}
LOG(4, "hint %p", hint_addr);
return hint_addr;
}
/*
* util_map_sync -- memory map given file into memory
*/
void *
util_map_sync(void *addr, size_t len, int proto, int flags, int fd,
os_off_t offset, int *map_sync)
{
LOG(15, "addr %p len %zu proto %x flags %x fd %d offset %ld",
addr, len, proto, flags, fd, offset);
if (map_sync)
*map_sync = 0;
return mmap(addr, len, proto, flags, fd, offset);
}
| 4,921
| 31.813333
| 76
|
c
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/valgrind/memcheck.h
|
/*
----------------------------------------------------------------
Notice that the following BSD-style license applies to this one
file (memcheck.h) only. The rest of Valgrind is licensed under the
terms of the GNU General Public License, version 2, unless
otherwise indicated. See the COPYING file in the source
distribution for details.
----------------------------------------------------------------
This file is part of MemCheck, a heavyweight Valgrind tool for
detecting memory errors.
Copyright (C) 2000-2017 Julian Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------
Notice that the above BSD-style license applies to this one file
(memcheck.h) only. The entire rest of Valgrind is licensed under
the terms of the GNU General Public License, version 2. See the
COPYING file in the source distribution for details.
----------------------------------------------------------------
*/
#ifndef __MEMCHECK_H
#define __MEMCHECK_H
/* This file is for inclusion into client (your!) code.
You can use these macros to manipulate and query memory permissions
inside your own programs.
See comment near the top of valgrind.h on how to use them.
*/
#include "valgrind.h"
/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
This enum comprises an ABI exported by Valgrind to programs
which use client requests. DO NOT CHANGE THE ORDER OF THESE
ENTRIES, NOR DELETE ANY -- add new ones at the end. */
typedef
enum {
VG_USERREQ__MAKE_MEM_NOACCESS = VG_USERREQ_TOOL_BASE('M','C'),
VG_USERREQ__MAKE_MEM_UNDEFINED,
VG_USERREQ__MAKE_MEM_DEFINED,
VG_USERREQ__DISCARD,
VG_USERREQ__CHECK_MEM_IS_ADDRESSABLE,
VG_USERREQ__CHECK_MEM_IS_DEFINED,
VG_USERREQ__DO_LEAK_CHECK,
VG_USERREQ__COUNT_LEAKS,
VG_USERREQ__GET_VBITS,
VG_USERREQ__SET_VBITS,
VG_USERREQ__CREATE_BLOCK,
VG_USERREQ__MAKE_MEM_DEFINED_IF_ADDRESSABLE,
/* Not next to VG_USERREQ__COUNT_LEAKS because it was added later. */
VG_USERREQ__COUNT_LEAK_BLOCKS,
VG_USERREQ__ENABLE_ADDR_ERROR_REPORTING_IN_RANGE,
VG_USERREQ__DISABLE_ADDR_ERROR_REPORTING_IN_RANGE,
VG_USERREQ__CHECK_MEM_IS_UNADDRESSABLE,
VG_USERREQ__CHECK_MEM_IS_UNDEFINED,
/* This is just for memcheck's internal use - don't use it */
_VG_USERREQ__MEMCHECK_RECORD_OVERLAP_ERROR
= VG_USERREQ_TOOL_BASE('M','C') + 256
} Vg_MemCheckClientRequest;
/* Client-code macros to manipulate the state of memory. */
/* Mark memory at _qzz_addr as unaddressable for _qzz_len bytes. */
#define VALGRIND_MAKE_MEM_NOACCESS(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__MAKE_MEM_NOACCESS, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Similarly, mark memory at _qzz_addr as addressable but undefined
for _qzz_len bytes. */
#define VALGRIND_MAKE_MEM_UNDEFINED(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__MAKE_MEM_UNDEFINED, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Similarly, mark memory at _qzz_addr as addressable and defined
for _qzz_len bytes. */
#define VALGRIND_MAKE_MEM_DEFINED(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__MAKE_MEM_DEFINED, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Similar to VALGRIND_MAKE_MEM_DEFINED except that addressability is
not altered: bytes which are addressable are marked as defined,
but those which are not addressable are left unchanged. */
#define VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__MAKE_MEM_DEFINED_IF_ADDRESSABLE, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Create a block-description handle. The description is an ascii
string which is included in any messages pertaining to addresses
within the specified memory range. Has no other effect on the
properties of the memory range. */
#define VALGRIND_CREATE_BLOCK(_qzz_addr,_qzz_len, _qzz_desc) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__CREATE_BLOCK, \
(_qzz_addr), (_qzz_len), (_qzz_desc), \
0, 0)
/* Discard a block-description-handle. Returns 1 for an
invalid handle, 0 for a valid handle. */
#define VALGRIND_DISCARD(_qzz_blkindex) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__DISCARD, \
0, (_qzz_blkindex), 0, 0, 0)
/* Client-code macros to check the state of memory. */
/* Check that memory at _qzz_addr is addressable for _qzz_len bytes.
If suitable addressibility is not established, Valgrind prints an
error message and returns the address of the first offending byte.
Otherwise it returns zero. */
#define VALGRIND_CHECK_MEM_IS_ADDRESSABLE(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__CHECK_MEM_IS_ADDRESSABLE, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Check that memory at _qzz_addr is addressable and defined for
_qzz_len bytes. If suitable addressibility and definedness are not
established, Valgrind prints an error message and returns the
address of the first offending byte. Otherwise it returns zero. */
#define VALGRIND_CHECK_MEM_IS_DEFINED(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__CHECK_MEM_IS_DEFINED, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Use this macro to force the definedness and addressibility of an
lvalue to be checked. If suitable addressibility and definedness
are not established, Valgrind prints an error message and returns
the address of the first offending byte. Otherwise it returns
zero. */
#define VALGRIND_CHECK_VALUE_IS_DEFINED(__lvalue) \
VALGRIND_CHECK_MEM_IS_DEFINED( \
(volatile unsigned char *)&(__lvalue), \
(unsigned long)(sizeof (__lvalue)))
/* Check that memory at _qzz_addr is unaddressable for _qzz_len bytes.
If any byte in this range is addressable, Valgrind returns the
address of the first offending byte. Otherwise it returns zero. */
#define VALGRIND_CHECK_MEM_IS_UNADDRESSABLE(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__CHECK_MEM_IS_UNADDRESSABLE,\
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Check that memory at _qzz_addr is undefined for _qzz_len bytes. If any
byte in this range is defined or unaddressable, Valgrind returns the
address of the first offending byte. Otherwise it returns zero. */
#define VALGRIND_CHECK_MEM_IS_UNDEFINED(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__CHECK_MEM_IS_UNDEFINED, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/* Do a full memory leak check (like --leak-check=full) mid-execution. */
#define VALGRIND_DO_LEAK_CHECK \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \
0, 0, 0, 0, 0)
/* Same as VALGRIND_DO_LEAK_CHECK but only showing the entries for
which there was an increase in leaked bytes or leaked nr of blocks
since the previous leak search. */
#define VALGRIND_DO_ADDED_LEAK_CHECK \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \
0, 1, 0, 0, 0)
/* Same as VALGRIND_DO_ADDED_LEAK_CHECK but showing entries with
increased or decreased leaked bytes/blocks since previous leak
search. */
#define VALGRIND_DO_CHANGED_LEAK_CHECK \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \
0, 2, 0, 0, 0)
/* Do a summary memory leak check (like --leak-check=summary) mid-execution. */
#define VALGRIND_DO_QUICK_LEAK_CHECK \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DO_LEAK_CHECK, \
1, 0, 0, 0, 0)
/* Return number of leaked, dubious, reachable and suppressed bytes found by
all previous leak checks. They must be lvalues. */
#define VALGRIND_COUNT_LEAKS(leaked, dubious, reachable, suppressed) \
/* For safety on 64-bit platforms we assign the results to private
unsigned long variables, then assign these to the lvalues the user
specified, which works no matter what type 'leaked', 'dubious', etc
are. We also initialise '_qzz_leaked', etc because
VG_USERREQ__COUNT_LEAKS doesn't mark the values returned as
defined. */ \
{ \
unsigned long _qzz_leaked = 0, _qzz_dubious = 0; \
unsigned long _qzz_reachable = 0, _qzz_suppressed = 0; \
VALGRIND_DO_CLIENT_REQUEST_STMT( \
VG_USERREQ__COUNT_LEAKS, \
&_qzz_leaked, &_qzz_dubious, \
&_qzz_reachable, &_qzz_suppressed, 0); \
leaked = _qzz_leaked; \
dubious = _qzz_dubious; \
reachable = _qzz_reachable; \
suppressed = _qzz_suppressed; \
}
/* Return number of leaked, dubious, reachable and suppressed bytes found by
all previous leak checks. They must be lvalues. */
#define VALGRIND_COUNT_LEAK_BLOCKS(leaked, dubious, reachable, suppressed) \
/* For safety on 64-bit platforms we assign the results to private
unsigned long variables, then assign these to the lvalues the user
specified, which works no matter what type 'leaked', 'dubious', etc
are. We also initialise '_qzz_leaked', etc because
VG_USERREQ__COUNT_LEAKS doesn't mark the values returned as
defined. */ \
{ \
unsigned long _qzz_leaked = 0, _qzz_dubious = 0; \
unsigned long _qzz_reachable = 0, _qzz_suppressed = 0; \
VALGRIND_DO_CLIENT_REQUEST_STMT( \
VG_USERREQ__COUNT_LEAK_BLOCKS, \
&_qzz_leaked, &_qzz_dubious, \
&_qzz_reachable, &_qzz_suppressed, 0); \
leaked = _qzz_leaked; \
dubious = _qzz_dubious; \
reachable = _qzz_reachable; \
suppressed = _qzz_suppressed; \
}
/* Get the validity data for addresses [zza..zza+zznbytes-1] and copy it
into the provided zzvbits array. Return values:
0 if not running on valgrind
1 success
2 [previously indicated unaligned arrays; these are now allowed]
3 if any parts of zzsrc/zzvbits are not addressable.
The metadata is not copied in cases 0, 2 or 3 so it should be
impossible to segfault your system by using this call.
*/
#define VALGRIND_GET_VBITS(zza,zzvbits,zznbytes) \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__GET_VBITS, \
(const char*)(zza), \
(char*)(zzvbits), \
(zznbytes), 0, 0)
/* Set the validity data for addresses [zza..zza+zznbytes-1], copying it
from the provided zzvbits array. Return values:
0 if not running on valgrind
1 success
2 [previously indicated unaligned arrays; these are now allowed]
3 if any parts of zza/zzvbits are not addressable.
The metadata is not copied in cases 0, 2 or 3 so it should be
impossible to segfault your system by using this call.
*/
#define VALGRIND_SET_VBITS(zza,zzvbits,zznbytes) \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__SET_VBITS, \
(const char*)(zza), \
(const char*)(zzvbits), \
(zznbytes), 0, 0 )
/* Disable and re-enable reporting of addressing errors in the
specified address range. */
#define VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__DISABLE_ADDR_ERROR_REPORTING_IN_RANGE, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
#define VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__ENABLE_ADDR_ERROR_REPORTING_IN_RANGE, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
#endif
| 15,621
| 47.666667
| 79
|
h
|
null |
NearPMSW-main/baseline/shadow/redis-NDP-sd/deps/pmdk/src/common/valgrind/pmemcheck.h
|
/*
* Copyright (c) 2014-2015, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __PMEMCHECK_H
#define __PMEMCHECK_H
/* This file is for inclusion into client (your!) code.
You can use these macros to manipulate and query memory permissions
inside your own programs.
See comment near the top of valgrind.h on how to use them.
*/
#include "valgrind.h"
/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
This enum comprises an ABI exported by Valgrind to programs
which use client requests. DO NOT CHANGE THE ORDER OF THESE
ENTRIES, NOR DELETE ANY -- add new ones at the end. */
typedef
enum {
VG_USERREQ__PMC_REGISTER_PMEM_MAPPING = VG_USERREQ_TOOL_BASE('P','C'),
VG_USERREQ__PMC_REGISTER_PMEM_FILE,
VG_USERREQ__PMC_REMOVE_PMEM_MAPPING,
VG_USERREQ__PMC_CHECK_IS_PMEM_MAPPING,
VG_USERREQ__PMC_PRINT_PMEM_MAPPINGS,
VG_USERREQ__PMC_DO_FLUSH,
VG_USERREQ__PMC_DO_FENCE,
VG_USERREQ__PMC_DO_COMMIT,
VG_USERREQ__PMC_WRITE_STATS,
VG_USERREQ__PMC_LOG_STORES,
VG_USERREQ__PMC_NO_LOG_STORES,
VG_USERREQ__PMC_ADD_LOG_REGION,
VG_USERREQ__PMC_REMOVE_LOG_REGION,
VG_USERREQ__PMC_FULL_REORDED,
VG_USERREQ__PMC_PARTIAL_REORDER,
VG_USERREQ__PMC_ONLY_FAULT,
VG_USERREQ__PMC_STOP_REORDER_FAULT,
VG_USERREQ__PMC_SET_CLEAN,
/* transaction support */
VG_USERREQ__PMC_START_TX,
VG_USERREQ__PMC_START_TX_N,
VG_USERREQ__PMC_END_TX,
VG_USERREQ__PMC_END_TX_N,
VG_USERREQ__PMC_ADD_TO_TX,
VG_USERREQ__PMC_ADD_TO_TX_N,
VG_USERREQ__PMC_REMOVE_FROM_TX,
VG_USERREQ__PMC_REMOVE_FROM_TX_N,
VG_USERREQ__PMC_ADD_THREAD_TO_TX_N,
VG_USERREQ__PMC_REMOVE_THREAD_FROM_TX_N,
VG_USERREQ__PMC_ADD_TO_GLOBAL_TX_IGNORE,
VG_USERREQ__PMC_DEFAULT_REORDER,
VG_USERREQ__PMC_EMIT_LOG,
} Vg_PMemCheckClientRequest;
/* Client-code macros to manipulate pmem mappings */
/** Register a persistent memory mapping region */
#define VALGRIND_PMC_REGISTER_PMEM_MAPPING(_qzz_addr, _qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REGISTER_PMEM_MAPPING, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Register a persistent memory file */
#define VALGRIND_PMC_REGISTER_PMEM_FILE(_qzz_desc, _qzz_addr_base, \
_qzz_size, _qzz_offset) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REGISTER_PMEM_FILE, \
(_qzz_desc), (_qzz_addr_base), (_qzz_size), \
(_qzz_offset), 0)
/** Remove a persistent memory mapping region */
#define VALGRIND_PMC_REMOVE_PMEM_MAPPING(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REMOVE_PMEM_MAPPING, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Check if the given range is a registered persistent memory mapping */
#define VALGRIND_PMC_CHECK_IS_PMEM_MAPPING(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_CHECK_IS_PMEM_MAPPING, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Register an SFENCE */
#define VALGRIND_PMC_PRINT_PMEM_MAPPINGS \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_PRINT_PMEM_MAPPINGS, \
0, 0, 0, 0, 0)
/** Register a CLFLUSH-like operation */
#define VALGRIND_PMC_DO_FLUSH(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_DO_FLUSH, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Register an SFENCE */
#define VALGRIND_PMC_DO_FENCE \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_DO_FENCE, \
0, 0, 0, 0, 0)
/** Register a PCOMMIT (DEPRECATED, DO NOT USE) */
#define VALGRIND_PMC_DO_COMMIT \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_DO_COMMIT, \
0, 0, 0, 0, 0)
/** Write tool stats */
#define VALGRIND_PMC_WRITE_STATS \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_WRITE_STATS, \
0, 0, 0, 0, 0)
/** Start logging memory operations */
#define VALGRIND_PMC_LOG_STORES \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_LOG_STORES, \
0, 0, 0, 0, 0)
/** Stop logging memory operations */
#define VALGRIND_PMC_NO_LOG_STORES \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_NO_LOG_STORES, \
0, 0, 0, 0, 0)
/** Add a region of persistent memory, for which all operations will be
* logged */
#define VALGRIND_PMC_ADD_LOG_REGION(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_ADD_LOG_REGION, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Remove the loggable persistent memory region */
#define VALGRIND_PMC_REMOVE_LOG_REGION(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REMOVE_LOG_REGION, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Issue a full reorder log */
#define VALGRIND_PMC_FULL_REORDER \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_FULL_REORDED, \
0, 0, 0, 0, 0)
/** Issue a partial reorder log */
#define VALGRIND_PMC_PARTIAL_REORDER \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_PARTIAL_REORDER, \
0, 0, 0, 0, 0)
/** Issue a log to disable reordering */
#define VALGRIND_PMC_ONLY_FAULT \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_ONLY_FAULT, \
0, 0, 0, 0, 0)
/** Issue a log to disable reordering and faults */
#define VALGRIND_PMC_STOP_REORDER_FAULT \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_STOP_REORDER_FAULT, \
0, 0, 0, 0, 0)
/** Issue a log to set the default reorder engine */
#define VALGRIND_PMC_DEFAULT_REORDER \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_DEFAULT_REORDER, \
0, 0, 0, 0, 0)
/** Set a region of persistent memory as clean */
#define VALGRIND_PMC_SET_CLEAN(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_SET_CLEAN, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Emit user log */
#define VALGRIND_PMC_EMIT_LOG(_qzz_emit_log) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_EMIT_LOG, \
(_qzz_emit_log), 0, 0, 0, 0)
/** Support for transactions */
/** Start an implicit persistent memory transaction */
#define VALGRIND_PMC_START_TX \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_START_TX, \
0, 0, 0, 0, 0)
/** Start an explicit persistent memory transaction */
#define VALGRIND_PMC_START_TX_N(_qzz_txn) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_START_TX_N, \
(_qzz_txn), 0, 0, 0, 0)
/** End an implicit persistent memory transaction */
#define VALGRIND_PMC_END_TX \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_END_TX, \
0, 0, 0, 0, 0)
/** End an explicit persistent memory transaction */
#define VALGRIND_PMC_END_TX_N(_qzz_txn) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_END_TX_N, \
(_qzz_txn), 0, 0, 0, 0)
/** Add a persistent memory region to the implicit transaction */
#define VALGRIND_PMC_ADD_TO_TX(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_ADD_TO_TX, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Add a persistent memory region to an explicit transaction */
#define VALGRIND_PMC_ADD_TO_TX_N(_qzz_txn,_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_ADD_TO_TX_N, \
(_qzz_txn), (_qzz_addr), (_qzz_len), 0, 0)
/** Remove a persistent memory region from the implicit transaction */
#define VALGRIND_PMC_REMOVE_FROM_TX(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REMOVE_FROM_TX, \
(_qzz_addr), (_qzz_len), 0, 0, 0)
/** Remove a persistent memory region from an explicit transaction */
#define VALGRIND_PMC_REMOVE_FROM_TX_N(_qzz_txn,_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REMOVE_FROM_TX_N, \
(_qzz_txn), (_qzz_addr), (_qzz_len), 0, 0)
/** End an explicit persistent memory transaction */
#define VALGRIND_PMC_ADD_THREAD_TX_N(_qzz_txn) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_ADD_THREAD_TO_TX_N, \
(_qzz_txn), 0, 0, 0, 0)
/** End an explicit persistent memory transaction */
#define VALGRIND_PMC_REMOVE_THREAD_FROM_TX_N(_qzz_txn) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__PMC_REMOVE_THREAD_FROM_TX_N, \
(_qzz_txn), 0, 0, 0, 0)
/** Remove a persistent memory region from the implicit transaction */
#define VALGRIND_PMC_ADD_TO_GLOBAL_TX_IGNORE(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__PMC_ADD_TO_GLOBAL_TX_IGNORE,\
(_qzz_addr), (_qzz_len), 0, 0, 0)
#endif
| 13,180
| 48.367041
| 77
|
h
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.