losetup silently fails to attach small files

Bug #1326110 reported by Ryan Harper
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
util-linux (Ubuntu)
Triaged
Low
Unassigned

Bug Description

1) # lsb_release -rd
Description: Ubuntu 12.04.4 LTS
Release: 12.04

2) # apt-cache policy util-linux
util-linux:
  Installed: 2.20.1-1ubuntu3
  Candidate: 2.20.1-1ubuntu3
  Version table:
 *** 2.20.1-1ubuntu3 0
        500 http://archive.ubuntu.com//ubuntu/ precise/main amd64 Packages
        100 /var/lib/dpkg/status

3) losetup -f /srv/swift.img
attach the file to a free loop device

4) losetup -f /srv/swift.img returned 0, but did not attach the file to a loop device.

Specifically, the target file was very small, 20 bytes. The following sequence was run:

truncate --size 20 /srv/swift.img
stat /srv/swift.img
losetup -f /srv/swift.img
losetup -a

When the file is small (20 bytes) losetup returns zero, but does not setup the file. Through some investigation, it appears any file of size < 512 will fail in this way:

root@hayward-42:~# truncate --size 511 /srv/swift.img
root@hayward-42:~# stat /srv/swift.img
  File: `/srv/swift.img'
  Size: 511 Blocks: 0 IO Block: 4096 regular file
Device: 801h/2049d Inode: 5767170 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-06-03 19:24:58.213512482 +0000
Modify: 2014-06-03 19:26:52.593509603 +0000
Change: 2014-06-03 19:26:52.593509603 +0000
 Birth: -
root@hayward-42:~# losetup --find /srv/swift.img
root@hayward-42:~# echo $?
0
root@hayward-42:~# losetup -a

Here is a successful sequence with size=512:

root@hayward-42:~# truncate --size 512 /srv/swift.img
root@hayward-42:~# stat /srv/swift.img
  File: `/srv/swift.img'
  Size: 512 Blocks: 0 IO Block: 4096 regular file
Device: 801h/2049d Inode: 5767170 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-06-03 19:24:58.213512482 +0000
Modify: 2014-06-03 19:27:33.029508499 +0000
Change: 2014-06-03 19:27:33.029508499 +0000
 Birth: -
root@hayward-42:~# losetup --find /srv/swift.img
root@hayward-42:~# echo $?
0
root@hayward-42:~# losetup -a
/dev/loop7: [0801]:5767170 (/srv/swift.img)

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: mount 2.20.1-1ubuntu3
ProcVersionSignature: Ubuntu 3.2.0-60.91-generic 3.2.55
Uname: Linux 3.2.0-60-generic x86_64
ApportVersion: 2.0.1-0ubuntu17.6
Architecture: amd64
Date: Tue Jun 3 19:16:57 2014
MarkForUpload: True
ProcEnviron:
 TERM=screen
 PATH=(custom, no user)
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: util-linux
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Ryan Harper (raharper) wrote :
Revision history for this message
Phillip Susi (psusi) wrote :

Actually it does succeed; losetup /dev/loop0 shows the association. It is losetup -a that does not find the device because it is not listed in /proc/partitions, since its size is zero. It probably should not be using /proc/partitions to find loop devices.

Phillip Susi (psusi)
Changed in util-linux (Ubuntu):
status: New → Triaged
importance: Undecided → Low
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.