Skip to contentSkip to conversation

pktcdvd: added sysfs interface + bio write queue handling fix

PATCH In review Thomas Maier 4 participants 14 messages Sep 8, 2006 – Sep 11, 2006

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pktcdvd: added sysfs interface + bio write queue handling fix

Hello

(3th try with fixed inline patch)

This is a patch for the packet writing driver pktcdvd. It adds a sysfs interface to the driver and a bio write queue "congestion" handling.

The patch modifies following files of the Linux 2.6.18-rc6 source tree:
Documentation/cdrom/packet-writing.txt Documentation/ABI/testing/sysfs-block-pktcdvd include/linux/pktcdvd.h drivers/block/pktcdvd.c
drivers/block/Kconfig
block/genhd.c

(genhd.c must be changed to export the block_subsys symbol)

The bio write queue changes are in pktcdvd.c in functions:
pkt_make_request()
pkt_bio_finished()

Any comments and improvements are welcomed ;)

Why this patch?
===============
This driver uses an internal bio write queue to store write requests from the block layer, passed to the driver over its own make_request function.
I am using Linux 2.6.17 on an Athlon 64 X2, 2G RAM and while writing huge files (>200M) to a DVDRAM using the pktcdvd driver, the bio write queue raised >200000 entries! This led to kernel out of memory Oops! e.g.:

----------------------------------------------------------

Aug 14 17:42:26 master vmunix: pktcdvd: 4473408kB available on disc
Aug 14 17:42:54 master vmunix: pktcdvd: write speed 4155kB/s
Aug 14 17:54:24 master vmunix: oom-killer: gfp_mask=0xd0, order=1
Aug 14 17:54:24 master vmunix:  <c014346f> out_of_memory+0x12f/0x150
<c01452d0> __alloc_pages+0x280/0x2e0
Aug 14 17:54:24 master vmunix:  <c015a52a> cache_alloc_refill+0x2ea/0x500
<c015a7a1> __kmalloc+0x61/0x70
Aug 14 17:54:24 master vmunix:  <c039c0b3> __alloc_skb+0x53/0x110
<c03985b6> sock_alloc_send_skb+0x176/0x1c0
Aug 14 17:54:24 master vmunix:  <c0399c5b> sock_def_readable+0x7b/0x80
<c041262b> unix_stream_sendmsg+0x1cb/0x310
Aug 14 17:54:24 master vmunix:  <c039502b> do_sock_write+0xab/0xc0
<c0395720> sock_aio_write+0x80/0x90
Aug 14 17:54:24 master vmunix:  <c011a609> __wake_up_common+0x39/0x60
<c015d984> do_sync_write+0xc4/0x100
Aug 14 17:54:47 master vmunix: printk: 10 messages suppressed.
Aug 14 17:54:47 master vmunix: oom-killer: gfp_mask=0xd0, order=0
Aug 14 17:54:47 master vmunix:  <c014346f> out_of_memory+0x12f/0x150
<c01452d0> __alloc_pages+0x280/0x2e0
Aug 14 17:54:47 master vmunix:  <c0258de2> __next_cpu+0x12/0x30
<c015a52a> cache_alloc_refill+0x2ea/0x500
Aug 14 17:54:47 master vmunix:  <c015a23a> kmem_cache_alloc+0x4a/0x50
<c03987ea> sk_alloc+0x2a/0x150
Aug 14 17:54:47 master vmunix:  <c03e3f8d> inet_create+0xed/0x320
<c03950a2> sock_alloc_inode+0x12/0x70
Aug 14 17:54:47 master vmunix:  <c017790e> alloc_inode+0xce/0x180
<c03966f3> __sock_create+0x123/0x2f0
Aug 14 17:54:49 master vmunix: Total swap = 2152668kB
Aug 14 17:54:49 master vmunix: Free swap:       2152436kB
Aug 14 17:54:49 master vmunix: 524272 pages of RAM
Aug 14 17:54:49 master vmunix: 294896 pages of HIGHMEM
Aug 14 17:54:49 master vmunix: 5767 reserved pages
Aug 14 17:54:49 master vmunix: 238277 pages shared
Aug 14 17:54:49 master vmunix: 35 pages swap cached
Aug 14 17:54:49 master vmunix: 47682 pages dirty
Aug 14 17:54:49 master vmunix: 157861 pages writeback
Aug 14 17:54:49 master vmunix: 17359 pages mapped
Aug 14 17:54:49 master vmunix: 23835 pages slab
Aug 14 17:54:49 master vmunix: 176 pages pagetables
Aug 14 17:54:59 master vmunix:   <c0145355> __get_free_pages+0x25/0x40
Aug 14 17:55:19 master vmunix: 294896 pages of HIGHM<6>5767 reserved pages

