From: Milan Broz <mbroz@redhat.com>
To: dm-devel@redhat.com
Cc: Milan Broz <mbroz@redhat.com>
Subject: [PATCH] Propagate device open error to table constructor.
Date: Tue, 15 Feb 2011 14:52:40 +0100 [thread overview]
Message-ID: <1297777960-22662-2-git-send-email-mbroz@redhat.com> (raw)
In-Reply-To: <1297777960-22662-1-git-send-email-mbroz@redhat.com>
Ensure that all errors in dm_get_device() propagates into
table constructor (thus into userspace).
This is required to properly handle EACCES/EROFS codes
when opening read-only device with recent kernel changes.
Userspace can later retry with read-only flag set.
Signed-off-by: Milan Broz <mbroz@redhat.com>
---
drivers/md/dm-crypt.c | 7 +++++--
drivers/md/dm-delay.c | 15 ++++++++++-----
drivers/md/dm-linear.c | 14 +++++++-------
drivers/md/dm-raid1.c | 8 +++++---
drivers/md/dm-stripe.c | 11 ++++++-----
5 files changed, 33 insertions(+), 22 deletions(-)
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 4e054bd..397e73a 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -1628,20 +1628,23 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
goto bad;
}
- ret = -EINVAL;
if (sscanf(argv[2], "%llu", &tmpll) != 1) {
ti->error = "Invalid iv_offset sector";
+ ret = -EINVAL;
goto bad;
}
cc->iv_offset = tmpll;
- if (dm_get_device(ti, argv[3], dm_table_get_mode(ti->table), &cc->dev)) {
+ ret = dm_get_device(ti, argv[3], dm_table_get_mode(ti->table),
+ &cc->dev);
+ if (ret) {
ti->error = "Device lookup failed";
goto bad;
}
if (sscanf(argv[4], "%llu", &tmpll) != 1) {
ti->error = "Invalid device sector";
+ ret = -EINVAL;
goto bad;
}
cc->start = tmpll;
diff --git a/drivers/md/dm-delay.c b/drivers/md/dm-delay.c
index f18375d..b07428f 100644
--- a/drivers/md/dm-delay.c
+++ b/drivers/md/dm-delay.c
@@ -131,6 +131,7 @@ static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv)
{
struct delay_c *dc;
unsigned long long tmpll;
+ int r = -EINVAL;
if (argc != 3 && argc != 6) {
ti->error = "requires exactly 3 or 6 arguments";
@@ -156,12 +157,14 @@ static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv)
goto bad;
}
- if (dm_get_device(ti, argv[0], dm_table_get_mode(ti->table),
- &dc->dev_read)) {
+ r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table),
+ &dc->dev_read);
+ if (r) {
ti->error = "Device lookup failed";
goto bad;
}
+ r = -EINVAL;
dc->dev_write = NULL;
if (argc == 3)
goto out;
@@ -177,8 +180,9 @@ static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv)
goto bad_dev_read;
}
- if (dm_get_device(ti, argv[3], dm_table_get_mode(ti->table),
- &dc->dev_write)) {
+ r = dm_get_device(ti, argv[3], dm_table_get_mode(ti->table),
+ &dc->dev_write);
+ if (r) {
ti->error = "Write device lookup failed";
goto bad_dev_read;
}
@@ -187,6 +191,7 @@ out:
dc->delayed_pool = mempool_create_slab_pool(128, delayed_cache);
if (!dc->delayed_pool) {
DMERR("Couldn't create delayed bio pool.");
+ r = -ENOMEM;
goto bad_dev_write;
}
@@ -209,7 +214,7 @@ bad_dev_read:
dm_put_device(ti, dc->dev_read);
bad:
kfree(dc);
- return -EINVAL;
+ return r;
}
static void delay_dtr(struct dm_target *ti)
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index 3921e3b..f3254e5 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -29,6 +29,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
{
struct linear_c *lc;
unsigned long long tmp;
+ int r;
if (argc != 2) {
ti->error = "Invalid argument count";
@@ -43,23 +44,22 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
if (sscanf(argv[1], "%llu", &tmp) != 1) {
ti->error = "dm-linear: Invalid device sector";
- goto bad;
+ kfree(lc);
+ return -EINVAL;
}
lc->start = tmp;
- if (dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &lc->dev)) {
+ r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &lc->dev);
+ if (r) {
ti->error = "dm-linear: Device lookup failed";
- goto bad;
+ kfree(lc);
+ return r;
}
ti->num_flush_requests = 1;
ti->num_discard_requests = 1;
ti->private = lc;
return 0;
-
- bad:
- kfree(lc);
- return -EINVAL;
}
static void linear_dtr(struct dm_target *ti)
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index dee3267..be38862 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -928,16 +928,18 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
unsigned int mirror, char **argv)
{
unsigned long long offset;
+ int r;
if (sscanf(argv[1], "%llu", &offset) != 1) {
ti->error = "Invalid offset";
return -EINVAL;
}
- if (dm_get_device(ti, argv[0], dm_table_get_mode(ti->table),
- &ms->mirror[mirror].dev)) {
+ r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table),
+ &ms->mirror[mirror].dev);
+ if (r) {
ti->error = "Device lookup failure";
- return -ENXIO;
+ return r;
}
ms->mirror[mirror].ms = ms;
diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
index dddfa14..50f88b9 100644
--- a/drivers/md/dm-stripe.c
+++ b/drivers/md/dm-stripe.c
@@ -74,18 +74,19 @@ static inline struct stripe_c *alloc_context(unsigned int stripes)
static int get_stripe(struct dm_target *ti, struct stripe_c *sc,
unsigned int stripe, char **argv)
{
+ int r;
unsigned long long start;
if (sscanf(argv[1], "%llu", &start) != 1)
return -EINVAL;
- if (dm_get_device(ti, argv[0], dm_table_get_mode(ti->table),
- &sc->stripe[stripe].dev))
- return -ENXIO;
+ r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table),
+ &sc->stripe[stripe].dev);
- sc->stripe[stripe].physical_start = start;
+ if (!r)
+ sc->stripe[stripe].physical_start = start;
- return 0;
+ return r;
}
/*
--
1.7.2.3
next prev parent reply other threads:[~2011-02-15 13:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-15 13:52 [PATCH] Do not open log and cow device read-write for read-only mappings Milan Broz
2011-02-15 13:52 ` Milan Broz [this message]
2011-02-16 17:32 ` [PATCH] Use only specific errors when failing dm-ioctl Milan Broz
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=1297777960-22662-2-git-send-email-mbroz@redhat.com \
--to=mbroz@redhat.com \
--cc=dm-devel@redhat.com \
/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