Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysfs & extents & badblocks #2246

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

LIBRARY_NAME = pmemcommon
SOURCE =\
badblock_filesrc_linux.c\
badblock_poolset.c\
badblock.c\
extent_linux.c\
file.c\
file_linux.c\
mmap.c\
Expand All @@ -45,6 +49,7 @@ SOURCE =\
pool_hdr.c\
pool_hdr_linux.c\
set.c\
sysfs.c\
util.c\
uuid.c\
uuid_$(shell uname -s | tr "[:upper:]" "[:lower:]").c\
Expand Down
103 changes: 103 additions & 0 deletions src/common/badblock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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.
*/

/*
* badblock.c - implementation of the linux badblock query API
*/
#include "queue.h"
#include "file.h"
#include "os.h"
#include "out.h"
#include "sysfs.h"
#include "extent.h"
#include "badblock.h"
#include "plugin.h"
#ifndef _WIN32
#include "badblock_filesrc.h"
#include "badblock_poolset.h"
#endif

#define PLUGIN_BADBLOCK_SOURCE_VERSION 1

struct badblock_source {
struct badblock_iter *(*iter_from_file)(const char *file);
SLIST_ENTRY(badblock_source) e;
};

static SLIST_HEAD(, badblock_source) sources;

#ifndef _WIN32
/*
* badblock_register_source -- registers a new badblock source
*/
static void
badblock_register_source(const char *name, void *funcs, void *arg)
{
LOG(3, "%s", name);

struct badblock_source *bsrc = Malloc(sizeof(*bsrc));
if (bsrc == NULL) {
ERR("failed to allocate badblock source");
return;
}

bsrc->iter_from_file = funcs;

SLIST_INSERT_HEAD(&sources, bsrc, e);
}
#endif

/*
* badblock_new -- creates a new badblock iterator
*/
struct badblock_iter *
badblock_new(const char *path)
{
struct badblock_iter *iter;

if (SLIST_EMPTY(&sources)) {
#ifndef _WIN32
badblock_poolset_source_add();
badblock_file_source_add();
plugin_load("badblock_source", PLUGIN_BADBLOCK_SOURCE_VERSION,
badblock_register_source, NULL);
#endif
}

struct badblock_source *bsrc;
SLIST_FOREACH(bsrc, &sources, e) {
if ((iter = bsrc->iter_from_file(path)) != NULL)
break;
}

return iter;
}
60 changes: 60 additions & 0 deletions src/common/badblock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.
*/

/*
* badblock.h -- badblock query API
*/

#ifndef NVML_BADBLOCK_H
#define NVML_BADBLOCK_H 1

#include <stdint.h>
#include <sys/types.h>

struct badblock {
const char *file;
uint64_t offset;
uint64_t length;
};

struct badblock_iter {
struct {
int (*next)(struct badblock_iter *iter, struct badblock *b);
int (*clear)(struct badblock_iter *iter, struct badblock *b);
void (*del)(struct badblock_iter *iter);
} i_ops;
/* the rest of this structure is private */
};

struct badblock_iter *badblock_new(const char *path);

#endif /* NVML_BADBLOCK_H */
42 changes: 42 additions & 0 deletions src/common/badblock_filesrc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.
*/

/*
* badblock_filesrc.h - builtin file badblock source
*/

#ifndef NVML_BADBLOCK_FILESRC_LINUX_H
#define NVML_BADBLOCK_FILESRC_LINUX_H 1

void badblock_file_source_add(void);

#endif
Loading