From patchwork Thu Apr 25 16:19:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MORITA Kazutaka X-Patchwork-Id: 239559 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B6A7A2C00D1 for ; Fri, 26 Apr 2013 02:16:38 +1000 (EST) Received: from localhost ([::1]:47543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVOqa-0001gI-Qq for incoming@patchwork.ozlabs.org; Thu, 25 Apr 2013 12:16:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVOq3-0001aI-Tu for qemu-devel@nongnu.org; Thu, 25 Apr 2013 12:16:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UVOpy-0008Vy-Hc for qemu-devel@nongnu.org; Thu, 25 Apr 2013 12:16:03 -0400 Received: from sh.osrg.net ([192.16.179.4]:57096) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVOpx-0008VO-U3 for qemu-devel@nongnu.org; Thu, 25 Apr 2013 12:15:58 -0400 Received: from fs.osrg.net (localns.osrg.net [10.0.0.11]) by sh.osrg.net (8.14.4/8.14.4/OSRG-NET) with ESMTP id r3PGFflu012693; Fri, 26 Apr 2013 01:15:41 +0900 Received: from localhost (dfs1401.osrg.net [10.68.14.1]) by fs.osrg.net (Postfix) with ESMTP id 2CC80F947; Fri, 26 Apr 2013 01:15:41 +0900 (JST) From: MORITA Kazutaka To: stefanha@redhat.com, kwolf@redhat.com Date: Fri, 26 Apr 2013 01:19:53 +0900 Message-Id: <1366906794-24878-4-git-send-email-morita.kazutaka@lab.ntt.co.jp> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1366906794-24878-1-git-send-email-morita.kazutaka@lab.ntt.co.jp> References: <1366906794-24878-1-git-send-email-morita.kazutaka@lab.ntt.co.jp> X-Dispatcher: imput version 20100215(IM150) Lines: 126 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (sh.osrg.net [192.16.179.4]); Fri, 26 Apr 2013 01:15:44 +0900 (JST) X-Virus-Scanned: clamav-milter 0.97.7 at sh X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 192.16.179.4 Cc: namei.unix@gmail.com, sheepdog@lists.wpkg.org, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH v2 3/4] sheepdog: add helper function to reload inode 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 This adds a helper function to update the current inode state with the specified vdi object. Signed-off-by: MORITA Kazutaka --- block/sheepdog.c | 67 +++++++++++++++++++++++++++++++---------------------- 1 files changed, 39 insertions(+), 28 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index f4e7204..0eaf4c3 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1150,6 +1150,42 @@ static int write_object(int fd, char *buf, uint64_t oid, int copies, create, cache_flags); } +/* update inode with the latest state */ +static int reload_inode(BDRVSheepdogState *s, uint32_t snapid, const char *tag) +{ + SheepdogInode *inode; + int ret = 0, fd; + uint32_t vid = 0; + + fd = connect_to_sdog(s); + if (fd < 0) { + return -EIO; + } + + inode = g_malloc(sizeof(s->inode)); + + ret = find_vdi_name(s, s->name, snapid, tag, &vid, false); + if (ret) { + goto out; + } + + ret = read_object(fd, (char *)inode, vid_to_vdi_oid(vid), + s->inode.nr_copies, sizeof(*inode), 0, s->cache_flags); + if (ret < 0) { + goto out; + } + + if (inode->vdi_id != s->inode.vdi_id) { + memcpy(&s->inode, inode, sizeof(s->inode)); + } + +out: + g_free(inode); + closesocket(fd); + + return ret; +} + /* TODO Convert to fine grained options */ static QemuOptsList runtime_opts = { .name = "sheepdog", @@ -1905,18 +1941,14 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) { BDRVSheepdogState *s = bs->opaque; BDRVSheepdogState *old_s; - char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN]; - char *buf = NULL; - uint32_t vid; + char tag[SD_MAX_VDI_TAG_LEN]; uint32_t snapid = 0; - int ret = 0, fd; + int ret = 0; old_s = g_malloc(sizeof(BDRVSheepdogState)); memcpy(old_s, s, sizeof(BDRVSheepdogState)); - pstrcpy(vdi, sizeof(vdi), s->name); - snapid = strtoul(snapshot_id, NULL, 10); if (snapid) { tag[0] = 0; @@ -1924,30 +1956,11 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) pstrcpy(tag, sizeof(tag), s->name); } - ret = find_vdi_name(s, vdi, snapid, tag, &vid, false); + ret = reload_inode(s, snapid, tag); if (ret) { - error_report("Failed to find_vdi_name"); goto out; } - fd = connect_to_sdog(s); - if (fd < 0) { - ret = fd; - goto out; - } - - buf = g_malloc(SD_INODE_SIZE); - ret = read_object(fd, buf, vid_to_vdi_oid(vid), s->inode.nr_copies, - SD_INODE_SIZE, 0, s->cache_flags); - - closesocket(fd); - - if (ret) { - goto out; - } - - memcpy(&s->inode, buf, sizeof(s->inode)); - if (!s->inode.vm_state_size) { error_report("Invalid snapshot"); ret = -ENOENT; @@ -1956,14 +1969,12 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) s->is_snapshot = true; - g_free(buf); g_free(old_s); return 0; out: /* recover bdrv_sd_state */ memcpy(s, old_s, sizeof(BDRVSheepdogState)); - g_free(buf); g_free(old_s); error_report("failed to open. recover old bdrv_sd_state.");