configfs: return value for drop_item()/make_item()?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 2 lines · Michael Noisternig
did you get my last reply? I hope you still consider it to be worthwhile to comment on. :)
I didn't get it, I'm sorry. I wonder what happened. Did you
send it to me, linux-kernel, or both (both is preferred).
Quoted 2 lines
And sorry for your double-reception of my last mail, I was unwittingly ignoring your follow-up-to setting.
I filter dupes by Message-ID :-)
Quoted 5 lines
-------- Original Message --------
Subject: Re: configfs: return value for drop_item()/make_item()?
From: Michael Noisternig
Date: Tue Jan 16 2007 - 11:40:50 EST
Quoted 7 lines
I fully agree with the idea of configfs not being allowed to destroy user-created objects. OTOH, while configfs is described as a filesystem for user-created objects under user control, compared to sysfs as a filesystem for kernel-created objects under kernel control, configfs _does_ permit kernel-created objects in a limited way (by filling in struct
config_group->default_groups), and these objects can only be destroyed again by the kernel, and not by the user.
They are not created by a kernel action. They are created as a
direct result of a user action. The user must mkdir(2) the parent in the chain. Only then do these default_groups appear. Contrast sysfs, where filesystem structures can be added at any time, from any codepath, via the sysfs in-kernel API.
Quoted 4 lines
As such I don't understand fully why one doesn't want to merge sysfs and configfs (let's call it sysconfs for now) in such a way that it allows _both_ user- and kernel-created objects, with user-objects only allowed to be destroyed by the user and kernel-objects only by the kernel.
The programming interface is very, very different. Check out
historical messages on this topic:
http://www.mail-archive.com/[email protected]/msg95708.html
http://www.mail-archive.com/[email protected]/msg95711.html
http://www.mail-archive.com/[email protected]/msg95714.html
http://www.mail-archive.com/[email protected]/msg95717.html
In addition, userspace would have no idea at any given time
whether they were dealing with kernel managed objects or user managed ones. So you'd confuse both the driver programmer *and* the userspace programmer.
Quoted 6 lines
One problem with configfs is that there is too little control over how many other objects a particular object may contain. IOW, an object may either contain
- n sub-objects (n entries in ->default_groups), or
- n..inf sub-objects (n entries in ->default_groups, ->make_item()/make_group() supplied)
Clearly you can have 0..N sub-objects by returning NULL from
successive ->make_item() calls, but as you point out, that results in ENOMEM, not the cleanest error for this case.
Quoted 4 lines
Often however, what you want is that an object may contain 0 or 1 other objects. If ->make_item()/make_group() would allow returning a meaningful error code the kernel could deny creation of a 2nd object other than by pretending to be out of memory.
You make a reasonable case that ENOMEM isn't always the error
you want, but perhaps we can add a better umbrella error code? I'm wary of introducing PTR_ERR() or any other complexity if we don't _need_ it. I'm all for thoughts on possibly compromises.
Quoted 11 lines
For another example, and directly related to above link, suppose having an object with a number of attributes, one of them being called 'type'. Dependent on the value of 'type' this object may contain a particular type of sub-object (with type-dependent attributes). E.g. 'type' may be empty | 'a' | 'b' | 'ab', then dependent on this there should be 0 or 1 directories called 'a', and 0 or 1 directories called 'b'. Doing it this way means that while the user decides what sub-directory/-ies the object has, he does not create them (directly) - it is the kernel which creates the object, and as such it is also the kernel only which is permitted to destroy the object again - by the user writing a different value to the 'type' attribute (or clearing it). sysconfs could solve this.
This is precisely what configfs is designed to forbid. The
kernel does not, ever, create configfs objects on its own. It does it as a result of userspace action. If you want the following:
# cd mydir
# ls -l
-rw-r--r-- 1 root root 0 2006-12-28 07:11 type
# echo 'ab' > type
# ls -l mydir
drwxr-xr-x 2 root root 4096 2007-01-08 14:21 ab
-rw-r--r-- 1 root root 2 2007-01-08 14:21 type
# echo '' > type
# ls -l mydir
-rw-r--r-- 1 root root 0 2007-01-08 14:22 typeyou're never going to get it from configfs. You should be using sysfs.
Quoted 8 lines
Above problem could be solved in a different manner within the realms of configfs by not having a 'type' attribute, but the other way around defining the (implicit) type of the object by the user creating certain sub-directories ('a' and 'b'). I.e. if the user creates directory 'a' the object is of type a, if the user also creates 'b' then the object is of type ab. However, the user should not be permitted to create other objects than 'a' and 'b' - thus ->make_item()/make_group() should permit returning a meaningful error code.
Or just returning an error, with the userspace program that
actually does the work interpretting it correctly. Remember, while it is convenient to be able to poke at configfs via the shell, real users are going to be using a wrapper program (eg, OCFS2 users don't manually add node information via mkdir(1) and echo(1), they use o2cb_ctl, which does it for them via mkdir(2) and write(2)).
Really, if you wanted to do this via configfs, you'd do
something like this:
# cd /sys/kernel/config
# ls -l
# modprobe mymodule
# ls -l
drwxr-xr-x 2 root root 4096 2007-01-08 14:21 mymodule
# cd mymodule
# ls -l
drwxr-xr-x 2 root root 4096 2007-01-08 14:21 a
drwxr-xr-x 2 root root 4096 2007-01-08 14:21 b
drwxr-xr-x 2 root root 4096 2007-01-08 14:21 ab
# mkdir a/object
# ls -l a
drwxr-xr-x 2 root root 4096 2007-01-08 14:22 object
# mkdir b/object
mkdir: cannot create directory `b/object`: Out of memory So your types are explicit in the fact that you havedefault_groups for type 'a', 'b', and 'ab'. You create an object of type 'a' via 'mkdir /sys/kernel/config/mymodule/a/object', and then you can't create objects under 'b' or 'ab'. When you 'rmdir a/object', now you can make 'b/object'.
You will notice, of course, the "Out of memory" error, because
it's only ENOMEM right now. Here, we could come up with a better umbrella error code, or the real wrapper program could say "I know this means an object already exists".
Quoted 4 lines
I was thinking about
ssize_tmake_item(struct config_group *group, const char *name, struct config_item **new_item)
with return value 0 meaning no-error.
Sure, it's another way to go, but it's effectively the same
thing.
Quoted 2 lines
Well, I understand and agree to the philosophy... but I still don't know how to solve my problem elegantly... more below...
Different problems (I'm sure you know that). That's why I'm
taking the time to respond, though, I'd like to help you solve the problem.
Quoted 1 line
It must be ordered because it's a priority list.
Just curious, I can certainly see a use.
Quoted 9 lines
I was thinking about having symlinks in a directory and deriving the order by the symlinks' filenames, too. I dismissed it originally for two reasons. First, I didn't see how to keep the order when some link gets deleted, e.g. there's 1,2,3 and then link 2 gets deleted. Now, thinking about it again, I can simply keep a ordered linked list internally, and therefrom remove the node for link 2. But it's still not perfect, because how do I insert a link between filenames 1 and 2? Ok, I have to delete all symlinks first and then rebuild them, and in the end it's like rewriting a
params_listattribute file... except that it's not
Quoted 8 lines
atomic. Second, a simple
params_listfile seems a lot more easy to handle from the user perspective... simply open the file with an editor, add or delete an entry, save it, close it. I don't know which method is better, the one described here with a params/ subdirectory containing symlinks with their order derived from their filenames, or method 2) from below with simply having aparams_listfile where params entries get renamed to <params removed> but are still valid until the user rewrites theparams_listfile.
Why not both? You need the reference, and the reference must
come from a userspace action. While a set of ordered names would be easy for some folks, maybe it isn't for you. So, the userspace process first symlinks all dependant parameters, thus taking a reference. Then, they write to params/order to order them. If they remove a symlink, you just delete the dentry from params/order.
# cd object/params
# ls -l
-rw-r--r-- 1 root root 0 2007-01-08 14:22 order
# ln -s ../../params/param1 .
# ln -s ../../params/param2 .
# ls -l
-rw-r--r-- 1 root root 0 2007-01-08 14:22 order
lrwxrwxrwx 1 root root 19 2007-01-08 15:30 param1 -> ../../params/param1
lrwxrwxrwx 1 root root 19 2007-01-08 15:30 param2 -> ../../params/param2
# cat order
# cat >order
param2
param1
^D
# cat order
param2
param1
# rm param2
# ls -l
-rw-r--r-- 1 root root 0 2007-01-08 14:31 order
lrwxrwxrwx 1 root root 19 2007-01-08 15:30 param1 -> ../../params/param1
# cat order
param1 Note that you don't need a "<param2 deleted>" placeholder in
'order'. Userspace explicitly removed the symlink, they should know what they did.
Quoted 3 lines
configfs should be a perfect fit for my purposes, as it's the user (and the user only) who creates and destroys the objects. The problem lies elsewhere. :/
Well, I hope I've come up with a few ways of doing this that
perhaps you'll either like or find inspiring. One thing to remember is that, while I'm using shell commands to show the configfs operations, in reality there'd be a wrapper program for your user. You want the actual user to be given a tool that speaks what they *want* to do, not how it actually gets done.
Quoted 8 lines
I'll give an example once more:
I have a directory called 'statistics' in my module's main dir in the configfs tree. This directory will contain several attributes for statistical purposes. Normally you would place this object into sysfs because it's an object created by the kernel (->default_groups). However, I certainly don't want to rip apart the statistics dir from the rest of the module parameters. What this shows in my eyes is that (1) configfs _does_ create kernel objects, and (2) sysconfs might make sense.
As I stated above, configfs does not allow objects to be created
in response to kernel actions. Sure, configfs does the actual work of filling out default_groups, and default_attrs, and even the object you just called mkdir(2) on. But it's all in response to a userspace action. That's what I mean by "user created".
Something to remember is taht there is nothing wrong with
putting some pieces in configfs and some pieces in sysfs. Really. You should be mostly hiding this from the user anyway. configfs and sysfs are userspace<->kernelspace interfaces. They provide some nice properties for the developer of kernel drivers needing a userspace interface and the developer of a userspace program communicating with kernelspace. But if you want a real user, "Joe Hacker" as it work, to see these things, you don't want them caring whether it's in configfs, sysfs, procfs, ioctl(2), or mmap(2). You want them using a tool.
You and I are hackers. We know that the kernel exposes our
laptop's batter info in /proc/acpi/battery/BAT0/state. So we can do 'cat /proc/acpi/battery/BAT0/state' if we like. But we're the exception. Almost everyone is going to do "acpitool -b".
If you have your configuration in configfs and your statistics
in sysfs, it provides you a nice set of programming interfaces. The fact that your tool checks two places is irrelevant to your users. They just know to call 'michaelstool --stats' to get statistics, and 'michaelstool --config' to configure the driver.
Joel
Signature · 10 lines
print STDOUT q Just another Perl hacker, unless $spring - Larry Wall Joel Becker Principal Software Developer Oracle E-mail: [email protected] Phone: (650) 506-8127
Thanks for your reply again! See comments inline...
Quoted 8 lines · Joel Becker
Quoted 7 lines
I fully agree with the idea of configfs not being allowed to destroy user-created objects. OTOH, while configfs is described as a filesystem for user-created objects under user control, compared to sysfs as a filesystem for kernel-created objects under kernel control, configfs _does_ permit kernel-created objects in a limited way (by filling in struct
config_group->default_groups), and these objects can only be destroyed again by the kernel, and not by the user.
Quoted 5 lines
They are not created by a kernel action. They are created as a
direct result of a user action. The user must mkdir(2) the parent in the chain. Only then do thesedefault_groupsappear. Contrast sysfs, where filesystem structures can be added at any time, from any codepath, via the sysfs in-kernel API.
Sure, but what I meant to say was that the user, when creating a directory, did not request creation of such sub-directories, so I see them as created by the kernel.
If you argue that they are in fact created by the user because they are a direct result of a user action, then I can apply the same argument to this one example:
Quoted 13 lines
Quoted 4 lines
For another example, and directly related to above link, suppose having an object with a number of attributes, one of them being called 'type'. Dependent on the value of 'type' this object may contain a particular type of sub-object (with type-dependent
Quoted 8 lines
attributes). E.g. 'type' may be empty | 'a' | 'b' | 'ab', then
dependent on this there should be 0 or 1 directories called 'a',
and 0 or 1 directories called 'b'. Doing it this way means that
while the user decides what sub-directory/-ies the object has, he
does not create them (directly) - it is the kernel which creates the object, and as such it is also the kernel only which is permitted to destroy the object again - by the user writing a
different value to the 'type' attribute (or clearing it). sysconfs
could solve this.
Quoted 3 lines
This is precisely what configfs is designed to forbid. The kernel does not, ever, create configfs objects on its own. It does it as a result of userspace action.
No. The sub-directory only appears as a direct result of the user writing a value into the 'type' attribute. ;-)
Quoted 13 lines
If you want the following:
# cd mydir # ls -l -rw-r--r-- 1 root root 0 2006-12-28 07:11 type # echo 'ab' > type # ls -l mydir drwxr-xr-x 2 root root 4096 2007-01-08 14:21 ab -rw-r--r-- 1 root root 2 2007-01-08 14:21 type # echo '' > type # ls -l mydir -rw-r--r-- 1 root root 0 2007-01-08 14:22 type
Quoted 2 lines
you're never going to get it from configfs. You should be using sysfs.
Hardly. sysfs doesn't allow the user creating directories. :>
Quoted 5 lines
Quoted 4 lines
As such I don't understand fully why one doesn't want to merge sysfs and configfs (let's call it sysconfs for now) in such a way that it allows _both_ user- and kernel-created objects, with user-objects only allowed to be destroyed by the user and kernel-objects only by the kernel.
Quoted 7 lines
The programming interface is very, very different. Check out
historical messages on this topic:http://www.mail-archive.com/[email protected]/msg95708.html
http://www.mail-archive.com/[email protected]/msg95711.html
http://www.mail-archive.com/[email protected]/msg95714.html
http://www.mail-archive.com/[email protected]/msg95717.html
Well, you could still use type (user object/kernel object) dependent structure pointers?
Quoted 10 lines
Quoted 4 lines
Often however, what you want is that an object may contain 0 or 1 other objects. If ->make_item()/make_group() would allow returning a meaningful error code the kernel could deny creation of a 2nd object other than by pretending to be out of memory.
You make a reasonable case that ENOMEM isn't always the error
you want, but perhaps we can add a better umbrella error code? I'm wary of introducingPTR_ERR()or any other complexity if we don't _need_ it. I'm all for thoughts on possibly compromises.
Quoted 7 lines
Quoted 4 lines
I was thinking about
ssize_tmake_item(struct config_group *group, const char *name, struct config_item **new_item)
with return value 0 meaning no-error.Sure, it's another way to go, but it's effectively the same
thing.
Well, you don't need PTR_ERR().
Quoted 49 lines
Quoted 9 lines
I was thinking about having symlinks in a directory and deriving the order by the symlinks' filenames, too. I dismissed it originally for two reasons. First, I didn't see how to keep the order when some link gets deleted, e.g. there's 1,2,3 and then link 2 gets deleted. Now, thinking about it again, I can simply keep a ordered linked list internally, and therefrom remove the node for link 2. But it's still not perfect, because how do I insert a link between filenames 1 and 2? Ok, I have to delete all symlinks first and then rebuild them, and in the end it's like rewriting a
params_listattribute file... except that it's notQuoted 8 lines
atomic. Second, a simple
params_listfile seems a lot more easy to handle from the user perspective... simply open the file with an editor, add or delete an entry, save it, close it. I don't know which method is better, the one described here with a params/ subdirectory containing symlinks with their order derived from their filenames, or method 2) from below with simply having aparams_listfile where params entries get renamed to <params removed> but are still valid until the user rewrites theparams_listfile.Why not both? You need the reference, and the reference must
come from a userspace action. While a set of ordered names would be easy for some folks, maybe it isn't for you. So, the userspace process first symlinks all dependant parameters, thus taking a reference. Then, they write to params/order to order them. If they remove a symlink, you just delete the dentry from params/order.# cd object/params # ls -l -rw-r--r-- 1 root root 0 2007-01-08 14:22 order # ln -s ../../params/param1 . # ln -s ../../params/param2 . # ls -l -rw-r--r-- 1 root root 0 2007-01-08 14:22 order lrwxrwxrwx 1 root root 19 2007-01-08 15:30 param1 -> ../../params/param1 lrwxrwxrwx 1 root root 19 2007-01-08 15:30 param2 -> ../../params/param2 # cat order # cat >order param2 param1 ^D # cat order param2 param1 # rm param2 # ls -l -rw-r--r-- 1 root root 0 2007-01-08 14:31 order lrwxrwxrwx 1 root root 19 2007-01-08 15:30 param1 -> ../../params/param1 # cat order param1
Quoted 3 lines
Note that you don't need a "<param2 deleted>" placeholder in
'order'. Userspace explicitly removed the symlink, they should know what they did.
That's an interesting other solution, however it seems a bit redundant (params are referenced by links as well as in the 'order' attribute file) and not as simple as my method 2). I guess, for now, in lack of a convincing solution, I will implement method 2) as the one easiest to adapt to given my current code base.
Quoted 6 lines
Well, I hope I've come up with a few ways of doing this that
perhaps you'll either like or find inspiring. One thing to remember is that, while I'm using shell commands to show the configfs operations, in reality there'd be a wrapper program for your user. You want the actual user to be given a tool that speaks what they *want* to do, not how it actually gets done.
Hm, I had envisioned the user to fully configure the module via file system operations only. Now if the user is supposed to use a wrapper program this sheds a different light on all those what's-the-best-solution issues...
Quoted 1 line
Joel
Thanks, Michael
Quoted 3 lines · Michael Noisternig
Sure, but what I meant to say was that the user, when creating a directory, did not request creation of such sub-directories, so I see them as created by the kernel.
Ahh, but userspace did! It's part of the configfs contract.
They've asked for an new config item and all that it entails.
Quoted 10 lines
If you argue that they are in fact created by the user because they are a direct result of a user action, then I can apply the same argument to this one example:
...Quoted 3 lines
This is precisely what configfs is designed to forbid. The kernel does not, ever, create configfs objects on its own. It does it as a result of userspace action.
No. The sub-directory only appears as a direct result of the user writing a value into the 'type' attribute. ;-)
Ok, you're stretching the metaphor. Writing a value to a "type"
attribute is, indeed, a userspace action. However, configfs' contract is that only mkdir(2) creates objects.
We're not trying to create the do-everything-kitchen-sink system
here. That way lies the problems we're trying to avoid. That's why configfs has a specific contract it provides to (a) userspace and (b) client drivers.
Quoted 4 lines
Quoted 2 lines
you're never going to get it from configfs. You should be using sysfs.
Hardly. sysfs doesn't allow the user creating directories. :>
sysfs certainly supports your "echo b > type" style of object
creation. You're type_file->store() method gets a "b" in the buffer and then does sysfs_mkdir() of your new object directory. Here, the kernel is creating the new object (the directory).
Quoted 1 line
Well, you don't need
PTR_ERR().
Sure, you could use **new_item. It's the same complexity
change.
Quoted 5 lines
That's an interesting other solution, however it seems a bit redundant (params are referenced by links as well as in the 'order' attribute file) and not as simple as my method 2). I guess, for now, in lack of a convincing solution, I will implement method 2) as the one easiest to adapt to given my current code base.
But they are not referenced by the order file. It's just an
attribute :-) Really, you can look at it either way. But configfs has a specific perspective based on its contracts, and so it works within them.
Quoted 4 lines
Hm, I had envisioned the user to fully configure the module via file system operations only. Now if the user is supposed to use a wrapper program this sheds a different light on all those what's-the-best-solution issues...
Certainly the user can do the configuration by hand. It will
always work. But why make them understand your userspace<->kernel API when you can just provide a tool? They're all going to script it up anyway.
Joel
Signature · 9 lines
"The doctrine of human equality reposes on this: that there is no man really clever who has not found that he is stupid." - Gilbert K. Chesterson Joel Becker Principal Software Developer Oracle E-mail: [email protected] Phone: (650) 506-8127
Quoted 7 lines
Quoted 6 lines
If you argue that they are in fact created by the user because they are a direct result of a user action, then I can apply the same argument to this one example:
...Quoted 3 lines
This is precisely what configfs is designed to forbid. The kernel does not, ever, create configfs objects on its own. It does it as a result of userspace action.
No. The sub-directory only appears as a direct result of the user writing a value into the 'type' attribute. ;-)
Quoted 7 lines
Ok, you're stretching the metaphor. Writing a value to a "type"
attribute is, indeed, a userspace action. However, configfs' contract is that only mkdir(2) creates objects.
We're not trying to create the do-everything-kitchen-sink system
here. That way lies the problems we're trying to avoid. That's why configfs has a specific contract it provides to (a) userspace and (b) client drivers.
Ok, so it's a design decision about configfs. I'll accept that. :)
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
you're never going to get it from configfs. You should be using sysfs.
Hardly. sysfs doesn't allow the user creating directories. :>
sysfs certainly supports your "echo b > type" style of object
creation. You'retype_file->store()method gets a "b" in the buffer and then doessysfs_mkdir()of your new object directory. Here, the kernel is creating the new object (the directory).
Sorry, I wasn't clear. I meant that it's not possible to let the user create the parent directory via mkdir(2) within sysfs. I.e.
# mkdir object <-- create object/, configfs only # ls object type # echo b > object/type <-- create b/, sysfs only # ls object type b/ I cannot have both, sysfs and configfs functionality, within the same module configuration file system tree.
Quoted 6 lines
Quoted 1 line
Hm, I had envisioned the user to fully configure the module via file system operations only. Now if the user is supposed to use a wrapper program this sheds a different light on all those what's-the-best-solution issues...
Certainly the user can do the configuration by hand. It will
always work. But why make them understand your userspace<->kernel API when you can just provide a tool? They're all going to script it up anyway.
Because the layout in say a user tool configuration file will look pretty much the same as the configfs tree.
Anyway, for something different now:
1. Is there any guarantee that strings passed to struct configfs_item_operations->store_attribute are 0-terminated? If not, there's not only potential for buffer overflows, but there already is - in configfs_example.c, using simple_strtoul().
2. A minor one: I realize that the CONFIGFS_ITEM_NAME_LEN value of 20 is taken over from sysfs, but in configfs a config_group now has 68 bytes of size, and assuming that many times one would simply kmalloc a simple struct config_group (without extending it) this would result in a waste of 60 bytes per malloc. Do you want to keep that #define or reduce it to 16? Just a thought...
Quoted 11 lines · Michael Noisternig
Sorry, I wasn't clear. I meant that it's not possible to let the user create the parent directory via mkdir(2) within sysfs. I.e.
# mkdir object <-- create object/, configfs only # ls object type # echo b > object/type <-- create b/, sysfs only # ls object type b/ I cannot have both, sysfs and configfs functionality, within the same module configuration file system tree.
No, you can't have sysfs and configfs functionality in the same
exact portion of the tree. But you can use both sysfs and configfs at the same time in your driver. The different parts will appear in the different trees. Up to you.
Quoted 4 lines
1. Is there any guarantee that strings passed to struct
configfs_item_operations->store_attributeare 0-terminated? If not, there's not only potential for buffer overflows, but there already is - inconfigfs_example.c, usingsimple_strtoul().
There is no guarantee, but that's a bug. The attribute handling
code came from sysfs. I assume the initial assumption was that since you can only copy a page, it's OK. Clearly not the case. sysfs fixed this in October (commit 035ed7a49447bc8e15d4d9316fc6a359b2d94333). I'll be porting that over. Thanks for noticing!
Quoted 6 lines
2. A minor one: I realize that the
CONFIGFS_ITEM_NAME_LENvalue of 20 is taken over from sysfs, but in configfs aconfig_groupnow has 68 bytes of size, and assuming that many times one would simply kmalloc a simple structconfig_group(without extending it) this would result in a waste of 60 bytes per malloc. Do you want to keep that #define or reduce it to 16? Just a thought...
Hmm, interesting. I'll look at that as well.
Joel
Signature · 9 lines
Life's Little Instruction Book #511 "Call your mother." Joel Becker Principal Software Developer Oracle E-mail: [email protected] Phone: (650) 506-8127