From patchwork Fri Sep 7 13:45:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1422521 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id E57F23FC85 for ; Fri, 7 Sep 2012 13:45:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753290Ab2IGNpQ (ORCPT ); Fri, 7 Sep 2012 09:45:16 -0400 Received: from mail-ie0-f174.google.com ([209.85.223.174]:33631 "EHLO mail-ie0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753283Ab2IGNpO (ORCPT ); Fri, 7 Sep 2012 09:45:14 -0400 Received: by ieje11 with SMTP id e11so5014223iej.19 for ; Fri, 07 Sep 2012 06:45:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=QCj6AkzwHFqXAc2AbspDTDgg3J6k9NuMGUPui/JmXjI=; b=hErPfiFfJx0OqDjBkMy44MxO6J00JKzCN2megNiMUnBVL7B3cyLtwv0PHZNm8SHxVY Xz4HMnbeTcgv54+OXykA+mI5s5PnVb59x1pJNtp53d0O4ebEEgCbd2rGiP0Bu35WcBAV fpLF9P+LrkXCWubw/6Ufh3hB/RgcZL2Bit0sJYGbgYNjyypPtLUDiAW8zh3YrlsY40H5 f0D7HZzlIKgInPiBk0/F6K4YvGdYKeK8yGouUs08ujbJ/XIygivEiYVpVpOC6sm9K8yT GSAzeq6Rdnzk1ijM0e2jR6ij4fpCYI+blTz1+6s9Q/zlOQP4v4fGSjz6RPlh+fovvZuC IFhw== Received: by 10.50.76.133 with SMTP id k5mr152744igw.23.1347025514111; Fri, 07 Sep 2012 06:45:14 -0700 (PDT) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPS id aa4sm8138144igc.15.2012.09.07.06.45.11 (version=SSLv3 cipher=OTHER); Fri, 07 Sep 2012 06:45:12 -0700 (PDT) Message-ID: <5049FA67.3060904@inktank.com> Date: Fri, 07 Sep 2012 08:45:11 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 1/7] rbd: separate mapping info in rbd_dev References: <5049F951.2030706@inktank.com> In-Reply-To: <5049F951.2030706@inktank.com> X-Gm-Message-State: ALoCoQn19hXtDfptEsy9spjieNvtl2IxUIDzPVivXhJLHG2h7qFqs35DkXHe3EFI04JJCpkelQvH Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Several fields in a struct rbd_dev are related to what is mapped, as opposed to the actual base rbd image. If the base image is mapped these are almost unneeded, but if a snapshot is mapped they describe information about that snapshot. In some contexts this can be a little bit confusing. So group these mapping-related field into a structure to make it clear what they are describing. This also includes a minor change that rearranges the fields in the in-core image header structure so that invariant fields are at the top, followed by those that change. Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 83 ++++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 38 deletions(-) } @@ -375,7 +379,7 @@ enum { static match_table_t rbd_opts_tokens = { /* int args above */ /* string args above */ - {Opt_read_only, "read_only"}, + {Opt_read_only, "mapping.read_only"}, {Opt_read_only, "ro"}, /* Alternate spelling */ {Opt_read_write, "read_write"}, {Opt_read_write, "rw"}, /* Alternate spelling */ @@ -583,13 +587,13 @@ static int rbd_header_from_disk(struct rbd_image_header *header, header->snap_sizes = NULL; } - header->image_size = le64_to_cpu(ondisk->image_size); header->obj_order = ondisk->options.order; header->crypt_type = ondisk->options.crypt_type; header->comp_type = ondisk->options.comp_type; /* Allocate and fill in the snapshot context */ + header->image_size = le64_to_cpu(ondisk->image_size); size = sizeof (struct ceph_snap_context); size += snap_count * sizeof (header->snapc->snaps[0]); header->snapc = kzalloc(size, GFP_KERNEL); @@ -645,23 +649,24 @@ static int rbd_header_set_snap(struct rbd_device *rbd_dev, u64 *size) down_write(&rbd_dev->header_rwsem); - if (!memcmp(rbd_dev->snap_name, RBD_SNAP_HEAD_NAME, + if (!memcmp(rbd_dev->mapping.snap_name, RBD_SNAP_HEAD_NAME, sizeof (RBD_SNAP_HEAD_NAME))) { - rbd_dev->snap_id = CEPH_NOSNAP; - rbd_dev->snap_exists = false; - rbd_dev->read_only = rbd_dev->rbd_opts.read_only; + rbd_dev->mapping.snap_id = CEPH_NOSNAP; + rbd_dev->mapping.snap_exists = false; + rbd_dev->mapping.read_only = rbd_dev->rbd_opts.read_only; if (size) *size = rbd_dev->header.image_size; } else { u64 snap_id = 0; - ret = snap_by_name(&rbd_dev->header, rbd_dev->snap_name, + ret = snap_by_name(&rbd_dev->header, + rbd_dev->mapping.snap_name, &snap_id, size); if (ret < 0) goto done; - rbd_dev->snap_id = snap_id; - rbd_dev->snap_exists = true; - rbd_dev->read_only = true; /* No choice for snapshots */ + rbd_dev->mapping.snap_id = snap_id; + rbd_dev->mapping.snap_exists = true; + rbd_dev->mapping.read_only = true; } ret = 0; @@ -1532,7 +1537,7 @@ static void rbd_rq_fn(struct request_queue *q) size = blk_rq_bytes(rq); ofs = blk_rq_pos(rq) * SECTOR_SIZE; rq_bio = rq->bio; - if (do_write && rbd_dev->read_only) { + if (do_write && rbd_dev->mapping.read_only) { __blk_end_request_all(rq, -EROFS); continue; } @@ -1541,7 +1546,8 @@ static void rbd_rq_fn(struct request_queue *q) down_read(&rbd_dev->header_rwsem); - if (rbd_dev->snap_id != CEPH_NOSNAP && !rbd_dev->snap_exists) { + if (rbd_dev->mapping.snap_id != CEPH_NOSNAP && + !rbd_dev->mapping.snap_exists) { up_read(&rbd_dev->header_rwsem); dout("request for non-existent snapshot"); spin_lock_irq(q->queue_lock); @@ -1595,7 +1601,7 @@ static void rbd_rq_fn(struct request_queue *q) coll, cur_seg); else rbd_req_read(rq, rbd_dev, - rbd_dev->snap_id, + rbd_dev->mapping.snap_id, ofs, op_size, bio, coll, cur_seg); @@ -1767,7 +1773,7 @@ static int rbd_header_add_snap(struct rbd_device *rbd_dev, struct ceph_mon_client *monc; /* we should create a snapshot only if we're pointing at the head */ - if (rbd_dev->snap_id != CEPH_NOSNAP) + if (rbd_dev->mapping.snap_id != CEPH_NOSNAP) return -EINVAL; monc = &rbd_dev->rbd_client->client->monc; @@ -1821,7 +1827,7 @@ static int __rbd_refresh_header(struct rbd_device *rbd_dev, u64 *hver) down_write(&rbd_dev->header_rwsem); /* resized? */ - if (rbd_dev->snap_id == CEPH_NOSNAP) { + if (rbd_dev->mapping.snap_id == CEPH_NOSNAP) { sector_t size = (sector_t) h.image_size / SECTOR_SIZE; dout("setting size to %llu sectors", (unsigned long long) size); @@ -2004,7 +2010,7 @@ static ssize_t rbd_snap_show(struct device *dev, { struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); - return sprintf(buf, "%s\n", rbd_dev->snap_name); + return sprintf(buf, "%s\n", rbd_dev->mapping.snap_name); } static ssize_t rbd_image_refresh(struct device *dev, @@ -2205,11 +2211,12 @@ static int rbd_dev_snap_devs_update(struct rbd_device *rbd_dev) /* Existing snapshot not in the new snap context */ - if (rbd_dev->snap_id == snap->id) - rbd_dev->snap_exists = false; + if (rbd_dev->mapping.snap_id == snap->id) + rbd_dev->mapping.snap_exists = false; __rbd_remove_snap_dev(snap); dout("%ssnap id %llu has been removed\n", - rbd_dev->snap_id == snap->id ? "mapped " : "", + rbd_dev->mapping.snap_id == snap->id ? + "mapped " : "", (unsigned long long) snap->id); /* Done with this list entry; advance */ @@ -2522,18 +2529,18 @@ static int rbd_add_parse_args(struct rbd_device *rbd_dev, * The snapshot name is optional. If none is is supplied, * we use the default value. */ - rbd_dev->snap_name = dup_token(&buf, &len); - if (!rbd_dev->snap_name) + rbd_dev->mapping.snap_name = dup_token(&buf, &len); + if (!rbd_dev->mapping.snap_name) goto out_err; if (!len) { /* Replace the empty name with the default */ - kfree(rbd_dev->snap_name); - rbd_dev->snap_name + kfree(rbd_dev->mapping.snap_name); + rbd_dev->mapping.snap_name = kmalloc(sizeof (RBD_SNAP_HEAD_NAME), GFP_KERNEL); - if (!rbd_dev->snap_name) + if (!rbd_dev->mapping.snap_name) goto out_err; - memcpy(rbd_dev->snap_name, RBD_SNAP_HEAD_NAME, + memcpy(rbd_dev->mapping.snap_name, RBD_SNAP_HEAD_NAME, sizeof (RBD_SNAP_HEAD_NAME)); } @@ -2642,7 +2649,7 @@ err_out_client: rbd_put_client(rbd_dev); err_put_id: if (rbd_dev->pool_name) { - kfree(rbd_dev->snap_name); + kfree(rbd_dev->mapping.snap_name); kfree(rbd_dev->header_name); kfree(rbd_dev->image_name); kfree(rbd_dev->pool_name); @@ -2695,7 +2702,7 @@ static void rbd_dev_release(struct device *dev) unregister_blkdev(rbd_dev->major, rbd_dev->name); /* done with the id, and with the rbd_dev */ - kfree(rbd_dev->snap_name); + kfree(rbd_dev->mapping.snap_name); kfree(rbd_dev->header_name); kfree(rbd_dev->pool_name); kfree(rbd_dev->image_name); diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index eb6b772..dff6210 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -81,13 +81,15 @@ * block device image metadata (in-memory version) */ struct rbd_image_header { - u64 image_size; + /* These four fields never change for a given rbd image */ char *object_prefix; __u8 obj_order; __u8 crypt_type; __u8 comp_type; - struct ceph_snap_context *snapc; + /* The remaining fields need to be updated occasionally */ + u64 image_size; + struct ceph_snap_context *snapc; char *snap_names; u64 *snap_sizes; @@ -146,6 +148,13 @@ struct rbd_snap { u64 id; }; +struct rbd_mapping { + char *snap_name; + u64 snap_id; + bool snap_exists; + bool read_only; +}; + /* * a single device */ @@ -174,13 +183,8 @@ struct rbd_device { /* protects updating the header */ struct rw_semaphore header_rwsem; - /* name of the snapshot this device reads from */ - char *snap_name; - /* id of the snapshot this device reads from */ - u64 snap_id; /* current snapshot id */ - /* whether the snap_id this device reads from still exists */ - bool snap_exists; - bool read_only; + + struct rbd_mapping mapping; struct list_head node; @@ -261,11 +265,11 @@ static int rbd_open(struct block_device *bdev, fmode_t mode) { struct rbd_device *rbd_dev = bdev->bd_disk->private_data; - if ((mode & FMODE_WRITE) && rbd_dev->read_only) + if ((mode & FMODE_WRITE) && rbd_dev->mapping.read_only) return -EROFS; rbd_get_dev(rbd_dev); - set_device_ro(bdev, rbd_dev->read_only); + set_device_ro(bdev, rbd_dev->mapping.read_only); return 0;