2019-05-24 10:04:05 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2005-12-15 22:29:43 +00:00
|
|
|
/* -*- mode: c; c-basic-offset: 8; -*-
|
|
|
|
* vim: noexpandtab sw=8 ts=8 sts=0:
|
|
|
|
*
|
|
|
|
* configfs.h - definitions for the device driver filesystem
|
|
|
|
*
|
|
|
|
* Based on sysfs:
|
|
|
|
* sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
|
|
|
|
*
|
|
|
|
* Based on kobject.h:
|
|
|
|
* Copyright (c) 2002-2003 Patrick Mochel
|
|
|
|
* Copyright (c) 2002-2003 Open Source Development Labs
|
|
|
|
*
|
|
|
|
* configfs Copyright (C) 2005 Oracle. All rights reserved.
|
|
|
|
*
|
2009-09-23 22:56:17 +00:00
|
|
|
* Please read Documentation/filesystems/configfs/configfs.txt before using
|
|
|
|
* the configfs interface, ESPECIALLY the parts about reference counts and
|
2005-12-15 22:29:43 +00:00
|
|
|
* item destructors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CONFIGFS_H_
|
|
|
|
#define _CONFIGFS_H_
|
|
|
|
|
2016-11-14 23:53:05 +00:00
|
|
|
#include <linux/stat.h> /* S_IRUGO */
|
|
|
|
#include <linux/types.h> /* ssize_t */
|
|
|
|
#include <linux/list.h> /* struct list_head */
|
|
|
|
#include <linux/kref.h> /* struct kref */
|
|
|
|
#include <linux/mutex.h> /* struct mutex */
|
2005-12-15 22:29:43 +00:00
|
|
|
|
|
|
|
#define CONFIGFS_ITEM_NAME_LEN 20
|
|
|
|
|
|
|
|
struct module;
|
|
|
|
|
|
|
|
struct configfs_item_operations;
|
|
|
|
struct configfs_group_operations;
|
|
|
|
struct configfs_attribute;
|
2015-10-22 20:30:04 +00:00
|
|
|
struct configfs_bin_attribute;
|
2005-12-15 22:29:43 +00:00
|
|
|
struct configfs_subsystem;
|
|
|
|
|
|
|
|
struct config_item {
|
|
|
|
char *ci_name;
|
|
|
|
char ci_namebuf[CONFIGFS_ITEM_NAME_LEN];
|
|
|
|
struct kref ci_kref;
|
|
|
|
struct list_head ci_entry;
|
|
|
|
struct config_item *ci_parent;
|
|
|
|
struct config_group *ci_group;
|
2017-10-16 15:18:40 +00:00
|
|
|
const struct config_item_type *ci_type;
|
2005-12-15 22:29:43 +00:00
|
|
|
struct dentry *ci_dentry;
|
|
|
|
};
|
|
|
|
|
2015-07-17 23:23:42 +00:00
|
|
|
extern __printf(2, 3)
|
|
|
|
int config_item_set_name(struct config_item *, const char *, ...);
|
2005-12-15 22:29:43 +00:00
|
|
|
|
|
|
|
static inline char *config_item_name(struct config_item * item)
|
|
|
|
{
|
|
|
|
return item->ci_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void config_item_init_type_name(struct config_item *item,
|
|
|
|
const char *name,
|
2017-10-16 15:18:40 +00:00
|
|
|
const struct config_item_type *type);
|
2005-12-15 22:29:43 +00:00
|
|
|
|
2017-02-10 01:28:50 +00:00
|
|
|
extern struct config_item *config_item_get(struct config_item *);
|
|
|
|
extern struct config_item *config_item_get_unless_zero(struct config_item *);
|
2005-12-15 22:29:43 +00:00
|
|
|
extern void config_item_put(struct config_item *);
|
|
|
|
|
|
|
|
struct config_item_type {
|
|
|
|
struct module *ct_owner;
|
|
|
|
struct configfs_item_operations *ct_item_ops;
|
|
|
|
struct configfs_group_operations *ct_group_ops;
|
|
|
|
struct configfs_attribute **ct_attrs;
|
2015-10-22 20:30:04 +00:00
|
|
|
struct configfs_bin_attribute **ct_bin_attrs;
|
2005-12-15 22:29:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* group - a group of config_items of a specific type, belonging
|
|
|
|
* to a specific subsystem.
|
|
|
|
*/
|
|
|
|
struct config_group {
|
|
|
|
struct config_item cg_item;
|
|
|
|
struct list_head cg_children;
|
|
|
|
struct configfs_subsystem *cg_subsys;
|
2016-02-26 10:02:14 +00:00
|
|
|
struct list_head default_groups;
|
|
|
|
struct list_head group_entry;
|
2005-12-15 22:29:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern void config_group_init(struct config_group *group);
|
|
|
|
extern void config_group_init_type_name(struct config_group *group,
|
|
|
|
const char *name,
|
2017-10-16 15:18:40 +00:00
|
|
|
const struct config_item_type *type);
|
2005-12-15 22:29:43 +00:00
|
|
|
|
|
|
|
static inline struct config_group *to_config_group(struct config_item *item)
|
|
|
|
{
|
|
|
|
return item ? container_of(item,struct config_group,cg_item) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct config_group *config_group_get(struct config_group *group)
|
|
|
|
{
|
|
|
|
return group ? to_config_group(config_item_get(&group->cg_item)) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void config_group_put(struct config_group *group)
|
|
|
|
{
|
|
|
|
config_item_put(&group->cg_item);
|
|
|
|
}
|
|
|
|
|
[PATCH] configfs+dlm: Rename config_group_find_obj and state semantics clearly
Configfs being based upon sysfs code, config_group_find_obj() is probably
so named because of the similar kset_find_obj() in sysfs. However,
"kobject"s in sysfs become "config_item"s in configfs, so let's call it
config_group_find_item() instead, for sake of uniformity, and make
corresponding change in the users of this function.
BTW a crucial difference between kset_find_obj and config_group_find_item
is in locking expectations. kset_find_obj does its locking by itself, but
config_group_find_item expects the *caller* to do the locking. The reason
for this: kset's have their own locks, config_group's don't but instead
rely on the subsystem mutex. And, subsystem needn't necessarily be around
when config_group_find_item() is called.
So let's state these locking semantics explicitly, and rectify the comment,
otherwise bugs could continue to occur in future, as they did in the past
(refer commit d82b8191e238 in gfs2-2.6-fixes.git).
[ I also took the opportunity to fix some bad whitespace and
double-empty lines. --Joel ]
[ Conflict in fs/dlm/config.c with commit
3168b0780d06ace875696f8a648d04d6089654e5 manually resolved. --Mark ]
Signed-off-by: Satyam Sharma <ssatyam@cse.iitk.ac.in>
Cc: David Teigland <teigland@redhat.com>
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
2007-07-04 11:07:16 +00:00
|
|
|
extern struct config_item *config_group_find_item(struct config_group *,
|
|
|
|
const char *);
|
2005-12-15 22:29:43 +00:00
|
|
|
|
|
|
|
|
2016-02-26 10:02:14 +00:00
|
|
|
static inline void configfs_add_default_group(struct config_group *new_group,
|
|
|
|
struct config_group *group)
|
|
|
|
{
|
|
|
|
list_add_tail(&new_group->group_entry, &group->default_groups);
|
|
|
|
}
|
|
|
|
|
2005-12-15 22:29:43 +00:00
|
|
|
struct configfs_attribute {
|
2006-01-25 21:31:07 +00:00
|
|
|
const char *ca_name;
|
2005-12-15 22:29:43 +00:00
|
|
|
struct module *ca_owner;
|
2011-07-25 04:05:26 +00:00
|
|
|
umode_t ca_mode;
|
2015-10-03 13:32:37 +00:00
|
|
|
ssize_t (*show)(struct config_item *, char *);
|
|
|
|
ssize_t (*store)(struct config_item *, const char *, size_t);
|
2005-12-15 22:29:43 +00:00
|
|
|
};
|
|
|
|
|
2015-10-03 13:32:37 +00:00
|
|
|
#define CONFIGFS_ATTR(_pfx, _name) \
|
|
|
|
static struct configfs_attribute _pfx##attr_##_name = { \
|
|
|
|
.ca_name = __stringify(_name), \
|
|
|
|
.ca_mode = S_IRUGO | S_IWUSR, \
|
|
|
|
.ca_owner = THIS_MODULE, \
|
|
|
|
.show = _pfx##_name##_show, \
|
|
|
|
.store = _pfx##_name##_store, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CONFIGFS_ATTR_RO(_pfx, _name) \
|
|
|
|
static struct configfs_attribute _pfx##attr_##_name = { \
|
|
|
|
.ca_name = __stringify(_name), \
|
|
|
|
.ca_mode = S_IRUGO, \
|
|
|
|
.ca_owner = THIS_MODULE, \
|
|
|
|
.show = _pfx##_name##_show, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CONFIGFS_ATTR_WO(_pfx, _name) \
|
|
|
|
static struct configfs_attribute _pfx##attr_##_name = { \
|
|
|
|
.ca_name = __stringify(_name), \
|
|
|
|
.ca_mode = S_IWUSR, \
|
|
|
|
.ca_owner = THIS_MODULE, \
|
|
|
|
.store = _pfx##_name##_store, \
|
|
|
|
}
|
|
|
|
|
2015-10-22 20:30:04 +00:00
|
|
|
struct file;
|
|
|
|
struct vm_area_struct;
|
|
|
|
|
|
|
|
struct configfs_bin_attribute {
|
|
|
|
struct configfs_attribute cb_attr; /* std. attribute */
|
|
|
|
void *cb_private; /* for user */
|
|
|
|
size_t cb_max_size; /* max core size */
|
|
|
|
ssize_t (*read)(struct config_item *, void *, size_t);
|
|
|
|
ssize_t (*write)(struct config_item *, const void *, size_t);
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz) \
|
|
|
|
static struct configfs_bin_attribute _pfx##attr_##_name = { \
|
|
|
|
.cb_attr = { \
|
|
|
|
.ca_name = __stringify(_name), \
|
|
|
|
.ca_mode = S_IRUGO | S_IWUSR, \
|
|
|
|
.ca_owner = THIS_MODULE, \
|
|
|
|
}, \
|
|
|
|
.cb_private = _priv, \
|
|
|
|
.cb_max_size = _maxsz, \
|
|
|
|
.read = _pfx##_name##_read, \
|
|
|
|
.write = _pfx##_name##_write, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz) \
|
2016-03-23 12:14:48 +00:00
|
|
|
static struct configfs_bin_attribute _pfx##attr_##_name = { \
|
2015-10-22 20:30:04 +00:00
|
|
|
.cb_attr = { \
|
|
|
|
.ca_name = __stringify(_name), \
|
|
|
|
.ca_mode = S_IRUGO, \
|
|
|
|
.ca_owner = THIS_MODULE, \
|
|
|
|
}, \
|
|
|
|
.cb_private = _priv, \
|
|
|
|
.cb_max_size = _maxsz, \
|
|
|
|
.read = _pfx##_name##_read, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz) \
|
2016-03-23 12:14:48 +00:00
|
|
|
static struct configfs_bin_attribute _pfx##attr_##_name = { \
|
2015-10-22 20:30:04 +00:00
|
|
|
.cb_attr = { \
|
|
|
|
.ca_name = __stringify(_name), \
|
|
|
|
.ca_mode = S_IWUSR, \
|
|
|
|
.ca_owner = THIS_MODULE, \
|
|
|
|
}, \
|
|
|
|
.cb_private = _priv, \
|
|
|
|
.cb_max_size = _maxsz, \
|
|
|
|
.write = _pfx##_name##_write, \
|
|
|
|
}
|
|
|
|
|
2005-12-15 22:29:43 +00:00
|
|
|
/*
|
|
|
|
* If allow_link() exists, the item can symlink(2) out to other
|
|
|
|
* items. If the item is a group, it may support mkdir(2).
|
|
|
|
* Groups supply one of make_group() and make_item(). If the
|
|
|
|
* group supports make_group(), one can create group children. If it
|
2008-07-17 22:21:29 +00:00
|
|
|
* supports make_item(), one can create config_item children. make_group()
|
|
|
|
* and make_item() return ERR_PTR() on errors. If it has
|
2005-12-15 22:29:43 +00:00
|
|
|
* default_groups on group->default_groups, it has automatically created
|
|
|
|
* group children. default_groups may coexist alongsize make_group() or
|
|
|
|
* make_item(), but if the group wishes to have only default_groups
|
|
|
|
* children (disallowing mkdir(2)), it need not provide either function.
|
2011-03-31 01:57:33 +00:00
|
|
|
* If the group has commit(), it supports pending and committed (active)
|
2005-12-15 22:29:43 +00:00
|
|
|
* items.
|
|
|
|
*/
|
|
|
|
struct configfs_item_operations {
|
|
|
|
void (*release)(struct config_item *);
|
|
|
|
int (*allow_link)(struct config_item *src, struct config_item *target);
|
2016-11-28 12:22:42 +00:00
|
|
|
void (*drop_link)(struct config_item *src, struct config_item *target);
|
2005-12-15 22:29:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct configfs_group_operations {
|
2008-07-17 21:53:48 +00:00
|
|
|
struct config_item *(*make_item)(struct config_group *group, const char *name);
|
|
|
|
struct config_group *(*make_group)(struct config_group *group, const char *name);
|
2005-12-15 22:29:43 +00:00
|
|
|
int (*commit_item)(struct config_item *item);
|
2006-10-07 00:33:23 +00:00
|
|
|
void (*disconnect_notify)(struct config_group *group, struct config_item *item);
|
2005-12-15 22:29:43 +00:00
|
|
|
void (*drop_item)(struct config_group *group, struct config_item *item);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct configfs_subsystem {
|
|
|
|
struct config_group su_group;
|
2007-07-07 06:33:17 +00:00
|
|
|
struct mutex su_mutex;
|
2005-12-15 22:29:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct configfs_subsystem *to_configfs_subsystem(struct config_group *group)
|
|
|
|
{
|
|
|
|
return group ?
|
|
|
|
container_of(group, struct configfs_subsystem, su_group) :
|
|
|
|
NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int configfs_register_subsystem(struct configfs_subsystem *subsys);
|
|
|
|
void configfs_unregister_subsystem(struct configfs_subsystem *subsys);
|
|
|
|
|
2015-11-20 23:56:53 +00:00
|
|
|
int configfs_register_group(struct config_group *parent_group,
|
|
|
|
struct config_group *group);
|
|
|
|
void configfs_unregister_group(struct config_group *group);
|
|
|
|
|
2016-02-26 10:02:14 +00:00
|
|
|
void configfs_remove_default_groups(struct config_group *group);
|
|
|
|
|
2015-11-20 23:56:53 +00:00
|
|
|
struct config_group *
|
|
|
|
configfs_register_default_group(struct config_group *parent_group,
|
|
|
|
const char *name,
|
2017-10-16 15:18:40 +00:00
|
|
|
const struct config_item_type *item_type);
|
2015-11-20 23:56:53 +00:00
|
|
|
void configfs_unregister_default_group(struct config_group *group);
|
|
|
|
|
configfs: config item dependancies.
Sometimes other drivers depend on particular configfs items. For
example, ocfs2 mounts depend on a heartbeat region item. If that
region item is removed with rmdir(2), the ocfs2 mount must BUG or go
readonly. Not happy.
This provides two additional API calls: configfs_depend_item() and
configfs_undepend_item(). A client driver can call
configfs_depend_item() on an existing item to tell configfs that it is
depended on. configfs will then return -EBUSY from rmdir(2) for that
item. When the item is no longer depended on, the client driver calls
configfs_undepend_item() on it.
These API cannot be called underneath any configfs callbacks, as
they will conflict. They can block and allocate. A client driver
probably shouldn't calling them of its own gumption. Rather it should
be providing an API that external subsystems call.
How does this work? Imagine the ocfs2 mount process. When it mounts,
it asks for a heart region item. This is done via a call into the
heartbeat code. Inside the heartbeat code, the region item is looked
up. Here, the heartbeat code calls configfs_depend_item(). If it
succeeds, then heartbeat knows the region is safe to give to ocfs2.
If it fails, it was being torn down anyway, and heartbeat can gracefully
pass up an error.
[ Fixed some bad whitespace in configfs.txt. --Mark ]
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
2007-06-19 01:06:09 +00:00
|
|
|
/* These functions can sleep and can alloc with GFP_KERNEL */
|
|
|
|
/* WARNING: These cannot be called underneath configfs callbacks!! */
|
2015-12-11 15:06:09 +00:00
|
|
|
int configfs_depend_item(struct configfs_subsystem *subsys,
|
|
|
|
struct config_item *target);
|
|
|
|
void configfs_undepend_item(struct config_item *target);
|
configfs: config item dependancies.
Sometimes other drivers depend on particular configfs items. For
example, ocfs2 mounts depend on a heartbeat region item. If that
region item is removed with rmdir(2), the ocfs2 mount must BUG or go
readonly. Not happy.
This provides two additional API calls: configfs_depend_item() and
configfs_undepend_item(). A client driver can call
configfs_depend_item() on an existing item to tell configfs that it is
depended on. configfs will then return -EBUSY from rmdir(2) for that
item. When the item is no longer depended on, the client driver calls
configfs_undepend_item() on it.
These API cannot be called underneath any configfs callbacks, as
they will conflict. They can block and allocate. A client driver
probably shouldn't calling them of its own gumption. Rather it should
be providing an API that external subsystems call.
How does this work? Imagine the ocfs2 mount process. When it mounts,
it asks for a heart region item. This is done via a call into the
heartbeat code. Inside the heartbeat code, the region item is looked
up. Here, the heartbeat code calls configfs_depend_item(). If it
succeeds, then heartbeat knows the region is safe to give to ocfs2.
If it fails, it was being torn down anyway, and heartbeat can gracefully
pass up an error.
[ Fixed some bad whitespace in configfs.txt. --Mark ]
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
2007-06-19 01:06:09 +00:00
|
|
|
|
2015-12-11 15:06:12 +00:00
|
|
|
/*
|
|
|
|
* These functions can sleep and can alloc with GFP_KERNEL
|
|
|
|
* NOTE: These should be called only underneath configfs callbacks.
|
|
|
|
* NOTE: First parameter is a caller's subsystem, not target's.
|
|
|
|
* WARNING: These cannot be called on newly created item
|
|
|
|
* (in make_group()/make_item() callback)
|
|
|
|
*/
|
|
|
|
int configfs_depend_item_unlocked(struct configfs_subsystem *caller_subsys,
|
|
|
|
struct config_item *target);
|
|
|
|
|
|
|
|
|
|
|
|
static inline void configfs_undepend_item_unlocked(struct config_item *target)
|
|
|
|
{
|
|
|
|
configfs_undepend_item(target);
|
|
|
|
}
|
configfs: config item dependancies.
Sometimes other drivers depend on particular configfs items. For
example, ocfs2 mounts depend on a heartbeat region item. If that
region item is removed with rmdir(2), the ocfs2 mount must BUG or go
readonly. Not happy.
This provides two additional API calls: configfs_depend_item() and
configfs_undepend_item(). A client driver can call
configfs_depend_item() on an existing item to tell configfs that it is
depended on. configfs will then return -EBUSY from rmdir(2) for that
item. When the item is no longer depended on, the client driver calls
configfs_undepend_item() on it.
These API cannot be called underneath any configfs callbacks, as
they will conflict. They can block and allocate. A client driver
probably shouldn't calling them of its own gumption. Rather it should
be providing an API that external subsystems call.
How does this work? Imagine the ocfs2 mount process. When it mounts,
it asks for a heart region item. This is done via a call into the
heartbeat code. Inside the heartbeat code, the region item is looked
up. Here, the heartbeat code calls configfs_depend_item(). If it
succeeds, then heartbeat knows the region is safe to give to ocfs2.
If it fails, it was being torn down anyway, and heartbeat can gracefully
pass up an error.
[ Fixed some bad whitespace in configfs.txt. --Mark ]
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
2007-06-19 01:06:09 +00:00
|
|
|
|
2005-12-15 22:29:43 +00:00
|
|
|
#endif /* _CONFIGFS_H_ */
|