------------------------------------------------------------

It don't know exactly what is wrong in the kernel, but it seems it must be something with the kernels memory handling.

To be able to use the pktcdvd driver now, i created this patch. It simply limits the size of the bio write queue of the driver to save kernel memory. Does not cure the "kernel bug", but the symptom ;)
If the number of bio write requests would raise the bio queue size over a high limit (congestion on), the make_request function waits till the worker thread has lowered the queue size below the "congestion off" mark. The wait is similar to the wait in get_request_wait(), called by the "normal" request function __make_request().

Also there is now a sysfs interface for the driver and the procfs interface can be switched of by a kernel config parameter. See the file
Documentation/ABI/testing/sysfs-block-pktcdvd
in this patch.

-Thomas Maier

---[snip]-----------------------------

Documentation/ABI/testing/sysfs-block-pktcdvd +84 -0
diff -urpN linux-2.6.18-rc6/Documentation/ABI/testing/sysfs-block-pktcdvd pktcdvd-patch-2.6.18-rc6/Documentation/ABI/testing/sysfs-block-pktcdvd
@@ -0,0 +1,84 @@
+What:           /sys/block/pktcdvd/
+Date:           Sep. 2006
+KernelVersion:  2.6.18
+Contact:        Thomas Maier <[email protected]>
+Description:
+
+sysfs interface
+---------------
+
+The pktcdvd module (packet writing driver) creates
+following files in the sysfs:
+
+( <pktdevname> is one of pktcdvd0..pktcdvd7 )
+( <devid> is in format  major:minor )
+
+/sys/block/pktcdvd/
+    add               (w)  Write a block device id to create a
+                           new pktcdvd device and map it to the
+                           block device.
+
+    remove            (w)  Write the pktcdvd device id or the
+                           mapped block device id to it, to
+                           remove the pktcdvd device.
+
+    device_map        (r)  Shows the device mapping in format:
+                           <pktdevname> <pktdevid> <blkdevid>
+
+    packet_buffers    (rw) Number of concurrent packets per
+                           pktcdvd device. Used for new created
+                           devices.
+	
+
+/sys/block/pktcdvd/<pktdevname>/packet/
+    statistic         (r)  Show device statistic. One line with
+                           5 values in following order:
+                              packets-started
+                              packets-end
+                              written in kB
+                              read gather in kB
+                              read in kB
+
+    reset_statistic   (w)  Write any value to it to reset
+                           pktcdvd device statistic values, like
+                           bytes read/written.
+
+    info              (r)  Lots of user readable driver statistics
+                           and infos. Multiple lines!
+
+    write_queue_size  (r)  Contains the size of the bio write
+                           queue.
+
+    write_congestion_off (rw) If bio write queue size is below
+                              this mark, accept new bio requests
+                              from the block layer.
+
+    write_congestion_on  (rw) If bio write queue size is higher
+                              as this mark, do no longer accept
+                              bio write requests from the block
+                              layer and wait till the pktcdvd
+                              device has processed enough bio's
+                              so that bio write queue size is
+                              below congestion off mark.
+
+    mapped_to              Symbolic link to mapped block device
+                           in the /sys/block tree.
+
+
+Example:
+--------
+To use the pktcdvd sysfs interface directly, you can do:
+
+# create a new pktcdvd device mapped to /dev/hdc
+echo "22:0" >/sys/block/pktcdvd/add
+cat /sys/block/pktcdvd/device_map
+# assuming device pktcdvd0 was created, look at stat's
+cat /sys/block/pktcdvd/pktcdvd0/packet/stat
+# print the device id of the mapped block device
+cat /sys/block/pktcdvd/pktcdvd0/packet/mapped_to/dev
+# similar to
+fgrep pktcdvd0 /sys/block/pktcdvd/device_map
+# remove device, using pktcdvd0 device id   253:0
+echo "253:0" >/sys/block/pktcdvd/remove
+# same as using the mapped block device id  22:0
+echo "22:0" >/sys/block/pktcdvd/remove
Documentation/cdrom/packet-writing.txt +270 -2

