aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/filesystems
diff options
context:
space:
mode:
authorPantelis Antoniou <pantelis.antoniou@konsulko.com>2015-10-22 16:30:04 -0400
committerChristoph Hellwig <hch@lst.de>2016-01-04 06:31:46 -0500
commit03607ace807b414eab46323c794b6fb8fcc2d48c (patch)
treea192ae4376e5db9eb02e2563d3c12a7312e677ba /Documentation/filesystems
parent4ef7675344d687a0ef5b0d7c0cee12da005870c0 (diff)
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>
Diffstat (limited to 'Documentation/filesystems')
-rw-r--r--Documentation/filesystems/configfs/configfs.txt57
1 files changed, 48 insertions, 9 deletions
diff --git a/Documentation/filesystems/configfs/configfs.txt b/Documentation/filesystems/configfs/configfs.txt
index af68efdbbfad..e5fe521eea1d 100644
--- a/Documentation/filesystems/configfs/configfs.txt
+++ b/Documentation/filesystems/configfs/configfs.txt
@@ -51,15 +51,27 @@ configfs tree is always there, whether mounted on /config or not.
51An item is created via mkdir(2). The item's attributes will also 51An item is created via mkdir(2). The item's attributes will also
52appear at this time. readdir(3) can determine what the attributes are, 52appear at this time. readdir(3) can determine what the attributes are,
53read(2) can query their default values, and write(2) can store new 53read(2) can query their default values, and write(2) can store new
54values. Like sysfs, attributes should be ASCII text files, preferably 54values. Don't mix more than one attribute in one attribute file.
55with only one value per file. The same efficiency caveats from sysfs 55
56apply. Don't mix more than one attribute in one attribute file. 56There are two types of configfs attributes:
57 57
58Like sysfs, configfs expects write(2) to store the entire buffer at 58* Normal attributes, which similar to sysfs attributes, are small ASCII text
59once. When writing to configfs attributes, userspace processes should 59files, with a maximum size of one page (PAGE_SIZE, 4096 on i386). Preferably
60first read the entire file, modify the portions they wish to change, and 60only one value per file should be used, and the same caveats from sysfs apply.
61then write the entire buffer back. Attribute files have a maximum size 61Configfs expects write(2) to store the entire buffer at once. When writing to
62of one page (PAGE_SIZE, 4096 on i386). 62normal configfs attributes, userspace processes should first read the entire
63file, modify the portions they wish to change, and then write the entire
64buffer back.
65
66* Binary attributes, which are somewhat similar to sysfs binary attributes,
67but with a few slight changes to semantics. The PAGE_SIZE limitation does not
68apply, but the whole binary item must fit in single kernel vmalloc'ed buffer.
69The write(2) calls from user space are buffered, and the attributes'
70write_bin_attribute method will be invoked on the final close, therefore it is
71imperative for user-space to check the return code of close(2) in order to
72verify that the operation finished successfully.
73To avoid a malicious user OOMing the kernel, there's a per-binary attribute
74maximum buffer value.
63 75
64When an item needs to be destroyed, remove it with rmdir(2). An 76When an item needs to be destroyed, remove it with rmdir(2). An
65item cannot be destroyed if any other item has a link to it (via 77item 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.
171 struct configfs_item_operations *ct_item_ops; 183 struct configfs_item_operations *ct_item_ops;
172 struct configfs_group_operations *ct_group_ops; 184 struct configfs_group_operations *ct_group_ops;
173 struct configfs_attribute **ct_attrs; 185 struct configfs_attribute **ct_attrs;
186 struct configfs_bin_attribute **ct_bin_attrs;
174 }; 187 };
175 188
176The most basic function of a config_item_type is to define what 189The 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
201attribute is writable and provides a ->store method, that method will be 214attribute is writable and provides a ->store method, that method will be
202be called whenever userspace asks for a write(2) on the attribute. 215be called whenever userspace asks for a write(2) on the attribute.
203 216
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
225The binary attribute is used when the one needs to use binary blob to
226appear as the contents of a file in the item's configfs directory.
227To do so add the binary attribute to the NULL-terminated array
228config_item_type->ct_bin_attrs, and the item appears in configfs, the
229attribute file will appear with the configfs_bin_attribute->cb_attr.ca_name
230filename. configfs_bin_attribute->cb_attr.ca_mode specifies the file
231permissions.
232The cb_private member is provided for use by the driver, while the
233cb_max_size member specifies the maximum amount of vmalloc buffer
234to be used.
235
236If binary attribute is readable and the config_item provides a
237ct_item_ops->read_bin_attribute() method, that method will be called
238whenever userspace asks for a read(2) on the attribute. The converse
239will happen for write(2). The reads/writes are bufferred so only a
240single read/write will occur; the attributes' need not concern itself
241with it.
242
204[struct config_group] 243[struct config_group]
205 244
206A config_item cannot live in a vacuum. The only way one can be created 245A config_item cannot live in a vacuum. The only way one can be created