|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
b3514a |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
b3514a |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
b3514a |
* of the License, or (at your option) any later version.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
b3514a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
b3514a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
b3514a |
* GNU General Public License for more details.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
b3514a |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
b3514a |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
b3514a |
* 02110-1301, USA.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/sysfs.c#5 $
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "sysfs.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include <linux/module.h>
|
|
Packit Service |
b3514a |
#include <linux/version.h>
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "dedupeIndex.h"
|
|
Packit Service |
b3514a |
#include "dmvdo.h"
|
|
Packit Service |
b3514a |
#include "logger.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
extern int defaultMaxRequestsActive;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
typedef struct vdoAttribute {
|
|
Packit Service |
b3514a |
struct attribute attr;
|
|
Packit Service |
b3514a |
ssize_t (*show)(struct kvdoDevice *d, struct attribute *attr, char *buf);
|
|
Packit Service |
b3514a |
ssize_t (*store)(struct kvdoDevice *d, const char *value, size_t count);
|
|
Packit Service |
b3514a |
// Location of value, if .show == showInt or showUInt or showBool.
|
|
Packit Service |
b3514a |
void *valuePtr;
|
|
Packit Service |
b3514a |
} VDOAttribute;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static char *statusStrings[] = {
|
|
Packit Service |
b3514a |
"UNINITIALIZED",
|
|
Packit Service |
b3514a |
"READY",
|
|
Packit Service |
b3514a |
"SHUTTING DOWN",
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t vdoStatusShow(struct kvdoDevice *device,
|
|
Packit Service |
b3514a |
struct attribute *attr,
|
|
Packit Service |
b3514a |
char *buf)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return sprintf(buf, "%s\n", statusStrings[device->status]);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t vdoLogLevelShow(struct kvdoDevice *device,
|
|
Packit Service |
b3514a |
struct attribute *attr,
|
|
Packit Service |
b3514a |
char *buf)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return sprintf(buf, "%s\n", priorityToString(getLogLevel()));
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t vdoLogLevelStore(struct kvdoDevice *device,
|
|
Packit Service |
b3514a |
const char *buf, size_t n)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
static char internalBuf[11];
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
if (n > 10) {
|
|
Packit Service |
b3514a |
return -EINVAL;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
memset(internalBuf, '\000', sizeof(internalBuf));
|
|
Packit Service |
b3514a |
memcpy(internalBuf, buf, n);
|
|
Packit Service |
b3514a |
if (internalBuf[n - 1] == '\n') {
|
|
Packit Service |
b3514a |
internalBuf[n - 1] = '\000';
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
setLogLevel(stringToPriority(internalBuf));
|
|
Packit Service |
b3514a |
return n;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t scanInt(const char *buf,
|
|
Packit Service |
b3514a |
size_t n,
|
|
Packit Service |
b3514a |
int *valuePtr,
|
|
Packit Service |
b3514a |
int minimum,
|
|
Packit Service |
b3514a |
int maximum)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
if (n > 12) {
|
|
Packit Service |
b3514a |
return -EINVAL;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
unsigned int value;
|
|
Packit Service |
b3514a |
if (sscanf(buf, "%d", &value) != 1) {
|
|
Packit Service |
b3514a |
return -EINVAL;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
if (value < minimum) {
|
|
Packit Service |
b3514a |
value = minimum;
|
|
Packit Service |
b3514a |
} else if (value > maximum) {
|
|
Packit Service |
b3514a |
value = maximum;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
*valuePtr = value;
|
|
Packit Service |
b3514a |
return n;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t showInt(struct kvdoDevice *device,
|
|
Packit Service |
b3514a |
struct attribute *attr,
|
|
Packit Service |
b3514a |
char *buf)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
VDOAttribute *vdoAttr = container_of(attr, VDOAttribute, attr);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
return sprintf(buf, "%d\n", *(int *)vdoAttr->valuePtr);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t scanUInt(const char *buf,
|
|
Packit Service |
b3514a |
size_t n,
|
|
Packit Service |
b3514a |
unsigned int *valuePtr,
|
|
Packit Service |
b3514a |
unsigned int minimum,
|
|
Packit Service |
b3514a |
unsigned int maximum)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
if (n > 12) {
|
|
Packit Service |
b3514a |
return -EINVAL;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
unsigned int value;
|
|
Packit Service |
b3514a |
if (sscanf(buf, "%u", &value) != 1) {
|
|
Packit Service |
b3514a |
return -EINVAL;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
if (value < minimum) {
|
|
Packit Service |
b3514a |
value = minimum;
|
|
Packit Service |
b3514a |
} else if (value > maximum) {
|
|
Packit Service |
b3514a |
value = maximum;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
*valuePtr = value;
|
|
Packit Service |
b3514a |
return n;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t showUInt(struct kvdoDevice *device,
|
|
Packit Service |
b3514a |
struct attribute *attr,
|
|
Packit Service |
b3514a |
char *buf)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
VDOAttribute *vdoAttr = container_of(attr, VDOAttribute, attr);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
return sprintf(buf, "%u\n", *(unsigned int *)vdoAttr->valuePtr);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t scanBool(const char *buf, size_t n, bool *valuePtr)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
unsigned int intValue = 0;
|
|
Packit Service |
b3514a |
n = scanUInt(buf, n, &intValue, 0, 1);
|
|
Packit Service |
b3514a |
if (n > 0) {
|
|
Packit Service |
b3514a |
*valuePtr = (intValue != 0);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
return n;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t showBool(struct kvdoDevice *device,
|
|
Packit Service |
b3514a |
struct attribute *attr,
|
|
Packit Service |
b3514a |
char *buf)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
VDOAttribute *vdoAttr = container_of(attr, VDOAttribute, attr);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
return sprintf(buf, "%u\n", *(bool *)vdoAttr->valuePtr ? 1 : 0);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t vdoTraceRecordingStore(struct kvdoDevice *device,
|
|
Packit Service |
b3514a |
const char *buf,
|
|
Packit Service |
b3514a |
size_t n)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return scanBool(buf, n, &traceRecording);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t vdoMaxReqActiveStore(struct kvdoDevice *device,
|
|
Packit Service |
b3514a |
const char *buf,
|
|
Packit Service |
b3514a |
size_t n)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* The base code has some hardcoded assumptions about the maximum
|
|
Packit Service |
b3514a |
* number of requests that can be in progress. Maybe someday we'll
|
|
Packit Service |
b3514a |
* do calculations with the actual number; for now, just make sure
|
|
Packit Service |
b3514a |
* the assumption holds.
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
return scanInt(buf, n, &defaultMaxRequestsActive, 1, MAXIMUM_USER_VIOS);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t vdoAlbireoTimeoutIntervalStore(struct kvdoDevice *device,
|
|
Packit Service |
b3514a |
const char *buf,
|
|
Packit Service |
b3514a |
size_t n)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
unsigned int value;
|
|
Packit Service |
b3514a |
ssize_t result = scanUInt(buf, n, &value, 0, UINT_MAX);
|
|
Packit Service |
b3514a |
if (result > 0) {
|
|
Packit Service |
b3514a |
setAlbireoTimeoutInterval(value);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t vdoMinAlbireoTimerIntervalStore(struct kvdoDevice *device,
|
|
Packit Service |
b3514a |
const char *buf,
|
|
Packit Service |
b3514a |
size_t n)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
unsigned int value;
|
|
Packit Service |
b3514a |
ssize_t result = scanUInt(buf, n, &value, 0, UINT_MAX);
|
|
Packit Service |
b3514a |
if (result > 0) {
|
|
Packit Service |
b3514a |
setMinAlbireoTimerInterval(value);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t vdoVersionShow(struct kvdoDevice *device,
|
|
Packit Service |
b3514a |
struct attribute *attr,
|
|
Packit Service |
b3514a |
char *buf)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return sprintf(buf, "%s\n", CURRENT_VERSION);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t vdoAttrShow(struct kobject *kobj,
|
|
Packit Service |
b3514a |
struct attribute *attr,
|
|
Packit Service |
b3514a |
char *buf)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
VDOAttribute *vdoAttr = container_of(attr, VDOAttribute, attr);
|
|
Packit Service |
b3514a |
if (vdoAttr->show == NULL) {
|
|
Packit Service |
b3514a |
return -EINVAL;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
struct kvdoDevice *device = container_of(kobj, struct kvdoDevice, kobj);
|
|
Packit Service |
b3514a |
return (*vdoAttr->show)(device, attr, buf);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static ssize_t vdoAttrStore(struct kobject *kobj,
|
|
Packit Service |
b3514a |
struct attribute *attr,
|
|
Packit Service |
b3514a |
const char *buf,
|
|
Packit Service |
b3514a |
size_t length)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
VDOAttribute *vdoAttr = container_of(attr, VDOAttribute, attr);
|
|
Packit Service |
b3514a |
if (vdoAttr->store == NULL) {
|
|
Packit Service |
b3514a |
return -EINVAL;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
struct kvdoDevice *device = container_of(kobj, struct kvdoDevice, kobj);
|
|
Packit Service |
b3514a |
return (*vdoAttr->store)(device, buf, length);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static VDOAttribute vdoStatusAttr = {
|
|
Packit Service |
b3514a |
.attr = { .name = "status", .mode = 0444, },
|
|
Packit Service |
b3514a |
.show = vdoStatusShow,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static VDOAttribute vdoLogLevelAttr = {
|
|
Packit Service |
b3514a |
.attr = {.name = "log_level", .mode = 0644, },
|
|
Packit Service |
b3514a |
.show = vdoLogLevelShow,
|
|
Packit Service |
b3514a |
.store = vdoLogLevelStore,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static VDOAttribute vdoMaxReqActiveAttr = {
|
|
Packit Service |
b3514a |
.attr = {.name = "max_requests_active", .mode = 0644, },
|
|
Packit Service |
b3514a |
.show = showInt,
|
|
Packit Service |
b3514a |
.store = vdoMaxReqActiveStore,
|
|
Packit Service |
b3514a |
.valuePtr = &defaultMaxRequestsActive,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static VDOAttribute vdoAlbireoTimeoutInterval = {
|
|
Packit Service |
b3514a |
.attr = {.name = "deduplication_timeout_interval", .mode = 0644, },
|
|
Packit Service |
b3514a |
.show = showUInt,
|
|
Packit Service |
b3514a |
.store = vdoAlbireoTimeoutIntervalStore,
|
|
Packit Service |
b3514a |
.valuePtr = &albireoTimeoutInterval,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static VDOAttribute vdoMinAlbireoTimerInterval = {
|
|
Packit Service |
b3514a |
.attr = {.name = "min_deduplication_timer_interval", .mode = 0644, },
|
|
Packit Service |
b3514a |
.show = showUInt,
|
|
Packit Service |
b3514a |
.store = vdoMinAlbireoTimerIntervalStore,
|
|
Packit Service |
b3514a |
.valuePtr = &minAlbireoTimerInterval,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static VDOAttribute vdoTraceRecording = {
|
|
Packit Service |
b3514a |
.attr = {.name = "trace_recording", .mode = 0644, },
|
|
Packit Service |
b3514a |
.show = showBool,
|
|
Packit Service |
b3514a |
.store = vdoTraceRecordingStore,
|
|
Packit Service |
b3514a |
.valuePtr = &traceRecording,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static VDOAttribute vdoVersionAttr = {
|
|
Packit Service |
b3514a |
.attr = { .name = "version", .mode = 0444, },
|
|
Packit Service |
b3514a |
.show = vdoVersionShow,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static struct attribute *defaultAttrs[] = {
|
|
Packit Service |
b3514a |
&vdoStatusAttr.attr,
|
|
Packit Service |
b3514a |
&vdoLogLevelAttr.attr,
|
|
Packit Service |
b3514a |
&vdoMaxReqActiveAttr.attr,
|
|
Packit Service |
b3514a |
&vdoAlbireoTimeoutInterval.attr,
|
|
Packit Service |
b3514a |
&vdoMinAlbireoTimerInterval.attr,
|
|
Packit Service |
b3514a |
&vdoTraceRecording.attr,
|
|
Packit Service |
b3514a |
&vdoVersionAttr.attr,
|
|
Packit Service |
b3514a |
NULL
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static struct sysfs_ops vdoSysfsOps = {
|
|
Packit Service |
b3514a |
.show = vdoAttrShow,
|
|
Packit Service |
b3514a |
.store = vdoAttrStore,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static void vdoRelease(struct kobject *kobj)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
struct kobj_type vdo_ktype = {
|
|
Packit Service |
b3514a |
.release = vdoRelease,
|
|
Packit Service |
b3514a |
.sysfs_ops = &vdoSysfsOps,
|
|
Packit Service |
b3514a |
.default_attrs = defaultAttrs,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int vdoInitSysfs(struct kobject *deviceObject)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
kobject_init(deviceObject, &vdo_ktype);
|
|
Packit Service |
b3514a |
int result = kobject_add(deviceObject, NULL, THIS_MODULE->name);
|
|
Packit Service |
b3514a |
if (result < 0) {
|
|
Packit Service |
b3514a |
logError("kobject_add failed with status %d", -result);
|
|
Packit Service |
b3514a |
kobject_put(deviceObject);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
logDebug("added sysfs objects");
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void vdoPutSysfs(struct kobject *deviceObject)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
kobject_put(deviceObject);
|
|
Packit Service |
b3514a |
}
|