LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-13-2011, 11:23 AM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, Ubuntu, Amazon Linux
Posts: 1,850
Blog Entries: 21

Rep: Reputation: 119Reputation: 119
How to stop udev from polling.


I'm looking for whatever setting(s)/config(s) I can make to cause udev to stop polling USB devices. Since polling is not needed to detect removal of USB devices, I shouldn't need it (the polling). The kernel has never needed to do this polling for it's hotplug feature.

Here's the actual problem:

A USB memory stick will be written to (directly, without being mounted). I need to determine when the memory stick is safe to remove. Just because the program doing the writing exits, it is not safe, yet. The kernel could still be flushing cached buffers out to it. And the device controller itself could still be updating flash blocks. The only way to know when it is safe to remove is when the busy indicator stops blinking.

But it never stops blinking because of constant persistent accesses being done by udev. I also tried hald, and it does the same, though not as rapidly, but rapid enough to still be an issue. But hald is depricated, so I'm not going to switch to it.

Basically, I can't know when all the behind the scenes writing is done because of the constant accesses by udev. I can only guess when the memory stick MIGHT be safe to remove. And in an older machine without udev, where the blinking does eventually stop after writing, sometimes it takes a while, perhaps due to kernel caching (it seems to cache a lot more when there is more RAM), or perhaps due to the flash wear leveling still updating stuff. I've seen this go on for more than a minute in a few rare cases.

The question is simply how to make udev NOT do this, either for all devices, or at least for all USB devices.
 
Old 09-14-2011, 05:09 AM   #2
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,703
Blog Entries: 23

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
A USB memory stick will be written to (directly, without being mounted)
Sorry, IMHO that's not possible...Linux MUST mount a device to interact with it like that...

Quote:
But it never stops blinking because of constant persistent accesses being done by udev
It's (again IMHO) not because udev is poking the thing that it's unsafe to remove it. Try to unmount it, the system will tell you when it's okay to do so.
And, a non-blinking licht does not guarantee an inactive device...

Quote:
The only way to know when it is safe to remove is when the busy indicator stops blinking.
Again, not really. Consider this: Libre Write has a document open...on the stick. As long as there's not action...the light stays off...

Quote:
Wanted: 3 button mouse WITHOUT roller on a button (PS/2 or USB)
...the roller IS a button...

Luck

Thor
 
Old 09-14-2011, 10:25 AM   #3
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, Ubuntu, Amazon Linux
Posts: 1,850
Blog Entries: 21

Original Poster
Rep: Reputation: 119Reputation: 119
Quote:
Originally Posted by Thor_2.0 View Post
Sorry, IMHO that's not possible...Linux MUST mount a device to interact with it like that...
That is not true at all. Once a device exists, it can be read from or written to just like any other device. A block device is similar to, though not exactly like, a file. This is how formatting tools like fdisk, parted, mkfs.* and fsck.* must access the device. But many other tools can, as well, such as dd. I also make bootable DISK images, using the LinuxMint and Ubuntu installer ISOs (it morphs the ISO into being a hard drive like image, complete with partition table). These images are written directly to the whole device, for example like:
Code:
dd if=ubuntu.img of=/dev/sdd bs=1048576 oflag=direct
You can also clone a USB memory stick by direct copy (make sure they are not mounted when doing this). Here is an example:
Code:
dd if=/dev/sdd iflag=direct bs=1048576 of=/dev/sde oflag=direct
I can also write tar images directly to a file without there being a filesystem, and with nothing being mounted. It's the quick way in the command line to just dump some files and go (provided nothing is on there to be saved). Example:
Code:
tar cf /dev/sdd1 files-to-take-home
Of course, always be sure you are using the correct device node name.

Quote:
Originally Posted by Thor_2.0 View Post
It's (again IMHO) not because udev is poking the thing that it's unsafe to remove it. Try to unmount it, the system will tell you when it's okay to do so.
And, a non-blinking licht does not guarantee an inactive device...
It is NOT mounted.

Perhaps there are USB memory sticks around that stop blinking even though they may be still updating the flash blocks in the wear leveling layer. I believe mine work correctly. But if not in that regard, then damage to the device because of removal while it's still updating is the manufacturer's issue.

My program that is writing to it (similar to dd) will exit when it is done. The kernel MAY be caching some data, although by using the O_DIRECT open flag, it shouldn't be. But the device should still be blinking as long as the kernel is still actively writing to it.

Quote:
Originally Posted by Thor_2.0 View Post
Again, not really. Consider this: Libre Write has a document open...on the stick. As long as there's not action...the light stays off...
It doesn't have any data that any application would be accessing. It is NOT mounted. It is being written to, raw, sequentially, and when that is done, for sure, I want to remove it ASAP. The lights should be blinking while my program is writing, while any kernel cache is still being written, while any flash blocks are being updated internal to the device, and maybe also for a timeout period of a few seconds after all activity is stopped. Then I can remove it because I know only this one program was started to write to it.

FYI, I'm writing a bootable image to it. When that is booted, then yes, it will be mounted at that time. It should not be removed until the shutdown is complete. Later I will be making a version that copies everything into RAM without ever mounting it.

Quote:
Originally Posted by Thor_2.0 View Post
...the roller IS a button...
The roller is a button that often also causes a rolling action to take place at the same time, sometimes resulting in the click action intended by the button to take place in the wrong way because the rolling action happened. These things need to be separated. I absolutely need the middle button. I can live without the roller if that has to be sacrificed. The ideal solution would be 3 separate buttons apart from a roller. Since roller-less 3 button mice used to be made, I'm hoping to find some old stock of those. PS/2 or USB is fine. I'm down to just 2 such mice, now, and they are getting old and cranky, needing frequent cleaning.
 
