summaryrefslogtreecommitdiffstats
path: root/lib/utils_device.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils_device.c')
-rw-r--r--lib/utils_device.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/utils_device.c b/lib/utils_device.c
index d80ea62..8bc329d 100644
--- a/lib/utils_device.c
+++ b/lib/utils_device.c
@@ -3,8 +3,8 @@
*
* Copyright (C) 2004 Jana Saout <jana@saout.de>
* Copyright (C) 2004-2007 Clemens Fruhwirth <clemens@endorphin.org>
- * Copyright (C) 2009-2023 Red Hat, Inc. All rights reserved.
- * Copyright (C) 2009-2023 Milan Broz
+ * Copyright (C) 2009-2024 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2009-2024 Milan Broz
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -178,6 +178,7 @@ static int device_ready(struct crypt_device *cd, struct device *device)
int devfd = -1, r = 0;
struct stat st;
size_t tmp_size;
+ const char *dm_name;
if (!device)
return -EINVAL;
@@ -188,7 +189,12 @@ static int device_ready(struct crypt_device *cd, struct device *device)
device->o_direct = 0;
devfd = open(device_path(device), O_RDONLY | O_DIRECT);
if (devfd >= 0) {
- if (device_read_test(devfd) == 0) {
+ /* skip check for suspended DM devices */
+ dm_name = device_dm_name(device);
+ if (dm_name && dm_status_suspended(cd, dm_name)) {
+ close(devfd);
+ devfd = -1;
+ } else if (device_read_test(devfd) == 0) {
device->o_direct = 1;
} else {
close(devfd);
@@ -470,7 +476,7 @@ void device_free(struct crypt_device *cd, struct device *device)
/* Get block device path */
const char *device_block_path(const struct device *device)
{
- if (!device || !device->init_done)
+ if (!device)
return NULL;
return device->path;
@@ -482,7 +488,7 @@ const char *device_dm_name(const struct device *device)
const char *dmdir = dm_get_dir();
size_t dmdir_len = strlen(dmdir);
- if (!device || !device->init_done)
+ if (!device)
return NULL;
if (strncmp(device->path, dmdir, dmdir_len))
@@ -985,6 +991,22 @@ int device_is_rotational(struct device *device)
return crypt_dev_is_rotational(major(st.st_rdev), minor(st.st_rdev));
}
+int device_is_dax(struct device *device)
+{
+ struct stat st;
+
+ if (!device)
+ return -EINVAL;
+
+ if (stat(device_path(device), &st) < 0)
+ return -EINVAL;
+
+ if (!S_ISBLK(st.st_mode))
+ return 0;
+
+ return crypt_dev_is_dax(major(st.st_rdev), minor(st.st_rdev));
+}
+
size_t device_alignment(struct device *device)
{
int devfd;