From patchwork Wed Jul 11 14:01:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 1182691 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 232183FC8E for ; Wed, 11 Jul 2012 14:01:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757837Ab2GKOB2 (ORCPT ); Wed, 11 Jul 2012 10:01:28 -0400 Received: from mail-yx0-f174.google.com ([209.85.213.174]:63502 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757702Ab2GKOB1 (ORCPT ); Wed, 11 Jul 2012 10:01:27 -0400 Received: by mail-yx0-f174.google.com with SMTP id l2so1225622yen.19 for ; Wed, 11 Jul 2012 07:01:27 -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=DUpNgunaHE/fRzW1VNREFYxEEMR+4dd3E+9qwVeRjQ0=; b=fAqtku+lzrSN2gM/+enLdAFR6Kt5VljjKRZMcGpWEFDGfw3nqsvvfjypRPdBqGGwPv WGKSo5a8h1wQN2YDX9TCwYq6rmKxv+lgGyOtk3cq6sS7p/jZfmgBiolydAQQsEX6J6JH oihBr5svX/59PxKYbnGEOHXEb2mVZeUIWJod0/ClhFAd9gaWX/hdVlU0PrJeS7SU/imw Tu1tM7TeT1VOdmPLGZRE1WHSRRzhGzhLEvqXQ9s7Zwm2R6KLLxM0e937I2PzoMTokWYf anq3l0dBtIeGm8F0J7I/qNMU1EQPKHXxWIagSbBwQ4ATT6/pAYMaF3qbZgKJFfN0CkWj lV5A== Received: by 10.101.134.19 with SMTP id l19mr16938408ann.57.1342015287142; Wed, 11 Jul 2012 07:01:27 -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 u23sm3256289yhl.21.2012.07.11.07.01.24 (version=SSLv3 cipher=OTHER); Wed, 11 Jul 2012 07:01:26 -0700 (PDT) Message-ID: <4FFD8733.9090305@inktank.com> Date: Wed, 11 Jul 2012 09:01:23 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 05/16] rbd: define dup_token() References: <4FFD847C.7070205@inktank.com> In-Reply-To: <4FFD847C.7070205@inktank.com> X-Gm-Message-State: ALoCoQm6QvNpcAo/siJeOwhM1NAkKWAUllTcyRAvWEQ1MTRGu5E8qT9OxRDv98wSdVSRKmphgAEL Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Define a new function dup_token(), to be used during argument parsing for making dynamically-allocated copies of tokens being parsed. For now, no gfp_flags parameter is defined (GFP_KERNEL is used) but it could be easily be added if needed. Signed-off-by: Alex Elder Reviewed-by: Yehuda Sadeh Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 2ae3bb0..63c132f 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -2281,6 +2281,42 @@ static inline size_t copy_token(const char **buf, } /* + * Finds the next token in *buf, dynamically allocates a buffer big + * enough to hold a copy of it, and copies the token into the new + * buffer. The copy is guaranteed to be terminated with '\0'. Note + * that a duplicate buffer is created even for a zero-length token. + * + * Returns a pointer to the newly-allocated duplicate, or a null + * pointer if memory for the duplicate was not available. If + * the lenp argument is a non-null pointer, the length of the token + * (not including the '\0') is returned in *lenp. + * + * If successful, the *buf pointer will be updated to point beyond + * the end of the found token. + * + * Note: For now, the memory is allocated using GFP_KERNEL. + */ +static inline char *dup_token(const char **buf, size_t *lenp) +{ + char *dup; + size_t len; + + len = next_token(buf); + dup = kmalloc(len + 1, GFP_KERNEL); + if (!dup) + return NULL; + + memcpy(dup, *buf, len); + *(dup + len) = '\0'; + *buf += len; + + if (lenp) + *lenp = len; + + return dup; +} + +/* * This fills in the pool_name, obj, obj_len, snap_name, obj_len, * rbd_dev, rbd_md_name, and name fields of the given rbd_dev, based * on the list of monitor addresses and other options provided via