Commit Graph

33 Commits

Author SHA1 Message Date
Karel Zak a61955ba1f lib/loopdev: cosmetic changes to LOOP_CONFIGURE
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-05 14:52:20 +02:00
Sinan Kaya d5fd456c88 loopdev: use LOOP_CONFIG ioctl
Prefer to use the new LOOP_CONFIG ioctl.
https://lwn.net/Articles/820408/

Signed-off-by: Sinan Kaya <sinan.kaya@microsoft.com>
2020-09-30 20:04:21 -04:00
Karel Zak 14bb8e3ca6 lsblk: ignore only loopdevs without backing file
* do not ignore all empty devices, we need more smart solution

* ignore only loop devices without backing file, for example:
 # touch img
 # losetup -f img
 losetup: img: Warning: file is smaller than 512 bytes; the loop device may be useless or invisible for system tools.

 - old version display nothing
 - new version:

 # lsblk /dev/loop0
 NAME  MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
 loop0   7:0    0   0B  0 loop

Addresses: https://github.com/karelzak/util-linux/issues/1118
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-09 12:23:33 +02:00
Karel Zak 75d239ffd8 lib/loopdev: set blocksize when create a new device
The partition scanner in kernel depends on blocksize. We need to set
the blocksize before we call LOOP_SET_STATUS64 (this ioctl triggers
the scanner).

This patch extends the internal API to save blocksize into loopdev
context to be usable later for loopcxt_setup_device().

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-01-22 11:37:35 +01:00
Karel Zak 9fcc893624 lib/loopdev: differentiate between setter()s and ioctl calls
Now the internal API uses loopcxt_set_...() to set context variables
as well as to call ioctls. This patch introduces loopcxt_ioctl_...()
to makes things more obvious to readers.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-01-22 11:12:42 +01:00
Karel Zak 7604f85fb6 lib/loopdev: use new ul_path_* API
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-21 13:07:46 +02:00
Stanislav Brabec a1a41597bf losetup: Add support for logical block size
Kernel since 4.14 supports setting of logical block size[1]. It allows to
create loop devices that report logical block size different from 512.

Add support for this feature to losetup.

References:
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/block/loop.c?id=89e4fdecb51cf5535867026274bc97de9480ade5

[kzak@redhat.com: - fix loopcxt_get_blocksize()
                  - remove lo_blocksize from loop_info64]

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Omar Sandoval <osandov@fb.com>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-27 14:30:02 +02:00
Stanislav Brabec bfd4e1f758 loopdev: Implememt loopcxt_set_status()
Implement stand-alone loopcxt_set_status(). It allows manipulation with some
loop device parameters even if it is initialized.

Its function is limited by the kernel implementation, and only a small subset of
changes is allowed.

For more see linux/drivers/block/loop.c:loop_set_status()

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-17 12:49:06 +02:00
Karel Zak c444a71b1b lib/loopdev: cleanup sizelimit check
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-04 10:49:46 +02:00
Stanislav Brabec 211e1d4609 Implement loopcxt_check_conflict()
Add a function that searches for a possible conflicting (i. e. overlaying loop
device).

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-03 11:53:28 +02:00
Stanislav Brabec 74a4705a99 Add sizelimit to internal API
Fully safe checks of loop device need to check sizelimit. To prevent need of two
nearly equal functions, introduce sizelimit parameter to several internal
functions:
loopdev_is_used()
loopdev_find_by_backing_file()
loopcxt_is_used()
loopcxt_find_by_backing_file()

If sizelimit is zero, fall back to the old behavior (ignoring of sizelimit).

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-03 11:53:28 +02:00
Ming Lei faeef4d2e9 losetup: support list direct io
So that user can see if DIO is set for current loop device.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
2015-11-19 11:27:36 +01:00
Ming Lei 64c3bb3cb7 losetup: support ioctl cmd of LOOP_SET_DIRECT_IO
From v4.4, linux kernel starts to support direct I/O and
AIO to backing file for loop driver, so allow losetup to
enable the feature by using LOOP_SET_DIRECT_IO ioctl cmd.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
2015-11-19 11:27:36 +01:00
Karel Zak 0bf037402a lib/loopdev: replace custom DBG() with include/debug.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-11-04 14:08:45 +01:00
Lauri Nurmi a5c523a0e7 Fix typo "ioclt" in various files. 2014-07-11 22:52:09 +03:00
Karel Zak 663bf04061 losetup: wait for udev
On system with /dev/lop-control the udevd creates /dev/loopN nodes.
It seems better to wait a moment after unsuccessful open(/dev/loopN)
and try it to open again.

