Blame source/vdo/kernel/workQueueSysfs.c

Packit Service d40955
/*
Packit Service d40955
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service d40955
 *
Packit Service d40955
 * This program is free software; you can redistribute it and/or
Packit Service d40955
 * modify it under the terms of the GNU General Public License
Packit Service d40955
 * as published by the Free Software Foundation; either version 2
Packit Service d40955
 * of the License, or (at your option) any later version.
Packit Service d40955
 * 
Packit Service d40955
 * This program is distributed in the hope that it will be useful,
Packit Service d40955
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service d40955
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service d40955
 * GNU General Public License for more details.
Packit Service d40955
 * 
Packit Service d40955
 * You should have received a copy of the GNU General Public License
Packit Service d40955
 * along with this program; if not, write to the Free Software
Packit Service d40955
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service d40955
 * 02110-1301, USA. 
Packit Service d40955
 *
Packit Service d40955
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/workQueueSysfs.c#1 $
Packit Service d40955
 */
Packit Service d40955
Packit Service d40955
#include "workQueueSysfs.h"
Packit Service d40955
Packit Service d40955
#include <linux/kobject.h>
Packit Service d40955
Packit Service d40955
#include "logger.h"
Packit Service d40955
#include "memoryAlloc.h"
Packit Service d40955
Packit Service d40955
#include "workQueueInternals.h"
Packit Service d40955
Packit Service d40955
typedef struct workQueueAttribute {
Packit Service d40955
  struct attribute attr;
Packit Service d40955
  ssize_t (*show)(const KvdoWorkQueue *queue, char *buf);
Packit Service d40955
  ssize_t (*store)(KvdoWorkQueue *queue, const char *buf, size_t length);
Packit Service d40955
} WorkQueueAttribute;
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static ssize_t nameShow(const KvdoWorkQueue *queue, char *buf)
Packit Service d40955
{
Packit Service d40955
  return sprintf(buf, "%s\n", queue->name);
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static ssize_t pidShow(const KvdoWorkQueue *queue, char *buf)
Packit Service d40955
{
Packit Service d40955
  return sprintf(buf, "%ld\n",
Packit Service d40955
                 (long) atomic_read(&asConstSimpleWorkQueue(queue)->threadID));
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static ssize_t timesShow(const KvdoWorkQueue *queue, char *buf)
Packit Service d40955
{
Packit Service d40955
  return formatRunTimeStats(&asConstSimpleWorkQueue(queue)->stats, buf);
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static ssize_t typeShow(const KvdoWorkQueue *queue, char *buf)
Packit Service d40955
{
Packit Service d40955
  strcpy(buf, queue->roundRobinMode ? "round-robin\n" : "simple\n");
Packit Service d40955
  return strlen(buf);
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static ssize_t workFunctionsShow(const KvdoWorkQueue *queue, char *buf)
Packit Service d40955
{
Packit Service d40955
  const SimpleWorkQueue *simpleQueue = asConstSimpleWorkQueue(queue);
Packit Service d40955
  return formatWorkItemStats(&simpleQueue->stats.workItemStats, buf,
Packit Service d40955
                             PAGE_SIZE);
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static WorkQueueAttribute nameAttr = {
Packit Service d40955
  .attr = { .name = "name", .mode = 0444, },
Packit Service d40955
  .show = nameShow,
Packit Service d40955
};
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static WorkQueueAttribute pidAttr = {
Packit Service d40955
  .attr = { .name = "pid", .mode = 0444, },
Packit Service d40955
  .show = pidShow,
Packit Service d40955
};
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static WorkQueueAttribute timesAttr = {
Packit Service d40955
  .attr = { .name = "times", .mode = 0444 },
Packit Service d40955
  .show = timesShow,
Packit Service d40955
};
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static WorkQueueAttribute typeAttr = {
Packit Service d40955
  .attr = { .name = "type", .mode = 0444, },
Packit Service d40955
  .show = typeShow,
Packit Service d40955
};
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static WorkQueueAttribute workFunctionsAttr = {
Packit Service d40955
  .attr = { .name = "work_functions", .mode = 0444, },
Packit Service d40955
  .show = workFunctionsShow,
Packit Service d40955
};
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static struct attribute *simpleWorkQueueAttrs[] = {
Packit Service d40955
  &nameAttr.attr,
Packit Service d40955
  &pidAttr.attr,
Packit Service d40955
  &timesAttr.attr,
Packit Service d40955
  &typeAttr.attr,
Packit Service d40955
  &workFunctionsAttr.attr,
Packit Service d40955
  NULL,
Packit Service d40955
};
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static struct attribute *roundRobinWorkQueueAttrs[] = {
Packit Service d40955
  &nameAttr.attr,
Packit Service d40955
  &typeAttr.attr,
Packit Service d40955
  NULL,
Packit Service d40955
};
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static ssize_t workQueueAttrShow(struct kobject   *kobj,
Packit Service d40955
                                 struct attribute *attr,
Packit Service d40955
                                 char             *buf)
Packit Service d40955
{
Packit Service d40955
  WorkQueueAttribute *wqAttr = container_of(attr, WorkQueueAttribute, attr);
Packit Service d40955
  if (wqAttr->show == NULL) {
Packit Service d40955
    return -EINVAL;
Packit Service d40955
  }
Packit Service d40955
  KvdoWorkQueue *queue = container_of(kobj, KvdoWorkQueue, kobj);
Packit Service d40955
  return wqAttr->show(queue, buf);
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static ssize_t workQueueAttrStore(struct kobject   *kobj,
Packit Service d40955
                                  struct attribute *attr,
Packit Service d40955
                                  const char       *buf,
Packit Service d40955
                                  size_t            length)
Packit Service d40955
{
Packit Service d40955
  WorkQueueAttribute *wqAttr = container_of(attr, WorkQueueAttribute, attr);
Packit Service d40955
  if (wqAttr->store == NULL) {
Packit Service d40955
    return -EINVAL;
Packit Service d40955
  }
Packit Service d40955
  KvdoWorkQueue *queue = container_of(kobj, KvdoWorkQueue, kobj);
Packit Service d40955
  return wqAttr->store(queue, buf, length);
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static struct sysfs_ops workQueueSysfsOps = {
Packit Service d40955
  .show  = workQueueAttrShow,
Packit Service d40955
  .store = workQueueAttrStore,
Packit Service d40955
};
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
static void workQueueRelease(struct kobject *kobj)
Packit Service d40955
{
Packit Service d40955
  KvdoWorkQueue *queue = container_of(kobj, KvdoWorkQueue, kobj);
Packit Service d40955
  FREE(queue->name);
Packit Service d40955
  if (queue->roundRobinMode) {
Packit Service d40955
    FREE(asRoundRobinWorkQueue(queue));
Packit Service d40955
  } else {
Packit Service d40955
    FREE(asSimpleWorkQueue(queue));
Packit Service d40955
  }
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
struct kobj_type simpleWorkQueueKobjType = {
Packit Service d40955
  .default_attrs = simpleWorkQueueAttrs,
Packit Service d40955
  .release       = workQueueRelease,
Packit Service d40955
  .sysfs_ops     = &workQueueSysfsOps,
Packit Service d40955
};
Packit Service d40955
Packit Service d40955
/**********************************************************************/
Packit Service d40955
struct kobj_type roundRobinWorkQueueKobjType = {
Packit Service d40955
  .default_attrs = roundRobinWorkQueueAttrs,
Packit Service d40955
  .release       = workQueueRelease,
Packit Service d40955
  .sysfs_ops     = &workQueueSysfsOps,
Packit Service d40955
};