From: Tobias Waldekranz <tobias@waldekranz.com>
To: barebox@lists.infradead.org
Subject: [PATCH 02/11] dm: linear: Refactor to make use of the generalized cdev management
Date: Thu, 18 Sep 2025 09:43:12 +0200 [thread overview]
Message-ID: <20250918074455.891780-3-tobias@waldekranz.com> (raw)
In-Reply-To: <20250918074455.891780-1-tobias@waldekranz.com>
Rely on the dm_cdev operations to do most of the heavy lifting of
managing the lower device. In addition this also adds support for
creating a linear target from a regular file (via a loop device).
Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
---
drivers/block/dm/dm-linear.c | 64 +++++++++++-------------------------
1 file changed, 19 insertions(+), 45 deletions(-)
diff --git a/drivers/block/dm/dm-linear.c b/drivers/block/dm/dm-linear.c
index 797d761f63..38e340af3a 100644
--- a/drivers/block/dm/dm-linear.c
+++ b/drivers/block/dm/dm-linear.c
@@ -11,45 +11,30 @@
#include "dm-target.h"
struct dm_linear {
- struct cdev *cdev;
- loff_t offset;
+ struct dm_cdev dmcdev;
};
static int dm_linear_read(struct dm_target *ti, void *buf,
sector_t block, blkcnt_t num_blocks)
{
struct dm_linear *l = ti->private;
- ssize_t ret;
-
- block <<= SECTOR_SHIFT;
- num_blocks <<= SECTOR_SHIFT;
- ret = cdev_read(l->cdev, buf, num_blocks, l->offset + block, 0);
- if (ret < num_blocks)
- return (ret < 0) ? ret : -EIO;
-
- return 0;
+ return dm_cdev_read(&l->dmcdev, buf, block, num_blocks);
}
static int dm_linear_write(struct dm_target *ti, const void *buf,
sector_t block, blkcnt_t num_blocks)
{
struct dm_linear *l = ti->private;
- ssize_t ret;
- block <<= SECTOR_SHIFT;
- num_blocks <<= SECTOR_SHIFT;
-
- ret = cdev_write(l->cdev, buf, num_blocks, l->offset + block, 0);
- if (ret < num_blocks)
- return (ret < 0) ? ret : -EIO;
-
- return 0;
+ return dm_cdev_write(&l->dmcdev, buf, block, num_blocks);
}
static int dm_linear_create(struct dm_target *ti, unsigned int argc, char **argv)
{
- struct dm_linear *l;
+ struct dm_linear *l = NULL;
+ loff_t offset;
+ char *errmsg;
int err;
if (argc != 2) {
@@ -62,37 +47,26 @@ static int dm_linear_create(struct dm_target *ti, unsigned int argc, char **argv
l = xzalloc(sizeof(*l));
ti->private = l;
- if (kstrtoull(argv[1], 0, &l->offset)) {
+ if (kstrtoull(argv[1], 0, &offset)) {
dm_target_err(ti, "Invalid offset: \"%s\"\n", argv[1]);
err = -EINVAL;
- goto err_free;
- }
- l->offset <<= SECTOR_SHIFT;
-
- l->cdev = cdev_open_by_path_name(argv[0], O_RDWR);
- if (!l->cdev) {
- dm_target_err(ti, "Cannot open device %s: %m\n", argv[0]);
- err = -ENODEV;
- goto err_free;
+ goto err;
}
- l->cdev = cdev_readlink(l->cdev);
-
- if ((ti->size << SECTOR_SHIFT) > (l->cdev->size - l->offset)) {
- dm_target_err(ti, "%s is too small to map %llu blocks at %llu, %llu available\n",
- argv[0], ti->size, l->offset >> SECTOR_SHIFT,
- (l->cdev->size - l->offset) >> SECTOR_SHIFT);
- err = -ENOSPC;
- goto err_close;
+ err = dm_cdev_open(&l->dmcdev, argv[0], O_RDWR, offset,
+ ti->size, SECTOR_SIZE, &errmsg);
+ if (err) {
+ dm_target_err(ti, "Cannot open device %s: %s\n", argv[0], errmsg);
+ free(errmsg);
+ goto err;
}
return 0;
-err_close:
- cdev_close(l->cdev);
-err_free:
- free(l);
err:
+ if (l)
+ free(l);
+
return err;
}
@@ -100,7 +74,7 @@ static int dm_linear_destroy(struct dm_target *ti)
{
struct dm_linear *l = ti->private;
- cdev_close(l->cdev);
+ dm_cdev_close(&l->dmcdev);
free(l);
return 0;
}
@@ -110,7 +84,7 @@ static char *dm_linear_asprint(struct dm_target *ti)
struct dm_linear *l = ti->private;
return xasprintf("dev:%s offset:%llu",
- cdev_name(l->cdev), l->offset >> SECTOR_SHIFT);
+ cdev_name(l->dmcdev.cdev), l->dmcdev.blk.start);
}
static struct dm_target_ops dm_linear_ops = {
--
2.43.0
next prev parent reply other threads:[~2025-09-18 7:45 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-18 7:43 [PATCH 00/11] dm: verity: Add transparent integrity checking target Tobias Waldekranz
2025-09-18 7:43 ` [PATCH 01/11] dm: Add helper to manage a lower device Tobias Waldekranz
2025-09-18 7:43 ` Tobias Waldekranz [this message]
2025-09-18 7:43 ` [PATCH 03/11] dm: verity: Add transparent integrity checking target Tobias Waldekranz
2025-09-18 13:06 ` Sascha Hauer
2025-09-18 7:43 ` [PATCH 04/11] dm: verity: Add helper to parse superblock information Tobias Waldekranz
2025-09-18 7:43 ` [PATCH 05/11] commands: veritysetup: Create dm-verity devices Tobias Waldekranz
2025-09-18 7:43 ` [PATCH 06/11] ci: pytest: Open up testfs to more consumers than the FIT test Tobias Waldekranz
2025-09-22 15:38 ` Ahmad Fatoum
2025-09-18 7:43 ` [PATCH 07/11] ci: pytest: Enable testfs feature on malta boards Tobias Waldekranz
2025-09-22 15:40 ` Ahmad Fatoum
2025-09-18 7:43 ` [PATCH 08/11] ci: pytest: Generate test data for dm-verity Tobias Waldekranz
2025-09-22 15:41 ` Ahmad Fatoum
2025-09-18 7:43 ` [PATCH 09/11] test: pytest: add basic dm-verity test Tobias Waldekranz
2025-09-22 15:44 ` Ahmad Fatoum
2025-09-18 7:43 ` [PATCH 10/11] ci: pytest: Centralize feature discovery to a separate step Tobias Waldekranz
2025-09-22 15:45 ` Ahmad Fatoum
2025-09-18 7:43 ` [PATCH 11/11] ci: pytest: Enable device-mapper labgrid tests Tobias Waldekranz
2025-09-22 15:46 ` Ahmad Fatoum
2025-09-18 14:08 ` [PATCH 00/11] dm: verity: Add transparent integrity checking target Sascha Hauer
2025-09-18 15:38 ` Tobias Waldekranz
2025-09-23 6:30 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250918074455.891780-3-tobias@waldekranz.com \
--to=tobias@waldekranz.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox