configfs: implement binary attributes

ConfigFS lacked binary attributes up until now. This patch
introduces support for binary attributes in a somewhat similar
manner of sysfs binary attributes albeit with changes that
fit the configfs usage model.

Problems that configfs binary attributes fix are everything that
requires a binary blob as part of the configuration of a resource,
such as bitstream loading for FPGAs, DTBs for dynamically created
devices etc.

Look at Documentation/filesystems/configfs/configfs.txt for internals
and howto use them.

This patch is against linux-next as of today that contains
Christoph's configfs rework.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
[hch: folded a fix from Geert Uytterhoeven <geert+renesas@glider.be>]
[hch: a few tiny updates based on review feedback]
Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Pantelis Antoniou 2015-10-22 23:30:04 +03:00 committed by Christoph Hellwig
parent 4ef7675344
commit 03607ace80
6 changed files with 373 additions and 21 deletions

View file

@ -51,6 +51,7 @@ struct module;
struct configfs_item_operations;
struct configfs_group_operations;
struct configfs_attribute;
struct configfs_bin_attribute;
struct configfs_subsystem;
struct config_item {
@ -84,6 +85,7 @@ struct config_item_type {
struct configfs_item_operations *ct_item_ops;
struct configfs_group_operations *ct_group_ops;
struct configfs_attribute **ct_attrs;
struct configfs_bin_attribute **ct_bin_attrs;
};
/**
@ -154,6 +156,54 @@ static struct configfs_attribute _pfx##attr_##_name = { \
.store = _pfx##_name##_store, \
}
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) \
static struct configfs_attribute _pfx##attr_##_name = { \
.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) \
static struct configfs_attribute _pfx##attr_##_name = { \
.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, \
}
/*
* If allow_link() exists, the item can symlink(2) out to other
* items. If the item is a group, it may support mkdir(2).