Old 09-15-2011, 04:14 AM   #4
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,703
Blog Entries: 23

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
...well...sorry I could'nt help....

I hope the answer will "materialise" here soon

Luck

Thor
 
Old 02-08-2012, 08:37 PM   #5
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, Ubuntu, Amazon Linux
Posts: 1,850
Blog Entries: 21

Original Poster
Rep: Reputation: 119Reputation: 119
I found the cause of the problem. It can still be argued that udev is NOT doing anything wrong. But, IMHO, it actually is doing a bad thing due to the fact that this is also killing my netbook battery. There still needs to be a way to turn this off in udev.

The cause is that many USB memory sticks have an auxiliary emulated cdrom device for storing the software they provide. When inserted, there are actually two subdevices created and registered in the USB device space. On is for the emulated hard drive, and one is for the emulated cdrom.

Udev sees cdroms as something it must constantly track the state of, to know when the cdrom is ejected. And it's using 34% of my netbook CPU capacity to do this (21% in one process, 13% in another). The only ways to make this stop that I can see are to kill or uninstall udev (very inconvenient), or to remove the USB memory stick (and use those that don't have emulated cdroms).
 
Old 02-08-2012, 11:18 PM   #6
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
I know you're probably long gone Thor, but yes, you can access a device without mounting it. It would be raw I/O. Doing so means you really, REALLY need to know what you're doing.

The requirement to mount a device is a mechanism for filesystem support. Under most circumstances, that's what people need.

Anyway, back to the original question. I can't offer you a solution per se, but a potential avenue to explore. If you are certain that this emulated CD portion of the thumb drive is the culprit and that the emulated CD portion is uniquely identifiable as a separate device (by USB bus-device ID or something similar), then you may be able to write a custom udev rule that will force udev to ignore that particular device. In effect, make the emulated CD portion invisible which should eliminate any access to it (outside of the access to the emulated HD).

There are quite a few udev-rule-writing guides on the web. Or perhaps start with the udev manpage. Obviously, if you choose to pursue this route, then you'll need to remove the rule anytime you need to access that emulated CD portion in the future.

Like I said, I can't give you a solution, but it would seem that the "ignore_device" option for the rule may be the ticket for this approach.
 
Old 02-09-2012, 02:31 PM   #7
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, Ubuntu, Amazon Linux
Posts: 1,850
Blog Entries: 21

Original Poster
Rep: Reputation: 119Reputation: 119
It only seems to be polling the device to detect if the media is ejected. Why? I don't know. Maybe it is to try to unmount a filesystem? If that is so, then it should only do so if mounted. But it is not mounted. Technically I can do a raw I/O of the CD/DVD. I've done so many times and saved them as ISO files (".iso" extension) for use in virtual machines, verify burns, etc. So maybe it will be removing the device node file when the media is absent? If it is no more than that, disabling it should not cripple anything.

I've written udev rules before. I actually had to do it dynamically. It reads /sys to get all ethernet NICs and map them to interface names in a canonical order based on physical bus address, so I can replace a NIC w/o losing the interface because the MAC changed. Eventually I'll upgrade that so it physically probes the network the NIC is attached to, so I can get a consistent network to name mapping. So this is probably a simpler challenge dealing with disabling media polling (what I think it is).
 
Old 02-09-2012, 04:21 PM   #8
Moss
LQ Newbie
 
Registered: Jul 2009
Location: Alaska USA
Distribution: Ubuntu and Puppy
Posts: 25

Rep: Reputation: 2
Quote:
Originally Posted by Skaperen View Post
The cause is that many USB memory sticks have an auxiliary emulated cdrom device for storing the software they provide. When inserted, there are actually two subdevices created and registered in the USB device space. On is for the emulated hard drive, and one is for the emulated cdrom.
Sounds like U3 strikes again. U3 is a royal pain to remove if you don't have access to admin on an MS machine, and San Disk is not at all cooperative about getting it out of there. Some IT types still think it can be removed by formatting the thumb drive. It cannot, because the computer sees it as "read only" or a CD-ROM.

Here is a thread on removing U3.
http://www.linuxquestions.org/questi...-drive-839426/

I finally smashed all of my San Drives, including the ones without U3, with a hammer and threw them away.
 
1 members found this post helpful.
Old 02-10-2012, 09:31 AM   #9
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Slackware, Ubuntu, Amazon Linux
Posts: 1,850
Blog Entries: 21

Original Poster
Rep: Reputation: 119Reputation: 119
That's definitely the source of the problem. I even knew the CD emulation was on those, but just didn't connect the dots.

BUT ... I do not put the full blame on San Disk. From their perspective, it's a way to be sure the loaded software does not get accidentally erased. And that's a plus for computer illiterate people which makes up the vast majority of the population. Yeah, sure, WE would like to recover that space which is surely in the flash, and use it for important stuff.

There should be "knobs and buttons" on software like udev to just turn stuff off, even if just "for now". But the Linux version of U3_tool could make these particular devices more geek friendly.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
UDEV: Unable to run a command line interface script after USB automount using udev mohamr2 Linux - Embedded & Single-board computer 8 08-16-2011 10:39 AM
UDEV - SBLive(emu10k) - Mandriva hangs at UDEV during boot.....still! Grrr. peterlowrie Linux - Hardware 2 05-23-2010 06:37 PM
current users - udev-128 - don't forget rc.udev.new! tobyl Slackware 3 10-08-2008 03:28 AM
Samba polling cups printserver, how do I stop it? cyent Linux - Server 4 06-11-2008 10:46 PM
slackware-current, udev 0.96, and custom udev rules not working rignes Slackware 6 08-10-2006 03:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration