]> Pileus Git - ~andy/linux/blobdiff - drivers/block/rbd.c
rbd: stop tracking header object version
[~andy/linux] / drivers / block / rbd.c
index 408e29f102c8237754d70685bce961cc9bdad5ec..8875bebbacfca13e46536c31c8c961da74ec19c7 100644 (file)
@@ -110,8 +110,6 @@ struct rbd_image_header {
 
        u64 stripe_unit;
        u64 stripe_count;
-
-       u64 obj_version;
 };
 
 /*
@@ -672,35 +670,6 @@ static void rbd_client_release(struct kref *kref)
        kfree(rbdc);
 }
 
-/* Caller has to fill in snapc->seq and snapc->snaps[0..snap_count-1] */
-
-static struct ceph_snap_context *rbd_snap_context_create(u32 snap_count)
-{
-       struct ceph_snap_context *snapc;
-       size_t size;
-
-       size = sizeof (struct ceph_snap_context);
-       size += snap_count * sizeof (snapc->snaps[0]);
-       snapc = kzalloc(size, GFP_KERNEL);
-       if (!snapc)
-               return NULL;
-
-       atomic_set(&snapc->nref, 1);
-       snapc->num_snaps = snap_count;
-
-       return snapc;
-}
-
-static inline void rbd_snap_context_get(struct ceph_snap_context *snapc)
-{
-       (void)ceph_get_snap_context(snapc);
-}
-
-static inline void rbd_snap_context_put(struct ceph_snap_context *snapc)
-{
-       ceph_put_snap_context(snapc);
-}
-
 /*
  * Drop reference to ceph client node. If it's not referenced anymore, release
  * it.
@@ -820,7 +789,7 @@ static int rbd_header_from_disk(struct rbd_image_header *header,
 
        header->image_size = le64_to_cpu(ondisk->image_size);
 
-       header->snapc = rbd_snap_context_create(snap_count);
+       header->snapc = ceph_create_snap_context(snap_count, GFP_KERNEL);
        if (!header->snapc)
                goto out_err;
        header->snapc->seq = le64_to_cpu(ondisk->snap_seq);
@@ -1753,7 +1722,7 @@ static struct rbd_img_request *rbd_img_request_create(
 
        if (write_request) {
                down_read(&rbd_dev->header_rwsem);
-               rbd_snap_context_get(rbd_dev->header.snapc);
+               ceph_get_snap_context(rbd_dev->header.snapc);
                up_read(&rbd_dev->header_rwsem);
        }
 
@@ -1805,7 +1774,7 @@ static void rbd_img_request_destroy(struct kref *kref)
        rbd_assert(img_request->obj_request_count == 0);
 
        if (img_request_write_test(img_request))
-               rbd_snap_context_put(img_request->snapc);
+               ceph_put_snap_context(img_request->snapc);
 
        if (img_request_child_test(img_request))
                rbd_obj_request_put(img_request->obj_request);
@@ -2583,8 +2552,7 @@ static int rbd_dev_header_watch_sync(struct rbd_device *rbd_dev, int start)
                                        rbd_dev->watch_request->osd_req);
 
        osd_req_op_watch_init(obj_request->osd_req, 0, CEPH_OSD_OP_WATCH,
-                               rbd_dev->watch_event->cookie,
-                               rbd_dev->header.obj_version, start);
+                               rbd_dev->watch_event->cookie, 0, start);
        rbd_osd_req_format_write(obj_request);
 
        ret = rbd_obj_request_submit(osdc, obj_request);
@@ -3016,8 +2984,6 @@ static int rbd_read_header(struct rbd_device *rbd_dev,
        if (IS_ERR(ondisk))
                return PTR_ERR(ondisk);
        ret = rbd_header_from_disk(header, ondisk);
-       if (ret >= 0)
-               header->obj_version = ver;
        kfree(ondisk);
 
        return ret;
@@ -3071,11 +3037,8 @@ static int rbd_dev_v1_refresh(struct rbd_device *rbd_dev, u64 *hver)
        kfree(rbd_dev->header.snap_sizes);
        kfree(rbd_dev->header.snap_names);
        /* osd requests may still refer to snapc */
-       rbd_snap_context_put(rbd_dev->header.snapc);
+       ceph_put_snap_context(rbd_dev->header.snapc);
 
-       if (hver)
-               *hver = h.obj_version;
-       rbd_dev->header.obj_version = h.obj_version;
        rbd_dev->header.image_size = h.image_size;
        rbd_dev->header.snapc = h.snapc;
        rbd_dev->header.snap_names = h.snap_names;
@@ -3094,19 +3057,22 @@ static int rbd_dev_v1_refresh(struct rbd_device *rbd_dev, u64 *hver)
 
 static int rbd_dev_refresh(struct rbd_device *rbd_dev, u64 *hver)
 {
+       u64 image_size;
        int ret;
 
        rbd_assert(rbd_image_format_valid(rbd_dev->image_format));
+       image_size = rbd_dev->header.image_size;
        mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
        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);
-       revalidate_disk(rbd_dev->disk);
        if (ret)
                rbd_warn(rbd_dev, "got notification but failed to "
                           " update snaps: %d\n", ret);
+       if (image_size != rbd_dev->header.image_size)
+               revalidate_disk(rbd_dev->disk);
 
        return ret;
 }
