Skip to content

Commit b9ef2b8

Browse files
committed
rbd: don't establish watch for read-only mappings
With exclusive lock out of the way, watch is the only thing left that prevents a read-only mapping from being used with read-only OSD caps. Signed-off-by: Ilya Dryomov <[email protected]> Reviewed-by: Jason Dillaman <[email protected]> Reviewed-by: Dongsheng Yang <[email protected]>
1 parent 3fe6992 commit b9ef2b8

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

drivers/block/rbd.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6961,6 +6961,24 @@ static int rbd_dev_header_name(struct rbd_device *rbd_dev)
69616961
return ret;
69626962
}
69636963

6964+
static void rbd_print_dne(struct rbd_device *rbd_dev, bool is_snap)
6965+
{
6966+
if (!is_snap) {
6967+
pr_info("image %s/%s%s%s does not exist\n",
6968+
rbd_dev->spec->pool_name,
6969+
rbd_dev->spec->pool_ns ?: "",
6970+
rbd_dev->spec->pool_ns ? "/" : "",
6971+
rbd_dev->spec->image_name);
6972+
} else {
6973+
pr_info("snap %s/%s%s%s@%s does not exist\n",
6974+
rbd_dev->spec->pool_name,
6975+
rbd_dev->spec->pool_ns ?: "",
6976+
rbd_dev->spec->pool_ns ? "/" : "",
6977+
rbd_dev->spec->image_name,
6978+
rbd_dev->spec->snap_name);
6979+
}
6980+
}
6981+
69646982
static void rbd_dev_image_release(struct rbd_device *rbd_dev)
69656983
{
69666984
rbd_dev_unprobe(rbd_dev);
@@ -6979,6 +6997,7 @@ static void rbd_dev_image_release(struct rbd_device *rbd_dev)
69796997
*/
69806998
static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)
69816999
{
7000+
bool need_watch = !rbd_is_ro(rbd_dev);
69827001
int ret;
69837002

69847003
/*
@@ -6995,22 +7014,21 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)
69957014
if (ret)
69967015
goto err_out_format;
69977016

6998-
if (!depth) {
7017+
if (need_watch) {
69997018
ret = rbd_register_watch(rbd_dev);
70007019
if (ret) {
70017020
if (ret == -ENOENT)
7002-
pr_info("image %s/%s%s%s does not exist\n",
7003-
rbd_dev->spec->pool_name,
7004-
rbd_dev->spec->pool_ns ?: "",
7005-
rbd_dev->spec->pool_ns ? "/" : "",
7006-
rbd_dev->spec->image_name);
7021+
rbd_print_dne(rbd_dev, false);
70077022
goto err_out_format;
70087023
}
70097024
}
70107025

70117026
ret = rbd_dev_header_info(rbd_dev);
7012-
if (ret)
7027+
if (ret) {
7028+
if (ret == -ENOENT && !need_watch)
7029+
rbd_print_dne(rbd_dev, false);
70137030
goto err_out_watch;
7031+
}
70147032

70157033
/*
70167034
* If this image is the one being mapped, we have pool name and
@@ -7024,12 +7042,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)
70247042
ret = rbd_spec_fill_names(rbd_dev);
70257043
if (ret) {
70267044
if (ret == -ENOENT)
7027-
pr_info("snap %s/%s%s%s@%s does not exist\n",
7028-
rbd_dev->spec->pool_name,
7029-
rbd_dev->spec->pool_ns ?: "",
7030-
rbd_dev->spec->pool_ns ? "/" : "",
7031-
rbd_dev->spec->image_name,
7032-
rbd_dev->spec->snap_name);
7045+
rbd_print_dne(rbd_dev, true);
70337046
goto err_out_probe;
70347047
}
70357048

@@ -7061,7 +7074,7 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)
70617074
err_out_probe:
70627075
rbd_dev_unprobe(rbd_dev);
70637076
err_out_watch:
7064-
if (!depth)
7077+
if (need_watch)
70657078
rbd_unregister_watch(rbd_dev);
70667079
err_out_format:
70677080
rbd_dev->image_format = 0;

0 commit comments

Comments
 (0)