Skip to content

Commit b26c047

Browse files
committed
rbd: support for images within namespaces
Cloning across namespaces isn't supported yet -- for now both the parent and the clone have to live in the same namespace, whether the default (i.e. "") or a user-created namespace. Signed-off-by: Ilya Dryomov <[email protected]>
1 parent c300156 commit b26c047

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

drivers/block/rbd.c

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ struct rbd_image_header {
181181
struct rbd_spec {
182182
u64 pool_id;
183183
const char *pool_name;
184+
const char *pool_ns; /* NULL if default, never "" */
184185

185186
const char *image_id;
186187
const char *image_name;
@@ -735,6 +736,7 @@ enum {
735736
Opt_lock_timeout,
736737
Opt_last_int,
737738
/* int args above */
739+
Opt_pool_ns,
738740
Opt_last_string,
739741
/* string args above */
740742
Opt_read_only,
@@ -749,6 +751,7 @@ static match_table_t rbd_opts_tokens = {
749751
{Opt_queue_depth, "queue_depth=%d"},
750752
{Opt_lock_timeout, "lock_timeout=%d"},
751753
/* int args above */
754+
{Opt_pool_ns, "_pool_ns=%s"},
752755
/* string args above */
753756
{Opt_read_only, "read_only"},
754757
{Opt_read_only, "ro"}, /* Alternate spelling */
@@ -817,6 +820,12 @@ static int parse_rbd_opts_token(char *c, void *private)
817820
}
818821
pctx->opts->lock_timeout = msecs_to_jiffies(intval * 1000);
819822
break;
823+
case Opt_pool_ns:
824+
kfree(pctx->spec->pool_ns);
825+
pctx->spec->pool_ns = match_strdup(argstr);
826+
if (!pctx->spec->pool_ns)
827+
return -ENOMEM;
828+
break;
820829
case Opt_read_only:
821830
pctx->opts->read_only = true;
822831
break;
@@ -1480,7 +1489,13 @@ rbd_osd_req_create(struct rbd_obj_request *obj_req, unsigned int num_ops)
14801489
req->r_callback = rbd_osd_req_callback;
14811490
req->r_priv = obj_req;
14821491

1492+
/*
1493+
* Data objects may be stored in a separate pool, but always in
1494+
* the same namespace in that pool as the header in its pool.
1495+
*/
1496+
ceph_oloc_copy(&req->r_base_oloc, &rbd_dev->header_oloc);
14831497
req->r_base_oloc.pool = rbd_dev->layout.pool_id;
1498+
14841499
if (ceph_oid_aprintf(&req->r_base_oid, GFP_NOIO, name_format,
14851500
rbd_dev->header.object_prefix, obj_req->ex.oe_objno))
14861501
goto err_req;
@@ -4124,6 +4139,14 @@ static ssize_t rbd_pool_id_show(struct device *dev,
41244139
(unsigned long long) rbd_dev->spec->pool_id);
41254140
}
41264141

4142+
static ssize_t rbd_pool_ns_show(struct device *dev,
4143+
struct device_attribute *attr, char *buf)
4144+
{
4145+
struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
4146+
4147+
return sprintf(buf, "%s\n", rbd_dev->spec->pool_ns ?: "");
4148+
}
4149+
41274150
static ssize_t rbd_name_show(struct device *dev,
41284151
struct device_attribute *attr, char *buf)
41294152
{
@@ -4222,6 +4245,7 @@ static DEVICE_ATTR(cluster_fsid, 0444, rbd_cluster_fsid_show, NULL);
42224245
static DEVICE_ATTR(config_info, 0400, rbd_config_info_show, NULL);
42234246
static DEVICE_ATTR(pool, 0444, rbd_pool_show, NULL);
42244247
static DEVICE_ATTR(pool_id, 0444, rbd_pool_id_show, NULL);
4248+
static DEVICE_ATTR(pool_ns, 0444, rbd_pool_ns_show, NULL);
42254249
static DEVICE_ATTR(name, 0444, rbd_name_show, NULL);
42264250
static DEVICE_ATTR(image_id, 0444, rbd_image_id_show, NULL);
42274251
static DEVICE_ATTR(refresh, 0200, NULL, rbd_image_refresh);
@@ -4240,6 +4264,7 @@ static struct attribute *rbd_attrs[] = {
42404264
&dev_attr_config_info.attr,
42414265
&dev_attr_pool.attr,
42424266
&dev_attr_pool_id.attr,
4267+
&dev_attr_pool_ns.attr,
42434268
&dev_attr_name.attr,
42444269
&dev_attr_image_id.attr,
42454270
&dev_attr_current_snap.attr,
@@ -4300,6 +4325,7 @@ static void rbd_spec_free(struct kref *kref)
43004325
struct rbd_spec *spec = container_of(kref, struct rbd_spec, kref);
43014326

43024327
kfree(spec->pool_name);
4328+
kfree(spec->pool_ns);
43034329
kfree(spec->image_id);
43044330
kfree(spec->image_name);
43054331
kfree(spec->snap_name);
@@ -4358,6 +4384,12 @@ static struct rbd_device *__rbd_dev_create(struct rbd_client *rbdc,
43584384
rbd_dev->header.data_pool_id = CEPH_NOPOOL;
43594385
ceph_oid_init(&rbd_dev->header_oid);
43604386
rbd_dev->header_oloc.pool = spec->pool_id;
4387+
if (spec->pool_ns) {
4388+
WARN_ON(!*spec->pool_ns);
4389+
rbd_dev->header_oloc.pool_ns =
4390+
ceph_find_or_create_string(spec->pool_ns,
4391+
strlen(spec->pool_ns));
4392+
}
43614393

43624394
mutex_init(&rbd_dev->watch_mutex);
43634395
rbd_dev->watch_state = RBD_WATCH_STATE_UNREGISTERED;
@@ -4638,6 +4670,17 @@ static int rbd_dev_v2_parent_info(struct rbd_device *rbd_dev)
46384670
parent_spec->pool_id = pool_id;
46394671
parent_spec->image_id = image_id;
46404672
parent_spec->snap_id = snap_id;
4673+
4674+
/* TODO: support cloning across namespaces */
4675+
if (rbd_dev->spec->pool_ns) {
4676+
parent_spec->pool_ns = kstrdup(rbd_dev->spec->pool_ns,
4677+
GFP_KERNEL);
4678+
if (!parent_spec->pool_ns) {
4679+
ret = -ENOMEM;
4680+
goto out_err;
4681+
}
4682+
}
4683+
46414684
rbd_dev->parent_spec = parent_spec;
46424685
parent_spec = NULL; /* rbd_dev now owns this */
46434686
} else {
@@ -5590,8 +5633,10 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)
55905633
ret = rbd_register_watch(rbd_dev);
55915634
if (ret) {
55925635
if (ret == -ENOENT)
5593-
pr_info("image %s/%s does not exist\n",
5636+
pr_info("image %s/%s%s%s does not exist\n",
55945637
rbd_dev->spec->pool_name,
5638+
rbd_dev->spec->pool_ns ?: "",
5639+
rbd_dev->spec->pool_ns ? "/" : "",
55955640
rbd_dev->spec->image_name);
55965641
goto err_out_format;
55975642
}
@@ -5613,8 +5658,10 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev, int depth)
56135658
ret = rbd_spec_fill_names(rbd_dev);
56145659
if (ret) {
56155660
if (ret == -ENOENT)
5616-
pr_info("snap %s/%s@%s does not exist\n",
5661+
pr_info("snap %s/%s%s%s@%s does not exist\n",
56175662
rbd_dev->spec->pool_name,
5663+
rbd_dev->spec->pool_ns ?: "",
5664+
rbd_dev->spec->pool_ns ? "/" : "",
56185665
rbd_dev->spec->image_name,
56195666
rbd_dev->spec->snap_name);
56205667
goto err_out_probe;

0 commit comments

Comments
 (0)