bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How best to wait for partition table kernel reload?


From: Jim Meyering
Subject: Re: How best to wait for partition table kernel reload?
Date: Thu, 24 Jun 2010 09:11:08 +0200

Harvey Chapman wrote:

> Summary: After using parted, the modified device files (/dev/sda1, etc.) have 
> not been restored before the next line in a script trying to use them.
>
> parted-2.3
> linux-2.6.34
> busybox-1.13.2   (using mdev with sequence numbers)
> ntfsprogs-2.0.0
>
> I have a bash script that resizes an NTFS partition using parted and 
> ntfsresize. I seem to have a race condition where sometimes, the device files 
> for the device just modifed have not yet been recreated before calling 
> ntfsresize. Is there anything I can do about this? I did have a problem with 
> mdev performing the hotplug actions out of order, but that seems to have been 
> fixed. I don't really want to sprinkle sleeps all throughout my scripts 
> either. I did that in one place, but on an older (read: slower) machine, that 
> failed.
>
> Is there a best practice way of doing this? Does anyone know how GParted 
> handles this?
>
> I don't have this problem with linux-2.6.31.5 and parted-1.8.9(ubuntu 8.10), 
> but I'd like to upgrade to get bug fixes and features.

You might want to try "udevadm settle" (aka the deprecated udevsettle command).

At worst, do something like I've done in parted's tests:
poll with a subsecond interval, checking for the existence
of a device file that you expect to be created.

Not everyone has a version of sleep that can handle
a subsecond interval, so I wrote a portable shell function
that degrades gracefully:

# Helper function: wait 2s (via .1s increments) for FILE to appear.
# Usage: wait_for_dev_to_appear_ /dev/sdg
# Return 0 upon success, 1 upon failure.
wait_for_dev_to_appear_()
{
  local file=$1
  local i=0
  local incr=1
  while :; do
    ls "$file" > /dev/null 2>&1 && return 0
    sleep .1 2>/dev/null || { sleep 1; incr=10; }
    i=$(expr $i + $incr); test $i = 20 && break
  done
  return 1
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]