291 lines not on this page · raw message

block/genhd.c +1 -0
diff -urpN linux-2.6.18-rc6/block/genhd.c pktcdvd-patch-2.6.18-rc6/block/genhd.c
@@ -510,6 +510,7 @@ static struct kset_uevent_ops block_ueve
  };
 
  decl_subsys(block, &ktype_block, &block_uevent_ops);
+EXPORT_SYMBOL(block_subsys);
 
  /*
   * aggregate disk stat collector.  Uses the same stats that the sysfs
drivers/block/Kconfig +25 -5
diff -urpN linux-2.6.18-rc6/drivers/block/Kconfig pktcdvd-patch-2.6.18-rc6/drivers/block/Kconfig
@@ -428,17 +428,22 @@ config CDROM_PKTCDVD
  	tristate "Packet writing on CD/DVD media"
  	depends on !UML
  	help
-	  If you have a CDROM drive that supports packet writing, say Y to
-	  include preliminary support. It should work with any MMC/Mt Fuji
-	  compliant ATAPI or SCSI drive, which is just about any newer CD
-	  writer.
+	  If you have a CDROM/DVD drive that supports packet writing, say
+	  Y to include preliminary support. It should work with any
+	  MMC/Mt Fuji compliant ATAPI or SCSI drive, which is just about
+	  any newer DVD/CD writer.
 
-	  Currently only writing to CD-RW, DVD-RW and DVD+RW discs is possible.
+	  Currently only writing to CD-RW, DVD-RW, DVD+RW and DVDRAM discs
+	  is possible.
  	  DVD-RW disks must be in restricted overwrite mode.
 
  	  To compile this driver as a module, choose M here: the
  	  module will be called pktcdvd.
 
+	  For further information see the file
+
+	    Documentation/cdrom/packet-writing.txt
+	
  config CDROM_PKTCDVD_BUFFERS
  	int "Free buffers for data gathering"
  	depends on CDROM_PKTCDVD
@@ -458,6 +463,21 @@ config CDROM_PKTCDVD_WCACHE
  	  this option is dangerous unless the CD-RW media is known good, as we
  	  don't do deferred write error handling yet.
 
+config CDROM_PKTCDVD_PROCINTF
+	bool "Enable procfs interface"
+	depends on CDROM_PKTCDVD
+	default y
+	help
+	  Enable the proc filesystem interface for pktcdvd.
+	  The files can be found as:
+	
+	  /proc/driver/pktcdvd/pktcdvd<idx>
+	
+	  Also a misc device is added with a dynamic minor device id.
+	  See the entry in  /proc/misc  for the minor number.
+	  The misc pktcdvd driver supports ioctl calls, needed
+	  by the pktsetup tool found in udftools package.
+
  source "drivers/s390/block/Kconfig"
 
  config ATA_OVER_ETH
drivers/block/pktcdvd.c +985 -429

1,659 lines not on this page · raw message

include/linux/pktcdvd.h +78 -31

164 lines not on this page · raw message

#1 lore raw
Quoted 8 lines · Thomas Maier

Hello

(3th try with fixed inline patch)

This is a patch for the packet writing driver pktcdvd. It adds a sysfs interface to the driver and a bio write queue "congestion" handling.

Why does pktcdvd need to handle congestion? Doesn't it get blocked when trying to send down bios to the underlying device if it's queue is congested?

#3 lore raw
In reply to Thomas Maier

Documentation/ABI/testing/sysfs-block-pktcdvd line 40

Quoted 8 lines · Thomas Maier
Documentation/ABI/testing/sysfs-block-pktcdvd +8 -0
+/sys/block/pktcdvd/<pktdevname>/packet/
+    statistic         (r)  Show device statistic. One line with
+                           5 values in following order:
+                              packets-started
+                              packets-end
+                              written in kB
+                              read gather in kB
+                              read in kB

Please no. One value per file is the sysfs rule.

Documentation/ABI/testing/sysfs-block-pktcdvd line 47

Quoted 6 lines
Documentation/ABI/testing/sysfs-block-pktcdvd +6 -0
+    reset_statistic   (w)  Write any value to it to reset
+                           pktcdvd device statistic values, like
+                           bytes read/written.
+
+    info              (r)  Lots of user readable driver statistics
+                           and infos. Multiple lines!

Again, no. Put it in debugfs if you want multiple lines.

Quoted 7 lines
Documentation/ABI/testing/sysfs-block-pktcdvd +7 -0
+    write_queue_size  (r)  Contains the size of the bio write
+                           queue.
+
+    write_congestion_off (rw) If bio write queue size is below
+                              this mark, accept new bio requests
+                              from the block layer.
+

Documentation/ABI/testing/sysfs-block-pktcdvd line 65

Quoted 10 lines
Documentation/ABI/testing/sysfs-block-pktcdvd +10 -0
+    write_congestion_on  (rw) If bio write queue size is higher
+                              as this mark, do no longer accept
+                              bio write requests from the block
+                              layer and wait till the pktcdvd
+                              device has processed enough bio's
+                              so that bio write queue size is
+                              below congestion off mark.
+
+    mapped_to              Symbolic link to mapped block device
+                           in the /sys/block tree.

Shouldn't this whole thing be in /sys/class/ instead of /sys/block/ ?

thanks,

greg k-h

#4 lore raw
Quoted 10 lines · Greg KH

Documentation/ABI/testing/sysfs-block-pktcdvd line 40

Quoted 8 lines · Thomas Maier
Documentation/ABI/testing/sysfs-block-pktcdvd +8 -0
+/sys/block/pktcdvd/<pktdevname>/packet/
+    statistic         (r)  Show device statistic. One line with
+                           5 values in following order:
+                              packets-started
+                              packets-end
+                              written in kB
+                              read gather in kB
+                              read in kB
Quoted 2 lines

Please no. One value per file is the sysfs rule.

Except in cases like this where you want to read the status of the device at a given point in time, and you can't do that unless you grab all the values at once.

#5 lore raw
Quoted 11 lines · Phillip Susi
Quoted 10 lines · Greg KH
Quoted 8 lines · Thomas Maier
Documentation/ABI/testing/sysfs-block-pktcdvd +8 -0
+/sys/block/pktcdvd/<pktdevname>/packet/
+    statistic         (r)  Show device statistic. One line with
+                           5 values in following order:
+                              packets-started
+                              packets-end
+                              written in kB
+                              read gather in kB
+                              read in kB
Quoted 6 lines
Quoted 2 lines

Please no. One value per file is the sysfs rule.

Except in cases like this where you want to read the status of the device at a given point in time, and you can't do that unless you grab all the values at once.

Then don't use sysfs for that. And is something like this as critical to get that kind of information all in one atomic chunk? It seems merely to be informational.

thanks,

greg k-h

#2 lore raw
In reply to Phillip Susi

Hello,

Quoted 10 lines
Quoted 8 lines · Thomas Maier

Hello

(3th try with fixed inline patch)

This is a patch for the packet writing driver pktcdvd. It adds a sysfs interface to the driver and a bio write queue "congestion" handling.

Quoted 5 lines

Why does pktcdvd need to handle congestion?

Doesn't it get blocked when
trying to send down bios to the underlying device if it's queue is congested?

Yes, that is right.

But the pktcdvd driver has an internal queue for *incoming* bio write request (over own make_request function), and this queue size was unlimited! Since the underlying (DVD writer in my case) can not process as much write packets as fast as new bio write requests are passed to the driver, the bio write queue size increases and increases and increases ;) Esp if you are write huge files. In my case, i wrote about 2G on data (using rsync for backup purpose) onto DVDRAM, with some huge files (about 300 MB). The bio write queue size raised over 200000 and more and at the end, the kernel said: ups, no more memory available, i let something fail.

-Thomas Maier

#6 lore raw
In reply to Greg KH

Hello,

Quoted 2 lines
Quoted 2 lines
Documentation/ABI/testing/sysfs-block-pktcdvd +2 -0
+    write_queue_size  (r)  Contains the size of the bio write
+                           queue.

...

Quoted 4 lines

Documentation/ABI/testing/sysfs-block-pktcdvd line 65

Quoted 2 lines
Documentation/ABI/testing/sysfs-block-pktcdvd +2 -0
+    mapped_to              Symbolic link to mapped block device
+                           in the /sys/block tree.

Shouldn't this whole thing be in /sys/class/ instead of /sys/block/ ?

Don't know. I thought, the pktcdvd is a block driver, so put the control files into /sys/block ..
Is /sys/class better? If yes, where to put it?

Quoted 15 lines · Phillip Susi
Quoted 14 lines
Quoted 12 lines · Greg KH

Documentation/ABI/testing/sysfs-block-pktcdvd line 40

Quoted 8 lines · Thomas Maier
Documentation/ABI/testing/sysfs-block-pktcdvd +8 -0
+/sys/block/pktcdvd/<pktdevname>/packet/
+    statistic         (r)  Show device statistic. One line with
+                           5 values in following order:
+                              packets-started
+                              packets-end
+                              written in kB
+                              read gather in kB
+                              read in kB

Please no. One value per file is the sysfs rule.

Quoted 7 lines
Quoted 3 lines

Except in cases like this where you want to read the status of the device at a given point in time, and you can't do that unless you grab all the values at once.

Then don't use sysfs for that. And is something like this as critical to get that kind of information all in one atomic chunk? It seems merely to be informational.

The "statistic" and "info" files are only for information purpose. Into /proc ? No. (i read somewhere /proc should only contain process information in future)
In debugfs? Hmm, this files should be infos that users should be able to read, no debug output.

Is it ok, if i split the "statistic" into 5 files, and put the "info" into debugfs ?

-Thomas Maier

#7 lore raw
Quoted 5 lines · Thomas Maier

Hello,

Quoted 2 lines
Quoted 2 lines
Documentation/ABI/testing/sysfs-block-pktcdvd +2 -0
+    write_queue_size  (r)  Contains the size of the bio write
+                           queue.

...

Quoted 8 lines
Quoted 4 lines

Documentation/ABI/testing/sysfs-block-pktcdvd line 65

Quoted 2 lines
Documentation/ABI/testing/sysfs-block-pktcdvd +2 -0
+    mapped_to              Symbolic link to mapped block device
+                           in the /sys/block tree.

Shouldn't this whole thing be in /sys/class/ instead of /sys/block/ ?

Don't know. I thought, the pktcdvd is a block driver, so put the control files into /sys/block ..
Is /sys/class better? If yes, where to put it?

Use /sys/class/pktcdvd/ and use struct device instead of struct class_device, so I don't have to convert the code later :)

Quoted 19 lines
Quoted 19 lines · Phillip Susi
Quoted 17 lines
Quoted 10 lines · Greg KH

Documentation/ABI/testing/sysfs-block-pktcdvd line 40

Quoted 8 lines · Thomas Maier
Documentation/ABI/testing/sysfs-block-pktcdvd +8 -0
+/sys/block/pktcdvd/<pktdevname>/packet/
+    statistic         (r)  Show device statistic. One line with
+                           5 values in following order:
+                              packets-started
+                              packets-end
+                              written in kB
+                              read gather in kB
+                              read in kB
Quoted 2 lines

Please no. One value per file is the sysfs rule.

Except in cases like this where you want to read the status of the device at a given point in time, and you can't do that unless you grab all the values at once.

Quoted 5 lines
Quoted 3 lines

Then don't use sysfs for that. And is something like this as critical to get that kind of information all in one atomic chunk? It seems merely to be informational.

The "statistic" and "info" files are only for information purpose.

Then please split them up into individual files.

Quoted 2 lines

Into /proc ? No. (i read somewhere /proc should only contain process information in future)

Exactly.

Quoted 2 lines

In debugfs? Hmm, this files should be infos that users should be able to read, no debug output.

Ok, then multiple files please.

Quoted 2 lines

Is it ok, if i split the "statistic" into 5 files, and put the "info" into debugfs ?

Yes, that would be fine.

thanks,

greg k-h

#8 lore raw
Quoted 9 lines · Greg KH
Quoted 8 lines · Thomas Maier

Hello,

Quoted 2 lines
Quoted 2 lines
Documentation/ABI/testing/sysfs-block-pktcdvd +2 -0
+    write_queue_size  (r)  Contains the size of the bio write
+                           queue.

...

Quoted 3 lines
Quoted 2 lines
Documentation/ABI/testing/sysfs-block-pktcdvd +2 -0
+    mapped_to              Symbolic link to mapped block device
+                           in the /sys/block tree.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Shouldn't this whole thing be in /sys/class/ instead of /sys/block/ ?

Don't know. I thought, the pktcdvd is a block driver, so put the control files into /sys/block ..
Is /sys/class better? If yes, where to put it?

Use /sys/class/pktcdvd/ and use struct device instead of struct class_device, so I don't have to convert the code later :)

Is this always device specific, or also driver global information? Is pktcdvd always on a block device? Maybe you just want them to be a group of attributes in the block device directory where they belong to, like:
/sys/block/sr0/pktcdvd/info /sys/block/sr0/pktcdvd/write_queue_size /sys/block/sr0/pktcdvd/...

Does that make sense? We should avoid messing around with symlinks pointing to other devices, if not absolutely needed. We should also not create a new device type, just for adding properties to an existing one, especially if there is not some kind of "device stacking". The "mapped_to" link to the parent device looks like a wild hack to me, we should avoid.

Thanks,
Kay

#11 lore raw
In reply to Greg KH

Hello,

Am 09.09.2006, 23:30 Uhr, schrieb Greg KH <[email protected]>:

Quoted 2 lines

Use /sys/class/pktcdvd/ and use struct device instead of struct class_device, so I don't have to convert the code later :)

I moved the pktcdvd control files (device add/remove/map) into /sys/class/pktcdvd/.
I only use "struct class", no need to use struct class_device, since this /sys/class/pktcdvd represents not a real device. The real devices are in /sys/block/pktcdvd[0-7] as created by a "struct gendisk".

I have a little improvement request for the class code:
since the create_class() function has no attributes parameter, i have to copy+paste the class_create() code into the module, assign the class attribute array to the struct class and do a class_register().
Would be nice if class_create() can be passed the class attribute array...

The file layout is now as follows:

/sys/block/pktcdvd[0-7]/ # device dir created by gendisk
packet/ # pktcdvd subdir
<files> # pktcdvd per device files
mapped_to # symlink to mapped device in /sys/block

/sys/class/pktcdvd/ # class dir for control files
add # add new device mapping, creates new pktcdvd device
remove # ...
device_map
packet_buffers

/debugfs/pktcdvd[0-7]/ # per device debugfs dir entry
info # lot of human readable device infos, previous
# found in /proc/driver/pktcdvd[0-7]

Suggestions/Alteratives:
* should there be pktcdvd[0-7] subdirs in /sys/class/pktcdvd/ ? With content stored in /sys/block/../packet/ ? Or a symlink to it?

* the files in /sys/class/pktcdvd can be moved to /sys/module/pktcdvd/ ?! Seems that some modules have control files in their /sys/module directory.

-Thomas Maier

#9 lore raw
In reply to Kay Sievers

Hello,

Quoted 7 lines

Is this always device specific, or also driver global information? Is pktcdvd always on a block device? Maybe you just want them to be a group of attributes in the block device directory where they belong to, like:
/sys/block/sr0/pktcdvd/info /sys/block/sr0/pktcdvd/write_queue_size /sys/block/sr0/pktcdvd/...

Quoted 6 lines

Does that make sense? We should avoid messing around with symlinks pointing to other devices, if not absolutely needed. We should also not create a new device type, just for adding properties to an existing one, especially if there is not some kind of "device stacking". The "mapped_to" link to the parent device looks like a wild hack to me, we should avoid.

The pktcdvd driver creates new block devices using a "struct gendisk" that creates the /sys/block/pktcdvd[0-7]/ entries (alloc_disk() -> add_disk()).

Since the files like write_queue_size are per pktcdvd device and belong to this device, they should be below the /sys/block/pktcdvd[0-7]/ directory, not below the e.g. /sys/block/sr0/ .

The pktcdvd driver can only be mapped to block devices, as i know.

-Thomas Maier

#10 lore raw
Quoted 16 lines · Thomas Maier

Hello,

Quoted 7 lines

Is this always device specific, or also driver global information? Is pktcdvd always on a block device? Maybe you just want them to be a group of attributes in the block device directory where they belong to, like:
/sys/block/sr0/pktcdvd/info /sys/block/sr0/pktcdvd/write_queue_size /sys/block/sr0/pktcdvd/...

Quoted 6 lines

Does that make sense? We should avoid messing around with symlinks pointing to other devices, if not absolutely needed. We should also not create a new device type, just for adding properties to an existing one, especially if there is not some kind of "device stacking". The "mapped_to" link to the parent device looks like a wild hack to me, we should avoid.

Quoted 6 lines

The pktcdvd driver creates new block devices using a "struct gendisk" that creates the /sys/block/pktcdvd[0-7]/ entries (alloc_disk() -> add_disk()).

Since the files like write_queue_size are per pktcdvd device and belong to this device, they should be below the /sys/block/pktcdvd[0-7]/ directory, not below the e.g. /sys/block/sr0/ .

So the pktcdvd device have their own device nodes, userspace talks to?

Kay

#13 lore raw

PATCH 1/1 class.c: added class_create_attrs() function

In reply to Greg KH

Hello,

this is a patch based on linux 2.6.18-rc6. It adds a class_create_attrs() function in drivers/base/class.c .
This new function works similar to class_create(), but also allows to create the class attribute files (if any) during class creation.

-Thomas Maier

drivers/base/class.c +14 -0
diff -urpN linux-2.6.18-rc6/drivers/base/class.c patch/drivers/base/class.c
@@ -199,6 +199,18 @@ static int class_device_create_uevent(st
   */
  struct class *class_create(struct module *owner, char *name)
  {
+	return class_create_attrs(owner, name, NULL);
+}
+/**
+ * class_create_attrs - similar to class_create(), but can also
+ * create class attribute files on class creation.
+ * @owner: pointer to the module that is to "own" this struct class
+ * @name: pointer to a string for the name of this class.
+ * @cls_attrs: pointer to a class_attribute array.
+ */
+struct class *class_create_attrs(struct module *owner, char *name,
+				struct class_attribute *cls_attrs)
+{
  	struct class *cls;
  	int retval;
 
@@ -212,6 +224,7 @@ struct class *class_create(struct module
  	cls->owner = owner;
  	cls->class_release = class_create_release;
  	cls->release = class_device_create_release;
+	cls->class_attrs = cls_attrs;
 
  	retval = class_register(cls);
  	if (retval)
@@ -900,6 +913,7 @@ EXPORT_SYMBOL_GPL(class_remove_file);
  EXPORT_SYMBOL_GPL(class_register);
  EXPORT_SYMBOL_GPL(class_unregister);
  EXPORT_SYMBOL_GPL(class_create);
+EXPORT_SYMBOL_GPL(class_create_attrs);
  EXPORT_SYMBOL_GPL(class_destroy);
 
  EXPORT_SYMBOL_GPL(class_device_register);
include/linux/device.h +2 -0
diff -urpN linux-2.6.18-rc6/include/linux/device.h patch/include/linux/device.h
@@ -272,6 +272,8 @@ extern int class_interface_register(stru
  extern void class_interface_unregister(struct class_interface *);
 
  extern struct class *class_create(struct module *owner, char *name);
+extern struct class *class_create_attrs(struct module *owner, char *name,
+					struct class_attribute *cls_attrs);
  extern void class_destroy(struct class *cls);
  extern struct class_device *class_device_create(struct class *cls,
  						struct class_device *parent,
#12 lore raw
In reply to Thomas Maier

Hello,

Quoted 13 lines

The file layout is now as follows:

/sys/block/pktcdvd[0-7]/ # device dir created by gendisk
packet/ # pktcdvd subdir
<files> # pktcdvd per device files
mapped_to # symlink to mapped device in /sys/block

/sys/class/pktcdvd/ # class dir for control files
add # add new device mapping, creates new pktcdvd device
remove # ...
device_map
packet_buffers

Quoted 5 lines

/debugfs/pktcdvd[0-7]/ # per device debugfs dir entry
info # lot of human readable device infos, previous
# found in /proc/driver/pktcdvd[0-7]

Also added class_device's below of /sys/class/pktcdvd , so that the file layout is now:

/sys/class/pktcdvd/pktcdvd[0-7]/
dev
uevent

Quoted 2 lines

Use /sys/class/pktcdvd/ and use struct device instead of struct class_device, so I don't have to convert the code later

Hmm, sorry. Don't know how to do this. The only thing i found is the code in class.c, where struct class_device is used to create these "dev" and "uevent" files...

Any comments?

-Thomas Maier