"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/utils_device.c" between
cryptsetup-2.0.6.tar.xz and cryptsetup-2.1.0.tar.xz

About: cryptsetup is a utility used to conveniently setup disk encryption based on the dm-crypt kernel module. These include plain dm-crypt volumes, LUKS volumes, loop-AES and TrueCrypt compatible format.

utils_device.c  (cryptsetup-2.0.6.tar.xz):utils_device.c  (cryptsetup-2.1.0.tar.xz)
/* /*
* device backend utilities * device backend utilities
* *
* Copyright (C) 2004, Jana Saout <jana@saout.de> * Copyright (C) 2004 Jana Saout <jana@saout.de>
* Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org> * Copyright (C) 2004-2007 Clemens Fruhwirth <clemens@endorphin.org>
* Copyright (C) 2009-2018, Red Hat, Inc. All rights reserved. * Copyright (C) 2009-2019 Red Hat, Inc. All rights reserved.
* Copyright (C) 2009-2018, Milan Broz * Copyright (C) 2009-2019 Milan Broz
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 52 skipping to change at line 52
struct device { struct device {
char *path; char *path;
char *file_path; char *file_path;
int loop_fd; int loop_fd;
struct crypt_lock_handle *lh; struct crypt_lock_handle *lh;
unsigned int o_direct:1; unsigned int o_direct:1;
unsigned int init_done:1; unsigned int init_done:1; /* path is bdev or loop already initialized */
/* cached values */ /* cached values */
size_t alignment; size_t alignment;
size_t block_size; size_t block_size;
}; };
static size_t device_fs_block_size_fd(int fd) static size_t device_fs_block_size_fd(int fd)
{ {
size_t page_size = crypt_getpagesize(); size_t page_size = crypt_getpagesize();
skipping to change at line 156 skipping to change at line 156
} }
/* /*
* The direct-io is always preferred. The header is usually mapped to the same * The direct-io is always preferred. The header is usually mapped to the same
* device and can be accessed when the rest of device is mapped to data device. * device and can be accessed when the rest of device is mapped to data device.
* Using dirct-io encsures that we do not mess with data in cache. * Using dirct-io encsures that we do not mess with data in cache.
* (But proper alignment should prevent this in the first place.) * (But proper alignment should prevent this in the first place.)
* The read test is needed to detect broken configurations (seen with remote * The read test is needed to detect broken configurations (seen with remote
* block devices) that allow open with direct-io but then fails on read. * block devices) that allow open with direct-io but then fails on read.
*/ */
static int device_ready(struct device *device) static int device_ready(struct crypt_device *cd, struct device *device)
{ {
int devfd = -1, r = 0; int devfd = -1, r = 0;
struct stat st; struct stat st;
size_t tmp_size; size_t tmp_size;
if (device->o_direct) { if (device->o_direct) {
log_dbg("Trying to open and read device %s with direct-io.", log_dbg(cd, "Trying to open and read device %s with direct-io.",
device_path(device)); device_path(device));
device->o_direct = 0; device->o_direct = 0;
devfd = open(device_path(device), O_RDONLY | O_DIRECT); devfd = open(device_path(device), O_RDONLY | O_DIRECT);
if (devfd >= 0) { if (devfd >= 0) {
if (device_read_test(devfd) == 0) { if (device_read_test(devfd) == 0) {
device->o_direct = 1; device->o_direct = 1;
} else { } else {
close(devfd); close(devfd);
devfd = -1; devfd = -1;
} }
} }
} }
if (devfd < 0) { if (devfd < 0) {
log_dbg("Trying to open device %s without direct-io.", log_dbg(cd, "Trying to open device %s without direct-io.",
device_path(device)); device_path(device));
devfd = open(device_path(device), O_RDONLY); devfd = open(device_path(device), O_RDONLY);
} }
if (devfd < 0) { if (devfd < 0) {
log_err(NULL, _("Device %s doesn't exist or access denied."), log_err(cd, _("Device %s doesn't exist or access denied."),
device_path(device)); device_path(device));
return -EINVAL; return -EINVAL;
} }
if (fstat(devfd, &st) < 0) if (fstat(devfd, &st) < 0)
r = -EINVAL; r = -EINVAL;
else if (!S_ISBLK(st.st_mode)) else if (!S_ISBLK(st.st_mode))
r = S_ISREG(st.st_mode) ? -ENOTBLK : -EINVAL; r = S_ISREG(st.st_mode) ? -ENOTBLK : -EINVAL;
if (r == -EINVAL) { if (r == -EINVAL) {
log_err(NULL, _("Device %s is not compatible."), log_err(cd, _("Device %s is not compatible."),
device_path(device)); device_path(device));
close(devfd); close(devfd);
return r; return r;
} }
/* Allow only increase (loop device) */ /* Allow only increase (loop device) */
tmp_size = device_alignment_fd(devfd); tmp_size = device_alignment_fd(devfd);
if (tmp_size > device->alignment) if (tmp_size > device->alignment)
device->alignment = tmp_size; device->alignment = tmp_size;
tmp_size = device_block_size_fd(devfd, NULL); tmp_size = device_block_size_fd(devfd, NULL);
if (tmp_size > device->block_size) if (tmp_size > device->block_size)
device->block_size = tmp_size; device->block_size = tmp_size;
close(devfd); close(devfd);
return r; return r;
} }
static int _open_locked(struct device *device, int flags) static int _open_locked(struct crypt_device *cd, struct device *device, int flag s)
{ {
int fd; int fd;
log_dbg("Opening locked device %s", device_path(device)); log_dbg(cd, "Opening locked device %s", device_path(device));
if ((flags & O_ACCMODE) != O_RDONLY && device_locked_readonly(device->lh) ) { if ((flags & O_ACCMODE) != O_RDONLY && device_locked_readonly(device->lh) ) {
log_dbg("Can not open locked device %s in write mode. Read lock h eld.", device_path(device)); log_dbg(cd, "Can not open locked device %s in write mode. Read lo ck held.", device_path(device));
return -EAGAIN; return -EAGAIN;
} }
fd = open(device_path(device), flags); fd = open(device_path(device), flags);
if (fd < 0) if (fd < 0)
return -errno; return -errno;
if (device_locked_verify(fd, device->lh)) { if (device_locked_verify(cd, fd, device->lh)) {
/* fd doesn't correspond to a locked resource */ /* fd doesn't correspond to a locked resource */
close(fd); close(fd);
log_dbg("Failed to verify lock resource for device %s.", device_p ath(device)); log_dbg(cd, "Failed to verify lock resource for device %s.", devi ce_path(device));
return -EINVAL; return -EINVAL;
} }
return fd; return fd;
} }
/* /*
* Common wrapper for device sync. * Common wrapper for device sync.
* FIXME: file descriptor will be in struct later. * FIXME: file descriptor will be in struct later.
*/ */
void device_sync(struct device *device, int devfd) void device_sync(struct crypt_device *cd, struct device *device, int devfd)
{ {
if (fsync(devfd) == -1) if (fsync(devfd) == -1)
log_dbg("Cannot sync device %s.", device_path(device)); log_dbg(cd, "Cannot sync device %s.", device_path(device));
} }
/* /*
* in non-locked mode returns always fd or -1 * in non-locked mode returns always fd or -1
* *
* in locked mode: * in locked mode:
* opened fd or one of: * opened fd or one of:
* -EAGAIN : requested write mode while device being locked in via shared lo ck * -EAGAIN : requested write mode while device being locked in via shared lo ck
* -EINVAL : invalid lock fd state * -EINVAL : invalid lock fd state
* -1 : all other errors * -1 : all other errors
*/ */
static int device_open_internal(struct device *device, int flags) static int device_open_internal(struct crypt_device *cd, struct device *device, int flags)
{ {
int devfd; int devfd;
if (device->o_direct) if (device->o_direct)
flags |= O_DIRECT; flags |= O_DIRECT;
if (device_locked(device->lh)) if (device_locked(device->lh))
devfd = _open_locked(device, flags); devfd = _open_locked(cd, device, flags);
else else
devfd = open(device_path(device), flags); devfd = open(device_path(device), flags);
if (devfd < 0) if (devfd < 0)
log_dbg("Cannot open device %s%s.", log_dbg(cd, "Cannot open device %s%s.",
device_path(device), device_path(device),
(flags & O_ACCMODE) != O_RDONLY ? " for write" : ""); (flags & O_ACCMODE) != O_RDONLY ? " for write" : "");
return devfd; return devfd;
} }
int device_open(struct device *device, int flags) int device_open(struct crypt_device *cd, struct device *device, int flags)
{ {
assert(!device_locked(device->lh)); assert(!device_locked(device->lh));
return device_open_internal(device, flags); return device_open_internal(cd, device, flags);
} }
int device_open_locked(struct device *device, int flags) int device_open_locked(struct crypt_device *cd, struct device *device, int flags )
{ {
assert(!crypt_metadata_locking_enabled() || device_locked(device->lh)); assert(!crypt_metadata_locking_enabled() || device_locked(device->lh));
return device_open_internal(device, flags); return device_open_internal(cd, device, flags);
} }
/* Avoid any read from device, expects direct-io to work. */ /* Avoid any read from device, expects direct-io to work. */
int device_alloc_no_check(struct device **device, const char *path) int device_alloc_no_check(struct device **device, const char *path)
{ {
struct device *dev; struct device *dev;
if (!path) { if (!path) {
*device = NULL; *device = NULL;
return 0; return 0;
skipping to change at line 316 skipping to change at line 316
free(dev); free(dev);
return -ENOMEM; return -ENOMEM;
} }
dev->loop_fd = -1; dev->loop_fd = -1;
dev->o_direct = 1; dev->o_direct = 1;
*device = dev; *device = dev;
return 0; return 0;
} }
int device_alloc(struct device **device, const char *path) int device_alloc(struct crypt_device *cd, struct device **device, const char *pa th)
{ {
struct device *dev; struct device *dev;
int r; int r;
r = device_alloc_no_check(&dev, path); r = device_alloc_no_check(&dev, path);
if (r < 0) if (r < 0)
return r; return r;
if (dev) { if (dev) {
r = device_ready(dev); r = device_ready(cd, dev);
if (!r) { if (!r) {
dev->init_done = 1; dev->init_done = 1;
} else if (r == -ENOTBLK) { } else if (r == -ENOTBLK) {
/* alloc loop later */ /* alloc loop later */
} else if (r < 0) { } else if (r < 0) {
free(dev->path); free(dev->path);
free(dev); free(dev);
return -ENOTBLK; return -ENOTBLK;
} }
} }
*device = dev; *device = dev;
return 0; return 0;
} }
void device_free(struct device *device) void device_free(struct crypt_device *cd, struct device *device)
{ {
if (!device) if (!device)
return; return;
if (device->loop_fd != -1) { if (device->loop_fd != -1) {
log_dbg("Closed loop %s (%s).", device->path, device->file_path); log_dbg(cd, "Closed loop %s (%s).", device->path, device->file_pa th);
close(device->loop_fd); close(device->loop_fd);
} }
assert (!device_locked(device->lh)); assert (!device_locked(device->lh));
free(device->file_path); free(device->file_path);
free(device->path); free(device->path);
free(device); free(device);
} }
skipping to change at line 402 skipping to change at line 402
return device->path; return device->path;
} }
/* block device topology ioctls, introduced in 2.6.32 */ /* block device topology ioctls, introduced in 2.6.32 */
#ifndef BLKIOMIN #ifndef BLKIOMIN
#define BLKIOMIN _IO(0x12,120) #define BLKIOMIN _IO(0x12,120)
#define BLKIOOPT _IO(0x12,121) #define BLKIOOPT _IO(0x12,121)
#define BLKALIGNOFF _IO(0x12,122) #define BLKALIGNOFF _IO(0x12,122)
#endif #endif
void device_topology_alignment(struct device *device, void device_topology_alignment(struct crypt_device *cd,
unsigned long *required_alignment, /* bytes */ struct device *device,
unsigned long *alignment_offset, /* bytes */ unsigned long *required_alignment, /* bytes */
unsigned long default_alignment) unsigned long *alignment_offset, /* bytes */
unsigned long default_alignment)
{ {
int dev_alignment_offset = 0; int dev_alignment_offset = 0;
unsigned int min_io_size = 0, opt_io_size = 0; unsigned int min_io_size = 0, opt_io_size = 0;
unsigned long temp_alignment = 0; unsigned long temp_alignment = 0;
int fd; int fd;
*required_alignment = default_alignment; *required_alignment = default_alignment;
*alignment_offset = 0; *alignment_offset = 0;
if (!device || !device->path) //FIXME if (!device || !device->path) //FIXME
return; return;
fd = open(device->path, O_RDONLY); fd = open(device->path, O_RDONLY);
if (fd == -1) if (fd == -1)
return; return;
/* minimum io size */ /* minimum io size */
if (ioctl(fd, BLKIOMIN, &min_io_size) == -1) { if (ioctl(fd, BLKIOMIN, &min_io_size) == -1) {
log_dbg("Topology info for %s not supported, using default offset %lu bytes.", log_dbg(cd, "Topology info for %s not supported, using default of fset %lu bytes.",
device->path, default_alignment); device->path, default_alignment);
goto out; goto out;
} }
/* optimal io size */ /* optimal io size */
if (ioctl(fd, BLKIOOPT, &opt_io_size) == -1) if (ioctl(fd, BLKIOOPT, &opt_io_size) == -1)
opt_io_size = min_io_size; opt_io_size = min_io_size;
/* alignment offset, bogus -1 means misaligned/unknown */ /* alignment offset, bogus -1 means misaligned/unknown */
if (ioctl(fd, BLKALIGNOFF, &dev_alignment_offset) == -1 || dev_alignment_ offset < 0) if (ioctl(fd, BLKALIGNOFF, &dev_alignment_offset) == -1 || dev_alignment_ offset < 0)
skipping to change at line 449 skipping to change at line 450
/* Ignore bogus opt-io that could break alignment */ /* Ignore bogus opt-io that could break alignment */
if ((temp_alignment < (unsigned long)opt_io_size) && if ((temp_alignment < (unsigned long)opt_io_size) &&
!((unsigned long)opt_io_size % temp_alignment)) !((unsigned long)opt_io_size % temp_alignment))
temp_alignment = (unsigned long)opt_io_size; temp_alignment = (unsigned long)opt_io_size;
/* If calculated alignment is multiple of default, keep default */ /* If calculated alignment is multiple of default, keep default */
if (temp_alignment && (default_alignment % temp_alignment)) if (temp_alignment && (default_alignment % temp_alignment))
*required_alignment = temp_alignment; *required_alignment = temp_alignment;
log_dbg("Topology: IO (%u/%u), offset = %lu; Required alignment is %lu by tes.", log_dbg(cd, "Topology: IO (%u/%u), offset = %lu; Required alignment is %l u bytes.",
min_io_size, opt_io_size, *alignment_offset, *required_alignment) ; min_io_size, opt_io_size, *alignment_offset, *required_alignment) ;
out: out:
(void)close(fd); (void)close(fd);
} }
size_t device_block_size(struct device *device) size_t device_block_size(struct crypt_device *cd, struct device *device)
{ {
int fd; int fd;
if (!device) if (!device)
return 0; return 0;
if (device->block_size) if (device->block_size)
return device->block_size; return device->block_size;
fd = open(device->file_path ?: device->path, O_RDONLY); fd = open(device->file_path ?: device->path, O_RDONLY);
if (fd >= 0) { if (fd >= 0) {
device->block_size = device_block_size_fd(fd, NULL); device->block_size = device_block_size_fd(fd, NULL);
close(fd); close(fd);
} }
if (!device->block_size) if (!device->block_size)
log_dbg("Cannot get block size for device %s.", device_path(devic e)); log_dbg(cd, "Cannot get block size for device %s.", device_path(d evice));
return device->block_size; return device->block_size;
} }
int device_read_ahead(struct device *device, uint32_t *read_ahead) int device_read_ahead(struct device *device, uint32_t *read_ahead)
{ {
int fd, r = 0; int fd, r = 0;
long read_ahead_long; long read_ahead_long;
if (!device) if (!device)
skipping to change at line 527 skipping to change at line 528
return r; return r;
} }
/* For a file, allocate the required space */ /* For a file, allocate the required space */
int device_fallocate(struct device *device, uint64_t size) int device_fallocate(struct device *device, uint64_t size)
{ {
struct stat st; struct stat st;
int devfd, r = -EINVAL; int devfd, r = -EINVAL;
devfd = open(device_path(device), O_RDWR); devfd = open(device_path(device), O_RDWR);
if(devfd == -1) if (devfd == -1)
return -EINVAL; return -EINVAL;
if (!fstat(devfd, &st) && S_ISREG(st.st_mode) && if (!fstat(devfd, &st) && S_ISREG(st.st_mode) &&
!posix_fallocate(devfd, 0, size)) { ((uint64_t)st.st_size >= size || !posix_fallocate(devfd, 0, size))) {
r = 0; r = 0;
if (device->file_path && crypt_loop_resize(device->path)) if (device->file_path && crypt_loop_resize(device->path))
r = -EINVAL; r = -EINVAL;
} }
close(devfd); close(devfd);
return r; return r;
} }
int device_check_size(struct crypt_device *cd,
struct device *device,
uint64_t req_offset, int falloc)
{
uint64_t dev_size;
if (device_size(device, &dev_size)) {
log_dbg(cd, "Cannot get device size for device %s.", device_path(
device));
return -EIO;
}
log_dbg(cd, "Device size %" PRIu64 ", offset %" PRIu64 ".", dev_size, req
_offset);
if (req_offset > dev_size) {
/* If it is header file, increase its size */
if (falloc && !device_fallocate(device, req_offset))
return 0;
log_err(cd, _("Device %s is too small. Need at least %" PRIu64 "
bytes."),
device_path(device), req_offset);
return -EINVAL;
}
return 0;
}
static int device_info(struct crypt_device *cd, static int device_info(struct crypt_device *cd,
struct device *device, struct device *device,
enum devcheck device_check, enum devcheck device_check,
int *readonly, uint64_t *size) int *readonly, uint64_t *size)
{ {
struct stat st; struct stat st;
int fd = -1, r, flags = 0, real_readonly; int fd = -1, r, flags = 0, real_readonly;
uint64_t real_size; uint64_t real_size;
if (!device) if (!device)
skipping to change at line 649 skipping to change at line 676
if (device->init_done) if (device->init_done)
return 0; return 0;
if (getuid() || geteuid()) { if (getuid() || geteuid()) {
log_err(cd, _("Cannot use a loopback device, " log_err(cd, _("Cannot use a loopback device, "
"running as non-root user.")); "running as non-root user."));
return -ENOTSUP; return -ENOTSUP;
} }
log_dbg("Allocating a free loop device."); log_dbg(cd, "Allocating a free loop device.");
/* Keep the loop open, dettached on last close. */ /* Keep the loop open, dettached on last close. */
loop_fd = crypt_loop_attach(&loop_device, device->path, 0, 1, &readonly); loop_fd = crypt_loop_attach(&loop_device, device->path, 0, 1, &readonly);
if (loop_fd == -1) { if (loop_fd == -1) {
log_err(cd, _("Attaching loopback device failed " log_err(cd, _("Attaching loopback device failed "
"(loop device with autoclear flag is required).")); "(loop device with autoclear flag is required)."));
free(loop_device); free(loop_device);
return -EINVAL; return -EINVAL;
} }
file_path = device->path; file_path = device->path;
device->path = loop_device; device->path = loop_device;
r = device_ready(device); r = device_ready(cd, device);
if (r < 0) { if (r < 0) {
device->path = file_path; device->path = file_path;
crypt_loop_detach(loop_device); crypt_loop_detach(loop_device);
free(loop_device); free(loop_device);
return r; return r;
} }
device->loop_fd = loop_fd; device->loop_fd = loop_fd;
device->file_path = file_path; device->file_path = file_path;
device->init_done = 1; device->init_done = 1;
skipping to change at line 716 skipping to change at line 743
*size = real_size; *size = real_size;
if (!*size) { if (!*size) {
log_err(cd, _("Device %s has zero size."), device_path(de vice)); log_err(cd, _("Device %s has zero size."), device_path(de vice));
return -ENOTBLK; return -ENOTBLK;
} }
*size -= device_offset; *size -= device_offset;
} }
/* in case of size is set by parameter */ /* in case of size is set by parameter */
if (size && ((real_size - device_offset) < *size)) { if (size && ((real_size - device_offset) < *size)) {
log_dbg("Device %s: offset = %" PRIu64 " requested size = %" PRIu 64 log_dbg(cd, "Device %s: offset = %" PRIu64 " requested size = %" PRIu64
", backing device size = %" PRIu64, ", backing device size = %" PRIu64,
device->path, device_offset, *size, real_size); device->path, device_offset, *size, real_size);
log_err(cd, _("Device %s is too small."), device_path(device)); log_err(cd, _("Device %s is too small."), device_path(device));
return -EINVAL; return -EINVAL;
} }
if (flags && real_readonly) if (flags && real_readonly)
*flags |= CRYPT_ACTIVATE_READONLY; *flags |= CRYPT_ACTIVATE_READONLY;
if (size) if (size)
log_dbg("Calculated device size is %" PRIu64" sectors (%s), offse t %" PRIu64 ".", log_dbg(cd, "Calculated device size is %" PRIu64" sectors (%s), o ffset %" PRIu64 ".",
*size, real_readonly ? "RO" : "RW", device_offset); *size, real_readonly ? "RO" : "RW", device_offset);
return 0; return 0;
} }
size_t size_round_up(size_t size, size_t block) size_t size_round_up(size_t size, size_t block)
{ {
size_t s = (size + (block - 1)) / block; size_t s = (size + (block - 1)) / block;
return s * block; return s * block;
} }
void device_disable_direct_io(struct device *device) void device_disable_direct_io(struct device *device)
{ {
device->o_direct = 0; device->o_direct = 0;
} }
int device_direct_io(const struct device *device) int device_direct_io(const struct device *device)
{ {
return device->o_direct; return device->o_direct;
} }
static dev_t device_devno(const struct device *device)
{
struct stat st;
if (stat(device->path, &st) || !S_ISBLK(st.st_mode))
return 0;
return st.st_rdev;
}
int device_is_identical(struct device *device1, struct device *device2) int device_is_identical(struct device *device1, struct device *device2)
{ {
if (!device1 || !device2)
return 0;
if (device1 == device2) if (device1 == device2)
return 1; return 1;
if (!device1 || !device2 || !device_path(device1) || !device_path(device2 if (device1->init_done && device2->init_done)
)) return (device_devno(device1) == device_devno(device2));
else if (device1->init_done || device2->init_done)
return 0; return 0;
/* This should be better check - major/minor for block device etc */
if (!strcmp(device_path(device1), device_path(device2))) if (!strcmp(device_path(device1), device_path(device2)))
return 1; return 1;
return 0; return 0;
} }
int device_is_rotational(struct device *device) int device_is_rotational(struct device *device)
{ {
struct stat st; struct stat st;
skipping to change at line 801 skipping to change at line 842
int device_read_lock(struct crypt_device *cd, struct device *device) int device_read_lock(struct crypt_device *cd, struct device *device)
{ {
if (!crypt_metadata_locking_enabled()) if (!crypt_metadata_locking_enabled())
return 0; return 0;
assert(!device_locked(device->lh)); assert(!device_locked(device->lh));
device->lh = device_read_lock_handle(cd, device_path(device)); device->lh = device_read_lock_handle(cd, device_path(device));
if (device_locked(device->lh)) { if (device_locked(device->lh)) {
log_dbg("Device %s READ lock taken.", device_path(device)); log_dbg(cd, "Device %s READ lock taken.", device_path(device));
return 0; return 0;
} }
return -EBUSY; return -EBUSY;
} }
int device_write_lock(struct crypt_device *cd, struct device *device) int device_write_lock(struct crypt_device *cd, struct device *device)
{ {
if (!crypt_metadata_locking_enabled()) if (!crypt_metadata_locking_enabled())
return 0; return 0;
assert(!device_locked(device->lh)); assert(!device_locked(device->lh));
device->lh = device_write_lock_handle(cd, device_path(device)); device->lh = device_write_lock_handle(cd, device_path(device));
if (device_locked(device->lh)) { if (device_locked(device->lh)) {
log_dbg("Device %s WRITE lock taken.", device_path(device)); log_dbg(cd, "Device %s WRITE lock taken.", device_path(device));
return 0; return 0;
} }
return -EBUSY; return -EBUSY;
} }
void device_read_unlock(struct device *device) void device_read_unlock(struct crypt_device *cd, struct device *device)
{ {
if (!crypt_metadata_locking_enabled()) if (!crypt_metadata_locking_enabled())
return; return;
assert(device_locked(device->lh) && device_locked_readonly(device->lh)); assert(device_locked(device->lh) && device_locked_readonly(device->lh));
device_unlock_handle(device->lh); device_unlock_handle(cd, device->lh);
log_dbg("Device %s READ lock released.", device_path(device)); log_dbg(cd, "Device %s READ lock released.", device_path(device));
device->lh = NULL; device->lh = NULL;
} }
void device_write_unlock(struct device *device) void device_write_unlock(struct crypt_device *cd, struct device *device)
{ {
if (!crypt_metadata_locking_enabled()) if (!crypt_metadata_locking_enabled())
return; return;
assert(device_locked(device->lh) && !device_locked_readonly(device->lh)); assert(device_locked(device->lh) && !device_locked_readonly(device->lh));
device_unlock_handle(device->lh); device_unlock_handle(cd, device->lh);
log_dbg("Device %s WRITE lock released.", device_path(device)); log_dbg(cd, "Device %s WRITE lock released.", device_path(device));
device->lh = NULL; device->lh = NULL;
} }
 End of changes. 49 change blocks. 
53 lines changed or deleted 96 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)