@@ -3461,10 +3427,10 @@ static struct rbd_snap *rbd_snap_create(struct rbd_device *rbd_dev,
  * Returns a dynamically-allocated snapshot name if successful, or a
  * pointer-coded error otherwise.
  */
-static char *rbd_dev_v1_snap_info(struct rbd_device *rbd_dev, u32 which,
+static const char *rbd_dev_v1_snap_info(struct rbd_device *rbd_dev, u32 which,
                u64 *snap_size, u64 *snap_features)
 {
-       char *snap_name;
+       const char *snap_name;
        int i;
 
        rbd_assert(which < rbd_dev->header.snapc->num_snaps);
@@ -3914,7 +3880,7 @@ static int rbd_dev_v2_snap_context(struct rbd_device *rbd_dev, u64 *ver)
                goto out;
        ret = 0;
 
-       snapc = rbd_snap_context_create(snap_count);
+       snapc = ceph_create_snap_context(snap_count, GFP_KERNEL);
        if (!snapc) {
                ret = -ENOMEM;
                goto out;
@@ -3933,7 +3899,7 @@ out:
        return ret;
 }
 
-static char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev, u32 which)
+static const char *rbd_dev_v2_snap_name(struct rbd_device *rbd_dev, u32 which)
 {
        size_t size;
        void *reply_buf;
@@ -3974,13 +3940,13 @@ out:
        return snap_name;
 }
 
-static char *rbd_dev_v2_snap_info(struct rbd_device *rbd_dev, u32 which,
+static const char *rbd_dev_v2_snap_info(struct rbd_device *rbd_dev, u32 which,
                u64 *snap_size, u64 *snap_features)
 {
        u64 snap_id;
        u64 size;
        u64 features;
-       char *snap_name;
+       const char *snap_name;
        int ret;
 
        rbd_assert(which < rbd_dev->header.snapc->num_snaps);
@@ -4004,7 +3970,7 @@ out_err:
        return ERR_PTR(ret);
 }
 
-static char *rbd_dev_snap_info(struct rbd_device *rbd_dev, u32 which,
+static const char *rbd_dev_snap_info(struct rbd_device *rbd_dev, u32 which,
                u64 *snap_size, u64 *snap_features)
 {
        if (rbd_dev->image_format == 1)
@@ -4071,7 +4037,7 @@ static int rbd_dev_snaps_update(struct rbd_device *rbd_dev)
        while (index < snap_count || links != head) {
                u64 snap_id;
                struct rbd_snap *snap;
-               char *snap_name;
+               const char *snap_name;
                u64 snap_size = 0;
                u64 snap_features = 0;
 
@@ -4590,7 +4556,7 @@ static void rbd_dev_unprobe(struct rbd_device *rbd_dev)
        /* Free dynamic fields from the header, then zero it out */
 
        header = &rbd_dev->header;
-       rbd_snap_context_put(header->snapc);
+       ceph_put_snap_context(header->snapc);
        kfree(header->snap_sizes);
        kfree(header->snap_names);
        kfree(header->object_prefix);
@@ -4653,8 +4619,15 @@ static int rbd_dev_v2_probe(struct rbd_device *rbd_dev)
                ret = rbd_dev_v2_parent_info(rbd_dev);
                if (ret)
                        goto out_err;
-               rbd_warn(rbd_dev, "WARNING: kernel support for "
-                                       "layered rbd images is EXPERIMENTAL!");
+
+               /*
+                * Don't print a warning for parent images.  We can
+                * tell this point because we won't know its pool
+                * name yet (just its pool id).
+                */
+               if (rbd_dev->spec->pool_name)
+                       rbd_warn(rbd_dev, "WARNING: kernel layering "
+                                       "is EXPERIMENTAL!");
        }
 
        /* If the image supports fancy striping, get its parameters */
@@ -4675,7 +4648,6 @@ static int rbd_dev_v2_probe(struct rbd_device *rbd_dev)
        ret = rbd_dev_v2_snap_context(rbd_dev, &ver);
        if (ret)
                goto out_err;
-       rbd_dev->header.obj_version = ver;
 
        dout("discovered version 2 image, header name is %s\n",
                rbd_dev->header_name);
@@ -4879,10 +4851,6 @@ static int rbd_dev_image_probe(struct rbd_device *rbd_dev)
                goto err_out_snaps;
 
        ret = rbd_dev_probe_parent(rbd_dev);
-       if (ret)
-               goto err_out_snaps;
-
-       ret = rbd_dev_device_setup(rbd_dev);
        if (!ret)
                return 0;
 
@@ -4964,9 +4932,12 @@ static ssize_t rbd_add(struct bus_type *bus,
        if (rc < 0)
                goto err_out_rbd_dev;
 
-       return count;
+       rc = rbd_dev_device_setup(rbd_dev);
+       if (!rc)
+               return count;
+
+       rbd_dev_image_release(rbd_dev);
 err_out_rbd_dev:
-       kfree(rbd_dev->header_name);
        rbd_dev_destroy(rbd_dev);
 err_out_client:
        rbd_put_client(rbdc);
@@ -5011,8 +4982,6 @@ static void rbd_dev_device_release(struct device *dev)
        rbd_dev->major = 0;
        rbd_dev_id_put(rbd_dev);
        rbd_dev_mapping_clear(rbd_dev);
-
-       rbd_dev_image_release(rbd_dev);
 }
 
 static void rbd_dev_remove_parent(struct rbd_device *rbd_dev)
@@ -5031,7 +5000,7 @@ static void rbd_dev_remove_parent(struct rbd_device *rbd_dev)
                        second = third;
                }
                rbd_assert(second);
-               rbd_bus_del_dev(second);
+               rbd_dev_image_release(second);
                first->parent = NULL;
                first->parent_overlap = 0;
 
@@ -5077,6 +5046,7 @@ static ssize_t rbd_remove(struct bus_type *bus,
                goto done;
        ret = count;
        rbd_bus_del_dev(rbd_dev);
+       rbd_dev_image_release(rbd_dev);
        module_put(THIS_MODULE);
 done:
        mutex_unlock(&ctl_mutex);