Skip to content

Commit 420d12d

Browse files
committed
Merge tag 'configfs-for-linus' of git://git.infradead.org/users/hch/configfs
Pull configfs updates from Christoph Hellwig: "I'm assisting Joel as co-maintainer and patch monkey now, and you will see pull reuquests from me for a while. Besides the MAINTAINERS update there is just a single change, which adds support for binary attributes to configfs, which are very similar to the sysfs binary attributes. Thanks to Pantelis Antoniou! You will see another actually bigger set of configfs changes in the SCSI target pull from Nic - those were merged before this new tree even existed" * tag 'configfs-for-linus' of git://git.infradead.org/users/hch/configfs: configfs: add myself as co-maintainer, updated git tree configfs: implement binary attributes
2 parents 4d58967 + 1609bac commit 420d12d

File tree

7 files changed

+376
-23
lines changed

7 files changed

+376
-23
lines changed

Documentation/filesystems/configfs/configfs.txt

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,27 @@ configfs tree is always there, whether mounted on /config or not.
5151
An item is created via mkdir(2). The item's attributes will also
5252
appear at this time. readdir(3) can determine what the attributes are,
5353
read(2) can query their default values, and write(2) can store new
54-
values. Like sysfs, attributes should be ASCII text files, preferably
55-
with only one value per file. The same efficiency caveats from sysfs
56-
apply. Don't mix more than one attribute in one attribute file.
57-
58-
Like sysfs, configfs expects write(2) to store the entire buffer at
59-
once. When writing to configfs attributes, userspace processes should
60-
first read the entire file, modify the portions they wish to change, and
61-
then write the entire buffer back. Attribute files have a maximum size
62-
of one page (PAGE_SIZE, 4096 on i386).
54+
values. Don't mix more than one attribute in one attribute file.
55+
56+
There are two types of configfs attributes:
57+
58+
* Normal attributes, which similar to sysfs attributes, are small ASCII text
59+
files, with a maximum size of one page (PAGE_SIZE, 4096 on i386). Preferably
60+
only one value per file should be used, and the same caveats from sysfs apply.
61+
Configfs expects write(2) to store the entire buffer at once. When writing to
62+
normal configfs attributes, userspace processes should first read the entire
63+
file, modify the portions they wish to change, and then write the entire
64+
buffer back.
65+
66+
* Binary attributes, which are somewhat similar to sysfs binary attributes,
67+
but with a few slight changes to semantics. The PAGE_SIZE limitation does not
68+
apply, but the whole binary item must fit in single kernel vmalloc'ed buffer.
69+
The write(2) calls from user space are buffered, and the attributes'
70+
write_bin_attribute method will be invoked on the final close, therefore it is
71+
imperative for user-space to check the return code of close(2) in order to
72+
verify that the operation finished successfully.
73+
To avoid a malicious user OOMing the kernel, there's a per-binary attribute
74+
maximum buffer value.
6375

6476
When an item needs to be destroyed, remove it with rmdir(2). An
6577
item cannot be destroyed if any other item has a link to it (via
@@ -171,6 +183,7 @@ among other things. For that, it needs a type.
171183
struct configfs_item_operations *ct_item_ops;
172184
struct configfs_group_operations *ct_group_ops;
173185
struct configfs_attribute **ct_attrs;
186+
struct configfs_bin_attribute **ct_bin_attrs;
174187
};
175188

176189
The most basic function of a config_item_type is to define what
@@ -201,6 +214,32 @@ be called whenever userspace asks for a read(2) on the attribute. If an
201214
attribute is writable and provides a ->store method, that method will be
202215
be called whenever userspace asks for a write(2) on the attribute.
203216

217+
[struct configfs_bin_attribute]
218+
219+
struct configfs_attribute {
220+
struct configfs_attribute cb_attr;
221+
void *cb_private;
222+
size_t cb_max_size;
223+
};
224+
225+
The binary attribute is used when the one needs to use binary blob to
226+
appear as the contents of a file in the item's configfs directory.
227+
To do so add the binary attribute to the NULL-terminated array
228+
config_item_type->ct_bin_attrs, and the item appears in configfs, the
229+
attribute file will appear with the configfs_bin_attribute->cb_attr.ca_name
230+
filename. configfs_bin_attribute->cb_attr.ca_mode specifies the file
231+
permissions.
232+
The cb_private member is provided for use by the driver, while the
233+
cb_max_size member specifies the maximum amount of vmalloc buffer
234+
to be used.
235+
236+
If binary attribute is readable and the config_item provides a
237+
ct_item_ops->read_bin_attribute() method, that method will be called
238+
whenever userspace asks for a read(2) on the attribute. The converse
239+
will happen for write(2). The reads/writes are bufferred so only a
240+
single read/write will occur; the attributes' need not concern itself
241+
with it.
242+
204243
[struct config_group]
205244

206245
A config_item cannot live in a vacuum. The only way one can be created

MAINTAINERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2938,7 +2938,8 @@ F: drivers/usb/atm/cxacru.c
29382938