The problem is pretty visible on systems where udevd also modifies
permission for loopN devices, then open() fails with EACCES when
losetup executed by non-root user (but user who is in "disk" group).

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1045432
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-24 13:58:40 +01:00
Karel Zak 3cb2413b02 losetup: use loop-control to explicitly ask for device
Now we use LOOP_CTL_GET_FREE ioctl to ask for free device, for example

  losetup -f foo.img

Unfortunately, losetup(8) allows to ask for specified device

  losetup /dev/loop100 foo.img

and in this case we assume that the device already exists in the
system. This is incorrect, we should be able to use loop-control
LOOP_CTL_ADD ioctl to ask for the specified device.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-08-06 11:04:35 +02:00
Jeff Mahoney 293714c0d1 loopdev: sync capacity after setting it
I recently tried to mount an hfsplus file system from an image file with
a partition table by using the loop offset and sizelimit options to specify
the location of the file system.

hfsplus stores some metadata at a set offset from the end of the partition,
so it's sensitive to the device size reported by the kernel.

It worked with this:

But failed with this:

/dev/loop0: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000
/dev/loop1: [0089]:2 (<imagefile>), offset 32768, sizelimit 102400000

/proc/partitions shows the correct number of blocks to match the sizelimit.

But if I set a breakpoint in mount before the mount syscall, I could see:
102400000
102432768

The kernel loop driver will set the gendisk capacity of the device at
LOOP_SET_STATUS64 but won't sync it to the block device until one of two
conditions are met: All open file descriptors referring to the device are
closed (and it will sync when re-opened) or if the LOOP_SET_CAPACITY ioctl
is called to sync it. Since mount opens the device and passes it directly
to the mount syscall after LOOP_SET_STATUS64 without closing and reopening
it, the sizelimit argument is effectively ignroed. The capacity needs to
be synced immediately for it to work as expected.

This patch adds the LOOP_SET_CAPACITY call to loopctx_setup_device since
the device isn't yet released to the user, so it's safe to sync the capacity
immediately.

[kzak@redhat.com: - port to the current git HEAD,
                  - use uint64_t]

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-09 14:32:50 +02:00
Ludwig Nussel 5cf05c7147 mount: losetup: remove obsolete encryption support
kernel cryptoloop is deprecated since ages and support for cryptoloop
in util-linux is incomplete/broken.
- no password hashing
- last 8 bit of key are always set to zero
- no binary keys possible (stops reading key at \n and \0)

In the past some Distros added the above features with patches. So
remove cryptoloop support from util-linux completely to make sure
people won't try using it.

Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-11 10:46:11 +02:00
Karel Zak defa0710b6 lib/loopdev: use warn_unused_result forimportant functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-21 10:40:43 +02:00
Karel Zak e4062c72d1 losetup: improve -a to report loopdevs < 512 bytes
# ll ~/xxx2
  -rw-r--r-- 1 root root 500 Jun 12 14:30 /root/xxx2

 old version:
  # losetup -a

 new version:
  # losetup -a
  /dev/loop0: [2052]:535312 (/root/xxx2)

The new version scans /sys/block/loopN, kernel >= 2.6.37 is required
otherwise fallback to the original not-so-smart /proc/partitions scan.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=730266
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-12 15:41:47 +02:00
Karel Zak 6219c25ecb lib/loopdev: more robust initialization
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-04-02 17:33:41 +02:00
Karel Zak 916bf85e62 losetup: add --partscan option
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-09 23:28:50 +01:00
Karel Zak 59d749c331 loopdev: support LO_FLAGS_PARTSCAN flag (kernel 3.2)
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-09 23:28:43 +01:00
Karel Zak c7e0925def losetup: rewrite loop setup
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-12-22 12:19:38 +01:00
Karel Zak 6c224de18b lib,loopdev: add missing functions
- improve loop_info usage (don't call ioctl more than once)
 - add functions to get devno and inode of the backing file
 - add function for compare any file with backing file by devno + inode
   or by filename

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-12-22 12:19:38 +01:00
Karel Zak 0b14bf7af1 lib,loopdev: add LOOP_CTL_GET_FREE support
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-07 16:45:11 +01:00
Dave Reisner c8ea35145e include/loopdev.h: add missing function prototype
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2011-10-12 10:01:09 +02:00
Karel Zak d568813071 umount: use new lib/loopdev.c code
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-30 11:09:38 +02:00
Karel Zak aee31ddc59 lib,loopdev: add debugu messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-29 23:28:36 +02:00
Karel Zak 9feec79cc5 misc: use unsigned int for bit-fileds
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-07-29 10:51:06 +02:00
Karel Zak fd7f0718d4 lib: [loopdev.c] cleanup flags usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-06-10 15:38:13 +02:00
Karel Zak 10ee593293 lib: [loopdev.c] add module for work loop devices
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-30 16:37:46 +02:00