All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@inktank.com>
To: Josh Durgin <josh.durgin@inktank.com>
Cc: ceph-devel@vger.kernel.org
Subject: Re: [PATCH 7/8] rbd: add reference counting to rbd_spec
Date: Tue, 30 Oct 2012 07:59:33 -0500	[thread overview]
Message-ID: <508FCF35.4090507@inktank.com> (raw)
In-Reply-To: <508F0147.1000205@inktank.com>

On 10/29/2012 05:20 PM, Josh Durgin wrote:
> On 10/26/2012 04:03 PM, Alex Elder wrote:
>> With layered images we'll share rbd_spec structures, so add a
>> reference count to it.  It neatens up some code also.
> 
> Could you explain your plan for these data structures? What
> will the structs and their relationships look like with
> clones mapped?

Like I mentioned in the previous message, this structure
encapsulates the information that identifies an rbd image.

In the next patch, the information defining the image to
be mapped is extracted from "command line" arguments to
populate the content of one of these in the argument
parsing routine.

In an upcoming patch, some create/destroy helper routines
will be defined for an rbd_device structure. To create an
rbd device, you provide an initialized (activated?)
rbd_client (which includes a ceph client) and the identity
of an image you want that rbd_device to map using that client.

So in response to a map request via /sys/bus/rbd/add, a
new rbd_client will be created in that way.  Later, a
mapped rbd image (v2) will continue its probing activity
by probing its parent, and if it has one, an rbd_device
structure will be created for that purpose, using the
same client as the original/child image and the image
specification fetched from the child for the parent.

I suppose it's not obvious at this point why reference
counting is needed.  It's one of those things that is
needed later on (in work that's well underway but which
I have not posted yet), and this turns out to be a
good time to put that in place so it's there when it's
needed, shortly.

In any case, the reference counting here arises because
the image spec for a parent will be created and filled in
while probing the child.  But I want to provide that image
spec for creating the parent rbd_device structure, and
keeping track of who owned what got a little confusing
so I decided that just sharing a reference counted
structure was the best way to go.

					-Alex