29392939
CONFIGFS
29402940
M: Joel Becker <[email protected]>
2941-
T: git git://git.kernel.org/pub/scm/linux/kernel/git/jlbec/configfs.git
2941+
M: Christoph Hellwig <[email protected]>
2942+
T: git git://git.infradead.org/users/hch/configfs.git
29422943
S: Supported
29432944
F: fs/configfs/
29442945
F: include/linux/configfs.h

fs/configfs/configfs_internal.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ struct configfs_dirent {
5353
#define CONFIGFS_ROOT 0x0001
5454
#define CONFIGFS_DIR 0x0002
5555
#define CONFIGFS_ITEM_ATTR 0x0004
56+
#define CONFIGFS_ITEM_BIN_ATTR 0x0008
5657
#define CONFIGFS_ITEM_LINK 0x0020
5758
#define CONFIGFS_USET_DIR 0x0040
5859
#define CONFIGFS_USET_DEFAULT 0x0080
5960
#define CONFIGFS_USET_DROPPING 0x0100
6061
#define CONFIGFS_USET_IN_MKDIR 0x0200
6162
#define CONFIGFS_USET_CREATING 0x0400
62-
#define CONFIGFS_NOT_PINNED (CONFIGFS_ITEM_ATTR)
63+
#define CONFIGFS_NOT_PINNED (CONFIGFS_ITEM_ATTR | CONFIGFS_ITEM_BIN_ATTR)
6364

6465
extern struct mutex configfs_symlink_mutex;
6566
extern spinlock_t configfs_dirent_lock;
@@ -72,6 +73,8 @@ extern struct inode * configfs_new_inode(umode_t mode, struct configfs_dirent *,
7273
extern int configfs_create(struct dentry *, umode_t mode, void (*init)(struct inode *));
7374

7475
extern int configfs_create_file(struct config_item *, const struct configfs_attribute *);
76+
extern int configfs_create_bin_file(struct config_item *,
77+
const struct configfs_bin_attribute *);
7578
extern int configfs_make_dirent(struct configfs_dirent *,
7679
struct dentry *, void *, umode_t, int);
7780
extern int configfs_dirent_is_ready(struct configfs_dirent *);
@@ -88,7 +91,7 @@ extern void configfs_release_fs(void);
8891
extern struct rw_semaphore configfs_rename_sem;
8992
extern const struct file_operations configfs_dir_operations;
9093
extern const struct file_operations configfs_file_operations;
91-
extern const struct file_operations bin_fops;
94+
extern const struct file_operations configfs_bin_file_operations;
9295
extern const struct inode_operations configfs_dir_inode_operations;
9396
extern const struct inode_operations configfs_root_inode_operations;
9497
extern const struct inode_operations configfs_symlink_inode_operations;
@@ -119,6 +122,13 @@ static inline struct configfs_attribute * to_attr(struct dentry * dentry)
119122
return ((struct configfs_attribute *) sd->s_element);
120123
}
121124

125+
static inline struct configfs_bin_attribute *to_bin_attr(struct dentry *dentry)
126+
{
127+
struct configfs_attribute *attr = to_attr(dentry);
128+
129+
return container_of(attr, struct configfs_bin_attribute, cb_attr);
130+
}
131+
122132
static inline struct config_item *configfs_get_config_item(struct dentry *dentry)
123133
{
124134
struct config_item * item = NULL;

fs/configfs/dir.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ static void configfs_init_file(struct inode * inode)
255255
inode->i_fop = &configfs_file_operations;
256256
}
257257

258+
static void configfs_init_bin_file(struct inode *inode)
259+
{
260+
inode->i_size = 0;
261+
inode->i_fop = &configfs_bin_file_operations;
262+
}
263+
258264
static void init_symlink(struct inode * inode)
259265
{
260266
inode->i_op = &configfs_symlink_inode_operations;
@@ -423,7 +429,9 @@ static int configfs_attach_attr(struct configfs_dirent * sd, struct dentry * den
423429
spin_unlock(&configfs_dirent_lock);
424430

425431
error = configfs_create(dentry, (attr->ca_mode & S_IALLUGO) | S_IFREG,
426-
configfs_init_file);
432+
(sd->s_type & CONFIGFS_ITEM_BIN_ATTR) ?
433+
configfs_init_bin_file :
434+
configfs_init_file);
427435
if (error) {
428436
configfs_put(sd);
429437
return error;
@@ -583,6 +591,7 @@ static int populate_attrs(struct config_item *item)
583591
{
584592
struct config_item_type *t = item->ci_type;
585593
struct configfs_attribute *attr;
594+
struct configfs_bin_attribute *bin_attr;
586595
int error = 0;
587596
int i;
588597

@@ -594,6 +603,13 @@ static int populate_attrs(struct config_item *item)
594603
break;
595604
}
596605
}
606+
if (t->ct_bin_attrs) {
607+
for (i = 0; (bin_attr = t->ct_bin_attrs[i]) != NULL; i++) {
608+
error = configfs_create_bin_file(item, bin_attr);
609+
if (error)
610+
break;
611+
}
612+
}
597613

598614
if (error)
599615
detach_attrs(item);

0 commit comments

Comments
 (0)