From patchwork Thu Oct 31 03:40:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Yuan X-Patchwork-Id: 287391 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 75BA52C014B for ; Thu, 31 Oct 2013 14:42:01 +1100 (EST) Received: from localhost ([::1]:55386 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vbj8w-0003A0-WF for incoming@patchwork.ozlabs.org; Wed, 30 Oct 2013 23:41:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vbj8O-00038P-QQ for qemu-devel@nongnu.org; Wed, 30 Oct 2013 23:41:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vbj8I-0002oX-Bc for qemu-devel@nongnu.org; Wed, 30 Oct 2013 23:41:24 -0400 Received: from mail-oa0-x236.google.com ([2607:f8b0:4003:c02::236]:41130) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vbj8I-0002oE-4w for qemu-devel@nongnu.org; Wed, 30 Oct 2013 23:41:18 -0400 Received: by mail-oa0-f54.google.com with SMTP id o20so2483316oag.41 for ; Wed, 30 Oct 2013 20:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QI0ByPXzLHAYQn24XXxxqUAFkK1yHeqr3A00cp83VJs=; b=VGKaLEYqmVq1Z6eejMqDfTBmmN0bh/Lrn3xG1nIYUSiTh57SY3v/ZQp1MjJzwuZihO qdmXtrBgfcjZD9gy4zP2NYgUYMH4e9ISfWNgUfmaIxSPXzwlwrUBwSwtekt466GkMFPG YmxvxfHQgsiiDAUFIavXipslVPOR/5enXxsYiX5OBhJKSSs96syzEyJ4+BJqVX88FXDG EnbAgMgp0EMXiyUTRLRRkFw35sklVvVrJbT99lm4wiUm2fQlIg5zQNaBq1m8fFCcBoCe IZUrj0VaZ7b/QYgbJojFQ3iRZkxjn7b55H3ueWdXHJCr1Ch0SajsCWsj1ByfYzQk8/Qb Gp5g== X-Received: by 10.182.34.194 with SMTP id b2mr777346obj.41.1383190877500; Wed, 30 Oct 2013 20:41:17 -0700 (PDT) Received: from ubuntu-precise.taobao.ali.com ([182.92.247.2]) by mx.google.com with ESMTPSA id eg8sm2330440obd.6.2013.10.30.20.41.14 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Oct 2013 20:41:16 -0700 (PDT) From: Liu Yuan To: qemu-devel@nongnu.org Date: Thu, 31 Oct 2013 11:40:59 +0800 Message-Id: <1383190860-3526-2-git-send-email-namei.unix@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1383190860-3526-1-git-send-email-namei.unix@gmail.com> References: <1383190860-3526-1-git-send-email-namei.unix@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c02::236 Cc: Kevin Wolf , sheepdog@lists.wpkg.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v3 1/2] sheepdog: refactor do_sd_create() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We can actually use BDRVSheepdogState *s to pass most of the parameters. Cc: Kevin Wolf Cc: Stefan Hajnoczi Reviewed-by: Benoit Canet Signed-off-by: Liu Yuan --- block/sheepdog.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index ef387de..66b3ea8 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1464,9 +1464,7 @@ out: return ret; } -static int do_sd_create(BDRVSheepdogState *s, char *filename, int64_t vdi_size, - uint32_t base_vid, uint32_t *vdi_id, int snapshot, - uint8_t copy_policy) +static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot) { SheepdogVdiReq hdr; SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr; @@ -1483,11 +1481,11 @@ static int do_sd_create(BDRVSheepdogState *s, char *filename, int64_t vdi_size, * does not fit in buf? For now, just truncate and avoid buffer overrun. */ memset(buf, 0, sizeof(buf)); - pstrcpy(buf, sizeof(buf), filename); + pstrcpy(buf, sizeof(buf), s->name); memset(&hdr, 0, sizeof(hdr)); hdr.opcode = SD_OP_NEW_VDI; - hdr.vdi_id = base_vid; + hdr.vdi_id = s->inode.vdi_id; wlen = SD_MAX_VDI_LEN; @@ -1495,8 +1493,8 @@ static int do_sd_create(BDRVSheepdogState *s, char *filename, int64_t vdi_size, hdr.snapid = snapshot; hdr.data_length = wlen; - hdr.vdi_size = vdi_size; - hdr.copy_policy = copy_policy; + hdr.vdi_size = s->inode.vdi_size; + hdr.copy_policy = s->inode.copy_policy; ret = do_req(fd, (SheepdogReq *)&hdr, buf, &wlen, &rlen); @@ -1507,7 +1505,7 @@ static int do_sd_create(BDRVSheepdogState *s, char *filename, int64_t vdi_size, } if (rsp->result != SD_RES_SUCCESS) { - error_report("%s, %s", sd_strerror(rsp->result), filename); + error_report("%s, %s", sd_strerror(rsp->result), s->inode.name); return -EIO; } @@ -1568,23 +1566,21 @@ static int sd_create(const char *filename, QEMUOptionParameter *options, Error **errp) { int ret = 0; - uint32_t vid = 0, base_vid = 0; - int64_t vdi_size = 0; + uint32_t vid = 0; char *backing_file = NULL; BDRVSheepdogState *s; - char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN]; + char tag[SD_MAX_VDI_TAG_LEN]; uint32_t snapid; bool prealloc = false; Error *local_err = NULL; s = g_malloc0(sizeof(BDRVSheepdogState)); - memset(vdi, 0, sizeof(vdi)); memset(tag, 0, sizeof(tag)); if (strstr(filename, "://")) { - ret = sd_parse_uri(s, filename, vdi, &snapid, tag); + ret = sd_parse_uri(s, filename, s->name, &snapid, tag); } else { - ret = parse_vdiname(s, filename, vdi, &snapid, tag); + ret = parse_vdiname(s, filename, s->name, &snapid, tag); } if (ret < 0) { goto out; @@ -1592,7 +1588,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options, while (options && options->name) { if (!strcmp(options->name, BLOCK_OPT_SIZE)) { - vdi_size = options->value.n; + s->inode.vdi_size = options->value.n; } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) { backing_file = options->value.s; } else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) { @@ -1610,7 +1606,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options, options++; } - if (vdi_size > SD_MAX_VDI_SIZE) { + if (s->inode.vdi_size > SD_MAX_VDI_SIZE) { error_report("too big image size"); ret = -EINVAL; goto out; @@ -1645,12 +1641,11 @@ static int sd_create(const char *filename, QEMUOptionParameter *options, goto out; } - base_vid = s->inode.vdi_id; bdrv_unref(bs); } /* TODO: allow users to specify copy number */ - ret = do_sd_create(s, vdi, vdi_size, base_vid, &vid, 0, 0); + ret = do_sd_create(s, &vid, 0); if (!prealloc || ret) { goto out; } @@ -1833,8 +1828,7 @@ static int sd_create_branch(BDRVSheepdogState *s) * false bail out. */ deleted = sd_delete(s); - ret = do_sd_create(s, s->name, s->inode.vdi_size, s->inode.vdi_id, &vid, - !deleted, s->inode.copy_policy); + ret = do_sd_create(s, &vid, !deleted); if (ret) { goto out; } @@ -2097,8 +2091,7 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) goto cleanup; } - ret = do_sd_create(s, s->name, s->inode.vdi_size, s->inode.vdi_id, &new_vid, - 1, s->inode.copy_policy); + ret = do_sd_create(s, &new_vid, 1); if (ret < 0) { error_report("failed to create inode for snapshot. %s", strerror(errno));