>> A silly get/put pair is added to the alloc routine just to avoid
>> "defined but not used" warnings.  It will go away soon.
>>
>> Signed-off-by: Alex Elder <elder@inktank.com>
>> ---
>>   drivers/block/rbd.c |   52
>> +++++++++++++++++++++++++++++++++++++++++----------
>>   1 file changed, 42 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
>> index c39e238..19c7c6b 100644
>> --- a/drivers/block/rbd.c
>> +++ b/drivers/block/rbd.c
>> @@ -2134,6 +2134,45 @@ static struct device_type rbd_snap_device_type = {
>>       .release    = rbd_snap_dev_release,
>>   };
>>
>> +static struct rbd_spec *rbd_spec_get(struct rbd_spec *spec)
>> +{
>> +    kref_get(&spec->kref);
>> +
>> +    return spec;
>> +}
>> +
>> +static void rbd_spec_free(struct kref *kref);
>> +static void rbd_spec_put(struct rbd_spec *spec)
>> +{
>> +    if (spec)
>> +        kref_put(&spec->kref, rbd_spec_free);
>> +}
>> +
>> +static struct rbd_spec *rbd_spec_alloc(void)
>> +{
>> +    struct rbd_spec *spec;
>> +
>> +    spec = kzalloc(sizeof (*spec), GFP_KERNEL);
>> +    if (!spec)
>> +        return NULL;
>> +    kref_init(&spec->kref);
>> +
>> +    rbd_spec_put(rbd_spec_get(spec));    /* TEMPORARY */
>> +
>> +    return spec;
>> +}
>> +
>> +static void rbd_spec_free(struct kref *kref)
>> +{
>> +    struct rbd_spec *spec = container_of(kref, struct rbd_spec, kref);
>> +
>> +    kfree(spec->pool_name);
>> +    kfree(spec->image_id);
>> +    kfree(spec->image_name);
>> +    kfree(spec->snap_name);
>> +    kfree(spec);
>> +}
>> +
>>   static bool rbd_snap_registered(struct rbd_snap *snap)
>>   {
>>       bool ret = snap->dev.type == &rbd_snap_device_type;
>> @@ -3165,7 +3204,7 @@ static ssize_t rbd_add(struct bus_type *bus,
>>       rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
>>       if (!rbd_dev)
>>           return -ENOMEM;
>> -    rbd_dev->spec = kzalloc(sizeof (*rbd_dev->spec), GFP_KERNEL);
>> +    rbd_dev->spec = rbd_spec_alloc();
>>       if (!rbd_dev->spec)
>>           goto err_out_mem;
>>
>> @@ -3278,16 +3317,12 @@ err_out_probe:
>>   err_out_client:
>>       kfree(rbd_dev->header_name);
>>       rbd_put_client(rbd_dev);
>> -    kfree(rbd_dev->spec->image_id);
>>   err_out_args:
>>       if (ceph_opts)
>>           ceph_destroy_options(ceph_opts);
>> -    kfree(rbd_dev->spec->snap_name);
>> -    kfree(rbd_dev->spec->image_name);
>> -    kfree(rbd_dev->spec->pool_name);
>>       kfree(rbd_opts);
>>   err_out_mem:
>> -    kfree(rbd_dev->spec);
>> +    rbd_spec_put(rbd_dev->spec);
>>       kfree(rbd_dev);
>>
>>       dout("Error adding device %s\n", buf);
>> @@ -3336,12 +3371,9 @@ static void rbd_dev_release(struct device *dev)
>>       rbd_header_free(&rbd_dev->header);
>>
>>       /* done with the id, and with the rbd_dev */
>> -    kfree(rbd_dev->spec->snap_name);
>> -    kfree(rbd_dev->spec->image_id);
>>       kfree(rbd_dev->header_name);
>> -    kfree(rbd_dev->spec->pool_name);
>> -    kfree(rbd_dev->spec->image_name);
>>       rbd_dev_id_put(rbd_dev);
>> +    rbd_spec_put(rbd_dev->spec);
>>       kfree(rbd_dev);
>>
>>       /* release module ref */
>>
> 


  reply	other threads:[~2012-10-30 12:59 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-26 22:42 Another pile of patches Alex Elder
2012-10-26 22:44 ` [PATCH, resend] rbd: simplify rbd_rq_fn() Alex Elder
2012-10-29 20:29   ` Josh Durgin
2012-10-30 12:01     ` Alex Elder
2012-10-26 22:45 ` [PATCH] rbd: remove snapshots on error in rbd_add() Alex Elder
2012-10-29 20:36   ` Josh Durgin
2012-10-26 22:45 ` [PATCH] rbd: make pool_id a 64 bit value Alex Elder
2012-10-29 20:40   ` Josh Durgin
2012-10-26 22:48 ` [PATCH 0/2] rbd: mapping structure changes Alex Elder
2012-10-26 22:51   ` [PATCH 1/2] rbd: move snap info out of rbd_mapping struct Alex Elder
2012-10-29 20:43     ` Josh Durgin
2012-10-26 22:51   ` [PATCH 2/2] rbd: rename snap_exists field Alex Elder
2012-10-29 20:46     ` Josh Durgin
2012-10-26 22:52 ` [PATCH 0/2] rbd: consolidate argument parsing Alex Elder
2012-10-26 22:55   ` [PATCH 1/2] rbd: move ceph_parse_options() call up Alex Elder
2012-10-29 21:08     ` Josh Durgin
2012-10-26 22:55   ` [PATCH 2/2] rbd: do all argument parsing in one place Alex Elder
2012-10-29 21:13     ` Josh Durgin
2012-10-26 22:56 ` [PATCH 0/8] rbd: have rbd_add_parse_args() only parse args Alex Elder
2012-10-26 23:00   ` [PATCH 1/8] rbd: get rid of snap_name_len Alex Elder
2012-10-29 21:14     ` Josh Durgin
2012-10-26 23:00   ` [PATCH 2/8] rbd: remove options args from rbd_add_parse_args() Alex Elder
2012-10-29 21:17     ` Josh Durgin
2012-10-26 23:01   ` [PATCH 3/8] rbd: remove snap_name arg " Alex Elder
2012-10-29 21:26     ` Josh Durgin
2012-10-26 23:02   ` [PATCH 4/8] rbd: pass and populate rbd_options structure Alex Elder
2012-10-29 21:27     ` Josh Durgin
2012-10-26 23:02   ` [PATCH 5/8] rbd: have rbd_add_parse_args() return error Alex Elder
2012-10-29 21:28     ` Josh Durgin
2012-10-26 23:03   ` [PATCH 6/8] rbd: define image specification structure Alex Elder
2012-10-29 22:13     ` Josh Durgin
2012-10-30 12:40       ` Alex Elder
2012-10-30 20:13         ` Josh Durgin
2012-10-26 23:03   ` [PATCH 7/8] rbd: add reference counting to rbd_spec Alex Elder
2012-10-29 22:20     ` Josh Durgin
2012-10-30 12:59       ` Alex Elder [this message]
2012-10-30 20:17         ` Josh Durgin
2012-10-26 23:03   ` [PATCH 8/8] rbd: fill rbd_spec in rbd_add_parse_args() Alex Elder
2012-10-29 22:30     ` Josh Durgin
2012-10-30 13:09       ` Alex Elder
2012-10-30 20:18         ` Josh Durgin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=508FCF35.4090507@inktank.com \
    --to=elder@inktank.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=josh.durgin@inktank.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.