All of lore.kernel.org
 help / color / mirror / Atom feed
From: Karel Zak <kzak@redhat.com>
To: butter@breezl.com
Cc: util-linux@vger.kernel.org, Phillip Susi <psusi@ubuntu.com>
Subject: Re: losetup -d does not move partition devices
Date: Mon, 7 Oct 2013 13:38:52 +0200	[thread overview]
Message-ID: <20131007113852.GF14360@x2.net.home> (raw)
In-Reply-To: <5241BC33.8050700@breezl.com>

On Tue, Sep 24, 2013 at 06:22:11PM +0200, butter@breezl.com wrote:
> get deleted when you call "losetup -d DEVICE". This causes other programs
> (like lvmdiskscan -l) to report Input/output errors.
> 
> Here is how to reproduce the problem:
> 
> 	LOOPDEV=/dev/loop3
> 	IMAGEFILE=`pwd`/mydisk.img
> 	MOUNTPOINT=`pwd`/mnt
> 
> 	# 1. Create and mount an ext4 partition from a file-based disk image
> 	dd if=/dev/zero of=$IMAGEFILE bs=1M count=80
> 	sudo losetup $LOOPDEV $IMAGEFILE

kernel uses partitions on loop devices conditionally, and here you said
"I don't care about partitions...". You have to use

    sudo losetup -P $LOOPDEV $IMAGEFILE

if you want to force kernel loopdev driver to use partitions.

> 	sudo parted $LOOPDEV mklabel msdos
> 	sudo parted $LOOPDEV mkpart primary 2048s    43007s
> 	sudo mkfs -t ext4 ${LOOPDEV}p1
> 	mkdir $MOUNTPOINT
> 	sudo mount ${LOOPDEV}p1 $MOUNTPOINT
> 
> 	# 2. Unmount again => ERROR: the partition device files are not deleted
> 	sudo umount $MOUNTPOINT

mount/umount is completely irrelevant for this issue. The simple way
to reproduce the problem is:

         dd if=/dev/zero of=img bs=1M count=80
         losetup -f img --show
         parted /dev/loop0 mklabel msdos
         parted /dev/loop0 mklabel msdos
         losetup -d /dev/loop0

         cat /sys/block/loop0/size
         cat /sys/block/loop0/loop0p1/size

Anyway, the problem is that parted uses BLKPG_ADD_PARTITION ioctl to create
/dev/loop0p1, but the loop0 device has been created without PARTSCAN flag 
(see /sys/block/loop0/loop/partscan). It means that loopdev kernel driver
does not call BLKRRPART during loop0 cleanup (loop_clr_fd() in kernel code).

You can remove the partition manually by BLKPG_DEL_PARTITION ioctl:

    # partx -d /dev/loop0p1


... but this all is known issue, Phillip Susi tried to fix this
disadvantage, but his solution has been reverted (see kernel commit
c2fccc1c9f7c81700cbac2120a4ad5441dd37004).


    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

  reply	other threads:[~2013-10-07 11:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-24 16:22 losetup -d does not move partition devices butter
2013-10-07 11:38 ` Karel Zak [this message]
2013-10-07 14:24   ` Phillip Susi
2013-10-08 23:22   ` butter
2013-10-09  7:53     ` Karel Zak
2013-10-09 10:16       ` Matthias Schniedermeyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131007113852.GF14360@x2.net.home \
    --to=kzak@redhat.com \
    --cc=butter@breezl.com \
    --cc=psusi@ubuntu.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.