How to grab a block of binary data w/out using ioctls?
Subsystems (2)
Since IOCTLs are out of favor these days, what would be a preferred way to get a block of binary data out of the kernel?
I just want to grab a stats structure (well-aligned 32 and 64-bit counters and fixed-length strings) for a pktgen interface.
Can you do this with seq-files somehow?
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Quoted 8 lines · On Mon, 23 Oct 2006 17:44:24 -0700 Ben Greear wrote:
Since IOCTLs are out of favor these days, what would be a preferred way to get a block of binary data out of the kernel?
I just want to grab a stats structure (well-aligned 32 and 64-bit counters and fixed-length strings) for a pktgen interface.
Can you do this with seq-files somehow?
seq-files just use printk() for text output. Not well-suited to binary output.
Similarly, sysfs is desirable in some circumstances, but not for blocks of binary data.
ioctls or netlink or debugfs or relay output (see how blktrace uses relay output) are your choices (I may have missed some. :) ioctls can be OK for some purposes. If you want to avoid them, try debugfs or relay. (I haven't looked at debugfs very much; it may be more text-oriented also...)
---
~Randy
Quoted 2 lines · Randy Dunlap
Similarly, sysfs is desirable in some circumstances, but not for blocks of binary data.
sysfs specifically has APIs for binary data...
Jeff
Quoted 5 lines · Jeff Garzik
Quoted 2 lines · Randy Dunlap
Similarly, sysfs is desirable in some circumstances, but not for blocks of binary data.
sysfs specifically has APIs for binary data...
Ack that, sorry about that.
Signature · 1 line
~Randy
Quoted 8 lines · Jeff Garzik
Quoted 3 lines · Randy Dunlap
Similarly, sysfs is desirable in some circumstances, but not for blocks of binary data.
sysfs specifically has APIs for binary data...
From reading the Documentation/filesystems/sysfs.txt, it seems like it is not recommended that one use sysfs for anything other than very simple (and single) attributes.
If you know of a piece of code that actually passes back a struct or other binary blob of data, please point me to it so I can learn from it.
Thanks,
Ben
Quoted 4 lines
Jeff
Signature · 1 line
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Quoted 6 lines · Ben Greear
From reading the
Documentation/filesystems/sysfs.txt, it seems like it is not recommended that one use sysfs for anything other than very simple (and single) attributes.If you know of a piece of code that actually passes back a struct or other binary blob of data, please point me to it so I can learn from it.
Please grep for sysfs_create_bin_file, you will find plenty of examples.
Jeff
Quoted 9 lines · On Tue, 24 Oct 2006 22:47:18 -0400 Jeff Garzik wrote:
Quoted 6 lines · Ben Greear
From reading the
Documentation/filesystems/sysfs.txt, it seems like it is not recommended that one use sysfs for anything other than very simple (and single) attributes.If you know of a piece of code that actually passes back a struct or other binary blob of data, please point me to it so I can learn from it.
Please grep for
sysfs_create_bin_file, you will find plenty of examples.
Hm, I thought that sysfs binary files were supposed to be for "transparent" blobs of data, not for structured data. E.g., a "firmware" blob would be OK.
And I'm looking at current users. ISTM that this one:
arch/ppc/syslib/mv64x60.c:2443: sysfs_create_bin_file(&mv64xxx_device.dev.kobj, &mv64xxx_hs_reg_attr);
in its sysfs read function returns a string (binary data converted to a string) instead of returning binary data. Or did I misread it? or misunderstand sysfs binary data?
---
~Randy
Quoted 6 lines · Randy Dunlap
Quoted 2 lines
Please grep for
sysfs_create_bin_file, you will find plenty of examples.Hm, I thought that sysfs binary files were supposed to be for "transparent" blobs of data, not for structured data. E.g., a "firmware" blob would be OK.
Depends. Normally ASCII is greatly preferred, but passing in/out big data structures can be a huge pain, thunking to/from ASCII.
Quoted 7 lines
And I'm looking at current users. ISTM that this one:
arch/ppc/syslib/mv64x60.c:2443:sysfs_create_bin_file(&mv64xxx_device.dev.kobj, &mv64xxx_hs_reg_attr);in its sysfs read function returns a string (binary data converted to a string) instead of returning binary data. Or did I misread it? or misunderstand sysfs binary data?
Yeah, that one shouldn't be using _bin_
Jeff
Quoted 12 lines · Jeff Garzik
Quoted 4 lines · Randy Dunlap
Quoted 1 line
Please grep for
sysfs_create_bin_file, you will find plenty of examples.Hm, I thought that sysfs binary files were supposed to be for "transparent" blobs of data, not for structured data. E.g., a "firmware" blob would be OK.
Depends. Normally ASCII is greatly preferred, but passing in/out big data structures can be a huge pain, thunking to/from ASCII.
Quoted 2 lines
And I'm looking at current users. ISTM that this one:
Quoted 7 lines
Quoted 5 lines
arch/ppc/syslib/mv64x60.c:2443:sysfs_create_bin_file(&mv64xxx_device.dev.kobj, &mv64xxx_hs_reg_attr);in its sysfs read function returns a string (binary data converted to a string) instead of returning binary data. Or did I misread it? or misunderstand sysfs binary data?
Yeah, that one shouldn't be using _bin_
Thanks. It's not the only one like that. Also these 3 uses are incorrect AFAICT:
./drivers/firmware/dell_rbu.c:721: rc = sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_data_attr);./drivers/firmware/dell_rbu.c:724: rc = sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_image_type_attr);./drivers/firmware/dell_rbu.c:727: rc = sysfs_create_bin_file(&rbu_device->dev.kobj,
Signature · 1 line
~Randy
Quoted 5 lines · Randy.Dunlap
Thanks. It's not the only one like that. Also these 3 uses are incorrect AFAICT:
./drivers/firmware/dell_rbu.c:721: rc =sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_data_attr);
this is ok
Quoted 4 lines
./drivers/firmware/dell_rbu.c:724: rc =sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_image_type_attr);./drivers/firmware/dell_rbu.c:727: rc =
sysfs_create_bin_file(&rbu_device->dev.kobj,
these appear to be incorrect
Jeff
Quoted 6 lines · Jeff Garzik
Quoted 3 lines · Randy.Dunlap
Thanks. It's not the only one like that. Also these 3 uses are incorrect AFAICT:
./drivers/firmware/dell_rbu.c:721: rc =sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_data_attr);this is ok
ack, thanks for looking.
Quoted 4 lines
Quoted 2 lines
./drivers/firmware/dell_rbu.c:724: rc =sysfs_create_bin_file(&rbu_device->dev.kobj, &rbu_image_type_attr);./drivers/firmware/dell_rbu.c:727: rc = sysfs_create_bin_file(&rbu_device->dev.kobj,these appear to be incorrect
Signature · 1 line
~Randy
Quoted 4 lines · Jeff Garzik
Quoted 2 lines · Randy Dunlap
Quoted 2 lines
Please grep for
sysfs_create_bin_file, you will find plenty of examples.
Quoted 8 lines
Quoted 4 lines
Hm, I thought that sysfs binary files were supposed to be for "transparent" blobs of data, not for structured data. E.g., a "firmware" blob would be OK.
Depends. Normally ASCII is greatly preferred, but passing in/out big data structures can be a huge pain, thunking to/from ASCII.
This is my scenario exactly. It is also much easier to make sure the data is coherent if I can grab it all at once.
In my case, I'm wanting to add this to the pktgen module, for reporting stats. But, it seems sysfs is designed mostly for drivers with some sort of 'object' behind it.
Would I need to create some faked out dummy object in order to use sysfs with pktgen?
I also notice there is already a /sys/modules/pktgen node in sysfs..is there any easy way to stick my binary file interface in that directory?
Thanks,
Ben
Signature · 1 line
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Quoted 3 lines · * Ben Greear | 2006-10-23 17:44:24 [-0700]:
Since IOCTLs are out of favor these days, what would be a preferred way to get a block of binary data out of the kernel?
I suggest netlink socket for that purpose! Netlink scales also well if the amount of data "surprisedly" rise.
Quoted 2 lines
Thanks,
Ben
HGN