From mboxrd@z Thu Jan 1 00:00:00 1970 From: Josh Durgin Subject: Re: [PATCH 2/4, v2] rbd: define rbd_dev_v2_refresh() Date: Tue, 09 Oct 2012 16:30:48 -0700 Message-ID: <5074B3A8.5020703@inktank.com> References: <50748FA5.4030508@inktank.com> <50749076.2070503@inktank.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from mail-pa0-f46.google.com ([209.85.220.46]:33983 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757172Ab2JIXaw (ORCPT ); Tue, 9 Oct 2012 19:30:52 -0400 Received: by mail-pa0-f46.google.com with SMTP id hz1so5744569pad.19 for ; Tue, 09 Oct 2012 16:30:52 -0700 (PDT) In-Reply-To: <50749076.2070503@inktank.com> Sender: ceph-devel-owner@vger.kernel.org List-ID: To: Alex Elder Cc: ceph-devel@vger.kernel.org Reviewed-by: Josh Durgin On 10/09/2012 02:00 PM, Alex Elder wrote: > Define a new function rbd_dev_v2_refresh() to update/refresh the > snapshot context for a format version 2 rbd image. This function > will update anything that is not fixed for the life of an rbd > image--at the moment this is mainly the snapshot context and (for > a base mapping) the size. > > Update rbd_refresh_header() so it selects which function to use > based on the image format. > > Rename __rbd_refresh_header() to be rbd_dev_v1_refresh() > to be consistent with the naming of its version 2 counterpart. > Similarly rename rbd_refresh_header() to be rbd_dev_refresh(). > > Unrelated--we use rbd_image_format_valid() here. Delete the other > use of it, which was primarily put in place to ensure that function > was referenced at the time it was defined. > > Signed-off-by: Alex Elder > --- > Changes in v2: > - also fetch size when refereshing image > - drop "snapc" from refresh function names > drivers/block/rbd.c | 55 > +++++++++++++++++++++++++++++++++++++++++++-------- > 1 file changed, 47 insertions(+), 8 deletions(-) > > diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c > index d36e6d7..23f3beb 100644 > --- a/drivers/block/rbd.c > +++ b/drivers/block/rbd.c > @@ -268,7 +268,8 @@ static void rbd_put_dev(struct rbd_device *rbd_dev) > put_device(&rbd_dev->dev); > } > > -static int rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver); > +static int rbd_dev_refresh(struct rbd_device *rbd_dev, u64 *hver); > +static int rbd_dev_v2_refresh(struct rbd_device *rbd_dev, u64 *hver); > > static int rbd_open(struct block_device *bdev, fmode_t mode) > { > @@ -1304,7 +1305,7 @@ static void rbd_watch_cb(u64 ver, u64 notify_id, > u8 opcode, void *data) > dout("rbd_watch_cb %s notify_id=%llu opcode=%u\n", > rbd_dev->header_name, (unsigned long long) notify_id, > (unsigned int) opcode); > - rc = rbd_refresh_header(rbd_dev, &hver); > + rc = rbd_dev_refresh(rbd_dev, &hver); > if (rc) > pr_warning(RBD_DRV_NAME "%d got notification but failed to " > " update snaps: %d\n", rbd_dev->major, rc); > @@ -1729,7 +1730,7 @@ static void rbd_update_size(struct rbd_device > *rbd_dev) > /* > * only read the first part of the ondisk header, without the snaps info > */ > -static int __rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver) > +static int rbd_dev_v1_refresh(struct rbd_device *rbd_dev, u64 *hver) > { > int ret; > struct rbd_image_header h; > @@ -1772,12 +1773,16 @@ static int __rbd_refresh_header(struct > rbd_device *rbd_dev, u64 *hver) > return ret; > } > > -static int rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver) > +static int rbd_dev_refresh(struct rbd_device *rbd_dev, u64 *hver) > { > int ret; > > + rbd_assert(rbd_image_format_valid(rbd_dev->image_format)); > mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); > - ret = __rbd_refresh_header(rbd_dev, hver); > + if (rbd_dev->image_format == 1) > + ret = rbd_dev_v1_refresh(rbd_dev, hver); > + else > + ret = rbd_dev_v2_refresh(rbd_dev, hver); > mutex_unlock(&ctl_mutex); > > return ret; > @@ -1937,7 +1942,7 @@ static ssize_t rbd_image_refresh(struct device *dev, > struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); > int ret; > > - ret = rbd_refresh_header(rbd_dev, NULL); > + ret = rbd_dev_refresh(rbd_dev, NULL); > > return ret < 0 ? ret : size; > } > @@ -2401,6 +2406,41 @@ static char *rbd_dev_snap_info(struct rbd_device > *rbd_dev, u32 which, > return ERR_PTR(-EINVAL); > } > > +static int rbd_dev_v2_refresh(struct rbd_device *rbd_dev, u64 *hver) > +{ > + int ret; > + __u8 obj_order; > + u64 image_size; > + > + down_write(&rbd_dev->header_rwsem); > + > + /* Grab old values first, to see if they change */ > + > + obj_order = rbd_dev->header.obj_order, > + image_size = rbd_dev->header.image_size; > + ret = rbd_dev_v2_image_size(rbd_dev); > + if (ret) > + goto out; > + rbd_assert(rbd_dev->header.obj_order == obj_order); > + if (image_size != rbd_dev->header.image_size) > + rbd_update_size(rbd_dev); > + > + ret = rbd_dev_v2_snap_context(rbd_dev, hver); > + dout("rbd_dev_v2_snap_context returned %d\n", ret); > + if (ret) > + goto out; > + ret = rbd_dev_snaps_update(rbd_dev); > + dout("rbd_dev_snaps_update returned %d\n", ret); > + if (ret) > + goto out; > + ret = rbd_dev_snaps_register(rbd_dev); > + dout("rbd_dev_snaps_register returned %d\n", ret); > +out: > + up_write(&rbd_dev->header_rwsem); > + > + return 0; > +} > + > /* > * Scan the rbd device's current snapshot list and compare it to the > * newly-received snapshot context. Remove any existing snapshots > @@ -2563,7 +2603,7 @@ static int rbd_init_watch_dev(struct rbd_device > *rbd_dev) > do { > ret = rbd_req_sync_watch(rbd_dev); > if (ret == -ERANGE) { > - rc = rbd_refresh_header(rbd_dev, NULL); > + rc = rbd_dev_refresh(rbd_dev, NULL); > if (rc < 0) > return rc; > } > @@ -3044,7 +3084,6 @@ static ssize_t rbd_add(struct bus_type *bus, > rc = rbd_dev_probe(rbd_dev); > if (rc < 0) > goto err_out_client; > - rbd_assert(rbd_image_format_valid(rbd_dev->image_format)); > > /* no need to lock here, as rbd_dev is not registered yet */ > rc = rbd_dev_snaps_update(rbd_dev);