* [PATCH] Do not open log and cow device read-write for read-only mappings
@ 2011-02-15 13:52 Milan Broz
2011-02-15 13:52 ` [PATCH] Propagate device open error to table constructor Milan Broz
0 siblings, 1 reply; 3+ messages in thread
From: Milan Broz @ 2011-02-15 13:52 UTC (permalink / raw)
To: dm-devel; +Cc: Milan Broz
Always use mode specified in table (as otherwise in code).
Signed-off-by: Milan Broz <mbroz@redhat.com>
---
drivers/md/dm-log.c | 2 +-
drivers/md/dm-snap.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-log.c b/drivers/md/dm-log.c
index 6951536..8e8a868 100644
--- a/drivers/md/dm-log.c
+++ b/drivers/md/dm-log.c
@@ -543,7 +543,7 @@ static int disk_ctr(struct dm_dirty_log *log, struct dm_target *ti,
return -EINVAL;
}
- r = dm_get_device(ti, argv[0], FMODE_READ | FMODE_WRITE, &dev);
+ r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &dev);
if (r)
return r;
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index fdde53c..a2d3309 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -1080,7 +1080,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
argv++;
argc--;
- r = dm_get_device(ti, cow_path, FMODE_READ | FMODE_WRITE, &s->cow);
+ r = dm_get_device(ti, cow_path, dm_table_get_mode(ti->table), &s->cow);
if (r) {
ti->error = "Cannot get COW device";
goto bad_cow;
--
1.7.2.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] Propagate device open error to table constructor.
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
2011-02-16 17:32 ` [PATCH] Use only specific errors when failing dm-ioctl Milan Broz
0 siblings, 1 reply; 3+ messages in thread
From: Milan Broz @ 2011-02-15 13:52 UTC (permalink / raw)
To: dm-devel; +Cc: Milan Broz
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] Use only specific errors when failing dm-ioctl
2011-02-15 13:52 ` [PATCH] Propagate device open error to table constructor Milan Broz
@ 2011-02-16 17:32 ` Milan Broz
0 siblings, 0 replies; 3+ messages in thread
From: Milan Broz @ 2011-02-16 17:32 UTC (permalink / raw)
To: dm-devel; +Cc: Milan Broz
The return codes of ioctl are part of device-mapper
API and only defined errno should be returned.
Unify return codes for device lookup function on one place
and allow ENOMEM and ENXIO for now.
(Later it can be added more codes as userspace is prepared
to handle them.)
Signed-off-by: Milan Broz <mbroz@redhat.com>
---
drivers/md/dm-table.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 38e4eb1..ca19e4d 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -532,7 +532,17 @@ EXPORT_SYMBOL_GPL(dm_set_device_limits);
int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,
struct dm_dev **result)
{
- return __table_get_device(ti->table, ti, path, mode, result);
+ int r = __table_get_device(ti->table, ti, path, mode, result);
+
+ /*
+ * Return code is directly used for dm ioctl.
+ * Allow only ENOMEM here, all other codes
+ * means device lookup failed.
+ */
+ if (r && r != -ENOMEM)
+ r = -ENXIO;
+
+ return r;
}
--
1.7.2.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-02-16 17:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH] Propagate device open error to table constructor Milan Broz
2011-02-16 17:32 ` [PATCH] Use only specific errors when failing dm-ioctl Milan Broz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox