From: Sage Weil Date: Thu, 31 Oct 2013 00:21:05 +0000 (-0700) Subject: librbd: localize or distribute parent (snap) reads X-Git-Tag: v0.75~37^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=909f8a42b695d9af0478e7a849f03ab4a135f4b7;p=ceph.git librbd: localize or distribute parent (snap) reads The parent is always a snapshot. We may want to treat it differently than other snaps by virtue of it (likely) being a more highly-shared image. By default, localize parent reads. Signed-off-by: Sage Weil --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 137e676b778..5f6ecdd78d4 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -643,6 +643,8 @@ OPTION(rbd_cache_block_writes_upfront, OPT_BOOL, false) // whether to block writ OPTION(rbd_concurrent_management_ops, OPT_INT, 10) // how many operations can be in flight for a management operation like deleting or resizing an image OPTION(rbd_balance_snap_reads, OPT_BOOL, false) OPTION(rbd_localize_snap_reads, OPT_BOOL, false) +OPTION(rbd_balance_parent_reads, OPT_BOOL, false) +OPTION(rbd_localize_parent_reads, OPT_BOOL, true) /* * The following options change the behavior for librbd's image creation methods that diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 41518b67698..6477e8dfd04 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -45,6 +45,7 @@ namespace librbd { snap_lock("librbd::ImageCtx::snap_lock"), parent_lock("librbd::ImageCtx::parent_lock"), refresh_lock("librbd::ImageCtx::refresh_lock"), + extra_read_flags(0), old_format(true), order(0), size(0), features(0), format_string(NULL), @@ -238,8 +239,12 @@ namespace librbd { delete perfcounter; } + void ImageCtx::set_read_flag(unsigned flag) { + extra_read_flags |= flag; + } + int ImageCtx::get_read_flags(snap_t snap_id) { - int flags = librados::OPERATION_NOFLAG; + int flags = librados::OPERATION_NOFLAG | extra_read_flags; if (snap_id == LIBRADOS_SNAP_HEAD) return flags; diff --git a/src/librbd/ImageCtx.h b/src/librbd/ImageCtx.h index c9e74393e13..026a3e05a45 100644 --- a/src/librbd/ImageCtx.h +++ b/src/librbd/ImageCtx.h @@ -69,6 +69,8 @@ namespace librbd { RWLock parent_lock; // protects parent_md and parent Mutex refresh_lock; // protects refresh_seq and last_refresh + unsigned extra_read_flags; + bool old_format; uint8_t order; uint64_t size; @@ -99,6 +101,7 @@ namespace librbd { void init_layout(); void perf_start(std::string name); void perf_stop(); + void set_read_flag(unsigned flag); int get_read_flags(librados::snap_t snap_id); int snap_set(std::string in_snap_name); void snap_unset(); diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 84e5477dec8..81b70dd310c 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -1246,6 +1246,13 @@ reprotect_and_return_err: // since we don't know the image and snapshot name, set their ids and // reset the snap_name and snap_exists fields after we read the header ictx->parent = new ImageCtx("", parent_image_id, NULL, p_ioctx, true); + + // set rados flags for reading the parent image + if (ictx->cct->_conf->rbd_balance_parent_reads) + ictx->parent->set_read_flag(librados::OPERATION_BALANCE_READS); + else if (ictx->cct->_conf->rbd_localize_parent_reads) + ictx->parent->set_read_flag(librados::OPERATION_LOCALIZE_READS); + r = open_image(ictx->parent); if (r < 0) { lderr(ictx->cct) << "error opening parent image: " << cpp_strerror(r)