mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Allow to open device without read check.
In some specific situation we do not want to read the devices before initialization. Here it is integrity checking that will produce warning, because the device is not yet initialized. Used only in wipe function (here we must use direct-io anyway) and expect the device is capable of direct-io.
This commit is contained in:
@@ -65,6 +65,7 @@ void crypt_free_volume_key(struct volume_key *vk);
|
||||
/* Device backend */
|
||||
struct device;
|
||||
int device_alloc(struct device **device, const char *path);
|
||||
int device_alloc_no_check(struct device **device, const char *path);
|
||||
void device_free(struct device *device);
|
||||
const char *device_path(const struct device *device);
|
||||
const char *device_block_path(const struct device *device);
|
||||
|
||||
@@ -143,16 +143,16 @@ static int device_read_test(int devfd)
|
||||
* 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.
|
||||
*/
|
||||
static int device_ready(struct device *device, int check_directio)
|
||||
static int device_ready(struct device *device)
|
||||
{
|
||||
int devfd = -1, r = 0;
|
||||
struct stat st;
|
||||
size_t tmp_size;
|
||||
|
||||
device->o_direct = 0;
|
||||
if (check_directio) {
|
||||
if (device->o_direct) {
|
||||
log_dbg("Trying to open and read device %s with direct-io.",
|
||||
device_path(device));
|
||||
device->o_direct = 0;
|
||||
devfd = open(device_path(device), O_RDONLY | O_DIRECT);
|
||||
if (devfd >= 0) {
|
||||
if (device_read_test(devfd) == 0) {
|
||||
@@ -210,10 +210,10 @@ int device_open(struct device *device, int flags)
|
||||
return devfd;
|
||||
}
|
||||
|
||||
int device_alloc(struct device **device, const char *path)
|
||||
/* Avoid any read from device, expects direct-io to work. */
|
||||
int device_alloc_no_check(struct device **device, const char *path)
|
||||
{
|
||||
struct device *dev;
|
||||
int r;
|
||||
|
||||
if (!path) {
|
||||
*device = NULL;
|
||||
@@ -231,8 +231,22 @@ int device_alloc(struct device **device, const char *path)
|
||||
return -ENOMEM;
|
||||
}
|
||||
dev->loop_fd = -1;
|
||||
dev->o_direct = 1;
|
||||
|
||||
r = device_ready(dev, 1);
|
||||
*device = dev;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int device_alloc(struct device **device, const char *path)
|
||||
{
|
||||
struct device *dev;
|
||||
int r;
|
||||
|
||||
r = device_alloc_no_check(&dev, path);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = device_ready(dev);
|
||||
if (!r) {
|
||||
dev->init_done = 1;
|
||||
} else if (r == -ENOTBLK) {
|
||||
@@ -529,7 +543,7 @@ static int device_internal_prepare(struct crypt_device *cd, struct device *devic
|
||||
file_path = device->path;
|
||||
device->path = loop_device;
|
||||
|
||||
r = device_ready(device, device->o_direct);
|
||||
r = device_ready(device);
|
||||
if (r < 0) {
|
||||
device->path = file_path;
|
||||
crypt_loop_detach(loop_device);
|
||||
|
||||
@@ -239,7 +239,7 @@ int crypt_wipe(struct crypt_device *cd,
|
||||
if (!dev_path)
|
||||
device = crypt_data_device(cd);
|
||||
else {
|
||||
r = device_alloc(&device, dev_path);
|
||||
r = device_alloc_no_check(&device, dev_path);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user