ceph - rbd namespaces

Posted on Mon 14 October 2019 in Ceph • 1 min read

Fun with rbd namespaces

cli

# rbd --namespace $namespace $command $pool/$image
# rbd $command $pool/$namespace/$image

create

# rbd namespace ls --format=json
[]
# rbd namespace create --namespace newns1
# rbd namespace ls --format=json
[{"name":"newns1"}]
# rbd create --namespace newns1 newrbd1 --size 1G
# rbd ls --long
# rbd --namespace newns1 ls --long
NAME    SIZE  PARENT FMT PROT LOCK
newrbd1 1 GiB          2

rbd map on centos 7 (1810)

# rbd map --namespace newns1 newrbd1
rbd: sysfs write failed
In some cases useful info is found in syslog - try "dmesg | tail".
rbd: map failed: (22) Invalid argument
# dmesg | tail
[...]
[604832.607051] libceph: bad option at '_pool_ns=newns1'

To map a rbd (+ namespace) you need a kernel >= 4.19.

with > 5.0 kernel (elrepo)

# rbd info rbd/newns1/newrbd1
rbd image 'newrbd1':
    size 1 GiB in 256 objects
    order 22 (4 MiB objects)
    snapshot_count: 0
    id: 198af95bfe170
    block_name_prefix: rbd_data.198af95bfe170
    format: 2
    features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
    op_features:
    flags:
    create_timestamp: Mon Oct 14 20:46:48 2019
    access_timestamp: Mon Oct 14 20:46:48 2019
    modify_timestamp: Mon Oct 14 20:46:48 2019
# rbd map rbd/newns1/newrbd1
/dev/rbd0
# rbd showmapped
id pool namespace image   snap device
0  rbd  newns1    newrbd1 -    /dev/rbd0
# uname -a
Linux ceph-test1 5.3.6-1.el7.elrepo.x86_64 #1 SMP Fri Oct 11 17:24:39 EDT 2019 x86_64 x86_64 x86_64 GNU/Linux

cephx

# ceph auth get-or-create client.$name \
  mon 'profile rbd' \
  osd 'profile rbd namespace=$namespace'

and go:

# ls /etc/ceph/ceph.client.$name.keyring
/etc/ceph/ceph.client.$name.keyring
# rbd -n client.$name ls
2019-10-14 21:49:41.227 7efceff6ab00 -1 librbd::api::Image: list_images: error listing v1 images: (1) Operation not permitted
rbd: listing images failed: (1) Operation not permitted
# rbd -n client.$name ls --namespace=newns1
newrbd1