From 73789cf9d9e465f87a67a12b0bb67c401f52c512 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 26 Jun 2017 09:48:00 -0400 Subject: [PATCH] rbd: add new 'pool init' action for initializing a RBD pool Signed-off-by: Jason Dillaman --- doc/rbd/libvirt.rst | 6 +++- doc/rbd/rados-rbd-cmds.rst | 13 +++++++- doc/rbd/rbd-cloudstack.rst | 5 +++ doc/rbd/rbd-openstack.rst | 8 +++++ doc/start/quick-rbd.rst | 12 ++++++-- src/test/cli/rbd/help.t | 15 +++++++++ src/tools/rbd/CMakeLists.txt | 1 + src/tools/rbd/action/Pool.cc | 60 ++++++++++++++++++++++++++++++++++++ 8 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 src/tools/rbd/action/Pool.cc diff --git a/doc/rbd/libvirt.rst b/doc/rbd/libvirt.rst index b0a3dbda3c7..a79eaa888d1 100644 --- a/doc/rbd/libvirt.rst +++ b/doc/rbd/libvirt.rst @@ -58,7 +58,7 @@ Configuring Ceph To configure Ceph for use with ``libvirt``, perform the following steps: -#. `Create a pool`_ (or use the default). The following example uses the +#. `Create a pool`_. The following example uses the pool name ``libvirt-pool`` with 128 placement groups. :: ceph osd pool create libvirt-pool 128 128 @@ -67,6 +67,10 @@ To configure Ceph for use with ``libvirt``, perform the following steps: ceph osd lspools +#. Use the ``rbd`` tool to initialize the pool for use by RBD:: + + rbd pool init + #. `Create a Ceph User`_ (or use ``client.admin`` for version 0.9.7 and earlier). The following example uses the Ceph user name ``client.libvirt`` and references ``libvirt-pool``. :: diff --git a/doc/rbd/rados-rbd-cmds.rst b/doc/rbd/rados-rbd-cmds.rst index a8e2302d23e..cc113c1d069 100644 --- a/doc/rbd/rados-rbd-cmds.rst +++ b/doc/rbd/rados-rbd-cmds.rst @@ -13,6 +13,17 @@ details. .. important:: To use Ceph Block Device commands, you must have access to a running Ceph cluster. +Create a Block Device Pool +========================== + +#. On the admin node, use the ``ceph`` tool to `create a pool`_. + +#. On the admin node, use the ``rbd`` tool to initialize the pool for use by RBD:: + + rbd pool init + +.. note:: The ``rbd`` tool assumes a default pool name of 'rbd' when not + provided. Creating a Block Device Image ============================= @@ -112,6 +123,6 @@ For example:: rbd rm swimmingpool/bar - +.. _create a pool: ../../rados/operations/pools/#create-a-pool .. _Storage Pools: ../../rados/operations/pools .. _RBD – Manage RADOS Block Device (RBD) Images: ../../man/8/rbd/ diff --git a/doc/rbd/rbd-cloudstack.rst b/doc/rbd/rbd-cloudstack.rst index c50f6f0f042..e888f787a3f 100644 --- a/doc/rbd/rbd-cloudstack.rst +++ b/doc/rbd/rbd-cloudstack.rst @@ -68,6 +68,11 @@ See `Create a Pool`_ for details on specifying the number of placement groups for your pools, and `Placement Groups`_ for details on the number of placement groups you should set for your pools. +A newly created pool must initialized prior to use. Use the ``rbd`` tool +to initialize the pool:: + + rbd pool init cloudstack + Create a Ceph User ================== diff --git a/doc/rbd/rbd-openstack.rst b/doc/rbd/rbd-openstack.rst index 8df63cb449a..907276fe15b 100644 --- a/doc/rbd/rbd-openstack.rst +++ b/doc/rbd/rbd-openstack.rst @@ -90,6 +90,14 @@ See `Create a Pool`_ for detail on specifying the number of placement groups for your pools, and `Placement Groups`_ for details on the number of placement groups you should set for your pools. +Newly created pools must initialized prior to use. Use the ``rbd`` tool +to initialize the pools:: + + rbd pool init volumes + rbd pool init images + rbd pool init backups + rbd pool init vms + .. _Create a Pool: ../../rados/operations/pools#createpool .. _Placement Groups: ../../rados/operations/placement-groups diff --git a/doc/start/quick-rbd.rst b/doc/start/quick-rbd.rst index 11d85262f4d..787807c36fc 100644 --- a/doc/start/quick-rbd.rst +++ b/doc/start/quick-rbd.rst @@ -47,11 +47,16 @@ Install Ceph directory. Ensure that the keyring file has appropriate read permissions (e.g., ``sudo chmod +r /etc/ceph/ceph.client.admin.keyring``). -Create an rbd pool -================== -#. On the admin node, use the ``ceph`` tool to `Create a Pool`_ +Create a Block Device Pool +========================== + +#. On the admin node, use the ``ceph`` tool to `create a pool`_ (we recommend the name 'rbd'). +#. On the admin node, use the ``rbd`` tool to initialize the pool for use by RBD:: + + rbd pool init + Configure a Block Device ======================== @@ -84,6 +89,7 @@ See `block devices`_ for additional details. .. _Create a Pool: ../../rados/operations/pools#createpool .. _Storage Cluster Quick Start: ../quick-ceph-deploy +.. _create a pool: ../../rados/operations/pools/#create-a-pool .. _block devices: ../../rbd/rbd .. _FAQ: http://wiki.ceph.com/How_Can_I_Give_Ceph_a_Try .. _OS Recommendations: ../os-recommendations diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 104dfc4f1ae..e1d99d82695 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -71,6 +71,7 @@ nbd unmap Unmap a nbd device. object-map check Verify the object map is correct. object-map rebuild Rebuild an invalid object map. + pool init Initialize pool for use by RBD. remove (rm) Delete an image. rename (mv) Rename image within pool. resize Resize (expand or shrink) image. @@ -1192,6 +1193,20 @@ --snap arg snapshot name --no-progress disable progress output + rbd help pool init + usage: rbd pool init [--pool ] [--force] + + + Initialize pool for use by RBD. + + Positional arguments + pool name + + Optional arguments + -p [ --pool ] arg pool name + --force force initialize pool for RBD use if registered by + another application + rbd help remove usage: rbd remove [--pool ] [--image ] [--no-progress] diff --git a/src/tools/rbd/CMakeLists.txt b/src/tools/rbd/CMakeLists.txt index 8774b490281..ad4005ebf0a 100644 --- a/src/tools/rbd/CMakeLists.txt +++ b/src/tools/rbd/CMakeLists.txt @@ -28,6 +28,7 @@ set(rbd_srcs action/MirrorImage.cc action/Nbd.cc action/ObjectMap.cc + action/Pool.cc action/Remove.cc action/Rename.cc action/Resize.cc diff --git a/src/tools/rbd/action/Pool.cc b/src/tools/rbd/action/Pool.cc new file mode 100644 index 00000000000..758393057a0 --- /dev/null +++ b/src/tools/rbd/action/Pool.cc @@ -0,0 +1,60 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "tools/rbd/ArgumentTypes.h" +#include "tools/rbd/Shell.h" +#include "tools/rbd/Utils.h" +#include "include/stringify.h" +#include "common/errno.h" +#include "osd/osd_types.h" +#include +#include + +namespace rbd { +namespace action { +namespace pool { + +namespace at = argument_types; +namespace po = boost::program_options; + +void get_arguments_init(po::options_description *positional, + po::options_description *options) { + at::add_pool_options(positional, options); + options->add_options() + ("force", po::bool_switch(), + "force initialize pool for RBD use if registered by another application"); +} + +int execute_init(const po::variables_map &vm) { + size_t arg_index = 0; + std::string pool_name = utils::get_pool_name(vm, &arg_index); + + librados::Rados rados; + librados::IoCtx io_ctx; + int r = utils::init(pool_name, &rados, &io_ctx); + if (r < 0) { + return r; + } + + r = io_ctx.application_enable(pg_pool_t::APPLICATION_NAME_RBD, + vm["force"].as()); + if (r == -EOPNOTSUPP) { + std::cerr << "rbd: luminous or later release required." << std::endl; + } else if (r == -EPERM) { + std::cerr << "rbd: pool already registered to a different application." + << std::endl; + } else if (r < 0) { + std::cerr << "rbd: error registered application: " << cpp_strerror(r) + << std::endl; + } + + return 0; +} + +Shell::Action action( + {"pool", "init"}, {}, "Initialize pool for use by RBD.", "", + &get_arguments_init, &execute_init); + +} // namespace pool +} // namespace action +} // namespace rbd -- 2.39.5